Skip to content

Commit

Permalink
Consider left and top when determining value from pixel in category s…
Browse files Browse the repository at this point in the history
…cale
  • Loading branch information
etimberg committed Jun 29, 2016
1 parent 266df5e commit 3660d9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/scales/scale.category.js
Expand Up @@ -81,6 +81,8 @@ module.exports = function(Chart) {
var innerDimension = horz ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
var valueDimension = innerDimension / offsetAmt;

pixel -= horz ? me.left : me.top;

if (me.options.gridLines.offsetGridLines) {
pixel -= (valueDimension / 2);
}
Expand Down
4 changes: 2 additions & 2 deletions test/scale.category.tests.js
Expand Up @@ -154,7 +154,7 @@ describe('Category scale tests', function() {

expect(scale.getPixelForValue(0, 4, 0, false)).toBe(452);
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(505);
expect(scale.getValueForPixel(452)).toBe(4);
expect(scale.getValueForPixel(453)).toBe(4);
expect(scale.getValueForPixel(505)).toBe(4);

config.gridLines.offsetGridLines = false;
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('Category scale tests', function() {

expect(scale.getPixelForValue(0, 4, 0, false)).toBe(161);
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(180);
expect(scale.getValueForPixel(161)).toBe(4);
expect(scale.getValueForPixel(162)).toBe(4);

config.gridLines.offsetGridLines = false;

Expand Down

0 comments on commit 3660d9b

Please sign in to comment.