翻译|使用教程|编辑:黄竹雯|2018-11-16 14:36:28.000|阅读 1623 次
概述:轻量级流程图控件GoJS流程图示例
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
GoJS是一款功能强大,快速且轻量级的流程图控件,可帮助你在JavaScript 和 HTML5 Canvas程序中创建流程图,且极大地简化你的JavaScript / Canvas 程序。
FlowChart示例演示了GoJS的几个关键功能,即, ,拖放行为, 以及图表中的使用 。
鼠标悬停在节点上以查看其端口。从这些端口拖动以创建新的链接。选择“链接”可以重新整形和重新链接它们。选择节点然后单击其TextBlock将允许您编辑文本(开始和结束节点除外)。
在页面中查看此示例页面的源代码
function init () {
if(window.goSamples)goSamples(); //这些样本的init - 你不需要调用这个
var $ = go.GraphObject.make; //为了简洁定义模板
myDiagram =
$(go.Diagram,“myDiagramDiv”, //必须命名或引用DIV HTML元素
{
initialContentAlignment:go.Spot.Center,
allowDrop:true, //必须为true才能接受来自Palette
“LinkDrawn”的 drop:showLinkLabel, //这个DiagramEvent监听器定义在
“LinkRelinked” 下面:showLinkLabel,
scrollsPageOnFocus:false,
“undoManager.isEnabled”:true //启用undo&redo
});
//修改文档时,在标题中添加“*”并启用“保存”按钮
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);
}
});
//节点模板的帮助程序定义
function nodeStyle () {
return [
// Node.location来自节点数据的“loc”属性,
//由Point.parse静态方法转换。
//如果更改了Node.location,它将更新节点数据的“loc”属性,
//使用Point.stringify静态方法转换回来。
new go.Binding( “location”, “loc”,go.Point.parse).makeTwoWay(go.Point.stringify),
{
// Node.location位于每个节点的中心
locationSpot:go.Spot.Center
}
]。
}
//定义用于创建通常透明的“端口”的函数。
//“name”用作GraphObject.portId,
//“align”用于确定端口相对于节点主体的位置,
//“spot”用于控制链接的连接方式使用端口以及端口
//
是否沿节点一侧延伸,//布尔“输出”和“输入”参数控制用户是否可以从端口绘制链接或从端口绘制链接。
function makePort (name,align,spot,output,input) {
var horizontal = align.equals(go.Spot.Top)|| align.equals(go.Spot.Bottom);
//当鼠标经过它时变成彩色
返回 $(go.Shape,
{
fill:“transparent”, //更改为mouseEnter事件处理程序中的颜色
strokeWidth:0, //没有笔画
宽度:水平?NaN:8, //如果不是水平拉伸,只有8个宽度
:水平?NaN:8, //如果不垂直拉伸,只需8个高
对齐:对齐, //对齐主形状上的端口
stretch :(水平?go.GraphObject.Horizontal:go.GraphObject.Vertical),
portId:name, //声明此对象是
来自Spot 的“端口”:spot, //声明链接可以在此端口连接的
地址fromLinkable:output, //声明用户是否可以从此处绘制链接到
Spot:spot, //声明链接可以在此端口连接到链接的
位置:input, //声明用户是否可以在此处绘制链接
:“指针”, //显示不同的光标以指示潜在的链接点
mouseEnter:function (e,port) { / / PORT参数将是这个Shape
if(!e.diagram.isReadOnly)port.fill = “rgba(255,0,255,0.5)” ;
},
mouseLeave:function (e,port) {
port.fill = “transparent” ;
}
});
}
function textStyle () {
return {
字体:“bold 11pt Helvetica,Arial,sans-serif”,
中风:“whitesmoke”
}
}
//定义常规节点的节点模板
myDiagram.nodeTemplateMap.add(“”, //默认类别
$(go.Node,“Table”,nodeStyle(),
//主要对象是一个围绕TextBlock的面板,其形状
为矩形 $(go.Panel,“自动”,
$(go.Shape,“矩形”,
{fill:“#00A9C9”,strokeWidth:0 },
new go.Binding(“figure”,“figure”)),
$(go.TextBlock,textStyle(),
{
保证金:8,
maxSize:new go.Size(160,NaN),
换行:go.TextBlock.WrapFit,
可编辑:是的
},
new go.Binding(“text”)。makeTwoWay())
)
//四个命名端口,每边一个:
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.nodeTemplateMap.add(“有条件的”,
$(go.Node,“Table”,nodeStyle(),
//主要对象是一个围绕TextBlock的面板,其矩形形状
为$(go.Panel,“Auto”,
$(go.Shape,“钻石”,
{fill:“#00A9C9”,strokeWidth:0 },
new go.Binding(“figure”,“figure”)),
$(go.TextBlock,textStyle(),
{
保证金:8,
maxSize:new go.Size(160,NaN),
换行:go.TextBlock.WrapFit,
可编辑:是的
},
new go.Binding(“text”)。makeTwoWay())
)
//四个命名端口,每边一个:
makePort(“T”,go.Spot.Top,go.Spot.Top,false,true),
makePort(“L”,go.Spot.Left,go.Spot.Left,true,true),
makePort(“R”,go.Spot.Right,go.Spot.Right,true,true),
makePort(“B”,go.Spot.Bottom,go.Spot.Bottom,true,false)
));
myDiagram.nodeTemplateMap.add(“开始”,
$(go.Node,“Table”,nodeStyle(),
$(go.Panel,“自动”,
$(go.Shape,“Circle”,
{minSize属性:新 go.Size(40,40),填充:“#79C900”,strokeWidth:0 }),
$(go.TextBlock,“Start”,textStyle(),
new go.Binding(“text”))
)
//三个命名端口,除了顶部之外每边一个,只输出:
makePort(“L”,go.Spot.Left,go.Spot.Left,true,false),
makePort(“R”,go.Spot.Right,go.Spot.Right,true,false),
makePort(“B”,go.Spot.Bottom,go.Spot.Bottom,true,false)
));
myDiagram.nodeTemplateMap.add(“结束”,
$(go.Node,“Table”,nodeStyle(),
$(go.Panel,“自动”,
$(go.Shape,“Circle”,
{minSize属性:新 go.Size(40,40),填充:“#DC3C00”,strokeWidth:0 }),
$(go.TextBlock,“End”,textStyle(),
new go.Binding(“text”))
)
//三个命名端口,每边一个除了底部,只有输入:
makePort(“T”,go.Spot.Top,go.Spot.Top,false,true),
makePort(“L”,go.Spot.Left,go.Spot.Left,false,true),
makePort(“R”,go.Spot.Right,go.Spot.Right,false,true)
));
myDiagram.nodeTemplateMap.add(“评论”,
$(go.Node,“Auto”,nodeStyle(),
$(go.Shape,“档案”,
{fill:“#EFFAB4”,strokeWidth:0 }),
$(go.TextBlock,textStyle(),
{
保证金:5,
maxSize:new go.Size(200,NaN),
换行:go.TextBlock.WrapFit,
textAlign:“center”,
可编辑:是的,
字体:“bold 12pt Helvetica,Arial,sans-serif”,
中风:'#454545'
},
new go.Binding(“text”)。makeTwoWay())
//没有端口,因为没有链接允许连接评论
));
//替换linkTemplateMap中的默认链接模板
myDiagram.linkTemplate =
$(go.Link, //整个链接面板
{
路由:go.Link.AvoidsNodes,
曲线:go.Link.JumpOver,
角落:5,toShortLength:4,
relinkable来自:true,
relinkableTo:是的,
reshapable:是的,
resegmentable:true,
//鼠标悬停巧妙地突出显示链接:
mouseEnter:function (e,link) { link.findObject(“HIGHLIGHT”)。stroke = “rgba(30,144,255,0.2)” ; },
mouseLeave:function (e,link) { link.findObject(“HIGHLIGHT”)。stroke = “transparent” ; },
selectionAdorned:false
},
new go.Binding(“points”)。makeTwoWay(),
$(go.Shape, //高亮形状,通常透明
{isPanelMain:true,strokeWidth:8,笔画:“透明”,名称:“HIGHLIGHT” }),
$(go.Shape, //链接路径形状
{isPanelMain:true,stroke:“gray”,strokeWidth:2 },
new go.Binding(“stroke”,“isSelected”,function (sel) { return sel?“ dodgerblue“:”grey“ ;})。ofObject()),
$(go.Shape, //箭头
{toArrow:“标准”,strokeWidth:0,填充:“灰色” }),
$(go.Panel,“Auto”, //链接标签,通常不可见
{visible:false,name:“LABEL”,segmentIndex:2,segmentFraction:0.5 },
new go.Binding(“visible”,“visible” “)。makeTwoWay(),
$(go.Shape,“ RoundedRectangle ”, //标签形状
{fill:“#F8F8F8”,strokeWidth:0 }),
$(go.TextBlock,“是”, //标签
{
textAlign:“center”,
字体:“10pt helvetica,arial,sans-serif”,
中风:“#333333”,
可编辑:是的
},
new go.Binding(“text”)。makeTwoWay())
)
);
//如果出现“条件”节点,则可以看到链接标签。
//此侦听器由“LinkDrawn”和“LinkRelinked”DiagramEvents调用。
function showLinkLabel (e) {
var label = e.subject.findObject(“LABEL”);
if(label!== null)label.visible =(e.subject.fromNode.data.category === “Conditional”);
}
// LinkingTool和RelinkingTool使用的临时链接也是正交的:
myDiagram.toolManager.linkingTool.temporaryLink.routing = go.Link.Orthogonal;
myDiagram.toolManager.relinkingTool.temporaryLink.routing = go.Link.Orthogonal;
加载(); //从一些JSON文本加载初始图表
//初始化页面左侧的Palette
myPalette =
$(go.Palette,“myPaletteDiv”, //必须命名或引用DIV HTML元素
{
scrollsPageOnFocus:false,
nodeTemplateMap:myDiagram.nodeTemplateMap, //共享myDiagram
模型使用的模板:new go.GraphLinksModel([ //指定Palette的内容
{category:“Start”,text:“Start” },
{text:“Step” },
{category:“Conditional”,text:“???” },
{category:“End”,text:“End” },
{category:“Comment”,text:“Comment” }
])
});
} //结束init
//以JSON格式显示图表模型,用户可以编辑
函数 save () {
document.getElementById(“mySavedModel”)。value = myDiagram.model.toJson();
myDiagram.isModified = false ;
}
function load () {
myDiagram.model = go.Model.fromJson(document.getElementById( “mySavedModel”)。 value);
}
//通过打开一个新窗口来打印图表,该窗口包含每个页面
函数 printDiagram ()
的图表内容的SVG图像{ var svgWindow = window.open();
if(!svgWindow)返回 ; //未能打开一个新的窗口
变种 printSize = 新 go.Size(700,960);
var bnds = myDiagram.documentBounds;
var x = bnds.x;
var y = bnds.y;
while(y <bnds.bottom){
while(x <bnds.right){
var svg = myDiagram.makeSVG({scale:1.0,position:new go.Point(x,y),size:printSize});
svgWindow.document.body.appendChild(SVG);
x + = printSize.width;
}
x = bnds.x;
y + = printSize.height;
}
setTimeout(function () { svgWindow.print();},1);
}
< div id = “sample” >
< div style = “width:100%; display:flex; justify-content:space-between” >
< div id = “myPaletteDiv” style = “width:100px; margin-right:2px ; background-color:whitesmoke; border:solid 1px black“ > </ div >
< div id = ”myDiagramDiv“ style = ”flex-grow:1; height:750px; border:solid 1px black“ > </ div >
< / div >
< p >
FlowChart示例演示了GoJS的几个关键功能,
即< 一个 HREF = “../intro/palette.html” >调色板</ 一 > S,
< 一 HREF = “../intro/links.html” >可链接节点</ 一 >,拖/放行为,
< 一个 HREF = “../intro/textBlocks.html” >文本编辑</ 一 >,以及使用
< 一个 HREF = “../intro/templateMaps.html” >节点模板地图</ 一 >在图表中。
</ p >
< p >
鼠标悬停在节点上以查看其端口。
从这些端口拖动以创建新的链接。
选择“链接”可以重新整形和重新链接它们。
选择一个节点,然后单击其TextBlock将允许
您要编辑文本(开始和结束节点除外)。
</ p >
< button id = “SaveButton” onclick = “save()” > Save </ button >
< button onclick = “load()” > Load </ button >
图模型以JSON格式保存:
< textarea id = “mySavedModel” style = “width:100%; height:300px” > {“class”:“go.GraphLinksModel”,
“linkFromPortIdProperty”:“fromPort”,
“linkToPortIdProperty”:“toPort”,
“nodeDataArray”:[
{“category”:“Comment”,“loc”:“360 -10”,“text”:“Kookie Brittle”,“key”: - 13},
{“key”: - 1,“category”:“Start”,“loc”:“175 0”,“text”:“Start”},
{“key”:0,“loc”:“ - 5 75”,“text”:“将烤箱预热到375 F”},
{“key”:1,“loc”:“175 100”,“text”:“在一个碗里,混合:1杯人造黄油,1.5茶匙香草,1茶匙盐”},
{“key”:2,“loc”:“175 200”,“text”:“逐渐打入1杯糖和2杯筛面粉”},
{“key”:3,“loc”:“175 290”,“text”:“混合6盎司(1杯)雀巢的半甜巧克力酱”},
{“key”:4,“loc”:“175 380”,“text”:“均匀按压到15x10x1 pan”},
{“key”:5,“loc”:“355 85”,“text”:“精选1/2杯你选择的坚果”},
{“key”:6,“loc”:“175 450”,“text”:“顶上撒上坚果”},
{“key”:7,“loc”:“175 515”,“text”:“烘烤25分钟,让凉爽”},
{“key”:8,“loc”:“175 585”,“text”:“切成矩形网格”},
{“key”: - 2,“category”:“End”,“loc”:“175 660”,“text”:“Enjoy!”}
]
“linkDataArray”:[
{“from”:1,“to”:2,“fromPort”:“B”,“toPort”:“T”},
{“from”:2,“to”:3,“fromPort”:“B”,“toPort”:“T”},
{“from”:3,“to”:4,“fromPort”:“B”,“toPort”:“T”},
{“from”:4,“to”:6,“fromPort”:“B”,“toPort”:“T”},
{“from”:6,“to”:7,“fromPort”:“B”,“toPort”:“T”},
{“from”:7,“to”:8,“fromPort”:“B”,“toPort”:“T”},
{“from”:8,“to”: - 2,“fromPort”:“B”,“toPort”:“T”},
{“from”: - 1,“to”:0,“fromPort”:“B”,“toPort”:“T”},
{“from”: - 1,“to”:1,“fromPort”:“B”,“toPort”:“T”},
{“from”: - 1,“to”:5,“fromPort”:“B”,“toPort”:“T”},
{“from”:5,“to”:4,“fromPort”:“B”,“toPort”:“T”},
{“from”:0,“to”:4,“fromPort”:“B”,“toPort”:“T”}
]}
</ textarea >
< button onclick = “printDiagram()” >使用SVG打印图</ button >
</ div >
在GitHub上查看此示例页面的源代码
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flowchart</title>
<meta name="description" content="Interactive flowchart diagram implemented by GoJS in JavaScript for HTML." />
<!-- 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 this
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagramDiv", // must name or refer to the DIV HTML element
{
initialContentAlignment: go.Spot.Center,
allowDrop: true, // must be true to accept drops from the Palette
"LinkDrawn": showLinkLabel, // this DiagramEvent listener is defined below
"LinkRelinked": showLinkLabel,
scrollsPageOnFocus: false,
"undoManager.isEnabled": true // enable undo & redo
});
// 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);
}
});
// helper definitions for node templates
function nodeStyle() {
return [
// The Node.location comes from the "loc" property of the node data,
// converted by the Point.parse static method.
// If the Node.location is changed, it updates the "loc" property of the node data,
// converting back using the Point.stringify static method.
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
}
];
}
// Define a function for creating a "port" that is normally transparent.
// The "name" is used as the GraphObject.portId,
// the "align" is used to determine where to position the port relative to the body of the node,
// the "spot" is used to control how links connect with the port and whether the port
// stretches along the side of the node,
// and the boolean "output" and "input" arguments control whether the user can draw links from or to the port.
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
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,0,255,0.5)";
},
mouseLeave: function(e, port) {
port.fill = "transparent";
}
});
}
function textStyle() {
return {
font: "bold 11pt Helvetica, Arial, sans-serif",
stroke: "whitesmoke"
}
}
// define the Node templates for regular nodes
myDiagram.nodeTemplateMap.add("", // the default category
$(go.Node, "Table", nodeStyle(),
// the main object is a Panel that surrounds a TextBlock with a rectangular Shape
$(go.Panel, "Auto",
$(go.Shape, "Rectangle",
{ fill: "#00A9C9", strokeWidth: 0 },
new go.Binding("figure", "figure")),
$(go.TextBlock, textStyle(),
{
margin: 8,
maxSize: new go.Size(160, NaN),
wrap: go.TextBlock.WrapFit,
editable: true
},
new go.Binding("text").makeTwoWay())
),
// four named ports, one on each side:
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.nodeTemplateMap.add("Conditional",
$(go.Node, "Table", nodeStyle(),
// the main object is a Panel that surrounds a TextBlock with a rectangular Shape
$(go.Panel, "Auto",
$(go.Shape, "Diamond",
{ fill: "#00A9C9", strokeWidth: 0 },
new go.Binding("figure", "figure")),
$(go.TextBlock, textStyle(),
{
margin: 8,
maxSize: new go.Size(160, NaN),
wrap: go.TextBlock.WrapFit,
editable: true
},
new go.Binding("text").makeTwoWay())
),
// four named ports, one on each side:
makePort("T", go.Spot.Top, go.Spot.Top, false, true),
makePort("L", go.Spot.Left, go.Spot.Left, true, true),
makePort("R", go.Spot.Right, go.Spot.Right, true, true),
makePort("B", go.Spot.Bottom, go.Spot.Bottom, true, false)
));
myDiagram.nodeTemplateMap.add("Start",
$(go.Node, "Table", nodeStyle(),
$(go.Panel, "Auto",
$(go.Shape, "Circle",
{ minSize: new go.Size(40, 40), fill: "#79C900", strokeWidth: 0 }),
$(go.TextBlock, "Start", textStyle(),
new go.Binding("text"))
),
// three named ports, one on each side except the top, all output only:
makePort("L", go.Spot.Left, go.Spot.Left, true, false),
makePort("R", go.Spot.Right, go.Spot.Right, true, false),
makePort("B", go.Spot.Bottom, go.Spot.Bottom, true, false)
));
myDiagram.nodeTemplateMap.add("End",
$(go.Node, "Table", nodeStyle(),
$(go.Panel, "Auto",
$(go.Shape, "Circle",
{ minSize: new go.Size(40, 40), fill: "#DC3C00", strokeWidth: 0 }),
$(go.TextBlock, "End", textStyle(),
new go.Binding("text"))
),
// three named ports, one on each side except the bottom, all input only:
makePort("T", go.Spot.Top, go.Spot.Top, false, true),
makePort("L", go.Spot.Left, go.Spot.Left, false, true),
makePort("R", go.Spot.Right, go.Spot.Right, false, true)
));
myDiagram.nodeTemplateMap.add("Comment",
$(go.Node, "Auto", nodeStyle(),
$(go.Shape, "File",
{ fill: "#EFFAB4", strokeWidth: 0 }),
$(go.TextBlock, textStyle(),
{
margin: 5,
maxSize: new go.Size(200, NaN),
wrap: go.TextBlock.WrapFit,
textAlign: "center",
editable: true,
font: "bold 12pt Helvetica, Arial, sans-serif",
stroke: '#454545'
},
new go.Binding("text").makeTwoWay())
// no ports, because no links are allowed to connect with a comment
));
// replace the default Link template in the linkTemplateMap
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: false
},
new go.Binding("points") DIV HTML element
{
scrollsPageOnFocus: false,
nodeTemplateMap: myDiagram.nodeTemplateMap, // share the templates used by myDiagram
model: new go.GraphLinksModel([ // specify the contents of the Palette
{ category: "Start", text: "Start" },
{ text: "Step" },
{ category: "Conditional", text: "???" },
{ category: "End", text: "End" },
{ category: "Comment", text: "Comment" }
])
});
} // end init
// Show the diagram's model in JSON format that the user may edit
function save() {
document.getElementById("mySavedModel").value = myDiagram.model.toJson();
myDiagram.isModified = false;
}
function load() {
myDiagram.model = go.Model.fromJson(document.getElementById("mySavedModel").value);
}
// print the diagram by opening a new window holding SVG images of the diagram contents for each page
function printDiagram() {
var svgWindow = window.open();
if (!svgWindow) return; // failure to open a new Window
var printSize = new go.Size(700, 960);
var bnds = myDiagram.documentBounds;
var x = bnds.x;
var y = bnds.y;
while (y < bnds.bottom) {
while (x < bnds.right) {
var svg = myDiagram.makeSVG({ scale: 1.0, position: new go.Point(x, y), size: printSize });
svgWindow.document.body.appendChild(svg);
x += printSize.width;
}
x = bnds.x;
y += printSize.height;
}
setTimeout(function() { svgWindow.print(); }, 1);
}
</script>
</head>
<body onload="init()">
<div id="sample">
<div style="width: 100%; display: flex; justify-content: space-between">
<div id="myPaletteDiv" style="width: 100px; margin-right: 2px; background-color: whitesmoke; border: solid 1px black"></div>
<div id="myDiagramDiv" style="flex-grow: 1; height: 750px; border: solid 1px black"></div>
</div>
<p>
The FlowChart sample demonstrates several key features of GoJS,
namely <a href="../intro/palette.html">Palette</a>s,
<a href="../intro/links.html">Linkable nodes</a>, Drag/Drop behavior,
<a href="../intro/textBlocks.html">Text Editing</a>, and the use of
<a href="../intro/templateMaps.html">Node Template Maps</a> in Diagrams.
</p>
<p>
Mouse-over a Node to view its ports.
Drag from these ports to create new Links.
Selecting Links allows you to re-shape and re-link them.
Selecting a Node and then clicking its TextBlock will allow
you to edit text (except on the Start and End Nodes).
</p>
<button id="SaveButton" onclick="save()">Save</button>
<button onclick="load()">Load</button>
Diagram Model saved in JSON format:
<textarea id="mySavedModel" style="width:100%;height:300px">
{ "class": "go.GraphLinksModel",
"linkFromPortIdProperty": "fromPort",
"linkToPortIdProperty": "toPort",
"nodeDataArray": [
{"category":"Comment", "loc":"360 -10", "text":"Kookie Brittle", "key":-13},
{"key":-1, "category":"Start", "loc":"175 0", "text":"Start"},
{"key":0, "loc":"-5 75", "text":"Preheat oven to 375 F"},
{"key":1, "loc":"175 100", "text":"In a bowl, blend: 1 cup margarine, 1.5 teaspoon vanilla, 1 teaspoon salt"},
{"key":2, "loc":"175 200", "text":"Gradually beat in 1 cup sugar and 2 cups sifted flour"},
{"key":3, "loc":"175 290", "text":"Mix in 6 oz (1 cup) Nestle's Semi-Sweet Chocolate Morsels"},
{"key":4, "loc":"175 380", "text":"Press evenly into ungreased 15x10x1 pan"},
{"key":5, "loc":"355 85", "text":"Finely chop 1/2 cup of your choice of nuts"},
{"key":6, "loc":"175 450", "text":"Sprinkle nuts on top"},
{"key":7, "loc":"175 515", "text":"Bake for 25 minutes and let cool"},
{"key":8, "loc":"175 585", "text":"Cut into rectangular grid"},
{"key":-2, "category":"End", "loc":"175 660", "text":"Enjoy!"}
],
"linkDataArray": [
{"from":1, "to":2, "fromPort":"B", "toPort":"T"},
{"from":2, "to":3, "fromPort":"B", "toPort":"T"},
{"from":3, "to":4, "fromPort":"B", "toPort":"T"},
{"from":4, "to":6, "fromPort":"B", "toPort":"T"},
{"from":6, "to":7, "fromPort":"B", "toPort":"T"},
{"from":7, "to":8, "fromPort":"B", "toPort":"T"},
{"from":8, "to":-2, "fromPort":"B", "toPort":"T"},
{"from":-1, "to":0, "fromPort":"B", "toPort":"T"},
{"from":-1, "to":1, "fromPort":"B", "toPort":"T"},
{"from":-1, "to":5, "fromPort":"B", "toPort":"T"},
{"from":5, "to":4, "fromPort":"B", "toPort":"T"},
{"from":0, "to":4, "fromPort":"B", "toPort":"T"}
]}
</textarea>
<button onclick="printDiagram()">Print Diagram Using SVG</button>
</div>
</body>
</html>
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn