11import React , { Component , useEffect , useState } from 'react' ;
22import * 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-
12526const 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 } ;
0 commit comments