mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
vmui: limit the number of decimal places to 10 characters (#3258)
* fix: limit the number of decimal places to 10 characters * fix: add float numbers stabilizer
This commit is contained in:
parent
ab880afa50
commit
346d49ae61
2 changed files with 12 additions and 3 deletions
|
@ -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<GraphViewProps> = ({
|
|||
}
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue