forked from codesinghanoop/react-native-d3-tree-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (94 loc) · 2.04 KB
/
index.js
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
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
View,
ScrollView,
Dimensions,
Animated
} from 'react-native';
import Svg,{ Circle, G, Path, Text, Rect } from 'react-native-svg'
import * as d3 from "d3";
import _ from 'lodash'
import { flatten } from './FlatNodes'
import { NodeCurves } from './ConstructCurves'
import { DeployNodes } from './DeployNodes'
import { SiblingCurves } from './SiblingCurves'
var {height, width} = Dimensions.get('window');
var margin = {
top: 10,
right: 10,
bottom: 10,
left: 10
},
curves,siblingpath,rectNodes
export default class AwesomeHierarchyGraph extends Component {
constructor (props) {
super(props);
this.state = {
scale: new Animated.Value(0)
}
this.animate = this.animate.bind(this);
}
componentDidMount() {
this.animate();
}
drawTree()
{
const { root, siblings } = this.props
var allNodes = flatten(root);
var tree = d3.layout.tree().size([1000, height]),
nodes = tree.nodes(root),
links = tree.links(nodes);
curves = NodeCurves(links)
siblingpath = SiblingCurves(siblings,allNodes)
rectNodes = DeployNodes(nodes)
}
animate() {
Animated.stagger(10,[
Animated.timing(this.state.scale,
{
toValue:1,
duration:5000
})
]).start(this.animate)
}
render() {
this.drawTree()
return (
<View>
<Animated.View style={{opacity: this.state.scale}}>
<ScrollView>
<ScrollView horizontal>
<Svg width={1000} height={1000}>
<G>
{ siblingpath }
{ rectNodes }
{ curves }
</G>
</Svg>
</ScrollView>
</ScrollView>
</Animated.View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});