js画图开发库--mxgraph--[perimeter-边界.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{// 去锯齿效果 in SVGmxRectangleShape.prototype.crisp = true;// 重定向周边的标签界限边缘和标签之间的交点mxGraphViewGetPerimeterPoint = mxGraphView.prototype.getPerimeterPoint;mxGraphView.prototype.getPerimeterPoint = function(terminal, next, orthogonal, border){var point = mxGraphViewGetPerimeterPoint.apply(this, arguments);if (point != null){var perimeter = this.getPerimeterFunction(terminal);if (terminal.text != null && terminal.text.boundingBox != null){// 添加标签的边界var b = terminal.text.boundingBox.clone();b.grow(3)if (mxUtils.rectangleIntersectsSegment(b, point, next)){point = perimeter(b, terminal, next, orthogonal);}}}return point;};// 在容器中创建图形var graph = new mxGraph(container);graph.setVertexLabelsMovable(true);graph.setConnectable(true);// 容器大小自动变化//graph.setResizeContainer(true);// 浏览器默认右键菜单new mxRubberband(graph);// 创建默认窗体var parent = graph.getDefaultParent();// 开启更新事务graph.getModel().beginUpdate();try{var v1 = graph.insertVertex(parent, null, 'Label', 20, 20, 80, 30, 'verticalLabelPosition=bottom');var v2 = graph.insertVertex(parent, null, 'Label', 200, 20, 80, 30, 'verticalLabelPosition=bottom');var v3 = graph.insertVertex(parent, null, 'Label', 20, 150, 80, 30, 'verticalLabelPosition=bottom');var e1 = graph.insertEdge(parent, null, '', v1, v2);var e1 = graph.insertEdge(parent, null, '', v1, v3);}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>
?
?