Skip to content

Commit

Permalink
add selection to heatmap plot
Browse files Browse the repository at this point in the history
  • Loading branch information
dvchristianbors committed Sep 26, 2023
1 parent 92a323b commit 793ee9b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/vis/heatmap/Heatmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ export function Heatmap({
}) {
const [ref, { width, height }] = useResizeObserver();

const aggregatedTable = useMemo(() => {
const baseTable = useMemo(() => {
if (!column1 || !column2) return null;

let valueTable = table({
return table({
xVal: column1.resolvedValues.map(({ val }) => val),
yVal: column2.resolvedValues.map(({ val }) => val),
aggregateValues: aggregateColumn?.resolvedValues.map(({ val }) => val) || [],
aggregateVal: aggregateColumn?.resolvedValues.map(({ val }) => val) || [],
id: column1.resolvedValues.map(({ id }) => id),
});
}, [aggregateColumn?.resolvedValues, column1, column2, config.aggregateType, config.sortedBy]);

Check failure on line 54 in src/vis/heatmap/Heatmap.tsx

View workflow job for this annotation

GitHub Actions / build / Node

React Hook useMemo has unnecessary dependencies: 'config.aggregateType' and 'config.sortedBy'. Either exclude them or remove the dependency array
const aggregatedTable = useMemo(() => {
if (!baseTable) return null;

valueTable = valueTable.groupby('xVal', 'yVal');

valueTable = rollupByAggregateType(valueTable, config.aggregateType);
let valueTable = rollupByAggregateType(baseTable.groupby('xVal', 'yVal'), config.aggregateType);

if (config.aggregateType === EAggregateTypes.COUNT) {
valueTable = valueTable.impute({ aggregateVal: () => 0 }, { expand: ['xVal', 'yVal'] });
Expand All @@ -75,7 +76,7 @@ export function Heatmap({
}

return valueTable;
}, [aggregateColumn?.resolvedValues, column1, column2, config.aggregateType, config.sortedBy]);
}, [baseTable]);

Check failure on line 79 in src/vis/heatmap/Heatmap.tsx

View workflow job for this annotation

GitHub Actions / build / Node

React Hook useMemo has missing dependencies: 'config.aggregateType' and 'config.sortedBy'. Either include them or remove the dependency array

const { groupedValues, rectHeight, rectWidth, yScale, xScale, colorScale } = React.useMemo(() => {
const groupedVals = aggregatedTable.objects() as { xVal: string; yVal: string; aggregateVal: number; ids: string[] }[];
Expand Down Expand Up @@ -149,7 +150,13 @@ export function Heatmap({
const rects = useMemo(() => {
if (width === 0 || height === 0) return null;
return groupedValues.map((d, i) => {
const { aggregateVal, ids, x, y, xVal, yVal, color } = d;
const { aggregateVal, x, y, xVal, yVal, color } = d;
const ids: string[] = Array.from(
baseTable
.params({ x: xVal, y: yVal })
.filter((b, $) => b.xVal === $.x && b.yVal === $.y)
.values('id'),
);
return (
<HeatmapRect
xOrder={1 - Math.floor(i / xScale.domain().length) / xScale.domain().length}
Expand Down

0 comments on commit 793ee9b

Please sign in to comment.