• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mermaid-js / mermaid / 4877493129

pending completion
4877493129

Pull #4259

github

GitHub
Merge 61e31b3fe into bf3795652
Pull Request #4259: Refactor to consolidate shared svgDraw components

1732 of 2144 branches covered (80.78%)

Branch coverage included in aggregate %.

157 of 157 new or added lines in 7 files covered. (100.0%)

18628 of 33485 relevant lines covered (55.63%)

394.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.54
/packages/mermaid/src/diagrams/c4/svgDraw.js
1
import common from '../common/common.js';
1✔
2
import * as svgDrawCommon from '../common/svgDrawCommon';
1✔
3
import { sanitizeUrl } from '@braintree/sanitize-url';
1✔
4

1✔
5
export const drawRect = function (elem, rectData) {
1✔
6
  return svgDrawCommon.drawRect(elem, rectData);
×
7
};
×
8

1✔
9
export const drawImage = function (elem, width, height, x, y, link) {
1✔
10
  const imageElem = elem.append('image');
×
11
  imageElem.attr('width', width);
×
12
  imageElem.attr('height', height);
×
13
  imageElem.attr('x', x);
×
14
  imageElem.attr('y', y);
×
15
  let sanitizedLink = link.startsWith('data:image/png;base64') ? link : sanitizeUrl(link);
×
16
  imageElem.attr('xlink:href', sanitizedLink);
×
17
};
×
18

1✔
19
export const drawRels = (elem, rels, conf) => {
1✔
20
  const relsElem = elem.append('g');
×
21
  let i = 0;
×
22
  for (let rel of rels) {
×
23
    let textColor = rel.textColor ? rel.textColor : '#444444';
×
24
    let strokeColor = rel.lineColor ? rel.lineColor : '#444444';
×
25
    let offsetX = rel.offsetX ? parseInt(rel.offsetX) : 0;
×
26
    let offsetY = rel.offsetY ? parseInt(rel.offsetY) : 0;
×
27

×
28
    let url = '';
×
29
    if (i === 0) {
×
30
      let line = relsElem.append('line');
×
31
      line.attr('x1', rel.startPoint.x);
×
32
      line.attr('y1', rel.startPoint.y);
×
33
      line.attr('x2', rel.endPoint.x);
×
34
      line.attr('y2', rel.endPoint.y);
×
35

×
36
      line.attr('stroke-width', '1');
×
37
      line.attr('stroke', strokeColor);
×
38
      line.style('fill', 'none');
×
39
      if (rel.type !== 'rel_b') {
×
40
        line.attr('marker-end', 'url(' + url + '#arrowhead)');
×
41
      }
×
42
      if (rel.type === 'birel' || rel.type === 'rel_b') {
×
43
        line.attr('marker-start', 'url(' + url + '#arrowend)');
×
44
      }
×
45
      i = -1;
×
46
    } else {
×
47
      let line = relsElem.append('path');
×
48
      line
×
49
        .attr('fill', 'none')
×
50
        .attr('stroke-width', '1')
×
51
        .attr('stroke', strokeColor)
×
52
        .attr(
×
53
          'd',
×
54
          'Mstartx,starty Qcontrolx,controly stopx,stopy '
×
55
            .replaceAll('startx', rel.startPoint.x)
×
56
            .replaceAll('starty', rel.startPoint.y)
×
57
            .replaceAll(
×
58
              'controlx',
×
59
              rel.startPoint.x +
×
60
                (rel.endPoint.x - rel.startPoint.x) / 2 -
×
61
                (rel.endPoint.x - rel.startPoint.x) / 4
×
62
            )
×
63
            .replaceAll('controly', rel.startPoint.y + (rel.endPoint.y - rel.startPoint.y) / 2)
×
64
            .replaceAll('stopx', rel.endPoint.x)
×
65
            .replaceAll('stopy', rel.endPoint.y)
×
66
        );
×
67
      if (rel.type !== 'rel_b') {
×
68
        line.attr('marker-end', 'url(' + url + '#arrowhead)');
×
69
      }
×
70
      if (rel.type === 'birel' || rel.type === 'rel_b') {
×
71
        line.attr('marker-start', 'url(' + url + '#arrowend)');
×
72
      }
×
73
    }
×
74

×
75
    let messageConf = conf.messageFont();
×
76
    _drawTextCandidateFunc(conf)(
×
77
      rel.label.text,
×
78
      relsElem,
×
79
      Math.min(rel.startPoint.x, rel.endPoint.x) +
×
80
        Math.abs(rel.endPoint.x - rel.startPoint.x) / 2 +
×
81
        offsetX,
×
82
      Math.min(rel.startPoint.y, rel.endPoint.y) +
×
83
        Math.abs(rel.endPoint.y - rel.startPoint.y) / 2 +
×
84
        offsetY,
×
85
      rel.label.width,
×
86
      rel.label.height,
×
87
      { fill: textColor },
×
88
      messageConf
×
89
    );
×
90

×
91
    if (rel.techn && rel.techn.text !== '') {
×
92
      messageConf = conf.messageFont();
×
93
      _drawTextCandidateFunc(conf)(
×
94
        '[' + rel.techn.text + ']',
×
95
        relsElem,
×
96
        Math.min(rel.startPoint.x, rel.endPoint.x) +
×
97
          Math.abs(rel.endPoint.x - rel.startPoint.x) / 2 +
×
98
          offsetX,
×
99
        Math.min(rel.startPoint.y, rel.endPoint.y) +
×
100
          Math.abs(rel.endPoint.y - rel.startPoint.y) / 2 +
×
101
          conf.messageFontSize +
×
102
          5 +
×
103
          offsetY,
×
104
        Math.max(rel.label.width, rel.techn.width),
×
105
        rel.techn.height,
×
106
        { fill: textColor, 'font-style': 'italic' },
×
107
        messageConf
×
108
      );
×
109
    }
×
110
  }
×
111
};
×
112

1✔
113
/**
1✔
114
 * Draws an boundary in the diagram
1✔
115
 *
1✔
116
 * @param {any} elem - The diagram we'll draw to.
1✔
117
 * @param {any} boundary - The boundary to draw.
1✔
118
 * @param {any} conf - DrawText implementation discriminator object
1✔
119
 */
