-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGraph1.js
More file actions
109 lines (93 loc) · 3.65 KB
/
Copy pathGraph1.js
File metadata and controls
109 lines (93 loc) · 3.65 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
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
import React, { PureComponent} from 'react' //createRef, useState, useEffect, useRef
import * as d3 from 'd3'
import Card from 'react-bootstrap/Card'
//import Row from 'react-bootstrap/Row'
//import Col from 'react-bootstrap/Col'
import Spinner from '../../Spinner'
import cachedData from './data'
import ForceTree from './ForceTree1'
const MOCK_DATA_MODE = true
export default class NetworkGraph extends PureComponent {
constructor(props) {
super(props)
this.state = {parsedResponse: null} // orientation: "td",
//this.containerRef = createRef()
}
render() {
return (
<Card style={{marginBottom:0}}>
<Card.Body>
{!this.state.parsedResponse ?
<Spinner/> :
//<ForceGraph2D
// ref={this.containerRef}
// graphData={this.state.parsedResponse}
// dagMode={this.state.orientation}
// dagLevelDistance={300}
// backgroundColor="#fff" //"#101020"
// linkColor={() => 'rgba(255,255,255,0.2)'}
// nodeRelSize={1}
// nodeId="path"
// nodeVal={node => 100 / (node.level + 1)}
// nodeLabel="path"
// nodeAutoColorBy="module"
// linkDirectionalParticles={2}
// linkDirectionalParticleWidth={2}
// d3VelocityDecay={0.3}
///>
//<ForceTree data={{ nodes, links }}/>
<ForceTree data={this.state.parsedResponse}/>
//<Row>
// <Col md={12}>
// <ForceTree data={this.state.parsedResponse}/>
// </Col>
//</Row>
}
</Card.Body>
</Card>
)
}
componentDidMount() {
console.log("DASHBOARD DID MOUNT")
if(MOCK_DATA_MODE){
this.fetchData()
} else {
this.setState({parsedResponse: cachedData})
//setTimeout(function(){
// this.setState({parsedResponse: cachedData})
//}.bind(this), 1000) // let you see the spinner
}
}
fetchData() {
// https://github.com/vasturiano/react-force-graph/blob/master/example/tree/index.html
const requestUrl = "https://raw.githubusercontent.com/vasturiano/react-force-graph/master/example/datasets/d3-dependencies.csv"
console.log("REQUEST URL:", requestUrl)
fetch(requestUrl)
.then(r => r.text())
.then(d3.csvParse)
.then(data => {
const nodes = [], links = []
data.forEach(({ size, path }) => {
const levels = path.split('/')
const level = levels.length - 1
const module = level > 0 ? levels[1] : null
const leaf = levels.pop()
const parent = levels.join('/')
const node = {
path,
leaf,
module,
size: +size || 20,
level
};
nodes.push(node)
if (parent) {
links.push({source: parent, target: path,
//targetNode: node
})
}
})
this.setState({parsedResponse: {nodes: nodes, links: links}})
})
}
}