Skip to content

Commit

Permalink
fix(pie): interaction for composite mark
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Sep 11, 2023
1 parent 952f6f9 commit bc4442c
Show file tree
Hide file tree
Showing 5 changed files with 53 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 @@ -69,3 +69,4 @@ export { commitsPointLegendFilter } from './commits-point-legend-filter';
export { settleWeatherLegendFilter } from './seattle-weather-legend-filter';
export { countriesBubbleMultiLegends } from './countries-bubble-multi-legends';
export { pointsPointTooltipMarker } from './points-point-tooltip-marker';
export { mockPieInteraction } from './mock-pie-interaction';
40 changes: 40 additions & 0 deletions __tests__/plots/interaction/mock-pie-interaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { deepMix } from '@antv/util';
import { G2Spec } from '../../../src';
import { LEGEND_ITEMS_CLASS_NAME } from '../../../src/interaction/legendFilter';
import { step } from './utils';

function Pie(options, context) {
const { encode = {}, ...rest } = options;
const { value, ...restEncode } = encode;
return deepMix(rest, {
type: 'interval',
transform: [{ type: 'stackY' }],
coordinate: { type: 'theta' },
encode: {
...restEncode,
y: value,
},
});
}

export function mockPieInteraction(): G2Spec {
return {
type: Pie,
data: [
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
],
// @ts-ignore
encode: { value: 'sold', color: 'genre' },
animate: false,
};
}

mockPieInteraction.steps = ({ canvas }) => {
const { document } = canvas;
const [e] = document.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME);
return [step(e, 'click')];
};
3 changes: 3 additions & 0 deletions src/runtime/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,14 @@ async function initializeView(
const flattenOptions = await transformMarks(options, library);

const mergedOptions = bubbleOptions(flattenOptions);

// @todo Remove this.
// !!! NOTE: Mute original view options.
// Update interaction and coordinate for this view.
options.interaction = mergedOptions.interaction;
options.coordinate = mergedOptions.coordinate;
// @ts-ignore
options.marks = [...mergedOptions.marks, ...mergedOptions.components];

const transformedOptions = coordinate2Transform(mergedOptions, library);
const state = await initializeMarks(transformedOptions, library);
Expand Down
10 changes: 9 additions & 1 deletion src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ export function copyAttributes(target: DisplayObject, source: DisplayObject) {
const { attributes } = source;
const exclude = new Set(['id', 'className']);
for (const [key, value] of Object.entries(attributes)) {
if (!exclude.has(key)) target.attr(key, value);
if (!exclude.has(key)) {
// @todo Fix in @antv/g
if (key === 'transform') {
target.attr(key, '');
target.attr(key, value);
} else {
target.attr(key, value);
}
}
}
}

Expand Down

0 comments on commit bc4442c

Please sign in to comment.