@@ -19,13 +19,10 @@ var FIND_TEX = /([^$]*)([$]+[^$]*[$]+)([^$]*)/;
19
19
20
20
/**
21
21
* Converts to <tspan /> SVG element.
22
- * @param {* } _context Context
23
- * @param {* } gd Graph DIV
24
- * @param {* } options All props are needed to wrap.
25
- * [axisLength]?: number
26
- * [orientation]?: 'v' | 'h'
27
- * [wrap]?: boolean
28
- * @param {Function } _callback Callback function.
22
+ * @param {* } _context
23
+ * @param {* } gd `graphDiv`.
24
+ * @param {{ axisLength: number, axisOrientation: 'v' | 'h', wrap?: boolean } } options
25
+ * @param {Function } _callback
29
26
* @returns Modified `_context`.
30
27
*/
31
28
exports . convertToTspans = function ( _context , gd , options , _callback ) {
@@ -440,7 +437,7 @@ function fromCodePoint(code) {
440
437
}
441
438
442
439
/**
443
- * Converts SVG `<tspan />` elements from pseudo-html into, and attach these to `containerNode`.
440
+ * Converts our pseudo-html SVG `<tspan />` into elements , and attach these to `containerNode`.
444
441
*
445
442
* @param {svg text element } containerNode: the <text> node to insert this text into
446
443
* @param {string } str: the pseudo-html string to convert to svg
@@ -456,7 +453,6 @@ function buildSVGText(containerNode, str, options) {
456
453
* I feel like at some point we turned these into <br> but currently we don't so
457
454
* I'm just going to cement what we do now in Chrome and FF
458
455
*/
459
- str = options && options . axisOrientation === 'v' ? 'One very long string that is soo long, that<br>I dont get it!' : str ;
460
456
str = str . replace ( NEWLINES , ' ' ) ;
461
457
462
458
var hasLink = false ;
@@ -574,8 +570,7 @@ function buildSVGText(containerNode, str, options) {
574
570
}
575
571
576
572
var parts = str . split ( SPLIT_TAGS ) ;
577
- // eslint-disable-next-line no-console
578
- // options && options.axisOrientation === 'v' && console.log(parts);
573
+
579
574
var i = 0 ;
580
575
for ( i ; i < parts . length ; i ++ ) {
581
576
var parti = parts [ i ] ;
@@ -586,31 +581,22 @@ function buildSVGText(containerNode, str, options) {
586
581
if ( tagType === 'br' ) {
587
582
newLine ( ) ;
588
583
} else if ( tagStyle === undefined ) {
589
- // addTextNode(currentNode, convertEntities(parti));
590
-
591
- if ( options && options . axisOrientation === 'v' ) {
592
- if ( options . wrap ) {
593
- var wordId = 0 ;
594
- var wordsArray = parti . split ( ' ' ) ;
595
- for ( wordId ; wordId < wordsArray . length ; wordId ++ ) {
596
- var word = wordsArray [ wordId ] ;
597
- var preSpace = wordId === 0 ? '' : ' ' ;
598
- var child = addTextNode ( currentNode , convertEntities ( preSpace + word ) ) ;
599
- if ( currentNode . getBBox ( ) . width > options . axisLength ) {
600
- removeTextNode ( currentNode , child ) ;
601
- newLine ( ) ;
602
- addTextNode ( currentNode , convertEntities ( word ) ) ;
603
- }
604
- // eslint-disable-next-line no-console
605
- // console.log(currentNode.getBBox().width);
606
- }
584
+ if ( ! ( options && options . wrap ) ) return void ( addTextNode ( currentNode , convertEntities ( parti ) ) ) ;
607
585
608
- // eslint-disable-next-line no-console
609
- // options && options.axisOrientation === 'v' && console.log(currentNode.getBoundingClientRect().height);
610
- // eslint-disable-next-line no-console
611
- // options && options.axisOrientation === 'v' && console.log(currentNode.getBBox().width);
612
- } else {
613
- addTextNode ( currentNode , convertEntities ( parti ) ) ;
586
+ var wordId = 0 ;
587
+ var wordsArray = parti . split ( ' ' ) ;
588
+
589
+ newLine ( ) ;
590
+
591
+ for ( wordId ; wordId < wordsArray . length ; wordId ++ ) {
592
+ var word = wordsArray [ wordId ] ;
593
+ var preSpace = wordId === 0 ? '' : ' ' ;
594
+ var child = addTextNode ( currentNode , convertEntities ( preSpace + word ) ) ;
595
+
596
+ if ( currentNode . getBBox ( ) . width > options . axisLength ) {
597
+ removeTextNode ( currentNode , child ) ;
598
+ newLine ( ) ;
599
+ addTextNode ( currentNode , convertEntities ( word ) ) ;
614
600
}
615
601
}
616
602
} else {
0 commit comments