mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
HeatmapNG: expand log y axis min/max config to full powers (#51472)
also fix x bucket count setting for calculate (regressed in #51089) Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
@@ -316,7 +316,12 @@ export function calculateHeatmapFromData(frames: DataFrame[], options: HeatmapCa
|
||||
xSorted: true,
|
||||
xTime: xField.type === FieldType.time,
|
||||
xMode: xBucketsCfg.mode,
|
||||
xSize: durationToMilliseconds(parseDuration(xBucketsCfg.value ?? '')),
|
||||
xSize:
|
||||
xBucketsCfg.mode === HeatmapCalculationMode.Size
|
||||
? durationToMilliseconds(parseDuration(xBucketsCfg.value ?? ''))
|
||||
: xBucketsCfg.value
|
||||
? +xBucketsCfg.value
|
||||
: undefined,
|
||||
yMode: yBucketsCfg.mode,
|
||||
ySize: yBucketsCfg.value ? +yBucketsCfg.value : undefined,
|
||||
yLog: scaleDistribution?.type === ScaleDistribution.Log ? (scaleDistribution?.log as any) : undefined,
|
||||
|
||||
@@ -289,15 +289,21 @@ export function prepConfig(opts: PrepConfigOpts) {
|
||||
: [dataMin, dataMax];
|
||||
|
||||
if (shouldUseLogScale && !isOrdianalY) {
|
||||
let yExp = u.scales[yScaleKey].log!;
|
||||
let log = yExp === 2 ? Math.log2 : Math.log10;
|
||||
|
||||
let { min: explicitMin, max: explicitMax } = yAxisConfig;
|
||||
|
||||
// guard against <= 0
|
||||
if (explicitMin != null && explicitMin > 0) {
|
||||
scaleMin = explicitMin;
|
||||
// snap to magnitude
|
||||
let minLog = log(explicitMin);
|
||||
scaleMin = yExp ** incrRoundDn(minLog, 1);
|
||||
}
|
||||
|
||||
if (explicitMax != null && explicitMax > 0) {
|
||||
scaleMax = explicitMax;
|
||||
let maxLog = log(explicitMax);
|
||||
scaleMax = yExp ** incrRoundUp(maxLog, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,6 +311,9 @@ export function prepConfig(opts: PrepConfigOpts) {
|
||||
}
|
||||
: // dense and ordinal only have one of yMin|yMax|y, so expand range by one cell in the direction of le/ge/unknown
|
||||
(u, dataMin, dataMax) => {
|
||||
let scaleMin = dataMin,
|
||||
scaleMax = dataMax;
|
||||
|
||||
let { min: explicitMin, max: explicitMax } = yAxisConfig;
|
||||
|
||||
// logarithmic expansion
|
||||
@@ -314,44 +323,47 @@ export function prepConfig(opts: PrepConfigOpts) {
|
||||
let minExpanded = false;
|
||||
let maxExpanded = false;
|
||||
|
||||
if (ySizeDivisor !== 1) {
|
||||
let log = yExp === 2 ? Math.log2 : Math.log10;
|
||||
let log = yExp === 2 ? Math.log2 : Math.log10;
|
||||
|
||||
if (ySizeDivisor !== 1) {
|
||||
let minLog = log(dataMin);
|
||||
let maxLog = log(dataMax);
|
||||
|
||||
if (!Number.isInteger(minLog)) {
|
||||
dataMin = yExp ** incrRoundDn(minLog, 1);
|
||||
scaleMin = yExp ** incrRoundDn(minLog, 1);
|
||||
minExpanded = true;
|
||||
}
|
||||
|
||||
if (!Number.isInteger(maxLog)) {
|
||||
dataMax = yExp ** incrRoundUp(maxLog, 1);
|
||||
scaleMax = yExp ** incrRoundUp(maxLog, 1);
|
||||
maxExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (dataRef.current?.yLayout === HeatmapCellLayout.le) {
|
||||
if (!minExpanded) {
|
||||
dataMin /= yExp;
|
||||
scaleMin /= yExp;
|
||||
}
|
||||
} else if (dataRef.current?.yLayout === HeatmapCellLayout.ge) {
|
||||
if (!maxExpanded) {
|
||||
dataMax *= yExp;
|
||||
scaleMax *= yExp;
|
||||
}
|
||||
} else {
|
||||
dataMin /= yExp / 2;
|
||||
dataMax *= yExp / 2;
|
||||
scaleMin /= yExp / 2;
|
||||
scaleMax *= yExp / 2;
|
||||
}
|
||||
|
||||
if (!isOrdianalY) {
|
||||
// guard against <= 0
|
||||
if (explicitMin != null && explicitMin > 0) {
|
||||
dataMin = explicitMin;
|
||||
// snap down to magnitude
|
||||
let minLog = log(explicitMin);
|
||||
scaleMin = yExp ** incrRoundDn(minLog, 1);
|
||||
}
|
||||
|
||||
if (explicitMax != null && explicitMax > 0) {
|
||||
dataMax = explicitMax;
|
||||
let maxLog = log(explicitMax);
|
||||
scaleMax = yExp ** incrRoundUp(maxLog, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,24 +377,24 @@ export function prepConfig(opts: PrepConfigOpts) {
|
||||
|
||||
if (bucketSize) {
|
||||
if (dataRef.current?.yLayout === HeatmapCellLayout.le) {
|
||||
dataMin -= bucketSize!;
|
||||
scaleMin -= bucketSize!;
|
||||
} else if (dataRef.current?.yLayout === HeatmapCellLayout.ge) {
|
||||
dataMax += bucketSize!;
|
||||
scaleMax += bucketSize!;
|
||||
} else {
|
||||
dataMin -= bucketSize! / 2;
|
||||
dataMax += bucketSize! / 2;
|
||||
scaleMin -= bucketSize! / 2;
|
||||
scaleMax += bucketSize! / 2;
|
||||
}
|
||||
} else {
|
||||
// how to expand scale range if inferred non-regular or log buckets?
|
||||
}
|
||||
|
||||
if (!isOrdianalY) {
|
||||
dataMin = explicitMin ?? dataMin;
|
||||
dataMax = explicitMax ?? dataMax;
|
||||
scaleMin = explicitMin ?? scaleMin;
|
||||
scaleMax = explicitMax ?? scaleMax;
|
||||
}
|
||||
}
|
||||
|
||||
return [dataMin, dataMax];
|
||||
return [scaleMin, scaleMax];
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user