@@ -67,7 +67,7 @@ const tooltipStyles = {
67
67
fontFamily : 'Roboto' ,
68
68
} ;
69
69
70
- const BarGraphComparison = props => {
70
+ const BarGraphComparisonActions = props => {
71
71
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
72
72
const {
73
73
width, height, data, comparison, setSeries, series, setAction
@@ -77,13 +77,7 @@ const BarGraphComparison = props => {
77
77
const [ open , setOpen ] = React . useState ( false ) ;
78
78
const [ picOpen , setPicOpen ] = React . useState ( false ) ;
79
79
const [ maxRender , setMaxRender ] = React . useState ( data . maxTotalRender ) ;
80
-
81
- function titleFilter ( comparisonArray ) {
82
- return comparisonArray . filter (
83
- elem => elem . title . split ( '-' ) [ 1 ] === tabs [ currentTab ] . title . split ( '-' ) [ 1 ] ,
84
- ) ;
85
- }
86
-
80
+
87
81
const currentIndex = tabs [ currentTab ] . sliderIndex ;
88
82
89
83
const {
@@ -97,44 +91,41 @@ const BarGraphComparison = props => {
97
91
let tooltipTimeout : number ;
98
92
99
93
const { containerRef, TooltipInPortal } = useTooltipInPortal ( ) ;
100
-
101
- const keys = Object . keys ( data . componentData ) ;
102
-
94
+ const keys = Object . keys ( data [ 0 ] ) . filter ( ( componentName ) => componentName !== 'name' && componentName !== 'seriesName' && componentName !== 'snapshotId' ) ;
103
95
// data accessor (used to generate scales) and formatter (add units for on hover box)
104
96
const getSnapshotId = ( d : snapshot ) => d . snapshotId ;
105
97
const formatSnapshotId = id => `Snapshot ID: ${ id } ` ;
106
98
const formatRenderTime = time => `${ time } ms ` ;
107
- const getCurrentTab = storedSeries => storedSeries . currentTab ;
99
+ const getSeriesName = action => action . seriesName ;
108
100
109
101
// create visualization SCALES with cleaned data
110
102
// the domain array/xAxisPoints elements will place the bars along the x-axis
111
- const xAxisPoints = [ 'currentTab' , 'comparison' ] ;
112
- const snapshotIdScale = scaleBand < string > ( {
113
- domain : xAxisPoints ,
103
+ const seriesNameScale = scaleBand < string > ( {
104
+ domain : data . map ( getSeriesName ) ,
114
105
padding : 0.2 ,
115
106
} ) ;
116
107
// This function will iterate through the snapshots of the series,
117
108
// and grab the highest render times (sum of all component times).
118
109
// We'll then use it in the renderingScale function and compare
119
110
// with the render time of the current tab.
120
111
// The max render time will determine the Y-axis's highest number.
121
- const calculateMaxTotalRender = series => {
122
- const currentSeriesBarStacks = ! comparison [ series ]
123
- ? [ ]
124
- : comparison [ series ] . data . barStack ;
125
- if ( currentSeriesBarStacks . length === 0 ) return 0 ;
112
+ const calculateMaxTotalRender = ( ) => {
126
113
let currentMax = - Infinity ;
127
- for ( let i = 0 ; i < currentSeriesBarStacks . length ; i += 1 ) {
128
- const renderTimes = Object . values ( currentSeriesBarStacks [ i ] ) . slice ( 1 ) ;
129
- const renderTotal = renderTimes . reduce ( ( acc , curr ) => acc + curr ) ;
130
- if ( renderTotal > currentMax ) currentMax = renderTotal ;
114
+ for ( let i = 0 ; i < data . length ; i ++ ) {
115
+ let currentSum = 0 ;
116
+
117
+ for ( const key of keys ) {
118
+ if ( data [ i ] [ key ] ) currentSum += data [ i ] [ key ]
119
+ }
120
+
121
+ if ( currentSum > currentMax ) currentMax = currentSum ;
131
122
}
132
123
return currentMax ;
133
124
} ;
134
125
135
126
// the domain array on rendering scale will set the coordinates for Y-aix points.
136
- const renderingScale = scaleLinear < number > ( {
137
- domain : [ 0 , Math . max ( calculateMaxTotalRender ( series ) , data . maxTotalRender ) ] ,
127
+ const renderingScale = scaleBand < number > ( {
128
+ domain : [ 0 , Math . max ( calculateMaxTotalRender ( ) , data . maxTotalRender ) ] ,
138
129
nice : true ,
139
130
} ) ;
140
131
// the domain array will assign each key a different color to make rectangle boxes
@@ -147,7 +138,7 @@ const BarGraphComparison = props => {
147
138
// setting max dimensions and scale ranges
148
139
const xMax = width - margin . left - margin . right ;
149
140
const yMax = height - margin . top - 200 ;
150
- snapshotIdScale . rangeRound ( [ 0 , xMax ] ) ;
141
+ seriesNameScale . rangeRound ( [ 0 , xMax ] ) ;
151
142
renderingScale . range ( [ yMax , 0 ] ) ;
152
143
153
144
// useStyles will change the styling on save series dropdown feature
@@ -189,7 +180,6 @@ const BarGraphComparison = props => {
189
180
const handleActionChange = event => {
190
181
setAction ( event . target . value ) ;
191
182
setSeries ( false ) ;
192
- console . log ( event . target . value )
193
183
// setXpoints();
194
184
} ;
195
185
@@ -203,23 +193,7 @@ const BarGraphComparison = props => {
203
193
// setXpoints();
204
194
} ;
205
195
206
- // manually assignin X -axis points with tab ID.
207
- function setXpointsComparison ( ) {
208
- comparison [ series ] . data . barStack . forEach ( elem => {
209
- elem . currentTab = 'comparison' ;
210
- } ) ;
211
- // comparison[series].data.barStack.currentTab = currentTab;
212
- console . log ( comparison )
213
- console . log ( series )
214
- console . log ( comparison [ series ] . data . barStack )
215
- return comparison [ series ] . data . barStack ;
216
- }
217
- function setXpointsCurrentTab ( ) {
218
- data . barStack . forEach ( element => {
219
- element . currentTab = 'currentTab' ;
220
- } ) ;
221
- return data . barStack ;
222
- }
196
+
223
197
const animateButton = function ( e ) {
224
198
e . preventDefault ;
225
199
e . target . classList . add ( 'animate' ) ;
@@ -241,20 +215,21 @@ const BarGraphComparison = props => {
241
215
for ( let i = 0 ; i < testList . length ; i ++ ) {
242
216
if ( testList [ i ] !== "" && ! finalList . includes ( testList [ i ] ) ) finalList . push ( testList [ i ] ) ;
243
217
}
244
- console . log ( 'Final List' , finalList )
218
+
219
+ console . log ( data ) ;
220
+ console . log ( keys ) ;
245
221
246
222
return (
247
223
< div >
248
224
< div className = "series-options-container" >
249
-
250
225
< div className = "dropdown-and-delete-series-container" >
251
226
< button
252
227
className = "delete-button"
253
228
onClick = { e => {
254
229
dispatch ( deleteSeries ( ) ) ;
255
230
} }
256
231
>
257
- Clear All Series1
232
+ Clear All Series
258
233
</ button >
259
234
< h4 style = { { padding : '0 1rem' } } > Compare Series: </ h4 >
260
235
< FormControl variant = "outlined" className = { classes . formControl } >
@@ -320,25 +295,26 @@ const BarGraphComparison = props => {
320
295
< Grid
321
296
top = { margin . top }
322
297
left = { margin . left }
323
- xScale = { snapshotIdScale }
298
+ xScale = { seriesNameScale }
324
299
yScale = { renderingScale }
325
300
width = { xMax }
326
301
height = { yMax }
327
302
stroke = "black"
328
303
strokeOpacity = { 0.1 }
329
- xOffset = { snapshotIdScale . bandwidth ( ) / 2 }
304
+ xOffset = { seriesNameScale . bandwidth ( ) / 2 }
330
305
/>
331
306
< Group top = { margin . top } left = { margin . left } >
332
307
< BarStack
333
- data = { data . barStack }
308
+ data = { data }
334
309
keys = { keys }
335
- x = { getSnapshotId }
336
- xScale = { snapshotIdScale }
310
+ x = { getSeriesName }
311
+ xScale = { seriesNameScale }
337
312
yScale = { renderingScale }
338
313
color = { colorScale }
339
314
>
340
315
{ barStacks => barStacks . map ( barStack => barStack . bars . map ( ( bar , idx ) => {
341
- console . log ( bar )
316
+ console . log ( 'barstack' , barStack )
317
+ console . log ( 'bar' , bar )
342
318
// Hides new components if components don't exist in previous snapshots.
343
319
if ( Number . isNaN ( bar . bar [ 1 ] ) || bar . height < 0 ) {
344
320
bar . height = 0 ;
@@ -395,7 +371,7 @@ const BarGraphComparison = props => {
395
371
< AxisBottom
396
372
top = { yMax + margin . top }
397
373
left = { margin . left }
398
- scale = { snapshotIdScale }
374
+ scale = { seriesNameScale }
399
375
stroke = { axisColor }
400
376
tickStroke = { axisColor }
401
377
strokeWidth = { 2 }
@@ -449,4 +425,4 @@ const BarGraphComparison = props => {
449
425
) ;
450
426
} ;
451
427
452
- export default BarGraphComparison ;
428
+ export default BarGraphComparisonActions ;
0 commit comments