Skip to content

Commit

Permalink
Zero line dash options
Browse files Browse the repository at this point in the history
* Add of zero line border dash options

* Update Readme with zero line border dash config options
  • Loading branch information
lndobryden authored and Lee Dobryden committed Mar 21, 2017
1 parent 6e57405 commit 6937437
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/axes/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The grid line configuration is nested under the scale configuration in the `grid
| `tickMarkLength` | `Number` | `10` | Length in pixels that the grid lines will draw into the axis area.
| `zeroLineWidth` | `Number` | `1` | Stroke width of the grid line for the first index (index 0).
| `zeroLineColor` | Color | `'rgba(0, 0, 0, 0.25)'` | Stroke color of the grid line for the first index (index 0).
| `zeroLineBorderDash` | `Number[]` | `[]` | Length and spacing of dashes of the grid line for the first index (index 0). See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash)
| `zeroLineBorderDashOffset` | `Number` | `0` | Offset for line dashes of the grid line for the first index (index 0). See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
| `offsetGridLines` | `Boolean` | `false` | If true, labels are shifted to be between grid lines. This is used in the bar chart and should not generally be used.

## Tick Configuration
Expand Down
10 changes: 7 additions & 3 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = function(Chart) {
tickMarkLength: 10,
zeroLineWidth: 1,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
offsetGridLines: false,
borderDash: [],
borderDashOffset: 0.0
Expand Down Expand Up @@ -503,8 +505,6 @@ module.exports = function(Chart) {
var tickFont = parseFontOptions(optionTicks);

var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
var borderDash = helpers.getValueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
var borderDashOffset = helpers.getValueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);

var scaleLabelFontColor = helpers.getValueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
var scaleLabelFont = parseFontOptions(scaleLabel);
Expand Down Expand Up @@ -561,14 +561,18 @@ module.exports = function(Chart) {
return;
}

var lineWidth, lineColor;
var lineWidth, lineColor, borderDash, borderDashOffset;
if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
// Draw the first index specially
lineWidth = gridLines.zeroLineWidth;
lineColor = gridLines.zeroLineColor;
borderDash = gridLines.zeroLineBorderDash;
borderDashOffset = gridLines.zeroLineBorderDashOffset;
} else {
lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index);
borderDash = helpers.getValueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
borderDashOffset = helpers.getValueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
}

// Common properties
Expand Down
4 changes: 4 additions & 0 deletions test/specs/core.helpers.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ describe('Core helper tests', function() {
display: true,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
borderDash: [],
borderDashOffset: 0.0
},
Expand Down Expand Up @@ -229,6 +231,8 @@ describe('Core helper tests', function() {
display: true,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
borderDash: [],
borderDashOffset: 0.0
},
Expand Down
2 changes: 2 additions & 0 deletions test/specs/scale.category.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('Category scale tests', function() {
display: true,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
borderDash: [],
borderDashOffset: 0.0
},
Expand Down
2 changes: 2 additions & 0 deletions test/specs/scale.linear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe('Linear Scale', function() {
display: true,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
borderDash: [],
borderDashOffset: 0.0
},
Expand Down
2 changes: 2 additions & 0 deletions test/specs/scale.logarithmic.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Logarithmic Scale tests', function() {
display: true,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
borderDash: [],
borderDashOffset: 0.0
},
Expand Down
2 changes: 2 additions & 0 deletions test/specs/scale.radialLinear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('Test the radial linear scale', function() {
display: true,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
borderDash: [],
borderDashOffset: 0.0
},
Expand Down
2 changes: 2 additions & 0 deletions test/specs/scale.time.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ describe('Time scale tests', function() {
display: true,
zeroLineColor: 'rgba(0,0,0,0.25)',
zeroLineWidth: 1,
zeroLineBorderDash: [],
zeroLineBorderDashOffset: 0.0,
borderDash: [],
borderDashOffset: 0.0
},
Expand Down

0 comments on commit 6937437

Please sign in to comment.