Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/interaction/brushFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {

setState('brushFilter', (options) => {
const { marks } = options;
const newMarks = marks.map((mark) =>
deepMix(
const newMarks = marks.map((mark) => {
// Independent y scale manages its own domain based on filtered data,
// so skip overriding it to avoid cross-scale domain pollution.
const isYIndependent = mark.scale?.y?.independent === true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current logic to detect an independent Y scale only checks for independent: true. This is correct, but might be incomplete. The codebase has other ways to define independent scales, for example by using different key properties on the scale.

To make this fix more robust and align with other parts of the codebase (like hasIndependentXYScale in utils.ts), consider also checking for scale keys. This would handle cases where dual axes are defined by keys without explicitly setting independent: true.

For example, you could modify the logic like this:

// At the top of the file:
import { hasIndependentXYScale } from './utils';

// ...

// Inside setState, before mapping marks:
const hasMultiYScales = hasIndependentXYScale('y', marks);

// ...

// Inside map, replace the isYIndependent check:
const isYIndependent =
  mark.scale?.y?.independent === true ||
  (hasMultiYScales && !!mark.scale?.y?.key);

return deepMix(
{
// Hide label to keep smooth transition.
axis: {
Expand All @@ -128,11 +131,13 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
// Set nice to false to avoid modify domain.
scale: {
x: { domain: domainX, nice: false },
y: { domain: domainY, nice: false },
...(!isYIndependent && {
y: { domain: domainY, nice: false },
}),
},
},
),
);
);
});

return {
...viewOptions,
Expand Down
Loading