日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

图形化编程 html,用GoJS实现图形化交互编程界面示例

發布時間:2023/11/27 生活经验 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图形化编程 html,用GoJS实现图形化交互编程界面示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

JavaScript

語言:

JaveScriptBabelCoffeeScript

確定

function init() {

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

myDiagram =

$(go.Diagram, "myDiagramDiv", //Diagram refers to its DIV HTML element by id

{

"undoManager.isEnabled": true

});

// when the document is modified, add a "*" to the title and enable the "Save" button

myDiagram.addDiagramListener("Modified", function(e) {

var button = document.getElementById("SaveButton");

if (button) button.disabled = !myDiagram.isModified;

var idx = document.title.indexOf("*");

if (myDiagram.isModified) {

if (idx < 0) document.title += "*";

} else {

if (idx >= 0) document.title = document.title.substr(0, idx);

}

});

// To simplify this code we define a function for creating a context menu button:

function makeButton(text, action, visiblePredicate) {

return $("ContextMenuButton",

$(go.TextBlock, text), {

click: action

},

// don't bother with binding GraphObject.visible if there's no predicate

visiblePredicate ? new go.Binding("visible", "", function(o, e) {

return o.diagram ? visiblePredicate(o, e) : false;

}).ofObject() : {});

}

var nodeMenu = // context menu for each Node

$("ContextMenu",

makeButton("Copy",

function(e, obj) {

e.diagram.commandHandler.copySelection();

}),

makeButton("Delete",

function(e, obj) {

e.diagram.commandHandler.deleteSelection();

}),

$(go.Shape, "LineH", {

strokeWidth: 2,

height: 1,

stretch: go.GraphObject.Horizontal

}),

makeButton("Add top port",

function(e, obj) {

addPort("top");

}),

makeButton("Add left port",

function(e, obj) {

addPort("left");

}),

makeButton("Add right port",

function(e, obj) {

addPort("right");

}),

makeButton("Add bottom port",

function(e, obj) {

addPort("bottom");

})

);

var portSize = new go.Size(8, 8);

var portMenu = // context menu for each port

$("ContextMenu",

makeButton("Swap order",

function(e, obj) {

swapOrder(obj.part.adornedObject);

}),

makeButton("Remove port",

// in the click event handler, the obj.part is the Adornment;

// its adornedObject is the port

function(e, obj) {

removePort(obj.part.adornedObject);

}),

makeButton("Change color",

function(e, obj) {

changeColor(obj.part.adornedObject);

}),

makeButton("Remove side ports",

function(e, obj) {

removeAll(obj.part.adornedObject);

})

);

// the node template

// includes a panel on each side with an itemArray of panels containing ports

myDiagram.nodeTemplate =

$(go.Node, "Table", {

locationObjectName: "BODY",

locationSpot: go.Spot.Center,

selectionObjectName: "BODY",

contextMenu: nodeMenu

},

new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),

// the body

$(go.Panel, "Auto", {

row: 1,

column: 1,

name: "BODY",

stretch: go.GraphObject.Fill

},

$(go.Shape, "Rectangle", {

fill: "#AC193D",

stroke: null,

strokeWidth: 0,

minSize: new go.Size(56, 56)

}),

$(go.TextBlock, {

margin: 10,

textAlign: "center",

font: "14px Segoe UI,sans-serif",

stroke: "white",

editable: true

},

new go.Binding("text", "name").makeTwoWay())

), // end Auto Panel body

// the Panel holding the left port elements, which are themselves Panels,

// created for each item in the itemArray, bound to data.leftArray

$(go.Panel, "Vertical",

new go.Binding("itemArray", "leftArray"), {

row: 1,

column: 0,

itemTemplate: $(go.Panel, {

_side: "left", // internal property to make it easier to tell which side it's on

fromSpot: go.Spot.Left,

toSpot: go.Spot.Left,

fromLinkable: true,

toLinkable: true,

cursor: "pointer",

contextMenu: portMenu

},

new go.Binding("portId", "portId"),

$(go.Shape, "Rectangle", {

stroke: null,

strokeWidth: 0,

desiredSize: portSize,

margin: new go.Margin(1, 0)

},

new go.Binding("fill", "portColor"))

) // end itemTemplate

}

), // end Vertical Panel

// the Panel holding the top port elements, which are themselves Panels,

// created for each item in the itemArray, bound to data.topArray

$(go.Panel, "Horizontal",

new go.Binding("itemArray", "topArray"), {

row: 0,

column: 1,

itemTemplate: $(go.Panel, {

_side: "top",

fromSpot: go.Spot.Top,

toSpot: go.Spot.Top,

fromLinkable: true,

toLinkable: true,

cursor: "pointer",

contextMenu: portMenu

},

new go.Binding("portId", "portId"),

$(go.Shape, "Rectangle", {

stroke: null,

strokeWidth: 0,

desiredSize: portSize,

margin: new go.Margin(0, 1)

},

new go.Binding("fill", "portColor"))

) // end itemTemplate

}

), // end Horizontal Panel

// the Panel holding the right port elements, which are themselves Panels,

// created for each item in the itemArray, bound to data.rightArray

$(go.Panel, "Vertical",

new go.Binding("itemArray", "rightArray"), {

row: 1,

column: 2,

itemTemplate: $(go.Panel, {

_side: "right",

fromSpot: go.Spot.Right,

toSpot: go.Spot.Right,

fromLinkable: true,

toLinkable: true,

cursor: "pointer",

contextMenu: portMenu

},

new go.Binding("portId", "portId"),

$(go.Shape, "Rectangle", {

stroke: null,

strokeWidth: 0,

desiredSize: portSize,

margin: new go.Margin(1, 0)

},

new go.Binding("fill", "portColor"))

) // end itemTemplate

}

), // end Vertical Panel

// the Panel holding the bottom port elements, which are themselves Panels,

// created for each item in the itemArray, bound to data.bottomArray

$(go.Panel, "Horizontal",

new go.Binding("itemArray", "bottomArray"), {

row: 2,

column: 1,

itemTemplate: $(go.Panel, {

_side: "bottom",

fromSpot: go.Spot.Bottom,

toSpot: go.Spot.Bottom,

fromLinkable: true,

toLinkable: true,

cursor: "pointer",

contextMenu: portMenu

},

new go.Binding("portId", "portId"),

$(go.Shape, "Rectangle", {

stroke: null,

strokeWidth: 0,

desiredSize: portSize,

margin: new go.Margin(0, 1)

},

new go.Binding("fill", "portColor"))

) // end itemTemplate

}

) // end Horizontal Panel

); // end Node

