Skip to content

Commit da1d375

Browse files
committed
modularizes visx legend element into separate file, and successfully renders history list and legend
1 parent c34775c commit da1d375

File tree

2 files changed

+12
-105
lines changed

2 files changed

+12
-105
lines changed

src/app/components/History.tsx

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import React, { Component, useEffect, useState } from 'react';
22
import * as d3 from 'd3';
3-
// import Legendary from './legend';
4-
import { scaleOrdinal } from '@visx/scale';
5-
import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend';
63

74
/**
85
* @var colors: Colors array for the diffrerent node branches, each color is for a different branch
@@ -26,102 +23,6 @@ const colors = [
2623
'#2C4870',
2724
];
2825

29-
/**
30-
*method of creating legend using Visx
31-
**/
32-
// where we set color scale for Legendary
33-
const ordinalColorScale = scaleOrdinal<number, string>({
34-
domain: [1, 2, 3, 4],
35-
// sync in with the snapshot color chosen in history tab already
36-
range: ['#66d981', '#71f5ef', '#4899f1', '#7d81f6'],
37-
});
38-
39-
const legendGlyphSize = 12;
40-
41-
function Legendary({ events = false }: { events?: boolean }) {
42-
return (
43-
<div className="legends">
44-
<LegendVisual title="State Snapshots">
45-
<LegendOrdinal scale={ordinalColorScale}>
46-
{(labels) => (
47-
<div style={{ display: 'flex', flexDirection: 'row' }}>
48-
{labels.map((label, i) => (
49-
<LegendItem
50-
key={`legend-quantile-${i}`}
51-
margin="0 5px"
52-
onClick={() => {
53-
if (events) alert(`clicked: ${JSON.stringify(label)}`);
54-
}}
55-
>
56-
<svg width={legendGlyphSize} height={legendGlyphSize}>
57-
<rect
58-
fill={label.value}
59-
width={legendGlyphSize}
60-
height={legendGlyphSize}
61-
/>
62-
</svg>
63-
<LegendLabel align="left" margin="0 0 0 4px">
64-
{label.text}
65-
</LegendLabel>
66-
</LegendItem>
67-
))}
68-
</div>
69-
)}
70-
</LegendOrdinal>
71-
</LegendVisual>
72-
73-
<style jsx="true">
74-
{`
75-
.legends {
76-
font-family: arial;
77-
font-weight: 900;
78-
background-color: black;
79-
border-radius: 14px;
80-
padding: 24px 24px 24px 32px;
81-
overflow-y: auto;
82-
flex-grow: 1;
83-
}
84-
`}
85-
</style>
86-
</div>
87-
);
88-
}
89-
90-
function LegendVisual({
91-
title,
92-
children,
93-
}: {
94-
title: string;
95-
children: React.ReactNode;
96-
}) {
97-
return (
98-
<div className="legend">
99-
<div className="title">{title}</div>
100-
{children}
101-
<style jsx="true">
102-
{`
103-
.legend {
104-
line-height: 0.9em;
105-
color: #efefef;
106-
font-size: 10px;
107-
font-family: arial;
108-
padding: 10px 10px;
109-
float: left;
110-
border: 1px solid rgba(255, 255, 255, 0.3);
111-
border-radius: 8px;
112-
margin: 5px 5px;
113-
}
114-
.title {
115-
font-size: 12px;
116-
margin-bottom: 10px;
117-
font-weight: 100;
118-
}
119-
`}
120-
</style>
121-
</div>
122-
);
123-
}
124-
12526
const filterHooks = (data: any[]) => {
12627
if (data[0].children && data[0].state === 'stateless') {
12728
return filterHooks(data[0].children);
@@ -350,13 +251,11 @@ function History(props) {
350251
return [(y = +y) * Math.cos((x -= Math.PI / 2)), y * Math.sin(x)];
351252
}
352253
};
353-
354254
return (
355255
<>
356256
<div ref={HistoryRef} className="history-d3-div" id="historyContainer" />
357-
{/* <Legendary /> */}
358257
</>
359258
);
360259
}
361260

362-
export default History;
261+
export { History, Legendary };

src/app/components/StateRoute.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import AtomsRelationship from './AtomsRelationship.jsx';
1818
import Example from './AtomsRelationship.jsx';
1919
import { ParentSize } from '@visx/responsive';
2020
import { Console } from 'console';
21+
import { History } from './History';
2122
import Legendary from './legend';
2223

23-
const History = require('./History').default;
24+
// const History = require('./History');
2425

2526
const ErrorHandler = require('./ErrorHandler').default;
2627

@@ -77,10 +78,17 @@ const StateRoute = (props: StateRouteProps) => {
7778
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
7879
// if true involk render chart with hierarchy
7980
const renderHistory = () => {
81+
console.log('hierarchy in stateroute is', hierarchy);
8082
if (hierarchy) {
8183
return (
82-
<History hierarchy={hierarchy} />
83-
// <Legendary />
84+
<div>
85+
<div>
86+
<Legendary />
87+
</div>
88+
<div>
89+
<History hierarchy={hierarchy} />
90+
</div>
91+
</div>
8492
);
8593
}
8694
return <div className="noState">{NO_STATE_MSG}</div>;

0 commit comments

Comments
 (0)