Skip to content

Commit

Permalink
Fix for width&height 0
Browse files Browse the repository at this point in the history
  • Loading branch information
fmannhardt committed Jun 12, 2019
1 parent 454561c commit 402b288
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions inst/htmlwidgets/lib/modules/animation_renderer_graphviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function PARendererGraphviz(el, data) {

// source https://stackoverflow.com/questions/178325/how-do-i-check-if-an-element-is-hidden-in-jquery/11511035#11511035
function isRendered(domObj) {
if (domObj === null) {
return false;
}
if ((domObj.nodeType != 1) || (domObj == document.body)) {
return true;
}
Expand Down Expand Up @@ -99,10 +102,6 @@ function PARendererGraphviz(el, data) {

postRender(svg);

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

}
).catch(function(error) {
viz = new PAViz();
Expand All @@ -119,17 +118,16 @@ function PARendererGraphviz(el, data) {

this.resize = function(width, height) {

// Adjust GraphViz diagram size
svg.setAttribute("width", width);
svg.setAttribute("height", height);

if (height > 0 && width > 0) {
// Adjust GraphViz diagram size
svg.setAttribute("width", width);
svg.setAttribute("height", height);
}

if (isRendered(svg)) {
if (isRendered(el)) {
if (svgPan) {
svgPan.resize();
if (height > 0) {
svgPan.fit();
}
svgPan.fit();
svgPan.center();
} else {
svgPan = svgPanZoom(svg, { dblClickZoomEnabled: false, preventEventsDefaults: true });
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
Expand Up @@ -86,7 +86,7 @@ function PAScales(el) {
};

this.resizeLegend = function(svg, width, height) {
if (legendSvg) {
if (legendSvg && width > 0 && height > 0) {
legendSvg.attr("style", "position: relative; bottom: "+height+"px; left: "+(width - legendSvg.attr("width")) +"px; z-index: 999;");
el.insertBefore(legendSvg.node(), null); // keep as last child!
}
Expand Down

0 comments on commit 402b288

Please sign in to comment.