10000 Minor vars renaming / Comments update / code cleaning · plotly/plotly.js@e00d528 · GitHub
[go: up one dir, main page]

Skip to content

Commit e00d528

Browse files
committed
Minor vars renaming / Comments update / code cleaning
1 parent 66f50aa commit e00d528

File tree

3 files changed

+28
-45
lines changed

3 files changed

+28
-45
lines changed

src/components/titles/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function draw(gd, titleClass, options) {
5656
var attributes = options.attributes;
5757
var transform = options.transform;
5858
var group = options.containerGroup;
59-
var isAxis = options.isAxis; // Prepare documentation for this
59+
var isAxis = options.isAxis;
6060
var wrap = options.wrap;
6161

6262
var fullLayout = gd._fullLayout;
@@ -137,13 +137,13 @@ function draw(gd, titleClass, options) {
137137
}
138138

139139
if(isAxis && wrap) {
140-
var axName = options.propContainer._name;
141-
var axOut = gd._fullLayout[axName];
140+
var axisName = options.propContainer._name;
141+
var axis = gd._fullLayout[axisName];
142142

143143
convertOptions = {
144144
wrap: wrap,
145-
axisLength: axOut._length,
146-
axisOrientation: axOut._id.substr(0, 1) === 'y' ? 'v' : 'h'
145+
axisLength: axis._length,
146+
axisOrientation: axis._id.substr(0, 1) === 'y' ? 'v' : 'h'
147147
};
148148
}
149149

src/lib/svg_text_utils.js

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ var FIND_TEX = /([^$]*)([$]+[^$]*[$]+)([^$]*)/;
1919

2020
/**
2121
* 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
2926
* @returns Modified `_context`.
3027
*/
3128
exports.convertToTspans = function(_context, gd, options, _callback) {
@@ -440,7 +437,7 @@ function fromCodePoint(code) {
440437
}
441438

442439
/**
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`.
444441
*
445442
* @param {svg text element} containerNode: the <text> node to insert this text into
446443
* @param {string} str: the pseudo-html string to convert to svg
@@ -456,7 +453,6 @@ function buildSVGText(containerNode, str, options) {
456453
* I feel like at some point we turned these into <br> but currently we don't so
457454
* I'm just going to cement what we do now in Chrome and FF
458455
*/
459-
str = options && options.axisOrientation === 'v' ? 'One very long string that is soo long, that<br>I dont get it!' : str;
460456
str = str.replace(NEWLINES, ' ');
461457

462458
var hasLink = false;
@@ -574,8 +570,7 @@ function buildSVGText(containerNode, str, options) {
574570
}
575571

576572
var parts = str.split(SPLIT_TAGS);
577-
// eslint-disable-next-line no-console
578-
// options && options.axisOrientation === 'v' && console.log(parts);
573+
579574
var i = 0;
580575
for(i; i < parts.length; i++) {
581576
var parti = parts[i];
@@ -586,31 +581,22 @@ function buildSVGText(containerNode, str, options) {
586581
if(tagType === 'br') {
587582
newLine();
588583
} 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)));
607585

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));
614600
}
615601
}
616602
} else {

src/plots/cartesian/axes.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,7 @@ function drawTitle(gd, ax) {
34643464
var axId = ax._id;
34653465
var axLetter = axId.charAt(0);
34663466
var fontSize = ax.title.font.size;
3467-
// var wrap = ax.title.wrap; // TODO: Update documentation and the TypeScript types.
3467+
var wrap = ax.title.wrap; // TODO: Update our API documentation and the TypeScript types!.
34683468

34693469
var titleStandoff;
34703470

@@ -3539,11 +3539,8 @@ function drawTitle(gd, ax) {
35393539
avoid: avoid,
35403540
transform: transform,
35413541
attributes: {x: x, y: y, 'text-anchor': 'middle'},
3542+
wrap: wrap,
35423543
isAxis: true,
3543-
// wrap: wrap
3544-
// HEY! This is for testing only!
3545-
wrap: 'breakword',
3546-
// TODO: options: 'breakword' | 'breakchar' | undefined (default)
35473544
});
35483545
}
35493546

0 commit comments

Comments
 (0)
0