// an orthogonal link template, reshapable and relinkable

myDiagram.linkTemplate =

$(CustomLink, // defined below

{

routing: go.Link.AvoidsNodes,

corner: 4,

curve: go.Link.JumpGap,

reshapable: true,

resegmentable: true,

relinkableFrom: true,

relinkableTo: true

},

new go.Binding("points").makeTwoWay(),

$(go.Shape, {

stroke: "#2F4F4F",

strokeWidth: 2

})

);

// support double-clicking in the background to add a copy of this data as a node

myDiagram.toolManager.clickCreatingTool.archetypeNodeData = {

name: "Unit",

leftArray: [],

rightArray: [],

topArray: [],

bottomArray: []

};

myDiagram.contextMenu =

$("ContextMenu",

makeButton("Paste",

function(e, obj) {

e.diagram.commandHandler.pasteSelection(e.diagram.lastInput.documentPoint);

},

function(o) {

return o.diagram.commandHandler.canPasteSelection();

}),

makeButton("Undo",

function(e, obj) {

e.diagram.commandHandler.undo();

},

function(o) {

return o.diagram.commandHandler.canUndo();

}),

makeButton("Redo",

function(e, obj) {

e.diagram.commandHandler.redo();

},

function(o) {

return o.diagram.commandHandler.canRedo();

})

);

// load the diagram from JSON data

load();

}

// This custom-routing Link class tries to separate parallel links from each other.

// This assumes that ports are lined up in a row/column on a side of the node.

function CustomLink() {

go.Link.call(this);

};

go.Diagram.inherit(CustomLink, go.Link);

CustomLink.prototype.findSidePortIndexAndCount = function(node, port) {

var nodedata = node.data;

if (nodedata !== null) {

var portdata = port.data;

var side = port._side;

var arr = nodedata[side + "Array"];

var len = arr.length;

for (var i = 0; i < len; i++) {

if (arr[i] === portdata) return [i, len];

}

}

return [-1, len];

};

