@@ -14,7 +14,7 @@ var isNumeric = require('fast-isnumeric');
1414
1515var Lib = require ( '../../lib' ) ;
1616var Icons = require ( '../../../build/ploticon' ) ;
17-
17+ var Parser = new DOMParser ( ) ;
1818
1919/**
2020 * UI controller for interactive plots
@@ -45,13 +45,29 @@ var proto = ModeBar.prototype;
4545proto . update = function ( graphInfo , buttons ) {
4646 this . graphInfo = graphInfo ;
4747
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 ;
4954
5055 if ( context . displayModeBar === 'hover' ) {
5156 this . element . className = 'modebar modebar--hover' ;
5257 }
5358 else this . element . className = 'modebar' ;
5459
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+
5571 // if buttons or logo have changed, redraw modebar interior
5672 var needsNewButtons = ! this . hasButtons ( buttons ) ;
5773 var needsNewLogo = ( this . hasLogo !== context . displaylogo ) ;
@@ -65,7 +81,12 @@ proto.update = function(graphInfo, buttons) {
6581 this . updateButtons ( buttons ) ;
6682
6783 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+
6990 this . hasLogo = true ;
7091 }
7192 }
@@ -173,31 +194,42 @@ proto.createButton = function(config) {
173194 * @Param {object} thisIcon
174195 * @Param {number} thisIcon.width
175196 * @Param {string} thisIcon.path
197+ * @Param {string} thisIcon.color
176198 * @Return {HTMLelement}
177199 */
178200proto . createIcon = function ( thisIcon ) {
179201 var iconHeight = isNumeric ( thisIcon . height ) ?
180202 Number ( thisIcon . height ) :
181203 thisIcon . ascent - thisIcon . descent ,
182204 svgNS = 'http://www.w3.org/2000/svg' ,
183- icon = document . createElementNS ( svgNS , 'svg' ) ,
184- path = document . createElementNS ( svgNS , 'path' ) ;
205+ icon ;
185206
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 ) ;
189214
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+ }
191222
192- if ( thisIcon . transform ) {
193- path . setAttribute ( 'transform' , thisIcon . transform ) ;
223+ icon . appendChild ( path ) ;
194224 }
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 ] ;
198229 }
199230
200- icon . appendChild ( path ) ;
231+ icon . setAttribute ( 'height' , '1em' ) ;
232+ icon . setAttribute ( 'width' , '1em' ) ;
201233
202234 return icon ;
203235} ;
@@ -272,7 +304,7 @@ proto.getLogo = function() {
272304 a . setAttribute ( 'data-title' , Lib . _ ( this . graphInfo , 'Produced with Plotly' ) ) ;
273305 a . className = 'modebar-btn plotlyjsicon modebar-btn--logo' ;
274306
275- a . appendChild ( this . createIcon ( Icons . plotlylogo ) ) ;
307+ a . appendChild ( this . createIcon ( Icons . newplotlylogo ) ) ;
276308
277309 group . appendChild ( a ) ;
278310 return group ;
@@ -288,6 +320,7 @@ proto.removeAllButtons = function() {
288320
289321proto . destroy = function ( ) {
290322 Lib . removeElement ( this . container . querySelector ( '.modebar' ) ) ;
323+ Lib . deleteRelatedStyleRule ( this . _uid ) ;
291324} ;
292325
293326function createModeBar ( gd , buttons ) {
0 commit comments