From e01cf1192571373914e02b7aa4eee8e1f4a51f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bona=C4=87i?= Date: Mon, 7 Dec 2015 13:17:13 +0100 Subject: [PATCH 1/2] Optimize by calling window.getComputedStyle once Although called on a single element, getComputedStyle forces layout thrashing/reflow: https://gist.github.com/paulirish/5d52fb081b3570c81e3a --- src/plot_api/plot_api.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 4c24b172103..9f039b4a5e4 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2517,7 +2517,8 @@ function calculateReservedMargins(margins) { function plotAutoSize(gd, aobj) { var fullLayout = gd._fullLayout, - context = gd._context; + context = gd._context + computedStyle; var newHeight, newWidth; @@ -2548,8 +2549,9 @@ function plotAutoSize(gd, aobj) { // provide height and width for the container div, // specify size in layout, or take the defaults, // but don't enforce any ratio restrictions - newHeight = parseFloat(window.getComputedStyle(gd).height) || fullLayout.height; - newWidth = parseFloat(window.getComputedStyle(gd).width) || fullLayout.width; + computedStyle = window.getComputedStyle(gd); + newHeight = parseFloat(computedStyle.height) || fullLayout.height; + newWidth = parseFloat(computedStyle.width) || fullLayout.width; } if(Math.abs(fullLayout.width - newWidth) > 1 || From 116ca51fcfbe39eb519166bd1027fab110b45349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Bona=C4=87i?= Date: Mon, 7 Dec 2015 13:40:14 +0100 Subject: [PATCH 2/2] Missing comma Damn! --- src/plot_api/plot_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 9f039b4a5e4..27c1ac736c6 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2517,7 +2517,7 @@ function calculateReservedMargins(margins) { function plotAutoSize(gd, aobj) { var fullLayout = gd._fullLayout, - context = gd._context + context = gd._context, computedStyle; var newHeight, newWidth;