CustomLink.prototype.computeEndSegmentLength = function(node, port, spot, from) {

var esl = go.Link.prototype.computeEndSegmentLength.call(this, node, port, spot, from);

var other = this.getOtherPort(port);

if (port !== null && other !== null) {

var thispt = port.getDocumentPoint(this.computeSpot(from));

var otherpt = other.getDocumentPoint(this.computeSpot(!from));

if (Math.abs(thispt.x - otherpt.x) > 20 || Math.abs(thispt.y - otherpt.y) > 20) {

var info = this.findSidePortIndexAndCount(node, port);

var idx = info[0];

var count = info[1];

if (port._side == "top" || port._side == "bottom") {

if (otherpt.x < thispt.x) {

return esl + 4 + idx * 8;

} else {

return esl + (count - idx - 1) * 8;

}

} else { // left or right

if (otherpt.y < thispt.y) {

return esl + 4 + idx * 8;

} else {

return esl + (count - idx - 1) * 8;

}

}

}

}

return esl;

};

CustomLink.prototype.hasCurviness = function() {

if (isNaN(this.curviness)) return true;

return go.Link.prototype.hasCurviness.call(this);

};

CustomLink.prototype.computeCurviness = function() {

if (isNaN(this.curviness)) {

var fromnode = this.fromNode;

var fromport = this.fromPort;

var fromspot = this.computeSpot(true);

var frompt = fromport.getDocumentPoint(fromspot);

var tonode = this.toNode;

var toport = this.toPort;

var tospot = this.computeSpot(false);

var topt = toport.getDocumentPoint(tospot);

if (Math.abs(frompt.x - topt.x) > 20 || Math.abs(frompt.y - topt.y) > 20) {

if ((fromspot.equals(go.Spot.Left) || fromspot.equals(go.Spot.Right)) &&

(tospot.equals(go.Spot.Left) || tospot.equals(go.Spot.Right))) {

var fromseglen = this.computeEndSegmentLength(fromnode, fromport, fromspot, true);

var toseglen = this.computeEndSegmentLength(tonode, toport, tospot, false);

var c = (fromseglen - toseglen) / 2;

if (frompt.x + fromseglen >= topt.x - toseglen) {

if (frompt.y < topt.y) return c;

if (frompt.y > topt.y) return -c;

}

} else if ((fromspot.equals(go.Spot.Top) || fromspot.equals(go.Spot.Bottom)) &&

(tospot.equals(go.Spot.Top) || tospot.equals(go.Spot.Bottom))) {

var fromseglen = this.computeEndSegmentLength(fromnode, fromport, fromspot, true);

var toseglen = this.computeEndSegmentLength(tonode, toport, tospot, false);

var c = (fromseglen - toseglen) / 2;

if (frompt.x + fromseglen >= topt.x - toseglen) {

if (frompt.y < topt.y) return c;

if (frompt.y > topt.y) return -c;

}

}

}

}

return go.Link.prototype.computeCurviness.call(this);

};

// end CustomLink class

// Add a port to the specified side of the selected nodes.

function addPort(side) {

myDiagram.startTransaction("addPort");

myDiagram.selection.each(function(node) {

// skip any selected Links

if (!(node instanceof go.Node)) return;

// compute the next available index number for the side

var i = 0;

while (node.findPort(side + i.toString()) !== node) i++;

// now this new port name is unique within the whole Node because of the side prefix

var name = side + i.toString();

// get the Array of port data to be modified

var arr = node.data[side + "Array"];

if (arr) {

// create a new port data object

var newportdata = {

portId: name,

portColor: go.Brush.randomColor()

// if you add port data properties here, you should copy them in copyPortData above

};

// and add it to the Array of port data

myDiagram.model.insertArrayItem(arr, -1, newportdata);

}

});

myDiagram.commitTransaction("addPort");

}

// Exchange the position/order of the given port with the next one.

// If it's the last one, swap with the previous one.

function swapOrder(port) {

var arr = port.panel.itemArray;

if (arr.length >= 2) { // only if there are at least two ports!

for (var i = 0; i < arr.length; i++) {

if (arr[i].portId === port.portId) {

myDiagram.startTransaction("swap ports");

if (i >= arr.length - 1) i--; // now can swap I and I+1, even if it's the last port

var newarr = arr.slice(0); // copy Array

newarr[i] = arr[i + 1]; // swap items

newarr[i + 1] = arr[i];

// remember the new Array in the model

myDiagram.model.setDataProperty(port.part.data, port._side + "Array", newarr);

myDiagram.commitTransaction("swap ports");

break;

}

}

}

}

// Remove the clicked port from the node.

// Links to the port will be redrawn to the node's shape.

function removePort(port) {

myDiagram.startTransaction("removePort");

var pid = port.portId;

var arr = port.panel.itemArray;

for (var i = 0; i < arr.length; i++) {

if (arr[i].portId === pid) {

myDiagram.model.removeArrayItem(arr, i);

break;

}

}

myDiagram.commitTransaction("removePort");

}

