BpmnRenderer.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  1. import inherits from 'inherits';
  2. import {
  3. isObject,
  4. assign,
  5. forEach
  6. } from 'min-dash';
  7. import BaseRenderer from 'diagram-js/lib/draw/BaseRenderer';
  8. import {
  9. isExpanded,
  10. isEventSubProcess
  11. } from '../util/DiUtil';
  12. import {
  13. getLabel
  14. } from '../features/label-editing/LabelUtil';
  15. import { is } from '../util/ModelUtil';
  16. import {
  17. createLine
  18. } from 'diagram-js/lib/util/RenderUtil';
  19. import {
  20. isTypedEvent,
  21. isThrowEvent,
  22. isCollection,
  23. getDi,
  24. getSemantic,
  25. getCirclePath,
  26. getRoundRectPath,
  27. getDiamondPath,
  28. getRectPath,
  29. getFillColor,
  30. getStrokeColor
  31. } from './BpmnRenderUtil';
  32. import {
  33. query as domQuery
  34. } from 'min-dom';
  35. import {
  36. append as svgAppend,
  37. attr as svgAttr,
  38. create as svgCreate,
  39. classes as svgClasses
  40. } from 'tiny-svg';
  41. import {
  42. rotate,
  43. transform,
  44. translate
  45. } from 'diagram-js/lib/util/SvgTransformUtil';
  46. import Ids from 'ids';
  47. var RENDERER_IDS = new Ids();
  48. var TASK_BORDER_RADIUS = 10;
  49. var INNER_OUTER_DIST = 3;
  50. var DEFAULT_FILL_OPACITY = .95,
  51. HIGH_FILL_OPACITY = .35;
  52. export default function BpmnRenderer(
  53. config, eventBus, styles, pathMap,
  54. canvas, textRenderer, priority) {
  55. BaseRenderer.call(this, eventBus, priority);
  56. var defaultFillColor = config && config.defaultFillColor,
  57. defaultStrokeColor = config && config.defaultStrokeColor;
  58. var rendererId = RENDERER_IDS.next();
  59. var markers = {};
  60. var computeStyle = styles.computeStyle;
  61. function addMarker(id, options) {
  62. var attrs = assign({
  63. fill: 'black',
  64. strokeWidth: 1,
  65. strokeLinecap: 'round',
  66. strokeDasharray: 'none'
  67. }, options.attrs);
  68. var ref = options.ref || { x: 0, y: 0 };
  69. var scale = options.scale || 1;
  70. // fix for safari / chrome / firefox bug not correctly
  71. // resetting stroke dash array
  72. if (attrs.strokeDasharray === 'none') {
  73. attrs.strokeDasharray = [10000, 1];
  74. }
  75. var marker = svgCreate('marker');
  76. svgAttr(options.element, attrs);
  77. svgAppend(marker, options.element);
  78. svgAttr(marker, {
  79. id: id,
  80. viewBox: '0 0 20 20',
  81. refX: ref.x,
  82. refY: ref.y,
  83. markerWidth: 20 * scale,
  84. markerHeight: 20 * scale,
  85. orient: 'auto'
  86. });
  87. var defs = domQuery('defs', canvas._svg);
  88. if (!defs) {
  89. defs = svgCreate('defs');
  90. svgAppend(canvas._svg, defs);
  91. }
  92. svgAppend(defs, marker);
  93. markers[id] = marker;
  94. }
  95. function colorEscape(str) {
  96. // only allow characters and numbers
  97. return str.replace(/[^0-9a-zA-z]+/g, '_');
  98. }
  99. function marker(type, fill, stroke) {
  100. var id = type + '-' + colorEscape(fill) + '-' + colorEscape(stroke) + '-' + rendererId;
  101. if (!markers[id]) {
  102. createMarker(id, type, fill, stroke);
  103. }
  104. return 'url(#' + id + ')';
  105. }
  106. function createMarker(id, type, fill, stroke) {
  107. if (type === 'sequenceflow-end') {
  108. var sequenceflowEnd = svgCreate('path');
  109. svgAttr(sequenceflowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
  110. addMarker(id, {
  111. element: sequenceflowEnd,
  112. ref: { x: 11, y: 10 },
  113. scale: 0.5,
  114. attrs: {
  115. fill: stroke,
  116. stroke: stroke
  117. }
  118. });
  119. }
  120. if (type === 'messageflow-start') {
  121. var messageflowStart = svgCreate('circle');
  122. svgAttr(messageflowStart, { cx: 6, cy: 6, r: 3.5 });
  123. addMarker(id, {
  124. element: messageflowStart,
  125. attrs: {
  126. fill: fill,
  127. stroke: stroke
  128. },
  129. ref: { x: 6, y: 6 }
  130. });
  131. }
  132. if (type === 'messageflow-end') {
  133. var messageflowEnd = svgCreate('path');
  134. svgAttr(messageflowEnd, { d: 'm 1 5 l 0 -3 l 7 3 l -7 3 z' });
  135. addMarker(id, {
  136. element: messageflowEnd,
  137. attrs: {
  138. fill: fill,
  139. stroke: stroke,
  140. strokeLinecap: 'butt'
  141. },
  142. ref: { x: 8.5, y: 5 }
  143. });
  144. }
  145. if (type === 'association-start') {
  146. var associationStart = svgCreate('path');
  147. svgAttr(associationStart, { d: 'M 11 5 L 1 10 L 11 15' });
  148. addMarker(id, {
  149. element: associationStart,
  150. attrs: {
  151. fill: 'none',
  152. stroke: stroke,
  153. strokeWidth: 1.5
  154. },
  155. ref: { x: 1, y: 10 },
  156. scale: 0.5
  157. });
  158. }
  159. if (type === 'association-end') {
  160. var associationEnd = svgCreate('path');
  161. svgAttr(associationEnd, { d: 'M 1 5 L 11 10 L 1 15' });
  162. addMarker(id, {
  163. element: associationEnd,
  164. attrs: {
  165. fill: 'none',
  166. stroke: stroke,
  167. strokeWidth: 1.5
  168. },
  169. ref: { x: 12, y: 10 },
  170. scale: 0.5
  171. });
  172. }
  173. if (type === 'conditional-flow-marker') {
  174. var conditionalflowMarker = svgCreate('path');
  175. svgAttr(conditionalflowMarker, { d: 'M 0 10 L 8 6 L 16 10 L 8 14 Z' });
  176. addMarker(id, {
  177. element: conditionalflowMarker,
  178. attrs: {
  179. fill: fill,
  180. stroke: stroke
  181. },
  182. ref: { x: -1, y: 10 },
  183. scale: 0.5
  184. });
  185. }
  186. if (type === 'conditional-default-flow-marker') {
  187. var conditionaldefaultflowMarker = svgCreate('path');
  188. svgAttr(conditionaldefaultflowMarker, { d: 'M 6 4 L 10 16' });
  189. addMarker(id, {
  190. element: conditionaldefaultflowMarker,
  191. attrs: {
  192. stroke: stroke
  193. },
  194. ref: { x: 0, y: 10 },
  195. scale: 0.5
  196. });
  197. }
  198. }
  199. function drawCircle(parentGfx, width, height, offset, attrs) {
  200. if (isObject(offset)) {
  201. attrs = offset;
  202. offset = 0;
  203. }
  204. offset = offset || 0;
  205. attrs = computeStyle(attrs, {
  206. stroke: 'black',
  207. strokeWidth: 2,
  208. fill: 'white'
  209. });
  210. if (attrs.fill === 'none') {
  211. delete attrs.fillOpacity;
  212. }
  213. var cx = width / 2,
  214. cy = height / 2;
  215. var circle = svgCreate('circle');
  216. svgAttr(circle, {
  217. cx: cx,
  218. cy: cy,
  219. r: Math.round((width + height) / 4 - offset)
  220. });
  221. svgAttr(circle, attrs);
  222. svgAppend(parentGfx, circle);
  223. return circle;
  224. }
  225. function drawRect(parentGfx, width, height, r, offset, attrs) {
  226. if (isObject(offset)) {
  227. attrs = offset;
  228. offset = 0;
  229. }
  230. offset = offset || 0;
  231. attrs = computeStyle(attrs, {
  232. stroke: 'black',
  233. strokeWidth: 2,
  234. fill: 'white'
  235. });
  236. var rect = svgCreate('rect');
  237. svgAttr(rect, {
  238. x: offset,
  239. y: offset,
  240. width: width - offset * 2,
  241. height: height - offset * 2,
  242. rx: r,
  243. ry: r
  244. });
  245. svgAttr(rect, attrs);
  246. svgAppend(parentGfx, rect);
  247. return rect;
  248. }
  249. function drawDiamond(parentGfx, width, height, attrs) {
  250. var x_2 = width / 2;
  251. var y_2 = height / 2;
  252. var points = [{ x: x_2, y: 0 }, { x: width, y: y_2 }, { x: x_2, y: height }, { x: 0, y: y_2 }];
  253. var pointsString = points.map(function(point) {
  254. return point.x + ',' + point.y;
  255. }).join(' ');
  256. attrs = computeStyle(attrs, {
  257. stroke: 'black',
  258. strokeWidth: 2,
  259. fill: 'white'
  260. });
  261. var polygon = svgCreate('polygon');
  262. svgAttr(polygon, {
  263. points: pointsString
  264. });
  265. svgAttr(polygon, attrs);
  266. svgAppend(parentGfx, polygon);
  267. return polygon;
  268. }
  269. function drawLine(parentGfx, waypoints, attrs) {
  270. attrs = computeStyle(attrs, [ 'no-fill' ], {
  271. stroke: 'black',
  272. strokeWidth: 2,
  273. fill: 'none'
  274. });
  275. var line = createLine(waypoints, attrs);
  276. svgAppend(parentGfx, line);
  277. return line;
  278. }
  279. function drawPath(parentGfx, d, attrs) {
  280. attrs = computeStyle(attrs, [ 'no-fill' ], {
  281. strokeWidth: 2,
  282. stroke: 'black'
  283. });
  284. var path = svgCreate('path');
  285. svgAttr(path, { d: d });
  286. svgAttr(path, attrs);
  287. svgAppend(parentGfx, path);
  288. return path;
  289. }
  290. function drawMarker(type, parentGfx, path, attrs) {
  291. return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
  292. }
  293. function as(type) {
  294. return function(parentGfx, element) {
  295. return handlers[type](parentGfx, element);
  296. };
  297. }
  298. function renderer(type) {
  299. return handlers[type];
  300. }
  301. function renderEventContent(element, parentGfx) {
  302. var event = getSemantic(element);
  303. var isThrowing = isThrowEvent(event);
  304. if (event.eventDefinitions && event.eventDefinitions.length>1) {
  305. if (event.parallelMultiple) {
  306. return renderer('bpmn:ParallelMultipleEventDefinition')(parentGfx, element, isThrowing);
  307. }
  308. else {
  309. return renderer('bpmn:MultipleEventDefinition')(parentGfx, element, isThrowing);
  310. }
  311. }
  312. if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
  313. return renderer('bpmn:MessageEventDefinition')(parentGfx, element, isThrowing);
  314. }
  315. if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
  316. return renderer('bpmn:TimerEventDefinition')(parentGfx, element, isThrowing);
  317. }
  318. if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
  319. return renderer('bpmn:ConditionalEventDefinition')(parentGfx, element);
  320. }
  321. if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
  322. return renderer('bpmn:SignalEventDefinition')(parentGfx, element, isThrowing);
  323. }
  324. if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
  325. return renderer('bpmn:EscalationEventDefinition')(parentGfx, element, isThrowing);
  326. }
  327. if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
  328. return renderer('bpmn:LinkEventDefinition')(parentGfx, element, isThrowing);
  329. }
  330. if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
  331. return renderer('bpmn:ErrorEventDefinition')(parentGfx, element, isThrowing);
  332. }
  333. if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
  334. return renderer('bpmn:CancelEventDefinition')(parentGfx, element, isThrowing);
  335. }
  336. if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
  337. return renderer('bpmn:CompensateEventDefinition')(parentGfx, element, isThrowing);
  338. }
  339. if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
  340. return renderer('bpmn:TerminateEventDefinition')(parentGfx, element, isThrowing);
  341. }
  342. return null;
  343. }
  344. function renderLabel(parentGfx, label, options) {
  345. options = assign({
  346. size: {
  347. width: 100
  348. }
  349. }, options);
  350. var text = textRenderer.createText(label || '', options);
  351. svgClasses(text).add('djs-label');
  352. svgAppend(parentGfx, text);
  353. return text;
  354. }
  355. function renderEmbeddedLabel(parentGfx, element, align) {
  356. var semantic = getSemantic(element);
  357. return renderLabel(parentGfx, semantic.name, {
  358. box: element,
  359. align: align,
  360. padding: 5,
  361. style: {
  362. fill: getStrokeColor(element, defaultStrokeColor)
  363. }
  364. });
  365. }
  366. function renderExternalLabel(parentGfx, element) {
  367. var box = {
  368. width: 90,
  369. height: 30,
  370. x: element.width / 2 + element.x,
  371. y: element.height / 2 + element.y
  372. };
  373. return renderLabel(parentGfx, getLabel(element), {
  374. box: box,
  375. fitBox: true,
  376. style: assign(
  377. {},
  378. textRenderer.getExternalStyle(),
  379. {
  380. fill: getStrokeColor(element, defaultStrokeColor)
  381. }
  382. )
  383. });
  384. }
  385. function renderLaneLabel(parentGfx, text, element) {
  386. var textBox = renderLabel(parentGfx, text, {
  387. box: {
  388. height: 30,
  389. width: element.height
  390. },
  391. align: 'center-middle',
  392. style: {
  393. fill: getStrokeColor(element, defaultStrokeColor)
  394. }
  395. });
  396. var top = -1 * element.height;
  397. transform(textBox, 0, -top, 270);
  398. }
  399. function createPathFromConnection(connection) {
  400. var waypoints = connection.waypoints;
  401. var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
  402. for (var i = 1; i < waypoints.length; i++) {
  403. pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
  404. }
  405. return pathData;
  406. }
  407. var handlers = this.handlers = {
  408. 'bpmn:Event': function(parentGfx, element, attrs) {
  409. if (!('fillOpacity' in attrs)) {
  410. attrs.fillOpacity = DEFAULT_FILL_OPACITY;
  411. }
  412. return drawCircle(parentGfx, element.width, element.height, attrs);
  413. },
  414. 'bpmn:StartEvent': function(parentGfx, element) {
  415. var attrs = {
  416. fill: getFillColor(element, defaultFillColor),
  417. stroke: getStrokeColor(element, defaultStrokeColor)
  418. };
  419. var semantic = getSemantic(element);
  420. if (!semantic.isInterrupting) {
  421. attrs = {
  422. strokeDasharray: '6',
  423. strokeLinecap: 'round',
  424. fill: getFillColor(element, defaultFillColor),
  425. stroke: getStrokeColor(element, defaultStrokeColor)
  426. };
  427. }
  428. var circle = renderer('bpmn:Event')(parentGfx, element, attrs);
  429. renderEventContent(element, parentGfx);
  430. return circle;
  431. },
  432. 'bpmn:MessageEventDefinition': function(parentGfx, element, isThrowing) {
  433. var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
  434. xScaleFactor: 0.9,
  435. yScaleFactor: 0.9,
  436. containerWidth: element.width,
  437. containerHeight: element.height,
  438. position: {
  439. mx: 0.235,
  440. my: 0.315
  441. }
  442. });
  443. var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor);
  444. var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor);
  445. var messagePath = drawPath(parentGfx, pathData, {
  446. strokeWidth: 1,
  447. fill: fill,
  448. stroke: stroke
  449. });
  450. return messagePath;
  451. },
  452. 'bpmn:TimerEventDefinition': function(parentGfx, element) {
  453. var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, {
  454. strokeWidth: 2,
  455. fill: getFillColor(element, defaultFillColor),
  456. stroke: getStrokeColor(element, defaultStrokeColor)
  457. });
  458. var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
  459. xScaleFactor: 0.75,
  460. yScaleFactor: 0.75,
  461. containerWidth: element.width,
  462. containerHeight: element.height,
  463. position: {
  464. mx: 0.5,
  465. my: 0.5
  466. }
  467. });
  468. drawPath(parentGfx, pathData, {
  469. strokeWidth: 2,
  470. strokeLinecap: 'square',
  471. stroke: getStrokeColor(element, defaultStrokeColor)
  472. });
  473. for (var i = 0;i < 12; i++) {
  474. var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
  475. xScaleFactor: 0.75,
  476. yScaleFactor: 0.75,
  477. containerWidth: element.width,
  478. containerHeight: element.height,
  479. position: {
  480. mx: 0.5,
  481. my: 0.5
  482. }
  483. });
  484. var width = element.width / 2;
  485. var height = element.height / 2;
  486. drawPath(parentGfx, linePathData, {
  487. strokeWidth: 1,
  488. strokeLinecap: 'square',
  489. transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')',
  490. stroke: getStrokeColor(element, defaultStrokeColor)
  491. });
  492. }
  493. return circle;
  494. },
  495. 'bpmn:EscalationEventDefinition': function(parentGfx, event, isThrowing) {
  496. var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
  497. xScaleFactor: 1,
  498. yScaleFactor: 1,
  499. containerWidth: event.width,
  500. containerHeight: event.height,
  501. position: {
  502. mx: 0.5,
  503. my: 0.2
  504. }
  505. });
  506. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  507. return drawPath(parentGfx, pathData, {
  508. strokeWidth: 1,
  509. fill: fill,
  510. stroke: getStrokeColor(event, defaultStrokeColor)
  511. });
  512. },
  513. 'bpmn:ConditionalEventDefinition': function(parentGfx, event) {
  514. var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
  515. xScaleFactor: 1,
  516. yScaleFactor: 1,
  517. containerWidth: event.width,
  518. containerHeight: event.height,
  519. position: {
  520. mx: 0.5,
  521. my: 0.222
  522. }
  523. });
  524. return drawPath(parentGfx, pathData, {
  525. strokeWidth: 1,
  526. stroke: getStrokeColor(event, defaultStrokeColor)
  527. });
  528. },
  529. 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) {
  530. var pathData = pathMap.getScaledPath('EVENT_LINK', {
  531. xScaleFactor: 1,
  532. yScaleFactor: 1,
  533. containerWidth: event.width,
  534. containerHeight: event.height,
  535. position: {
  536. mx: 0.57,
  537. my: 0.263
  538. }
  539. });
  540. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  541. return drawPath(parentGfx, pathData, {
  542. strokeWidth: 1,
  543. fill: fill,
  544. stroke: getStrokeColor(event, defaultStrokeColor)
  545. });
  546. },
  547. 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) {
  548. var pathData = pathMap.getScaledPath('EVENT_ERROR', {
  549. xScaleFactor: 1.1,
  550. yScaleFactor: 1.1,
  551. containerWidth: event.width,
  552. containerHeight: event.height,
  553. position: {
  554. mx: 0.2,
  555. my: 0.722
  556. }
  557. });
  558. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  559. return drawPath(parentGfx, pathData, {
  560. strokeWidth: 1,
  561. fill: fill,
  562. stroke: getStrokeColor(event, defaultStrokeColor)
  563. });
  564. },
  565. 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) {
  566. var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
  567. xScaleFactor: 1.0,
  568. yScaleFactor: 1.0,
  569. containerWidth: event.width,
  570. containerHeight: event.height,
  571. position: {
  572. mx: 0.638,
  573. my: -0.055
  574. }
  575. });
  576. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  577. var path = drawPath(parentGfx, pathData, {
  578. strokeWidth: 1,
  579. fill: fill,
  580. stroke: getStrokeColor(event, defaultStrokeColor)
  581. });
  582. rotate(path, 45);
  583. return path;
  584. },
  585. 'bpmn:CompensateEventDefinition': function(parentGfx, event, isThrowing) {
  586. var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
  587. xScaleFactor: 1,
  588. yScaleFactor: 1,
  589. containerWidth: event.width,
  590. containerHeight: event.height,
  591. position: {
  592. mx: 0.22,
  593. my: 0.5
  594. }
  595. });
  596. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  597. return drawPath(parentGfx, pathData, {
  598. strokeWidth: 1,
  599. fill: fill,
  600. stroke: getStrokeColor(event, defaultStrokeColor)
  601. });
  602. },
  603. 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) {
  604. var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
  605. xScaleFactor: 0.9,
  606. yScaleFactor: 0.9,
  607. containerWidth: event.width,
  608. containerHeight: event.height,
  609. position: {
  610. mx: 0.5,
  611. my: 0.2
  612. }
  613. });
  614. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  615. return drawPath(parentGfx, pathData, {
  616. strokeWidth: 1,
  617. fill: fill,
  618. stroke: getStrokeColor(event, defaultStrokeColor)
  619. });
  620. },
  621. 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) {
  622. var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
  623. xScaleFactor: 1.1,
  624. yScaleFactor: 1.1,
  625. containerWidth: event.width,
  626. containerHeight: event.height,
  627. position: {
  628. mx: 0.222,
  629. my: 0.36
  630. }
  631. });
  632. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  633. return drawPath(parentGfx, pathData, {
  634. strokeWidth: 1,
  635. fill: fill
  636. });
  637. },
  638. 'bpmn:ParallelMultipleEventDefinition': function(parentGfx, event) {
  639. var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
  640. xScaleFactor: 1.2,
  641. yScaleFactor: 1.2,
  642. containerWidth: event.width,
  643. containerHeight: event.height,
  644. position: {
  645. mx: 0.458,
  646. my: 0.194
  647. }
  648. });
  649. return drawPath(parentGfx, pathData, {
  650. strokeWidth: 1,
  651. fill: getStrokeColor(event, defaultStrokeColor),
  652. stroke: getStrokeColor(event, defaultStrokeColor)
  653. });
  654. },
  655. 'bpmn:EndEvent': function(parentGfx, element) {
  656. var circle = renderer('bpmn:Event')(parentGfx, element, {
  657. strokeWidth: 4,
  658. fill: getFillColor(element, defaultFillColor),
  659. stroke: getStrokeColor(element, defaultStrokeColor)
  660. });
  661. renderEventContent(element, parentGfx, true);
  662. return circle;
  663. },
  664. 'bpmn:TerminateEventDefinition': function(parentGfx, element) {
  665. var circle = drawCircle(parentGfx, element.width, element.height, 8, {
  666. strokeWidth: 4,
  667. fill: getStrokeColor(element, defaultStrokeColor),
  668. stroke: getStrokeColor(element, defaultStrokeColor)
  669. });
  670. return circle;
  671. },
  672. 'bpmn:IntermediateEvent': function(parentGfx, element) {
  673. var outer = renderer('bpmn:Event')(parentGfx, element, {
  674. strokeWidth: 1,
  675. fill: getFillColor(element, defaultFillColor),
  676. stroke: getStrokeColor(element, defaultStrokeColor)
  677. });
  678. /* inner */
  679. drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, {
  680. strokeWidth: 1,
  681. fill: getFillColor(element, 'none'),
  682. stroke: getStrokeColor(element, defaultStrokeColor)
  683. });
  684. renderEventContent(element, parentGfx);
  685. return outer;
  686. },
  687. 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
  688. 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
  689. 'bpmn:Activity': function(parentGfx, element, attrs) {
  690. attrs = attrs || {};
  691. if (!('fillOpacity' in attrs)) {
  692. attrs.fillOpacity = DEFAULT_FILL_OPACITY;
  693. }
  694. return drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, attrs);
  695. },
  696. 'bpmn:Task': function(parentGfx, element) {
  697. var attrs = {
  698. fill: getFillColor(element, defaultFillColor),
  699. stroke: getStrokeColor(element, defaultStrokeColor)
  700. };
  701. var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
  702. renderEmbeddedLabel(parentGfx, element, 'center-middle');
  703. attachTaskMarkers(parentGfx, element);
  704. return rect;
  705. },
  706. 'bpmn:ServiceTask': function(parentGfx, element) {
  707. var task = renderer('bpmn:Task')(parentGfx, element);
  708. var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  709. abspos: {
  710. x: 12,
  711. y: 18
  712. }
  713. });
  714. /* service bg */ drawPath(parentGfx, pathDataBG, {
  715. strokeWidth: 1,
  716. fill: getFillColor(element, defaultFillColor),
  717. stroke: getStrokeColor(element, defaultStrokeColor)
  718. });
  719. var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
  720. abspos: {
  721. x: 17.2,
  722. y: 18
  723. }
  724. });
  725. /* service fill */ drawPath(parentGfx, fillPathData, {
  726. strokeWidth: 0,
  727. fill: getFillColor(element, defaultFillColor)
  728. });
  729. var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  730. abspos: {
  731. x: 17,
  732. y: 22
  733. }
  734. });
  735. /* service */ drawPath(parentGfx, pathData, {
  736. strokeWidth: 1,
  737. fill: getFillColor(element, defaultFillColor),
  738. stroke: getStrokeColor(element, defaultStrokeColor)
  739. });
  740. return task;
  741. },
  742. 'bpmn:UserTask': function(parentGfx, element) {
  743. var task = renderer('bpmn:Task')(parentGfx, element);
  744. var x = 15;
  745. var y = 12;
  746. var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
  747. abspos: {
  748. x: x,
  749. y: y
  750. }
  751. });
  752. /* user path */ drawPath(parentGfx, pathData, {
  753. strokeWidth: 0.5,
  754. fill: getFillColor(element, defaultFillColor),
  755. stroke: getStrokeColor(element, defaultStrokeColor)
  756. });
  757. var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
  758. abspos: {
  759. x: x,
  760. y: y
  761. }
  762. });
  763. /* user2 path */ drawPath(parentGfx, pathData2, {
  764. strokeWidth: 0.5,
  765. fill: getFillColor(element, defaultFillColor),
  766. stroke: getStrokeColor(element, defaultStrokeColor)
  767. });
  768. var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
  769. abspos: {
  770. x: x,
  771. y: y
  772. }
  773. });
  774. /* user3 path */ drawPath(parentGfx, pathData3, {
  775. strokeWidth: 0.5,
  776. fill: getStrokeColor(element, defaultStrokeColor),
  777. stroke: getStrokeColor(element, defaultStrokeColor)
  778. });
  779. return task;
  780. },
  781. 'bpmn:ManualTask': function(parentGfx, element) {
  782. var task = renderer('bpmn:Task')(parentGfx, element);
  783. var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
  784. abspos: {
  785. x: 17,
  786. y: 15
  787. }
  788. });
  789. /* manual path */ drawPath(parentGfx, pathData, {
  790. strokeWidth: 0.5, // 0.25,
  791. fill: getFillColor(element, defaultFillColor),
  792. stroke: getStrokeColor(element, defaultStrokeColor)
  793. });
  794. return task;
  795. },
  796. 'bpmn:SendTask': function(parentGfx, element) {
  797. var task = renderer('bpmn:Task')(parentGfx, element);
  798. var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  799. xScaleFactor: 1,
  800. yScaleFactor: 1,
  801. containerWidth: 21,
  802. containerHeight: 14,
  803. position: {
  804. mx: 0.285,
  805. my: 0.357
  806. }
  807. });
  808. /* send path */ drawPath(parentGfx, pathData, {
  809. strokeWidth: 1,
  810. fill: getStrokeColor(element, defaultStrokeColor),
  811. stroke: getFillColor(element, defaultFillColor)
  812. });
  813. return task;
  814. },
  815. 'bpmn:ReceiveTask' : function(parentGfx, element) {
  816. var semantic = getSemantic(element);
  817. var task = renderer('bpmn:Task')(parentGfx, element);
  818. var pathData;
  819. if (semantic.instantiate) {
  820. drawCircle(parentGfx, 28, 28, 20 * 0.22, { strokeWidth: 1 });
  821. pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
  822. abspos: {
  823. x: 7.77,
  824. y: 9.52
  825. }
  826. });
  827. } else {
  828. pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  829. xScaleFactor: 0.9,
  830. yScaleFactor: 0.9,
  831. containerWidth: 21,
  832. containerHeight: 14,
  833. position: {
  834. mx: 0.3,
  835. my: 0.4
  836. }
  837. });
  838. }
  839. /* receive path */ drawPath(parentGfx, pathData, {
  840. strokeWidth: 1,
  841. fill: getFillColor(element, defaultFillColor),
  842. stroke: getStrokeColor(element, defaultStrokeColor)
  843. });
  844. return task;
  845. },
  846. 'bpmn:ScriptTask': function(parentGfx, element) {
  847. var task = renderer('bpmn:Task')(parentGfx, element);
  848. var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
  849. abspos: {
  850. x: 15,
  851. y: 20
  852. }
  853. });
  854. /* script path */ drawPath(parentGfx, pathData, {
  855. strokeWidth: 1,
  856. stroke: getStrokeColor(element, defaultStrokeColor)
  857. });
  858. return task;
  859. },
  860. 'bpmn:BusinessRuleTask': function(parentGfx, element) {
  861. var task = renderer('bpmn:Task')(parentGfx, element);
  862. var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
  863. abspos: {
  864. x: 8,
  865. y: 8
  866. }
  867. });
  868. var businessHeaderPath = drawPath(parentGfx, headerPathData);
  869. svgAttr(businessHeaderPath, {
  870. strokeWidth: 1,
  871. fill: getFillColor(element, '#aaaaaa'),
  872. stroke: getStrokeColor(element, defaultStrokeColor)
  873. });
  874. var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
  875. abspos: {
  876. x: 8,
  877. y: 8
  878. }
  879. });
  880. var businessPath = drawPath(parentGfx, headerData);
  881. svgAttr(businessPath, {
  882. strokeWidth: 1,
  883. stroke: getStrokeColor(element, defaultStrokeColor)
  884. });
  885. return task;
  886. },
  887. 'bpmn:SubProcess': function(parentGfx, element, attrs) {
  888. attrs = assign({
  889. fill: getFillColor(element, defaultFillColor),
  890. stroke: getStrokeColor(element, defaultStrokeColor)
  891. }, attrs);
  892. var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
  893. var expanded = isExpanded(element);
  894. if (isEventSubProcess(element)) {
  895. svgAttr(rect, {
  896. strokeDasharray: '1,2'
  897. });
  898. }
  899. renderEmbeddedLabel(parentGfx, element, expanded ? 'center-top' : 'center-middle');
  900. if (expanded) {
  901. attachTaskMarkers(parentGfx, element);
  902. } else {
  903. attachTaskMarkers(parentGfx, element, ['SubProcessMarker']);
  904. }
  905. return rect;
  906. },
  907. 'bpmn:AdHocSubProcess': function(parentGfx, element) {
  908. return renderer('bpmn:SubProcess')(parentGfx, element);
  909. },
  910. 'bpmn:Transaction': function(parentGfx, element) {
  911. var outer = renderer('bpmn:SubProcess')(parentGfx, element);
  912. var innerAttrs = styles.style([ 'no-fill', 'no-events' ], {
  913. stroke: getStrokeColor(element, defaultStrokeColor)
  914. });
  915. /* inner path */ drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
  916. return outer;
  917. },
  918. 'bpmn:CallActivity': function(parentGfx, element) {
  919. return renderer('bpmn:SubProcess')(parentGfx, element, {
  920. strokeWidth: 5
  921. });
  922. },
  923. 'bpmn:Participant': function(parentGfx, element) {
  924. var attrs = {
  925. fillOpacity: DEFAULT_FILL_OPACITY,
  926. fill: getFillColor(element, defaultFillColor),
  927. stroke: getStrokeColor(element, defaultStrokeColor)
  928. };
  929. var lane = renderer('bpmn:Lane')(parentGfx, element, attrs);
  930. var expandedPool = isExpanded(element);
  931. if (expandedPool) {
  932. drawLine(parentGfx, [
  933. { x: 30, y: 0 },
  934. { x: 30, y: element.height }
  935. ], {
  936. stroke: getStrokeColor(element, defaultStrokeColor)
  937. });
  938. var text = getSemantic(element).name;
  939. renderLaneLabel(parentGfx, text, element);
  940. } else {
  941. // Collapsed pool draw text inline
  942. var text2 = getSemantic(element).name;
  943. renderLabel(parentGfx, text2, {
  944. box: element, align: 'center-middle',
  945. style: {
  946. fill: getStrokeColor(element, defaultStrokeColor)
  947. }
  948. });
  949. }
  950. var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
  951. if (participantMultiplicity) {
  952. renderer('ParticipantMultiplicityMarker')(parentGfx, element);
  953. }
  954. return lane;
  955. },
  956. 'bpmn:Lane': function(parentGfx, element, attrs) {
  957. var rect = drawRect(parentGfx, element.width, element.height, 0, assign({
  958. fill: getFillColor(element, defaultFillColor),
  959. fillOpacity: HIGH_FILL_OPACITY,
  960. stroke: getStrokeColor(element, defaultStrokeColor)
  961. }, attrs));
  962. var semantic = getSemantic(element);
  963. if (semantic.$type === 'bpmn:Lane') {
  964. var text = semantic.name;
  965. renderLaneLabel(parentGfx, text, element);
  966. }
  967. return rect;
  968. },
  969. 'bpmn:InclusiveGateway': function(parentGfx, element) {
  970. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  971. /* circle path */
  972. drawCircle(parentGfx, element.width, element.height, element.height * 0.24, {
  973. strokeWidth: 2.5,
  974. fill: getFillColor(element, defaultFillColor),
  975. stroke: getStrokeColor(element, defaultStrokeColor)
  976. });
  977. return diamond;
  978. },
  979. 'bpmn:ExclusiveGateway': function(parentGfx, element) {
  980. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  981. var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
  982. xScaleFactor: 0.4,
  983. yScaleFactor: 0.4,
  984. containerWidth: element.width,
  985. containerHeight: element.height,
  986. position: {
  987. mx: 0.32,
  988. my: 0.3
  989. }
  990. });
  991. if ((getDi(element).isMarkerVisible)) {
  992. drawPath(parentGfx, pathData, {
  993. strokeWidth: 1,
  994. fill: getStrokeColor(element, defaultStrokeColor),
  995. stroke: getStrokeColor(element, defaultStrokeColor)
  996. });
  997. }
  998. return diamond;
  999. },
  1000. 'bpmn:ComplexGateway': function(parentGfx, element) {
  1001. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  1002. var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
  1003. xScaleFactor: 0.5,
  1004. yScaleFactor:0.5,
  1005. containerWidth: element.width,
  1006. containerHeight: element.height,
  1007. position: {
  1008. mx: 0.46,
  1009. my: 0.26
  1010. }
  1011. });
  1012. /* complex path */ drawPath(parentGfx, pathData, {
  1013. strokeWidth: 1,
  1014. fill: getStrokeColor(element, defaultStrokeColor),
  1015. stroke: getStrokeColor(element, defaultStrokeColor)
  1016. });
  1017. return diamond;
  1018. },
  1019. 'bpmn:ParallelGateway': function(parentGfx, element) {
  1020. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  1021. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  1022. xScaleFactor: 0.6,
  1023. yScaleFactor:0.6,
  1024. containerWidth: element.width,
  1025. containerHeight: element.height,
  1026. position: {
  1027. mx: 0.46,
  1028. my: 0.2
  1029. }
  1030. });
  1031. /* parallel path */ drawPath(parentGfx, pathData, {
  1032. strokeWidth: 1,
  1033. fill: getStrokeColor(element, defaultStrokeColor),
  1034. stroke: getStrokeColor(element, defaultStrokeColor)
  1035. });
  1036. return diamond;
  1037. },
  1038. 'bpmn:EventBasedGateway': function(parentGfx, element) {
  1039. var semantic = getSemantic(element);
  1040. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  1041. /* outer circle path */ drawCircle(parentGfx, element.width, element.height, element.height * 0.20, {
  1042. strokeWidth: 1,
  1043. fill: 'none',
  1044. stroke: getStrokeColor(element, defaultStrokeColor)
  1045. });
  1046. var type = semantic.eventGatewayType;
  1047. var instantiate = !!semantic.instantiate;
  1048. function drawEvent() {
  1049. var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
  1050. xScaleFactor: 0.18,
  1051. yScaleFactor: 0.18,
  1052. containerWidth: element.width,
  1053. containerHeight: element.height,
  1054. position: {
  1055. mx: 0.36,
  1056. my: 0.44
  1057. }
  1058. });
  1059. var attrs = {
  1060. strokeWidth: 2,
  1061. fill: getFillColor(element, 'none'),
  1062. stroke: getStrokeColor(element, defaultStrokeColor)
  1063. };
  1064. /* event path */ drawPath(parentGfx, pathData, attrs);
  1065. }
  1066. if (type === 'Parallel') {
  1067. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  1068. xScaleFactor: 0.4,
  1069. yScaleFactor:0.4,
  1070. containerWidth: element.width,
  1071. containerHeight: element.height,
  1072. position: {
  1073. mx: 0.474,
  1074. my: 0.296
  1075. }
  1076. });
  1077. var parallelPath = drawPath(parentGfx, pathData);
  1078. svgAttr(parallelPath, {
  1079. strokeWidth: 1,
  1080. fill: 'none'
  1081. });
  1082. } else if (type === 'Exclusive') {
  1083. if (!instantiate) {
  1084. var innerCircle = drawCircle(parentGfx, element.width, element.height, element.height * 0.26);
  1085. svgAttr(innerCircle, {
  1086. strokeWidth: 1,
  1087. fill: 'none',
  1088. stroke: getStrokeColor(element, defaultStrokeColor)
  1089. });
  1090. }
  1091. drawEvent();
  1092. }
  1093. return diamond;
  1094. },
  1095. 'bpmn:Gateway': function(parentGfx, element) {
  1096. var attrs = {
  1097. fill: getFillColor(element, defaultFillColor),
  1098. fillOpacity: DEFAULT_FILL_OPACITY,
  1099. stroke: getStrokeColor(element, defaultStrokeColor)
  1100. };
  1101. return drawDiamond(parentGfx, element.width, element.height, attrs);
  1102. },
  1103. 'bpmn:SequenceFlow': function(parentGfx, element) {
  1104. var pathData = createPathFromConnection(element);
  1105. var fill = getFillColor(element, defaultFillColor),
  1106. stroke = getStrokeColor(element, defaultStrokeColor);
  1107. var attrs = {
  1108. strokeLinejoin: 'round',
  1109. markerEnd: marker('sequenceflow-end', fill, stroke),
  1110. stroke: getStrokeColor(element, defaultStrokeColor)
  1111. };
  1112. var path = drawPath(parentGfx, pathData, attrs);
  1113. var sequenceFlow = getSemantic(element);
  1114. var source;
  1115. if (element.source) {
  1116. source = element.source.businessObject;
  1117. // conditional flow marker
  1118. if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Activity')) {
  1119. svgAttr(path, {
  1120. markerStart: marker('conditional-flow-marker', fill, stroke)
  1121. });
  1122. }
  1123. // default marker
  1124. if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
  1125. source.default === sequenceFlow) {
  1126. svgAttr(path, {
  1127. markerStart: marker('conditional-default-flow-marker', fill, stroke)
  1128. });
  1129. }
  1130. }
  1131. return path;
  1132. },
  1133. 'bpmn:Association': function(parentGfx, element, attrs) {
  1134. var semantic = getSemantic(element);
  1135. var fill = getFillColor(element, defaultFillColor),
  1136. stroke = getStrokeColor(element, defaultStrokeColor);
  1137. attrs = assign({
  1138. strokeDasharray: '0.5, 5',
  1139. strokeLinecap: 'round',
  1140. strokeLinejoin: 'round',
  1141. stroke: getStrokeColor(element, defaultStrokeColor)
  1142. }, attrs || {});
  1143. if (semantic.associationDirection === 'One' ||
  1144. semantic.associationDirection === 'Both') {
  1145. attrs.markerEnd = marker('association-end', fill, stroke);
  1146. }
  1147. if (semantic.associationDirection === 'Both') {
  1148. attrs.markerStart = marker('association-start', fill, stroke);
  1149. }
  1150. return drawLine(parentGfx, element.waypoints, attrs);
  1151. },
  1152. 'bpmn:DataInputAssociation': function(parentGfx, element) {
  1153. var fill = getFillColor(element, defaultFillColor),
  1154. stroke = getStrokeColor(element, defaultStrokeColor);
  1155. return renderer('bpmn:Association')(parentGfx, element, {
  1156. markerEnd: marker('association-end', fill, stroke)
  1157. });
  1158. },
  1159. 'bpmn:DataOutputAssociation': function(parentGfx, element) {
  1160. var fill = getFillColor(element, defaultFillColor),
  1161. stroke = getStrokeColor(element, defaultStrokeColor);
  1162. return renderer('bpmn:Association')(parentGfx, element, {
  1163. markerEnd: marker('association-end', fill, stroke)
  1164. });
  1165. },
  1166. 'bpmn:MessageFlow': function(parentGfx, element) {
  1167. var semantic = getSemantic(element),
  1168. di = getDi(element);
  1169. var fill = getFillColor(element, defaultFillColor),
  1170. stroke = getStrokeColor(element, defaultStrokeColor);
  1171. var pathData = createPathFromConnection(element);
  1172. var attrs = {
  1173. markerEnd: marker('messageflow-end', fill, stroke),
  1174. markerStart: marker('messageflow-start', fill, stroke),
  1175. strokeDasharray: '10, 12',
  1176. strokeLinecap: 'round',
  1177. strokeLinejoin: 'round',
  1178. strokeWidth: '1.5px',
  1179. stroke: getStrokeColor(element, defaultStrokeColor)
  1180. };
  1181. var path = drawPath(parentGfx, pathData, attrs);
  1182. if (semantic.messageRef) {
  1183. var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
  1184. var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
  1185. abspos: {
  1186. x: midPoint.x,
  1187. y: midPoint.y
  1188. }
  1189. });
  1190. var messageAttrs = { strokeWidth: 1 };
  1191. if (di.messageVisibleKind === 'initiating') {
  1192. messageAttrs.fill = 'white';
  1193. messageAttrs.stroke = 'black';
  1194. } else {
  1195. messageAttrs.fill = '#888';
  1196. messageAttrs.stroke = 'white';
  1197. }
  1198. drawPath(parentGfx, markerPathData, messageAttrs);
  1199. }
  1200. return path;
  1201. },
  1202. 'bpmn:DataObject': function(parentGfx, element) {
  1203. var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
  1204. xScaleFactor: 1,
  1205. yScaleFactor: 1,
  1206. containerWidth: element.width,
  1207. containerHeight: element.height,
  1208. position: {
  1209. mx: 0.474,
  1210. my: 0.296
  1211. }
  1212. });
  1213. var elementObject = drawPath(parentGfx, pathData, {
  1214. fill: getFillColor(element, defaultFillColor),
  1215. fillOpacity: DEFAULT_FILL_OPACITY,
  1216. stroke: getStrokeColor(element, defaultStrokeColor)
  1217. });
  1218. var semantic = getSemantic(element);
  1219. if (isCollection(semantic)) {
  1220. renderDataItemCollection(parentGfx, element);
  1221. }
  1222. return elementObject;
  1223. },
  1224. 'bpmn:DataObjectReference': as('bpmn:DataObject'),
  1225. 'bpmn:DataInput': function(parentGfx, element) {
  1226. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  1227. // page
  1228. var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
  1229. /* input arrow path */ drawPath(parentGfx, arrowPathData, { strokeWidth: 1 });
  1230. return elementObject;
  1231. },
  1232. 'bpmn:DataOutput': function(parentGfx, element) {
  1233. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  1234. // page
  1235. var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
  1236. /* output arrow path */ drawPath(parentGfx, arrowPathData, {
  1237. strokeWidth: 1,
  1238. fill: 'black'
  1239. });
  1240. return elementObject;
  1241. },
  1242. 'bpmn:DataStoreReference': function(parentGfx, element) {
  1243. var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
  1244. xScaleFactor: 1,
  1245. yScaleFactor: 1,
  1246. containerWidth: element.width,
  1247. containerHeight: element.height,
  1248. position: {
  1249. mx: 0,
  1250. my: 0.133
  1251. }
  1252. });
  1253. var elementStore = drawPath(parentGfx, DATA_STORE_PATH, {
  1254. strokeWidth: 2,
  1255. fill: getFillColor(element, defaultFillColor),
  1256. fillOpacity: DEFAULT_FILL_OPACITY,
  1257. stroke: getStrokeColor(element, defaultStrokeColor)
  1258. });
  1259. return elementStore;
  1260. },
  1261. 'bpmn:BoundaryEvent': function(parentGfx, element) {
  1262. var semantic = getSemantic(element),
  1263. cancel = semantic.cancelActivity;
  1264. var attrs = {
  1265. strokeWidth: 1,
  1266. fill: getFillColor(element, defaultFillColor),
  1267. stroke: getStrokeColor(element, defaultStrokeColor)
  1268. };
  1269. if (!cancel) {
  1270. attrs.strokeDasharray = '6';
  1271. attrs.strokeLinecap = 'round';
  1272. }
  1273. // apply fillOpacity
  1274. var outerAttrs = assign({}, attrs, {
  1275. fillOpacity: 1
  1276. });
  1277. // apply no-fill
  1278. var innerAttrs = assign({}, attrs, {
  1279. fill: 'none'
  1280. });
  1281. var outer = renderer('bpmn:Event')(parentGfx, element, outerAttrs);
  1282. /* inner path */ drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, innerAttrs);
  1283. renderEventContent(element, parentGfx);
  1284. return outer;
  1285. },
  1286. 'bpmn:Group': function(parentGfx, element) {
  1287. var group = drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, {
  1288. stroke: getStrokeColor(element, defaultStrokeColor),
  1289. strokeWidth: 1,
  1290. strokeDasharray: '8,3,1,3',
  1291. fill: 'none',
  1292. pointerEvents: 'none'
  1293. });
  1294. return group;
  1295. },
  1296. 'label': function(parentGfx, element) {
  1297. return renderExternalLabel(parentGfx, element);
  1298. },
  1299. 'bpmn:TextAnnotation': function(parentGfx, element) {
  1300. var style = {
  1301. 'fill': 'none',
  1302. 'stroke': 'none'
  1303. };
  1304. var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style);
  1305. var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
  1306. xScaleFactor: 1,
  1307. yScaleFactor: 1,
  1308. containerWidth: element.width,
  1309. containerHeight: element.height,
  1310. position: {
  1311. mx: 0.0,
  1312. my: 0.0
  1313. }
  1314. });
  1315. drawPath(parentGfx, textPathData, {
  1316. stroke: getStrokeColor(element, defaultStrokeColor)
  1317. });
  1318. var text = getSemantic(element).text || '';
  1319. renderLabel(parentGfx, text, {
  1320. box: element,
  1321. align: 'left-top',
  1322. padding: 5,
  1323. style: {
  1324. fill: getStrokeColor(element, defaultStrokeColor)
  1325. }
  1326. });
  1327. return textElement;
  1328. },
  1329. 'ParticipantMultiplicityMarker': function(parentGfx, element) {
  1330. var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  1331. xScaleFactor: 1,
  1332. yScaleFactor: 1,
  1333. containerWidth: element.width,
  1334. containerHeight: element.height,
  1335. position: {
  1336. mx: ((element.width / 2) / element.width),
  1337. my: (element.height - 15) / element.height
  1338. }
  1339. });
  1340. drawMarker('participant-multiplicity', parentGfx, markerPath, {
  1341. strokeWidth: 1,
  1342. fill: getFillColor(element, defaultFillColor),
  1343. stroke: getStrokeColor(element, defaultStrokeColor)
  1344. });
  1345. },
  1346. 'SubProcessMarker': function(parentGfx, element) {
  1347. var markerRect = drawRect(parentGfx, 14, 14, 0, {
  1348. strokeWidth: 1,
  1349. fill: getFillColor(element, defaultFillColor),
  1350. stroke: getStrokeColor(element, defaultStrokeColor)
  1351. });
  1352. // Process marker is placed in the middle of the box
  1353. // therefore fixed values can be used here
  1354. translate(markerRect, element.width / 2 - 7.5, element.height - 20);
  1355. var markerPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
  1356. xScaleFactor: 1.5,
  1357. yScaleFactor: 1.5,
  1358. containerWidth: element.width,
  1359. containerHeight: element.height,
  1360. position: {
  1361. mx: (element.width / 2 - 7.5) / element.width,
  1362. my: (element.height - 20) / element.height
  1363. }
  1364. });
  1365. drawMarker('sub-process', parentGfx, markerPath, {
  1366. fill: getFillColor(element, defaultFillColor),
  1367. stroke: getStrokeColor(element, defaultStrokeColor)
  1368. });
  1369. },
  1370. 'ParallelMarker': function(parentGfx, element, position) {
  1371. var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  1372. xScaleFactor: 1,
  1373. yScaleFactor: 1,
  1374. containerWidth: element.width,
  1375. containerHeight: element.height,
  1376. position: {
  1377. mx: ((element.width / 2 + position.parallel) / element.width),
  1378. my: (element.height - 20) / element.height
  1379. }
  1380. });
  1381. drawMarker('parallel', parentGfx, markerPath, {
  1382. fill: getFillColor(element, defaultFillColor),
  1383. stroke: getStrokeColor(element, defaultStrokeColor)
  1384. });
  1385. },
  1386. 'SequentialMarker': function(parentGfx, element, position) {
  1387. var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
  1388. xScaleFactor: 1,
  1389. yScaleFactor: 1,
  1390. containerWidth: element.width,
  1391. containerHeight: element.height,
  1392. position: {
  1393. mx: ((element.width / 2 + position.seq) / element.width),
  1394. my: (element.height - 19) / element.height
  1395. }
  1396. });
  1397. drawMarker('sequential', parentGfx, markerPath, {
  1398. fill: getFillColor(element, defaultFillColor),
  1399. stroke: getStrokeColor(element, defaultStrokeColor)
  1400. });
  1401. },
  1402. 'CompensationMarker': function(parentGfx, element, position) {
  1403. var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', {
  1404. xScaleFactor: 1,
  1405. yScaleFactor: 1,
  1406. containerWidth: element.width,
  1407. containerHeight: element.height,
  1408. position: {
  1409. mx: ((element.width / 2 + position.compensation) / element.width),
  1410. my: (element.height - 13) / element.height
  1411. }
  1412. });
  1413. drawMarker('compensation', parentGfx, markerMath, {
  1414. strokeWidth: 1,
  1415. fill: getFillColor(element, defaultFillColor),
  1416. stroke: getStrokeColor(element, defaultStrokeColor)
  1417. });
  1418. },
  1419. 'LoopMarker': function(parentGfx, element, position) {
  1420. var markerPath = pathMap.getScaledPath('MARKER_LOOP', {
  1421. xScaleFactor: 1,
  1422. yScaleFactor: 1,
  1423. containerWidth: element.width,
  1424. containerHeight: element.height,
  1425. position: {
  1426. mx: ((element.width / 2 + position.loop) / element.width),
  1427. my: (element.height - 7) / element.height
  1428. }
  1429. });
  1430. drawMarker('loop', parentGfx, markerPath, {
  1431. strokeWidth: 1,
  1432. fill: getFillColor(element, defaultFillColor),
  1433. stroke: getStrokeColor(element, defaultStrokeColor),
  1434. strokeLinecap: 'round',
  1435. strokeMiterlimit: 0.5
  1436. });
  1437. },
  1438. 'AdhocMarker': function(parentGfx, element, position) {
  1439. var markerPath = pathMap.getScaledPath('MARKER_ADHOC', {
  1440. xScaleFactor: 1,
  1441. yScaleFactor: 1,
  1442. containerWidth: element.width,
  1443. containerHeight: element.height,
  1444. position: {
  1445. mx: ((element.width / 2 + position.adhoc) / element.width),
  1446. my: (element.height - 15) / element.height
  1447. }
  1448. });
  1449. drawMarker('adhoc', parentGfx, markerPath, {
  1450. strokeWidth: 1,
  1451. fill: getStrokeColor(element, defaultStrokeColor),
  1452. stroke: getStrokeColor(element, defaultStrokeColor)
  1453. });
  1454. }
  1455. };
  1456. function attachTaskMarkers(parentGfx, element, taskMarkers) {
  1457. var obj = getSemantic(element);
  1458. var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
  1459. var position;
  1460. if (subprocess) {
  1461. position = {
  1462. seq: -21,
  1463. parallel: -22,
  1464. compensation: -42,
  1465. loop: -18,
  1466. adhoc: 10
  1467. };
  1468. } else {
  1469. position = {
  1470. seq: -3,
  1471. parallel: -6,
  1472. compensation: -27,
  1473. loop: 0,
  1474. adhoc: 10
  1475. };
  1476. }
  1477. forEach(taskMarkers, function(marker) {
  1478. renderer(marker)(parentGfx, element, position);
  1479. });
  1480. if (obj.isForCompensation) {
  1481. renderer('CompensationMarker')(parentGfx, element, position);
  1482. }
  1483. if (obj.$type === 'bpmn:AdHocSubProcess') {
  1484. renderer('AdhocMarker')(parentGfx, element, position);
  1485. }
  1486. var loopCharacteristics = obj.loopCharacteristics,
  1487. isSequential = loopCharacteristics && loopCharacteristics.isSequential;
  1488. if (loopCharacteristics) {
  1489. if (isSequential === undefined) {
  1490. renderer('LoopMarker')(parentGfx, element, position);
  1491. }
  1492. if (isSequential === false) {
  1493. renderer('ParallelMarker')(parentGfx, element, position);
  1494. }
  1495. if (isSequential === true) {
  1496. renderer('SequentialMarker')(parentGfx, element, position);
  1497. }
  1498. }
  1499. }
  1500. function renderDataItemCollection(parentGfx, element) {
  1501. var yPosition = (element.height - 16) / element.height;
  1502. var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
  1503. xScaleFactor: 1,
  1504. yScaleFactor: 1,
  1505. containerWidth: element.width,
  1506. containerHeight: element.height,
  1507. position: {
  1508. mx: 0.451,
  1509. my: yPosition
  1510. }
  1511. });
  1512. /* collection path */ drawPath(parentGfx, pathData, {
  1513. strokeWidth: 2
  1514. });
  1515. }
  1516. // extension API, use at your own risk
  1517. this._drawPath = drawPath;
  1518. }
  1519. inherits(BpmnRenderer, BaseRenderer);
  1520. BpmnRenderer.$inject = [
  1521. 'config.bpmnRenderer',
  1522. 'eventBus',
  1523. 'styles',
  1524. 'pathMap',
  1525. 'canvas',
  1526. 'textRenderer'
  1527. ];
  1528. BpmnRenderer.prototype.canRender = function(element) {
  1529. return is(element, 'bpmn:BaseElement');
  1530. };
  1531. BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
  1532. var type = element.type;
  1533. var h = this.handlers[type];
  1534. /* jshint -W040 */
  1535. return h(parentGfx, element);
  1536. };
  1537. BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
  1538. var type = element.type;
  1539. var h = this.handlers[type];
  1540. /* jshint -W040 */
  1541. return h(parentGfx, element);
  1542. };
  1543. BpmnRenderer.prototype.getShapePath = function(element) {
  1544. if (is(element, 'bpmn:Event')) {
  1545. return getCirclePath(element);
  1546. }
  1547. if (is(element, 'bpmn:Activity')) {
  1548. return getRoundRectPath(element, TASK_BORDER_RADIUS);
  1549. }
  1550. if (is(element, 'bpmn:Gateway')) {
  1551. return getDiamondPath(element);
  1552. }
  1553. return getRectPath(element);
  1554. };