From 7538338803cafa672e8e60f3e0092cf43bde4baf Mon Sep 17 00:00:00 2001 From: hy9be Date: Tue, 11 Apr 2017 14:01:23 -0400 Subject: [PATCH 1/2] Cache the selected rangeslider containers in drawData --- src/plot_api/plot_api.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 2494c9d76e2..eef92ea0f3d 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -282,7 +282,8 @@ Plotly.plot = function(gd, data, layout, config) { // Now plot the data function drawData() { var calcdata = gd.calcdata, - i; + i, + rangesliderContainers = fullLayout._infolayer.selectAll('g.rangeslider-container'); // in case of traces that were heatmaps or contour maps // previously, remove them and their colorbars explicitly @@ -302,7 +303,7 @@ Plotly.plot = function(gd, data, layout, config) { .selectAll(query) .remove(); - fullLayout._infolayer.selectAll('g.rangeslider-container') + rangesliderContainers .selectAll(query) .remove(); } From 29abb5d8ec3dea92cc71f438fffa6785463d1fb1 Mon Sep 17 00:00:00 2001 From: hy9be Date: Tue, 11 Apr 2017 16:12:25 -0400 Subject: [PATCH 2/2] Cache DOM nodes and selected d3 node --- src/components/drawing/index.js | 25 +++++++++++++++---------- src/lib/svg_text_utils.js | 4 +++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index fa995b0641e..c7c23ddac7a 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -504,6 +504,7 @@ drawing.makeTester = function(gd) { // always returns a copy of the bbox, so the caller can modify it safely var savedBBoxes = [], maxSavedBBoxes = 10000; + drawing.bBox = function(node) { // cache elements we've already measured so we don't have to // remeasure the same thing many times @@ -512,12 +513,14 @@ drawing.bBox = function(node) { return Lib.extendFlat({}, savedBBoxes[saveNum.value]); } - var test3 = d3.select('#js-plotly-tester'), - tester = test3.node(); + if(!drawing.test3) { + drawing.test3 = d3.select('#js-plotly-tester'); + drawing.tester = drawing.test3.node(); + } // copy the node to test into the tester var testNode = node.cloneNode(true); - tester.appendChild(testNode); + drawing.tester.appendChild(testNode); // standardize its position... do we really want to do this? d3.select(testNode).attr({ x: 0, @@ -525,19 +528,21 @@ drawing.bBox = function(node) { transform: '' }); - var testRect = testNode.getBoundingClientRect(), - refRect = test3.select('.js-reference-point') + var testRect = testNode.getBoundingClientRect(); + if(!drawing.refRect) { + drawing.refRect = drawing.test3.select('.js-reference-point') .node().getBoundingClientRect(); + } - tester.removeChild(testNode); + drawing.tester.removeChild(testNode); var bb = { height: testRect.height, width: testRect.width, - left: testRect.left - refRect.left, - top: testRect.top - refRect.top, - right: testRect.right - refRect.left, - bottom: testRect.bottom - refRect.top + left: testRect.left - drawing.refRect.left, + top: testRect.top - drawing.refRect.top, + right: testRect.right - drawing.refRect.left, + bottom: testRect.bottom - drawing.refRect.top }; // make sure we don't have too many saved boxes, diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index f6d4419dc0c..bb76fa2d283 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -19,6 +19,8 @@ var stringMappings = require('../constants/string_mappings'); // Append SVG +var parser = new DOMParser(); + d3.selection.prototype.appendSVG = function(_svgString) { var skeleton = [ '' ].join(''); - var dom = new DOMParser().parseFromString(skeleton, 'application/xml'), + var dom = parser.parseFromString(skeleton, 'application/xml'), childNode = dom.documentElement.firstChild; while(childNode) {