mxER.js 51 KB

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