From 4099ed2b64b7814be01aaab967bc07c45295a372 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 10 Dec 2024 16:51:29 +0800 Subject: [PATCH] chore: dev env support switch case and print time spend --- packages/g6/__tests__/main.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/g6/__tests__/main.ts b/packages/g6/__tests__/main.ts index 896b1082be0..ebafd1c0fc6 100644 --- a/packages/g6/__tests__/main.ts +++ b/packages/g6/__tests__/main.ts @@ -52,6 +52,24 @@ 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) => { + const keys = Object.keys(demos); + 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 }; } @@ -74,6 +92,10 @@ 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, @@ -81,6 +103,10 @@ async function render() { 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);