Skip to content

Commit

Permalink
refactor: dev env add fps monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Dec 30, 2024
1 parent 0c84e3c commit 3288ed4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/jest": "^29.5.14",
"@types/jsdom": "^21.1.7",
"@types/node": "^20.17.10",
"@types/stats.js": "^0.17.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"chalk": "^4.1.2",
Expand Down
1 change: 1 addition & 0 deletions packages/g6/__tests__/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

<body style="font-family: Arial, Helvetica, sans-serif">
<div id="panel"></div>
<div id="stats"></div>
<div id="app"></div>
<script type="module" src="./main.ts"></script>
</body>
Expand Down
24 changes: 22 additions & 2 deletions packages/g6/__tests__/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CanvasEvent } from '@antv/g';
import { Canvas, ComboEvent, CommonEvent, EdgeEvent, NodeEvent } from '@antv/g6';
import type { Controller } from 'lil-gui';
import GUI from 'lil-gui';
import { ComboEvent, CommonEvent, EdgeEvent, NodeEvent } from '../src';
import Stats from 'stats.js';
import '../src/preset';
import * as demos from './demos';
import { createGraphCanvas } from './utils';
Expand Down Expand Up @@ -36,6 +38,7 @@ const params = ['Type', 'Demo', 'Renderer', 'GridLine', 'Theme', 'Animation'] as
syncParamsFromSearch();

const panels = initPanel();
const stats = initStats();

window.onload = render;

Expand Down Expand Up @@ -78,10 +81,24 @@ function initPanel() {
return { panel, Demo, Search, Renderer, GridLine, Theme, Animation, MultiLayers, reload };
}

function initStats() {
const container = document.getElementById('stats')!;
const stats = new Stats();
stats.showPanel(0);
container.appendChild(stats.dom);
return stats;
}

let canvas: Canvas | undefined;
const statsListener = () => stats.update();

async function render() {
syncParamsToSearch();
applyTheme();
destroyForm();
if (canvas) {
canvas.getLayer().removeEventListener(CanvasEvent.AFTER_RENDER, statsListener);
}

const $container = initContainer();

Expand All @@ -92,7 +109,10 @@ async function render() {

const canvasOptions = { enableMultiLayer: MultiLayers };

const canvas = createGraphCanvas($container, 500, 500, Renderer, canvasOptions);
canvas = createGraphCanvas($container, 500, 500, Renderer, canvasOptions);

canvas.getLayer().addEventListener(CanvasEvent.AFTER_RENDER, statsListener);

await canvas.ready;
const testCase = demos[Demo as keyof typeof demos];
if (!testCase) return;
Expand Down

0 comments on commit 3288ed4

Please sign in to comment.