Skip to content

Commit a9b4df7

Browse files
committed
mg compare series sort of fixed and blue
1 parent 546b6b9 commit a9b4df7

File tree

1 file changed

+78
-33
lines changed

1 file changed

+78
-33
lines changed

src/app/components/StateRoute/PerformanceVisx/BarGraphComparison.tsx

Lines changed: 78 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ import { useTheme } from '@mui/material/styles';
1818
import { Button, InputLabel } from '@mui/material';
1919
import { onHover, onHoverExit, deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
2020
import { useStoreContext } from '../../../store';
21-
import { snapshot, TooltipData, Margin, BarGraphComparisonProps, ActionObj, Series } from '../../../FrontendTypes';
21+
import {
22+
snapshot,
23+
TooltipData,
24+
Margin,
25+
BarGraphComparisonProps,
26+
ActionObj,
27+
Series,
28+
} from '../../../FrontendTypes';
2229

2330
/* DEFAULTS */
2431
const margin: Margin = {
@@ -48,7 +55,7 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
4855
comparison, // result from invoking 'allStorage' in 'PerformanceVisx'
4956
setSeries, // setter function to update the state located in 'PerfomanceVisx'
5057
series, // initialized as boolean, can be an object, from state set in 'PerformanceVisx'
51-
setAction // setter function to update the state located in 'PerfomanceVisx'
58+
setAction, // setter function to update the state located in 'PerfomanceVisx'
5259
} = props;
5360
const [snapshots] = useState(0); // creates a local state snapshots and sets it to a value of 0 (why is there no setter function? Also, why use state when it's only referenced once and never changed? 08/03/2023)
5461
const [open, setOpen] = useState(false); // creates a local state setOpen and sets it to false (why is there no setter function? 08/03/2023)
@@ -62,7 +69,7 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
6269

6370
const currentIndex: number = tabs[currentTab].sliderIndex;
6471

65-
const {
72+
const {
6673
tooltipData, // value/data that tooltip may need to render
6774
tooltipLeft, // number used for tooltip positioning
6875
tooltipTop, // number used for tooltip positioning
@@ -92,7 +99,8 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
9299
padding: 0.2,
93100
});
94101

95-
const calculateMaxTotalRender = (serie: number): number => { // This function will iterate through the snapshots of the series, and grab the highest render times (sum of all component times). We'll then use it in the renderingScale function and compare with the render time of the current tab. The max render time will determine the Y-axis's highest number.
102+
const calculateMaxTotalRender = (serie: number): number => {
103+
// This function will iterate through the snapshots of the series, and grab the highest render times (sum of all component times). We'll then use it in the renderingScale function and compare with the render time of the current tab. The max render time will determine the Y-axis's highest number.
96104
const currentSeriesBarStacks: ActionObj[] = !comparison[serie]
97105
? []
98106
: comparison[serie].data.barStack;
@@ -109,7 +117,8 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
109117
return currentMax;
110118
};
111119

112-
const renderingScale = scaleLinear<number>({ // this function will use the domain array to assign each key a different color to make rectangle boxes and use range to set the color scheme each bar
120+
const renderingScale = scaleLinear<number>({
121+
// this function will use the domain array to assign each key a different color to make rectangle boxes and use range to set the color scheme each bar
113122
domain: [0, Math.max(calculateMaxTotalRender(series), data.maxTotalRender)], // [minY, maxY] the domain array on rendering scale will set the coordinates for Y-axis points.
114123
nice: true,
115124
});
@@ -126,22 +135,23 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
126135
snapshotIdScale.rangeRound([0, xMax]);
127136
renderingScale.range([yMax, 0]);
128137

129-
const StyledFormControl = styled(FormControl)(({ theme }) => ({ // applies the theme style to the FormControl component
130-
margin: theme.spacing(1),
131-
minWidth: 160,
132-
height: 30,
133-
}));
134-
{
135-
/* StyledSelect to use for MUI select components to maintain consistent styling for all select components*/
136-
}
137-
const StyledSelect = styled(Select)({
138-
// applies the object to customize the style of the 'Select' component
139-
minWidth: 160,
140-
fontSize: '1.2rem',
141-
fontWeight: 200,
142-
height: 30,
143-
border: '1px solid #da262c',
144-
});
138+
// const StyledFormControl = styled(FormControl)(({ theme }) => ({
139+
// // applies the theme style to the FormControl component
140+
// margin: theme.spacing(1),
141+
// minWidth: 160,
142+
// height: 30,
143+
// }));
144+
145+
// StyledSelect to use for MUI select components to maintain consistent styling for all select components
146+
147+
// const StyledSelect = styled(Select)({
148+
// // applies the object to customize the style of the 'Select' component
149+
// minWidth: 160,
150+
// fontSize: '1.2rem',
151+
// fontWeight: 200,
152+
// height: 30,
153+
// border: '1px solid #da262c',
154+
// });
145155

146156
const handleSeriesChange = (event: Event) => {
147157
if (!event) {
@@ -179,14 +189,15 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
179189
setPicOpen(true);
180190
};
181191

182-
function setXpointsComparison() { // manually assigning X -axis points with tab ID.
192+
function setXpointsComparison() {
193+
// manually assigning X -axis points with tab ID.
183194
comparison[series].data.barStack.forEach((elem: ActionObj) => {
184195
elem.currentTab = 'comparison';
185196
});
186197
return comparison[series].data.barStack;
187198
}
188199

189-
function setXpointsCurrentTab() {
200+
function setXpointsCurrentTab() {
190201
data.barStack.forEach((element) => {
191202
element.currentTab = 'currentTab';
192203
});
@@ -228,7 +239,7 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
228239
{buttonLoad ? 'Deleted' : 'Clear Series'}
229240
</Button>
230241
{/* Mui 'Compare Series Dropdown Starts here */}
231-
<StyledFormControl // MUI styled 'FormControl' component
242+
{/* <StyledFormControl // MUI styled 'FormControl' component
232243
variant='filled'
233244
>
234245
<InputLabel
@@ -257,7 +268,34 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
257268
))
258269
)}
259270
</StyledSelect>
260-
</StyledFormControl>
271+
</StyledFormControl> */}
272+
<FormControl sx={{ m: 1, minWidth: 180 }} size='small'>
273+
<InputLabel id='simple-select-outlined-label' sx={{ color: 'white' }}>
274+
Compare Series
275+
</InputLabel>
276+
<Select
277+
variant='filled'
278+
labelId='simple-select-outlined-label'
279+
id='simple-select-outlined-label'
280+
value={series}
281+
label='Compare Series'
282+
onClose={handleClose}
283+
onOpen={handleOpen}
284+
onChange={handleSeriesChange}
285+
sx={{ backgroundColor: '#58c1e2', color: 'white' }}
286+
>
287+
<MenuItem>None</MenuItem>
288+
{!comparison.length ? (
289+
<MenuItem>No series available</MenuItem>
290+
) : (
291+
comparison.map((tabElem, index) => (
292+
<MenuItem key={`MenuItem${tabElem.name}`} value={index}>
293+
{tabElem.name}
294+
</MenuItem>
295+
))
296+
)}
297+
</Select>
298+
</FormControl>
261299
{/* Mui 'Compare Series Dropdown ENDS here */}
262300

263301
{/*==============================================================================================================================*/}
@@ -320,8 +358,11 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
320358
yScale={renderingScale} // takes in a value and maps it to an y axis position
321359
color={colorScale} // returns the desired color for a bar with a given key and index
322360
>
323-
{(barStacks) => // overides render function which is past the configured stack generator
324-
barStacks.map((barStack, idx) => { // Uses map method to iterate through all components, creating a rect component, from visx, for each iteration. height, width, etc are calculated by visx to set X and Y scale. The scaler will used the passed in function and will run it on the array thats outputted by data
361+
{(
362+
barStacks, // overides render function which is past the configured stack generator
363+
) =>
364+
barStacks.map((barStack, idx) => {
365+
// Uses map method to iterate through all components, creating a rect component, from visx, for each iteration. height, width, etc are calculated by visx to set X and Y scale. The scaler will used the passed in function and will run it on the array thats outputted by data
325366
const bar = barStack.bars[currentIndex];
326367
if (Number.isNaN(bar.bar[1]) || bar.height < 0) {
327368
bar.height = 0;
@@ -336,7 +377,8 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
336377
fill={bar.color}
337378
/* TIP TOOL EVENT HANDLERS */
338379
// Hides tool tip once cursor moves off the current rect
339-
onMouseLeave={() => { // Hides tool tip once cursor moves off the current rect
380+
onMouseLeave={() => {
381+
// Hides tool tip once cursor moves off the current rect
340382
dispatch(
341383
onHoverExit(data.componentData[bar.key].rtid),
342384
(tooltipTimeout = window.setTimeout(() => {
@@ -345,7 +387,8 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
345387
);
346388
}}
347389
// Cursor position in window updates position of the tool tip
348-
onMouseMove={(event) => { // Cursor position in window updates position of the tool tip
390+
onMouseMove={(event) => {
391+
// Cursor position in window updates position of the tool tip
349392
dispatch(onHover(data.componentData[bar.key].rtid));
350393
if (tooltipTimeout) clearTimeout(tooltipTimeout);
351394
const top = event.clientY - margin.top - bar.height;
@@ -370,7 +413,8 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
370413
color={colorScale}
371414
>
372415
{(barStacks) =>
373-
barStacks.map((barStack, idx) => { // Uses map method to iterate through all components, creating a react component (from visx) for each iteration. height/width/etc. are calculated by visx.
416+
barStacks.map((barStack, idx) => {
417+
// Uses map method to iterate through all components, creating a react component (from visx) for each iteration. height/width/etc. are calculated by visx.
374418
if (!barStack.bars[currentIndex]) {
375419
return <h1>No Comparison</h1>;
376420
}
@@ -387,16 +431,17 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
387431
width={bar.width}
388432
fill={bar.color}
389433
/* TIP TOOL EVENT HANDLERS */
390-
onMouseLeave={() => { // Hides tool tip once cursor moves off the current rect
434+
onMouseLeave={() => {
435+
// Hides tool tip once cursor moves off the current rect
391436
dispatch(
392437
onHoverExit(data.componentData[bar.key].rtid),
393438
(tooltipTimeout = window.setTimeout(() => {
394439
hideTooltip();
395440
}, 300)),
396441
);
397442
}}
398-
399-
onMouseMove={(event) => { // Cursor position in window updates position of the tool tip
443+
onMouseMove={(event) => {
444+
// Cursor position in window updates position of the tool tip
400445
dispatch(onHover(data.componentData[bar.key].rtid));
401446
if (tooltipTimeout) clearTimeout(tooltipTimeout);
402447
const top = event.clientY - margin.top - bar.height;

0 commit comments

Comments
 (0)