@@ -155,7 +155,13 @@ proto.createButton = function(config) {
155
155
button . setAttribute ( 'data-toggle' , config . toggle || false ) ;
156
156
if ( config . toggle ) d3 . select ( button ) . classed ( 'active' , true ) ;
157
157
158
- button . appendChild ( this . createIcon ( config . icon || Icons . question , config . name ) ) ;
158
+ var icon = config . icon ;
159
+ if ( typeof icon === 'function' ) {
160
+ button . appendChild ( icon ( ) ) ;
161
+ }
162
+ else {
163
+ button . appendChild ( this . createIcon ( icon || Icons . question , config . name ) ) ;
164
+ }
159
165
button . setAttribute ( 'data-gravity' , config . gravity || 'n' ) ;
160
166
161
167
return button ;
@@ -169,7 +175,9 @@ proto.createButton = function(config) {
169
175
* @Return {HTMLelement}
170
176
*/
171
177
proto . createIcon = function ( thisIcon , name ) {
172
- var iconHeight = thisIcon . ascent - thisIcon . descent ,
178
+ var iconHeight = thisIcon . height !== undefined ?
179
+ thisIcon . height :
180
+ thisIcon . ascent - thisIcon . descent ,
173
181
svgNS = 'http://www.w3.org/2000/svg' ,
174
182
icon = document . createElementNS ( svgNS , 'svg' ) ,
175
183
path = document . createElementNS ( svgNS , 'path' ) ;
@@ -178,12 +186,19 @@ proto.createIcon = function(thisIcon, name) {
178
186
icon . setAttribute ( 'width' , ( thisIcon . width / iconHeight ) + 'em' ) ;
179
187
icon . setAttribute ( 'viewBox' , [ 0 , 0 , thisIcon . width , iconHeight ] . join ( ' ' ) ) ;
180
188
181
- var transform = name === 'toggleSpikelines' ?
182
- 'matrix(1.5 0 0 -1.5 0 ' + thisIcon . ascent + ')' :
183
- 'matrix(1 0 0 -1 0 ' + thisIcon . ascent + ')' ;
184
-
185
189
path . setAttribute ( 'd' , thisIcon . path ) ;
186
- path . setAttribute ( 'transform' , transform ) ;
190
+
191
+ if ( thisIcon . transform ) {
192
+ path . setAttribute ( 'transform' , thisIcon . transform ) ;
193
+ }
194
+ else if ( thisIcon . ascent ) {
195
+ // Legacy icon transform calculation
196
+ var transform = name === 'toggleSpikelines' ?
197
+ 'matrix(1.5 0 0 -1.5 0 ' + thisIcon . ascent + ')' :
198
+ 'matrix(1 0 0 -1 0 ' + thisIcon . ascent + ')' ;
199
+ path . setAttribute ( 'transform' , transform ) ;
200
+ }
201
+
187
202
icon . appendChild ( path ) ;
188
203
189
204
return icon ;
0 commit comments