Skip to content

Commit e472ec5

Browse files
author
aiyin.lzy
committed
fix: 双轴图 label 支持 formatter
1 parent 3fac3c6 commit e472ec5

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

__tests__/bugs/issue-2021-spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TinyLine, TinyArea, TinyColumn } from '../../src';
2-
import { CountryEconomy } from '../data/country-economy';
32
import { createDiv } from '../utils/dom';
43

54
const DATA = [

__tests__/unit/plots/dual-axes/column-spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ describe('Line-Column', () => {
2525
connectNulls: false,
2626
smooth: true,
2727
color: '#f00',
28+
label: {
29+
formatter: (datum) => {
30+
return `${datum.pv}个`;
31+
},
32+
},
2833
},
2934
{
3035
geometry: 'column',
36+
label: {
37+
formatter: (datum) => {
38+
return `${datum.uv}*`;
39+
},
40+
},
3141
},
3242
],
3343
});
@@ -47,6 +57,15 @@ describe('Line-Column', () => {
4757
expect(leftGeometry.shapeType).toBe('line');
4858
expect(rightGeometry.shapeType).toBe('interval');
4959

60+
// @ts-ignore
61+
expect(leftGeometry.labelOption.fields).toEqual(['pv']);
62+
// @ts-ignore
63+
expect(leftGeometry.labelOption.cfg.formatter(PV_DATA[0])).toBe('123000个');
64+
// @ts-ignore
65+
expect(rightGeometry.labelOption.fields).toEqual(['uv']);
66+
// @ts-ignore
67+
expect(rightGeometry.labelOption.cfg.formatter(UV_DATA[0])).toBe('1212*');
68+
5069
dualAxes.destroy();
5170
});
5271

__tests__/unit/plots/dual-axes/interaction-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DualAxes, Plot } from '../../../../src';
1+
import { DualAxes } from '../../../../src';
22
import { PV_DATA, UV_DATA } from '../../../data/pv-uv';
33
import { createDiv } from '../../../utils/dom';
44

__tests__/unit/plots/funnel/compare-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('compare funnel', () => {
6060
};
6161

6262
const { data } = funnel.chart.getOptions();
63-
data.forEach((item, index) => {
63+
data.forEach((item) => {
6464
const originData = origin[item.quarter];
6565
const originIndex = originData.findIndex((jtem) => jtem.pv === item.pv);
6666
expect(item[FUNNEL_PERCENT]).toEqual(item.pv / originData[0].pv);

__tests__/unit/plots/gauge/shapes/index-spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Gauge } from '../../../../../src';
2-
import { pick } from '../../../../../src/utils';
32
import { createDiv } from '../../../../utils/dom';
43

54
describe('gauge', () => {

__tests__/unit/plots/pie/html-statistic-spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Pie } from '../../../../src';
33
import { StatisticAction } from '../../../../src/plots/pie/interactions/pie-statistic-action';
44
import { POSITIVE_NEGATIVE_DATA } from '../../../data/common';
55
import { createDiv } from '../../../utils/dom';
6-
import { delay } from '../../../utils/delay';
76

87
describe('html-statistics', () => {
98
const div = createDiv();

examples/dual-axes/dual-line/demo/custom-dual-line.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const dualAxes = new DualAxes('container', {
2121
geometry: 'line',
2222
smooth: false,
2323
color: '#5B8FF9',
24+
label: {
25+
formatter: (datum) => {
26+
return `${datum.value}个`;
27+
},
28+
},
2429
lineStyle: {
2530
lineWidth: 3,
2631
lineDash: [5, 5],
@@ -34,7 +39,11 @@ const dualAxes = new DualAxes('container', {
3439
lineWidth: 4,
3540
opacity: 0.5,
3641
},
37-
label: {},
42+
label: {
43+
formatter: (datum) => {
44+
return `${datum.count}个`;
45+
},
46+
},
3847
point: {
3948
shape: 'circle',
4049
size: 4,

src/plots/dual-axes/util/geometry.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { each } from '@antv/util';
22
import { Geometry } from '@antv/g2';
33
import { Params } from '../../../core/adaptor';
44
import { point, line, interval } from '../../../adaptor/geometries';
5-
import { pick, findGeometry, deepAssign } from '../../../utils';
5+
import { pick, deepAssign } from '../../../utils';
66
import { GeometryOption } from '../types';
77
import { isLine, isColumn } from './option';
88

@@ -14,7 +14,7 @@ export function drawSingleGeometry<O extends { xField: string; yField: string; g
1414
params: Params<O>
1515
): Params<O> {
1616
const { options, chart } = params;
17-
const { geometryOption, yField } = options;
17+
const { geometryOption } = options;
1818
const { isStack, color, seriesField, groupField, isGroup } = geometryOption;
1919

2020
const FIELD_KEY = ['xField', 'yField'];
@@ -83,18 +83,5 @@ export function drawSingleGeometry<O extends { xField: string; yField: string; g
8383
);
8484
}
8585

86-
// 绘制 label
87-
const mainGeometry = findGeometry(chart, 'line') || findGeometry(chart, 'interval');
88-
if (!geometryOption.label) {
89-
mainGeometry.label(false);
90-
} else {
91-
const { callback, ...cfg } = geometryOption.label;
92-
mainGeometry.label({
93-
fields: [yField],
94-
callback,
95-
cfg,
96-
});
97-
}
98-
9986
return params;
10087
}

0 commit comments

Comments
 (0)