1✔
120
const drawBoundary = function (elem, boundary, conf) {
1✔
121
  const boundaryElem = elem.append('g');
×
122

×
123
  let fillColor = boundary.bgColor ? boundary.bgColor : 'none';
×
124
  let strokeColor = boundary.borderColor ? boundary.borderColor : '#444444';
×
125
  let fontColor = boundary.fontColor ? boundary.fontColor : 'black';
×
126

×
127
  let attrsValue = { 'stroke-width': 1.0, 'stroke-dasharray': '7.0,7.0' };
×
128
  if (boundary.nodeType) {
×
129
    attrsValue = { 'stroke-width': 1.0 };
×
130
  }
×
131
  let rectData = {
×
132
    x: boundary.x,
×
133
    y: boundary.y,
×
134
    fill: fillColor,
×
135
    stroke: strokeColor,
×
136
    width: boundary.width,
×
137
    height: boundary.height,
×
138
    rx: 2.5,
×
139
    ry: 2.5,
×
140
    attrs: attrsValue,
×
141
  };
×
142

×
143
  drawRect(boundaryElem, rectData);
×
144

×
145
  // draw label
×
146
  let boundaryConf = conf.boundaryFont();
×
147
  boundaryConf.fontWeight = 'bold';
×
148
  boundaryConf.fontSize = boundaryConf.fontSize + 2;
×
149
  boundaryConf.fontColor = fontColor;
×
150
  _drawTextCandidateFunc(conf)(
×
151
    boundary.label.text,
×
152
    boundaryElem,
×
153
    boundary.x,
×
154
    boundary.y + boundary.label.Y,
×
155
    boundary.width,
×
156
    boundary.height,
×
157
    { fill: '#444444' },
×
158
    boundaryConf
×
159
  );
×
160

×
161
  // draw type
×
162
  if (boundary.type && boundary.type.text !== '') {
×
163
    boundaryConf = conf.boundaryFont();
×
164
    boundaryConf.fontColor = fontColor;
×
165
    _drawTextCandidateFunc(conf)(
×
166
      boundary.type.text,
×
167
      boundaryElem,
×
168
      boundary.x,
×
169
      boundary.y + boundary.type.Y,
×
170
      boundary.width,
×
171
      boundary.height,
×
172
      { fill: '#444444' },
×
173
      boundaryConf
×
174
    );
×
175
  }
×
176

×
177
  // draw descr
×
178
  if (boundary.descr && boundary.descr.text !== '') {
×
179
    boundaryConf = conf.boundaryFont();
×
180
    boundaryConf.fontSize = boundaryConf.fontSize - 2;
×
181
    boundaryConf.fontColor = fontColor;
×
182
    _drawTextCandidateFunc(conf)(
×
183
      boundary.descr.text,
×
184
      boundaryElem,
×
185
      boundary.x,
×
186
      boundary.y + boundary.descr.Y,
×
187
      boundary.width,
×
188
      boundary.height,
×
189
      { fill: '#444444' },
×
190
      boundaryConf
×
191
    );
×
192
  }
×
193
};
×
194

