Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Fix bad method calls; fix NaN bugs
  • Loading branch information
camdecoster committed Aug 21, 2025
commit a1e2dee63cfad21e13f9ee85c8acedd64c3426d9
3 changes: 2 additions & 1 deletion src/components/color/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const combine = (front, back = background) => {
fc.alpha ||= 1;
if(fc.alpha === 1) return color(front).rgb().string();

const bc = color(back).rgb().object;
const bc = color(back).rgb().object();
bc.alpha ||= 1;
const bcflat = bc.alpha === 1
? bc
Expand Down Expand Up @@ -77,6 +77,7 @@ const contrast = (cstr, lightAmount, darkAmount) => {

if(c.alpha() !== 1) c = color(combine(cstr, background));

// TODO: Should the API change such that lightAmount/darkAmount are passed in as decimal instead of percent number?
const newColor = color(
c.isDark()
? (lightAmount ? c.lighten(lightAmount / 100) : background)
Expand Down
5 changes: 3 additions & 2 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ function createSpikelines(gd, closestPoints, opts) {
hLinePointX = xa._offset + hLinePoint.x;
hLinePointY = ya._offset + hLinePoint.y;
}
var dfltHLineColor = Color.color(hLinePoint.color).contrast(contrastColor) < 1.5
var dfltHLineColor = Color.color(hLinePoint.color).contrast(Color.color(contrastColor)) < 1.5
? Color.contrast(contrastColor)
: hLinePoint.color;
var yMode = ya.spikemode;
Expand Down Expand Up @@ -2207,7 +2207,8 @@ function createSpikelines(gd, closestPoints, opts) {
vLinePointX = xa._offset + vLinePoint.x;
vLinePointY = ya._offset + vLinePoint.y;
}
var dfltVLineColor = Color.color(vLinePoint.color).contrast(contrastColor) < 1.5

var dfltVLineColor = Color.color(vLinePoint.color).contrast(Color.color(contrastColor)) < 1.5
? Color.contrast(contrastColor)
: vLinePoint.color;
var xMode = xa.spikemode;
Expand Down
1 change: 1 addition & 0 deletions src/lib/gl_format_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var isNumeric = require('fast-isnumeric');
var rgba = require('color-normalize');

var Colorscale = require('../components/colorscale');
var Color = require('../components/color');
var colorDflt = require('../components/color/attributes').defaultLine;
var isArrayOrTypedArray = require('./array').isArrayOrTypedArray;

Expand Down
44 changes: 24 additions & 20 deletions src/traces/heatmap/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
var xb, xi, v, row, c;

function setColor(v, pixsize) {
if(v !== undefined) {
var c = sclFunc(v);
c[0] = Math.round(c[0]);
c[1] = Math.round(c[1]);
c[2] = Math.round(c[2]);

pixcount += pixsize;
rcount += c[0] * pixsize;
gcount += c[1] * pixsize;
bcount += c[2] * pixsize;
return c;
}
return [0, 0, 0, 0];
if (v === undefined || pixsize === undefined) return [0, 0, 0, 0];

var c = sclFunc(v);
c[0] = Math.round(c[0]);
c[1] = Math.round(c[1]);
c[2] = Math.round(c[2]);

pixcount += pixsize;
rcount += c[0] * pixsize;
gcount += c[1] * pixsize;
bcount += c[2] * pixsize;

return c;
}

function interpColor(r0, r1, xinterp, yinterp) {
Expand Down Expand Up @@ -340,13 +340,17 @@ module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
}
}

rcount = Math.round(rcount / pixcount);
gcount = Math.round(gcount / pixcount);
bcount = Math.round(bcount / pixcount);
const cstr = `rgb(${rcount}, ${gcount}, ${bcount})`;

gd._hmpixcount = (gd._hmpixcount||0) + pixcount;
gd._hmlumcount = (gd._hmlumcount||0) + pixcount * Color.color(cstr).luminosity();
// Guard against dividing by zero and the resulting bad color string
if (pixcount) {
rcount = Math.round(rcount / pixcount);
gcount = Math.round(gcount / pixcount);
bcount = Math.round(bcount / pixcount);

const cstr = `rgb(${rcount}, ${gcount}, ${bcount})`;

gd._hmpixcount = (gd._hmpixcount || 0) + pixcount;
gd._hmlumcount = (gd._hmlumcount || 0) + pixcount * Color.color(cstr).luminosity();
}

var image3 = plotGroup.selectAll('image')
.data(cd);
Expand Down