美文网首页
gojs之Minimal学习

gojs之Minimal学习

作者: zackxizi | 来源:发表于2018-11-08 15:21 被阅读0次
gojs之Minimal学习
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>gojs之Minimal学习</title>
    <script src="./node_modules/gojs/release/go-debug.js"></script>
    <script id="code">
        function init() {
            if (window.goSamples) goSamples();
            /*
            * gojs 有两种使用方法, 一种是使用原本的 go 对象,
            * 第二种则是构造器方式创建, 即使用 go.GraphObject.make 对象创建,我们将该对象赋值给 $,
            * 当然为了避免冲突也可以是其他符号
            * */
            var $ = go.GraphObject.make;
            /*
            * $(go.Diagram, [selector], [options])
             * 该方法会执行 canvas 画布的初始化操作,
             * 同时也提供了丰富的配置项使用
            * */
            myDiagram = $(go.Diagram, "myDiagramDiv",  // create a Diagram for the DIV HTML element
                {
                    initialContentAlignment: go.Spot.Center,  // 令绘制的元素相对画布居中
                    "undoManager.isEnabled": true  // 是否可撤销编辑 Ctrl+z / Ctrl+y 撤销重做
                });
            // 编写节点模板
            myDiagram.nodeTemplate =
                $(go.Node, "Auto",  // Shape 将环绕在 TextBlock 周围
                    // 绘图形
                    $(go.Shape, "RoundedRectangle", {strokeWidth: 0, fill: "white"},
                        // Shape.fill is bound to Node.data.color
                        /*
                        * new go.Binding([origin], [target], [filter = Func])
                        * 这是 gojs 中的数据绑定, 使用该方法实现了模板与真实数据之间的传递
                        * 该方法能在任意构造器中使用
                        * origin: 该构造器中的属性名
                        * target: 需要绑定到数据集中的属性名
                        * filter: 过滤函数
                        * */
                        // fill 填充颜色从GraphLinksModel内获取,与color对应
                        new go.Binding("fill", "color")),
                    // 添加文字
                    $(go.TextBlock,
                        // 设置文字的margin值
                        {margin: 8},
                        // 设置文字内容,从GraphLinksModel内获取,与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 属性是必填的且具有唯一性, 它将运用到连接线数据集中  这里被用于每个node的文字
                    {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 onload="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>
</div>
</body>
</html>

相关文章

  • gojs之Minimal学习

  • gojs库学习记录(一)

    gojs[https://gojs.net/latest/index.html] 图形库功能非常强大,大家先看它的...

  • gojs实现自定义图表

    效果图: 1、vuecli创建gojs-demo脚手架工程。 package.json文件中引入gojs组件,vs...

  • gojs

    Gojs项目文档 简介: Gojs 用canvas 作图,一般用来绘制流程图,关系图,表示节点与节点之间的关系,节...

  • gojs库学习记录(二)

    接上文[https://www.jianshu.com/p/a0b0792d32ea]。目前有一个具体的项目需求是...

  • GOJS基础相关视频

    整理了一些GOJS基础相关视频,因为最近公司项目上需要用GOJS,中文文档比较稀缺 视频是英文的,俺也英文不好,?...

  • HEXO - Minimal 一款为开源作者而生的主题

    关于 Minimal Minimal 简介、优雅、尊贵。一款能展示项目的主题; Minimal 是一款专为开源贡献...

  • gojs api

    1、创建画布let (go.Diagram, 'myDiagramDiv',{'undoManager.isEna...

  • 简介

    转(GoJS官方文档)https://www.cnblogs.com/wenruo/p/10766707.html...

  • Gojs 快速入门

    一、前言Gojs提供了很多API给我们使用,下面只是提供完成关系图表(如下图)的某种方法,用其他方法也可以实现同样...

网友评论

      本文标题:gojs之Minimal学习

      本文链接:https://www.haomeiwen.com/subject/fddwxqtx.html