BpmnRenderUtil.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import {
  2. every,
  3. some
  4. } from 'min-dash';
  5. import {
  6. componentsToPath
  7. } from 'diagram-js/lib/util/RenderUtil';
  8. // element utils //////////////////////
  9. /**
  10. * Checks if eventDefinition of the given element matches with semantic type.
  11. *
  12. * @return {boolean} true if element is of the given semantic type
  13. */
  14. export function isTypedEvent(event, eventDefinitionType, filter) {
  15. function matches(definition, filter) {
  16. return every(filter, function(val, key) {
  17. // we want a == conversion here, to be able to catch
  18. // undefined == false and friends
  19. /* jshint -W116 */
  20. return definition[key] == val;
  21. });
  22. }
  23. return some(event.eventDefinitions, function(definition) {
  24. return definition.$type === eventDefinitionType && matches(event, filter);
  25. });
  26. }
  27. export function isThrowEvent(event) {
  28. return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
  29. }
  30. export function isCollection(element) {
  31. var dataObject = element.dataObjectRef;
  32. return element.isCollection || (dataObject && dataObject.isCollection);
  33. }
  34. export function getDi(element) {
  35. return element.businessObject.di;
  36. }
  37. export function getSemantic(element) {
  38. return element.businessObject;
  39. }
  40. // color access //////////////////////
  41. export function getFillColor(element, defaultColor) {
  42. return getDi(element).get('bioc:fill') || defaultColor || 'white';
  43. }
  44. export function getStrokeColor(element, defaultColor) {
  45. return getDi(element).get('bioc:stroke') || defaultColor || 'black';
  46. }
  47. // cropping path customizations //////////////////////
  48. export function getCirclePath(shape) {
  49. var cx = shape.x + shape.width / 2,
  50. cy = shape.y + shape.height / 2,
  51. radius = shape.width / 2;
  52. var circlePath = [
  53. ['M', cx, cy],
  54. ['m', 0, -radius],
  55. ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
  56. ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
  57. ['z']
  58. ];
  59. return componentsToPath(circlePath);
  60. }
  61. export function getRoundRectPath(shape, borderRadius) {
  62. var x = shape.x,
  63. y = shape.y,
  64. width = shape.width,
  65. height = shape.height;
  66. var roundRectPath = [
  67. ['M', x + borderRadius, y],
  68. ['l', width - borderRadius * 2, 0],
  69. ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
  70. ['l', 0, height - borderRadius * 2],
  71. ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
  72. ['l', borderRadius * 2 - width, 0],
  73. ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
  74. ['l', 0, borderRadius * 2 - height],
  75. ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
  76. ['z']
  77. ];
  78. return componentsToPath(roundRectPath);
  79. }
  80. export function getDiamondPath(shape) {
  81. var width = shape.width,
  82. height = shape.height,
  83. x = shape.x,
  84. y = shape.y,
  85. halfWidth = width / 2,
  86. halfHeight = height / 2;
  87. var diamondPath = [
  88. ['M', x + halfWidth, y],
  89. ['l', halfWidth, halfHeight],
  90. ['l', -halfWidth, halfHeight],
  91. ['l', -halfWidth, -halfHeight],
  92. ['z']
  93. ];
  94. return componentsToPath(diamondPath);
  95. }
  96. export function getRectPath(shape) {
  97. var x = shape.x,
  98. y = shape.y,
  99. width = shape.width,
  100. height = shape.height;
  101. var rectPath = [
  102. ['M', x, y],
  103. ['l', width, 0],
  104. ['l', 0, height],
  105. ['l', -width, 0],
  106. ['z']
  107. ];
  108. return componentsToPath(rectPath);
  109. }