[英]Display diagram in mxGraph with the help of xml
图表(带有 xml)与我在 mxGraph 工具的帮助下创建的图表不完全相同,我正在使用以下代码创建图表:
我使用 mxGraph 工具创建了如下图表:
到目前为止,我将 xml 保存在 localstorage 中,并且从 xml 我执行了以下代码以在我的一个 div 容器中显示图表,如下所示:
let xml = '<mxGraphModel dx="963" dy="318" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="2" value="" style="shape=mxgraph.basic.t2;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;strokeWidth=2" vertex="1" parent="1"><mxGeometry x="30" y="30" width="79" height="267" as="geometry"/></mxCell><mxCell id="3" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1"><mxGeometry x="470" y="80" width="140" height="120" as="geometry"/></mxCell><mxCell id="4" value="" style="shape=internalStorage;whiteSpace=wrap;html=1;backgroundOutline=1;" vertex="1" parent="1"><mxGeometry x="300" y="40" width="80" height="80" as="geometry"/></mxCell><mxCell id="5" value="" style="ellipse;shape=cloud;whiteSpace=wrap;html=1;" vertex="1" parent="1"><mxGeometry x="220" y="230" width="120" height="80" as="geometry"/></mxCell></root></mxGraphModel>';
let doc = mxUtils.parseXml(xml);
let codec = new mxCodec(doc);
codec.decode(doc.documentElement, graph.getModel());
let elt = doc.documentElement.firstChild;
let cells = [];
while (elt != null)
{
let cell = codec.decode(elt)
if(cell != undefined){
if(cell.id != undefined && cell.parent != undefined && (cell.id == cell.parent)){
elt = elt.nextSibling;
continue;
}
cells.push(cell);
}
elt = elt.nextSibling;
}
graph.addCells(cells);
下面的输出是从上面的代码中生成的:
所以问题是我想显示与我创建的完全相同的图表,但它只显示对象的形状。
核心 mxGraph 库不理解 3 个不正确形状的形状样式。 这些是在GraphEditor的图中定义的。 例如,请参阅umlActor 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.