js画图开发库--mxgraph--[swimlanes-泳道图.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 = '../src'; </script> <!-- 引入支持库文件 --> <script type="text/javascript" src="../src/js/mxClient.js"></script> <!-- 示例代码 --> <script type="text/javascript"> // 定义创建新的连接的图标。 // 这将自动禁用高亮显示。 mxConnectionHandler.prototype.connectImage = new mxImage('images/connector.gif', 16, 16); // 程序在此方法中启动 function main(container) { // 检查浏览器支持 if (!mxClient.isBrowserSupported()) { mxUtils.error('Browser is not supported!', 200, false); } else { // 去锯齿效果 mxSwimlane.prototype.crisp = true; // 根据给定的xml文件在容器中创建图形编辑器 var config = mxUtils.load( 'editors/config/keyhandler-commons.xml'). getDocumentElement(); var editor = new mxEditor(config); editor.setGraphContainer(container); var graph = editor.graph; var model = graph.getModel(); //自动调整大小的容器 graph.border = 80; graph.getView().translate = new mxPoint(graph.border/2, graph.border/2); graph.setResizeContainer(true); graph.graphHandler.setRemoveCellsFromParent(false); // 改变默认样式 var style = graph.getStylesheet().getDefaultVertexStyle(); style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_SWIMLANE; style[mxConstants.STYLE_VERTICAL_ALIGN] = 'middle'; style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR] = 'white'; style[mxConstants.STYLE_FONTSIZE] = 11; style[mxConstants.STYLE_STARTSIZE] = 22; style[mxConstants.STYLE_HORIZONTAL] = false; style[mxConstants.STYLE_FONTCOLOR] = 'black'; style[mxConstants.STYLE_STROKECOLOR] = 'black'; delete style[mxConstants.STYLE_FILLCOLOR]; style = mxUtils.clone(style); style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_RECTANGLE; style[mxConstants.STYLE_FONTSIZE] = 10; style[mxConstants.STYLE_ROUNDED] = true; style[mxConstants.STYLE_HORIZONTAL] = true; style[mxConstants.STYLE_VERTICAL_ALIGN] = 'middle'; delete style[mxConstants.STYLE_STARTSIZE]; style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR] = 'none'; graph.getStylesheet().putCellStyle('process', style); style = mxUtils.clone(style); style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_ELLIPSE; style[mxConstants.STYLE_PERIMETER] = mxPerimeter.EllipsePerimeter; delete style[mxConstants.STYLE_ROUNDED]; graph.getStylesheet().putCellStyle('state', style); style = mxUtils.clone(style); style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_RHOMBUS; style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RhombusPerimeter; style[mxConstants.STYLE_VERTICAL_ALIGN] = 'top'; style[mxConstants.STYLE_SPACING_TOP] = 40; style[mxConstants.STYLE_SPACING_RIGHT] = 64; graph.getStylesheet().putCellStyle('condition', style); style = mxUtils.clone(style); style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_DOUBLE_ELLIPSE; style[mxConstants.STYLE_PERIMETER] = mxPerimeter.EllipsePerimeter; style[mxConstants.STYLE_SPACING_TOP] = 28; style[mxConstants.STYLE_FONTSIZE] = 14; style[mxConstants.STYLE_FONTSTYLE] = 1; delete style[mxConstants.STYLE_SPACING_RIGHT]; graph.getStylesheet().putCellStyle('end', style); style = graph.getStylesheet().getDefaultEdgeStyle(); style[mxConstants.STYLE_EDGE] = mxEdgeStyle.ElbowConnector; style[mxConstants.STYLE_ENDARROW] = mxConstants.ARROW_BLOCK; style[mxConstants.STYLE_ROUNDED] = true; style[mxConstants.STYLE_FONTCOLOR] = 'black'; style[mxConstants.STYLE_STROKECOLOR] = 'black'; style = mxUtils.clone(style); style[mxConstants.STYLE_DASHED] = true; style[mxConstants.STYLE_ENDARROW] = mxConstants.ARROW_OPEN; style[mxConstants.STYLE_STARTARROW] = mxConstants.ARROW_OVAL; graph.getStylesheet().putCellStyle('crossover', style); // 双击时改变边框样式 graph.alternateEdgeStyle = 'elbow=vertical'; // 启用了图形添加了自动布局和各种开关 if (graph.isEnabled()) { // Allows new connections but no dangling edges graph.setConnectable(true); graph.setAllowDanglingEdges(false); // End-states are no valid sources var previousIsValidSource = graph.isValidSource; graph.isValidSource = function(cell) { if (previousIsValidSource.apply(this, arguments)) { var style = this.getModel().getStyle(cell); return style == null || !(style == 'end' || style.indexOf('end') == 0); } return false; }; // 判断状态有无合法目标,不执行调用父类的功能,因为这会调用isValidSource graph.isValidTarget = function(cell) { var style = this.getModel().getStyle(cell); return !this.getModel().isEdge(cell) && !this.isSwimlane(cell) && (style == null || !(style == 'state' || style.indexOf('state') == 0)); }; // 可以将新元素转换为新泳道,新泳道为新泳道池 graph.setDropEnabled(true); graph.setSplitEnabled(false); // 有效的拖放操作,则返回true graph.isValidDropTarget = function(target, cells, evt) { if (this.isSplitEnabled() && this.isSplitTarget(target, cells, evt)) { return true; } var model = this.getModel(); var lane = false; var pool = false; var cell = false; // 检查元素是否被选择 for (var i = 0; i < cells.length; i++) { var tmp = model.getParent(cells[i]); lane = lane || this.isPool(tmp); pool = pool || this.isPool(cells[i]); cell = cell || !(lane || pool); } return !pool && cell != lane && ((lane && this.isPool(target)) || (cell && this.isPool(model.getParent(target)))); }; // 添加新的方法识别泳道池 graph.isPool = function(cell) { var model = this.getModel(); var parent = model.getParent(cell); return parent != null && model.getParent(parent) == model.getRoot(); }; //删除元素时清楚泳道 graph.model.getStyle = function(cell) { var style = mxGraphModel.prototype.getStyle.apply(this, arguments); if (graph.isCellCollapsed(cell)) { if (style != null) { style += ';'; } else { style = ''; } style += 'horizontal=1;align=left;spacingLeft=14;'; } return style; }; // 收缩窗体时保持宽度 var foldingHandler = function(sender, evt) { var cells = evt.getProperty('cells'); for (var i = 0; i < cells.length; i++) { var geo = graph.model.getGeometry(cells[i]); if (geo.alternateBounds != null) { geo.width = geo.alternateBounds.width; } } }; graph.addListener(mxEvent.FOLD_CELLS, foldingHandler); } // 父元素和同级元素间跳转大小 new mxSwimlaneManager(graph); // 创建一个堆栈布局 var layout = new mxStackLayout(graph, false); // 确保所有的子元素都适应父泳道 layout.resizeParent = true; // 子元素适用父元素的变化 layout.fill = true; // 仅仅更新泳道的大小 layout.isVertexIgnored = function(vertex) { return !graph.isSwimlane(vertex); } // 保持泳道池与泳道的层叠关系 var layoutMgr = new mxLayoutManager(graph); layoutMgr.getLayout = function(cell) { if (!model.isEdge(cell) && graph.getModel().getChildCount(cell) > 0 && (model.getParent(cell) == model.getRoot() || graph.isPool(cell))) { layout.fill = graph.isPool(cell); return layout; } return null; }; // 创建默认窗体 var parent = graph.getDefaultParent(); // 开启更新事务 model.beginUpdate(); try { var pool1 = graph.insertVertex(parent, null, 'Pool 1', 0, 0, 640, 0); pool1.setConnectable(false); var lane1a = graph.insertVertex(pool1, null, 'Lane A', 0, 0, 640, 110); lane1a.setConnectable(false); var lane1b = graph.insertVertex(pool1, null, 'Lane B', 0, 0, 640, 110); lane1b.setConnectable(false); var pool2 = graph.insertVertex(parent, null, 'Pool 2', 0, 0, 640, 0); pool2.setConnectable(false); var lane2a = graph.insertVertex(pool2, null, 'Lane A', 0, 0, 640, 140); lane2a.setConnectable(false); var lane2b = graph.insertVertex(pool2, null, 'Lane B', 0, 0, 640, 110); lane2b.setConnectable(false); var start1 = graph.insertVertex(lane1a, null, null, 40, 40, 30, 30, 'state'); var end1 = graph.insertVertex(lane1a, null, 'A', 560, 40, 30, 30, 'end'); var step1 = graph.insertVertex(lane1a, null, 'Contact\nProvider', 90, 30, 80, 50, 'process'); var step11 = graph.insertVertex(lane1a, null, 'Complete\nAppropriate\nRequest', 190, 30, 80, 50, 'process'); var step111 = graph.insertVertex(lane1a, null, 'Receive and\nAcknowledge', 385, 30, 80, 50, 'process'); var start2 = graph.insertVertex(lane2b, null, null, 40, 40, 30, 30, 'state'); var step2 = graph.insertVertex(lane2b, null, 'Receive\nRequest', 90, 30, 80, 50, 'process'); var step22 = graph.insertVertex(lane2b, null, 'Refer to Tap\nSystems\nCoordinator', 190, 30, 80, 50, 'process'); var step3 = graph.insertVertex(lane1b, null, 'Request 1st-\nGate\nInformation', 190, 30, 80, 50, 'process'); var step33 = graph.insertVertex(lane1b, null, 'Receive 1st-\nGate\nInformation', 290, 30, 80, 50, 'process'); var step4 = graph.insertVertex(lane2a, null, 'Receive and\nAcknowledge', 290, 20, 80, 50, 'process'); var step44 = graph.insertVertex(lane2a, null, 'Contract\nConstraints?', 400, 20, 50, 50, 'condition'); var step444 = graph.insertVertex(lane2a, null, 'Tap for gas\ndelivery?', 480, 20, 50, 50, 'condition'); var end2 = graph.insertVertex(lane2a, null, 'B', 560, 30, 30, 30, 'end'); var end3 = graph.insertVertex(lane2a, null, 'C', 560, 84, 30, 30, 'end'); var e = null; graph.insertEdge(lane1a, null, null, start1, step1); graph.insertEdge(lane1a, null, null, step1, step11); graph.insertEdge(lane1a, null, null, step11, step111); graph.insertEdge(lane2b, null, null, start2, step2); graph.insertEdge(lane2b, null, null, step2, step22); graph.insertEdge(parent, null, null, step22, step3); graph.insertEdge(lane1b, null, null, step3, step33); graph.insertEdge(lane2a, null, null, step4, step44); graph.insertEdge(lane2a, null, 'No', step44, step444, 'verticalAlign=bottom'); graph.insertEdge(parent, null, 'Yes', step44, step111, 'verticalAlign=bottom;horizontal=0'); graph.insertEdge(lane2a, null, 'Yes', step444, end2, 'verticalAlign=bottom'); e = graph.insertEdge(lane2a, null, 'No', step444, end3, 'verticalAlign=top'); e.geometry.points = [new mxPoint(step444.geometry.x + step444.geometry.width / 2, end3.geometry.y + end3.geometry.height / 2)]; graph.insertEdge(parent, null, null, step1, step2, 'crossover'); graph.insertEdge(parent, null, null, step3, step11, 'crossover'); e = graph.insertEdge(lane1a, null, null, step11, step33, 'crossover'); e.geometry.points = [new mxPoint(step33.geometry.x + step33.geometry.width / 2 + 20, step11.geometry.y + step11.geometry.height * 4 / 5)]; graph.insertEdge(parent, null, null, step33, step4); graph.insertEdge(lane1a, null, null, step111, end1); } finally { // 结束更新事务 model.endUpdate(); } } }; </script> </head> <!-- 页面载入时启动程序 --> <body onload="main(document.getElementById('graphContainer'))"> <div id="graphContainer" style="position:absolute;overflow:hidden;top:40px;left:40px;width:600px;height:400px;border: gray dotted 1px;cursor:default;"> </div> </body> </html>
相关推荐
MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..MXGRAPH..
资源:mxGraph;包含ie,Firefox两个版本;版本号都是1.4.0.0;只带了一个Hello World的示例,其他的例子请自己去官网找吧
mxgraph开发包
NULL 博文链接:https://chwshuang.iteye.com/blog/1797168
mxGraph里头包含源码,以及常用的一些实例,相关介绍可以查阅博客:http://www.cnblogs.com/shawWey/p/7115124.html
这个插件支持在HTML页面中插入流程图,画得很漂亮 :-)
带Webpack的typed-mxgraph演示 来自Webpack Typescript入门 如何使用 在本地克隆项目 git clone https://github.com/typed-mxgraph/typed-mxgraph-demo.git 切换到项目目录 cd typed-mxgraph-demo 确保使用节点10...
前段实现mxgraph插件绘制流程图,后台实现保存的xml导出成图片格式,遇到图标没有引用,文字label位置不正确,label换行不识别 标签,linux服务器部署中文字体等问题
mxGraph 简单易用,只需要在HTML文件中加入JavaScript链接,就可立即使用最简洁最强大的基于浏览器自身的绘图工具。 HTML 5和全系列IE支持。 想像一下,整个应用都是基于Web。在浏览器中设计工作流,操纵有背景图...
mxGraph1.8.0.3破解版mxclient,分IE ,FF 和chrome三个部分,不同浏览器加载不同的js文件,手动尝试过,1.8.0.5官方的例子都可以正常运行。
web开发拓扑图插件 mxGraph - An open source JavaScript diagramming component, started in 2005, that works on all major browsers, including touch devices.
mxgraph-svg2shape 一套将SVG文件转换为mxGraph资源的工具。 该存储库基于: SVG to XML mxGraph stencil definition translation tool. ... 添加 :将XML mxGraph模具定义转换为一组相应JavaScript /
mxGraph 是一个 JS 绘图组件适用于需要在网页中设计/编辑 Workflow/BPM 流 程图、图表、网络图和普通图形的 Web 应用程序。mxgraph 下载包中包括用 javescript 写的前端程序,也包括多个和后端程序(java/C#等等)...
十分强大的js绘图工具,适用于设计/编辑 Workflow/BPM 流程图、图表、网络图和普通图形的 Web 应用程序。这是破解过的源js库。
mxgraph-1_10_4_0 官方源码+文档+示例
mxgraph-demo-源码.rar
vue配合mxGraph 入门实例项目,
本demo是运用mxgraph.js 和node api 读取xml文件,并解析出来显示,业务上常用这个画流程图和topo状态图;主要适用于,现在的图形可视化操作
比较好的javascrip绘制流程图的js脚本。进一步的了解可参考mxGraph的官网~~
在线画图www.draw.io网站的源码,基于mxGraph开发