-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmxSvgCanvas2D.d.ts
466 lines (408 loc) · 11.2 KB
/
mxSvgCanvas2D.d.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/**
* Copyright (c) 2006-2015, JGraph Ltd
* Copyright (c) 2006-2015, Gaudenz Alder
*/
/**
* Class: mxSvgCanvas2D
*
* Extends <mxAbstractCanvas2D> to implement a canvas for SVG. This canvas writes all
* calls as SVG output to the given SVG root node.
*
* (code)
* var svgDoc = mxUtils.createXmlDocument();
* var root = (svgDoc.createElementNS != null) ?
* svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') : svgDoc.createElement('svg');
*
* if (svgDoc.createElementNS == null)
* {
* root.setAttribute('xmlns', mxConstants.NS_SVG);
* root.setAttribute('xmlns:xlink', mxConstants.NS_XLINK);
* }
* else
* {
* root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', mxConstants.NS_XLINK);
* }
*
* var bounds = graph.getGraphBounds();
* root.setAttribute('width', (bounds.x + bounds.width + 4) + 'px');
* root.setAttribute('height', (bounds.y + bounds.height + 4) + 'px');
* root.setAttribute('version', '1.1');
*
* svgDoc.appendChild(root);
*
* var svgCanvas = new mxSvgCanvas2D(root);
* (end)
*
* A description of the public API is available in <mxXmlCanvas2D>.
*
* To disable anti-aliasing in the output, use the following code.
*
* (code)
* graph.view.canvas.ownerSVGElement.setAttribute('shape-rendering', 'crispEdges');
* (end)
*
* Or set the respective attribute in the SVG element directly.
*
* Constructor: mxSvgCanvas2D
*
* Constructs a new SVG canvas.
*
* Parameters:
*
* root - SVG container for the output.
* styleEnabled - Optional boolean that specifies if a style section should be
* added. The style section sets the default font-size, font-family and
* stroke-miterlimit globally. Default is false.
*/
declare namespace mxgraph {
export class mxSvgCanvas2D extends mxAbstractCanvas2D {
constructor(root: Element, styleEnabled?: boolean);
/**
* Variable: root
*
* Reference to the container for the SVG content.
*/
root: Element;
/**
* Variable: gradients
*
* Local cache of gradients for quick lookups.
*/
gradients: Element[];
/**
* Variable: defs
*
* Reference to the defs section of the SVG document. Only for export.
*/
defs: Element;
/**
* Variable: styleEnabled
*
* Stores the value of styleEnabled passed to the constructor.
*/
styleEnabled: boolean;
/**
* Variable: node
*
* Holds the current DOM node.
*/
node: Element;
/**
* Variable: matchHtmlAlignment
*
* Specifies if plain text output should match the vertical HTML alignment.
* Defaul is true.
*/
matchHtmlAlignment: boolean;
/**
* Variable: textEnabled
*
* Specifies if text output should be enabled. Default is true.
*/
textEnabled: boolean;
/**
* Variable: foEnabled
*
* Specifies if use of foreignObject for HTML markup is allowed. Default is true.
*/
foEnabled: boolean;
/**
* Variable: foAltText
*
* Specifies the fallback text for unsupported foreignObjects in exported
* documents. Default is '[Object]'. If this is set to null then no fallback
* text is added to the exported document.
*/
foAltText: string;
/**
* Variable: foOffset
*
* Offset to be used for foreignObjects.
*/
foOffset: number;
/**
* Variable: textOffset
*
* Offset to be used for text elements.
*/
textOffset: number;
/**
* Variable: imageOffset
*
* Offset to be used for image elements.
*/
imageOffset: number;
/**
* Variable: strokeTolerance
*
* Adds transparent paths for strokes.
*/
strokeTolerance: number;
/**
* Variable: minStrokeWidth
*
* Minimum stroke width for output.
*/
minStrokeWidth: number;
/**
* Variable: refCount
*
* Local counter for references in SVG export.
*/
refCount: number;
/**
* Variable: blockImagePointerEvents
*
* Specifies if a transparent rectangle should be added on top of images to absorb
* all pointer events. Default is false. This is only needed in Firefox to disable
* control-clicks on images.
*/
blockImagePointerEvents: boolean;
/**
* Variable: lineHeightCorrection
*
* Correction factor for <mxConstants.LINE_HEIGHT> in HTML output. Default is 1.
*/
lineHeightCorrection: number;
/**
* Variable: pointerEventsValue
*
* Default value for active pointer events. Default is all.
*/
pointerEventsValue: string;
/**
* Variable: fontMetricsPadding
*
* Padding to be added for text that is not wrapped to account for differences
* in font metrics on different platforms in pixels. Default is 10.
*/
fontMetricsPadding: number;
/**
* Variable: cacheOffsetSize
*
* Specifies if offsetWidth and offsetHeight should be cached. Default is true.
* This is used to speed up repaint of text in <updateText>.
*/
cacheOffsetSize: boolean;
/**
* Function: format
*
* Rounds all numbers to 2 decimal points.
*/
format(value: number): number;
/**
* Function: getBaseUrl
*
* Returns the URL of the page without the hash part. This needs to use href to
* include any search part with no params (ie question mark alone). This is a
* workaround for the fact that window.location.search is empty if there is
* no search string behind the question mark.
*/
getBaseUrl(): string;
/**
* Function: reset
*
* Returns any offsets for rendering pixels.
*/
reset(): void;
/**
* Function: createStyle
*
* Creates the optional style section.
*/
createStyle(x?: any): HTMLElement;
/**
* Function: createElement
*
* Private helper function to create SVG elements
*/
createElement(tagName: string, namespace: string): HTMLElement;
/**
* Function: getAlternateContent
*
* Returns the alternate content for the given foreignObject.
*/
createAlternateContent(fo, x: number, y: number, w: number, h: number, str: string, align: string, valign: string, wrap: string, format: string, overflow: string, clip: string, rotation: number);
/**
* Function: createGradientId
*
* Private helper function to create SVG elements
*/
createGradientId(start: string, end: string, alpha1: string, alpha2: string, direction: string): string;
/**
* Function: getSvgGradient
*
* Private helper function to create SVG elements
*/
getSvgGradient(start: string, end: string, alpha1: string, alpha2: string, direction: string): Element;
/**
* Function: createSvgGradient
*
* Creates the given SVG gradient.
*/
createSvgGradient(start: string, end: string, alpha1: string, alpha2: string, direction: string): Element;
/**
* Function: addNode
*
* Private helper function to create SVG elements
*/
addNode(filled: boolean, stroked: boolean): Element;
/**
* Function: updateFill
*
* Transfers the stroke attributes from <state> to <node>.
*/
updateFill(): void;
/**
* Function: getCurrentStrokeWidth
*
* Returns the current stroke width (>= 1), ie. max(1, this.format(this.state.strokeWidth * this.state.scale)).
*/
getCurrentStrokeWidth(): number;
/**
* Function: updateStroke
*
* Transfers the stroke attributes from <state> to <node>.
*/
updateStroke(): void;
/**
* Function: updateStrokeAttributes
*
* Transfers the stroke attributes from <state> to <node>.
*/
updateStrokeAttributes(): void;
/**
* Function: createDashPattern
*
* Creates the SVG dash pattern for the given state.
*/
createDashPattern(scale: number): Number[];
/**
* Function: createTolerance
*
* Creates a hit detection tolerance shape for the given node.
*/
createTolerance(node: Element): Element;
/**
* Function: createShadow
*
* Creates a shadow for the given node.
*/
createShadow(node: Element): Element;
/**
* Function: setLink
*
* Experimental implementation for hyperlinks.
*/
setLink(link: string): void;
/**
* Function: rotate
*
* Sets the rotation of the canvas. Note that rotation cannot be concatenated.
*/
rotate(theta: number, flipH: boolean, flipV: boolean, cx: number, cy: number): void;
/**
* Function: begin
*
* Extends superclass to create path.
*/
begin(): void;
/**
* Function: rect
*
* Private helper function to create SVG elements
*/
rect(x: number, y: number, w: number, h: number): void;
/**
* Function: roundrect
*
* Private helper function to create SVG elements
*/
roundrect(x: number, y: number, w: number, h: number, dx: number, dy: number): void;
/**
* Function: ellipse
*
* Private helper function to create SVG elements
*/
ellipse(x: number, y: number, w: number, h: number): void;
/**
* Function: image
*
* Private helper function to create SVG elements
*/
image(x: number, y: number, w: number, h: number, src: string, aspect: boolean, flipH: boolean, flipV: boolean);
/**
* Function: convertHtml
*
* Converts the given HTML string to XHTML.
*/
convertHtml(val: string): string;
/**
* Function: createDiv
*
* Private helper function to create SVG elements
*/
createDiv(str: string, align: string, valign: string, style: string, overflow: string): HTMLElement;
/**
* Invalidates the cached offset size for the given node.
*/
invalidateCachedOffsetSize(node: Element): void;
/**
* Updates existing DOM nodes for text rendering. LATER: Merge common parts with text function below.
*/
updateText(x: number, y: number, w: number, h: number, align: string, valign: string, wrap: string, overflow: string, clip: string, rotation: number, node: Element): void;
/**
* Function: text
*
* Paints the given text. Possible values for format are empty string for plain
* text and html for HTML markup. Note that HTML markup is only supported if
* foreignObject is supported and <foEnabled> is true. (This means IE9 and later
* does currently not support HTML text as part of shapes.)
*/
text(x: number, y: number, w: number, h: number, str: string, align: string, valign: string, wrap: string, format: string, overflow: string, clip: string, rotation: number, dir: string): void;
/**
* Function: createClip
*
* Creates a clip for the given coordinates.
*/
createClip(x: number, y: number, w: number, h: number): Element;
/**
* Function: text
*
* Paints the given text. Possible values for format are empty string for
* plain text and html for HTML markup.
*/
plainText(x: number, y: number, w: number, h: number, str: string, align: string, valign: string, wrap: string, overflow: string, clip: string, rotation: number, dir: string): void;
/**
* Function: updateFont
*
* Updates the text properties for the given node. (NOTE: For this to work in
* IE, the given node must be a text or tspan element.)
*/
updateFont(node: Element): void;
/**
* Function: addTextBackground
*
* Background color and border
*/
addTextBackground(node: Element, str: string, x: number, y: number, w: number, h: number, align: string, valign: string, overflow: string): void;
/**
* Function: stroke
*
* Paints the outline of the current path.
*/
stroke(): void;
/**
* Function: fill
*
* Fills the current path.
*/
fill(): void;
/**
* Function: fillAndStroke
*
* Fills and paints the outline of the current path.
*/
fillAndStroke(): void;
}
}