每次我使用下面显示的方法将图形对象转换为点语言时 - 兄弟姐妹的顺序都会丢失。有没有办法避免这种情况?
StringWriter theGraph = new StringWriter();
graph.printGraph(theGraph);
theGraph.toString();
更新:
我的程序生成图形并在 java 小程序中显示它们。为了使它们格式化,我使用 GrappaSupport.filterGraph 函数将非格式化图形提供给 dot.exe 并取回格式化图形。该函数返回一个图形对象。但是,要将图形发送到小程序,我需要将其显示为字符串,因此我将其转换回点语言(使用上面给出的代码)。
我的程序生成的图表:
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]
}
由 dot.exe 布局并转换回点语言图:
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"
];
}
如您所见,节点的 i168CF2 子节点的顺序从: i168D02、i168D010、i168D22、i168D210、i168D211
至: i168D22、i168D211、i168D02、i168D210、i168D010
有没有办法避免这种情况?这种洗牌发生在从图形对象到点语言的对话期间,而不是在使用 dot.exe 的自动布局期间(它返回相同的顺序)。