1
1
'use strict' ;
2
2
3
3
// ---external global dependencies
4
- /* global d3:false, MathJax:false
5
- Promise:false */
4
+ /* global d3:false, MathJax:false, Promise:false */
6
5
7
6
var util = module . exports = { } ,
8
7
Plotly = require ( './plotly' ) ;
@@ -139,15 +138,13 @@ util.jsHook = function(_el){
139
138
// text converter
140
139
/////////////////////////////
141
140
142
- util . getSize = function ( _selection , _dimension ) {
141
+ function getSize ( _selection , _dimension ) {
143
142
return _selection . node ( ) . getBoundingClientRect ( ) [ _dimension ] ;
144
- } ;
145
-
146
-
143
+ }
147
144
148
145
util . convertToTspans = function ( _context , _callback ) {
149
146
var str = _context . text ( ) ;
150
- var converted = Plotly . util . convertToSvg ( str ) ;
147
+ var converted = convertToSVG ( str ) ;
151
148
var that = _context ;
152
149
// Until we get tex integrated more fully (so it can be used along with non-tex)
153
150
// allow some elements to prohibit it by attaching 'data-notex' to the original
@@ -193,7 +190,8 @@ util.convertToTspans = function(_context, _callback){
193
190
( ( td && td . _promises ) || [ ] ) . push ( new Promise ( function ( resolve ) {
194
191
that . style ( { visibility : 'hidden' } ) ;
195
192
var config = { fontSize : parseInt ( that . style ( 'font-size' ) , 10 ) } ;
196
- Plotly . util . texToSVG ( tex [ 2 ] , config , function ( _svgEl , _glyphDefs , _svgBBox ) {
193
+
194
+ texToSVG ( tex [ 2 ] , config , function ( _svgEl , _glyphDefs , _svgBBox ) {
197
195
parent . selectAll ( 'svg.' + svgClass ) . remove ( ) ;
198
196
parent . selectAll ( 'g.' + svgClass + '-group' ) . remove ( ) ;
199
197
@@ -225,13 +223,13 @@ util.convertToTspans = function(_context, _callback){
225
223
var fill = that . style ( 'fill' ) || 'black' ;
226
224
newSvg . select ( 'g' ) . attr ( { fill : fill , stroke : fill } ) ;
227
225
228
- var newSvgW = Plotly . util . getSize ( newSvg , 'width' ) ,
229
- newSvgH = Plotly . util . getSize ( newSvg , 'height' ) ,
226
+ var newSvgW = getSize ( newSvg , 'width' ) ,
227
+ newSvgH = getSize ( newSvg , 'height' ) ,
230
228
newX = + that . attr ( 'x' ) - newSvgW *
231
229
{ start :0 , middle :0.5 , end :1 } [ that . attr ( 'text-anchor' ) || 'start' ] ,
232
230
// font baseline is about 1/4 fontSize below centerline
233
231
textHeight = parseInt ( that . style ( 'font-size' ) , 10 ) ||
234
- Plotly . util . getSize ( that , 'height' ) ,
232
+ getSize ( that , 'height' ) ,
235
233
dy = - textHeight / 4 ;
236
234
237
235
if ( svgClass [ 0 ] === 'y' ) {
@@ -270,7 +268,7 @@ function cleanEscapesForTex(s) {
270
268
. replace ( / ( > | & g t ; | & # 6 2 ; ) / g, '\\gt ' ) ;
271
269
}
272
270
273
- util . texToSVG = function ( _texString , _config , _callback ) {
271
+ function texToSVG ( _texString , _config , _callback ) {
274
272
var randomID = 'math-output-' + Plotly . Lib . randstr ( [ ] , 64 ) ;
275
273
var tmpDiv = d3 . select ( 'body' ) . append ( 'div' )
276
274
. attr ( { id : randomID } )
@@ -292,7 +290,7 @@ util.texToSVG = function(_texString, _config, _callback){
292
290
293
291
tmpDiv . remove ( ) ;
294
292
} ) ;
295
- } ;
293
+ }
296
294
297
295
var TAG_STYLES = {
298
296
// would like to use baseline-shift but FF doesn't support it yet
@@ -316,7 +314,7 @@ util.plainText = function(_str){
316
314
return ( _str || '' ) . replace ( STRIP_TAGS , ' ' ) ;
317
315
} ;
318
316
319
- util . convertToSvg = function ( _str ) {
317
+ function convertToSVG ( _str ) {
320
318
var htmlEntitiesDecoded = Plotly . util . html_entity_decode ( _str ) ;
321
319
var result = htmlEntitiesDecoded
322
320
. split ( / ( < [ ^ < > ] * > ) / ) . map ( function ( d ) {
@@ -410,10 +408,9 @@ util.convertToSvg = function(_str){
410
408
}
411
409
412
410
return result . join ( '' ) ;
413
- } ;
414
-
411
+ }
415
412
416
- util . alignHTMLWith = function ( _base , container , options ) {
413
+ function alignHTMLWith ( _base , container , options ) {
417
414
var alignH = options . horizontalAlign ,
418
415
alignV = options . verticalAlign || 'top' ,
419
416
bRect = _base . node ( ) . getBoundingClientRect ( ) ,
@@ -447,7 +444,7 @@ util.alignHTMLWith = function (_base, container, options){
447
444
} ) ;
448
445
return this ;
449
446
} ;
450
- } ;
447
+ }
451
448
452
449
// Editable title
453
450
/////////////////////////////
@@ -504,7 +501,7 @@ util.makeEditable = function(context, _delegate, options){
504
501
} )
505
502
. attr ( { contenteditable : true } )
506
503
. text ( options . text || that . attr ( 'data-unformatted' ) )
507
- . call ( util . alignHTMLWith ( that , container , options ) )
504
+ . call ( alignHTMLWith ( that , container , options ) )
508
505
. on ( 'blur' , function ( ) {
509
506
that . text ( this . textContent )
510
507
. style ( { opacity : 1 } ) ;
@@ -538,7 +535,7 @@ util.makeEditable = function(context, _delegate, options){
538
535
}
539
536
else {
540
537
dispatch . input . call ( that , this . textContent ) ;
541
- d3 . select ( this ) . call ( util . alignHTMLWith ( that , container , options ) ) ;
538
+ d3 . select ( this ) . call ( alignHTMLWith ( that , container , options ) ) ;
542
539
}
543
540
} )
544
541
. on ( 'keydown' , function ( ) {
0 commit comments