Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var moveItems = (function(){
- var todoNode = 0;
- var todoLink = 0;
- var MAX_NODES = 240*4;
- var MAX_LINKS = MAX_NODES/2;
- var restart = false;
- function moveSomeNodes(){
- var n;
- var goal = Math.min(todoNode+MAX_NODES, node[0].length);
- for(var i=todoNode ; i < goal ; i++){
- n = node[0][i];
- n.setAttribute('transform', 'translate(' + n.__data__.x + ',' + n.__data__.y + ')');
- //n.setAttribute('cx', n.__data__.x);
- //n.setAttribute('cy', n.__data__.y);
- }
- todoNode = goal;
- requestAnimationFrame(moveSome)
- }
- function moveSomeLinks(){
- var l;
- var goal = Math.min(todoLink+MAX_LINKS, link[0].length);
- for(var i=todoLink ; i < goal ; i++){
- l = link[0][i];
- //console.log(l);
- l.setAttribute('x1', l.__data__.source.x);
- l.setAttribute('y1', l.__data__.source.y);
- l.setAttribute('x2', l.__data__.target.x);
- l.setAttribute('y2', l.__data__.target.y);
- }
- todoLink = goal;
- requestAnimationFrame(moveSome)
- }
- function moveSome(){
- console.time('moveSome')
- if(todoNode < node[0].length) // some more nodes to do
- moveSomeNodes()
- else{ // nodes are done
- if(todoLink < link[0].length) // some more links to do
- moveSomeLinks()
- else{ // both nodes and links are done
- if(restart){
- restart = false;
- todoNode = 0;
- todoLink = 0;
- requestAnimationFrame(moveSome);
- }
- }
- }
- console.timeEnd('moveSome')
- }
- return function moveItems(){
- if(!restart){
- restart = true;
- requestAnimationFrame(moveSome);
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement