每次使用下面显示的方法将图形对象转换为点语言时 - 兄弟姐妹的顺序都会丢失。有什么方法可以避免这种情况吗?
StringWriter theGraph = new StringWriter();
graph.printGraph(theGraph);
theGraph.toString();
更新
我的程序生成图形并在java applet中显示它们。为了让它们格式化,我使用GrappaSupport.filterGraph函数将非格式化图形提供给dot.exe并返回格式化图形。该函数返回一个图形对象。但是要将图形发送到applet,我需要将其显示为字符串,以便将其转换回点语言(使用上面给出的代码)。
我的程序生成的图表:
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的自动布局期间(它返回相同的顺序)。
答案 0 :(得分:0)
这可能无法解决您的问题,但以防万一:如果您的目标是美化点图,您可以考虑将dot
与输出格式{{1}一起使用}。来自documentation:
使用canon生成一个漂亮的输入版本,不执行任何布局。
此转换遵循节点的出现顺序。