question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

D3 svg-overlay with draggable elements

See original GitHub issue

I am using SVG overlay and calling D3 to draw elements on top of the the image when the user clicks on top of it. I understand from svg-overlay that I can use onClick(node, handler) to accept click events on a sub-node and it raises an OpenSeadragon.MouseTracker click event.

The thing is that I need to tell D3 and OSD that this a draggable element.

In this super cool OSD+D3 example there is a working example on D3 elements that it is possible to click and get an OSD event that provides a reference to the D3 element which can be called using D3 calls to do a click dependent action. But since dragging is another type of event I am not really sure what to do.

D3 dragging is done like so and I am trying to use the previous example and doing some kind of monster like this:

d3.selectAll(".aClass").each(function() { 
    return svg-overlay.onClick(this,
        d3.select(this.element)
            .call(d3.drag().on("start",dragged))
    ); 
} );

So I wonder if anyone has tried such a thing, dragging the elements created on top of the SVG-overlay. Any ideas or suggestions are welcome.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
iangilmancommented, Apr 4, 2018

Oh, of course! I’m just not used to having the constrain turned on like that, I suppose.

Looking good! 😃

1reaction
iangilmancommented, Mar 21, 2018

I’ve not tried to do such a thing, but I imagine it’ll work better if you allow OSD to do the event tracking and not try to use D3’s event tracking. Looking at onClick it looks like it’s just a thin wrapper around MouseTracker, so you can probably just go around it like so:

function addTracking(node) {
  new $.MouseTracker({
    element: node,
    dragHandler: function(event) {
      // Move node by event.delta 
    }
  }).setTracking(true);
}

d3.selectAll(".aClass").each(function() {
  addTracking(this); 
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenSeaDragon with D3 svg-overlay draggable elements
The question is how to make those d3 objects draggable within OSD. The problem arises with the fact that OSD has to handle...
Read more >
OpenSeaDragon with D3 svg-overlay draggable elements-d3.js
Looking at the SVG overlay plugin's onClick it looks like it's just a thin wrapper around MouseTracker, so you can probably just go...
Read more >
interact.js - JavaScript drag and drop, resizing and multi-touch ...
JavaScript drag and drop, resizing, and multi-touch gestures for modern browsers (and also IE9+). version. Free and open source; Powerful snap and restriction ......
Read more >
d3-drag - npm
API Reference. This table describes how the drag behavior interprets native events: Event, Listening Element, Drag Event, Default Prevented?
Read more >
D3.js Drag and Drop Collapsible Tree with Node Editing
D3.js Drag and Drop Collapsible Tree with Node Editing ... The D3.js collapsible tree with editing nodes functionality. Nodes can be renamed, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found