Merge pull request #2870 from chartjs/fix/2802

Consider left and top when determining value from pixel in category s…
This commit is contained in:
Evert Timberg 2016-07-06 17:53:50 -04:00 committed by GitHub
commit 44a9866bd8
2 changed files with 4 additions and 2 deletions

View File

@ -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);
}

View File

@ -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;
@ -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;