Skip to content

Commit ce970f1

Browse files
authored
Merge pull request #1585 from hy9be/perf-misc
Misc performance optimization
2 parents 082bfc1 + 29abb5d commit ce970f1

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/components/drawing/index.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ drawing.makeTester = function(gd) {
512512
// always returns a copy of the bbox, so the caller can modify it safely
513513
var savedBBoxes = [],
514514
maxSavedBBoxes = 10000;
515+
515516
drawing.bBox = function(node) {
516517
// cache elements we've already measured so we don't have to
517518
// remeasure the same thing many times
@@ -520,32 +521,36 @@ drawing.bBox = function(node) {
520521
return Lib.extendFlat({}, savedBBoxes[saveNum.value]);
521522
}
522523

523-
var test3 = d3.select('#js-plotly-tester'),
524-
tester = test3.node();
524+
if(!drawing.test3) {
525+
drawing.test3 = d3.select('#js-plotly-tester');
526+
drawing.tester = drawing.test3.node();
527+
}
525528

526529
// copy the node to test into the tester
527530
var testNode = node.cloneNode(true);
528-
tester.appendChild(testNode);
531+
drawing.tester.appendChild(testNode);
529532
// standardize its position... do we really want to do this?
530533
d3.select(testNode).attr({
531534
x: 0,
532535
y: 0,
533536
transform: ''
534537
});
535538

536-
var testRect = testNode.getBoundingClientRect(),
537-
refRect = test3.select('.js-reference-point')
539+
var testRect = testNode.getBoundingClientRect();
540+
if(!drawing.refRect) {
541+
drawing.refRect = drawing.test3.select('.js-reference-point')
538542
.node().getBoundingClientRect();
543+
}
539544

540-
tester.removeChild(testNode);
545+
drawing.tester.removeChild(testNode);
541546

542547
var bb = {
543548
height: testRect.height,
544549
width: testRect.width,
545-
left: testRect.left - refRect.left,
546-
top: testRect.top - refRect.top,
547-
right: testRect.right - refRect.left,
548-
bottom: testRect.bottom - refRect.top
550+
left: testRect.left - drawing.refRect.left,
551+
top: testRect.top - drawing.refRect.top,
552+
right: testRect.right - drawing.refRect.left,
553+
bottom: testRect.bottom - drawing.refRect.top
549554
};
550555

551556
// make sure we don't have too many saved boxes,

src/lib/svg_text_utils.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var stringMappings = require('../constants/string_mappings');
1919

2020
// Append SVG
2121

22+
var parser = new DOMParser();
23+
2224
d3.selection.prototype.appendSVG = function(_svgString) {
2325
var skeleton = [
2426
'<svg xmlns="', xmlnsNamespaces.svg, '" ',
@@ -27,7 +29,7 @@ d3.selection.prototype.appendSVG = function(_svgString) {
2729
'</svg>'
2830
].join('');
2931

30-
var dom = new DOMParser().parseFromString(skeleton, 'application/xml'),
32+
var dom = parser.parseFromString(skeleton, 'application/xml'),
3133
childNode = dom.documentElement.firstChild;
3234

3335
while(childNode) {

src/plot_api/plot_api.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ Plotly.plot = function(gd, data, layout, config) {
285285
// Now plot the data
286286
function drawData() {
287287
var calcdata = gd.calcdata,
288-
i;
288+
i,
289+
rangesliderContainers = fullLayout._infolayer.selectAll('g.rangeslider-container');
289290

290291
// in case of traces that were heatmaps or contour maps
291292
// previously, remove them and their colorbars explicitly
@@ -305,7 +306,7 @@ Plotly.plot = function(gd, data, layout, config) {
305306
.selectAll(query)
306307
.remove();
307308

308-
fullLayout._infolayer.selectAll('g.rangeslider-container')
309+
rangesliderContainers
309310
.selectAll(query)
310311
.remove();
311312
}

0 commit comments

Comments
 (0)