Skip to content

Commit cfeb3e1

Browse files
committed
use xmlns namespaces module instead of hard-coded the urls
1 parent 5b1bdc4 commit cfeb3e1

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

src/components/drawing/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var Plotly = require('../../plotly');
1313
var d3 = require('d3');
1414
var isNumeric = require('fast-isnumeric');
1515

16+
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1617
var subTypes = require('../../traces/scatter/subtypes');
1718
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
1819

@@ -449,12 +450,8 @@ drawing.makeTester = function(gd) {
449450
.data([0]);
450451

451452
tester.enter().append('svg')
452-
.attr({
453-
id: 'js-plotly-tester',
454-
xmlns: 'http://www.w3.org/2000/svg',
455-
// odd d3 quirk - need namespace twice??
456-
'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink'
457-
})
453+
.attr('id', 'js-plotly-tester')
454+
.attr(xmlnsNamespaces.svgAttrs)
458455
.style({
459456
position: 'absolute',
460457
left: '-10000px',

src/lib/svg_text_utils.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@
1414
var Plotly = require('../plotly');
1515
var d3 = require('d3');
1616

17+
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
18+
1719
var util = module.exports = {};
1820

1921
// Append SVG
2022

2123
d3.selection.prototype.appendSVG = function(_svgString) {
22-
var skeleton = '<svg xmlns="http://www.w3.org/2000/svg" ' +
23-
'xmlns:xlink="http://www.w3.org/1999/xlink">' +
24-
_svgString + '</svg>',
25-
dom = new DOMParser().parseFromString(skeleton, 'application/xml'),
24+
var skeleton = [
25+
'<svg xmlns="', xmlnsNamespaces.svg, '" ',
26+
'xmlns:xlink="', xmlnsNamespaces.xlink, '">',
27+
_svgString,
28+
'</svg>'
29+
].join('');
30+
31+
var dom = new DOMParser().parseFromString(skeleton, 'application/xml'),
2632
childNode = dom.documentElement.firstChild;
33+
2734
while(childNode) {
2835
this.node().appendChild(this.node().ownerDocument.importNode(childNode, true));
2936
childNode = childNode.nextSibling;

src/plot_api/plot_api.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var Legend = require('../components/legend');
2828
var Shapes = require('../components/shapes');
2929
var Titles = require('../components/titles');
3030
var manageModeBar = require('../components/modebar/manage');
31+
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
3132

3233

3334
/**
@@ -2567,11 +2568,7 @@ function makePlotFramework(gd) {
25672568
}
25682569

25692570
fullLayout._paperdiv.selectAll('.main-svg')
2570-
.attr({
2571-
xmlns: 'http://www.w3.org/2000/svg',
2572-
// odd d3 quirk - need namespace twice??
2573-
'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink'
2574-
});
2571+
.attr(xmlnsNamespaces.svgAttrs);
25752572

25762573
fullLayout._defs = fullLayout._paper.append('defs')
25772574
.attr('id', 'defs-' + fullLayout._uid);

src/plots/geo/geo.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var createGeoScale = require('./set_scale');
2121
var createGeoZoom = require('./zoom');
2222
var createGeoZoomReset = require('./zoom_reset');
2323

24+
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
2425
var constants = require('../../constants/geo_constants');
2526
var topojsonUtils = require('../../lib/topojson_utils');
2627
var topojsonFeature = require('topojson').feature;
@@ -214,10 +215,7 @@ proto.makeFramework = function() {
214215

215216
var hoverContainer = this.hoverContainer = geoDiv.append('svg');
216217
hoverContainer
217-
.attr({
218-
xmlns:'http://www.w3.org/2000/svg',
219-
'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink'
220-
})
218+
.attr(xmlnsNamespaces.svgAttrs)
221219
.style({
222220
'position': 'absolute',
223221
'z-index': 20,
@@ -226,9 +224,8 @@ proto.makeFramework = function() {
226224

227225
var framework = this.framework = geoDiv.append('svg');
228226
framework
227+
.attr(xmlnsNamespaces.svgAttrs)
229228
.attr({
230-
'xmlns':'http://www.w3.org/2000/svg',
231-
'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink',
232229
'position': 'absolute',
233230
'preserveAspectRatio': 'none'
234231
});

src/snapshot/tosvg.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../plotly'),
13-
d3 = require('d3');
12+
var Plotly = require('../plotly');
13+
var d3 = require('d3');
14+
15+
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
16+
1417

1518
module.exports = function toSVG(gd, format) {
1619

@@ -139,8 +142,8 @@ module.exports = function toSVG(gd, format) {
139142

140143
// fix for IE namespacing quirk?
141144
// http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie
142-
svg.node().setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg');
143-
svg.node().setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
145+
svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns', xmlnsNamespaces.svg);
146+
svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns:xlink', xmlnsNamespaces.xlink);
144147

145148
var s = new window.XMLSerializer().serializeToString(svg.node());
146149
s = Plotly.util.html_entity_decode(s);
@@ -154,8 +157,8 @@ function insertGlImage(fullLayout, scene, opts) {
154157

155158
fullLayout._glimages.append('svg:image')
156159
.attr({
157-
xmlns:'http://www.w3.org/2000/svg',
158-
'xlink:xlink:href': imageData, // odd d3 quirk, need namespace twice
160+
xmlns: xmlnsNamespaces.svg,
161+
'xlink:href': imageData,
159162
x: opts.x,
160163
y: opts.y,
161164
width: opts.width,

src/traces/heatmap/plot.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var tinycolor = require('tinycolor2');
1515
var Plotly = require('../../plotly');
1616
var Lib = require('../../lib');
1717
var getColorscale = require('../../components/colorscale/get_scale');
18+
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1819

1920
var maxRowLength = require('./max_row_length');
2021

@@ -372,8 +373,8 @@ function plotOne(gd, plotinfo, cd) {
372373
.classed(id, true)
373374
.datum(cd[0])
374375
.attr({
375-
xmlns: 'http://www.w3.org/2000/svg',
376-
'xlink:xlink:href': canvas.toDataURL('image/png'), // odd d3 quirk, need namespace twice
376+
xmlns: xmlnsNamespaces.svg,
377+
'xlink:href': canvas.toDataURL('image/png'),
377378
height: imageHeight,
378379
width: imageWidth,
379380
x: left,

0 commit comments

Comments
 (0)