实现蛇形节点布局

Posted on 2021-01-20 11:50  凡凡0410  阅读(301)  评论(0编辑  收藏  举报

let sixLists= [], threeLists = [] , twoList=[];       
this_.nodeData.forEach((item,idx)=>{
     if(idx==0||idx%6==0||(idx+1)%6===0){
            sixLists.push(idx);
     };
     if(idx%3==0||(idx-2)%3===0){
         //因为3的倍数也有可能是6的倍数
          if(!sixLists.includes(idx)){
                  threeLists.push(idx);
             };
      };
      if((idx-1)%3===0){
            twoList.push(idx);
       };
});
this_.nodeData.forEach((item,idx)=>{
      let x=0,y=0;
      let pos = -1;    
      if(sixLists.includes(idx)){
           pos = sixLists.indexOf(idx);
           x = 100;
       }
        if(threeLists.includes(idx)){
              pos = threeLists.indexOf(idx);
              x = 900;
        }
         if(twoList.includes(idx)){
              pos = twoList.indexOf(idx);
             x = 500;
          };
          y=pos>-1?pos*240+30:30;
           item.x = x;
           item.y = y;
                
 });    

 

 

Copyright © 2024 凡凡0410
Powered by .NET 9.0 on Kubernetes