/
index.ts
207 lines (183 loc) · 5.62 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import type { IBBox, ILine } from "./geotypes";
import type { MagicType, IBoxOptions, IOptions } from "./magic";
import * as straight from "./straight";
import * as svgprimitives from "./svgprimitives";
import * as wobbly from "./wobbly";
let gRenderMagic = straight;
let gOptions: any = {};
function determineRenderMagic(pRenderMagic: MagicType): any {
if (!Boolean(pRenderMagic)) {
return gRenderMagic;
}
/* istanbul ignore if */
if ("wobbly" === pRenderMagic) {
return wobbly;
}
return straight;
}
/**
* Function to set the document to use. Introduced to enable use of the
* rendering utilities under node.js (using the jsdom module)
*
* @param {document} pDocument
*/
export function init(pDocument: Document, pOptions) {
svgprimitives.init(pDocument);
gOptions = Object.assign(
{
LINE_WIDTH: 2,
FONT_SIZE: 12,
},
pOptions
);
}
/**
* Creates a basic SVG with id pId, and size 0x0
*/
export function createSVG(
pId: string,
pClass: string,
pRenderMagic?: any
): SVGSVGElement {
gRenderMagic = determineRenderMagic(pRenderMagic);
return svgprimitives.createSVG(pId, pClass);
}
export const updateSVG = svgprimitives.updateSVG;
export const createTitle = svgprimitives.createTitle;
/**
* Creates a desc element with id pId
*
* @param {string} pID
* @returns {SVGDescElement}
*/
export const createDesc = svgprimitives.createDesc;
/**
* Creates an empty 'defs' element
*
* @returns {SVGDefsElement}
*/
export const createDefs = svgprimitives.createDefs;
/**
* creates a tspan with label pLabel, optionally wrapped in a link
* if the url pURL is passed
*/
export const createTSpan = svgprimitives.createTSpan;
/**
* Creates an svg rectangle of width x height, with the top left
* corner at coordinates (x, y). pRX and pRY define the amount of
* rounding the corners of the rectangle get; when they're left out
* the function will render the corners as straight.
*
* Unit: pixels
*/
export const createRect = (
pBBox: IBBox,
pOptions: IBoxOptions
): SVGRectElement | SVGPathElement => gRenderMagic.createRect(pBBox, pOptions);
/**
* Creates rect with 6px rounded corners of width x height, with the top
* left corner at coordinates (x, y)
*/
export const createRBox = (
pBBox: IBBox,
pOptions: IBoxOptions
): SVGRectElement | SVGPathElement => gRenderMagic.createRBox(pBBox, pOptions);
/**
* Creates an angled box of width x height, with the top left corner
* at coordinates (x, y)
*/
export const createABox = (
pBBox: IBBox,
pOptions: IBoxOptions
): SVGPathElement => gRenderMagic.createABox(pBBox, pOptions);
/**
* Creates a note of pWidth x pHeight, with the top left corner
* at coordinates (pX, pY). pFoldSize controls the size of the
* fold in the top right corner.
*/
export const createNote = (pBBox: IBBox, pOptions: IOptions): SVGPathElement =>
gRenderMagic.createNote(pBBox, pOptions);
/**
* Creates an edge remark (for use in inline expressions) of width x height,
* with the top left corner at coordinates (x, y). pFoldSize controls the size of the
* fold bottom right corner.
*/
export function createEdgeRemark(pBBox: IBBox, pOptions: any) {
return gRenderMagic.createEdgeRemark(pBBox, {
class: pOptions.class,
color: pOptions.color,
bgColor: pOptions.bgColor,
foldSize: pOptions.foldSize,
lineWidth: gOptions.LINE_WIDTH,
});
}
/**
* Creates a text node with the appropriate tspan & a elements on
* position pCoords.
*/
export const createText = svgprimitives.createText;
/**
* Creates a text node with the given pText fitting diagonally (bottom-left
* - top right) in canvas pCanvas
*/
export const createDiagonalText = svgprimitives.createDiagonalText;
/**
* Creates a line between to coordinates
*/
export function createLine(
pLine: ILine,
pOptions
): SVGPathElement | SVGLineElement {
if (Boolean(pOptions) && Boolean(pOptions.doubleLine)) {
if (!pOptions.lineWidth) {
pOptions.lineWidth = gOptions.LINE_WIDTH;
}
return gRenderMagic.createDoubleLine(pLine, pOptions);
} else {
return gRenderMagic.createSingleLine(pLine, pOptions);
}
}
/**
* Creates a u-turn, departing on pStartX, pStarty and
* ending on pStartX, pEndY with a width of pWidth
*
* @param {object} pBBox
* @param {object} pOptions
* @return {SVGPathElement}
*/
export const createUTurn = svgprimitives.createUTurn;
/**
* Creates an svg group, identifiable with id pId
* @param {string} pId
* @return {SVGGElement}
*/
export const createGroup = svgprimitives.createGroup;
/**
* Create an arrow marker consisting of a path as specified in pD
*
* @param {string} pId
* @param {string} pD - a string containing the path
* @return {SVGPathElement}
*/
export const createMarkerPath = svgprimitives.createMarkerPath;
/**
* Create a (filled) arrow marker consisting of a polygon as specified in pPoints
*
* @param {string} pId
* @param {string} pPoints - a string with the points of the polygon
* @return {SVGPolygonElement}
*/
export const createMarkerPolygon = svgprimitives.createMarkerPolygon;
/*
This file is part of mscgen_js.
mscgen_js is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
mscgen_js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with mscgen_js. If not, see <http://www.gnu.org/licenses/>.
*/