From ffd8052552d068ed07630eb4771dfca550f935e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 19 Jan 2016 15:50:08 -0500 Subject: [PATCH 01/10] bump dev deps --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 370d37a1b06..f5955e1517d 100644 --- a/package.json +++ b/package.json @@ -77,13 +77,13 @@ "topojson": "^1.6.19" }, "devDependencies": { - "brfs": "^1.4.1", - "browserify": "^12.0.1", - "browserify-transform-tools": "^1.5.0", + "brfs": "^1.4.3", + "browserify": "^13.0.0", + "browserify-transform-tools": "^1.5.1", "ecstatic": "^1.2.0", "eslint": "^1.10.3", "falafel": "^1.2.0", - "glob": "^6.0.1", + "glob": "^6.0.4", "jasmine-core": "^2.3.4", "karma": "^0.13.15", "karma-browserify": "^4.4.1", @@ -97,7 +97,7 @@ "prettysize": "0.0.3", "through2": "^2.0.0", "uglify-js": "^2.5.0", - "watchify": "^3.6.0", - "xml2js": "^0.4.15" + "watchify": "^3.7.0", + "xml2js": "^0.4.16" } } From ac862ccc5272d75ebf08343bdeb28b771b05fb5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 19 Jan 2016 16:03:56 -0500 Subject: [PATCH 02/10] bump tinycolor2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f5955e1517d..c0a802effef 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "robust-orientation": "^1.1.3", "sane-topojson": "^1.2.0", "superscript-text": "^1.0.0", - "tinycolor2": "1.1.2", + "tinycolor2": "^1.3.0", "topojson": "^1.6.19" }, "devDependencies": { From 70bade0cf8a77c428d1917160add55521c0a66fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 19 Jan 2016 16:10:16 -0500 Subject: [PATCH 03/10] bump topojson --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c0a802effef..41be26e4ec2 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "sane-topojson": "^1.2.0", "superscript-text": "^1.0.0", "tinycolor2": "^1.3.0", - "topojson": "^1.6.19" + "topojson": "^1.6.20" }, "devDependencies": { "brfs": "^1.4.3", From 20e0bc99fc03178aa3e87534cd8953cfab6f2702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 19 Jan 2016 16:29:24 -0500 Subject: [PATCH 04/10] bump d3 (tests fail) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 41be26e4ec2..f6fa22ce468 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "alpha-shape": "^1.0.0", "arraytools": "^1.0.0", "convex-hull": "^1.0.3", - "d3": "3.5.6", + "d3": "^3.5.12", "delaunay-triangulate": "^1.1.6", "es6-promise": "^3.0.2", "fast-isnumeric": "^1.1.1", From 5b1bdc47b720f724f343eca812917980406e025c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 19 Jan 2016 17:46:02 -0500 Subject: [PATCH 05/10] add xmlns namespaces constant file --- src/constants/xmlns_namespaces.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/constants/xmlns_namespaces.js diff --git a/src/constants/xmlns_namespaces.js b/src/constants/xmlns_namespaces.js new file mode 100644 index 00000000000..a2da63d921e --- /dev/null +++ b/src/constants/xmlns_namespaces.js @@ -0,0 +1,22 @@ +/** +* Copyright 2012-2016, Plotly, Inc. +* All rights reserved. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +*/ + + +'use strict'; + + +exports.xmlns = 'http://www.w3.org/2000/xmlns/'; +exports.svg = 'http://www.w3.org/2000/svg'; +exports.xlink = 'http://www.w3.org/1999/xlink'; + +// the 'old' d3 quirk got fix in v3.5.7 +// https://github.com/mbostock/d3/commit/a6f66e9dd37f764403fc7c1f26be09ab4af24fed +exports.svgAttrs = { + xmlns: exports.svg, + 'xmlns:xlink': exports.xlink +}; From cfeb3e16932c38d20a0046b6d686b15b64341ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 19 Jan 2016 17:49:18 -0500 Subject: [PATCH 06/10] use xmlns namespaces module instead of hard-coded the urls --- src/components/drawing/index.js | 9 +++------ src/lib/svg_text_utils.js | 15 +++++++++++---- src/plot_api/plot_api.js | 7 ++----- src/plots/geo/geo.js | 9 +++------ src/snapshot/tosvg.js | 15 +++++++++------ src/traces/heatmap/plot.js | 5 +++-- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index 6f2a025ae73..8e0f48fcbfe 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -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'); @@ -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', diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index ae5c151bc99..032b01fee14 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -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 = '' + - _svgString + '', - dom = new DOMParser().parseFromString(skeleton, 'application/xml'), + var skeleton = [ + '', + _svgString, + '' + ].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; diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 86d92cdfea4..094f803597e 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -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'); /** @@ -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); diff --git a/src/plots/geo/geo.js b/src/plots/geo/geo.js index 7bd6ed0aa35..fc4d08a2532 100644 --- a/src/plots/geo/geo.js +++ b/src/plots/geo/geo.js @@ -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; @@ -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, @@ -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' }); diff --git a/src/snapshot/tosvg.js b/src/snapshot/tosvg.js index bea6334e528..0ebc68e44e4 100644 --- a/src/snapshot/tosvg.js +++ b/src/snapshot/tosvg.js @@ -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) { @@ -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); @@ -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, diff --git a/src/traces/heatmap/plot.js b/src/traces/heatmap/plot.js index e087f306e18..3f0f87d0597 100644 --- a/src/traces/heatmap/plot.js +++ b/src/traces/heatmap/plot.js @@ -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'); @@ -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, From 7280aedf71f0ed7963bed5f002e818691ad8fd89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 19 Jan 2016 18:06:00 -0500 Subject: [PATCH 07/10] fix polar (oh polar) --- src/plots/polar/micropolar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plots/polar/micropolar.js b/src/plots/polar/micropolar.js index f28af079454..a17a0cf3995 100644 --- a/src/plots/polar/micropolar.js +++ b/src/plots/polar/micropolar.js @@ -1071,7 +1071,7 @@ var extendDeepAll = Plotly.Lib.extendDeepAll; width: 300, height: height + lineHeight, xmlns: 'http://www.w3.org/2000/svg', - 'xmlns:xmlns:xlink': 'http://www.w3.org/1999/xlink', + 'xmlns:xlink': 'http://www.w3.org/1999/xlink', version: '1.1' }); svgEnter.append('g').classed('legend-axis', true); From 0a1cbaa7bff432a265841bcc5f70a2b5136406fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 20 Jan 2016 12:25:48 -0500 Subject: [PATCH 08/10] use d3.selectAll().size() to count number of items --- test/jasmine/tests/plot_interact_test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/jasmine/tests/plot_interact_test.js b/test/jasmine/tests/plot_interact_test.js index bdf46fafbd7..859a036a220 100644 --- a/test/jasmine/tests/plot_interact_test.js +++ b/test/jasmine/tests/plot_interact_test.js @@ -21,17 +21,17 @@ describe('Test plot structure', function() { it('has one *subplot xy* node', function() { var nodes = d3.selectAll('g.subplot.xy'); - expect(nodes[0].length).toEqual(1); + expect(nodes.size()).toEqual(1); }); it('has one *scatterlayer* node', function() { var nodes = d3.selectAll('g.scatterlayer'); - expect(nodes[0].length).toEqual(1); + expect(nodes.size()).toEqual(1); }); it('has as many *trace scatter* nodes as there are traces', function() { var nodes = d3.selectAll('g.trace.scatter'); - expect(nodes[0].length).toEqual(mock.data.length); + expect(nodes.size()).toEqual(mock.data.length); }); it('has as many *point* nodes as there are traces', function() { @@ -42,7 +42,7 @@ describe('Test plot structure', function() { Npts += trace.x.length; }); - expect(nodes[0].length).toEqual(Npts); + expect(nodes.size()).toEqual(Npts); }); }); @@ -61,7 +61,7 @@ describe('Test plot structure', function() { Npts += trace.values.length; }); - expect(nodes[0].length).toEqual(Npts); + expect(nodes.size()).toEqual(Npts); }); }); }); @@ -82,7 +82,7 @@ describe('Test plot structure', function() { if(items) Npts += items.length; }); - expect(nodes[0].length).toEqual(Npts); + expect(nodes.size()).toEqual(Npts); }); it('has as many *point* nodes as there are marker points', function() { @@ -94,7 +94,7 @@ describe('Test plot structure', function() { if(items) Npts += items.length; }); - expect(nodes[0].length).toEqual(Npts); + expect(nodes.size()).toEqual(Npts); }); }); @@ -113,7 +113,7 @@ describe('Test plot structure', function() { Npts += trace.r.length; }); - expect(nodes[0].length).toEqual(Npts); + expect(nodes.size()).toEqual(Npts); }); }); }); From 5dbf06538d8441d041c67055a8232685f98f7a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 20 Jan 2016 12:26:04 -0500 Subject: [PATCH 09/10] add svg/xlink namespace tests --- test/jasmine/tests/plot_interact_test.js | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/jasmine/tests/plot_interact_test.js b/test/jasmine/tests/plot_interact_test.js index 859a036a220..89d1970be64 100644 --- a/test/jasmine/tests/plot_interact_test.js +++ b/test/jasmine/tests/plot_interact_test.js @@ -9,6 +9,13 @@ var destroyGraphDiv = require('../assets/destroy_graph_div'); describe('Test plot structure', function() { 'use strict'; + function assertNamespaces(node) { + expect(node.getAttribute('xmlns')) + .toEqual('http://www.w3.org/2000/svg'); + expect(node.getAttribute('xmlns:xlink')) + .toEqual('http://www.w3.org/1999/xlink'); + } + afterEach(destroyGraphDiv); describe('cartesian plots', function() { @@ -44,6 +51,15 @@ describe('Test plot structure', function() { expect(nodes.size()).toEqual(Npts); }); + + it('has the correct name spaces', function() { + var mainSVGs = d3.selectAll('.main-svg'); + + mainSVGs.each(function() { + var node = this; + assertNamespaces(node); + }); + }); }); describe('pie traces', function() { @@ -63,6 +79,18 @@ describe('Test plot structure', function() { expect(nodes.size()).toEqual(Npts); }); + + it('has the correct name spaces', function() { + var mainSVGs = d3.selectAll('.main-svg'); + + mainSVGs.each(function() { + var node = this; + assertNamespaces(node); + }); + + var testerSVG = d3.selectAll('#js-plotly-tester'); + assertNamespaces(testerSVG.node()); + }); }); }); @@ -96,6 +124,22 @@ describe('Test plot structure', function() { expect(nodes.size()).toEqual(Npts); }); + + it('has the correct name spaces', function() { + var mainSVGs = d3.selectAll('.main-svg'); + + mainSVGs.each(function() { + var node = this; + assertNamespaces(node); + }); + + var geoSVGs = d3.select('#geo').selectAll('svg'); + + geoSVGs.each(function() { + var node = this; + assertNamespaces(node); + }); + }); }); describe('polar plots', function() { From b5bf3ff655c8957a7e0521be3bb14d86a253a644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 20 Jan 2016 12:27:50 -0500 Subject: [PATCH 10/10] add check for xdescribe and xfit + add syntax test to `npm test` --- package.json | 2 +- test/syntax_test.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ad1a12e9149..905f7f29d3a 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "citest-jasmine": "karma start test/jasmine/karma.ciconf.js", "test-image": "./tasks/test_image.sh", "test-syntax": "node test/syntax_test.js", - "test": "npm run test-jasmine && npm test-image", + "test": "npm run test-jasmine && npm test-image && npm test-syntax", "start-test_dashboard": "node devtools/test_dashboard/server.js", "start-image_viewer": "node devtools/image_viewer/server.js", "baseline": "./tasks/baseline.sh", diff --git a/test/syntax_test.js b/test/syntax_test.js index 9f982601c60..cb4dc383340 100644 --- a/test/syntax_test.js +++ b/test/syntax_test.js @@ -6,7 +6,7 @@ var glob = require('glob'); var constants = require('../tasks/util/constants'); -var focusGlobals = ['fdescribe', 'fit']; +var focusGlobals = ['fdescribe', 'fit', 'xdescribe', 'xit']; var logs = []; @@ -19,12 +19,13 @@ glob(path.join(constants.pathToJasmineTests, '**/*.js'), function(err, files) { logs.push([ path.basename(file), '[line ' + node.loc.start.line + '] :', - 'contains either a *fdescribe* or a *fit* block.' + 'contains either a *fdescribe*, *fit*,', + '*xdescribe* or *xit* block.' ].join(' ')); } }); }); - if(logs.length) throw new Error(logs.join('\n')); + if(logs.length) throw new Error('\n' + logs.join('\n') + '\n'); });