Skip to content
Snippets Groups Projects
Commit efec159a authored by Yan, Andrew N.'s avatar Yan, Andrew N.
Browse files

provide error handling for bbox failures when the div isn't being shown

parent 76b1172b
No related branches found
No related tags found
No related merge requests found
...@@ -126,7 +126,21 @@ function drawSimpleLegend(svg, {legendMarkerRows, layout}) { ...@@ -126,7 +126,21 @@ function drawSimpleLegend(svg, {legendMarkerRows, layout}) {
let detachedMarker = markerType(markerArgs); let detachedMarker = markerType(markerArgs);
legendGroup.node().appendChild(detachedMarker.node()); legendGroup.node().appendChild(detachedMarker.node());
// add text for the legend marker // add text for the legend marker
let detachedMarkerBBox = detachedMarker.node().getBBox(); let detachedMarkerBBox;
// Long story short, firefox is unable to get the bounding box if
// the svg element isn't actually taking up space and visible. Folks on the
// internet seem to have gotten around this by setting `visibility:hidden`
// to hide things, but that would still mean the elements will take up space.
// which we don't want. So, here's some error handling for getBBox failures.
// This handling ends up not creating the legend, but that's okay because the
// graph is being shown anyway. A more detailed discussion of this can be found at:
// https://bugzilla.mozilla.org/show_bug.cgi?id=612118 and
// https://stackoverflow.com/questions/28282295/getbbox-of-svg-when-hidden.
try {
detachedMarkerBBox = detachedMarker.node().getBBox();
} catch(error) {
continue;
}
legendGroup.append('text') legendGroup.append('text')
.attr('x', detachedMarkerBBox.x + detachedMarkerBBox.width + markerTextXOffset) .attr('x', detachedMarkerBBox.x + detachedMarkerBBox.width + markerTextXOffset)
.attr('y', verticalRowOffset * rowCount) .attr('y', verticalRowOffset * rowCount)
...@@ -136,7 +150,12 @@ function drawSimpleLegend(svg, {legendMarkerRows, layout}) { ...@@ -136,7 +150,12 @@ function drawSimpleLegend(svg, {legendMarkerRows, layout}) {
} }
// Set the size of the containing svg node to the size of the legend. // Set the size of the containing svg node to the size of the legend.
const bBox = legend.node().getBBox(); let bBox;
try {
bBox = legend.node().getBBox();
} catch(error) {
return;
}
svg.attr('viewBox', `0 0 ${layout.width} ${bBox.height + 10}`); svg.attr('viewBox', `0 0 ${layout.width} ${bBox.height + 10}`);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment