[转] js画图开发库--mxgraph--[graphlayout-图形布局.html]
【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>
[转] js画图开发库--mxgraph--[graphlayout-图形布局.html]的更多相关文章
- [资料搜集狂]D3.js数据可视化开发库
偶然看到一个强大的D3.js,存档之. D3.js 是近年来十分流行的一个数据可视化开发库. 采用BSD协议 源码:https://github.com/mbostock/d3 官网:http://d ...
- iOS(iPhone,iPad))开发(Objective-C)开发库常用库索引
http://www.code4app.com 这网站不错,收集各种 iOS App 开发可以用到的代码示例 http://www.cocoacontrols.com/ 英文版本的lib收集 ht ...
- JS模块化开发:使用SeaJs高效构建页面
一.扯淡部分 很久很久以前,也就是刚开始接触前端的那会儿,脑袋里压根没有什么架构.重构.性能这些概念,天真地以为前端===好看的页面,甚至把js都划分到除了用来写一些美美的特效别无它用的阴暗角落里,就 ...
- js模块开发(一)
现在嵌入页面里面的javascript代码越来越复杂,于是可能依赖也越来越严重,使用别人开发的js也越来越多,于是在理想情况下,我们只需要实现核心的业务逻辑,其他都可以加载别人已经写好的模块. 于是j ...
- 25 个超棒的 HTML5 & JavaScript 游戏引擎开发库
就像在汽车中,引擎完成主要的工作,使汽车看起来不可思议.游戏引擎同理,游戏开发者完成细节的工作,使游戏看起来真实.吸引人眼球.游戏引擎负责其余的事情.早期,游戏开发者通常从草图做起,花费高昂,且不容易 ...
- 跨平台的C++应用和UI开发库 QT
跨平台的C++应用和UI开发库 QT 运行环境: 授权方式:BSD 软件大小:M 下载量:3912 更新日期:2012-04-05 来源地址: 联系作者:Linux Qt是诺基亚开发的一个跨平 ...
- js模块开发
js模块开发(一) 现在嵌入页面里面的javascript代码越来越复杂,于是可能依赖也越来越严重,使用别人开发的js也越来越多,于是在理想情况下,我们只需要实现核心的业务逻辑,其他都可以加载别人已经 ...
- js页码生成库,一个适合前后端分离的页码生成器
原文:js页码生成库,一个适合前后端分离的页码生成器 前言 上星期写的任务里面有需要进行分页的处理,git搜索了一番,没有觉得合适的,于是自己临时写了个分页的算法. 然后等闲下来的时候,决定把分页进行 ...
- Canvas开发库封装
一.Canvas第三方类库 1.常见的第三方类库 konva.js <style> body{ margin:0; } </style> </head> <b ...
随机推荐
- DIV+CSS布局时, DIV的高度和宽度特性
这个没有特别的做要求,你要根据你自己的页面整体布局来设置,还有根据div的特性来设置,div默认情况是宽度最大化(100%).高度最小化,高度随着内容自动伸展: 一般情况做网页的话,大部分都是固定了总 ...
- Some details of UIKit
[Some details of UIKit] 1.UIViewController的toolbarItems属性与UINavigationController配合使用. 2.The view for ...
- 475. Heaters
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- ScreenCapture手动卸载教程-Xproer.ScreenCapture
此教程包含WindowsXP,Windows7(x86) ,Windows7(x64),Firefox,Chrome卸载教程. 1.1. 手动卸载控件-Windows XP 主要步骤如下: 1.关闭所 ...
- PHP中刷新输出缓冲详解[转载]
PHP中刷新输出缓冲详解 分类: PHP Web开发2011-07-23 17:42 1795人阅读 评论(0) 收藏 举报 phpbuffer浏览器outputapache模块脚本 buffer是一 ...
- CSS定位DIV(一)一列样式
前记:CSS样式核心就是DIV布局,一些基础知识省略不记,接下来的日志只关注最核心的布局问题. 一.一列布局 1.固定宽高 直接声明宽高,或用百分比表示. width:400px; 或 width:7 ...
- WPF 绑定备忘单
Part I – Common Examples Basic Binding {Binding} Bind to current DataContext. {Binding Name} Bi ...
- 创建圆角 抛出一个错误:二元运算符“|”不能用于两个UIRectCorner操作数
// let beizer:UIBezierPath = UIBezierPath(roundedRect: btn5.bounds, byRoundingCorners: UIRect ...
- Oracle EBS Patch Demo
Oracle EBS APP & DB 打补丁过程简述l例子: 打 Patch# 11843100:R12.CAC.B 打PATCH之前先查询一下是否已经有了这个PATCH. SELECT ...
- Android-自定义圆环
效果图: 布局的代码,指定引用自定义View类: <!-- 绘制圆环 --> <LinearLayout xmlns:android="http://schemas.and ...