@@ -88,6 +88,8 @@ export default function PerformanceVisx({
88
88
hierarchy,
89
89
} : BarStackProps )
90
90
91
+ let tooltipTimeout : number ;
92
+
91
93
{
92
94
const {
93
95
tooltipOpen,
@@ -98,12 +100,12 @@ export default function PerformanceVisx({
98
100
showTooltip
99
101
} = useTooltip < TooltipData > ( ) ;
100
102
101
- // data prep
103
+ // filter and structure incoming data for VISX
102
104
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) )
103
105
const keys = Object . keys ( data [ 0 ] ) . filter ( ( d ) => d !== "snapshotId" ) as CityName [ ] ;
104
106
console . log ( data )
105
107
106
- // ARRAY OF TOTAL VALUES PER SNAPSHOT
108
+ // create array of total render times for each snapshot
107
109
const totalRenderArr = data . reduce ( ( totalRender , curSnapshot ) => {
108
110
const curRenderTotal = keys . reduce ( ( acc , cur ) => {
109
111
acc += Number ( curSnapshot [ cur ] ) ;
@@ -113,42 +115,41 @@ const totalRenderArr = data.reduce((totalRender, curSnapshot) => {
113
115
return totalRender ;
114
116
} , [ ] as number [ ] ) ;
115
117
116
- const temperatureScale = scaleLinear < number > ( {
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 > ( {
125
+ domain : data . map ( getSnapshotId ) ,
126
+ padding : 0.2
127
+ } ) ;
128
+
129
+ const renderingScale = scaleLinear < number > ( {
117
130
domain : [ 0 , Math . max ( ...totalRenderArr ) ] ,
118
131
nice : true
119
- } ) ;
120
- const colorScale = scaleOrdinal < CityName , string > ( {
132
+ } ) ;
133
+
134
+ const colorScale = scaleOrdinal < CityName , string > ( {
121
135
domain : keys ,
122
136
range : schemeSet3
123
- } ) ;
124
-
125
- let tooltipTimeout : number ;
126
-
127
-
128
- /* ACCESSORS */
129
- const getSnapshot = ( d : snapshot ) => d . snapshotId ;
137
+ } ) ;
130
138
131
- /* SCALE */
132
- const dateScale = scaleBand < string > ( {
133
- domain : data . map ( getSnapshot ) ,
134
- padding : 0.2
135
- } ) ;
136
139
140
+ // initial set-up for Tool Tip (aka the on hover bar)
137
141
const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
138
142
143
+ // setting max dimensions and scale ranges
139
144
if ( width < 10 ) return null ;
140
- // bounds
141
-
142
- // width, height
143
145
const xMax = width ;
144
146
const yMax = height - margin . top - 100 ;
145
147
146
- dateScale . rangeRound ( [ 0 , xMax ] ) ;
147
- temperatureScale . range ( [ yMax , 0 ] ) ;
148
+ snapshotIdScale . rangeRound ( [ 0 , xMax ] ) ;
149
+ renderingScale . range ( [ yMax , 0 ] ) ;
148
150
149
151
return width < 10 ? null : (
150
152
// relative position is needed for correct tooltip positioning
151
-
152
153
< div style = { { position : "relative" } } >
153
154
< svg ref = { containerRef } width = { width } height = { height } >
154
155
< rect
@@ -162,21 +163,21 @@ const dateScale = scaleBand<string>({
162
163
< Grid
163
164
top = { margin . top }
164
165
left = { margin . left }
165
- xScale = { dateScale }
166
- yScale = { temperatureScale }
166
+ xScale = { snapshotIdScale }
167
+ yScale = { renderingScale }
167
168
width = { xMax }
168
169
height = { yMax }
169
170
stroke = "black"
170
171
strokeOpacity = { 0.1 }
171
- xOffset = { dateScale . bandwidth ( ) / 2 }
172
+ xOffset = { snapshotIdScale . bandwidth ( ) / 2 }
172
173
/>
173
174
< Group top = { margin . top } >
174
175
< BarStack < snapshot , CityName >
175
176
data = { data }
176
177
keys = { keys }
177
- x = { getSnapshot }
178
- xScale = { dateScale }
179
- yScale = { temperatureScale }
178
+ x = { getSnapshotId }
179
+ xScale = { snapshotIdScale }
180
+ yScale = { renderingScale }
180
181
color = { colorScale }
181
182
>
182
183
{ ( barStacks ) => barStacks . map ( barStack => barStack . bars . map ( ( bar => (
@@ -213,7 +214,7 @@ const dateScale = scaleBand<string>({
213
214
</ Group >
214
215
< AxisBottom
215
216
top = { yMax + margin . top }
216
- scale = { dateScale }
217
+ scale = { snapshotIdScale }
217
218
// tickFormat={formatDate}
218
219
stroke = { tickColor }
219
220
tickStroke = { tickColor }
@@ -256,7 +257,7 @@ const dateScale = scaleBand<string>({
256
257
{ tooltipData . bar . data [ tooltipData . key ] }
257
258
</ div >
258
259
< div >
259
- < small > { getSnapshot ( tooltipData . bar . data ) } </ small >
260
+ < small > { getSnapshotId ( tooltipData . bar . data ) } </ small >
260
261
</ div >
261
262
</ TooltipInPortal >
262
263
) }
0 commit comments