diff --git a/public/app/plugins/panel/histogram/Histogram.tsx b/public/app/plugins/panel/histogram/Histogram.tsx index 89cb7d674f2..092560382f4 100644 --- a/public/app/plugins/panel/histogram/Histogram.tsx +++ b/public/app/plugins/panel/histogram/Histogram.tsx @@ -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] @@ -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); @@ -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];