Skip to content

Commit

Permalink
chore: dev env support switch case and print time spend
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Dec 10, 2024
1 parent 586c942 commit 4438372
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/g6/__tests__/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ function initPanel() {
const Animation = panel.add(options, 'Animation').onChange(render);
const MultiLayers = panel.add(options, 'MultiLayers').onChange(render);
const reload = panel.add(options, 'Reload').onChange(render);

const goTo = (diff: number) => {
// @ts-expect-error private property
const keys = Demo._values;
const currentIndex = keys.indexOf(options.Demo);
const nextIndex = (currentIndex + diff + keys.length) % keys.length;
options.Demo = keys[nextIndex];
Demo.updateDisplay();
render();
};

globalThis.addEventListener('keydown', (e) => {
if (['ArrowRight', 'ArrowDown'].includes(e.key)) {
goTo(1);
} else if (['ArrowLeft', 'ArrowUp'].includes(e.key)) {
goTo(-1);
}
});

return { panel, Demo, Search, Renderer, GridLine, Theme, Animation, MultiLayers, reload };
}

Expand All @@ -74,13 +93,21 @@ async function render() {
const testCase = demos[Demo as keyof typeof demos];
if (!testCase) return;

performance.clearMarks();
performance.clearMeasures();
performance.mark('demo-start');

const graph = await testCase({
container: canvas,
animation: Animation,
theme: Theme,
canvas: canvasOptions,
});

performance.mark('demo-end');
performance.measure('demo', 'demo-start', 'demo-end');
console.log('Time:', performance.getEntriesByName('demo')[0].duration, 'ms');

Object.assign(window, { graph, __g_instances__: Object.values(graph.getCanvas().getLayers()) });

renderForm(panels.panel, testCase.form);
Expand Down

0 comments on commit 4438372

Please sign in to comment.