Skip to content

Commit cde99fe

Browse files
Merge pull request #12 from oslabs-beta/dev
Dev
2 parents 6f93259 + 0891d9a commit cde99fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+43691
-2562
lines changed

.eslintrc.json

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"globals": {
3+
"NodeJS": true,
4+
"JSX": true,
5+
"Electron": true
6+
},
27
"plugins": ["react", "prettier"],
38
"parser": "babel-eslint",
49
"parserOptions": {
@@ -16,6 +21,7 @@
1621
},
1722
"extends": ["airbnb", "eslint:recommended", "plugin:react/recommended", "prettier"],
1823
"rules": {
24+
"react/display-name": "off",
1925
"prettier/prettier": "error",
2026
"no-unused-vars": [
2127
"warn",
@@ -35,6 +41,28 @@
3541
"react/no-array-index-key": "warn",
3642
"no-restricted-syntax": "off",
3743
"guard-for-in": "off",
38-
"no-param-reassign": "off"
44+
"no-param-reassign": "off",
45+
"import/extensions": [
46+
"error",
47+
"ignorePackages",
48+
{
49+
"js": "never",
50+
"jsx": "never",
51+
"ts": "never",
52+
"tsx": "never",
53+
"mjs": "never"
54+
}
55+
]
56+
},
57+
"settings": {
58+
"import/extensions": [".js", ".mjs", ".jsx", ".ts", ".tsx"],
59+
// "import/parsers": {
60+
// "@typescript-eslint/parser": [".ts", ".tsx"]
61+
// },
62+
"import/resolver": {
63+
"node": {
64+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
65+
}
66+
}
3967
}
40-
}
68+
}

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ __tests__/**/__snapshots__
4444
.Spotlight-V100
4545
.Trashes
4646
ehthumbs.db
47-
Thumbs.db
48-
47+
Thumbs.db

app/assets/search.svg

Lines changed: 1 addition & 0 deletions
Loading

app/charts/LatencyChart.tsx

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,99 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, useEffect, useState } from 'react';
22
import Plot from 'react-plotly.js';
3+
import moment from 'moment';
34
import { HealthContext } from '../context/HealthContext';
5+
import { all, solo as soloStyle } from './sizeSwitch';
46

5-
const LatencyChart = React.memo(() => {
7+
interface GraphsContainerProps {
8+
sizing: string;
9+
}
10+
11+
interface SoloStyles {
12+
height: number;
13+
width: number;
14+
}
15+
16+
const LatencyChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) => {
617
const { healthData } = useContext(HealthContext);
18+
const [data, setData] = useState<Array<Array<string | (string | number)[]>>>([]);
19+
20+
useEffect(() => {
21+
if (healthData.length) {
22+
const tempArr: ((string | number)[] | string)[][] = [];
23+
// loop over each
24+
healthData.forEach(
25+
(service: {
26+
time: string[];
27+
latency: (string | number)[];
28+
service: string[]
29+
}) => {
30+
let timeArr: string[] = [];
31+
// perform this when we 'setTime'
32+
if (service.time !== undefined) {
33+
timeArr = service.time.map((el: any) => moment(el).format('kk:mm:ss'));
34+
}
35+
36+
const temp: [string[], (string | number)[], string] = [
37+
timeArr,
38+
service.latency,
39+
service.service[0],
40+
];
41+
tempArr.push(temp);
42+
}
43+
);
44+
setData(tempArr);
45+
}
46+
}, [healthData]);
47+
48+
// FOR CHECKING
49+
// useEffect(() => {
50+
// console.log(data);
51+
// }, [data]);
52+
53+
const [solo, setSolo] = useState<SoloStyles | null>(null);
54+
55+
setInterval(() => {
56+
if (solo != soloStyle) {
57+
setSolo(soloStyle);
58+
}
59+
}, 20);
760

861
const createChart = () => {
962
const yAxis: Array<number> = healthData.latency;
1063

64+
let plotlyData: {
65+
name: any;
66+
x: any;
67+
y: any;
68+
type: any;
69+
mode: any;
70+
marker: { color: string };
71+
}[] = [];
72+
73+
plotlyData = data.map(dataArr => {
74+
// eslint-disable-next-line no-bitwise
75+
const randomColor = `#${(((1 << 24) * Math.random()) | 0).toString(16)}`;
76+
77+
return {
78+
name: dataArr[2],
79+
x: data[0][0],
80+
y: dataArr[1],
81+
type: 'scattergl',
82+
mode: 'lines',
83+
marker: { color: randomColor }
84+
};
85+
});
86+
87+
88+
const sizeSwitch = sizing === 'all' ? all : solo;
89+
90+
1191
return (
1292
<Plot
13-
data={[
14-
{
15-
name: 'CPU Latency',
16-
type: 'scattergl',
17-
y: yAxis,
18-
mode: 'lines',
19-
marker: { color: '#fc4039' },
20-
},
21-
]}
93+
data={[...plotlyData]}
2294
layout={{
2395
title: 'Latency',
24-
height: 300,
25-
width: 300,
96+
...sizeSwitch,
2697
font: {
2798
color: '#444d56',
2899
size: 11.5,
@@ -38,7 +109,7 @@ const LatencyChart = React.memo(() => {
38109
y: 5,
39110
},
40111
xaxis: {
41-
title: 'Time Elapsed (min)',
112+
title: 'Time',
42113
tickmode: 'linear',
43114
tick0: 0,
44115
dtick: 10,
@@ -56,7 +127,7 @@ const LatencyChart = React.memo(() => {
56127
);
57128
};
58129

59-
return <div className="chart">{createChart()}</div>;
130+
return <div className="chart">{solo && createChart()}</div>;
60131
});
61132

62133
export default LatencyChart;

0 commit comments

Comments
 (0)