forked from NorthwoodsSoftware/GoJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFishboneScript.ts
More file actions
201 lines (182 loc) · 6.05 KB
/
Copy pathFishboneScript.ts
File metadata and controls
201 lines (182 loc) · 6.05 KB
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
192
193
194
195
196
197
198
199
200
201
/*
* Copyright (C) 1998-2019 by Northwoods Software Corporation. All Rights Reserved.
*/
import * as go from '../release/go';
import { FishboneLayout } from './FishboneLayout';
import { FishboneLink } from './FishboneLayout';
let myDiagram: go.Diagram;
export function init() {
if ((window as any).goSamples) (window as any).goSamples(); // init for these samples -- you don't need to call this F
const $ = 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: any) {
let size = data.size;
if (size === undefined) size = 13;
let 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',
$(FishboneLink, // defined above
$(go.Shape)
));
// here is the structured data used to build the model
const 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: any, arr: any) {
const key = arr.length;
obj.key = key;
arr.push(obj);
const children = obj.causes;
if (children) {
for (let i = 0; i < children.length; i++) {
const o = children[i];
o.parent = key; // reference to parent node data
walkJson(o, arr);
}
}
}
// build the tree model
const nodeDataArray: Array<Object> = [];
walkJson(json, nodeDataArray);
myDiagram.model = new go.TreeModel(nodeDataArray);
layoutFishbone();
// Attach to the window for console manipulation
(window as any).myDiagram = myDiagram;
}
// use FishboneLayout and FishboneLink
export function layoutFishbone() {
myDiagram.startTransaction('fishbone layout');
myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('fishbone') as go.Link;
myDiagram.layout = go.GraphObject.make(FishboneLayout, { // defined above
angle: 180,
layerSpacing: 10,
nodeSpacing: 20,
rowSpacing: 10
});
myDiagram.commitTransaction('fishbone layout');
}
// make the layout a branching tree layout and use a normal link template
export function layoutBranching() {
myDiagram.startTransaction('branching layout');
myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('normal') as go.Link;
myDiagram.layout = go.GraphObject.make(go.TreeLayout, {
angle: 180,
layerSpacing: 20,
alignment: go.TreeLayout.AlignmentBusBranching
});
myDiagram.commitTransaction('branching layout');
}
// make the layout a basic tree layout and use a normal link template
export function layoutNormal() {
myDiagram.startTransaction('normal layout');
myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('normal') as go.Link;
myDiagram.layout = go.GraphObject.make(go.TreeLayout, {
angle: 180,
breadthLimit: 1000,
alignment: go.TreeLayout.AlignmentStart
});
myDiagram.commitTransaction('normal layout');
}