jaredly / treed

Powerful Tree Editor
http://jaredly.github.io/treed/
1.72k stars 193 forks source link

View end node type and value #5

Open Fr33maan opened 10 years ago

Fr33maan commented 10 years ago

I can see in the given example that json structure is assumed as following :

var flare_data = {
 "name": "flare",
 "children": [
  {
   "name": "analytics",
   "children": [ 
.......

I see on the sample app that 'name' field is used for display node name.

I would like to use a JSON structure like this :

var flare_data = {
 flare : {
   analytics : {
    cluster : {
       agglomerativeCluster : 'myPersonnalString',
       communityStructure : [{string1 : 'myPersonnalString'}, {string2 : 'myPersonnalString'}],
    },
    graph : {}
  },
  animate : {}
}

Then i would like this to be samely displayed as in app example.

I would like to know how easy it will be to make 'JSON structure switchin ' improvement

jaredly commented 10 years ago

The flare_data structure was just a nice way to get started. In the model, nodes look like:

{
  id: "id",
  collapsed: bool,
  parent: "id",
  children: ["id", "id", ...],
  data: {
    name: "Some awesome node", // <-- this is what is actually displayed
    done: bool, // also used visually
    // you can add any extra data you want here.
  }
}

There's a root node id, and everything is filled in from there by traversing the children.

If I understand correctly, you want to be able to have full JSON loading & export?

This could be accomplished by adding a type attribute to the data object (it is supported to add arbitrary values to data, which are preserved).

You would need to write a custom Node class that was aware of the type attribute and displayed things accordingly, but I think it would be totally doable.

Fr33maan commented 10 years ago

@jaredly "If I understand correctly, you want to be able to have full JSON loading & export?"

Exactly, i want to have a tool that is able to load/edit a JSON with no need of a particular structure.