电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

880 lines
22 KiB

  1. /* Copyright 2005-2015 Alfresco Software, Ltd.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. function _bpmnGetColor(element, defaultColor)
  16. {
  17. var strokeColor;
  18. if(element.current) {
  19. strokeColor = CURRENT_COLOR;
  20. } else if(element.completed) {
  21. strokeColor = COMPLETED_COLOR;
  22. } else {
  23. strokeColor = defaultColor;
  24. }
  25. return strokeColor;
  26. }
  27. function _drawPool(pool)
  28. {
  29. var rect = paper.rect(pool.x, pool.y, pool.width, pool.height);
  30. rect.attr({"stroke-width": 1,
  31. "stroke": "#000000",
  32. "fill": "white"
  33. });
  34. if (pool.name)
  35. {
  36. var poolName = paper.text(pool.x + 14, pool.y + (pool.height / 2), pool.name).attr({
  37. "text-anchor" : "middle",
  38. "font-family" : "Arial",
  39. "font-size" : "12",
  40. "fill" : "#000000"
  41. });
  42. poolName.transform("r270");
  43. }
  44. if (pool.lanes)
  45. {
  46. for (var i = 0; i < pool.lanes.length; i++)
  47. {
  48. var lane = pool.lanes[i];
  49. _drawLane(lane);
  50. }
  51. }
  52. }
  53. function _drawLane(lane)
  54. {
  55. var rect = paper.rect(lane.x, lane.y, lane.width, lane.height);
  56. rect.attr({"stroke-width": 1,
  57. "stroke": "#000000",
  58. "fill": "white"
  59. });
  60. if (lane.name)
  61. {
  62. var laneName = paper.text(lane.x + 10, lane.y + (lane.height / 2), lane.name).attr({
  63. "text-anchor" : "middle",
  64. "font-family" : "Arial",
  65. "font-size" : "12",
  66. "fill" : "#000000"
  67. });
  68. laneName.transform("r270");
  69. }
  70. }
  71. function _drawSubProcess(element)
  72. {
  73. var rect = paper.rect(element.x, element.y, element.width, element.height, 4);
  74. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  75. rect.attr({"stroke-width": 1,
  76. "stroke": strokeColor,
  77. "fill": "white"
  78. });
  79. }
  80. function _drawTransaction(element)
  81. {
  82. var rect = paper.rect(element.x, element.y, element.width, element.height, 4);
  83. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  84. rect.attr({"stroke-width": 1,
  85. "stroke": strokeColor,
  86. "fill": "white"
  87. });
  88. var borderRect = paper.rect(element.x + 2, element.y + 2, element.width - 4, element.height -4, 4);
  89. borderRect.attr({"stroke-width": 1,
  90. "stroke": "black",
  91. "fill": "none"
  92. });
  93. }
  94. function _drawEventSubProcess(element)
  95. {
  96. var rect = paper.rect(element.x, element.y, element.width, element.height, 4);
  97. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  98. rect.attr({"stroke-width": 1,
  99. "stroke": strokeColor,
  100. "stroke-dasharray": ".",
  101. "fill": "white"
  102. });
  103. }
  104. function _drawAdhocSubProcess(element)
  105. {
  106. var rect = paper.rect(element.x, element.y, element.width, element.height, 4);
  107. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  108. rect.attr({"stroke-width": 1,
  109. "stroke": strokeColor,
  110. "fill": "white"
  111. });
  112. paper.text(element.x + (element.width / 2), element.y + element.height - 8).attr({
  113. "text-anchor" : "middle",
  114. "font-family" : "Arial",
  115. "font-size" : 20,
  116. "text" : "~",
  117. "fill" : "#373e48"
  118. });
  119. }
  120. function _drawStartEvent(element)
  121. {
  122. var startEvent = _drawEvent(element, NORMAL_STROKE, 15);
  123. startEvent.click(function() {
  124. _zoom(true);
  125. });
  126. _addHoverLogic(element, "circle", MAIN_STROKE_COLOR);
  127. }
  128. function _drawEndEvent(element)
  129. {
  130. var endEvent = _drawEvent(element, ENDEVENT_STROKE, 14);
  131. endEvent.click(function() {
  132. _zoom(false);
  133. });
  134. _addHoverLogic(element, "circle", MAIN_STROKE_COLOR);
  135. }
  136. function _drawEvent(element, strokeWidth, radius)
  137. {
  138. var x = element.x + (element.width / 2);
  139. var y = element.y + (element.height / 2);
  140. var circle = paper.circle(x, y, radius);
  141. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  142. // Fill
  143. var eventFillColor = _determineCustomFillColor(element, "#ffffff");
  144. // Opacity
  145. var eventOpacity = 1.0;
  146. if (customActivityBackgroundOpacity) {
  147. eventOpacity = customActivityBackgroundOpacity;
  148. }
  149. if (element.interrupting === undefined || element.interrupting) {
  150. circle.attr({
  151. "stroke-width": strokeWidth,
  152. "stroke": strokeColor,
  153. "fill": eventFillColor,
  154. "fill-opacity": eventOpacity
  155. });
  156. } else {
  157. circle.attr({
  158. "stroke-width": strokeWidth,
  159. "stroke": strokeColor,
  160. "stroke-dasharray": ".",
  161. "fill": eventFillColor,
  162. "fill-opacity": eventOpacity
  163. });
  164. }
  165. circle.id = element.id;
  166. _drawEventIcon(paper, element);
  167. return circle;
  168. }
  169. function _drawServiceTask(element)
  170. {
  171. _drawTask(element);
  172. if (element.taskType === "mail")
  173. {
  174. _drawSendTaskIcon(paper, element.x + 4, element.y + 4);
  175. }
  176. else if (element.taskType === "camel")
  177. {
  178. _drawCamelTaskIcon(paper, element.x + 4, element.y + 4);
  179. }
  180. else if (element.taskType === "mule")
  181. {
  182. _drawMuleTaskIcon(paper, element.x + 4, element.y + 4);
  183. }
  184. else if (element.taskType === "http")
  185. {
  186. _drawHttpTaskIcon(paper, element.x + 4, element.y + 4);
  187. }
  188. else if (element.taskType === "shell")
  189. {
  190. _drawShellTaskIcon(paper, element.x + 4, element.y + 4);
  191. }
  192. else if (element.taskType === "dmn") {
  193. _drawDecisionTaskIcon(paper, element.x + 4, element.y + 4);
  194. }
  195. else if (element.stencilIconId)
  196. {
  197. paper.image("../service/stencilitem/" + element.stencilIconId + "/icon", element.x + 4, element.y + 4, 16, 16);
  198. }
  199. else
  200. {
  201. _drawServiceTaskIcon(paper, element.x + 4, element.y + 4);
  202. }
  203. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  204. }
  205. function _drawSendEventServiceTask(element)
  206. {
  207. _drawTask(element);
  208. _drawSendTaskIcon(paper, element.x + 4, element.y + 4);
  209. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  210. }
  211. function _drawExternalWorkerServiceTask(element)
  212. {
  213. _drawTask(element);
  214. _drawServiceTaskIcon(paper, element.x + 4, element.y + 4);
  215. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  216. }
  217. function _drawHttpServiceTask(element)
  218. {
  219. _drawTask(element);
  220. _drawHttpTaskIcon(paper, element.x + 4, element.y + 4);
  221. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  222. }
  223. function _drawCallActivity(element)
  224. {
  225. var width = element.width - (CALL_ACTIVITY_STROKE / 2);
  226. var height = element.height - (CALL_ACTIVITY_STROKE / 2);
  227. var rect = paper.rect(element.x, element.y, width, height, 4);
  228. var strokeColor = _bpmnGetColor(element, ACTIVITY_STROKE_COLOR);
  229. // Fill
  230. var callActivityFillColor = _determineCustomFillColor(element, ACTIVITY_FILL_COLOR);
  231. // Opacity
  232. var callActivityOpacity = 1.0;
  233. if (customActivityBackgroundOpacity) {
  234. callActivityOpacity = customActivityBackgroundOpacity;
  235. }
  236. rect.attr({"stroke-width": CALL_ACTIVITY_STROKE,
  237. "stroke": strokeColor,
  238. "fill": callActivityFillColor,
  239. "fill-opacity": callActivityOpacity
  240. });
  241. rect.id = element.id;
  242. if (element.name) {
  243. this._drawMultilineText(element.name, element.x, element.y, element.width, element.height, "middle", "middle", 11);
  244. }
  245. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  246. }
  247. function _drawScriptTask(element)
  248. {
  249. _drawTask(element);
  250. _drawScriptTaskIcon(paper, element.x + 4, element.y + 4);
  251. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  252. }
  253. function _drawUserTask(element)
  254. {
  255. _drawTask(element);
  256. _drawUserTaskIcon(paper, element.x + 4, element.y + 4);
  257. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  258. }
  259. function _drawBusinessRuleTask(element)
  260. {
  261. _drawTask(element);
  262. _drawBusinessRuleTaskIcon(paper, element.x + 4, element.y + 4);
  263. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  264. }
  265. function _drawManualTask(element)
  266. {
  267. _drawTask(element);
  268. _drawManualTaskIcon(paper, element.x + 4, element.y + 4);
  269. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  270. }
  271. function _drawSendTask(element)
  272. {
  273. _drawTask(element);
  274. _drawSendTaskIcon(paper, element.x + 4, element.y + 4);
  275. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  276. }
  277. function _drawReceiveTask(element)
  278. {
  279. _drawTask(element);
  280. _drawReceiveTaskIcon(paper, element.x, element.y);
  281. _addHoverLogic(element, "rect", ACTIVITY_STROKE_COLOR);
  282. }
  283. function _drawTask(element)
  284. {
  285. var rectAttrs = {};
  286. // Stroke
  287. var strokeColor = _bpmnGetColor(element, ACTIVITY_STROKE_COLOR);
  288. rectAttrs['stroke'] = strokeColor;
  289. var strokeWidth;
  290. if (strokeColor === ACTIVITY_STROKE_COLOR) {
  291. strokeWidth = TASK_STROKE;
  292. } else {
  293. strokeWidth = TASK_HIGHLIGHT_STROKE;
  294. }
  295. var width = element.width - (strokeWidth / 2);
  296. var height = element.height - (strokeWidth / 2);
  297. var rect = paper.rect(element.x, element.y, width, height, 4);
  298. rectAttrs['stroke-width'] = strokeWidth;
  299. // Fill
  300. var fillColor = _determineCustomFillColor(element, ACTIVITY_FILL_COLOR);
  301. rectAttrs['fill'] = fillColor;
  302. // Opacity
  303. if (customActivityBackgroundOpacity) {
  304. rectAttrs['fill-opacity'] = customActivityBackgroundOpacity;
  305. }
  306. rect.attr(rectAttrs);
  307. rect.id = element.id;
  308. if (element.name) {
  309. this._drawMultilineText(element.name, element.x, element.y, element.width, element.height, "middle", "middle", 11);
  310. }
  311. }
  312. function _drawExclusiveGateway(element)
  313. {
  314. _drawGateway(element);
  315. var quarterWidth = element.width / 4;
  316. var quarterHeight = element.height / 4;
  317. var iks = paper.path(
  318. "M" + (element.x + quarterWidth + 3) + " " + (element.y + quarterHeight + 3) +
  319. "L" + (element.x + 3 * quarterWidth - 3) + " " + (element.y + 3 * quarterHeight - 3) +
  320. "M" + (element.x + quarterWidth + 3) + " " + (element.y + 3 * quarterHeight - 3) +
  321. "L" + (element.x + 3 * quarterWidth - 3) + " " + (element.y + quarterHeight + 3)
  322. );
  323. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  324. // Fill
  325. var gatewayFillColor = _determineCustomFillColor(element, ACTIVITY_FILL_COLOR);
  326. // Opacity
  327. var gatewayOpacity = 1.0;
  328. if (customActivityBackgroundOpacity) {
  329. gatewayOpacity = customActivityBackgroundOpacity;
  330. }
  331. iks.attr({"stroke-width": 3, "stroke": strokeColor, "fill": gatewayFillColor, "fill-opacity": gatewayOpacity});
  332. _addHoverLogic(element, "rhombus", MAIN_STROKE_COLOR);
  333. }
  334. function _drawParallelGateway(element)
  335. {
  336. _drawGateway(element);
  337. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  338. var path1 = paper.path("M 6.75,16 L 25.75,16 M 16,6.75 L 16,25.75");
  339. // Fill
  340. var gatewayFillColor = _determineCustomFillColor(element, ACTIVITY_FILL_COLOR);
  341. // Opacity
  342. var gatewayOpacity = 1.0;
  343. if (customActivityBackgroundOpacity) {
  344. gatewayOpacity = customActivityBackgroundOpacity;
  345. }
  346. path1.attr({
  347. "stroke-width": 3,
  348. "stroke": strokeColor,
  349. "fill": gatewayFillColor,
  350. "fill-opacity": gatewayOpacity
  351. });
  352. path1.transform("T" + (element.x + 4) + "," + (element.y + 4));
  353. _addHoverLogic(element, "rhombus", MAIN_STROKE_COLOR);
  354. }
  355. function _drawInclusiveGateway(element)
  356. {
  357. _drawGateway(element);
  358. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  359. var circle1 = paper.circle(element.x + (element.width / 2), element.y + (element.height / 2), 9.75);
  360. // Fill
  361. var gatewayFillColor = _determineCustomFillColor(element, ACTIVITY_FILL_COLOR);
  362. // Opacity
  363. var gatewayOpacity = 1.0;
  364. if (customActivityBackgroundOpacity) {
  365. gatewayOpacity = customActivityBackgroundOpacity;
  366. }
  367. circle1.attr({
  368. "stroke-width": 2.5,
  369. "stroke": strokeColor,
  370. "fill": gatewayFillColor,
  371. "fill-opacity": gatewayOpacity
  372. });
  373. _addHoverLogic(element, "rhombus", MAIN_STROKE_COLOR);
  374. }
  375. function _drawEventGateway(element)
  376. {
  377. _drawGateway(element);
  378. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  379. var circle1 = paper.circle(element.x + (element.width / 2), element.y + (element.height / 2), 10.4);
  380. // Fill
  381. var gatewayFillColor = _determineCustomFillColor(element, ACTIVITY_FILL_COLOR);
  382. // Opacity
  383. var gatewayOpacity = 1.0;
  384. if (customActivityBackgroundOpacity) {
  385. gatewayOpacity = customActivityBackgroundOpacity;
  386. }
  387. circle1.attr({
  388. "stroke-width": 0.5,
  389. "stroke": strokeColor,
  390. "fill": gatewayFillColor,
  391. "fill-opacity": gatewayOpacity
  392. });
  393. var circle2 = paper.circle(element.x + (element.width / 2), element.y + (element.height / 2), 11.7);
  394. circle2.attr({
  395. "stroke-width": 0.5,
  396. "stroke": strokeColor,
  397. "fill": gatewayFillColor,
  398. "fill-opacity": gatewayOpacity
  399. });
  400. var path1 = paper.path("M 20.327514,22.344972 L 11.259248,22.344216 L 8.4577203,13.719549 L 15.794545,8.389969 L 23.130481,13.720774 L 20.327514,22.344972 z");
  401. path1.attr({
  402. "stroke-width": 1.39999998,
  403. "stroke": strokeColor,
  404. "fill": gatewayFillColor,
  405. "fill-opacity": gatewayOpacity,
  406. "stroke-linejoin": "bevel"
  407. });
  408. path1.transform("T" + (element.x + 4) + "," + (element.y + 4));
  409. _addHoverLogic(element, "rhombus", MAIN_STROKE_COLOR);
  410. }
  411. function _drawGateway(element)
  412. {
  413. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  414. var rhombus = paper.path("M" + element.x + " " + (element.y + (element.height / 2)) +
  415. "L" + (element.x + (element.width / 2)) + " " + (element.y + element.height) +
  416. "L" + (element.x + element.width) + " " + (element.y + (element.height / 2)) +
  417. "L" + (element.x + (element.width / 2)) + " " + element.y + "z"
  418. );
  419. // Fill
  420. var gatewayFillColor = _determineCustomFillColor(element, ACTIVITY_FILL_COLOR);
  421. // Opacity
  422. var gatewayOpacity = 1.0;
  423. if (customActivityBackgroundOpacity) {
  424. gatewayOpacity = customActivityBackgroundOpacity;
  425. }
  426. rhombus.attr("stroke-width", 2);
  427. rhombus.attr("stroke", strokeColor);
  428. rhombus.attr("fill", gatewayFillColor);
  429. rhombus.attr("fill-opacity", gatewayOpacity);
  430. rhombus.id = element.id;
  431. return rhombus;
  432. }
  433. function _drawBoundaryEvent(element)
  434. {
  435. var x = element.x + (element.width / 2);
  436. var y = element.y + (element.height / 2);
  437. var circle = paper.circle(x, y, 15);
  438. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  439. if (element.cancelActivity) {
  440. circle.attr({
  441. "stroke-width": 1,
  442. "stroke": strokeColor,
  443. "fill": "white"
  444. });
  445. } else {
  446. circle.attr({
  447. "stroke-width": 1,
  448. "stroke-dasharray": ".",
  449. "stroke": strokeColor,
  450. "fill": "white"
  451. });
  452. }
  453. var innerCircle = paper.circle(x, y, 12);
  454. if (element.cancelActivity) {
  455. innerCircle.attr({"stroke-width": 1,
  456. "stroke": strokeColor,
  457. "fill": "none"
  458. });
  459. } else {
  460. innerCircle.attr({
  461. "stroke-width": 1,
  462. "stroke-dasharray": ".",
  463. "stroke": strokeColor,
  464. "fill": "none"
  465. });
  466. }
  467. _drawEventIcon(paper, element);
  468. _addHoverLogic(element, "circle", MAIN_STROKE_COLOR);
  469. circle.id = element.id;
  470. innerCircle.id = element.id + "_inner";
  471. }
  472. function _drawIntermediateCatchEvent(element)
  473. {
  474. var x = element.x + (element.width / 2);
  475. var y = element.y + (element.height / 2);
  476. var circle = paper.circle(x, y, 15);
  477. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  478. circle.attr({"stroke-width": 1,
  479. "stroke": strokeColor,
  480. "fill": "white"
  481. });
  482. var innerCircle = paper.circle(x, y, 12);
  483. innerCircle.attr({"stroke-width": 1,
  484. "stroke": strokeColor,
  485. "fill": "none"
  486. });
  487. _drawEventIcon(paper, element);
  488. _addHoverLogic(element, "circle", MAIN_STROKE_COLOR);
  489. circle.id = element.id;
  490. innerCircle.id = element.id + "_inner";
  491. }
  492. function _drawThrowEvent(element)
  493. {
  494. var x = element.x + (element.width / 2);
  495. var y = element.y + (element.height / 2);
  496. var circle = paper.circle(x, y, 15);
  497. var strokeColor = _bpmnGetColor(element, MAIN_STROKE_COLOR);
  498. circle.attr({"stroke-width": 1,
  499. "stroke": strokeColor,
  500. "fill": "white"
  501. });
  502. var innerCircle = paper.circle(x, y, 12);
  503. innerCircle.attr({"stroke-width": 1,
  504. "stroke": strokeColor,
  505. "fill": "none"
  506. });
  507. _drawEventIcon(paper, element);
  508. _addHoverLogic(element, "circle", MAIN_STROKE_COLOR);
  509. circle.id = element.id;
  510. innerCircle.id = element.id + "_inner";
  511. }
  512. function _drawMultilineText(text, x, y, boxWidth, boxHeight, horizontalAnchor, verticalAnchor, fontSize)
  513. {
  514. if (!text || text == "")
  515. {
  516. return;
  517. }
  518. var textBoxX, textBoxY;
  519. var width = boxWidth - (2 * TEXT_PADDING);
  520. if (horizontalAnchor === "middle")
  521. {
  522. textBoxX = x + (boxWidth / 2);
  523. }
  524. else if (horizontalAnchor === "start")
  525. {
  526. textBoxX = x;
  527. }
  528. textBoxY = y + (boxHeight / 2);
  529. var t = paper.text(textBoxX + TEXT_PADDING, textBoxY + TEXT_PADDING).attr({
  530. "text-anchor" : horizontalAnchor,
  531. "font-family" : "Arial",
  532. "font-size" : fontSize,
  533. "fill" : "#373e48"
  534. });
  535. var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  536. t.attr({
  537. "text" : abc
  538. });
  539. var letterWidth = t.getBBox().width / abc.length;
  540. t.attr({
  541. "text" : text
  542. });
  543. var removedLineBreaks = text.split("\n");
  544. var x = 0, s = [];
  545. for (var r = 0; r < removedLineBreaks.length; r++)
  546. {
  547. var words = removedLineBreaks[r].split(" ");
  548. for ( var i = 0; i < words.length; i++) {
  549. var l = words[i].length;
  550. if (x + (l * letterWidth) > width) {
  551. s.push("\n");
  552. x = 0;
  553. }
  554. x += l * letterWidth;
  555. s.push(words[i] + " ");
  556. }
  557. s.push("\n");
  558. x = 0;
  559. }
  560. t.attr({
  561. "text" : s.join("")
  562. });
  563. if (verticalAnchor && verticalAnchor === "top")
  564. {
  565. t.attr({"y": y + (t.getBBox().height / 2)});
  566. }
  567. }
  568. function _drawTextAnnotation(element)
  569. {
  570. var path1 = paper.path("M20,1 L1,1 L1,50 L20,50");
  571. path1.attr({
  572. "stroke": "#585858",
  573. "fill": "none"
  574. });
  575. var annotation = paper.set();
  576. annotation.push(path1);
  577. annotation.transform("T" + element.x + "," + element.y);
  578. if (element.text) {
  579. this._drawMultilineText(element.text, element.x + 2, element.y, element.width, element.height, "start", "middle", 11);
  580. }
  581. }
  582. function _drawFlow(flow){
  583. var polyline = new Polyline(flow.id, flow.waypoints, SEQUENCEFLOW_STROKE, paper);
  584. var strokeColor = _bpmnGetColor(flow, MAIN_STROKE_COLOR);
  585. polyline.element = paper.path(polyline.path);
  586. polyline.element.attr({"stroke-width":SEQUENCEFLOW_STROKE});
  587. polyline.element.attr({"stroke":strokeColor});
  588. polyline.element.id = flow.id;
  589. var lastLineIndex = polyline.getLinesCount() - 1;
  590. var line = polyline.getLine(lastLineIndex);
  591. if (line == undefined) return;
  592. if (flow.type == "connection" && flow.conditions)
  593. {
  594. var middleX = (line.x1 + line.x2) / 2;
  595. var middleY = (line.y1 + line.y2) / 2;
  596. var image = paper.image("../editor/images/condition-flow.png", middleX - 8, middleY - 8, 16, 16);
  597. }
  598. var polylineInvisible = new Polyline(flow.id, flow.waypoints, SEQUENCEFLOW_STROKE, paper);
  599. polylineInvisible.element = paper.path(polyline.path);
  600. polylineInvisible.element.attr({
  601. "opacity": 0,
  602. "stroke-width": 8,
  603. "stroke" : "#000000"
  604. });
  605. if (flow.name) {
  606. var firstLine = polyline.getLine(0);
  607. var angle;
  608. if (firstLine.x1 !== firstLine.x2) {
  609. angle = Math.atan((firstLine.y2 - firstLine.y1) / (firstLine.x2 - firstLine.x1));
  610. } else if (firstLine.y1 < firstLine.y2) {
  611. angle = Math.PI / 2;
  612. } else {
  613. angle = -Math.PI / 2;
  614. }
  615. var flowName = paper.text(firstLine.x1, firstLine.y1, flow.name).attr({
  616. "text-anchor": "middle",
  617. "font-family" : "Arial",
  618. "font-size" : "12",
  619. "fill" : "#000000"
  620. });
  621. var offsetX = (flowName.getBBox().width / 2 + 5);
  622. var offsetY = -(flowName.getBBox().height / 2 + 5);
  623. if (firstLine.x1 > firstLine.x2) {
  624. offsetX = -offsetX;
  625. }
  626. var rotatedOffsetX = offsetX * Math.cos(angle) - offsetY * Math.sin(angle);
  627. var rotatedOffsetY = offsetX * Math.sin(angle) + offsetY * Math.cos(angle);
  628. flowName.attr({
  629. x: firstLine.x1 + rotatedOffsetX,
  630. y: firstLine.y1 + rotatedOffsetY
  631. });
  632. flowName.transform("r" + ((angle) * 180) / Math.PI);
  633. }
  634. _showTip(jQuery(polylineInvisible.element.node), flow);
  635. polylineInvisible.element.mouseover(function() {
  636. paper.getById(polyline.element.id).attr({"stroke":"blue"});
  637. });
  638. polylineInvisible.element.mouseout(function() {
  639. paper.getById(polyline.element.id).attr({"stroke":"#585858"});
  640. });
  641. _drawArrowHead(line);
  642. }
  643. function _drawAssociation(flow){
  644. var polyline = new Polyline(flow.id, flow.waypoints, ASSOCIATION_STROKE, paper);
  645. polyline.element = paper.path(polyline.path);
  646. polyline.element.attr({"stroke-width": ASSOCIATION_STROKE});
  647. polyline.element.attr({"stroke-dasharray": ". "});
  648. polyline.element.attr({"stroke":"#585858"});
  649. polyline.element.id = flow.id;
  650. var polylineInvisible = new Polyline(flow.id, flow.waypoints, ASSOCIATION_STROKE, paper);
  651. polylineInvisible.element = paper.path(polyline.path);
  652. polylineInvisible.element.attr({
  653. "opacity": 0,
  654. "stroke-width": 8,
  655. "stroke" : "#000000"
  656. });
  657. _showTip(jQuery(polylineInvisible.element.node), flow);
  658. polylineInvisible.element.mouseover(function() {
  659. paper.getById(polyline.element.id).attr({"stroke":"blue"});
  660. });
  661. polylineInvisible.element.mouseout(function() {
  662. paper.getById(polyline.element.id).attr({"stroke":"#585858"});
  663. });
  664. }
  665. function _drawArrowHead(line, connectionType)
  666. {
  667. var doubleArrowWidth = 2 * ARROW_WIDTH;
  668. var arrowHead = paper.path("M0 0L-" + (ARROW_WIDTH / 2 + .5) + " -" + doubleArrowWidth + "L" + (ARROW_WIDTH/2 + .5) + " -" + doubleArrowWidth + "z");
  669. // anti smoothing
  670. if (this.strokeWidth%2 == 1)
  671. line.x2 += .5, line.y2 += .5;
  672. arrowHead.transform("t" + line.x2 + "," + line.y2 + "");
  673. arrowHead.transform("...r" + Raphael.deg(line.angle - Math.PI / 2) + " " + 0 + " " + 0);
  674. arrowHead.attr("fill", "#585858");
  675. arrowHead.attr("stroke-width", SEQUENCEFLOW_STROKE);
  676. arrowHead.attr("stroke", "#585858");
  677. return arrowHead;
  678. }
  679. function _determineCustomFillColor(element, defaultColor) {
  680. var color;
  681. // By name
  682. if (customActivityColors && customActivityColors[element.name]) {
  683. color = customActivityColors[element.name];
  684. }
  685. if (color !== null && color !== undefined) {
  686. return color;
  687. }
  688. // By id
  689. if (customActivityColors && customActivityColors[element.id]) {
  690. color = customActivityColors[element.id];
  691. }
  692. if (color !== null && color !== undefined) {
  693. return color;
  694. }
  695. return defaultColor;
  696. }