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

小编为大家准备了一套完整的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 thisvar $ = go.GraphObject.make;  // for conciseness in defining templatesmyDiagram = $(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 templatemyDiagram.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.colornew go.Binding("fill", "color")),$(go.TextBlock,{ margin: 8 },  // some room around the text// TextBlock.text is bound to Node.data.keynew 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 LinksmyDiagram.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" }]);}
<div id="sample" deep="0"><!-- The DIV for the Diagram needs an explicit size or else we won't see anything.This also adds a border to help see the edges of the viewport. --><div id="myDiagramDiv" style="border: solid 1px black; width:400px; height:400px"></div><p>This isn't a truly <i>minimal</i> demonstration of <b>GoJS</b>,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.</p><p>This sample sets the <a>Diagram.nodeTemplate</a>, with a <a>Node</a> 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 <a href="../learn/index.html">Getting Started tutorial.</a></p><p>The <a>Diagram.initialContentAlignment</a> setting causes the diagram's contentsto appear in the center of the diagram's viewport.</p><p>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 thatare enabled at that time for the selected object.</p><p>For a more elaborate and capable sample, see the <a href="basic.html">Basic</a> sample.For a sample that loads JSON data from the server,see the <a href="minimalJSON.html">Minimal JSON</a> sample.For a sample that loads XML data from the server,see the <a href="minimalXML.html">Minimal XML</a> sample.</p>
</div>

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

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Minimal GoJS Sample</title>
<meta name="description" content="An almost minimal diagram using a very simple node template and the default link template." />
<!-- Copyright 1998-2018 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="../release/go.js"></script>
<script src="../assets/js/goSamples.js"></script>  <!-- this is only for the GoJS Samples framework -->
<script id="code">function init() {if (window.goSamples) goSamples();  // init for these samples -- you don't need to call thisvar $ = go.GraphObject.make;  // for conciseness in defining templatesmyDiagram = $(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 templatemyDiagram.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.colornew go.Binding("fill", "color")),$(go.TextBlock,{ margin: 8 },  // some room around the text// TextBlock.text is bound to Node.data.keynew 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 LinksmyDiagram.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" }]);}
</script>
</head>
<body οnlοad="init()">
<div id="sample"><!-- The DIV for the Diagram needs an explicit size or else we won't see anything.This also adds a border to help see the edges of the viewport. --><div id="myDiagramDiv" style="border: solid 1px black; width:400px; height:400px"></div><p>This isn't a truly <i>minimal</i> demonstration of <b>GoJS</b>,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.</p><p>This sample sets the <a>Diagram.nodeTemplate</a>, with a <a>Node</a> 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 <a href="../learn/index.html">Getting Started tutorial.</a></p><p>The <a>Diagram.initialContentAlignment</a> setting causes the diagram's contentsto appear in the center of the diagram's viewport.</p><p>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 thatare enabled at that time for the selected object.</p><p>For a more elaborate and capable sample, see the <a href="basic.html">Basic</a> sample.For a sample that loads JSON data from the server,see the <a href="minimalJSON.html">Minimal JSON</a> sample.For a sample that loads XML data from the server,see the <a href="minimalXML.html">Minimal XML</a> sample.</p>
</div>
</body>
</html>

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

转载于:https://juejin.im/post/5bebb2576fb9a049ea388104

轻量级流程图控件GoJS示例连载(一):最小化相关推荐

  1. cad画流程图的插件_流程图控件FlowChart.NET使用教程:安排组件的使用

    FlowChart.NET现在更名为MindFusion.Diagramming for WinForms,这个是一个通用的流程图控件.MindFusion.Diagramming除WinForms版 ...

  2. 可能是目前轻量级弹幕控件中功能最强大的一款

    本项目是一个开源的弹幕控件库,能够支持多种样式弹幕,弹幕点击监听,弹幕分区域显示,自定义移动速度等功能,项目原理是通过自定义ViewGroup.可能是目前轻量级弹幕控件中功能最强大的一款了. Gith ...

  3. 基于GDI+用C#编写的.NET流程图控件开发周记(2011-08-05)

    花了差不多一个月的业余时间,新编写了一个流程图控件(用于.NET和C#),这个控件现在终于有了一个原型.控件可以用在主界面的导航画面,也可以代替Visio来绘制流程图,最重要的是可以用于日后的工作流功 ...

  4. wxWidgets:网格控件 wxWidgets 示例

    wxWidgets:网格控件 wxWidgets 示例 wxWidgets:网格控件 wxWidgets 示例 griddemo.h griddemo.cpp wxWidgets:网格控件 wxWid ...

  5. 基于GDI+用C#编写的.NET流程图控件开发周记(2011-08-28)

    自从上次发布之后,本月几乎一直都在忙于处理工作上的事情,使得这段时间疏于更新流程图控件,所以这一次只作了小范围的功能更新: 1.增加了代表数据库图形 2.实现了对图形进行操作后的撤销(Ctrl+Z)与 ...

  6. 大量的QT控件及示例发放,求泛滥

    大量的QT控件及示例发放,求泛滥 2017年01月13日 14:36:22 阅读数:781  在论坛中,看到一位朋友介绍http://qt-apps.org/站上有很多好的资料和示例,现在发出来,与大 ...

  7. Qt实践录:常见控件操作示例2

    继前篇,本文继续记录QT常见控件的操作示例.包括:QProgressBar 等. QProgressBar 设置范围及初始值ui->progressBar->setRange(0, 100 ...

  8. Qt实践录:常见控件操作示例1

    本文记录QT常见控件的操作示例.包括:QPushBotton.QLabel.QComboBox.QSlider.QSpinBox.编辑框(QLineEdit/QPlainTextEdit/QTextE ...

  9. 大量的QT控件及示例发放

    QT属性控件项目 https://github.com/lexxmark/QtnProperty 比特币交易软件 https://github.com/JulyIGHOR/QtBitcoinTrade ...

最新文章

  1. 观峰雨个人空间 2010 STOCK ADVICE !
  2. HDU 2094:产生冠军(拓扑排序)
  3. 智能合约重构社会契约(8)以太坊分片
  4. 【励志好文】老爸推荐的好文,受益良多!
  5. 我的世界java版怎么装在u盘_我的世界选择器参数怎么使用?
  6. MyEclipse启动tomcat出现java.lang.OutOfMemoryError: PermGen space 的解决方案
  7. 【分享】154页微软WPF官方手册(含.NETCore和.NET Framwork双版本)
  8. mysql存储过程中as_mysql - 存储过程mySQL语法错误意外“ AS” - 堆栈内存溢出
  9. overflowhidden把内容遮住了怎么办_图片有水印怎么办?不用PS,有这4招就够了
  10. 下列关于html5表单的多样输入方式,IT兄弟连 HTML5教程 HTML5表单 多样的输入类型1...
  11. Memcache for Windows
  12. magisk核心功能模式是什么_科技板块——深入解析MM管理器
  13. 极域电子教室创建和登录教师端的方法
  14. 【动画消消乐|CSS】083.纯CSS实现卡通齿轮效果
  15. Linux cp命令的内涵
  16. Revisiting Domain Generalized Stereo Matching Networks from a FeatureConsistency Perspective
  17. js 文件下载请求两种方式
  18. 全球计算机科学和电子,科学网—[转载]【喜报】祝贺IEEE TCSS入选全球计算机与电子领域Top 1000期刊 - 王飞跃的博文...
  19. Deep learning for arts——王乃岩(图森科技)
  20. zotero 使用小技巧

热门文章

  1. Erdaicms旅游网站系统微信和手机端分销系统正式上线发布啦
  2. Android LayoutInflater详解(转)
  3. 设为首页及收藏本页代码 兼容IE和Firefox
  4. int能表示的数据范围(在VS2017下,int和long都是32位)
  5. 实模式与保护模式详解一:寄存器
  6. Markdown写作中的图床解决方案(基于七牛云、PicGo)
  7. 好嗨哟~谷歌量子神经网络新进展揭秘
  8. property classmethod staticmethod的用法
  9. svn更新提交等操作报svn: E155004错误,解决办法
  10. Android进阶笔记:AIDL内部实现详解 (二)