1✔
195
export const drawC4Shape = function (elem, c4Shape, conf) {
1✔
196
  let fillColor = c4Shape.bgColor ? c4Shape.bgColor : conf[c4Shape.typeC4Shape.text + '_bg_color'];
×
197
  let strokeColor = c4Shape.borderColor
×
198
    ? c4Shape.borderColor
×
199
    : conf[c4Shape.typeC4Shape.text + '_border_color'];
×
200
  let fontColor = c4Shape.fontColor ? c4Shape.fontColor : '#FFFFFF';
×
201

×
202
  let personImg =
×
203
    'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACD0lEQVR4Xu2YoU4EMRCGT+4j8Ai8AhaH4QHgAUjQuFMECUgMIUgwJAgMhgQsAYUiJCiQIBBY+EITsjfTdme6V24v4c8vyGbb+ZjOtN0bNcvjQXmkH83WvYBWto6PLm6v7p7uH1/w2fXD+PBycX1Pv2l3IdDm/vn7x+dXQiAubRzoURa7gRZWd0iGRIiJbOnhnfYBQZNJjNbuyY2eJG8fkDE3bbG4ep6MHUAsgYxmE3nVs6VsBWJSGccsOlFPmLIViMzLOB7pCVO2AtHJMohH7Fh6zqitQK7m0rJvAVYgGcEpe//PLdDz65sM4pF9N7ICcXDKIB5Nv6j7tD0NoSdM2QrU9Gg0ewE1LqBhHR3BBdvj2vapnidjHxD/q6vd7Pvhr31AwcY8eXMTXAKECZZJFXuEq27aLgQK5uLMohCenGGuGewOxSjBvYBqeG6B+Nqiblggdjnc+ZXDy+FNFpFzw76O3UBAROuXh6FoiAcf5g9eTvUgzy0nWg6I8cXHRUpg5bOVBCo+KDpFajOf23GgPme7RSQ+lacIENUgJ6gg1k6HjgOlqnLqip4tEuhv0hNEMXUD0clyXE3p6pZA0S2nnvTlXwLJEZWlb7cTQH1+USgTN4VhAenm/wea1OCAOmqo6fE1WCb9WSKBah+rbUWPWAmE2Rvk0ApiB45eOyNAzU8xcTvj8KvkKEoOaIYeHNA3ZuygAvFMUO0AAAAASUVORK5CYII=';
×
204
  switch (c4Shape.typeC4Shape.text) {
×
205
    case 'person':
×
206
      personImg =
×
207
        'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACD0lEQVR4Xu2YoU4EMRCGT+4j8Ai8AhaH4QHgAUjQuFMECUgMIUgwJAgMhgQsAYUiJCiQIBBY+EITsjfTdme6V24v4c8vyGbb+ZjOtN0bNcvjQXmkH83WvYBWto6PLm6v7p7uH1/w2fXD+PBycX1Pv2l3IdDm/vn7x+dXQiAubRzoURa7gRZWd0iGRIiJbOnhnfYBQZNJjNbuyY2eJG8fkDE3bbG4ep6MHUAsgYxmE3nVs6VsBWJSGccsOlFPmLIViMzLOB7pCVO2AtHJMohH7Fh6zqitQK7m0rJvAVYgGcEpe//PLdDz65sM4pF9N7ICcXDKIB5Nv6j7tD0NoSdM2QrU9Gg0ewE1LqBhHR3BBdvj2vapnidjHxD/q6vd7Pvhr31AwcY8eXMTXAKECZZJFXuEq27aLgQK5uLMohCenGGuGewOxSjBvYBqeG6B+Nqiblggdjnc+ZXDy+FNFpFzw76O3UBAROuXh6FoiAcf5g9eTvUgzy0nWg6I8cXHRUpg5bOVBCo+KDpFajOf23GgPme7RSQ+lacIENUgJ6gg1k6HjgOlqnLqip4tEuhv0hNEMXUD0clyXE3p6pZA0S2nnvTlXwLJEZWlb7cTQH1+USgTN4VhAenm/wea1OCAOmqo6fE1WCb9WSKBah+rbUWPWAmE2Rvk0ApiB45eOyNAzU8xcTvj8KvkKEoOaIYeHNA3ZuygAvFMUO0AAAAASUVORK5CYII=';
×
208
      break;
×
209
    case 'external_person':
×
210
      personImg =
×
211
        'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAAB6ElEQVR4Xu2YLY+EMBCG9+dWr0aj0Wg0Go1Go0+j8Xdv2uTCvv1gpt0ebHKPuhDaeW4605Z9mJvx4AdXUyTUdd08z+u6flmWZRnHsWkafk9DptAwDPu+f0eAYtu2PEaGWuj5fCIZrBAC2eLBAnRCsEkkxmeaJp7iDJ2QMDdHsLg8SxKFEJaAo8lAXnmuOFIhTMpxxKATebo4UiFknuNo4OniSIXQyRxEA3YsnjGCVEjVXD7yLUAqxBGUyPv/Y4W2beMgGuS7kVQIBycH0fD+oi5pezQETxdHKmQKGk1eQEYldK+jw5GxPfZ9z7Mk0Qnhf1W1m3w//EUn5BDmSZsbR44QQLBEqrBHqOrmSKaQAxdnLArCrxZcM7A7ZKs4ioRq8LFC+NpC3WCBJsvpVw5edm9iEXFuyNfxXAgSwfrFQ1c0iNda8AdejvUgnktOtJQQxmcfFzGglc5WVCj7oDgFqU18boeFSs52CUh8LE8BIVQDT1ABrB0HtgSEYlX5doJnCwv9TXocKCaKbnwhdDKPq4lf3SwU3HLq4V/+WYhHVMa/3b4IlfyikAduCkcBc7mQ3/z/Qq/cTuikhkzB12Ae/mcJC9U+Vo8Ej1gWAtgbeGgFsAMHr50BIWOLCbezvhpBFUdY6EJuJ/QDW0XoMX60zZ0AAAAASUVORK5CYII=';
×
212
      break;
×
213
  }
×
214

×
215
  const c4ShapeElem = elem.append('g');
×
216
  c4ShapeElem.attr('class', 'person-man');
×
217

×
218
  // <rect fill="#08427B" height="119.2188" rx="2.5" ry="2.5" stroke="#073B6F" stroke-width="0.5" width="110" x="120" y="7"/>
×
219
  // draw rect of c4Shape
×
220
  const rect = svgDrawCommon.getNoteRect();
×
221

×
222
  switch (c4Shape.typeC4Shape.text) {
×
223
    case 'person':
×
224
    case 'external_person':
×
225
    case 'system':
×
226
    case 'external_system':
×
227
    case 'container':
×
228
    case 'external_container':
×
229
    case 'component':
×
230
    case 'external_component':
×
231
      rect.x = c4Shape.x;
×
232
      rect.y = c4Shape.y;
×
233
      rect.fill = fillColor;
×
234
      rect.width = c4Shape.width;
×
235
      rect.height = c4Shape.height;
×
236
      rect.stroke = strokeColor;
×
237
      rect.rx = 2.5;
×
238
      rect.ry = 2.5;
×
239
      rect.attrs = { 'stroke-width': 0.5 };
×
240
      drawRect(c4ShapeElem, rect);
×
241
      break;
×
242
    case 'system_db':
×
243
    case 'external_system_db':
×
244
    case 'container_db':
×
245
    case 'external_container_db':
×
246
    case 'component_db':
×
247
    case 'external_component_db':
×
248
      c4ShapeElem
×
249
        .append('path')
×
250
        .attr('fill', fillColor)
×
251
        .attr('stroke-width', '0.5')
×
252
        .attr('stroke', strokeColor)
×
253
        .attr(
×
254
          'd',
×
255
          'Mstartx,startyc0,-10 half,-10 half,-10c0,0 half,0 half,10l0,heightc0,10 -half,10 -half,10c0,0 -half,0 -half,-10l0,-height'
×
256
            .replaceAll('startx', c4Shape.x)
×
257
            .replaceAll('starty', c4Shape.y)
×
258
            .replaceAll('half', c4Shape.width / 2)
×
259
            .replaceAll('height', c4Shape.height)
×
260
        );
×
261
      c4ShapeElem
×
262
        .append('path')
×
263
        .attr('fill', 'none')
×
264
        .attr('stroke-width', '0.5')
×
265
        .attr('stroke', strokeColor)
×
266
        .attr(
×
267
          'd',
×
268
          'Mstartx,startyc0,10 half,10 half,10c0,0 half,0 half,-10'
×
269
            .replaceAll('startx', c4Shape.x)
×
270
            .replaceAll('starty', c4Shape.y)
×
271
            .replaceAll('half', c4Shape.width / 2)
×
272
        );
×
273
      break;
×
274
    case 'system_queue':
×
275
    case 'external_system_queue':
×
276
    case 'container_queue':
×
277
    case 'external_container_queue':
×
278
    case 'component_queue':
×
279
    case 'external_component_queue':
×
280
      c4ShapeElem
×
281
        .append('path')
×
282
        .attr('fill', fillColor)
×
283
        .attr('stroke-width', '0.5')
×
284
        .attr('stroke', strokeColor)
×
285
        .attr(
×
286
          'd',
×
287
          'Mstartx,startylwidth,0c5,0 5,half 5,halfc0,0 0,half -5,halfl-width,0c-5,0 -5,-half -5,-halfc0,0 0,-half 5,-half'
×
288
            .replaceAll('startx', c4Shape.x)
×
289
            .replaceAll('starty', c4Shape.y)
×
290
            .replaceAll('width', c4Shape.width)
×
291
            .replaceAll('half', c4Shape.height / 2)
×
292
        );
×
293
      c4ShapeElem
×
294
        .append('path')
×
295
        .attr('fill', 'none')
×
296
        .attr('stroke-width', '0.5')
×
297
        .attr('stroke', strokeColor)
×
298
        .attr(
×
299
          'd',
×
300
          'Mstartx,startyc-5,0 -5,half -5,halfc0,half 5,half 5,half'
×
301
            .replaceAll('startx', c4Shape.x + c4Shape.width)
×
302
            .replaceAll('starty', c4Shape.y)
×
303
            .replaceAll('half', c4Shape.height / 2)
×
304
        );
×
305
      break;
×
306
  }
×
307

×
308
  // draw type of c4Shape
×
309
  let c4ShapeFontConf = getC4ShapeFont(conf, c4Shape.typeC4Shape.text);
×
310
  c4ShapeElem
×
311
    .append('text')
×
312
    .attr('fill', fontColor)
×
313
    .attr('font-family', c4ShapeFontConf.fontFamily)
×
314
    .attr('font-size', c4ShapeFontConf.fontSize - 2)
×
315
    .attr('font-style', 'italic')
×
316
    .attr('lengthAdjust', 'spacing')
×
317
    .attr('textLength', c4Shape.typeC4Shape.width)
×
318
    .attr('x', c4Shape.x + c4Shape.width / 2 - c4Shape.typeC4Shape.width / 2)
×
319
    .attr('y', c4Shape.y + c4Shape.typeC4Shape.Y)
×
320
    .text('<<' + c4Shape.typeC4Shape.text + '>>');
×
321

×
322
  // draw image/sprite
×
323
  switch (c4Shape.typeC4Shape.text) {
×
324
    case 'person':
×
325
    case 'external_person':
×
326
      drawImage(
×
327
        c4ShapeElem,
×
328
        48,
×
329
        48,
×
330
        c4Shape.x + c4Shape.width / 2 - 24,
×
331
        c4Shape.y + c4Shape.image.Y,
×
332
        personImg
×
333
      );
×
334
      break;
×
335
  }
×
336

×
337
  // draw label
×
338
  let textFontConf = conf[c4Shape.typeC4Shape.text + 'Font']();
×
339
  textFontConf.fontWeight = 'bold';
×
340
  textFontConf.fontSize = textFontConf.fontSize + 2;
×
341
  textFontConf.fontColor = fontColor;
×
342
  _drawTextCandidateFunc(conf)(
×
343
    c4Shape.label.text,
×
344
    c4ShapeElem,
×
345
    c4Shape.x,
×
346
    c4Shape.y + c4Shape.label.Y,
×
347
    c4Shape.width,
×
348
    c4Shape.height,
×
349
    { fill: fontColor },
×
350
    textFontConf
×
351
  );
×
352

×
353
  // draw techn/type
×
354
  textFontConf = conf[c4Shape.typeC4Shape.text + 'Font']();
×
355
  textFontConf.fontColor = fontColor;
×
356

×
357
  if (c4Shape.techn && c4Shape.techn?.text !== '') {
×
358
    _drawTextCandidateFunc(conf)(
×
359
      c4Shape.techn.text,
×
360
      c4ShapeElem,
×
361
      c4Shape.x,
×
362
      c4Shape.y + c4Shape.techn.Y,
×
363
      c4Shape.width,
×
364
      c4Shape.height,
×
365
      { fill: fontColor, 'font-style': 'italic' },
×
366
      textFontConf
×
367
    );
×
368
  } else if (c4Shape.type && c4Shape.type.text !== '') {
×
369
    _drawTextCandidateFunc(conf)(
×
370
      c4Shape.type.text,
×
371
      c4ShapeElem,
×
372
      c4Shape.x,
×
373
      c4Shape.y + c4Shape.type.Y,
×
374
      c4Shape.width,
×
375
      c4Shape.height,
×
376
      { fill: fontColor, 'font-style': 'italic' },
×
377
      textFontConf
×
378
    );
×
379
  }
×
380

×
381
  // draw descr
×
382
  if (c4Shape.descr && c4Shape.descr.text !== '') {
×
383
    textFontConf = conf.personFont();
×
384
    textFontConf.fontColor = fontColor;
×
385
    _drawTextCandidateFunc(conf)(
×
386
      c4Shape.descr.text,
×
387
      c4ShapeElem,
×
388
      c4Shape.x,
×
389
      c4Shape.y + c4Shape.descr.Y,
×
390
      c4Shape.width,
×
391
      c4Shape.height,
×
392
      { fill: fontColor },
×
393
      textFontConf
×
394
    );
×
395
  }
×
396

×
397
  return c4Shape.height;
×
398
};
×
399

