Skip to content

Commit 2e2e004

Browse files
committed
first commit - switchng recoil mode
1 parent 8699203 commit 2e2e004

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React, { Component, useEffect, useState } from 'react';
2+
import * as d3 from 'd3';
3+
4+
/**
5+
* @var colors: Colors array for the diffrerent node branches, each color is for a different branch
6+
*/
7+
const colors = [
8+
'#95B6B7',
9+
'#475485',
10+
'#519331',
11+
'#AA5039',
12+
'#8B2F5F',
13+
'#C5B738',
14+
'#858DFF',
15+
'#FF8D02',
16+
'#FFCD51',
17+
'#ACDAE6',
18+
'#FC997E',
19+
'#CF93AD',
20+
'#AA3939',
21+
'#AA6C39',
22+
'#226666',
23+
'#2C4870',
24+
];
25+
26+
const filterHooks = (data: any[]) => {
27+
if (data[0].children && data[0].state === 'stateless') {
28+
return filterHooks(data[0].children);
29+
}
30+
return JSON.stringify(data[0].state);
31+
};
32+
33+
interface HistoryProps {
34+
hierarchy: Record<string, unknown>;
35+
}
36+
37+
38+
/**
39+
* @method maked3Tree :Creates a new D3 Tree
40+
*/
41+
42+
function AtomsRelationship(props) {
43+
let { hierarchy } = props;
44+
let root = JSON.parse(JSON.stringify(hierarchy));
45+
let isRecoil = false;
46+
let HistoryRef = React.createRef(root); //React.createRef(root);
47+
48+
useEffect(() => {
49+
maked3Tree();
50+
}, [root]);
51+
52+
let removed3Tree = function () {
53+
const { current } = HistoryRef;
54+
while (current.hasChildNodes()) {
55+
current.removeChild(current.lastChild);
56+
}
57+
};
58+
59+
/**
60+
* @method maked3Tree Creates a new Tree History
61+
* @var
62+
*/
63+
let maked3Tree = function () {
64+
removed3Tree();
65+
};
66+
67+
return (
68+
<div className="history-d3-container">
69+
<div ref={HistoryRef} className="history-d3-div" />
70+
</div>
71+
);
72+
}
73+
74+
export default AtomsRelationship;

src/app/components/StateRoute.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
import Tree from './Tree';
1515
import ComponentMap from './ComponentMap';
1616
import PerfView from './PerfView';
17+
import AtomsRelationship from './AtomsRelationship'
18+
1719

1820
const History = require('./History').default;
1921

@@ -37,6 +39,7 @@ interface StateRouteProps {
3739

3840
const StateRoute = (props: StateRouteProps) => {
3941
const { snapshot, hierarchy, snapshots, viewIndex } = props;
42+
let isRecoil = snapshot.children[0].name === 'RecoilRoot';
4043
const [noRenderData, setNoRenderData] = useState(false);
4144
const [{ x, y, k }, setZoomState]: any = useState({
4245
x: 150,
@@ -52,6 +55,7 @@ const StateRoute = (props: StateRouteProps) => {
5255
return <div className="noState">{NO_STATE_MSG}</div>;
5356
};
5457

58+
5559
// the hierarchy gets set on the first click in the page
5660
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
5761
// if true involk render chart with hierarchy
@@ -62,6 +66,13 @@ const StateRoute = (props: StateRouteProps) => {
6266
return <div className="noState">{NO_STATE_MSG}</div>;
6367
};
6468

69+
const renderAtomsRelationship = () => {
70+
if (hierarchy) {
71+
return <AtomsRelationship hierarchy={hierarchy} />;
72+
}
73+
return <div className="noState">{NO_STATE_MSG}</div>;
74+
};
75+
6576
// the hierarchy gets set on the first click in the page
6677
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
6778
// if true involk render Tree with snapshot
@@ -129,7 +140,7 @@ const StateRoute = (props: StateRouteProps) => {
129140
</div>
130141
<Switch>
131142
<Route path="/map" render={renderComponentMap} />
132-
<Route path="/history" render={renderHistory} />
143+
<Route path="/history" render={isRecoil ? renderAtomsRelationship: renderHistory} />
133144
<Route path="/performance" render={renderPerfView} />
134145
<Route path="/" render={renderTree} />
135146
</Switch>

0 commit comments

Comments
 (0)