cpee 2.1.143 → 2.1.144

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/cockpit/compliance-view.html +6 -6
  3. data/cockpit/compliance.html +6 -6
  4. data/cockpit/conformance.html +6 -6
  5. data/cockpit/css/llmmodel.css +17 -22
  6. data/cockpit/css/ui.css +2 -9
  7. data/cockpit/edit.html +6 -6
  8. data/cockpit/graph.html +2 -2
  9. data/cockpit/index.html +6 -6
  10. data/cockpit/js/extended_columns.js +7 -6
  11. data/cockpit/js/instance.js +0 -1
  12. data/cockpit/js/llmmodel.js +32 -0
  13. data/cockpit/llm.html +57 -44
  14. data/cockpit/llmmodel.html +40 -32
  15. data/cockpit/model.html +5 -5
  16. data/cockpit/only_llm.html +4 -4
  17. data/cockpit/templates/Coopis 2010 Replay.xml +7 -7
  18. data/cockpit/templates/Coopis 2010.xml +7 -7
  19. data/cockpit/templates/Frames.xml +1 -1
  20. data/cockpit/templates/Frames1.xml +527 -0
  21. data/cockpit/templates/ML-pipe-multi.xml +9 -9
  22. data/cockpit/templates/Readonly Local.xml +4 -4
  23. data/cockpit/templates/Track Test Local.xml +6 -6
  24. data/cockpit/templates/Track Test.xml +5 -5
  25. data/cockpit/templates/UR-VUE 2020 Solution Baseline.xml +6 -6
  26. data/cockpit/templates/UR-VUE 2020 Solution NN.xml +5 -5
  27. data/cockpit/templates/UR-VUE 2020 Solution View.xml +1 -1
  28. data/cockpit/templates/UR-VUE 2020.xml +1 -1
  29. data/cockpit/templates/Wait.xml +1 -1
  30. data/cockpit/templates/Worklist Vote.xml +2 -2
  31. data/cockpit/templates/Worklist.xml +1 -1
  32. data/cockpit/templates/instantiate/Take_Sub.xml +1 -1
  33. data/cockpit/templates/instantiate.local/Take_Sub.xml +1 -1
  34. data/cockpit/themes/base.js +13 -6
  35. data/cockpit/themes/presetlr/theme.js +1 -0
  36. data/cockpit/track.html +2 -2
  37. data/cpee.gemspec +2 -2
  38. data/lib/cpee/implementation.rb +2 -1
  39. data/lib/cpee/persistence.rb +1 -0
  40. data/lib/engine/instances.rng +5 -0
  41. data/lib/properties/description.rng +0 -1
  42. data/lib/properties/dslx.rng +0 -1
  43. data/lib/properties/properties.rng +1 -0
  44. data/lib/properties/set-properties.rng +1 -0
  45. data/lib/properties/set-some-properties.rng +1 -0
  46. data/lib/properties/set-testset.rng +1 -0
  47. data/lib/properties/state.rng +0 -2
  48. data/lib/properties.xml +0 -1
  49. data/server/executionhandlers/eval/connection.rb +3 -6
  50. data/server/executionhandlers/ruby/connection.rb +3 -6
  51. data/server/executionhandlers/ruby/controller.rb +18 -15
  52. data/server/resources/states.dot +0 -4
  53. data/server/resources/states.xml +2 -8
  54. data/server/resources/topics.xml +0 -3
  55. data/tools/cpee +115 -2
  56. metadata +5 -5
  57. data/cockpit/css/wfadaptor.css +0 -401
  58. data/cockpit/js/wfadaptor.js +0 -1691
