Skip to content

Commit

Permalink
Fixed part of the problem reported in #16, resize and use svgPanZoom …
Browse files Browse the repository at this point in the history
…only when visible
  • Loading branch information
fmannhardt committed Jun 7, 2019
1 parent a9b7f34 commit 29ee7a5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/modules/animation_playback_control.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
processanimateR 1.0.1.9000
processanimateR 1.0.1
Copyright (c) 2018 Felix Mannhardt
Licensed under MIT license
*/
Expand Down
39 changes: 32 additions & 7 deletions inst/htmlwidgets/lib/modules/animation_renderer_graphviz.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
processanimateR 1.0.1.9000
processanimateR 1.0.1
Copyright (c) 2018 Felix Mannhardt
Licensed under MIT license
*/
Expand All @@ -8,6 +8,24 @@ function RendererGraphviz(el, data) {
var svg = null;
var svgPan = null;

// source https://stackoverflow.com/questions/178325/how-do-i-check-if-an-element-is-hidden-in-jquery/11511035#11511035
function isRendered(domObj) {
if ((domObj.nodeType != 1) || (domObj == document.body)) {
return true;
}
if (domObj.currentStyle && domObj.currentStyle.display != "none" &&
domObj.currentStyle.visibility != "hidden") {
return isRendered(domObj.parentNode);
} else if (window.getComputedStyle) {
var cs = document.defaultView.getComputedStyle(domObj, null);
if (cs.getPropertyValue("display") != "none" &&
cs.getPropertyValue("visibility") != "hidden") {
return isRendered(domObj.parentNode);
}
}
return false;
}

this.getSvg = function() {
return svg;
};
Expand Down Expand Up @@ -81,7 +99,9 @@ function RendererGraphviz(el, data) {

postRender(svg);

svgPan = svgPanZoom(svg, { dblClickZoomEnabled: false, preventEventsDefaults: true });
if (isRendered(svg)) {
svgPan = svgPanZoom(svg, { dblClickZoomEnabled: false, preventEventsDefaults: true });
}

}
).catch(function(error) {
Expand All @@ -103,12 +123,17 @@ function RendererGraphviz(el, data) {
svg.setAttribute("width", width);
svg.setAttribute("height", height);

if (svgPan) {
svgPan.resize();
if (height > 0) {
svgPan.fit();

if (isRendered(svg)) {
if (svgPan) {
svgPan.resize();
if (height > 0) {
svgPan.fit();
}
svgPan.center();
} else {
svgPan = svgPanZoom(svg, { dblClickZoomEnabled: false, preventEventsDefaults: true });
}
svgPan.center();
}

};
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/modules/animation_renderer_leaflet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
processanimateR 1.0.1.9000
processanimateR 1.0.1
Copyright (c) 2018 Felix Mannhardt
Licensed under MIT license
*/
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/modules/animation_scales.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
processanimateR 1.0.1.9000
processanimateR 1.0.1
Copyright (c) 2018 Felix Mannhardt
Licensed under MIT license
*/
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/modules/animation_tokens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
processanimateR 1.0.1.9000
processanimateR 1.0.1
Copyright (c) 2018 Felix Mannhardt
Licensed under MIT license
*/
Expand Down

0 comments on commit 29ee7a5

Please sign in to comment.