Skip to content

Commit

Permalink
fix: legend resize
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed Jan 2, 2024
1 parent 2aaa51f commit b29b612
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/f2/src/components/legend/withLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export default (View) => {
willUpdate(): void {
const items = this.getItems();
if (!items || !items.length) return;
this._init();
this.updateCoord();
}

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 44 additions & 1 deletion packages/f2/test/components/canvas/canvas.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { jsx } from '../../../src';
import { createContext, delay } from '../../util';
import { Canvas, Component, Chart, Interval } from '../../../src';
import { Canvas, Component, Chart, Interval, Legend } from '../../../src';

const context = createContext('', {
width: '300px',
height: '300px',
Expand All @@ -13,6 +14,25 @@ const data = [
{ type: 'a', genre: 'Shooter', sold: 20 },
{ type: 'a', genre: 'Other', sold: 40 },
];

const data2 = [
{ type: '增额终身寿', genre: 'Sports', sold: 5 },
{ type: '增额终身寿', genre: 'Strategy', sold: 10 },
{ type: '增额终身寿', genre: 'Action', sold: 20 },
{ type: '增额终身寿', genre: 'Shooter', sold: 20 },
{ type: '增额终身寿', genre: 'Other', sold: 40 },
{ type: '增额终身寿2.0', genre: 'Sports', sold: 3 },
{ type: '增额终身寿2.0', genre: 'Strategy', sold: 7 },
{ type: '增额终身寿2.0', genre: 'Action', sold: 16 },
{ type: '增额终身寿2.0', genre: 'Shooter', sold: 18 },
{ type: '增额终身寿2.0', genre: 'Other', sold: 37 },
{ type: '鑫相守增额寿', genre: 'Sports', sold: 2 },
{ type: '鑫相守增额寿', genre: 'Strategy', sold: 6 },
{ type: '鑫相守增额寿', genre: 'Action', sold: 16 },
{ type: '鑫相守增额寿', genre: 'Shooter', sold: 18 },
{ type: '鑫相守增额寿', genre: 'Other', sold: 32 },
];

class Test extends Component {
render() {
return (
Expand Down Expand Up @@ -76,4 +96,27 @@ describe('Canvas', () => {
await delay(1000);
expect(context).toMatchImageSnapshot();
});

it('chart resize legend', async () => {
const chartRef = { current: null };
const context = createContext('chart resize legend');
const width = 300;
const height = 300;
const { type, props } = (
<Canvas context={context} pixelRatio={1} animate={false} width={width} height={height}>
<Chart ref={chartRef} data={data2} coord={{ transposed: true }}>
<Interval x="genre" y="sold" color="type" adjust="dodge" />
<Legend></Legend>
</Chart>
</Canvas>
);

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

await delay(1000);
await canvas.resize(200, 200);
await delay(1000);
expect(context).toMatchImageSnapshot();
});
});

0 comments on commit b29b612

Please sign in to comment.