【流程图示例】轻量级流程图控件GoJS示例连载(一):最小化
admin
2023-07-26 12:40:08
0

GoJS是一款功能强大,快速且轻量级的流程图控件,可帮助你在JavaScript 和 HTML5 Canvas程序中创建流程图,且极大地简化你的JavaScript / Canvas 程序。

小编为大家准备了一套完整的GoJS的示例,将以连载的形式展开,供大家学习和交流讨论。

【流程图示例】轻量级流程图控件GoJS示例连载(一):最小化

这不是GoJS的真正最小化演示,因为我们确实指定了自定义Node模板,但它非常简单。如果单击链接,示例的完整来源如下所示。

此示例使用Node模板设置Diagram.nodeTemplate,该模板数据绑定文本字符串和形状的填充颜色。有关构建自己的模板和模型数据的概述,请参阅“入门教程”。

该Diagram.initialContentAlignment设置导致图表内容出现在图的视口的中心。

使用鼠标和常用键盘命令,你可以平移,选择,移动,复制,删除和撤消/重做。在触摸设备上,使用手指作为鼠标,并保持手指静止以显示上下文菜单。默认上下文菜单支持当时为所选对象启用的大多数标准命令。

有关更精细和更有说服力的样本,请参阅基本示例。有关从服务器加载JSON数据的示例,请参阅最小化JSON示例。有关从服务器加载XML数据的示例,请参阅最小化XML示例

以下为在页面中查看此示例页面的源代码:

  function init() {
    if (window.goSamples) goSamples();  // init for these samples -- you don't need to call this

    var $ = go.GraphObject.make;  // for conciseness in defining templates

    myDiagram = $(go.Diagram, "myDiagramDiv",  // create a Diagram for the DIV HTML element
                  {
                    initialContentAlignment: go.Spot.Center,  // center the content
                    "undoManager.isEnabled": true  // enable undo & redo
                  });

    // define a simple Node template
    myDiagram.nodeTemplate =
      $(go.Node, "Auto",  // the Shape will go around the TextBlock
        $(go.Shape, "RoundedRectangle", { strokeWidth: 0, fill: "white" },
          // Shape.fill is bound to Node.data.color
          new go.Binding("fill", "color")),
        $(go.TextBlock,
          { margin: 8 },  // some room around the text
          // TextBlock.text is bound to Node.data.key
          new go.Binding("text", "key"))
      );

    // but use the default Link template, by not setting Diagram.linkTemplate

    // create the model data that will be represented by Nodes and Links
    myDiagram.model = new go.GraphLinksModel(
    [
      { key: "Alpha", color: "lightblue" },
      { key: "Beta", color: "orange" },
      { key: "Gamma", color: "lightgreen" },
      { key: "Delta", color: "pink" }
    ],
    [
      { from: "Alpha", to: "Beta" },
      { from: "Alpha", to: "Gamma" },
      { from: "Beta", to: "Beta" },
      { from: "Gamma", to: "Delta" },
      { from: "Delta", to: "Alpha" }
    ]);
  }

  
  
  

    This isn't a truly minimal demonstration of GoJS,     because we do specify a custom Node template, but it's pretty simple.     The whole source for the sample is shown below if you click on the link.   

  

    This sample sets the Diagram.nodeTemplate, with a Node template that data binds both the text string and the shape's fill color.     For an overview of building your own templates and model data, see the Getting Started tutorial.   

  

    The Diagram.initialContentAlignment setting causes the diagram's contents     to appear in the center of the diagram's viewport.   

  

    Using the mouse and common keyboard commands, you can pan, select, move, copy, delete, and undo/redo.     On touch devices, use your finger to act as the mouse, and hold your finger stationary to bring up a context menu.     The default context menu supports most of the standard commands that     are enabled at that time for the selected object.   

  

    For a more elaborate and capable sample, see the Basic sample.     For a sample that loads JSON data from the server,     see the Minimal JSON sample.     For a sample that loads XML data from the server,     see the Minimal XML sample.   

以下为在GitHub上查看此示例页面的源代码:





