2016-09-14 20:05:19 +02:00
|
|
|
'use strict';
|
2016-02-12 04:30:53 +01:00
|
|
|
|
|
|
|
module.exports = function(Chart) {
|
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
var helpers = Chart.helpers;
|
|
|
|
|
|
|
|
Chart.defaults.scale = {
|
|
|
|
display: true,
|
2016-09-14 20:05:19 +02:00
|
|
|
position: 'left',
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// grid line settings
|
|
|
|
gridLines: {
|
|
|
|
display: true,
|
2016-09-14 20:05:19 +02:00
|
|
|
color: 'rgba(0, 0, 0, 0.1)',
|
2016-02-14 23:06:00 +01:00
|
|
|
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,
|
2016-09-14 20:05:19 +02:00
|
|
|
zeroLineColor: 'rgba(0,0,0,0.25)',
|
2016-08-12 18:31:54 +02:00
|
|
|
offsetGridLines: false,
|
|
|
|
borderDash: [],
|
|
|
|
borderDashOffset: 0.0
|
2016-02-14 23:06:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// 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,
|
2016-11-05 01:41:54 +01:00
|
|
|
padding: 0,
|
2016-02-14 23:06:00 +01:00
|
|
|
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-06-03 21:15:29 +02:00
|
|
|
// We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
|
2016-09-24 22:56:16 +02:00
|
|
|
callback: Chart.Ticks.formatters.values
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-08 03:17:20 +01:00
|
|
|
function computeTextSize(context, tick, font) {
|
|
|
|
return helpers.isArray(tick) ?
|
|
|
|
helpers.longestText(context, font, tick) :
|
|
|
|
context.measureText(tick).width;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseFontOptions(options) {
|
|
|
|
var getValueOrDefault = helpers.getValueOrDefault;
|
|
|
|
var globalDefaults = Chart.defaults.global;
|
|
|
|
var size = getValueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
|
|
|
|
var style = getValueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
|
|
|
|
var family = getValueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
|
|
|
|
|
|
|
|
return {
|
|
|
|
size: size,
|
|
|
|
style: style,
|
|
|
|
family: family,
|
|
|
|
font: helpers.fontString(size, style, family)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
Chart.Scale = Chart.Element.extend({
|
2016-10-25 04:36:50 +02:00
|
|
|
/**
|
|
|
|
* Get the padding needed for the scale
|
|
|
|
* @method getPadding
|
|
|
|
* @private
|
|
|
|
* @returns {Padding} the necessary padding
|
|
|
|
*/
|
2016-10-25 03:43:52 +02:00
|
|
|
getPadding: function() {
|
|
|
|
var me = this;
|
|
|
|
return {
|
|
|
|
left: me.paddingLeft || 0,
|
|
|
|
top: me.paddingTop || 0,
|
|
|
|
right: me.paddingRight || 0,
|
|
|
|
bottom: me.paddingBottom || 0
|
|
|
|
};
|
|
|
|
},
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-10-25 03:43:52 +02:00
|
|
|
// These methods are ordered by lifecyle. Utilities then follow.
|
2016-02-14 23:06:00 +01:00
|
|
|
// 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);
|
2016-11-08 03:17:20 +01:00
|
|
|
me.longestTextCache = me.longestTextCache || {};
|
2016-02-14 23:06:00 +01:00
|
|
|
|
|
|
|
// 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-10-14 02:43:11 +02:00
|
|
|
var tickOpts = me.options.ticks;
|
|
|
|
me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback);
|
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-11-08 03:17:20 +01:00
|
|
|
var tickOpts = me.options.ticks;
|
2016-05-14 05:07:39 +02:00
|
|
|
|
2016-09-14 20:05:19 +02:00
|
|
|
// Get the width of each grid by calculating the difference
|
|
|
|
// between x offsets between 0 and 1.
|
2016-11-08 03:17:20 +01:00
|
|
|
var tickFont = parseFontOptions(tickOpts);
|
|
|
|
context.font = tickFont.font;
|
|
|
|
|
|
|
|
var labelRotation = tickOpts.minRotation || 0;
|
|
|
|
|
|
|
|
if (me.options.display && me.isHorizontal()) {
|
|
|
|
var originalLabelWidth = helpers.longestText(context, tickFont.font, me.ticks, me.longestTextCache);
|
|
|
|
var labelWidth = originalLabelWidth;
|
|
|
|
var cosRotation;
|
|
|
|
var sinRotation;
|
|
|
|
|
|
|
|
// Allow 3 pixels x2 padding either side for label readability
|
|
|
|
var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
|
|
|
|
|
|
|
|
// Max label rotation can be set or default to 90 - also act as a loop counter
|
|
|
|
while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
|
|
|
|
var angleRadians = helpers.toRadians(labelRotation);
|
|
|
|
cosRotation = Math.cos(angleRadians);
|
|
|
|
sinRotation = Math.sin(angleRadians);
|
|
|
|
|
|
|
|
if (sinRotation * originalLabelWidth > me.maxHeight) {
|
|
|
|
// go back one step
|
|
|
|
labelRotation--;
|
|
|
|
break;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 03:17:20 +01:00
|
|
|
labelRotation++;
|
|
|
|
labelWidth = cosRotation * originalLabelWidth;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 03:17:20 +01:00
|
|
|
me.labelRotation = labelRotation;
|
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-07 22:26:44 +02:00
|
|
|
var tickOpts = opts.ticks;
|
|
|
|
var scaleLabelOpts = opts.scaleLabel;
|
2016-08-23 02:09:09 +02:00
|
|
|
var gridLineOpts = opts.gridLines;
|
2016-05-07 22:26:44 +02:00
|
|
|
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-11-08 03:17:20 +01:00
|
|
|
var tickFont = parseFontOptions(tickOpts);
|
|
|
|
var scaleLabelFontSize = parseFontOptions(scaleLabelOpts).size * 1.5;
|
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-08-23 02:09:09 +02:00
|
|
|
minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// height
|
2016-05-07 22:26:44 +02:00
|
|
|
if (isHorizontal) {
|
2016-08-23 02:09:09 +02:00
|
|
|
minSize.height = display && gridLineOpts.drawTicks ? 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) {
|
2016-11-08 03:17:20 +01:00
|
|
|
minSize.height += scaleLabelFontSize;
|
2016-02-14 23:06:00 +01:00
|
|
|
} else {
|
2016-11-08 03:17:20 +01:00
|
|
|
minSize.width += scaleLabelFontSize;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 03:17:20 +01:00
|
|
|
// Don't bother fitting the ticks if we are not showing them
|
2016-05-07 22:26:44 +02:00
|
|
|
if (tickOpts.display && display) {
|
2016-11-08 03:17:20 +01:00
|
|
|
var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, me.ticks, me.longestTextCache);
|
2016-06-05 02:48:26 +02:00
|
|
|
var tallestLabelHeightInLines = helpers.numberOfLabelLines(me.ticks);
|
2016-11-08 03:17:20 +01:00
|
|
|
var lineSpace = tickFont.size * 0.5;
|
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
|
|
|
|
2016-11-08 03:17:20 +01:00
|
|
|
var angleRadians = helpers.toRadians(me.labelRotation);
|
|
|
|
var cosRotation = Math.cos(angleRadians);
|
|
|
|
var sinRotation = Math.sin(angleRadians);
|
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
// TODO - improve this calculation
|
2016-11-08 03:17:20 +01:00
|
|
|
var labelHeight = (sinRotation * largestTextWidth)
|
|
|
|
+ (tickFont.size * tallestLabelHeightInLines)
|
|
|
|
+ (lineSpace * tallestLabelHeightInLines);
|
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);
|
2016-11-08 03:17:20 +01:00
|
|
|
me.ctx.font = tickFont.font;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-11-08 03:17:20 +01:00
|
|
|
var firstTick = me.ticks[0];
|
|
|
|
var firstLabelWidth = computeTextSize(me.ctx, firstTick, tickFont.font);
|
|
|
|
|
|
|
|
var lastTick = me.ticks[me.ticks.length - 1];
|
|
|
|
var lastLabelWidth = computeTextSize(me.ctx, lastTick, tickFont.font);
|
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
|
2017-01-05 15:00:05 +01:00
|
|
|
if (me.labelRotation !== 0) {
|
|
|
|
me.paddingLeft = opts.position === 'bottom'? (cosRotation * firstLabelWidth) + 3: (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
|
|
|
|
me.paddingRight = opts.position === 'bottom'? (cosRotation * lineSpace) + 3: (cosRotation * lastLabelWidth) + 3;
|
|
|
|
} else {
|
|
|
|
me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
|
|
|
|
me.paddingRight = lastLabelWidth / 2 + 3;
|
|
|
|
}
|
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
|
|
|
|
// Account for padding
|
2016-11-08 03:17:20 +01:00
|
|
|
|
|
|
|
if (tickOpts.mirror) {
|
2016-05-07 22:26:44 +02:00
|
|
|
largestTextWidth = 0;
|
2016-11-08 03:17:20 +01:00
|
|
|
} else {
|
|
|
|
largestTextWidth += me.options.ticks.padding;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-11-05 02:31:00 +01:00
|
|
|
minSize.width += largestTextWidth;
|
2016-11-08 03:17:20 +01:00
|
|
|
me.paddingTop = tickFont.size / 2;
|
|
|
|
me.paddingBottom = tickFont.size / 2;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 03:17:20 +01:00
|
|
|
me.handleMargins();
|
|
|
|
|
|
|
|
me.width = minSize.width;
|
|
|
|
me.height = minSize.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle margins and padding interactions
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
handleMargins: function() {
|
|
|
|
var me = this;
|
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-11-08 03:17:20 +01:00
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
afterFit: function() {
|
|
|
|
helpers.callCallback(this.options.afterFit, [this]);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Shared Methods
|
|
|
|
isHorizontal: function() {
|
2016-09-14 20:05:19 +02:00
|
|
|
return this.options.position === 'top' || this.options.position === 'bottom';
|
2016-02-14 23:06:00 +01:00
|
|
|
},
|
|
|
|
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
|
2016-06-18 11:15:25 +02:00
|
|
|
getRightValue: function(rawValue) {
|
2016-02-14 23:06:00 +01:00
|
|
|
// Null and undefined values first
|
|
|
|
if (rawValue === null || typeof(rawValue) === 'undefined') {
|
|
|
|
return NaN;
|
|
|
|
}
|
2016-09-24 18:19:49 +02:00
|
|
|
// isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
|
|
|
|
if (typeof(rawValue) === 'number' && !isFinite(rawValue)) {
|
2016-02-14 23:06:00 +01:00
|
|
|
return NaN;
|
|
|
|
}
|
|
|
|
// If it is in fact an object, dive in one more level
|
2016-09-14 20:05:19 +02:00
|
|
|
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;
|
|
|
|
}
|
2016-09-15 02:23:30 +02:00
|
|
|
return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2016-09-15 02:23:30 +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
|
2016-09-14 20:05:19 +02:00
|
|
|
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;
|
|
|
|
}
|
2016-09-15 02:23:30 +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() {
|
2016-12-09 02:56:33 +01:00
|
|
|
return this.getPixelForValue(this.getBaseValue());
|
|
|
|
},
|
|
|
|
|
|
|
|
getBaseValue: function() {
|
2016-05-20 20:17:28 +02:00
|
|
|
var me = this;
|
|
|
|
var min = me.min;
|
|
|
|
var max = me.max;
|
|
|
|
|
2016-12-09 02:56:33 +01:00
|
|
|
return me.beginAtZero ? 0:
|
2016-05-20 20:17:28 +02:00
|
|
|
min < 0 && max < 0? max :
|
|
|
|
min > 0 && max > 0? min :
|
2016-12-09 02:56:33 +01:00
|
|
|
0;
|
2016-05-20 20:17:28 +02:00
|
|
|
},
|
|
|
|
|
Spelling fixes (#3522)
Including: actually, aspect, bottom, changes, characters, datasets, divisible, downward, guidelines, instance, instances, interrupted, item, javascript, label, lifecycle, lines, plugins, manually, milliseconds, nearest, occurring, position, predefined, recalculate, tooltip, those
2016-10-27 21:18:31 +02:00
|
|
|
// Actually draw the scale on the canvas
|
2016-02-14 23:06:00 +01:00
|
|
|
// @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;
|
|
|
|
|
2016-06-04 20:14:16 +02:00
|
|
|
var isRotated = me.labelRotation !== 0;
|
2016-05-14 15:58:42 +02:00
|
|
|
var skipRatio;
|
|
|
|
var useAutoskipper = optionTicks.autoSkip;
|
2016-06-08 03:32:26 +02:00
|
|
|
var isHorizontal = me.isHorizontal();
|
2016-05-14 15:58:42 +02:00
|
|
|
|
|
|
|
// 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);
|
2016-11-08 03:17:20 +01:00
|
|
|
var tickFont = parseFontOptions(optionTicks);
|
|
|
|
|
2016-12-04 04:21:25 +01:00
|
|
|
var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
|
2016-08-12 18:31:54 +02:00
|
|
|
var borderDash = helpers.getValueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
|
|
|
|
var borderDashOffset = helpers.getValueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-05-14 15:58:42 +02:00
|
|
|
var scaleLabelFontColor = helpers.getValueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
|
2016-11-08 03:17:20 +01:00
|
|
|
var scaleLabelFont = parseFontOptions(scaleLabel);
|
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);
|
2016-06-04 20:14:16 +02:00
|
|
|
var longestRotatedLabel = me.longestLabelWidth * cosRotation;
|
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-08 03:32:26 +02:00
|
|
|
var itemsToDraw = [];
|
|
|
|
|
|
|
|
if (isHorizontal) {
|
2016-05-14 15:58:42 +02:00
|
|
|
skipRatio = false;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-18 11:00:11 +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-05-19 00:20:06 +02:00
|
|
|
|
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-06-08 03:32:26 +02:00
|
|
|
}
|
2016-03-06 04:58:34 +01:00
|
|
|
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-09-14 20:05:19 +02:00
|
|
|
var xTickStart = options.position === 'right' ? me.left : me.right - tl;
|
|
|
|
var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
|
|
|
|
var yTickStart = options.position === 'bottom' ? me.top : me.bottom - tl;
|
|
|
|
var yTickEnd = options.position === 'bottom' ? me.top + tl : me.bottom;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
helpers.each(me.ticks, function(label, index) {
|
|
|
|
// 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-08 03:32:26 +02:00
|
|
|
var isLastTick = me.ticks.length === index + 1;
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
// Since we always show the last tick,we need may need to hide the last shown one before
|
|
|
|
var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
|
|
|
|
if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
var lineWidth, lineColor;
|
|
|
|
if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
|
|
|
|
// Draw the first index specially
|
|
|
|
lineWidth = gridLines.zeroLineWidth;
|
|
|
|
lineColor = gridLines.zeroLineColor;
|
2016-09-14 20:05:19 +02:00
|
|
|
} else {
|
2016-06-08 03:32:26 +02:00
|
|
|
lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
|
|
|
|
lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index);
|
2016-05-14 15:58:42 +02:00
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
// Common properties
|
|
|
|
var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
|
2016-09-15 02:23:30 +02:00
|
|
|
var textAlign = 'middle';
|
|
|
|
var textBaseline = 'middle';
|
2016-05-14 15:58:42 +02:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
if (isHorizontal) {
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2017-01-05 15:00:05 +01:00
|
|
|
if (options.position === 'bottom') {
|
|
|
|
// bottom
|
|
|
|
textBaseline = !isRotated? 'top':'middle';
|
|
|
|
textAlign = !isRotated? 'center': 'right';
|
|
|
|
labelY = me.top + tl;
|
|
|
|
} else {
|
|
|
|
// top
|
|
|
|
textBaseline = !isRotated? 'bottom':'middle';
|
|
|
|
textAlign = !isRotated? 'center': 'left';
|
|
|
|
labelY = me.bottom - tl;
|
|
|
|
}
|
2016-06-08 03:32:26 +02:00
|
|
|
|
|
|
|
var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines
|
|
|
|
labelX = me.getPixelForTick(index, gridLines.offsetGridLines) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
|
2016-05-14 15:58:42 +02:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
tx1 = tx2 = x1 = x2 = xLineValue;
|
|
|
|
ty1 = yTickStart;
|
|
|
|
ty2 = yTickEnd;
|
|
|
|
y1 = chartArea.top;
|
|
|
|
y2 = chartArea.bottom;
|
|
|
|
} else {
|
2016-11-05 01:41:54 +01:00
|
|
|
var isLeft = options.position === 'left';
|
|
|
|
var tickPadding = optionTicks.padding;
|
|
|
|
var labelXOffset;
|
|
|
|
|
|
|
|
if (optionTicks.mirror) {
|
|
|
|
textAlign = isLeft ? 'left' : 'right';
|
|
|
|
labelXOffset = tickPadding;
|
2016-06-08 03:32:26 +02:00
|
|
|
} else {
|
2016-11-05 01:41:54 +01:00
|
|
|
textAlign = isLeft ? 'right' : 'left';
|
|
|
|
labelXOffset = tl + tickPadding;
|
2016-06-08 03:32:26 +02:00
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-11-05 01:41:54 +01:00
|
|
|
labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
|
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
|
|
|
|
yLineValue += helpers.aliasPixel(lineWidth);
|
|
|
|
labelY = me.getPixelForTick(index, gridLines.offsetGridLines);
|
|
|
|
|
|
|
|
tx1 = xTickStart;
|
|
|
|
tx2 = xTickEnd;
|
|
|
|
x1 = chartArea.left;
|
|
|
|
x2 = chartArea.right;
|
|
|
|
ty1 = ty2 = y1 = y2 = yLineValue;
|
|
|
|
}
|
2016-05-14 15:58:42 +02:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
itemsToDraw.push({
|
|
|
|
tx1: tx1,
|
|
|
|
ty1: ty1,
|
|
|
|
tx2: tx2,
|
|
|
|
ty2: ty2,
|
|
|
|
x1: x1,
|
|
|
|
y1: y1,
|
|
|
|
x2: x2,
|
|
|
|
y2: y2,
|
|
|
|
labelX: labelX,
|
|
|
|
labelY: labelY,
|
|
|
|
glWidth: lineWidth,
|
|
|
|
glColor: lineColor,
|
2016-08-12 18:31:54 +02:00
|
|
|
glBorderDash: borderDash,
|
|
|
|
glBorderDashOffset: borderDashOffset,
|
2016-06-08 03:32:26 +02:00
|
|
|
rotation: -1 * labelRotationRadians,
|
|
|
|
label: label,
|
|
|
|
textBaseline: textBaseline,
|
|
|
|
textAlign: textAlign
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Draw all of the tick labels, tick marks, and grid lines at the correct places
|
|
|
|
helpers.each(itemsToDraw, function(itemToDraw) {
|
|
|
|
if (gridLines.display) {
|
2016-08-12 18:31:54 +02:00
|
|
|
context.save();
|
2016-06-08 03:32:26 +02:00
|
|
|
context.lineWidth = itemToDraw.glWidth;
|
|
|
|
context.strokeStyle = itemToDraw.glColor;
|
2016-08-12 18:31:54 +02:00
|
|
|
if (context.setLineDash) {
|
|
|
|
context.setLineDash(itemToDraw.glBorderDash);
|
|
|
|
context.lineDashOffset = itemToDraw.glBorderDashOffset;
|
|
|
|
}
|
2016-06-08 03:32:26 +02:00
|
|
|
|
|
|
|
context.beginPath();
|
|
|
|
|
|
|
|
if (gridLines.drawTicks) {
|
|
|
|
context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
|
|
|
|
context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
|
2016-05-14 15:58:42 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
if (gridLines.drawOnChartArea) {
|
|
|
|
context.moveTo(itemToDraw.x1, itemToDraw.y1);
|
|
|
|
context.lineTo(itemToDraw.x2, itemToDraw.y2);
|
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
context.stroke();
|
2016-08-12 18:31:54 +02:00
|
|
|
context.restore();
|
2016-06-08 03:32:26 +02:00
|
|
|
}
|
2016-02-14 23:06:00 +01:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
if (optionTicks.display) {
|
|
|
|
context.save();
|
|
|
|
context.translate(itemToDraw.labelX, itemToDraw.labelY);
|
|
|
|
context.rotate(itemToDraw.rotation);
|
2016-11-08 03:17:20 +01:00
|
|
|
context.font = tickFont.font;
|
2016-06-08 03:32:26 +02:00
|
|
|
context.textBaseline = itemToDraw.textBaseline;
|
|
|
|
context.textAlign = itemToDraw.textAlign;
|
|
|
|
|
|
|
|
var label = itemToDraw.label;
|
|
|
|
if (helpers.isArray(label)) {
|
2016-11-08 03:17:20 +01:00
|
|
|
for (var i = 0, y = 0; i < label.length; ++i) {
|
2016-06-08 03:32:26 +02:00
|
|
|
// We just make sure the multiline element is a string here..
|
|
|
|
context.fillText('' + label[i], 0, y);
|
|
|
|
// apply same lineSpacing as calculated @ L#320
|
2016-11-08 03:17:20 +01:00
|
|
|
y += (tickFont.size * 1.5);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-06-08 03:32:26 +02:00
|
|
|
} else {
|
2016-05-14 15:58:42 +02:00
|
|
|
context.fillText(label, 0, 0);
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-06-08 03:32:26 +02:00
|
|
|
context.restore();
|
|
|
|
}
|
|
|
|
});
|
2016-05-14 15:58:42 +02:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
if (scaleLabel.display) {
|
|
|
|
// Draw the scale label
|
|
|
|
var scaleLabelX;
|
|
|
|
var scaleLabelY;
|
|
|
|
var rotation = 0;
|
2016-05-14 15:58:42 +02:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
if (isHorizontal) {
|
|
|
|
scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
|
2016-12-16 08:15:14 +01:00
|
|
|
scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFont.size / 2) : me.top + (scaleLabelFont.size / 2);
|
2016-06-08 03:32:26 +02:00
|
|
|
} else {
|
|
|
|
var isLeft = options.position === 'left';
|
2016-11-08 03:17:20 +01:00
|
|
|
scaleLabelX = isLeft ? me.left + (scaleLabelFont.size / 2) : me.right - (scaleLabelFont.size / 2);
|
2016-06-08 03:32:26 +02:00
|
|
|
scaleLabelY = me.top + ((me.bottom - me.top) / 2);
|
|
|
|
rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
|
2016-02-14 23:06:00 +01:00
|
|
|
}
|
2016-06-18 11:00:11 +02:00
|
|
|
|
2016-06-08 03:32:26 +02:00
|
|
|
context.save();
|
|
|
|
context.translate(scaleLabelX, scaleLabelY);
|
|
|
|
context.rotate(rotation);
|
|
|
|
context.textAlign = 'center';
|
|
|
|
context.textBaseline = 'middle';
|
|
|
|
context.fillStyle = scaleLabelFontColor; // render in correct colour
|
2016-11-08 03:17:20 +01:00
|
|
|
context.font = scaleLabelFont.font;
|
2016-06-08 03:32:26 +02:00
|
|
|
context.fillText(scaleLabel.labelString, 0, 0);
|
|
|
|
context.restore();
|
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
|
2016-06-08 02:22:06 +02:00
|
|
|
context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, 0);
|
|
|
|
context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, 0);
|
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-08 03:32:26 +02:00
|
|
|
if (isHorizontal) {
|
2016-06-04 20:14:16 +02:00
|
|
|
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
|
|
|
};
|