1
1
// @ts -nocheck
2
- import React from 'react' ;
2
+ import React , { useEffect } 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' ;
@@ -14,6 +14,7 @@ import Select from '@material-ui/core/Select';
14
14
import InputLabel from '@material-ui/core/InputLabel' ;
15
15
import MenuItem from '@material-ui/core/MenuItem' ;
16
16
import FormControl from '@material-ui/core/FormControl' ;
17
+ import FormHelperText from '@material-ui/core/FormHelperText' ;
17
18
import snapshots from './snapshots' ;
18
19
import { onHover , onHoverExit } from '../actions/actions' ;
19
20
import { useStoreContext } from '../store' ;
@@ -71,11 +72,30 @@ const BarGraphComparison = (props) => {
71
72
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
72
73
const { width, height, data, comparison } = props ;
73
74
74
- console . log ( 'comparison >>>' , comparison ) ;
75
+ const [ series , setSeries ] = React . useState ( 0 ) ;
76
+ const [ open , setOpen ] = React . useState ( false ) ;
77
+ const [ maxRender , setMaxRender ] = React . useState ( data . maxTotalRender ) ;
78
+
79
+ // console.log('comparison >>>', comparison);
80
+ // console.log('tabs[currentTab] >>>', tabs[currentTab]);
81
+ // console.log('props in comparison graph >>>', props);
82
+ // console.log('data >>>>>', data);
83
+ // change scale of graph based on clicking of forward and backwards buttons effect
84
+ // useEffect(() => {
85
+ // console.log('setSeries is changing everytime currentIndex changes');
86
+ // //change the state with setChangeSeries
87
+ // setSeries(tabs[currentTab].sliderIndex);
88
+ // }, [tabs[currentTab].sliderIndex]);
75
89
90
+ // console.log('tabs in Bargraphs comparison >>', tabs);
91
+ function titleFilter ( comparisonArray ) {
92
+ return comparisonArray . filter (
93
+ ( elem ) => elem . title === tabs [ currentTab ] . title
94
+ ) ;
95
+ }
76
96
// console.log('tabs in BGComp >>>', tabs);
77
97
const currentIndex = tabs [ currentTab ] . sliderIndex ;
78
- console . log ( 'sliderIndx outside of bargraph >>>' , currentIndex ) ;
98
+ // console.log('sliderIndx outside of bargraph >>>', currentIndex);
79
99
const {
80
100
tooltipOpen,
81
101
tooltipLeft,
@@ -92,31 +112,54 @@ const BarGraphComparison = (props) => {
92
112
93
113
// data accessor (used to generate scales) and formatter (add units for on hover box)
94
114
const getSnapshotId = ( d : snapshot ) => d . snapshotId ;
95
- const getSeriesId = ( d : series ) => d . currentTab ;
115
+ // const getSeriesId = (d: series) => d.currentTab;
96
116
const formatSnapshotId = ( id ) => `Snapshot ID: ${ id } ` ;
97
117
const formatRenderTime = ( time ) => `${ time } ms ` ;
98
118
99
119
// create visualization SCALES with cleaned data
100
120
const snapshotIdScale = scaleBand < string > ( {
101
- domain : getSnapshotId ( data . barStack [ currentIndex ] ) ,
121
+ // domain: getSnapshotId(data.barStack[currentIndex]),
122
+ // domain: [currentTab, comparison[series].currentTab],
123
+ domain : [
124
+ `Series ${ ! currentTab ? null : currentTab } (Current Tab)` ,
125
+ `Series ${ ! comparison [ series ] ? null : comparison [ series ] . currentTab } ` ,
126
+ ] ,
102
127
padding : 0.2 ,
103
128
} ) ;
104
129
130
+ const calculateMaxTotalRender = ( series ) => {
131
+ const currentSeriesBarStacks = ! comparison [ series ]
132
+ ? [ ]
133
+ : comparison [ series ] . data . barStack ;
134
+ console . log (
135
+ 'currentSeriesBarStacks index in Max func' ,
136
+ currentSeriesBarStacks [ series ]
137
+ ) ;
138
+ let renderTimes = Object . values ( currentSeriesBarStacks [ series ] ) ;
139
+ renderTimes = renderTimes . slice ( 1 ) ;
140
+ // console.log('RendERrrrTimes', renderTimes);
141
+ const renderTotal = renderTimes . reduce ( ( a , b ) => a + b ) ;
142
+ // console.log('renderTotal', renderTotal);
143
+ return renderTotal ;
144
+ } ;
145
+
105
146
const renderingScale = scaleLinear < number > ( {
106
- domain : [ 0 , data . maxTotalRender ] ,
147
+ domain : [ 0 , Math . max ( calculateMaxTotalRender ( series ) , data . maxTotalRender ) ] ,
107
148
nice : true ,
108
149
} ) ;
109
- `` ;
150
+
110
151
const colorScale = scaleOrdinal < string > ( {
111
152
domain : keys ,
112
153
range : schemeSet3 ,
113
154
} ) ;
114
155
156
+ // console.log('rendering scale invocation', renderingScale);
115
157
// setting max dimensions and scale ranges
116
158
const xMax = width - margin . left - margin . right ;
117
159
const yMax = height - margin . top - 150 ;
118
160
snapshotIdScale . rangeRound ( [ 0 , xMax ] ) ;
119
161
renderingScale . range ( [ yMax , 0 ] ) ;
162
+
120
163
// const filterSeries = (comparisonArray) => {
121
164
// return comparisonArray.map((sessionName, idx) => {
122
165
// return <MenuItem>{sessionName}</MenuItem>;
@@ -126,19 +169,21 @@ const BarGraphComparison = (props) => {
126
169
const useStyles = makeStyles ( ( theme ) => ( {
127
170
formControl : {
128
171
margin : theme . spacing ( 1 ) ,
129
- minWidth : 120 ,
130
- color : 'white' ,
172
+ minWidth : 150 ,
173
+ border : '1px solid grey' ,
174
+ borderRadius : 4 ,
175
+ borderColor : 'grey' ,
131
176
} ,
132
177
} ) ) ;
133
178
134
179
const classes = useStyles ( ) ;
135
- const [ series , setSeries ] = React . useState ( 0 ) ;
136
- const [ open , setOpen ] = React . useState ( false ) ;
137
180
138
181
const handleChange = ( event ) => {
139
- console . log ( 'Series is : ' , series ) ;
140
182
setSeries ( event . target . value ) ;
141
- console . log ( 'Series is after click:' , series ) ;
183
+ const renderTime = calculateMaxTotalRender ( series ) ;
184
+ console . log ( 'handleCh renderTime' , renderTime ) ;
185
+ // setMaxRender(renderTime);
186
+ console . log ( 'maxRender' , maxRender ) ;
142
187
} ;
143
188
144
189
const handleClose = ( ) => {
@@ -158,27 +203,30 @@ const BarGraphComparison = (props) => {
158
203
159
204
return (
160
205
< div >
161
- < h1 > { `Current Snapshot: ${ currentIndex + 1 } ` } </ h1 >
162
- < FormControl className = { classes . formControl } >
163
- < InputLabel id = "demo-controlled-open-select-label" >
164
- Select Series
165
- </ InputLabel >
206
+ { /* <h1>{`Current Snapshot: ${currentIndex + 1}`}</h1> */ }
207
+ < FormHelperText style = { { color : 'white' } } > Select Series</ FormHelperText >
208
+ < FormControl variant = "outlined" className = { classes . formControl } >
166
209
< Select
167
- labelId = "demo-controlled-open-select-label whi"
168
- id = "demo-controlled-open-select"
210
+ style = { { color : 'white' } }
211
+ labelId = "simple-select-outlined-label"
212
+ id = "simple-select-outlined"
169
213
open = { open }
170
214
onClose = { handleClose }
171
215
onOpen = { handleOpen }
172
216
value = { series }
217
+ //data={data.barStack}
218
+ // value={titleFilter(comparison)}
173
219
onChange = { handleChange }
174
220
>
175
- { comparison . map ( ( tabElem , index ) => {
176
- return (
177
- < MenuItem value = { index } >
178
- { `Series ${ tabElem . currentTab } ` }
179
- </ MenuItem >
180
- ) ;
181
- } ) }
221
+ { ! comparison
222
+ ? null
223
+ : titleFilter ( comparison ) . map ( ( tabElem , index ) => {
224
+ return (
225
+ < MenuItem value = { index } >
226
+ { `Series ${ tabElem . currentTab } ` }
227
+ </ MenuItem >
228
+ ) ;
229
+ } ) }
182
230
</ Select >
183
231
</ FormControl >
184
232
< svg ref = { containerRef } width = { width } height = { height } >
@@ -216,13 +264,15 @@ const BarGraphComparison = (props) => {
216
264
>
217
265
{ ( barStacks ) =>
218
266
barStacks . map ( ( barStack , idx ) => {
267
+ console . log ( 'maxTotalRender 1st Barstack' , data . maxTotalRender ) ;
219
268
const bar = barStack . bars [ currentIndex ] ;
220
- console . log ( 'data.barStack >>>' , data . barStack ) ;
269
+ // console.log('Y SCALEEE', barStacks);
270
+ // console.log('data.barStack >>>', data.barStack);
221
271
222
272
return (
223
273
< rect
224
274
key = { `bar-stack-${ idx } -NewView` }
225
- x = { 300 }
275
+ x = { bar . x + 50 }
226
276
y = { bar . y }
227
277
height = { bar . height === 0 ? null : bar . height }
228
278
width = { bar . width }
@@ -256,11 +306,11 @@ const BarGraphComparison = (props) => {
256
306
</ BarStack >
257
307
< BarStack
258
308
// Comparison Barstack
259
- data = { ! comparison ? [ ] : comparison [ series ] . data . barStack }
309
+ data = { ! comparison [ series ] ? [ ] : comparison [ series ] . data . barStack }
260
310
// data={data.barStack}
261
311
keys = { keys }
262
- // x={getSnapshotId}
263
312
x = { getSnapshotId }
313
+ // x={getSeriesId}
264
314
xScale = { snapshotIdScale }
265
315
yScale = { renderingScale }
266
316
color = { colorScale }
@@ -270,12 +320,12 @@ const BarGraphComparison = (props) => {
270
320
if ( ! barStack . bars [ currentIndex ] ) {
271
321
return < h1 > No Comparison</ h1 > ;
272
322
}
273
- console . log ( 'barStacks in Comparison' , barStacks ) ;
323
+ // console.log('barStacks in Comparison', barStacks);
274
324
const bar = barStack . bars [ currentIndex ] ;
275
325
return (
276
326
< rect
277
327
key = { `bar-stack-${ idx } -${ bar . index } ` }
278
- x = { bar . x + 50 }
328
+ x = { 300 }
279
329
y = { bar . y }
280
330
height = { bar . height === 0 ? null : bar . height }
281
331
width = { bar . width }
0 commit comments