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 Jan 3, 2025
1 parent 0c84e3c commit 0229915
Show file tree
Hide file tree
Showing 2 changed files with 25 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
26 changes: 24 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,26 @@ function initPanel() {
return { panel, Demo, Search, Renderer, GridLine, Theme, Animation, MultiLayers, reload };
}

function initStats() {
const container = document.getElementById('panel')!;
const stats = new Stats();
stats.showPanel(0);
const dom = stats.dom;
Object.assign(dom.style, { position: 'relative', top: 'unset', right: 'unset' });
container.appendChild(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 +111,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 0229915

Please sign in to comment.