// Remove all ports from the same side of the node as the clicked port.

function removeAll(port) {

myDiagram.startTransaction("removePorts");

var nodedata = port.part.data;

var side = port._side; // there are four property names, all ending in "Array"

myDiagram.model.setDataProperty(nodedata, side + "Array", []); // an empty Array

myDiagram.commitTransaction("removePorts");

}

// Change the color of the clicked port.

function changeColor(port) {

myDiagram.startTransaction("colorPort");

var data = port.data;

myDiagram.model.setDataProperty(data, "portColor", go.Brush.randomColor());

myDiagram.commitTransaction("colorPort");

}

// Save the model to / load it from JSON text shown on the page itself, not in a database.

function save() {

document.getElementById("mySavedModel").value = myDiagram.model.toJson();

myDiagram.isModified = false;

}

function load() {

myDiagram.model = go.Model.fromJson(document.getElementById("mySavedModel").value);

// When copying a node, we need to copy the data that the node is bound to.

// This JavaScript object includes properties for the node as a whole, and

// four properties that are Arrays holding data for each port.

// Those arrays and port data objects need to be copied too.

// Thus Model.copiesArrays and Model.copiesArrayObjects both need to be true.

// Link data includes the names of the to- and from- ports;

// so the GraphLinksModel needs to set these property names:

// linkFromPortIdProperty and linkToPortIdProperty.

}

window.onload = function() {

init()

};

總結

以上是生活随笔為你收集整理的图形化编程 html,用GoJS实现图形化交互编程界面示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 91污网站 | 美女张开腿让男人桶爽 | 中文字幕高清一区 | 国产精品免费电影 | 日日夜夜操操操 | 婷婷视频网 | 伊人称影院 | 香蕉视频官方网站 | 91黄视频在线观看 | 国产专区一区二区三区 | 久久婷婷网 | 超碰啪啪| 少妇三级全黄 | 特黄aaaaaaaaa毛片免费视频 | 中文字幕欧美人妻精品 | a v视频在线观看 | 国产精品无码中文 | 国产视频第三页 | 色老板最新地址 | 亚洲第一区av | 国产剧情一区在线 | 成人乱人乱一区二区三区 | 影院色原网站 | 日韩欧美激情视频 | 欧美精品在线一区二区三区 | 国产精品高潮呻吟久久 | 女人色极品影院 | 菲律宾黄色片 | 亚洲一区二区三区高清 | 男人天堂2014 | 青青操网 | 一区二区三区视频播放 | 91精选视频 | 日本a级无毛| www黄色网| 高级家教课程在线观看 | 亚洲成人三区 | 午夜毛片在线 | 天天躁夜夜躁av天天爽 | 久久精品aⅴ无码中文字字幕重口 | 乱色视频 | 亚洲女同在线 | 99香蕉视频 | 欧美丰满bbw | 亚洲视频欧美 | 欧美日韩片 | 中文字幕永久在线观看 | 久久久精品日韩 | 日韩欧美一级二级 | 成人激情社区 | 日本美女a级片 | 五月婷婷亚洲 | 激情亚洲网 | aaaaaav| 喷水了…太爽了高h | 国产精品theporn88| 色很久| 中文字幕1区2区3区 www.com黄色片 | 国精产品一区一区三区mba下载 | 国产一区二区三区在线视频 | 国产精品污 | 黄色avv | 国产精品乱码一区二三区小蝌蚪 | 伊人久久超碰 | 超级变态重口av番号 | 国产三级视频在线播放 | 午夜888| www.av88| 天天爱综合网 | 日韩精品区 | 国产美女免费观看 | 欧美一区二 | 尤物网址在线观看 | 亚洲天堂久久新 | 91视频一区二区 | 成人免费看片视频 | 久热国产精品 | 精品国产鲁一鲁一区二区张丽 | 高清日韩av| 亚洲av成人精品一区二区三区 | 国产精品99精品久久免费 | 国产高清无遮挡 | 久久久久久久九九九九 | 人人干干| 欧美偷拍一区二区三区 | 白浆一区| 国产3p视频 | 久久久久久久一区 | 成人精品在线观看视频 | 男女网站在线观看 | 欧美性高潮 | 久久亚洲综合色 | 欧美日韩中 | 在线中文字幕日韩 | 亚洲字幕av一区二区三区四区 | 欧美黄色大片免费观看 | 色综合久久88色综合天天 | 国产色婷婷 | 国产明星换脸xxxx色视频 |