Forums

Full Version: Problem in NodeLink TreeLayout
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to create a graph using GraphML with NodeLinkTreeLayout

Code:
<graphml>
  <key id="d0" for="node" attr.name="name" attr.type="string">
    <default>unknown</default>
  </key>
  <graph id="G" edgedefault="directed">
    <node id="n4">
        <data key="d0">n4</data>
    </node>
    <node id="n6">
        <data key="d0">n6</data>
    </node>
    <node id="n2">
        <data key="d0">n2</data>
    </node>
    <node id="n3">
        <data key="d0">n3</data>
    </node>
    <node id="n5">
        <data key="d0">n5</data>
    </node>
    <edge directed="true" source="n2" target="n4"/>
    <edge directed="true" source="n3" target="n4"/>
    <edge directed="true" source="n4" target="n6"/>
    <edge directed="true" source="n5" target="n6"/>
  </graph>
</graphml>

and I am getting my Output rendered wrongly

I am getting node 'n4' at top while i am expecting 'n6' at top.

if I change the GraphML to

Code:
<graphml>
  <key id="d0" for="node" attr.name="name" attr.type="string">
    <default>unknown</default>
  </key>
  <graph id="G" edgedefault="directed">
    <node id="n6">
        <data key="d0">n6</data>
    </node>
    <node id="n4">
        <data key="d0">n4</data>
    </node>
    <node id="n2">
        <data key="d0">n2</data>
    </node>
    <node id="n3">
        <data key="d0">n3</data>
    </node>
    <node id="n5">
        <data key="d0">n5</data>
    </node>
    <edge directed="true" source="n2" target="n4"/>
    <edge directed="true" source="n3" target="n4"/>
    <edge directed="true" source="n4" target="n6"/>
    <edge directed="true" source="n5" target="n6"/>
  </graph>
</graphml>

I am getting my graph rendered correctly.

Does Flare take the first node given in the graphML to be root node?

Is there any way for me to render my graph the way I want without changing the graphML
Good morning Codebreaker.

If I am not complete confused this morning (which happens ...) then first of all you switched source and target. The root would be the source without being any target of another node. Apart from that since you have a graph (and not a tree) as structure when you use the GraphMLReader (which includes trees but is handled differently form layouts) the NodeLinkTreeLayout will compute the "spanning tree" of the graph using as root whatever is defined as the layout root. If not set explicitly, this just happens to be the first node. So you have to tell the layout that it should use the node n6 as layout root,
Code:
YourLayout.layoutRoot = YourNodeN6;
The computation of the spanning tree of a graph doesn't "care" about the direction of the edges in the graph, so for that matter the source/target switch has no effect for the resulting spanning tree.

The other option I see is using the TreeMLReader which creates a tree and not a graph, but then you have to use the treeml xml format rather than the graphml format (which is different)

Hope that helps

martin
Martin,

Thanks for your reply.I now got the problem.I have a DAG which I want represent in some format like Node link tree layout.I there any chance that I will get a layout like that?

Thanks,
Jaga
Hi Jaga

DAG = Directed acyclic graph?

As far as I know there is no layout for this type of graph neither in flare nor in java prefuse. Nevertheless somebody did something in that direction on top of flare before so maybe you can contact him

http://goosebumps4all.net/34all/bb/showt...hp?tid=135

and

http://sourceforge.net/forum/message.php?msg_id=4909516

Unfortunately a commercial project so the complete source couldn't be published.

cheers

martin
Reference URL's