@@ -203,7 +203,7 @@ drawing.symbolNumber = function(v) {
203203 return Math . floor ( Math . max ( v , 0 ) ) ;
204204} ;
205205
206- function singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , markerLine , gd ) {
206+ function singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , markerLine , gd , i ) {
207207 // only scatter & box plots get marker path and opacity
208208 // bars, histograms don't
209209 if ( Registry . traceIs ( trace , 'symbols' ) ) {
@@ -238,6 +238,8 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL
238238 } ) ;
239239 }
240240
241+ var perPointGradient = false ;
242+
241243 // 'so' is suspected outliers, for box plots
242244 var fillColor ,
243245 lineColor ,
@@ -257,8 +259,12 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL
257259 else if ( Array . isArray ( markerLine . color ) ) lineColor = Color . defaultLine ;
258260 else lineColor = markerLine . color ;
259261
262+ if ( Array . isArray ( marker . color ) ) {
263+ fillColor = Color . defaultLine ;
264+ perPointGradient = true ;
265+ }
266+
260267 if ( 'mc' in d ) fillColor = d . mcc = markerScale ( d . mc ) ;
261- else if ( Array . isArray ( marker . color ) ) fillColor = Color . defaultLine ;
262268 else fillColor = marker . color || 'rgba(0,0,0,0)' ;
263269 }
264270
@@ -275,10 +281,20 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL
275281 sel . style ( 'stroke-width' , lineWidth + 'px' ) ;
276282
277283 var markerGradient = marker . gradient ;
278- var gradientColor = markerGradient && ( d . mgc || markerGradient . color ) ;
279- var gradientType = markerGradient && ( d . mgt || markerGradient . type ) ;
284+
285+ var gradientType = d . mgt ;
286+ if ( gradientType ) perPointGradient = true ;
287+ else gradientType = markerGradient && markerGradient . type ;
288+
280289 if ( gradientType && gradientType !== 'none' ) {
281- sel . call ( drawing . gradient , gd , gradientType , fillColor , gradientColor ) ;
290+ var gradientColor = d . mgc ;
291+ if ( gradientColor ) perPointGradient = true ;
292+ else gradientColor = markerGradient . color ;
293+
294+ var gradientID = 'g' + gd . _fullLayout . _uid + '-' + trace . uid ;
295+ if ( perPointGradient ) gradientID += '-' + i ;
296+
297+ sel . call ( drawing . gradient , gd , gradientID , gradientType , fillColor , gradientColor ) ;
282298 }
283299 else {
284300 sel . call ( Color . fill , fillColor ) ;
@@ -293,12 +309,12 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL
293309var HORZGRADIENT = { x1 : 1 , x2 : 0 , y1 : 0 , y2 : 0 } ;
294310var VERTGRADIENT = { x1 : 0 , x2 : 0 , y1 : 1 , y2 : 0 } ;
295311
296- drawing . gradient = function ( sel , gd , type , color1 , color2 ) {
297- var fullLayout = gd . _fullLayout ;
298- var gradientID = (
299- type + fullLayout . _uid + '-' + color1 + '-' + color2
300- ) . replace ( / [ ^ \w \- ] + / g , '_' ) ;
301- var gradient = fullLayout . _defs . select ( '.gradients' ) . selectAll ( '#' + gradientID ) . data ( [ 0 ] ) ;
312+ drawing . gradient = function ( sel , gd , gradientID , type , color1 , color2 ) {
313+ var gradient = gd . _fullLayout . _defs . select ( '.gradients' )
314+ . selectAll ( '#' + gradientID )
315+ . data ( [ type + color1 + color2 ] , Lib . identity ) ;
316+
317+ gradient . exit ( ) . remove ( ) ;
302318
303319 gradient . enter ( )
304320 . append ( type === 'radial' ? 'radialGradient' : 'linearGradient' )
@@ -345,10 +361,10 @@ drawing.initGradients = function(gd) {
345361 gradientsGroup . selectAll ( 'linearGradient,radialGradient' ) . remove ( ) ;
346362} ;
347363
348- drawing . singlePointStyle = function ( d , sel , trace , markerScale , lineScale , gd ) {
364+ drawing . singlePointStyle = function ( d , sel , trace , markerScale , lineScale , gd , i ) {
349365 var marker = trace . marker ;
350366
351- singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , marker . line , gd ) ;
367+ singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , marker . line , gd , i ) ;
352368
353369} ;
354370
@@ -362,8 +378,8 @@ drawing.pointStyle = function(s, trace) {
362378 var lineScale = drawing . tryColorscale ( marker , 'line' ) ;
363379 var gd = Lib . getPlotDiv ( s . node ( ) ) ;
364380
365- s . each ( function ( d ) {
366- drawing . singlePointStyle ( d , d3 . select ( this ) , trace , markerScale , lineScale , gd ) ;
381+ s . each ( function ( d , i ) {
382+ drawing . singlePointStyle ( d , d3 . select ( this ) , trace , markerScale , lineScale , gd , i ) ;
367383 } ) ;
368384} ;
369385
0 commit comments