2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
every,
|
|
|
|
some
|
|
|
|
} from 'min-dash';
|
2017-12-01 13:45:54 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
componentsToPath
|
|
|
|
} from 'diagram-js/lib/util/RenderUtil';
|
2017-12-01 13:45:54 +00:00
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// element utils //////////////////////
|
2017-12-01 13:45:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if eventDefinition of the given element matches with semantic type.
|
|
|
|
*
|
|
|
|
* @return {boolean} true if element is of the given semantic type
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function isTypedEvent(event, eventDefinitionType, filter) {
|
2017-12-01 13:45:54 +00:00
|
|
|
|
|
|
|
function matches(definition, filter) {
|
|
|
|
return every(filter, function(val, key) {
|
|
|
|
|
|
|
|
// we want a == conversion here, to be able to catch
|
|
|
|
// undefined == false and friends
|
|
|
|
/* jshint -W116 */
|
|
|
|
return definition[key] == val;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return some(event.eventDefinitions, function(definition) {
|
|
|
|
return definition.$type === eventDefinitionType && matches(event, filter);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function isThrowEvent(event) {
|
2017-12-01 13:45:54 +00:00
|
|
|
return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function isCollection(element) {
|
2017-12-01 13:45:54 +00:00
|
|
|
var dataObject = element.dataObjectRef;
|
|
|
|
|
|
|
|
return element.isCollection || (dataObject && dataObject.isCollection);
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getDi(element) {
|
2017-12-01 13:45:54 +00:00
|
|
|
return element.businessObject.di;
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getSemantic(element) {
|
2017-12-01 13:45:54 +00:00
|
|
|
return element.businessObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// color access //////////////////////
|
2017-12-01 13:45:54 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getFillColor(element, defaultColor) {
|
2021-05-25 14:07:59 +00:00
|
|
|
var di = getDi(element);
|
|
|
|
|
|
|
|
return di.get('color:background-color') || di.get('bioc:fill') || defaultColor || 'white';
|
2017-12-01 13:45:54 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getStrokeColor(element, defaultColor) {
|
2021-05-25 14:07:59 +00:00
|
|
|
var di = getDi(element);
|
|
|
|
|
|
|
|
return di.get('color:border-color') || di.get('bioc:stroke') || defaultColor || 'black';
|
2017-12-01 13:45:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 14:07:59 +00:00
|
|
|
export function getLabelColor(element, defaultColor, defaultStrokeColor) {
|
|
|
|
var di = getDi(element),
|
|
|
|
label = di.get('label');
|
|
|
|
|
|
|
|
return label && label.get('color:color') || defaultColor ||
|
|
|
|
getStrokeColor(element, defaultStrokeColor);
|
|
|
|
}
|
2017-12-01 13:45:54 +00:00
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// cropping path customizations //////////////////////
|
2017-12-01 13:45:54 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getCirclePath(shape) {
|
2017-12-01 13:45:54 +00:00
|
|
|
|
|
|
|
var cx = shape.x + shape.width / 2,
|
|
|
|
cy = shape.y + shape.height / 2,
|
|
|
|
radius = shape.width / 2;
|
|
|
|
|
|
|
|
var circlePath = [
|
|
|
|
['M', cx, cy],
|
|
|
|
['m', 0, -radius],
|
|
|
|
['a', radius, radius, 0, 1, 1, 0, 2 * radius],
|
|
|
|
['a', radius, radius, 0, 1, 1, 0, -2 * radius],
|
|
|
|
['z']
|
|
|
|
];
|
|
|
|
|
|
|
|
return componentsToPath(circlePath);
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getRoundRectPath(shape, borderRadius) {
|
2017-12-01 13:45:54 +00:00
|
|
|
|
|
|
|
var x = shape.x,
|
|
|
|
y = shape.y,
|
|
|
|
width = shape.width,
|
|
|
|
height = shape.height;
|
|
|
|
|
|
|
|
var roundRectPath = [
|
|
|
|
['M', x + borderRadius, y],
|
|
|
|
['l', width - borderRadius * 2, 0],
|
|
|
|
['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
|
|
|
|
['l', 0, height - borderRadius * 2],
|
|
|
|
['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
|
|
|
|
['l', borderRadius * 2 - width, 0],
|
|
|
|
['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
|
|
|
|
['l', 0, borderRadius * 2 - height],
|
|
|
|
['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
|
|
|
|
['z']
|
|
|
|
];
|
|
|
|
|
|
|
|
return componentsToPath(roundRectPath);
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getDiamondPath(shape) {
|
2017-12-01 13:45:54 +00:00
|
|
|
|
|
|
|
var width = shape.width,
|
|
|
|
height = shape.height,
|
|
|
|
x = shape.x,
|
|
|
|
y = shape.y,
|
|
|
|
halfWidth = width / 2,
|
|
|
|
halfHeight = height / 2;
|
|
|
|
|
|
|
|
var diamondPath = [
|
|
|
|
['M', x + halfWidth, y],
|
|
|
|
['l', halfWidth, halfHeight],
|
|
|
|
['l', -halfWidth, halfHeight],
|
|
|
|
['l', -halfWidth, -halfHeight],
|
|
|
|
['z']
|
|
|
|
];
|
|
|
|
|
|
|
|
return componentsToPath(diamondPath);
|
|
|
|
}
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getRectPath(shape) {
|
2017-12-01 13:45:54 +00:00
|
|
|
var x = shape.x,
|
|
|
|
y = shape.y,
|
|
|
|
width = shape.width,
|
|
|
|
height = shape.height;
|
|
|
|
|
|
|
|
var rectPath = [
|
|
|
|
['M', x, y],
|
|
|
|
['l', width, 0],
|
|
|
|
['l', 0, height],
|
|
|
|
['l', -width, 0],
|
|
|
|
['z']
|
|
|
|
];
|
|
|
|
|
|
|
|
return componentsToPath(rectPath);
|
2018-04-02 19:01:53 +00:00
|
|
|
}
|