Skip to content

Commit

Permalink
feat(shape): add index and point2d params
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jun 7, 2022
1 parent 4ee4f06 commit 5a62ded
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/runtime/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,18 @@ async function plotView(

// Render marks with corresponding data.
for (const [{ key }, { data }] of markState.entries()) {
const point2d = data.map((d) => d.points);
selection
.select(`#${key}`)
.selectAll('.element')
.data(data, (d) => d.key)
.join(
(enter) =>
enter
.append(({ shape, points, ...v }) =>
shape(points, v, coordinate, theme),
)
.append(({ shape, points, ...v }, i) => {
const value = { ...v, index: i };
return shape(points, value, coordinate, theme, point2d);
})
.attr('className', 'element')
.each(function ({ enterType: animate, ...v }) {
const {
Expand All @@ -379,8 +381,9 @@ async function plotView(
animate(this, style, coordinate, theme);
}),
(update) =>
update.each(function ({ shape, points, ...v }) {
const node = shape(points, v, coordinate, theme);
update.each(function ({ shape, points, ...v }, i) {
const value = { ...v, index: i };
const node = shape(points, value, coordinate, theme, point2d);
copyAttributes(this, node);
}),
);
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/types/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ export type Shape = (
points: Vector2[],
value: {
color?: string;
index?: number;
[key: string]: Primitive;
},
coordinate: Coordinate,
theme: G2Theme,
point2d?: Vector2[][],
) => DisplayObject;
export type ShapeProps = {
defaultEnterAnimation: string;
Expand Down

0 comments on commit 5a62ded

Please sign in to comment.