Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/GraphNG: support soft min max axis #30238

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/grafana-ui/src/components/GraphNG/GraphNG.tsx
Expand Up @@ -155,6 +155,8 @@ export const GraphNG: React.FC<GraphNGProps> = ({
log: customConfig.scaleDistribution?.log,
min: field.config.min,
max: field.config.max,
softMin: customConfig.axisSoftMin,
softMax: customConfig.axisSoftMax,
});

builder.addAxis({
Expand Down
4 changes: 3 additions & 1 deletion packages/grafana-ui/src/components/uPlot/config.ts
Expand Up @@ -110,7 +110,9 @@ export interface ScaleDistributionConfig {
export interface AxisConfig {
axisPlacement?: AxisPlacement;
axisLabel?: string;
axisWidth?: number; // pixels ideally auto?
axisWidth?: number;
axisSoftMin?: number;
axisSoftMax?: number;
scaleDistribution?: ScaleDistributionConfig;
}

Expand Down
Expand Up @@ -9,18 +9,24 @@ export interface ScaleProps {
max?: number | null;
range?: () => number[]; // min/max
distribution?: ScaleDistribution;
softMin?: number | null;
softMax?: number | null;
log?: number;
}

export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
merge(props: ScaleProps) {
this.props.min = optMinMax('min', this.props.min, props.min);
this.props.max = optMinMax('max', this.props.max, props.max);

// Soft varient
this.props.softMin = optMinMax('min', this.props.softMin, props.softMin);
this.props.softMax = optMinMax('max', this.props.softMax, props.softMax);
}

// uPlot range function
range = (u: uPlot, dataMin: number, dataMax: number, scaleKey: string) => {
const { min, max } = this.props;
const { min, max, softMin, softMax } = this.props;

const scale = u.scales[scaleKey];

Expand All @@ -33,6 +39,8 @@ export class UPlotScaleBuilder extends PlotConfigBuilder<ScaleProps, Scale> {
[smin, smax] = uPlot.rangeLog(min ?? dataMin, max ?? dataMax, scale.log, true);
}

console.log('TODO, use soft limits', softMin, softMax);

return [min ?? smin, max ?? smax];
};

Expand Down
16 changes: 16 additions & 0 deletions public/app/plugins/panel/timeseries/config.ts
Expand Up @@ -158,6 +158,22 @@ export function getGraphFieldConfig(cfg: GraphFieldConfig): SetFieldConfigOption
},
showIf: c => c.axisPlacement !== AxisPlacement.Hidden,
})
.addNumberInput({
path: 'axisSoftMin',
name: 'Soft min',
category: ['Axis'],
settings: {
placeholder: 'See: Standard options > Min',
},
})
.addNumberInput({
path: 'axisSoftMax',
name: 'Soft max',
category: ['Axis'],
settings: {
placeholder: 'See: Standard options > Max',
},
})
.addCustomEditor<void, ScaleDistributionConfig>({
id: 'scaleDistribution',
path: 'scaleDistribution',
Expand Down