-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from visdesignlab/249-alternative-attribute-p…
…lots Additional attribute plot types (dot, strip, density)
- Loading branch information
Showing
13 changed files
with
429 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/upset/src/components/Columns/Attribute/AttributePlots/DensityPlot.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { VegaLite } from 'react-vega'; | ||
import { Subset, Aggregate, AttributePlotType } from '@visdesignlab/upset2-core'; | ||
import { FC } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { generateAttributePlotSpec } from './generateAttributePlotSpec'; | ||
import { dimensionsSelector } from '../../../../atoms/dimensionsAtom'; | ||
import { attributeMinMaxSelector } from '../../../../atoms/attributeAtom'; | ||
import { | ||
bookmarkedColorPalette, bookmarkedIntersectionSelector, currentIntersectionSelector, nextColorSelector, | ||
} from '../../../../atoms/config/currentIntersectionAtom'; | ||
import { ATTRIBUTE_DEFAULT_COLOR } from '../../../../utils/styles'; | ||
|
||
/** | ||
* Props for the DotPlot component. | ||
*/ | ||
type Props = { | ||
/** | ||
* Array of attribute values to plot. | ||
*/ | ||
values: number[]; | ||
/** | ||
* The attribute name. | ||
*/ | ||
attribute: string; | ||
/** | ||
* The row object. Rows can be either Subsets or Aggregates. | ||
*/ | ||
row: Subset | Aggregate; | ||
}; | ||
|
||
/** | ||
* DensityPlot component displays a density plot for a given attribute. | ||
* @param values - The values for the density plot. | ||
* @param attribute - The attribute for which the density plot is displayed. | ||
* @param row - The row for which the density plot is displayed. | ||
*/ | ||
export const DensityPlot: FC<Props> = ({ | ||
values, attribute, row, | ||
}) => { | ||
const dimensions = useRecoilValue(dimensionsSelector); | ||
|
||
const { min, max } = useRecoilValue(attributeMinMaxSelector(attribute)); | ||
const currentIntersection = useRecoilValue(currentIntersectionSelector); | ||
const bookmarks = useRecoilValue(bookmarkedIntersectionSelector); | ||
const colorPalette = useRecoilValue(bookmarkedColorPalette); | ||
const nextColor = useRecoilValue(nextColorSelector); | ||
|
||
/** | ||
* Logic for determining the selection/bookmark status of the row. | ||
* @returns {string} The fill color for the density plot. | ||
*/ | ||
function getFillColor(): string { | ||
// if the row is bookmarked, highlight the bar with the bookmark color | ||
if (row !== undefined && bookmarks.some((b) => b.id === row.id)) { | ||
// darken the color for advanced scale sub-bars | ||
return colorPalette[row.id]; | ||
} | ||
|
||
// We don't want to evaluate this to true if both currentIntersection and row are undefined, hence the 1st condition | ||
if (currentIntersection && currentIntersection?.id === row?.id) { // if currently selected, use the highlight colors | ||
return nextColor; | ||
} | ||
return ATTRIBUTE_DEFAULT_COLOR; | ||
} | ||
|
||
const spec = generateAttributePlotSpec(AttributePlotType.DensityPlot, values, min, max, getFillColor()); | ||
|
||
return ( | ||
<g | ||
id="Density" | ||
transform={`translate(0, ${-dimensions.attribute.plotHeight / 1.5})`} | ||
> | ||
<foreignObject width={dimensions.attribute.width} height={dimensions.attribute.plotHeight + 20}> | ||
<VegaLite | ||
renderer="svg" | ||
height={dimensions.attribute.plotHeight + 6} | ||
actions={false} | ||
spec={spec as any} | ||
/> | ||
</foreignObject> | ||
</g> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.