0

I use this example : http://bl.ocks.org/mbostock/1062288 , to generate a collapsible Force Layout.

My problem is : I would like to plot a graph whose a son is linked to two fathers.

  father  father
     |     |
      \   /     
       son  

There is a way to do that in my JSON file ? I can't invert my son by a father (and my fathers by two sons).

Thanks for your help.

VividD
  • 10,456
  • 6
  • 64
  • 111
user1528760
  • 157
  • 3
  • 13
  • What does your current data file look like? – Felix Kling Mar 25 '13 at 10:31
  • Something like that: `{ "name": "parent1", "name": "parent2", "children": [ { "name" : "child" } ] }` – user1528760 Mar 25 '13 at 11:24
  • Well, if you want to use the layout as it is, you have to convert your structure into the proper format at some point. You don't have to change the JSON, you can restructure it in JS once you parsed the data. – Felix Kling Mar 25 '13 at 11:32
  • Yes but, D3.js don't recognise this kind of structure ; so if I have to modify how D3js parse the JSON ... – user1528760 Mar 25 '13 at 11:43
  • I think we have a terminology problem here. *JSON* is a textual data representation, like XML, YAML or CSV. You *parse* JSON into JavaScript objects and arrays with `JSON.parse`. This is the part where you don't have to change anything. Parsing JSON is always the same process. What you have to do once it is parsed is *restructuring* the object so that D3 understands it, i.e. you have to write a procedure which converts your data to a new object (for example), like `var new_obj = {name: 'child', children: [{name: 'parent1'}, {name: 'parent2;}]};`. – Felix Kling Mar 25 '13 at 11:46
  • Alright. Thanks. So I'm looking for modify the JS. – user1528760 Mar 25 '13 at 11:52
  • 1
    Your data object, yes. If you don't know how to iterate over an object/array or access its properties/elements, I recommend to have a look at the [MDN documentation](https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects) and [this question](http://stackoverflow.com/q/11922383/218196). – Felix Kling Mar 25 '13 at 11:54

1 Answers1

0

I should use this layout : http://bl.ocks.org/mbostock/4062045 for doing that.

user1528760
  • 157
  • 3
  • 13