zoukankan      html  css  js  c++  java
  • g6使用-解决图形相对于画布完全居中

    第一种方式:

       使用fitView()方法,图形自动适配画布大小,但是会有一个问题,当图形节点比较少初始化的时候,节点就会放大好几倍,看起来很不好。

    第二种方式:

       重写fitView()方法,将中心点设置到画布的中心点

    const width = graph.get("width");
          const height = graph.get("height");
          const group = graph.get("group");
          group.resetMatrix();
          const bbox = group.getCanvasBBox();
    
          if (bbox.width === 0 || bbox.height === 0) return;
          const viewCenter = {
            x: width / 2,
            y: height / 2,
          };
    
          const groupCenter = {
            x: bbox.x + bbox.width / 2,
            y: bbox.y + bbox.height / 2,
          };
          graph.translate(viewCenter.x - groupCenter.x, viewCenter.y - groupCenter.y);
    

      

  • 相关阅读:
    Hive小结
    Redis小结
    Hbase小结
    Rdd/DataFrame/DataSet 小结
    spark杂记2
    shiyan
    stanford推荐阅读目录
    超市收银系统之——3
    超市收银系统之超市类——4
    超市收银系统_仓库类——2
  • 原文地址:https://www.cnblogs.com/zoey-blog/p/14059575.html
Copyright © 2011-2022 走看看