Skip to content

Commit 69512b9

Browse files
committed
why is it not working?
1 parent 5195d5b commit 69512b9

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/app/components/Chart.jsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,32 @@ import * as d3 from 'd3';
44

55

66

7-
87
class Chart extends Component {
98
constructor(props){
109
super(props);
11-
console.log('constructor')
10+
this.state = {d3: {}}
1211
}
1312

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+
}
1816

1917
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());
2320
}
2421

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());
2727

28-
console.log(this.props.snapshot)
29-
this.removed3Tree();
30-
this.maked3Tree();
28+
}
3129
}
3230

3331

32+
3433
removed3Tree(){
3534
console.log('function removed3Tree')
3635

@@ -41,6 +40,7 @@ class Chart extends Component {
4140
}
4241

4342
maked3Tree(){
43+
this.removed3Tree();
4444
console.log('function maked3Tree')
4545

4646
var margin = {top: 20, right: 120, bottom: 20, left: 120},
@@ -64,7 +64,8 @@ class Chart extends Component {
6464
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
6565

6666

67-
root = JSON.parse(JSON.stringify(this.props.snapshot));
67+
// root = JSON.parse(JSON.stringify(this.props.snapshot));
68+
root = this.state.d3;
6869
root.x0 = height / 2;
6970
root.y0 = 0;
7071

@@ -203,12 +204,11 @@ class Chart extends Component {
203204

204205
render(){
205206
console.log('render')
206-
207+
var htmlElement = <div>hello</div>;
207208
// this.removed3Tree();
208209
// this.maked3Tree();
209210
return (
210211
<div ref="anchor" className={'d3Container'} width={'100%'}>
211-
212212
</div>
213213
)
214214
}

0 commit comments

Comments
 (0)