• 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

69.75
/packages/mermaid/src/diagrams/common/svgDrawCommon.js
1
import { sanitizeUrl } from '@braintree/sanitize-url';
1✔
2

1✔
3
export const drawRect = function (elem, rectData) {
1✔
4
  const rectElem = elem.append('rect');
83✔
5
  rectElem.attr('x', rectData.x);
83✔
6
  rectElem.attr('y', rectData.y);
83✔
7
  rectElem.attr('fill', rectData.fill);
83✔
8
  rectElem.attr('stroke', rectData.stroke);
83✔
9
  rectElem.attr('width', rectData.width);
83✔
10
  rectElem.attr('height', rectData.height);
83✔
11
  rectElem.attr('rx', rectData.rx);
83✔
12
  rectElem.attr('ry', rectData.ry);
83✔
13

83✔
14
  if (rectData.attrs !== 'undefined' && rectData.attrs !== null) {
83✔
15
    for (let attrKey in rectData.attrs) {
83!
16
      rectElem.attr(attrKey, rectData.attrs[attrKey]);
×
17
    }
×
18
  }
×
19

83✔
20
  if (rectData.class !== 'undefined') {
83✔
21
    rectElem.attr('class', rectData.class);
83✔
22
  }
83✔
23

83✔
24
  return rectElem;
83✔
25
};
83✔
26

1✔
27
/**
1✔
28
 * Draws a background rectangle
1✔
29
 *
1✔
30
 * @param {any} elem Diagram (reference for bounds)
1✔
31
 * @param {any} bounds Shape of the rectangle
1✔
32
 */
1✔
33
export const drawBackgroundRect = function (elem, bounds) {
1✔
34
  const rectElem = drawRect(elem, {
3✔
35
    x: bounds.startx,
3✔
36
    y: bounds.starty,
3✔
37
    width: bounds.stopx - bounds.startx,
3✔
38
    height: bounds.stopy - bounds.starty,
3✔
39
    fill: bounds.fill,
3✔
40
    stroke: bounds.stroke,
3✔
41
    class: 'rect',
3✔
42
  });
3✔
43
  rectElem.lower();
3✔
44
};
3✔
45

1✔
46
export const drawText = function (elem, textData) {
1✔
47
  // Remove and ignore br:s
×
48
  const nText = textData.text.replace(/<br\s*\/?>/gi, ' ');
×
49

×
50
  const textElem = elem.append('text');
×
51
  textElem.attr('x', textData.x);
×
52
  textElem.attr('y', textData.y);
×
53
  textElem.attr('class', 'legend');
×
54

×
55
  textElem.style('text-anchor', textData.anchor);
×
56

×
57
  if (textData.class !== undefined) {
×
58
    textElem.attr('class', textData.class);
×
59
  }
×
60

×
61
  const span = textElem.append('tspan');
×
62
  span.attr('x', textData.x + textData.textMargin * 2);
×
63
  span.text(nText);
×
64

×
65
  return textElem;
×
66
};
×
67

1✔
68
export const drawImage = function (elem, x, y, link) {
1✔
69
  const imageElem = elem.append('image');
×
70
  imageElem.attr('x', x);
×
71
  imageElem.attr('y', y);
×
72
  var sanitizedLink = sanitizeUrl(link);
×
73
  imageElem.attr('xlink:href', sanitizedLink);
×
74
};
×
75

1✔
76
export const drawEmbeddedImage = function (elem, x, y, link) {
1✔
77
  const imageElem = elem.append('use');
×
78
  imageElem.attr('x', x);
×
79
  imageElem.attr('y', y);
×
80
  const sanitizedLink = sanitizeUrl(link);
×
81
  imageElem.attr('xlink:href', '#' + sanitizedLink);
×
82
};
×
83

1✔
84
export const getNoteRect = function () {
1✔
85
  return {
78✔
86
    x: 0,
78✔
87
    y: 0,
78✔
88
    width: 100,
78✔
89
    height: 100,
78✔
90
    fill: '#EDF2AE',
78✔
91
    stroke: '#666',
78✔
92
    anchor: 'start',
78✔
93
    rx: 0,
78✔
94
    ry: 0,
78✔
95
  };
78✔
96
};
78✔
97

1✔
98
export const getTextObj = function () {
1✔
99
  return {
48✔
100
    x: 0,
48✔
101
    y: 0,
48✔
102
    width: 100,
48✔
103
    height: 100,
48✔
104
    fill: undefined,
48✔
105
    anchor: undefined,
48✔
106
    'text-anchor': 'start',
48✔
107
    style: '#666',
48✔
108
    textMargin: 0,
48✔
109
    rx: 0,
48✔
110
    ry: 0,
48✔
111
    tspan: true,
48✔
112
    valign: undefined,
48✔
113
  };
48✔
114
};
48✔
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