From 97223f062870ad10f65e008c4039b38126c44e5e Mon Sep 17 00:00:00 2001 From: hustcc Date: Tue, 30 Jul 2024 15:11:47 +0800 Subject: [PATCH] fix: line,area,radar label style with callback (#3805) * fix: line,area,radar label style with callback * chore: new version * chore: remove console.log * chore: update node version of ci * chore; update ci workflow --- .github/workflows/build.yml | 4 +-- CHANGELOG.md | 23 +++++++++++++++++ __tests__/bugs/issue-3804-spec.ts | 41 +++++++++++++++++++++++++++++++ package.json | 2 +- src/index.ts | 2 +- src/plots/area/adaptor.ts | 4 +-- src/plots/line/adaptor.ts | 4 +-- src/plots/radar/adaptor.ts | 4 +-- 8 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 __tests__/bugs/issue-3804-spec.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f859ab1e2..76a4874d79 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,11 +13,11 @@ jobs: - name: Setup Node.js environment uses: actions/setup-node@v2.1.5 with: - node-version: '14' + node-version: '18' - name: Run CI run: | - npm install + npm install --legacy-peer-deps npm run lint npm run build npm run coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index 225a6720c3..43a31bb675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ +#### 2.4.32 (2024-07-30) + +##### Chores + +* update github action ([#3608](https://github.com/antvis/G2plot/pull/3608)) ([90020297](https://github.com/antvis/G2plot/commit/90020297669dbe0d213ebae7abebf3f7d9509ec8)) +* fix customized stock demo typo ([#3564](https://github.com/antvis/G2plot/pull/3564)) ([99b9f638](https://github.com/antvis/G2plot/commit/99b9f63863684dc592f79388c99888c5d24184bd)) +* update version of @antv/component to 0.8.34 for dist build ([#3545](https://github.com/antvis/G2plot/pull/3545)) ([ec015ea5](https://github.com/antvis/G2plot/commit/ec015ea55490621de20cc2e8cdae872272f3789d)) + +##### Documentation Changes + +* update readme ([#3757](https://github.com/antvis/G2plot/pull/3757)) ([3725803e](https://github.com/antvis/G2plot/commit/3725803e982e7b4eb6595742462afbc23172ea76)) +* fix link ([#3514](https://github.com/antvis/G2plot/pull/3514)) ([0f570eb0](https://github.com/antvis/G2plot/commit/0f570eb085612910651cd9cd57b3c95cea97a1db)) +* Fix a few typos ([#3525](https://github.com/antvis/G2plot/pull/3525)) ([ce615a2a](https://github.com/antvis/G2plot/commit/ce615a2a17fae845fd6badf044491447a713cb90)) + +##### Bug Fixes + +* line,area,radar label style with callback ([02bf66f3](https://github.com/antvis/G2plot/commit/02bf66f36a39539a326d15689bd22f5f0a9b6025)) + +##### Other Changes + +* the default value of isPercent option should be false ([#3725](https://github.com/antvis/G2plot/pull/3725)) ([bdc1342e](https://github.com/antvis/G2plot/commit/bdc1342e3cc8a71d8cb1284acec9299b64648774)) +* **demo:** heatmap-base parameter error ([#3679](https://github.com/antvis/G2plot/pull/3679)) ([bd6af004](https://github.com/antvis/G2plot/commit/bd6af0044efe869b503c2d388adac8326d1e6f31)) + #### 2.4.31 (2023-05-10) ##### Chores diff --git a/__tests__/bugs/issue-3804-spec.ts b/__tests__/bugs/issue-3804-spec.ts new file mode 100644 index 0000000000..bb4dee400c --- /dev/null +++ b/__tests__/bugs/issue-3804-spec.ts @@ -0,0 +1,41 @@ +import { get } from '@antv/util'; +import { Line } from '../../src'; +import { createDiv } from '../utils/dom'; + +describe('#3804', () => { + it('line label style with callback', () => { + const line = new Line(createDiv(), { + width: 400, + height: 300, + autoFit: false, + data: [ + { year: '1991', value: 3 }, + { year: '1992', value: 4 }, + { year: '1993', value: 3.5 }, + { year: '1994', value: 5 }, + { year: '1995', value: 4.9 }, + { year: '1996', value: 6 }, + { year: '1997', value: 7 }, + { year: '1998', value: 9 }, + { year: '1999', value: 13 }, + ], + xField: 'year', + yField: 'value', + label: { + fields: ['year', 'value'], + callback: (year, value) => { + return { + style: { + text: value, + fill: value > 10 ? '#f24' : '#000', + }, + }; + }, + }, + }); + line.render(); + const geometry = line.chart.geometries[0]; + expect(get(geometry, ['labelOption', 'fields'])).toEqual(['year', 'value']); + line.destroy(); + }); +}); diff --git a/package.json b/package.json index 78fc90f876..5179370980 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g2plot", - "version": "2.4.31", + "version": "2.4.32", "description": "An interactive and responsive charting library", "keywords": [ "chart", diff --git a/src/index.ts b/src/index.ts index 96b860f90f..797b88d9f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export const version = '2.4.31'; +export const version = '2.4.32'; // G2 自定义能力透出 import * as G2 from '@antv/g2'; diff --git a/src/plots/area/adaptor.ts b/src/plots/area/adaptor.ts index 4288ae071c..e65c6cb41a 100644 --- a/src/plots/area/adaptor.ts +++ b/src/plots/area/adaptor.ts @@ -118,9 +118,9 @@ function label(params: Params): Params { if (!label) { areaGeometry.label(false); } else { - const { callback, ...cfg } = label; + const { fields, callback, ...cfg } = label; areaGeometry.label({ - fields: [yField], + fields: fields || [yField], callback, cfg: { layout: [ diff --git a/src/plots/line/adaptor.ts b/src/plots/line/adaptor.ts index 30292942b8..6af93c7da6 100644 --- a/src/plots/line/adaptor.ts +++ b/src/plots/line/adaptor.ts @@ -163,9 +163,9 @@ function label(params: Params): Params { if (!label) { lineGeometry.label(false); } else { - const { callback, ...cfg } = label; + const { fields, callback, ...cfg } = label; lineGeometry.label({ - fields: [yField], + fields: fields || [yField], callback, cfg: { layout: [ diff --git a/src/plots/radar/adaptor.ts b/src/plots/radar/adaptor.ts index 46cb58d61a..5f43d43894 100644 --- a/src/plots/radar/adaptor.ts +++ b/src/plots/radar/adaptor.ts @@ -113,9 +113,9 @@ function label(params: Params): Params { if (!label) { geometry.label(false); } else { - const { callback, ...cfg } = label; + const { fields, callback, ...cfg } = label; geometry.label({ - fields: [yField], + fields: fields || [yField], callback, cfg: transformLabel(cfg), });