From: Evert Timberg Date: Wed, 8 Jun 2016 00:22:06 +0000 (-0400) Subject: Support arrays of colors and line widths in cartesian axes X-Git-Tag: v2.1.5~6^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6b2cfd5e11c3f19fc9ca7f3c09260ff77a52fc8e;p=thirdparty%2FChart.js.git Support arrays of colors and line widths in cartesian axes --- diff --git a/samples/line-logarithmic.html b/samples/line-logarithmic.html index fa17a4b6e..290ea43ea 100644 --- a/samples/line-logarithmic.html +++ b/samples/line-logarithmic.html @@ -59,6 +59,9 @@ scales: { xAxes: [{ display: true, + gridLines: { + color: ['black', 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] + }, scaleLabel: { display: true, labelString: 'x axis' diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 171527b43..16f95bbc7 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -488,7 +488,6 @@ module.exports = function(Chart) { var gridLines = options.gridLines; var scaleLabel = options.scaleLabel; - var setContextLineSettings; var isRotated = me.labelRotation !== 0; var skipRatio; var scaleLabelX; @@ -524,7 +523,6 @@ module.exports = function(Chart) { context.fillStyle = tickFontColor; if (me.isHorizontal()) { - setContextLineSettings = true; var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl; var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom; skipRatio = false; @@ -571,11 +569,9 @@ module.exports = function(Chart) { // Draw the first index specially context.lineWidth = gridLines.zeroLineWidth; context.strokeStyle = gridLines.zeroLineColor; - setContextLineSettings = true; // reset next time - } else if (setContextLineSettings) { - context.lineWidth = gridLines.lineWidth; - context.strokeStyle = gridLines.color; - setContextLineSettings = false; + } else { + context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index); + context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, index); } xLineValue += helpers.aliasPixel(context.lineWidth); @@ -635,7 +631,6 @@ module.exports = function(Chart) { } } else { - setContextLineSettings = true; var xTickStart = options.position === "right" ? me.left : me.right - 5; var xTickEnd = options.position === "right" ? me.left + 5 : me.right; @@ -652,11 +647,9 @@ module.exports = function(Chart) { // Draw the first index specially context.lineWidth = gridLines.zeroLineWidth; context.strokeStyle = gridLines.zeroLineColor; - setContextLineSettings = true; // reset next time - } else if (setContextLineSettings) { - context.lineWidth = gridLines.lineWidth; - context.strokeStyle = gridLines.color; - setContextLineSettings = false; + } else { + context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index); + context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, index); } yLineValue += helpers.aliasPixel(context.lineWidth); @@ -733,8 +726,8 @@ module.exports = function(Chart) { if (gridLines.drawBorder) { // Draw the line at the edge of the axis - context.lineWidth = gridLines.lineWidth; - context.strokeStyle = gridLines.color; + context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, 0); + context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, 0); var x1 = me.left, x2 = me.right, y1 = me.top,