mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeSeries: Fix crash when min >= max in config (#54069)
* TimeSeries: fix crash when min === max in config * stat sparkline, too * better types
This commit is contained in:
parent
c29a2c37c1
commit
530dd63ac6
@ -1694,8 +1694,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "20"]
|
||||
],
|
||||
"packages/grafana-ui/src/components/Sparkline/Sparkline.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
|
@ -93,7 +93,7 @@ export class Sparkline extends PureComponent<SparklineProps, State> {
|
||||
}
|
||||
}
|
||||
|
||||
getYRange(field: Field) {
|
||||
getYRange(field: Field): Range.MinMax {
|
||||
let { min, max } = this.state.alignedDataFrame.fields[1].state?.range!;
|
||||
|
||||
if (min === max) {
|
||||
@ -103,12 +103,11 @@ export class Sparkline extends PureComponent<SparklineProps, State> {
|
||||
min = 0;
|
||||
max! *= 2;
|
||||
}
|
||||
|
||||
return [min, max!];
|
||||
}
|
||||
|
||||
return [
|
||||
Math.max(min!, field.config.min ?? -Infinity),
|
||||
Math.min(max!, field.config.max ?? Infinity),
|
||||
] as Range.MinMax;
|
||||
return [Math.max(min!, field.config.min ?? -Infinity), Math.min(max!, field.config.max ?? Infinity)];
|
||||
}
|
||||
|
||||
prepareConfig(data: DataFrame) {
|
||||
|
@ -109,6 +109,12 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
||||
minMax[1] = hardMax!;
|
||||
}
|
||||
|
||||
// guard against invalid y ranges
|
||||
if (minMax[0]! >= minMax[1]!) {
|
||||
minMax[0] = 0;
|
||||
minMax[1] = 100;
|
||||
}
|
||||
|
||||
return minMax;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user