forked from NorthwoodsSoftware/GoJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFishboneScript.js
191 lines (191 loc) · 8.34 KB
/
FishboneScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Copyright (C) 1998-2019 by Northwoods Software Corporation. All Rights Reserved.
*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../release/go", "./FishboneLayout", "./FishboneLayout"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var go = require("../release/go");
var FishboneLayout_1 = require("./FishboneLayout");
var FishboneLayout_2 = require("./FishboneLayout");
var myDiagram;
function init() {
if (window.goSamples)
window.goSamples(); // init for these samples -- you don't need to call this F
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, 'myDiagramDiv', // refers to its DIV HTML element by id
{ isReadOnly: true }); // do not allow the user to modify the diagram
// define the normal node template, just some text
myDiagram.nodeTemplate =
$(go.Node, 'Auto', $(go.TextBlock, new go.Binding('text'), new go.Binding('font', '', convertFont)));
function convertFont(data) {
var size = data.size;
if (size === undefined)
size = 13;
var weight = data.weight;
if (weight === undefined)
weight = '';
return weight + ' ' + size + 'px sans-serif';
}
// This demo switches the Diagram.linkTemplate between the "normal" and the "fishbone" templates.
// If you are only doing a FishboneLayout, you could just set Diagram.linkTemplate
// to the template named "fishbone" here, and not switch templates dynamically.
// define the non-fishbone link template
myDiagram.linkTemplateMap.add('normal', $(go.Link, { routing: go.Link.Orthogonal, corner: 4 }, $(go.Shape)));
// use this link template for fishbone layouts
myDiagram.linkTemplateMap.add('fishbone', $(FishboneLayout_2.FishboneLink, // defined above
$(go.Shape)));
// here is the structured data used to build the model
var json = {
'text': 'Incorrect Deliveries', 'size': 18, 'weight': 'Bold', 'causes': [
{
'text': 'Skills', 'size': 14, 'weight': 'Bold', 'causes': [
{
'text': 'knowledge', 'weight': 'Bold', 'causes': [
{
'text': 'procedures', 'causes': [
{ 'text': 'documentation' }
]
},
{ 'text': 'products' }
]
},
{ 'text': 'literacy', 'weight': 'Bold' }
]
},
{
'text': 'Procedures', 'size': 14, 'weight': 'Bold', 'causes': [
{
'text': 'manual', 'weight': 'Bold', 'causes': [
{ 'text': 'consistency' }
]
},
{
'text': 'automated', 'weight': 'Bold', 'causes': [
{ 'text': 'correctness' },
{ 'text': 'reliability' }
]
}
]
},
{
'text': 'Communication', 'size': 14, 'weight': 'Bold', 'causes': [
{ 'text': 'ambiguity', 'weight': 'Bold' },
{
'text': 'sales staff', 'weight': 'Bold', 'causes': [
{
'text': 'order details', 'causes': [
{ 'text': 'lack of knowledge' }
]
}
]
},
{
'text': 'telephone orders', 'weight': 'Bold', 'causes': [
{ 'text': 'lack of information' }
]
},
{
'text': 'picking slips', 'weight': 'Bold', 'causes': [
{ 'text': 'details' },
{ 'text': 'legibility' }
]
}
]
},
{
'text': 'Transport', 'size': 14, 'weight': 'Bold', 'causes': [
{
'text': 'information', 'weight': 'Bold', 'causes': [
{ 'text': 'incorrect person' },
{
'text': 'incorrect addresses', 'causes': [
{
'text': 'customer data base', 'causes': [
{ 'text': 'not up-to-date' },
{ 'text': 'incorrect program' }
]
}
]
},
{ 'text': 'incorrect dept' }
]
},
{
'text': 'carriers', 'weight': 'Bold', 'causes': [
{ 'text': 'efficiency' },
{ 'text': 'methods' }
]
}
]
}
]
};
function walkJson(obj, arr) {
var key = arr.length;
obj.key = key;
arr.push(obj);
var children = obj.causes;
if (children) {
for (var i = 0; i < children.length; i++) {
var o = children[i];
o.parent = key; // reference to parent node data
walkJson(o, arr);
}
}
}
// build the tree model
var nodeDataArray = [];
walkJson(json, nodeDataArray);
myDiagram.model = new go.TreeModel(nodeDataArray);
layoutFishbone();
// Attach to the window for console manipulation
window.myDiagram = myDiagram;
}
exports.init = init;
// use FishboneLayout and FishboneLink
function layoutFishbone() {
myDiagram.startTransaction('fishbone layout');
myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('fishbone');
myDiagram.layout = go.GraphObject.make(FishboneLayout_1.FishboneLayout, {
angle: 180,
layerSpacing: 10,
nodeSpacing: 20,
rowSpacing: 10
});
myDiagram.commitTransaction('fishbone layout');
}
exports.layoutFishbone = layoutFishbone;
// make the layout a branching tree layout and use a normal link template
function layoutBranching() {
myDiagram.startTransaction('branching layout');
myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('normal');
myDiagram.layout = go.GraphObject.make(go.TreeLayout, {
angle: 180,
layerSpacing: 20,
alignment: go.TreeLayout.AlignmentBusBranching
});
myDiagram.commitTransaction('branching layout');
}
exports.layoutBranching = layoutBranching;
// make the layout a basic tree layout and use a normal link template
function layoutNormal() {
myDiagram.startTransaction('normal layout');
myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('normal');
myDiagram.layout = go.GraphObject.make(go.TreeLayout, {
angle: 180,
breadthLimit: 1000,
alignment: go.TreeLayout.AlignmentStart
});
myDiagram.commitTransaction('normal layout');
}
exports.layoutNormal = layoutNormal;
});