@@ -11,14 +11,19 @@ import { Text } from '@visx/text';
11
11
import { schemeSet3 } from 'd3-scale-chromatic' ;
12
12
import snapshots from './snapshots' ;
13
13
import { onHover , onHoverExit } from '../actions/actions' ;
14
- import { useStoreContext } from '../store'
14
+ import { useStoreContext } from '../store' ;
15
15
16
16
/* TYPESCRIPT */
17
17
interface data {
18
18
snapshotId ?: string ;
19
19
}
20
20
21
- interface margin { top : number ; right : number ; bottom : number ; left : number } ;
21
+ interface margin {
22
+ top : number ;
23
+ right : number ;
24
+ bottom : number ;
25
+ left : number ;
26
+ }
22
27
23
28
interface snapshot {
24
29
snapshotId ?: string ;
@@ -50,14 +55,19 @@ const tooltipStyles = {
50
55
color : 'white' ,
51
56
fontSize : '14px' ,
52
57
lineHeight : '18px' ,
53
- fontFamily : 'Roboto'
58
+ fontFamily : 'Roboto' ,
54
59
} ;
55
60
56
61
const BarGraph = ( props ) => {
57
62
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
58
63
const { width, height, data } = props ;
59
64
const {
60
- tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip,
65
+ tooltipOpen,
66
+ tooltipLeft,
67
+ tooltipTop,
68
+ tooltipData,
69
+ hideTooltip,
70
+ showTooltip,
61
71
} = useTooltip < TooltipData > ( ) ;
62
72
let tooltipTimeout : number ;
63
73
const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
@@ -91,7 +101,7 @@ const BarGraph = (props) => {
91
101
snapshotIdScale . rangeRound ( [ 0 , xMax ] ) ;
92
102
renderingScale . range ( [ yMax , 0 ] ) ;
93
103
return (
94
- < div >
104
+ < div >
95
105
< svg ref = { containerRef } width = { width } height = { height } >
96
106
{ }
97
107
< rect
@@ -122,9 +132,9 @@ const BarGraph = (props) => {
122
132
yScale = { renderingScale }
123
133
color = { colorScale }
124
134
>
125
- { barStacks =>
126
- barStacks . map ( barStack =>
127
- barStack . bars . map ( ( ( bar , idx ) => {
135
+ { ( barStacks ) =>
136
+ barStacks . map ( ( barStack ) =>
137
+ barStack . bars . map ( ( bar , idx ) => {
128
138
// hides new components if components don't exist in previous snapshots
129
139
if ( Number . isNaN ( bar . bar [ 1 ] ) || bar . height < 0 ) {
130
140
bar . height = 0 ;
@@ -140,14 +150,16 @@ const BarGraph = (props) => {
140
150
/* TIP TOOL EVENT HANDLERS */
141
151
// Hides tool tip once cursor moves off the current rect
142
152
onMouseLeave = { ( ) => {
143
- dispatch ( onHoverExit ( data . componentData [ bar . key ] . rtid ) ,
144
- tooltipTimeout = window . setTimeout ( ( ) => {
145
- hideTooltip ( )
146
- } , 300 ) )
153
+ dispatch (
154
+ onHoverExit ( data . componentData [ bar . key ] . rtid ) ,
155
+ ( tooltipTimeout = window . setTimeout ( ( ) => {
156
+ hideTooltip ( ) ;
157
+ } , 300 ) )
158
+ ) ;
147
159
} }
148
160
// Cursor position in window updates position of the tool tip
149
- onMouseMove = { event => {
150
- dispatch ( onHover ( data . componentData [ bar . key ] . rtid ) )
161
+ onMouseMove = { ( event ) => {
162
+ dispatch ( onHover ( data . componentData [ bar . key ] . rtid ) ) ;
151
163
if ( tooltipTimeout ) clearTimeout ( tooltipTimeout ) ;
152
164
const top = event . clientY - margin . top - bar . height ;
153
165
const left = bar . x + bar . width / 2 ;
@@ -158,8 +170,10 @@ const BarGraph = (props) => {
158
170
} ) ;
159
171
} }
160
172
/>
161
- ) } ) ) )
162
- }
173
+ ) ;
174
+ } )
175
+ )
176
+ }
163
177
</ BarStack >
164
178
</ Group >
165
179
< AxisLeft
@@ -189,8 +203,20 @@ const BarGraph = (props) => {
189
203
textAnchor : 'middle' ,
190
204
} ) }
191
205
/>
192
- < Text x = { - xMax / 2 } y = "15" transform = "rotate(-90)" fontSize = { 12 } fill = "#FFFFFF" > Rendering Time (ms) </ Text >
193
- < Text x = { xMax / 2 } y = { yMax + 65 } fontSize = { 12 } fill = "#FFFFFF" > Snapshot Id </ Text >
206
+ < Text
207
+ x = { - xMax / 2 }
208
+ y = "15"
209
+ transform = "rotate(-90)"
210
+ fontSize = { 12 }
211
+ fill = "#FFFFFF"
212
+ >
213
+ { ' ' }
214
+ Rendering Time (ms){ ' ' }
215
+ </ Text >
216
+ < Text x = { xMax / 2 } y = { yMax + 65 } fontSize = { 12 } fill = "#FFFFFF" >
217
+ { ' ' }
218
+ Snapshot Id{ ' ' }
219
+ </ Text >
194
220
</ svg >
195
221
{ /* FOR HOVER OVER DISPLAY */ }
196
222
{ tooltipOpen && tooltipData && (
@@ -201,23 +227,21 @@ const BarGraph = (props) => {
201
227
style = { tooltipStyles }
202
228
>
203
229
< div style = { { color : colorScale ( tooltipData . key ) } } >
204
- { ' ' }
205
- < strong > { tooltipData . key } </ strong >
206
- { ' ' }
207
- </ div >
208
- < div > { data . componentData [ tooltipData . key ] . stateType } </ div >
209
- < div >
210
- { ' ' }
211
- { formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) }
212
230
{ ' ' }
231
+ < strong > { tooltipData . key } </ strong > { ' ' }
213
232
</ div >
233
+ < div > { data . componentData [ tooltipData . key ] . stateType } </ div >
234
+ < div > { formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) } </ div >
214
235
< div >
215
236
{ ' ' }
216
- < small > { formatSnapshotId ( getSnapshotId ( tooltipData . bar . data ) ) } </ small >
237
+ < small >
238
+ { formatSnapshotId ( getSnapshotId ( tooltipData . bar . data ) ) }
239
+ </ small >
217
240
</ div >
218
241
</ TooltipInPortal >
219
242
) }
220
243
</ div >
221
- ) } ;
244
+ ) ;
245
+ } ;
222
246
223
- export default BarGraph ;
247
+ export default BarGraph ;
0 commit comments