Skip to content

Commit

Permalink
fix(label): correct label selector parameter handling and test case
Browse files Browse the repository at this point in the history
  • Loading branch information
BQXBQX committed Dec 3, 2024
1 parent cc2c480 commit ad57a37
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions __tests__/plots/bugfix/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { issue6396 } from './issue-6396';
export { issue6399 } from './issue-6399';
export { issueChart2719 } from './issue-chart-2719';
export { issue6020 } from './issue-6020';
46 changes: 46 additions & 0 deletions __tests__/plots/bugfix/issue-6020.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Chart } from '../../../src';

export function issue6020(context) {
const { container, canvas } = context;

const chart = new Chart({
container: container,
autoFit: true,
insetRight: 10,
canvas,
});

let i = 0;

chart
.line()
.data({
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/indices.json',
})
.transform({ type: 'normalizeY', basis: 'first', groupBy: 'color' })
.encode('x', (d) => new Date(d.Date))
.encode('y', 'Close')
.encode('color', 'Symbol')
.scale('y', { type: 'log' })
.axis('y', { title: '↑ Change in price (%)' })
.label({
text: 'Symbol',
selector: (data) => {
if (data.length) {
// 对于每个系列的数据,只保留索引等于 2 的标签
return data.filter((d, index) => index === 2);
}
return data;
},
fontSize: 10,
})
.tooltip({ channel: 'y', valueFormatter: '.1f' });

chart.render().then(() => {
console.log(i);
i = 0;
});

return { chart };
}
1 change: 1 addition & 0 deletions src/runtime/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@ function createLabelShapeFunction(
transform,
style: abstractStyle,
render,
selector,
...abstractOptions
} = options;
const visualOptions = mapObject(
Expand Down

0 comments on commit ad57a37

Please sign in to comment.