Skip to content

Commit 84ca60d

Browse files
Merge pull request #12 from guizzettic/master
Additional Legend Component Functionality
2 parents ae91b39 + 59c5b23 commit 84ca60d

File tree

3 files changed

+60
-67
lines changed

3 files changed

+60
-67
lines changed

src/app/components/History.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ const filterHooks = (data: any[]) => {
3434
* @method maked3Tree :Creates a new D3 Tree
3535
*/
3636

37-
export default function History(props) {
37+
function History(props) {
3838
let { hierarchy } = props;
39-
console.log('hierarchy is', hierarchy);
4039
let root = JSON.parse(JSON.stringify(hierarchy));
4140
let isRecoil = false;
4241
let HistoryRef = React.createRef(root); //React.createRef(root);
@@ -251,9 +250,12 @@ export default function History(props) {
251250
return [(y = +y) * Math.cos((x -= Math.PI / 2)), y * Math.sin(x)];
252251
}
253252
};
253+
254254
return (
255255
<>
256256
<div ref={HistoryRef} className="history-d3-div" id="historyContainer" />
257257
</>
258258
);
259259
}
260+
261+
export default History;

src/app/components/StateRoute.tsx

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const StateRoute = (props: StateRouteProps) => {
5151
console.log(hierarchy)
5252

5353
const isRecoil = snapshot.atomsComponents ? true : false;
54-
5554
const [noRenderData, setNoRenderData] = useState(false);
5655

5756
// component map zoom state
@@ -72,7 +71,7 @@ const StateRoute = (props: StateRouteProps) => {
7271
</ParentSize>
7372
);
7473
}
75-
return <div className='noState'>{NO_STATE_MSG}</div>;
74+
return <div className="noState">{NO_STATE_MSG}</div>;
7675
};
7776

7877
// the hierarchy gets set on the first click in the page
@@ -91,7 +90,7 @@ const StateRoute = (props: StateRouteProps) => {
9190
</div>
9291
);
9392
}
94-
return <div className='noState'>{NO_STATE_MSG}</div>;
93+
return <div className="noState">{NO_STATE_MSG}</div>;
9594
};
9695

9796
const renderAtomsRelationship = () => (
@@ -102,10 +101,6 @@ const StateRoute = (props: StateRouteProps) => {
102101
height={height}
103102
snapshots={snapshots} />}
104103
</ParentSize>
105-
106-
// atomsComponents={snapshot.atomsComponents}
107-
// atomSelectors={snapshot.atomSelectors}
108-
// />
109104
);
110105

111106
// the hierarchy gets set on the first click in the page
@@ -115,7 +110,7 @@ const StateRoute = (props: StateRouteProps) => {
115110
if (hierarchy) {
116111
return <Tree snapshot={snapshot} />;
117112
}
118-
return <div className='noState'>{NO_STATE_MSG}</div>;
113+
return <div className="noState">{NO_STATE_MSG}</div>;
119114
};
120115

121116
const renderPerfView = () => {
@@ -139,55 +134,55 @@ const StateRoute = (props: StateRouteProps) => {
139134
// />
140135
);
141136
}
142-
return <div className='noState'>{NO_STATE_MSG}</div>;
137+
return <div className="noState">{NO_STATE_MSG}</div>;
143138
};
144139

