0

Each time I convert graph object to dot language using approach shown below - the order of siblings is lost. Is there any way to avoid this?

StringWriter theGraph = new StringWriter();
graph.printGraph(theGraph);
theGraph.toString();

Update:

My program generates graphs and displays them in java applet. In order to have them formatted I use GrappaSupport.filterGraph function to feed non formatted graph to dot.exe and get back formatted graph. The function returns a graph object. However to send graph to applet I need to display it as string so I convert it back to dot language (using code given above).

Graph generated by my program:

digraph "Graph" { 
    i168CF2[label="PROPERTY\n(2-cur.)" ]
    i168D02[style=filled, label="NAME\n(2-9, 13-cur.)", color=palegreen ]
    i168CF2->i168D02 
    i168D010[style=filled, label="NAME\n(10-12)", color=lightgrey ]
    i168CF2->i168D010 [color=lightgrey] 
    i168D22[style=filled, label="TEXT\n(2-9)", color=lightgrey ]
    i168CF2->i168D22 [color=lightgrey] 
    i168D210[style=filled, label="TEXT\n(10, 12-cur.)", color=palegreen ] 
    i168CF2->i168D210 
    i168D211[style=filled, label="TEXT\n(11)", color=lightgrey ] 
    i168CF2->i168D211 [color=lightgrey]  
}

Layouted by dot.exe and converted back to dot language graph:

digraph "Graph" {
    graph [bb = "0,0,552,144"];
    i168D22 [
        height = "0.74639",
        style = filled,
        color = lightgray,
        width = "1.0344",
        label = "TEXT\n(2-9)",
        pos = "37,27"
    ];
    i168CF2 [
        height = "0.74639",
        width = "1.7589",
        label = "PROPERTY\n(2-cur.)",
        pos = "250,117"
     ];
    i168D211 [
        height = "0.74639",
        style = filled,
        color = lightgray,
        width = "1.0344",
        label = "TEXT\n(11)",
        pos = "130,27"
    ];
    i168D02 [
        height = "0.74639",
        style = filled,
        color = palegreen,
        width = "1.7826",
        label = "NAME\n(2-9, 13-cur.)",
        pos = "250,27"
    ];
    i168D210 [
        height = "0.74639",
        style = filled,
        color = palegreen,
        width = "1.6779",
        label = "TEXT\n(10, 12-cur.)",
        pos = "393,27"
    ];
    i168D010 [
        height = "0.74639",
        style = filled,
        color = lightgray,
        width = "1.1153",
        label = "NAME\n(10-12)",
        pos = "512,27"
    ];
    i168CF2 -> i168D010 [
        color = lightgray,
        pos = "e,481.77,44.917 304.57,103.17 347.98,92.22409.87,74.943462,54465.47,52.605 469.02,51.046 472.55,49.404"
    ];
    i168CF2 -> i168D210 [
            pos = "e,358.38,49.305 284.98,94.473 304.52,82.452 329.02,67.371 349.75,54.614"
    ];
    i168CF2 -> i168D22 [
            color = lightgray,
            pos = "e,65.486,44.636 200.92,99.814 167.46,88.26 122.43,71.686 84,54 80.855,52.553 77.634,50.978 74.425,49.344"
    ];
    i168CF2 -> i168D211 [
            color = lightgray,
            pos = "e,155.54,46.726 219.1,93.338 202.15,80.909 181.11,65.483 163.74,52.741"
    ];
    i168CF2 -> i168D02 [
            pos = "e,250,54.046 250,90.073 250,81.999 250,72.943 250,64.296"
    ];

}

As you can see order of node's i168CF2 children changed from: i168D02, i168D010, i168D22, i168D210, i168D211

To: i168D22, i168D211, i168D02, i168D210, i168D010

Is there any way to avoid this? This shuffle takes place during conversation from graph object to dot language not during automated layout using dot.exe (it returns the same order).

M T
  • 968
  • 1
  • 8
  • 24
  • Do you expect we can reproduce your problem with this code snippet? – Thor Jun 01 '12 at 08:37
  • The problem is that the sequence of the input nodes is not preserved after conversation (I pasted code to show what conversation I use, maybe there are some other ways) and siblings order is different than it was initially. Maybe there exist some parameters that explicitly define the order of the siblings in directional graph? – M T Jun 01 '12 at 10:24
  • Can you show this with a `.dot` file? – Thor Jun 01 '12 at 10:34
  • You can look at http://stackoverflow.com/questions/16637305/children-order-in-graphviz-tree/18960111#18960111 for a solution to a similar question. – Pekka Sep 23 '13 at 13:32

1 Answers1

0

This probably won't resolve your problem, but just in case: if your goal is to prettify dot graphs, you may consider using dot with the output format canon. From the documentation:

Using canon produces a prettyprinted version of the input, with no layout performed.

This transformation respects the order of appearance of the nodes.

marapet
  • 54,856
  • 12
  • 170
  • 184