diff --git a/public/app/features/transformers/calculateHeatmap/heatmap.ts b/public/app/features/transformers/calculateHeatmap/heatmap.ts index 8a19940b6c6..af52aa0edfb 100644 --- a/public/app/features/transformers/calculateHeatmap/heatmap.ts +++ b/public/app/features/transformers/calculateHeatmap/heatmap.ts @@ -387,6 +387,8 @@ function heatmap(xs: number[], ys: number[], opts?: HeatmapOpts) { let maxX = xSorted ? xs[len - 1] : -Infinity; let maxY = ySorted ? ys[len - 1] : -Infinity; + let yExp = opts?.yLog; + for (let i = 0; i < len; i++) { if (!xSorted) { minX = Math.min(minX, xs[i]); @@ -394,17 +396,13 @@ function heatmap(xs: number[], ys: number[], opts?: HeatmapOpts) { } if (!ySorted) { - minY = Math.min(minY, ys[i]); - maxY = Math.max(maxY, ys[i]); + if (!yExp || ys[i] > 0) { + minY = Math.min(minY, ys[i]); + maxY = Math.max(maxY, ys[i]); + } } } - let yExp = opts?.yLog; - - if (yExp && (minY <= 0 || maxY <= 0)) { - throw 'Log Y axes cannot have values <= 0'; - } - //let scaleX = opts?.xLog === 10 ? Math.log10 : opts?.xLog === 2 ? Math.log2 : (v: number) => v; //let scaleY = opts?.yLog === 10 ? Math.log10 : opts?.yLog === 2 ? Math.log2 : (v: number) => v; @@ -466,6 +464,10 @@ function heatmap(xs: number[], ys: number[], opts?: HeatmapOpts) { let [xs2, ys2, counts] = initBins(xBinQty, yBinQty, minXBin, xBinIncr, minYBin, yBinIncr, yExp); for (let i = 0; i < len; i++) { + if (yExp && ys[i] <= 0) { + continue; + } + const xi = (binX(xs[i]) - minXBin) / xBinIncr; const yi = (binY(ys[i]) - minYBin) / yBinIncr; const ci = xi * yBinQty + yi; diff --git a/public/app/plugins/panel/heatmap-new/utils.ts b/public/app/plugins/panel/heatmap-new/utils.ts index 579307f4060..c4fc2bffc12 100644 --- a/public/app/plugins/panel/heatmap-new/utils.ts +++ b/public/app/plugins/panel/heatmap-new/utils.ts @@ -919,7 +919,7 @@ export const boundedMinMax = ( }; export const valuesToFills = (values: number[], palette: string[], minValue: number, maxValue: number) => { - let range = maxValue - minValue; + let range = Math.max(maxValue - minValue, 1); let paletteSize = palette.length;