2

everyone I was trying to make Force layout that selection node always at the center and the whole graph redraw. I current now set 1 node as a "root" and fix it to the center but i am stuck there. My current approach

Psuedo code:

root=nodes[0]
root.x and root.y=center and root.fix=true

onclick(){
root=not root anymore//Make current root is no longer root
d3.select(this)=root; // Selection become root
update() //What should be in this function?
}

Data format: miserables.json at http://bl.ocks.org/sjengle/5431779

The idea is this Flash example: http://www.liveplasma.com/#/artist/Arctic_Monkeys/ada7a83c-e3e1-40f1-93f9-3e73dbc9298a/DE

Loredra L
  • 1,485
  • 2
  • 16
  • 32
  • Just assign `fixed = true` to the single node that you want to be centered (also give it the proper `x` and `y`) and the rest of the layout will adjust around it. See `fixed` property [here](https://github.com/mbostock/d3/wiki/Force-Layout#nodes) – meetamit Mar 09 '16 at 18:19
  • Thx meetamit. I was able to center the first node. But when I click on other node, it is fixed but not to center, even though I called fixed=true last. Do you have any idea? – Loredra L Mar 11 '16 at 09:34
  • You need to assign it x and y that equal the coordinates of the center. You also have to "un-fixed" the previously selected node. – meetamit Mar 11 '16 at 14:50

0 Answers0