Skip to content

Commit e84b635

Browse files
committed
added initial legend functionality to ComponentMap
1 parent b9d588a commit e84b635

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

src/app/components/StateRoute.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,21 @@ const StateRoute = (props: StateRouteProps) => {
6161
const renderComponentMap = () => {
6262
if (hierarchy) {
6363
return (
64-
<ComponentMap
65-
viewIndex={viewIndex}
66-
snapshots={snapshots}
67-
x={x}
68-
y={y}
69-
k={k}
70-
setZoomState={setZoomState}
71-
/>
64+
<div>
65+
<div>
66+
<Legendary hierarchy={hierarchy} />
67+
</div>
68+
<div>
69+
<ComponentMap
70+
viewIndex={viewIndex}
71+
snapshots={snapshots}
72+
x={x}
73+
y={y}
74+
k={k}
75+
setZoomState={setZoomState}
76+
/>
77+
</div>
78+
</div>
7279
);
7380
}
7481
return <div className="noState">{NO_STATE_MSG}</div>;
@@ -78,12 +85,11 @@ const StateRoute = (props: StateRouteProps) => {
7885
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
7986
// if true involk render chart with hierarchy
8087
const renderHistory = () => {
81-
console.log('hierarchy in stateroute is', hierarchy);
8288
if (hierarchy) {
8389
return (
8490
<div>
8591
<div>
86-
<Legendary />
92+
<Legendary hierarchy={hierarchy} />
8793
</div>
8894
<div>
8995
<History hierarchy={hierarchy} />

src/app/components/legend.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,47 @@ import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend';
44

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

12+
const displayArray = (obj: {
13+
stateSnapshot: { children: any[] };
14+
name: number;
15+
branch: number;
16+
index: number;
17+
children?: [];
18+
}) => {
19+
if (
20+
obj.stateSnapshot.children.length > 0 &&
21+
obj.stateSnapshot.children[0] &&
22+
obj.stateSnapshot.children[0].state &&
23+
obj.stateSnapshot.children[0].name
24+
) {
25+
const newObj: Record<string, unknown> = {
26+
index: obj.index,
27+
displayName: `${obj.name}.${obj.branch}`,
28+
state: obj.stateSnapshot.children[0].state,
29+
componentName: obj.stateSnapshot.children[0].name,
30+
componentData:
31+
JSON.stringify(obj.stateSnapshot.children[0].componentData) === '{}'
32+
? ''
33+
: obj.stateSnapshot.children[0].componentData,
34+
};
35+
hierarchyArr.push(newObj);
36+
}
37+
if (obj.children) {
38+
obj.children.forEach((element) => {
39+
displayArray(element);
40+
});
41+
}
42+
};
43+
// the hierarchy gets set on the first click in the page
44+
// when page in refreshed we may not have a hierarchy so we need to check if hierarchy was initialized
45+
// if true involk displayArray to display the hierarchy
46+
// if (hierarchy) displayArray(hierarchy);
47+
1248
const legendGlyphSize = 12;
1349

1450
export default function Legendary({ events = false }: { events?: boolean }) {
@@ -26,7 +62,7 @@ export default function Legendary({ events = false }: { events?: boolean }) {
2662
if (events) alert(`clicked: ${JSON.stringify(label)}`);
2763
}}
2864
>
29-
<svg width={legendGlyphSize} height={legendGlyphSize}>
65+
<svg width={10} height={10}>
3066
<rect
3167
fill={label.value}
3268
width={legendGlyphSize}
@@ -48,7 +84,7 @@ export default function Legendary({ events = false }: { events?: boolean }) {
4884
.legends {
4985
font-family: arial;
5086
font-weight: 900;
51-
background-color: ${242529};
87+
background-color: 242529;
5288
border-radius: 14px;
5389
padding: 24px 24px 24px 32px;
5490
overflow-y: auto;
@@ -76,7 +112,7 @@ function LegendVisual({
76112
.legend {
77113
line-height: 0.9em;
78114
color: #efefef;
79-
font-size: 10px;
115+
font-size: 9px;
80116
font-family: arial;
81117
padding: 10px 10px;
82118
float: left;

0 commit comments

Comments
 (0)