//go.js 基础配置
//项目需求,实在Vue中写的 需要构建流水线
methods:{
init(){
var mySelf = this;
const MAKE = go.GraphObject.make;
mySelf.myDiagram = MAKE(go.Diagram, "mygoChart",
//图表整体属性设置
{
initialContentAlignment: go.Spot.TopLeft, // 画布初始位置
allowZoom: true,
maxSelectionCount: 1,
"grid.visible": false, //是否显示背景栅格
"grid.gridCellSize": new go.Size(1, 1), //栅格大小
"commandHandler.copiesTree": true, // 禁用复制快捷键
"commandHandler.deletesTree": true, // 禁用删除快捷键
"toolManager.mouseWheelBehavior": go.ToolManager.GestureCancel, //禁用视图放大缩小 ( WheelScroll、 WheelZoom 、WheelNone、GestureZoom 、GestureCancel、 GestureNone )
"animationManager.duration": 600, //画布初始化时间
"grid.visible": false, //显示网格
scale: 1.5, //画布比例
autoScale: go.Diagram.Uniform, //自适应
allowHorizontalScroll: false, //禁止水平拖动画布
allowVerticalScroll: false, //禁止垂直拖动画布
allowLink: false, //是否允许拖拽连线
allowRelink: false, //是否允许重新连线
padding: 10, // 画布边距
LinkRelinked: mySelf.showLinkLabel, //节点连线
isReadOnly: true, //节点只读 节点不可拖拽
//布局设置 https://gojs.net/latest/api/symbols/Layout.html
//LayeredDigraphLayout布局 https://gojs.net/latest/api/symbols/LayeredDigraphLayout.html
layout: MAKE(go.LayeredDigraphLayout, {
direction: 0,
layeringOption: go.LayeredDigraphLayout.LayerLongestPathSource
}), //0向右,90向下,180向左,270向上。默认值是0
"undoManager.isEnabled": true, //是否启用撤销回退 Ctrl-Z Ctrl-Y
LinkReshaped: function(e) {
mySelf.myDiagram.model.removeLinkData(e.subject.data);
// mySelf.myDiagram.model.addLinkData({from: e.subject.data.from, to: e.subject.data.to, group: 'tree_001'})
return;
}
});
}
}
//连线
mySelf.myDiagram.linkTemplate =
MAKE(go.Link,
//设置连接线属性
{
relinkableFrom: true,
relinkableTo: true,
corner: 12,
routing: go.Link.Orthogonal,
curve: go.Link.JumpOver
},
MAKE(go.Shape, {
stroke: "black",
strokeWidth: 2
}),
//设置箭头
MAKE(go.Shape, {
toArrow: "Standard",
stroke: "black",
fill: "black"
})
)
//节点
mySelf.myDiagram.nodeTemplate = MAKE(
go.Node,
"Auto",
MAKE(go.Shape, "RoundedRectangle", { //RoundedRectangle 节点的形状
width: 152, //节点宽度
height: 44, //节点高度
strokeWidth: 0, //设置边框
fill: "#f3f3ff", //填充颜色 (节点背景颜色)
portId: "",
fromLinkable: true,
toLinkable: true
}),
MAKE(
go.TextBlock, {
margin: 15,
stroke: "black" //字体填充色 (字体颜色)
},
new go.Binding("text", "text", function(c) {
if(c.length > 6) {
return c.substring(0, 6) + "...";
} else {
return c;
}
})
),
);
//未更新完