Skip to content

Commit

Permalink
fix(heatmap): brushing selection values
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme committed Apr 21, 2023
1 parent 4439802 commit 02c277d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ export function shapeViewModel<D extends BaseDatum = Datum>(

const getPanelPointCoordinates = (x: Pixels, y: Pixels) => {
const { category: v, panelValue: panelY, panelOffset: panelOffsetY } = getPanelPointCoordinate(y, 'vertical');
const { category: h, panelValue: panelX, panelOffset: panelOffsetX } = getPanelPointCoordinate(x, 'horizontal');
const {
category: h,
panelValue: panelX,
panelOffset: panelOffsetX,
} = getPanelPointCoordinate(x - chartDimensions.left, 'horizontal');

return {
x: panelX,
Expand Down Expand Up @@ -278,7 +282,7 @@ export function shapeViewModel<D extends BaseDatum = Datum>(
return [];
}

const { x: xValue, y: yValue, h, v } = getPanelPointCoordinates(x - chartDimensions.left, y);
const { x: xValue, y: yValue, h, v } = getPanelPointCoordinates(x, y);

if (xValue === undefined || yValue === undefined) {
return [];
Expand All @@ -304,7 +308,7 @@ export function shapeViewModel<D extends BaseDatum = Datum>(

// Find panel based on start pointer
const { category: smHorizontalAccessorValue, panelOffset: hOffset } = getPanelPointCoordinate(
start.x,
start.x - chartDimensions.left,
'horizontal',
);
const { category: smVerticalAccessorValue, panelOffset: vOffset } = getPanelPointCoordinate(start.y, 'vertical');
Expand Down
8 changes: 6 additions & 2 deletions storybook/stories/small_multiples/9_heatmap.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { boolean, number } from '@storybook/addon-knobs';
import { range } from 'lodash';
import { DateTime } from 'luxon';
import React, { useMemo } from 'react';
import React, { useEffect, useMemo } from 'react';

import {
ScaleType,
Expand Down Expand Up @@ -130,7 +130,11 @@ export const Example = () => {
() => sampleSize(fullData, vSplitCountAbs * hSplitCountAbs * dataCount * categories * density),
[categories, dataCount, density, fullData, vSplitCountAbs, hSplitCountAbs],
);
const { highlightedData, onElementClick, onBrushEnd } = useHeatmapSelection();
const { highlightedData, onElementClick, onBrushEnd, clearSelection } = useHeatmapSelection();

useEffect(() => {
clearSelection();
}, [clearSelection, vSplit, hSplit, vSplitCount, hSplitCount, categories, density, xScaleType]);

return (
<Chart>
Expand Down
1 change: 1 addition & 0 deletions storybook/stories/utils/use_heatmap_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const useHeatmapSelection = (disableActions = false) => {
setSelection,
onBrushEnd,
onElementClick,
clearSelection,
highlightedData: persistCellsSelection ? selection : undefined,
};
};

0 comments on commit 02c277d

Please sign in to comment.