?js画图开发库--mxgraph--[fixedpoints-固定点.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"> //程序在此启动 function main(container) { // 检测浏览器兼容性 if (!mxClient.isBrowserSupported()) { mxUtils.error('Browser is not supported!', 200, false); } else { // 去锯齿效果 mxRectangleShape.prototype.crisp = true; // 在容器中创建图形 var graph = new mxGraph(container); graph.setConnectable(true); graph.getAllConnectionConstraints = function(terminal) { if (terminal != null && this.model.isVertex(terminal.cell)) { return [new mxConnectionConstraint(new mxPoint(0, 0), true), new mxConnectionConstraint(new mxPoint(0.5, 0), true), new mxConnectionConstraint(new mxPoint(1, 0), true), new mxConnectionConstraint(new mxPoint(0, 0.5), true), new mxConnectionConstraint(new mxPoint(1, 0.5), true), new mxConnectionConstraint(new mxPoint(0, 1), true), new mxConnectionConstraint(new mxPoint(0.5, 1), true), new mxConnectionConstraint(new mxPoint(1, 1), true)]; } return null; }; // 连线预览 graph.connectionHandler.createEdgeState = function(me) { var edge = graph.createEdge(null, null, null, null, null, 'edgeStyle=elbowEdgeStyle'); return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge)); }; // 禁止浮动连接 graph.connectionHandler.isConnectableCell = function(cell) { return false; }; mxEdgeHandler.prototype.isConnectableCell = function(cell) { return graph.connectionHandler.isConnectableCell(cell); }; // 启用浏览器默认右键下拉列表 new mxRubberband(graph); // 创建默认窗口 var parent = graph.getDefaultParent(); // 开启更新事务 graph.getModel().beginUpdate(); try { var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 60, 'shape=triangle;perimeter=trianglePerimeter'); var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 60, 'shape=ellipse;perimeter=ellipsePerimeter'); var v3 = graph.insertVertex(parent, null, 'Hello,', 200, 20, 80, 30); var e1 = graph.insertEdge(parent, null, '', v1, v2, 'edgeStyle=elbowEdgeStyle;elbow=horizontal;'+ 'exitX=0.5;exitY=1;exitPerimeter=1;entryX=0;entryY=0;entryPerimeter=1;'); var e2 = graph.insertEdge(parent, null, '', v3, v2, 'edgeStyle=elbowEdgeStyle;elbow=horizontal;orthogonal=0;'+ 'entryX=0;entryY=0;entryPerimeter=1;'); } finally { // 结束更新事务 graph.getModel().endUpdate(); } } }; </script> </head> <!-- 页面载入时启动程序 --> <body onload="main(document.getElementById('graphContainer'))"> <!-- 创建带网格壁纸和曲线的一个容器 --> <div id="graphContainer" style="overflow:hidden;position:relative;width:321px;height:241px;background:url('editors/images/grid.gif');cursor:default;"> </div> </body> </html>
?
?
?