Skip to content

Commit 9ef1f5c

Browse files
committed
successfully get data from the backend and show the chart in the front end
1 parent 2e2e004 commit 9ef1f5c

File tree

9 files changed

+375
-80
lines changed

9 files changed

+375
-80
lines changed

package-lock.json

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@
115115
"rc-tooltip": "^3.7.3",
116116
"react": "^16.13.1",
117117
"react-dom": "^16.13.1",
118+
"react-google-chart": "^0.1.2",
119+
"react-google-charts": "^3.0.15",
118120
"react-html-parser": "^2.0.2",
119121
"react-json-tree": "^0.11.2",
120122
"react-router-dom": "^5.2.0",
121123
"react-select": "^3.1.0",
122-
"recoil": "0.0.10"
124+
"recoil": "0.0.10",
125+
"sankey": "^2.0.2"
123126
}
124127
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
import React, { Component, useEffect, useState } from 'react';
2+
// import * as d3 from 'd3';
3+
// import {sankey} from 'sankey';
4+
import { Chart } from "react-google-charts";
5+
/**
6+
* @var colors: Colors array for the diffrerent node branches, each color is for a different branch
7+
*/
8+
const colors = [
9+
'#95B6B7',
10+
'#475485',
11+
'#519331',
12+
'#AA5039',
13+
'#8B2F5F',
14+
'#C5B738',
15+
'#858DFF',
16+
'#FF8D02',
17+
'#FFCD51',
18+
'#ACDAE6',
19+
'#FC997E',
20+
'#CF93AD',
21+
'#AA3939',
22+
'#AA6C39',
23+
'#226666',
24+
'#2C4870',
25+
];
26+
27+
// interface HistoryProps {
28+
// hierarchy: Record<string, unknown>;
29+
// }
30+
31+
const data = {
32+
nodes: [
33+
{
34+
name: 'atom 1',
35+
category: 1
36+
},
37+
{
38+
name: 'atom 2',
39+
category: 1
40+
},
41+
{
42+
name: 'atom 3',
43+
category: 1
44+
},
45+
{
46+
name: 'selector 1',
47+
category: 2
48+
},
49+
{
50+
name: 'selector 2',
51+
category: 2
52+
},
53+
{
54+
name: 'component 1',
55+
category: 3
56+
},
57+
{
58+
name: 'component 2',
59+
category: 3
60+
},
61+
{
62+
name: 'component 3',
63+
category: 3
64+
},
65+
],
66+
links: [
67+
{
68+
source: "atom 1",
69+
target: "select 1",
70+
value: 100
71+
},
72+
{
73+
source: "atom 1",
74+
target: "component 1",
75+
value: 100
76+
},
77+
{
78+
source: "atom 2",
79+
target: "component 2",
80+
value: 100
81+
},
82+
{
83+
source: "atom 2",
84+
target: "select 2",
85+
value: 100
86+
},
87+
{
88+
source: "atom 3",
89+
target: "component 3",
90+
value: 100
91+
},
92+
{
93+
source: "selector 2",
94+
target: "component 1",
95+
value: 100
96+
},
97+
{
98+
source: "selector 1",
99+
target: "component 1",
100+
value: 100
101+
},
102+
]
103+
104+
}
105+
106+
107+
108+
/**
109+
* @method maked3Tree :Creates a new D3 Tree
110+
*/
111+
112+
function AtomsRelationship(props) {
113+
// let { hierarchy } = props;
114+
// let root = JSON.parse(JSON.stringify(hierarchy));
115+
// let HistoryRef = React.createRef(root); //React.createRef(root);
116+
117+
useEffect(() => {
118+
maked3Tree();
119+
}, [root]);
120+
121+
let removed3Tree = function () {
122+
const { current } = HistoryRef;
123+
while (current.hasChildNodes()) {
124+
current.removeChild(current.lastChild);
125+
}
126+
};
127+
128+
/**
129+
* @method maked3Tree Creates a new Tree History
130+
* @var
131+
*/
132+
let maked3Tree = function () {
133+
// removed3Tree();
134+
// const dimension = {width: 800, height: 500};
135+
// const margin = {left: 10, right: 10, top:10, bottom:10};
136+
137+
// const svg = d3.select(HistoryRef.current)
138+
// .append('svg')
139+
// .attr('width', dimension.width)
140+
// .attr('height', dimension.height);
141+
142+
// const graph = svg.append('g')
143+
// .attr('width', dimension.width - margin.left - margin.right)
144+
// .attr('width', dimension.height - margin.top - margin.bottom);
145+
146+
// // const sankey = d3.sankey()
147+
// // .nodeWidth(36)
148+
// // .nodePadding(290)
149+
// // .size([dimension.width, dimension.height])
150+
// console.log(data);
151+
// let a = sankey.nodes(data.nodes).links(data.links).layout(1);
152+
// console.log(a);
153+
// console.log(d3);
154+
return 2
155+
};
156+
157+
return (
158+
<div className="history-d3-container">
159+
{/* <div ref={HistoryRef} className="history-d3-div" /> */}
160+
<Chart
161+
width={600}
162+
height={'300px'}
163+
chartType="Sankey"
164+
loader={<div>Loading Chart</div>}
165+
data={[
166+
['From', 'To', 'Weight'],
167+
['Brazil', 'Portugal', 5],
168+
['Brazil', 'France', 1],
169+
['Brazil', 'Spain', 1],
170+
['Brazil', 'England', 1],
171+
['Canada', 'Portugal', 1],
172+
['Canada', 'France', 5],
173+
['Canada', 'England', 1],
174+
['Mexico', 'Portugal', 1],
175+
['Mexico', 'France', 1],
176+
['Mexico', 'Spain', 5],
177+
['Mexico', 'England', 1],
178+
['USA', 'Portugal', 1],
179+
['USA', 'France', 1],
180+
['USA', 'Spain', 1],
181+
['USA', 'England', 5],
182+
['Portugal', 'Angola', 2],
183+
['Portugal', 'Senegal', 1],
184+
['Portugal', 'Morocco', 1],
185+
['Portugal', 'South Africa', 3],
186+
['France', 'Angola', 1],
187+
['France', 'Senegal', 3],
188+
['France', 'Mali', 3],
189+
['France', 'Morocco', 3],
190+
['France', 'South Africa', 1],
191+
['Spain', 'Senegal', 1],
192+
['Spain', 'Morocco', 3],
193+
['Spain', 'South Africa', 1],
194+
['England', 'Angola', 1],
195+
['England', 'Senegal', 1],
196+
['England', 'Morocco', 2],
197+
['England', 'South Africa', 7],
198+
['South Africa', 'China', 5],
199+
['South Africa', 'India', 1],
200+
['South Africa', 'Japan', 3],
201+
['Angola', 'China', 5],
202+
['Angola', 'India', 1],
203+
['Angola', 'Japan', 3],
204+
['Senegal', 'China', 5],
205+
['Senegal', 'India', 1],
206+
['Senegal', 'Japan', 3],
207+
['Mali', 'China', 5],
208+
['Mali', 'India', 1],
209+
['Mali', 'Japan', 3],
210+
['Morocco', 'China', 5],
211+
['Morocco', 'India', 1],
212+
['Morocco', 'Japan', 3],
213+
]}
214+
rootProps={{ 'data-testid': '2' }}
215+
/>
216+
</div>
217+
);
218+
}
219+
220+
export default AtomsRelationship;

0 commit comments

Comments
 (0)