forked from PlanQK/workflow-modeler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderUtilities.js
81 lines (69 loc) · 1.98 KB
/
RenderUtilities.js
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
import {
append as svgAppend,
attr as svgAttr,
create as svgCreate,
innerSVG,
select as svgSelect,
} from "tiny-svg";
/**
* Draw svg path with the given attributes.
*
* @param parentGfx The element the path is appended to
* @param d The SVG path
* @param attrs The given attributes
* @returns {SVGPathElement}
*/
export function drawPath(parentGfx, d, attrs) {
const path = svgCreate("path");
svgAttr(path, { d: d });
svgAttr(path, attrs);
svgAppend(parentGfx, path);
return path;
}
/**
* Draw the given SVG in the parent element of type BPMN task
*
* @param parentGfx The parent element the SVG is drawn in
* @param importSVG The SVG
* @param svgAttributes Attributes for the SVG
* @param foreground true if SVG should be above Task
* @returns The created svg element
*/
export function drawTaskSVG(parentGfx, importSVG, svgAttributes, foreground) {
const innerSvgStr = importSVG.svg,
transformDef = importSVG.transform;
const groupDef = svgCreate("g");
svgAttr(groupDef, { transform: transformDef });
innerSVG(groupDef, innerSvgStr);
if (!foreground) {
// set task box opacity to 0 such that icon can be in the background
svgAttr(svgSelect(parentGfx, "rect"), { "fill-opacity": 0 });
}
if (svgAttributes) {
svgAttr(groupDef, svgAttributes);
}
if (foreground) {
parentGfx.append(groupDef);
} else {
parentGfx.prepend(groupDef);
}
return groupDef;
}
/**
* Draw the given SVG in the parent element of type BPMN DataObject
*
* @param parentGfx The parent element the SVG is drawn in
* @param importSVG The SVG
* @param svgAttributes Attributes for the SVG
*/
export function drawDataElementSVG(parentGfx, importSVG, svgAttributes) {
const innerSvgStr = importSVG.svg,
transformDef = importSVG.transform;
const groupDef = svgCreate("g");
svgAttr(groupDef, { transform: transformDef });
innerSVG(groupDef, innerSvgStr);
if (svgAttributes) {
svgAttr(groupDef, svgAttributes);
}
parentGfx.append(groupDef);
}