Skip to content

Commit b0a7a75

Browse files
author
Kevin Ngo
committed
Add function to calculate total render time for comparison bar graph (incomplete)
1 parent 2331a42 commit b0a7a75

File tree

1 file changed

+83
-33
lines changed

1 file changed

+83
-33
lines changed

src/app/components/BarGraphComparison.tsx

Lines changed: 83 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-nocheck
2-
import React from 'react';
2+
import React, { useEffect } from 'react';
33
import { BarStack } from '@visx/shape';
44
import { SeriesPoint } from '@visx/shape/lib/types';
55
import { Group } from '@visx/group';
@@ -14,6 +14,7 @@ import Select from '@material-ui/core/Select';
1414
import InputLabel from '@material-ui/core/InputLabel';
1515
import MenuItem from '@material-ui/core/MenuItem';
1616
import FormControl from '@material-ui/core/FormControl';
17+
import FormHelperText from '@material-ui/core/FormHelperText';
1718
import snapshots from './snapshots';
1819
import { onHover, onHoverExit } from '../actions/actions';
1920
import { useStoreContext } from '../store';
@@ -71,11 +72,30 @@ const BarGraphComparison = (props) => {
7172
const [{ tabs, currentTab }, dispatch] = useStoreContext();
7273
const { width, height, data, comparison } = props;
7374

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]);
7589

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+
}
7696
// console.log('tabs in BGComp >>>', tabs);
7797
const currentIndex = tabs[currentTab].sliderIndex;
78-
console.log('sliderIndx outside of bargraph >>>', currentIndex);
98+
// console.log('sliderIndx outside of bargraph >>>', currentIndex);
7999
const {
80100
tooltipOpen,
81101
tooltipLeft,
@@ -92,31 +112,54 @@ const BarGraphComparison = (props) => {
92112

93113
// data accessor (used to generate scales) and formatter (add units for on hover box)
94114
const getSnapshotId = (d: snapshot) => d.snapshotId;
95-
const getSeriesId = (d: series) => d.currentTab;
115+
// const getSeriesId = (d: series) => d.currentTab;
96116
const formatSnapshotId = (id) => `Snapshot ID: ${id}`;
97117
const formatRenderTime = (time) => `${time} ms `;
98118

99119
// create visualization SCALES with cleaned data
100120
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+
],
102127
padding: 0.2,
103128
});
104129

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+
105146
const renderingScale = scaleLinear<number>({
106-
domain: [0, data.maxTotalRender],
147+
domain: [0, Math.max(calculateMaxTotalRender(series), data.maxTotalRender)],
107148
nice: true,
108149
});
109-
``;
150+
110151
const colorScale = scaleOrdinal<string>({
111152
domain: keys,
112153
range: schemeSet3,
113154
});
114155

156+
// console.log('rendering scale invocation', renderingScale);
115157
// setting max dimensions and scale ranges
116158
const xMax = width - margin.left - margin.right;
117159
const yMax = height - margin.top - 150;
118160
snapshotIdScale.rangeRound([0, xMax]);
119161
renderingScale.range([yMax, 0]);
162+
120163
// const filterSeries = (comparisonArray) => {
121164
// return comparisonArray.map((sessionName, idx) => {
122165
// return <MenuItem>{sessionName}</MenuItem>;
@@ -126,19 +169,21 @@ const BarGraphComparison = (props) => {
126169
const useStyles = makeStyles((theme) => ({
127170
formControl: {
128171
margin: theme.spacing(1),
129-
minWidth: 120,
130-
color: 'white',
172+
minWidth: 150,
173+
border: '1px solid grey',
174+
borderRadius: 4,
175+
borderColor: 'grey',
131176
},
132177
}));
133178

134179
const classes = useStyles();
135-
const [series, setSeries] = React.useState(0);
136-
const [open, setOpen] = React.useState(false);
137180

138181
const handleChange = (event) => {
139-
console.log('Series is : ', series);
140182
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);
142187
};
143188

144189
const handleClose = () => {
@@ -158,27 +203,30 @@ const BarGraphComparison = (props) => {
158203

159204
return (
160205
<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}>
166209
<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"
169213
open={open}
170214
onClose={handleClose}
171215
onOpen={handleOpen}
172216
value={series}
217+
//data={data.barStack}
218+
// value={titleFilter(comparison)}
173219
onChange={handleChange}
174220
>
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+
})}
182230
</Select>
183231
</FormControl>
184232
<svg ref={containerRef} width={width} height={height}>
@@ -216,13 +264,15 @@ const BarGraphComparison = (props) => {
216264
>
217265
{(barStacks) =>
218266
barStacks.map((barStack, idx) => {
267+
console.log('maxTotalRender 1st Barstack', data.maxTotalRender);
219268
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);
221271

222272
return (
223273
<rect
224274
key={`bar-stack-${idx}-NewView`}
225-
x={300}
275+
x={bar.x + 50}
226276
y={bar.y}
227277
height={bar.height === 0 ? null : bar.height}
228278
width={bar.width}
@@ -256,11 +306,11 @@ const BarGraphComparison = (props) => {
256306
</BarStack>
257307
<BarStack
258308
// Comparison Barstack
259-
data={!comparison ? [] : comparison[series].data.barStack}
309+
data={!comparison[series] ? [] : comparison[series].data.barStack}
260310
// data={data.barStack}
261311
keys={keys}
262-
// x={getSnapshotId}
263312
x={getSnapshotId}
313+
// x={getSeriesId}
264314
xScale={snapshotIdScale}
265315
yScale={renderingScale}
266316
color={colorScale}
@@ -270,12 +320,12 @@ const BarGraphComparison = (props) => {
270320
if (!barStack.bars[currentIndex]) {
271321
return <h1>No Comparison</h1>;
272322
}
273-
console.log('barStacks in Comparison', barStacks);
323+
// console.log('barStacks in Comparison', barStacks);
274324
const bar = barStack.bars[currentIndex];
275325
return (
276326
<rect
277327
key={`bar-stack-${idx}-${bar.index}`}
278-
x={bar.x + 50}
328+
x={300}
279329
y={bar.y}
280330
height={bar.height === 0 ? null : bar.height}
281331
width={bar.width}

0 commit comments

Comments
 (0)