Heatmap: Improve error messaging if no numeric fields were provided (#113985)
* Heatmap: Improve error messaging if no numeric fields were provided * update i18n
This commit is contained in:
@@ -108,4 +108,17 @@ describe('Heatmap transformer', () => {
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('throws error if no numeric fields are present', async () => {
|
||||
expect(() =>
|
||||
rowsToCellsHeatmap({
|
||||
frame: toDataFrame({
|
||||
fields: [
|
||||
{ name: 'time', type: FieldType.time, values: [1, 2, 3, 4] },
|
||||
{ name: 'label', type: FieldType.string, values: ['a', 'b', 'c', 'd'] },
|
||||
],
|
||||
}),
|
||||
})
|
||||
).toThrowErrorMatchingInlineSnapshot(`"No numeric fields found for heatmap"`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,6 +125,10 @@ export function rowsToCellsHeatmap(opts: RowsHeatmapOptions): DataFrame {
|
||||
const xValues = xField.values;
|
||||
const yFields = opts.frame.fields.filter((f, idx) => f.type === FieldType.number && idx > 0);
|
||||
|
||||
if (yFields.length === 0) {
|
||||
throw new Error(t('heatmap.error.no-y-fields', 'No numeric fields found for heatmap'));
|
||||
}
|
||||
|
||||
// similar to initBins() below
|
||||
const len = xValues.length * yFields.length;
|
||||
const xs = new Array(len);
|
||||
|
||||
@@ -55,6 +55,7 @@ export const HeatmapPanel = (props: HeatmapPanelProps) => {
|
||||
timeRange,
|
||||
});
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
return { warning: `${ex}` };
|
||||
}
|
||||
}, [data.series, data.annotations, options, palette, theme, replaceVariables, timeRange]);
|
||||
|
||||
@@ -9153,6 +9153,9 @@
|
||||
"category-legend": "Legend",
|
||||
"category-tooltip": "Tooltip",
|
||||
"category-y-axis": "Y Axis",
|
||||
"error": {
|
||||
"no-y-fields": "No numeric fields found for heatmap"
|
||||
},
|
||||
"mode-options": {
|
||||
"label-opacity": "Opacity",
|
||||
"label-scheme": "Scheme"
|
||||
|
||||
Reference in New Issue
Block a user