Skip to content

Commit

Permalink
fix(legend): filter with pages
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jul 7, 2023
1 parent 17ed2cb commit 56fec4c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/plots/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ export { penguinsPointBrushHandleCustom } from './penguins-point-brush-handle-cu
export { unemploymentChoropleth } from './unemployment-choropleth';
export { weatherLineLegendMark } from './weather-line-legend-mark';
export { countriesAnnotationSliderFilter } from './countries-annotation-slider-filter';
export { unemploymentAreaLegendFilterPages } from './unemployment-area-legend-filter-pages';
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { G2Spec } from '../../../src';
import { LEGEND_ITEMS_CLASS_NAME } from '../../../src/interaction/legendFilter';
import { step } from './utils';

export function unemploymentAreaLegendFilterPages(): G2Spec {
return {
width: 800,
type: 'area',
data: {
type: 'fetch',
value: 'data/unemployment-by-industry.csv',
},
transform: [{ type: 'stackY' }],
encode: {
x: 'date',
y: 'unemployed',
color: 'industry',
},
interaction: { tooltip: false },
};
}

unemploymentAreaLegendFilterPages.steps = ({ canvas }) => {
const { document } = canvas;
const [, page] = document.getElementsByClassName('items-item-page');
const elements = page.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME);
const [e0] = elements;
return [step(e0, 'click')];
};
5 changes: 4 additions & 1 deletion src/interaction/legendFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,15 @@ export function LegendFilter() {
];
return deepMix({}, mark, {
transform: newTransform,
// Set domain of scale to preserve legends.
//Set domain of scale to preserve legends.
scale: {
[channel]: {
domain: scaleOrdinal.getOptions().domain,
},
},
legend: {
[channel]: { preserve: true },
},
});
});
const newOptions = {
Expand Down

0 comments on commit 56fec4c

Please sign in to comment.