Skip to content

Commit 56f1c3a

Browse files
committed
fixes legend issue, now legend key on state change
1 parent 1d373e1 commit 56f1c3a

File tree

2 files changed

+60
-74
lines changed

2 files changed

+60
-74
lines changed

src/app/components/StateRoute.tsx

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import AtomsRelationship from './AtomsRelationship.jsx';
1818
import Example from './AtomsRelationship.jsx';
1919
import { ParentSize } from '@visx/responsive';
2020
import { Console } from 'console';
21-
<<<<<<< HEAD
2221
import Legendary from './legend';
23-
=======
24-
>>>>>>> staging
2522

2623
const History = require('./History').default;
2724

@@ -50,10 +47,6 @@ const StateRoute = (props: StateRouteProps) => {
5047
const { snapshot, hierarchy, snapshots, viewIndex } = props;
5148

5249
const isRecoil = snapshot.atomsComponents ? true : false;
53-
<<<<<<< HEAD
54-
=======
55-
56-
>>>>>>> staging
5750
const [noRenderData, setNoRenderData] = useState(false);
5851

5952
// component map zoom state
@@ -74,7 +67,7 @@ const StateRoute = (props: StateRouteProps) => {
7467
</ParentSize>
7568
);
7669
}
77-
return <div className='noState'>{NO_STATE_MSG}</div>;
70+
return <div className="noState">{NO_STATE_MSG}</div>;
7871
};
7972

8073
// the hierarchy gets set on the first click in the page
@@ -93,7 +86,7 @@ const StateRoute = (props: StateRouteProps) => {
9386
</div>
9487
);
9588
}
96-
return <div className='noState'>{NO_STATE_MSG}</div>;
89+
return <div className="noState">{NO_STATE_MSG}</div>;
9790
};
9891

9992
const renderAtomsRelationship = () => (
@@ -102,13 +95,6 @@ const StateRoute = (props: StateRouteProps) => {
10295
<Example width={width} height={height} snapshots={snapshots} />
10396
)}
10497
</ParentSize>
105-
<<<<<<< HEAD
106-
107-
// atomsComponents={snapshot.atomsComponents}
108-
// atomSelectors={snapshot.atomSelectors}
109-
// />
110-
=======
111-
>>>>>>> staging
11298
);
11399

114100
// the hierarchy gets set on the first click in the page
@@ -118,7 +104,7 @@ const StateRoute = (props: StateRouteProps) => {
118104
if (hierarchy) {
119105
return <Tree snapshot={snapshot} />;
120106
}
121-
return <div className='noState'>{NO_STATE_MSG}</div>;
107+
return <div className="noState">{NO_STATE_MSG}</div>;
122108
};
123109

124110
const renderPerfView = () => {
@@ -133,55 +119,55 @@ const StateRoute = (props: StateRouteProps) => {
133119
/>
134120
);
135121
}
136-
return <div className='noState'>{NO_STATE_MSG}</div>;
122+
return <div className="noState">{NO_STATE_MSG}</div>;
137123
};
138124

139125
return (
140126
<Router>
141-
<div className='navbar'>
127+
<div className="navbar">
142128
<NavLink
143-
className='router-link'
144-
activeClassName='is-active'
129+
className="router-link"
130+
activeClassName="is-active"
145131
exact
146-
to='/'
132+
to="/"
147133
>
148134
Tree
149135
</NavLink>
150136
<NavLink
151-
className='router-link'
152-
activeClassName='is-active'
153-
to='/history'
137+
className="router-link"
138+
activeClassName="is-active"
139+
to="/history"
154140
>
155141
History
156142
</NavLink>
157-
<NavLink className='router-link' activeClassName='is-active' to='/map'>
143+
<NavLink className="router-link" activeClassName="is-active" to="/map">
158144
Map
159145
</NavLink>
160146

161147
{isRecoil && (
162148
<NavLink
163-
className='router-link'
164-
activeClassName='is-active'
165-
to='/relationship'
149+
className="router-link"
150+
activeClassName="is-active"
151+
to="/relationship"
166152
>
167153
AtomsRecoil
168154
</NavLink>
169155
)}
170156

171157
<NavLink
172-
className='router-link'
173-
activeClassName='is-active'
174-
to='/performance'
158+
className="router-link"
159+
activeClassName="is-active"
160+
to="/performance"
175161
>
176162
Performance
177163
</NavLink>
178164
</div>
179165
<Switch>
180-
<Route path='/map' render={renderComponentMap} />
181-
<Route path='/history' render={renderHistory} />
182-
<Route path='/relationship' render={renderAtomsRelationship} />
183-
<Route path='/performance' render={renderPerfView} />
184-
<Route path='/' render={renderTree} />
166+
<Route path="/map" render={renderComponentMap} />
167+
<Route path="/history" render={renderHistory} />
168+
<Route path="/relationship" render={renderAtomsRelationship} />
169+
<Route path="/performance" render={renderPerfView} />
170+
<Route path="/" render={renderTree} />
185171
</Switch>
186172
</Router>
187173
);

src/app/components/legend.tsx

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@ 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+
console.log('successfully invoke Legendary function call');
13+
const { hierarchy } = props;
14+
console.log('and hierarchy being passed in is', hierarchy);
15+
16+
const getSnapshotIds = (obj, snapshotIds = []) => {
17+
console.log('obj.name is', obj.name);
18+
snapshotIds.push(`${obj.name}.${obj.branch}`);
4119
if (obj.children) {
42-
obj.children.forEach((element) => {
43-
displayArray(element);
20+
obj.children.forEach((child) => {
21+
getSnapshotIds(child, snapshotIds);
4422
});
4523
}
24+
return snapshotIds;
4625
};
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);
26+
27+
const snap = getSnapshotIds(hierarchy);
28+
console.log('passing hierarchy as an object to getSnapshotIds is -->', snap);
29+
30+
const ordinalColorScale = scaleOrdinal<number, string>({
31+
domain: snap,
32+
// sync in with the snapshot color chosen in history tab already
33+
range: [
34+
'#95B6B7',
35+
'#475485',
36+
'#519331',
37+
'#AA5039',
38+
'#8B2F5F',
39+
'#C5B738',
40+
'#858DFF',
41+
'#FF8D02',
42+
'#FFCD51',
43+
'#ACDAE6',
44+
'#FC997E',
45+
'#CF93AD',
46+
'#AA3939',
47+
'#AA6C39',
48+
'#226666',
49+
'#2C4870',
50+
],
51+
});
5252

5353
return (
5454
<div className="legends">

0 commit comments

Comments
 (0)