@@ -45,8 +45,12 @@ var proto = ModeBar.prototype;
45
45
proto . update = function ( graphInfo , buttons ) {
46
46
this . graphInfo = graphInfo ;
47
47
48
- var context = this . graphInfo . _context ;
49
- var fullLayout = this . graphInfo . _fullLayout ;
48
+ var context = this . graphInfo . _context ,
49
+ fullLayout = this . graphInfo . _fullLayout ,
50
+ modeBarId = 'modebar-' + fullLayout . _uid ;
51
+
52
+ this . element . setAttribute ( 'id' , modeBarId ) ;
53
+ this . _uid = modeBarId ;
50
54
51
55
if ( context . displayModeBar === 'hover' ) {
52
56
this . element . className = 'modebar modebar--hover' ;
@@ -57,7 +61,11 @@ proto.update = function(graphInfo, buttons) {
57
61
this . element . className += ' vertical' ;
58
62
buttons = buttons . reverse ( ) ;
59
63
}
60
- this . element . style . backgroundColor = fullLayout . modeBarStyle . bgcolor ;
64
+
65
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId , 'background-color: ' + fullLayout . modeBarStyle . bgcolor ) ;
66
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId + ' .modebar-btn .icon path' , 'fill: ' + fullLayout . modeBarStyle . iconColor ) ;
67
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId + ' .modebar-btn:hover .icon path' , 'fill: ' + fullLayout . modeBarStyle . activeIconColor ) ;
68
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId + ' .modebar-btn.active .icon path' , 'fill: ' + fullLayout . modeBarStyle . activeIconColor ) ;
61
69
62
70
// if buttons or logo have changed, redraw modebar interior
63
71
var needsNewButtons = ! this . hasButtons ( buttons ) ;
@@ -69,7 +77,7 @@ proto.update = function(graphInfo, buttons) {
69
77
if ( needsNewButtons || needsNewLogo || needsNewLocale ) {
70
78
this . removeAllButtons ( ) ;
71
79
72
- this . updateButtons ( buttons , fullLayout . modeBarStyle . iconColor ) ;
80
+ this . updateButtons ( buttons ) ;
73
81
74
82
if ( context . displaylogo ) {
75
83
if ( fullLayout . modeBarStyle . orientation === 'v' ) {
@@ -85,7 +93,7 @@ proto.update = function(graphInfo, buttons) {
85
93
this . updateActiveButton ( ) ;
86
94
} ;
87
95
88
- proto . updateButtons = function ( buttons , iconColor ) {
96
+ proto . updateButtons = function ( buttons ) {
89
97
var _this = this ;
90
98
91
99
this . buttons = buttons ;
@@ -105,7 +113,6 @@ proto.updateButtons = function(buttons, iconColor) {
105
113
}
106
114
_this . buttonsNames . push ( buttonName ) ;
107
115
108
- buttonConfig . color = iconColor ;
109
116
var button = _this . createButton ( buttonConfig ) ;
110
117
_this . buttonElements . push ( button ) ;
111
118
group . appendChild ( button ) ;
@@ -174,7 +181,6 @@ proto.createButton = function(config) {
174
181
button . appendChild ( icon ( ) ) ;
175
182
}
176
183
else {
177
- if ( icon ) icon . color = config . color ;
178
184
button . appendChild ( this . createIcon ( icon || Icons . question ) ) ;
179
185
}
180
186
button . setAttribute ( 'data-gravity' , config . gravity || 'n' ) ;
@@ -200,6 +206,7 @@ proto.createIcon = function(thisIcon) {
200
206
if ( thisIcon . path ) {
201
207
icon = document . createElementNS ( svgNS , 'svg' ) ;
202
208
icon . setAttribute ( 'viewBox' , [ 0 , 0 , thisIcon . width , iconHeight ] . join ( ' ' ) ) ;
209
+ icon . setAttribute ( 'class' , 'icon' ) ;
203
210
204
211
var path = document . createElementNS ( svgNS , 'path' ) ;
205
212
path . setAttribute ( 'd' , thisIcon . path ) ;
@@ -212,10 +219,6 @@ proto.createIcon = function(thisIcon) {
212
219
path . setAttribute ( 'transform' , 'matrix(1 0 0 -1 0 ' + thisIcon . ascent + ')' ) ;
213
220
}
214
221
215
- if ( thisIcon . color ) {
216
- path . setAttribute ( 'fill' , thisIcon . color ) ;
217
- }
218
-
219
222
icon . appendChild ( path ) ;
220
223
}
221
224
@@ -316,6 +319,7 @@ proto.removeAllButtons = function() {
316
319
317
320
proto . destroy = function ( ) {
318
321
Lib . removeElement ( this . container . querySelector ( '.modebar' ) ) ;
322
+ Lib . deleteRelatedStyleRule ( this . _uid ) ;
319
323
} ;
320
324
321
325
function createModeBar ( gd , buttons ) {
0 commit comments