Minimal GoJS Sample




  

  function init() {
    if (window.goSamples) goSamples();  // init for these samples -- you don't need to call this
    var $ = go.GraphObject.make;  // for conciseness in defining templates
    myDiagram = $(go.Diagram, "myDiagramDiv",  // create a Diagram for the DIV HTML element
                  {
                    initialContentAlignment: go.Spot.Center,  // center the content
                    "undoManager.isEnabled": true  // enable undo & redo
                  });
    // define a simple Node template
    myDiagram.nodeTemplate =
      $(go.Node, "Auto",  // the Shape will go around the TextBlock
        $(go.Shape, "RoundedRectangle", { strokeWidth: 0, fill: "white" },
          // Shape.fill is bound to Node.data.color
          new go.Binding("fill", "color")),
        $(go.TextBlock,
          { margin: 8 },  // some room around the text
          // TextBlock.text is bound to Node.data.key
          new go.Binding("text", "key"))
      );
    // but use the default Link template, by not setting Diagram.linkTemplate
    // create the model data that will be represented by Nodes and Links
    myDiagram.model = new go.GraphLinksModel(
    [
      { key: "Alpha", color: "lightblue" },
      { key: "Beta", color: "orange" },
      { key: "Gamma", color: "lightgreen" },
      { key: "Delta", color: "pink" }
    ],
    [
      { from: "Alpha", to: "Beta" },
      { from: "Alpha", to: "Gamma" },
      { from: "Beta", to: "Beta" },
      { from: "Gamma", to: "Delta" },
      { from: "Delta", to: "Alpha" }
    ]);
  }




  
  
  

    This isn't a truly minimal demonstration of GoJS,     because we do specify a custom Node template, but it's pretty simple.     The whole source for the sample is shown below if you click on the link.   

  

    This sample sets the Diagram.nodeTemplate, with a Node template that data binds both the text string and the shape's fill color.     For an overview of building your own templates and model data, see the Getting Started tutorial.   

  

    The Diagram.initialContentAlignment setting causes the diagram's contents     to appear in the center of the diagram's viewport.   

  

    Using the mouse and common keyboard commands, you can pan, select, move, copy, delete, and undo/redo.     On touch devices, use your finger to act as the mouse, and hold your finger stationary to bring up a context menu.     The default context menu supports most of the standard commands that     are enabled at that time for the selected object.   

  

    For a more elaborate and capable sample, see the Basic sample.     For a sample that loads JSON data from the server,     see the Minimal JSON sample.     For a sample that loads XML data from the server,     see the Minimal XML sample.   

想要查看在线操作示例,可以点击此处>>>>>


相关内容

热门资讯

韩国政府将投资千万亿韩元于AI... 韩国总统李在明29日在总统府青瓦台主持召开会议,公布总额超千万亿韩元的半导体、物理人工智能(AI)和...
以色列防长称以伊可能随时再起冲... △卡茨(资料图)据以色列方面29日消息,以国防部长卡茨当天表示,鉴于复杂的安全局势和在黎巴嫩的军事行...
零售门店会员激活与5G视频触达... 导语:据2025年行业白皮书数据显示,国内AI语音呼叫市场近三年复合增长率达32.7%,2026年市...
存量商办“变”医院!深圳探索公... 深圳商报·读创客户端首席记者 李秀瑜 深圳存量资产盘活跑出新模式。 6月27日,深圳市中医院针灸推拿...
伊朗称未来几天没有与美方谈判的... △巴加埃(资料图)当地时间29日晚间,伊朗外交部发言人巴加埃对外界表示,伊方未来几天没有与美方开展任...
关于霍尔木兹海峡排雷,伊朗:我... 伊朗外交部当地时间29日晚间在一份声明中表示,根据《伊斯兰堡谅解备忘录》,霍尔木兹海峡的排雷工作将由...
卡塔尔建议民众暂停出海 卡塔尔交通部29日建议民众暂停出海航行和海上活动。卡塔尔交通部当天在社交媒体发布公报说,为保障公共安...
朱克力:促进算力供给持续稳定普... 朱克力 | 立方大家谈专栏作者 当前,我国经济社会进入数字化智能化深度融合的发展阶段,生产方式、产业...
把脉“人工智能+” 求解教育科... 推进新质生产力发展,教育科技人才须同频共振;拥抱人工智能时代,技术创新当与人文精神相互校准。 近日...
“人造太阳”有新突破!可控核聚... 万亿级赛道传来好消息。 核聚变堆超导磁体研发取得重要突破 6月27日,我国“人造太阳”项目取得关键进...