mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
HeatmapNG: skip y <= 0 values when log y axis (#51221)
This commit is contained in:
parent
be6a878fd6
commit
ef53a49896
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user