1
1
// @ts -nocheck
2
2
import React , { useEffect , useState } from 'react' ;
3
3
import { BarStack } from '@visx/shape' ;
4
+ import { Bar } from '@visx/shape' ;
4
5
import { SeriesPoint } from '@visx/shape/lib/types' ;
5
6
import { Group } from '@visx/group' ;
6
7
import { Grid } from '@visx/grid' ;
@@ -61,7 +62,7 @@ const tooltipStyles = {
61
62
62
63
const BarGraph = props => {
63
64
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
64
- const { width, height, data, comparison, setRoute, allRoutes, filteredSnapshots } = props ;
65
+ const { width, height, data, comparison, setRoute, allRoutes, filteredSnapshots, setSnapshot } = props ;
65
66
const [ seriesNameInput , setSeriesNameInput ] = useState ( `Series ${ comparison . length + 1 } ` ) ;
66
67
const {
67
68
tooltipOpen,
@@ -76,13 +77,78 @@ const BarGraph = props => {
76
77
detectBounds : true ,
77
78
scroll : true ,
78
79
} ) ;
80
+
81
+ const HorizontalGraph = ( ) => {
82
+ // data.barStack =
83
+ // [{snapshot: 1.0,
84
+ // box1: 5.4,
85
+ // box2: 3.7
86
+ // box3: 2.3
87
+ // box4: 5.9,
88
+ // box5: 3.5
89
+ // box6: 2.9
90
+ // }]
91
+
92
+ // width = 50
93
+ // -xxxxx-xxxxx
94
+ const BarArray = [ ] ;
95
+ // []
96
+ //-----------:: :: 3 4
97
+ let i = 0 ;
98
+ let barWidth = ( xMax / ( Object . keys ( data . barStack [ 0 ] ) . length ) + 5 ) ;
99
+ console . log ( data , '<-- data from snapshot' ) ;
100
+ for ( const [ key , value ] of Object . entries ( data . barStack [ 0 ] ) ) {
101
+ if ( key !== 'snapshotId' && key !== 'route' ) {
102
+ console . log ( `${ key } : ${ value } ` ) ;
103
+ BarArray . push ( < Bar
104
+ x = { 10 + 10 * i + barWidth * i }
105
+ y = { yMax - value * 25 }
106
+ height = { value * 25 }
107
+ key = { key }
108
+ width = { barWidth }
109
+ fill = "rgba(23, 233, 217, .5)"
110
+ onMouseLeave = { ( ) => {
111
+ dispatch (
112
+ onHoverExit ( data . componentData [ key ] . rtid ) ,
113
+ ( tooltipTimeout = window . setTimeout ( ( ) => {
114
+ hideTooltip ( ) ;
115
+ } , 300 ) ) ,
116
+ ) ;
117
+ } }
118
+ // Cursor position in window updates position of the tool tip.
119
+ onMouseMove = { event => {
120
+ console . log ( event , '<-- event from onMouseMove' )
121
+ console . log ( key , '<--key from onMouseMove' ) ;
122
+ dispatch ( onHover ( data . componentData [ key ] . rtid ) ) ;
123
+ if ( tooltipTimeout ) clearTimeout ( tooltipTimeout ) ;
124
+ const top = event . clientY - margin . top - value * 25 ;
125
+ const left = 10 + 10 * i + barWidth * i + barWidth / 2 ;
126
+ showTooltip ( {
127
+ tooltipData : value ,
128
+ tooltipTop : top ,
129
+ tooltipLeft : left ,
130
+ } ) ;
131
+ } }
132
+ /> ) ;
133
+ }
134
+ i ++ ;
135
+ }
136
+ console . log ( BarArray , '<-- barArray' ) ;
137
+ return BarArray ;
138
+ } ;
79
139
const keys = Object . keys ( data . componentData ) ;
80
- console . log ( 'this is data in barGraph.tsx: ' , data ) ;
81
- console . log ( 'these are the data\'s keys: ' , keys ) ;
140
+ // console.log('this is data in barGraph.tsx: ', data);
141
+ // console.log('these are the data\'s keys: ', keys);
82
142
83
143
// data accessor (used to generate scales) and formatter (add units for on hover box)
84
144
const getSnapshotId = ( d : snapshot ) => {
85
- console . log ( 'snapshot object here: ' , d ) ;
145
+ //d coming from data.barstack post filtered data
146
+ //Object.keys(data.barStack[0]).map(keys => if ())
147
+ console . log ( 'snapshot object here from getSnapshotId: ' , d ) ;
148
+ return d . snapshotId ;
149
+ } ;
150
+ const getComponentKeys = d => {
151
+ console . log ( 'snapshot object here from getComponentKeys: ' , d ) ;
86
152
return d . snapshotId ;
87
153
} ;
88
154
const formatSnapshotId = id => `Snapshot ID: ${ id } ` ;
@@ -161,7 +227,10 @@ const BarGraph = props => {
161
227
< select
162
228
labelId = "demo-simple-select-label"
163
229
id = "routes-select"
164
- onChange = { e => setRoute ( e . target . value ) }
230
+ onChange = { e => {
231
+ setSnapshot ( 'All Snapshots' ) ;
232
+ setRoute ( e . target . value ) ;
233
+ } }
165
234
>
166
235
< option >
167
236
All Routes
@@ -178,7 +247,7 @@ const BarGraph = props => {
178
247
< select
179
248
labelId = "demo-simple-select-label"
180
249
id = "routes-select"
181
- onChange = { e => setSnapshot ( e . target . value ) }
250
+ onChange = { e => setSnapshot ( e . target . value ) }
182
251
>
183
252
< option >
184
253
All Snapshots
@@ -211,57 +280,68 @@ const BarGraph = props => {
211
280
strokeOpacity = { 0.1 }
212
281
xOffset = { snapshotIdScale . bandwidth ( ) / 2 }
213
282
/>
283
+ { console . log ( 'this is from the BarStack graph' ) }
214
284
< Group top = { margin . top } left = { margin . left } >
215
- < BarStack
216
- data = { data . barStack }
217
- keys = { keys }
218
- x = { getSnapshotId }
219
- xScale = { snapshotIdScale }
220
- yScale = { renderingScale }
221
- color = { colorScale }
222
- >
223
- { barStacks => barStacks . map ( barStack => barStack . bars . map ( ( bar , idx ) => {
224
- console . log ( width , '<-- width' ) ;
225
- console . log ( height , '<-- height' ) ;
226
- console . log ( bar , '<-- bar' ) ;
227
- // Hides new components if components don't exist in previous snapshots.
228
- if ( Number . isNaN ( bar . bar [ 1 ] ) || bar . height < 0 ) {
229
- bar . height = 0 ;
230
- }
231
- return (
232
- < rect
233
- key = { `bar-stack-${ bar . bar . data . snapshotId } -${ bar . key } ` }
234
- x = { bar . x }
235
- y = { bar . y }
236
- height = { bar . height === 0 ? null : bar . height }
237
- width = { bar . width }
238
- fill = { bar . color }
239
- /* TIP TOOL EVENT HANDLERS */
240
- // Hides tool tip once cursor moves off the current rect.
241
- onMouseLeave = { ( ) => {
242
- dispatch (
243
- onHoverExit ( data . componentData [ bar . key ] . rtid ) ,
244
- ( tooltipTimeout = window . setTimeout ( ( ) => {
245
- hideTooltip ( ) ;
246
- } , 300 ) ) ,
247
- ) ;
248
- } }
249
- // Cursor position in window updates position of the tool tip.
250
- onMouseMove = { event => {
251
- dispatch ( onHover ( data . componentData [ bar . key ] . rtid ) ) ;
252
- if ( tooltipTimeout ) clearTimeout ( tooltipTimeout ) ;
253
- const top = event . clientY - margin . top - bar . height ;
254
- const left = bar . x + bar . width / 2 ;
255
- showTooltip ( {
256
- tooltipData : bar ,
257
- tooltipTop : top ,
258
- tooltipLeft : left ,
259
- } ) ;
260
- } }
261
- />
262
- ) ;
263
- } ) ) }
264
- </ BarStack >
285
+ { data . barStack . length > 1 ? (
286
+ < BarStack
287
+ data = { data . barStack }
288
+ keys = { keys }
289
+ x = { getSnapshotId }
290
+ xScale = { snapshotIdScale }
291
+ yScale = { renderingScale }
292
+ color = { colorScale }
293
+ >
294
+ { barStacks => barStacks . map ( barStack => barStack . bars . map ( ( bar , idx ) => {
295
+ console . log ( filteredSnapshots , '<-- filtered snap shots' ) ;
296
+ console . log ( data , '<-- data from barStacks' ) ;
297
+ console . log ( data . barStack , '<-- data.barstack' ) ;
298
+ console . log ( barStacks , '<--barStacks' ) ;
299
+ console . log ( width , '<-- width' ) ;
300
+ console . log ( height , '<-- height' ) ;
301
+ console . log ( bar , '<-- bar' ) ;
302
+ // Hides new components if components don't exist in previous snapshots.
303
+ if ( Number . isNaN ( bar . bar [ 1 ] ) || bar . height < 0 ) {
304
+ bar . height = 0 ;
305
+ }
306
+ return (
307
+ < rect
308
+ key = { `bar-stack-${ bar . bar . data . snapshotId } -${ bar . key } ` }
309
+ x = { bar . x }
310
+ y = { bar . y }
311
+ height = { bar . height === 0 ? null : bar . height }
312
+ width = { bar . width }
313
+ fill = { bar . color }
314
+ /* TIP TOOL EVENT HANDLERS */
315
+ // Hides tool tip once cursor moves off the current rect.
316
+ onMouseLeave = { ( ) => {
317
+ dispatch (
318
+ onHoverExit ( data . componentData [ bar . key ] . rtid ) ,
319
+ ( tooltipTimeout = window . setTimeout ( ( ) => {
320
+ hideTooltip ( ) ;
321
+ } , 300 ) ) ,
322
+ ) ;
323
+ } }
324
+ // Cursor position in window updates position of the tool tip.
325
+ onMouseMove = { event => {
326
+ dispatch ( onHover ( data . componentData [ bar . key ] . rtid ) ) ;
327
+ if ( tooltipTimeout ) clearTimeout ( tooltipTimeout ) ;
328
+ const top = event . clientY - margin . top - bar . height ;
329
+ const left = bar . x + bar . width / 2 ;
330
+ showTooltip ( {
331
+ tooltipData : bar ,
332
+ tooltipTop : top ,
333
+ tooltipLeft : left ,
334
+ } ) ;
335
+ } }
336
+ />
337
+ ) ;
338
+ } ) ) }
339
+ </ BarStack >
340
+ )
341
+ : (
342
+ HorizontalGraph ( )
343
+ )
344
+ }
265
345
</ Group >
266
346
< AxisLeft
267
347
top = { margin . top }
0 commit comments