@@ -17,16 +17,38 @@ var Color = require('../color');
17
17
18
18
var subTypes = require ( '../../traces/scatter/subtypes' ) ;
19
19
var stylePie = require ( '../../traces/pie/style_one' ) ;
20
+ var pieCastOption = require ( '../../traces/pie/helpers' ) . castOption ;
21
+
22
+ var CST_MARKER_SIZE = 12 ;
23
+ var CST_LINE_WIDTH = 5 ;
24
+ var CST_MARKER_LINE_WIDTH = 2 ;
25
+ var MAX_LINE_WIDTH = 10 ;
26
+ var MAX_MARKER_LINE_WIDTH = 5 ;
20
27
21
28
module . exports = function style ( s , gd ) {
29
+ var fullLayout = gd . _fullLayout ;
30
+ var legend = fullLayout . legend ;
31
+ var constantItemSizing = legend . itemsizing === 'constant' ;
32
+
33
+ function boundLineWidth ( mlw , cont , max , cst ) {
34
+ var v ;
35
+ if ( mlw + 1 ) {
36
+ v = mlw ;
37
+ } else if ( cont && cont . width > 0 ) {
38
+ v = cont . width ;
39
+ } else {
40
+ return 0 ;
41
+ }
42
+ return constantItemSizing ? cst : Math . min ( v , max ) ;
43
+ }
44
+
22
45
s . each ( function ( d ) {
23
46
var traceGroup = d3 . select ( this ) ;
24
47
25
48
var layers = Lib . ensureSingle ( traceGroup , 'g' , 'layers' ) ;
26
49
layers . style ( 'opacity' , d [ 0 ] . trace . opacity ) ;
27
50
28
- // Marker vertical alignment
29
- var valign = gd . _fullLayout . legend . valign ;
51
+ var valign = legend . valign ;
30
52
var lineHeight = d [ 0 ] . lineHeight ;
31
53
var height = d [ 0 ] . height ;
32
54
@@ -71,28 +93,27 @@ module.exports = function style(s, gd) {
71
93
. each ( styleOHLC ) ;
72
94
73
95
function styleLines ( d ) {
74
- var trace = d [ 0 ] . trace ;
96
+ var d0 = d [ 0 ] ;
97
+ var trace = d0 . trace ;
75
98
var showFill = trace . visible && trace . fill && trace . fill !== 'none' ;
76
99
var showLine = subTypes . hasLines ( trace ) ;
77
100
var contours = trace . contours ;
78
101
var showGradientLine = false ;
79
102
var showGradientFill = false ;
103
+ var dMod , tMod ;
80
104
81
105
if ( contours ) {
82
106
var coloring = contours . coloring ;
83
107
84
108
if ( coloring === 'lines' ) {
85
109
showGradientLine = true ;
86
- }
87
- else {
88
- showLine = coloring === 'none' || coloring === 'heatmap' ||
89
- contours . showlines ;
110
+ } else {
111
+ showLine = coloring === 'none' || coloring === 'heatmap' || contours . showlines ;
90
112
}
91
113
92
114
if ( contours . type === 'constraint' ) {
93
115
showFill = contours . _operation !== '=' ;
94
- }
95
- else if ( coloring === 'fill' || coloring === 'heatmap' ) {
116
+ } else if ( coloring === 'fill' || coloring === 'heatmap' ) {
96
117
showGradientFill = true ;
97
118
}
98
119
}
@@ -116,8 +137,14 @@ module.exports = function style(s, gd) {
116
137
fill . attr ( 'd' , pathStart + 'h30v6h-30z' )
117
138
. call ( showFill ? Drawing . fillGroupStyle : fillGradient ) ;
118
139
140
+ if ( showLine || showGradientLine ) {
141
+ var lw = boundLineWidth ( undefined , trace . line , MAX_LINE_WIDTH , CST_LINE_WIDTH ) ;
142
+ tMod = Lib . minExtend ( trace , { line : { width : lw } } ) ;
143
+ dMod = [ Lib . minExtend ( d0 , { trace : tMod } ) ] ;
144
+ }
145
+
119
146
var line = this3 . select ( '.legendlines' ) . selectAll ( 'path' )
120
- . data ( showLine || showGradientLine ? [ d ] : [ ] ) ;
147
+ . data ( showLine || showGradientLine ? [ dMod ] : [ ] ) ;
121
148
line . enter ( ) . append ( 'path' ) . classed ( 'js-line' , true ) ;
122
149
line . exit ( ) . remove ( ) ;
123
150
@@ -159,12 +186,16 @@ module.exports = function style(s, gd) {
159
186
// 'scatter3d' don't use gd.calcdata,
160
187
// use d0.trace to infer arrayOk attributes
161
188
162
- function boundVal ( attrIn , arrayToValFn , bounds ) {
189
+ function boundVal ( attrIn , arrayToValFn , bounds , cst ) {
163
190
var valIn = Lib . nestedProperty ( trace , attrIn ) . get ( ) ;
164
191
var valToBound = ( Lib . isArrayOrTypedArray ( valIn ) && arrayToValFn ) ?
165
192
arrayToValFn ( valIn ) :
166
193
valIn ;
167
194
195
+ if ( constantItemSizing && valToBound && cst !== undefined ) {
196
+ valToBound = cst ;
197
+ }
198
+
168
199
if ( bounds ) {
169
200
if ( valToBound < bounds [ 0 ] ) return bounds [ 0 ] ;
170
201
else if ( valToBound > bounds [ 1 ] ) return bounds [ 1 ] ;
@@ -184,21 +215,21 @@ module.exports = function style(s, gd) {
184
215
dEdit . mx = boundVal ( 'marker.symbol' , pickFirst ) ;
185
216
dEdit . mo = boundVal ( 'marker.opacity' , Lib . mean , [ 0.2 , 1 ] ) ;
186
217
dEdit . mlc = boundVal ( 'marker.line.color' , pickFirst ) ;
187
- dEdit . mlw = boundVal ( 'marker.line.width' , Lib . mean , [ 0 , 5 ] ) ;
218
+ dEdit . mlw = boundVal ( 'marker.line.width' , Lib . mean , [ 0 , 5 ] , CST_MARKER_LINE_WIDTH ) ;
188
219
tEdit . marker = {
189
220
sizeref : 1 ,
190
221
sizemin : 1 ,
191
222
sizemode : 'diameter'
192
223
} ;
193
224
194
- var ms = boundVal ( 'marker.size' , Lib . mean , [ 2 , 16 ] ) ;
225
+ var ms = boundVal ( 'marker.size' , Lib . mean , [ 2 , 16 ] , CST_MARKER_SIZE ) ;
195
226
dEdit . ms = ms ;
196
227
tEdit . marker . size = ms ;
197
228
}
198
229
199
230
if ( showLines ) {
200
231
tEdit . line = {
201
- width : boundVal ( 'line.width' , pickFirst , [ 0 , 10 ] )
232
+ width : boundVal ( 'line.width' , pickFirst , [ 0 , 10 ] , CST_LINE_WIDTH )
202
233
} ;
203
234
}
204
235
@@ -262,12 +293,13 @@ module.exports = function style(s, gd) {
262
293
pts . each ( function ( dd ) {
263
294
var pt = d3 . select ( this ) ;
264
295
var cont = trace [ dd [ 0 ] ] . marker ;
296
+ var lw = boundLineWidth ( undefined , cont . line , MAX_MARKER_LINE_WIDTH , CST_MARKER_LINE_WIDTH ) ;
265
297
266
298
pt . attr ( 'd' , dd [ 1 ] )
267
- . style ( 'stroke-width' , cont . line . width + 'px' )
299
+ . style ( 'stroke-width' , lw + 'px' )
268
300
. call ( Color . fill , cont . color ) ;
269
301
270
- if ( cont . line . width ) {
302
+ if ( lw ) {
271
303
pt . call ( Color . stroke , cont . line . color ) ;
272
304
}
273
305
} ) ;
@@ -289,14 +321,12 @@ module.exports = function style(s, gd) {
289
321
barpath . each ( function ( d ) {
290
322
var p = d3 . select ( this ) ;
291
323
var d0 = d [ 0 ] ;
292
- var w = ( d0 . mlw + 1 || markerLine . width + 1 ) - 1 ;
324
+ var w = boundLineWidth ( d0 . mlw , marker . line , MAX_MARKER_LINE_WIDTH , CST_MARKER_LINE_WIDTH ) ;
293
325
294
326
p . style ( 'stroke-width' , w + 'px' )
295
327
. call ( Color . fill , d0 . mc || marker . color ) ;
296
328
297
- if ( w ) {
298
- p . call ( Color . stroke , d0 . mlc || markerLine . color ) ;
299
- }
329
+ if ( w ) Color . stroke ( p , d0 . mlc || markerLine . color ) ;
300
330
} ) ;
301
331
}
302
332
@@ -313,15 +343,13 @@ module.exports = function style(s, gd) {
313
343
pts . exit ( ) . remove ( ) ;
314
344
315
345
pts . each ( function ( ) {
316
- var w = trace . line . width ;
317
346
var p = d3 . select ( this ) ;
347
+ var w = boundLineWidth ( undefined , trace . line , MAX_MARKER_LINE_WIDTH , CST_MARKER_LINE_WIDTH ) ;
318
348
319
349
p . style ( 'stroke-width' , w + 'px' )
320
350
. call ( Color . fill , trace . fillcolor ) ;
321
351
322
- if ( w ) {
323
- Color . stroke ( p , trace . line . color ) ;
324
- }
352
+ if ( w ) Color . stroke ( p , trace . line . color ) ;
325
353
} ) ;
326
354
}
327
355
@@ -341,16 +369,14 @@ module.exports = function style(s, gd) {
341
369
pts . exit ( ) . remove ( ) ;
342
370
343
371
pts . each ( function ( _ , i ) {
344
- var container = trace [ i ? 'increasing' : 'decreasing' ] ;
345
- var w = container . line . width ;
346
372
var p = d3 . select ( this ) ;
373
+ var cont = trace [ i ? 'increasing' : 'decreasing' ] ;
374
+ var w = boundLineWidth ( undefined , cont . line , MAX_MARKER_LINE_WIDTH , CST_MARKER_LINE_WIDTH ) ;
347
375
348
376
p . style ( 'stroke-width' , w + 'px' )
349
- . call ( Color . fill , container . fillcolor ) ;
377
+ . call ( Color . fill , cont . fillcolor ) ;
350
378
351
- if ( w ) {
352
- Color . stroke ( p , container . line . color ) ;
353
- }
379
+ if ( w ) Color . stroke ( p , cont . line . color ) ;
354
380
} ) ;
355
381
}
356
382
@@ -370,21 +396,20 @@ module.exports = function style(s, gd) {
370
396
pts . exit ( ) . remove ( ) ;
371
397
372
398
pts . each ( function ( _ , i ) {
373
- var container = trace [ i ? 'increasing' : 'decreasing' ] ;
374
- var w = container . line . width ;
375
399
var p = d3 . select ( this ) ;
400
+ var cont = trace [ i ? 'increasing' : 'decreasing' ] ;
401
+ var w = boundLineWidth ( undefined , cont . line , MAX_MARKER_LINE_WIDTH , CST_MARKER_LINE_WIDTH ) ;
376
402
377
403
p . style ( 'fill' , 'none' )
378
- . call ( Drawing . dashLine , container . line . dash , w ) ;
404
+ . call ( Drawing . dashLine , cont . line . dash , w ) ;
379
405
380
- if ( w ) {
381
- Color . stroke ( p , container . line . color ) ;
382
- }
406
+ if ( w ) Color . stroke ( p , cont . line . color ) ;
383
407
} ) ;
384
408
}
385
409
386
410
function stylePies ( d ) {
387
- var trace = d [ 0 ] . trace ;
411
+ var d0 = d [ 0 ] ;
412
+ var trace = d0 . trace ;
388
413
389
414
var pts = d3 . select ( this ) . select ( 'g.legendpoints' )
390
415
. selectAll ( 'path.legendpie' )
@@ -394,6 +419,12 @@ module.exports = function style(s, gd) {
394
419
. attr ( 'transform' , 'translate(20,0)' ) ;
395
420
pts . exit ( ) . remove ( ) ;
396
421
397
- if ( pts . size ( ) ) pts . call ( stylePie , d [ 0 ] , trace ) ;
422
+ if ( pts . size ( ) ) {
423
+ var cont = ( trace . marker || { } ) . line ;
424
+ var lw = boundLineWidth ( pieCastOption ( cont . width , d0 . pts ) , cont , MAX_MARKER_LINE_WIDTH , CST_MARKER_LINE_WIDTH ) ;
425
+ var tMod = Lib . minExtend ( trace , { marker : { line : { width : lw } } } ) ;
426
+ var d0Mod = Lib . minExtend ( d0 , { trace : tMod } ) ;
427
+ stylePie ( pts , d0Mod , tMod ) ;
428
+ }
398
429
}
399
430
} ;
0 commit comments