1 | import {
|
2 | has,
|
3 | some
|
4 | } from 'min-dash';
|
5 |
|
6 | import {
|
7 | getDi
|
8 | } from '../util/ModelUtil';
|
9 |
|
10 | import {
|
11 | componentsToPath
|
12 | } from 'diagram-js/lib/util/RenderUtil';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export {
|
27 | getDi,
|
28 | getBusinessObject as getSemantic
|
29 | } from '../util/ModelUtil';
|
30 |
|
31 |
|
32 | export var black = 'hsl(225, 10%, 15%)';
|
33 | export var white = 'white';
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | export function isTypedEvent(event, eventDefinitionType) {
|
46 | return some(event.eventDefinitions, function(definition) {
|
47 | return definition.$type === eventDefinitionType;
|
48 | });
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | export function isThrowEvent(event) {
|
59 | return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | export function isCollection(element) {
|
70 | var dataObject = element.dataObjectRef;
|
71 |
|
72 | return element.isCollection || (dataObject && dataObject.isCollection);
|
73 | }
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export function getFillColor(element, defaultColor, overrideColor) {
|
86 | var di = getDi(element);
|
87 |
|
88 | return overrideColor || di.get('color:background-color') || di.get('bioc:fill') || defaultColor || white;
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | export function getStrokeColor(element, defaultColor, overrideColor) {
|
99 | var di = getDi(element);
|
100 |
|
101 | return overrideColor || di.get('color:border-color') || di.get('bioc:stroke') || defaultColor || black;
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | export function getLabelColor(element, defaultColor, defaultStrokeColor, overrideColor) {
|
113 | var di = getDi(element),
|
114 | label = di.get('label');
|
115 |
|
116 | return overrideColor || (label && label.get('color:color')) || defaultColor ||
|
117 | getStrokeColor(element, defaultStrokeColor);
|
118 | }
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | export function getCirclePath(shape) {
|
128 |
|
129 | var cx = shape.x + shape.width / 2,
|
130 | cy = shape.y + shape.height / 2,
|
131 | radius = shape.width / 2;
|
132 |
|
133 | var circlePath = [
|
134 | [ 'M', cx, cy ],
|
135 | [ 'm', 0, -radius ],
|
136 | [ 'a', radius, radius, 0, 1, 1, 0, 2 * radius ],
|
137 | [ 'a', radius, radius, 0, 1, 1, 0, -2 * radius ],
|
138 | [ 'z' ]
|
139 | ];
|
140 |
|
141 | return componentsToPath(circlePath);
|
142 | }
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | export function getRoundRectPath(shape, borderRadius) {
|
151 |
|
152 | var x = shape.x,
|
153 | y = shape.y,
|
154 | width = shape.width,
|
155 | height = shape.height;
|
156 |
|
157 | var roundRectPath = [
|
158 | [ 'M', x + borderRadius, y ],
|
159 | [ 'l', width - borderRadius * 2, 0 ],
|
160 | [ 'a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius ],
|
161 | [ 'l', 0, height - borderRadius * 2 ],
|
162 | [ 'a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius ],
|
163 | [ 'l', borderRadius * 2 - width, 0 ],
|
164 | [ 'a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius ],
|
165 | [ 'l', 0, borderRadius * 2 - height ],
|
166 | [ 'a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius ],
|
167 | [ 'z' ]
|
168 | ];
|
169 |
|
170 | return componentsToPath(roundRectPath);
|
171 | }
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | export function getDiamondPath(shape) {
|
179 |
|
180 | var width = shape.width,
|
181 | height = shape.height,
|
182 | x = shape.x,
|
183 | y = shape.y,
|
184 | halfWidth = width / 2,
|
185 | halfHeight = height / 2;
|
186 |
|
187 | var diamondPath = [
|
188 | [ 'M', x + halfWidth, y ],
|
189 | [ 'l', halfWidth, halfHeight ],
|
190 | [ 'l', -halfWidth, halfHeight ],
|
191 | [ 'l', -halfWidth, -halfHeight ],
|
192 | [ 'z' ]
|
193 | ];
|
194 |
|
195 | return componentsToPath(diamondPath);
|
196 | }
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | export function getRectPath(shape) {
|
204 | var x = shape.x,
|
205 | y = shape.y,
|
206 | width = shape.width,
|
207 | height = shape.height;
|
208 |
|
209 | var rectPath = [
|
210 | [ 'M', x, y ],
|
211 | [ 'l', width, 0 ],
|
212 | [ 'l', 0, height ],
|
213 | [ 'l', -width, 0 ],
|
214 | [ 'z' ]
|
215 | ];
|
216 |
|
217 | return componentsToPath(rectPath);
|
218 | }
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | export function getBounds(bounds, overrides = {}) {
|
229 | return {
|
230 | width: getWidth(bounds, overrides),
|
231 | height: getHeight(bounds, overrides)
|
232 | };
|
233 | }
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | export function getWidth(bounds, overrides = {}) {
|
244 | return has(overrides, 'width') ? overrides.width : bounds.width;
|
245 | }
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | export function getHeight(bounds, overrides = {}) {
|
256 | return has(overrides, 'height') ? overrides.height : bounds.height;
|
257 | } |
\ | No newline at end of file |