@@ -35,11 +35,7 @@ export type BarStackProps = {
35
35
} ;
36
36
37
37
/* DEFAULT STYLING */
38
- const purple1 = "#6c5efb" ;
39
- const purple2 = "#c998ff" ;
40
- const purple4 = "#00ffff " ;
41
- const purple3 = "#a44afe" ;
42
- const tickColor = '#679DCA' ;
38
+ const axisColor = '#679DCA' ;
43
39
const background = "#242529" ;
44
40
const defaultMargin = { top : 40 , right : 0 , bottom : 0 , left : 0 } ;
45
41
const tooltipStyles = {
@@ -88,8 +84,6 @@ export default function PerformanceVisx({
88
84
hierarchy,
89
85
} : BarStackProps )
90
86
91
- let tooltipTimeout : number ;
92
-
93
87
{
94
88
const {
95
89
tooltipOpen,
@@ -100,6 +94,8 @@ let tooltipTimeout: number;
100
94
showTooltip
101
95
} = useTooltip < TooltipData > ( ) ;
102
96
97
+ let tooltipTimeout : number ;
98
+
103
99
// filter and structure incoming data for VISX
104
100
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) )
105
101
const keys = Object . keys ( data [ 0 ] ) . filter ( ( d ) => d !== "snapshotId" ) as CityName [ ] ;
@@ -115,41 +111,39 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
115
111
return totalRender ;
116
112
} , [ ] as number [ ] ) ;
117
113
114
+ // data accessor (used to generate scales) and formatter (add units for on hover box)
115
+ const getSnapshotId = ( d : snapshot ) => d . snapshotId ;
116
+ const formatSnapshotId = id => 'Snapshot ID: ' + id ;
117
+ const formatRenderTime = time => time + ' ms' ;
118
118
119
-
120
- // data accessor - used for generating scales
121
- const getSnapshotId = ( d : snapshot ) => d . snapshotId ;
122
-
123
- // create visualization scales with filtered data
124
- const snapshotIdScale = scaleBand < string > ( {
119
+ // create visualization scales with filtered data
120
+ const snapshotIdScale = scaleBand < string > ( {
125
121
domain : data . map ( getSnapshotId ) ,
126
122
padding : 0.2
127
- } ) ;
123
+ } ) ;
128
124
129
- const renderingScale = scaleLinear < number > ( {
125
+ const renderingScale = scaleLinear < number > ( {
130
126
domain : [ 0 , Math . max ( ...totalRenderArr ) ] ,
131
127
nice : true
132
- } ) ;
128
+ } ) ;
133
129
134
- const colorScale = scaleOrdinal < CityName , string > ( {
130
+ const colorScale = scaleOrdinal < CityName , string > ( {
135
131
domain : keys ,
136
132
range : schemeSet3
137
- } ) ;
138
-
133
+ } ) ;
139
134
140
- // initial set-up for Tool Tip (aka the on hover bar)
141
135
const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
142
136
143
- // setting max dimensions and scale ranges
144
- if ( width < 10 ) return null ;
145
- const xMax = width ;
146
- const yMax = height - margin . top - 100 ;
147
-
148
- snapshotIdScale . rangeRound ( [ 0 , xMax ] ) ;
149
- renderingScale . range ( [ yMax , 0 ] ) ;
137
+ // setting max dimensions and scale ranges
138
+ if ( width < 10 ) return null ;
139
+ const xMax = width ;
140
+ const yMax = height - margin . top - 100 ;
141
+ snapshotIdScale . rangeRound ( [ 0 , xMax ] ) ;
142
+ renderingScale . range ( [ yMax , 0 ] ) ;
150
143
151
144
return width < 10 ? null : (
152
145
// relative position is needed for correct tooltip positioning
146
+
153
147
< div style = { { position : "relative" } } >
154
148
< svg ref = { containerRef } width = { width } height = { height } >
155
149
< rect
@@ -215,17 +209,17 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
215
209
< AxisBottom
216
210
top = { yMax + margin . top }
217
211
scale = { snapshotIdScale }
218
- // tickFormat={formatDate}
219
- stroke = { tickColor }
220
- tickStroke = { tickColor }
212
+ stroke = { axisColor }
213
+ tickStroke = { axisColor }
221
214
tickLabelProps = { ( ) => ( {
222
- fill : tickColor ,
215
+ fill : axisColor ,
223
216
fontSize : 11 ,
224
217
textAnchor : 'middle' ,
225
218
} ) }
226
219
/>
227
220
</ svg >
228
221
222
+ // OPTIONAL legend
229
223
{ /* <div
230
224
style={{
231
225
position: "absolute",
@@ -242,6 +236,7 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
242
236
labelMargin="0 15px 0 0"
243
237
/>
244
238
</div> */ }
239
+
245
240
{ /* FOR HOVER OVER DISPLAY */ }
246
241
{ tooltipOpen && tooltipData && (
247
242
< TooltipInPortal
@@ -254,10 +249,10 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
254
249
< strong > { tooltipData . key } </ strong >
255
250
</ div >
256
251
< div >
257
- { tooltipData . bar . data [ tooltipData . key ] }
252
+ { formatRenderTime ( tooltipData . bar . data [ tooltipData . key ] ) }
258
253
</ div >
259
254
< div >
260
- < small > { getSnapshotId ( tooltipData . bar . data ) } </ small >
255
+ < small > { formatSnapshotId ( getSnapshotId ( tooltipData . bar . data ) ) } </ small >
261
256
</ div >
262
257
</ TooltipInPortal >
263
258
) }
0 commit comments