1

我尝试了自己,但显然我还不够好,无法完成这项工作:-) 我想要实现的目标类似于 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() {

   }

}

谢谢

卢卡斯

4

1 回答 1

0

有几种方法可以在 JS 中执行 OOP。你可以在 JS 大师的书中找到它们

如果你只是想了解几个图表是如何工作的,请看看 Bob Monteverde 如何在他的图表库中实现模型... https://github.com/novus/nvd3/tree/gh-pages/src/models 我想你会从他的代码中学到很多东西。

在这个 google 组线程中还有各种可重用图表的示例: https ://groups.google.com/forum/#!searchin/d3-js/reusable$20charts/d3js/6VSl7srPYIo/iKNkxSr1YF0J

于 2012-04-19T18:28:05.020 回答