Skip to content

Conversation

@dustradio
Copy link

This should fix:

#2

If the range of heatmap data isn't sufficiently large you can get divide by zero errors. Looks like maybe should be adding one here instead of subtracting.

Not sure what version of Charts.js you were basing this off off, so I didn't rebuild the whole project, just changed the main source file.

…s. Add 1 to dataLength instead of subtracting one.
@sharozmirza
Copy link

I fixed this issue by using a conditional statement before it calculates the scaleFactor for 'gradient' colorInterpolation. Since I was not having any issue if the datalength is equal to zero, I just used the conditional statement for datalength 1 or 2. I tried to use your fix but I was not getting the exact color gradient, so here it looks like in my code:

var colorFunction, scaleFactor;
var dataLength = max-min;
var base = min;
if (dataLength === 1 || dataLength === 2){
      colorInterpolation = 'palette';
}
if (colorInterpolation === 'gradient'){
  colorFunction = getGradientColor;
  scaleFactor = (colors.length-1)/(dataLength -1);
} else {
  colorFunction = getIndexedColor;
  scaleFactor = (colors.length)/(dataLength+1);
} 

Copy link

@shoffing shoffing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same problem, this change resolves it. Please merge this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants