Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error if there are unexpected children of d3fc-svg/d3fc-canvas #1125

Closed
ColinEberhardt opened this issue Aug 9, 2018 · 4 comments
Closed
Assignees
Projects

Comments

@ColinEberhardt
Copy link
Member

From @chrisprice on November 24, 2016 10:55

I've just debugged a weird problem in safari which came down to the following DOM structure -

<d3fc-svg>
  <svg>...</svg>
  <svg class="something">...</svg>
</d3fc-svg>

This is not an supported usage of the element. There are two workarounds -

  • Move the svg.something inside the svg (useful if it relates to the content of the existing d3fc-svg)
  • Move the svg.something to it's own d3fc-svg (useful if you want to use css layout)

We should throw an error if we detect more than one child node inside the d3fc-svg/d3fc-canvas elements.

Copied from original issue: d3fc/d3fc-element#24

@ColinEberhardt
Copy link
Member Author

see: #80 for context

@chrisprice chrisprice added this to short term in Roadmap Aug 24, 2018
@chrisprice chrisprice self-assigned this Aug 24, 2018
chrisprice added a commit to chrisprice/d3fc that referenced this issue Aug 24, 2018
The surface will now throw if it detects elements have been added to it, ensure elements are added as descendants of the svg.

Fixes d3fc#1126.
Fixes d3fc#1125.
chrisprice added a commit to chrisprice/d3fc that referenced this issue Aug 24, 2018
The surface will now throw if it detects elements have been added to it, ensure elements are added as descendants of the svg.

Fixes d3fc#1126.
Fixes d3fc#1125.
chrisprice added a commit to chrisprice/d3fc that referenced this issue Aug 24, 2018
The surface will now throw if it detects elements have been added to it, ensure elements are added as descendants of the svg.

Fixes d3fc#1126.
Fixes d3fc#1125.
Roadmap automation moved this from short term to done Aug 24, 2018
chrisprice added a commit that referenced this issue Aug 24, 2018
The surface will now throw if it detects elements have been added to it, ensure elements are added as descendants of the svg.

Fixes #1126.
Fixes #1125.
@duhaime
Copy link

duhaime commented Feb 25, 2021

@ColinEberhardt I'm working on a plot that wants to add a custom HTML tooltip to a plot: https://codepen.io/duhaime/pen/gOLGwvg

This error has cropped up a few times (I can't yet tell what triggers it). Is there a better pattern to position the tooltip inside the chart?

For context, the tooltip in my real app is a React component that's shared elsewhere in the app, so I'd prefer not to rewrite the DOM in SVG as is the case with the tooltip approach you used in your HathiTrust example (which is awesome and very instructive!), as I need my tooltip to match other instances of the same element throughout the app...

I'd be grateful for any thoughts you might have on the best approach to this problem!

@ColinEberhardt
Copy link
Member Author

@duhaime I'd suggest looking at the following example: https://github.com/ColinEberhardt/d3fc-webgl-hathi-explorer

It uses the 'standard' pattern whereby all rendering is performed via a single data-join. The tooltip logic finds the closest point and updates the data that is data-joined to the chart, then re-renders.

The annotation itself is rendered using a simple annotation series component that wraps the d3-annotation library. The annotation is rendered using SVG, so is added to the SVG plot area of the chart.

Hope that helps.

@duhaime
Copy link

duhaime commented Feb 26, 2021

@ColinEberhardt Hmm, yes, but this approach would require that I rewrite the DOM rendered by React using D3, right? I'm hoping to just use the same component in two places to refrain from repeating myself in the code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Roadmap
  
done
Development

No branches or pull requests

3 participants