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

[v9.5.x] Histogram: Respect min/max panel settings for x-axis #68244

Merged
merged 1 commit into from May 10, 2023
Merged
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
16 changes: 14 additions & 2 deletions public/app/plugins/panel/histogram/Histogram.tsx
Expand Up @@ -53,6 +53,10 @@ export function getBucketSize(frame: DataFrame) {
const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => {
// todo: scan all values in BucketMin and BucketMax fields to assert if uniform bucketSize

// since this is x axis range, this should ideally come from xMin or xMax fields, not a count field
// though both methods are probably hacks, and we should just accept explicit opts into this prepConfig
let { min: xScaleMin, max: xScaleMax } = frame.fields[2].config;

let builder = new UPlotConfigBuilder();

// assumes BucketMin is fields[0] and BucktMax is fields[1]
Expand All @@ -64,8 +68,8 @@ const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => {
let minSpace = u.axes[axisIdx]._space;
let bucketWidth = u.valToPos(u.data[0][0] + bucketSize, 'x') - u.valToPos(u.data[0][0], 'x');

let firstSplit = u.data[0][0];
let lastSplit = u.data[0][u.data[0].length - 1] + bucketSize;
let firstSplit = incrRoundDn(xScaleMin ?? u.data[0][0], bucketSize);
let lastSplit = incrRoundUp(xScaleMax ?? u.data[0][u.data[0].length - 1] + bucketSize, bucketSize);

let splits = [];
let skip = Math.ceil(minSpace / bucketWidth);
Expand All @@ -84,6 +88,14 @@ const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => {
orientation: ScaleOrientation.Horizontal,
direction: ScaleDirection.Right,
range: (u, wantedMin, wantedMax) => {
// these settings will prevent zooming, probably okay?
if (xScaleMin != null) {
wantedMin = xScaleMin;
}
if (xScaleMax != null) {
wantedMax = xScaleMax;
}

let fullRangeMin = u.data[0][0];
let fullRangeMax = u.data[0][u.data[0].length - 1];

Expand Down