@@ -9,9 +9,8 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
9
9
import { useTooltip , useTooltipInPortal , defaultStyles } from '@visx/tooltip' ;
10
10
import { Text } from '@visx/text' ;
11
11
import { schemeSet3 } from 'd3-scale-chromatic' ;
12
- import { onHover , onHoverExit } from '../actions/actions' ;
12
+ import { onHover , onHoverExit , save } from '../actions/actions' ;
13
13
import { useStoreContext } from '../store' ;
14
- import { save } from '../actions/actions' ;
15
14
16
15
/* TYPESCRIPT */
17
16
interface data {
@@ -45,7 +44,9 @@ interface TooltipData {
45
44
}
46
45
47
46
/* 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
+ } ;
49
50
const axisColor = '#62d6fb' ;
50
51
const background = '#242529' ;
51
52
const tooltipStyles = {
@@ -58,7 +59,7 @@ const tooltipStyles = {
58
59
fontFamily : 'Roboto' ,
59
60
} ;
60
61
61
- const BarGraph = ( props ) => {
62
+ const BarGraph = props => {
62
63
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
63
64
const { width, height, data } = props ;
64
65
const {
@@ -78,8 +79,8 @@ const BarGraph = (props) => {
78
79
79
80
// data accessor (used to generate scales) and formatter (add units for on hover box)
80
81
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 ` ;
83
84
84
85
// create visualization SCALES with cleaned data
85
86
const snapshotIdScale = scaleBand < string > ( {
@@ -105,7 +106,7 @@ const BarGraph = (props) => {
105
106
106
107
const toStorage = {
107
108
currentTab,
108
- title : tabs [ currentTab ] [ ' title' ] ,
109
+ title : tabs [ currentTab ] . title ,
109
110
data,
110
111
} ;
111
112
@@ -119,14 +120,14 @@ const BarGraph = (props) => {
119
120
} else {
120
121
saveButtons [ i ] . innerHTML = 'Save Series' ;
121
122
saveButtons [ i ] . classList . remove ( 'animate' ) ;
122
- } ;
123
- } ;
123
+ }
124
+ }
124
125
} ) ;
125
126
return (
126
- < div className = ' bargraph-position' >
127
+ < div className = " bargraph-position" >
127
128
< button
128
- className = ' save-series-button'
129
- onClick = { ( e ) => {
129
+ className = " save-series-button"
130
+ onClick = { e => {
130
131
dispatch ( save ( toStorage ) ) ;
131
132
} }
132
133
>
@@ -149,7 +150,7 @@ const BarGraph = (props) => {
149
150
yScale = { renderingScale }
150
151
width = { xMax }
151
152
height = { yMax }
152
- stroke = ' black'
153
+ stroke = " black"
153
154
strokeOpacity = { 0.1 }
154
155
xOffset = { snapshotIdScale . bandwidth ( ) / 2 }
155
156
/>
@@ -162,48 +163,44 @@ const BarGraph = (props) => {
162
163
yScale = { renderingScale }
163
164
color = { colorScale }
164
165
>
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 }
180
179
/* TIP TOOL EVENT HANDLERS */
181
180
// 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
+ } }
190
189
// 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
+ } ) ) }
207
204
</ BarStack >
208
205
</ Group >
209
206
< AxisLeft
@@ -235,15 +232,15 @@ const BarGraph = (props) => {
235
232
/>
236
233
< Text
237
234
x = { - xMax / 2 }
238
- y = '15'
239
- transform = ' rotate(-90)'
235
+ y = "15"
236
+ transform = " rotate(-90)"
240
237
fontSize = { 12 }
241
- fill = ' #FFFFFF'
238
+ fill = " #FFFFFF"
242
239
>
243
240
Rendering Time (ms)
244
241
</ Text >
245
242
< 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" >
247
244
Snapshot ID
248
245
</ Text >
249
246
</ svg >
@@ -257,10 +254,15 @@ const BarGraph = (props) => {
257
254
>
258
255
< div style = { { color : colorScale ( tooltipData . key ) } } >
259
256
{ ' ' }
260
- < strong > { tooltipData . key } </ strong > { ' ' }
257
+ < strong > { tooltipData . key } </ strong >
258
+ { ' ' }
261
259
</ div >
262
260
< 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 >
264
266
< div >
265
267
{ ' ' }
266
268
< small >
0 commit comments