Support multiple gradient offsets at 0

Closes #1241
This commit is contained in:
Jürg Lehni 2017-01-24 18:14:56 -05:00
parent 4833c588e5
commit d18fa8bb03
2 changed files with 7 additions and 4 deletions

View file

@ -863,12 +863,14 @@ var Color = Base.extend(new function() {
destination.x, destination.y); destination.x, destination.y);
} }
for (var i = 0, l = stops.length; i < l; i++) { 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 // Use the defined offset, and fall back to automatic linear
// calculation. // calculation.
// NOTE: that if _offset is 0 for the first entry, the fall-back // NOTE: that if _offset is 0 for the first entry, the fall-back
// will be so too. // will be so too.
canvasGradient.addColorStop(stop._offset || i / (l - 1), canvasGradient.addColorStop(
offset == null ? i / (l - 1) : offset,
stop._color.toCanvasStyle()); stop._color.toCanvasStyle());
} }
return this._canvasStyle = canvasGradient; return this._canvasStyle = canvasGradient;

View file

@ -232,9 +232,10 @@ new function() {
for (var i = 0, l = stops.length; i < l; i++) { for (var i = 0, l = stops.length; i < l; i++) {
var stop = stops[i], var stop = stops[i],
stopColor = stop._color, stopColor = stop._color,
alpha = stopColor.getAlpha(); alpha = stopColor.getAlpha(),
offset = stop._offset;
attrs = { attrs = {
offset: stop._offset || i / (l - 1) offset: offset == null ? i / (l - 1) : offset
}; };
if (stopColor) if (stopColor)
attrs['stop-color'] = stopColor.toCSS(true); attrs['stop-color'] = stopColor.toCSS(true);