From 0a5c3a28330e7b8f18b950bb98aa3ac1ae234537 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 21 May 2014 09:52:19 +0200 Subject: Fix such dragging is limited to the bar --- bubble.html | 1 - bubble.js | 36 ++++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bubble.html b/bubble.html index c6305d4..e50fab1 100644 --- a/bubble.html +++ b/bubble.html @@ -108,7 +108,6 @@ html, body {
-
    diff --git a/bubble.js b/bubble.js index 9724886..ccc4f4a 100644 --- a/bubble.js +++ b/bubble.js @@ -285,22 +285,26 @@ function processData(data) { // initialize information panel (function () { var infoPane = d3.select('#infobox'); - // SHIT: d3js cannot handle drag with nested elements --> stutter! - // BREAKS TEXT SELECTION :( - infoPane //.select('.draggable') - .call(d3.behavior.drag() - .on('drag', function () { - var changes = { - 'left': d3.event.dx, - 'top': d3.event.dy - }; - // add the differences to the old positions - for (var name in changes) { - var newValue = parseInt(infoPane.style(name)); - newValue += changes[name]; - infoPane.style(name, newValue + 'px'); - } - })); + infoPane.select('.draggable') + .on('mousedown', function () { + infoPane.call(d3.behavior.drag().on('drag', dragger)); + }) + .on('mouseup', function () { + infoPane.on('mousedown.drag', null); + }); + + function dragger() { + var changes = { + 'left': d3.event.dx, + 'top': d3.event.dy + }; + // add the differences to the old positions + for (var name in changes) { + var newValue = parseInt(infoPane.style(name)); + newValue += changes[name]; + infoPane.style(name, newValue + 'px'); + } + } }()); function run() { -- cgit v1.2.1