diff --git a/packages/f2/.fatherrc.js b/packages/f2/.fatherrc.js index 3e088a2d4..34b9cbb08 100644 --- a/packages/f2/.fatherrc.js +++ b/packages/f2/.fatherrc.js @@ -20,5 +20,12 @@ export default process.env.CI && process.env.CI === 'true' // umd: { name: 'F2JSXRuntime', file: 'jsx-runtime' }, // }, }, + typescriptOpts: { + tsconfigOverride: { + compilerOptions: { + target: 'es5', + }, + }, + }, extraRollupPlugins: [...(isBundleVis ? [visualizer()] : [])], }; diff --git a/site/.dumi/components/FirstRender.tsx b/site/.dumi/components/FirstRender.tsx new file mode 100644 index 000000000..4ce9e0d63 --- /dev/null +++ b/site/.dumi/components/FirstRender.tsx @@ -0,0 +1,69 @@ +import React, { useEffect, useRef } from 'react'; +import Stats from 'stats.js'; +import data from './data.json'; + +// @ts-ignore +const stats = new Stats(); +stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom +// const $stats = stats.dom; +// $stats.style.position = 'relative'; +// $stats.style.left = '0px'; +// $stats.style.top = '0px'; + +document.body.insertBefore(stats.dom, document.body.firstChild); + +function renderChart(F2, canvasEl) { + const { Axis, Canvas, Chart, Line } = F2; + // 清空画布 + // canvasEl.width = 0; + // canvasEl.height = 0; + + function getProps(data) { + const vNode = ( + // @ts-ignore + + + + + + + + ); + + return vNode.props; + } + + const props = getProps(data.data); + // @ts-ignore + const canvas = new Canvas(props); + canvas.render(); + stats.update(); + + window.requestAnimationFrame(() => renderChart(F2, canvasEl)); +} + +export default (props) => { + const { F2 } = props; + + if (!F2) return null; + + const canvasRef = useRef(null); + + useEffect(() => { + const canvasEl = canvasRef.current; + if (!canvasEl) return; + + renderChart(F2, canvasEl); + }, []); + + return ( +
+

首次渲染

+ +
+ ); +}; diff --git a/site/.dumi/pages/benchmark/5/index.tsx b/site/.dumi/components/MultiRender.tsx similarity index 85% rename from site/.dumi/pages/benchmark/5/index.tsx rename to site/.dumi/components/MultiRender.tsx index 99a9be2b8..2b165ad65 100644 --- a/site/.dumi/pages/benchmark/5/index.tsx +++ b/site/.dumi/components/MultiRender.tsx @@ -1,10 +1,9 @@ -import React, { useRef, useState } from 'react'; -import Stats from 'stats.js'; -import { Canvas, Chart, Axis, Line } from '@antv/f2'; import { Renderer as CanvasRenderer } from '@antv/g-mobile-canvas'; import { Renderer as SVGRenderer } from '@antv/g-mobile-svg'; import { Renderer as WebGLRenderer } from '@antv/g-mobile-webgl'; -import data from '../data.json'; +import React, { useRef, useState } from 'react'; +import Stats from 'stats.js'; +import data from './data.json'; // @ts-ignore const stats = new Stats(); @@ -16,7 +15,8 @@ stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom document.body.insertBefore(stats.dom, document.body.firstChild); -function renderChart(options) { +function renderChart(F2, options) { + const { Canvas, Chart, Axis, Line } = F2; function getProps(data) { const { props } = ( // @ts-ignore @@ -49,8 +49,10 @@ function renderChart(options) { return canvas; } -export default () => { - const [canvasInstance, setCanvas] = useState(null); +export default ({ F2 }) => { + if (!F2) return null; + const { Canvas } = F2; + const [canvasInstance, setCanvas] = useState(null); const containerRef = useRef(null); const selectRef = useRef(null); @@ -65,14 +67,17 @@ export default () => { canvasEl.style.height = '100%'; container.appendChild(canvasEl); const canvasRenderer = new CanvasRenderer(); - const canvas = renderChart({ renderer: canvasRenderer, context: canvasEl.getContext('2d') }); + const canvas = renderChart(F2, { + renderer: canvasRenderer, + context: canvasEl.getContext('2d'), + }); setCanvas(canvas); return; } if (value === 'svg') { const svgRenderer = new SVGRenderer(); const { width, height } = container.getBoundingClientRect(); - const canvas = renderChart({ renderer: svgRenderer, container, width, height }); + const canvas = renderChart(F2, { renderer: svgRenderer, container, width, height }); setCanvas(canvas); return; } @@ -82,7 +87,7 @@ export default () => { canvasEl.style.width = '100%'; canvasEl.style.height = '100%'; container.appendChild(canvasEl); - const canvas = renderChart({ + const canvas = renderChart(F2, { renderer: webglRenderer, context: canvasEl.getContext('webgl'), }); @@ -103,7 +108,7 @@ export default () => { return (
-

F2 5.x

+

二次渲染