From 046ea5fd230d87aacdb4ca26695f076a295ac77f Mon Sep 17 00:00:00 2001 From: MiniPear Date: Tue, 5 Dec 2023 11:22:42 +0800 Subject: [PATCH] fix: ci and bench (#5880) --- scripts/bench/chart.ts | 41 ++++++++++--------- .../chart/point-temperatures/g2-v4-canvas.ts | 2 + .../point-temperatures/g2-v5-canvas-spec.ts | 7 ++-- src/runtime/library.ts | 9 ++-- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/scripts/bench/chart.ts b/scripts/bench/chart.ts index 8089e0ee32..b9c6e7c1c6 100644 --- a/scripts/bench/chart.ts +++ b/scripts/bench/chart.ts @@ -1,4 +1,4 @@ -import { render } from '@antv/g2v5'; +import { render, stdlib } from '@antv/g2v5'; import { html } from 'htl'; import * as _cases from './tests/chart'; @@ -162,14 +162,14 @@ async function launch(container: HTMLDivElement) { end: (node: any) => { const result = performance.measure(key, key); results.push(result); - renderPrefResultEach(container, node, key, result, false); + renderPrefResultEach(container, node, key, result, true); resolve(); }, }); }); } - renderPreResultAll(container, results); + // renderPreResultAll(container, results); renderReportUpload(container, results); @@ -212,26 +212,29 @@ function renderPreResultAll( const dashboard = document.createElement('div'); dashboard.id = id; container.appendChild(dashboard); - const node = render({ - type: 'interval', - width: 1000, - data: results, - encode: { x: 'name', y: 'duration' }, - style: { fill: 'black' }, - transform: [{ type: 'sortX', by: 'y', reverse: true }], - scale: { - y: { nice: true }, + const node = render( + { + type: 'interval', + width: 1000, + data: results, + encode: { x: 'name', y: 'duration' }, + style: { fill: 'black' }, + transform: [{ type: 'sortX', by: 'y', reverse: true }], + scale: { + y: { nice: true }, + }, + axis: { + x: { labelAutoRotate: false, title: 'library + env' }, + y: { title: 'duration(ms)' }, + }, + labels: [{ text: 'duration', position: 'inside', formatter: '.1f' }], }, - axis: { - x: { labelAutoRotate: false, title: 'library + env' }, - y: { title: 'duration(ms)' }, - }, - labels: [{ text: 'duration', position: 'inside', formatter: '.1f' }], - }); + { library: stdlib() }, + ); dashboard.appendChild(node); } -function clearNodes(className: string = 'chart') { +function clearNodes(className = 'chart') { const charts = document.getElementsByClassName(className); Array.from(charts).forEach((d) => d.remove()); } diff --git a/scripts/bench/tests/chart/point-temperatures/g2-v4-canvas.ts b/scripts/bench/tests/chart/point-temperatures/g2-v4-canvas.ts index adc8441eb2..4034eeaa9e 100644 --- a/scripts/bench/tests/chart/point-temperatures/g2-v4-canvas.ts +++ b/scripts/bench/tests/chart/point-temperatures/g2-v4-canvas.ts @@ -14,6 +14,8 @@ export const g2V4Canvas: ChartType = (data, { start, end }) => { chart.point().position('date*value').style({ stroke: 'black' }); + chart.animate(false); + chart.render(); end(node); diff --git a/scripts/bench/tests/chart/point-temperatures/g2-v5-canvas-spec.ts b/scripts/bench/tests/chart/point-temperatures/g2-v5-canvas-spec.ts index 0aad995753..a18a6ca852 100644 --- a/scripts/bench/tests/chart/point-temperatures/g2-v5-canvas-spec.ts +++ b/scripts/bench/tests/chart/point-temperatures/g2-v5-canvas-spec.ts @@ -1,10 +1,9 @@ -import { render } from '@antv/g2v5'; +import { render, stdlib } from '@antv/g2v5'; import type { Chart } from '../types'; export const g2V5CanvasSpec: Chart = (data, { start, end }) => { - let node: HTMLElement; start(); - node = render( + const node = render( { type: 'point', data, @@ -18,7 +17,7 @@ export const g2V5CanvasSpec: Chart = (data, { start, end }) => { }, animate: false, }, - undefined, + { library: stdlib() }, () => end(node), ); }; diff --git a/src/runtime/library.ts b/src/runtime/library.ts index d97ffffe1b..6854ecef53 100644 --- a/src/runtime/library.ts +++ b/src/runtime/library.ts @@ -15,7 +15,7 @@ export function useLibrary< >( namespace: G2ComponentNamespaces, publicLibrary: G2Library, -): [(options: O, context?: G2Context) => V, (type: O['type']) => C] { +): [(options: O, context?) => V, (type: O['type']) => C] { const library = { ...builtinlib(), ...publicLibrary }; const create = (type: O['type']) => { @@ -24,12 +24,9 @@ export function useLibrary< return library[key] || error(`Unknown Component: ${key}`); }; - const use = (options: O, context?: G2Context) => { + const use = (options: O, context?) => { const { type, ...rest } = options; - if (!type) { - error(`Plot type is required!`); - } - + if (!type) error(`Plot type is required!`); const currentLibrary = create(type); return currentLibrary?.(rest, context); };