-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdev.tsx
59 lines (46 loc) · 1.28 KB
/
dev.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { useRef, useEffect, useCallback } from 'react'
import ReactDOM from 'react-dom'
import './dev.less'
import CRender, { GRAPHS } from './src/index'
function randomNum(start: number, end: number, fixed = 0): number {
const differ = end - start
const random = Math.random()
return +(start + differ * random).toFixed(fixed)
}
const Dev: React.FC = () => {
const canvas = useRef<HTMLCanvasElement>(null)
const renderTest = useCallback(async () => {
const render = new CRender(canvas.current!)
const [w, h] = render.area
const graph = new GRAPHS.Text({
animationCurve: 'easeOutElastic',
shape: {
content: 'top\nmiddle\nbottom',
position: [w / 2, h / 2],
},
hover: true,
drag: true,
style: {
stroke: 'black',
fontSize: 30,
fontWeight: 'normal',
textAlign: 'start',
textBaseline: 'top',
},
})
render.add(graph)
await graph.animation('shape', {
position: [100, 100],
})
await graph.animation('shape', {
position: [w / 2, h / 2],
})
render.delAllGraph()
}, [])
useEffect(() => {
renderTest()
}, [renderTest])
return <canvas ref={canvas} />
}
ReactDOM.render(<Dev />, document.getElementById('root'))
export default null