mxBasic.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /**
  2. * $Id: mxBasic.js,v 1.5 2016/04/1 12:32:06 mate Exp $
  3. * Copyright (c) 2006-2016, JGraph Ltd
  4. */
  5. //**********************************************************************************************************************************************************
  6. //Cross
  7. //**********************************************************************************************************************************************************
  8. /**
  9. * Extends mxShape.
  10. */
  11. function mxShapeBasicCross(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. this.dx = 0.5;
  19. };
  20. /**
  21. * Extends mxShape.
  22. */
  23. mxUtils.extend(mxShapeBasicCross, mxActor);
  24. mxShapeBasicCross.prototype.cst = {
  25. CROSS : 'mxgraph.basic.cross2'
  26. };
  27. /**
  28. * Function: paintVertexShape
  29. *
  30. * Paints the vertex shape.
  31. */
  32. mxShapeBasicCross.prototype.paintVertexShape = function(c, x, y, w, h)
  33. {
  34. c.translate(x, y);
  35. var dx = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  36. c.begin();
  37. c.moveTo(w * 0.5 + dx, 0);
  38. c.lineTo(w * 0.5 + dx, h * 0.5 - dx);
  39. c.lineTo(w, h * 0.5 - dx);
  40. c.lineTo(w, h * 0.5 + dx);
  41. c.lineTo(w * 0.5 + dx, h * 0.5 + dx);
  42. c.lineTo(w * 0.5 + dx, h);
  43. c.lineTo(w * 0.5 - dx, h);
  44. c.lineTo(w * 0.5 - dx, h * 0.5 + dx);
  45. c.lineTo(0, h * 0.5 + dx);
  46. c.lineTo(0, h * 0.5 - dx);
  47. c.lineTo(w * 0.5 - dx, h * 0.5 - dx);
  48. c.lineTo(w * 0.5 - dx, 0);
  49. c.close();
  50. c.fillAndStroke();
  51. };
  52. mxCellRenderer.registerShape(mxShapeBasicCross.prototype.cst.CROSS, mxShapeBasicCross);
  53. mxShapeBasicCross.prototype.constraints = null;
  54. Graph.handleFactory[mxShapeBasicCross.prototype.cst.CROSS] = function(state)
  55. {
  56. var handles = [Graph.createHandle(state, ['dx'], function(bounds)
  57. {
  58. var dx = Math.max(0, Math.min(bounds.width / 2, bounds.width / 2, parseFloat(mxUtils.getValue(this.state.style, 'dx', this.dx))));
  59. return new mxPoint(bounds.x + bounds.width / 2 + dx, bounds.y + bounds.height / 2 - dx);
  60. }, function(bounds, pt)
  61. {
  62. this.state.style['dx'] = Math.round(100 * Math.max(0, Math.min(bounds.height / 2, bounds.width / 2, pt.x - bounds.x - bounds.width / 2))) / 100;
  63. })];
  64. return handles;
  65. }
  66. //**********************************************************************************************************************************************************
  67. //Rectangular Callout
  68. //**********************************************************************************************************************************************************
  69. /**
  70. * Extends mxShape.
  71. */
  72. function mxShapeBasicRectCallout(bounds, fill, stroke, strokewidth)
  73. {
  74. mxShape.call(this);
  75. this.bounds = bounds;
  76. this.fill = fill;
  77. this.stroke = stroke;
  78. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  79. this.dy = 0.5;
  80. this.dx = 0.5;
  81. };
  82. /**
  83. * Extends mxShape.
  84. */
  85. mxUtils.extend(mxShapeBasicRectCallout, mxActor);
  86. mxShapeBasicRectCallout.prototype.cst = {
  87. RECT_CALLOUT : 'mxgraph.basic.rectCallout'
  88. };
  89. /**
  90. * Function: paintVertexShape
  91. *
  92. * Paints the vertex shape.
  93. */
  94. mxShapeBasicRectCallout.prototype.paintVertexShape = function(c, x, y, w, h)
  95. {
  96. c.translate(x, y);
  97. var dx = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  98. var dy = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))));
  99. var dh = 20;
  100. c.begin();
  101. c.moveTo(dx - dy * 0.5, h - dy);
  102. c.lineTo(0, h - dy);
  103. c.lineTo(0, 0);
  104. c.lineTo(w, 0);
  105. c.lineTo(w, h - dy);
  106. c.lineTo(dx + dy * 0.5, h - dy);
  107. c.lineTo(dx - dy, h);
  108. c.close();
  109. c.fillAndStroke();
  110. };
  111. mxCellRenderer.registerShape(mxShapeBasicRectCallout.prototype.cst.RECT_CALLOUT, mxShapeBasicRectCallout);
  112. mxShapeBasicRectCallout.prototype.constraints = null;
  113. Graph.handleFactory[mxShapeBasicRectCallout.prototype.cst.RECT_CALLOUT] = function(state)
  114. {
  115. var handles = [Graph.createHandle(state, ['dx', 'dy'], function(bounds)
  116. {
  117. var dx = Math.max(0, Math.min(bounds.width, parseFloat(mxUtils.getValue(this.state.style, 'dx', this.dx))));
  118. var dy = Math.max(0, Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy))));
  119. return new mxPoint(bounds.x + dx, bounds.y + bounds.height - dy);
  120. }, function(bounds, pt)
  121. {
  122. var y = parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy)) * 0.6;
  123. this.state.style['dx'] = Math.round(100 * Math.max(y, Math.min(bounds.width - y, pt.x - bounds.x))) / 100;
  124. this.state.style['dy'] = Math.round(100 * Math.max(0, Math.min(bounds.height, bounds.y + bounds.height - pt.y))) / 100;
  125. })];
  126. return handles;
  127. }
  128. //**********************************************************************************************************************************************************
  129. //Rounded Rectangular Callout
  130. //**********************************************************************************************************************************************************
  131. /**
  132. * Extends mxShape.
  133. */
  134. function mxShapeBasicRoundRectCallout(bounds, fill, stroke, strokewidth)
  135. {
  136. mxShape.call(this);
  137. this.bounds = bounds;
  138. this.fill = fill;
  139. this.stroke = stroke;
  140. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  141. this.dy = 0.5;
  142. this.dx = 0.5;
  143. this.size = 10;
  144. };
  145. /**
  146. * Extends mxShape.
  147. */
  148. mxUtils.extend(mxShapeBasicRoundRectCallout, mxActor);
  149. mxShapeBasicRoundRectCallout.prototype.cst = {
  150. ROUND_RECT_CALLOUT : 'mxgraph.basic.roundRectCallout'
  151. };
  152. /**
  153. * Function: paintVertexShape
  154. *
  155. * Paints the vertex shape.
  156. */
  157. mxShapeBasicRoundRectCallout.prototype.paintVertexShape = function(c, x, y, w, h)
  158. {
  159. c.translate(x, y);
  160. var dx = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  161. var dy = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))));
  162. var r = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  163. r = Math.min((h - dy) / 2, w / 2, r);
  164. dx = Math.max(r + dy * 0.5, dx);
  165. dx = Math.min(w - r - dy * 0.5, dx);
  166. c.begin();
  167. c.moveTo(dx - dy * 0.5, h - dy);
  168. c.lineTo(r, h - dy);
  169. c.arcTo(r, r, 0, 0, 1, 0, h - dy - r);
  170. c.lineTo(0, r);
  171. c.arcTo(r, r, 0, 0, 1, r, 0);
  172. c.lineTo(w - r, 0);
  173. c.arcTo(r, r, 0, 0, 1, w, r);
  174. c.lineTo(w, h - dy - r);
  175. c.arcTo(r, r, 0, 0, 1, w - r, h - dy);
  176. c.lineTo(dx + dy * 0.5, h - dy);
  177. c.arcTo(1.9 * dy, 1.4 * dy, 0, 0, 1, dx - dy, h);
  178. c.arcTo(0.9 * dy, 1.4 * dy, 0, 0, 0, dx - dy * 0.5, h - dy);
  179. c.close();
  180. c.fillAndStroke();
  181. };
  182. mxCellRenderer.registerShape(mxShapeBasicRoundRectCallout.prototype.cst.ROUND_RECT_CALLOUT, mxShapeBasicRoundRectCallout);
  183. mxShapeBasicRoundRectCallout.prototype.constraints = null;
  184. Graph.handleFactory[mxShapeBasicRoundRectCallout.prototype.cst.ROUND_RECT_CALLOUT] = function(state)
  185. {
  186. var handles = [Graph.createHandle(state, ['dx', 'dy'], function(bounds)
  187. {
  188. var dx = Math.max(0, Math.min(bounds.width, parseFloat(mxUtils.getValue(this.state.style, 'dx', this.dx))));
  189. var dy = Math.max(0, Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy))));
  190. return new mxPoint(bounds.x + dx, bounds.y + bounds.height - dy);
  191. }, function(bounds, pt)
  192. {
  193. var y = parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy)) * 0.6;
  194. this.state.style['dx'] = Math.round(100 * Math.max(y, Math.min(bounds.width - y, pt.x - bounds.x))) / 100;
  195. this.state.style['dy'] = Math.round(100 * Math.max(0, Math.min(bounds.height, bounds.y + bounds.height - pt.y))) / 100;
  196. })];
  197. var handle2 = Graph.createHandle(state, ['size'], function(bounds)
  198. {
  199. var size = Math.max(0, Math.min(bounds.width, parseFloat(mxUtils.getValue(this.state.style, 'size', this.size))));
  200. return new mxPoint(bounds.x + bounds.width - size, bounds.y + 10);
  201. }, function(bounds, pt)
  202. {
  203. var dy = parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy));
  204. this.state.style['size'] = Math.round(100 * Math.max(0, Math.min(bounds.width / 2, (bounds.height - dy) / 2, bounds.x + bounds.width - pt.x))) / 100;
  205. });
  206. handles.push(handle2);
  207. return handles;
  208. }
  209. //**********************************************************************************************************************************************************
  210. //Wave
  211. //**********************************************************************************************************************************************************
  212. /**
  213. * Extends mxShape.
  214. */
  215. function mxShapeBasicWave(bounds, fill, stroke, strokewidth)
  216. {
  217. mxShape.call(this);
  218. this.bounds = bounds;
  219. this.fill = fill;
  220. this.stroke = stroke;
  221. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  222. this.dy = 0.5;
  223. };
  224. /**
  225. * Extends mxShape.
  226. */
  227. mxUtils.extend(mxShapeBasicWave, mxActor);
  228. mxShapeBasicWave.prototype.cst = {
  229. WAVE : 'mxgraph.basic.wave2'
  230. };
  231. /**
  232. * Function: paintVertexShape
  233. *
  234. * Paints the vertex shape.
  235. */
  236. mxShapeBasicWave.prototype.paintVertexShape = function(c, x, y, w, h)
  237. {
  238. c.translate(x, y);
  239. var dy = h * Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))));
  240. var fy = 1.4
  241. c.begin();
  242. c.moveTo(0, dy / 2);
  243. c.quadTo(w / 6, dy * (1 - fy), w / 3, dy / 2);
  244. c.quadTo(w / 2, dy * fy, w * 2 / 3, dy / 2);
  245. c.quadTo(w * 5 / 6, dy * (1 - fy), w, dy / 2);
  246. c.lineTo(w, h - dy / 2);
  247. c.quadTo(w * 5 / 6, h - dy * fy, w * 2 / 3, h - dy / 2);
  248. c.quadTo(w / 2, h - dy * (1 - fy), w / 3, h - dy / 2);
  249. c.quadTo(w / 6, h - dy * fy, 0, h - dy / 2);
  250. c.close();
  251. c.fillAndStroke();
  252. };
  253. mxCellRenderer.registerShape(mxShapeBasicWave.prototype.cst.WAVE, mxShapeBasicWave);
  254. mxShapeBasicWave.prototype.constraints = null;
  255. Graph.handleFactory[mxShapeBasicWave.prototype.cst.WAVE] = function(state)
  256. {
  257. var handles = [Graph.createHandle(state, ['dy'], function(bounds)
  258. {
  259. var dy = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy))));
  260. return new mxPoint(bounds.x + bounds.width / 2, bounds.y + dy * bounds.height);
  261. }, function(bounds, pt)
  262. {
  263. this.state.style['dy'] = Math.round(100 * Math.max(0, Math.min(1, (pt.y - bounds.y) / bounds.height))) / 100;
  264. })];
  265. return handles;
  266. }