1✔
400
export const insertDatabaseIcon = function (elem) {
1✔
401
  elem
×
402
    .append('defs')
×
403
    .append('symbol')
×
404
    .attr('id', 'database')
×
405
    .attr('fill-rule', 'evenodd')
×
406
    .attr('clip-rule', 'evenodd')
×
407
    .append('path')
×
408
    .attr('transform', 'scale(.5)')
×
409
    .attr(
×
410
      'd',
×
411
      'M12.258.001l.256.004.255.005.253.008.251.01.249.012.247.015.246.016.242.019.241.02.239.023.236.024.233.027.231.028.229.031.225.032.223.034.22.036.217.038.214.04.211.041.208.043.205.045.201.046.198.048.194.05.191.051.187.053.183.054.18.056.175.057.172.059.168.06.163.061.16.063.155.064.15.066.074.033.073.033.071.034.07.034.069.035.068.035.067.035.066.035.064.036.064.036.062.036.06.036.06.037.058.037.058.037.055.038.055.038.053.038.052.038.051.039.05.039.048.039.047.039.045.04.044.04.043.04.041.04.04.041.039.041.037.041.036.041.034.041.033.042.032.042.03.042.029.042.027.042.026.043.024.043.023.043.021.043.02.043.018.044.017.043.015.044.013.044.012.044.011.045.009.044.007.045.006.045.004.045.002.045.001.045v17l-.001.045-.002.045-.004.045-.006.045-.007.045-.009.044-.011.045-.012.044-.013.044-.015.044-.017.043-.018.044-.02.043-.021.043-.023.043-.024.043-.026.043-.027.042-.029.042-.03.042-.032.042-.033.042-.034.041-.036.041-.037.041-.039.041-.04.041-.041.04-.043.04-.044.04-.045.04-.047.039-.048.039-.05.039-.051.039-.052.038-.053.038-.055.038-.055.038-.058.037-.058.037-.06.037-.06.036-.062.036-.064.036-.064.036-.066.035-.067.035-.068.035-.069.035-.07.034-.071.034-.073.033-.074.033-.15.066-.155.064-.16.063-.163.061-.168.06-.172.059-.175.057-.18.056-.183.054-.187.053-.191.051-.194.05-.198.048-.201.046-.205.045-.208.043-.211.041-.214.04-.217.038-.22.036-.223.034-.225.032-.229.031-.231.028-.233.027-.236.024-.239.023-.241.02-.242.019-.246.016-.247.015-.249.012-.251.01-.253.008-.255.005-.256.004-.258.001-.258-.001-.256-.004-.255-.005-.253-.008-.251-.01-.249-.012-.247-.015-.245-.016-.243-.019-.241-.02-.238-.023-.236-.024-.234-.027-.231-.028-.228-.031-.226-.032-.223-.034-.22-.036-.217-.038-.214-.04-.211-.041-.208-.043-.204-.045-.201-.046-.198-.048-.195-.05-.19-.051-.187-.053-.184-.054-.179-.056-.176-.057-.172-.059-.167-.06-.164-.061-.159-.063-.155-.064-.151-.066-.074-.033-.072-.033-.072-.034-.07-.034-.069-.035-.068-.035-.067-.035-.066-.035-.064-.036-.063-.036-.062-.036-.061-.036-.06-.037-.058-.037-.057-.037-.056-.038-.055-.038-.053-.038-.052-.038-.051-.039-.049-.039-.049-.039-.046-.039-.046-.04-.044-.04-.043-.04-.041-.04-.04-.041-.039-.041-.037-.041-.036-.041-.034-.041-.033-.042-.032-.042-.03-.042-.029-.042-.027-.042-.026-.043-.024-.043-.023-.043-.021-.043-.02-.043-.018-.044-.017-.043-.015-.044-.013-.044-.012-.044-.011-.045-.009-.044-.007-.045-.006-.045-.004-.045-.002-.045-.001-.045v-17l.001-.045.002-.045.004-.045.006-.045.007-.045.009-.044.011-.045.012-.044.013-.044.015-.044.017-.043.018-.044.02-.043.021-.043.023-.043.024-.043.026-.043.027-.042.029-.042.03-.042.032-.042.033-.042.034-.041.036-.041.037-.041.039-.041.04-.041.041-.04.043-.04.044-.04.046-.04.046-.039.049-.039.049-.039.051-.039.052-.038.053-.038.055-.038.056-.038.057-.037.058-.037.06-.037.061-.036.062-.036.063-.036.064-.036.066-.035.067-.035.068-.035.069-.035.07-.034.072-.034.072-.033.074-.033.151-.066.155-.064.159-.063.164-.061.167-.06.172-.059.176-.057.179-.056.184-.054.187-.053.19-.051.195-.05.198-.048.201-.046.204-.045.208-.043.211-.041.214-.04.217-.038.22-.036.223-.034.226-.032.228-.031.231-.028.234-.027.236-.024.238-.023.241-.02.243-.019.245-.016.247-.015.249-.012.251-.01.253-.008.255-.005.256-.004.258-.001.258.001zm-9.258 20.499v.01l.001.021.003.021.004.022.005.021.006.022.007.022.009.023.01.022.011.023.012.023.013.023.015.023.016.024.017.023.018.024.019.024.021.024.022.025.023.024.024.025.052.049.056.05.061.051.066.051.07.051.075.051.079.052.084.052.088.052.092.052.097.052.102.051.105.052.11.052.114.051.119.051.123.051.127.05.131.05.135.05.139.048.144.049.147.047.152.047.155.047.16.045.163.045.167.043.171.043.176.041.178.041.183.039.187.039.19.037.194.035.197.035.202.033.204.031.209.03.212.029.216.027.219.025.222.024.226.021.23.02.233.018.236.016.24.015.243.012.246.01.249.008.253.005.256.004.259.001.26-.001.257-.004.254-.005.25-.008.247-.011.244-.012.241-.014.237-.016.233-.018.231-.021.226-.021.224-.024.22-.026.216-.027.212-.028.21-.031.205-.031.202-.034.198-.034.194-.036.191-.037.187-.039.183-.04.179-.04.175-.042.172-.043.168-.044.163-.045.16-.046.155-.046.152-.047.148-.048.143-.049.139-.049.136-.05.131-.05.126-.05.123-.051.118-.052.114-.051.11-.052.106-.052.101-.052.096-.052.092-.052.088-.053.083-.051.079-.052.074-.052.07-.051.065-.051.06-.051.056-.05.051-.05.023-.024.023-.025.021-.024.02-.024.019-.024.018-.024.017-.024.015-.023.014-.024.013-.023.012-.023.01-.023.01-.022.008-.022.006-.022.006-.022.004-.022.004-.021.001-.021.001-.021v-4.127l-.077.055-.08.053-.083.054-.085.053-.087.052-.09.052-.093.051-.095.05-.097.05-.1.049-.102.049-.105.048-.106.047-.109.047-.111.046-.114.045-.115.045-.118.044-.12.043-.122.042-.124.042-.126.041-.128.04-.13.04-.132.038-.134.038-.135.037-.138.037-.139.035-.142.035-.143.034-.144.033-.147.032-.148.031-.15.03-.151.03-.153.029-.154.027-.156.027-.158.026-.159.025-.161.024-.162.023-.163.022-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.011-.178.01-.179.008-.179.008-.181.006-.182.005-.182.004-.184.003-.184.002h-.37l-.184-.002-.184-.003-.182-.004-.182-.005-.181-.006-.179-.008-.179-.008-.178-.01-.176-.011-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.022-.162-.023-.161-.024-.159-.025-.157-.026-.156-.027-.155-.027-.153-.029-.151-.03-.15-.03-.148-.031-.146-.032-.145-.033-.143-.034-.141-.035-.14-.035-.137-.037-.136-.037-.134-.038-.132-.038-.13-.04-.128-.04-.126-.041-.124-.042-.122-.042-.12-.044-.117-.043-.116-.045-.113-.045-.112-.046-.109-.047-.106-.047-.105-.048-.102-.049-.1-.049-.097-.05-.095-.05-.093-.052-.09-.051-.087-.052-.085-.053-.083-.054-.08-.054-.077-.054v4.127zm0-5.654v.011l.001.021.003.021.004.021.005.022.006.022.007.022.009.022.01.022.011.023.012.023.013.023.015.024.016.023.017.024.018.024.019.024.021.024.022.024.023.025.024.024.052.05.056.05.061.05.066.051.07.051.075.052.079.051.084.052.088.052.092.052.097.052.102.052.105.052.11.051.114.051.119.052.123.05.127.051.131.05.135.049.139.049.144.048.147.048.152.047.155.046.16.045.163.045.167.044.171.042.176.042.178.04.183.04.187.038.19.037.194.036.197.034.202.033.204.032.209.03.212.028.216.027.219.025.222.024.226.022.23.02.233.018.236.016.24.014.243.012.246.01.249.008.253.006.256.003.259.001.26-.001.257-.003.254-.006.25-.008.247-.01.244-.012.241-.015.237-.016.233-.018.231-.02.226-.022.224-.024.22-.025.216-.027.212-.029.21-.03.205-.032.202-.033.198-.035.194-.036.191-.037.187-.039.183-.039.179-.041.175-.042.172-.043.168-.044.163-.045.16-.045.155-.047.152-.047.148-.048.143-.048.139-.05.136-.049.131-.05.126-.051.123-.051.118-.051.114-.052.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.051.07-.052.065-.051.06-.05.056-.051.051-.049.023-.025.023-.024.021-.025.02-.024.019-.024.018-.024.017-.024.015-.023.014-.023.013-.024.012-.022.01-.023.01-.023.008-.022.006-.022.006-.022.004-.021.004-.022.001-.021.001-.021v-4.139l-.077.054-.08.054-.083.054-.085.052-.087.053-.09.051-.093.051-.095.051-.097.05-.1.049-.102.049-.105.048-.106.047-.109.047-.111.046-.114.045-.115.044-.118.044-.12.044-.122.042-.124.042-.126.041-.128.04-.13.039-.132.039-.134.038-.135.037-.138.036-.139.036-.142.035-.143.033-.144.033-.147.033-.148.031-.15.03-.151.03-.153.028-.154.028-.156.027-.158.026-.159.025-.161.024-.162.023-.163.022-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.011-.178.009-.179.009-.179.007-.181.007-.182.005-.182.004-.184.003-.184.002h-.37l-.184-.002-.184-.003-.182-.004-.182-.005-.181-.007-.179-.007-.179-.009-.178-.009-.176-.011-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.022-.162-.023-.161-.024-.159-.025-.157-.026-.156-.027-.155-.028-.153-.028-.151-.03-.15-.03-.148-.031-.146-.033-.145-.033-.143-.033-.141-.035-.14-.036-.137-.036-.136-.037-.134-.038-.132-.039-.13-.039-.128-.04-.126-.041-.124-.042-.122-.043-.12-.043-.117-.044-.116-.044-.113-.046-.112-.046-.109-.046-.106-.047-.105-.048-.102-.049-.1-.049-.097-.05-.095-.051-.093-.051-.09-.051-.087-.053-.085-.052-.083-.054-.08-.054-.077-.054v4.139zm0-5.666v.011l.001.02.003.022.004.021.005.022.006.021.007.022.009.023.01.022.011.023.012.023.013.023.015.023.016.024.017.024.018.023.019.024.021.025.022.024.023.024.024.025.052.05.056.05.061.05.066.051.07.051.075.052.079.051.084.052.088.052.092.052.097.052.102.052.105.051.11.052.114.051.119.051.123.051.127.05.131.05.135.05.139.049.144.048.147.048.152.047.155.046.16.045.163.045.167.043.171.043.176.042.178.04.183.04.187.038.19.037.194.036.197.034.202.033.204.032.209.03.212.028.216.027.219.025.222.024.226.021.23.02.233.018.236.017.24.014.243.012.246.01.249.008.253.006.256.003.259.001.26-.001.257-.003.254-.006.25-.008.247-.01.244-.013.241-.014.237-.016.233-.018.231-.02.226-.022.224-.024.22-.025.216-.027.212-.029.21-.03.205-.032.202-.033.198-.035.194-.036.191-.037.187-.039.183-.039.179-.041.175-.042.172-.043.168-.044.163-.045.16-.045.155-.047.152-.047.148-.048.143-.049.139-.049.136-.049.131-.051.126-.05.123-.051.118-.052.114-.051.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.052.07-.051.065-.051.06-.051.056-.05.051-.049.023-.025.023-.025.021-.024.02-.024.019-.024.018-.024.017-.024.015-.023.014-.024.013-.023.012-.023.01-.022.01-.023.008-.022.006-.022.006-.022.004-.022.004-.021.001-.021.001-.021v-4.153l-.077.054-.08.054-.083.053-.085.053-.087.053-.09.051-.093.051-.095.051-.097.05-.1.049-.102.048-.105.048-.106.048-.109.046-.111.046-.114.046-.115.044-.118.044-.12.043-.122.043-.124.042-.126.041-.128.04-.13.039-.132.039-.134.038-.135.037-.138.036-.139.036-.142.034-.143.034-.144.033-.147.032-.148.032-.15.03-.151.03-.153.028-.154.028-.156.027-.158.026-.159.024-.161.024-.162.023-.163.023-.165.021-.166.02-.167.019-.169.018-.169.017-.171.016-.173.015-.173.014-.175.013-.175.012-.177.01-.178.01-.179.009-.179.007-.181.006-.182.006-.182.004-.184.003-.184.001-.185.001-.185-.001-.184-.001-.184-.003-.182-.004-.182-.006-.181-.006-.179-.007-.179-.009-.178-.01-.176-.01-.176-.012-.175-.013-.173-.014-.172-.015-.171-.016-.17-.017-.169-.018-.167-.019-.166-.02-.165-.021-.163-.023-.162-.023-.161-.024-.159-.024-.157-.026-.156-.027-.155-.028-.153-.028-.151-.03-.15-.03-.148-.032-.146-.032-.145-.033-.143-.034-.141-.034-.14-.036-.137-.036-.136-.037-.134-.038-.132-.039-.13-.039-.128-.041-.126-.041-.124-.041-.122-.043-.12-.043-.117-.044-.116-.044-.113-.046-.112-.046-.109-.046-.106-.048-.105-.048-.102-.048-.1-.05-.097-.049-.095-.051-.093-.051-.09-.052-.087-.052-.085-.053-.083-.053-.08-.054-.077-.054v4.153zm8.74-8.179l-.257.004-.254.005-.25.008-.247.011-.244.012-.241.014-.237.016-.233.018-.231.021-.226.022-.224.023-.22.026-.216.027-.212.028-.21.031-.205.032-.202.033-.198.034-.194.036-.191.038-.187.038-.183.04-.179.041-.175.042-.172.043-.168.043-.163.045-.16.046-.155.046-.152.048-.148.048-.143.048-.139.049-.136.05-.131.05-.126.051-.123.051-.118.051-.114.052-.11.052-.106.052-.101.052-.096.052-.092.052-.088.052-.083.052-.079.052-.074.051-.07.052-.065.051-.06.05-.056.05-.051.05-.023.025-.023.024-.021.024-.02.025-.019.024-.018.024-.017.023-.015.024-.014.023-.013.023-.012.023-.01.023-.01.022-.008.022-.006.023-.006.021-.004.022-.004.021-.001.021-.001.021.001.021.001.021.004.021.004.022.006.021.006.023.008.022.01.022.01.023.012.023.013.023.014.023.015.024.017.023.018.024.019.024.02.025.021.024.023.024.023.025.051.05.056.05.06.05.065.051.07.052.074.051.079.052.083.052.088.052.092.052.096.052.101.052.106.052.11.052.114.052.118.051.123.051.126.051.131.05.136.05.139.049.143.048.148.048.152.048.155.046.16.046.163.045.168.043.172.043.175.042.179.041.183.04.187.038.191.038.194.036.198.034.202.033.205.032.21.031.212.028.216.027.22.026.224.023.226.022.231.021.233.018.237.016.241.014.244.012.247.011.25.008.254.005.257.004.26.001.26-.001.257-.004.254-.005.25-.008.247-.011.244-.012.241-.014.237-.016.233-.018.231-.021.226-.022.224-.023.22-.026.216-.027.212-.028.21-.031.205-.032.202-.033.198-.034.194-.036.191-.038.187-.038.183-.04.179-.041.175-.042.172-.043.168-.043.163-.045.16-.046.155-.046.152-.048.148-.048.143-.048.139-.049.136-.05.131-.05.126-.051.123-.051.118-.051.114-.052.11-.052.106-.052.101-.052.096-.052.092-.052.088-.052.083-.052.079-.052.074-.051.07-.052.065-.051.06-.05.056-.05.051-.05.023-.025.023-.024.021-.024.02-.025.019-.024.018-.024.017-.023.015-.024.014-.023.013-.023.012-.023.01-.023.01-.022.008-.022.006-.023.006-.021.004-.022.004-.021.001-.021.001-.021-.001-.021-.001-.021-.004-.021-.004-.022-.006-.021-.006-.023-.008-.022-.01-.022-.01-.023-.012-.023-.013-.023-.014-.023-.015-.024-.017-.023-.018-.024-.019-.024-.02-.025-.021-.024-.023-.024-.023-.025-.051-.05-.056-.05-.06-.05-.065-.051-.07-.052-.074-.051-.079-.052-.083-.052-.088-.052-.092-.052-.096-.052-.101-.052-.106-.052-.11-.052-.114-.052-.118-.051-.123-.051-.126-.051-.131-.05-.136-.05-.139-.049-.143-.048-.148-.048-.152-.048-.155-.046-.16-.046-.163-.045-.168-.043-.172-.043-.175-.042-.179-.041-.183-.04-.187-.038-.191-.038-.194-.036-.198-.034-.202-.033-.205-.032-.21-.031-.212-.028-.216-.027-.22-.026-.224-.023-.226-.022-.231-.021-.233-.018-.237-.016-.241-.014-.244-.012-.247-.011-.25-.008-.254-.005-.257-.004-.26-.001-.26.001z'
×
412
    );
×
413
};
×
414

