Skip to content

Commit 7f60e73

Browse files
authored
fix(react-charting): Log empty x and y arrays for bar chart (microsoft#35166)
1 parent d7aef65 commit 7f60e73

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix(react-charting): Log empty x and y arrays for bar chart",
4+
"packageName": "@fluentui/chart-utilities",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/chart-utilities/src/PlotlySchemaConverter.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ const validateSeriesData = (series: Partial<PlotData>, validateNumericY: boolean
232232
};
233233

234234
const validateBarData = (data: Partial<PlotData>) => {
235+
const isXEmpty = data.x && isArrayOrTypedArray(data.x) && data.x.length === 0;
236+
const isYEmpty = data.y && isArrayOrTypedArray(data.y) && data.y.length === 0;
237+
if (isXEmpty || isYEmpty) {
238+
let emptyMsg = 'Bar chart: ';
239+
if (isXEmpty && isYEmpty) {
240+
emptyMsg += 'both x and y arrays are empty.';
241+
} else if (isXEmpty) {
242+
emptyMsg += 'x array is empty.';
243+
} else if (isYEmpty) {
244+
emptyMsg += 'y array is empty.';
245+
}
246+
throw new Error(emptyMsg);
247+
}
235248
if (data.orientation === 'h') {
236249
if (!isNumberArray(data.x) && !isDateArray(data.x)) {
237250
throw new Error(
@@ -245,8 +258,10 @@ const validateBarData = (data: Partial<PlotData>) => {
245258
);
246259
}
247260
validateSeriesData(data, false);
248-
} else if (!isNumberArray(data.y) && !isStringArray(data.y) && !isObjectArray(data.y)) {
249-
throw new Error(`Non numeric, string, or object Y values encountered, type: ${typeof data.y}`);
261+
} else {
262+
if (!isNumberArray(data.y) && !isStringArray(data.y) && !isObjectArray(data.y)) {
263+
throw new Error(`Non numeric, string, or object Y values encountered, type: ${typeof data.y}`);
264+
}
250265
}
251266
};
252267
const isScatterMarkers = (mode: string): boolean => {

0 commit comments

Comments
 (0)