@@ -20,6 +20,8 @@ var subTypes = require('../../traces/scatter/subtypes');
20
20
var stylePie = require ( '../../traces/pie/style_one' ) ;
21
21
var pieCastOption = require ( '../../traces/pie/helpers' ) . castOption ;
22
22
23
+ var constants = require ( './constants' ) ;
24
+
23
25
var CST_MARKER_SIZE = 12 ;
24
26
var CST_LINE_WIDTH = 5 ;
25
27
var CST_MARKER_LINE_WIDTH = 2 ;
@@ -30,6 +32,8 @@ module.exports = function style(s, gd, legend) {
30
32
var fullLayout = gd . _fullLayout ;
31
33
if ( ! legend ) legend = fullLayout . legend ;
32
34
var constantItemSizing = legend . itemsizing === 'constant' ;
35
+ var itemWidth = legend . itemwidth ;
36
+ var centerPos = ( itemWidth + constants . itemGap * 2 ) / 2 ;
33
37
34
38
var boundLineWidth = function ( mlw , cont , max , cst ) {
35
39
var v ;
@@ -161,7 +165,7 @@ module.exports = function style(s, gd, legend) {
161
165
. data ( showFill || showGradientFill ? [ d ] : [ ] ) ;
162
166
fill . enter ( ) . append ( 'path' ) . classed ( 'js-fill' , true ) ;
163
167
fill . exit ( ) . remove ( ) ;
164
- fill . attr ( 'd' , pathStart + 'h30v6h-30z ' )
168
+ fill . attr ( 'd' , pathStart + 'h' + itemWidth + 'v6h-' + itemWidth + 'z ')
165
169
. call ( showFill ? Drawing . fillGroupStyle : fillGradient ) ;
166
170
167
171
if ( showLine || showGradientLine ) {
@@ -181,7 +185,7 @@ module.exports = function style(s, gd, legend) {
181
185
// though there *is* no vertical variation in this case.
182
186
// so add an invisibly small angle to the line
183
187
// This issue (and workaround) exist across (Mac) Chrome, FF, and Safari
184
- line . attr ( 'd' , pathStart + ( showGradientLine ? 'l30 ,0.0001' : 'h30' ) )
188
+ line . attr ( 'd' , pathStart + ( showGradientLine ? 'l' + itemWidth + ' ,0.0001' : 'h' + itemWidth ) )
185
189
. call ( showLine ? Drawing . lineGroupStyle : lineGradient ) ;
186
190
}
187
191
@@ -271,7 +275,7 @@ module.exports = function style(s, gd, legend) {
271
275
// make sure marker is on the bottom, in case it enters after text
272
276
pts . enter ( ) . insert ( 'path' , ':first-child' )
273
277
. classed ( 'scatterpts' , true )
274
- . attr ( 'transform' , 'translate(20 ,0)' ) ;
278
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)') ;
275
279
pts . exit ( ) . remove ( ) ;
276
280
pts . call ( Drawing . pointStyle , tMod , gd ) ;
277
281
@@ -283,7 +287,7 @@ module.exports = function style(s, gd, legend) {
283
287
. data ( showText ? dMod : [ ] ) ;
284
288
txt . enter ( )
285
289
. append ( 'g' ) . classed ( 'pointtext' , true )
286
- . append ( 'text' ) . attr ( 'transform' , 'translate(20 ,0)' ) ;
290
+ . append ( 'text' ) . attr ( 'transform' , 'translate(' + centerPos + ' ,0)') ;
287
291
txt . exit ( ) . remove ( ) ;
288
292
txt . selectAll ( 'text' ) . call ( Drawing . textPointStyle , tMod , gd ) ;
289
293
}
@@ -311,7 +315,7 @@ module.exports = function style(s, gd, legend) {
311
315
. selectAll ( 'path.legendwaterfall' )
312
316
. data ( ptsData ) ;
313
317
pts . enter ( ) . append ( 'path' ) . classed ( 'legendwaterfall' , true )
314
- . attr ( 'transform' , 'translate(20 ,0)' )
318
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)')
315
319
. style ( 'stroke-miterlimit' , 1 ) ;
316
320
pts . exit ( ) . remove ( ) ;
317
321
@@ -351,7 +355,7 @@ module.exports = function style(s, gd, legend) {
351
355
. data ( isVisible ? [ d ] : [ ] ) ;
352
356
barpath . enter ( ) . append ( 'path' ) . classed ( 'legend' + desiredType , true )
353
357
. attr ( 'd' , 'M6,6H-6V-6H6Z' )
354
- . attr ( 'transform' , 'translate(20 ,0)' ) ;
358
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)') ;
355
359
barpath . exit ( ) . remove ( ) ;
356
360
357
361
barpath . each ( function ( d ) {
@@ -375,7 +379,7 @@ module.exports = function style(s, gd, legend) {
375
379
pts . enter ( ) . append ( 'path' ) . classed ( 'legendbox' , true )
376
380
// if we want the median bar, prepend M6,0H-6
377
381
. attr ( 'd' , 'M6,6H-6V-6H6Z' )
378
- . attr ( 'transform' , 'translate(20 ,0)' ) ;
382
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)') ;
379
383
pts . exit ( ) . remove ( ) ;
380
384
381
385
pts . each ( function ( ) {
@@ -415,7 +419,7 @@ module.exports = function style(s, gd, legend) {
415
419
if ( i ) return 'M-15,0H-8M-8,6V-6H8Z' ; // increasing
416
420
return 'M15,0H8M8,-6V6H-8Z' ; // decreasing
417
421
} )
418
- . attr ( 'transform' , 'translate(20 ,0)' )
422
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)')
419
423
. style ( 'stroke-miterlimit' , 1 ) ;
420
424
pts . exit ( ) . remove ( ) ;
421
425
@@ -442,7 +446,7 @@ module.exports = function style(s, gd, legend) {
442
446
if ( i ) return 'M-15,0H0M-8,-6V0' ; // increasing
443
447
return 'M15,0H0M8,6V0' ; // decreasing
444
448
} )
445
- . attr ( 'transform' , 'translate(20 ,0)' )
449
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)')
446
450
. style ( 'stroke-miterlimit' , 1 ) ;
447
451
pts . exit ( ) . remove ( ) ;
448
452
@@ -478,7 +482,7 @@ module.exports = function style(s, gd, legend) {
478
482
. data ( isVisible ? [ d ] : [ ] ) ;
479
483
pts . enter ( ) . append ( 'path' ) . classed ( 'legend' + desiredType , true )
480
484
. attr ( 'd' , 'M6,6H-6V-6H6Z' )
481
- . attr ( 'transform' , 'translate(20 ,0)' ) ;
485
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)') ;
482
486
pts . exit ( ) . remove ( ) ;
483
487
484
488
if ( pts . size ( ) ) {
@@ -576,7 +580,7 @@ module.exports = function style(s, gd, legend) {
576
580
. selectAll ( 'path.legend3dandfriends' )
577
581
. data ( ptsData ) ;
578
582
pts . enter ( ) . append ( 'path' ) . classed ( 'legend3dandfriends' , true )
579
- . attr ( 'transform' , 'translate(20 ,0)' )
583
+ . attr ( 'transform' , 'translate(' + centerPos + ' ,0)')
580
584
. style ( 'stroke-miterlimit' , 1 ) ;
581
585
pts . exit ( ) . remove ( ) ;
582
586
0 commit comments