mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 04:22:13 +08:00
DataLinks: make sure we use the correct datapoint when dataset contains null value. (#22981)
* Fix to make sure we have the correct dataIndex when using data links. * fixed strict null errors. * decreased number of errors.
This commit is contained in:
@ -37,6 +37,8 @@ import {
|
|||||||
PanelEvents,
|
PanelEvents,
|
||||||
formattedValueToString,
|
formattedValueToString,
|
||||||
FieldType,
|
FieldType,
|
||||||
|
DataFrame,
|
||||||
|
getTimeField,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { GraphContextMenuCtrl } from './GraphContextMenuCtrl';
|
import { GraphContextMenuCtrl } from './GraphContextMenuCtrl';
|
||||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||||
@ -254,6 +256,7 @@ class GraphElement {
|
|||||||
const yAxisConfig = this.panel.yaxes[item.series.yaxis.n === 2 ? 1 : 0];
|
const yAxisConfig = this.panel.yaxes[item.series.yaxis.n === 2 ? 1 : 0];
|
||||||
const dataFrame = this.ctrl.dataList[item.series.dataFrameIndex];
|
const dataFrame = this.ctrl.dataList[item.series.dataFrameIndex];
|
||||||
const field = dataFrame.fields[item.series.fieldIndex];
|
const field = dataFrame.fields[item.series.fieldIndex];
|
||||||
|
const dataIndex = this.getDataIndexWithNullValuesCorrection(item, dataFrame);
|
||||||
|
|
||||||
let links = this.panel.options.dataLinks || [];
|
let links = this.panel.options.dataLinks || [];
|
||||||
if (field.config.links && field.config.links.length) {
|
if (field.config.links && field.config.links.length) {
|
||||||
@ -267,13 +270,13 @@ class GraphElement {
|
|||||||
const fieldDisplay = getDisplayProcessor({
|
const fieldDisplay = getDisplayProcessor({
|
||||||
field: { config: fieldConfig, type: FieldType.number },
|
field: { config: fieldConfig, type: FieldType.number },
|
||||||
theme: getCurrentTheme(),
|
theme: getCurrentTheme(),
|
||||||
})(field.values.get(item.dataIndex));
|
})(field.values.get(dataIndex));
|
||||||
linksSupplier = links.length
|
linksSupplier = links.length
|
||||||
? getFieldLinksSupplier({
|
? getFieldLinksSupplier({
|
||||||
display: fieldDisplay,
|
display: fieldDisplay,
|
||||||
name: field.name,
|
name: field.name,
|
||||||
view: new DataFrameView(dataFrame),
|
view: new DataFrameView(dataFrame),
|
||||||
rowIndex: item.dataIndex,
|
rowIndex: dataIndex,
|
||||||
colIndex: item.series.fieldIndex,
|
colIndex: item.series.fieldIndex,
|
||||||
field: fieldConfig,
|
field: fieldConfig,
|
||||||
})
|
})
|
||||||
@ -290,6 +293,36 @@ class GraphElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDataIndexWithNullValuesCorrection(item: any, dataFrame: DataFrame): number {
|
||||||
|
/** This is one added to handle the scenario where we have null values in
|
||||||
|
* the time series data and the: "visualization options -> null value"
|
||||||
|
* set to "connected". In this scenario we will get the wrong dataIndex.
|
||||||
|
*
|
||||||
|
* https://github.com/grafana/grafana/issues/22651
|
||||||
|
*/
|
||||||
|
const { datapoint, dataIndex } = item;
|
||||||
|
|
||||||
|
if (!Array.isArray(datapoint) || datapoint.length === 0) {
|
||||||
|
return dataIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ts = datapoint[0];
|
||||||
|
const { timeField } = getTimeField(dataFrame);
|
||||||
|
|
||||||
|
if (!timeField || !timeField.values) {
|
||||||
|
return dataIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
const field = timeField.values.get(dataIndex);
|
||||||
|
|
||||||
|
if (field === ts) {
|
||||||
|
return dataIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
const correctIndex = timeField.values.toArray().findIndex(value => value === ts);
|
||||||
|
return correctIndex > -1 ? correctIndex : dataIndex;
|
||||||
|
}
|
||||||
|
|
||||||
shouldAbortRender() {
|
shouldAbortRender() {
|
||||||
if (!this.data) {
|
if (!this.data) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
echo -e "Collecting code stats (typescript errors & more)"
|
echo -e "Collecting code stats (typescript errors & more)"
|
||||||
|
|
||||||
|
|
||||||
ERROR_COUNT_LIMIT=820
|
ERROR_COUNT_LIMIT=816
|
||||||
DIRECTIVES_LIMIT=172
|
DIRECTIVES_LIMIT=172
|
||||||
CONTROLLERS_LIMIT=139
|
CONTROLLERS_LIMIT=139
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user