const tl = getTickMarkLength(grid);
const items = [];
- const borderOpts = grid.setContext(me.getContext(0));
+ const borderOpts = grid.setContext(me.getContext());
const axisWidth = borderOpts.drawBorder ? borderOpts.borderWidth : 0;
const axisHalfWidth = axisWidth / 2;
const alignBorderValue = function(pixel) {
const me = this;
const grid = me.options.grid;
const ctx = me.ctx;
- const chart = me.chart;
- const borderOpts = grid.setContext(me.getContext());
- const axisWidth = grid.drawBorder ? borderOpts.borderWidth : 0;
const items = me._gridLineItems || (me._gridLineItems = me._computeGridLineItems(chartArea));
let i, ilen;
}
}
}
+ }
- if (axisWidth) {
- // Draw the line at the edge of the axis
- const lastLineWidth = borderOpts.lineWidth;
- const borderValue = me._borderValue;
- let x1, x2, y1, y2;
+ /**
+ * @protected
+ */
+ drawBorder() {
+ const me = this;
+ const {chart, ctx, options: {grid}} = me;
+ const borderOpts = grid.setContext(me.getContext());
+ const axisWidth = grid.drawBorder ? borderOpts.borderWidth : 0;
+ if (!axisWidth) {
+ return;
+ }
+ const lastLineWidth = grid.setContext(me.getContext(0)).lineWidth;
+ const borderValue = me._borderValue;
+ let x1, x2, y1, y2;
- if (me.isHorizontal()) {
- x1 = _alignPixel(chart, me.left, axisWidth) - axisWidth / 2;
- x2 = _alignPixel(chart, me.right, lastLineWidth) + lastLineWidth / 2;
- y1 = y2 = borderValue;
- } else {
- y1 = _alignPixel(chart, me.top, axisWidth) - axisWidth / 2;
- y2 = _alignPixel(chart, me.bottom, lastLineWidth) + lastLineWidth / 2;
- x1 = x2 = borderValue;
- }
- drawLine(
- {x: x1, y: y1},
- {x: x2, y: y2},
- {width: axisWidth, color: borderOpts.borderColor});
+ if (me.isHorizontal()) {
+ x1 = _alignPixel(chart, me.left, axisWidth) - axisWidth / 2;
+ x2 = _alignPixel(chart, me.right, lastLineWidth) + lastLineWidth / 2;
+ y1 = y2 = borderValue;
+ } else {
+ y1 = _alignPixel(chart, me.top, axisWidth) - axisWidth / 2;
+ y2 = _alignPixel(chart, me.bottom, lastLineWidth) + lastLineWidth / 2;
+ x1 = x2 = borderValue;
}
+ ctx.save();
+ ctx.lineWidth = borderOpts.borderWidth;
+ ctx.strokeStyle = borderOpts.borderColor;
+
+ ctx.beginPath();
+ ctx.moveTo(x1, y1);
+ ctx.lineTo(x2, y2);
+ ctx.stroke();
+
+ ctx.restore();
}
/**
me.drawBackground();
me.drawGrid(chartArea);
+ me.drawBorder();
me.drawTitle();
me.drawLabels(chartArea);
}
const tz = opts.ticks && opts.ticks.z || 0;
const gz = opts.grid && opts.grid.z || 0;
- if (!me._isVisible() || tz === gz || me.draw !== Scale.prototype.draw) {
+ if (!me._isVisible() || me.draw !== Scale.prototype.draw) {
// backward compatibility: draw has been overridden by custom scale
return [{
z: tz,
me.drawGrid(chartArea);
me.drawTitle();
}
+ }, {
+ z: gz + 1, // TODO, v4 move border options to its own object and add z
+ draw() {
+ me.drawBorder();
+ }
}, {
z: tz,
draw(chartArea) {
});
describe('_layers', function() {
- it('should default to one layer', function() {
+ it('should default to three layers', function() {
var chart = window.acquireChart({
type: 'line',
options: {
});
var scale = chart.scales.x;
- expect(scale._layers().length).toEqual(1);
+ expect(scale._layers().length).toEqual(3);
});
it('should default to one layer for custom scales', function() {
expect(scale._layers()[0].z).toEqual(20);
});
- it('should default to one layer when z is equal between ticks and grid', function() {
- var chart = window.acquireChart({
- type: 'line',
- options: {
- scales: {
- x: {
- type: 'linear',
- ticks: {
- z: 10
- },
- grid: {
- z: 10
- }
- }
- }
- }
- });
-
- var scale = chart.scales.x;
- expect(scale._layers().length).toEqual(1);
- });
-
-
- it('should return 2 layers when z is not equal between ticks and grid', function() {
+ it('should return 3 layers when z is not equal between ticks and grid', function() {
var chart = window.acquireChart({
type: 'line',
options: {
}
});
- expect(chart.scales.x._layers().length).toEqual(2);
+ expect(chart.scales.x._layers().length).toEqual(3);
chart = window.acquireChart({
type: 'line',
}
});
- expect(chart.scales.x._layers().length).toEqual(2);
+ expect(chart.scales.x._layers().length).toEqual(3);
chart = window.acquireChart({
type: 'line',
}
});
- expect(chart.scales.x._layers().length).toEqual(2);
+ expect(chart.scales.x._layers().length).toEqual(3);
});