Skip to content

Commit e01cf11

Browse files
committed
Optimize by calling window.getComputedStyle once
Although called on a single element, getComputedStyle forces layout thrashing/reflow: https://gist.github.com/paulirish/5d52fb081b3570c81e3a
1 parent 43b7098 commit e01cf11

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/plot_api/plot_api.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,8 @@ function calculateReservedMargins(margins) {
25172517

25182518
function plotAutoSize(gd, aobj) {
25192519
var fullLayout = gd._fullLayout,
2520-
context = gd._context;
2520+
context = gd._context
2521+
computedStyle;
25212522

25222523
var newHeight, newWidth;
25232524

@@ -2548,8 +2549,9 @@ function plotAutoSize(gd, aobj) {
25482549
// provide height and width for the container div,
25492550
// specify size in layout, or take the defaults,
25502551
// but don't enforce any ratio restrictions
2551-
newHeight = parseFloat(window.getComputedStyle(gd).height) || fullLayout.height;
2552-
newWidth = parseFloat(window.getComputedStyle(gd).width) || fullLayout.width;
2552+
computedStyle = window.getComputedStyle(gd);
2553+
newHeight = parseFloat(computedStyle.height) || fullLayout.height;
2554+
newWidth = parseFloat(computedStyle.width) || fullLayout.width;
25532555
}
25542556

25552557
if(Math.abs(fullLayout.width - newWidth) > 1 ||

0 commit comments

Comments
 (0)