From d18fa8bb0308cde76189ad5d88c1e349e8a160d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 24 Jan 2017 18:14:56 -0500 Subject: [PATCH] Support multiple gradient offsets at 0 Closes #1241 --- src/style/Color.js | 6 ++++-- src/svg/SvgExport.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/style/Color.js b/src/style/Color.js index 4fcb8a9e..98072939 100644 --- a/src/style/Color.js +++ b/src/style/Color.js @@ -863,12 +863,14 @@ var Color = Base.extend(new function() { destination.x, destination.y); } for (var i = 0, l = stops.length; i < l; i++) { - var stop = stops[i]; + var stop = stops[i], + offset = stop._offset; // Use the defined offset, and fall back to automatic linear // calculation. // NOTE: that if _offset is 0 for the first entry, the fall-back // will be so too. - canvasGradient.addColorStop(stop._offset || i / (l - 1), + canvasGradient.addColorStop( + offset == null ? i / (l - 1) : offset, stop._color.toCanvasStyle()); } return this._canvasStyle = canvasGradient; diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index 394f194f..fefc7653 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -232,9 +232,10 @@ new function() { for (var i = 0, l = stops.length; i < l; i++) { var stop = stops[i], stopColor = stop._color, - alpha = stopColor.getAlpha(); + alpha = stopColor.getAlpha(), + offset = stop._offset; attrs = { - offset: stop._offset || i / (l - 1) + offset: offset == null ? i / (l - 1) : offset }; if (stopColor) attrs['stop-color'] = stopColor.toCSS(true);