@@ -4,33 +4,32 @@ import * as d3 from 'd3';
4
4
5
5
6
6
7
-
8
7
class Chart extends Component {
9
8
constructor ( props ) {
10
9
super ( props ) ;
11
- console . log ( 'constructor' )
10
+ this . state = { d3 : { } }
12
11
}
13
12
14
- // componentWillMount(){
15
- // const {snapshot} = this.props;
16
- // this.setState({ d3Tree: JSON.parse(JSON.stringify(snapshot))})
17
- // }
13
+ componentWillMount ( ) {
14
+ this . setState ( { d3 : JSON . parse ( JSON . stringify ( this . props . snapshot ) ) } ) ;
15
+ }
18
16
19
17
componentDidMount ( ) {
20
- console . log ( 'componentDidMount' )
21
- this . removed3Tree ( ) ;
22
- this . maked3Tree ( ) ;
18
+ console . log ( 'componentDidMount' , this . props . snapshot )
19
+ this . setState ( { d3 : JSON . parse ( JSON . stringify ( this . props . snapshot ) ) } , this . maked3Tree ( ) ) ;
23
20
}
24
21
25
- componentWillUpdate ( ) {
26
- console . log ( 'componentWillUpdate' )
22
+ componentDidUpdate ( prevProps ) {
23
+ if ( this . props . snapshot !== prevProps ) {
24
+ console . log ( 'componentWillUpdate' , this . props . snapshot )
25
+ // this.maked3Tree();
26
+ this . setState ( { d3 : JSON . parse ( JSON . stringify ( this . props . snapshot ) ) } , this . maked3Tree ( ) ) ;
27
27
28
- console . log ( this . props . snapshot )
29
- this . removed3Tree ( ) ;
30
- this . maked3Tree ( ) ;
28
+ }
31
29
}
32
30
33
31
32
+
34
33
removed3Tree ( ) {
35
34
console . log ( 'function removed3Tree' )
36
35
@@ -41,6 +40,7 @@ class Chart extends Component {
41
40
}
42
41
43
42
maked3Tree ( ) {
43
+ this . removed3Tree ( ) ;
44
44
console . log ( 'function maked3Tree' )
45
45
46
46
var margin = { top : 20 , right : 120 , bottom : 20 , left : 120 } ,
@@ -64,7 +64,8 @@ class Chart extends Component {
64
64
. attr ( "transform" , "translate(" + margin . left + "," + margin . top + ")" ) ;
65
65
66
66
67
- root = JSON . parse ( JSON . stringify ( this . props . snapshot ) ) ;
67
+ // root = JSON.parse(JSON.stringify(this.props.snapshot));
68
+ root = this . state . d3 ;
68
69
root . x0 = height / 2 ;
69
70
root . y0 = 0 ;
70
71
@@ -203,12 +204,11 @@ class Chart extends Component {
203
204
204
205
render ( ) {
205
206
console . log ( 'render' )
206
-
207
+ var htmlElement = < div > hello </ div > ;
207
208
// this.removed3Tree();
208
209
// this.maked3Tree();
209
210
return (
210
211
< div ref = "anchor" className = { 'd3Container' } width = { '100%' } >
211
-
212
212
</ div >
213
213
)
214
214
}
0 commit comments