From 121bfcb984f08ff2dc8bca2f41d26d93760b4851 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Tue, 7 Aug 2018 14:50:28 -0500 Subject: [PATCH] Import old brush after image has loaded --- srcjs/output_binding_image.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/srcjs/output_binding_image.js b/srcjs/output_binding_image.js index d174be040..052e39959 100644 --- a/srcjs/output_binding_image.js +++ b/srcjs/output_binding_image.js @@ -998,8 +998,15 @@ imageutils.createBrushHandler = function(inputId, $el, opts, coordmap, outputId) if (!opts.brushResetOnNew) { if ($el.data("mostRecentBrush")) { - brush.importOldBrush(); - brushInfoSender.immediateCall(); + // Importing an old brush must happen after the image data has loaded + // and the DOM element has the updated size. If importOldBrush() + // is called before this happens, then the css-img coordinate mappings + // will give the wrong result, and the brush will have the wrong + // position. + $el.find("img").one("load.shiny-image-interaction", function() { + brush.importOldBrush(); + brushInfoSender.immediateCall(); + }); } }