mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TrendPanel: use isLikelyAscendingVector rather than brute force (#65977)
use likely frames
This commit is contained in:
parent
a378e34250
commit
7e312a6aa6
@ -1,6 +1,7 @@
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { FieldType, PanelProps } from '@grafana/data';
|
||||
import { isLikelyAscendingVector } from '@grafana/data/src/transformations/transformers/joinDataFrames';
|
||||
import { config, PanelDataErrorView } from '@grafana/runtime';
|
||||
import { KeyboardPlugin, TimeSeries, TooltipDisplayMode, TooltipPlugin, usePanelContext } from '@grafana/ui';
|
||||
import { findFieldIndex } from 'app/features/dimensions';
|
||||
@ -56,20 +57,11 @@ export const TrendPanel = ({
|
||||
// Make sure values are ascending
|
||||
if (xFieldIdx != null) {
|
||||
const field = frames[0].fields[xFieldIdx];
|
||||
if (field.type === FieldType.number) {
|
||||
// we may support ordinal soon
|
||||
let last = Number.NEGATIVE_INFINITY;
|
||||
const values = field.values.toArray();
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
const v = values[i];
|
||||
if (last > v) {
|
||||
return {
|
||||
warning: `Values must be in ascending order (index: ${i}, ${last} > ${v})`,
|
||||
frames,
|
||||
};
|
||||
}
|
||||
last = v;
|
||||
}
|
||||
if (field.type === FieldType.number && !isLikelyAscendingVector(field.values)) {
|
||||
return {
|
||||
warning: `Values must be in ascending order`,
|
||||
frames,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user