gojs青铜段位

1、效果图

在这里插入图片描述

html代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./go.js"></script>
    <style>
        html{
            height: 100%;
        }
        body{
            margin: 0;
            height: 100%;
        }
        .box{
            display: flex;
            justify-content: space-between;
            height: 100%;
            background-color: #282c34;
            box-sizing: border-box;
            padding: 8px;
            position: relative;
        }
        #myPaletteDiv{
            background-color: #282c34;
            width: 180px;
            height: 100%;
            border-right: 2px solid #fff;
            box-sizing: border-box;
        }
        #myDiagramDiv{
            background-color: #282c34;
            height: 100%;
            flex: 1;

        }
        .btn-box{
            position: absolute;
            right: 20px;
            z-index: 2;
        }
        .btn-box button{
            border-radius:4px;
            background-color: #fff;
            border: 1px solid #00A9C9;
            color: #00A9C9;
            padding: 4px 11px;
            cursor: pointer;
        }
    </style>
</head>
<body onload="init()">
    <div class="box">
        <div id="myPaletteDiv"></div>
        <div id="myDiagramDiv"></div>
        <div class="btn-box">
            <button  onclick="save()">保存</button>
        </div>
    </div>
    <script src="./nodeData.js"></script>
    <script  src="./demo.js"></script>
</body>
</html>

js代码


