mxgraph有encode 和decode方法,既然可以通过encode编码为xml文件:
var encoder = new mxCodec();
var node = encoder.encode(graph.getModel());
那么解码成图像也可以实现:
var req = mxUtils.load('jbpm/mxgraph.xml');
var root = req.getDocumentElement();
var dec = new mxCodec(root);
dec.decode(root, graph.getModel());
graph.getModel().endUpdate();
需要注意的是:
mxgraph.xml中自定义的style在这个解码图像的js中也要写一遍,如:
var style = new Object();
style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_IMAGE;
style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RectanglePerimeter;
style[mxConstants.STYLE_IMAGE] = 'editors/images/bigicon/start_event_empty.png';
style[mxConstants.STYLE_IMAGE_WIDTH] = '48';
style[mxConstants.STYLE_IMAGE_HEIGHT] = '48';
style[mxConstants.STYLE_FONTCOLOR] = '#000000';
style[mxConstants.STYLE_VERTICAL_LABEL_POSITION] = mxConstants.ALIGN_CENTER;
graph.getStylesheet().putCellStyle('start-s', style);
完整的一个显示xml流程图的代码:
mxgraphShow.html
<!--
$Id: uiconfig.html,v 1.6 2010-01-02 09:45:14 gaudenz Exp $
Copyright (c) 2006-2010, JGraph Ltd
UIConfig example for mxGraph. This example demonstrates using a config
file to configure the toolbar and popup menu in mxEditor.
-->
<html>
<head>
<title>UIConfig example</title>
<!-- Sets the basepath for the library if not in same directory -->
<!-- Loads and initiaizes the library -->
<link rel="stylesheet" type="text/css" href="ext-3.3.0/resources/css/ext-all.css" />
<script type="text/javascript" src="ext-3.3.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.3.0/ext-all.js"></script>
<script type="text/javascript">
mxBasePath = 'ext-3.3.0/src';
</script>
<!-- Loads and initiaizes the library -->
<script type="text/javascript" src="ext-3.3.0/mxclient-chrome.js"></script>
<script type="text/javascript" src="ext-3.3.0/mxclient-ff.js"></script>
<script type="text/javascript" src="ext-3.3.0/mxclient-ie.js"></script>
<!-- Example code -->
<script type="text/javascript">
// Program starts here. Creates a sample graph in the
// DOM node with the specified ID. This function is invoked
// from the onLoad event handler of the document (see below).
function main()
{
// Checks if the browser is supported
if (!mxClient.isBrowserSupported())
{
// Displays an error message if the browser is not supported.
mxUtils.error('Browser is not supported!', 200, false);
}
else
{
var container = document.getElementById('lala');
container.style.position = 'absolute';
container.style.overflow = 'hidden';
container.style.left = '0px';
container.style.top = '0px';
container.style.right = '0px';
container.style.bottom = '0px';
document.body.appendChild(container);
var model = new mxGraphModel();
var graph = new mxGraph(container, model);
var style = new Object();
style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_IMAGE;
style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RectanglePerimeter;
style[mxConstants.STYLE_IMAGE] = 'images/start_event_empty.png';
style[mxConstants.STYLE_IMAGE_WIDTH] = '48';
style[mxConstants.STYLE_IMAGE_HEIGHT] = '48';
style[mxConstants.STYLE_FONTCOLOR] = '#000000';
style[mxConstants.STYLE_VERTICAL_LABEL_POSITION] = mxConstants.ALIGN_CENTER;
graph.getStylesheet().putCellStyle('start-s', style);
graph.getModel().beginUpdate();
var req = mxUtils.load('mxgraph.xml');
var root = req.getDocumentElement();
var dec = new mxCodec(root);
dec.decode(root, graph.getModel());
graph.getModel().endUpdate();
}
}
</script>
</head>
<!-- Page passes the container for the graph to the grogram -->
<body onload="main();" style="margin:0px;">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div id="lala"></div></td></tr>
</table>
</body>
</html>
mxgraph.xml
<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" style="start-s" vertex="1" parent="1">
<mxGeometry x="130" y="40" width="60" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
将附件中图片放在webRoot/images/start_event_empty.png
*******************结束的格叽格叽************************
感动比不上心动,Lysh,你心动过么?
- 大小: 1.9 KB
分享到:
相关推荐
前段实现mxgraph插件绘制流程图,后台实现保存的xml导出成图片格式,遇到图标没有引用,文字label位置不正确,label换行不识别 标签,linux服务器部署中文字体等问题
非常酷的Web页面工作流设计器,兼容IE/Firfox浏览器,纯JavaScript程序,无需插件。有例子程序和源码程序。
本demo是运用mxgraph.js 和node api 读取xml文件,并解析出来显示,业务上常用这个画流程图和topo状态图;主要适用于,现在的图形可视化操作
Based on the latest web technologies, mxGraph is the ultimate component for drawing diagrams in a browser. Using open standards, mxGraph does not depend on any third-party plugins and proprietary ...
基于mxGraph来做的一款web的绘制流程图的javascript库工具
mxGraph 破解版备份 流程图 绘制
这个插件支持在HTML页面中插入流程图,画得很漂亮 :-)
比较好的javascrip绘制流程图的js脚本。进一步的了解可参考mxGraph的官网~~
mxgraph自定义图元很难调试,这个工具可以通过svg转为xml ,通过微调达到图元定义的目的
NULL 博文链接:https://lynnlysh.iteye.com/blog/1290007
mxGraph 是一个 JS 绘图组件适用于需要在网页中设计/编辑 Workflow/BPM 流 程图、图表、网络图和普通图形的 Web 应用程序。mxgraph 下载包中包括用 javescript 写的前端程序,也包括多个和后端程序(java/C#等等)...
mxGraph是一个JS绘图组件适用于需要在网页中设计/编辑Workflow/BPM流程图、图表、网络图和普通图形的Web应用程序。mxgraph下载包中包括用javescript写的前端程序,也包括多个和后端程序(java/C#等等)集成的例子。以下...
SVG到XML mxGraph模具定义转换工具。 它是为内部使用而创建的,因此还有很多未完成的事情。 要编译并运行此程序,请使用ant或以下命令。 编译 mkdir classes javac -d classes -classpath lib/mxgraph-core.jar -...
MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..
extJs 跟mxgraph一样都是一种前台框架,可以混着用,这个例子将结合extjs + mxgraph 做网络拓扑图。mxgraph是将html的页面元素当做一个容器(container),并在此容器中画图的,而extJs也是将此容器包装成一个window...
mxGraph是一个JS绘图组件适用于需要在网页中设计/编辑Workflow/BPM流程图、图表、网络图和普通图形的Web应用程序。mxgraph下载包中包括用javascript写的前端程序,也包括多个和后端程序(java/C#等)集成的例子。以下是...
mxGraph是一款基于web的绘制流程图的javascript库工具
mxGraph是一个JS绘图组件适用于需要在网页中设计/编辑Workflow/BPM流程图、图表、网络图和普通图形的Web应用程序。 基于EXTJS. 此附件版权归原作者所有。
很好的一个JS绘图库 var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30); var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30); var e1 = graph.insertEdge(parent, null,...
mxgraph如何实现拓扑图中节点闪烁或节点边框闪烁的功能,模拟某些节点出现故障时候图元闪烁。