forked from TamimEhsan/AlgorithmVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvertexOriginal.jsx
More file actions
76 lines (70 loc) · 2.07 KB
/
vertexOriginal.jsx
File metadata and controls
76 lines (70 loc) · 2.07 KB
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
import React, {Component} from 'react';
class Vertex extends Component {
constructor() {
super();
this.state = {
prevPoss:{
x:0,
y:0
},
poss:{
x:0,
y:0,
xx:0,
yy:0
},
prevX:0
}
}
componentDidUpdate(prevProps) {
if (this.state.poss.x !== this.props.pos.x) {
let pp = this.state.poss;
pp.xx = pp.x;
pp.yy = pp.y;
pp.x = this.props.pos.x;
pp.y = this.props.pos.y;
this.setState({poss:pp});
document.getElementById('vbanim').beginElement();
}
}
render() {
return (
<g>
<circle
cx={this.state.poss.x}
cy={this.state.poss.y}
r={this.props.radius}
stroke="black" stroke-width="1" fill="red"
>
{/*<animate*/}
{/* attributeName='r'*/}
{/* values='0;25;5;10'*/}
{/* dur='1s'*/}
{/* repeatCount="1"*/}
{/*/>*/}
<animate
id={'vbanim'}
attributeName='cx'
values={(this.state.poss.x-50)+';'+this.state.poss.x}
dur='2s'
repeatCount="1"
/>
</circle>
<text
style={{font:'5px sans-serif'}}
x={this.props.pos.x}
y={this.props.pos.y}
>
{this.props.label}
</text>
<rect width="10" height="10">
<animate attributeName="rx" values="0;5;0" dur="10s" repeatCount="2" />
</rect>
</g>
);
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default Vertex;