`
lynnlysh
  • 浏览: 176016 次
  • 性别: Icon_minigender_2
  • 来自: 天津
社区版块
存档分类
最新评论

mxgraph 之 让流程图文件(xml格式)以图的方式显示在面板上

阅读更多
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
5
1
分享到:
评论
10 楼 wf213 2017-09-15  
您好,我用mxgraph画好图之后存到数据库里面了,但是怎么在读取展示出来呢?
9 楼 zxxcjb 2012-06-25  
xml里面有中文,直接解析不出来,怎怒解决呀?
8 楼 lynnlysh 2012-05-30  
hty1902 写道
楼主,我准备用mxgraph画拓扑图,能用你这种方法从数据库读出设备,然后在页面上画出来吗?

mxgraph可以画拓扑图,但不一定用xml代码方式存在后台中.
7 楼 hty1902 2012-03-30  
楼主,我准备用mxgraph画拓扑图,能用你这种方法从数据库读出设备,然后在页面上画出来吗?
6 楼 lynnlysh 2012-02-02  
xiaotiantian-58 写道
楼主你好,我刚开始学习mxgraph,有些问题想请教您,加我吧,我的QQ:734373252

刚开始入门你可以从mxgraph的例子开始学,然后不会的地方看它的docs文件夹中的api文档。它的例子基本涵盖了mxgraph技术的各种应用,并且难度由浅入深。我就是这么学的,比问别人方便。就不加qq了哈 ^_^
5 楼 xiaotiantian-58 2012-01-04  
楼主你好,我刚开始学习mxgraph,有些问题想请教您,加我吧,我的QQ:734373252
4 楼 lynnlysh 2011-09-20  
torch921 写道
大虾,你好,我刚刚开始用mxGraph,有些问题想请教您,能加下QQ么?
我的是39306859

你直接在这问吧,我如果会就回答,不会的话被真正的大虾看到也能帮你解答 ^_^
3 楼 torch921 2011-09-09  
大虾,你好,我刚刚开始用mxGraph,有些问题想请教您,能加下QQ么?
我的是39306859
2 楼 lynnlysh 2011-09-02  
mxgraphShow.html
qikitty 写道
能发我一份源码么?356657939@qq.com

mxgraphShow.html 就是所需源码
新建web项目
将它和mxgraph.xml 放在WebRoot下,然后将附件中的图片放在webRoot/images/start_event_empty.png
下。
启动tomcat服务器 运行mxgraphShow.html页即可
1 楼 qikitty 2011-09-01  
能发我一份源码么?356657939@qq.com

相关推荐

    mxGraph插件,java代码xml导出成图片

    前段实现mxgraph插件绘制流程图,后台实现保存的xml导出成图片格式,遇到图标没有引用,文字label位置不正确,label换行不识别 标签,linux服务器部署中文字体等问题

    mxGraph流程图

    非常酷的Web页面工作流设计器,兼容IE/Firfox浏览器,纯JavaScript程序,无需插件。有例子程序和源码程序。

    mxgraph.zip

    本demo是运用mxgraph.js 和node api 读取xml文件,并解析出来显示,业务上常用这个画流程图和topo状态图;主要适用于,现在的图形可视化操作

    mxgraph流程图绘制

    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_gpx.zip

    基于mxGraph来做的一款web的绘制流程图的javascript库工具

    mxGraph 破解版备份 流程图 绘制

    mxGraph 破解版备份 流程图 绘制

    mxGraph:在HTML页面中制作流程图的JS插件

    这个插件支持在HTML页面中插入流程图,画得很漂亮 :-)

    mxGraph流程图js包

    比较好的javascrip绘制流程图的js脚本。进一步的了解可参考mxGraph的官网~~

    mxgraph svg2xml

    mxgraph自定义图元很难调试,这个工具可以通过svg转为xml ,通过微调达到图元定义的目的

    mxgraph之保存图片

    NULL 博文链接:https://lynnlysh.iteye.com/blog/1290007

    mxGraph JS 绘图组件

    mxGraph 是一个 JS 绘图组件适用于需要在网页中设计/编辑 Workflow/BPM 流  程图、图表、网络图和普通图形的 Web 应用程序。mxgraph 下载包中包括用  javescript 写的前端程序,也包括多个和后端程序(java/C#等等)...

    mxGraph图形嵌入开发

    mxGraph是一个JS绘图组件适用于需要在网页中设计/编辑Workflow/BPM流程图、图表、网络图和普通图形的Web应用程序。mxgraph下载包中包括用javescript写的前端程序,也包括多个和后端程序(java/C#等等)集成的例子。以下...

    svg2xml:SVG到XML mxGraph模具定义转换工具

    SVG到XML mxGraph模具定义转换工具。 它是为内部使用而创建的,因此还有很多未完成的事情。 要编译并运行此程序,请使用ant或以下命令。 编译 mkdir classes javac -d classes -classpath lib/mxgraph-core.jar -...

    mxgraph.MXGRAPH..MXGRAPH..

    MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..

    结合extjs + mxgraph 网络拓扑图的开发

    extJs 跟mxgraph一样都是一种前台框架,可以混着用,这个例子将结合extjs + mxgraph 做网络拓扑图。mxgraph是将html的页面元素当做一个容器(container),并在此容器中画图的,而extJs也是将此容器包装成一个window...

    mxgraph实体关系(ERD)

    mxGraph是一个JS绘图组件适用于需要在网页中设计/编辑Workflow/BPM流程图、图表、网络图和普通图形的Web应用程序。mxgraph下载包中包括用javascript写的前端程序,也包括多个和后端程序(java/C#等)集成的例子。以下是...

    web的绘制流程图的javascript库工具(mxgraph)

    mxGraph是一款基于web的绘制流程图的javascript库工具

    mxgraph-eval-1_5_1_11(流程图表编辑)

    mxGraph是一个JS绘图组件适用于需要在网页中设计/编辑Workflow/BPM流程图、图表、网络图和普通图形的Web应用程序。 基于EXTJS. 此附件版权归原作者所有。

    mxGraph JS绘制流程

    很好的一个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如何实现拓扑图中节点闪烁或节点边框闪烁

    mxgraph如何实现拓扑图中节点闪烁或节点边框闪烁的功能,模拟某些节点出现故障时候图元闪烁。

Global site tag (gtag.js) - Google Analytics