Fix: prevents the BarGauge from exploding when the datasource returns empty result. (#21791)

* Fixed issue where gauge throw error on empty result.

* Some refactorings to improve the code.

* Added some tests to make sure this doesn't happen again.
This commit is contained in:
Marcus Andersson
2020-01-29 11:40:30 +01:00
committed by GitHub
parent 8aed87394d
commit cab082438e
4 changed files with 77 additions and 3 deletions
@@ -1,5 +1,6 @@
import { Vector } from '../types/vector';
import { DataFrame } from '../types/dataFrame';
import { DisplayProcessor } from '../types';
/**
* This abstraction will present the contents of a DataFrame as if
@@ -55,6 +56,20 @@ export class DataFrameView<T = any> implements Vector<T> {
return this.data.length;
}
getFieldDisplayProcessor(colIndex: number): DisplayProcessor | null {
if (!this.dataFrame || !this.dataFrame.fields) {
return null;
}
const field = this.dataFrame.fields[colIndex];
if (!field || !field.display) {
return null;
}
return field.display;
}
get(idx: number) {
this.index = idx;
return this.obj;