Skip to content
Prev Previous commit
Next Next commit
use xmlns namespaces module instead of hard-coded the urls
  • Loading branch information
etpinard committed Jan 19, 2016
commit cfeb3e16932c38d20a0046b6d686b15b64341ebf
9 changes: 3 additions & 6 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Plotly = require('../../plotly');
var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
var subTypes = require('../../traces/scatter/subtypes');
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');

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

tester.enter().append('svg')
.attr({
id: 'js-plotly-tester',
xmlns: 'http://www.w3.org/2000/svg',
// odd d3 quirk - need namespace twice??
'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink'
})
.attr('id', 'js-plotly-tester')
.attr(xmlnsNamespaces.svgAttrs)
.style({
position: 'absolute',
left: '-10000px',
Expand Down
15 changes: 11 additions & 4 deletions src/lib/svg_text_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@
var Plotly = require('../plotly');
var d3 = require('d3');

var xmlnsNamespaces = require('../constants/xmlns_namespaces');

var util = module.exports = {};

// Append SVG

d3.selection.prototype.appendSVG = function(_svgString) {
var skeleton = '<svg xmlns="http://www.w3.org/2000/svg" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink">' +
_svgString + '</svg>',
dom = new DOMParser().parseFromString(skeleton, 'application/xml'),
var skeleton = [
'<svg xmlns="', xmlnsNamespaces.svg, '" ',
'xmlns:xlink="', xmlnsNamespaces.xlink, '">',
_svgString,
'</svg>'
].join('');

var dom = new DOMParser().parseFromString(skeleton, 'application/xml'),
childNode = dom.documentElement.firstChild;

while(childNode) {
this.node().appendChild(this.node().ownerDocument.importNode(childNode, true));
childNode = childNode.nextSibling;
Expand Down
7 changes: 2 additions & 5 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var Legend = require('../components/legend');
var Shapes = require('../components/shapes');
var Titles = require('../components/titles');
var manageModeBar = require('../components/modebar/manage');
var xmlnsNamespaces = require('../constants/xmlns_namespaces');


/**
Expand Down Expand Up @@ -2567,11 +2568,7 @@ function makePlotFramework(gd) {
}

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

fullLayout._defs = fullLayout._paper.append('defs')
.attr('id', 'defs-' + fullLayout._uid);
Expand Down
9 changes: 3 additions & 6 deletions src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var createGeoScale = require('./set_scale');
var createGeoZoom = require('./zoom');
var createGeoZoomReset = require('./zoom_reset');

var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
var constants = require('../../constants/geo_constants');
var topojsonUtils = require('../../lib/topojson_utils');
var topojsonFeature = require('topojson').feature;
Expand Down Expand Up @@ -214,10 +215,7 @@ proto.makeFramework = function() {

var hoverContainer = this.hoverContainer = geoDiv.append('svg');
hoverContainer
.attr({
xmlns:'http://www.w3.org/2000/svg',
'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink'
})
.attr(xmlnsNamespaces.svgAttrs)
.style({
'position': 'absolute',
'z-index': 20,
Expand All @@ -226,9 +224,8 @@ proto.makeFramework = function() {

var framework = this.framework = geoDiv.append('svg');
framework
.attr(xmlnsNamespaces.svgAttrs)
.attr({
'xmlns':'http://www.w3.org/2000/svg',
'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink',
'position': 'absolute',
'preserveAspectRatio': 'none'
});
Expand Down
15 changes: 9 additions & 6 deletions src/snapshot/tosvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

'use strict';

var Plotly = require('../plotly'),
d3 = require('d3');
var Plotly = require('../plotly');
var d3 = require('d3');

var xmlnsNamespaces = require('../constants/xmlns_namespaces');


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

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

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

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

fullLayout._glimages.append('svg:image')
.attr({
xmlns:'http://www.w3.org/2000/svg',
'xlink:xlink:href': imageData, // odd d3 quirk, need namespace twice
xmlns: xmlnsNamespaces.svg,
'xlink:href': imageData,
x: opts.x,
y: opts.y,
width: opts.width,
Expand Down
5 changes: 3 additions & 2 deletions src/traces/heatmap/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var tinycolor = require('tinycolor2');
var Plotly = require('../../plotly');
var Lib = require('../../lib');
var getColorscale = require('../../components/colorscale/get_scale');
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');

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

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