mxDFD.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /**
  2. * Copyright (c) 2006-2018, JGraph Holdings Ltd
  3. */
  4. //**********************************************************************************************************************************************************
  5. // Start
  6. //**********************************************************************************************************************************************************
  7. /**
  8. * Extends mxShape.
  9. */
  10. function mxShapeDFDStart(bounds, fill, stroke, strokewidth)
  11. {
  12. mxShape.call(this);
  13. this.bounds = bounds;
  14. this.fill = fill;
  15. this.stroke = stroke;
  16. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  17. };
  18. /**
  19. * Extends mxShape.
  20. */
  21. mxUtils.extend(mxShapeDFDStart, mxShape);
  22. mxShapeDFDStart.prototype.cst = {START : 'mxgraph.dfd.start'};
  23. /**
  24. * Function: paintVertexShape
  25. *
  26. * Paints the vertex shape.
  27. */
  28. mxShapeDFDStart.prototype.paintVertexShape = function(c, x, y, w, h)
  29. {
  30. c.translate(x, y);
  31. var r = Math.min(h * 0.5, w * 0.5);
  32. c.begin();
  33. c.moveTo(w - r, h * 0.5 - r);
  34. c.arcTo(r, r, 0, 0, 1, w, h * 0.5);
  35. c.arcTo(r, r, 0, 0, 1, w - r, h * 0.5 + r);
  36. c.lineTo(r, h * 0.5 + r);
  37. c.arcTo(r, r, 0, 0, 1, 0, h * 0.5);
  38. c.arcTo(r, r, 0, 0, 1, r, h * 0.5 - r);
  39. c.close();
  40. c.fillAndStroke();
  41. };
  42. mxCellRenderer.registerShape(mxShapeDFDStart.prototype.cst.START, mxShapeDFDStart);
  43. mxShapeDFDStart.prototype.getConstraints = function(style, w, h)
  44. {
  45. var constr = [];
  46. var r = Math.min(h * 0.5, w * 0.5);
  47. constr.push(new mxConnectionConstraint(new mxPoint(0, 0.5), false));
  48. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 0.5), false, null, 0, -r));
  49. constr.push(new mxConnectionConstraint(new mxPoint(1, 0.5), false));
  50. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 0.5), false, null, 0, r));
  51. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, r * 0.293, h * 0.5 - r * 0.707));
  52. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - r * 0.293, h * 0.5 - r * 0.707));
  53. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - r * 0.293, h * 0.5 + r * 0.707));
  54. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, r * 0.293, h * 0.5 + r * 0.707));
  55. if (w >= 4 * h)
  56. {
  57. constr.push(new mxConnectionConstraint(new mxPoint(0.25, 0), false));
  58. constr.push(new mxConnectionConstraint(new mxPoint(0.75, 0), false));
  59. constr.push(new mxConnectionConstraint(new mxPoint(0.75, 1), false));
  60. constr.push(new mxConnectionConstraint(new mxPoint(0.25, 1), false));
  61. }
  62. return (constr);
  63. }
  64. //**********************************************************************************************************************************************************
  65. //Archive
  66. //**********************************************************************************************************************************************************
  67. /**
  68. * Extends mxShape.
  69. */
  70. function mxShapeDFDArchive(bounds, fill, stroke, strokewidth)
  71. {
  72. mxShape.call(this);
  73. this.bounds = bounds;
  74. this.fill = fill;
  75. this.stroke = stroke;
  76. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  77. };
  78. /**
  79. * Extends mxShape.
  80. */
  81. mxUtils.extend(mxShapeDFDArchive, mxShape);
  82. mxShapeDFDArchive.prototype.cst = {ARCHIVE : 'mxgraph.dfd.archive'};
  83. /**
  84. * Function: paintVertexShape
  85. *
  86. * Paints the vertex shape.
  87. */
  88. mxShapeDFDArchive.prototype.paintVertexShape = function(c, x, y, w, h)
  89. {
  90. c.translate(x, y);
  91. c.begin();
  92. c.moveTo(0,0);
  93. c.lineTo(w, 0);
  94. c.lineTo(w * 0.5, h);
  95. c.close();
  96. c.fillAndStroke();
  97. c.setShadow(false);
  98. c.begin();
  99. c.moveTo(w * 0.1, h * 0.2);
  100. c.lineTo(w * 0.9, h * 0.2);
  101. c.stroke();
  102. };
  103. mxCellRenderer.registerShape(mxShapeDFDArchive.prototype.cst.ARCHIVE, mxShapeDFDArchive);
  104. mxShapeDFDArchive.prototype.getConstraints = function(style, w, h)
  105. {
  106. var constr = [];
  107. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false));
  108. constr.push(new mxConnectionConstraint(new mxPoint(0.25, 0), false));
  109. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 0), false));
  110. constr.push(new mxConnectionConstraint(new mxPoint(0.75, 0), false));
  111. constr.push(new mxConnectionConstraint(new mxPoint(1, 0), false));
  112. constr.push(new mxConnectionConstraint(new mxPoint(0.875, 0.25), false));
  113. constr.push(new mxConnectionConstraint(new mxPoint(0.75, 0.5), false));
  114. constr.push(new mxConnectionConstraint(new mxPoint(0.625, 0.75), false));
  115. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 1), false));
  116. constr.push(new mxConnectionConstraint(new mxPoint(0.375, 0.75), false));
  117. constr.push(new mxConnectionConstraint(new mxPoint(0.25, 0.5), false));
  118. constr.push(new mxConnectionConstraint(new mxPoint(0.125, 0.25), false));
  119. return (constr);
  120. }
  121. //**********************************************************************************************************************************************************
  122. //Check2
  123. //**********************************************************************************************************************************************************
  124. /**
  125. * Extends mxShape.
  126. */
  127. function mxShapeDFDCheck2(bounds, fill, stroke, strokewidth)
  128. {
  129. mxShape.call(this);
  130. this.bounds = bounds;
  131. this.fill = fill;
  132. this.stroke = stroke;
  133. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  134. };
  135. /**
  136. * Extends mxShape.
  137. */
  138. mxUtils.extend(mxShapeDFDCheck2, mxShape);
  139. mxShapeDFDCheck2.prototype.cst = {CHECK2 : 'mxgraph.dfd.check2'};
  140. /**
  141. * Function: paintVertexShape
  142. *
  143. * Paints the vertex shape.
  144. */
  145. mxShapeDFDCheck2.prototype.paintVertexShape = function(c, x, y, w, h)
  146. {
  147. c.translate(x, y);
  148. var size = Math.min(h * 0.5, w * 0.5);
  149. c.begin();
  150. c.moveTo(0, h * 0.5);
  151. c.lineTo(size, 0);
  152. c.lineTo(w - size, 0);
  153. c.lineTo(w, h * 0.5);
  154. c.lineTo(w - size, h);
  155. c.lineTo(size, h);
  156. c.lineTo(0, h * 0.5);
  157. c.close();
  158. c.fillAndStroke();
  159. c.setShadow(false);
  160. c.begin();
  161. c.moveTo(w - size, 0);
  162. c.lineTo(w - 2 * size, h * 0.5);
  163. c.lineTo(w - size, h);
  164. c.stroke();
  165. };
  166. mxCellRenderer.registerShape(mxShapeDFDCheck2.prototype.cst.CHECK2, mxShapeDFDCheck2);
  167. mxShapeDFDCheck2.prototype.getConstraints = function(style, w, h)
  168. {
  169. var constr = [];
  170. var size = Math.min(h * 0.5, w * 0.5);
  171. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 0), false));
  172. constr.push(new mxConnectionConstraint(new mxPoint(1, 0.5), false));
  173. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 1), false));
  174. constr.push(new mxConnectionConstraint(new mxPoint(0, 0.5), false));
  175. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, size * 0.5, h * 0.25));
  176. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - size * 0.5, h * 0.25));
  177. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, size * 0.5, h * 0.75));
  178. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - size * 0.5, h * 0.75));
  179. if (w > h)
  180. {
  181. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, size, 0));
  182. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - size, 0));
  183. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, size, h));
  184. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - size, h));
  185. }
  186. if(size * 4 <= w)
  187. {
  188. constr.push(new mxConnectionConstraint(new mxPoint(0.25, 0), false));
  189. constr.push(new mxConnectionConstraint(new mxPoint(0.75, 0), false));
  190. constr.push(new mxConnectionConstraint(new mxPoint(0.25, 1), false));
  191. constr.push(new mxConnectionConstraint(new mxPoint(0.75, 1), false));
  192. }
  193. return (constr);
  194. }
  195. //**********************************************************************************************************************************************************
  196. //Data Store with ID
  197. //**********************************************************************************************************************************************************
  198. /**
  199. * Extends mxShape.
  200. */
  201. function mxShapeDFDDataStoreID(bounds, fill, stroke, strokewidth)
  202. {
  203. mxShape.call(this);
  204. this.bounds = bounds;
  205. this.fill = fill;
  206. this.stroke = stroke;
  207. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  208. };
  209. /**
  210. * Extends mxShape.
  211. */
  212. mxUtils.extend(mxShapeDFDDataStoreID, mxShape);
  213. mxShapeDFDDataStoreID.prototype.cst = {DATA_STORE_ID : 'mxgraph.dfd.dataStoreID'};
  214. /**
  215. * Function: paintVertexShape
  216. *
  217. * Paints the vertex shape.
  218. */
  219. mxShapeDFDDataStoreID.prototype.paintVertexShape = function(c, x, y, w, h)
  220. {
  221. c.translate(x, y);
  222. var size = Math.min(h * 0.5, w * 0.5);
  223. c.begin();
  224. c.moveTo(w, h);
  225. c.lineTo(0, h);
  226. c.lineTo(0, 0);
  227. c.lineTo(w, 0);
  228. c.fillAndStroke();
  229. c.setShadow(false);
  230. var s = Math.min(30, w);
  231. c.begin();
  232. c.moveTo(s, 0);
  233. c.lineTo(s, h);
  234. c.stroke();
  235. };
  236. mxCellRenderer.registerShape(mxShapeDFDDataStoreID.prototype.cst.DATA_STORE_ID, mxShapeDFDDataStoreID);
  237. mxShapeDFDDataStoreID.prototype.constraints = null;
  238. //**********************************************************************************************************************************************************
  239. //External Entity
  240. //**********************************************************************************************************************************************************
  241. /**
  242. * Extends mxShape.
  243. */
  244. function mxShapeDFDExternalEntity(bounds, fill, stroke, strokewidth)
  245. {
  246. mxShape.call(this);
  247. this.bounds = bounds;
  248. this.fill = fill;
  249. this.stroke = stroke;
  250. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  251. };
  252. /**
  253. * Extends mxShape.
  254. */
  255. mxUtils.extend(mxShapeDFDExternalEntity, mxShape);
  256. mxShapeDFDExternalEntity.prototype.cst = {EXTERNAL_ENTITY : 'mxgraph.dfd.externalEntity'};
  257. /**
  258. * Function: paintVertexShape
  259. *
  260. * Paints the vertex shape.
  261. */
  262. mxShapeDFDExternalEntity.prototype.paintVertexShape = function(c, x, y, w, h)
  263. {
  264. c.translate(x, y);
  265. var size = 10;
  266. c.begin();
  267. c.moveTo(0, 0);
  268. c.lineTo(w - size, 0);
  269. c.lineTo(w, size);
  270. c.lineTo(w, h);
  271. c.lineTo(size, h);
  272. c.lineTo(0, h - size);
  273. c.close();
  274. c.fillAndStroke();
  275. c.setShadow(false);
  276. c.setFillColor('#000000');
  277. c.setAlpha(0.5);
  278. c.begin();
  279. c.moveTo(0, 0);
  280. c.lineTo(w - size, 0);
  281. c.lineTo(w, size);
  282. c.lineTo(size, size);
  283. c.lineTo(size, h);
  284. c.lineTo(0, h - size);
  285. c.close();
  286. c.fill();
  287. var opacity = parseFloat(mxUtils.getValue(this.style, 'opacity', '100'));
  288. c.setAlpha(opacity / 100);
  289. c.begin();
  290. c.moveTo(0, 0);
  291. c.lineTo(w - size, 0);
  292. c.lineTo(w, size);
  293. c.lineTo(w, h);
  294. c.lineTo(size, h);
  295. c.lineTo(0, h - size);
  296. c.close();
  297. c.moveTo(size, h);
  298. c.lineTo(size, size);
  299. c.lineTo(w, size);
  300. c.moveTo(0, 0);
  301. c.lineTo(size, size);
  302. c.stroke();
  303. };
  304. mxCellRenderer.registerShape(mxShapeDFDExternalEntity.prototype.cst.EXTERNAL_ENTITY, mxShapeDFDExternalEntity);
  305. mxShapeDFDExternalEntity.prototype.getConstraints = function(style, w, h)
  306. {
  307. var constr = [];
  308. var size = 10;
  309. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false));
  310. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, (w - size) * 0.25, 0));
  311. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, (w - size) * 0.5, 0));
  312. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, (w - size) * 0.75, 0));
  313. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - size, 0));
  314. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, size, h));
  315. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, (w - size) * 0.25 + size, h));
  316. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, (w - size) * 0.5 + size, h));
  317. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, (w - size) * 0.75 + size, h));
  318. constr.push(new mxConnectionConstraint(new mxPoint(1, 1), false));
  319. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w, size));
  320. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w, size + (h - size) * 0.25));
  321. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w, size + (h - size) * 0.5));
  322. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w, size + (h - size) * 0.75));
  323. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, 0, (h - size) * 0.25));
  324. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, 0, (h - size) * 0.5));
  325. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, 0, (h - size) * 0.75));
  326. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, 0, h - size));
  327. return (constr);
  328. }
  329. //**********************************************************************************************************************************************************
  330. //Loop
  331. //**********************************************************************************************************************************************************
  332. /**
  333. * Extends mxShape.
  334. */
  335. function mxShapeDFDLoop(bounds, fill, stroke, strokewidth)
  336. {
  337. mxShape.call(this);
  338. this.bounds = bounds;
  339. this.fill = fill;
  340. this.stroke = stroke;
  341. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  342. };
  343. /**
  344. * Extends mxShape.
  345. */
  346. mxUtils.extend(mxShapeDFDLoop, mxShape);
  347. mxShapeDFDLoop.prototype.cst = {LOOP : 'mxgraph.dfd.loop'};
  348. /**
  349. * Function: paintVertexShape
  350. *
  351. * Paints the vertex shape.
  352. */
  353. mxShapeDFDLoop.prototype.paintVertexShape = function(c, x, y, w, h)
  354. {
  355. c.translate(x, y);
  356. var r = Math.min(h * 0.8, w * 0.8);
  357. c.begin();
  358. c.moveTo(w - r * 0.25, 0);
  359. c.arcTo(r, r, 0, 0, 1, w - r * 0.25, h);
  360. c.lineTo(r * 0.25, h);
  361. c.arcTo(r, r, 0, 0, 1, r * 0.25, 0);
  362. c.close();
  363. c.fillAndStroke();
  364. };
  365. mxCellRenderer.registerShape(mxShapeDFDLoop.prototype.cst.LOOP, mxShapeDFDLoop);
  366. mxShapeDFDLoop.prototype.getConstraints = function(style, w, h)
  367. {
  368. var constr = [];
  369. var r = Math.min(h * 0.8, w * 0.8);
  370. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - r * 0.25, 0));
  371. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, w - r * 0.25, h));
  372. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, r * 0.25, 0));
  373. constr.push(new mxConnectionConstraint(new mxPoint(0, 0), false, null, r * 0.25, h));
  374. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 0), false));
  375. constr.push(new mxConnectionConstraint(new mxPoint(0.5, 1), false));
  376. return (constr);
  377. }