1✔
415
export const insertComputerIcon = function (elem) {
1✔
416
  elem
×
417
    .append('defs')
×
418
    .append('symbol')
×
419
    .attr('id', 'computer')
×
420
    .attr('width', '24')
×
421
    .attr('height', '24')
×
422
    .append('path')
×
423
    .attr('transform', 'scale(.5)')
×
424
    .attr(
×
425
      'd',
×
426
      'M2 2v13h20v-13h-20zm18 11h-16v-9h16v9zm-10.228 6l.466-1h3.524l.467 1h-4.457zm14.228 3h-24l2-6h2.104l-1.33 4h18.45l-1.297-4h2.073l2 6zm-5-10h-14v-7h14v7z'
×
427
    );
×
428
};
×
429

1✔
430
export const insertClockIcon = function (elem) {
1✔
431
  elem
×
432
    .append('defs')
×
433
    .append('symbol')
×
434
    .attr('id', 'clock')
×
435
    .attr('width', '24')
×
436
    .attr('height', '24')
×
437
    .append('path')
×
438
    .attr('transform', 'scale(.5)')
×
439
    .attr(
×
440
      'd',
×
441
      'M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm5.848 12.459c.202.038.202.333.001.372-1.907.361-6.045 1.111-6.547 1.111-.719 0-1.301-.582-1.301-1.301 0-.512.77-5.447 1.125-7.445.034-.192.312-.181.343.014l.985 6.238 5.394 1.011z'
×
442
    );
×
443
};
×
444

