@@ -26,6 +26,7 @@ var Polar = require('../plots/polar/legacy');
2626var Axes = require ( '../plots/cartesian/axes' ) ;
2727var Drawing = require ( '../components/drawing' ) ;
2828var Color = require ( '../components/color' ) ;
29+ var connectColorbar = require ( '../components/colorbar/connect' ) ;
2930var initInteractions = require ( '../plots/cartesian/graph_interact' ) . initInteractions ;
3031var xmlnsNamespaces = require ( '../constants/xmlns_namespaces' ) ;
3132var svgTextUtils = require ( '../lib/svg_text_utils' ) ;
@@ -265,10 +266,11 @@ exports.plot = function(gd, data, layout, config) {
265266 for ( i = 0 ; i < calcdata . length ; i ++ ) {
266267 cd = calcdata [ i ] ;
267268 trace = cd [ 0 ] . trace ;
268- if ( trace . visible !== true || ! trace . _module . colorbar ) {
269+ var colorbarOpts = trace . _module . colorbar ;
270+ if ( trace . visible !== true || ! colorbarOpts ) {
269271 Plots . autoMargin ( gd , 'cb' + trace . uid ) ;
270272 }
271- else trace . _module . colorbar ( gd , cd ) ;
273+ else connectColorbar ( gd , cd , colorbarOpts ) ;
272274 }
273275
274276 Plots . doAutoMargin ( gd ) ;
@@ -1448,6 +1450,11 @@ function _restyle(gd, aobj, traces) {
14481450
14491451 if ( newVal === undefined ) continue ;
14501452
1453+ var finalPart = param . parts [ param . parts . length - 1 ] ;
1454+ var prefix = ai . substr ( 0 , ai . length - finalPart . length - 1 ) ;
1455+ var prefixDot = prefix ? prefix + '.' : '' ;
1456+ var innerContFull = prefix ? Lib . nestedProperty ( contFull , prefix ) : contFull ;
1457+
14511458 valObject = PlotSchema . getTraceValObject ( contFull , param . parts ) ;
14521459
14531460 if ( valObject && valObject . impliedEdits && newVal !== null ) {
@@ -1461,31 +1468,30 @@ function _restyle(gd, aobj, traces) {
14611468 // note that colorbar fractional sizing is based on the
14621469 // original plot size, before anything (like a colorbar)
14631470 // increases the margins
1464- else if ( ai === 'colorbar.thicknessmode' && param . get ( ) !== newVal &&
1465- [ 'fraction' , 'pixels' ] . indexOf ( newVal ) !== - 1 &&
1466- contFull . colorbar ) {
1467- var thicknorm =
1468- [ 'top' , 'bottom' ] . indexOf ( contFull . colorbar . orient ) !== - 1 ?
1469- ( fullLayout . height - fullLayout . margin . t - fullLayout . margin . b ) :
1470- ( fullLayout . width - fullLayout . margin . l - fullLayout . margin . r ) ;
1471- doextra ( 'colorbar.thickness' , contFull . colorbar . thickness *
1472- ( newVal === 'fraction' ? 1 / thicknorm : thicknorm ) , i ) ;
1473- }
1474- else if ( ai === 'colorbar.lenmode' && param . get ( ) !== newVal &&
1475- [ 'fraction' , 'pixels' ] . indexOf ( newVal ) !== - 1 &&
1476- contFull . colorbar ) {
1477- var lennorm =
1478- [ 'top' , 'bottom' ] . indexOf ( contFull . colorbar . orient ) !== - 1 ?
1479- ( fullLayout . width - fullLayout . margin . l - fullLayout . margin . r ) :
1480- ( fullLayout . height - fullLayout . margin . t - fullLayout . margin . b ) ;
1481- doextra ( 'colorbar.len' , contFull . colorbar . len *
1482- ( newVal === 'fraction' ? 1 / lennorm : lennorm ) , i ) ;
1483- }
1484- else if ( ai === 'colorbar.tick0' || ai === 'colorbar.dtick' ) {
1485- doextra ( 'colorbar.tickmode' , 'linear' , i ) ;
1471+ else if ( ( finalPart === 'thicknessmode' || finalPart === 'lenmode' ) &&
1472+ oldVal !== newVal &&
1473+ ( newVal === 'fraction' || newVal === 'pixels' ) &&
1474+ innerContFull
1475+ ) {
1476+ if ( finalPart === 'thicknessmode' ) {
1477+ var thicknorm =
1478+ [ 'top' , 'bottom' ] . indexOf ( innerContFull . orient ) !== - 1 ?
1479+ ( fullLayout . height - fullLayout . margin . t - fullLayout . margin . b ) :
1480+ ( fullLayout . width - fullLayout . margin . l - fullLayout . margin . r ) ;
1481+ doextra ( prefixDot + 'thickness' , innerContFull . thickness *
1482+ ( newVal === 'fraction' ? 1 / thicknorm : thicknorm ) , i ) ;
1483+ }
1484+ else {
1485+ var lennorm =
1486+ [ 'top' , 'bottom' ] . indexOf ( innerContFull . orient ) !== - 1 ?
1487+ ( fullLayout . width - fullLayout . margin . l - fullLayout . margin . r ) :
1488+ ( fullLayout . height - fullLayout . margin . t - fullLayout . margin . b ) ;
1489+ doextra ( prefixDot + 'len' , innerContFull . len *
1490+ ( newVal === 'fraction' ? 1 / lennorm : lennorm ) , i ) ;
1491+ }
14861492 }
14871493
1488- if ( ai === 'type' && ( newVal === 'pie' ) !== ( oldVal === 'pie' ) ) {
1494+ else if ( ai === 'type' && ( newVal === 'pie' ) !== ( oldVal === 'pie' ) ) {
14891495 var labelsTo = 'x' ,
14901496 valuesTo = 'y' ;
14911497 if ( ( newVal === 'bar' || oldVal === 'bar' ) && cont . orientation === 'h' ) {
0 commit comments