145140
return (
146141
<Router>
147-
<div className='navbar'>
142+
<div className="navbar">
148143
<NavLink
149-
className='router-link'
150-
activeClassName='is-active'
144+
className="router-link"
145+
activeClassName="is-active"
151146
exact
152-
to='/'
147+
to="/"
153148
>
154149
Tree
155150
</NavLink>
156151
<NavLink
157-
className='router-link'
158-
activeClassName='is-active'
159-
to='/history'
152+
className="router-link"
153+
activeClassName="is-active"
154+
to="/history"
160155
>
161156
History
162157
</NavLink>
163-
<NavLink className='router-link' activeClassName='is-active' to='/map'>
158+
<NavLink className="router-link" activeClassName="is-active" to="/map">
164159
Map
165160
</NavLink>
166161

167162
{isRecoil && (
168163
<NavLink
169-
className='router-link'
170-
activeClassName='is-active'
171-
to='/relationship'
164+
className="router-link"
165+
activeClassName="is-active"
166+
to="/relationship"
172167
>
173168
AtomsRecoil
174169
</NavLink>
175170
)}
176171

177172
<NavLink
178-
className='router-link'
179-
activeClassName='is-active'
180-
to='/performance'
173+
className="router-link"
174+
activeClassName="is-active"
175+
to="/performance"
181176
>
182177
Performance
183178
</NavLink>
184179
</div>
185180
<Switch>
186-
<Route path='/map' render={renderComponentMap} />
187-
<Route path='/history' render={renderHistory} />
188-
<Route path='/relationship' render={renderAtomsRelationship} />
189-
<Route path='/performance' render={renderPerfView} />
190-
<Route path='/' render={renderTree} />
181+
<Route path="/map" render={renderComponentMap} />
182+
<Route path="/history" render={renderHistory} />
183+
<Route path="/relationship" render={renderAtomsRelationship} />
184+
<Route path="/performance" render={renderPerfView} />
185+
<Route path="/" render={renderTree} />
191186
</Switch>
192187
</Router>
193188
);

src/app/components/legend.tsx

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,48 @@ import { scaleOrdinal } from '@visx/scale';
33
import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend';
44

55
// implement algorithm to check snapshot history and their respective colors
6-
const ordinalColorScale = scaleOrdinal<number, string>({
7-
domain: [1.0, 2.0, 3.0, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2],
8-
// sync in with the snapshot color chosen in history tab already
9-
range: ['#66d981', '#71f5ef', '#4899f1', '#7d81f6'],
10-
});
116

127
const legendGlyphSize = 12;
138

149
export default function Legendary(props: any) {
1510
// { events = false }: { events?: boolean }) {
16-
const displayArray = (obj: {
17-
stateSnapshot: { children: any[] };
18-
name: number;
19-
branch: number;
20-
index: number;
21-
children?: [];
22-
}) => {
23-
if (
24-
obj.stateSnapshot.children.length > 0 &&
25-
obj.stateSnapshot.children[0] &&
26-
obj.stateSnapshot.children[0].state &&
27-
obj.stateSnapshot.children[0].name
28-
) {
29-
const newObj: Record<string, unknown> = {
30-
index: obj.index,
31-
displayName: `${obj.name}.${obj.branch}`,
32-
state: obj.stateSnapshot.children[0].state,
33-
componentName: obj.stateSnapshot.children[0].name,
34-
componentData:
35-
JSON.stringify(obj.stateSnapshot.children[0].componentData) === '{}'
36-
? ''
37-
: obj.stateSnapshot.children[0].componentData,
38-
};
39-
hierarchyArr.push(newObj);
40-
}
11+
12+
const { hierarchy } = props;
13+
14+
const getSnapshotIds = (obj, snapshotIds = []) => {
15+
snapshotIds.push(`${obj.name}.${obj.branch}`);
4116
if (obj.children) {
42-
obj.children.forEach((element) => {
43-
displayArray(element);
17+
obj.children.forEach((child) => {
18+
getSnapshotIds(child, snapshotIds);
4419
});
4520
}
21+
return snapshotIds;
4622
};
47-
// the hierarchy gets set on the first click in the page
48-
// when page in refreshed we may not have a hierarchy so we need to check if hierarchy was initialized
49-
// if true involk displayArray to display the hierarchy
50-
// if (hierarchy) displayArray(hierarchy);
51-
console.log('Inside Legendary, props is', props);
23+
24+
const snap = getSnapshotIds(hierarchy);
25+
26+
const ordinalColorScale = scaleOrdinal<number, string>({
27+
domain: snap,
28+
// sync in with the snapshot color chosen in history tab already
29+
range: [
30+
'#95B6B7',
31+
'#475485',
32+
'#519331',
33+
'#AA5039',
34+
'#8B2F5F',
35+
'#C5B738',
36+
'#858DFF',
37+
'#FF8D02',
38+
'#FFCD51',
39+
'#ACDAE6',
40+
'#FC997E',
41+
'#CF93AD',
42+
'#AA3939',
43+
'#AA6C39',
44+
'#226666',
45+
'#2C4870',
46+
],
47+
});
5248

5349
return (
5450
<div className="legends">

0 commit comments

Comments
 (0)