Skip to content

Commit 23c604c

Browse files
committed
(add) Added a VISX legend to RecoilAtomsRelationship tab, still need to fix up CSS to make more visually appealing
1 parent 923e511 commit 23c604c

File tree

3 files changed

+110
-12
lines changed

3 files changed

+110
-12
lines changed

src/app/components/AtomsRelationship.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { LinkVertical } from '@visx/shape';
66
import { LinearGradient } from '@visx/gradient';
77
import { StateRouteProps} from './StateRoute'
88

9-
const blue = '#acdbdf';
10-
const selectWhite = '#f0ece2';
9+
export const blue = '#acdbdf';
10+
export const selectWhite = '#f0ece2';
1111

1212
export const lightgreen = '#0BAB64';
13-
const green = '#3BB78F'
14-
const orange = '#FED8B1';
13+
export const green = '#3BB78F'
14+
export const orange = '#FED8B1';
1515

16-
const merlinsbeard = '#f7f7f3';
16+
export const merlinsbeard = '#f7f7f3';
1717
export const background = '#242529';
18-
const root = '#d2f5e3';
18+
export const root = '#d2f5e3';
1919

2020
interface clusterShape {
2121
name?:string;
@@ -218,7 +218,7 @@ function SelectorNode({ node }) {
218218
);
219219
}
220220

221-
const defaultMargin = { top: 40, left: 0, right: 0, bottom: 40 };
221+
const defaultMargin = { top: 0, left: 0, right: 0, bottom: 40 };
222222

223223
// export type DendrogramProps = {
224224
// width: number;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React from 'react';
2+
import { scaleOrdinal } from '@visx/scale';
3+
import {
4+
LegendOrdinal,
5+
LegendItem,
6+
LegendLabel,
7+
} from '@visx/legend';
8+
9+
import {
10+
green,
11+
selectWhite,
12+
orange,
13+
blue
14+
} from './AtomsRelationship'
15+
16+
const ordinalColorScale = scaleOrdinal({
17+
domain: ['root', 'selectors', 'atoms', 'components'],
18+
range: [ green, selectWhite, orange, blue],
19+
});
20+
21+
const legendGlyphSize = 10;
22+
23+
export default function Legend({ events = false }: { events?: boolean }) {
24+
return (
25+
<div className="legends">
26+
<LegendDemo title="Recoil Relationships">
27+
<LegendOrdinal scale={ordinalColorScale} labelFormat={label => `${label.toUpperCase()}`}>
28+
{labels => (
29+
<div style={{ display: 'flex', flexDirection: 'column' }}>
30+
{labels.map((label, i) => (
31+
<LegendItem
32+
key={`legend-quantile-${i}`}
33+
margin="0 5px"
34+
onClick={() => {
35+
if (events) alert(`clicked: ${JSON.stringify(label)}`);
36+
}}
37+
>
38+
<svg width={legendGlyphSize} height={legendGlyphSize}>
39+
<circle
40+
fill={label.value}
41+
r={legendGlyphSize / 2}
42+
cx={legendGlyphSize / 2}
43+
cy={legendGlyphSize / 2}
44+
// width={legendGlyphSize}
45+
// height={legendGlyphSize}
46+
/>
47+
</svg>
48+
<LegendLabel align="left" margin="0 0 0 4px">
49+
{label.text}
50+
</LegendLabel>
51+
</LegendItem>
52+
))}
53+
</div>
54+
)}
55+
</LegendOrdinal>
56+
</LegendDemo>
57+
<style jsx>{`
58+
.legends {
59+
font-family: arial;
60+
font-weight: 900;
61+
border-radius: 14px;
62+
padding: 24px 24px 24px 32px;
63+
overflow-y: auto;
64+
flex-grow: 1;
65+
}
66+
.chart h2 {
67+
margin-left: 10px;
68+
}
69+
`}</style>
70+
</div>
71+
);
72+
}
73+
74+
function LegendDemo({ title, children }: { title: string; children: React.ReactNode }) {
75+
return (
76+
<div className="legend">
77+
<div className="title">{title}</div>
78+
{children}
79+
<style jsx>{`
80+
.legend {
81+
line-height: 0.9em;
82+
color: #efefef;
83+
font-size: 10px;
84+
font-family: arial;
85+
padding: 10px 10px;
86+
float: left;
87+
border: 1px solid rgba(255, 255, 255, 0.3);
88+
border-radius: 8px;
89+
margin: 5px 5px;
90+
}
91+
.title {
92+
font-size: 12px;
93+
margin-bottom: 10px;
94+
font-weight: 100;
95+
}
96+
`}</style>
97+
</div>
98+
);
99+
}

src/app/components/StateRoute.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import {
1313
} from 'react-router-dom';
1414
import Tree from './Tree';
1515
import ComponentMap from './ComponentMap';
16-
// import PerfView from './PerfView';
17-
import AtomsRelationship from './AtomsRelationship';
1816
import PerformanceVisx from './PerformanceVisx';
19-
17+
import Legend from './AtomsRelationshipLegend'
2018
import Example from './AtomsRelationship';
2119
import { ParentSize } from '@visx/responsive';
22-
import { Console } from 'console';
2320
import Legendary from './legend';
2421

2522
const History = require('./History').default;
@@ -90,12 +87,14 @@ const StateRoute = (props: StateRouteProps) => {
9087
};
9188

9289
const renderAtomsRelationship = () => (
93-
9490
<ParentSize>{({ width, height }) =>
91+
<>
92+
<Legend />
9593
<Example
9694
width={width}
9795
height={height}
9896
snapshots={snapshots} />}
97+
</>
9998
</ParentSize>
10099
);
101100

0 commit comments

Comments
 (0)