Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
waterdataui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Maintenance scheduled for Thursday, April 10, from 5 PM to 6 PM ET.
Show more breadcrumbs
Water Mission Area
Internet of Water
waterdataui
Commits
efec159a
Commit
efec159a
authored
7 years ago
by
Yan, Andrew N.
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
assets/src/scripts/components/hydrograph/legend.js
+21
-2
21 additions, 2 deletions
assets/src/scripts/components/hydrograph/legend.js
with
21 additions
and
2 deletions
assets/src/scripts/components/hydrograph/legend.js
+
21
−
2
View file @
efec159a
...
@@ -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
}
`
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment