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

Enable override settings for the axis border #6883

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/axes/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The grid line configuration is nested under the scale configuration in the `grid
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| `display` | `boolean` | `true` | If false, do not display grid lines for this axis.
| `borderColor` | `Color` | | If set, used as the color of the border line. If unset, the first `color` option is resolved and used.
| `borderWidth` | `number` | | If set, used as the width of the border line. If unset, the first `lineWidth` option is resolved and used.
| `circular` | `boolean` | `false` | If true, gridlines are circular (on radar chart only).
| `color` | <code>Color&#124;Color[]&#124;function</code> | `'rgba(0, 0, 0, 0.1)'` | The color of the grid lines. If specified as an array, the first color applies to the first grid line, the second to the second grid line and so on.
| `borderDash` | `number[]` | `[]` | Length and spacing of dashes on grid lines. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash).
Expand Down
6 changes: 3 additions & 3 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ class Scale extends Element {
scale: me,
tick: ticks[0],
};
var axisWidth = gridLines.drawBorder ? resolve([gridLines.lineWidth, 0], context, 0) : 0;
var axisWidth = gridLines.drawBorder ? resolve([gridLines.borderWidth, gridLines.lineWidth, 0], context, 0) : 0;
var axisHalfWidth = axisWidth / 2;
var alignBorderValue = function(pixel) {
return alignPixel(chart, pixel, axisWidth);
Expand Down Expand Up @@ -1186,7 +1186,7 @@ class Scale extends Element {
scale: me,
tick: me.ticks[0],
};
var axisWidth = gridLines.drawBorder ? resolve([gridLines.lineWidth, 0], context, 0) : 0;
var axisWidth = gridLines.drawBorder ? resolve([gridLines.borderWidth, gridLines.lineWidth, 0], context, 0) : 0;
var items = me._gridLineItems || (me._gridLineItems = me._computeGridLineItems(chartArea));
var width, color, i, ilen, item;

Expand Down Expand Up @@ -1243,7 +1243,7 @@ class Scale extends Element {
}

ctx.lineWidth = axisWidth;
ctx.strokeStyle = resolve([gridLines.color], context, 0);
ctx.strokeStyle = resolve([gridLines.borderColor, gridLines.color], context, 0);
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
Expand Down
58 changes: 58 additions & 0 deletions test/fixtures/core.scale/cartesian-axis-border-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"config": {
"type": "scatter",
"data": {
"datasets": [{
"data": [{
"x": -20,
"y": -30
}, {
"x": 0,
"y": 0
}, {
"x": 20,
"y": 15
}]
}]
},
"options": {
"legend": false,
"title": false,
"scales": {
"x": {
"axis": "x",
"min": -100,
"max": 100,
"gridLines": {
"borderColor": "blue",
"borderWidth": 5,
"color": "red",
"drawBorder": true,
"drawOnChartArea": false
},
"ticks": {
"display": false
}
},
"y": {
"axis": "y",
"min": -100,
"max": 100,
"gridLines": {
"color": "red",
"drawOnChartArea": false
},
"ticks": {
"display": false
}
}
}
}
},
"options": {
"canvas": {
"height": 256,
"width": 512
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.