From 314b5095aa5704e47e63b2c6552015a7fc3fa78c Mon Sep 17 00:00:00 2001 From: sdMac <553828127@qq.com> Date: Tue, 12 Jan 2021 21:58:59 +0800 Subject: [PATCH] The value of templateAlpha will be NaN if max is equal to min. Actually NaN does not lead to a bug, cause I find something below about globalAlpha on MDN: "Values outside that range, including Infinity and NaN, will not be set, and globalAlpha will retain its previous value." And, of course. The default value is 1. However, I do not think it is a good idea to compare a number with NaN. Hope this commit will help. --- src/renderer/canvas2d.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/canvas2d.js b/src/renderer/canvas2d.js index 259c8d14..9d62e070 100644 --- a/src/renderer/canvas2d.js +++ b/src/renderer/canvas2d.js @@ -193,7 +193,7 @@ var Canvas2dRenderer = (function Canvas2dRendererClosure() { } // value from minimum / value range // => [0, 1] - var templateAlpha = (value-min)/(max-min); + var templateAlpha = max === min ? 1 : (value - min) / (max - min); // this fixes #176: small values are not visible because globalAlpha < .01 cannot be read from imageData shadowCtx.globalAlpha = templateAlpha < .01 ? .01 : templateAlpha;