mxBasic.js 10 KB

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