1✔
445
/**
1✔
446
 * Setup arrow head and define the marker. The result is appended to the svg.
1✔
447
 *
1✔
448
 * @param elem
1✔
449
 */
1✔
450
export const insertArrowHead = function (elem) {
1✔
451
  elem
×
452
    .append('defs')
×
453
    .append('marker')
×
454
    .attr('id', 'arrowhead')
×
455
    .attr('refX', 9)
×
456
    .attr('refY', 5)
×
457
    .attr('markerUnits', 'userSpaceOnUse')
×
458
    .attr('markerWidth', 12)
×
459
    .attr('markerHeight', 12)
×
460
    .attr('orient', 'auto')
×
461
    .append('path')
×
462
    .attr('d', 'M 0 0 L 10 5 L 0 10 z'); // this is actual shape for arrowhead
×
463
};
×
464

1✔
465
export const insertArrowEnd = function (elem) {
1✔
466
  elem
×
467
    .append('defs')
×
468
    .append('marker')
×
469
    .attr('id', 'arrowend')
×
470
    .attr('refX', 1)
×
471
    .attr('refY', 5)
×
472
    .attr('markerUnits', 'userSpaceOnUse')
×
473
    .attr('markerWidth', 12)
×
474
    .attr('markerHeight', 12)
×
475
    .attr('orient', 'auto')
×
476
    .append('path')
×
477
    .attr('d', 'M 10 0 L 0 5 L 10 10 z'); // this is actual shape for arrowhead
×
478
};
×
479

