Skip to content

Commit

Permalink
Histogram: Respect min/max panel settings for x-axis (#62273)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed May 10, 2023
1 parent 8cd4866 commit 8f8baf1
Showing 1 changed file with 14 additions and 2 deletions.
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

0 comments on commit 8f8baf1

Please sign in to comment.