views:

78

answers:

2

I'm using JIT to render graphs. I'm using the RGraph feature.

This JSON defines a graph:

var json = [


    {
        'id': '1',
        'name': 'CS 2110',
        'adjacencies': ['0', '2']
    },

    {
        'id': '1.5',
        'name': 'INFO 2300',
        'adjacencies': ['1']
    },

    {
        'id': '0',
        'name': 'CS 1110',
        'adjacencies': ['1']
    },

    {
        'id': '2',
        'name': 'INFO 3300',
        'adjacencies': ['1']
    },

]

If I want a directed graph, how can I specify which nodes are sources and which are sinks?

A: 

According to the API, only the edgewise format is supported:

  'adjacencies': [{nodeTo: '0'},{nodeTo: '2'}]

If you want sources and sinks, you'll have to implement a function that transforms the data:

function(json, sinks, sources):
  while (get source from sources):
    get vertex=source from json  # inefficient
    adjacencies_new := ø
    for (adjacent in vertex.adjacencies):
      unless adjacent in sources:
        add {nodeTo: adjacent.id} to adjacencies_new
      else:
        add adjacent.id to adjancies_new
      unless adjacent in sinks:
        add adjacent to sources
    end
    vertex.adjacencies := adjacencies_new
  end
end
Pete
A: 

Looks like you can specify it in the JSON data like so:

data: {
  $direction: ["idfrom", "idTo"]
} 

from:

http://groups.google.com/group/javascript-information-visualization-toolkit/browse_thread/thread/28602df76b6aa194

Rosarch