1✔
480
/**
1✔
481
 * Setup arrow head and define the marker. The result is appended to the svg.
1✔
482
 *
1✔
483
 * @param {any} elem
1✔
484
 */
1✔
485
export const insertArrowFilledHead = function (elem) {
1✔
486
  elem
×
487
    .append('defs')
×
488
    .append('marker')
×
489
    .attr('id', 'filled-head')
×
490
    .attr('refX', 18)
×
491
    .attr('refY', 7)
×
492
    .attr('markerWidth', 20)
×
493
    .attr('markerHeight', 28)
×
494
    .attr('orient', 'auto')
×
495
    .append('path')
×
496
    .attr('d', 'M 18,7 L9,13 L14,7 L9,1 Z');
×
497
};
×
498

1✔
499
/**
1✔
500
 * Setup node number. The result is appended to the svg.
1✔
501
 *
1✔
502
 * @param {any} elem
1✔
503
 */
1✔
504
export const insertDynamicNumber = function (elem) {
1✔
505
  elem
×
506
    .append('defs')
×
507
    .append('marker')
×
508
    .attr('id', 'sequencenumber')
×
509
    .attr('refX', 15)
×
510
    .attr('refY', 15)
×
511
    .attr('markerWidth', 60)
×
512
    .attr('markerHeight', 40)
×
513
    .attr('orient', 'auto')
×
514
    .append('circle')
×
515
    .attr('cx', 15)
×
516
    .attr('cy', 15)
×
517
    .attr('r', 6);
×
518
  // .style("fill", '#f00');
×
519
};
×
520

