From: Evert Timberg Date: Sun, 8 May 2016 11:55:29 +0000 (-0400) Subject: Linear scale improvements X-Git-Tag: v2.1.4~32^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ef5d942e682d50078c31431b6888c0e998cf9ec;p=thirdparty%2FChart.js.git Linear scale improvements --- diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 90fcab9fe..15db914ba 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -228,41 +228,44 @@ module.exports = function(Chart) { return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); }, convertTicksToLabels: function() { - this.ticksAsNumbers = this.ticks.slice(); - this.zeroLineIndex = this.ticks.indexOf(0); + var _this = this; + _this.ticksAsNumbers = _this.ticks.slice(); + _this.zeroLineIndex = _this.ticks.indexOf(0); - Chart.Scale.prototype.convertTicksToLabels.call(this); + Chart.Scale.prototype.convertTicksToLabels.call(_this); }, // Utils getPixelForValue: function(value, index, datasetIndex, includeOffset) { // This must be called after fit has been run so that // this.left, this.top, this.right, and this.bottom have been defined - var rightValue = +this.getRightValue(value); + var _this = this; + var paddingLeft = _this.paddingLeft; + var paddingBottom = _this.paddingBottom; + var start = _this.start; + + var rightValue = +_this.getRightValue(value); var pixel; - var range = this.end - this.start; + var innerDimension; + var range = _this.end - start; - if (this.isHorizontal()) { - var innerWidth = this.width - (this.paddingLeft + this.paddingRight); - pixel = this.left + (innerWidth / range * (rightValue - this.start)); - return Math.round(pixel + this.paddingLeft); + if (_this.isHorizontal()) { + innerDimension = _this.width - (paddingLeft + _this.paddingRight); + pixel = _this.left + (innerDimension / range * (rightValue - start)); + return Math.round(pixel + paddingLeft); } else { - var innerHeight = this.height - (this.paddingTop + this.paddingBottom); - pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (rightValue - this.start)); + innerDimension = _this.height - (_this.paddingTop + paddingBottom); + pixel = (_this.bottom - paddingBottom) - (innerDimension / range * (rightValue - start)); return Math.round(pixel); } }, getValueForPixel: function(pixel) { - var offset; - - if (this.isHorizontal()) { - var innerWidth = this.width - (this.paddingLeft + this.paddingRight); - offset = (pixel - this.left - this.paddingLeft) / innerWidth; - } else { - var innerHeight = this.height - (this.paddingTop + this.paddingBottom); - offset = (this.bottom - this.paddingBottom - pixel) / innerHeight; - } - - return this.start + ((this.end - this.start) * offset); + var _this = this; + var isHorizontal = _this.isHorizontal(); + var paddingLeft = _this.paddingLeft; + var paddingBottom = _this.paddingBottom; + var innerDimension = isHorizontal ? _this.width - (paddingLeft + _this.paddingRight) : _this.height - (_this.paddingTop + paddingBottom); + var offset = (isHorizontal ? pixel - _this.left - paddingLeft : _this.bottom - paddingBottom - pixel) / innerDimension; + return _this.start + ((_this.end - _this.start) * offset); }, getPixelForTick: function(index, includeOffset) { return this.getPixelForValue(this.ticksAsNumbers[index], null, null, includeOffset);