@@ -30,7 +30,7 @@ module.exports = function style(s, gd) {
30
30
var legend = fullLayout . legend ;
31
31
var constantItemSizing = legend . itemsizing === 'constant' ;
32
32
33
- function boundLineWidth ( mlw , cont , max , cst ) {
33
+ var boundLineWidth = function ( mlw , cont , max , cst ) {
34
34
var v ;
35
35
if ( mlw + 1 ) {
36
36
v = mlw ;
@@ -40,7 +40,17 @@ module.exports = function style(s, gd) {
40
40
return 0 ;
41
41
}
42
42
return constantItemSizing ? cst : Math . min ( v , max ) ;
43
- }
43
+ } ;
44
+
45
+ var getColorscale = function ( trace ) {
46
+ var coloraxis = trace . coloraxis ;
47
+ return ( coloraxis ? fullLayout [ coloraxis ] : trace ) . colorscale ;
48
+ } ;
49
+
50
+ var getReversescale = function ( trace ) {
51
+ var coloraxis = trace . coloraxis ;
52
+ return ( coloraxis ? fullLayout [ coloraxis ] : trace ) . reversescale ;
53
+ } ;
44
54
45
55
s . each ( function ( d ) {
46
56
var traceGroup = d3 . select ( this ) ;
@@ -104,6 +114,28 @@ module.exports = function style(s, gd) {
104
114
var showGradientFill = false ;
105
115
var dMod , tMod ;
106
116
117
+ var colorscale = getColorscale ( trace ) ;
118
+ var reversescale = getReversescale ( trace ) ;
119
+
120
+ var fillGradient = function ( s ) {
121
+ if ( s . size ( ) ) {
122
+ var gradientID = 'legendfill-' + trace . uid ;
123
+ Drawing . gradient ( s , gd , gradientID ,
124
+ getGradientDirection ( reversescale ) ,
125
+ colorscale , 'fill' ) ;
126
+ }
127
+ } ;
128
+
129
+ var lineGradient = function ( s ) {
130
+ if ( s . size ( ) ) {
131
+ var gradientID = 'legendline-' + trace . uid ;
132
+ Drawing . lineGroupStyle ( s ) ;
133
+ Drawing . gradient ( s , gd , gradientID ,
134
+ getGradientDirection ( reversescale ) ,
135
+ colorscale , 'stroke' ) ;
136
+ }
137
+ } ;
138
+
107
139
if ( contours ) {
108
140
var coloring = contours . coloring ;
109
141
@@ -158,23 +190,6 @@ module.exports = function style(s, gd) {
158
190
// This issue (and workaround) exist across (Mac) Chrome, FF, and Safari
159
191
line . attr ( 'd' , pathStart + ( showGradientLine ? 'l30,0.0001' : 'h30' ) )
160
192
. call ( showLine ? Drawing . lineGroupStyle : lineGradient ) ;
161
-
162
- function fillGradient ( s ) {
163
- if ( s . size ( ) ) {
164
- var gradientID = 'legendfill-' + trace . uid ;
165
- Drawing . gradient ( s , gd , gradientID , 'horizontalreversed' ,
166
- trace . colorscale , 'fill' ) ;
167
- }
168
- }
169
-
170
- function lineGradient ( s ) {
171
- if ( s . size ( ) ) {
172
- var gradientID = 'legendline-' + trace . uid ;
173
- Drawing . lineGroupStyle ( s ) ;
174
- Drawing . gradient ( s , gd , gradientID , 'horizontalreversed' ,
175
- trace . colorscale , 'stroke' ) ;
176
- }
177
- }
178
193
}
179
194
180
195
function stylePoints ( d ) {
@@ -278,7 +293,7 @@ module.exports = function style(s, gd) {
278
293
var trace = d [ 0 ] . trace ;
279
294
280
295
var ptsData = [ ] ;
281
- if ( trace . type === 'waterfall' && trace . visible ) {
296
+ if ( trace . visible && trace . type === 'waterfall' ) {
282
297
ptsData = d [ 0 ] . hasTotals ?
283
298
[ [ 'increasing' , 'M-6,-6V6H0Z' ] , [ 'totals' , 'M6,6H0L-6,-6H-0Z' ] , [ 'decreasing' , 'M6,6V-6H0Z' ] ] :
284
299
[ [ 'increasing' , 'M-6,-6V6H6Z' ] , [ 'decreasing' , 'M6,6V-6H-6Z' ] ] ;
@@ -321,7 +336,7 @@ module.exports = function style(s, gd) {
321
336
var markerLine = marker . line || { } ;
322
337
323
338
var isVisible = ( ! desiredType ) ? Registry . traceIs ( trace , 'bar' ) :
324
- ( trace . type === desiredType && trace . visible ) ;
339
+ ( trace . visible && trace . type === desiredType ) ;
325
340
326
341
var barpath = d3 . select ( lThis ) . select ( 'g.legendpoints' )
327
342
. selectAll ( 'path.legend' + desiredType )
@@ -348,7 +363,7 @@ module.exports = function style(s, gd) {
348
363
349
364
var pts = d3 . select ( this ) . select ( 'g.legendpoints' )
350
365
. selectAll ( 'path.legendbox' )
351
- . data ( Registry . traceIs ( trace , 'box-violin' ) && trace . visible ? [ d ] : [ ] ) ;
366
+ . data ( trace . visible && Registry . traceIs ( trace , 'box-violin' ) ? [ d ] : [ ] ) ;
352
367
pts . enter ( ) . append ( 'path' ) . classed ( 'legendbox' , true )
353
368
// if we want the median bar, prepend M6,0H-6
354
369
. attr ( 'd' , 'M6,6H-6V-6H6Z' )
@@ -386,7 +401,7 @@ module.exports = function style(s, gd) {
386
401
387
402
var pts = d3 . select ( this ) . select ( 'g.legendpoints' )
388
403
. selectAll ( 'path.legendcandle' )
389
- . data ( trace . type === 'candlestick' && trace . visible ? [ d , d ] : [ ] ) ;
404
+ . data ( trace . visible && trace . type === 'candlestick' ? [ d , d ] : [ ] ) ;
390
405
pts . enter ( ) . append ( 'path' ) . classed ( 'legendcandle' , true )
391
406
. attr ( 'd' , function ( _ , i ) {
392
407
if ( i ) return 'M-15,0H-8M-8,6V-6H8Z' ; // increasing
@@ -413,7 +428,7 @@ module.exports = function style(s, gd) {
413
428
414
429
var pts = d3 . select ( this ) . select ( 'g.legendpoints' )
415
430
. selectAll ( 'path.legendohlc' )
416
- . data ( trace . type === 'ohlc' && trace . visible ? [ d , d ] : [ ] ) ;
431
+ . data ( trace . visible && trace . type === 'ohlc' ? [ d , d ] : [ ] ) ;
417
432
pts . enter ( ) . append ( 'path' ) . classed ( 'legendohlc' , true )
418
433
. attr ( 'd' , function ( _ , i ) {
419
434
if ( i ) return 'M-15,0H0M-8,-6V0' ; // increasing
@@ -448,7 +463,7 @@ module.exports = function style(s, gd) {
448
463
var trace = d0 . trace ;
449
464
450
465
var isVisible = ( ! desiredType ) ? Registry . traceIs ( trace , desiredType ) :
451
- ( trace . type === desiredType && trace . visible ) ;
466
+ ( trace . visible && trace . type === desiredType ) ;
452
467
453
468
var pts = d3 . select ( lThis ) . select ( 'g.legendpoints' )
454
469
. selectAll ( 'path.legend' + desiredType )
@@ -472,3 +487,7 @@ module.exports = function style(s, gd) {
472
487
}
473
488
}
474
489
} ;
490
+
491
+ function getGradientDirection ( reversescale ) {
492
+ return reversescale ? 'horizontal' : 'horizontalreversed' ;
493
+ }
0 commit comments