@@ -9,9 +9,8 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
99import { useTooltip , useTooltipInPortal , defaultStyles } from '@visx/tooltip' ;
1010import { Text } from '@visx/text' ;
1111import { schemeSet3 } from 'd3-scale-chromatic' ;
12- import { onHover , onHoverExit } from '../actions/actions' ;
12+ import { onHover , onHoverExit , save } from '../actions/actions' ;
1313import { useStoreContext } from '../store' ;
14- import { save } from '../actions/actions' ;
1514
1615/* TYPESCRIPT */
1716interface data {
@@ -45,7 +44,9 @@ interface TooltipData {
4544}
4645
4746/* DEFAULTS */
48- const margin = { top : 30 , right : 30 , bottom : 0 , left : 50 } ;
47+ const margin = {
48+ top : 30 , right : 30 , bottom : 0 , left : 50 ,
49+ } ;
4950const axisColor = '#62d6fb' ;
5051const background = '#242529' ;
5152const tooltipStyles = {
@@ -58,7 +59,7 @@ const tooltipStyles = {
5859 fontFamily : 'Roboto' ,
5960} ;
6061
61- const BarGraph = ( props ) => {
62+ const BarGraph = props => {
6263 const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
6364 const { width, height, data } = props ;
6465 const {
@@ -78,8 +79,8 @@ const BarGraph = (props) => {
7879
7980 // data accessor (used to generate scales) and formatter (add units for on hover box)
8081 const getSnapshotId = ( d : snapshot ) => d . snapshotId ;
81- const formatSnapshotId = ( id ) => `Snapshot ID: ${ id } ` ;
82- const formatRenderTime = ( time ) => `${ time } ms ` ;
82+ const formatSnapshotId = id => `Snapshot ID: ${ id } ` ;
83+ const formatRenderTime = time => `${ time } ms ` ;
8384
8485 // create visualization SCALES with cleaned data
8586 const snapshotIdScale = scaleBand < string > ( {
@@ -105,7 +106,7 @@ const BarGraph = (props) => {
105106
106107 const toStorage = {
107108 currentTab,
108- title : tabs [ currentTab ] [ ' title' ] ,
109+ title : tabs [ currentTab ] . title ,
109110 data,
110111 } ;
111112
@@ -119,14 +120,14 @@ const BarGraph = (props) => {
119120 } else {
120121 saveButtons [ i ] . innerHTML = 'Save Series' ;
121122 saveButtons [ i ] . classList . remove ( 'animate' ) ;
122- } ;
123- } ;
123+ }
124+ }
124125 } ) ;
125126 return (
126- < div className = ' bargraph-position' >
127+ < div className = " bargraph-position" >
127128 < button
128- className = ' save-series-button'
129- onClick = { ( e ) => {
129+ className = " save-series-button"
130+ onClick = { e => {
130131 dispatch ( save ( toStorage ) ) ;
131132 } }
132133 >
@@ -149,7 +150,7 @@ const BarGraph = (props) => {
149150 yScale = { renderingScale }
150151 width = { xMax }
151152 height = { yMax }
152- stroke = ' black'
153+ stroke = " black"
153154 strokeOpacity = { 0.1 }
154155 xOffset = { snapshotIdScale . bandwidth ( ) / 2 }
155156 />
@@ -162,48 +163,44 @@ const BarGraph = (props) => {
162163 yScale = { renderingScale }
163164 color = { colorScale }
164165 >
165- { ( barStacks ) =>
166- barStacks . map ( ( barStack ) =>
167- barStack . bars . map ( ( bar , idx ) => {
168- // Hides new components if components don't exist in previous snapshots.
169- if ( Number . isNaN ( bar . bar [ 1 ] ) || bar . height < 0 ) {
170- bar . height = 0 ;
171- }
172- return (
173- < rect
174- key = { `bar-stack-${ barStack . id } -${ bar . id } ` }
175- x = { bar . x }
176- y = { bar . y }
177- height = { bar . height === 0 ? null : bar . height }
178- width = { bar . width }
179- fill = { bar . color }
166+ { barStacks => barStacks . map ( barStack => barStack . bars . map ( ( bar , idx ) => {
167+ // Hides new components if components don't exist in previous snapshots.
168+ if ( Number . isNaN ( bar . bar [ 1 ] ) || bar . height < 0 ) {
169+ bar . height = 0 ;
170+ }
171+ return (
172+ < rect
173+ key = { `bar-stack-${ barStack . id } -${ bar . id } ` }
174+ x = { bar . x }
175+ y = { bar . y }
176+ height = { bar . height === 0 ? null : bar . height }
177+ width = { bar . width }
178+ fill = { bar . color }
180179 /* TIP TOOL EVENT HANDLERS */
181180 // Hides tool tip once cursor moves off the current rect.
182- onMouseLeave = { ( ) => {
183- dispatch (
184- onHoverExit ( data . componentData [ bar . key ] . rtid ) ,
185- ( tooltipTimeout = window . setTimeout ( ( ) => {
186- hideTooltip ( ) ;
187- } , 300 ) )
188- ) ;
189- } }
181+ onMouseLeave = { ( ) => {
182+ dispatch (
183+ onHoverExit ( data . componentData [ bar . key ] . rtid ) ,
184+ ( tooltipTimeout = window . setTimeout ( ( ) => {
185+ hideTooltip ( ) ;
186+ } , 300 ) ) ,
187+ ) ;
188+ } }
190189 // Cursor position in window updates position of the tool tip.
191- onMouseMove = { ( event ) => {
192- dispatch ( onHover ( data . componentData [ bar . key ] . rtid ) ) ;
193- if ( tooltipTimeout ) clearTimeout ( tooltipTimeout ) ;
194- const top = event . clientY - margin . top - bar . height ;
195- const left = bar . x + bar . width / 2 ;
196- showTooltip ( {
197- tooltipData : bar ,
198- tooltipTop : top ,
199- tooltipLeft : left ,
200- } ) ;
201- } }
202- />
203- ) ;
204- } )
205- )
206- }
190+ onMouseMove = { event => {
191+ dispatch ( onHover ( data . componentData [ bar . key ] . rtid ) ) ;
192+ if ( tooltipTimeout ) clearTimeout ( tooltipTimeout ) ;
193+ const top = event . clientY - margin . top - bar . height ;
194+ const left = bar . x + bar . width / 2 ;
195+ showTooltip ( {
196+ tooltipData : bar ,
197+ tooltipTop : top ,
198+ tooltipLeft : left ,
199+ } ) ;
200+ } }
201+ />
202+ ) ;
203+ } ) ) }
207204 </ BarStack >
208205 </ Group >
209206 < AxisLeft
@@ -235,15 +232,15 @@ const BarGraph = (props) => {
235232 />
236233 < Text
237234 x = { - xMax / 2 }
238- y = '15'
239- transform = ' rotate(-90)'
235+ y = "15"
236+ transform = " rotate(-90)"
240237 fontSize = { 12 }
241- fill = ' #FFFFFF'
238+ fill = " #FFFFFF"
242239 >
243240 Rendering Time (ms)
244241 </ Text >
245242 < br />
246- < Text x = { xMax / 2 + 15 } y = { yMax + 70 } fontSize = { 12 } fill = ' #FFFFFF' >
243+ < Text x = { xMax / 2 + 15 } y = { yMax + 70 } fontSize = { 12 } fill = " #FFFFFF" >
247244 Snapshot ID
248245 </ Text >
249246 </ svg >
@@ -257,10 +254,15 @@ const BarGraph = (props) => {
257254 >
258255 < div style = { { color : colorScale ( tooltipData . key ) } } >
259256 { ' ' }
260- < strong > { tooltipData . key } </ strong > { ' ' }
257+ < strong > { tooltipData . key } </ strong >
258+ { ' ' }
261259 </ div >
262260 < div > { data . componentData [ tooltipData . key ] . stateType } </ div >
263- < div > { formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) } </ div >
261+ < div >
262+ { ' ' }
263+ { formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) }
264+ { ' ' }
265+ </ div >
264266 < div >
265267 { ' ' }
266268 < small >
0 commit comments