Skip to content

Commit d1ba94b

Browse files
committed
rename third array property in link fiber, add styling to AtomsRelationships
1 parent f91d538 commit d1ba94b

File tree

2 files changed

+35
-206
lines changed

2 files changed

+35
-206
lines changed

src/app/components/AtomsRelationship.jsx

Lines changed: 32 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -1,219 +1,48 @@
11
import React, { Component, useEffect, useState } from 'react';
22
// import * as d3 from 'd3';
33
// 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-
4+
import { Chart } from 'react-google-charts';
1075

1086
/**
1097
* @method maked3Tree :Creates a new D3 Tree
1108
*/
1119

11210
function AtomsRelationship(props) {
113-
// let { hierarchy } = props;
114-
// let root = JSON.parse(JSON.stringify(hierarchy));
115-
// let HistoryRef = React.createRef(root); //React.createRef(root);
11611
console.log('Props', props.atomsRel);
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-
};
15612

15713
return (
15814
<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-
...props.atomsRel
168-
// ['Brazil', 'Portugal', 5],
169-
// ['Brazil', 'France', 1],
170-
// ['Brazil', 'Spain', 1],
171-
// ['Brazil', 'England', 1],
172-
// ['Canada', 'Portugal', 1],
173-
// ['Canada', 'France', 5],
174-
// ['Canada', 'England', 1],
175-
// ['Mexico', 'Portugal', 1],
176-
// ['Mexico', 'France', 1],
177-
// ['Mexico', 'Spain', 5],
178-
// ['Mexico', 'England', 1],
179-
// ['USA', 'Portugal', 1],
180-
// ['USA', 'France', 1],
181-
// ['USA', 'Spain', 1],
182-
// ['USA', 'England', 5],
183-
// ['Portugal', 'Angola', 2],
184-
// ['Portugal', 'Senegal', 1],
185-
// ['Portugal', 'Morocco', 1],
186-
// ['Portugal', 'South Africa', 3],
187-
// ['France', 'Angola', 1],
188-
// ['France', 'Senegal', 3],
189-
// ['France', 'Mali', 3],
190-
// ['France', 'Morocco', 3],
191-
// ['France', 'South Africa', 1],
192-
// ['Spain', 'Senegal', 1],
193-
// ['Spain', 'Morocco', 3],
194-
// ['Spain', 'South Africa', 1],
195-
// ['England', 'Angola', 1],
196-
// ['England', 'Senegal', 1],
197-
// ['England', 'Morocco', 2],
198-
// ['England', 'South Africa', 7],
199-
// ['South Africa', 'China', 5],
200-
// ['South Africa', 'India', 1],
201-
// ['South Africa', 'Japan', 3],
202-
// ['Angola', 'China', 5],
203-
// ['Angola', 'India', 1],
204-
// ['Angola', 'Japan', 3],
205-
// ['Senegal', 'China', 5],
206-
// ['Senegal', 'India', 1],
207-
// ['Senegal', 'Japan', 3],
208-
// ['Mali', 'China', 5],
209-
// ['Mali', 'India', 1],
210-
// ['Mali', 'Japan', 3],
211-
// ['Morocco', 'China', 5],
212-
// ['Morocco', 'India', 1],
213-
// ['Morocco', 'Japan', 3],
214-
]}
215-
rootProps={{ 'data-testid': '2' }}
216-
/>
15+
<Chart
16+
width={'100%'}
17+
height={'100%'}
18+
chartType="Sankey"
19+
options={{
20+
sankey: {
21+
link: { color: { fill: '#c6e6f', fillOpacity: 0.1 } },
22+
node: {
23+
colors: [
24+
'#4a91c7',
25+
'#5b9bce',
26+
'#6ba6d5',
27+
'#7bb0dc',
28+
'#8abbe3',
29+
'#99c6ea',
30+
'#a8d0f1',
31+
'#b7dbf8',
32+
'#c6e6ff',
33+
'#46edf2',
34+
'#95B6B7',
35+
],
36+
label: { color: '#fff', fontSize: '14' },
37+
nodePadding: 50,
38+
width: 15,
39+
},
40+
},
41+
}}
42+
loader={<div>Loading Chart</div>}
43+
data={[['Atom', 'Selector', ''], ...props.atomsRel]}
44+
rootProps={{ 'data-testid': '1' }}
45+
/>
21746
</div>
21847
);
21948
}

src/backend/linkFiber.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function getRecoilState() : any {
7272
nodeToNodeSubsKeys.forEach(
7373
node => {
7474
nodeToNodeSubs.get(node).forEach(
75-
nodeSubs => allAtomsRelationship.push([node, nodeSubs, 2])
75+
nodeSubs => allAtomsRelationship.push([node, nodeSubs, 1])
7676
)
7777
}
7878
)
@@ -186,13 +186,13 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
186186
if (pointer?.memoizedState[1]?.[0].current) {
187187
let atomName = pointer.memoizedState[1]?.[0].current.keys().next().value;
188188
console.log('atom', pointer.memoizedState[1]?.[0].current.keys().next().value);
189-
allAtomsRelationship.push([atomName, elementType?.name, 2])
189+
allAtomsRelationship.push([atomName, elementType?.name, 1])
190190
}
191191

192192
if (pointer?.memoizedState[1]?.[0].key) {
193193
let atomName = pointer.memoizedState[1]?.[0].key;
194194
console.log('atom', pointer.memoizedState[1]?.[0].key);
195-
allAtomsRelationship.push([atomName, elementType?.name, 2])
195+
allAtomsRelationship.push([atomName, elementType?.name, 1])
196196
}
197197
}
198198

0 commit comments

Comments
 (0)