mxGraphを使用して、Web ページに描画可能な領域を作成しています。
これはレガシー コードであり、この領域にはグリッド以外の画像が表示されていないため、理解しようとしています。
簡単な図を表示するための私のJavaScriptコードは次のとおりです
//define a window to show the image and put a grid as background
container.style.background = 'url("js/src/images/grid.gif")';
//some other definitions here
var model = new mxGraphModel();
var graph = new mxGraph(container, model);
var id = _GET("id");
mxUtils.post("../Diagram",
"action=get&id="+id,
function(req)
{
var node = req.getDocumentElement();
var dec = new mxCodec(node.ownerDocument);
dec.decode(node, graph.getModel());
},
function(error){
console.log("Error in the design area");
console.log(error);
});
これ../Diagram
は、以下に示すサーブレット Java です。
try {
BufferedReader buffRead = new BufferedReader(new FileReader("/home/glassfish/mySite/Repository/"+getId()+"/"+getName()+".txt"));
String line = "";
while (true) {
if (line != null) {
file = line;
} else {
break;
}
line = buffRead.readLine();
}
buffRead.close();
} catch(Exception e) {
System.out.println("File not found");
}
return file;
返される XML (ファイル) は次のようになります。
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" parent="1" style="shape=ellipse;fillColor=#33CCFF" value="Objective" vertex="1">
<mxGeometry as="geometry" height="40" width="100" x="262" y="90"/>
</mxCell>
</root>
ただし、画面の結果は常にグリッドのみです
行をデバッグして値dec.decode(node, graph.getModel());
を確認するnode
と、Java から返された情報を含む XML オブジェクトを取得しました。
Chrome ではコンソールにメッセージが表示されませんが、Firefox でテストすると、「graph.properties ファイルに XML 解析エラーがある」という警告が表示されますが、このファイルは XML ではありません (実際には、このファイルが何であるかわかりません)。ここにもファイルを貼り付けています
グラフのプロパティ
alreadyConnected=Nodes already connected
containsValidationErrors=Contains validation errors
updatingDocument=Updating Document. Please wait...
updatingSelection=Updating Selection. Please wait...
collapse-expand=Collapse/Expand
doubleClickOrientation=Doubleclick to change orientation
close=Close
error=Error
done=Done
cancel=Cancel
ok=OK
アップデート
まだ問題は解決していませんが、新たな証拠が得られました。
行をデバッグするdec.decode(node, graph.getModel());
と、変数に 2 つのプロパティがありdec
ます。XMLDocument と空の配列。問題はエンコーディング部分にあると思いますが、mxCodec に関するページにはヒントが見つかりませんでした。