0

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 に関するページにはヒントが見つかりませんでした。

デバッグのイメージ

4

1 に答える 1

0

私は最終的に問題の解決策を見つけました。

エラーは Javascript の部分にありましたが、コンソールに問題が表示されなかった理由がわかりません。とにかく、以下のコードの元の成功関数を置き換えると、問題が解決します。

    function(req)
    {
        var doc = req.getDocumentElement();
        var codec = new mxCodec(doc);
        var elt = doc.firstChild;
        var cells = [];

        while (elt != null)
        {
          cells.push(codec.decode(elt));
          elt = elt.nextSibling;
        }

        graph.addCells(cells);
    }
于 2016-10-29T00:08:57.803 に答える