From 4c2027aabb68a6c5291b2b846c00b366313e3864 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 24 Sep 2015 12:59:03 -0600 Subject: [PATCH] Horizontal Log Scale --- src/scales/scale.linear.js | 1 + src/scales/scale.logarithmic.js | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 662c69e60..27cdff3dd 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -158,6 +158,7 @@ var range = this.end - this.start; if (this.isHorizontal()) { + var innerWidth = this.width - (this.paddingLeft + this.paddingRight); pixel = this.left + (innerWidth / range * (this.getRightValue(value) - this.start)); return Math.round(pixel + this.paddingLeft); diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index dbe896d3c..3bc3d02d4 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -144,41 +144,39 @@ this.ticks.push(label); // empty string will not render so we're good }, this); - - console.log(this.tickValues, this.ticks); }, // Get the correct value. If the value type is object get the x or y based on whether we are horizontal or not getRightValue: function(rawValue) { return typeof rawValue === "object" ? (this.isHorizontal() ? rawValue.x : rawValue.y) : rawValue; }, getPixelForTick: function(index, includeOffset) { - return this.getPixelForValue(this.tickValues[index], includeOffset); + return this.getPixelForValue(this.tickValues[index], null, null, includeOffset); }, - getPixelForValue: function(value) { - // This must be called after fit has been run so that - // this.left, this.top, this.right, and this.bottom have been defined + getPixelForValue: function(value, index, datasetIndex, includeOffset) { var pixel; + + var newVal = this.getRightValue(value); var range = helpers.log10(this.end) - helpers.log10(this.start); if (this.isHorizontal()) { - if (value === 0) { + + if (newVal === 0) { pixel = this.left + this.paddingLeft; } else { var innerWidth = this.width - (this.paddingLeft + this.paddingRight); - pixel = this.left + (innerWidth / range * (helpers.log10(value) - helpers.log10(this.start))); - pixel += this.paddingLeft; + pixel = this.left + (innerWidth / range * (helpers.log10(newVal) - helpers.log10(this.start))); + return pixel + this.paddingLeft; } } else { // Bottom - top since pixels increase downard on a screen - if (value === 0) { + if (newVal === 0) { pixel = this.top + this.paddingTop; } else { var innerHeight = this.height - (this.paddingTop + this.paddingBottom); - pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (helpers.log10(value) - helpers.log10(this.start))); + return (this.bottom - this.paddingBottom) - (innerHeight / range * (helpers.log10(newVal) - helpers.log10(this.start))); } } - return pixel; }, }); -- 2.47.3