拓撲框架Jtopo

使用HTML5製做網絡拓撲圖的方式有主要有Canvas和SVG,Jtopo採用HTML5的Canvas實現,可使用到Html5的平臺(PC,手機,平板),免費易用,適用於瀏覽器IE, Firefox, Safari,Chrome等javascript

開發流程:
1.引入jtopo.js文件java

<script type="text/javascript" src="js/jtopo-min.js"></script>

 


2.Canvas標籤訂義拓撲圖node

<canvas width="910" height="400" id="canvas"></canvas>

 


3.繪製拓撲圖canvas

$(document).ready(function(){ 
var canvas = document.getElementById('canvas');
var stage = new JTopo.Stage(canvas);//建立舞臺對象
var scene = new JTopo.Scene(stage); //建立場景對象 
scene.alpha = 1;


//加節點
function addNode(text, color){
var node = new JTopo.Node();
node.setImage('./img/topo/'+ color +'.png', true);
node.fontColor = '0,0,0';
scene.add(node);

node.mouseover(function(){
this.text = text;
});
node.mouseout(function(){
this.text = null;
});
return node;
}


//連線
function addLink(nodeA, nodeZ){
var link = new JTopo.FlexionalLink(nodeA, nodeZ);
link.strokeColor = '204,204,204';
link.lineWidth = 1;
scene.add(link);
return link;
}

var rootNode = addNode('root', 'gray');

var icons = ['green', 'blue', 'red1', 'red2'];
for(var i=0; i<icons.length; i++){

var node = addNode('second_' + i, icons[i]); 
addLink(rootNode, node); 
if(i == 0 || i == icons.length - 1){
for(var j=0; j<4; j++){
var thirdNode = addNode('third_' + j, 'green');
addLink(node, thirdNode);

}
}
}

// 樹形佈局
scene.doLayout(JTopo.layout.TreeLayout('down', 30, 107));
});

更多實例官網中都有瀏覽器

相關文章
相關標籤/搜索