电子档案
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.

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