Skip to content

Commit 9d66375

Browse files
authored
fix: remove unnecessary structure and update label attributes (#6538)
- Removed redundant structure in the label rendering process. - Replaced elementStyle with element to expose the correct attributes in label functions.
1 parent 56c0a3e commit 9d66375

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

__tests__/plots/bugfix/issue-5474.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function issue5474(context) {
2727
.encode('color', 'genre')
2828
.label({
2929
text: 'genre',
30-
fill: (_, i, array, d) => d.elementStyle.fill,
30+
fill: (_, i, array, d) => d.element.attributes.fill,
3131
});
3232
}
3333

site/docs/spec/label/overview.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ chart
127127
d,
128128
i,
129129
data,
130-
{ channel, elementStyle }, // 聚合图形的样式 & label依赖元素的样式
130+
{ channel, element }, // 聚合图形的样式 & label所依赖元素
131131
) => (channel.y[i] < 11700 ? '#E49361' : '#4787F7'),
132132
);
133133
```

src/runtime/plot.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ function plotLabel(
11981198
const L = getLabels(options, i, e);
11991199
L.forEach((l) => {
12001200
labelShapeFunction.set(l, (data) =>
1201-
shapeFunction({ ...data, elementStyle: e.attributes }),
1201+
shapeFunction({ ...data, element: e }),
12021202
);
12031203
labelDescriptor.set(l, labelOption);
12041204
});
@@ -1367,16 +1367,16 @@ function createLabelShapeFunction(
13671367
style: abstractStyle,
13681368
render,
13691369
selector,
1370-
elementStyle,
1370+
element,
13711371
...abstractOptions
13721372
} = options;
13731373

13741374
const visualOptions = mapObject(
13751375
{ ...abstractOptions, ...abstractStyle } as Record<string, any>,
13761376
(d) =>
13771377
valueOf(d, datum, index, abstractData, {
1378-
channel: { ...channel },
1379-
elementStyle,
1378+
channel,
1379+
element,
13801380
}),
13811381
);
13821382
const { shape = defaultLabelShape, text, ...style } = visualOptions;
@@ -1401,7 +1401,7 @@ function valueOf(
14011401
datum: Record<string, any>,
14021402
i: number,
14031403
data: Record<string, any>,
1404-
options: { channel: Record<string, any>; elementStyle?: Record<string, any> },
1404+
options: { channel: Record<string, any>; element?: G2Element },
14051405
) {
14061406
if (typeof value === 'function') return value(datum, i, data, options);
14071407
if (typeof value !== 'string') return value;

0 commit comments

Comments
 (0)