1
1
// @ts -nocheck
2
- import React , { useEffect , useForceUpdate } from 'react' ;
2
+ import React from 'react' ;
3
3
import { BarStack } from '@visx/shape' ;
4
4
import { SeriesPoint } from '@visx/shape/lib/types' ;
5
5
import { Group } from '@visx/group' ;
@@ -8,15 +8,11 @@ import { AxisBottom, AxisLeft } from '@visx/axis';
8
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
-
12
11
import { schemeSet3 } from 'd3-scale-chromatic' ;
13
12
import { makeStyles } from '@material-ui/core/styles' ;
14
13
import Select from '@material-ui/core/Select' ;
15
- import InputLabel from '@material-ui/core/InputLabel' ;
16
14
import MenuItem from '@material-ui/core/MenuItem' ;
17
15
import FormControl from '@material-ui/core/FormControl' ;
18
- import FormHelperText from '@material-ui/core/FormHelperText' ;
19
- import snapshots from './snapshots' ;
20
16
import { onHover , onHoverExit } from '../actions/actions' ;
21
17
import { useStoreContext } from '../store' ;
22
18
import { deleteSeries } from '../actions/actions' ;
@@ -105,15 +101,17 @@ const BarGraphComparison = (props) => {
105
101
const formatRenderTime = ( time ) => `${ time } ms ` ;
106
102
const getCurrentTab = ( storedSeries ) => storedSeries . currentTab ;
107
103
// create visualization SCALES with cleaned data
108
- //const xAxisPoints = [...titleFilter(comparison).map(getTabID), currentTab];
109
- //the domain array elements will place the bars along the x-axis
110
- const xAxisPoints = [ 'currentTab' , 'comparison' ] ; //[1.0.,2.0]
111
- //{ currentTab : 1 }, {currentTab : 2 }
104
+ // the domain array/xAxisPoints elements will place the bars along the x-axis
105
+ const xAxisPoints = [ 'currentTab' , 'comparison' ] ;
112
106
const snapshotIdScale = scaleBand < string > ( {
113
107
domain : xAxisPoints ,
114
108
padding : 0.2 ,
115
109
} ) ;
116
- // calculateMax
110
+ // This function will iterate through the snapshots of the series,
111
+ // and grab the highest render times (sum of all component times).
112
+ // We'll then use it in the renderingScale function and compare
113
+ // with the render time of the current tab.
114
+ // The max render time will determine the Y-axis's highest number.
117
115
const calculateMaxTotalRender = ( series ) => {
118
116
const currentSeriesBarStacks = ! comparison [ series ]
119
117
? [ ]
@@ -128,11 +126,13 @@ const BarGraphComparison = (props) => {
128
126
return currentMax ;
129
127
} ;
130
128
129
+ // the domain array on rendering scale will set the coordinates for Y-aix points.
131
130
const renderingScale = scaleLinear < number > ( {
132
131
domain : [ 0 , Math . max ( calculateMaxTotalRender ( series ) , data . maxTotalRender ) ] ,
133
132
nice : true ,
134
133
} ) ;
135
-
134
+ // the domain array will assign each key(component on test app) a different color
135
+ // and use range to set the color scheme each bar
136
136
const colorScale = scaleOrdinal < string > ( {
137
137
domain : keys ,
138
138
range : schemeSet3 ,
@@ -144,7 +144,7 @@ const BarGraphComparison = (props) => {
144
144
snapshotIdScale . rangeRound ( [ 0 , xMax ] ) ;
145
145
renderingScale . range ( [ yMax , 0 ] ) ;
146
146
147
- // Dropdown to select series.
147
+ // useStyles will change the styling on save series dropdown feature
148
148
const useStyles = makeStyles ( ( theme ) => ( {
149
149
formControl : {
150
150
margin : theme . spacing ( 1 ) ,
@@ -198,37 +198,37 @@ const BarGraphComparison = (props) => {
198
198
e . target . classList . add ( 'animate' ) ;
199
199
e . target . innerHTML = 'Deleted!' ;
200
200
setTimeout ( function ( ) {
201
- e . target . innerHTML = 'Clear Series' ;
201
+ e . target . innerHTML = 'Clear All Series' ;
202
202
e . target . classList . remove ( 'animate' ) ;
203
203
} , 1000 ) ;
204
204
} ;
205
205
const classname = document . getElementsByClassName ( 'delete-button' ) ;
206
206
for ( let i = 0 ; i < classname . length ; i ++ ) {
207
207
classname [ i ] . addEventListener ( 'click' , animateButton , false ) ;
208
208
}
209
- //console.log('set x on current bar', setXpointsCurrentTab());
210
209
return (
211
210
< div >
212
- < div className = ' series-options-container' >
213
- < div className = ' snapshotId-header' >
211
+ < div className = " series-options-container" >
212
+ < div className = " snapshotId-header" >
214
213
{ ' ' }
215
214
Snapshot ID: { currentIndex + 1 } { ' ' }
216
215
</ div >
217
216
218
- < div className = ' dropdown-and-delete-series-container' >
217
+ < div className = " dropdown-and-delete-series-container" >
219
218
< button
220
- className = ' delete-button'
219
+ className = " delete-button"
221
220
onClick = { ( e ) => {
222
221
dispatch ( deleteSeries ( ) ) ;
223
222
} }
224
223
>
225
224
Clear All Series
226
225
</ button >
227
- < FormControl variant = 'outlined' className = { classes . formControl } >
226
+ < h4 style = { { padding : '0 1rem' } } > Compare with: </ h4 >
227
+ < FormControl variant = "outlined" className = { classes . formControl } >
228
228
< Select
229
229
style = { { color : 'white' } }
230
- labelId = ' simple-select-outlined-label'
231
- id = ' simple-select-outlined'
230
+ labelId = " simple-select-outlined-label"
231
+ id = " simple-select-outlined"
232
232
className = { classes . select }
233
233
open = { open }
234
234
onClose = { handleClose }
@@ -267,13 +267,13 @@ const BarGraphComparison = (props) => {
267
267
yScale = { renderingScale }
268
268
width = { xMax }
269
269
height = { yMax }
270
- stroke = ' black'
270
+ stroke = " black"
271
271
strokeOpacity = { 0.1 }
272
272
xOffset = { snapshotIdScale . bandwidth ( ) / 2 }
273
273
/>
274
274
< Group top = { margin . top } left = { margin . left } >
275
275
< BarStack
276
- // OG Barstack
276
+ // Current Tab bar stack.
277
277
data = { setXpointsCurrentTab ( ) }
278
278
keys = { keys }
279
279
x = { getCurrentTab }
@@ -283,6 +283,11 @@ const BarGraphComparison = (props) => {
283
283
>
284
284
{ ( barStacks ) =>
285
285
barStacks . map ( ( barStack , idx ) => {
286
+ // Uses map method to iterate through all components,
287
+ // creating a rect component (from visx) for each iteration.
288
+ // height/width/etc. are calculated by visx.
289
+ // to set X and Y scale, it will used the passed in function and
290
+ // will run it on the array thats outputted by data
286
291
const bar = barStack . bars [ currentIndex ] ;
287
292
if ( Number . isNaN ( bar . bar [ 1 ] ) || bar . height < 0 ) {
288
293
bar . height = 0 ;
@@ -323,7 +328,9 @@ const BarGraphComparison = (props) => {
323
328
}
324
329
</ BarStack >
325
330
< BarStack
326
- // Comparison Barstack
331
+ // Comparison Barstack (populates based on series selected)
332
+ //to set X and Y scale, it will used the passed in function and
333
+ // will run it on the array thats outputted by data
327
334
data = { ! comparison [ series ] ? [ ] : setXpointsComparison ( ) }
328
335
keys = { keys }
329
336
x = { getCurrentTab }
@@ -333,6 +340,9 @@ const BarGraphComparison = (props) => {
333
340
>
334
341
{ ( barStacks ) =>
335
342
barStacks . map ( ( barStack , idx ) => {
343
+ // Uses map method to iterate through all components,
344
+ // creating a rect component (from visx) for each iteration.
345
+ // height/width/etc. are calculated by visx.
336
346
if ( ! barStack . bars [ currentIndex ] ) {
337
347
return < h1 > No Comparison</ h1 > ;
338
348
}
@@ -405,14 +415,14 @@ const BarGraphComparison = (props) => {
405
415
/>
406
416
< Text
407
417
x = { - xMax / 2 }
408
- y = '15'
409
- transform = ' rotate(-90)'
418
+ y = "15"
419
+ transform = " rotate(-90)"
410
420
fontSize = { 12 }
411
- fill = ' #FFFFFF'
421
+ fill = " #FFFFFF"
412
422
>
413
423
Rendering Time (ms)
414
424
</ Text >
415
- < Text x = { xMax / 2 } y = { yMax + 65 } fontSize = { 12 } fill = ' #FFFFFF' >
425
+ < Text x = { xMax / 2 } y = { yMax + 65 } fontSize = { 12 } fill = " #FFFFFF" >
416
426
Series ID
417
427
</ Text >
418
428
</ svg >
0 commit comments