【From】 http://chwshuang.iteye.com/blog/1797740

布局变化,下方还有动画效果选项:

<!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
{
// 在容器中创建图形
var graph = new mxGraph(container); // 禁用选择和单元格处理
graph.setEnabled(false); // 更改点风格的样式
var style = graph.getStylesheet().getDefaultVertexStyle();
style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_ELLIPSE;
style[mxConstants.STYLE_PERIMETER] = mxPerimeter.EllipsePerimeter;
style[mxConstants.STYLE_GRADIENTCOLOR] = 'white';
style[mxConstants.STYLE_FONTSIZE] = '10'; // 设置容器随内容自适应
//graph.setResizeContainer(true); // 设置图大小
graph.gridSize = 40; // 创建默认窗体
var parent = graph.getDefaultParent(); // 创建新的布局算法
var layout = new mxFastOrganicLayout(graph); // 移动距离
layout.forceConstant = 80; // 动画效果选项
var animate = document.getElementById('animate'); // 添加按钮来更新布局
document.body.insertBefore(mxUtils.button('圆形布局Circle Layout',
function(evt)
{
graph.getModel().beginUpdate();
try
{
// 创建圆形布局算法
var circleLayout = new mxCircleLayout(graph);
circleLayout.execute(parent);
}
catch (e)
{
throw e;
}
finally
{
if (animate.checked)
{
var morph = new mxMorphing(graph);
morph.addListener(mxEvent.DONE, function()
{
graph.getModel().endUpdate();
}); morph.startAnimation();
}
else
{
graph.getModel().endUpdate();
}
}
}
), document.body.firstChild); // 添加按钮来更新布局
document.body.insertBefore(mxUtils.button('随机布局Organic Layout',
function(evt)
{
graph.getModel().beginUpdate();
try
{
layout.execute(parent);
}
catch (e)
{
throw e;
}
finally
{
if (animate.checked)
{
//默认值是 6, 1.5, 20
var morph = new mxMorphing(graph, 10, 1.7, 20);
morph.addListener(mxEvent.DONE, function()
{
graph.getModel().endUpdate();
});
morph.startAnimation();
}
else
{
graph.getModel().endUpdate();
}
}
}
), document.body.firstChild); // 开启更新事务
graph.getModel().beginUpdate();
var w = 30;
var h = 30;
try
{
var v1 = graph.insertVertex(parent, null, 'A', 0, 0, w, h);
var v2 = graph.insertVertex(parent, null, 'B', 0, 0, w, h);
var v3 = graph.insertVertex(parent, null, 'C', 0, 0, w, h);
var v4 = graph.insertVertex(parent, null, 'D', 0, 0, w, h);
var v5 = graph.insertVertex(parent, null, 'E', 0, 0, w, h);
var v6 = graph.insertVertex(parent, null, 'F', 0, 0, w, h);
var v7 = graph.insertVertex(parent, null, 'G', 0, 0, w, h);
var v8 = graph.insertVertex(parent, null, 'H', 0, 0, w, h);
var e1 = graph.insertEdge(parent, null, 'ab', v1, v2);
var e2 = graph.insertEdge(parent, null, 'ac', v1, v3);
var e3 = graph.insertEdge(parent, null, 'cd', v3, v4);
var e4 = graph.insertEdge(parent, null, 'be', v2, v5);
var e5 = graph.insertEdge(parent, null, 'cf', v3, v6);
var e6 = graph.insertEdge(parent, null, 'ag', v1, v7);
var e7 = graph.insertEdge(parent, null, 'gh', v7, v8);
var e8 = graph.insertEdge(parent, null, 'gc', v7, v3);
var e9 = graph.insertEdge(parent, null, 'gd', v7, v4);
var e10 = graph.insertEdge(parent, null, 'eh', v5, v8); // 执行更改
layout.execute(parent);
}
finally
{
// 结束更新事务
graph.getModel().endUpdate();
}
}
};
</script>
</head> <!-- 页面载入时启动程序 -->
<body onload="main(document.getElementById('graphContainer'))"> <!-- 创建带网格壁纸和曲线的一个容器,请一定要定义的position和overflow的属性!根据在线API的54 页内容增加的大小侦听器 -->
<div id="graphContainer"
style="position:relative;overflow:visible;width:821px;height:641px;background:url('editors/images/grid.gif');">
</div>
<br>
<input type="checkbox" id="animate" checked="checked"/> Transitions
</body>
</html>

最新文章

  1. Hibernate的关联映射关系
  2. 操作系统 页面置换算法LRU和FIFO
  3. WinForm------ToolTipController与GridControl的连用
  4. Centos 安装了 Wkhtmltopdf 却依旧显示 无法打印pdf
  5. H5测试区别与PC端测试关注点
  6. UVaLive 6694 Toy Boxes (二分+想法)
  7. Redhat 6.5 x64 下载地址
  8. Eclipse下使用Fat Jar插件对源代码进行打包
  9. SQL学习之用通配符进行数据过滤
  10. Play framework 2.0
  11. Java中 +=是什么意思 什么情况下用
  12. 如何自定义容器网络?- 每天5分钟玩转 Docker 容器技术(33)
  13. thinkphp项目在apache服务器中“去掉”index.php后出现找不到url的问题
  14. robotframework自动化系统:操作mysql数据库
  15. OpenLayer3调用天地图,拖拽后,地图消失的问题[已解决]
  16. 英语笔记3(git)
  17. Fiddler抓取https的设置
  18. 把dotx模板的样式应用到当前文档中(不应用dotx的其他东西)
  19. centos6上调整lv逻辑卷
  20. angular面试记忆的内容

热门文章

  1. CSS 如何让Table的里面TD全有边框 而Table的右左边框没有
  2. GPS坐标转换为百度地图坐标
  3. 电商商品规则属性sku 工具类
  4. ceph故障:too many PGs per OSD
  5. Gym 101201F Illumination (Two-Sat)
  6. Linux 基础教程 25-命令和文件查找
  7. Oracle E-Business Suite并发请求的优先级(Concurrent Request Priority)
  8. ISO in CSS content
  9. Postgresql fillfactor
  10. nginx停止