@@ -14,6 +14,7 @@ var Registry = require('../../registry');
1414var Lib = require ( '../../lib' ) ;
1515var Drawing = require ( '../drawing' ) ;
1616var Color = require ( '../color' ) ;
17+ var extractOpts = require ( '../colorscale/helpers' ) . extractOpts ;
1718
1819var subTypes = require ( '../../traces/scatter/subtypes' ) ;
1920var stylePie = require ( '../../traces/pie/style_one' ) ;
@@ -30,7 +31,7 @@ module.exports = function style(s, gd) {
3031 var legend = fullLayout . legend ;
3132 var constantItemSizing = legend . itemsizing === 'constant' ;
3233
33- function boundLineWidth ( mlw , cont , max , cst ) {
34+ var boundLineWidth = function ( mlw , cont , max , cst ) {
3435 var v ;
3536 if ( mlw + 1 ) {
3637 v = mlw ;
@@ -40,7 +41,7 @@ module.exports = function style(s, gd) {
4041 return 0 ;
4142 }
4243 return constantItemSizing ? cst : Math . min ( v , max ) ;
43- }
44+ } ;
4445
4546 s . each ( function ( d ) {
4647 var traceGroup = d3 . select ( this ) ;
@@ -104,6 +105,29 @@ module.exports = function style(s, gd) {
104105 var showGradientFill = false ;
105106 var dMod , tMod ;
106107
108+ var cOpts = extractOpts ( trace ) ;
109+ var colorscale = cOpts . colorscale ;
110+ var reversescale = cOpts . reversescale ;
111+
112+ var fillGradient = function ( s ) {
113+ if ( s . size ( ) ) {
114+ var gradientID = 'legendfill-' + trace . uid ;
115+ Drawing . gradient ( s , gd , gradientID ,
116+ getGradientDirection ( reversescale ) ,
117+ colorscale , 'fill' ) ;
118+ }
119+ } ;
120+
121+ var lineGradient = function ( s ) {
122+ if ( s . size ( ) ) {
123+ var gradientID = 'legendline-' + trace . uid ;
124+ Drawing . lineGroupStyle ( s ) ;
125+ Drawing . gradient ( s , gd , gradientID ,
126+ getGradientDirection ( reversescale ) ,
127+ colorscale , 'stroke' ) ;
128+ }
129+ } ;
130+
107131 if ( contours ) {
108132 var coloring = contours . coloring ;
109133
@@ -158,23 +182,6 @@ module.exports = function style(s, gd) {
158182 // This issue (and workaround) exist across (Mac) Chrome, FF, and Safari
159183 line . attr ( 'd' , pathStart + ( showGradientLine ? 'l30,0.0001' : 'h30' ) )
160184 . 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- }
178185 }
179186
180187 function stylePoints ( d ) {
@@ -278,7 +285,7 @@ module.exports = function style(s, gd) {
278285 var trace = d [ 0 ] . trace ;
279286
280287 var ptsData = [ ] ;
281- if ( trace . type === 'waterfall' && trace . visible ) {
288+ if ( trace . visible && trace . type === 'waterfall' ) {
282289 ptsData = d [ 0 ] . hasTotals ?
283290 [ [ 'increasing' , 'M-6,-6V6H0Z' ] , [ 'totals' , 'M6,6H0L-6,-6H-0Z' ] , [ 'decreasing' , 'M6,6V-6H0Z' ] ] :
284291 [ [ 'increasing' , 'M-6,-6V6H6Z' ] , [ 'decreasing' , 'M6,6V-6H-6Z' ] ] ;
@@ -321,7 +328,7 @@ module.exports = function style(s, gd) {
321328 var markerLine = marker . line || { } ;
322329
323330 var isVisible = ( ! desiredType ) ? Registry . traceIs ( trace , 'bar' ) :
324- ( trace . type === desiredType && trace . visible ) ;
331+ ( trace . visible && trace . type === desiredType ) ;
325332
326333 var barpath = d3 . select ( lThis ) . select ( 'g.legendpoints' )
327334 . selectAll ( 'path.legend' + desiredType )
@@ -348,7 +355,7 @@ module.exports = function style(s, gd) {
348355
349356 var pts = d3 . select ( this ) . select ( 'g.legendpoints' )
350357 . selectAll ( 'path.legendbox' )
351- . data ( Registry . traceIs ( trace , 'box-violin' ) && trace . visible ? [ d ] : [ ] ) ;
358+ . data ( trace . visible && Registry . traceIs ( trace , 'box-violin' ) ? [ d ] : [ ] ) ;
352359 pts . enter ( ) . append ( 'path' ) . classed ( 'legendbox' , true )
353360 // if we want the median bar, prepend M6,0H-6
354361 . attr ( 'd' , 'M6,6H-6V-6H6Z' )
@@ -386,7 +393,7 @@ module.exports = function style(s, gd) {
386393
387394 var pts = d3 . select ( this ) . select ( 'g.legendpoints' )
388395 . selectAll ( 'path.legendcandle' )
389- . data ( trace . type === 'candlestick' && trace . visible ? [ d , d ] : [ ] ) ;
396+ . data ( trace . visible && trace . type === 'candlestick' ? [ d , d ] : [ ] ) ;
390397 pts . enter ( ) . append ( 'path' ) . classed ( 'legendcandle' , true )
391398 . attr ( 'd' , function ( _ , i ) {
392399 if ( i ) return 'M-15,0H-8M-8,6V-6H8Z' ; // increasing
@@ -413,7 +420,7 @@ module.exports = function style(s, gd) {
413420
414421 var pts = d3 . select ( this ) . select ( 'g.legendpoints' )
415422 . selectAll ( 'path.legendohlc' )
416- . data ( trace . type === 'ohlc' && trace . visible ? [ d , d ] : [ ] ) ;
423+ . data ( trace . visible && trace . type === 'ohlc' ? [ d , d ] : [ ] ) ;
417424 pts . enter ( ) . append ( 'path' ) . classed ( 'legendohlc' , true )
418425 . attr ( 'd' , function ( _ , i ) {
419426 if ( i ) return 'M-15,0H0M-8,-6V0' ; // increasing
@@ -448,7 +455,7 @@ module.exports = function style(s, gd) {
448455 var trace = d0 . trace ;
449456
450457 var isVisible = ( ! desiredType ) ? Registry . traceIs ( trace , desiredType ) :
451- ( trace . type === desiredType && trace . visible ) ;
458+ ( trace . visible && trace . type === desiredType ) ;
452459
453460 var pts = d3 . select ( lThis ) . select ( 'g.legendpoints' )
454461 . selectAll ( 'path.legend' + desiredType )
@@ -472,3 +479,7 @@ module.exports = function style(s, gd) {
472479 }
473480 }
474481} ;
482+
483+ function getGradientDirection ( reversescale ) {
484+ return reversescale ? 'horizontal' : 'horizontalreversed' ;
485+ }
0 commit comments