Skip to content

Commit

Permalink
fix: Time brush not updating domain after using interactive filters
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Dec 6, 2021
1 parent 480b4dd commit 58d89b6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/charts/shared/brush.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export const BrushTime = () => {

brushWidthScale.range([0, brushWidth]);

const [minBrushDomainValue, maxBrushDomainValue] = useMemo(
() => brushWidthScale.domain().map((d) => d.getTime()),
[brushWidthScale]
);

const updateBrushStatus = (event: $FixMe) => {
const selection = event.selection;
if (!event.sourceEvent || !selection) {
Expand Down Expand Up @@ -279,16 +284,19 @@ export const BrushTime = () => {
// without transition
useEffect(() => {
const g = select(ref.current);

// Happens when transitioning from e.g. '2010-2020' to '1990-2000';
// the selection is then changed to the full extent
const identical = closestFrom.getTime() === closestTo.getTime();
const defaultSelection = [
brushWidthScale(closestFrom),
brushWidthScale(closestTo),
brushWidthScale(identical ? minBrushDomainValue : closestFrom),
brushWidthScale(identical ? maxBrushDomainValue : closestTo),
];

(g as Selection<SVGGElement, unknown, null, undefined>).call(
brush.move,
defaultSelection
);
}, [closestFrom.toString(), closestTo.toString()]);
}, [minBrushDomainValue, maxBrushDomainValue]);

// This effect makes the brush responsive
useEffect(() => {
Expand Down

0 comments on commit 58d89b6

Please sign in to comment.