Skip to content

Commit

Permalink
fix: tooltip alias 配置 Closed: #1412 (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Mar 28, 2022
1 parent d2542d6 commit 75eccf0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/f2/src/components/tooltip/withTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ export default (View) => {

const records = snapRecords.map((record) => {
const { origin, xField, yField } = record;
let name = xScale.getText(origin[xField]);
const value = yScale.getText(origin[yField]);
if (legendItems && legendItems.length) {
const item = find<any>(legendItems, (item) => {
const { field, tickValue } = item;
return origin[field] === tickValue;
});
if (item && item.name) {
name = item.name;

// 默认取 alias 的配置
let name = yScale.alias;
if (!name) {
name = xScale.getText(origin[xField]);
if (legendItems && legendItems.length) {
const item = find<any>(legendItems, (item) => {
const { field, tickValue } = item;
return origin[field] === tickValue;
});
if (item && item.name) {
name = item.name;
}
}
}
return {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions packages/f2/test/components/tooltip/alias.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { jsx, Canvas, Chart, Axis, Line, Interval, Tooltip, Legend } from '../../../src';
import { createContext, delay, gestureSimulator } from '../../util';

const data = [
{ type: 'a', genre: 'Sports', sold: 5 },
{ type: 'a', genre: 'Strategy', sold: 10 },
{ type: 'a', genre: 'Action', sold: 20 },
{ type: 'a', genre: 'Shooter', sold: 20 },
{ type: 'a', genre: 'Other', sold: 40 },
];

describe('alias', () => {
it('别名', async () => {
const context = createContext();
const { props } = (
<Canvas context={context} pixelRatio={1} animate={false}>
<Chart
data={data}
scale={{
sold: {
alias: '销量',
},
}}
>
<Axis field="genre" />
<Axis field="sold" />
<Interval x="genre" y="sold" color="genre" />
<Tooltip defaultItem={data[0]} />
</Chart>
</Canvas>
);

const canvas = new Canvas(props);
canvas.render();

await delay(500);
expect(context).toMatchImageSnapshot();
});
});

0 comments on commit 75eccf0

Please sign in to comment.