From 9d66375cc42f99c2b35257f77d33938ee0cfaab8 Mon Sep 17 00:00:00 2001 From: bqxbqx <132878537+BQXBQX@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:05:05 +0800 Subject: [PATCH] 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. --- __tests__/plots/bugfix/issue-5474.ts | 2 +- site/docs/spec/label/overview.zh.md | 2 +- src/runtime/plot.ts | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/__tests__/plots/bugfix/issue-5474.ts b/__tests__/plots/bugfix/issue-5474.ts index 70d505fa35..18efeb03fb 100644 --- a/__tests__/plots/bugfix/issue-5474.ts +++ b/__tests__/plots/bugfix/issue-5474.ts @@ -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, }); } diff --git a/site/docs/spec/label/overview.zh.md b/site/docs/spec/label/overview.zh.md index e327ef3c85..a6b4219839 100644 --- a/site/docs/spec/label/overview.zh.md +++ b/site/docs/spec/label/overview.zh.md @@ -127,7 +127,7 @@ chart d, i, data, - { channel, elementStyle }, // 聚合图形的样式 & label依赖元素的样式 + { channel, element }, // 聚合图形的样式 & label所依赖元素 ) => (channel.y[i] < 11700 ? '#E49361' : '#4787F7'), ); ``` diff --git a/src/runtime/plot.ts b/src/runtime/plot.ts index ae1725b8c5..dc5bd0f350 100644 --- a/src/runtime/plot.ts +++ b/src/runtime/plot.ts @@ -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); }); @@ -1367,7 +1367,7 @@ function createLabelShapeFunction( style: abstractStyle, render, selector, - elementStyle, + element, ...abstractOptions } = options; @@ -1375,8 +1375,8 @@ function createLabelShapeFunction( { ...abstractOptions, ...abstractStyle } as Record, (d) => valueOf(d, datum, index, abstractData, { - channel: { ...channel }, - elementStyle, + channel, + element, }), ); const { shape = defaultLabelShape, text, ...style } = visualOptions; @@ -1401,7 +1401,7 @@ function valueOf( datum: Record, i: number, data: Record, - options: { channel: Record; elementStyle?: Record }, + options: { channel: Record; element?: G2Element }, ) { if (typeof value === 'function') return value(datum, i, data, options); if (typeof value !== 'string') return value;