Skip to content

Commit 664bf92

Browse files
Merge pull request #8868 from GilbertCherrie/fix_utlization_chart
Fix utilization chart
2 parents 0e07a1d + 5e732d4 commit 664bf92

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { GroupedBarChart } from '@carbon/charts-react';
4+
import { getYAxisValue } from './helpers';
5+
6+
const GroupBarChart = ({
7+
data, format, size, title,
8+
}) => {
9+
const options = {
10+
title,
11+
axes: {
12+
left: {
13+
mapsTo: 'value',
14+
ticks: {
15+
formatter(n) { return getYAxisValue(format, n); },
16+
},
17+
},
18+
bottom: {
19+
scaleType: 'labels',
20+
mapsTo: 'key',
21+
},
22+
},
23+
height: size,
24+
tooltip: {
25+
truncation: {
26+
type: 'none',
27+
},
28+
},
29+
};
30+
31+
return (
32+
<GroupedBarChart data={data} options={options} />
33+
);
34+
};
35+
36+
GroupBarChart.propTypes = {
37+
data: PropTypes.instanceOf(Array),
38+
format: PropTypes.instanceOf(Object),
39+
size: PropTypes.string,
40+
title: PropTypes.string,
41+
};
42+
43+
GroupBarChart.defaultProps = {
44+
data: null,
45+
format: null,
46+
size: '400px',
47+
title: '',
48+
};
49+
50+
export default GroupBarChart;

app/javascript/components/performance-charts/index.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import LineChartGraph from './lineChart';
44
import AreaChartGraph from './areaChart';
5-
import { getLineConvertedData } from '../carbon-charts/helpers';
5+
import GroupBarChart from './groupChart';
6+
import { getConvertedData, getLineConvertedData } from '../carbon-charts/helpers';
7+
import EmptyChart from '../dashboard-widgets/dashboard-charts/emptyChart';
68

79
const PerformanceChartWidget = ({
810
// eslint-disable-next-line no-unused-vars
911
data, id, size, title,
1012
}) => {
11-
const convertedData = getLineConvertedData(data);
12-
13+
let convertedData = getLineConvertedData(data);
14+
if (data.miq && data.miq.empty) {
15+
return (<EmptyChart />);
16+
}
1317
if (data.miqChart === 'Area') {
1418
return (<AreaChartGraph data={convertedData} format={data.miq.format} size={size} title={title} />);
1519
}
20+
if ((data.miqChart === 'StackedColumn' || data.miqChart === 'Column') && !data.data.groups) {
21+
convertedData = getConvertedData(data);
22+
return (<GroupBarChart data={convertedData} format={data.miq.format} size={size} title={title} />);
23+
}
1624
return (<LineChartGraph data={convertedData} format={data.miq.format} size={size} title={title} />);
1725
};
1826

0 commit comments

Comments
 (0)