mxER.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. /**
  2. * Copyright (c) 2006-2010, JGraph Holdings Ltd
  3. */
  4. //TODO markers.html probably isn't needed, because it was used for testing during development before the new canvas was introduced
  5. //**********************************************************************************************************************************************************
  6. //Entity
  7. //**********************************************************************************************************************************************************
  8. /**
  9. * Extends mxShape.
  10. */
  11. function mxShapeEREntity(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(mxShapeEREntity, mxShape);
  23. /**
  24. * Function: paintVertexShape
  25. *
  26. * Paints the vertex shape.
  27. */
  28. mxShapeEREntity.prototype.paintVertexShape = function(c, x, y, w, h)
  29. {
  30. var mainText = mxUtils.getValue(this.style, 'buttonText', 'Entity');
  31. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  32. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  33. c.translate(x, y);
  34. var rSize = 10;
  35. w = Math.max(w, 2 * rSize);
  36. h = Math.max(h, 2 * rSize);
  37. this.background(c, x, y, w, h, rSize, fontColor);
  38. c.setShadow(false);
  39. this.mainText(c, x, y, w, h, mainText, fontSize, fontColor);
  40. };
  41. mxShapeEREntity.prototype.background = function(c, x, y, w, h, rSize, fontColor)
  42. {
  43. var buttonStyle = mxUtils.getValue(this.style, 'buttonStyle', 'round').toString();
  44. if (buttonStyle === 'round')
  45. {
  46. c.begin();
  47. c.moveTo(0, rSize);
  48. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  49. c.lineTo(w - rSize, 0);
  50. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  51. c.lineTo(w, h - rSize);
  52. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  53. c.lineTo(rSize, h);
  54. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  55. c.close();
  56. c.fillAndStroke();
  57. }
  58. else if (buttonStyle === 'rect')
  59. {
  60. c.begin();
  61. c.moveTo(0, 0);
  62. c.lineTo(w, 0);
  63. c.lineTo(w, h);
  64. c.lineTo(0, h);
  65. c.close();
  66. c.fillAndStroke();
  67. }
  68. else if (buttonStyle === 'dblFrame')
  69. {
  70. var fillColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  71. c.setFillColor(fillColor);
  72. c.begin();
  73. c.moveTo(0, 0);
  74. c.lineTo(w, 0);
  75. c.lineTo(w, h);
  76. c.lineTo(0, h);
  77. c.close();
  78. c.fillAndStroke();
  79. rSize = Math.min(w, h);
  80. c.begin();
  81. c.moveTo(rSize * 0.1, rSize * 0.1);
  82. c.lineTo(w - rSize * 0.1, rSize * 0.1);
  83. c.lineTo(w - rSize * 0.1, h - rSize * 0.1);
  84. c.lineTo(rSize * 0.1, h - rSize * 0.1);
  85. c.close();
  86. c.stroke();
  87. }
  88. };
  89. mxShapeEREntity.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  90. {
  91. c.begin();
  92. c.setFontSize(fontSize);
  93. c.setFontColor(fontColor);
  94. c.text(w * 0.5, h * 0.5, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  95. };
  96. mxCellRenderer.registerShape('mxgraph.er.entity', mxShapeEREntity);
  97. mxShapeEREntity.prototype.constraints = [
  98. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  99. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  100. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  101. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  102. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  103. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  104. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  105. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  106. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  107. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  108. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  109. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  110. ];
  111. //**********************************************************************************************************************************************************
  112. //Entity Extended
  113. //**********************************************************************************************************************************************************
  114. /**
  115. * Extends mxShape.
  116. */
  117. function mxShapeEREntityExt(bounds, fill, stroke, strokewidth)
  118. {
  119. mxShape.call(this);
  120. this.bounds = bounds;
  121. this.fill = fill;
  122. this.stroke = stroke;
  123. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  124. };
  125. /**
  126. * Extends mxShape.
  127. */
  128. mxUtils.extend(mxShapeEREntityExt, mxShape);
  129. /**
  130. * Function: paintVertexShape
  131. *
  132. * Paints the vertex shape.
  133. */
  134. mxShapeEREntityExt.prototype.paintVertexShape = function(c, x, y, w, h)
  135. {
  136. var mainText = mxUtils.getValue(this.style, 'buttonText', 'Entity');
  137. var attributes = mxUtils.getValue(this.style, 'subText', '+ attribute 1,+ attribute 2,+ attribute 3').toString().split(',');
  138. var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#666666');
  139. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  140. var mainColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#008cff');
  141. var attrColor = mxUtils.getValue(this.style, 'fillColor2', '#ffffff');
  142. var maxTextWidth = 0;
  143. c.translate(x, y);
  144. var rSize = 10;
  145. var barY = fontSize * 1.25;
  146. for (var i = 0; i < attributes.length; i++)
  147. {
  148. var currWidth = mxUtils.getSizeForString(attributes[i], fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  149. if (currWidth > maxTextWidth)
  150. {
  151. maxTextWidth = currWidth;
  152. }
  153. }
  154. w = Math.max(w, 2 * rSize, maxTextWidth + rSize);
  155. h = Math.max(h, 2 * rSize, (attributes.length + 1) * barY);
  156. this.background(c, x, y, w, h, rSize);
  157. c.setShadow(false);
  158. this.shapes(c, x, y, w, h, fontSize, mainColor, attrColor, rSize, barY);
  159. this.mainText(c, x, y, w, h, mainText, fontSize, attrColor);
  160. this.attrText(c, x, y, w, h, attributes, fontSize, strokeColor, barY, rSize);
  161. };
  162. mxShapeEREntityExt.prototype.background = function(c, x, y, w, h, rSize)
  163. {
  164. var buttonStyle = mxUtils.getValue(this.style, 'buttonStyle', 'round').toString();
  165. c.begin();
  166. if (buttonStyle === 'round')
  167. {
  168. c.moveTo(0, rSize);
  169. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  170. c.lineTo(w - rSize, 0);
  171. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  172. c.lineTo(w, h - rSize);
  173. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  174. c.lineTo(rSize, h);
  175. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  176. }
  177. else if (buttonStyle === 'rect')
  178. {
  179. c.moveTo(0, 0);
  180. c.lineTo(w, 0);
  181. c.lineTo(w, h);
  182. c.lineTo(0, h);
  183. }
  184. c.close();
  185. c.fillAndStroke();
  186. };
  187. mxShapeEREntityExt.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  188. {
  189. c.begin();
  190. c.setFontSize(fontSize);
  191. c.setFontColor(fontColor);
  192. c.text(w * 0.5, fontSize * 0.5, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  193. };
  194. mxShapeEREntityExt.prototype.shapes = function(c, x, y, w, h, fontSize, mainColor, attrColor, rSize, barY)
  195. {
  196. var buttonStyle = mxUtils.getValue(this.style, 'buttonStyle', 'round').toString();
  197. if (buttonStyle === 'round')
  198. {
  199. c.begin();
  200. c.moveTo(0, rSize);
  201. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  202. c.lineTo(w - rSize, 0);
  203. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  204. c.lineTo(w, barY);
  205. c.lineTo(0, barY);
  206. c.close();
  207. c.fill();
  208. c.setFillColor(attrColor);
  209. c.begin();
  210. c.moveTo(w, barY);
  211. c.lineTo(w, h - rSize);
  212. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  213. c.lineTo(rSize, h);
  214. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  215. c.lineTo(0, barY);
  216. c.close();
  217. c.fill();
  218. }
  219. else if (buttonStyle === 'rect')
  220. {
  221. c.begin();
  222. c.moveTo(0, 0);
  223. c.lineTo(w, 0);
  224. c.lineTo(w, barY);
  225. c.lineTo(0, barY);
  226. c.close();
  227. c.fill();
  228. c.setFillColor(attrColor);
  229. c.begin();
  230. c.moveTo(0, barY);
  231. c.lineTo(w, barY);
  232. c.lineTo(w, h);
  233. c.lineTo(0, h);
  234. c.close();
  235. c.fill();
  236. }
  237. c.begin();
  238. if (buttonStyle === 'round')
  239. {
  240. c.moveTo(0, rSize);
  241. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  242. c.lineTo(w - rSize, 0);
  243. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  244. c.lineTo(w, h - rSize);
  245. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  246. c.lineTo(rSize, h);
  247. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  248. }
  249. else if (buttonStyle === 'rect')
  250. {
  251. c.moveTo(0, 0);
  252. c.lineTo(w, 0);
  253. c.lineTo(w, h);
  254. c.lineTo(0, h);
  255. }
  256. c.close();
  257. c.stroke();
  258. };
  259. mxShapeEREntityExt.prototype.attrText = function(c, x, y, w, h, attributes, fontSize, fontColor, barY, rSize)
  260. {
  261. for (var i = 0; i < attributes.length; i++)
  262. {
  263. c.begin();
  264. c.setFontSize(fontSize);
  265. c.setFontColor(fontColor);
  266. c.text(rSize * 0.5, (i + 1.5) * barY, 0, 0, attributes[i], mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  267. }
  268. };
  269. mxCellRenderer.registerShape('mxgraph.er.entityExt', mxShapeEREntityExt);
  270. mxShapeEREntityExt.prototype.constraints = [
  271. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  272. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  273. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  274. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  275. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  276. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  277. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  278. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  279. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  280. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  281. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  282. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  283. ];
  284. //**********************************************************************************************************************************************************
  285. //Attribute
  286. //**********************************************************************************************************************************************************
  287. /**
  288. * Extends mxShape.
  289. */
  290. function mxShapeERAttribute(bounds, fill, stroke, strokewidth)
  291. {
  292. mxShape.call(this);
  293. this.bounds = bounds;
  294. this.fill = fill;
  295. this.stroke = stroke;
  296. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  297. };
  298. /**
  299. * Extends mxShape.
  300. */
  301. mxUtils.extend(mxShapeERAttribute, mxShape);
  302. /**
  303. * Function: paintVertexShape
  304. *
  305. * Paints the vertex shape.
  306. */
  307. mxShapeERAttribute.prototype.paintVertexShape = function(c, x, y, w, h)
  308. {
  309. var mainText = mxUtils.getValue(this.style, 'buttonText', 'Entity');
  310. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  311. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  312. c.translate(x, y);
  313. var rSize = 10;
  314. w = Math.max(w, 2 * rSize);
  315. h = Math.max(h, 2 * rSize);
  316. this.background(c, x, y, w, h, rSize, fontColor);
  317. c.setShadow(false);
  318. this.mainText(c, x, y, w, h, mainText, fontSize, fontColor);
  319. };
  320. mxShapeERAttribute.prototype.background = function(c, x, y, w, h, rSize, fontColor)
  321. {
  322. var buttonStyle = mxUtils.getValue(this.style, 'buttonStyle', 'simple').toString();
  323. if (buttonStyle === 'simple')
  324. {
  325. c.begin();
  326. c.ellipse(0, 0, w, h);
  327. c.fillAndStroke();
  328. }
  329. else if (buttonStyle === 'dblFrame')
  330. {
  331. var fillColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#666666');
  332. c.setFillColor(fillColor);
  333. c.begin();
  334. c.ellipse(0, 0, w, h);
  335. c.fillAndStroke();
  336. rSize = Math.min(w, h);
  337. c.begin();
  338. c.ellipse(rSize * 0.1, rSize * 0.1, w - rSize * 0.2, h - rSize * 0.2);
  339. c.stroke();
  340. }
  341. };
  342. mxShapeERAttribute.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  343. {
  344. c.begin();
  345. c.setFontSize(fontSize);
  346. c.setFontColor(fontColor);
  347. c.text(w * 0.5, h * 0.5, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  348. };
  349. mxCellRenderer.registerShape('mxgraph.er.attribute', mxShapeERAttribute);
  350. mxShapeERAttribute.prototype.constraints = [
  351. new mxConnectionConstraint(new mxPoint(0.144, 0.144), false),
  352. new mxConnectionConstraint(new mxPoint(0.856, 0.144), false),
  353. new mxConnectionConstraint(new mxPoint(0.856, 0.856), false),
  354. new mxConnectionConstraint(new mxPoint(0.144, 0.856), false),
  355. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  356. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  357. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  358. new mxConnectionConstraint(new mxPoint(0.5, 1), true)
  359. ];
  360. //**********************************************************************************************************************************************************
  361. //Has
  362. //**********************************************************************************************************************************************************
  363. /**
  364. * Extends mxShape.
  365. */
  366. function mxShapeERHas(bounds, fill, stroke, strokewidth)
  367. {
  368. mxShape.call(this);
  369. this.bounds = bounds;
  370. this.fill = fill;
  371. this.stroke = stroke;
  372. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  373. };
  374. /**
  375. * Extends mxShape.
  376. */
  377. mxUtils.extend(mxShapeERHas, mxShape);
  378. /**
  379. * Function: paintVertexShape
  380. *
  381. * Paints the vertex shape.
  382. */
  383. mxShapeERHas.prototype.paintVertexShape = function(c, x, y, w, h)
  384. {
  385. var mainText = mxUtils.getValue(this.style, 'buttonText', 'Entity');
  386. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  387. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  388. c.translate(x, y);
  389. var rSize = 10;
  390. w = Math.max(w, 2 * rSize);
  391. h = Math.max(h, 2 * rSize);
  392. this.background(c, x, y, w, h, rSize, fontColor);
  393. c.setShadow(false);
  394. this.mainText(c, x, y, w, h, mainText, fontSize, fontColor);
  395. };
  396. mxShapeERHas.prototype.background = function(c, x, y, w, h, rSize, fontColor)
  397. {
  398. var buttonStyle = mxUtils.getValue(this.style, 'buttonStyle', 'rhombus').toString();
  399. if (buttonStyle === 'rhombus')
  400. {
  401. c.begin();
  402. c.moveTo(0, h * 0.5);
  403. c.lineTo(w * 0.5, 0);
  404. c.lineTo(w, h * 0.5);
  405. c.lineTo(w * 0.5, h);
  406. c.close();
  407. c.fillAndStroke();
  408. }
  409. else if (buttonStyle === 'dblFrame')
  410. {
  411. var fillColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#666666');
  412. c.setFillColor(fillColor);
  413. c.begin();
  414. c.moveTo(0, h * 0.5);
  415. c.lineTo(w * 0.5, 0);
  416. c.lineTo(w, h * 0.5);
  417. c.lineTo(w * 0.5, h);
  418. c.close();
  419. c.fillAndStroke();
  420. c.begin();
  421. c.moveTo(w * 0.1, h * 0.5);
  422. c.lineTo(w * 0.5, h * 0.1);
  423. c.lineTo(w * 0.9, h * 0.5);
  424. c.lineTo(w * 0.5, h * 0.9);
  425. c.close();
  426. c.stroke();
  427. }
  428. };
  429. mxShapeERHas.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  430. {
  431. c.begin();
  432. c.setFontSize(fontSize);
  433. c.setFontColor(fontColor);
  434. c.text(w * 0.5, h * 0.5, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  435. };
  436. mxCellRenderer.registerShape('mxgraph.er.has', mxShapeERHas);
  437. mxShapeERHas.prototype.constraints = [
  438. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  439. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  440. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  441. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  442. new mxConnectionConstraint(new mxPoint(0.25, 0.25), false),
  443. new mxConnectionConstraint(new mxPoint(0.25, 0.75), false),
  444. new mxConnectionConstraint(new mxPoint(0.75, 0.25), false),
  445. new mxConnectionConstraint(new mxPoint(0.75, 0.75), false)
  446. ];
  447. //**********************************************************************************************************************************************************
  448. //Cloud
  449. //**********************************************************************************************************************************************************
  450. /**
  451. * Extends mxShape.
  452. */
  453. function mxShapeERCloud(bounds, fill, stroke, strokewidth)
  454. {
  455. mxShape.call(this);
  456. this.bounds = bounds;
  457. this.fill = fill;
  458. this.stroke = stroke;
  459. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  460. };
  461. /**
  462. * Extends mxShape.
  463. */
  464. mxUtils.extend(mxShapeERCloud, mxShape);
  465. /**
  466. * Function: paintVertexShape
  467. *
  468. * Paints the vertex shape.
  469. */
  470. mxShapeERCloud.prototype.paintVertexShape = function(c, x, y, w, h)
  471. {
  472. var mainText = mxUtils.getValue(this.style, 'buttonText', 'Entity');
  473. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  474. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  475. c.translate(x, y);
  476. var rSize = 10;
  477. w = Math.max(w, 2 * rSize);
  478. h = Math.max(h, 2 * rSize);
  479. this.background(c, x, y, w, h, rSize, fontColor);
  480. c.setShadow(false);
  481. this.mainText(c, x, y, w, h, mainText, fontSize, fontColor);
  482. };
  483. mxShapeERCloud.prototype.background = function(c, x, y, w, h, rSize, fontColor)
  484. {
  485. c.begin();
  486. c.moveTo(0.25 * w, 0.25 * h);
  487. c.curveTo(0.05 * w, 0.25 * h, 0, 0.5 * h, 0.16 * w, 0.55 * h);
  488. c.curveTo(0, 0.66 * h, 0.18 * w, 0.9 * h, 0.31 * w, 0.8 * h);
  489. c.curveTo(0.4 * w, h, 0.7 * w, h, 0.8 * w, 0.8 * h);
  490. c.curveTo(w, 0.8 * h, w, 0.6 * h, 0.875 * w, 0.5 * h);
  491. c.curveTo(w, 0.3 * h, 0.8 * w, 0.1 * h, 0.625 * w, 0.2 * h);
  492. c.curveTo(0.5 * w, 0.05 * h, 0.3 * w, 0.05 * h, 0.25 * w, 0.25 * h);
  493. c.fillAndStroke();
  494. };
  495. mxShapeERCloud.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  496. {
  497. c.begin();
  498. c.setFontSize(fontSize);
  499. c.setFontColor(fontColor);
  500. c.text(w * 0.5, h * 0.5, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  501. };
  502. mxCellRenderer.registerShape('mxgraph.er.cloud', mxShapeERCloud);
  503. mxShapeERCloud.prototype.constraints = [
  504. new mxConnectionConstraint(new mxPoint(0.08, 0.5), false),
  505. new mxConnectionConstraint(new mxPoint(0.9, 0.5), false),
  506. new mxConnectionConstraint(new mxPoint(0.5, 0.1), false),
  507. new mxConnectionConstraint(new mxPoint(0.5, 0.92), false),
  508. new mxConnectionConstraint(new mxPoint(0.24, 0.24), false),
  509. new mxConnectionConstraint(new mxPoint(0.22, 0.8), false),
  510. new mxConnectionConstraint(new mxPoint(0.81, 0.2), false),
  511. new mxConnectionConstraint(new mxPoint(0.78, 0.78), false)
  512. ];
  513. //**********************************************************************************************************************************************************
  514. //Hierarchy (LEGACY)
  515. //**********************************************************************************************************************************************************
  516. /**
  517. * Extends mxShape.
  518. */
  519. function mxShapeERHierarchy(bounds, fill, stroke, strokewidth)
  520. {
  521. mxShape.call(this);
  522. this.bounds = bounds;
  523. this.fill = fill;
  524. this.stroke = stroke;
  525. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  526. };
  527. /**
  528. * Extends mxShape.
  529. */
  530. mxUtils.extend(mxShapeERHierarchy, mxShape);
  531. /**
  532. * Function: paintVertexShape
  533. *
  534. * Paints the vertex shape.
  535. */
  536. mxShapeERHierarchy.prototype.paintVertexShape = function(c, x, y, w, h)
  537. {
  538. var mainText = mxUtils.getValue(this.style, 'buttonText', 'main').toString().split(',');
  539. var subText = mxUtils.getValue(this.style, 'subText', 'sub').toString().split(',');
  540. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  541. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  542. c.translate(x, y);
  543. var rSize = 10;
  544. w = Math.max(w, 2 * rSize);
  545. h = Math.max(h, 2 * rSize);
  546. this.background(c, x, y, w, h, rSize, fontColor);
  547. c.setShadow(false);
  548. this.shapeText(c, x, y, w, h, mainText, subText, fontSize, fontColor);
  549. };
  550. mxShapeERHierarchy.prototype.background = function(c, x, y, w, h, rSize, fontColor)
  551. {
  552. var buttonStyle = mxUtils.getValue(this.style, 'buttonStyle', 'round').toString();
  553. if (buttonStyle === 'round')
  554. {
  555. c.begin();
  556. c.moveTo(0, rSize);
  557. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  558. c.lineTo(w - rSize, 0);
  559. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  560. c.lineTo(w, h - rSize);
  561. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  562. c.lineTo(rSize, h);
  563. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  564. c.close();
  565. c.fillAndStroke();
  566. }
  567. else if (buttonStyle === 'rect')
  568. {
  569. c.begin();
  570. c.moveTo(0, 0);
  571. c.lineTo(w, 0);
  572. c.lineTo(w, h);
  573. c.lineTo(0, h);
  574. c.close();
  575. c.fillAndStroke();
  576. }
  577. else if (buttonStyle === 'dblFrame')
  578. {
  579. var fillColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#666666');
  580. c.setFillColor(fillColor);
  581. c.begin();
  582. c.moveTo(0, 0);
  583. c.lineTo(w, 0);
  584. c.lineTo(w, h);
  585. c.lineTo(0, h);
  586. c.close();
  587. c.fillAndStroke();
  588. rSize = Math.min(w, h);
  589. c.begin();
  590. c.moveTo(rSize * 0.1, rSize * 0.1);
  591. c.lineTo(w - rSize * 0.1, rSize * 0.1);
  592. c.lineTo(w - rSize * 0.1, h - rSize * 0.1);
  593. c.lineTo(rSize * 0.1, h - rSize * 0.1);
  594. c.close();
  595. c.stroke();
  596. }
  597. var trX = 0;
  598. var trY = 0;
  599. if (buttonStyle === 'round')
  600. {
  601. trX = w * 0.5;
  602. trY = rSize;
  603. c.translate(trX, trY);
  604. w = w * 0.5 - rSize;
  605. h = h - 2 * rSize;
  606. c.begin();
  607. c.moveTo(0, rSize);
  608. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  609. c.lineTo(w - rSize, 0);
  610. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  611. c.lineTo(w, h - rSize);
  612. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  613. c.lineTo(rSize, h);
  614. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  615. c.close();
  616. c.fillAndStroke();
  617. }
  618. else if (buttonStyle === 'rect')
  619. {
  620. trX = w * 0.5;
  621. trY = rSize;
  622. c.translate(trX, trY);
  623. w = w * 0.5 - rSize;
  624. h = h - 2 * rSize;
  625. c.begin();
  626. c.moveTo(0, 0);
  627. c.lineTo(w, 0);
  628. c.lineTo(w, h);
  629. c.lineTo(0, h);
  630. c.close();
  631. c.fillAndStroke();
  632. }
  633. else if (buttonStyle === 'dblFrame')
  634. {
  635. trX = w * 0.5;
  636. trY = rSize * 0.15;
  637. c.translate(trX, trY);
  638. w = w * 0.5 - rSize * 0.15;
  639. h = h - rSize * 0.3;
  640. var fillColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#666666');
  641. c.setFillColor(fillColor);
  642. c.begin();
  643. c.moveTo(0, 0);
  644. c.lineTo(w, 0);
  645. c.lineTo(w, h);
  646. c.lineTo(0, h);
  647. c.close();
  648. c.fillAndStroke();
  649. rSize = Math.min(w, h);
  650. c.begin();
  651. c.moveTo(rSize * 0.1, rSize * 0.1);
  652. c.lineTo(w - rSize * 0.1, rSize * 0.1);
  653. c.lineTo(w - rSize * 0.1, h - rSize * 0.1);
  654. c.lineTo(rSize * 0.1, h - rSize * 0.1);
  655. c.close();
  656. c.stroke();
  657. }
  658. c.translate(- trX, - trY);
  659. };
  660. mxShapeERHierarchy.prototype.shapeText = function(c, x, y, w, h, text, subText, fontSize, fontColor, rSize)
  661. {
  662. c.begin();
  663. c.setFontSize(fontSize);
  664. c.setFontColor(fontColor);
  665. c.text(w * 0.25, (h - fontSize) * 0.5, 0, 0, text[0], mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  666. c.text(w * 0.25, (h + fontSize) * 0.5, 0, 0, text[1], mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  667. c.text(w * 0.7, (h - fontSize) * 0.5, 0, 0, subText[0], mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  668. c.text(w * 0.7, (h + fontSize) * 0.5, 0, 0, subText[1], mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  669. };
  670. mxCellRenderer.registerShape('mxgraph.er.hierarchy', mxShapeERHierarchy);
  671. mxShapeERHierarchy.prototype.constraints = [
  672. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  673. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  674. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  675. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  676. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  677. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  678. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  679. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  680. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  681. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  682. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  683. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  684. ];
  685. //**********************************************************************************************************************************************************
  686. //Note
  687. //**********************************************************************************************************************************************************
  688. /**
  689. * Extends mxShape.
  690. */
  691. function mxShapeERNote(bounds, fill, stroke, strokewidth)
  692. {
  693. mxShape.call(this);
  694. this.bounds = bounds;
  695. this.fill = fill;
  696. this.stroke = stroke;
  697. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  698. };
  699. /**
  700. * Extends mxShape.
  701. */
  702. mxUtils.extend(mxShapeERNote, mxShape);
  703. /**
  704. * Function: paintVertexShape
  705. *
  706. * Paints the vertex shape.
  707. */
  708. mxShapeERNote.prototype.paintVertexShape = function(c, x, y, w, h)
  709. {
  710. var mainText = mxUtils.getValue(this.style, 'buttonText', 'Entity');
  711. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  712. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  713. var backColor = mxUtils.getValue(this.style, 'fillColor2', '#ffffff');
  714. c.translate(x, y);
  715. var flipSize = 20;
  716. w = Math.max(w, flipSize * 2);
  717. h = Math.max(h, flipSize * 2);
  718. this.background(c, x, y, w, h, flipSize);
  719. c.setShadow(false);
  720. this.flipShape(c, x, y, w, h, flipSize, backColor);
  721. this.mainText(c, x, y, w, h, mainText, fontSize, fontColor);
  722. };
  723. mxShapeERNote.prototype.background = function(c, x, y, w, h, flipSize)
  724. {
  725. c.begin();
  726. c.moveTo(0, 0);
  727. c.lineTo(w - flipSize, 0);
  728. c.lineTo(w, flipSize);
  729. c.lineTo(w, h);
  730. c.lineTo(0, h);
  731. c.close();
  732. c.fillAndStroke();
  733. };
  734. mxShapeERNote.prototype.flipShape = function(c, x, y, w, h, flipSize, backColor)
  735. {
  736. c.setLineJoin('round');
  737. c.setFillColor(backColor);
  738. c.begin();
  739. c.moveTo(w - flipSize, 0);
  740. c.lineTo(w, flipSize);
  741. c.lineTo(w - flipSize, flipSize);
  742. c.close();
  743. c.fillAndStroke();
  744. };
  745. mxShapeERNote.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  746. {
  747. c.begin();
  748. c.setFontSize(fontSize);
  749. c.setFontColor(fontColor);
  750. c.text(w * 0.5, h * 0.5, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  751. };
  752. mxCellRenderer.registerShape('mxgraph.er.note', mxShapeERNote);
  753. mxShapeERNote.prototype.constraints = [
  754. new mxConnectionConstraint(new mxPoint(0, 0), true),
  755. new mxConnectionConstraint(new mxPoint(0, 1), true),
  756. new mxConnectionConstraint(new mxPoint(1, 1), true),
  757. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  758. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  759. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  760. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  761. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  762. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  763. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  764. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  765. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  766. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  767. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  768. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  769. ];
  770. //**********************************************************************************************************************************************************
  771. //Chen's Notation Legend (LEGACY)
  772. //**********************************************************************************************************************************************************
  773. /**
  774. * Extends mxShape.
  775. */
  776. function mxShapeERChen(bounds, fill, stroke, strokewidth)
  777. {
  778. mxShape.call(this);
  779. this.bounds = bounds;
  780. this.fill = fill;
  781. this.stroke = stroke;
  782. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  783. };
  784. /**
  785. * Extends mxShape.
  786. */
  787. mxUtils.extend(mxShapeERChen, mxShape);
  788. /**
  789. * Function: paintVertexShape
  790. *
  791. * Paints the vertex shape.
  792. */
  793. mxShapeERChen.prototype.paintVertexShape = function(c, x, y, w, h)
  794. {
  795. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  796. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  797. c.translate(x, y);
  798. var flipSize = 20;
  799. w = Math.max(w, flipSize * 2);
  800. h = Math.max(h, flipSize * 2);
  801. this.background(c, x, y, w, h);
  802. c.setShadow(false);
  803. this.foreground(c, x, y, w, h, fontSize, fontColor);
  804. };
  805. mxShapeERChen.prototype.background = function(c, x, y, w, h)
  806. {
  807. c.begin();
  808. c.moveTo(0, 0);
  809. c.lineTo(w, 0);
  810. c.lineTo(w, h);
  811. c.lineTo(0, h);
  812. c.close();
  813. c.fillAndStroke();
  814. };
  815. mxShapeERChen.prototype.foreground = function(c, x, y, w, h, fontSize, fontColor)
  816. {
  817. c.begin();
  818. c.moveTo(0, h * 0.25);
  819. c.lineTo(w, h * 0.25);
  820. c.moveTo(0, h * 0.5);
  821. c.lineTo(w, h * 0.5);
  822. c.moveTo(0, h * 0.75);
  823. c.lineTo(w, h * 0.75);
  824. c.moveTo(w * 0.25, h * 0.5);
  825. c.lineTo(w * 0.25, h);
  826. c.moveTo(w * 0.5, h * 0.25);
  827. c.lineTo(w * 0.5, h);
  828. c.moveTo(w * 0.75, h * 0.5);
  829. c.lineTo(w * 0.75, h);
  830. c.stroke();
  831. c.begin();
  832. c.setFontSize(fontSize);
  833. c.setFontColor(fontColor);
  834. c.text(w * 0.5, h * 0.125, 0, 0, 'ERD Peter Chen\'s Notation', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  835. c.setFontSize(fontSize * 0.85);
  836. c.text(w * 0.25, h * 0.375, 0, 0, 'Cardinality', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  837. c.text(w * 0.75, h * 0.375, 0, 0, 'Optionality', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  838. c.setFontSize(fontSize * 0.7);
  839. c.text(w * 0.125, h * 0.625, 0, 0, '1', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  840. c.text(w * 0.375, h * 0.625, 0, 0, 'One', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  841. c.text(w * 0.625, h * 0.625, 0, 0, '0', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  842. c.text(w * 0.875, h * 0.625, 0, 0, 'Optional', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  843. c.text(w * 0.125, h * 0.875, 0, 0, 'N', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  844. c.text(w * 0.375, h * 0.875, 0, 0, 'Many', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  845. c.text(w * 0.625, h * 0.875, 0, 0, '1', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  846. c.text(w * 0.875, h * 0.875, 0, 0, 'Mandatory', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  847. };
  848. mxCellRenderer.registerShape('mxgraph.er.chens', mxShapeERChen);
  849. mxShapeERChen.prototype.constraints = [
  850. new mxConnectionConstraint(new mxPoint(0, 0), true),
  851. new mxConnectionConstraint(new mxPoint(1, 0), true),
  852. new mxConnectionConstraint(new mxPoint(0, 1), true),
  853. new mxConnectionConstraint(new mxPoint(1, 1), true),
  854. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  855. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  856. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  857. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  858. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  859. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  860. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  861. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  862. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  863. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  864. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  865. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  866. ];
  867. //**********************************************************************************************************************************************************
  868. //Bachman's Notation Legend (LEGACY)
  869. //**********************************************************************************************************************************************************
  870. /**
  871. * Extends mxShape.
  872. */
  873. function mxShapeERBachman(bounds, fill, stroke, strokewidth)
  874. {
  875. mxShape.call(this);
  876. this.bounds = bounds;
  877. this.fill = fill;
  878. this.stroke = stroke;
  879. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  880. };
  881. /**
  882. * Extends mxShape.
  883. */
  884. mxUtils.extend(mxShapeERBachman, mxShape);
  885. /**
  886. * Function: paintVertexShape
  887. *
  888. * Paints the vertex shape.
  889. */
  890. mxShapeERBachman.prototype.paintVertexShape = function(c, x, y, w, h)
  891. {
  892. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  893. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  894. c.translate(x, y);
  895. this.background(c, x, y, w, h);
  896. c.setShadow(false);
  897. this.foreground(c, x, y, w, h, fontSize, fontColor);
  898. };
  899. mxShapeERBachman.prototype.background = function(c, x, y, w, h)
  900. {
  901. c.begin();
  902. c.moveTo(0, 0);
  903. c.lineTo(w, 0);
  904. c.lineTo(w, h);
  905. c.lineTo(0, h);
  906. c.close();
  907. c.fillAndStroke();
  908. };
  909. mxShapeERBachman.prototype.foreground = function(c, x, y, w, h, fontSize, fontColor)
  910. {
  911. c.begin();
  912. c.moveTo(0, h * 0.125);
  913. c.lineTo(w, h * 0.125);
  914. c.moveTo(0, h * 0.25);
  915. c.lineTo(w, h * 0.25);
  916. c.moveTo(0, h * 0.375);
  917. c.lineTo(w, h * 0.375);
  918. c.moveTo(0, h * 0.5);
  919. c.lineTo(w, h * 0.5);
  920. c.moveTo(0, h * 0.625);
  921. c.lineTo(w, h * 0.625);
  922. c.moveTo(0, h * 0.75);
  923. c.lineTo(w, h * 0.75);
  924. c.moveTo(0, h * 0.875);
  925. c.lineTo(w, h * 0.875);
  926. c.moveTo(w * 0.5, h * 0.125);
  927. c.lineTo(w * 0.5, h);
  928. c.stroke();
  929. c.begin();
  930. c.setFontSize(fontSize);
  931. c.setFontColor(fontColor);
  932. c.text(w * 0.5, h * 0.0625, 0, 0, 'ERD Bachman\'s Notation', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  933. c.setFontSize(fontSize * 0.85);
  934. c.text(w * 0.52, h * 0.1875, 0, 0, 'Relationship', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  935. c.text(w * 0.52, h * 0.3125, 0, 0, 'Cardinality (One)', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  936. c.text(w * 0.52, h * 0.4375, 0, 0, 'Cardinality (Many)', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  937. c.text(w * 0.52, h * 0.5625, 0, 0, 'Mandatory, One', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  938. c.text(w * 0.52, h * 0.6875, 0, 0, 'Mandatory, Many', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  939. c.text(w * 0.52, h * 0.8125, 0, 0, 'Optional, One', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  940. c.text(w * 0.52, h * 0.9375, 0, 0, 'Optional, Many', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  941. var textWidth = mxUtils.getSizeForString('has/forms', fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  942. c.begin();
  943. c.moveTo(w * 0.04, h * 0.1875);
  944. c.lineTo(w * 0.25 - textWidth * 0.5, h * 0.1875);
  945. c.moveTo(w * 0.25 + textWidth * 0.5, h * 0.1875);
  946. c.lineTo(w * 0.46, h * 0.1875);
  947. c.text(w * 0.25, h * 0.1875, 0, 0, 'has/forms', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, true, 0, 0);
  948. c.moveTo(w * 0.04, h * 0.3125);
  949. c.lineTo(w * 0.46, h * 0.3125);
  950. c.moveTo(w * 0.04, h * 0.4375);
  951. c.lineTo(w * 0.46, h * 0.4375);
  952. c.moveTo(w * 0.46, h * 0.4050);
  953. c.lineTo(w * 0.4, h * 0.4375);
  954. c.lineTo(w * 0.46, h * 0.47);
  955. c.moveTo(w * 0.04, h * 0.5625);
  956. c.lineTo(w * 0.46, h * 0.5625);
  957. c.moveTo(w * 0.38, h * 0.53);
  958. c.lineTo(w * 0.38, h * 0.595);
  959. c.moveTo(w * 0.04, h * 0.6875);
  960. c.lineTo(w * 0.46, h * 0.6875);
  961. c.moveTo(w * 0.46, h * 0.655);
  962. c.lineTo(w * 0.4, h * 0.6875);
  963. c.lineTo(w * 0.46, h * 0.72);
  964. c.moveTo(w * 0.38, h * 0.655);
  965. c.lineTo(w * 0.38, h * 0.72);
  966. c.moveTo(w * 0.04, h * 0.8125);
  967. c.lineTo(w * 0.46, h * 0.8125);
  968. c.moveTo(w * 0.04, h * 0.9375);
  969. c.lineTo(w * 0.46, h * 0.9375);
  970. c.moveTo(w * 0.46, h * 0.9050);
  971. c.lineTo(w * 0.4, h * 0.9375);
  972. c.lineTo(w * 0.46, h * 0.97);
  973. c.stroke();
  974. var ellSize = h / 15;
  975. c.begin();
  976. c.ellipse(w * 0.46 - ellSize, h * 0.8125 - ellSize * 0.5, ellSize, ellSize);
  977. c.fillAndStroke();
  978. c.begin();
  979. c.ellipse(w * 0.4 - ellSize, h * 0.9375 - ellSize * 0.5, ellSize, ellSize);
  980. c.fillAndStroke();
  981. };
  982. mxCellRenderer.registerShape('mxgraph.er.bachmans', mxShapeERBachman);
  983. mxShapeERBachman.prototype.constraints = [
  984. new mxConnectionConstraint(new mxPoint(0, 0), true),
  985. new mxConnectionConstraint(new mxPoint(1, 0), true),
  986. new mxConnectionConstraint(new mxPoint(0, 1), true),
  987. new mxConnectionConstraint(new mxPoint(1, 1), true),
  988. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  989. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  990. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  991. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  992. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  993. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  994. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  995. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  996. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  997. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  998. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  999. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  1000. ];
  1001. //**********************************************************************************************************************************************************
  1002. //Information Engineering Notation Legend (LEGACY)
  1003. //**********************************************************************************************************************************************************
  1004. /**
  1005. * Extends mxShape.
  1006. */
  1007. function mxShapeERInfEng(bounds, fill, stroke, strokewidth)
  1008. {
  1009. mxShape.call(this);
  1010. this.bounds = bounds;
  1011. this.fill = fill;
  1012. this.stroke = stroke;
  1013. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  1014. };
  1015. /**
  1016. * Extends mxShape.
  1017. */
  1018. mxUtils.extend(mxShapeERInfEng, mxShape);
  1019. /**
  1020. * Function: paintVertexShape
  1021. *
  1022. * Paints the vertex shape.
  1023. */
  1024. mxShapeERInfEng.prototype.paintVertexShape = function(c, x, y, w, h)
  1025. {
  1026. var fontColor = mxUtils.getValue(this.style, 'textColor', '#666666');
  1027. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '17');
  1028. c.translate(x, y);
  1029. w = Math.max(w, h / 1.5);
  1030. h = Math.max(h, fontSize * 5);
  1031. this.background(c, x, y, w, h);
  1032. c.setShadow(false);
  1033. this.foreground(c, x, y, w, h, fontSize, fontColor);
  1034. };
  1035. mxShapeERInfEng.prototype.background = function(c, x, y, w, h)
  1036. {
  1037. c.begin();
  1038. c.moveTo(0, 0);
  1039. c.lineTo(w, 0);
  1040. c.lineTo(w, h);
  1041. c.lineTo(0, h);
  1042. c.close();
  1043. c.fillAndStroke();
  1044. };
  1045. mxShapeERInfEng.prototype.foreground = function(c, x, y, w, h, fontSize, fontColor)
  1046. {
  1047. c.begin();
  1048. c.moveTo(0, h * 0.2);
  1049. c.lineTo(w, h * 0.2);
  1050. c.moveTo(0, h * 0.4);
  1051. c.lineTo(w, h * 0.4);
  1052. c.moveTo(0, h * 0.6);
  1053. c.lineTo(w, h * 0.6);
  1054. c.moveTo(0, h * 0.8);
  1055. c.lineTo(w, h * 0.8);
  1056. c.moveTo(w * 0.5, h * 0.2);
  1057. c.lineTo(w * 0.5, h);
  1058. c.stroke();
  1059. c.begin();
  1060. c.setFontSize(fontSize);
  1061. c.setFontColor(fontColor);
  1062. c.text(w * 0.5, h * 0.1, 0, 0, 'ERD Information Engineering Notation', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  1063. c.setFontSize(fontSize * 0.85);
  1064. c.text(w * 0.52, h * 0.3, 0, 0, 'Zero or one', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  1065. c.text(w * 0.52, h * 0.5, 0, 0, 'One only', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  1066. c.text(w * 0.52, h * 0.7, 0, 0, 'Zero or more', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  1067. c.text(w * 0.52, h * 0.9, 0, 0, 'One or more', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  1068. var ellSize = h / 12;
  1069. c.begin();
  1070. c.moveTo(w * 0.04, h * 0.3);
  1071. c.lineTo(w * 0.46, h * 0.3);
  1072. c.moveTo(w * 0.46 - ellSize, h * 0.25);
  1073. c.lineTo(w * 0.46 - ellSize, h * 0.35);
  1074. c.moveTo(w * 0.04, h * 0.5);
  1075. c.lineTo(w * 0.46, h * 0.5);
  1076. c.moveTo(w * 0.46 - ellSize * 2, h * 0.45);
  1077. c.lineTo(w * 0.46 - ellSize * 2, h * 0.55);
  1078. c.moveTo(w * 0.46 - ellSize * 2.5, h * 0.45);
  1079. c.lineTo(w * 0.46 - ellSize * 2.5, h * 0.55);
  1080. c.moveTo(w * 0.04, h * 0.7);
  1081. c.lineTo(w * 0.46, h * 0.7);
  1082. c.moveTo(w * 0.46, h * 0.65);
  1083. c.lineTo(w * 0.46 - ellSize * 2, h * 0.7);
  1084. c.lineTo(w * 0.46, h * 0.75);
  1085. c.stroke();
  1086. c.moveTo(w * 0.04, h * 0.9);
  1087. c.lineTo(w * 0.46, h * 0.9);
  1088. c.moveTo(w * 0.46, h * 0.85);
  1089. c.lineTo(w * 0.46 - ellSize * 2, h * 0.9);
  1090. c.lineTo(w * 0.46, h * 0.95);
  1091. c.moveTo(w * 0.46 - ellSize * 2.5, h * 0.85);
  1092. c.lineTo(w * 0.46 - ellSize * 2.5, h * 0.95);
  1093. c.stroke();
  1094. c.begin();
  1095. c.ellipse(w * 0.46 - ellSize * 3, h * 0.3 - ellSize * 0.5, ellSize, ellSize);
  1096. c.fillAndStroke();
  1097. c.begin();
  1098. c.ellipse(w * 0.46 - ellSize * 3, h * 0.7 - ellSize * 0.5, ellSize, ellSize);
  1099. c.fillAndStroke();
  1100. };
  1101. mxCellRenderer.registerShape('mxgraph.er.ie', mxShapeERInfEng);
  1102. mxShapeERInfEng.prototype.constraints = [
  1103. new mxConnectionConstraint(new mxPoint(0, 0), true),
  1104. new mxConnectionConstraint(new mxPoint(1, 0), true),
  1105. new mxConnectionConstraint(new mxPoint(0, 1), true),
  1106. new mxConnectionConstraint(new mxPoint(1, 1), true),
  1107. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  1108. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  1109. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  1110. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  1111. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  1112. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  1113. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  1114. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  1115. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  1116. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  1117. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  1118. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  1119. ];
  1120. // ER markers
  1121. mxMarker.addMarker('ERone', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1122. {
  1123. var nx = unitX * (size + sw + 1);
  1124. var ny = unitY * (size + sw + 1);
  1125. return function()
  1126. {
  1127. c.begin();
  1128. c.moveTo(pe.x - nx / 2 - ny / 2, pe.y - ny / 2 + nx / 2);
  1129. c.lineTo(pe.x - nx / 2 + ny / 2, pe.y - ny / 2 - nx / 2);
  1130. c.stroke();
  1131. };
  1132. });
  1133. mxMarker.addMarker('ERmandOne', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1134. {
  1135. var nx = unitX * (size + sw + 1);
  1136. var ny = unitY * (size + sw + 1);
  1137. return function()
  1138. {
  1139. c.begin();
  1140. c.moveTo(pe.x - nx / 2 - ny / 2, pe.y - ny / 2 + nx / 2);
  1141. c.lineTo(pe.x - nx / 2 + ny / 2, pe.y - ny / 2 - nx / 2);
  1142. c.moveTo(pe.x - nx - ny / 2, pe.y - ny + nx / 2);
  1143. c.lineTo(pe.x - nx + ny / 2, pe.y - ny - nx / 2);
  1144. c.stroke();
  1145. };
  1146. });
  1147. mxMarker.addMarker('ERmany', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1148. {
  1149. var nx = unitX * (size + sw + 1);
  1150. var ny = unitY * (size + sw + 1);
  1151. return function()
  1152. {
  1153. c.begin();
  1154. c.moveTo(pe.x + ny / 2, pe.y - nx / 2);
  1155. c.lineTo(pe.x - nx, pe.y - ny);
  1156. c.lineTo(pe.x - ny / 2, pe.y + nx / 2);
  1157. c.stroke();
  1158. };
  1159. });
  1160. mxMarker.addMarker('ERoneToMany', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1161. {
  1162. var nx = unitX * (size + sw + 1);
  1163. var ny = unitY * (size + sw + 1);
  1164. return function()
  1165. {
  1166. c.begin();
  1167. c.moveTo(pe.x - nx - ny / 2, pe.y - ny + nx / 2);
  1168. c.lineTo(pe.x - nx + ny / 2, pe.y - ny - nx / 2);
  1169. c.moveTo(pe.x + ny / 2, pe.y - nx / 2);
  1170. c.lineTo(pe.x - nx, pe.y - ny);
  1171. c.lineTo(pe.x - ny / 2, pe.y + nx / 2);
  1172. c.stroke();
  1173. };
  1174. });
  1175. mxMarker.addMarker('ERzeroToMany', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1176. {
  1177. var nx = unitX * (size + sw + 1);
  1178. var ny = unitY * (size + sw + 1);
  1179. var a = size / 2;
  1180. var px = pe.x;
  1181. var py = pe.y;
  1182. if (!filled)
  1183. {
  1184. pe.x -= 2 * nx - unitX * sw / 2;
  1185. pe.y -= 2 * ny - unitY * sw / 2;
  1186. }
  1187. return function()
  1188. {
  1189. c.begin();
  1190. c.ellipse(px - 1.5 * nx - a, py - 1.5 * ny - a, 2 * a, 2 * a);
  1191. if (filled)
  1192. {
  1193. // TODO not sure if this is ok, because by default, markers use strokeColor for filling
  1194. var oldColor = mxUtils.getValue(shape.style, mxConstants.STYLE_STROKECOLOR, '#666666');
  1195. c.setFillColor('#ffffff');
  1196. c.fillAndStroke();
  1197. c.setFillColor(oldColor);
  1198. }
  1199. else
  1200. {
  1201. c.stroke();
  1202. }
  1203. c.begin();
  1204. c.moveTo(px + ny / 2, py - nx / 2);
  1205. c.lineTo(px - nx, py - ny);
  1206. c.lineTo(px - ny / 2, py + nx / 2);
  1207. if (!filled)
  1208. {
  1209. c.moveTo(px - nx, py - ny);
  1210. c.lineTo(px, py);
  1211. }
  1212. c.stroke();
  1213. };
  1214. });
  1215. mxMarker.addMarker('ERzeroToOne', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  1216. {
  1217. var nx = unitX * (size + sw + 1);
  1218. var ny = unitY * (size + sw + 1);
  1219. var a = size / 2;
  1220. var px = pe.x;
  1221. var py = pe.y;
  1222. if (!filled)
  1223. {
  1224. pe.x -= 2 * nx - unitX * sw / 2;
  1225. pe.y -= 2 * ny - unitY * sw / 2;
  1226. }
  1227. return function()
  1228. {
  1229. c.begin();
  1230. c.ellipse(px - 1.5 * nx - a, py - 1.5 * ny - a, 2 * a, 2 * a);
  1231. if (filled)
  1232. {
  1233. // TODO not sure if this is ok, because by default, markers use strokeColor for filling
  1234. var oldColor = mxUtils.getValue(shape.style, mxConstants.STYLE_STROKECOLOR, '#666666');
  1235. c.setFillColor('#ffffff');
  1236. c.fillAndStroke();
  1237. c.setFillColor(oldColor);
  1238. }
  1239. else
  1240. {
  1241. c.stroke();
  1242. }
  1243. c.begin();
  1244. c.moveTo(px - nx / 2 - ny / 2, py - ny / 2 + nx / 2);
  1245. c.lineTo(px - nx / 2 + ny / 2, py - ny / 2 - nx / 2);
  1246. if (!filled)
  1247. {
  1248. c.moveTo(px - nx - unitX * sw / 2, py - ny - unitY * sw / 2);
  1249. c.lineTo(px, py);
  1250. }
  1251. c.stroke();
  1252. };
  1253. });
  1254. //**********************************************************************************************************************************************************
  1255. //Rounded rectangle (adjustable rounding)
  1256. //**********************************************************************************************************************************************************
  1257. /**
  1258. * Extends mxShape.
  1259. */
  1260. function mxShapeERRRect(bounds, fill, stroke, strokewidth)
  1261. {
  1262. mxShape.call(this);
  1263. this.bounds = bounds;
  1264. this.fill = fill;
  1265. this.stroke = stroke;
  1266. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  1267. };
  1268. /**
  1269. * Extends mxShape.
  1270. */
  1271. mxUtils.extend(mxShapeERRRect, mxShape);
  1272. mxShapeERRRect.prototype.cst = {
  1273. RRECT : 'mxgraph.er.rrect',
  1274. R_SIZE : 'rSize'
  1275. };
  1276. mxShapeERRRect.prototype.customProperties = [
  1277. {name: 'rSize', dispName: 'Rounding Size', type: 'float'},
  1278. ];
  1279. /**
  1280. * Function: paintVertexShape
  1281. *
  1282. * Paints the vertex shape.
  1283. */
  1284. mxShapeERRRect.prototype.paintVertexShape = function(c, x, y, w, h)
  1285. {
  1286. c.translate(x, y);
  1287. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeERRRect.prototype.cst.R_SIZE, '10'));
  1288. c.roundrect(0, 0, w, h, rSize);
  1289. c.fillAndStroke();
  1290. };
  1291. mxCellRenderer.registerShape(mxShapeERRRect.prototype.cst.RRECT, mxShapeERRRect);
  1292. mxShapeERRRect.prototype.constraints = [
  1293. new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  1294. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  1295. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  1296. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  1297. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  1298. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  1299. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  1300. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  1301. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  1302. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  1303. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  1304. new mxConnectionConstraint(new mxPoint(0.75, 1), true)
  1305. ];
  1306. //**********************************************************************************************************************************************************
  1307. //Anchor (a dummy shape without visuals used for anchoring)
  1308. //**********************************************************************************************************************************************************
  1309. /**
  1310. * Extends mxShape.
  1311. */
  1312. function mxShapeERAnchor(bounds, fill, stroke, strokewidth)
  1313. {
  1314. mxShape.call(this);
  1315. this.bounds = bounds;
  1316. };
  1317. /**
  1318. * Extends mxShape.
  1319. */
  1320. mxUtils.extend(mxShapeERAnchor, mxShape);
  1321. mxShapeERAnchor.prototype.cst = {
  1322. ANCHOR : 'mxgraph.er.anchor'
  1323. };
  1324. /**
  1325. * Function: paintVertexShape
  1326. *
  1327. * Paints the vertex shape.
  1328. */
  1329. mxShapeERAnchor.prototype.paintVertexShape = function(c, x, y, w, h)
  1330. {
  1331. };
  1332. mxCellRenderer.registerShape(mxShapeERAnchor.prototype.cst.ANCHOR, mxShapeERAnchor);