d3-annotation icon indicating copy to clipboard operation
d3-annotation copied to clipboard

EditMode not working properly in ShadowDOM

Open manuelroth opened this issue 5 years ago • 5 comments

Hi @susielu , Thank you for this great d3 plugin. Really love working with it. I encountered a problem when using d3-annotation inside a shadowDOM:

Problem:

My svg element lives inside a shadowDOM. If the element is in editMode it is not possible to drag the annotation handles. I have created a codepen to reproduce the problem -> https://codepen.io/anon/pen/GzqvbY?editors=1010

Try to drag the annotation handles and check the console for the error message (Cannot read property 'ownerSVGElement' of null).

Possible solution

I did some debugging and found out that the drag handler is registered on all elements passing this selector g.annotations (see code here):

drag().container(select("g.annotations").node())

This doesn't play nicely with shadowDOM, because the svg element inside the shadowDOM is not visible from outside. A possible solution could be to make the selection relative to the annotation-group:

drag().container(group.selectAll("g.annotations").node())

I wanted to create a PR but failed to implement a working solution. Do you have an idea how we could fix this?

Kind regards, Manuel

manuelroth avatar Jan 28 '19 16:01 manuelroth

Hey Manuel, thanks for posting this. I haven't worked with the shadowDOM before. Thanks for making a codepen example. I'll take a look.

susielu avatar Feb 05 '19 19:02 susielu

Hi @susielu, just wanted to let you know that I used your library to cover communal elections in the canton of zurich (switzerland). Thank you so much, it let us build this in a very short time -> https://www.nzz.ch/zuerich/regierungsrat-und-kantonsrat-zuerich-die-resultate-der-wahlen-ld.1465859?h

Bildschirmfoto 2019-03-24 um 14 55 47

Kind regards, Manuel

manuelroth avatar Mar 24 '19 13:03 manuelroth

Thanks Manuel, still haven't put aside time to look at the shadow dom example, were you able to get your use case to work around it?

susielu avatar Mar 24 '19 15:03 susielu

Really great to see the example, thanks for sharing!

susielu avatar Mar 24 '19 15:03 susielu

Yes, I was able to work around it. It would still be helpful for future use of the library though. I think its always cool to share back some implementation examples to an open source project.

manuelroth avatar Mar 24 '19 15:03 manuelroth