//初始配置
function init() {
    var $ = go.GraphObject.make;  // for conciseness in defining templates
      myDiagram =
        $(go.Diagram, "myDiagramDiv",  // must name or refer to the DIV HTML element
          {
            "LinkDrawn": showLinkLabel,  // this DiagramEvent listener is defined below
            "LinkRelinked": showLinkLabel,
			"undoManager.isEnabled": true,  // enable undo & redo
			"draggingTool.isGridSnapEnabled": true,
          })
    //变更节点的位置
    function nodeLoc() {
        return [
            new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), //变更节点位置信息
            {
                // the Node.location is at the center of each node
                locationSpot: go.Spot.Center
            }
        ]
    }
      //配置箭头
      //name是GraphObject.portId,align表示相对主体的位置,spot用于控制线条如何连接以及是否从侧面连接
      //output”和“input”参数控制用户是否可以从端口或到端口绘制链接
      function makePort(name, align, spot, output, input) {
        var horizontal = align.equals(go.Spot.Top) || align.equals(go.Spot.Bottom);
        // the port is basically just a transparent rectangle that stretches along the side of the node,
        // and becomes colored when the mouse passes over it
        return $(go.Shape,
          {
            fill: "transparent",  // changed to a color in the mouseEnter event handler
            strokeWidth: 0,  // no stroke
            fromLinkable: true, 
            fromLinkableSelfNode: true,  //配置是否可以连接自身(环路)
            fromLinkableDuplicates: true,//重复设置连接
            toLinkable: true, 
            toLinkableSelfNode: true, 
            toLinkableDuplicates: true,
            width: horizontal ? NaN : 8,  // if not stretching horizontally, just 8 wide
            height: !horizontal ? NaN : 8,  // if not stretching vertically, just 8 tall
            alignment: align,  // align the port on the main Shape
            stretch: (horizontal ? go.GraphObject.Horizontal : go.GraphObject.Vertical),
            portId: name,  // declare this object to be a "port"
            fromSpot: spot,  // declare where links may connect at this port
            fromLinkable: output,  // declare whether the user may draw links from here
            toSpot: spot,  // declare where links may connect at this port
            toLinkable: input,  // declare whether the user may draw links to here
            cursor: "pointer",  // show a different cursor to indicate potential link point
            mouseEnter: function(e, port) {  // the PORT argument will be this Shape
              if (!e.diagram.isReadOnly) port.fill = "rgba(255,165,0,0.5)";  //鼠标悬浮四周的线条阴影
            },
            mouseLeave: function(e, port) {
              port.fill = "transparent";
            }
          });
      }
      function showLinkLabel(e) {
        var label = e.subject.findObject("LABEL");
        console.log(label)
        if (label !== null){
            label.visible = (e.subject.fromNode.data.category === "Conditional");
        } 
        console.log(label)
      }

      //创建连接线样式模板
      myDiagram.linkTemplate =
        $(go.Link,  // the whole link panel
          {
            routing: go.Link.AvoidsNodes,
            curve: go.Link.JumpOver,
            corner: 5, toShortLength: 4,
            relinkableFrom: true,
            relinkableTo: true,
            reshapable: true,
		    resegmentable: true,
            // mouse-overs subtly highlight links:
            mouseEnter: function(e, link) { link.findObject("HIGHLIGHT").stroke = "rgba(30,144,255,0.2)"; },
            mouseLeave: function(e, link) { link.findObject("HIGHLIGHT").stroke = "transparent"; },
            selectionAdorned: true
          },
          new go.Binding("points").makeTwoWay(),
          $(go.Shape,  // the highlight shape, normally transparent
            { isPanelMain: true, strokeWidth: 8, stroke: "transparent", name: "HIGHLIGHT" }),
          $(go.Shape,  // the link path shape
            { isPanelMain: true, stroke: "gray", strokeWidth: 2 },
            new go.Binding("stroke", "isSelected", function(sel) { return sel ? "dodgerblue" : "gray"; }).ofObject()),
          $(go.Shape,  // the arrowhead
            { toArrow: "standard", strokeWidth: 0, fill: "gray" }),
          $(go.Panel, "Auto",  // the link label, normally not visible
            { visible: false, name: "LABEL", segmentIndex: 2, segmentFraction: 0.5 },
            new go.Binding("visible", "visible").makeTwoWay(),
            $(go.Shape, "RoundedRectangle",  // the label shape
              { fill: "#F8F8F8", strokeWidth: 0 }),
            $(go.TextBlock, "Yes",  // the label
              {
                textAlign: "center",
                font: "10pt helvetica, arial, sans-serif",
                stroke: "#333333",
                editable: true
              },
              new go.Binding("text").makeTwoWay())
          )
        );

    //创建节点模版
    myDiagram.nodeTemplateMap.add("",  // 创建矩形
        $(go.Node, "Auto",nodeLoc(),//Horizontal设置节点内容的横向排序方式,node代表整个节点,panel代表里面的一部分
          $(go.Panel, "Vertical",//第二个属性设置面板排序方式,Vertical表示垂直排放,这样文字跟图片就是竖直排放
            $(go.Picture,  // 使用图标设置
              { 	
				  	
					desiredSize: new go.Size(66, 66),
					margin:8
            	},
				new go.Binding("source", "text", convertKeyImage),
              ),
            $(go.TextBlock,
              {
                margin: 8,
                maxSize: new go.Size(160, NaN),
                wrap: go.TextBlock.WrapFit,
				editable: true,
				stroke: "white",
				font: "16px sans-serif"
              },
			//   new go.Binding("name").makeTwoWay())
			  new go.Binding("text", "name"))
          ),
          //设置箭头线条的连接方式,四个方向
          makePort("T", go.Spot.Top, go.Spot.TopSide, false, true),
          makePort("L", go.Spot.Left, go.Spot.LeftSide, true, true),
          makePort("R", go.Spot.Right, go.Spot.RightSide, true, true),
          makePort("B", go.Spot.Bottom, go.Spot.BottomSide, true, false)
		))

		myDiagram.nodeTemplate.selectionAdornmentTemplate =
        $(go.Adornment, "Spot",
          $(go.Placeholder, { padding: 5 }),
          makeArrowButton(go.Spot.Top, "TriangleUp"),
          makeArrowButton(go.Spot.Left, "TriangleLeft"),
          makeArrowButton(go.Spot.Right, "TriangleRight"),
          makeArrowButton(go.Spot.Bottom, "TriangleDown"),
        //   CMButton({ alignment: new go.Spot(0.75, 0) })
        );
        //获取图片
        function convertKeyImage(key){
          return './img/' +key +'.png'
        }
        //装饰节点,单击节点出现的四个三角形
        function makeArrowButton(spot, fig) {
			var maker = function(e, shape) {
					e.handled = true;
					e.diagram.model.commit(function(m) {
					var selnode = shape.part.adornedPart;
					// create a new node in the direction of the spot
					var p = new go.Point().setRectSpot(selnode.actualBounds, spot);
					p.subtract(selnode.location);
					p.scale(2, 2);
					p.x += Math.sign(p.x) * 60;
					p.y += Math.sign(p.y) * 60;
					p.add(selnode.location);
					p.snapToGridPoint(e.diagram.grid.gridOrigin, e.diagram.grid.gridCellSize);
					// make the new node a copy of the selected node
					var nodedata = m.copyNodeData(selnode.data);
					// add to same group as selected node
					m.setGroupKeyForNodeData(nodedata, m.getGroupKeyForNodeData(selnode.data));
					m.addNodeData(nodedata);  // add to model
					// create a link from the selected node to the new node
					var linkdata = { from: selnode.key, to: m.getKeyForNodeData(nodedata) };
					m.addLinkData(linkdata);  // add to model
					// move the new node to the computed location, select it, and start to edit it
					var newnode = e.diagram.findNodeForData(nodedata);
					newnode.location = p;
					e.diagram.select(newnode);
					setTimeout(function() {
					e.diagram.commandHandler.editTextBlock();
					}, 20);
				});
			};
         	return $(go.Shape,
            {
				figure: fig,
				alignment: spot, alignmentFocus: spot.opposite(),
				width: (spot.equals(go.Spot.Top) || spot.equals(go.Spot.Bottom)) ? 36 : 18,
				height: (spot.equals(go.Spot.Top) || spot.equals(go.Spot.Bottom)) ? 18 : 36,
				fill: "orange", strokeWidth: 0,
				isActionable: true,  // needed because it's in an Adornment
				click: maker, contextClick: maker
            })
        }
    //加载已经画好的图
    function load(){
        myDiagram.model = go.Model.fromJson(nodeData);
    }
    // load()

