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

Coloring an axis line separately from gridLines #4058

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions docs/axes/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The grid line configuration is nested under the scale configuration in the `grid
| -----| ---- | --------| -----------
| `display` | `Boolean` | `true` | If false, do not display grid lines for this axis.
| `color` | Color or Color[] | `'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.
| `axisColor` | Color | `'rgba(0, 0, 0, 0.1)'` | The color of axis line.
| `borderDash` | `Number[]` | `[]` | Length and spacing of dashes on grid lines. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash)
| `borderDashOffset` | `Number` | `0` | Offset for line dashes. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
| `lineWidth` | `Number or Number[]` | `1` | Stroke width of grid lines.
Expand Down
3 changes: 2 additions & 1 deletion src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = function(Chart) {
gridLines: {
display: true,
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
lineWidth: 1,
drawBorder: true,
drawOnChartArea: true,
Expand Down Expand Up @@ -730,7 +731,7 @@ module.exports = function(Chart) {
if (gridLines.drawBorder) {
// Draw the line at the edge of the axis
context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, 0);
context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, 0);
context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.axisColor, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what's the difference between zeroLineColor and axisColor?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zeroLineColor affects only the line at 0, which could be in the middle of the graph(e.g. min: -20, max: 20) or not displayed at all(e.g. min: 50, max: 100).
axisColor is always the border line near ticks

also zeroLineColor affects the other axis(see pic)
axiscolor_zerolinecolor demonstartion

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood :) @etimberg what do you think about the option name axisColor?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do borderColor ?

var x1 = me.left,
x2 = me.right,
y1 = me.top,
Expand Down
2 changes: 2 additions & 0 deletions test/specs/core.helpers.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ describe('Core helper tests', function() {

gridLines: {
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label
Expand Down Expand Up @@ -222,6 +223,7 @@ describe('Core helper tests', function() {

gridLines: {
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label,
Expand Down
1 change: 1 addition & 0 deletions test/specs/scale.category.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Category scale tests', function() {

gridLines: {
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label
Expand Down
1 change: 1 addition & 0 deletions test/specs/scale.linear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Linear Scale', function() {

gridLines: {
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true, // draw ticks extending towards the label
Expand Down
1 change: 1 addition & 0 deletions test/specs/scale.logarithmic.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Logarithmic Scale tests', function() {
display: true,
gridLines: {
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true,
Expand Down
1 change: 1 addition & 0 deletions test/specs/scale.radialLinear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Test the radial linear scale', function() {
gridLines: {
circular: false,
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true,
Expand Down
1 change: 1 addition & 0 deletions test/specs/scale.time.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Time scale tests', function() {
display: true,
gridLines: {
color: 'rgba(0, 0, 0, 0.1)',
axisColor: 'rgba(0, 0, 0, 0.1)',
drawBorder: true,
drawOnChartArea: true,
drawTicks: true,
Expand Down