mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeSeries: Add option for symmetrical y axes (align 0) (#52555)
This commit is contained in:
parent
bf8bb26f63
commit
d7b208ec58
@ -95,6 +95,7 @@ AxisConfig: {
|
|||||||
axisSoftMax?: number
|
axisSoftMax?: number
|
||||||
axisGridShow?: bool
|
axisGridShow?: bool
|
||||||
scaleDistribution?: ScaleDistributionConfig
|
scaleDistribution?: ScaleDistributionConfig
|
||||||
|
axisCenteredZero?: bool
|
||||||
} @cuetsy(kind="interface")
|
} @cuetsy(kind="interface")
|
||||||
|
|
||||||
// TODO docs
|
// TODO docs
|
||||||
|
@ -123,6 +123,7 @@ export interface ScaleDistributionConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AxisConfig {
|
export interface AxisConfig {
|
||||||
|
axisCenteredZero?: boolean;
|
||||||
axisColorMode?: AxisColorMode;
|
axisColorMode?: AxisColorMode;
|
||||||
axisGridShow?: boolean;
|
axisGridShow?: boolean;
|
||||||
axisLabel?: string;
|
axisLabel?: string;
|
||||||
|
@ -185,6 +185,7 @@ export const preparePlotConfigBuilder: UPlotConfigPrepFn<{
|
|||||||
max: field.config.max,
|
max: field.config.max,
|
||||||
softMin: customConfig.axisSoftMin,
|
softMin: customConfig.axisSoftMin,
|
||||||
softMax: customConfig.axisSoftMax,
|
softMax: customConfig.axisSoftMax,
|
||||||
|
centeredZero: customConfig.axisCenteredZero,
|
||||||
},
|
},
|
||||||
field
|
field
|
||||||
)
|
)
|
||||||
|
@ -17,6 +17,7 @@ export interface ScaleProps {
|
|||||||
orientation: ScaleOrientation;
|
orientation: ScaleOrientation;
|
||||||
direction: ScaleDirection;
|
direction: ScaleDirection;
|
||||||
log?: number;
|
log?: number;
|
||||||
|
centeredZero?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
||||||
@ -26,7 +27,18 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConfig(): Scale {
|
getConfig(): Scale {
|
||||||
let { isTime, scaleKey, min: hardMin, max: hardMax, softMin, softMax, range, direction, orientation } = this.props;
|
let {
|
||||||
|
isTime,
|
||||||
|
scaleKey,
|
||||||
|
min: hardMin,
|
||||||
|
max: hardMax,
|
||||||
|
softMin,
|
||||||
|
softMax,
|
||||||
|
range,
|
||||||
|
direction,
|
||||||
|
orientation,
|
||||||
|
centeredZero,
|
||||||
|
} = this.props;
|
||||||
const distribution = !isTime
|
const distribution = !isTime
|
||||||
? {
|
? {
|
||||||
distr:
|
distr:
|
||||||
@ -68,6 +80,14 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
|
|||||||
let minMax: uPlot.Range.MinMax = [dataMin, dataMax];
|
let minMax: uPlot.Range.MinMax = [dataMin, dataMax];
|
||||||
|
|
||||||
if (scale.distr === 1 || scale.distr === 2) {
|
if (scale.distr === 1 || scale.distr === 2) {
|
||||||
|
if (centeredZero) {
|
||||||
|
let absMin = Math.abs(dataMin);
|
||||||
|
let absMax = Math.abs(dataMax);
|
||||||
|
let max = Math.max(absMin, absMax);
|
||||||
|
dataMin = -max;
|
||||||
|
dataMax = max;
|
||||||
|
}
|
||||||
|
|
||||||
// @ts-ignore here we may use hardMin / hardMax to make sure any extra padding is computed from a more accurate delta
|
// @ts-ignore here we may use hardMin / hardMax to make sure any extra padding is computed from a more accurate delta
|
||||||
minMax = uPlot.rangeNum(hardMinOnly ? hardMin : dataMin, hardMaxOnly ? hardMax : dataMax, rangeConfig);
|
minMax = uPlot.rangeNum(hardMinOnly ? hardMin : dataMin, hardMaxOnly ? hardMax : dataMax, rangeConfig);
|
||||||
} else if (scale.distr === 3) {
|
} else if (scale.distr === 3) {
|
||||||
|
@ -20,6 +20,8 @@ export function addAxisConfig(
|
|||||||
hideScale?: boolean
|
hideScale?: boolean
|
||||||
) {
|
) {
|
||||||
const category = ['Axis'];
|
const category = ['Axis'];
|
||||||
|
|
||||||
|
// options for axis appearance
|
||||||
builder
|
builder
|
||||||
.addRadio({
|
.addRadio({
|
||||||
path: 'axisPlacement',
|
path: 'axisPlacement',
|
||||||
@ -51,24 +53,6 @@ export function addAxisConfig(
|
|||||||
},
|
},
|
||||||
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
|
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
|
||||||
})
|
})
|
||||||
.addNumberInput({
|
|
||||||
path: 'axisSoftMin',
|
|
||||||
name: 'Soft min',
|
|
||||||
defaultValue: defaultConfig.axisSoftMin,
|
|
||||||
category,
|
|
||||||
settings: {
|
|
||||||
placeholder: 'See: Standard options > Min',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.addNumberInput({
|
|
||||||
path: 'axisSoftMax',
|
|
||||||
name: 'Soft max',
|
|
||||||
defaultValue: defaultConfig.axisSoftMax,
|
|
||||||
category,
|
|
||||||
settings: {
|
|
||||||
placeholder: 'See: Standard options > Max',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.addRadio({
|
.addRadio({
|
||||||
path: 'axisGridShow',
|
path: 'axisGridShow',
|
||||||
name: 'Show grid lines',
|
name: 'Show grid lines',
|
||||||
@ -95,8 +79,9 @@ export function addAxisConfig(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!hideScale) {
|
// options for scale range
|
||||||
builder.addCustomEditor<void, ScaleDistributionConfig>({
|
builder
|
||||||
|
.addCustomEditor<void, ScaleDistributionConfig>({
|
||||||
id: 'scaleDistribution',
|
id: 'scaleDistribution',
|
||||||
path: 'scaleDistribution',
|
path: 'scaleDistribution',
|
||||||
name: 'Scale',
|
name: 'Scale',
|
||||||
@ -106,8 +91,32 @@ export function addAxisConfig(
|
|||||||
defaultValue: { type: ScaleDistribution.Linear },
|
defaultValue: { type: ScaleDistribution.Linear },
|
||||||
shouldApply: (f) => f.type === FieldType.number,
|
shouldApply: (f) => f.type === FieldType.number,
|
||||||
process: identityOverrideProcessor,
|
process: identityOverrideProcessor,
|
||||||
|
})
|
||||||
|
.addBooleanSwitch({
|
||||||
|
path: 'axisCenteredZero',
|
||||||
|
name: 'Centered zero',
|
||||||
|
category,
|
||||||
|
defaultValue: false,
|
||||||
|
showIf: (c) => c.scaleDistribution?.type !== ScaleDistribution.Log,
|
||||||
|
})
|
||||||
|
.addNumberInput({
|
||||||
|
path: 'axisSoftMin',
|
||||||
|
name: 'Soft min',
|
||||||
|
defaultValue: defaultConfig.axisSoftMin,
|
||||||
|
category,
|
||||||
|
settings: {
|
||||||
|
placeholder: 'See: Standard options > Min',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.addNumberInput({
|
||||||
|
path: 'axisSoftMax',
|
||||||
|
name: 'Soft max',
|
||||||
|
defaultValue: defaultConfig.axisSoftMax,
|
||||||
|
category,
|
||||||
|
settings: {
|
||||||
|
placeholder: 'See: Standard options > Max',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const DISTRIBUTION_OPTIONS: Array<SelectableValue<ScaleDistribution>> = [
|
const DISTRIBUTION_OPTIONS: Array<SelectableValue<ScaleDistribution>> = [
|
||||||
|
@ -37,6 +37,7 @@ export const defaultGraphConfig: GraphFieldConfig = {
|
|||||||
group: 'A',
|
group: 'A',
|
||||||
},
|
},
|
||||||
axisGridShow: true,
|
axisGridShow: true,
|
||||||
|
axisCenteredZero: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const categoryStyles = ['Graph styles'];
|
const categoryStyles = ['Graph styles'];
|
||||||
|
Loading…
Reference in New Issue
Block a user