Skip to content

Commit 41a2aab

Browse files
Kevin NgoC-STYRCourageWolfDennisLpzdemircaner
committed
Add comments throughout background.js, contentScript.js, and BarGraphComparison.tsx
- [x] New feature (change which adds functionality) - Add comments so that future devs have self-documenting codebase - Wrote in detail what the different functions do in the above files to help future devs understand the data flow of Reactime. Co-authored-by: C-STYR <[email protected]> Co-authored-by: CourageWolf <[email protected]> Co-authored-by: DennisLpz <[email protected]> Co-authored-by: demircaner <[email protected]>
1 parent ee9b6ce commit 41a2aab

File tree

8 files changed

+544
-518
lines changed

8 files changed

+544
-518
lines changed

src/app/components/BarGraph.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const BarGraph = (props) => {
126126
return (
127127
<div>
128128
<button
129-
className='save-series-button'
129+
className="save-series-button"
130130
onClick={(e) => {
131131
dispatch(save(toStorage));
132132
}}
@@ -150,7 +150,7 @@ const BarGraph = (props) => {
150150
yScale={renderingScale}
151151
width={xMax}
152152
height={yMax}
153-
stroke='black'
153+
stroke="black"
154154
strokeOpacity={0.1}
155155
xOffset={snapshotIdScale.bandwidth() / 2}
156156
/>
@@ -166,9 +166,7 @@ const BarGraph = (props) => {
166166
{(barStacks) =>
167167
barStacks.map((barStack) =>
168168
barStack.bars.map((bar, idx) => {
169-
console.log('barstacks >>>', barStack);
170-
console.log('bars >>>', bar);
171-
// hides new components if components don't exist in previous snapshots
169+
// Hides new components if components don't exist in previous snapshots.
172170
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
173171
bar.height = 0;
174172
}
@@ -181,7 +179,7 @@ const BarGraph = (props) => {
181179
width={bar.width}
182180
fill={bar.color}
183181
/* TIP TOOL EVENT HANDLERS */
184-
// Hides tool tip once cursor moves off the current rect
182+
// Hides tool tip once cursor moves off the current rect.
185183
onMouseLeave={() => {
186184
dispatch(
187185
onHoverExit(data.componentData[bar.key].rtid),
@@ -190,7 +188,7 @@ const BarGraph = (props) => {
190188
}, 300))
191189
);
192190
}}
193-
// Cursor position in window updates position of the tool tip
191+
// Cursor position in window updates position of the tool tip.
194192
onMouseMove={(event) => {
195193
dispatch(onHover(data.componentData[bar.key].rtid));
196194
if (tooltipTimeout) clearTimeout(tooltipTimeout);
@@ -238,15 +236,15 @@ const BarGraph = (props) => {
238236
/>
239237
<Text
240238
x={-xMax / 2}
241-
y='15'
242-
transform='rotate(-90)'
239+
y="15"
240+
transform="rotate(-90)"
243241
fontSize={12}
244-
fill='#FFFFFF'
242+
fill="#FFFFFF"
245243
>
246244
Rendering Time (ms)
247245
</Text>
248246
<br />
249-
<Text x={xMax / 2 + 15} y={yMax + 70} fontSize={12} fill='#FFFFFF'>
247+
<Text x={xMax / 2 + 15} y={yMax + 70} fontSize={12} fill="#FFFFFF">
250248
Snapshot ID
251249
</Text>
252250
</svg>

src/app/components/BarGraphComparison.tsx

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,17 @@ const BarGraphComparison = (props) => {
105105
const formatRenderTime = (time) => `${time} ms `;
106106
const getCurrentTab = (storedSeries) => storedSeries.currentTab;
107107
// create visualization SCALES with cleaned data
108-
//const xAxisPoints = [...titleFilter(comparison).map(getTabID), currentTab];
109-
//the domain array elements will place the bars along the x-axis
110-
const xAxisPoints = ['currentTab', 'comparison']; //[1.0.,2.0]
111-
//{ currentTab : 1 }, {currentTab : 2 }
108+
// the domain array/xAxisPoints elements will place the bars along the x-axis
109+
const xAxisPoints = ['currentTab', 'comparison'];
112110
const snapshotIdScale = scaleBand<string>({
113111
domain: xAxisPoints,
114112
padding: 0.2,
115113
});
116-
// calculateMax
114+
// This function will iterate through the snapshots of the series,
115+
// and grab the highest render times (sum of all component times).
116+
// We'll then use it in the renderingScale function and compare
117+
// with the render time of the current tab.
118+
// The max render time will determine the Y-axis's highest number.
117119
const calculateMaxTotalRender = (series) => {
118120
const currentSeriesBarStacks = !comparison[series]
119121
? []
@@ -128,11 +130,13 @@ const BarGraphComparison = (props) => {
128130
return currentMax;
129131
};
130132

133+
// the domain array on rendering scale will set the coordinates for Y-aix points.
131134
const renderingScale = scaleLinear<number>({
132135
domain: [0, Math.max(calculateMaxTotalRender(series), data.maxTotalRender)],
133136
nice: true,
134137
});
135-
138+
// the domain array will assign each key(component on test app) a different color
139+
// and use range to set the color scheme each bar
136140
const colorScale = scaleOrdinal<string>({
137141
domain: keys,
138142
range: schemeSet3,
@@ -144,7 +148,7 @@ const BarGraphComparison = (props) => {
144148
snapshotIdScale.rangeRound([0, xMax]);
145149
renderingScale.range([yMax, 0]);
146150

147-
// Dropdown to select series.
151+
// useStyles will change the styling on save series dropdown feature
148152
const useStyles = makeStyles((theme) => ({
149153
formControl: {
150154
margin: theme.spacing(1),
@@ -198,37 +202,37 @@ const BarGraphComparison = (props) => {
198202
e.target.classList.add('animate');
199203
e.target.innerHTML = 'Deleted!';
200204
setTimeout(function () {
201-
e.target.innerHTML = 'Clear Series';
205+
e.target.innerHTML = 'Clear All Series';
202206
e.target.classList.remove('animate');
203207
}, 1000);
204208
};
205209
const classname = document.getElementsByClassName('delete-button');
206210
for (let i = 0; i < classname.length; i++) {
207211
classname[i].addEventListener('click', animateButton, false);
208212
}
209-
//console.log('set x on current bar', setXpointsCurrentTab());
210213
return (
211214
<div>
212-
<div className='series-options-container'>
213-
<div className='snapshotId-header'>
215+
<div className="series-options-container">
216+
<div className="snapshotId-header">
214217
{' '}
215218
Snapshot ID: {currentIndex + 1}{' '}
216219
</div>
217220

218-
<div className='dropdown-and-delete-series-container'>
221+
<div className="dropdown-and-delete-series-container">
219222
<button
220-
className='delete-button'
223+
className="delete-button"
221224
onClick={(e) => {
222225
dispatch(deleteSeries());
223226
}}
224227
>
225228
Clear All Series
226229
</button>
227-
<FormControl variant='outlined' className={classes.formControl}>
230+
<h4 style={{ padding: '0 1rem' }}>Compare with: </h4>
231+
<FormControl variant="outlined" className={classes.formControl}>
228232
<Select
229233
style={{ color: 'white' }}
230-
labelId='simple-select-outlined-label'
231-
id='simple-select-outlined'
234+
labelId="simple-select-outlined-label"
235+
id="simple-select-outlined"
232236
className={classes.select}
233237
open={open}
234238
onClose={handleClose}
@@ -267,13 +271,13 @@ const BarGraphComparison = (props) => {
267271
yScale={renderingScale}
268272
width={xMax}
269273
height={yMax}
270-
stroke='black'
274+
stroke="black"
271275
strokeOpacity={0.1}
272276
xOffset={snapshotIdScale.bandwidth() / 2}
273277
/>
274278
<Group top={margin.top} left={margin.left}>
275279
<BarStack
276-
// OG Barstack
280+
// Current Tab bar stack.
277281
data={setXpointsCurrentTab()}
278282
keys={keys}
279283
x={getCurrentTab}
@@ -283,6 +287,11 @@ const BarGraphComparison = (props) => {
283287
>
284288
{(barStacks) =>
285289
barStacks.map((barStack, idx) => {
290+
// Uses map method to iterate through all components,
291+
// creating a rect component (from visx) for each iteration.
292+
// height/width/etc. are calculated by visx.
293+
// to set X and Y scale, it will used the passed in function and
294+
// will run it on the array thats outputted by data
286295
const bar = barStack.bars[currentIndex];
287296
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
288297
bar.height = 0;
@@ -323,7 +332,9 @@ const BarGraphComparison = (props) => {
323332
}
324333
</BarStack>
325334
<BarStack
326-
// Comparison Barstack
335+
// Comparison Barstack (populates based on series selected)
336+
//to set X and Y scale, it will used the passed in function and
337+
// will run it on the array thats outputted by data
327338
data={!comparison[series] ? [] : setXpointsComparison()}
328339
keys={keys}
329340
x={getCurrentTab}
@@ -333,6 +344,9 @@ const BarGraphComparison = (props) => {
333344
>
334345
{(barStacks) =>
335346
barStacks.map((barStack, idx) => {
347+
// Uses map method to iterate through all components,
348+
// creating a rect component (from visx) for each iteration.
349+
// height/width/etc. are calculated by visx.
336350
if (!barStack.bars[currentIndex]) {
337351
return <h1>No Comparison</h1>;
338352
}
@@ -405,14 +419,14 @@ const BarGraphComparison = (props) => {
405419
/>
406420
<Text
407421
x={-xMax / 2}
408-
y='15'
409-
transform='rotate(-90)'
422+
y="15"
423+
transform="rotate(-90)"
410424
fontSize={12}
411-
fill='#FFFFFF'
425+
fill="#FFFFFF"
412426
>
413427
Rendering Time (ms)
414428
</Text>
415-
<Text x={xMax / 2} y={yMax + 65} fontSize={12} fill='#FFFFFF'>
429+
<Text x={xMax / 2} y={yMax + 65} fontSize={12} fill="#FFFFFF">
416430
Series ID
417431
</Text>
418432
</svg>

0 commit comments

Comments
 (0)