Skip to content

Commit 5bd0e79

Browse files
committed
small edit for a prop in HealthChart.
1 parent 31119f5 commit 5bd0e79

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

app/charts/HealthChart.tsx

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type PlotlyData = {
2626
};
2727

2828
const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
29-
const { dataType, chartData, categoryName, sizing, colourGenerator } = props;
29+
const { dataType, serviceName, chartData, categoryName, sizing, colourGenerator } = props;
3030
const [solo, setSolo] = useState<SoloStyles | null>(null);
3131

3232
// makes time data human-readable, and reverses it so it shows up correctly in the graph
@@ -51,33 +51,28 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
5151
// generates an array of plotly data objects to be passed into our plotly chart's data prop
5252
const generatePlotlyDataObjects = (chartDataObj: object): object[] => {
5353
const arrayOfPlotlyDataObjects: PlotlyData[] = [];
54-
// iterate through the chartData
55-
for (const serviceName in chartDataObj) {
56-
// define the metrics for this service
57-
const metrics = chartDataObj[serviceName];
58-
// loop through the list of metrics for the current service
59-
for (const metricName in metrics) {
60-
// define the value and time arrays; allow data to be reassignable in case we need to convert the bytes data into megabytes
61-
let dataArray = metrics[metricName].value;
62-
const timeArray = metrics[metricName].time;
63-
// specifically for `Megabyte` types, convert the original data of bytes into a value of megabytes before graphing
64-
if (dataType === 'Memory in Megabytes' || dataType === 'Cache in Megabytes') {
65-
dataArray = dataArray.map(value => (value / 1000000).toFixed(2));
66-
}
67-
// create the plotly object
68-
const plotlyDataObject: PlotlyData = {
69-
name: prettyMetricName(metricName),
70-
x: prettyTimeInReverse(timeArray),
71-
y: dataArray,
72-
type: 'scattergl',
73-
mode: 'lines',
74-
marker: {
75-
colors: ['#fc4039', '#4b54ea', '#32b44f', '#3788fc', '#9c27b0', '#febc2c'],
76-
},
77-
};
78-
// push the dataObject into the arrayOfPlotlyDataObjects
79-
arrayOfPlotlyDataObjects.push(plotlyDataObject);
54+
// loop through the list of metrics for the current chart
55+
for (const metricName in chartDataObj) {
56+
// define the value and time arrays; allow data to be reassignable in case we need to convert the bytes data into megabytes
57+
let dataArray = chartDataObj[metricName].value;
58+
const timeArray = chartDataObj[metricName].time;
59+
// specifically for `Megabyte` types, convert the original data of bytes into a value of megabytes before graphing
60+
if (dataType === 'Memory in Megabytes' || dataType === 'Cache in Megabytes') {
61+
dataArray = dataArray.map(value => (value / 1000000).toFixed(2));
8062
}
63+
// create the plotly object
64+
const plotlyDataObject: PlotlyData = {
65+
name: prettyMetricName(metricName),
66+
x: prettyTimeInReverse(timeArray),
67+
y: dataArray,
68+
type: 'scattergl',
69+
mode: 'lines',
70+
marker: {
71+
colors: ['#fc4039', '#4b54ea', '#32b44f', '#3788fc', '#9c27b0', '#febc2c'],
72+
},
73+
};
74+
// push the dataObject into the arrayOfPlotlyDataObjects
75+
arrayOfPlotlyDataObjects.push(plotlyDataObject);
8176
}
8277
// return the array of plotlyDataObject
8378
return arrayOfPlotlyDataObjects;
@@ -91,16 +86,16 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
9186

9287
const createChart = () => {
9388
const dataArray = generatePlotlyDataObjects(chartData);
94-
const serviceNames = serviceNamesAsString(chartData);
95-
console.log('serviceNames: ', serviceNames);
89+
90+
console.log('serviceName: ', serviceName);
9691
const sizeSwitch = sizing === 'all' ? all : solo;
9792

9893
return (
9994
<Plot
10095
data={dataArray}
10196
config={{ displayModeBar: true }}
10297
layout={{
103-
title: `${serviceNames}| ${categoryName}`,
98+
title: `${serviceName} || ${categoryName}`,
10499
...sizeSwitch,
105100
font: {
106101
color: '#444d56',

app/components/Occupied.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const Occupied = React.memo(() => {
8686
// Grab services and applications whenever the user changes
8787
// v10: Runs once when Occupied is memoized, and subsequently when user is updated.
8888
useEffect(() => {
89-
console.log('Hi, inside Occupied.ts useEffect function.');
89+
// console.log('Hi, inside Occupied.ts useEffect function.');
9090
setServicesData([]);
9191
getApplications();
9292
}, [user]);

app/containers/HealthContainer.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,22 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
151151
for (const dataType in sortedData) {
152152
const serviceObjects = sortedData[dataType];
153153
for (const serviceName in serviceObjects) {
154-
// pass down the value of the current data type object
154+
// pass down the value of the current data type and service
155155
const chartData = serviceObjects[serviceName];
156-
console.log('dataType: ', dataType, 'chartData: ', chartData);
156+
console.log(
157+
'dataType: ',
158+
dataType,
159+
'service name: ',
160+
serviceName,
161+
'chartData: ',
162+
chartData
163+
);
157164
chartsArray.push(
158165
<HealthChart
159166
key={'H' + keymaker()}
160167
dataType={dataType}
161168
serviceName={serviceName}
162-
chartData={sortedData[dataType]}
169+
chartData={chartData}
163170
categoryName={`${category}`}
164171
sizing={props.sizing}
165172
colourGenerator={props.colourGenerator}

0 commit comments

Comments
 (0)