2016-02-12 04:30:53 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
module.exports = function(Chart) {
|
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
var helpers = Chart.helpers;
|
|
|
|
|
|
|
|
Chart.defaults.scale = {
|
|
|
|
display: true,
|
2016-04-26 03:09:35 +02:00
|
|
|
position: "left",
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// grid line settings
|
|
|
|
gridLines: {
|
|
|
|
display: true,
|
|
|
|
color: "rgba(0, 0, 0, 0.1)",
|
|
|
|
lineWidth: 1,
|
2016-05-17 21:11:29 +02:00
|
|
|
drawBorder: true,
|
2016-02-14 23:06:00 +01:00
|
|
|
drawOnChartArea: true,
|
|
|
|
drawTicks: true,
|
2016-04-17 03:46:29 +02:00
|
|
|
tickMarkLength: 10,
|
2016-02-14 23:06:00 +01:00
|
|
|
zeroLineWidth: 1,
|
|
|
|
zeroLineColor: "rgba(0,0,0,0.25)",
|
|
|
|
offsetGridLines: false
|
|
|
|
},
|
|
|
|
|
|
|
|
// scale label
|
|
|
|
scaleLabel: {
|
|
|
|
// actual label
|
|
|
|
labelString: '',
|
|
|
|
|
|
|
|
// display property
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
|
|
|
|
// label settings
|
|
|
|
ticks: {
|
|
|
|
beginAtZero: false,
|
2016-05-10 13:10:01 +02:00
|
|
|
minRotation: 0,
|
2016-04-17 00:38:03 +02:00
|
|
|
maxRotation: 50,
|
2016-02-14 23:06:00 +01:00
|
|
|
mirror: false,
|
|
|
|
padding: 10,
|
|
|
|
reverse: false,
|
|
|
|
display: true,
|
|
|
|
autoSkip: true,
|
2016-04-17 00:38:03 +02:00
|
|
|
autoSkipPadding: 0,
|
2016-05-11 11:43:22 +02:00
|
|
|
labelOffset: 0,
|
2016-02-14 23:06:00 +01:00
|
|
|
callback: function(value) {
|
|
|
|
return '' + value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Chart.Scale = Chart.Element.extend({
|
|
|
|
|
|
|
|
// These methods are ordered by lifecyle. Utilities then follow.
|
|
|
|
// Any function defined here is inherited by all scale types.
|
|
|
|
// Any function can be extended by the scale type
|
|
|
|
|
|
|
|
beforeUpdate: function() {
|
|
|
|
helpers.callCallback(this.options.beforeUpdate, [this]);
|
|
|
|
},
|
|
|
|
update: function(maxWidth, maxHeight, margins) {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
|
2016-06-04 20:14:16 +02:00
|
|
|
me.beforeUpdate();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Absorb the master measurements
|
2016-06-04 20:14:16 +02:00
|
|
|
me.maxWidth = maxWidth;
|
|
|
|
me.maxHeight = maxHeight;
|
|
|
|
me.margins = helpers.extend({
|
2016-02-14 23:06:00 +01:00
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
bottom: 0
|
|
|
|
}, margins);
|
|
|
|
|
|
|
|
// Dimensions
|
2016-06-04 20:14:16 +02:00
|
|
|
me.beforeSetDimensions();
|
|
|
|
me.setDimensions();
|
|
|
|
me.afterSetDimensions();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Data min/max
|
2016-06-04 20:14:16 +02:00
|
|
|
me.beforeDataLimits();
|
|
|
|
me.determineDataLimits();
|
|
|
|
me.afterDataLimits();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Ticks
|
2016-06-04 20:14:16 +02:00
|
|
|
me.beforeBuildTicks();
|
|
|
|
me.buildTicks();
|
|
|
|
me.afterBuildTicks();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
me.beforeTickToLabelConversion();
|
|
|
|
me.convertTicksToLabels();
|
|
|
|
me.afterTickToLabelConversion();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Tick Rotation
|
2016-06-04 20:14:16 +02:00
|
|
|
me.beforeCalculateTickRotation();
|
|
|
|
me.calculateTickRotation();
|
|
|
|
me.afterCalculateTickRotation();
|
2016-02-14 23:06:00 +01:00
|
|
|
// Fit
|
2016-06-04 20:14:16 +02:00
|
|
|
me.beforeFit();
|
|
|
|
me.fit();
|
|
|
|
me.afterFit();
|
2016-02-14 23:06:00 +01:00
|
|
|
//
|
2016-06-04 20:14:16 +02:00
|
|
|
me.afterUpdate();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
return me.minSize;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
},
|
|
|
|
afterUpdate: function() {
|
|
|
|
helpers.callCallback(this.options.afterUpdate, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
beforeSetDimensions: function() {
|
|
|
|
helpers.callCallback(this.options.beforeSetDimensions, [this]);
|
|
|
|
},
|
|
|
|
setDimensions: function() {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
2016-02-14 23:06:00 +01:00
|
|
|
// Set the unconstrained dimension before label rotation
|
2016-06-04 20:14:16 +02:00
|
|
|
if (me.isHorizontal()) {
|
2016-02-14 23:06:00 +01:00
|
|
|
// Reset position before calculating rotation
|
2016-06-04 20:14:16 +02:00
|
|
|
me.width = me.maxWidth;
|
|
|
|
me.left = 0;
|
|
|
|
me.right = me.width;
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
2016-06-04 20:14:16 +02:00
|
|
|
me.height = me.maxHeight;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Reset position before calculating rotation
|
2016-06-04 20:14:16 +02:00
|
|
|
me.top = 0;
|
|
|
|
me.bottom = me.height;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset padding
|
2016-06-04 20:14:16 +02:00
|
|
|
me.paddingLeft = 0;
|
|
|
|
me.paddingTop = 0;
|
|
|
|
me.paddingRight = 0;
|
|
|
|
me.paddingBottom = 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
},
|
|
|
|
afterSetDimensions: function() {
|
|
|
|
helpers.callCallback(this.options.afterSetDimensions, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Data limits
|
|
|
|
beforeDataLimits: function() {
|
|
|
|
helpers.callCallback(this.options.beforeDataLimits, [this]);
|
|
|
|
},
|
|
|
|
determineDataLimits: helpers.noop,
|
|
|
|
afterDataLimits: function() {
|
|
|
|
helpers.callCallback(this.options.afterDataLimits, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
beforeBuildTicks: function() {
|
|
|
|
helpers.callCallback(this.options.beforeBuildTicks, [this]);
|
|
|
|
},
|
|
|
|
buildTicks: helpers.noop,
|
|
|
|
afterBuildTicks: function() {
|
|
|
|
helpers.callCallback(this.options.afterBuildTicks, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeTickToLabelConversion: function() {
|
|
|
|
helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
|
|
|
|
},
|
|
|
|
convertTicksToLabels: function() {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
2016-02-14 23:06:00 +01:00
|
|
|
// Convert ticks to strings
|
2016-06-04 20:14:16 +02:00
|
|
|
me.ticks = me.ticks.map(function(numericalTick, index, ticks) {
|
|
|
|
if (me.options.ticks.userCallback) {
|
|
|
|
return me.options.ticks.userCallback(numericalTick, index, ticks);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-06-04 20:14:16 +02:00
|
|
|
return me.options.ticks.callback(numericalTick, index, ticks);
|
2016-02-14 23:06:00 +01:00
|
|
|
},
|
2016-06-04 20:14:16 +02:00
|
|
|
me);
|
2016-02-14 23:06:00 +01:00
|
|
|
},
|
|
|
|
afterTickToLabelConversion: function() {
|
|
|
|
helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
beforeCalculateTickRotation: function() {
|
|
|
|
helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
|
|
|
|
},
|
|
|
|
calculateTickRotation: function() {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
|
|
|
var context = me.ctx;
|
2016-05-14 15:58:42 +02:00
|
|
|
var globalDefaults = Chart.defaults.global;
|
2016-06-04 20:14:16 +02:00
|
|
|
var optionTicks = me.options.ticks;
|
2016-05-14 05:07:39 +02:00
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
//Get the width of each grid by calculating the difference
|
|
|
|
//between x offsets between 0 and 1.
|
2016-05-14 05:07:39 +02:00
|
|
|
var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
|
|
|
|
var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
|
|
|
|
var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
|
2016-02-28 19:41:17 +01:00
|
|
|
var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
|
2016-05-14 05:07:39 +02:00
|
|
|
context.font = tickLabelFont;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var firstWidth = context.measureText(me.ticks[0]).width;
|
|
|
|
var lastWidth = context.measureText(me.ticks[me.ticks.length - 1]).width;
|
2016-02-14 23:06:00 +01:00
|
|
|
var firstRotated;
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
me.labelRotation = optionTicks.minRotation || 0;
|
|
|
|
me.paddingRight = 0;
|
|
|
|
me.paddingLeft = 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
if (me.options.display) {
|
|
|
|
if (me.isHorizontal()) {
|
|
|
|
me.paddingRight = lastWidth / 2 + 3;
|
|
|
|
me.paddingLeft = firstWidth / 2 + 3;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
if (!me.longestTextCache) {
|
|
|
|
me.longestTextCache = {};
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-06-04 20:14:16 +02:00
|
|
|
var originalLabelWidth = helpers.longestText(context, tickLabelFont, me.ticks, me.longestTextCache);
|
2016-02-14 23:06:00 +01:00
|
|
|
var labelWidth = originalLabelWidth;
|
|
|
|
var cosRotation;
|
|
|
|
var sinRotation;
|
|
|
|
|
|
|
|
// Allow 3 pixels x2 padding either side for label readability
|
|
|
|
// only the index matters for a dataset scale, but we want a consistent interface between scales
|
2016-06-04 20:14:16 +02:00
|
|
|
var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
//Max label rotation can be set or default to 90 - also act as a loop counter
|
2016-06-04 20:14:16 +02:00
|
|
|
while (labelWidth > tickWidth && me.labelRotation < optionTicks.maxRotation) {
|
|
|
|
cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
|
|
|
|
sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
firstRotated = cosRotation * firstWidth;
|
|
|
|
|
|
|
|
// We're right aligning the text now.
|
2016-06-04 20:14:16 +02:00
|
|
|
if (firstRotated + tickFontSize / 2 > me.yLabelWidth) {
|
|
|
|
me.paddingLeft = firstRotated + tickFontSize / 2;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
me.paddingRight = tickFontSize / 2;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
if (sinRotation * originalLabelWidth > me.maxHeight) {
|
2016-02-14 23:06:00 +01:00
|
|
|
// go back one step
|
2016-06-04 20:14:16 +02:00
|
|
|
me.labelRotation--;
|
2016-02-14 23:06:00 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
me.labelRotation++;
|
2016-02-14 23:06:00 +01:00
|
|
|
labelWidth = cosRotation * originalLabelWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
if (me.margins) {
|
|
|
|
me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
|
|
|
|
me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
afterCalculateTickRotation: function() {
|
|
|
|
helpers.callCallback(this.options.afterCalculateTickRotation, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
beforeFit: function() {
|
|
|
|
helpers.callCallback(this.options.beforeFit, [this]);
|
|
|
|
},
|
|
|
|
fit: function() {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
2016-05-07 22:26:44 +02:00
|
|
|
// Reset
|
2016-06-04 20:14:16 +02:00
|
|
|
var minSize = me.minSize = {
|
2016-02-14 23:06:00 +01:00
|
|
|
width: 0,
|
|
|
|
height: 0
|
|
|
|
};
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var opts = me.options;
|
2016-05-14 05:39:11 +02:00
|
|
|
var globalDefaults = Chart.defaults.global;
|
2016-05-07 22:26:44 +02:00
|
|
|
var tickOpts = opts.ticks;
|
|
|
|
var scaleLabelOpts = opts.scaleLabel;
|
|
|
|
var display = opts.display;
|
2016-06-04 20:14:16 +02:00
|
|
|
var isHorizontal = me.isHorizontal();
|
2016-05-07 22:26:44 +02:00
|
|
|
|
2016-05-14 05:07:39 +02:00
|
|
|
var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
|
|
|
|
var tickFontStyle = helpers.getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
|
|
|
|
var tickFontFamily = helpers.getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
|
2016-02-28 19:41:17 +01:00
|
|
|
var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
|
|
|
|
|
2016-05-14 05:07:39 +02:00
|
|
|
var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabelOpts.fontSize, globalDefaults.defaultFontSize);
|
|
|
|
var scaleLabelFontStyle = helpers.getValueOrDefault(scaleLabelOpts.fontStyle, globalDefaults.defaultFontStyle);
|
|
|
|
var scaleLabelFontFamily = helpers.getValueOrDefault(scaleLabelOpts.fontFamily, globalDefaults.defaultFontFamily);
|
2016-02-28 19:41:17 +01:00
|
|
|
var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
|
|
|
|
|
2016-05-07 22:26:44 +02:00
|
|
|
var tickMarkLength = opts.gridLines.tickMarkLength;
|
2016-05-07 20:18:36 +02:00
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
// Width
|
2016-05-07 22:26:44 +02:00
|
|
|
if (isHorizontal) {
|
2016-02-14 23:06:00 +01:00
|
|
|
// subtract the margins to line up with the chartArea if we are a full width scale
|
2016-06-04 20:14:16 +02:00
|
|
|
minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
2016-05-07 22:26:44 +02:00
|
|
|
minSize.width = display ? tickMarkLength : 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// height
|
2016-05-07 22:26:44 +02:00
|
|
|
if (isHorizontal) {
|
|
|
|
minSize.height = display ? tickMarkLength : 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
2016-06-04 20:14:16 +02:00
|
|
|
minSize.height = me.maxHeight; // fill all the height
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Are we showing a title for the scale?
|
2016-05-07 22:26:44 +02:00
|
|
|
if (scaleLabelOpts.display && display) {
|
|
|
|
if (isHorizontal) {
|
|
|
|
minSize.height += (scaleLabelFontSize * 1.5);
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
2016-05-07 22:26:44 +02:00
|
|
|
minSize.width += (scaleLabelFontSize * 1.5);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 22:26:44 +02:00
|
|
|
if (tickOpts.display && display) {
|
2016-02-14 23:06:00 +01:00
|
|
|
// Don't bother fitting the ticks if we are not showing them
|
2016-06-04 20:14:16 +02:00
|
|
|
if (!me.longestTextCache) {
|
|
|
|
me.longestTextCache = {};
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var largestTextWidth = helpers.longestText(me.ctx, tickLabelFont, me.ticks, me.longestTextCache);
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-07 22:26:44 +02:00
|
|
|
if (isHorizontal) {
|
2016-02-14 23:06:00 +01:00
|
|
|
// A horizontal axis is more constrained by the height.
|
2016-06-04 20:14:16 +02:00
|
|
|
me.longestLabelWidth = largestTextWidth;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// TODO - improve this calculation
|
2016-06-04 20:14:16 +02:00
|
|
|
var labelHeight = (Math.sin(helpers.toRadians(me.labelRotation)) * me.longestLabelWidth) + 1.5 * tickFontSize;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight);
|
|
|
|
me.ctx.font = tickLabelFont;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var firstLabelWidth = me.ctx.measureText(me.ticks[0]).width;
|
|
|
|
var lastLabelWidth = me.ctx.measureText(me.ticks[me.ticks.length - 1]).width;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
|
|
|
|
// by the font height
|
2016-06-04 20:14:16 +02:00
|
|
|
var cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
|
|
|
|
var sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
|
|
|
|
me.paddingLeft = me.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
|
|
|
|
me.paddingRight = me.labelRotation !== 0 ? (sinRotation * (tickFontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
|
|
|
// A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
|
2016-06-04 20:14:16 +02:00
|
|
|
var maxLabelWidth = me.maxWidth - minSize.width;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// Account for padding
|
2016-05-07 22:26:44 +02:00
|
|
|
var mirror = tickOpts.mirror;
|
|
|
|
if (!mirror) {
|
2016-06-04 20:14:16 +02:00
|
|
|
largestTextWidth += me.options.ticks.padding;
|
2016-05-07 22:26:44 +02:00
|
|
|
} else {
|
|
|
|
// If mirrored text is on the inside so don't expand
|
|
|
|
largestTextWidth = 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (largestTextWidth < maxLabelWidth) {
|
|
|
|
// We don't need all the room
|
2016-05-07 22:26:44 +02:00
|
|
|
minSize.width += largestTextWidth;
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
|
|
|
// Expand to max size
|
2016-06-04 20:14:16 +02:00
|
|
|
minSize.width = me.maxWidth;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
me.paddingTop = tickFontSize / 2;
|
|
|
|
me.paddingBottom = tickFontSize / 2;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
if (me.margins) {
|
|
|
|
me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
|
|
|
|
me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
|
|
|
|
me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
|
|
|
|
me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
me.width = minSize.width;
|
|
|
|
me.height = minSize.height;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
},
|
|
|
|
afterFit: function() {
|
|
|
|
helpers.callCallback(this.options.afterFit, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Shared Methods
|
|
|
|
isHorizontal: function() {
|
|
|
|
return this.options.position === "top" || this.options.position === "bottom";
|
|
|
|
},
|
|
|
|
isFullWidth: function() {
|
|
|
|
return (this.options.fullWidth);
|
|
|
|
},
|
|
|
|
|
|
|
|
// 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
|
|
|
|
getRightValue: function getRightValue(rawValue) {
|
|
|
|
// Null and undefined values first
|
|
|
|
if (rawValue === null || typeof(rawValue) === 'undefined') {
|
|
|
|
return NaN;
|
|
|
|
}
|
|
|
|
// isNaN(object) returns true, so make sure NaN is checking for a number
|
|
|
|
if (typeof(rawValue) === 'number' && isNaN(rawValue)) {
|
|
|
|
return NaN;
|
|
|
|
}
|
|
|
|
// If it is in fact an object, dive in one more level
|
|
|
|
if (typeof(rawValue) === "object") {
|
2016-05-18 18:38:20 +02:00
|
|
|
if ((rawValue instanceof Date) || (rawValue.isValid)) {
|
2016-02-14 23:06:00 +01:00
|
|
|
return rawValue;
|
|
|
|
} else {
|
|
|
|
return getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value is good, return it
|
|
|
|
return rawValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Used to get the value to display in the tooltip for the data at the given index
|
|
|
|
// function getLabelForIndex(index, datasetIndex)
|
|
|
|
getLabelForIndex: helpers.noop,
|
|
|
|
|
|
|
|
// Used to get data value locations. Value can either be an index or a numerical value
|
|
|
|
getPixelForValue: helpers.noop,
|
|
|
|
|
2016-04-21 13:48:47 +02:00
|
|
|
// Used to get the data value from a given pixel. This is the inverse of getPixelForValue
|
|
|
|
getValueForPixel: helpers.noop,
|
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
// Used for tick location, should
|
|
|
|
getPixelForTick: function(index, includeOffset) {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
|
|
|
if (me.isHorizontal()) {
|
|
|
|
var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
|
|
|
|
var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
|
|
|
|
var pixel = (tickWidth * index) + me.paddingLeft;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
if (includeOffset) {
|
|
|
|
pixel += tickWidth / 2;
|
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var finalVal = me.left + Math.round(pixel);
|
|
|
|
finalVal += me.isFullWidth() ? me.margins.left : 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
return finalVal;
|
|
|
|
} else {
|
2016-06-04 20:14:16 +02:00
|
|
|
var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
|
|
|
|
return me.top + (index * (innerHeight / (me.ticks.length - 1)));
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Utility for getting the pixel location of a percentage of scale
|
|
|
|
getPixelForDecimal: function(decimal /*, includeOffset*/ ) {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
|
|
|
if (me.isHorizontal()) {
|
|
|
|
var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
|
|
|
|
var valueOffset = (innerWidth * decimal) + me.paddingLeft;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var finalVal = me.left + Math.round(valueOffset);
|
|
|
|
finalVal += me.isFullWidth() ? me.margins.left : 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
return finalVal;
|
|
|
|
} else {
|
2016-06-04 20:14:16 +02:00
|
|
|
return me.top + (decimal * me.height);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-20 20:17:28 +02:00
|
|
|
getBasePixel: function() {
|
|
|
|
var me = this;
|
|
|
|
var min = me.min;
|
|
|
|
var max = me.max;
|
|
|
|
|
|
|
|
return me.getPixelForValue(
|
|
|
|
me.beginAtZero? 0:
|
|
|
|
min < 0 && max < 0? max :
|
|
|
|
min > 0 && max > 0? min :
|
|
|
|
0);
|
|
|
|
},
|
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
// Actualy draw the scale on the canvas
|
|
|
|
// @param {rectangle} chartArea : the area of the chart to draw full grid lines on
|
|
|
|
draw: function(chartArea) {
|
2016-06-04 20:14:16 +02:00
|
|
|
var me = this;
|
|
|
|
var options = me.options;
|
2016-05-14 15:58:42 +02:00
|
|
|
if (!options.display) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var context = me.ctx;
|
2016-05-14 15:58:42 +02:00
|
|
|
var globalDefaults = Chart.defaults.global;
|
|
|
|
var optionTicks = options.ticks;
|
|
|
|
var gridLines = options.gridLines;
|
|
|
|
var scaleLabel = options.scaleLabel;
|
|
|
|
|
|
|
|
var setContextLineSettings;
|
2016-06-04 20:14:16 +02:00
|
|
|
var isRotated = me.labelRotation !== 0;
|
2016-05-14 15:58:42 +02:00
|
|
|
var skipRatio;
|
|
|
|
var scaleLabelX;
|
|
|
|
var scaleLabelY;
|
|
|
|
var useAutoskipper = optionTicks.autoSkip;
|
|
|
|
|
|
|
|
// figure out the maximum number of gridlines to show
|
|
|
|
var maxTicks;
|
|
|
|
if (optionTicks.maxTicksLimit) {
|
|
|
|
maxTicks = optionTicks.maxTicksLimit;
|
|
|
|
}
|
2016-02-28 19:41:17 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
var tickFontColor = helpers.getValueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
|
|
|
|
var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
|
|
|
|
var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
|
|
|
|
var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
|
|
|
|
var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
|
|
|
|
var tl = gridLines.tickMarkLength;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
var scaleLabelFontColor = helpers.getValueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
|
|
|
|
var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabel.fontSize, globalDefaults.defaultFontSize);
|
|
|
|
var scaleLabelFontStyle = helpers.getValueOrDefault(scaleLabel.fontStyle, globalDefaults.defaultFontStyle);
|
|
|
|
var scaleLabelFontFamily = helpers.getValueOrDefault(scaleLabel.fontFamily, globalDefaults.defaultFontFamily);
|
|
|
|
var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
|
2016-02-28 19:41:17 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var labelRotationRadians = helpers.toRadians(me.labelRotation);
|
2016-05-14 15:58:42 +02:00
|
|
|
var cosRotation = Math.cos(labelRotationRadians);
|
|
|
|
var sinRotation = Math.sin(labelRotationRadians);
|
2016-06-04 20:14:16 +02:00
|
|
|
var longestRotatedLabel = me.longestLabelWidth * cosRotation;
|
2016-05-14 15:58:42 +02:00
|
|
|
var rotatedLabelHeight = tickFontSize * sinRotation;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
// Make sure we draw text in the correct color and font
|
|
|
|
context.fillStyle = tickFontColor;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
if (me.isHorizontal()) {
|
2016-05-14 15:58:42 +02:00
|
|
|
setContextLineSettings = true;
|
2016-06-04 20:14:16 +02:00
|
|
|
var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl;
|
|
|
|
var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom;
|
2016-05-14 15:58:42 +02:00
|
|
|
skipRatio = false;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-19 00:20:06 +02:00
|
|
|
// Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
|
|
|
|
// See #2584
|
|
|
|
if (isRotated) {
|
|
|
|
longestRotatedLabel /= 2;
|
|
|
|
}
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
if ((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length > (me.width - (me.paddingLeft + me.paddingRight))) {
|
|
|
|
skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length) / (me.width - (me.paddingLeft + me.paddingRight)));
|
2016-05-14 15:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if they defined a max number of optionTicks,
|
|
|
|
// increase skipRatio until that number is met
|
2016-06-04 20:14:16 +02:00
|
|
|
if (maxTicks && me.ticks.length > maxTicks) {
|
|
|
|
while (!skipRatio || me.ticks.length / (skipRatio || 1) > maxTicks) {
|
2016-05-14 15:58:42 +02:00
|
|
|
if (!skipRatio) {
|
|
|
|
skipRatio = 1;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-05-14 15:58:42 +02:00
|
|
|
skipRatio += 1;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-05-14 15:58:42 +02:00
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
if (!useAutoskipper) {
|
|
|
|
skipRatio = false;
|
|
|
|
}
|
2016-03-06 04:58:34 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
helpers.each(me.ticks, function (label, index) {
|
2016-05-14 15:58:42 +02:00
|
|
|
// Blank optionTicks
|
2016-06-04 20:14:16 +02:00
|
|
|
var isLastTick = me.ticks.length === index + 1;
|
2016-02-15 16:43:19 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
// Since we always show the last tick,we need may need to hide the last shown one before
|
2016-06-04 20:14:16 +02:00
|
|
|
var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
|
2016-05-14 15:58:42 +02:00
|
|
|
if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-04 20:14:16 +02:00
|
|
|
var xLineValue = me.getPixelForTick(index); // xvalues for grid lines
|
|
|
|
var xLabelValue = me.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
|
2016-05-14 15:58:42 +02:00
|
|
|
|
|
|
|
if (gridLines.display) {
|
2016-06-04 20:14:16 +02:00
|
|
|
if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
|
2016-05-14 15:58:42 +02:00
|
|
|
// Draw the first index specially
|
|
|
|
context.lineWidth = gridLines.zeroLineWidth;
|
|
|
|
context.strokeStyle = gridLines.zeroLineColor;
|
|
|
|
setContextLineSettings = true; // reset next time
|
|
|
|
} else if (setContextLineSettings) {
|
|
|
|
context.lineWidth = gridLines.lineWidth;
|
|
|
|
context.strokeStyle = gridLines.color;
|
|
|
|
setContextLineSettings = false;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
xLineValue += helpers.aliasPixel(context.lineWidth);
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
// Draw the label area
|
|
|
|
context.beginPath();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
if (gridLines.drawTicks) {
|
|
|
|
context.moveTo(xLineValue, yTickStart);
|
|
|
|
context.lineTo(xLineValue, yTickEnd);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
// Draw the chart area
|
|
|
|
if (gridLines.drawOnChartArea) {
|
|
|
|
context.moveTo(xLineValue, chartArea.top);
|
|
|
|
context.lineTo(xLineValue, chartArea.bottom);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
// Need to stroke in the loop because we are potentially changing line widths & colours
|
|
|
|
context.stroke();
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
if (optionTicks.display) {
|
|
|
|
context.save();
|
2016-06-04 20:14:16 +02:00
|
|
|
context.translate(xLabelValue + optionTicks.labelOffset, (isRotated) ? me.top + 12 : options.position === "top" ? me.bottom - tl : me.top + tl);
|
2016-05-14 15:58:42 +02:00
|
|
|
context.rotate(labelRotationRadians * -1);
|
|
|
|
context.font = tickLabelFont;
|
|
|
|
context.textAlign = (isRotated) ? "right" : "center";
|
|
|
|
context.textBaseline = (isRotated) ? "middle" : options.position === "top" ? "bottom" : "top";
|
|
|
|
context.fillText(label, 0, 0);
|
|
|
|
context.restore();
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-06-04 20:14:16 +02:00
|
|
|
}, me);
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
if (scaleLabel.display) {
|
|
|
|
// Draw the scale label
|
|
|
|
context.textAlign = "center";
|
|
|
|
context.textBaseline = 'middle';
|
|
|
|
context.fillStyle = scaleLabelFontColor; // render in correct colour
|
|
|
|
context.font = scaleLabelFont;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
|
|
|
|
scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFontSize / 2) : me.top + (scaleLabelFontSize / 2);
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
context.fillText(scaleLabel.labelString, scaleLabelX, scaleLabelY);
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
} else {
|
|
|
|
setContextLineSettings = true;
|
2016-06-04 20:14:16 +02:00
|
|
|
var xTickStart = options.position === "right" ? me.left : me.right - 5;
|
|
|
|
var xTickEnd = options.position === "right" ? me.left + 5 : me.right;
|
2016-05-14 15:58:42 +02:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
helpers.each(me.ticks, function (label, index) {
|
2016-05-14 15:58:42 +02:00
|
|
|
// If the callback returned a null or undefined value, do not draw this line
|
|
|
|
if (label === undefined || label === null) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
|
2016-05-14 15:58:42 +02:00
|
|
|
|
|
|
|
if (gridLines.display) {
|
2016-06-04 20:14:16 +02:00
|
|
|
if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
|
2016-05-14 15:58:42 +02:00
|
|
|
// Draw the first index specially
|
|
|
|
context.lineWidth = gridLines.zeroLineWidth;
|
|
|
|
context.strokeStyle = gridLines.zeroLineColor;
|
|
|
|
setContextLineSettings = true; // reset next time
|
|
|
|
} else if (setContextLineSettings) {
|
|
|
|
context.lineWidth = gridLines.lineWidth;
|
|
|
|
context.strokeStyle = gridLines.color;
|
|
|
|
setContextLineSettings = false;
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
yLineValue += helpers.aliasPixel(context.lineWidth);
|
|
|
|
|
|
|
|
// Draw the label area
|
|
|
|
context.beginPath();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
if (gridLines.drawTicks) {
|
|
|
|
context.moveTo(xTickStart, yLineValue);
|
|
|
|
context.lineTo(xTickEnd, yLineValue);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
// Draw the chart area
|
|
|
|
if (gridLines.drawOnChartArea) {
|
|
|
|
context.moveTo(chartArea.left, yLineValue);
|
|
|
|
context.lineTo(chartArea.right, yLineValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to stroke in the loop because we are potentially changing line widths & colours
|
|
|
|
context.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optionTicks.display) {
|
|
|
|
var xLabelValue;
|
2016-06-04 20:14:16 +02:00
|
|
|
var yLabelValue = me.getPixelForTick(index, gridLines.offsetGridLines); // x values for optionTicks (need to consider offsetLabel option)
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
context.save();
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
if (options.position === "left") {
|
|
|
|
if (optionTicks.mirror) {
|
2016-06-04 20:14:16 +02:00
|
|
|
xLabelValue = me.right + optionTicks.padding;
|
2016-05-14 15:58:42 +02:00
|
|
|
context.textAlign = "left";
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
2016-06-04 20:14:16 +02:00
|
|
|
xLabelValue = me.right - optionTicks.padding;
|
2016-05-14 15:58:42 +02:00
|
|
|
context.textAlign = "right";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// right side
|
|
|
|
if (optionTicks.mirror) {
|
2016-06-04 20:14:16 +02:00
|
|
|
xLabelValue = me.left - optionTicks.padding;
|
2016-05-14 15:58:42 +02:00
|
|
|
context.textAlign = "right";
|
|
|
|
} else {
|
2016-06-04 20:14:16 +02:00
|
|
|
xLabelValue = me.left + optionTicks.padding;
|
2016-05-14 15:58:42 +02:00
|
|
|
context.textAlign = "left";
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
context.translate(xLabelValue, yLabelValue + optionTicks.labelOffset);
|
|
|
|
context.rotate(labelRotationRadians * -1);
|
|
|
|
context.font = tickLabelFont;
|
|
|
|
context.textBaseline = "middle";
|
|
|
|
context.fillText(label, 0, 0);
|
2016-05-14 05:07:39 +02:00
|
|
|
context.restore();
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-06-04 20:14:16 +02:00
|
|
|
}, me);
|
2016-05-14 15:58:42 +02:00
|
|
|
|
|
|
|
if (scaleLabel.display) {
|
|
|
|
// Draw the scale label
|
2016-06-04 20:14:16 +02:00
|
|
|
scaleLabelX = options.position === 'left' ? me.left + (scaleLabelFontSize / 2) : me.right - (scaleLabelFontSize / 2);
|
|
|
|
scaleLabelY = me.top + ((me.bottom - me.top) / 2);
|
2016-05-14 15:58:42 +02:00
|
|
|
var rotation = options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
|
|
|
|
|
|
|
|
context.save();
|
|
|
|
context.translate(scaleLabelX, scaleLabelY);
|
|
|
|
context.rotate(rotation);
|
|
|
|
context.textAlign = "center";
|
|
|
|
context.fillStyle = scaleLabelFontColor; // render in correct colour
|
|
|
|
context.font = scaleLabelFont;
|
|
|
|
context.textBaseline = 'middle';
|
|
|
|
context.fillText(scaleLabel.labelString, 0, 0);
|
|
|
|
context.restore();
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-05-14 15:58:42 +02:00
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-17 21:11:29 +02:00
|
|
|
if (gridLines.drawBorder) {
|
|
|
|
// Draw the line at the edge of the axis
|
|
|
|
context.lineWidth = gridLines.lineWidth;
|
|
|
|
context.strokeStyle = gridLines.color;
|
2016-06-04 20:14:16 +02:00
|
|
|
var x1 = me.left,
|
|
|
|
x2 = me.right,
|
|
|
|
y1 = me.top,
|
|
|
|
y2 = me.bottom;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-17 21:11:29 +02:00
|
|
|
var aliasPixel = helpers.aliasPixel(context.lineWidth);
|
2016-06-04 20:14:16 +02:00
|
|
|
if (me.isHorizontal()) {
|
|
|
|
y1 = y2 = options.position === 'top' ? me.bottom : me.top;
|
2016-05-17 21:11:29 +02:00
|
|
|
y1 += aliasPixel;
|
|
|
|
y2 += aliasPixel;
|
|
|
|
} else {
|
2016-06-04 20:14:16 +02:00
|
|
|
x1 = x2 = options.position === 'left' ? me.right : me.left;
|
2016-05-17 21:11:29 +02:00
|
|
|
x1 += aliasPixel;
|
|
|
|
x2 += aliasPixel;
|
|
|
|
}
|
2016-05-14 15:58:42 +02:00
|
|
|
|
2016-05-17 21:11:29 +02:00
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(x1, y1);
|
|
|
|
context.lineTo(x2, y2);
|
|
|
|
context.stroke();
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
});
|
2016-04-17 00:38:03 +02:00
|
|
|
};
|