Skip to content

Commit

Permalink
fix: line,area,radar label style with callback
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Jul 30, 2024
1 parent bdc1342 commit 02bf66f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
41 changes: 41 additions & 0 deletions __tests__/bugs/issue-3804-spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 2 additions & 0 deletions src/adaptor/geometries/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export function line<O extends LineGeometryOptions>(params: Params<O>): Params<O

const { fields, formatter } = getTooltipMapping(tooltip, [xField, yField, seriesField]);

console.log(0, options);

// 如果存在才处理
return line
? geometry(
Expand Down
4 changes: 2 additions & 2 deletions src/plots/area/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ function label(params: Params<AreaOptions>): Params<AreaOptions> {
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: [
Expand Down
4 changes: 2 additions & 2 deletions src/plots/line/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ function label(params: Params<LineOptions>): Params<LineOptions> {
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: [
Expand Down
4 changes: 2 additions & 2 deletions src/plots/radar/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ function label(params: Params<RadarOptions>): Params<RadarOptions> {
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),
});
Expand Down

0 comments on commit 02bf66f

Please sign in to comment.