Skip to content

Commit

Permalink
fix(legend): update legend item (#5258)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored Jun 30, 2023
1 parent 237d463 commit 48873ba
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
23 changes: 23 additions & 0 deletions __tests__/integration/api-chart-change-data-legend.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { chartChangeDataLegend as render } from '../plots/api/chart-change-data-legend';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
import { sleep } from './utils/sleep';
import './utils/useSnapshotMatchers';

describe('chart.changeData', () => {
const canvas = createNodeGCanvas(640, 480);

it('mark.changeSize(width, height) should rerender expected chart', async () => {
const { finished } = render({
canvas,
container: document.createElement('div'),
});
await finished;
const dir = `${__dirname}/snapshots/api`;
await sleep(20);
await expect(canvas).toMatchCanvasSnapshot(dir, render.name);
});

afterAll(() => {
canvas?.destroy();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/api/markChangeData.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions __tests__/plots/api/chart-change-data-legend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Chart } from '../../../src';

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

const chart = new Chart({
theme: 'classic',
container,
canvas,
});

const data = [
{ time: '10:10', call: 4, waiting: 2, people: 2, type: 'a' },
{ time: '10:10', call: 2, waiting: 6, people: 3, type: 'b' },
{ time: '10:20', call: 13, waiting: 2, people: 5, type: 'a' },
{ time: '10:20', call: 9, waiting: 9, people: 1, type: 'b' },
{ time: '10:30', call: 5, waiting: 2, people: 3, type: 'a' },
{ time: '10:30', call: 8, waiting: 5, people: 1, type: 'b' },
{ time: '10:40', call: 13, waiting: 1, people: 2, type: 'a' },
{ time: '10:40', call: 13, waiting: 3, people: 2, type: 'b' },
];

chart.options({
theme: 'classic',
type: 'interval',
data,
encode: {
x: 'time',
y: 'waiting',
color: 'type',
},
transform: [{ type: 'dodgeX' }],
labels: [{ text: 'type' }],
});

const finished = chart
.render()
.then((chart) =>
chart.changeData(data.sort((x, y) => (x.type > y.type ? -1 : 1))),
);

return { chart, finished };
}
1 change: 1 addition & 0 deletions __tests__/plots/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export { chartEmitScrollbarFilter } from './chart-emit-scrollbar-filter';
export { chartOptionsCompositeMark } from './chart-options-composite-mark';
export { chartEmitItemTooltipHideContent } from './chart-emit-item-tooltip-hide-content';
export { chartEmitClickTooltip } from './chart-emit-click-tooltip';
export { chartChangeDataLegend } from './chart-change-data-legend';

0 comments on commit 48873ba

Please sign in to comment.