mxDFD.js 14 KB

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