@@ -14,7 +14,7 @@ var isNumeric = require('fast-isnumeric');
14
14
15
15
var Lib = require ( '../../lib' ) ;
16
16
var Icons = require ( '../../../build/ploticon' ) ;
17
-
17
+ var Parser = new DOMParser ( ) ;
18
18
19
19
/**
20
20
* UI controller for interactive plots
@@ -45,13 +45,29 @@ var proto = ModeBar.prototype;
45
45
proto . update = function ( graphInfo , buttons ) {
46
46
this . graphInfo = graphInfo ;
47
47
48
- var context = this . graphInfo . _context ;
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 ;
49
54
50
55
if ( context . displayModeBar === 'hover' ) {
51
56
this . element . className = 'modebar modebar--hover' ;
52
57
}
53
58
else this . element . className = 'modebar' ;
54
59
60
+ if ( fullLayout . modebar . orientation === 'v' ) {
61
+ this . element . className += ' vertical' ;
62
+ buttons = buttons . reverse ( ) ;
63
+ }
64
+
65
+ Lib . deleteRelatedStyleRule ( modeBarId ) ;
66
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId , 'background-color: ' + fullLayout . modebar . bgcolor ) ;
67
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId + ' .modebar-btn .icon path' , 'fill: ' + fullLayout . modebar . color ) ;
68
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId + ' .modebar-btn:hover .icon path' , 'fill: ' + fullLayout . modebar . activecolor ) ;
69
+ Lib . addRelatedStyleRule ( modeBarId , '#' + modeBarId + ' .modebar-btn.active .icon path' , 'fill: ' + fullLayout . modebar . activecolor ) ;
70
+
55
71
// if buttons or logo have changed, redraw modebar interior
56
72
var needsNewButtons = ! this . hasButtons ( buttons ) ;
57
73
var needsNewLogo = ( this . hasLogo !== context . displaylogo ) ;
@@ -65,7 +81,12 @@ proto.update = function(graphInfo, buttons) {
65
81
this . updateButtons ( buttons ) ;
66
82
67
83
if ( context . displaylogo ) {
68
- this . element . appendChild ( this . getLogo ( ) ) ;
84
+ if ( fullLayout . modebar . orientation === 'v' ) {
85
+ this . element . prepend ( this . getLogo ( ) ) ;
86
+ } else {
87
+ this . element . appendChild ( this . getLogo ( ) ) ;
88
+ }
89
+
69
90
this . hasLogo = true ;
70
91
}
71
92
}
@@ -173,31 +194,42 @@ proto.createButton = function(config) {
173
194
* @Param {object} thisIcon
174
195
* @Param {number} thisIcon.width
175
196
* @Param {string} thisIcon.path
197
+ * @Param {string} thisIcon.color
176
198
* @Return {HTMLelement}
177
199
*/
178
200
proto . createIcon = function ( thisIcon ) {
179
201
var iconHeight = isNumeric ( thisIcon . height ) ?
180
202
Number ( thisIcon . height ) :
181
203
thisIcon . ascent - thisIcon . descent ,
182
204
svgNS = 'http://www.w3.org/2000/svg' ,
183
- icon = document . createElementNS ( svgNS , 'svg' ) ,
184
- path = document . createElementNS ( svgNS , 'path' ) ;
205
+ icon ;
185
206
186
- icon . setAttribute ( 'height' , '1em' ) ;
187
- icon . setAttribute ( 'width' , ( thisIcon . width / iconHeight ) + 'em' ) ;
188
- icon . setAttribute ( 'viewBox' , [ 0 , 0 , thisIcon . width , iconHeight ] . join ( ' ' ) ) ;
207
+ if ( thisIcon . path ) {
208
+ icon = document . createElementNS ( svgNS , 'svg' ) ;
209
+ icon . setAttribute ( 'viewBox' , [ 0 , 0 , thisIcon . width , iconHeight ] . join ( ' ' ) ) ;
210
+ icon . setAttribute ( 'class' , 'icon' ) ;
211
+
212
+ var path = document . createElementNS ( svgNS , 'path' ) ;
213
+ path . setAttribute ( 'd' , thisIcon . path ) ;
189
214
190
- path . setAttribute ( 'd' , thisIcon . path ) ;
215
+ if ( thisIcon . transform ) {
216
+ path . setAttribute ( 'transform' , thisIcon . transform ) ;
217
+ }
218
+ else if ( thisIcon . ascent !== undefined ) {
219
+ // Legacy icon transform calculation
220
+ path . setAttribute ( 'transform' , 'matrix(1 0 0 -1 0 ' + thisIcon . ascent + ')' ) ;
221
+ }
191
222
192
- if ( thisIcon . transform ) {
193
- path . setAttribute ( 'transform' , thisIcon . transform ) ;
223
+ icon . appendChild ( path ) ;
194
224
}
195
- else if ( thisIcon . ascent !== undefined ) {
196
- // Legacy icon transform calculation
197
- path . setAttribute ( 'transform' , 'matrix(1 0 0 -1 0 ' + thisIcon . ascent + ')' ) ;
225
+
226
+ if ( thisIcon . svg ) {
227
+ var svgDoc = Parser . parseFromString ( thisIcon . svg , 'application/xml' ) ;
228
+ icon = svgDoc . childNodes [ 0 ] ;
198
229
}
199
230
200
- icon . appendChild ( path ) ;
231
+ icon . setAttribute ( 'height' , '1em' ) ;
232
+ icon . setAttribute ( 'width' , '1em' ) ;
201
233
202
234
return icon ;
203
235
} ;
@@ -272,7 +304,7 @@ proto.getLogo = function() {
272
304
a . setAttribute ( 'data-title' , Lib . _ ( this . graphInfo , 'Produced with Plotly' ) ) ;
273
305
a . className = 'modebar-btn plotlyjsicon modebar-btn--logo' ;
274
306
275
- a . appendChild ( this . createIcon ( Icons . plotlylogo ) ) ;
307
+ a . appendChild ( this . createIcon ( Icons . newplotlylogo ) ) ;
276
308
277
309
group . appendChild ( a ) ;
278
310
return group ;
@@ -288,6 +320,7 @@ proto.removeAllButtons = function() {
288
320
289
321
proto . destroy = function ( ) {
290
322
Lib . removeElement ( this . container . querySelector ( '.modebar' ) ) ;
323
+ Lib . deleteRelatedStyleRule ( this . _uid ) ;
291
324
} ;
292
325
293
326
function createModeBar ( gd , buttons ) {
0 commit comments