Permalink
Browse files

fix issue with max 0. Closes #2

  • Loading branch information...
1 parent 7a4d1cb commit 97142d563b137179e8a9b2e910bccaaaa676c34f @tj tj committed Feb 28, 2014
Showing with 1 addition and 1 deletion.
  1. +1 −1 index.js
View
@@ -42,7 +42,7 @@ function histogram(data, opts) {
for (var i = 0; i < data.length; i++) {
var d = data[i];
- var p = d.val / maxVal;
+ var p = (d.val / maxVal) || 1;
var shown = Math.round(width * p);
var blank = width - shown
var bar = Array(shown + 1).join(barc);

1 comment on commit 97142d5

This change breaks some of your examples. When d.val is 0 (and maxVal is nonzero), then its bar is completely filled, since p gets assigned 1 instead of 0.

Perhaps just using a special case for (maxVal === 0 && d.val === 0) would be better.

https://github.com/steel/bars made a patch for it about a month ago.

Please sign in to comment.