Skip to content

Commit c4605c9

Browse files
committed
(add) Incorporated legend with proper color schema in AtomRelationships tab using VISX library
Co-authored-by: Chris Guizzetti
1 parent 23c604c commit c4605c9

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

src/app/components/AtomsRelationship.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Cluster, hierarchy } from '@visx/hierarchy';
55
import { LinkVertical } from '@visx/shape';
66
import { LinearGradient } from '@visx/gradient';
77
import { StateRouteProps} from './StateRoute'
8+
import Legend from './AtomsRelationshipLegend'
89

910
export const blue = '#acdbdf';
1011
export const selectWhite = '#f0ece2';
@@ -190,7 +191,6 @@ function RootNode({ node }) {
190191
}
191192

192193
function SelectorNode({ node }) {
193-
194194
return (
195195
<Group top={node.y} left={node.x}>
196196
{node.depth !== 0 && (
@@ -218,7 +218,7 @@ function SelectorNode({ node }) {
218218
);
219219
}
220220

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

223223
// export type DendrogramProps = {
224224
// width: number;
@@ -242,11 +242,16 @@ export default function Example({
242242
const yMax = height - margin.top - margin.bottom;
243243

244244
return width < 10 ? null : (
245+
<>
246+
<div>
247+
<Legend
248+
hierarchy = {hierarchy} />
249+
</div>
245250
<svg width={width} height={height}>
251+
246252
<LinearGradient id="top" from={lightgreen} to={green} />
247253

248254
<rect width={width} height={height} rx={14} fill={background} />
249-
250255
<Cluster root={data} size={[xMax, yMax]}>
251256
{(cluster) => (
252257
<Group top={margin.top} left={margin.left}>
@@ -267,5 +272,6 @@ export default function Example({
267272
)}
268273
</Cluster>
269274
</svg>
275+
</>
270276
);
271-
}
277+
}

src/app/components/AtomsRelationshipLegend.tsx

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,23 @@ import {
66
LegendLabel,
77
} from '@visx/legend';
88

9-
import {
10-
green,
11-
selectWhite,
12-
orange,
13-
blue
14-
} from './AtomsRelationship'
159

1610
const ordinalColorScale = scaleOrdinal({
17-
domain: ['root', 'selectors', 'atoms', 'components'],
18-
range: [ green, selectWhite, orange, blue],
11+
domain: ['Root', 'Selectors', 'Atoms', 'Components'],
12+
range: [ '#3BB78F', '#f0ece2', '#FED8B1', '#acdbdf'],
1913
});
2014

21-
const legendGlyphSize = 10;
15+
const legendGlyphSize = 15;
2216

2317
export default function Legend({ events = false }: { events?: boolean }) {
2418
return (
2519
<div className="legends">
2620
<LegendDemo title="Recoil Relationships">
27-
<LegendOrdinal scale={ordinalColorScale} labelFormat={label => `${label.toUpperCase()}`}>
21+
<LegendOrdinal scale={ordinalColorScale} labelFormat={label => `${label}`}>
2822
{labels => (
29-
<div style={{ display: 'flex', flexDirection: 'column' }}>
23+
<div
24+
style={{ display: 'flex', flexDirection: 'column' }}
25+
>
3026
{labels.map((label, i) => (
3127
<LegendItem
3228
key={`legend-quantile-${i}`}
@@ -41,11 +37,9 @@ export default function Legend({ events = false }: { events?: boolean }) {
4137
r={legendGlyphSize / 2}
4238
cx={legendGlyphSize / 2}
4339
cy={legendGlyphSize / 2}
44-
// width={legendGlyphSize}
45-
// height={legendGlyphSize}
4640
/>
4741
</svg>
48-
<LegendLabel align="left" margin="0 0 0 4px">
42+
<LegendLabel align="left" margin="4px 0px 4px 4px">
4943
{label.text}
5044
</LegendLabel>
5145
</LegendItem>
@@ -54,19 +48,19 @@ export default function Legend({ events = false }: { events?: boolean }) {
5448
)}
5549
</LegendOrdinal>
5650
</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>
51+
<style jsx>
52+
{`
53+
.legends {
54+
width: 25%;
55+
font-family: arial;
56+
font-weight: 900;;
57+
border-radius: 14px;
58+
padding: 2px 2px 2px 2px;
59+
overflow-y: auto;
60+
flex-grow: 1;
61+
}
62+
`}
63+
</style>
7064
</div>
7165
);
7266
}
@@ -78,15 +72,16 @@ function LegendDemo({ title, children }: { title: string; children: React.ReactN
7872
{children}
7973
<style jsx>{`
8074
.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;
75+
position: absolute;
76+
top: 50;
77+
left: 50;
78+
line-height: 0.9em;
79+
color: #efefef;
80+
font-size: 9px;
81+
font-family: arial;
82+
padding: 10px 10px;
83+
float: left;
84+
margin: 5px 5px;
9085
}
9186
.title {
9287
font-size: 12px;

src/app/components/StateRoute.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ const StateRoute = (props: StateRouteProps) => {
8989
const renderAtomsRelationship = () => (
9090
<ParentSize>{({ width, height }) =>
9191
<>
92-
<Legend />
92+
{/* <Legend /> */}
9393
<Example
9494
width={width}
9595
height={height}
96-
snapshots={snapshots} />}
96+
snapshots={snapshots} />
9797
</>
9898
</ParentSize>
9999
);

0 commit comments

Comments
 (0)