Skip to content

Commit 52ee002

Browse files
authored
Merge pull request #8 from oslabs-beta/staging
2 parents 009f5d4 + 6165841 commit 52ee002

File tree

5 files changed

+299
-190
lines changed

5 files changed

+299
-190
lines changed

src/app/components/BarGraph.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ const BarGraph = (props) => {
7070
showTooltip,
7171
} = useTooltip<TooltipData>();
7272
let tooltipTimeout: number;
73-
const { containerRef, TooltipInPortal } = useTooltipInPortal();
73+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
74+
detectBounds: true,
75+
scroll: true,
76+
});
7477

7578
const keys = Object.keys(data.componentData);
7679

@@ -139,9 +142,10 @@ const BarGraph = (props) => {
139142
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
140143
bar.height = 0;
141144
}
145+
console.log('bar in BarGraph.tsx', bar);
142146
return (
143147
<rect
144-
key={`bar-stack-${barStack.index}-${bar.index}`}
148+
key={`bar-stack-${barStack.id}-${bar.id}`}
145149
x={bar.x}
146150
y={bar.y}
147151
height={bar.height === 0 ? null : bar.height}

src/app/components/BarGraphComparison.tsx

Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { AxisBottom, AxisLeft } from '@visx/axis';
88
import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
99
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
1010
import { Text } from '@visx/text';
11+
1112
import { schemeSet3 } from 'd3-scale-chromatic';
1213
import { makeStyles } from '@material-ui/core/styles';
1314
import Select from '@material-ui/core/Select';
@@ -18,7 +19,6 @@ import FormHelperText from '@material-ui/core/FormHelperText';
1819
import snapshots from './snapshots';
1920
import { onHover, onHoverExit } from '../actions/actions';
2021
import { useStoreContext } from '../store';
21-
2222
/* TYPESCRIPT */
2323
interface data {
2424
snapshotId?: string;
@@ -112,7 +112,6 @@ const BarGraphComparison = (props) => {
112112

113113
// data accessor (used to generate scales) and formatter (add units for on hover box)
114114
const getSnapshotId = (d: snapshot) => d.snapshotId;
115-
// const getSeriesId = (d: series) => d.currentTab;
116115
const formatSnapshotId = (id) => `Snapshot ID: ${id}`;
117116
const formatRenderTime = (time) => `${time} ms `;
118117

@@ -121,8 +120,8 @@ const BarGraphComparison = (props) => {
121120
// domain: getSnapshotId(data.barStack[currentIndex]),
122121
// domain: [currentTab, comparison[series].currentTab],
123122
domain: [
124-
`Series ${!currentTab ? null : currentTab} (Current Tab)`,
125-
`Series ${!comparison[series] ? null : comparison[series].currentTab}`,
123+
`Current Tab Series`,
124+
`Series ${!comparison[series] ? null : series + 1}`,
126125
],
127126
padding: 0.2,
128127
});
@@ -131,16 +130,14 @@ const BarGraphComparison = (props) => {
131130
const currentSeriesBarStacks = !comparison[series]
132131
? []
133132
: 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;
133+
if (currentSeriesBarStacks.length === 0) return 0;
134+
let currentMax = -Infinity;
135+
for (let i = 0; i < currentSeriesBarStacks.length; i += 1) {
136+
const renderTimes = Object.values(currentSeriesBarStacks[i]).slice(1);
137+
const renderTotal = renderTimes.reduce((acc, curr) => acc + curr);
138+
if (renderTotal > currentMax) currentMax = renderTotal;
139+
}
140+
return currentMax;
144141
};
145142

146143
const renderingScale = scaleLinear<number>({
@@ -169,21 +166,26 @@ const BarGraphComparison = (props) => {
169166
const useStyles = makeStyles((theme) => ({
170167
formControl: {
171168
margin: theme.spacing(1),
172-
minWidth: 150,
169+
minWidth: 80,
170+
// padding: '0.5rem',
171+
height: 30,
172+
},
173+
select: {
174+
minWidth: 80,
173175
border: '1px solid grey',
174176
borderRadius: 4,
175-
borderColor: 'grey',
177+
color: 'grey',
178+
height: 30,
176179
},
177180
}));
178181

179182
const classes = useStyles();
180183

181184
const handleChange = (event) => {
182185
setSeries(event.target.value);
183-
const renderTime = calculateMaxTotalRender(series);
184-
console.log('handleCh renderTime', renderTime);
185-
// setMaxRender(renderTime);
186-
console.log('maxRender', maxRender);
186+
// console.log('handleCh renderTime', renderTime);
187+
// // setMaxRender(renderTime);
188+
// console.log('maxRender', maxRender);
187189
};
188190

189191
const handleClose = () => {
@@ -204,31 +206,52 @@ const BarGraphComparison = (props) => {
204206
return (
205207
<div>
206208
{/* <h1>{`Current Snapshot: ${currentIndex + 1}`}</h1> */}
207-
<FormHelperText style={{ color: 'white' }}> Select Series</FormHelperText>
208-
<FormControl variant="outlined" className={classes.formControl}>
209-
<Select
210-
style={{ color: 'white' }}
211-
labelId="simple-select-outlined-label"
212-
id="simple-select-outlined"
213-
open={open}
214-
onClose={handleClose}
215-
onOpen={handleOpen}
216-
value={series}
217-
//data={data.barStack}
218-
// value={titleFilter(comparison)}
219-
onChange={handleChange}
220-
>
221-
{!comparison
222-
? null
223-
: titleFilter(comparison).map((tabElem, index) => {
224-
return (
225-
<MenuItem value={index}>
226-
{`Series ${tabElem.currentTab}`}
227-
</MenuItem>
228-
);
229-
})}
230-
</Select>
231-
</FormControl>
209+
{/* <div class="dropdown dropdown-dark">
210+
<select name="two" class="dropdown-select">
211+
{!comparison[series] ? (
212+
<option value={series}>No series available</option>
213+
) : (
214+
titleFilter(comparison).map((tabElem, index) => {
215+
return <option value={index}>{`Series ${index + 1}`}</option>;
216+
})
217+
)}
218+
</select>
219+
</div> */}
220+
<div className="series-options-container">
221+
<div className="snapshotId-container">
222+
<h1 className="snashotId-header">
223+
{' '}
224+
Snapshot ID: {currentIndex + 1}{' '}
225+
</h1>
226+
</div>
227+
<div className="dropdown-and-save-series-container">
228+
<FormControl variant="outlined" className={classes.formControl}>
229+
<Select
230+
style={{ color: 'white' }}
231+
labelId="simple-select-outlined-label"
232+
id="simple-select-outlined"
233+
className={classes.select}
234+
open={open}
235+
onClose={handleClose}
236+
onOpen={handleOpen}
237+
value={series}
238+
//data={data.barStack}
239+
// value={titleFilter(comparison)}
240+
onChange={handleChange}
241+
>
242+
{!comparison[series] ? (
243+
<MenuItem>No series available</MenuItem>
244+
) : (
245+
titleFilter(comparison).map((tabElem, index) => {
246+
return (
247+
<MenuItem value={index}>{`Series ${index + 1}`}</MenuItem>
248+
);
249+
})
250+
)}
251+
</Select>
252+
</FormControl>
253+
</div>
254+
</div>
232255
<svg ref={containerRef} width={width} height={height}>
233256
{}
234257
<rect
@@ -268,6 +291,7 @@ const BarGraphComparison = (props) => {
268291
const bar = barStack.bars[currentIndex];
269292
// console.log('Y SCALEEE', barStacks);
270293
// console.log('data.barStack >>>', data.barStack);
294+
console.log('OG bar.x', bar.x);
271295

272296
return (
273297
<rect
@@ -322,10 +346,11 @@ const BarGraphComparison = (props) => {
322346
}
323347
// console.log('barStacks in Comparison', barStacks);
324348
const bar = barStack.bars[currentIndex];
349+
console.log('Comparison bar.x', bar.x);
325350
return (
326351
<rect
327352
key={`bar-stack-${idx}-${bar.index}`}
328-
x={300}
353+
x={275}
329354
y={bar.y}
330355
height={bar.height === 0 ? null : bar.height}
331356
width={bar.width}

src/app/components/ComponentMap.tsx

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ import useForceUpdate from './useForceUpdate';
88
import LinkControls from './LinkControls';
99
import getLinkComponent from './getLinkComponent';
1010
import { localPoint } from '@visx/event';
11-
import { useTooltip, useTooltipInPortal, TooltipWithBounds } from '@visx/tooltip';
12-
import { onHover, onHoverExit } from '../actions/actions';
11+
import {
12+
useTooltip,
13+
useTooltipInPortal,
14+
TooltipWithBounds,
15+
defaultStyles,
16+
} from '@visx/tooltip';
17+
import { onHover, onHoverExit } from '../actions/actions';
1318
import { useStoreContext } from '../store';
1419

1520
const root = hierarchy({
@@ -32,7 +37,6 @@ interface TreeNode {
3237
children?: TreeNode[];
3338
}
3439

35-
3640
type HierarchyNode = HierarchyPointNode<TreeNode>;
3741

3842
const defaultMargin = { top: 30, left: 30, right: 55, bottom: 70 };
@@ -93,8 +97,7 @@ export default function ComponentMap({
9397
}
9498
}
9599

96-
97-
//Tooltip stuff:
100+
//Tooltip stuff:
98101
const {
99102
tooltipData,
100103
tooltipLeft,
@@ -104,20 +107,25 @@ export default function ComponentMap({
104107
hideTooltip,
105108
} = useTooltip();
106109

107-
const { containerRef, TooltipInPortal } = useTooltipInPortal();
110+
const { containerRef, TooltipInPortal } = useTooltipInPortal({
111+
detectBounds: true,
112+
scroll: true,
113+
});
108114

109-
//mousing controls
110-
const handleMouseOver = (event) => {
111-
console.log("mouse entered");
112-
const coords = localPoint(event.target.ownerSVGElement, event);
113-
console.log("I'm coords", coords);
114-
showTooltip({
115-
tooltipLeft: coords.x,
116-
tooltipTop: coords.y,
117-
tooltipData: "test"
118-
});
119-
}
115+
const tooltipStyles = {
116+
...defaultStyles,
117+
minWidth: 60,
118+
backgroundColor: 'rgba(0,0,0,0.9)',
119+
color: 'white',
120+
fontSize: '14px',
121+
lineHeight: '18px',
122+
fontFamily: 'Roboto',
123+
};
120124

125+
const formatRenderTime = (time) => {
126+
time = time.toFixed(3);
127+
return `${time} ms `;
128+
};
121129

122130
// controls for the map
123131
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
@@ -180,6 +188,24 @@ export default function ComponentMap({
180188
left = node.y;
181189
}
182190

191+
//mousing controls
192+
const handleMouseOver = (event) => {
193+
() => dispatch(onHover(node.data.rtid));
194+
const coords = localPoint(
195+
event.target.ownerSVGElement,
196+
event
197+
);
198+
const tooltipObj = Object.assign({}, node.data);
199+
if (typeof tooltipObj.state === 'object')
200+
tooltipObj.state = 'stateful';
201+
console.log('tooltipObj', tooltipObj);
202+
showTooltip({
203+
tooltipLeft: coords.x,
204+
tooltipTop: coords.y,
205+
tooltipData: tooltipObj,
206+
});
207+
};
208+
183209
return (
184210
<Group top={top} left={left} key={key}>
185211
{node.depth === 0 && (
@@ -241,16 +267,26 @@ export default function ComponentMap({
241267
</Tree>
242268
</Group>
243269
</svg>
244-
tooltipOpen && tooltipData && (
270+
{tooltipOpen && tooltipData && (
245271
<TooltipInPortal
246272
// set this to random so it correctly updates with parent bounds
247273
key={Math.random()}
248274
top={tooltipTop}
249275
left={tooltipLeft}
276+
style={tooltipStyles}
250277
>
251-
Tooltip Data: <strong>{tooltipData}</strong>
278+
<div style={{}}>
279+
{' '}
280+
<strong>{tooltipData.name}</strong>{' '}
281+
</div>
282+
<div>State: {tooltipData.state}</div>
283+
<div>
284+
{' '}
285+
Render time:{' '}
286+
{formatRenderTime(tooltipData.componentData.actualDuration)}{' '}
287+
</div>
252288
</TooltipInPortal>
253-
)
289+
)}
254290
</div>
255291
);
256292
}

src/app/components/PerformanceVisx.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ const traverse = (snapshot, data, currTotalRender = 0) => {
7676
return data;
7777
};
7878

79+
const allStorage = () => {
80+
const values = [];
81+
const keys = Object.keys(localStorage);
82+
let i = keys.length;
83+
84+
while (i--) {
85+
const series = localStorage.getItem(keys[i]);
86+
values.push(JSON.parse(series));
87+
}
88+
return values;
89+
};
90+
7991
const getSnapshotIds = (obj, snapshotIds = []): string[] => {
8092
snapshotIds.push(`${obj.name}.${obj.branch}`);
8193
if (obj.children) {
@@ -116,18 +128,6 @@ const PerformanceVisx = (props: BarStackProps) => {
116128
const [comparisonView, setComparisonView] = useState('barStack');
117129
const [comparisonData, setComparisonData] = useState();
118130

119-
const allStorage = () => {
120-
const values = [];
121-
const keys = Object.keys(localStorage);
122-
let i = keys.length;
123-
124-
while (i--) {
125-
const series = localStorage.getItem(keys[i]);
126-
values.push(JSON.parse(series));
127-
}
128-
return values;
129-
};
130-
131131
const toggleComponentDetailsView = () => {
132132
detailsView === 'frequencyCards'
133133
? setDetailsView('barStack')

0 commit comments

Comments
 (0)