[英]Draw line in mxGraph with XML?
我使用mxGraph 編輯器的此示例
我正在嘗試使用該庫制作梯形圖編輯器,因此我想繪制起點和終點線,但是我需要始終將它們全部作為圖形區域的邊界(每次都從編輯器開始) ,我該怎么做以及如何使它們可連接到元素?
有人可以幫忙嗎?
編輯 :
這段代碼畫了一條線,然后用geometry屬性定位它。
var xml = "<root>"+
"<MyObject id=\"2\">"+
"<mxCell style=\"strokeColor=black;fillColor=black\" parent=\"1\" vertex=\"1\" type = 'startLine'>"+
"<mxGeometry x=\"0\" y=\"0\" width=\"2\" height=\"119\" as=\"geometry\"/>"+
"</mxCell></MyObject></root>";
doc = mxUtils.parseXml(xml),
codec = new mxCodec(doc),
elt = doc.documentElement.firstChild,
cells = [];
while (elt != null){
cells.push(codec.decodeCell(elt));
elt.setAttribute('attribute1', 'value1');
$this.editor.graph.refresh();
elt = elt.nextSibling;
}
$this.editor.graph.addCells(cells);
為了將問題標記為“已回答”,以便其他人可以看到它:
做這個 :
var xml = "<root>"+
"<MyObject id=\"2\">"+
"<mxCell style=\"strokeColor=black;fillColor=black\" parent=\"1\" vertex=\"1\" type = 'startLine'>"+
"<mxGeometry x=\"0\" y=\"0\" width=\"2\" height=\"119\" as=\"geometry\"/>"+
"</mxCell></MyObject></root>";
doc = mxUtils.parseXml(xml),
codec = new mxCodec(doc),
elt = doc.documentElement.firstChild,
cells = [];
while (elt != null){
cells.push(codec.decodeCell(elt));
elt.setAttribute('attribute1', 'value1');
$this.editor.graph.refresh();
elt = elt.nextSibling;
}
$this.editor.graph.addCells(cells);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.