mxSwimlane.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxSwimlane
  7. *
  8. * Extends <mxShape> to implement a swimlane shape. This shape is registered
  9. * under <mxConstants.SHAPE_SWIMLANE> in <mxCellRenderer>. Use the
  10. * <mxConstants.STYLE_STYLE_STARTSIZE> to define the size of the title
  11. * region, <mxConstants.STYLE_SWIMLANE_FILLCOLOR> for the content area fill,
  12. * <mxConstants.STYLE_SEPARATORCOLOR> to draw an additional vertical separator
  13. * and <mxConstants.STYLE_SWIMLANE_LINE> to hide the line between the title
  14. * region and the content area. The <mxConstants.STYLE_HORIZONTAL> affects
  15. * the orientation of this shape, not only its label.
  16. *
  17. * Constructor: mxSwimlane
  18. *
  19. * Constructs a new swimlane shape.
  20. *
  21. * Parameters:
  22. *
  23. * bounds - <mxRectangle> that defines the bounds. This is stored in
  24. * <mxShape.bounds>.
  25. * fill - String that defines the fill color. This is stored in <fill>.
  26. * stroke - String that defines the stroke color. This is stored in <stroke>.
  27. * strokewidth - Optional integer that defines the stroke width. Default is
  28. * 1. This is stored in <strokewidth>.
  29. */
  30. function mxSwimlane(bounds, fill, stroke, strokewidth)
  31. {
  32. mxShape.call(this);
  33. this.bounds = bounds;
  34. this.fill = fill;
  35. this.stroke = stroke;
  36. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  37. };
  38. /**
  39. * Extends mxShape.
  40. */
  41. mxUtils.extend(mxSwimlane, mxShape);
  42. /**
  43. * Variable: imageSize
  44. *
  45. * Default imagewidth and imageheight if an image but no imagewidth
  46. * and imageheight are defined in the style. Value is 16.
  47. */
  48. mxSwimlane.prototype.imageSize = 16;
  49. /**
  50. * Function: isRoundable
  51. *
  52. * Adds roundable support.
  53. */
  54. mxSwimlane.prototype.isRoundable = function(c, x, y, w, h)
  55. {
  56. return true;
  57. };
  58. /**
  59. * Function: getTitleSize
  60. *
  61. * Returns the title size.
  62. */
  63. mxSwimlane.prototype.getTitleSize = function()
  64. {
  65. return Math.max(0, mxUtils.getValue(this.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE));
  66. };
  67. /**
  68. * Function: getLabelBounds
  69. *
  70. * Returns the bounding box for the label.
  71. */
  72. mxSwimlane.prototype.getLabelBounds = function(rect)
  73. {
  74. var start = this.getTitleSize();
  75. var bounds = new mxRectangle(rect.x, rect.y, rect.width, rect.height);
  76. var horizontal = this.isHorizontal();
  77. var flipH = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPH, 0) == 1;
  78. var flipV = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPV, 0) == 1;
  79. // East is default
  80. var shapeVertical = (this.direction == mxConstants.DIRECTION_NORTH ||
  81. this.direction == mxConstants.DIRECTION_SOUTH);
  82. var realHorizontal = horizontal == !shapeVertical;
  83. var realFlipH = !realHorizontal && flipH != (this.direction == mxConstants.DIRECTION_SOUTH ||
  84. this.direction == mxConstants.DIRECTION_WEST);
  85. var realFlipV = realHorizontal && flipV != (this.direction == mxConstants.DIRECTION_SOUTH ||
  86. this.direction == mxConstants.DIRECTION_WEST);
  87. // Shape is horizontal
  88. if (!shapeVertical)
  89. {
  90. var tmp = Math.min(bounds.height, start * this.scale);
  91. if (realFlipH || realFlipV)
  92. {
  93. bounds.y += bounds.height - tmp;
  94. }
  95. bounds.height = tmp;
  96. }
  97. else
  98. {
  99. var tmp = Math.min(bounds.width, start * this.scale);
  100. if (realFlipH || realFlipV)
  101. {
  102. bounds.x += bounds.width - tmp;
  103. }
  104. bounds.width = tmp;
  105. }
  106. return bounds;
  107. };
  108. /**
  109. * Function: getGradientBounds
  110. *
  111. * Returns the bounding box for the gradient box for this shape.
  112. */
  113. mxSwimlane.prototype.getGradientBounds = function(c, x, y, w, h)
  114. {
  115. var start = this.getTitleSize();
  116. if (this.isHorizontal())
  117. {
  118. start = Math.min(start, h);
  119. return new mxRectangle(x, y, w, start);
  120. }
  121. else
  122. {
  123. start = Math.min(start, w);
  124. return new mxRectangle(x, y, start, h);
  125. }
  126. };
  127. /**
  128. * Function: getSwimlaneArcSize
  129. *
  130. * Returns the arcsize for the swimlane.
  131. */
  132. mxSwimlane.prototype.getSwimlaneArcSize = function(w, h, start)
  133. {
  134. if (mxUtils.getValue(this.style, mxConstants.STYLE_ABSOLUTE_ARCSIZE, 0) == '1')
  135. {
  136. return Math.min(w / 2, Math.min(h / 2, mxUtils.getValue(this.style,
  137. mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2));
  138. }
  139. else
  140. {
  141. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  142. return start * f * 3;
  143. }
  144. };
  145. /**
  146. * Function: isHorizontal
  147. *
  148. * Paints the swimlane vertex shape.
  149. */
  150. mxSwimlane.prototype.isHorizontal = function()
  151. {
  152. return mxUtils.getValue(this.style, mxConstants.STYLE_HORIZONTAL, 1) == 1;
  153. };
  154. /**
  155. * Function: paintVertexShape
  156. *
  157. * Paints the swimlane vertex shape.
  158. */
  159. mxSwimlane.prototype.paintVertexShape = function(c, x, y, w, h)
  160. {
  161. var start = this.getTitleSize();
  162. var fill = mxUtils.getValue(this.style, mxConstants.STYLE_SWIMLANE_FILLCOLOR, mxConstants.NONE);
  163. var swimlaneLine = mxUtils.getValue(this.style, mxConstants.STYLE_SWIMLANE_LINE, 1) == 1;
  164. var r = 0;
  165. if (this.isHorizontal())
  166. {
  167. start = Math.min(start, h);
  168. }
  169. else
  170. {
  171. start = Math.min(start, w);
  172. }
  173. c.translate(x, y);
  174. if (!this.isRounded)
  175. {
  176. this.paintSwimlane(c, x, y, w, h, start, fill, swimlaneLine);
  177. }
  178. else
  179. {
  180. r = this.getSwimlaneArcSize(w, h, start);
  181. r = Math.min(((this.isHorizontal()) ? h : w) - start, Math.min(start, r));
  182. this.paintRoundedSwimlane(c, x, y, w, h, start, r, fill, swimlaneLine);
  183. }
  184. var sep = mxUtils.getValue(this.style, mxConstants.STYLE_SEPARATORCOLOR, mxConstants.NONE);
  185. this.paintSeparator(c, x, y, w, h, start, sep);
  186. if (this.image != null)
  187. {
  188. var bounds = this.getImageBounds(x, y, w, h);
  189. c.image(bounds.x - x, bounds.y - y, bounds.width, bounds.height,
  190. this.image, false, false, false);
  191. }
  192. if (this.glass)
  193. {
  194. c.setShadow(false);
  195. this.paintGlassEffect(c, 0, 0, w, start, r);
  196. }
  197. };
  198. /**
  199. * Function: paintSwimlane
  200. *
  201. * Paints the swimlane vertex shape.
  202. */
  203. mxSwimlane.prototype.paintSwimlane = function(c, x, y, w, h, start, fill, swimlaneLine)
  204. {
  205. c.begin();
  206. var events = true;
  207. if (this.style != null)
  208. {
  209. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  210. }
  211. if (!events && (this.fill == null || this.fill == mxConstants.NONE))
  212. {
  213. c.pointerEvents = false;
  214. }
  215. if (this.isHorizontal())
  216. {
  217. c.moveTo(0, start);
  218. c.lineTo(0, 0);
  219. c.lineTo(w, 0);
  220. c.lineTo(w, start);
  221. c.fillAndStroke();
  222. if (start < h)
  223. {
  224. if (fill == mxConstants.NONE || !events)
  225. {
  226. c.pointerEvents = false;
  227. }
  228. if (fill != mxConstants.NONE)
  229. {
  230. c.setFillColor(fill);
  231. }
  232. c.begin();
  233. c.moveTo(0, start);
  234. c.lineTo(0, h);
  235. c.lineTo(w, h);
  236. c.lineTo(w, start);
  237. if (fill == mxConstants.NONE)
  238. {
  239. c.stroke();
  240. }
  241. else
  242. {
  243. c.fillAndStroke();
  244. }
  245. }
  246. }
  247. else
  248. {
  249. c.moveTo(start, 0);
  250. c.lineTo(0, 0);
  251. c.lineTo(0, h);
  252. c.lineTo(start, h);
  253. c.fillAndStroke();
  254. if (start < w)
  255. {
  256. if (fill == mxConstants.NONE || !events)
  257. {
  258. c.pointerEvents = false;
  259. }
  260. if (fill != mxConstants.NONE)
  261. {
  262. c.setFillColor(fill);
  263. }
  264. c.begin();
  265. c.moveTo(start, 0);
  266. c.lineTo(w, 0);
  267. c.lineTo(w, h);
  268. c.lineTo(start, h);
  269. if (fill == mxConstants.NONE)
  270. {
  271. c.stroke();
  272. }
  273. else
  274. {
  275. c.fillAndStroke();
  276. }
  277. }
  278. }
  279. if (swimlaneLine)
  280. {
  281. this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE);
  282. }
  283. };
  284. /**
  285. * Function: paintRoundedSwimlane
  286. *
  287. * Paints the swimlane vertex shape.
  288. */
  289. mxSwimlane.prototype.paintRoundedSwimlane = function(c, x, y, w, h, start, r, fill, swimlaneLine)
  290. {
  291. c.begin();
  292. var events = true;
  293. if (this.style != null)
  294. {
  295. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  296. }
  297. if (!events && (this.fill == null || this.fill == mxConstants.NONE))
  298. {
  299. c.pointerEvents = false;
  300. }
  301. if (this.isHorizontal())
  302. {
  303. c.moveTo(w, start);
  304. c.lineTo(w, r);
  305. c.quadTo(w, 0, w - Math.min(w / 2, r), 0);
  306. c.lineTo(Math.min(w / 2, r), 0);
  307. c.quadTo(0, 0, 0, r);
  308. c.lineTo(0, start);
  309. c.fillAndStroke();
  310. if (start < h)
  311. {
  312. if (fill == mxConstants.NONE || !events)
  313. {
  314. c.pointerEvents = false;
  315. }
  316. if (fill != mxConstants.NONE)
  317. {
  318. c.setFillColor(fill);
  319. }
  320. c.begin();
  321. c.moveTo(0, start);
  322. c.lineTo(0, h - r);
  323. c.quadTo(0, h, Math.min(w / 2, r), h);
  324. c.lineTo(w - Math.min(w / 2, r), h);
  325. c.quadTo(w, h, w, h - r);
  326. c.lineTo(w, start);
  327. if (fill == mxConstants.NONE)
  328. {
  329. c.stroke();
  330. }
  331. else
  332. {
  333. c.fillAndStroke();
  334. }
  335. }
  336. }
  337. else
  338. {
  339. c.moveTo(start, 0);
  340. c.lineTo(r, 0);
  341. c.quadTo(0, 0, 0, Math.min(h / 2, r));
  342. c.lineTo(0, h - Math.min(h / 2, r));
  343. c.quadTo(0, h, r, h);
  344. c.lineTo(start, h);
  345. c.fillAndStroke();
  346. if (start < w)
  347. {
  348. if (fill == mxConstants.NONE || !events)
  349. {
  350. c.pointerEvents = false;
  351. }
  352. if (fill != mxConstants.NONE)
  353. {
  354. c.setFillColor(fill);
  355. }
  356. c.begin();
  357. c.moveTo(start, h);
  358. c.lineTo(w - r, h);
  359. c.quadTo(w, h, w, h - Math.min(h / 2, r));
  360. c.lineTo(w, Math.min(h / 2, r));
  361. c.quadTo(w, 0, w - r, 0);
  362. c.lineTo(start, 0);
  363. if (fill == mxConstants.NONE)
  364. {
  365. c.stroke();
  366. }
  367. else
  368. {
  369. c.fillAndStroke();
  370. }
  371. }
  372. }
  373. if (swimlaneLine)
  374. {
  375. this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE);
  376. }
  377. };
  378. /**
  379. * Function: paintDivider
  380. *
  381. * Paints the divider between swimlane title and content area.
  382. */
  383. mxSwimlane.prototype.paintDivider = function(c, x, y, w, h, start, shadow)
  384. {
  385. if (!shadow)
  386. {
  387. c.setShadow(false);
  388. }
  389. c.begin();
  390. if (this.isHorizontal())
  391. {
  392. c.moveTo(0, start);
  393. c.lineTo(w, start);
  394. }
  395. else
  396. {
  397. c.moveTo(start, 0);
  398. c.lineTo(start, h);
  399. }
  400. c.stroke();
  401. };
  402. /**
  403. * Function: paintSeparator
  404. *
  405. * Paints the vertical or horizontal separator line between swimlanes.
  406. */
  407. mxSwimlane.prototype.paintSeparator = function(c, x, y, w, h, start, color)
  408. {
  409. if (color != mxConstants.NONE)
  410. {
  411. c.setStrokeColor(color);
  412. c.setDashed(true);
  413. c.begin();
  414. if (this.isHorizontal())
  415. {
  416. c.moveTo(w, start);
  417. c.lineTo(w, h);
  418. }
  419. else
  420. {
  421. c.moveTo(start, 0);
  422. c.lineTo(w, 0);
  423. }
  424. c.stroke();
  425. c.setDashed(false);
  426. }
  427. };
  428. /**
  429. * Function: getImageBounds
  430. *
  431. * Paints the swimlane vertex shape.
  432. */
  433. mxSwimlane.prototype.getImageBounds = function(x, y, w, h)
  434. {
  435. if (this.isHorizontal())
  436. {
  437. return new mxRectangle(x + w - this.imageSize, y, this.imageSize, this.imageSize);
  438. }
  439. else
  440. {
  441. return new mxRectangle(x, y, this.imageSize, this.imageSize);
  442. }
  443. };
  444. __mxOutput.mxSwimlane = typeof mxSwimlane !== 'undefined' ? mxSwimlane : undefined;