/*****************创建选盘(工具栏)**************************** */
    myPalette =
    $(go.Palette, "myPaletteDiv", 
        {
            "animationManager.initialAnimationStyle": go.AnimationManager.None,
            // "InitialAnimationStarting": animateFadeDown, // Instead, animate with this function
            nodeTemplateMap: myDiagram.nodeTemplateMap,  // share the templates used by myDiagram
            model: new go.GraphLinksModel([  // specify the contents of the Palette
            { category: "Start", text: "robot_error" ,key:'robot_error',name:"robot01"},
            { text:'robot_stand',key:"robot_stand",name:"robot02"},
            { category: "Conditional", text: "vision_error",key:'vision_error',name:"vision01"},
            { category: "End", text: "vision_stand",key:'vision_stand',name:"vision02"},
            // { category: "Comment", text: "Comment"}
            ])
        })

    }
//保存新的图形已经原有的
function save(){
    let newNode =  myDiagram.model.toJson()
   
}
   

总结

还在青铜段位,更多知识等待开黑探索中…
参考官网的实列流程图1
参考官网链接2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: IPD, CMMI和Scrum都是与软件开发和项目管理相关的方法或模型。 IPD是指集成项目交付模型(Integrated Project Delivery),它是一种用于建筑和工程项目的协作方法。IPD的特点是项目团队的共同决策和利益共享,通过整合各方的资源和专业知识,实现项目高效快速交付,并提升项目质量和客户满意度。 CMMI是指能力成熟度模型集成(Capability Maturity Model Integration),它是一种用于评估和提升组织过程能力的模型。CMMI的评估标准包括5个成熟度级别和4个能力级别,通过对组织过程的管理和改进,实现项目效率和质量的提升,推动组织的持续改进。 Scrum是一种敏捷项目管理方法,它强调团队合作、迭代开发和快速反馈。Scrum通过将项目切分为多个迭代周期(Sprint),每个迭代周期都包括需求规划、任务分配、开发、测试和演示等环节,实现对项目的可控和可见,同时提高团队的协作和响应能力。 青铜是三种方法或模型的不同级别。通常来说,青铜级别是初级阶段,代表对方法或模型的基本了解和应用。在软件开发和项目管理领域,青铜级别通常意味着初步落地了IPD、CMMI或Scrum的实践,并开始产生一定的效果。 总之,IPD、CMMI和Scrum是在软件开发和项目管理领域常用的方法或模型,通过它们的应用可以提升项目效率和质量,促进团队合作和创新。青铜级别则是初级阶段,代表对这些方法或模型的基本掌握和应用。 ### 回答2: IPD、CMMI和Scrum都是软件开发领域中的一些方法和框架。 IPD是集成项目交付的缩写,它强调了团队合作和跨职能团队的重要性。IPD方法鼓励项目各方在整个项目周期中共同参与决策和问题解决,从而帮助项目更好地满足需求和实现交付目标。 CMMI是能力成熟度模型集成的缩写,它是一种软件开发过程改进模型。CMMI根据不同级别的能力成熟度,提供了一系列的最佳实践和指南,旨在帮助组织提高软件开发和管理的能力,并更好地满足客户需求。 Scrum是一种敏捷项目管理方法,它强调迭代和增量的开发方式。Scrum框架包括由跨职能团队组成的迭代周期,称为Sprint,以及一系列会议和技术实践,以促进团队协作和项目交付。 青铜可能是指这些方法和框架在等级上的一个比喻。青铜等级通常表示入门级别或初级水平。在软件开发领域,青铜级别可能指的是刚开始应用IPD、CMMI和Scrum的组织或团队,他们正在学习和适应这些方法和框架,并逐步积累经验和能力。 综上所述,IPD、CMMI和Scrum都是软件开发领域中的一些方法和框架,它们分别强调团队合作、过程改进和敏捷项目管理。在刚开始应用这些方法和框架的组织或团队可能被称为青铜级别,表示他们的水平是初级或入门水平。 ### 回答3: IPD(面向项目的开发)是一种项目管理模型,它将不同的开发阶段集成在一起,以达到更高的效率和质量。CMMI(能力成熟度模型集成)是一种评估和改进组织软件开发能力的框架,它主要关注过程和实践的管理。Scrum是一种敏捷开发方法,强调灵活性、自组织和迭代开发。青铜则是指低级别或基础级别。 要将这些概念联系在一起,首先我们可以说IPD是一个综合了CMMI和Scrum的项目管理方法。IPD充分借鉴了CMMI的过程管理和质量控制,使项目能够更好地符合标准和规范。同时,IPD也采用了Scrum的敏捷开发理念,通过短周期的迭代开发,快速适应变化和实时反馈。 在一个IPD项目中,团队成员可以根据Scrum的原则自组织和自主管理工作。Scrum中的角色如Scrum主管、产品负责人和开发团队也可以与CMMI中的过程负责人和项目团队进行对应。利用CMMI的过程和实践,IPD能够确保项目按照既定的标准和质量要求进行。通过Scrum的灵活性和快速反馈,IPD能够及时调整项目计划和优化开发过程。 总的来说,IPD是一个将CMMI和Scrum相结合的项目管理方法,它既关注过程和实践的规范,又强调团队的灵活性和自组织能力。青铜表示基础级别,可能意味着在实施IPD过程中还有提升的空间,需要不断改进和学习。对于一个团队来说,理解和应用IPD、CMMI和Scrum的原则和方法都是非常重要的,这将有助于提高项目开发的效率和质量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值