Skip to content

Commit

Permalink
fix(barchart): handle null data correctly when we do have series
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdickerson committed Nov 10, 2020
1 parent 5cbdc1d commit b161d15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/components/BarChartCard/BarChartCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ const BarChartCard = ({
);

// Set the colors for each dataset
const uniqueDatasets = [
...new Set(chartData.map((dataset) => dataset.group)),
];
const uniqueDatasets = !isAllValuesEmpty
? [...new Set(chartData.map((dataset) => dataset.group))]
: [];
const colors = !isAllValuesEmpty
? formatColors(series, uniqueDatasets, isEditable)
: null;
Expand Down
5 changes: 3 additions & 2 deletions src/components/BarChartCard/barChartUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ export const formatChartData = (
timeDataSourceId,
type
) => {
const data = [];
if (!isNil(values) || !isEmpty(series)) {
let data = values;
if (!isNil(values) && !isEmpty(series)) {
data = [];
// grouped or stacked
if (type === BAR_CHART_TYPES.GROUPED || type === BAR_CHART_TYPES.STACKED) {
let uniqueDatasetNames;
Expand Down
14 changes: 14 additions & 0 deletions src/components/BarChartCard/barChartUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ describe('barChartUtils', () => {
value: 270,
},
]);
expect(
formatChartData(series, null, 'city', null, BAR_CHART_TYPES.GROUPED)
).toBeNull();
});

it('formatChartData returns formatted data for time-based and group-based chart', () => {
Expand Down Expand Up @@ -257,6 +260,11 @@ describe('barChartUtils', () => {
value: 200,
},
]);

// Handle nulls
expect(
formatChartData(series, null, null, 'timestamp', BAR_CHART_TYPES.STACKED)
).toBeNull();
});

it('formatChartData returns formatted data for simple, non-time and non-group chart', () => {
Expand Down Expand Up @@ -292,6 +300,9 @@ describe('barChartUtils', () => {
value: 388,
},
]);
expect(
formatChartData(series, null, 'city', null, BAR_CHART_TYPES.SIMPLE)
).toBeNull();
});

it('formatChartData returns formatted data for time-based, non-group chart', () => {
Expand Down Expand Up @@ -332,6 +343,9 @@ describe('barChartUtils', () => {
value: 565,
},
]);
expect(
formatChartData(series, null, null, 'timestamp', BAR_CHART_TYPES.SIMPLE)
).toBeNull();
});

it('formatChartData doesnt return null values', () => {
Expand Down

0 comments on commit b161d15

Please sign in to comment.