Skip to content

Commit 058da08

Browse files
committed
Linting/formatting
1 parent 8965c3d commit 058da08

2 files changed

Lines changed: 444 additions & 396 deletions

File tree

src/snapshot/tosvg.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ var DUMMY_SUB = 'TOBESTRIPPED';
1212
var DUMMY_REGEX = new RegExp('("' + DUMMY_SUB + ')|(' + DUMMY_SUB + '")', 'g');
1313

1414
function htmlEntityDecode(s) {
15-
var hiddenDiv = d3.select('body').append('div').style({display: 'none'}).html('');
16-
var replaced = s.replace(/(&[^;]*;)/gi, function(d) {
17-
if(d === '<') { return '<'; } // special handling for brackets
18-
if(d === '&rt;') { return '>'; }
19-
if(d.indexOf('<') !== -1 || d.indexOf('>') !== -1) { return ''; }
15+
var hiddenDiv = d3.select('body').append('div').style({ display: 'none' }).html('');
16+
var replaced = s.replace(/(&[^;]*;)/gi, function (d) {
17+
if (d === '&lt;') {
18+
return '&#60;';
19+
} // special handling for brackets
20+
if (d === '&rt;') {
21+
return '&#62;';
22+
}
23+
if (d.indexOf('<') !== -1 || d.indexOf('>') !== -1) {
24+
return '';
25+
}
2026
return hiddenDiv.html(d).text(); // everything else, let the browser decode it to unicode
2127
});
2228
hiddenDiv.remove();
@@ -48,29 +54,29 @@ module.exports = function toSVG(gd, format, scale) {
4854
// which notably add the contents of the gl-container
4955
// into the main svg node
5056
var basePlotModules = fullLayout._basePlotModules || [];
51-
for(i = 0; i < basePlotModules.length; i++) {
57+
for (i = 0; i < basePlotModules.length; i++) {
5258
var _module = basePlotModules[i];
5359

54-
if(_module.toSVG) _module.toSVG(gd);
60+
if (_module.toSVG) _module.toSVG(gd);
5561
}
5662

5763
// add top items above them assumes everything in toppaper is either
5864
// a group or a defs, and if it's empty (like hoverlayer) we can ignore it.
59-
if(toppaper) {
65+
if (toppaper) {
6066
var nodes = toppaper.node().childNodes;
6167

6268
// make copy of nodes as childNodes prop gets mutated in loop below
6369
var topGroups = Array.prototype.slice.call(nodes);
6470

65-
for(i = 0; i < topGroups.length; i++) {
71+
for (i = 0; i < topGroups.length; i++) {
6672
var topGroup = topGroups[i];
6773

68-
if(topGroup.childNodes.length) svg.node().appendChild(topGroup);
74+
if (topGroup.childNodes.length) svg.node().appendChild(topGroup);
6975
}
7076
}
7177

7278
// remove draglayer for Adobe Illustrator compatibility
73-
if(fullLayout._draggers) {
79+
if (fullLayout._draggers) {
7480
fullLayout._draggers.remove();
7581
}
7682

@@ -80,70 +86,70 @@ module.exports = function toSVG(gd, format, scale) {
8086
svg.node().style.background = '';
8187

8288
svg.selectAll('text')
83-
.attr({'data-unformatted': null, 'data-math': null})
84-
.each(function() {
89+
.attr({ 'data-unformatted': null, 'data-math': null })
90+
.each(function () {
8591
var txt = d3.select(this);
8692

8793
// hidden text is pre-formatting mathjax, the browser ignores it
8894
// but in a static plot it's useless and it can confuse batik
8995
// we've tried to standardize on display:none but make sure we still
9096
// catch visibility:hidden if it ever arises
91-
if(this.style.visibility === 'hidden' || this.style.display === 'none') {
97+
if (this.style.visibility === 'hidden' || this.style.display === 'none') {
9298
txt.remove();
9399
return;
94100
} else {
95101
// clear other visibility/display values to default
96102
// to not potentially confuse non-browser SVG implementations
97-
txt.style({visibility: null, display: null});
103+
txt.style({ visibility: null, display: null });
98104
}
99105

100106
// Font family styles break things because of quotation marks,
101107
// so we must remove them *after* the SVG DOM has been serialized
102108
// to a string (browsers convert singles back)
103109
var ff = this.style.fontFamily;
104-
if(ff && ff.indexOf('"') !== -1) {
110+
if (ff && ff.indexOf('"') !== -1) {
105111
txt.style('font-family', ff.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
106112
}
107113

108114
// Drop normal font-weight, font-style and font-variant to reduce the size
109115
var fw = this.style.fontWeight;
110-
if(fw && (fw === 'normal' || fw === '400')) { // font-weight 400 is similar to normal
116+
if (fw && (fw === 'normal' || fw === '400')) {
117+
// font-weight 400 is similar to normal
111118
txt.style('font-weight', undefined);
112119
}
113120
var fs = this.style.fontStyle;
114-
if(fs && fs === 'normal') {
121+
if (fs && fs === 'normal') {
115122
txt.style('font-style', undefined);
116123
}
117124
var fv = this.style.fontVariant;
118-
if(fv && fv === 'normal') {
125+
if (fv && fv === 'normal') {
119126
txt.style('font-variant', undefined);
120127
}
121128
});
122129

123-
svg.selectAll('.gradient_filled,.pattern_filled').each(function() {
130+
svg.selectAll('.gradient_filled,.pattern_filled').each(function () {
124131
var pt = d3.select(this);
125132

126133
// similar to font family styles above,
127134
// we must remove " after the SVG DOM has been serialized
128135
var fill = this.style.fill;
129-
if(fill && fill.indexOf('url(') !== -1) {
136+
if (fill && fill.indexOf('url(') !== -1) {
130137
pt.style('fill', fill.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
131138
}
132139

133140
var stroke = this.style.stroke;
134-
if(stroke && stroke.indexOf('url(') !== -1) {
141+
if (stroke && stroke.indexOf('url(') !== -1) {
135142
pt.style('stroke', stroke.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
136143
}
137144
});
138145

139-
if(format === 'pdf' || format === 'eps') {
146+
if (format === 'pdf' || format === 'eps') {
140147
// these formats make the extra line MathJax adds around symbols look super thick in some cases
141148
// it looks better if this is removed entirely.
142-
svg.selectAll('#MathJax_SVG_glyphs path')
143-
.attr('stroke-width', 0);
149+
svg.selectAll('#MathJax_SVG_glyphs path').attr('stroke-width', 0);
144150
}
145151

146-
if(format === 'svg' && scale) {
152+
if (format === 'svg' && scale) {
147153
svg.attr('width', scale * width);
148154
svg.attr('height', scale * height);
149155
svg.attr('viewBox', '0 0 ' + width + ' ' + height);
@@ -154,7 +160,7 @@ module.exports = function toSVG(gd, format, scale) {
154160
s = xmlEntityEncode(s);
155161

156162
// Fix quotations around font strings and gradient URLs
157-
s = s.replace(DUMMY_REGEX, '\'');
163+
s = s.replace(DUMMY_REGEX, "'");
158164

159165
return s;
160166
};

0 commit comments

Comments
 (0)