Created
November 15, 2012 09:33
-
-
Save jbilcke/4077655 to your computer and use it in GitHub Desktop.
fix for the d3.js radial tree bug (when there is only 1 child on the root)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
importScripts('../vendor/d3/d3.layout.redux.js') | |
@onmessage = (msg) -> | |
tree = msg.data | |
# the layout has a weird effect | |
if tree.children.length is 1 | |
for n in tree.children[0].children | |
tree.children.push ghost: yes, children: [] | |
d3_layout = d3.layout.tree() | |
d3_layout.separation (a, b) -> | |
(if a.parent is b.parent then 1 else 3) / a.depth | |
nodes = d3_layout.nodes tree | |
newNodes = for n in nodes | |
continue if n.ghost | |
angle = n.x * Math.PI * 2 | |
n.x = 2000 * n.y * Math.cos angle | |
n.y = 2000 * n.y * Math.sin angle | |
n | |
nodes = newNodes | |
# sort elements by id | |
nodes.sort (a,b) -> a.id - b.id | |
postMessage nodes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment