Skip to content

Commit 17cc510

Browse files
committed
Fix drag behavior on for <svg:use> elements
Drag behavior is broken for <svg:use> elements on certain browsers. This includes d3.layout.force(...).drag() On browsers like Internet Explorer 11, the <svg:use> EventTarget is represented by a SVGElementInstance that looks like this: [object SVGElementInstance] { [functions]: , __proto__: { }, childNodes: { }, constructor: { }, correspondingElement: { }, correspondingUseElement: { }, firstChild: null, lastChild: null, nextSibling: null, parentNode: { }, previousSibling: { } } No other properties such as .style are present. We must use the correspondingElement property to access the actual SVG element instantiated by the <svg:use> in order to have a successful drag.
1 parent 9f96bf5 commit 17cc510

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@
12041204
}
12051205
function dragstart(id, position, subject, move, end) {
12061206
return function() {
1207-
var that = this, target = d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
1207+
var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
12081208
if (origin) {
12091209
dragOffset = origin.apply(that, arguments);
12101210
dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];

0 commit comments

Comments
 (0)