Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up issues in core scale #1756

Merged
merged 1 commit into from
Dec 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
var originalLabelWidth = helpers.longestText(this.ctx, labelFont, this.ticks);
var cosRotation;
var sinRotation;
var firstRotatedWidth;

this.labelWidth = originalLabelWidth;

Expand Down Expand Up @@ -256,7 +255,6 @@

if (this.isHorizontal()) {
// A horizontal axis is more constrained by the height.
var maxLabelHeight = this.maxHeight - this.minSize.height;
var longestLabelWidth = helpers.longestText(this.ctx, labelFont, this.ticks);

// TODO - improve this calculation
Expand Down Expand Up @@ -319,7 +317,7 @@

// Shared Methods
isHorizontal: function() {
return this.options.position == "top" || this.options.position == "bottom";
return this.options.position === "top" || this.options.position === "bottom";
},

// Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
Expand Down Expand Up @@ -370,7 +368,7 @@
},

// Utility for getting the pixel location of a percentage of scale
getPixelForDecimal: function(decimal, includeOffset) {
getPixelForDecimal: function(decimal/*, includeOffset*/) {
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
var valueOffset = (innerWidth * decimal) + this.paddingLeft;
Expand Down Expand Up @@ -398,8 +396,8 @@

if (this.isHorizontal()) {
setContextLineSettings = true;
var yTickStart = this.options.position == "bottom" ? this.top : this.bottom - 10;
var yTickEnd = this.options.position == "bottom" ? this.top + 10 : this.bottom;
var yTickStart = this.options.position === "bottom" ? this.top : this.bottom - 10;
var yTickEnd = this.options.position === "bottom" ? this.top + 10 : this.bottom;
skipRatio = false;

if ((this.options.ticks.fontSize + 4) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
Expand Down Expand Up @@ -466,15 +464,15 @@
this.ctx.font = helpers.fontString(this.options.scaleLabel.fontSize, this.options.scaleLabel.fontStyle, this.options.scaleLabel.fontFamily);

scaleLabelX = this.left + ((this.right - this.left) / 2); // midpoint of the width
scaleLabelY = this.options.position == 'bottom' ? this.bottom - (this.options.scaleLabel.fontSize / 2) : this.top + (this.options.scaleLabel.fontSize / 2);
scaleLabelY = this.options.position === 'bottom' ? this.bottom - (this.options.scaleLabel.fontSize / 2) : this.top + (this.options.scaleLabel.fontSize / 2);

this.ctx.fillText(this.options.scaleLabel.labelString, scaleLabelX, scaleLabelY);
}

} else {
setContextLineSettings = true;
var xTickStart = this.options.position == "right" ? this.left : this.right - 5;
var xTickEnd = this.options.position == "right" ? this.left + 5 : this.right;
var xTickStart = this.options.position === "right" ? this.left : this.right - 5;
var xTickEnd = this.options.position === "right" ? this.left + 5 : this.right;

helpers.each(this.ticks, function(label, index) {
// If the callback returned a null or undefined value, do not draw this line
Expand Down Expand Up @@ -522,7 +520,7 @@

this.ctx.save();

if (this.options.position == "left") {
if (this.options.position === "left") {
if (this.options.ticks.mirror) {
xLabelValue = this.right + this.options.ticks.padding;
this.ctx.textAlign = "left";
Expand Down Expand Up @@ -553,9 +551,9 @@

if (this.options.scaleLabel.display) {
// Draw the scale label
scaleLabelX = this.options.position == 'left' ? this.left + (this.options.scaleLabel.fontSize / 2) : this.right - (this.options.scaleLabel.fontSize / 2);
scaleLabelX = this.options.position === 'left' ? this.left + (this.options.scaleLabel.fontSize / 2) : this.right - (this.options.scaleLabel.fontSize / 2);
scaleLabelY = this.top + ((this.bottom - this.top) / 2);
var rotation = this.options.position == 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
var rotation = this.options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;

this.ctx.save();
this.ctx.translate(scaleLabelX, scaleLabelY);
Expand Down