Hi,
I've read the API reference and tested it with an
RDF/OWL based Tree visualization that I'm working on.
Unless I'm missing something (which is always possible) I believe there's an issue with the existing D3 Tree API that strips out attributes of Nodes and Links based on how the tree.nodes() and tree.links() methods work, which is to "auto-generate" Node and Link arrays from things like a JSON structure, rather than taking in predefined and pre-existing Node and Link arrays.
Most existing D3 Tree examples I've found use data structures like JSON to feed the visualization. The JSON is used to auto-generate Node and Link arrays. The code assumes, for example, that there's no additional information (i.e. attributes) for Link arrays other than "source" and "target".What if there's a descriptive predicate or a link ID? Even the CSV generated Tree example auto-generates Nodes from a link set, assuming the Nodes have no descriptive attributes.
In an RDF/OWL-like environment, both, Nodes and Links are assumed to be "richer" in descriptive data and can have many additional attributes. For example...
var nodeSet = [
{id: "N0", name: "Node 0", size: 20, hlink: "some link"},
{id: "N1", name: "Node 1", size: 30, hlink: "some link"},
{id: "N2", name: "Node 2", size: 20, hlink: "some link"},
{id: "N3", name: "Node 3", size: 10, hlink: "some link"},
{id: "N4", name: "Node 4", size: 70, hlink: "some link"}
];
// Notice the additional Link Attributes "linkId" and "predicate"
var linkSet = [
{linkId: "L0", source: "N0", predicate: "Descriptive Predicate 1", target: "N1"},
{linkId: "L1", source: "N0", predicate: "Descriptive Predicate 2", target: "N2"},
{linkId: "L2", source: "N2", predicate: "Descriptive Predicate 1", target: "N3"},
{linkId: "L3", source: "N0", predicate: "Descriptive Predicate 1", target: "N4"}
];
Some very distinct things to keep in mind are the extra attributes in the linkSet, such as the linkId and predicate.
Based on my experience, it appears that JSON structures don't really have a clean way of representing Link attributes like Link identifiers or descriptive predicates all that way. This seems to be reflected in the D3 Tree API.
For example, the D3 Tree API method "tree.nodes(linkSet[0])" will traverse links to create a an array of Nodes, ignoring the original nodeSet and, therefore, creates a whole new Node array (independent of the original nodeSet) that lacks all the other Node related attributes (i.e. "id", "size", and "hlink").
Additionally, the D3 Tree API method "tree.links(nodes)" seems to generate a whole new Links array that is independent of the original linkSet, and that lacks all the other Link related attributes (i.e. "linkId" and "predicate").
My Question: Is there a need for two new Tree API methods, in order to deal with more RDF/OWL-like data structures, that allow a user to "assign predefined" Node and Link arrays, so that other Node and Link related attributes don't get stripped out? In other words, while the methods "tree.nodes(root)" and "tree.links(nodes)" seem to make sense for JSON structures, is there a need for two new API methods? For example:
"tree.usePredefinedNode(nodeSet)" and
"tree.usePredefinedLInks(linkSet)"
Or, is there some better way of using the above data formats that I'm completely missing?
NOTE: I came across this in a RDF/OWL based Tree visualization that I've been working on, where I try to provide RDF/OWL-like data to the tree layout and the existing API loses/ignores the additional Node and Link attributes. In one case, I have a hack that loops through the Tree generated Node array and merges in the lost attributes from the original nodeSet array. I haven't yet figure out how I'm going to cleanly merge in the lost linkSet attributes, yet. This "additional looping" in order to re-merge lost attributes seems wasteful.
NOTE: I believe that if the D3 API were extended to handle these predefined RDF/OWL-like Node and Link arrays, it would be a very natural and very powerful extension for seamlessly interfacing Graph/Network data from RDF/OWL with D3.
Would love to hear your thoughts on this.
Thanks,
Frank