HeatmapNG: skip y <= 0 values when log y axis (#51221)

This commit is contained in:
Leon Sorokin 2022-06-22 09:12:22 -05:00 committed by GitHub
parent be6a878fd6
commit ef53a49896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -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;

View File

@ -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;