11
22// adapted from source: https://github.com/vasturiano/react-force-graph/blob/master/example/tree/index.html
3+ // https://github.com/vasturiano/react-force-graph#data-input
34
45import React , { PureComponent , useEffect , useRef } from 'react'
56import { ForceGraph2D } from 'react-force-graph'
@@ -12,6 +13,26 @@ import Spinner from '../../Spinner'
1213import cachedData from './data'
1314
1415const ForceTree = ( { data } ) => {
16+
17+ data [ "nodes" ] = data [ "nodes" ] . map ( function ( node ) {
18+ return {
19+ "id" : node [ "id" ] , // NODE ID
20+ "mean_opinion" : node [ "opinion" ] ,
21+ "status_count" : node [ "Rate" ] ,
22+ "color" : node [ "color" ] , // NODE COLOR
23+ //"x": node["xcoord"],
24+ //"y": node["ycoord"],
25+ }
26+ } )
27+
28+ data [ "links" ] = data [ "links" ] . map ( function ( link ) {
29+ return {
30+ "source" : link [ "source" ] , // SOURCE NODE ID
31+ "target" : link [ "target" ] , // TARGET NODE ID
32+ //"weight": link["weight"],
33+ }
34+ } )
35+
1536 const containerRef = useRef ( )
1637 useEffect ( ( ) => {
1738 // add collision force
@@ -21,18 +42,17 @@ const ForceTree = ({ data }) => {
2142 } , [ ] )
2243 //console.log("GRAPH DATA", data)
2344
24- return < ForceGraph2D ref = { containerRef } width = { 900 } height = { 550 }
45+ return < ForceGraph2D ref = { containerRef } width = { 900 } height = { 500 } backgroundColor = "#101020"
2546 graphData = { data }
47+
2648 nodeId = "id"
27- nodeVal = { node => Math . sqrt ( 50 ) }
28- nodeLabel = "Name"
29- nodeAutoColorBy = "color"
49+ nodeVal = "status_count"
50+ nodeLabel = { ( node ) => `@ ${ node [ "id" ] } ` }
51+ nodeRelSize = { 1 }
3052
31- dagMode = "td"
32- dagLevelDistance = { 300 }
33- backgroundColor = "#101020"
53+ //dagMode="td"
54+ //dagLevelDistance={300}
3455 linkColor = { ( ) => 'rgba(255,255,255,0.2)' }
35- nodeRelSize = { 1 }
3656 linkDirectionalParticles = { 2 }
3757 linkDirectionalParticleWidth = { 2 }
3858 d3VelocityDecay = { 0.3 }
@@ -60,10 +80,11 @@ export default class NetworkGraph extends PureComponent {
6080
6181 componentDidMount ( ) {
6282 console . log ( "DASHBOARD DID MOUNT" )
63- this . fetchData ( ) // temporary for dev
64- setTimeout ( function ( ) {
65- this . setState ( { parsedResponse : cachedData } )
66- } . bind ( this ) , 800 ) // let you see the spinner
83+ //this.fetchData() // temporary for dev
84+ //setTimeout(function(){
85+ // this.setState({parsedResponse: cachedData})
86+ //}.bind(this), 800) // let you see the spinner
87+ this . setState ( { parsedResponse : cachedData } )
6788 }
6889
6990 fetchData ( ) {
0 commit comments