2017-10-12 93 views
0

我正尝试使用JavaScript将mxGraph的XML图转换为SVG。有了XML字符串,我需要将它解析为SVG,以便进一步分发给html。 This post显示我需要做什么与solution implemented in Java。我可以将XML解析为图形,并且无法将图形渲染为SVG,似乎无法找到与mxCellRenderer.js中的drawCells()方法等效的方法。在mxGraph中将XML转换为SVG javascript

任何人都可以使用JavaScript(可用的mxGraph库)将XML转换为SVG吗?

回答

1

为我工作的解决方案:

数据 - 表示mxGraphModel XML

var doc = mxUtils.parseXml(data); // parse XML into document 
var graph = new Graph(container, null, null, null, null); // create Graph instance, container is an HTML element where the SVG will be exported 
var outputSvg = graph.getSvg("#FFFFFF", 1, null, null, true, null, null); 

的最终输出是可以被包括HTML文档中的SVG对象:

document.getElementById('divForSvg').appendChild(outputSvg); 

检查Graph.js一个getSvg()方法的细节。

1

搜索setGraphXml函数是在mxGraph的(在editor.js内)

的graphEditor例如这将读取XML和使得它在图形上