@@ -20,6 +20,8 @@ var subTypes = require('../../traces/scatter/subtypes');
2020var stylePie = require ( '../../traces/pie/style_one' ) ;
2121var pieCastOption = require ( '../../traces/pie/helpers' ) . castOption ;
2222
23+ var constants = require ( './constants' ) ;
24+
2325var CST_MARKER_SIZE = 12 ;
2426var CST_LINE_WIDTH = 5 ;
2527var CST_MARKER_LINE_WIDTH = 2 ;
@@ -30,6 +32,9 @@ module.exports = function style(s, gd, legend) {
3032 var fullLayout = gd . _fullLayout ;
3133 if ( ! legend ) legend = fullLayout . legend ;
3234 var constantItemSizing = legend . itemsizing === 'constant' ;
35+ var itemWidth = legend . itemwidth ;
36+ var centerPos = ( itemWidth + constants . itemGap * 2 ) / 2 ;
37+ var centerTransform = 'translate(' + centerPos + ',0)' ;
3338
3439 var boundLineWidth = function ( mlw , cont , max , cst ) {
3540 var v ;
@@ -161,7 +166,7 @@ module.exports = function style(s, gd, legend) {
161166 . data ( showFill || showGradientFill ? [ d ] : [ ] ) ;
162167 fill . enter ( ) . append ( 'path' ) . classed ( 'js-fill' , true ) ;
163168 fill . exit ( ) . remove ( ) ;
164- fill . attr ( 'd' , pathStart + 'h30v6h-30z ' )
169+ fill . attr ( 'd' , pathStart + 'h' + itemWidth + 'v6h-' + itemWidth + 'z ')
165170 . call ( showFill ? Drawing . fillGroupStyle : fillGradient ) ;
166171
167172 if ( showLine || showGradientLine ) {
@@ -181,7 +186,7 @@ module.exports = function style(s, gd, legend) {
181186 // though there *is* no vertical variation in this case.
182187 // so add an invisibly small angle to the line
183188 // This issue (and workaround) exist across (Mac) Chrome, FF, and Safari
184- line . attr ( 'd' , pathStart + ( showGradientLine ? 'l30 ,0.0001' : 'h30' ) )
189+ line . attr ( 'd' , pathStart + ( showGradientLine ? 'l' + itemWidth + ' ,0.0001' : 'h' + itemWidth ) )
185190 . call ( showLine ? Drawing . lineGroupStyle : lineGradient ) ;
186191 }
187192
@@ -271,7 +276,7 @@ module.exports = function style(s, gd, legend) {
271276 // make sure marker is on the bottom, in case it enters after text
272277 pts . enter ( ) . insert ( 'path' , ':first-child' )
273278 . classed ( 'scatterpts' , true )
274- . attr ( 'transform' , 'translate(20,0)' ) ;
279+ . attr ( 'transform' , centerTransform ) ;
275280 pts . exit ( ) . remove ( ) ;
276281 pts . call ( Drawing . pointStyle , tMod , gd ) ;
277282
@@ -283,7 +288,7 @@ module.exports = function style(s, gd, legend) {
283288 . data ( showText ? dMod : [ ] ) ;
284289 txt . enter ( )
285290 . append ( 'g' ) . classed ( 'pointtext' , true )
286- . append ( 'text' ) . attr ( 'transform' , 'translate(20,0)' ) ;
291+ . append ( 'text' ) . attr ( 'transform' , centerTransform ) ;
287292 txt . exit ( ) . remove ( ) ;
288293 txt . selectAll ( 'text' ) . call ( Drawing . textPointStyle , tMod , gd ) ;
289294 }
@@ -311,7 +316,7 @@ module.exports = function style(s, gd, legend) {
311316 . selectAll ( 'path.legendwaterfall' )
312317 . data ( ptsData ) ;
313318 pts . enter ( ) . append ( 'path' ) . classed ( 'legendwaterfall' , true )
314- . attr ( 'transform' , 'translate(20,0)' )
319+ . attr ( 'transform' , centerTransform )
315320 . style ( 'stroke-miterlimit' , 1 ) ;
316321 pts . exit ( ) . remove ( ) ;
317322
@@ -351,7 +356,7 @@ module.exports = function style(s, gd, legend) {
351356 . data ( isVisible ? [ d ] : [ ] ) ;
352357 barpath . enter ( ) . append ( 'path' ) . classed ( 'legend' + desiredType , true )
353358 . attr ( 'd' , 'M6,6H-6V-6H6Z' )
354- . attr ( 'transform' , 'translate(20,0)' ) ;
359+ . attr ( 'transform' , centerTransform ) ;
355360 barpath . exit ( ) . remove ( ) ;
356361
357362 barpath . each ( function ( d ) {
@@ -375,7 +380,7 @@ module.exports = function style(s, gd, legend) {
375380 pts . enter ( ) . append ( 'path' ) . classed ( 'legendbox' , true )
376381 // if we want the median bar, prepend M6,0H-6
377382 . attr ( 'd' , 'M6,6H-6V-6H6Z' )
378- . attr ( 'transform' , 'translate(20,0)' ) ;
383+ . attr ( 'transform' , centerTransform ) ;
379384 pts . exit ( ) . remove ( ) ;
380385
381386 pts . each ( function ( ) {
@@ -415,7 +420,7 @@ module.exports = function style(s, gd, legend) {
415420 if ( i ) return 'M-15,0H-8M-8,6V-6H8Z' ; // increasing
416421 return 'M15,0H8M8,-6V6H-8Z' ; // decreasing
417422 } )
418- . attr ( 'transform' , 'translate(20,0)' )
423+ . attr ( 'transform' , centerTransform )
419424 . style ( 'stroke-miterlimit' , 1 ) ;
420425 pts . exit ( ) . remove ( ) ;
421426
@@ -442,7 +447,7 @@ module.exports = function style(s, gd, legend) {
442447 if ( i ) return 'M-15,0H0M-8,-6V0' ; // increasing
443448 return 'M15,0H0M8,6V0' ; // decreasing
444449 } )
445- . attr ( 'transform' , 'translate(20,0)' )
450+ . attr ( 'transform' , centerTransform )
446451 . style ( 'stroke-miterlimit' , 1 ) ;
447452 pts . exit ( ) . remove ( ) ;
448453
@@ -478,7 +483,7 @@ module.exports = function style(s, gd, legend) {
478483 . data ( isVisible ? [ d ] : [ ] ) ;
479484 pts . enter ( ) . append ( 'path' ) . classed ( 'legend' + desiredType , true )
480485 . attr ( 'd' , 'M6,6H-6V-6H6Z' )
481- . attr ( 'transform' , 'translate(20,0)' ) ;
486+ . attr ( 'transform' , centerTransform ) ;
482487 pts . exit ( ) . remove ( ) ;
483488
484489 if ( pts . size ( ) ) {
@@ -576,7 +581,7 @@ module.exports = function style(s, gd, legend) {
576581 . selectAll ( 'path.legend3dandfriends' )
577582 . data ( ptsData ) ;
578583 pts . enter ( ) . append ( 'path' ) . classed ( 'legend3dandfriends' , true )
579- . attr ( 'transform' , 'translate(20,0)' )
584+ . attr ( 'transform' , centerTransform )
580585 . style ( 'stroke-miterlimit' , 1 ) ;
581586 pts . exit ( ) . remove ( ) ;
582587
0 commit comments