• goJS-绘图-控制显示内容


    goJs是国外画图的一个包,同比阿里的antv/x6
    中文文档

    1. 字段是否显示
      参考: Decorated Content 一节
    	{
          toolTip:
            $(go.Adornment, "Auto",
              $(go.Shape, { fill: "#FFFFCC" },
                new go.Binding("visible", "info", function(i) { return i ? true : false; })),
              $(go.TextBlock, { margin: 4 },
                new go.Binding("text", "info"))
            )
        }
        // 主要是 visible 这个属性的设置,根据外部传入的字段来控制这行显示与否,从而可以根据业务场景来显示不同的字段。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在这里插入图片描述
    还有控制opacity属性,详情参考该章节实例。

    1. 分发模板显示
      根据不同的category值来进入不同模板,显示不同的信息。比如list和detail的显示。
    ...
    let xxxtemplate = ...
    
    var templmap = new go.Map();
    templmap.add("simple", simpletemplate);
    templmap.add("detailed", detailtemplate);
    templmap.add("", diagram.nodeTemplate);
    diagram.nodeTemplateMap = templmap;
    ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    外部数据

    nodeDataArray = [
    	...
    	{
    		...
    		category: 'simple' // 不加进入默认模板
    	},
    	{
    		...
    		category: 'detailed'
    	},
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    1. 控制某个模板显示
      参考 Example of Item Templates 一节
      动态增加字段
    var itemtemplates = new go.Map();
    
    // the template when type == "text"
    itemtemplates.add("text",
      $(go.Panel,
        $(go.TextBlock,
          new go.Binding("text"))
      ));
    
    // the template when type == "button"
    itemtemplates.add("button",
      $("Button",
        $(go.TextBlock,
          new go.Binding("text")),
        new go.Binding("click", "handler",
                        function(name) {
                          if (name === "alert") return raiseAlert;  // defined below
                          return null;
                        })
      ));
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    ...
    
    ...
    itemCategoryProperty: "type",
    itemTemplateMap: itemtemplates
    ···
    // 主要是这两句,第一句表示使用什么字段来控制显示。
    // 第二句将数据映射到对应的模板。
    ...
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    数据

    	diagram.model = new go.GraphLinksModel( [
      { key: "Alpha",
        info: [
                { type: "text", text: "some text" },
                { type: "button", text: "Click me!", handler: "alert"}
              ]
      },
      { key: "Beta",
        info: [
                { type: "text", text: "first line" },
                { type: "button", text: "First Button", handler: "alert"},
                { type: "text", text: "second line" },
                { type: "button", text: "Second Button", handler: "alert" }
              ]
      }
    ],[
      { 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    1. 截图如果元素超过可视区域,超出部分不会被截到。
      antv/x6解决了该问题
      在这里插入图片描述
      goJs截图存在该问题。
    2. 处理数据以及事件
      参考下面三个链接来理解。
      https://gojs.net/latest/learn/graphObject.html
      https://gojs.net/latest/intro/transactions.html
      https://gojs.net/latest/intro/changedEvents.html
  • 相关阅读:
    animate.css
    u-view组件库开发中的u-avatar-group头像组组件的层级反方向层级覆盖的实现
    Chapter 02 - Let's Get Started(C#篇)
    使用Spring的StopWatch类优雅打印方法执行耗时
    【附源码】计算机毕业设计JAVA药品管理系统
    vue--vuerouter缓存路由组件
    Blazor前后端框架Known-V1.2.15
    java异常
    sqlmap结合dnslog外带注入
    pdf文件签名的问题解决
  • 原文地址:https://blog.csdn.net/junjiahuang/article/details/125496531