我尝试了自己,但显然我还不够好,无法完成这项工作:-) 我想要实现的目标类似于 Mike 的可重用性演讲 - http://bost.ocks.org/mike/chart/:
marbles = new Marbles();
marbles.width();//getter, setter
marbles.height();//-||-
...etc
marbles.run();//run the code
代码示例如下所示。有人可以帮我吗?我知道如何在 Java 或 PHP 中创建类和 OOP,但纯 JS 不是我的专业领域 :-)
我有这个代码:
//initialize on (menu click)
jQuery(document).ready(function(){
marbles();
});
});
带有变量和主要功能:
function marbles(){
var height = 500,
width = 1000;
var path = "";
..另一个变量(大约 15 个)
var force = d3.layout.force()
.size([width, height]);
//foci to be set for relation type positioning and nodes placing
var links = force.links(),
nodes = force.nodes();
run();
//graph starts here by loading data - d3.xml
function run (rootNode){
begin();
}
//internal timer function - adding nodes one at the time
function begin(clickedNode){
}
//classical update function
function update() {
}
}
谢谢
卢卡斯