diff --git a/app/vmui/packages/vmui/src/components/CustomPanel/Views/GraphView.tsx b/app/vmui/packages/vmui/src/components/CustomPanel/Views/GraphView.tsx index 84ea4d9e2..ef58f0108 100644 --- a/app/vmui/packages/vmui/src/components/CustomPanel/Views/GraphView.tsx +++ b/app/vmui/packages/vmui/src/components/CustomPanel/Views/GraphView.tsx @@ -4,10 +4,11 @@ import LineChart from "../../LineChart/LineChart"; import {AlignedData as uPlotData, Series as uPlotSeries} from "uplot"; import Legend from "../../Legend/Legend"; import {getHideSeries, getLegendItem, getSeriesItem} from "../../../utils/uplot/series"; -import {getLimitsYAxis, getTimeSeries} from "../../../utils/uplot/axes"; +import {getLimitsYAxis, getMinMaxBuffer, getTimeSeries} from "../../../utils/uplot/axes"; import {LegendItem} from "../../../utils/uplot/types"; import {TimeParams} from "../../../types"; import {AxisRange, YaxisState} from "../../../state/graph/reducer"; +import {getAvgFromArray, getMaxFromArray, getMinFromArray} from "../../../utils/math"; export interface GraphViewProps { data?: MetricResult[]; @@ -104,10 +105,16 @@ const GraphView: FC = ({ } results.push(v); } - return results; + + // stabilize float numbers + const resultAsNumber = results.filter(s => s !== null) as number[]; + const avg = Math.abs(getAvgFromArray(resultAsNumber)); + const range = getMinMaxBuffer(getMinFromArray(resultAsNumber), getMaxFromArray(resultAsNumber)); + const rangeStep = Math.abs(range[1] - range[0]); + + return (avg > rangeStep * 1e10) ? results.map(() => avg) : results; }); timeDataSeries.unshift(timeSeries); - setLimitsYaxis(tempValues); setDataChart(timeDataSeries as uPlotData); setSeries(tempSeries); diff --git a/app/vmui/packages/vmui/src/utils/math.ts b/app/vmui/packages/vmui/src/utils/math.ts index 7fc1e9856..0463f9531 100644 --- a/app/vmui/packages/vmui/src/utils/math.ts +++ b/app/vmui/packages/vmui/src/utils/math.ts @@ -21,3 +21,5 @@ export const getMinFromArray = (a: number[]) => { } return Number.isFinite(min) ? min : null; }; + +export const getAvgFromArray = (a: number[]) => a.reduce((a,b) => a+b) / a.length;