diff options
| author | Alon Levy <alon@pobox.com> | 2014-12-08 11:36:02 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-12-08 11:37:43 +0200 |
| commit | 07add10d7ed8cd042db37f4a7387254d8dee1c2a (patch) | |
| tree | 85bb091a5c5adc4e8e9107f49188b63b4e28e7a0 /src/rz_core.js | |
| parent | 19361430c6e85014baea8428cde8d20daec4e2c3 (diff) | |
reorder related & selected on top; Fixes #198
Diffstat (limited to 'src/rz_core.js')
| -rw-r--r-- | src/rz_core.js | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/rz_core.js b/src/rz_core.js index b2e70be8..22b9743b 100644 --- a/src/rz_core.js +++ b/src/rz_core.js @@ -436,12 +436,35 @@ function update_view__graph(no_relayout) { .attr('visibility', 'hidden') // made visible on first tick .call(drag); - node.each(function (d) { - this.node = d; - }) - .attr('class', function(d) { - return ['node', selection.selected_class(d)].join(' '); + // reorder nodes so selected are last, and so rendered last, and so on top. + (function () { + var ontop = [], last = node[0].length - 1, bubble, + parent = node[0].length > 0 ? node[0][0].parentNode : null; + node.each(function (d) { + this.node = d; + }) + .attr('class', function(d) { + if (selection.node_selected(d)) { + if (d.type == 'bubble') { + bubble = this; + } else { + ontop.push(this); + } + } + return ['node', selection.selected_class(d)].join(' '); + }); + if (bubble === undefined) { + // nothing to do if there is no bubble + return; + } + function insertAtEnd(e) { + parent.appendChild(parent.removeChild(e)); + } + insertAtEnd(bubble); + ontop.reverse().forEach(function (e) { + insertAtEnd(e); }); + })(); nodetext = nodeEnter.insert("text") .attr("class", "nodetext graph") |
