-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
1.tsx
125 lines (111 loc) 路 2.65 KB
/
1.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React from 'react'
import { Graph, Cell, Point, Timing, Interp } from '@antv/x6'
import '../index.less'
export default class Example extends React.Component {
private container: HTMLDivElement
componentDidMount() {
const graph = new Graph({
container: this.container,
width: 650,
height: 400,
grid: 1,
})
const ball = graph.addNode({
type: 'circle',
x: -25,
y: 50,
width: 50,
height: 50,
attrs: {
label: {
text: 'ball',
fontSize: 20,
},
body: {
fill: '#FFFFFF',
},
},
})
ball.transition('rotation', 360, {
delay: 1000,
duration: 1000,
})
ball.transition('position/x', 550, {
delay: 1000,
duration: 1000,
timing: Timing.decorators.reverse(Timing.quad),
})
ball.transition('position/y', 350, {
delay: 1000,
duration: 1000,
timing: Timing.decorators.reverse(Timing.bounce),
})
ball.transition('attrs/body/fill', '#FFFF00', {
delay: 3000,
duration: 500,
interp: Interp.color,
})
ball.transition(
'attrs/label',
{ text: 'yellow ball', fontSize: 8 },
{
delay: 5000,
duration: 2000,
easing: 'easeInBounce',
interp: (
start: { text: String; fontSize: number },
end: { text: String; fontSize: number },
) => {
return function (time: number) {
return {
text: end.text.substr(0, Math.ceil(end.text.length * time)),
fontSize: start.fontSize + (end.fontSize - start.fontSize) * time,
}
}
},
},
)
const ufo = graph.addNode({
type: 'ellipse',
x: 400,
y: 50,
width: 35,
height: 20,
attrs: {
label: {
text: 'u.f.o.',
fontSize: 10,
},
body: {
fill: '#FFFFFF',
},
},
})
function fly(cell: Cell) {
cell.transition('position', 20, {
delay: 0,
duration: 5000,
interp: function (a: Point.PointLike, b: number) {
return function (t: number) {
return {
x: a.x + 10 * b * (Math.cos(t * 2 * Math.PI) - 1),
y: a.y - b * Math.sin(t * 2 * Math.PI),
}
}
},
})
}
fly(ufo)
ufo.on('transition:end', ({ cell }) => fly(cell))
}
refContainer = (container: HTMLDivElement) => {
this.container = container
}
render() {
return (
<div className="x6-graph-wrap">
<div ref={this.refContainer} className="x6-graph" />
</div>
)
}
}