Skip to content

Commit

Permalink
fix: remove unnecessary structure and update label attributes (#6538)
Browse files Browse the repository at this point in the history
- Removed redundant structure in the label rendering process.
- Replaced elementStyle with element to expose the correct attributes in label functions.
  • Loading branch information
BQXBQX authored Dec 6, 2024
1 parent 56c0a3e commit 9d66375
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion __tests__/plots/bugfix/issue-5474.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function issue5474(context) {
.encode('color', 'genre')
.label({
text: 'genre',
fill: (_, i, array, d) => d.elementStyle.fill,
fill: (_, i, array, d) => d.element.attributes.fill,
});
}

Expand Down
2 changes: 1 addition & 1 deletion site/docs/spec/label/overview.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ chart
d,
i,
data,
{ channel, elementStyle }, // 聚合图形的样式 & label依赖元素的样式
{ channel, element }, // 聚合图形的样式 & label所依赖元素
) => (channel.y[i] < 11700 ? '#E49361' : '#4787F7'),
);
```
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ function plotLabel(
const L = getLabels(options, i, e);
L.forEach((l) => {
labelShapeFunction.set(l, (data) =>
shapeFunction({ ...data, elementStyle: e.attributes }),
shapeFunction({ ...data, element: e }),
);
labelDescriptor.set(l, labelOption);
});
Expand Down Expand Up @@ -1367,16 +1367,16 @@ function createLabelShapeFunction(
style: abstractStyle,
render,
selector,
elementStyle,
element,
...abstractOptions
} = options;

const visualOptions = mapObject(
{ ...abstractOptions, ...abstractStyle } as Record<string, any>,
(d) =>
valueOf(d, datum, index, abstractData, {
channel: { ...channel },
elementStyle,
channel,
element,
}),
);
const { shape = defaultLabelShape, text, ...style } = visualOptions;
Expand All @@ -1401,7 +1401,7 @@ function valueOf(
datum: Record<string, any>,
i: number,
data: Record<string, any>,
options: { channel: Record<string, any>; elementStyle?: Record<string, any> },
options: { channel: Record<string, any>; element?: G2Element },
) {
if (typeof value === 'function') return value(datum, i, data, options);
if (typeof value !== 'string') return value;
Expand Down

0 comments on commit 9d66375

Please sign in to comment.