Skip to content

Commit

Permalink
Fix start_value going negative when series is positive
Browse files Browse the repository at this point in the history
  • Loading branch information
Menno van der Sman committed Apr 21, 2010
1 parent c00b8e0 commit 6a5b13d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions source/grafico.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Grafico.Normaliser = Class.create({
}

// Add some headroom to the bottom
if (this.min <= 0) {
if (this.min < 0) {
graphmin = graphmin - margin;
} else {
graphmin = [graphmin - margin, 0].max();
Expand Down Expand Up @@ -186,7 +186,6 @@ Grafico.Normaliser = Class.create({
offset = offset || 1;
multiplier = Math.pow(10, -offset);
rounded_value = Math.round(value * multiplier) / multiplier;

return (rounded_value > this.min) ? this.roundToOrigin(value - this.step) : rounded_value;
}
});
Expand Down
14 changes: 14 additions & 0 deletions tests/normalisation.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ <h1>Unit Test for Normalisation</h1>
assertEqual( 0.5, normaliser.step);
assertEqual( 90, normaliser.start_value);
assertEqual(10.9, normaliser.range);
}},

test_bottom_headroom_stays_positive: function() { with(this) {
var normaliser = new Grafico.Normaliser([1, 50, 100, 0, 0]);
assertEqual( 10, normaliser.step);
assertEqual( 0, normaliser.start_value);
assertEqual(105, normaliser.range);
}},

test_top_headroom_stays_negative: function() { with(this) {
var normaliser = new Grafico.Normaliser([-1, -50, -100, 0, 0]);
assertEqual( 10, normaliser.step);
assertEqual(-100, normaliser.start_value);
assertEqual( 100, normaliser.range);
}}

});
Expand Down

0 comments on commit 6a5b13d

Please sign in to comment.