Skip to content

Commit 1be9322

Browse files
committed
modularized by removing typescripts into FrontendTypes.ts and imported into BarGraphComparison.tsx, BarGraph.tsx
1 parent 3941189 commit 1be9322

File tree

4 files changed

+57
-89
lines changed

4 files changed

+57
-89
lines changed

src/app/components/FrontendTypes.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { SeriesPoint } from '@visx/shape/lib/types';
2+
13
export interface PerfData {
24
barStack: BarStackProp[],
35
componentData?: Record<string, unknown>,
@@ -8,3 +10,50 @@ interface BarStackProp {
810
snapshotId: string,
911
route: URL,
1012
}
13+
14+
// On-hover data for BarGraph/BarGraphComparison.tsx
15+
export interface TooltipData {
16+
bar: SeriesPoint<snapshot>;
17+
key: string;
18+
index: number;
19+
height: number;
20+
width: number;
21+
x: number;
22+
y: number;
23+
color: string;
24+
}
25+
26+
export interface snapshot {
27+
snapshotId?: string;
28+
children: [];
29+
componentData: any;
30+
name: string;
31+
state: string;
32+
}
33+
34+
export interface margin {
35+
top: number;
36+
right: number;
37+
bottom: number;
38+
left: number;
39+
}
40+
41+
interface BarGraphBase {
42+
width: number,
43+
height: number,
44+
data: PerfData,
45+
comparison: string | [],
46+
}
47+
export interface BarGraphComparisonProps extends BarGraphBase {
48+
setSeries: () => void,
49+
series: unknown,
50+
setAction: () => void,
51+
}
52+
53+
export interface BarGraphProps extends BarGraphBase{
54+
setRoute: () => void,
55+
allRoutes: unknown,
56+
filteredSnapshots: unknown,
57+
snapshot: unknown,
58+
setSnapshot: () => void
59+
}

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

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,7 @@ import { Text } from '@visx/text';
1111
import { schemeSet3 } from 'd3-scale-chromatic';
1212
import { onHover, onHoverExit, save } from '../../../actions/actions';
1313
import { useStoreContext } from '../../../store';
14-
import { PerfData } from '../../FrontendTypes';
15-
16-
/* TYPESCRIPT */
17-
18-
interface margin {
19-
top: number;
20-
right: number;
21-
bottom: number;
22-
left: number;
23-
}
24-
25-
interface snapshot {
26-
snapshotId?: string;
27-
children: [];
28-
componentData: any;
29-
name: string;
30-
state: string;
31-
}
32-
33-
interface TooltipData {
34-
bar: SeriesPoint<snapshot>;
35-
key: string;
36-
index: number;
37-
height: number;
38-
width: number;
39-
x: number;
40-
y: number;
41-
color: string;
42-
}
43-
44-
interface BarGraphProps {
45-
width: number,
46-
height: number,
47-
data: PerfData,
48-
comparison: unknown,
49-
setRoute: () => void,
50-
allRoutes: unknown,
51-
filteredSnapshots: unknown,
52-
snapshot: unknown,
53-
setSnapshot: () => void
54-
}
14+
import { snapshot, TooltipData, margin, BarGraphProps } from '../../FrontendTypes';
5515

5616
/* DEFAULTS */
5717
const margin = {

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

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// @ts-nocheck
21
import React, { useEffect } from 'react';
32
import { BarStack } from '@visx/shape';
4-
import { SeriesPoint } from '@visx/shape/lib/types';
53
import { Group } from '@visx/group';
64
import { Grid } from '@visx/grid';
75
import { AxisBottom, AxisLeft } from '@visx/axis';
@@ -15,46 +13,7 @@ import MenuItem from '@material-ui/core/MenuItem';
1513
import FormControl from '@material-ui/core/FormControl';
1614
import { onHover, onHoverExit, deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
1715
import { useStoreContext } from '../../../store';
18-
import { PerfData } from '../../FrontendTypes';
19-
20-
/* TYPESCRIPT */
21-
22-
interface margin {
23-
top: number;
24-
right: number;
25-
bottom: number;
26-
left: number;
27-
}
28-
29-
interface snapshot {
30-
snapshotId?: string;
31-
children: [];
32-
componentData: any;
33-
name: string;
34-
state: string;
35-
}
36-
37-
// On-hover data.
38-
interface TooltipData {
39-
bar: SeriesPoint<snapshot>;
40-
key: string;
41-
index: number;
42-
height: number;
43-
width: number;
44-
x: number;
45-
y: number;
46-
color: string;
47-
}
48-
49-
interface BarGraphComparisonProps {
50-
width: number,
51-
height: number,
52-
data: PerfData,
53-
comparison: string | [],
54-
setSeries: () => void,
55-
series: unknown,
56-
setAction: () => void,
57-
}
16+
import { snapshot, TooltipData, margin, BarGraphComparisonProps } from '../../FrontendTypes';
5817

5918
/* DEFAULTS */
6019
const margin = {
@@ -118,10 +77,10 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
11877
// We'll then use it in the renderingScale function and compare
11978
// with the render time of the current tab.
12079
// The max render time will determine the Y-axis's highest number.
121-
const calculateMaxTotalRender = serie => {
122-
const currentSeriesBarStacks = !comparison[serie]
80+
const calculateMaxTotalRender = series => {
81+
const currentSeriesBarStacks = !comparison[series]
12382
? []
124-
: comparison[serie].data.barStack;
83+
: comparison[series].data.barStack;
12584
if (currentSeriesBarStacks.length === 0) return 0;
12685
let currentMax = -Infinity;
12786
for (let i = 0; i < currentSeriesBarStacks.length; i += 1) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useStoreContext } from '../../../store';
1919
import { setCurrentTabInApp } from '../../../actions/actions';
2020
import { PerfData } from '../../FrontendTypes';
2121

22-
interface BarStackProps {
22+
interface PerformanceVisxProps {
2323
width: number;
2424
height: number;
2525
snapshots: [];
@@ -171,8 +171,8 @@ const getPerfMetrics = (snapshots, snapshotsIds): PerfData => {
171171
};
172172

173173
/* EXPORT COMPONENT */
174-
const PerformanceVisx = (props: BarStackProps): JSX.Element => {
175-
// hook used to dispatch onhover action in rect
174+
const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
175+
// hook used to dispatch onhover action in react
176176
const {
177177
width, height, snapshots, hierarchy,
178178
} = props;

0 commit comments

Comments
 (0)