mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Timeseries: Utilize min/max on stacking percentage (#95581)
* Bring in defined min/max into stacking range * simplify logic * different approach --------- Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
parent
ddf766567b
commit
68aefc73b6
@ -1,7 +1,7 @@
|
|||||||
import uPlot, { Scale, Range } from 'uplot';
|
import uPlot, { Scale, Range } from 'uplot';
|
||||||
|
|
||||||
import { DecimalCount, incrRoundDn, incrRoundUp, isBooleanUnit } from '@grafana/data';
|
import { DecimalCount, incrRoundDn, incrRoundUp, isBooleanUnit } from '@grafana/data';
|
||||||
import { ScaleOrientation, ScaleDirection, ScaleDistribution } from '@grafana/schema';
|
import { ScaleOrientation, ScaleDirection, ScaleDistribution, StackingMode } from '@grafana/schema';
|
||||||
|
|
||||||
import { PlotConfigBuilder } from '../types';
|
import { PlotConfigBuilder } from '../types';
|
||||||
|
|
||||||
@ -20,6 +20,7 @@ export interface ScaleProps {
|
|||||||
linearThreshold?: number;
|
linearThreshold?: number;
|
||||||
centeredZero?: boolean;
|
centeredZero?: boolean;
|
||||||
decimals?: DecimalCount;
|
decimals?: DecimalCount;
|
||||||
|
stackingMode?: StackingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
||||||
@ -41,8 +42,19 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
|||||||
orientation,
|
orientation,
|
||||||
centeredZero,
|
centeredZero,
|
||||||
decimals,
|
decimals,
|
||||||
|
stackingMode,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
if (stackingMode === StackingMode.Percent) {
|
||||||
|
if (hardMin == null && softMin == null) {
|
||||||
|
softMin = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hardMax == null && softMax == null) {
|
||||||
|
softMax = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const distr = this.props.distribution;
|
const distr = this.props.distribution;
|
||||||
|
|
||||||
const distribution = !isTime
|
const distribution = !isTime
|
||||||
|
@ -247,14 +247,9 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn = ({
|
|||||||
softMin: customConfig.axisSoftMin,
|
softMin: customConfig.axisSoftMin,
|
||||||
softMax: customConfig.axisSoftMax,
|
softMax: customConfig.axisSoftMax,
|
||||||
centeredZero: customConfig.axisCenteredZero,
|
centeredZero: customConfig.axisCenteredZero,
|
||||||
|
stackingMode: customConfig.stacking?.mode,
|
||||||
range:
|
range:
|
||||||
customConfig.stacking?.mode === StackingMode.Percent
|
field.type === FieldType.enum
|
||||||
? (u: uPlot, dataMin: number, dataMax: number) => {
|
|
||||||
dataMin = dataMin < 0 ? -1 : 0;
|
|
||||||
dataMax = dataMax > 0 ? 1 : 0;
|
|
||||||
return [dataMin, dataMax];
|
|
||||||
}
|
|
||||||
: field.type === FieldType.enum
|
|
||||||
? (u: uPlot, dataMin: number, dataMax: number) => {
|
? (u: uPlot, dataMin: number, dataMax: number) => {
|
||||||
// this is the exhaustive enum (stable)
|
// this is the exhaustive enum (stable)
|
||||||
let len = field.config.type!.enum!.text!.length;
|
let len = field.config.type!.enum!.text!.length;
|
||||||
|
Loading…
Reference in New Issue
Block a user