@@ -1,1691 +0,0 @@
1
- /*
2
- This file is part of cpee-layout.
3
-
4
- cpee-layout is free software: you can redistribute it and/or modify it under
5
- the terms of the GNU Lesser General Public License as published by the Free
6
- Software Foundation, either version 3 of the License, or (at your option) any
7
- later version.
8
-
9
- cpee-layout is distributed in the hope that it will be useful, but WITHOUT
10
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
- FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12
- details.
13
-
14
- You should have received a copy of the GNU Lesser General Public License
15
- along with cpee-layout (file LICENSE in the main directory). If not, see
16
- <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- // TODO: changes in svg-script:
20
- // 1) drawing functions
21
- // 2) creation of svg-container (Bug: arrows on lines)
22
- // 3) after-function to insert using namespace of description
23
-
24
- // WfAdaptor:
25
- // Handles interaction between Illustartor and Description
26
- // e.g. Event fires to Adaptor to insert Element and Illustrator and Description do it
27
- function WfAdaptor(theme_base,doit) { // Controller {{{
28
-
29
- // public variables {{{
30
- this.illustrator;
31
- this.description;
32
- this.elements = {};
33
- this.theme_base = theme_base;
34
- this.theme_dir = theme_base.replace(/theme.js/,'');
35
- this.properties = {};
36
- // }}}
37
-
38
- // private variables {{{
39
- var illustrator;
40
- var description;
41
- var self = this;
42
- // }}}
43
-
44
- // helper funtions
45
- this.set_description = function(desc,auto_update) { // public {{{
46
- this.description.set_description(desc,auto_update);
47
- } // }}}
48
-
49
- this.get_description = function() { // public {{{
50
- return description.get_description();
51
- } // }}}
52
- this.notify = function() { // public {{{
53
- } // }}}
54
- this.draw_labels = function(max,labels,dimensions,striped){ // public {{{
55
- } // }}}
56
- this.set_svg_container = function (container) { // {{{
57
- illustrator.set_svg_container(container); // TODO: shadowing the container element
58
- } // }}}
59
- this.set_label_container = function(container) { // {{{
60
- illustrator.set_label_container(container);
61
- } // }}}
62
- this.get_svg = function() { // {{{
63
- return illustrator.get_svg();
64
- } // }}}
65
- this.get_svg_metrics = function() { // {{{
66
- return illustrator.get_svg_metrics();
67
- } // }}}
68
-
69
- function loadTheme(doit) { //{{{
70
- manifestation = new WFAdaptorManifestation(self);
71
- illustrator.compact = manifestation.compact == true ? true : false;
72
- illustrator.rotated_labels = manifestation.rotated_labels == true ? true : false;
73
- illustrator.striped = manifestation.striped == true ? true : false;
74
- illustrator.lr = manifestation.lr == true ? true : false;
75
- illustrator.wellformed_pre_test = manifestation.wellformed_pre_test == true ? true : false;
76
- description.source = manifestation.source;
77
- var deferreds = [];
78
- // copy parent stuff
79
- for(element in manifestation.elements) {
80
- if (manifestation.elements[element].parent) {
81
- if (!manifestation.elements[element].description) {
82
- manifestation.elements[element].description = manifestation.elements[manifestation.elements[element].parent].description;
83
- }
84
- if (!manifestation.elements[element].adaptor) {
85
- manifestation.elements[element].adaptor = manifestation.elements[manifestation.elements[element].parent].adaptor;
86
- }
87
- var ill = manifestation.elements[manifestation.elements[element].parent].illustrator;
88
- for (var key in ill) {
89
- if (manifestation.elements[element].illustrator[key] == undefined) {
90
- manifestation.elements[element].illustrator[key] = ill[key];
91
- }
92
- }
93
- if (manifestation.elements[element].type == undefined) {
94
- manifestation.elements[element].type = manifestation.elements[manifestation.elements[element].parent].type;
95
- }
96
- }
97
- }
98
- // doit
99
- for(element in manifestation.resources) {
100
- deferreds.push(
101
- $.ajax({
102
- type: "GET",
103
- dataType: "xml",
104
- url: manifestation.resources[element],
105
- context: element,
106
- success: function(res){
107
- manifestation.resources[this] = $(res.documentElement);
108
- }
109
- })
110
- );
111
- }
112
- for(element in manifestation.elements) {
113
- if (manifestation.elements[element].illustrator) {
114
- if (manifestation.elements[element].illustrator.svg && (typeof manifestation.elements[element].illustrator.svg === 'string' || manifestation.elements[element].illustrator.svg instanceof String)) {
115
- deferreds.push(
116
- $.ajax({
117
- type: "GET",
118
- dataType: "xml",
119
- url: manifestation.elements[element].illustrator.svg,
120
- context: element,
121
- success: function(res){
122
- manifestation.elements[this].illustrator.svg = $(res.documentElement);
123
- }
124
- })
125
- );
126
- } else if (manifestation.elements[element].illustrator.svg && (typeof manifestation.elements[element].illustrator.svg === 'object' || manifestation.elements[element].illustrator.svg instanceof Object)) {
127
- if (manifestation.elements[element].illustrator.svg.start) {
128
- deferreds.push(
129
- $.ajax({
130
- type: "GET",
131
- dataType: "xml",
132
- url: manifestation.elements[element].illustrator.svg.start,
133
- context: element,
134
- success: function(res){
135
- manifestation.elements[this].illustrator.svg.start = $(res.documentElement);
136
- }
137
- })
138
- );
139
- }
140
- if (manifestation.elements[element].illustrator.svg.middle) {
141
- deferreds.push(
142
- $.ajax({
143
- type: "GET",
144
- dataType: "xml",
145
- url: manifestation.elements[element].illustrator.svg.middle,
146
- context: element,
147
- success: function(res){
148
- manifestation.elements[this].illustrator.svg.middle = $(res.documentElement);
149
- }
150
- })
151
- );
152
- }
153
- if (manifestation.elements[element].illustrator.svg.end) {
154
- deferreds.push(
155
- $.ajax({
156
- type: "GET",
157
- dataType: "xml",
158
- url: manifestation.elements[element].illustrator.svg.end,
159
- context: element,
160
- success: function(res){
161
- manifestation.elements[this].illustrator.svg.end = $(res.documentElement);
162
- }
163
- })
164
- );
165
- }
166
- }
167
- illustrator.elements[element] = manifestation.elements[element].illustrator;
168
- illustrator.elements[element].type = manifestation.elements[element].type || 'abstract';
169
- }
170
- if (manifestation.elements[element].description) {
171
- if ( typeof manifestation.elements[element].description === 'string' ) {
172
- manifestation.elements[element].description = [ manifestation.elements[element].description ];
173
- }
174
- if (Array.isArray(manifestation.elements[element].description)) {
175
- manifestation.elements[element].description.forEach(function(val,ind){
176
- deferreds.push(
177
- $.ajax({
178
- type: "GET",
179
- dataType: "xml",
180
- url: val,
181
- context: element,
182
- success: function(res){
183
- manifestation.elements[this].description = $(res.documentElement);
184
- description.elements[this] = manifestation.elements[this].description;
185
- }
186
- })
187
- );
188
- });
189
- }
190
- }
191
- if (manifestation.elements[element].adaptor) {
192
- self.elements[element] = manifestation.elements[element].adaptor;
193
- }
194
- }
195
- $.when.apply($, deferreds).then(function(x) {
196
- doit(self);
197
- })
198
- } //}}}
199
-
200
- // initialize
201
- this.illustrator = illustrator = new WfIllustrator(this);
202
- this.description = description = new WfDescription(this, this.illustrator);
203
-
204
- this.draw_element = function(type,id,label) {
205
- let pos = {'row': 1,'col': 0};
206
- let block = { 'max': {'row': pos.row, 'col': pos.col}, 'endnodes': [], 'svg': $X('<g class="group" xmlns="http://www.w3.org/2000/svg"/>') };
207
- illustrator.draw.draw_symbol(type, id, label, pos.row, pos.row, pos.row, pos.col, block.svg, false, {}, {})
208
- self.illustrator.set_svg(block);
209
- }
210
-
211
- this.redraw = function(doit){
212
- description.redraw(doit);
213
- }
214
-
215
- $.getScript(self.theme_base).done(function() {
216
- loadTheme(doit);
217
- }).fail(function(){
218
- // default theme
219
- self.theme_base = 'themes/preset/theme.js';
220
- self.theme_dir = self.theme_base.replace(/theme.js/,'');
221
- $.getScript(self.theme_base,function() {
222
- loadTheme(doit);
223
- });
224
- });
225
- } // }}}
226
-
227
- // WfIllustrator:
228
- // Is in charge of displaying the Graph. It is further able insert and remove elements with given ID's from the illustration.
229
- function WfIllustrator(wf_adaptor) { // View {{{
230
- // Variable {{{
231
- // public
232
- this.endclipshift = 17;
233
- this.height = 40;
234
- this.width = 40;
235
- this.default_width = 40;
236
- this.default_height = 40;
237
- this.height_shift = this.height * 0.26;
238
- this.width_shift = this.width * 0.39;
239
- this.width_shift_label = 7;
240
- this.group_extend = 1;
241
- this.structural_tighten = 3; // 'structural' borders are smaller in y
242
- this.conn_center = 15; // connectors attach to the center of the symbols, i.e. half a symbol before the end of the cell
243
- this.elements = {}; // the svgs
244
- this.svg = {};
245
- this.draw = {};
246
- this.dim = {};
247
- this.dim.symbols = [];
248
- this.dim.connections = [];
249
- this.dim.implied = []; // symbols that an icon draws in a neighbouring cell (theme: implied), for the metrics only
250
- this.dim.labels = {}; // the shown label of each cell ('row,col'), for the metrics only
251
- this.dim.rows = []; // lr only: start and size of each symbol along the rows
252
- this.compact = true;
253
- this.rotated_labels = true;
254
- this.striped = true;
255
- this.lr = false;
256
- this.wellformed_pre_test = false; // experimental: pre_test loops are drawn reversed
257
- this.inverted = false; // true while drawing inside such a loop, nested pre_test loops toggle it
258
- this.global_style = {};
259
- // private
260
- var self = this;
261
- var adaptor = null;
262
- // }}}
263
- // Internal Functions
264
- this.set_label_container = function(con) { // {{{
265
- self.svg.label_container = con;
266
- } // }}}
267
- this.set_svg_container = function(con) { // {{{
268
- self.svg.container = con;
269
- self.svg.container.append($X('<defs xmlns="http://www.w3.org/2000/svg">' +
270
- ' <marker id="arrow" viewBox="0 0 10 10" refX="28.5" refY="5" orient="auto" markerUnits="strokeWidth" markerWidth="14" markerHeight="3.5">' +
271
- ' <path d="m 2 2 l 6 3 l -6 3 z"/>' +
272
- ' </marker>' +
273
- ' <marker id="endarrow" viewBox="0 0 10 10" refX="7" refY="5" orient="auto" markerUnits="strokeWidth" markerWidth="14" markerHeight="5.2">' +
274
- ' <path d="M 2,2 L 6.21,4.11 Q 8,5 6.21,5.89 L 2,8 Z"/>' +
275
- ' </marker>' +
276
- ' <marker id="arrowrev" viewBox="0 0 10 10" refX="28.5" refY="5" orient="auto-start-reverse" markerUnits="strokeWidth" markerWidth="14" markerHeight="3.5">' +
277
- ' <path d="m 2 2 l 6 3 l -6 3 z"/>' +
278
- ' </marker>' +
279
- ' <marker id="endarrowrev" viewBox="0 0 10 10" refX="7" refY="5" orient="auto-start-reverse" markerUnits="strokeWidth" markerWidth="14" markerHeight="5.2">' +
280
- ' <path d="M 2,2 L 6.21,4.11 Q 8,5 6.21,5.89 L 2,8 Z"/>' +
281
- ' </marker>' +
282
- ' <marker id="arrowdiag" viewBox="0 0 10 10" refX="24.5" refY="5" orient="auto" markerUnits="strokeWidth" markerWidth="14" markerHeight="3.5">' +
283
- ' <path d="m 2 2 l 6 3 l -6 3 z"/>' +
284
- ' </marker>' +
285
- ' <marker id="arrowdiagrev" viewBox="0 0 10 10" refX="24.5" refY="5" orient="auto-start-reverse" markerUnits="strokeWidth" markerWidth="14" markerHeight="3.5">' +
286
- ' <path d="m 2 2 l 6 3 l -6 3 z"/>' +
287
- ' </marker>' +
288
- ' <clipPath id="startclip">' +
289
- ' <rect x="-4" y="-4" width="35" height="38"/>' +
290
- ' </clipPath>' +
291
- ' <clipPath id="endclip">' +
292
- ' <rect x="20" y="-1" width="' + self.endclipshift + '" height="35"/>' +
293
- ' </clipPath>' +
294
- ' <linearGradient id="custom-gradient" x2="0.35" y2="1">' +
295
- ' <stop offset="0%" stop-color="var(--wfadaptor-background)"/>' +
296
- ' <stop offset="50%" stop-color="var(--custom-color)"/>' +
297
- ' <stop offset="100%" stop-color="var(--custom-color)"/>' +
298
- ' </linearGradient>' +
299
- '</defs>'));
300
- self.svg.defs = {};
301
- self.svg.defs['unknown'] = $X('<g xmlns="http://www.w3.org/2000/svg" class="unknown">' +
302
- '<circle cx="15" cy="15" r="14" class="unkown"/>' +
303
- '<text transform="translate(15,20)" class="normal">?</text>' +
304
- '</g>');
305
- for(element in self.elements)
306
- if(self.elements[element].svg) {
307
- var sym = $X('<g xmlns="http://www.w3.org/2000/svg"/>').append(self.elements[element].svg.clone().children()); // append all children to symbol
308
- $.each(self.elements[element].svg.attr('class').split(/\s+/), function(index, item) { sym.addClass(item); }); // copy all classes from the root node
309
- self.svg.defs[element] = sym;
310
- }
311
- } // }}}
312
- this.set_svg = function(graph) { // {{{
313
- self.svg.container.append(graph.svg);
314
- let bb = graph.svg[0].getBBox();
315
-
316
- let w = self.dim.get_x_max(0,graph.max.row,graph.max.col,'start');
317
- if (w == 0) { w = bb.x + bb.width + self.width_shift; }
318
- // the alternative is bb.x + bb.width + self.width_shift, but this is bad when clipped elements
319
- if (self.lr) { w = Math.max(w, bb.x + bb.width + self.width_shift); } // lr: labels can reach across the flow, e.g. rotated below a gateway; clipped labels only reach along it
320
-
321
- if (self.lr) { // mirror at the diagonal: rows go to the right, columns go down
322
- graph.svg.attr('transform',lr_matrix());
323
- self.svg.container.attr('height', w - lr_shift() + self.height_shift);
324
- self.svg.container.attr('width', bb.y + bb.height + self.height_shift + lr_shift());
325
- } else {
326
- self.svg.container.attr('height', bb.y + bb.height + self.height_shift); // small border on the bottom
327
- self.svg.container.attr('width', w); // small border on the right
328
- }
329
- } // }}}
330
- this.get_svg = function() { // {{{
331
- // standalone copy for export: the rules of all stylesheets marked with
332
- // data-include-export are inlined into the style attributes (var()
333
- // resolved, in cascade order), further columns from the label container are
334
- // merged in, and interaction state and the render time are removed
335
- var svgs = [self.svg.container.get(0)];
336
- if (self.svg.label_container) {
337
- self.svg.label_container.children('svg').not(self.svg.container).each(function(_,ele) { svgs.push(ele); });
338
- }
339
- var clones = svgs.map(function(s) { return s.cloneNode(true); });
340
-
341
- var root = getComputedStyle(document.documentElement);
342
- var rules = [];
343
- var family = '';
344
- $.each(document.styleSheets, function(_,sheet) {
345
- if (!sheet.ownerNode || !sheet.ownerNode.hasAttribute('data-include-export')) { return; }
346
- $.each(sheet.cssRules, function(_,rule) {
347
- if (!rule.selectorText || rule.selectorText == ':root') { return; }
348
- if (rule.selectorText == 'svg') {
349
- if (rule.style.getPropertyValue('font-family') != '') {
350
- family = getComputedStyle(svgs[0]).getPropertyValue('font-family').replace(/["']/g,'').trim();
351
- }
352
- return;
353
- }
354
- var css = rule.style.cssText.replace(/var\((--[\w-]+)\)/g, function(m,v) { return root.getPropertyValue(v).trim() || m; });
355
- rule.selectorText.split(',').forEach(function(sel) {
356
- rules.push({ sel: sel.trim(), spec: specificity(sel), order: rules.length, css: css });
357
- });
358
- });
359
- });
360
- rules.sort(function(a,b) { return a.spec - b.spec || a.order - b.order; });
361
- family = family.replace(/-/,' ').split(' ').map(function(w) { return w[0].toUpperCase() + w.substr(1); }).join(' '); // adwaita-sans -> Adwaita Sans, the installed name
362
-
363
- clones.forEach(function(clone) {
364
- $(clone).find('.duration').remove();
365
- $(clone).find('.selected').removeClass('selected');
366
- $(clone).find('.hover').removeClass('hover');
367
- $(clone).find('*').each(function(_,el) {
368
- var decl = [];
369
- rules.forEach(function(r) {
370
- try { if (el.matches(r.sel)) { decl.push(r.css); } } catch (e) { } // e.g. unsupported pseudo classes
371
- });
372
- var own = el.getAttribute('style');
373
- if (own && own.trim() != '') { decl.push(own.trim().replace(/;?$/,';')); }
374
- if ($(el).is('text.super, g.hoverstyle, g.markstyle')) { decl.push('display: none;'); }
375
- if (el.nodeName == 'text' && family != '') { decl.push('font-family: \'' + family + '\';'); }
376
- if (decl.length > 0) { el.setAttribute('style', decl.join(' ')); }
377
- });
378
- });
379
-
380
- var svg = clones.shift();
381
- var width = parseInt(svg.getAttribute('width'));
382
- clones.forEach(function(clone) {
383
- var gr = $X('<g transform="translate(' + width + ')" xmlns="http://www.w3.org/2000/svg"></g>');
384
- gr.append($(clone).children());
385
- width += parseInt(clone.getAttribute('width'));
386
- $(svg).append(gr);
387
- });
388
- svg.setAttribute('width', width + 1);
389
- return svg;
390
- } // }}}
391
- this.get_svg_metrics = function() { // {{{
392
- // the layout of the last drawing as it is shown (a copy, empty cells are
393
- // null): pos_matrix holds the symbols per row and column, x and width are
394
- // horizontal; con_list the connections between them. Rows and columns are
395
- // 0-indexed here, the layout counts from 1. lr is laid out top to bottom
396
- // and mirrored at the diagonal, so rows and columns are swapped back, and x
397
- // and width come from the rows (as in get_x, x is the symbol position plus
398
- // width_shift). geometry: a symbol is drawn shift left of its x, and the
399
- // symbols of row r start at top + r * row. label_box is where the label is
400
- // shown, in the coordinates of the svg
401
- var center_x = (self.width - self.default_width) / 2;
402
- var center_y = (self.height - self.default_height) / 2;
403
- var geometry = self.lr ? // lr: x runs along the internal rows, the rows are the internal columns, lr_matrix moves both by lr_shift
404
- { shift: self.width_shift - center_y, top: 2 * self.height_shift + center_x, row: self.width } :
405
- { shift: self.width_shift - center_x, top: self.height_shift + center_y, row: self.height };
406
- var pos =function(r,c) { return self.lr ? { row: c - 1, col: r - 1 } : { row: r - 1, col: c - 1 }; };
407
- var row_start = function(r,c) { // like get_row, but symbols without an own entry (e.g. alternative) also find one to the right
408
- var rs = self.dim.rows[r] || [];
409
- for (var j = c; j >= 0; j--) { if (rs[j]) { return rs[j].start; } }
410
- for (var j = c + 1; j < rs.length; j++) { if (rs[j]) { return rs[j].start; } }
411
- return 0;
412
- };
413
- var pos_matrix = [];
414
- self.dim.symbols.forEach(function(row,r) {
415
- if (!row) { return; }
416
- row.forEach(function(sym,c) {
417
- if (!sym || !sym.type || r == 0 || c == 0) { return; } // without type the cell is only reserved (set_x), nothing is drawn there
418
- var p = pos(r,c);
419
- var s = $.extend({}, sym);
420
- if (self.lr) {
421
- s.x = row_start(r,c) + self.width;
422
- s.width = (self.dim.rows[r] && self.dim.rows[r][c] && self.dim.rows[r][c].size) || self.height;
423
- }
424
- var lab = self.dim.labels[r + ',' + c];
425
- if (lab) {
426
- var b = get_box(lab);
427
- s.label_box = { x: b.x, y: b.y, width: b.width, height: b.height };
428
- }
429
- if (!pos_matrix[p.row]) { pos_matrix[p.row] = []; }
430
- pos_matrix[p.row][p.col] = s;
431
- });
432
- });
433
- self.dim.implied.forEach(function(i) { // x/y are cells in the icon; lr mirrors the icon, so its x runs along the rows there
434
- var dr = self.lr ? (i.x || 0) : (i.y || 0), dc = self.lr ? (i.y || 0) : (i.x || 0);
435
- var r = i.row + dr, c = i.col + dc;
436
- var p = pos(r,c);
437
- var src = self.dim.symbols[i.row][i.col];
438
- if (!pos_matrix[p.row]) { pos_matrix[p.row] = []; }
439
- if (pos_matrix[p.row][p.col]) { return; } // a real symbol wins
440
- pos_matrix[p.row][p.col] = self.lr ?
441
- { x: row_start(i.row,i.col) + self.width + dr * self.height, width: self.height, type: i.type, eid: src.eid } :
442
- { x: src.x + dc * self.width, width: self.width, type: i.type, eid: src.eid };
443
- });
444
- var con_list = self.dim.connections.map(function(c) {
445
- return { from: pos(c.from.row,c.from.col), to: pos(c.to.row,c.to.col) };
446
- });
447
- return JSON.parse(JSON.stringify({ lr: self.lr == true, geometry: geometry, pos_matrix: pos_matrix, con_list: con_list })); // holes become null
448
- } // }}}
449
- var specificity = function(sel) { // {{{ ids, classes/attributes/pseudo classes, types
450
- var s = sel.replace(/::[\w-]+/g,'');
451
- var a = (s.match(/#[\w-]+/g) || []).length;
452
- var b = (s.match(/\.[\w-]+|\[[^\]]*\]|:[\w-]+/g) || []).length;
453
- var c = (s.replace(/\[[^\]]*\]/g,'').match(/(^|[\s>+~(])[a-zA-Z][\w-]*/g) || []).length;
454
- return a * 10000 + b * 100 + c;
455
- } // }}}
456
- this.set_duration = function(start) { //{{{
457
- self.svg.container.append(
458
- $X('<text class="duration" transform="translate(3,' + self.height_shift + ') rotate(90)" xmlns="http://www.w3.org/2000/svg">' +
459
- Math.trunc(performance.now()-start) + ' ms' +
460
- '</text>')
461
- );
462
- } //}}}
463
-
464
- this.get_node_by_svg_id = function(svg_id) { // {{{
465
- return $('[element-id = \'' + svg_id + '\'] g.activities', self.svg.container);
466
- } // }}}
467
- this.get_label_by_svg_id = function(svg_id) { // {{{
468
- return $('[element-id = \'' + svg_id + '\']', self.svg.label_container);
469
- } // }}}
470
- this.get_elements = function() { // {{{
471
- return $('g.element', self.svg.container);
472
- } // }}}
473
- this.get_labels = function() { // {{{
474
- return $('[element-id]', self.svg.label_container);
475
- } // }}}
476
-
477
- // External Functions
478
- var clear = this.clear = function() { // {{{
479
- $('> :not(defs)', self.svg.container).each(function() {$(this).remove()});
480
- $('> defs > [belongs-to=element]', self.svg.container).each(function() {$(this).remove()});
481
- self.dim.symbols = [];
482
- self.dim.connections = [];
483
- self.dim.implied = [];
484
- self.dim.labels = {};
485
- self.dim.rows = [];
486
- } // }}}
487
- var get_symbol = this.get_symbol = function() { // {{{
488
- } // }}}
489
- var get_properties = this.get_properties = function() { // {{{
490
- } // }}}
491
-
492
- // Helper Functions {{{
493
- var debug_dim = this.dim.debug = function() { //{{{
494
- line = '\n';
495
- for (let i=1; i < self.dim.symbols.length; i++) {
496
- line += i.sprintf('%02d') + ': ';
497
- if (self.dim.symbols[i]) {
498
- for (let j=1; j < self.dim.symbols[i].length; j++) {
499
- line += ' [ ';
500
- if (self.dim.symbols[i] && self.dim.symbols[i][j] && self.dim.symbols[i][j].x) { line += self.dim.symbols[i][j].x.sprintf('%3d'); } else { line += ' '; }
501
- line += ', ';
502
- if (self.dim.symbols[i] && self.dim.symbols[i][j] && self.dim.symbols[i][j].width) { line += self.dim.symbols[i][j].width.sprintf('%3d'); } else { line += ' '; }
503
- line += ' ] ';
504
- }
505
- }
506
- line += "\n";
507
- }
508
- return line;
509
- } //}}}
510
-
511
- var set_x = this.dim.set_x = function(row,col,twidth) { //{{{
512
- // reserves the space of a cell; what is drawn there (type, label, ...) is set by set_x_cond
513
- if (!self.dim.symbols[row]) { self.dim.symbols[row] = []; }
514
- if (!self.dim.symbols[row][col]) { self.dim.symbols[row][col] = {}; }
515
-
516
- if (self.dim.symbols[row-1] && self.dim.symbols[row-1][col] && self.dim.symbols[row-1][col].x) { // row before
517
- self.dim.symbols[row][col].x = self.dim.symbols[row-1][col].x;
518
- } else if (self.dim.symbols[row] && self.dim.symbols[row][col-1] && self.dim.symbols[row][col-1].x) { // column before
519
- let mx = 0;
520
- for (let i=row; i<self.dim.symbols.length; i++) {
521
- if (self.dim.symbols[i][col-1] && mx < self.dim.symbols[i][col-1].x + self.dim.symbols[i][col-1].width) {
522
- mx = self.dim.symbols[i][col-1].x + self.dim.symbols[i][col-1].width;
523
- }
524
- }
525
- self.dim.symbols[row][col].x = mx;
526
- } else if (self.dim.symbols[row-1] && self.dim.symbols[row-1][col-1] && self.dim.symbols[row-1][col-1].x) { // diagonal left above
527
- self.dim.symbols[row][col].x = self.dim.symbols[row-1][col-1].x + self.dim.symbols[row-1][col-1].width;
528
- } else if (self.dim.symbols.length > row + 1) { // same column below
529
- let mx = 0;
530
- for (let i=row; i<self.dim.symbols.length; i++) {
531
- if (self.dim.symbols[i] && self.dim.symbols[i][col] && mx < self.dim.symbols[i][col].x) {
532
- mx = self.dim.symbols[i][col].x;
533
- }
534
- }
535
- self.dim.symbols[row][col].x = mx;
536
- } else { // same column above
537
- let mx = 0;
538
- for (let i=row; i>0; i--) {
539
- if (self.dim.symbols[i] && self.dim.symbols[i][col] && mx < self.dim.symbols[i][col].x) {
540
- mx = self.dim.symbols[i][col].x;
541
- }
542
- }
543
- self.dim.symbols[row][col].x = mx;
544
- }
545
- if (self.dim.symbols[row][col].width) {
546
- if (twidth > self.dim.symbols[row][col].width) {
547
- self.dim.symbols[row][col].width = twidth;
548
- }
549
- } else {
550
- self.dim.symbols[row][col].width = twidth;
551
- }
552
- // console.log('set_x ',row,col,debug_dim());
553
- } //}}}
554
- var set_x_cond = this.dim.set_x_cond = function(row,col,tx,twidth,sname,label,subtype,sty,eid) { //{{{
555
- if (self.lr) { // labels widen the row, not the column
556
- set_row(row,col,[]);
557
- self.dim.rows[row][col].size = Math.max(self.dim.rows[row][col].size || 0, twidth);
558
- twidth = self.width;
559
- }
560
- if (!self.dim.symbols[row]) { self.dim.symbols[row] = []; }
561
- if (!self.dim.symbols[row][col] || self.dim.symbols[row][col].width < twidth) {
562
- self.dim.symbols[row][col] = {};
563
- self.dim.symbols[row][col].x = tx;
564
- self.dim.symbols[row][col].width = twidth;
565
- }
566
- self.dim.symbols[row][col].type = sname;
567
- self.dim.symbols[row][col].label = label;
568
- self.dim.symbols[row][col].subtype = subtype;
569
- self.dim.symbols[row][col].eid = eid;
570
- for (const s in sty) {
571
- self.dim.symbols[row][col][s] = sty[s];
572
- }
573
- // console.log('set_x_cond',row,col,debug_dim());
574
- } //}}}
575
-
576
- var get_x = this.dim.get_x = function(row,col,deb='') { //{{{
577
- if (row<0) { row = 0 };
578
-
579
- let mlen = 0;
580
- if (self.dim.symbols[row] && self.dim.symbols[row][col] && self.dim.symbols[row][col].x) { // this column
581
- mlen = self.dim.symbols[row][col].x;
582
- } else if (self.dim.symbols[row] && !self.dim.symbols[row][col] && self.dim.symbols.length > row && self.dim.symbols[row+1] && self.dim.symbols[row+1][col] && self.dim.symbols[row+1][col].x ) { // row after
583
- mlen = self.dim.symbols[row+1][col].x;
584
- } else if (self.dim.symbols[row-1] && self.dim.symbols[row-1][col] && self.dim.symbols[row-1][col].x) { // row before
585
- mlen = self.dim.symbols[row-1][col].x;
586
- } else if (self.dim.symbols[row] && self.dim.symbols[row][col-1] && self.dim.symbols[row][col-1].x) { // column before
587
- for (let i=row; i<self.dim.symbols.length; i++) {
588
- if (self.dim.symbols[i][col-1] && mlen < self.dim.symbols[i][col-1].x + self.dim.symbols[i][col-1].width) {
589
- mlen = self.dim.symbols[i][col-1].x + self.dim.symbols[i][col-1].width;
590
- }
591
- }
592
- } else if (self.dim.symbols[row+1] && self.dim.symbols[row+1][col] && self.dim.symbols[row+1][col].x) { // directly below
593
- mlen = self.dim.symbols[row+1][col].x;
594
- } else if (self.dim.symbols[row-1] && self.dim.symbols[row-1][col-1] && self.dim.symbols[row-1][col-1].x) { // diagonal left above
595
- mlen = self.dim.symbols[row-1][col-1].x + self.dim.symbols[row-1][col-1].width;
596
- } else { // same column below
597
- for (let i=row; i<self.dim.symbols.length; i++) {
598
- if (self.dim.symbols[i] && self.dim.symbols[i][col] && mlen < self.dim.symbols[i][col].x + self.dim.symbols[i][col].width) {
599
- mlen = self.dim.symbols[i][col].x;
600
- }
601
- }
602
- // found nothing in the rows below
603
- if (mlen == 0) { // mostly for column 0
604
- mlen = self.width;
605
- }
606
- }
607
- // console.log(deb,row,col,'--> ' + mlen,debug_dim());
608
- return mlen;
609
- } //}}}
610
- var get_x_plus = this.dim.get_x_plus = function(rowf,rowt,col,deb='') { //{{{
611
- if (rowf<0) { rowf = 0 };
612
-
613
- mlen = 0;
614
- for (let i=rowf; i<=rowt; i++) {
615
- if (self.dim.symbols[i] && self.dim.symbols[i][col] && mlen < self.dim.symbols[i][col].x + self.dim.symbols[i][col].width) {
616
- mlen = self.dim.symbols[i][col].x + self.dim.symbols[i][col].width;
617
- }
618
- }
619
- // console.log(deb,rowf,rowt,col,'--> ' + mlen,debug_dim());
620
- return mlen;
621
- } //}}}
622
- var get_x_max = this.dim.get_x_max = function(rowf,rowt,colt,deb='') { //{{{
623
- if (rowf<0) { rowf = 0 };
624
-
625
- mlen = 0;
626
- for (let i=rowf; i<=rowt; i++) {
627
- for (let j=0; j<=colt; j++) {
628
- if (self.dim.symbols[i] && self.dim.symbols[i][j] && mlen < self.dim.symbols[i][j].x + self.dim.symbols[i][j].width) {
629
- mlen = self.dim.symbols[i][j].x + self.dim.symbols[i][j].width;
630
- }
631
- }
632
- }
633
- // console.log(deb,rowf,rowt,colt,'--> ' + mlen,debug_dim());
634
- return mlen;
635
- } //}}}
636
- var get_x_width = this.dim.get_x_width = function(maxcol) { //{{{
637
- let cwidth = 0;
638
- for (let i=0; i < self.dim.symbols.length; i++) {
639
- let lwidth = 0;
640
- for (let j=0; j <= maxcol; j++) {
641
- if (typeof self.dim.symbols[i] !== 'undefined' && typeof self.dim.symbols[i][j] !== 'undefined') {
642
- lwidth += self.dim.symbols[i][j].width;
643
- } else {
644
- // go up the column and find the next valid value
645
- let x = i;
646
- let found = false;
647
- while (x > 0 && !found) {
648
- x -= 1;
649
- if (typeof self.dim.symbols[x] !== 'undefined' && typeof self.dim.symbols[x][j] !== 'undefined') {
650
- lwidth += self.dim.symbols[x][j].width;
651
- found = true;
652
- }
653
- }
654
- if (!found) {
655
- lwidth[i] += self.width;
656
- }
657
- }
658
- }
659
- if (cwidth < lwidth) { cwidth = lwidth; }
660
- }
661
- return cwidth;
662
- } //}}}
663
-
664
- var get_y = this.draw.get_y = function(row) { // {{{
665
- return { y: row * self.height - self.height, height_shift: self.height_shift};
666
- } // }}}
667
- var lr_shift = function() { // {{{
668
- // mirroring swaps the left (width - width_shift) and top (height_shift) margins, so shift them back
669
- return self.width - self.width_shift - self.height_shift;
670
- } // }}}
671
- var lr_matrix = function() { // {{{
672
- return 'matrix(0,1,1,0,' + lr_shift() + ',' + (self.height_shift - lr_shift()) + ')'; // top margin is twice the height_shift
673
- } // }}}
674
- var set_row = this.dim.set_row = function(row,col,prev) { // {{{
675
- // lr: a symbol starts where its predecessors end, so only things in the same block are aligned
676
- if (!self.lr) { return; }
677
- if (!self.dim.rows[row]) { self.dim.rows[row] = []; }
678
- if (self.dim.rows[row][col]) { return; }
679
- let mx = 0;
680
- prev.forEach((p) => {
681
- if (!p) { return; }
682
- if (p.row == 0 || p.col == 0) { p = { row: 1, col: 1 }; } // first element connects to description
683
- mx = Math.max(mx, get_row_end(p.row,p.col));
684
- });
685
- for (let i=1; i<row; i++) { // and after everything before in this and the following columns, e.g. blocks in vertical parallels share columns
686
- for (let j=col; self.dim.rows[i] && j<self.dim.rows[i].length; j++) {
687
- if (self.dim.rows[i][j]) { mx = Math.max(mx, get_row_end(i,j)); }
688
- }
689
- }
690
- self.dim.rows[row][col] = { start: mx };
691
- } // }}}
692
- var get_row = this.dim.get_row = function(row,col) { // {{{
693
- if (!self.lr) { return (row - 1) * self.height; }
694
- for (let j=col; j>=0; j--) { // e.g. wide connections point to empty columns
695
- if (self.dim.rows[row] && self.dim.rows[row][j]) { return self.dim.rows[row][j].start; }
696
- }
697
- return 0;
698
- } // }}}
699
- var get_row_end = this.dim.get_row_end = function(row,col) { // {{{
700
- if (!self.lr) { return row * self.height; }
701
- let size = self.dim.rows[row] && self.dim.rows[row][col] && self.dim.rows[row][col].size;
702
- return get_row(row,col) + (size || self.height);
703
- } // }}}
704
- var get_row_max = this.dim.get_row_max = function(rowf,rowt,colf,colt) { // {{{
705
- if (!self.lr) { return rowt * self.height; }
706
- let mx = 0;
707
- let last = false;
708
- for (let i=rowf; i<=rowt; i++) {
709
- for (let j=colf; j<=colt; j++) {
710
- if (self.dim.rows[i] && self.dim.rows[i][j]) {
711
- mx = Math.max(mx, get_row_end(i,j));
712
- if (i == rowt) { last = true; }
713
- }
714
- }
715
- }
716
- return last ? mx : mx + self.height; // closing symbols are drawn after the border
717
- } // }}}
718
-
719
- var get_width = this.draw.get_width = function(g) { //{{{
720
- let t = g.clone();
721
- self.svg.container.append(t);
722
- let bb = t[0].getBBox();
723
- let w = bb.width - bb.x;
724
- t.remove();
725
- return w;
726
- } //}}}
727
- var get_label_end = this.draw.get_label_end = function(lab,frame) { //{{{
728
- // where a label ends, in the coordinates of frame (one of its ancestors),
729
- // including all transforms in between, so it does not matter if the label
730
- // is beside the icon, below it, rotated or right aligned
731
- let inner = lab.clone();
732
- lab.parentsUntil(frame).each(function(_,p) {
733
- let w = $X('<g xmlns="http://www.w3.org/2000/svg"></g>');
734
- if ($(p).attr('transform')) { w.attr('transform',$(p).attr('transform')); }
735
- inner = w.append(inner);
736
- });
737
- let g = $X('<g xmlns="http://www.w3.org/2000/svg"></g>').append(inner);
738
- self.svg.container.append(g);
739
- let bb = g[0].getBBox();
740
- g.remove();
741
- return Math.max(0, bb.x + bb.width);
742
- } //}}}
743
- var get_height = this.draw.get_height = function(g) { //{{{
744
- let t = g.clone();
745
- self.svg.container.append(t);
746
- let bb = t[0].getBBox();
747
- let h = bb.height - bb.y;
748
- t.remove();
749
- return h;
750
- } //}}}
751
- var get_dim = this.draw.get_dim = function(g) { //{{{
752
- let element = g.clone();
753
- self.svg.container.append(element);
754
- let dim = get_box(element[0]);
755
- element.remove();
756
- return dim;
757
- } //}}}
758
- var get_box = this.draw.get_box = function(el) { //{{{
759
- // the enclosing box of a drawn element, in the coordinates of its svg,
760
- // including all transforms (e.g. its blocks and the lr mirroring)
761
- let svg = el.ownerSVGElement;
762
-
763
- var r = el.getBBox();
764
-
765
- if (!svg) {
766
- return { x: 0, y: 0, cx: 0, cy: 0, width: 0, height: 0 };
767
- }
768
-
769
- var p = svg.createSVGPoint();
770
-
771
- var matrix = svg.getScreenCTM().inverse().multiply(el.getScreenCTM());
772
-
773
- p.x = r.x;
774
- p.y = r.y;
775
- var a = p.matrixTransform(matrix);
776
-
777
- p.x = r.x + r.width;
778
- p.y = r.y;
779
- var b = p.matrixTransform(matrix);
780
-
781
- p.x = r.x + r.width;
782
- p.y = r.y + r.height;
783
- var c = p.matrixTransform(matrix);
784
-
785
- p.x = r.x;
786
- p.y = r.y + r.height;
787
- var d = p.matrixTransform(matrix);
788
-
789
- var minX = Math.min(a.x, b.x, c.x, d.x);
790
- var maxX = Math.max(a.x, b.x, c.x, d.x);
791
- var minY = Math.min(a.y, b.y, c.y, d.y);
792
- var maxY = Math.max(a.y, b.y, c.y, d.y);
793
-
794
- var width = maxX - minX;
795
- var height = maxY - minY;
796
-
797
- return {
798
- x: minX,
799
- y: minY,
800
- width: width,
801
- height: height,
802
- cx: minX + width / 2,
803
- cy: minY + height / 2
804
- };
805
- } //}}}
806
-
807
- var bind_event = this.draw.bind_event = function(sym,tname,context) { //{{{
808
- for(event_name in adaptor.elements[tname]) {
809
- sym.bind(event_name, {'function_call':adaptor.elements[tname][event_name]}, function(e) { e.data.function_call($(this).attr('element-id'),e)});
810
- if(event_name == 'mousedown') sym.bind('contextmenu', false);
811
- }
812
- } //}}}
813
-
814
- var draw_stripe = this.draw.draw_stripe = function (row, maxcol) { // {{{
815
- if (maxcol < 1) maxcol = 1;
816
-
817
- let cwidth = get_x_width(maxcol);
818
- cwidth = cwidth + 2 * self.width - self.width_shift;
819
-
820
- var g = $X('<rect element-row="' + row + '" class="stripe ' + (row % 2 == 0 ? 'even' : 'odd') + '" x="0" y="' + String(row*self.height+self.height_shift/2) + '" width="' + cwidth + '" height="' + (self.height) + '" xmlns="http://www.w3.org/2000/svg"></rect>');
821
- self.svg.container.prepend(g);
822
- return g;
823
- } // }}}
824
- var draw_symbol = this.draw.draw_symbol = function(sname, id, title, parent_row, max_row, row, col, group, addition, info, style) { // {{{
825
- if(self.elements[sname] == undefined || self.elements[sname].svg == undefined) sname = 'unknown';
826
- let center_x = (self.width - self.default_width) / 2;
827
- let center_y = (self.height - self.default_height) / 2;
828
-
829
- let dstart = get_x(parent_row,col,'symbol ' + sname);
830
-
831
- let sstart = dstart + center_x - self.width_shift;
832
- let stop = get_row(row,col) + center_y + self.height_shift;
833
-
834
- var g = $X('<g class="element" element-row="' + (row-1) + '" element-type="' + sname + '" element-id="' + id + '" xmlns="http://www.w3.org/2000/svg">' +
835
- '<g transform="translate(' + String(sstart) + ',' + String(stop) + ')' + (self.lr ? ' matrix(0,1,1,0,0,0)' : '') + '"></g>' + // lr: mirror back, so that the symbol is upright
836
- '</g>');
837
-
838
- // add the element-endpoint and other stuff to each symbol (from theme info function)
839
- for (const key in info) {
840
- g.attr(key, info[key]);
841
- }
842
-
843
- var sym = self.svg.defs[sname].clone();
844
- var subtype = undefined;
845
-
846
- if (g.attr('element-endpoint')) {
847
- let tsym = self.get_symbol(g.attr('element-endpoint'));
848
- if (tsym) {
849
- let tpart = (p) => $('.part-' + p,tsym);
850
- let tnor = tpart('normal');
851
- if (tnor.length + tpart('start').length + tpart('middle').length + tpart('end').length == 0) {
852
- // a plain icon, all of it is the normal part
853
- tnor = $X('<g class="part-normal" xmlns="http://www.w3.org/2000/svg"></g>');
854
- tnor.append($(tsym.documentElement.children).clone());
855
- }
856
- if (tpart('start').length + tpart('middle').length + tpart('end').length == 0) {
857
- // only a normal part: the icon has no place for a label, so none is shown
858
- $('.part-start, .part-middle, .part-end',sym).remove();
859
- } else {
860
- // an own middle without an end is not clipped after the label, so then the default end goes as well
861
- if (tpart('middle').length > 0 || tpart('end').length > 0) {
862
- $('.part-end',sym).remove();
863
- }
864
- if (tpart('end').length > 0) {
865
- sym.prepend(tpart('end').clone());
866
- }
867
- if (tpart('middle').length > 0) {
868
- $('.part-middle',sym).remove();
869
- sym.prepend(tpart('middle').clone());
870
- }
871
- let dsta = $('.part-start',sym);
872
- if (tpart('start').length > 0) {
873
- dsta.remove();
874
- sym.prepend(tpart('start').clone());
875
- } else if (dsta.length > 0 && tnor.length > 0) {
876
- // without an own start, the normal part is the start, clipped like the default start
877
- let tsta = tnor.clone().attr('class','part-start');
878
- if (dsta.attr('clip-path')) { tsta.attr('clip-path',dsta.attr('clip-path')); }
879
- dsta.remove();
880
- sym.prepend(tsta);
881
- }
882
- }
883
- if (tnor.length > 0) {
884
- $('.part-normal',sym).remove();
885
- sym.prepend(tnor.clone());
886
- }
887
- }
888
- let tprop = self.get_properties(g.attr('element-endpoint'));
889
- if (tprop) {
890
- subtype = tprop.subtype;
891
- }
892
- }
893
-
894
- sym.attr('class','activities');
895
- let sty = { ...self.global_style, ...style };
896
- for (const s in sty) {
897
- $('.colorstyle', sym).each((_,ele) => {
898
- $(ele).css(s,sty[s]);
899
- });
900
- }
901
-
902
- var tit = $X('<title xmlns="http://www.w3.org/2000/svg"></title>');
903
- tit.text(title);
904
- sym.prepend(tit);
905
- let lab = $('.label',sym);
906
- if (lab.length > 0 && self.compact) {
907
- let l_maxlen = 40; // max label size
908
- let l_split = 18; // desired split position
909
- let l_dev = 10; // if one split line is bigger than l_split + l_dev, split was not successfull and we have to display a more truncated string
910
- let l_trunc = 18; // trucation size
911
-
912
- let sta = $('.part-start',sym);
913
- let mid = $('.part-middle',sym);
914
- let end = $('.part-end',sym);
915
- let xtr = $('.part-extra',sym);
916
- let nor = $('.part-normal',sym);
917
- if (title && title != '') {
918
- if (title.length < l_split) {
919
- lab.text(title);
920
- } else {
921
- if (title.length > l_maxlen) { title = title.substr(0,l_maxlen) + '\u2026'; }
922
- if (title.includes(' ')) {
923
- let len = title.length;
924
- let pos = -2;
925
- let seps = []
926
- while (pos != -1) {
927
- pos = title.indexOf(' ',pos+1);
928
- if (pos > -1) seps.push(pos);
929
- }
930
- let closest = title.length;
931
- let it = 0;
932
- seps.forEach((ele) => {
933
- let min = Math.abs(title.length/2 - ele);
934
- if (min < closest) { closest = min; it = ele; }
935
- });
936
- let l1 = title.substr(0,it);
937
- let l2 = title.substr(it+1);
938
- if (l1.length > l_split+l_dev) {
939
- title = title.substr(0,l_trunc) + '\u2026';
940
- lab.text(title);
941
- } else {
942
- if (l2.length > l_split) { l2 = l2.substr(0,l_trunc) + '\u2026'; }
943
- let a1 = $X('<tspan x="0" dy="-8" xmlns="http://www.w3.org/2000/svg"></tspan>');
944
- a1.text(l1);
945
- let a2 = $X('<tspan x="0" dy="12" xmlns="http://www.w3.org/2000/svg"></tspan>');
946
- a2.text(l2);
947
- lab.append(a1);
948
- lab.append(a2);
949
- }
950
- } else {
951
- if (title.length > l_split) { title = title.substr(0,l_trunc) + '\u2026'; }
952
- lab.text(title);
953
- }
954
- }
955
- if (self.elements[sname].hidelabel) { lab.addClass('invisible'); } // still takes its space
956
- if (mid.length > 0) {
957
- if (end.length > 0) {
958
- let width = this.get_label_end(lab,mid); // the clip path is inside part-middle
959
- let pos = get_dim(mid);
960
- mid.attr('clip-path','url(#ele-' + id + ')');
961
- let clip = $X('<clipPath belongs-to="element" id="ele-' + id + '" xmlns="http://www.w3.org/2000/svg">' +
962
- '<rect x="0" y="-1" width="' + width + '" height="' + (pos.y + pos.height + 4) + '"></rect>' +
963
- '</clipPath>');
964
- $('defs',self.svg.container).append(clip);
965
-
966
- end.attr('transform','translate(' + (pos.x + width - self.endclipshift - 4) + ',0)');
967
- if (xtr.length > 0) {
968
- xtr.attr('transform','translate(' + (pos.x + width - self.endclipshift - 4) + ',0)');
969
- }
970
- set_x_cond(row,col,dstart,pos.x + width - self.endclipshift - 4 + this.get_width(end) + 2 * self.width_shift_label,sname,title,subtype,sty,id);
971
- } else {
972
- let tdim = 0;
973
- if (self.rotated_labels && self.elements[sname].rotatelabels != false) {
974
- lab.addClass('rotate');
975
- tdim = self.width;
976
- } else {
977
- tdim = Math.max(self.width, this.get_label_end(lab,sym) + self.width_shift_label);
978
- }
979
- set_x_cond(row,col,dstart,tdim,sname,title,subtype,sty,id);
980
- }
981
- } else {
982
- set_x_cond(row,col,dstart,self.width,sname,title,subtype,sty,id);
983
- }
984
- if (nor.length > 0) { nor.remove(); }
985
- } else {
986
- set_x_cond(row,col,dstart,self.width,sname,title,subtype,sty,id);
987
- if (sta.length > 0) { sta.remove(); }
988
- if (mid.length > 0) { mid.remove(); }
989
- if (end.length > 0) { end.remove(); }
990
- }
991
- } else {
992
- $('.part-start',sym).remove();
993
- $('.part-middle',sym).remove();
994
- $('.part-end',sym).remove();
995
- set_x_cond(row,col,dstart,self.width,sname,title,subtype,sty,id);
996
- }
997
- if (self.elements[sname].implied) { self.dim.implied.push($.extend({row: row, col: col}, self.elements[sname].implied)); }
998
- if (self.elements[sname].hidelabel) { // only takes its space, it is not shown
999
- self.dim.symbols[row][col].label = undefined;
1000
- } else if (lab.length > 0 && lab.text() != '' && $.contains(sym[0],lab[0])) {
1001
- self.dim.labels[row + ',' + col] = lab[0];
1002
- }
1003
-
1004
-
1005
- $(g[0].childNodes[0]).append(sym);
1006
- if (!addition) {
1007
- // TODO change to better respresent exec
1008
- $(g[0].childNodes[0]).append(
1009
- $X('<text class="super" transform="translate(20,-2)" xmlns="http://www.w3.org/2000/svg">' +
1010
- '<tspan class="exec">▶</tspan>' +
1011
- '<tspan class="active">0</tspan>' +
1012
- '<tspan class="colon">,</tspan>' +
1013
- '<tspan class="vote">0</tspan>' +
1014
- '</text>')
1015
- );
1016
- }
1017
-
1018
- // hover, top left of the symbol, or top right if the theme says so (e.g. because of a label on the left)
1019
- $(g[0].childNodes[0]).append(
1020
- $X(
1021
- '<g class="hoverstyle markstyle"' + (self.elements[sname].mark_position == 'right' ? ' transform="translate(27,0)"' : '') + ' xmlns="http://www.w3.org/2000/svg">' +
1022
- '<circle cx="2" cy="0" r="7"/>' +
1023
- '<path d="m -1 0 l 2 2 l 4 -4" class="standline"/>' +
1024
- '</g>'
1025
- )
1026
- );
1027
-
1028
- // Binding events for symbol
1029
- bind_event(g,sname,true);
1030
-
1031
- if (group) {group.append(g);}
1032
- else {self.svg.container.children('g:first').append(g);}
1033
-
1034
- return g;
1035
- } // }}}
1036
- var draw_border = this.draw.draw_border = function(id, p1, p2, group, yshrink) { // {{{
1037
- yshrink = yshrink || 0;
1038
- let bstart = get_x(p1.row,p1.col,'border from');
1039
- let bend = get_x_plus(p1.row,p2.row,p2.col,'border to');
1040
- group.prepend($X('<rect element-id="' + id + '" x="' + (bstart - 1.1 * self.width_shift - self.group_extend) + '" ' +
1041
- 'y="' + (get_row(p1.row,p1.col)+self.height_shift/2-self.group_extend+yshrink) + '" ' +
1042
- 'width="' + (bend-bstart+2*self.group_extend) + '" ' +
1043
- 'height="' + (get_row_max(p1.row,p2.row,p1.col,p2.col)-get_row(p1.row,p1.col)+2*self.group_extend-2*yshrink) + '" ' +
1044
- 'class="block" rx="12" ry="12" xmlns="http://www.w3.org/2000/svg"/>'));
1045
- } // }}}
1046
- var draw_tile = this.draw.draw_tile = function(id, p1, p2, group, yshrink=0) { // {{{
1047
- let bstart = get_x(p1.row,p1.col,'tile from');
1048
- let bend = get_x_plus(p1.row,p2.row,p2.col,'tile to');
1049
- group.prepend($X('<rect element-id="' + id + '" x="' + (bstart - 1.1 * self.width_shift - self.group_extend) + '" ' +
1050
- 'y="' + (get_row(p1.row,p1.col)+self.height_shift/2-self.group_extend+yshrink) + '" ' +
1051
- 'width="' + (bend-bstart+2*self.group_extend) + '" ' +
1052
- 'height="' + (get_row_max(p1.row,p2.row,p1.col,p2.col)-get_row(p1.row,p1.col)+2*self.group_extend-2*yshrink) + '" ' +
1053
- 'class="tile" rx="12" ry="12" xmlns="http://www.w3.org/2000/svg"/>'));
1054
- } // }}}
1055
- var draw_connection = this.draw.draw_connection = function(group, start, end, context_row, arrow, around=false) { // {{{
1056
- let sr = Math.min(start.row,end.row);
1057
- let cstart = get_x(sr,start.col,'conn from');
1058
- let cend = get_x(sr,end.col,'conn to');
1059
- let from = {row: start.row, col: start.col}, to = {row: end.row, col: end.col};
1060
- self.dim.connections.push(self.inverted ? {from: to, to: from} : {from: from, to: to}); // inverted: the arrow points to the start
1061
-
1062
- if(((end['row']-start['row']) == 0) && ((end['col']-start['col']) == 0)) return;
1063
- var line = $X('<path xmlns="http://www.w3.org/2000/svg" class="edge"/>');
1064
- let diag = false; // the arrow sits on a diagonal segment (into a gateway), so it has to be closer to the center
1065
- let sy = get_row(start['row'],start['col']) + self.height - self.conn_center + start.yoffset; // center of the symbols
1066
- let ssym = self.dim.symbols[start['row']] && self.dim.symbols[start['row']][start['col']];
1067
- if (self.lr && self.inverted && ssym && self.elements[ssym.type] && self.elements[ssym.type].svg && $('.part-end',self.elements[ssym.type].svg).length > 0) { // inverted: the arrow points into the start from its end, not under the task template (tasks are the symbols with a part-end)
1068
- sy = get_row_end(start['row'],start['col']) - self.conn_center + start.yoffset; // as far in from the end as other arrows are from the start
1069
- }
1070
- let ey = get_row(end['row'],end['col']) + self.height - self.conn_center + end.yoffset;
1071
- if (around) { // e.g. back in an empty loop: leave at 45 degrees to the right, go straight, enter at 45 degrees
1072
- diag = true;
1073
- let off = 7.5 + 7; // from the center to the corner of the gateway, then 7 further
1074
- line.attr("d", "M " + String(cstart) + "," + String(sy) +" "+
1075
- String(cstart+off) + "," + String(sy-off) +" "+
1076
- String(cend+off) + "," + String(ey+off) +" "+
1077
- String(cend) + "," + String(ey)
1078
- );
1079
- } else if (end['row']-start['row'] == 0 || end['col']-start['col'] == 0) { // straight line
1080
- line.attr("d", "M " + String(cstart) + "," + String(sy) +" "+
1081
- String(cend) + "," + String(ey)
1082
- );
1083
- } else if (end['row']-start['row'] > 0) { // downwards
1084
- if (end['col']-start['col'] > 0) {// left - right
1085
- if (self.compact) {
1086
- diag = self.inverted;
1087
- line.attr("d", "M " + String(cstart) + "," + String(sy) +" "+
1088
- String(cstart+14) + "," + String(get_row_end(start['row'],start['col'])) +" "+ // first turn of horizontal-line going away from node
1089
- String(cend) + "," + String(get_row_end(start['row'],start['col'])) +" "+
1090
- String(cend) + "," + String(ey)
1091
- );
1092
- } else {
1093
- line.attr("d", "M " + String(cstart) + "," + String(sy) +" "+
1094
- String(cend) + "," + String(sy) +" "+
1095
- String(cend) + "," + String(ey)
1096
- );
1097
- }
1098
- } else { // right - left
1099
- diag = !self.inverted;
1100
- line.attr("d", "M " + String(cstart) + "," + String(sy) +" "+
1101
- String(cstart) + "," + String(get_row(end['row'],end['col'])+self.height-32) +" "+
1102
- String(cend+14) + "," + String(get_row(end['row'],end['col'])+self.height-32) +" "+ // last turn of horizontal-line going into the node
1103
- String(cend) + "," + String(ey)
1104
- );
1105
- }
1106
- } else if(end['row']-start['row'] < 0) { // upwards
1107
- diag = !self.inverted;
1108
- let by = (self.lr ? get_row_end(start['row'],start['col']) : (self.dim.symbols.length-1)*self.height) + 4;
1109
- line.attr("d", "M " + String(cstart) + "," + String(sy) +" "+
1110
- String(cstart) + "," + String(by) +" "+
1111
- String(cend+15) + "," + String(by) +" "+
1112
- String(cend+15) + "," + String(get_row(end['row'],end['col'])+self.height+15)+" "+
1113
- String(cend) + "," + String(ey)
1114
- );
1115
- }
1116
- if (arrow) { line.attr(self.inverted ? 'marker-start' : 'marker-end', 'url(#' + (end.structural ? 'endarrow' : (diag ? 'arrowdiag' : 'arrow')) + (self.inverted ? 'rev' : '') + ')'); } // inverted: arrow points to the start
1117
- if (self.lr) { line.attr('transform',lr_matrix()); } // connections are not part of the graph group
1118
- self.svg.container.append(line);
1119
- } // }}}
1120
- // }}}
1121
-
1122
- // Initialize {{{
1123
- adaptor = wf_adaptor;
1124
- // }}}
1125
-
1126
- } // }}}
1127
-
1128
- // WfDescription:
1129
- // Manages the description. Is is further able to add/remove elements from the controlflow description.
1130
- function WfDescription(wf_adaptor, wf_illustrator) { // Model {{{
1131
- // public variables
1132
- this.elements = {}; // the rngs
1133
- this.source = null;
1134
- // private variables
1135
- var self = this;
1136
- var adaptor;
1137
- var illustrator;
1138
- var used_id_list = [];
1139
- var description;
1140
- var orig_description;
1141
- var id_counter = {};
1142
- var update_illustrator = true;
1143
- var labels = [];
1144
-
1145
- // Set Labels //{{{
1146
- this.set_labels = function(graph) {
1147
- if (illustrator.striped == true && illustrator.compact == false) {
1148
- for (var i=0; i < graph.max.row; i++) {
1149
- illustrator.draw.draw_stripe(i,graph.max.col);
1150
- }
1151
- }
1152
- adaptor.draw_labels(graph.max,labels,{ 'height': illustrator.height, 'stripe_height': illustrator.default_height, 'height_shift': illustrator.height_shift },illustrator.striped == true ? true : false);
1153
- } //}}}
1154
-
1155
- // Generic Functions {{{
1156
- this.set_description = function(desc, auto_update) { // public {{{
1157
- if(auto_update != undefined) update_illustrator = auto_update;
1158
- if(typeof desc == "string") {
1159
- description = $($.parseXML(desc));
1160
- } else if(desc instanceof jQuery) {
1161
- description = desc;
1162
- } else {
1163
- alert("WfDescription: unknown description type:\nConstructor-Name: " + desc.constructor + " / TypeOf: " + (typeof desc));
1164
- description = null;
1165
- }
1166
- orig_description = $($X(description.serializeXML()).get(0).ownerDocument);
1167
- id_counter = {};
1168
- labels = [];
1169
- let start = performance.now();
1170
- illustrator.clear();
1171
- var graph = parse(description.children('description').get(0), {'row':0,'col':0,final:false,wide:false,yoffset:0});
1172
- illustrator.set_svg(graph);
1173
- self.set_labels(graph);
1174
- illustrator.set_duration(start);
1175
- } // }}}
1176
- var gd = this.get_description = function() { // public {{{
1177
- var serxml = $(description.get(0).documentElement).clone(true);
1178
- serxml.attr('dir', illustrator.lr ? 'lr' : 'td'); // layout direction of the theme, e.g. for the bpmn export
1179
- serxml.removeAttr('svg-id');
1180
- serxml.removeAttr('svg-type');
1181
- serxml.removeAttr('svg-subtype');
1182
- serxml.removeAttr('svg-label');
1183
- $('*[svg-id]',serxml).each(function(){
1184
- $(this).removeAttr('svg-id');
1185
- });
1186
- $('*[svg-type]',serxml).each(function(){
1187
- $(this).removeAttr('svg-type');
1188
- });
1189
- $('*[svg-subtype]',serxml).each(function(){
1190
- $(this).removeAttr('svg-subtype');
1191
- });
1192
- $('*[svg-label]',serxml).each(function(){
1193
- $(this).removeAttr('svg-label');
1194
- });
1195
- return serxml.serializeXML();
1196
- } // }}}
1197
- this.get_node_by_svg_id = function(svg_id) { // {{{
1198
- return $('[svg-id = \'' + svg_id + '\']', description);
1199
- } // }}}
1200
- var context_eval = this.context_eval = function(what) { // {{{
1201
- return eval(what);
1202
- } // }}}
1203
-
1204
- var reset_used_id_list = this.reset_used_id_list = function() { // {{{
1205
- used_id_list = [];
1206
- } // }}}
1207
- var get_free_id = this.get_free_id = function(prefix,aname,other) { // {{{
1208
- var existing = new Array();
1209
- if (other) {
1210
- if ($(other).attr(aname)) {
1211
- existing.push($(other).attr(aname));
1212
- }
1213
- $(other).find("[" + aname + "]").each(function(k,v){
1214
- existing.push($(v).attr(aname));
1215
- });
1216
- }
1217
- $('*[' + aname + ']', description).each(function(){existing.push($(this).attr(aname))});
1218
- var id = 1;
1219
- while ($.inArray(prefix + id,existing) != -1) {
1220
- id += 1;
1221
- }
1222
- while ($.inArray(prefix + id,used_id_list) != -1) {
1223
- id += 1;
1224
- }
1225
- used_id_list.push(prefix + id);
1226
- return prefix + id;
1227
- } // }}}
1228
- var redraw = this.redraw = function(doit) {
1229
- id_counter = {};
1230
- let start = performance.now();
1231
- labels = [];
1232
- illustrator.clear();
1233
- clean_description();
1234
- var graph = parse(description.children('description').get(0), {'row':0,'col':0,final:false,wide:false,yoffset:0});
1235
- illustrator.set_svg(graph);
1236
- self.set_labels(graph);
1237
- illustrator.set_duration(start);
1238
- if (doit) doit(self);
1239
- }
1240
- var update = this.update = function(svgid) { // {{{
1241
- id_counter = {};
1242
- var notify_target = () => {
1243
- var newn = $('*[new=true]',description);
1244
- newn.removeAttr('new');
1245
-
1246
- if (newn.attr('svg-id') != undefined)
1247
- adaptor.notify(newn.attr('svg-id'));
1248
- else if (svgid != undefined)
1249
- adaptor.notify(svgid);
1250
- else if (newn.parents('[svg-id]').length > 0)
1251
- adaptor.notify(newn.parent('[svg-id]').attr('svg-id'));
1252
- else
1253
- console.info('Something went horribly wrong');
1254
- };
1255
- if (update_illustrator) {
1256
- self.redraw(notify_target);
1257
- } else {
1258
- notify_target();
1259
- }
1260
- } // }}}
1261
- // }}}
1262
- // Adaption functions {{{
1263
- this.insert_after = function(new_node, target, source_opts) { // {{{
1264
- reset_used_id_list();
1265
- if (Array.isArray(new_node)) {
1266
- $.each(new_node,function(k,v){
1267
- var nn = self.source(v,source_opts);
1268
- target.after(nn);
1269
- nn.attr('new','true');
1270
- });
1271
- } else {
1272
- var nn = self.source(new_node,source_opts);
1273
- target.after(nn);
1274
- nn.attr('new','true');
1275
- }
1276
- update();
1277
- } // }}}
1278
- this.insert_first_into = function(new_node, target, source_opts) { // {{{
1279
- reset_used_id_list();
1280
- if (Array.isArray(new_node)) {
1281
- $.each(new_node,function(k,v){
1282
- var nn = self.source(v,source_opts);
1283
- target.prepend(nn);
1284
- nn.attr('new','true');
1285
- });
1286
- } else {
1287
- var nn = self.source(new_node,source_opts);
1288
- target.prepend(nn);
1289
- nn.attr('new','true');
1290
- }
1291
- update();
1292
- } // }}}
1293
- this.insert_last_into = function(new_node, target) { // {{{
1294
- reset_used_id_list();
1295
- if (Array.isArray(new_node)) {
1296
- $.each(new_node,function(k,v){
1297
- var nn = self.source(v);
1298
- target.append(nn);
1299
- nn.attr('new','true');
1300
- });
1301
- } else {
1302
- var nn = self.source(new_node);
1303
- target.append(nn);
1304
- nn.attr('new','true');
1305
- }
1306
- update();
1307
- } // }}}
1308
- this.remove = function(selector, target) {//{{{
1309
- var svgid;
1310
- if(selector == undefined) {
1311
- svgid = target.attr('svg-id');
1312
- target.remove()
1313
- } else {
1314
- svgid = $(selector, target).attr('svg-id');
1315
- if (!svgid) {
1316
- svgid = target.attr('svg-id');
1317
- }
1318
- $(selector, target).remove();
1319
- }
1320
- update(svgid);
1321
- }
1322
- // }}}
1323
- // }}}
1324
- // Helper Functions {{{
1325
- var clean_description = function() { // private {{{
1326
- $('*[svg-id]',description).each(function(){
1327
- $(this).removeAttr('svg-id');
1328
- });
1329
- $('*[svg-type]',description).each(function(){
1330
- $(this).removeAttr('svg-type');
1331
- });
1332
- $('*[svg-subtype]',description).each(function(){
1333
- $(this).removeAttr('svg-subtype');
1334
- });
1335
- $('*[svg-label]',description).each(function(){
1336
- $(this).removeAttr('svg-label');
1337
- });
1338
- } //}}}
1339
- var reversed_loop = function(node) { // private {{{
1340
- return illustrator.wellformed_pre_test && node.tagName == 'loop' && $(node).attr('mode') == 'pre_test';
1341
- } // }}}
1342
- var parse = function(root, parent_pos, first_prev) { // private {{{
1343
- var pos = JSON.parse(JSON.stringify(parent_pos));
1344
- var max = {'row': 0,'col': 0};
1345
- var prev = [first_prev || parent_pos]; // connects parent with child(s), depending on the expansion
1346
- var endnodes = [];
1347
- var markers = []; // wellformed_pre_test: branch markers, drawn in one row below all branches
1348
- var sname = sym_name(root.tagName,root);
1349
- var root_expansion = illustrator.elements[root.tagName].expansion(root);
1350
- var block = { 'max': {'row': pos.row, 'col': pos.col}, 'endnodes': [], 'svg': $X('<g class="group" xmlns="http://www.w3.org/2000/svg"/>') };
1351
-
1352
- if(root_expansion == 'horizontal') pos.row++;
1353
- if(illustrator.elements[root.tagName].col_shift(root) == true && root_expansion != 'horizontal') pos.col++;
1354
-
1355
- if(root.tagName == 'description') { // First parsing {{{
1356
- pos.row++;
1357
- $(root).attr('svg-id','description');
1358
- $(root).attr('svg-type','description');
1359
- $(root).attr('svg-subtype','description');
1360
- block.svg.attr('element-id','group-description');
1361
- if (illustrator.elements[sname].label) {
1362
- // javascript object spread syntax is my new weird crush - the JS designers must be serious people
1363
- labels.push({...{row: pos.row, element_id: 'start', tname: 'start', label: illustrator.elements[sname].label(root)},...illustrator.draw.get_y(pos.row)});
1364
- }
1365
- illustrator.global_style = (illustrator.elements[sname].style && root) ? illustrator.elements[sname].style(root) : {};
1366
- illustrator.draw.draw_symbol(sname, 'description', '', pos.row, pos.row, pos.row, pos.col, block.svg, false, {}, {})
1367
- } // }}}
1368
-
1369
- var children = $(root).children().filter(function(){ return this.localName[0] != '_'; });
1370
- if (illustrator.inverted && root_expansion != 'horizontal') { children = $(children.get().reverse()); } // wellformed_pre_test: everything inside is drawn in reverse order, but not the branches
1371
- children.each(function() {
1372
- var context = this;
1373
- var tname = context.tagName;
1374
- var sname = sym_name(tname,context);
1375
- pos.final = illustrator.elements[sname].final ? true : false;
1376
- pos.wide = illustrator.elements[sname].wide ? true : false;
1377
- pos.noindent = illustrator.elements[sname].noindent ? true : false;
1378
-
1379
- // Calculate next position {{{
1380
- if(root_expansion == 'vertical') { pos.row++; }
1381
- if(root_expansion == 'horizontal') {
1382
- // for noindent themes do not indent the first column
1383
- if (!pos.noindent || (pos.noindent && endnodes.length > 1)) {
1384
- illustrator.dim.set_x(pos.row,pos.col,illustrator.width);
1385
- pos.col++;
1386
- }
1387
- if (!illustrator.compact) {
1388
- if (block.max.row) {
1389
- illustrator.dim.set_x(pos.row,pos.col,illustrator.width);
1390
- pos.row = block.max.row + 1;
1391
- }
1392
- }
1393
- }
1394
-
1395
- var bottom = false;
1396
- if(illustrator.elements[tname] != undefined && illustrator.elements[tname].type == 'complex') {
1397
- bottom = illustrator.inverted && root_expansion == 'horizontal'; // wellformed_pre_test: branch markers are drawn below their content
1398
- if(illustrator.elements[tname] != undefined && !illustrator.elements[tname].svg) pos.row--;
1399
- // TODO: Remaining problem is the order inside the svg. Thats why the connection is above the icon
1400
-
1401
- illustrator.dim.set_x(pos.row,pos.col,illustrator.width);
1402
- illustrator.dim.set_row(pos.row,pos.col,prev);
1403
- if ((bottom ? !illustrator.lr : (illustrator.lr && illustrator.elements[tname].expansion(context) == 'vertical' && !illustrator.elements[tname].col_shift(context))) && illustrator.elements[sname].svg) { // lr: the content follows the label in the same column, bottom: the marker is drawn after the next branches, so measure the symbol before it is drawn
1404
- let lab = (illustrator.elements[sname].label ? illustrator.elements[sname].label(context) : []) || [];
1405
- let tit = lab.find((l) => l && l.column == 'Label' && l.value);
1406
- illustrator.draw.draw_symbol(sname, 'measure', tit ? tit.value : undefined, pos.row, pos.row, pos.row, pos.col, $X('<g xmlns="http://www.w3.org/2000/svg"/>'), true, {}, {});
1407
- }
1408
- // but fuuuuu, we calculate the gateways only later, so we couldnt even have them bigger for now
1409
-
1410
- // console.log('----> down', tname, parent_pos.row, pos.row, parent_pos.col, pos.col, illustrator.dim.debug());
1411
-
1412
- if (reversed_loop(context)) { illustrator.inverted = !illustrator.inverted; }
1413
- let tblock;
1414
- if (bottom) { // content starts in the row of the marker and connects to the gateway
1415
- let up = JSON.parse(JSON.stringify(pos));
1416
- up.row--;
1417
- tblock = parse(context, up, prev[0]);
1418
- } else {
1419
- tblock = parse(context, JSON.parse(JSON.stringify(pos)));
1420
- }
1421
- if (reversed_loop(context)) { illustrator.inverted = !illustrator.inverted; }
1422
-
1423
- // merge block and tblock, enforce the max, as the second branch could have fewer nodes than the first
1424
- block.max.row = Math.max(block.max.row,tblock.max.row);
1425
- block.max.col = Math.max(block.max.col,tblock.max.col);
1426
- block.endnodes = tblock.endnodes;
1427
- if (bottom) { // markers are drawn after all branches, see below
1428
- markers.push({ tname: tname, sname: sname, context: context, prev: tblock.endnodes, col: pos.col, top: pos.row, maxcol: tblock.max.col });
1429
- }
1430
-
1431
- // console.log('<---- up', tname, parent_pos.row, block.max.row, parent_pos.col, block.max.col, illustrator.dim.debug());
1432
-
1433
- block.svg.append(tblock.svg);
1434
- block.svg.attr('id', 'group-' + $(context).attr('svg-id'));
1435
- if(illustrator.elements[sname].endnodes == 'aggregate') endnodes = []; // resets endpoints e.g. potential preceding primitive
1436
- } else {
1437
- if(illustrator.elements[tname] != undefined && illustrator.elements[tname].type == 'primitive' && illustrator.elements[tname].svg) { // This enables "invisble" elements, by returning undefined in the SVG function (e.g. constraints)
1438
- block.max.row = pos.row;
1439
- block.max.col = pos.col;
1440
- block.endnodes = [pos];
1441
- }
1442
- }
1443
- // }}}
1444
-
1445
- var g;
1446
- if (!bottom) {
1447
- set_details(tname,sname,pos,context);
1448
- var origpos = JSON.parse(JSON.stringify(pos));
1449
- [g, endnodes] = draw_position(tname,parent_pos,origpos,prev,block,endnodes,context);
1450
- }
1451
-
1452
- // Prepare next iteration {{{
1453
- if(root_expansion == 'vertical') { prev = JSON.parse(JSON.stringify(endnodes)); pos.row = block.max.row;} // covers e.g. input's for alternative, parallel_branch, ... everything with horizontal expansion
1454
- if(root_expansion == 'horizontal') pos.col = block.max.col;
1455
- if(max.row < block.max.row) max.row = block.max.row;
1456
- if(max.col < block.max.col) max.col = block.max.col;
1457
- // }}}
1458
-
1459
- if (illustrator.elements[sname].closing_symbol) {
1460
- var ctname = illustrator.elements[sname].closing_symbol;
1461
- var csname = sym_name(ctname,context);
1462
- pos.row++;
1463
- max.row++;
1464
- block.max.row = pos.row;
1465
- // the arrows to the closing symbol belong to the loop. empty loops: the
1466
- // straight arrow comes from the opening symbol, not from the content, and
1467
- // the way back goes around the side, so both point the other way
1468
- let flip = reversed_loop(context) != (illustrator.elements[csname].closeblock == true && pos.row == origpos.row + 1);
1469
- if (flip) { illustrator.inverted = !illustrator.inverted; }
1470
- if (illustrator.elements[sname].endnodes == 'this') {
1471
- pos.col++;
1472
- if (pos.col > max.col) {
1473
- max.col++;
1474
- block.max.col = pos.col;
1475
- }
1476
- draw_position(ctname,parent_pos,pos,block.endnodes,block,[],context,{svg: g, pos: origpos});
1477
- pos.col--;
1478
- set_details(ctname,csname,pos,context,true);
1479
- } else {
1480
- set_details(ctname,csname,pos,context,true);
1481
- [undefined, endnodes] = draw_position(ctname,parent_pos,pos,prev,block,[],context,{svg: g, pos: origpos});
1482
- }
1483
- if (flip) { illustrator.inverted = !illustrator.inverted; }
1484
- if (illustrator.elements[sname].border == 'structural') {
1485
- // structural border: outgoing arrow starts at the group border instead of from the icon
1486
- // small y offset.
1487
- endnodes = endnodes.map(function(p) {
1488
- var np = JSON.parse(JSON.stringify(p));
1489
- np.yoffset = illustrator.height_shift/2 + illustrator.group_extend + illustrator.conn_center - illustrator.structural_tighten;
1490
- return np;
1491
- });
1492
- }
1493
- prev = JSON.parse(JSON.stringify(endnodes));
1494
- }
1495
- });
1496
-
1497
- if (markers.length > 0) {
1498
- max.row++;
1499
- block.max.row = max.row;
1500
- let maxcol = block.max.col;
1501
- if (illustrator.lr) { // all markers start at the same position, after the longest branch
1502
- markers.forEach((m) => { illustrator.dim.set_row(max.row,m.col,m.prev); });
1503
- let start = Math.max(...markers.map((m) => illustrator.dim.get_row(max.row,m.col)));
1504
- markers.forEach((m) => { illustrator.dim.rows[max.row][m.col].start = start; });
1505
- }
1506
- markers.forEach((m) => {
1507
- let mpos = { row: max.row, col: m.col, final: false, wide: false, yoffset: 0, top: m.top, marker: true }; // the tile starts at the top of the branch
1508
- block.endnodes = [mpos]; // the marker is the end of its branch
1509
- block.max.col = m.maxcol; // the tile only covers its own branch
1510
- set_details(m.tname,m.sname,mpos,m.context);
1511
- draw_position(m.tname,parent_pos,mpos,m.prev,block,endnodes,m.context);
1512
- });
1513
- block.max.col = maxcol;
1514
- }
1515
-
1516
- if($(root).children().filter(function(){ return this.attributes['svg-id'] != undefined; }).length == 0) { // empty complex found
1517
- endnodes = [prev[0]]; // parent_pos, or for markers below their content the gateway
1518
- max.row = parent_pos.row;
1519
- max.col = parent_pos.col;
1520
- }
1521
-
1522
- if(root.tagName == 'description' && illustrator.elements[root.tagName].closing_symbol) {
1523
- pos.row++;
1524
- max.row = pos.row;
1525
- draw_position(illustrator.elements['start'].closing_symbol,parent_pos,pos,prev,block,[],root,{svg: block.svg, pos: pos});
1526
- }
1527
-
1528
- return {'endnodes': endnodes, 'max':max, 'svg': block.svg};
1529
- } // }}}
1530
- var sym_name = function(tname,context) { //{{{
1531
- var sname;
1532
- if(!illustrator.elements[tname]) {sname = 'unknown';}
1533
- else if(typeof illustrator.elements[tname].resolve_symbol == 'function') {sname = illustrator.elements[tname].resolve_symbol(context,illustrator.elements[tname].col_shift ? illustrator.elements[tname].col_shift(context) : undefined);}
1534
- else if(typeof illustrator.elements[tname].resolve_symbol == 'string') {sname = illustrator.elements[tname].resolve_symbol;}
1535
- else {sname = tname;}
1536
- if (sname == null) {sname = tname;}
1537
- return sname;
1538
- } //}}}
1539
- var set_details = function(tname,sname,pos,context,simple) { //{{{
1540
- if (simple == undefined || simple == false) {
1541
- if($(context).attr('id') == undefined) {
1542
- if(id_counter[tname] == undefined) id_counter[tname] = -1;
1543
- $(context).attr('svg-id', tname + '_' + (++id_counter[tname]));
1544
- } else {
1545
- $(context).attr('svg-id', $(context).attr('id'));
1546
- }
1547
- }
1548
- if (illustrator.elements[sname].label) {
1549
- var lab = illustrator.elements[sname].label(context);
1550
- if (lab) {
1551
- for (let i=0; i<lab.length; i++) {
1552
- if (lab[i] && lab[i].value && lab[i].column == 'Label' && lab[i].value != '') {
1553
- $(context).attr('svg-label', lab[0].value);
1554
- if (illustrator.compact) {
1555
- lab.splice(i,1);
1556
- }
1557
- }
1558
- }
1559
- labels.push({...{row: pos.row, element_id: $(context).attr('svg-id'), tname: tname, label: lab},...illustrator.draw.get_y(pos.row)});
1560
- }
1561
- }
1562
- } //}}}
1563
- var draw_position = function(tname,parent_pos,pos,prev,block,endnodes,context,second) { // private {{{
1564
- var sname = sym_name(tname,context);
1565
- // console.log('----- pos ' + sname, parent_pos.row, block.max.row, parent_pos.col, block.max.col, block, illustrator.dim.debug());
1566
-
1567
- // Draw Symbol {{{
1568
- illustrator.dim.set_row(pos.row,pos.col,prev);
1569
- let style = {};
1570
- if (illustrator.elements[sname].style && context) {
1571
- style = illustrator.elements[sname].style(context);
1572
- }
1573
- if (second) {
1574
- // wide is only for the special case of variable parallel, only event_end has it, all others should reference the first row
1575
- illustrator.draw.draw_symbol(sname, $(context).attr('svg-id'), $(context).attr('svg-label'), illustrator.elements[sname].wide == true ? parent_pos.row+1 : parent_pos.row, block.max.row, pos.row, pos.col, second.svg, true, {}, style).addClass(illustrator.elements[sname] ? illustrator.elements[sname].type : 'primitive unknown');
1576
- } else {
1577
- $(context).attr('svg-type',tname);
1578
- $(context).attr('svg-subtype',sname);
1579
- if((illustrator.elements[sname] && illustrator.elements[sname].svg) || sname == 'unknown') {
1580
- let info = {};
1581
- if (illustrator.elements[sname].info && context) {
1582
- info = illustrator.elements[sname].info(context);
1583
- }
1584
- var g = illustrator.draw.draw_symbol(sname, $(context).attr('svg-id'), $(context).attr('svg-label'), parent_pos.row, block.max.row, pos.row, pos.col, block.svg, false, info, style).addClass(illustrator.elements[sname] ? illustrator.elements[sname].type : 'primitive unknown');
1585
- } else { console.log("no icon "+ sname);}
1586
- if (illustrator.elements[sname] && illustrator.elements[sname].border) {
1587
- let wide = (illustrator.elements[sname].wide == true && block.max.col == pos.col) ? pos.col + 1 : block.max.col;
1588
- let yshrink = illustrator.elements[sname].border == 'structural' ? illustrator.structural_tighten : 0;
1589
- if (illustrator.elements[sname].closing_symbol) {
1590
- illustrator.draw.draw_border($(context).attr('svg-id'), pos, { col: wide, row: block.max.row + 1 }, block.svg, yshrink);
1591
- } else {
1592
- illustrator.draw.draw_border($(context).attr('svg-id'), pos, { col: wide, row: block.max.row }, block.svg, yshrink);
1593
- }
1594
- }
1595
- if (illustrator.elements[sname] && illustrator.elements[sname].type == 'complex') {
1596
- let wide = (illustrator.elements[sname].wide == true && block.max.col == pos.col) ? pos.col + 1 : block.max.col;
1597
- let yshrink = illustrator.elements[sname].border == 'structural' ? illustrator.structural_tighten : 0;
1598
- if (illustrator.elements[sname].closing_symbol) {
1599
- illustrator.draw.draw_tile($(context).attr('svg-id'), pos, { col: wide, row: block.max.row + 1 }, block.svg, yshrink);
1600
- } else {
1601
- illustrator.draw.draw_tile($(context).attr('svg-id'), pos.top ? { row: pos.top, col: pos.col } : pos, { col: wide, row: block.max.row }, block.svg, yshrink); // top: marker below its content
1602
- }
1603
- }
1604
- }
1605
- // }}}
1606
-
1607
- // Calculate Connection {{{
1608
- let connection_case = 0;
1609
- var conn_target = pos;
1610
- if (illustrator.elements[sname].border == 'structural' && !second) {
1611
- // structural border: incoming arrow stops at the group border instead of reaching into the icon
1612
- // (only a pixel-level yoffset, row/col stay integers so get_x() column lookups stay correct)
1613
- conn_target = JSON.parse(JSON.stringify(pos));
1614
- conn_target.yoffset = -illustrator.height + illustrator.height_shift/2 - illustrator.group_extend + illustrator.conn_center + illustrator.structural_tighten;
1615
- conn_target.structural = true;
1616
- }
1617
- if(illustrator.elements[sname] != undefined && illustrator.elements[sname].closeblock == true) { // Close Block if element e.g. loop
1618
- if (second) {
1619
- if (second.pos.row+1 < pos.row) { // when no content, dont paint the up arrow
1620
- connection_case = 1;
1621
- // console.log('++ case 1',prev[node].row,pos.row,illustrator.dim.debug());
1622
- illustrator.draw.draw_connection(block.svg, pos, second.pos, 0, true);
1623
- } else { // no content: the way back goes around the side
1624
- connection_case = 7;
1625
- illustrator.draw.draw_connection(block.svg, pos, second.pos, 0, true, true);
1626
- }
1627
- } else {
1628
- for (let node=0; node < block.endnodes.length; node++) {
1629
- if (block.endnodes[node] && !block.endnodes[node].final) {
1630
- connection_case = 2;
1631
- // console.log('++ case 2',prev[node].row,pos.row,illustrator.dim.debug());
1632
- illustrator.draw.draw_connection(block.svg, block.endnodes[node], pos, 0, true);
1633
- }
1634
- }
1635
- }
1636
- }
1637
- if(illustrator.elements[sname] != undefined && illustrator.elements[sname].endnodes != 'this') {
1638
- for(i in block.endnodes) { endnodes.push(block.endnodes[i]); } // collects all endpoints from different childs e.g. alternatives from choose
1639
- } else { endnodes = [JSON.parse(JSON.stringify(pos))]; } // sets this element as only endpoint (aggregate)
1640
- if(prev[0].row == 0 || prev[0].col == 0) { // this enforces the connection from description to the first element
1641
- connection_case = 3;
1642
- illustrator.draw.draw_connection(block.svg, { row: 1, col: 1, yoffset: 0 }, conn_target, 0, true);
1643
- } else {
1644
- if (illustrator.elements[sname].noarrow == undefined || illustrator.elements[sname].noarrow == false || illustrator.inverted) { // inverted: the arrow points from the marker to the content
1645
- for (let node=0; node < prev.length; node++) {
1646
- if (prev[node] && !(illustrator.inverted ? pos.final : prev[node].final)) { // inverted: nothing goes out of a final element, which is drawn as the target
1647
- if (prev[node].wide) {
1648
- var pn = JSON.parse(JSON.stringify(prev[node]));
1649
- if (pos.col > prev[node].col) {
1650
- pn.col = pos.col;
1651
- }
1652
- connection_case = 4;
1653
- // console.log('++ case 4',prev[node].row,pos.row,illustrator.dim.debug());
1654
- illustrator.draw.draw_connection(block.svg, pn, conn_target, 0, true);
1655
- } else {
1656
- connection_case = 5;
1657
- if (prev.length == 1) {
1658
- // console.log('++ case 5a',parent_pos.row, '---', prev[node].row,pos.row,illustrator.dim.debug());
1659
- illustrator.draw.draw_connection(block.svg, prev[node], conn_target, 0, !prev[node].marker);
1660
- } else {
1661
- // console.log('++ case 5b',prev[node].row,pos.row,illustrator.dim.debug());
1662
- illustrator.draw.draw_connection(block.svg, prev[node], conn_target, 0, !prev[node].marker); // no arrow into markers drawn below their content
1663
- }
1664
- }
1665
- }
1666
- }
1667
- } else {
1668
- for (let node=0; node < prev.length; node++) {
1669
- if (prev[node] && !prev[node].final) {
1670
- connection_case = 6;
1671
- // console.log('++ case 6',prev[node].row,pos.row,illustrator.dim.debug());
1672
- illustrator.draw.draw_connection(block.svg, prev[node], conn_target, prev[node].row, false);
1673
- }
1674
- }
1675
- }
1676
- }
1677
- // }}}
1678
-
1679
- ///////// show graph step by step
1680
- // illustrator.set_svg(block);
1681
- // debugger;
1682
-
1683
- return [g, endnodes];
1684
- } // }}}
1685
- // }}}
1686
-
1687
- // Initialze {{{
1688
- adaptor = wf_adaptor;
1689
- illustrator = wf_illustrator;
1690
- // }}}
1691
- } // }}}