码迷,mamicode.com
首页 > Web开发 > 详细

使用joint.js 绘制图

时间:2015-04-12 16:16:51      阅读:1061      评论:0      收藏:0      [点我收藏+]

标签:

试了几种在js画graph的库,还是joint.js合适一些,对于简单的图显示很适用。具体链接:

http://www.daviddurman.com/automatic-graph-layout-with-jointjs-and-dagre.html


demo:


1.script和css下载:



http://jointjs.com/download :


<link rel="stylesheet" href="joint.css" >
<script src="joint.js" ></script>
<script src="joint.layout.DirectedGraph.js"></script>


http://www.daviddurman.com/assets/autolayout.js:


<script src="autolayout.js" ></script>


2. 示例代码:


<link rel="stylesheet" href="joint.css" >


<script src="joint.js" ></script>
<script src="joint.layout.DirectedGraph.js"></script>
<script src="autolayout.js" ></script>






<textarea id="adjacency-list" rows=40 cols=100>{
  ‘a‘: [‘b‘],
  ‘a‘: [‘c‘],
  ‘b‘: [‘f‘],
  ‘c‘: [‘e‘, ‘d‘],
  ‘d‘: [],
  ‘e‘: [],
  ‘f‘: [‘g‘],
  ‘g‘: []
}</textarea>
<br>
<button id="btn-layout">Layout</button>


<div id="paper"></div>


<script>


// Main.
// -----


var graph = new joint.dia.Graph;


var paper = new joint.dia.Paper({


    el: $(‘#paper‘),
    width: 2000,
    height: 2000,
    gridSize: 1,
    model: graph
});


// Just give the viewport a little padding.
V(paper.viewport).translate(20, 20);


$(‘#btn-layout‘).on(‘click‘, layout);


function layout() {
    
    try {
        var adjacencyList = eval(‘adjacencyList = ‘ + $(‘#adjacency-list‘).val());
    } catch (e) { alert(e); }
    
    var cells = buildGraphFromAdjacencyList(adjacencyList);
    graph.resetCells(cells);
    joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false });
}
layout();
</script>


使用joint.js 绘制图

标签:

原文地址:http://blog.csdn.net/lan_liang/article/details/45010331

(2)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!