GraphStream
グラフのノード座標を変更する必要があるプロジェクトがあります。
これらの座標は、と呼ばれる変数に格納されます。"xy"
この仕事をする関数は、 または のいずれsetAttribute()
かaddAttribute()
であるはずですが、それらを使用しても何も起こらないか、メッセージが表示されることがありNaN
ます。
これは、まったく変更を加えないコードの例です。
public class TestClass {
public static void main(String[] args) {
Graph graph = new MultiGraph("Dorogovtsev mendes");
Generator gen = new DMCoordGen(); // Coordinates Generator
gen.addSink(graph);
gen.begin();
for (int j = 0; j < 5; j++) { // Graph Nodes
gen.nextEvents();
}
gen.end();
System.out.println("-----------------");
System.out.println("First Coordinates");
System.out.println("-----------------");
for(int i=0; i<graph.getNodeCount(); i++) { // First Reading
Double[] attributes = (Double[]) graph.getNode(i).getAttribute("xy");
Double x = attributes[0];
Double y = attributes[1];
System.out.println(x + " , " + y);
}
System.out.println("---------------");
System.out.println("New Coordinates");
System.out.println("---------------");
for(int i=0; i<graph.getNodeCount(); i++) { // Modification
Double[] attributes = (Double[]) graph.getNode(i).getAttribute("xy");
Double x = attributes[0] * 100;
Double y = attributes[1] * 100;
graph.getNode(i).setAttribute("xy", (Object[]) attributes);
}
for(int i=0; i<graph.getNodeCount(); i++) { // Second Reading
Double[] attributes = (Double[]) graph.getNode(i).getAttribute("xy");
Double x = attributes[0];
Double y = attributes[1];
System.out.println(x + " , " + y);
}
}
}
このコードによって返される結果は次のとおりです。
-----------------
First Coordinates
-----------------
0.27463410536937105 , 0.908142618579691
0.5945324304252239 , 0.011861230502362319
0.7645069243611142 , 0.8994092027470882
0.23856199477010953 , 0.6174255664753833
0.9215549969974312 , 0.46748048612026005
0.5283548936726747 , 0.3995089175747245
0.14035732608566487 , 0.32181008971710223
0.8782155705197804 , 0.8271792979519879
---------------
New Coordinates
---------------
0.27463410536937105 , 0.908142618579691
0.5945324304252239 , 0.011861230502362319
0.7645069243611142 , 0.8994092027470882
0.23856199477010953 , 0.6174255664753833
0.9215549969974312 , 0.46748048612026005
0.5283548936726747 , 0.3995089175747245
0.14035732608566487 , 0.32181008971710223
0.8782155705197804 , 0.8271792979519879
ご覧のとおり、setAttribute()
またはを使用しても何も変更されていませんaddAttribute()
。
行を参照してくださいgraph.getNode(i).setAttribute("xy", (Object[]) attributes);
。
私は何を間違えましたか?どうすれば修正できますか?
ありがとう !