1 | import { sanitizeUrl } from "@braintree/sanitize-url";
|
2 | const drawRect = function(elem, rectData) {
|
3 | const rectElem = elem.append("rect");
|
4 | rectElem.attr("x", rectData.x);
|
5 | rectElem.attr("y", rectData.y);
|
6 | rectElem.attr("fill", rectData.fill);
|
7 | rectElem.attr("stroke", rectData.stroke);
|
8 | rectElem.attr("width", rectData.width);
|
9 | rectElem.attr("height", rectData.height);
|
10 | rectElem.attr("rx", rectData.rx);
|
11 | rectElem.attr("ry", rectData.ry);
|
12 | if (rectData.attrs !== "undefined" && rectData.attrs !== null) {
|
13 | for (let attrKey in rectData.attrs) {
|
14 | rectElem.attr(attrKey, rectData.attrs[attrKey]);
|
15 | }
|
16 | }
|
17 | if (rectData.class !== "undefined") {
|
18 | rectElem.attr("class", rectData.class);
|
19 | }
|
20 | return rectElem;
|
21 | };
|
22 | const drawBackgroundRect = function(elem, bounds) {
|
23 | const rectElem = drawRect(elem, {
|
24 | x: bounds.startx,
|
25 | y: bounds.starty,
|
26 | width: bounds.stopx - bounds.startx,
|
27 | height: bounds.stopy - bounds.starty,
|
28 | fill: bounds.fill,
|
29 | stroke: bounds.stroke,
|
30 | class: "rect"
|
31 | });
|
32 | rectElem.lower();
|
33 | };
|
34 | const drawText = function(elem, textData) {
|
35 | const nText = textData.text.replace(/<br\s*\/?>/gi, " ");
|
36 | const textElem = elem.append("text");
|
37 | textElem.attr("x", textData.x);
|
38 | textElem.attr("y", textData.y);
|
39 | textElem.attr("class", "legend");
|
40 | textElem.style("text-anchor", textData.anchor);
|
41 | if (textData.class !== void 0) {
|
42 | textElem.attr("class", textData.class);
|
43 | }
|
44 | const span = textElem.append("tspan");
|
45 | span.attr("x", textData.x + textData.textMargin * 2);
|
46 | span.text(nText);
|
47 | return textElem;
|
48 | };
|
49 | const drawImage = function(elem, x, y, link) {
|
50 | const imageElem = elem.append("image");
|
51 | imageElem.attr("x", x);
|
52 | imageElem.attr("y", y);
|
53 | var sanitizedLink = sanitizeUrl(link);
|
54 | imageElem.attr("xlink:href", sanitizedLink);
|
55 | };
|
56 | const drawEmbeddedImage = function(elem, x, y, link) {
|
57 | const imageElem = elem.append("use");
|
58 | imageElem.attr("x", x);
|
59 | imageElem.attr("y", y);
|
60 | const sanitizedLink = sanitizeUrl(link);
|
61 | imageElem.attr("xlink:href", "#" + sanitizedLink);
|
62 | };
|
63 | const getNoteRect = function() {
|
64 | return {
|
65 | x: 0,
|
66 | y: 0,
|
67 | width: 100,
|
68 | height: 100,
|
69 | fill: "#EDF2AE",
|
70 | stroke: "#666",
|
71 | anchor: "start",
|
72 | rx: 0,
|
73 | ry: 0
|
74 | };
|
75 | };
|
76 | const getTextObj = function() {
|
77 | return {
|
78 | x: 0,
|
79 | y: 0,
|
80 | width: 100,
|
81 | height: 100,
|
82 | fill: void 0,
|
83 | anchor: void 0,
|
84 | "text-anchor": "start",
|
85 | style: "#666",
|
86 | textMargin: 0,
|
87 | rx: 0,
|
88 | ry: 0,
|
89 | tspan: true,
|
90 | valign: void 0
|
91 | };
|
92 | };
|
93 | export {
|
94 | drawBackgroundRect as a,
|
95 | drawEmbeddedImage as b,
|
96 | drawImage as c,
|
97 | drawRect as d,
|
98 | getTextObj as e,
|
99 | drawText as f,
|
100 | getNoteRect as g
|
101 | };
|