-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 增加 gesture benchmark 测试页面 (#1824)
* feat: 增加benchmark * chore: site 的 benchmark 在 ios 9 报错 (#1827) * feat: 事件模拟支持到ios 9 * feat: 增加benchMark&修改father配置使用ts编译代码兼容 --------- Co-authored-by: 兵人 <[email protected]> Co-authored-by: zengyue ye <[email protected]>
- Loading branch information
1 parent
71e4c79
commit f00dac9
Showing
46 changed files
with
324,829 additions
and
19,676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<Canvas | ||
context={canvasEl.getContext('2d')} | ||
pixelRatio={window.devicePixelRatio} | ||
animate={false} | ||
> | ||
<Chart data={data}> | ||
<Axis field="rate" /> | ||
<Axis field="reportDate" type="timeCat" tickCount={5} /> | ||
<Line x="reportDate" y="rate" color="codeType" /> | ||
</Chart> | ||
</Canvas> | ||
); | ||
|
||
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<HTMLCanvasElement>(null); | ||
|
||
useEffect(() => { | ||
const canvasEl = canvasRef.current; | ||
if (!canvasEl) return; | ||
|
||
renderChart(F2, canvasEl); | ||
}, []); | ||
|
||
return ( | ||
<div style={{ paddingTop: '50px' }}> | ||
<h2>首次渲染</h2> | ||
<canvas ref={canvasRef} style={{ width: '100%', height: '260px' }} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import Stats from 'stats.js'; | ||
import { gestureSimulator, isTouchEvent } from '../utils'; | ||
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: HTMLCanvasElement) { | ||
const { Axis, Canvas, Chart, Line, ScrollBar } = F2; | ||
|
||
// 清空画布 | ||
canvasEl.width = 0; | ||
canvasEl.height = 0; | ||
|
||
function getProps(data) { | ||
const vNode = ( | ||
// @ts-ignore | ||
<Canvas | ||
context={canvasEl.getContext('2d')} | ||
pixelRatio={window.devicePixelRatio} | ||
animate={false} | ||
> | ||
<Chart data={data}> | ||
<Axis field="rate" /> | ||
<Axis field="reportDate" type="timeCat" tickCount={5} /> | ||
<Line x="reportDate" y="rate" color="codeType" /> | ||
<ScrollBar mode="x" range={[0, 0.2]} /> | ||
</Chart> | ||
</Canvas> | ||
); | ||
|
||
return vNode.props; | ||
} | ||
|
||
const props = getProps(data.data); | ||
// @ts-ignore | ||
const canvas = new Canvas(props); | ||
// @ts-ignore | ||
const gcanvas = canvas.canvas; | ||
gcanvas.isTouchEvent = isTouchEvent; | ||
canvas.render(); | ||
|
||
gcanvas.addEventListener('afterrender', () => { | ||
stats.update(); | ||
}); | ||
|
||
let i = 0; | ||
const loopTouchmove = () => { | ||
i++; | ||
gestureSimulator(canvasEl, 'touchmove', { | ||
x: i, | ||
y: 35, | ||
}); | ||
if (i >= canvasEl.width / 2) i = 0; | ||
window.requestAnimationFrame(loopTouchmove); | ||
}; | ||
|
||
setTimeout(async () => { | ||
gestureSimulator(canvasEl, 'touchstart', { x: 350, y: 35 }); | ||
loopTouchmove(); | ||
}); | ||
|
||
return canvas; | ||
} | ||
|
||
export default ({ F2 }) => { | ||
const canvasRef = useRef<HTMLCanvasElement>(null); | ||
|
||
useEffect(() => { | ||
const canvasEl = canvasRef.current; | ||
if (!canvasEl) return; | ||
|
||
renderChart(F2, canvasEl); | ||
}, []); | ||
|
||
return ( | ||
<div style={{ paddingTop: '50px' }}> | ||
<h2>Pan</h2> | ||
<canvas ref={canvasRef} style={{ width: '100%', height: '260px' }} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import Stats from 'stats.js'; | ||
import { gestureSimulator, isTouchEvent } from '../utils'; | ||
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: HTMLCanvasElement) { | ||
const { Axis, Canvas, Chart, Line, ScrollBar } = F2; | ||
|
||
// 清空画布 | ||
canvasEl.width = 0; | ||
canvasEl.height = 0; | ||
|
||
function getProps(data) { | ||
const vNode = ( | ||
// @ts-ignore | ||
<Canvas | ||
context={canvasEl.getContext('2d')} | ||
pixelRatio={window.devicePixelRatio} | ||
animate={false} | ||
> | ||
<Chart data={data}> | ||
<Axis field="rate" /> | ||
<Axis field="reportDate" type="timeCat" tickCount={5} /> | ||
<Line x="reportDate" y="rate" color="codeType" /> | ||
<ScrollBar mode="x" range={[0, 0.7]} /> | ||
<ScrollBar mode="y" range={[0, 0.7]} /> | ||
</Chart> | ||
</Canvas> | ||
); | ||
|
||
return vNode.props; | ||
} | ||
|
||
const props = getProps(data.data); | ||
// @ts-ignore | ||
const canvas = new Canvas(props); | ||
// @ts-ignore | ||
const gcanvas = canvas.canvas; | ||
gcanvas.isTouchEvent = isTouchEvent; | ||
canvas.render(); | ||
|
||
gcanvas.addEventListener('afterrender', () => { | ||
stats.update(); | ||
}); | ||
|
||
let flag = false; | ||
const loopTouchmove = () => { | ||
if (flag) { | ||
gestureSimulator(canvasEl, 'touchmove', [ | ||
{ x: 114, y: 114 }, | ||
{ x: 186, y: 186 }, | ||
]); | ||
} else { | ||
gestureSimulator(canvasEl, 'touchmove', [ | ||
{ x: 50, y: 50 }, | ||
{ x: 260, y: 260 }, | ||
]); | ||
} | ||
flag = !flag; | ||
window.requestAnimationFrame(loopTouchmove); | ||
}; | ||
|
||
setTimeout(async () => { | ||
gestureSimulator(canvasEl, 'touchstart', [ | ||
{ x: 50, y: 50 }, | ||
{ x: 260, y: 260 }, | ||
]); | ||
loopTouchmove(); | ||
}); | ||
|
||
return canvas; | ||
} | ||
|
||
export default ({ F2 }) => { | ||
const canvasRef = useRef<HTMLCanvasElement>(null); | ||
|
||
useEffect(() => { | ||
const canvasEl = canvasRef.current; | ||
if (!canvasEl) return; | ||
|
||
renderChart(F2, canvasEl); | ||
}, []); | ||
|
||
return ( | ||
<div style={{ paddingTop: '50px' }}> | ||
<h2>Pinch</h2> | ||
<canvas ref={canvasRef} style={{ width: '100%', height: '260px' }} /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.