`

js画图开发库--mxgraph--[serverview-服务器视图.html]

阅读更多

 js画图开发库--mxgraph--[serverview-服务器视图.html] 

 

 

 

<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml>
	<head>
	<meta http-equiv=Content-Type content="text/html;charset=utf-8">
	<title>服务器视图</title>

	<!-- 如果本文件的包与src不是在同一个目录,就要将basepath设置到src目录下 -->
	<script type="text/javascript">
		mxBasePath = '/mxgraph/javascript/src';
	</script>

	<!-- 引入支持库文件 -->
	<script type="text/javascript" src="/mxgraph/javascript/src/js/mxClient.js"></script>

	<!-- 覆盖所需的服务器端的图像要使用的某些方法。-->
	<script type="text/javascript">
		// 编辑器使用非透明背景
		var previousStartEditing = mxCellEditor.prototype.startEditing;
		mxCellEditor.prototype.startEditing = function (cell, trigger)
		{
			previousStartEditing.apply(this, arguments);
	
			var state = this.graph.getView().getState(cell);
	
			if (state != null)
			{
				var color = mxUtils.getValue(state.style, mxConstants.STYLE_FILLCOLOR, 'white');
				this.textarea.style.background = color;
			}
		};
	
		// 替换在图表视图中的事件触发机制
		// FIXME: Since we do not render the label we don't have the label bounds
		// here which means hit detection will only work for the vertex bounds,
		// the edge but not for overlapping labels or most part of the edge labels.
		mxGraphView.prototype.installListeners = function()
		{
			var graph = this.graph;
			var container = graph.container;
			
			if (container != null)
			{
				var md = (mxClient.IS_TOUCH) ? 'touchstart' : 'mousedown';
				var mm = (mxClient.IS_TOUCH) ? 'touchmove' : 'mousemove';
				var mu = (mxClient.IS_TOUCH) ? 'touchend' : 'mouseup';
				
				// Adds basic listeners for graph event dispatching
				mxEvent.addListener(container, md,
					mxUtils.bind(this, function(evt)
					{
						var pt = mxUtils.convertPoint(graph.container,
							mxEvent.getClientX(evt), mxEvent.getClientY(evt));
						var cell = graph.getCellAt(pt.x, pt.y);
						var state = this.getState(cell);

						if (state != null)
						{
							graph.fireMouseEvent(mxEvent.MOUSE_DOWN,
									new mxMouseEvent(evt, state));
						}
						// Condition to avoid scrollbar events starting a rubberband
						// selection
						else if (this.isContainerEvent(evt) &&
							((!mxClient.IS_IE && 
							!mxClient.IS_GC && !mxClient.IS_OP && !mxClient.IS_SF) ||
							!this.isScrollEvent(evt)))
						{
							graph.fireMouseEvent(mxEvent.MOUSE_DOWN,
								new mxMouseEvent(evt));
						}
					})
				);
				mxEvent.addListener(container, mm,
					mxUtils.bind(this, function(evt)
					{
						var pt = mxUtils.convertPoint(graph.container,
							mxEvent.getClientX(evt), mxEvent.getClientY(evt));
						var cell = graph.getCellAt(pt.x, pt.y);
						var state = this.getState(cell);
	
						if (state != null)
						{
							graph.fireMouseEvent(mxEvent.MOUSE_MOVE,
									new mxMouseEvent(evt, state));
						}
						else if (this.isContainerEvent(evt))
						{
							graph.fireMouseEvent(mxEvent.MOUSE_MOVE,
								new mxMouseEvent(evt));
						}
					})
				);
				mxEvent.addListener(container, mu,
					mxUtils.bind(this, function(evt)
					{
						var pt = mxUtils.convertPoint(graph.container,
							mxEvent.getClientX(evt), mxEvent.getClientY(evt));
						var cell = graph.getCellAt(pt.x, pt.y);
						var state = this.getState(cell);
	
						if (state != null)
						{
							graph.fireMouseEvent(mxEvent.MOUSE_UP,
									new mxMouseEvent(evt, state));
						}
						else if (this.isContainerEvent(evt))
						{
							graph.fireMouseEvent(mxEvent.MOUSE_UP,
								new mxMouseEvent(evt));
						}
					})
				);
				
				// 添加双击事件
				mxEvent.addListener(container, 'dblclick',
					mxUtils.bind(this, function(evt)
					{
						var pt = mxUtils.convertPoint(graph.container,
							mxEvent.getClientX(evt), mxEvent.getClientY(evt));
						var cell = graph.getCellAt(pt.x, pt.y);
						
						graph.dblClick(evt, cell);
					})
				);
							
				// 增加了基本的手势的处理侦听器
				mxEvent.addListener(document, md,
					mxUtils.bind(this, function(evt)
					{
						if (this.isContainerEvent(evt))
						{
							graph.panningHandler.hideMenu();
						}
					})
				);
				mxEvent.addListener(document, mm,
					mxUtils.bind(this, function(evt)
					{
						// 鼠标一开容器时隐藏工具提示 
						if (graph.tooltipHandler != null &&
							graph.tooltipHandler.isHideOnHover())
						{
							graph.tooltipHandler.hide();
						}
						
						if (this.captureDocumentGesture &&
							graph.isMouseDown &&
							!mxEvent.isConsumed(evt))
						{
							graph.fireMouseEvent(mxEvent.MOUSE_MOVE,
								new mxMouseEvent(evt));
						}
					})
				);
				mxEvent.addListener(document, mu,
					mxUtils.bind(this, function(evt)
					{
						if (this.captureDocumentGesture)
						{
							graph.fireMouseEvent(mxEvent.MOUSE_UP,
								new mxMouseEvent(evt));
						}
					})
				);
			}
		};
	</script>

	<!-- 示例代码 -->
	<script type="text/javascript">
		//  程序在此方法中启动 
		function main(container)
		{
			// 检查浏览器支持
			if (!mxClient.isBrowserSupported())
			{
				mxUtils.error('Browser is not supported!', 200, false);
			}
			else
			{
				// 在容器中创建图形
				var graph = new mxGraph(container);

				// 保存当前的图像
				var img = null;
				var loader = new Image();
				loader.src = 'images/loading.gif';
				loader.style.zIndex = 1;
				loader.style.visibility = 'hidden';
				loader.style.position = 'absolute';
				
				graph.container.insertBefore(loader, graph.container.firstChild);
				
				// 禁用基于DOM的图形渲染,图形和显示图像的每个验证步骤,使用导出的servlet
				graph.view.rendering = false;
				
				// 图形加载完成后进行重绘验证
				graph.view.validate = function()
				{
					loader.style.left = graph.container.scrollLeft + graph.container.clientWidth / 2 - 32;
					loader.style.top = graph.container.scrollTop + graph.container.clientHeight / 2 - 32;
					loader.style.visibility = 'visible';
					mxGraphView.prototype.validate.apply(this, arguments);

					var t0 = new Date().getTime();
					var bounds = graph.getGraphBounds();

					// 需要注意的是,我们的观点,这使我们能够向客户端发送一个自定义XML文本。没有变量被用在这里,被发送给服务器后更新完整视图。
					var node = mxUtils.getViewXml(graph, 1);
					var xml = encodeURIComponent(mxUtils.getXml(node));

					var onload = function(req)
					{
						var dt = (new Date().getTime() - t0) / 1000;
						//mxLog.debug('post returned after '+dt+' secs');
					
						if (req.getStatus() == 200)
						{
							var image =new Image();

							// 禁用图像打扰事件。提示:IE启动时在图像上的下拉菜单事件被忽略
							if (mxClient.IS_IE)
							{
								graph.view.isContainerEvent = function(evt)
								{
									var source = mxEvent.getSource(evt);
					
									return (source == image ||
										source == this.graph.container ||
										source.parentNode == this.backgroundPane ||
										(source.parentNode != null &&
										source.parentNode.parentNode == this.backgroundPane) ||
										source == this.canvas.parentNode ||
										source == this.canvas ||
										source == this.backgroundPane ||
										source == this.drawPane ||
										source == this.overlayPane);
								};
							}
							
							// 如果旧的图像被删除后新图像从服务器收到后减少闪烁
							image.onload = function()
							{
								if (img != null)
								{
									img.parentNode.removeChild(img);
								}
						
								img = image;
								graph.container.insertBefore(img, graph.container.firstChild);
								loader.style.visibility = 'hidden';
								
								var dt = (new Date().getTime() - t0) / 1000;
								//mxLog.debug('received '+img.clientWidth+'x'+img.clientHeight+' pixels in '+dt+' secs');
								graph.setEnabled(true);
							};

							// URL包含时间戳,以避免缓存在浏览器中
							image.src = '/ServerView?'+new Date().getTime();
							image.style.position = 'absolute';
							image.style.left = bounds.x - 4;
							image.style.top = bounds.y - 4;
							image.style.zIndex = -1;
						}
					};

					var onerror = function(req)
					{
						//mxLog.debug('error: '+req.getStatus());
					}
					
					//mxLog.debug('sent '+(xml.length/1024)+' KB');
					graph.setEnabled(false);
					new mxXmlRequest('/ServerView', 'xml='+xml).send(onload, onerror);
				};

				// 容器自适应
				//graph.setResizeContainer(true);
				
				// Enables rubberband selection
				new mxRubberband(graph);
				graph.setConnectable(true);
				graph.setPanning(true);
				graph.setTooltips(true);
				
				// 创建默认窗体
				var parent = graph.getDefaultParent();
				//mxLog.show();

				// 开启更新事务
				graph.getModel().beginUpdate();
				try
				{
					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, '', v1, v2);
				}
				finally
				{
					// 结束更新事务
					graph.getModel().endUpdate();
				}
			}
		};
	</script>
</head>

<!-- 页面载入时启动程序 -->
<body onload="main(document.getElementById('graphContainer'))">
<!-- 创建带网格壁纸和曲线的一个容器  -->
<div id="graphContainer"
	style="overflow:auto;width:500px;height:500px;border: black solid 1px;cursor:default;">
</div>
<br>
<strong>Important:</strong>
<p>
  To use this example, start com.mxgraph.examples.web.main in Java
  and point your<br>browser to:
  要使用这个例子中,启动com.mxgraph.examples.web.main的Java

  <br>您的浏览器指向到:
  <a href="http://localhost:8080/mxgraph/javascript/examples/serverview.html">http://localhost:8080/mxgraph/javascript/examples/serverview.html</a>
</p>
</body>
</html>

 

 

  • 大小: 6.3 KB
分享到:
评论

相关推荐

    mxgraph.MXGRAPH..MXGRAPH..

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

    mxGraph 1.4.0.0

    资源:mxGraph;包含ie,Firefox两个版本;版本号都是1.4.0.0;只带了一个Hello World的示例,其他的例子请自己去官网找吧

    mxgraph开发包

    mxgraph开发包

    js画图框架--mxgraph--入门

    NULL 博文链接:https://chwshuang.iteye.com/blog/1797168

    mxGraph绘图插件

    mxGraph里头包含源码,以及常用的一些实例,相关介绍可以查阅博客:http://www.cnblogs.com/shawWey/p/7115124.html

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

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

    typed-mxgraph-example-bundled-with-webpack

    带Webpack的typed-mxgraph演示 来自Webpack Typescript入门 如何使用 在本地克隆项目 git clone https://github.com/typed-mxgraph/typed-mxgraph-demo.git 切换到项目目录 cd typed-mxgraph-demo 确保使用节点10...

    mxGraph.zip

    mxGraph 简单易用,只需要在HTML文件中加入JavaScript链接,就可立即使用最简洁最强大的基于浏览器自身的绘图工具。 HTML 5和全系列IE支持。 想像一下,整个应用都是基于Web。在浏览器中设计工作流,操纵有背景图...

    mxGraph\mxclient-1.8.0.3破解

    mxGraph1.8.0.3破解版mxclient,分IE ,FF 和chrome三个部分,不同浏览器加载不同的js文件,手动尝试过,1.8.0.5官方的例子都可以正常运行。

    mxgraph-master.zip

    web开发拓扑图插件 mxGraph - An open source JavaScript diagramming component, started in 2005, that works on all major browsers, including touch devices.

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

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

    mxgraph-svg2shape:mxGraph SVG到Shape的转换工具

    mxgraph-svg2shape 一套将SVG文件转换为mxGraph资源的工具。 该存储库基于: SVG to XML mxGraph stencil definition translation tool. ... 添加 :将XML mxGraph模具定义转换为一组相应JavaScript /

    mxgraph-1_10_4_0

    mxgraph-1_10_4_0 官方源码+文档+示例

    mxgraph-demo-源码.rar

    mxgraph-demo-源码.rar

    在线画图wwwdrawio网站的源码基于mxGraph开发

    在线画图www.draw.io网站的源码,基于mxGraph开发

    vue-mxgraph-example-master (2).zip

    vue配合mxGraph 入门实例项目,

    mxGraph1.9.1.1 mxclient.js破解文件下载

    mxGraph1.9.1.1 mxclient.js破解文件下载 1.找到mxclient.js文件中的这句代码 注释 if ((eval&#40;'/156/145/167/40/104/141/164/145/50/51/56/147/145/164/124/151/155/145/50/51'&#41; / 1000) - 1270532723 &gt;...

    mxGraph绘图软件js库(版本1.9.1.3,破解版)

    十分强大的js绘图工具,适用于设计/编辑 Workflow/BPM 流程图、图表、网络图和普通图形的 Web 应用程序。这是破解过的源js库。

    mxgraph-eval

    mxgraph\.classpath .......\.project .......\ChangeLog .......\docs .......\....\images .......\....\......\MX_MANUAL_html_1cc55dd3.png .......\....\......\MX_MANUAL_html_ba4bf13.png .......\......

    mxgraph.zip

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

Global site tag (gtag.js) - Google Analytics