1✔
521
/**
1✔
522
 * Setup arrow head and define the marker. The result is appended to the svg.
1✔
523
 *
1✔
524
 * @param {any} elem
1✔
525
 */
1✔
526
export const insertArrowCrossHead = function (elem) {
1✔
527
  const defs = elem.append('defs');
×
528
  const marker = defs
×
529
    .append('marker')
×
530
    .attr('id', 'crosshead')
×
531
    .attr('markerWidth', 15)
×
532
    .attr('markerHeight', 8)
×
533
    .attr('orient', 'auto')
×
534
    .attr('refX', 16)
×
535
    .attr('refY', 4);
×
536

×
537
  // The arrow
×
538
  marker
×
539
    .append('path')
×
540
    .attr('fill', 'black')
×
541
    .attr('stroke', '#000000')
×
542
    .style('stroke-dasharray', '0, 0')
×
543
    .attr('stroke-width', '1px')
×
544
    .attr('d', 'M 9,2 V 6 L16,4 Z');
×
545

×
546
  // The cross
×
547
  marker
×
548
    .append('path')
×
549
    .attr('fill', 'none')
×
550
    .attr('stroke', '#000000')
×
551
    .style('stroke-dasharray', '0, 0')
×
552
    .attr('stroke-width', '1px')
×
553
    .attr('d', 'M 0,1 L 6,7 M 6,1 L 0,7');
×
554
  // this is actual shape for arrowhead
×
555
};
×
556

1✔
557
const getC4ShapeFont = (cnf, typeC4Shape) => {
1✔
558
  return {
×
559
    fontFamily: cnf[typeC4Shape + 'FontFamily'],
×
560
    fontSize: cnf[typeC4Shape + 'FontSize'],
×
561
    fontWeight: cnf[typeC4Shape + 'FontWeight'],
×
562
  };
×
563
};
×
564

1✔
565
const _drawTextCandidateFunc = (function () {
1✔
566
  /**
2✔
567
   * @param {any} content
2✔
568
   * @param {any} g
2✔
569
   * @param {any} x
2✔
570
   * @param {any} y
2✔
571
   * @param {any} width
2✔
572
   * @param {any} height
2✔
573
   * @param {any} textAttrs
2✔
574
   */
2✔
575
  function byText(content, g, x, y, width, height, textAttrs) {
2✔
576
    const text = g
×
577
      .append('text')
×
578
      .attr('x', x + width / 2)
×
579
      .attr('y', y + height / 2 + 5)
×
580
      .style('text-anchor', 'middle')
×
581
      .text(content);
×
582
    _setTextAttrs(text, textAttrs);
×
583
  }
×
584

2✔
585
  /**
2✔
586
   * @param {any} content
2✔
587
   * @param {any} g
2✔
588
   * @param {any} x
2✔
589
   * @param {any} y
2✔
590
   * @param {any} width
2✔
591
   * @param {any} height
2✔
592
   * @param {any} textAttrs
2✔
593
   * @param {any} conf
2✔
594
   */
2✔
595
  function byTspan(content, g, x, y, width, height, textAttrs, conf) {
2✔
596
    const { fontSize, fontFamily, fontWeight } = conf;
×
597

×
598
    const lines = content.split(common.lineBreakRegex);
×
599
    for (let i = 0; i < lines.length; i++) {
×
600
      const dy = i * fontSize - (fontSize * (lines.length - 1)) / 2;
×
601
      const text = g
×
602
        .append('text')
×
603
        .attr('x', x + width / 2)
×
604
        .attr('y', y)
×
605
        .style('text-anchor', 'middle')
×
606
        .attr('dominant-baseline', 'middle')
×
607
        .style('font-size', fontSize)
×
608
        .style('font-weight', fontWeight)
×
609
        .style('font-family', fontFamily);
×
610
      text
×
611
        .append('tspan')
×
612
        // .attr('x', x + width / 2)
×
613
        .attr('dy', dy)
×
614
        .text(lines[i])
×
615
        // .attr('y', y + height / 2)
×
616
        .attr('alignment-baseline', 'mathematical');
×
617

×
618
      _setTextAttrs(text, textAttrs);
×
619
    }
×
620
  }
×
621

2✔
622
  /**
2✔
623
   * @param {any} content
2✔
624
   * @param {any} g
2✔
625
   * @param {any} x
2✔
626
   * @param {any} y
2✔
627
   * @param {any} width
2✔
628
   * @param {any} height
2✔
629
   * @param {any} textAttrs
2✔
630
   * @param {any} conf
2✔
631
   */
2✔
632
  function byFo(content, g, x, y, width, height, textAttrs, conf) {
2✔
633
    const s = g.append('switch');
×
634
    const f = s
×
635
      .append('foreignObject')
×
636
      .attr('x', x)
×
637
      .attr('y', y)
×
638
      .attr('width', width)
×
639
      .attr('height', height);
×
640

×
641
    const text = f
×
642
      .append('xhtml:div')
×
643
      .style('display', 'table')
×
644
      .style('height', '100%')
×
645
      .style('width', '100%');
×
646

×
647
    text
×
648
      .append('div')
×
649
      .style('display', 'table-cell')
×
650
      .style('text-align', 'center')
×
651
      .style('vertical-align', 'middle')
×
652
      .text(content);
×
653

×
654
    byTspan(content, s, x, y, width, height, textAttrs, conf);
×
655
    _setTextAttrs(text, textAttrs);
×
656
  }
×
657

2✔
658
  /**
2✔
659
   * @param {any} toText
2✔
660
   * @param {any} fromTextAttrsDict
2✔
661
   */
2✔
662
  function _setTextAttrs(toText, fromTextAttrsDict) {
2✔
663
    for (const key in fromTextAttrsDict) {
×
664
      if (fromTextAttrsDict.hasOwnProperty(key)) {
×
665
        toText.attr(key, fromTextAttrsDict[key]);
×
666
      }
×
667
    }
×
668
  }
×
669

2✔
670
  return function (conf) {
2✔
671
    return conf.textPlacement === 'fo' ? byFo : conf.textPlacement === 'old' ? byText : byTspan;
×
672
  };
2✔
673
})();
1✔
674

1✔
675
export default {
1✔
676
  drawRect,
1✔
677
  drawBoundary,
1✔
678
  drawC4Shape,
1✔
679
  drawRels,
1✔
680
  drawImage,
1✔
681
  insertArrowHead,
1✔
682
  insertArrowEnd,
1✔
683
  insertArrowFilledHead,
1✔
684
  insertDynamicNumber,
1✔
685
  insertArrowCrossHead,
1✔
686
  insertDatabaseIcon,
1✔
687
  insertComputerIcon,
1✔
688
  insertClockIcon,
1✔
689
};
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc