Skip to content

Commit 60760a7

Browse files
committed
Figuring out barstack in progress
1 parent 81699fb commit 60760a7

File tree

2 files changed

+34
-57
lines changed

2 files changed

+34
-57
lines changed

src/app/components/BarGraphComparisonActions.tsx

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const tooltipStyles = {
6767
fontFamily: 'Roboto',
6868
};
6969

70-
const BarGraphComparison = props => {
70+
const BarGraphComparisonActions = props => {
7171
const [{ tabs, currentTab }, dispatch] = useStoreContext();
7272
const {
7373
width, height, data, comparison, setSeries, series, setAction
@@ -77,13 +77,7 @@ const BarGraphComparison = props => {
7777
const [open, setOpen] = React.useState(false);
7878
const [picOpen, setPicOpen] = React.useState(false);
7979
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+
8781
const currentIndex = tabs[currentTab].sliderIndex;
8882

8983
const {
@@ -97,44 +91,41 @@ const BarGraphComparison = props => {
9791
let tooltipTimeout: number;
9892

9993
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');
10395
// data accessor (used to generate scales) and formatter (add units for on hover box)
10496
const getSnapshotId = (d: snapshot) => d.snapshotId;
10597
const formatSnapshotId = id => `Snapshot ID: ${id}`;
10698
const formatRenderTime = time => `${time} ms `;
107-
const getCurrentTab = storedSeries => storedSeries.currentTab;
99+
const getSeriesName = action => action.seriesName;
108100

109101
// create visualization SCALES with cleaned data
110102
// 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),
114105
padding: 0.2,
115106
});
116107
// This function will iterate through the snapshots of the series,
117108
// and grab the highest render times (sum of all component times).
118109
// We'll then use it in the renderingScale function and compare
119110
// with the render time of the current tab.
120111
// 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 = () => {
126113
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;
131122
}
132123
return currentMax;
133124
};
134125

135126
// 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)],
138129
nice: true,
139130
});
140131
// the domain array will assign each key a different color to make rectangle boxes
@@ -147,7 +138,7 @@ const BarGraphComparison = props => {
147138
// setting max dimensions and scale ranges
148139
const xMax = width - margin.left - margin.right;
149140
const yMax = height - margin.top - 200;
150-
snapshotIdScale.rangeRound([0, xMax]);
141+
seriesNameScale.rangeRound([0, xMax]);
151142
renderingScale.range([yMax, 0]);
152143

153144
// useStyles will change the styling on save series dropdown feature
@@ -189,7 +180,6 @@ const BarGraphComparison = props => {
189180
const handleActionChange = event => {
190181
setAction(event.target.value);
191182
setSeries(false);
192-
console.log(event.target.value)
193183
// setXpoints();
194184
};
195185

@@ -203,23 +193,7 @@ const BarGraphComparison = props => {
203193
// setXpoints();
204194
};
205195

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+
223197
const animateButton = function (e) {
224198
e.preventDefault;
225199
e.target.classList.add('animate');
@@ -241,20 +215,21 @@ const BarGraphComparison = props => {
241215
for (let i = 0; i < testList.length; i++) {
242216
if (testList[i] !== "" && !finalList.includes(testList[i])) finalList.push(testList[i]);
243217
}
244-
console.log('Final List', finalList)
218+
219+
console.log(data);
220+
console.log(keys);
245221

246222
return (
247223
<div>
248224
<div className="series-options-container">
249-
250225
<div className="dropdown-and-delete-series-container">
251226
<button
252227
className="delete-button"
253228
onClick={e => {
254229
dispatch(deleteSeries());
255230
}}
256231
>
257-
Clear All Series1
232+
Clear All Series
258233
</button>
259234
<h4 style={{ padding: '0 1rem' }}>Compare Series: </h4>
260235
<FormControl variant="outlined" className={classes.formControl}>
@@ -320,25 +295,26 @@ const BarGraphComparison = props => {
320295
<Grid
321296
top={margin.top}
322297
left={margin.left}
323-
xScale={snapshotIdScale}
298+
xScale={seriesNameScale}
324299
yScale={renderingScale}
325300
width={xMax}
326301
height={yMax}
327302
stroke="black"
328303
strokeOpacity={0.1}
329-
xOffset={snapshotIdScale.bandwidth() / 2}
304+
xOffset={seriesNameScale.bandwidth() / 2}
330305
/>
331306
<Group top={margin.top} left={margin.left}>
332307
<BarStack
333-
data={data.barStack}
308+
data={data}
334309
keys={keys}
335-
x={getSnapshotId}
336-
xScale={snapshotIdScale}
310+
x={getSeriesName}
311+
xScale={seriesNameScale}
337312
yScale={renderingScale}
338313
color={colorScale}
339314
>
340315
{barStacks => barStacks.map(barStack => barStack.bars.map((bar, idx) => {
341-
console.log(bar)
316+
console.log('barstack', barStack)
317+
console.log('bar', bar)
342318
// Hides new components if components don't exist in previous snapshots.
343319
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
344320
bar.height = 0;
@@ -395,7 +371,7 @@ const BarGraphComparison = props => {
395371
<AxisBottom
396372
top={yMax + margin.top}
397373
left={margin.left}
398-
scale={snapshotIdScale}
374+
scale={seriesNameScale}
399375
stroke={axisColor}
400376
tickStroke={axisColor}
401377
strokeWidth={2}
@@ -449,4 +425,4 @@ const BarGraphComparison = props => {
449425
);
450426
};
451427

452-
export default BarGraphComparison;
428+
export default BarGraphComparisonActions;

src/app/components/PerformanceVisx.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,13 @@ const PerformanceVisx = (props: BarStackProps) => {
255255
return (
256256
<BarGraphComparisonActions
257257
// comparison={allStorage()}
258-
data={data}
258+
data={getActions()}
259259
width={width}
260260
height={height}
261261
setSeries={setSeries}
262262
action={action}
263263
setAction={setAction}
264+
comparison={allStorage()}
264265
/>
265266
);
266267
};

0 commit comments

Comments
 (0)