Shapes.js 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. */
  4. /**
  5. * Registers shapes.
  6. */
  7. (function()
  8. {
  9. // Cube Shape, supports size style
  10. function CubeShape()
  11. {
  12. mxCylinder.call(this);
  13. };
  14. mxUtils.extend(CubeShape, mxCylinder);
  15. CubeShape.prototype.size = 20;
  16. CubeShape.prototype.redrawPath = function(path, x, y, w, h, isForeground)
  17. {
  18. var s = Math.max(0, Math.min(w, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size)))));
  19. if (isForeground)
  20. {
  21. path.moveTo(s, h);
  22. path.lineTo(s, s);
  23. path.lineTo(0, 0);
  24. path.moveTo(s, s);
  25. path.lineTo(w, s);
  26. path.end();
  27. }
  28. else
  29. {
  30. path.moveTo(0, 0);
  31. path.lineTo(w - s, 0);
  32. path.lineTo(w, s);
  33. path.lineTo(w, h);
  34. path.lineTo(s, h);
  35. path.lineTo(0, h - s);
  36. path.lineTo(0, 0);
  37. path.close();
  38. path.end();
  39. }
  40. };
  41. mxCellRenderer.prototype.defaultShapes['cube'] = CubeShape;
  42. var tan30 = Math.tan(mxUtils.toRadians(30));
  43. var tan30Dx = (0.5 - tan30) / 2;
  44. // Cube Shape, supports size style
  45. function IsoRectangleShape()
  46. {
  47. mxActor.call(this);
  48. };
  49. mxUtils.extend(IsoRectangleShape, mxActor);
  50. IsoRectangleShape.prototype.size = 20;
  51. IsoRectangleShape.prototype.redrawPath = function(path, x, y, w, h)
  52. {
  53. var m = Math.min(w, h / tan30);
  54. path.translate((w - m) / 2, (h - m) / 2 + m / 4);
  55. path.moveTo(0, 0.25 * m);
  56. path.lineTo(0.5 * m, m * tan30Dx);
  57. path.lineTo(m, 0.25 * m);
  58. path.lineTo(0.5 * m, (0.5 - tan30Dx) * m);
  59. path.lineTo(0, 0.25 * m);
  60. path.close();
  61. path.end();
  62. };
  63. mxCellRenderer.prototype.defaultShapes['isoRectangle'] = IsoRectangleShape;
  64. // Cube Shape, supports size style
  65. function IsoCubeShape()
  66. {
  67. mxCylinder.call(this);
  68. };
  69. mxUtils.extend(IsoCubeShape, mxCylinder);
  70. IsoCubeShape.prototype.size = 20;
  71. IsoCubeShape.prototype.redrawPath = function(path, x, y, w, h, isForeground)
  72. {
  73. var m = Math.min(w, h / (0.5 + tan30));
  74. if (isForeground)
  75. {
  76. path.moveTo(0, 0.25 * m);
  77. path.lineTo(0.5 * m, (0.5 - tan30Dx) * m);
  78. path.lineTo(m, 0.25 * m);
  79. path.moveTo(0.5 * m, (0.5 - tan30Dx) * m);
  80. path.lineTo(0.5 * m, (1 - tan30Dx) * m);
  81. path.end();
  82. }
  83. else
  84. {
  85. path.translate((w - m) / 2, (h - m) / 2);
  86. path.moveTo(0, 0.25 * m);
  87. path.lineTo(0.5 * m, m * tan30Dx);
  88. path.lineTo(m, 0.25 * m);
  89. path.lineTo(m, 0.75 * m);
  90. path.lineTo(0.5 * m, (1 - tan30Dx) * m);
  91. path.lineTo(0, 0.75 * m);
  92. path.close();
  93. path.end();
  94. }
  95. };
  96. mxCellRenderer.prototype.defaultShapes['isoCube'] = IsoCubeShape;
  97. // DataStore Shape, supports size style
  98. function DataStoreShape()
  99. {
  100. mxCylinder.call(this);
  101. };
  102. mxUtils.extend(DataStoreShape, mxCylinder);
  103. DataStoreShape.prototype.redrawPath = function(c, x, y, w, h, isForeground)
  104. {
  105. var dy = Math.min(h / 2, Math.round(h / 8) + this.strokewidth - 1);
  106. if ((isForeground && this.fill != null) || (!isForeground && this.fill == null))
  107. {
  108. c.moveTo(0, dy);
  109. c.curveTo(0, 2 * dy, w, 2 * dy, w, dy);
  110. // Needs separate shapes for correct hit-detection
  111. if (!isForeground)
  112. {
  113. c.stroke();
  114. c.begin();
  115. }
  116. c.translate(0, dy / 2);
  117. c.moveTo(0, dy);
  118. c.curveTo(0, 2 * dy, w, 2 * dy, w, dy);
  119. // Needs separate shapes for correct hit-detection
  120. if (!isForeground)
  121. {
  122. c.stroke();
  123. c.begin();
  124. }
  125. c.translate(0, dy / 2);
  126. c.moveTo(0, dy);
  127. c.curveTo(0, 2 * dy, w, 2 * dy, w, dy);
  128. // Needs separate shapes for correct hit-detection
  129. if (!isForeground)
  130. {
  131. c.stroke();
  132. c.begin();
  133. }
  134. c.translate(0, -dy);
  135. }
  136. if (!isForeground)
  137. {
  138. c.moveTo(0, dy);
  139. c.curveTo(0, -dy / 3, w, -dy / 3, w, dy);
  140. c.lineTo(w, h - dy);
  141. c.curveTo(w, h + dy / 3, 0, h + dy / 3, 0, h - dy);
  142. c.close();
  143. }
  144. };
  145. DataStoreShape.prototype.getLabelBounds = function(rect)
  146. {
  147. var dy = 2.5 * Math.min(rect.height / 2, Math.round(rect.height / 8) + this.strokewidth - 1);
  148. if ((!this.flipV && (this.direction == null || this.direction == mxConstants.DIRECTION_EAST) ||
  149. (this.flipV && this.direction == mxConstants.DIRECTION_WEST)))
  150. {
  151. rect.y += dy;
  152. rect.height -= dy;
  153. }
  154. else if ((!this.flipV && this.direction == mxConstants.DIRECTION_SOUTH) ||
  155. ((this.flipV && this.direction == mxConstants.DIRECTION_NORTH)))
  156. {
  157. rect.width -= dy;
  158. }
  159. else if ((!this.flipV && this.direction == mxConstants.DIRECTION_WEST) ||
  160. (this.flipV && (this.direction == null || this.direction == mxConstants.DIRECTION_EAST)))
  161. {
  162. rect.height -= dy;
  163. }
  164. else if ((!this.flipV && this.direction == mxConstants.DIRECTION_NORTH) ||
  165. (this.flipV && this.direction == mxConstants.DIRECTION_SOUTH))
  166. {
  167. rect.x += dy;
  168. rect.width -= dy;
  169. }
  170. return rect;
  171. };
  172. mxCellRenderer.prototype.defaultShapes['datastore'] = DataStoreShape;
  173. // Note Shape, supports size style
  174. function NoteShape()
  175. {
  176. mxCylinder.call(this);
  177. };
  178. mxUtils.extend(NoteShape, mxCylinder);
  179. NoteShape.prototype.size = 30;
  180. NoteShape.prototype.redrawPath = function(path, x, y, w, h, isForeground)
  181. {
  182. var s = Math.max(0, Math.min(w, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size)))));
  183. if (isForeground)
  184. {
  185. path.moveTo(w - s, 0);
  186. path.lineTo(w - s, s);
  187. path.lineTo(w, s);
  188. path.end();
  189. }
  190. else
  191. {
  192. path.moveTo(0, 0);
  193. path.lineTo(w - s, 0);
  194. path.lineTo(w, s);
  195. path.lineTo(w, h);
  196. path.lineTo(0, h);
  197. path.lineTo(0, 0);
  198. path.close();
  199. path.end();
  200. }
  201. };
  202. mxCellRenderer.prototype.defaultShapes['note'] = NoteShape;
  203. // Note Shape, supports size style
  204. function SwitchShape()
  205. {
  206. mxActor.call(this);
  207. };
  208. mxUtils.extend(SwitchShape, mxActor);
  209. SwitchShape.prototype.redrawPath = function(c, x, y, w, h)
  210. {
  211. var curve = 0.5;
  212. c.moveTo(0, 0);
  213. c.quadTo(w / 2, h * curve, w, 0);
  214. c.quadTo(w * (1 - curve), h / 2, w, h);
  215. c.quadTo(w / 2, h * (1 - curve), 0, h);
  216. c.quadTo(w * curve, h / 2, 0, 0);
  217. c.end();
  218. };
  219. mxCellRenderer.prototype.defaultShapes['switch'] = SwitchShape;
  220. // Folder Shape, supports tabWidth, tabHeight styles
  221. function FolderShape()
  222. {
  223. mxCylinder.call(this);
  224. };
  225. mxUtils.extend(FolderShape, mxCylinder);
  226. FolderShape.prototype.tabWidth = 60;
  227. FolderShape.prototype.tabHeight = 20;
  228. FolderShape.prototype.tabPosition = 'right';
  229. FolderShape.prototype.redrawPath = function(path, x, y, w, h, isForeground)
  230. {
  231. var dx = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'tabWidth', this.tabWidth))));
  232. var dy = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'tabHeight', this.tabHeight))));
  233. var tp = mxUtils.getValue(this.style, 'tabPosition', this.tabPosition);
  234. if (isForeground)
  235. {
  236. if (tp == 'left')
  237. {
  238. path.moveTo(0, dy);
  239. path.lineTo(dx, dy);
  240. }
  241. // Right is default
  242. else
  243. {
  244. path.moveTo(w - dx, dy);
  245. path.lineTo(w, dy);
  246. }
  247. path.end();
  248. }
  249. else
  250. {
  251. if (tp == 'left')
  252. {
  253. path.moveTo(0, 0);
  254. path.lineTo(dx, 0);
  255. path.lineTo(dx, dy);
  256. path.lineTo(w, dy);
  257. }
  258. // Right is default
  259. else
  260. {
  261. path.moveTo(0, dy);
  262. path.lineTo(w - dx, dy);
  263. path.lineTo(w - dx, 0);
  264. path.lineTo(w, 0);
  265. }
  266. path.lineTo(w, h);
  267. path.lineTo(0, h);
  268. path.lineTo(0, dy);
  269. path.close();
  270. path.end();
  271. }
  272. };
  273. mxCellRenderer.prototype.defaultShapes['folder'] = FolderShape;
  274. // Card shape
  275. function CardShape()
  276. {
  277. mxActor.call(this);
  278. };
  279. mxUtils.extend(CardShape, mxActor);
  280. CardShape.prototype.size = 30;
  281. CardShape.prototype.redrawPath = function(c, x, y, w, h)
  282. {
  283. var s = Math.max(0, Math.min(w, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size)))));
  284. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  285. this.addPoints(c, [new mxPoint(s, 0), new mxPoint(w, 0), new mxPoint(w, h), new mxPoint(0, h), new mxPoint(0, s)],
  286. this.isRounded, arcSize, true);
  287. c.end();
  288. };
  289. mxCellRenderer.prototype.defaultShapes['card'] = CardShape;
  290. // Tape shape
  291. function TapeShape()
  292. {
  293. mxActor.call(this);
  294. };
  295. mxUtils.extend(TapeShape, mxActor);
  296. TapeShape.prototype.size = 0.4;
  297. TapeShape.prototype.redrawPath = function(c, x, y, w, h)
  298. {
  299. var dy = h * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  300. var fy = 1.4;
  301. c.moveTo(0, dy / 2);
  302. c.quadTo(w / 4, dy * fy, w / 2, dy / 2);
  303. c.quadTo(w * 3 / 4, dy * (1 - fy), w, dy / 2);
  304. c.lineTo(w, h - dy / 2);
  305. c.quadTo(w * 3 / 4, h - dy * fy, w / 2, h - dy / 2);
  306. c.quadTo(w / 4, h - dy * (1 - fy), 0, h - dy / 2);
  307. c.lineTo(0, dy / 2);
  308. c.close();
  309. c.end();
  310. };
  311. TapeShape.prototype.getLabelBounds = function(rect)
  312. {
  313. if (mxUtils.getValue(this.style, 'boundedLbl', false))
  314. {
  315. var size = mxUtils.getValue(this.style, 'size', this.size);
  316. var w = rect.width;
  317. var h = rect.height;
  318. if (this.direction == null ||
  319. this.direction == mxConstants.DIRECTION_EAST ||
  320. this.direction == mxConstants.DIRECTION_WEST)
  321. {
  322. var dy = h * size;
  323. return new mxRectangle(rect.x, rect.y + dy, w, h - 2 * dy);
  324. }
  325. else
  326. {
  327. var dx = w * size;
  328. return new mxRectangle(rect.x + dx, rect.y, w - 2 * dx, h);
  329. }
  330. }
  331. return rect;
  332. };
  333. mxCellRenderer.prototype.defaultShapes['tape'] = TapeShape;
  334. // Document shape
  335. function DocumentShape()
  336. {
  337. mxActor.call(this);
  338. };
  339. mxUtils.extend(DocumentShape, mxActor);
  340. DocumentShape.prototype.size = 0.3;
  341. DocumentShape.prototype.redrawPath = function(c, x, y, w, h)
  342. {
  343. var dy = h * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  344. var fy = 1.4;
  345. c.moveTo(0, 0);
  346. c.lineTo(w, 0);
  347. c.lineTo(w, h - dy / 2);
  348. c.quadTo(w * 3 / 4, h - dy * fy, w / 2, h - dy / 2);
  349. c.quadTo(w / 4, h - dy * (1 - fy), 0, h - dy / 2);
  350. c.lineTo(0, dy / 2);
  351. c.close();
  352. c.end();
  353. };
  354. mxCellRenderer.prototype.defaultShapes['document'] = DocumentShape;
  355. // Parallelogram shape
  356. function ParallelogramShape()
  357. {
  358. mxActor.call(this);
  359. };
  360. mxUtils.extend(ParallelogramShape, mxActor);
  361. ParallelogramShape.prototype.size = 0.2;
  362. ParallelogramShape.prototype.redrawPath = function(c, x, y, w, h)
  363. {
  364. var dx = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  365. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  366. this.addPoints(c, [new mxPoint(0, h), new mxPoint(dx, 0), new mxPoint(w, 0), new mxPoint(w - dx, h)],
  367. this.isRounded, arcSize, true);
  368. c.end();
  369. };
  370. mxCellRenderer.prototype.defaultShapes['parallelogram'] = ParallelogramShape;
  371. // Trapezoid shape
  372. function TrapezoidShape()
  373. {
  374. mxActor.call(this);
  375. };
  376. mxUtils.extend(TrapezoidShape, mxActor);
  377. TrapezoidShape.prototype.size = 0.2;
  378. TrapezoidShape.prototype.redrawPath = function(c, x, y, w, h)
  379. {
  380. var dx = w * Math.max(0, Math.min(0.5, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  381. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  382. this.addPoints(c, [new mxPoint(0, h), new mxPoint(dx, 0), new mxPoint(w - dx, 0), new mxPoint(w, h)],
  383. this.isRounded, arcSize, true);
  384. };
  385. mxCellRenderer.prototype.defaultShapes['trapezoid'] = TrapezoidShape;
  386. // Curly Bracket shape
  387. function CurlyBracketShape()
  388. {
  389. mxActor.call(this);
  390. };
  391. mxUtils.extend(CurlyBracketShape, mxActor);
  392. CurlyBracketShape.prototype.size = 0.5;
  393. CurlyBracketShape.prototype.redrawPath = function(c, x, y, w, h)
  394. {
  395. c.setFillColor(null);
  396. var s = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  397. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  398. this.addPoints(c, [new mxPoint(w, 0), new mxPoint(s, 0), new mxPoint(s, h / 2),
  399. new mxPoint(0, h / 2), new mxPoint(s, h / 2), new mxPoint(s, h),
  400. new mxPoint(w, h)], this.isRounded, arcSize, false);
  401. c.end();
  402. };
  403. mxCellRenderer.prototype.defaultShapes['curlyBracket'] = CurlyBracketShape;
  404. // Parallel marker shape
  405. function ParallelMarkerShape()
  406. {
  407. mxActor.call(this);
  408. };
  409. mxUtils.extend(ParallelMarkerShape, mxActor);
  410. ParallelMarkerShape.prototype.redrawPath = function(c, x, y, w, h)
  411. {
  412. c.setStrokeWidth(1);
  413. c.setFillColor(this.stroke);
  414. var w2 = w / 5;
  415. c.rect(0, 0, w2, h);
  416. c.fillAndStroke();
  417. c.rect(2 * w2, 0, w2, h);
  418. c.fillAndStroke();
  419. c.rect(4 * w2, 0, w2, h);
  420. c.fillAndStroke();
  421. };
  422. mxCellRenderer.prototype.defaultShapes['parallelMarker'] = ParallelMarkerShape;
  423. /**
  424. * Adds handJiggle style (jiggle=n sets jiggle)
  425. */
  426. function HandJiggle(canvas, defaultVariation)
  427. {
  428. this.canvas = canvas;
  429. // Avoids "spikes" in the output
  430. this.canvas.setLineJoin('round');
  431. this.canvas.setLineCap('round');
  432. this.defaultVariation = defaultVariation;
  433. this.originalLineTo = this.canvas.lineTo;
  434. this.canvas.lineTo = mxUtils.bind(this, HandJiggle.prototype.lineTo);
  435. this.originalMoveTo = this.canvas.moveTo;
  436. this.canvas.moveTo = mxUtils.bind(this, HandJiggle.prototype.moveTo);
  437. this.originalClose = this.canvas.close;
  438. this.canvas.close = mxUtils.bind(this, HandJiggle.prototype.close);
  439. this.originalQuadTo = this.canvas.quadTo;
  440. this.canvas.quadTo = mxUtils.bind(this, HandJiggle.prototype.quadTo);
  441. this.originalCurveTo = this.canvas.curveTo;
  442. this.canvas.curveTo = mxUtils.bind(this, HandJiggle.prototype.curveTo);
  443. this.originalArcTo = this.canvas.arcTo;
  444. this.canvas.arcTo = mxUtils.bind(this, HandJiggle.prototype.arcTo);
  445. };
  446. HandJiggle.prototype.moveTo = function(endX, endY)
  447. {
  448. this.originalMoveTo.apply(this.canvas, arguments);
  449. this.lastX = endX;
  450. this.lastY = endY;
  451. this.firstX = endX;
  452. this.firstY = endY;
  453. };
  454. HandJiggle.prototype.close = function()
  455. {
  456. if (this.firstX != null && this.firstY != null)
  457. {
  458. this.lineTo(this.firstX, this.firstY);
  459. this.originalClose.apply(this.canvas, arguments);
  460. }
  461. this.originalClose.apply(this.canvas, arguments);
  462. };
  463. HandJiggle.prototype.quadTo = function(x1, y1, x2, y2)
  464. {
  465. this.originalQuadTo.apply(this.canvas, arguments);
  466. this.lastX = x2;
  467. this.lastY = y2;
  468. };
  469. HandJiggle.prototype.curveTo = function(x1, y1, x2, y2, x3, y3)
  470. {
  471. this.originalCurveTo.apply(this.canvas, arguments);
  472. this.lastX = x3;
  473. this.lastY = y3;
  474. };
  475. HandJiggle.prototype.arcTo = function(rx, ry, angle, largeArcFlag, sweepFlag, x, y)
  476. {
  477. this.originalArcTo.apply(this.canvas, arguments);
  478. this.lastX = x;
  479. this.lastY = y;
  480. };
  481. HandJiggle.prototype.lineTo = function(endX, endY)
  482. {
  483. // LATER: Check why this.canvas.lastX cannot be used
  484. if (this.lastX != null && this.lastY != null)
  485. {
  486. var dx = Math.abs(endX - this.lastX);
  487. var dy = Math.abs(endY - this.lastY);
  488. var dist = Math.sqrt(dx * dx + dy * dy);
  489. if (dist < 2)
  490. {
  491. this.originalLineTo.apply(this.canvas, arguments);
  492. this.lastX = endX;
  493. this.lastY = endY;
  494. return;
  495. }
  496. var segs = Math.round(dist / 10);
  497. var variation = this.defaultVariation;
  498. if (segs < 5)
  499. {
  500. segs = 5;
  501. variation /= 3;
  502. }
  503. function sign(x)
  504. {
  505. return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
  506. }
  507. var stepX = sign(endX - this.lastX) * dx / segs;
  508. var stepY = sign(endY - this.lastY) * dy / segs;
  509. var fx = dx / dist;
  510. var fy = dy / dist;
  511. for (var s = 0; s < segs; s++)
  512. {
  513. var x = stepX * s + this.lastX;
  514. var y = stepY * s + this.lastY;
  515. var offset = (Math.random() - 0.5) * variation;
  516. this.originalLineTo.call(this.canvas, x - offset * fy, y - offset * fx);
  517. }
  518. this.originalLineTo.call(this.canvas, endX, endY);
  519. this.lastX = endX;
  520. this.lastY = endY;
  521. }
  522. else
  523. {
  524. this.originalLineTo.apply(this.canvas, arguments);
  525. this.lastX = endX;
  526. this.lastY = endY;
  527. }
  528. };
  529. HandJiggle.prototype.destroy = function()
  530. {
  531. this.canvas.lineTo = this.originalLineTo;
  532. this.canvas.moveTo = this.originalMoveTo;
  533. this.canvas.close = this.originalClose;
  534. this.canvas.quadTo = this.originalQuadTo;
  535. this.canvas.curveTo = this.originalCurveTo;
  536. this.canvas.arcTo = this.originalArcTo;
  537. };
  538. // Installs hand jiggle in all shapes
  539. var mxShapePaint0 = mxShape.prototype.paint;
  540. mxShape.prototype.defaultJiggle = 1.5;
  541. mxShape.prototype.paint = function(c)
  542. {
  543. // NOTE: getValue does not return a boolean value so !('0') would return true here and below
  544. if (this.style != null && mxUtils.getValue(this.style, 'comic', '0') != '0' && c.handHiggle == null)
  545. {
  546. c.handJiggle = new HandJiggle(c, mxUtils.getValue(this.style, 'jiggle', this.defaultJiggle));
  547. }
  548. mxShapePaint0.apply(this, arguments);
  549. if (c.handJiggle != null)
  550. {
  551. c.handJiggle.destroy();
  552. delete c.handJiggle;
  553. }
  554. };
  555. // Sets default jiggle for diamond
  556. mxRhombus.prototype.defaultJiggle = 2;
  557. /**
  558. * Overrides to avoid call to rect
  559. */
  560. var mxRectangleShapeIsHtmlAllowed0 = mxRectangleShape.prototype.isHtmlAllowed;
  561. mxRectangleShape.prototype.isHtmlAllowed = function()
  562. {
  563. return (this.style == null || mxUtils.getValue(this.style, 'comic', '0') == '0') &&
  564. mxRectangleShapeIsHtmlAllowed0.apply(this, arguments);
  565. };
  566. var mxRectangleShapePaintBackground0 = mxRectangleShape.prototype.paintBackground;
  567. mxRectangleShape.prototype.paintBackground = function(c, x, y, w, h)
  568. {
  569. if (c.handJiggle == null)
  570. {
  571. mxRectangleShapePaintBackground0.apply(this, arguments);
  572. }
  573. else
  574. {
  575. var events = true;
  576. if (this.style != null)
  577. {
  578. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  579. }
  580. if (events || (this.fill != null && this.fill != mxConstants.NONE) ||
  581. (this.stroke != null && this.stroke != mxConstants.NONE))
  582. {
  583. if (!events && (this.fill == null || this.fill == mxConstants.NONE))
  584. {
  585. c.pointerEvents = false;
  586. }
  587. c.begin();
  588. if (this.isRounded)
  589. {
  590. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  591. mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  592. var r = Math.min(w * f, h * f);
  593. c.moveTo(x + r, y);
  594. c.lineTo(x + w - r, y);
  595. c.quadTo(x + w, y, x + w, y + r);
  596. c.lineTo(x + w, y + h - r);
  597. c.quadTo(x + w, y + h, x + w - r, y + h);
  598. c.lineTo(x + r, y + h);
  599. c.quadTo(x, y + h, x, y + h - r);
  600. c.lineTo(x, y + r);
  601. c.quadTo(x, y, x + r, y);
  602. }
  603. else
  604. {
  605. c.moveTo(x, y);
  606. c.lineTo(x + w, y);
  607. c.lineTo(x + w, y + h);
  608. c.lineTo(x, y + h);
  609. c.lineTo(x, y);
  610. }
  611. // LATER: Check if close is needed here
  612. c.close();
  613. c.end();
  614. c.fillAndStroke();
  615. }
  616. }
  617. };
  618. /**
  619. * Disables glass effect with hand jiggle.
  620. */
  621. var mxRectangleShapePaintForeground0 = mxRectangleShape.prototype.paintForeground;
  622. mxRectangleShape.prototype.paintForeground = function(c, x, y, w, h)
  623. {
  624. if (c.handJiggle == null)
  625. {
  626. mxRectangleShapePaintForeground0.apply(this, arguments);
  627. }
  628. };
  629. // End of hand jiggle integration
  630. // Process Shape
  631. function ProcessShape()
  632. {
  633. mxRectangleShape.call(this);
  634. };
  635. mxUtils.extend(ProcessShape, mxRectangleShape);
  636. ProcessShape.prototype.size = 0.1;
  637. ProcessShape.prototype.isHtmlAllowed = function()
  638. {
  639. return false;
  640. };
  641. ProcessShape.prototype.getLabelBounds = function(rect)
  642. {
  643. if (mxUtils.getValue(this.state.style, mxConstants.STYLE_HORIZONTAL, true) ==
  644. (this.direction == null ||
  645. this.direction == mxConstants.DIRECTION_EAST ||
  646. this.direction == mxConstants.DIRECTION_WEST))
  647. {
  648. var w = rect.width;
  649. var h = rect.height;
  650. var r = new mxRectangle(rect.x, rect.y, w, h);
  651. var inset = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  652. if (this.isRounded)
  653. {
  654. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  655. mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  656. inset = Math.max(inset, Math.min(w * f, h * f));
  657. }
  658. r.x += inset;
  659. r.width -= 2 * inset;
  660. return r;
  661. }
  662. return rect;
  663. };
  664. ProcessShape.prototype.paintForeground = function(c, x, y, w, h)
  665. {
  666. var inset = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  667. if (this.isRounded)
  668. {
  669. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  670. mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  671. inset = Math.max(inset, Math.min(w * f, h * f));
  672. }
  673. c.begin();
  674. c.moveTo(x + inset, y);
  675. c.lineTo(x + inset, y + h);
  676. c.moveTo(x + w - inset, y);
  677. c.lineTo(x + w - inset, y + h);
  678. c.end();
  679. c.stroke();
  680. mxRectangleShape.prototype.paintForeground.apply(this, arguments);
  681. };
  682. mxCellRenderer.prototype.defaultShapes['process'] = ProcessShape;
  683. // Step shape
  684. function StepShape()
  685. {
  686. mxActor.call(this);
  687. };
  688. mxUtils.extend(StepShape, mxActor);
  689. StepShape.prototype.size = 0.2;
  690. StepShape.prototype.redrawPath = function(c, x, y, w, h)
  691. {
  692. var s = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  693. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  694. this.addPoints(c, [new mxPoint(0, 0), new mxPoint(w - s, 0), new mxPoint(w, h / 2), new mxPoint(w - s, h),
  695. new mxPoint(0, h), new mxPoint(s, h / 2)], this.isRounded, arcSize, true);
  696. c.end();
  697. };
  698. mxCellRenderer.prototype.defaultShapes['step'] = StepShape;
  699. // Hexagon shape
  700. function HexagonShape()
  701. {
  702. mxActor.call(this);
  703. };
  704. mxUtils.extend(HexagonShape, mxHexagon);
  705. HexagonShape.prototype.size = 0.25;
  706. HexagonShape.prototype.redrawPath = function(c, x, y, w, h)
  707. {
  708. var s = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  709. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  710. this.addPoints(c, [new mxPoint(s, 0), new mxPoint(w - s, 0), new mxPoint(w, 0.5 * h), new mxPoint(w - s, h),
  711. new mxPoint(s, h), new mxPoint(0, 0.5 * h)], this.isRounded, arcSize, true);
  712. };
  713. mxCellRenderer.prototype.defaultShapes['hexagon'] = HexagonShape;
  714. // Plus Shape
  715. function PlusShape()
  716. {
  717. mxRectangleShape.call(this);
  718. };
  719. mxUtils.extend(PlusShape, mxRectangleShape);
  720. PlusShape.prototype.isHtmlAllowed = function()
  721. {
  722. return false;
  723. };
  724. PlusShape.prototype.paintForeground = function(c, x, y, w, h)
  725. {
  726. var border = Math.min(w / 5, h / 5) + 1;
  727. c.begin();
  728. c.moveTo(x + w / 2, y + border);
  729. c.lineTo(x + w / 2, y + h - border);
  730. c.moveTo(x + border, y + h / 2);
  731. c.lineTo(x + w - border, y + h / 2);
  732. c.end();
  733. c.stroke();
  734. mxRectangleShape.prototype.paintForeground.apply(this, arguments);
  735. };
  736. mxCellRenderer.prototype.defaultShapes['plus'] = PlusShape;
  737. // Overrides painting of rhombus shape to allow for double style
  738. var mxRhombusPaintVertexShape = mxRhombus.prototype.paintVertexShape;
  739. mxRhombus.prototype.getLabelBounds = function(rect)
  740. {
  741. if (this.style['double'] == 1)
  742. {
  743. var margin = (Math.max(2, this.strokewidth + 1) * 2 + parseFloat(this.style[mxConstants.STYLE_MARGIN] || 0)) * this.scale;
  744. return new mxRectangle(rect.x + margin, rect.y + margin, rect.width - 2 * margin, rect.height - 2 * margin);
  745. }
  746. return rect;
  747. };
  748. mxRhombus.prototype.paintVertexShape = function(c, x, y, w, h)
  749. {
  750. mxRhombusPaintVertexShape.apply(this, arguments);
  751. if (!this.outline && this.style['double'] == 1)
  752. {
  753. var margin = Math.max(2, this.strokewidth + 1) * 2 + parseFloat(this.style[mxConstants.STYLE_MARGIN] || 0);
  754. x += margin;
  755. y += margin;
  756. w -= 2 * margin;
  757. h -= 2 * margin;
  758. if (w > 0 && h > 0)
  759. {
  760. c.setShadow(false);
  761. // Workaround for closure compiler bug where the lines with x and y above
  762. // are removed if arguments is used as second argument in call below.
  763. mxRhombusPaintVertexShape.apply(this, [c, x, y, w, h]);
  764. }
  765. }
  766. };
  767. // CompositeShape
  768. function ExtendedShape()
  769. {
  770. mxRectangleShape.call(this);
  771. };
  772. mxUtils.extend(ExtendedShape, mxRectangleShape);
  773. ExtendedShape.prototype.isHtmlAllowed = function()
  774. {
  775. return false;
  776. };
  777. ExtendedShape.prototype.getLabelBounds = function(rect)
  778. {
  779. if (this.style['double'] == 1)
  780. {
  781. var margin = (Math.max(2, this.strokewidth + 1) + parseFloat(this.style[mxConstants.STYLE_MARGIN] || 0)) * this.scale;
  782. return new mxRectangle(rect.x + margin, rect.y + margin, rect.width - 2 * margin, rect.height - 2 * margin);
  783. }
  784. return rect;
  785. };
  786. ExtendedShape.prototype.paintForeground = function(c, x, y, w, h)
  787. {
  788. if (this.style != null)
  789. {
  790. if (!this.outline && this.style['double'] == 1)
  791. {
  792. var margin = Math.max(2, this.strokewidth + 1) + parseFloat(this.style[mxConstants.STYLE_MARGIN] || 0);
  793. x += margin;
  794. y += margin;
  795. w -= 2 * margin;
  796. h -= 2 * margin;
  797. if (w > 0 && h > 0)
  798. {
  799. mxRectangleShape.prototype.paintBackground.apply(this, arguments);
  800. }
  801. }
  802. c.setDashed(false);
  803. // Draws the symbols defined in the style. The symbols are
  804. // numbered from 1...n. Possible postfixes are align,
  805. // verticalAlign, spacing, arcSpacing, width, height
  806. var counter = 0;
  807. var shape = null;
  808. do
  809. {
  810. shape = mxCellRenderer.prototype.defaultShapes[this.style['symbol' + counter]];
  811. if (shape != null)
  812. {
  813. var align = this.style['symbol' + counter + 'Align'];
  814. var valign = this.style['symbol' + counter + 'VerticalAlign'];
  815. var width = this.style['symbol' + counter + 'Width'];
  816. var height = this.style['symbol' + counter + 'Height'];
  817. var spacing = this.style['symbol' + counter + 'Spacing'] || 0;
  818. var vspacing = this.style['symbol' + counter + 'VSpacing'] || spacing;
  819. var arcspacing = this.style['symbol' + counter + 'ArcSpacing'];
  820. if (arcspacing != null)
  821. {
  822. var arcSize = this.getArcSize(w + this.strokewidth, h + this.strokewidth) * arcspacing;
  823. spacing += arcSize;
  824. vspacing += arcSize;
  825. }
  826. var x2 = x;
  827. var y2 = y;
  828. if (align == mxConstants.ALIGN_CENTER)
  829. {
  830. x2 += (w - width) / 2;
  831. }
  832. else if (align == mxConstants.ALIGN_RIGHT)
  833. {
  834. x2 += w - width - spacing;
  835. }
  836. else
  837. {
  838. x2 += spacing;
  839. }
  840. if (valign == mxConstants.ALIGN_MIDDLE)
  841. {
  842. y2 += (h - height) / 2;
  843. }
  844. else if (valign == mxConstants.ALIGN_BOTTOM)
  845. {
  846. y2 += h - height - vspacing;
  847. }
  848. else
  849. {
  850. y2 += vspacing;
  851. }
  852. c.save();
  853. // Small hack to pass style along into subshape
  854. var tmp = new shape();
  855. // TODO: Clone style and override settings (eg. strokewidth)
  856. tmp.style = this.style;
  857. shape.prototype.paintVertexShape.call(tmp, c, x2, y2, width, height);
  858. c.restore();
  859. }
  860. counter++;
  861. }
  862. while (shape != null);
  863. }
  864. // Paints glass effect
  865. mxRectangleShape.prototype.paintForeground.apply(this, arguments);
  866. };
  867. mxCellRenderer.prototype.defaultShapes['ext'] = ExtendedShape;
  868. // Tape Shape, supports size style
  869. function MessageShape()
  870. {
  871. mxCylinder.call(this);
  872. };
  873. mxUtils.extend(MessageShape, mxCylinder);
  874. MessageShape.prototype.redrawPath = function(path, x, y, w, h, isForeground)
  875. {
  876. if (isForeground)
  877. {
  878. path.moveTo(0, 0);
  879. path.lineTo(w / 2, h / 2);
  880. path.lineTo(w, 0);
  881. path.end();
  882. }
  883. else
  884. {
  885. path.moveTo(0, 0);
  886. path.lineTo(w, 0);
  887. path.lineTo(w, h);
  888. path.lineTo(0, h);
  889. path.close();
  890. }
  891. };
  892. mxCellRenderer.prototype.defaultShapes['message'] = MessageShape;
  893. // UML Actor Shape
  894. function UmlActorShape()
  895. {
  896. mxShape.call(this);
  897. };
  898. mxUtils.extend(UmlActorShape, mxShape);
  899. UmlActorShape.prototype.paintBackground = function(c, x, y, w, h)
  900. {
  901. c.translate(x, y);
  902. // Head
  903. c.ellipse(w / 4, 0, w / 2, h / 4);
  904. c.fillAndStroke();
  905. c.begin();
  906. c.moveTo(w / 2, h / 4);
  907. c.lineTo(w / 2, 2 * h / 3);
  908. // Arms
  909. c.moveTo(w / 2, h / 3);
  910. c.lineTo(0, h / 3);
  911. c.moveTo(w / 2, h / 3);
  912. c.lineTo(w, h / 3);
  913. // Legs
  914. c.moveTo(w / 2, 2 * h / 3);
  915. c.lineTo(0, h);
  916. c.moveTo(w / 2, 2 * h / 3);
  917. c.lineTo(w, h);
  918. c.end();
  919. c.stroke();
  920. };
  921. // Replaces existing actor shape
  922. mxCellRenderer.prototype.defaultShapes['umlActor'] = UmlActorShape;
  923. // UML Boundary Shape
  924. function UmlBoundaryShape()
  925. {
  926. mxShape.call(this);
  927. };
  928. mxUtils.extend(UmlBoundaryShape, mxShape);
  929. UmlBoundaryShape.prototype.getLabelBounds = function(rect)
  930. {
  931. return new mxRectangle(rect.x + rect.width / 6, rect.y, rect.width * 5 / 6, rect.height);
  932. };
  933. UmlBoundaryShape.prototype.paintBackground = function(c, x, y, w, h)
  934. {
  935. c.translate(x, y);
  936. // Base line
  937. c.begin();
  938. c.moveTo(0, h / 4);
  939. c.lineTo(0, h * 3 / 4);
  940. c.end();
  941. c.stroke();
  942. // Horizontal line
  943. c.begin();
  944. c.moveTo(0, h / 2);
  945. c.lineTo(w / 6, h / 2);
  946. c.end();
  947. c.stroke();
  948. // Circle
  949. c.ellipse(w / 6, 0, w * 5 / 6, h);
  950. c.fillAndStroke();
  951. };
  952. // Replaces existing actor shape
  953. mxCellRenderer.prototype.defaultShapes['umlBoundary'] = UmlBoundaryShape;
  954. // UML Entity Shape
  955. function UmlEntityShape()
  956. {
  957. mxEllipse.call(this);
  958. };
  959. mxUtils.extend(UmlEntityShape, mxEllipse);
  960. UmlEntityShape.prototype.paintVertexShape = function(c, x, y, w, h)
  961. {
  962. mxEllipse.prototype.paintVertexShape.apply(this, arguments);
  963. c.begin();
  964. c.moveTo(x + w / 8, y + h);
  965. c.lineTo(x + w * 7 / 8, y + h);
  966. c.end();
  967. c.stroke();
  968. };
  969. mxCellRenderer.prototype.defaultShapes['umlEntity'] = UmlEntityShape;
  970. // UML Destroy Shape
  971. function UmlDestroyShape()
  972. {
  973. mxShape.call(this);
  974. };
  975. mxUtils.extend(UmlDestroyShape, mxShape);
  976. UmlDestroyShape.prototype.paintVertexShape = function(c, x, y, w, h)
  977. {
  978. c.translate(x, y);
  979. c.begin();
  980. c.moveTo(w, 0);
  981. c.lineTo(0, h);
  982. c.moveTo(0, 0);
  983. c.lineTo(w, h);
  984. c.end();
  985. c.stroke();
  986. };
  987. mxCellRenderer.prototype.defaultShapes['umlDestroy'] = UmlDestroyShape;
  988. // UML Control Shape
  989. function UmlControlShape()
  990. {
  991. mxShape.call(this);
  992. };
  993. mxUtils.extend(UmlControlShape, mxShape);
  994. UmlControlShape.prototype.getLabelBounds = function(rect)
  995. {
  996. return new mxRectangle(rect.x, rect.y + rect.height / 8, rect.width, rect.height * 7 / 8);
  997. };
  998. UmlControlShape.prototype.paintBackground = function(c, x, y, w, h)
  999. {
  1000. c.translate(x, y);
  1001. // Upper line
  1002. c.begin();
  1003. c.moveTo(w * 3 / 8, h / 8 * 1.1);
  1004. c.lineTo(w * 5 / 8, 0);
  1005. c.end();
  1006. c.stroke();
  1007. // Circle
  1008. c.ellipse(0, h / 8, w, h * 7 / 8);
  1009. c.fillAndStroke();
  1010. };
  1011. UmlControlShape.prototype.paintForeground = function(c, x, y, w, h)
  1012. {
  1013. // Lower line
  1014. c.begin();
  1015. c.moveTo(w * 3 / 8, h / 8 * 1.1);
  1016. c.lineTo(w * 5 / 8, h / 4);
  1017. c.end();
  1018. c.stroke();
  1019. };
  1020. // Replaces existing actor shape
  1021. mxCellRenderer.prototype.defaultShapes['umlControl'] = UmlControlShape;
  1022. // UML Lifeline Shape
  1023. function UmlLifeline()
  1024. {
  1025. mxRectangleShape.call(this);
  1026. };
  1027. mxUtils.extend(UmlLifeline, mxRectangleShape);
  1028. UmlLifeline.prototype.size = 40;
  1029. UmlLifeline.prototype.isHtmlAllowed = function()
  1030. {
  1031. return false;
  1032. };
  1033. UmlLifeline.prototype.getLabelBounds = function(rect)
  1034. {
  1035. var size = Math.max(0, Math.min(rect.height, parseFloat(mxUtils.getValue(this.style, 'size', this.size)) * this.scale));
  1036. return new mxRectangle(rect.x, rect.y, rect.width, size);
  1037. };
  1038. UmlLifeline.prototype.paintBackground = function(c, x, y, w, h)
  1039. {
  1040. var size = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  1041. var participant = mxUtils.getValue(this.style, 'participant');
  1042. if (participant == null || this.state == null)
  1043. {
  1044. mxRectangleShape.prototype.paintBackground.call(this, c, x, y, w, size);
  1045. }
  1046. else
  1047. {
  1048. var ctor = this.state.view.graph.cellRenderer.getShape(participant);
  1049. if (ctor != null && ctor != UmlLifeline)
  1050. {
  1051. var shape = new ctor();
  1052. shape.apply(this.state);
  1053. c.save();
  1054. shape.paintVertexShape(c, x, y, w, size);
  1055. c.restore();
  1056. }
  1057. }
  1058. if (size < h)
  1059. {
  1060. c.setDashed(true);
  1061. c.begin();
  1062. c.moveTo(x + w / 2, y + size);
  1063. c.lineTo(x + w / 2, y + h);
  1064. c.end();
  1065. c.stroke();
  1066. }
  1067. };
  1068. UmlLifeline.prototype.paintForeground = function(c, x, y, w, h)
  1069. {
  1070. var size = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  1071. mxRectangleShape.prototype.paintForeground.call(this, c, x, y, w, Math.min(h, size));
  1072. };
  1073. mxCellRenderer.prototype.defaultShapes['umlLifeline'] = UmlLifeline;
  1074. // UML Frame Shape
  1075. function UmlFrame()
  1076. {
  1077. mxShape.call(this);
  1078. };
  1079. mxUtils.extend(UmlFrame, mxShape);
  1080. UmlFrame.prototype.width = 60;
  1081. UmlFrame.prototype.height = 30;
  1082. UmlFrame.prototype.corner = 10;
  1083. UmlFrame.prototype.getLabelBounds = function(rect)
  1084. {
  1085. var w = Math.max(0, Math.min(rect.width, parseFloat(mxUtils.getValue(this.style, 'width', this.width)) * this.scale));
  1086. var h = Math.max(0, Math.min(rect.height, parseFloat(mxUtils.getValue(this.style, 'height', this.height)) * this.scale));
  1087. return new mxRectangle(rect.x, rect.y, w, h);
  1088. };
  1089. UmlFrame.prototype.paintBackground = function(c, x, y, w, h)
  1090. {
  1091. var co = this.corner;
  1092. var w0 = Math.min(w, Math.max(co, parseFloat(mxUtils.getValue(this.style, 'width', this.width))));
  1093. var h0 = Math.min(h, Math.max(co * 1.5, parseFloat(mxUtils.getValue(this.style, 'height', this.height))));
  1094. c.begin();
  1095. c.moveTo(x, y);
  1096. c.lineTo(x + w0, y);
  1097. c.lineTo(x + w0, y + Math.max(0, h0 - co * 1.5));
  1098. c.lineTo(x + Math.max(0, w0 - co), y + h0);
  1099. c.lineTo(x, y + h0);
  1100. c.close();
  1101. c.fillAndStroke();
  1102. c.begin();
  1103. c.moveTo(x + w0, y);
  1104. c.lineTo(x + w, y);
  1105. c.lineTo(x + w, y + h);
  1106. c.lineTo(x, y + h);
  1107. c.lineTo(x, y + h0);
  1108. c.stroke();
  1109. };
  1110. mxCellRenderer.prototype.defaultShapes['umlFrame'] = UmlFrame;
  1111. mxPerimeter.LifelinePerimeter = function (bounds, vertex, next, orthogonal)
  1112. {
  1113. var size = UmlLifeline.prototype.size;
  1114. if (vertex != null)
  1115. {
  1116. size = mxUtils.getValue(vertex.style, 'size', size) * vertex.view.scale;
  1117. }
  1118. var sw = (parseFloat(vertex.style[mxConstants.STYLE_STROKEWIDTH] || 1) * vertex.view.scale / 2) - 1;
  1119. if (next.x < bounds.getCenterX())
  1120. {
  1121. sw += 1;
  1122. sw *= -1;
  1123. }
  1124. return new mxPoint(bounds.getCenterX() + sw, Math.min(bounds.y + bounds.height,
  1125. Math.max(bounds.y + size, next.y)));
  1126. };
  1127. mxStyleRegistry.putValue('lifelinePerimeter', mxPerimeter.LifelinePerimeter);
  1128. mxPerimeter.OrthogonalPerimeter = function (bounds, vertex, next, orthogonal)
  1129. {
  1130. orthogonal = true;
  1131. return mxPerimeter.RectanglePerimeter.apply(this, arguments);
  1132. };
  1133. mxStyleRegistry.putValue('orthogonalPerimeter', mxPerimeter.OrthogonalPerimeter);
  1134. mxPerimeter.BackbonePerimeter = function (bounds, vertex, next, orthogonal)
  1135. {
  1136. var sw = (parseFloat(vertex.style[mxConstants.STYLE_STROKEWIDTH] || 1) * vertex.view.scale / 2) - 1;
  1137. if (vertex.style['backboneSize'] != null)
  1138. {
  1139. sw += (parseFloat(vertex.style['backboneSize']) * vertex.view.scale / 2) - 1;
  1140. }
  1141. if (vertex.style[mxConstants.STYLE_DIRECTION] == 'south' ||
  1142. vertex.style[mxConstants.STYLE_DIRECTION] == 'north')
  1143. {
  1144. if (next.x < bounds.getCenterX())
  1145. {
  1146. sw += 1;
  1147. sw *= -1;
  1148. }
  1149. return new mxPoint(bounds.getCenterX() + sw, Math.min(bounds.y + bounds.height,
  1150. Math.max(bounds.y, next.y)));
  1151. }
  1152. else
  1153. {
  1154. if (next.y < bounds.getCenterY())
  1155. {
  1156. sw += 1;
  1157. sw *= -1;
  1158. }
  1159. return new mxPoint(Math.min(bounds.x + bounds.width, Math.max(bounds.x, next.x)),
  1160. bounds.getCenterY() + sw);
  1161. }
  1162. };
  1163. mxStyleRegistry.putValue('backbonePerimeter', mxPerimeter.BackbonePerimeter);
  1164. mxPerimeter.lineIntersection = function (line1Start, line1End, line2Start, line2End)
  1165. {
  1166. // if the lines intersect, the result contains the the
  1167. // intersection point if both line segment 1 and line segment 2 contain the point
  1168. // null otherwise
  1169. var denominator = ((line2End.y - line2Start.y) * (line1End.x - line1Start.x))
  1170. - ((line2End.x - line2Start.x) * (line1End.y - line1Start.y));
  1171. if (denominator == 0) //parallel?
  1172. {
  1173. return null;
  1174. }
  1175. else
  1176. {
  1177. var a = line1Start.y - line2Start.y;
  1178. var b = line1Start.x - line2Start.x;
  1179. var numerator1 = ((line2End.x - line2Start.x) * a) - ((line2End.y - line2Start.y) * b);
  1180. var numerator2 = ((line1End.x - line1Start.x) * a) - ((line1End.y - line1Start.y) * b);
  1181. a = numerator1 / denominator;
  1182. b = numerator2 / denominator;
  1183. // if we cast these lines infinitely in both directions, they intersect here:
  1184. var x = line1Start.x + (a * (line1End.x - line1Start.x));
  1185. var y = line1Start.y + (a * (line1End.y - line1Start.y));
  1186. if (a >= 0 && a <= 1)// on line1?
  1187. {
  1188. var dx = line2End.x - x;
  1189. var dy = line2End.y - y;
  1190. var d = Math.sqrt(dy * dy + dx * dx); //distance from end of line 2 (next) to intersection point
  1191. return {dist: d, p: new mxPoint(x, y)};
  1192. }
  1193. else
  1194. {
  1195. return null;
  1196. }
  1197. }
  1198. };
  1199. mxPerimeter.getPerimeterPoint = function (points, center, point)
  1200. {
  1201. var min = false;
  1202. for (var i = 0; i < points.length - 1; i++)
  1203. {
  1204. var ip = mxPerimeter.lineIntersection(points[i], points[i + 1], center, point);
  1205. if (ip != null && (!min || min.dist > ip.dist))
  1206. {
  1207. min = ip;
  1208. }
  1209. }
  1210. return min.p;
  1211. };
  1212. //Parallelogram Perimeter
  1213. mxPerimeter.ParallelogramPerimeter = function (bounds, vertex, next, orthogonal)
  1214. {
  1215. var size = ParallelogramShape.prototype.size;
  1216. if (vertex != null)
  1217. {
  1218. size = mxUtils.getValue(vertex.style, 'size', size);
  1219. }
  1220. var x = bounds.x;
  1221. var y = bounds.y;
  1222. var w = bounds.width;
  1223. var h = bounds.height;
  1224. var direction = (vertex != null) ? mxUtils.getValue(
  1225. vertex.style, mxConstants.STYLE_DIRECTION,
  1226. mxConstants.DIRECTION_EAST) : mxConstants.DIRECTION_EAST;
  1227. var vertical = direction == mxConstants.DIRECTION_NORTH
  1228. || direction == mxConstants.DIRECTION_SOUTH;
  1229. var points;
  1230. if (vertical)
  1231. {
  1232. var dy = h * Math.max(0, Math.min(1, size));
  1233. points = [new mxPoint(x, y), new mxPoint(x + w, y + dy),
  1234. new mxPoint(x + w, y + h), new mxPoint(x, y + h - dy), new mxPoint(x, y)];
  1235. }
  1236. else
  1237. {
  1238. var dx = w * Math.max(0, Math.min(1, size));
  1239. points = [new mxPoint(x + dx, y), new mxPoint(x + w, y),
  1240. new mxPoint(x + w - dx, y + h), new mxPoint(x, y + h), new mxPoint(x + dx, y)];
  1241. }
  1242. var cx = bounds.getCenterX();
  1243. var cy = bounds.getCenterY();
  1244. var p1 = new mxPoint(cx, cy);
  1245. if (orthogonal)
  1246. {
  1247. if (next.x < x || next.x > x + w)
  1248. p1.y = next.y;
  1249. else
  1250. p1.x = next.x;
  1251. }
  1252. return mxPerimeter.getPerimeterPoint(points, p1, next);
  1253. };
  1254. mxStyleRegistry.putValue('parallelogramPerimeter', mxPerimeter.ParallelogramPerimeter);
  1255. //Trapezoid Perimeter
  1256. mxPerimeter.TrapezoidPerimeter = function (bounds, vertex, next, orthogonal)
  1257. {
  1258. var size = TrapezoidShape.prototype.size;
  1259. if (vertex != null)
  1260. {
  1261. size = mxUtils.getValue(vertex.style, 'size', size);
  1262. }
  1263. var x = bounds.x;
  1264. var y = bounds.y;
  1265. var w = bounds.width;
  1266. var h = bounds.height;
  1267. var direction = (vertex != null) ? mxUtils.getValue(
  1268. vertex.style, mxConstants.STYLE_DIRECTION,
  1269. mxConstants.DIRECTION_EAST) : mxConstants.DIRECTION_EAST;
  1270. var points;
  1271. if (direction == mxConstants.DIRECTION_EAST)
  1272. {
  1273. var dx = w * Math.max(0, Math.min(1, size));
  1274. points = [new mxPoint(x + dx, y), new mxPoint(x + w - dx, y),
  1275. new mxPoint(x + w, y + h), new mxPoint(x, y + h), new mxPoint(x + dx, y)];
  1276. }
  1277. else if (direction == mxConstants.DIRECTION_WEST)
  1278. {
  1279. var dx = w * Math.max(0, Math.min(1, size));
  1280. points = [new mxPoint(x, y), new mxPoint(x + w, y),
  1281. new mxPoint(x + w - dx, y + h), new mxPoint(x + dx, y + h), new mxPoint(x, y)];
  1282. }
  1283. else if (direction == mxConstants.DIRECTION_NORTH)
  1284. {
  1285. var dy = h * Math.max(0, Math.min(1, size));
  1286. points = [new mxPoint(x, y + dy), new mxPoint(x + w, y),
  1287. new mxPoint(x + w, y + h), new mxPoint(x, y + h - dy), new mxPoint(x, y + dy)];
  1288. }
  1289. else
  1290. {
  1291. var dy = h * Math.max(0, Math.min(1, size));
  1292. points = [new mxPoint(x, y), new mxPoint(x + w, y + dy),
  1293. new mxPoint(x + w, y + h - dy), new mxPoint(x, y + h), new mxPoint(x, y)];
  1294. }
  1295. var cx = bounds.getCenterX();
  1296. var cy = bounds.getCenterY();
  1297. var p1 = new mxPoint(cx, cy);
  1298. if (orthogonal)
  1299. {
  1300. if (next.x < x || next.x > x + w)
  1301. p1.y = next.y;
  1302. else
  1303. p1.x = next.x;
  1304. }
  1305. return mxPerimeter.getPerimeterPoint(points, p1, next);
  1306. };
  1307. mxStyleRegistry.putValue('trapezoidPerimeter', mxPerimeter.TrapezoidPerimeter);
  1308. //Step Perimeter
  1309. mxPerimeter.StepPerimeter = function (bounds, vertex, next, orthogonal)
  1310. {
  1311. var size = StepShape.prototype.size;
  1312. if (vertex != null)
  1313. {
  1314. size = mxUtils.getValue(vertex.style, 'size', size);
  1315. }
  1316. var x = bounds.x;
  1317. var y = bounds.y;
  1318. var w = bounds.width;
  1319. var h = bounds.height;
  1320. var cx = bounds.getCenterX();
  1321. var cy = bounds.getCenterY();
  1322. var direction = (vertex != null) ? mxUtils.getValue(
  1323. vertex.style, mxConstants.STYLE_DIRECTION,
  1324. mxConstants.DIRECTION_EAST) : mxConstants.DIRECTION_EAST;
  1325. var points;
  1326. if (direction == mxConstants.DIRECTION_EAST)
  1327. {
  1328. var dx = w * Math.max(0, Math.min(1, size));
  1329. points = [new mxPoint(x, y), new mxPoint(x + w - dx, y), new mxPoint(x + w, cy),
  1330. new mxPoint(x + w - dx, y + h), new mxPoint(x, y + h),
  1331. new mxPoint(x + dx, cy), new mxPoint(x, y)];
  1332. }
  1333. else if (direction == mxConstants.DIRECTION_WEST)
  1334. {
  1335. var dx = w * Math.max(0, Math.min(1, size));
  1336. points = [new mxPoint(x + dx, y), new mxPoint(x + w, y), new mxPoint(x + w - dx, cy),
  1337. new mxPoint(x + w, y + h), new mxPoint(x + dx, y + h),
  1338. new mxPoint(x, cy), new mxPoint(x + dx, y)];
  1339. }
  1340. else if (direction == mxConstants.DIRECTION_NORTH)
  1341. {
  1342. var dy = h * Math.max(0, Math.min(1, size));
  1343. points = [new mxPoint(x, y + dy), new mxPoint(cx, y), new mxPoint(x + w, y + dy),
  1344. new mxPoint(x + w, y + h), new mxPoint(cx, y + h - dy),
  1345. new mxPoint(x, y + h), new mxPoint(x, y + dy)];
  1346. }
  1347. else
  1348. {
  1349. var dy = h * Math.max(0, Math.min(1, size));
  1350. points = [new mxPoint(x, y), new mxPoint(cx, y + dy), new mxPoint(x + w, y),
  1351. new mxPoint(x + w, y + h - dy), new mxPoint(cx, y + h),
  1352. new mxPoint(x, y + h - dy), new mxPoint(x, y)];
  1353. }
  1354. var p1 = new mxPoint(cx, cy);
  1355. if (orthogonal)
  1356. {
  1357. if (next.x < x || next.x > x + w)
  1358. p1.y = next.y;
  1359. else
  1360. p1.x = next.x;
  1361. }
  1362. return mxPerimeter.getPerimeterPoint(points, p1, next);
  1363. };
  1364. mxStyleRegistry.putValue('stepPerimeter', mxPerimeter.StepPerimeter);
  1365. //Hexagon Perimeter (keep existing one)
  1366. mxPerimeter.HexagonPerimeter2 = function (bounds, vertex, next, orthogonal)
  1367. {
  1368. var size = HexagonShape.prototype.size;
  1369. if (vertex != null)
  1370. {
  1371. size = mxUtils.getValue(vertex.style, 'size', size);
  1372. }
  1373. var x = bounds.x;
  1374. var y = bounds.y;
  1375. var w = bounds.width;
  1376. var h = bounds.height;
  1377. var cx = bounds.getCenterX();
  1378. var cy = bounds.getCenterY();
  1379. var direction = (vertex != null) ? mxUtils.getValue(
  1380. vertex.style, mxConstants.STYLE_DIRECTION,
  1381. mxConstants.DIRECTION_EAST) : mxConstants.DIRECTION_EAST;
  1382. var vertical = direction == mxConstants.DIRECTION_NORTH
  1383. || direction == mxConstants.DIRECTION_SOUTH;
  1384. var points;
  1385. if (vertical)
  1386. {
  1387. var dy = h * Math.max(0, Math.min(1, size));
  1388. points = [new mxPoint(cx, y), new mxPoint(x + w, y + dy), new mxPoint(x + w, y + h - dy),
  1389. new mxPoint(cx, y + h), new mxPoint(x, y + h - dy),
  1390. new mxPoint(x, y + dy), new mxPoint(cx, y)];
  1391. }
  1392. else
  1393. {
  1394. var dx = w * Math.max(0, Math.min(1, size));
  1395. points = [new mxPoint(x + dx, y), new mxPoint(x + w - dx, y), new mxPoint(x + w, cy),
  1396. new mxPoint(x + w - dx, y + h), new mxPoint(x + dx, y + h),
  1397. new mxPoint(x, cy), new mxPoint(x + dx, y)];
  1398. }
  1399. var p1 = new mxPoint(cx, cy);
  1400. if (orthogonal)
  1401. {
  1402. if (next.x < x || next.x > x + w)
  1403. p1.y = next.y;
  1404. else
  1405. p1.x = next.x;
  1406. }
  1407. return mxPerimeter.getPerimeterPoint(points, p1, next);
  1408. };
  1409. mxStyleRegistry.putValue('hexagonPerimeter2', mxPerimeter.HexagonPerimeter2);
  1410. // Lollipop Shape
  1411. function LollipopShape()
  1412. {
  1413. mxShape.call(this);
  1414. };
  1415. mxUtils.extend(LollipopShape, mxShape);
  1416. LollipopShape.prototype.size = 10;
  1417. LollipopShape.prototype.paintBackground = function(c, x, y, w, h)
  1418. {
  1419. var sz = parseFloat(mxUtils.getValue(this.style, 'size', this.size));
  1420. c.translate(x, y);
  1421. c.ellipse((w - sz) / 2, 0, sz, sz);
  1422. c.fillAndStroke();
  1423. c.begin();
  1424. c.moveTo(w / 2, sz);
  1425. c.lineTo(w / 2, h);
  1426. c.end();
  1427. c.stroke();
  1428. };
  1429. mxCellRenderer.prototype.defaultShapes['lollipop'] = LollipopShape;
  1430. // Lollipop Shape
  1431. function RequiresShape()
  1432. {
  1433. mxShape.call(this);
  1434. };
  1435. mxUtils.extend(RequiresShape, mxShape);
  1436. RequiresShape.prototype.size = 10;
  1437. RequiresShape.prototype.inset = 2;
  1438. RequiresShape.prototype.paintBackground = function(c, x, y, w, h)
  1439. {
  1440. var sz = parseFloat(mxUtils.getValue(this.style, 'size', this.size));
  1441. var inset = parseFloat(mxUtils.getValue(this.style, 'inset', this.inset)) + this.strokewidth;
  1442. c.translate(x, y);
  1443. c.begin();
  1444. c.moveTo(w / 2, sz + inset);
  1445. c.lineTo(w / 2, h);
  1446. c.end();
  1447. c.stroke();
  1448. c.begin();
  1449. c.moveTo((w - sz) / 2 - inset, sz / 2);
  1450. c.quadTo((w - sz) / 2 - inset, sz + inset, w / 2, sz + inset);
  1451. c.quadTo((w + sz) / 2 + inset, sz + inset, (w + sz) / 2 + inset, sz / 2);
  1452. c.end();
  1453. c.stroke();
  1454. };
  1455. mxCellRenderer.prototype.defaultShapes['requires'] = RequiresShape;
  1456. // Component shape
  1457. function ComponentShape()
  1458. {
  1459. mxCylinder.call(this);
  1460. };
  1461. mxUtils.extend(ComponentShape, mxCylinder);
  1462. ComponentShape.prototype.jettyWidth = 32;
  1463. ComponentShape.prototype.jettyHeight = 12;
  1464. ComponentShape.prototype.redrawPath = function(path, x, y, w, h, isForeground)
  1465. {
  1466. var dx = parseFloat(mxUtils.getValue(this.style, 'jettyWidth', this.jettyWidth));
  1467. var dy = parseFloat(mxUtils.getValue(this.style, 'jettyHeight', this.jettyHeight));
  1468. var x0 = dx / 2;
  1469. var x1 = x0 + dx / 2;
  1470. var y0 = 0.3 * h - dy / 2;
  1471. var y1 = 0.7 * h - dy / 2;
  1472. if (isForeground)
  1473. {
  1474. path.moveTo(x0, y0);
  1475. path.lineTo(x1, y0);
  1476. path.lineTo(x1, y0 + dy);
  1477. path.lineTo(x0, y0 + dy);
  1478. path.moveTo(x0, y1);
  1479. path.lineTo(x1, y1);
  1480. path.lineTo(x1, y1 + dy);
  1481. path.lineTo(x0, y1 + dy);
  1482. path.end();
  1483. }
  1484. else
  1485. {
  1486. path.moveTo(x0, 0);
  1487. path.lineTo(w, 0);
  1488. path.lineTo(w, h);
  1489. path.lineTo(x0, h);
  1490. path.lineTo(x0, y1 + dy);
  1491. path.lineTo(0, y1 + dy);
  1492. path.lineTo(0, y1);
  1493. path.lineTo(x0, y1);
  1494. path.lineTo(x0, y0 + dy);
  1495. path.lineTo(0, y0 + dy);
  1496. path.lineTo(0, y0);
  1497. path.lineTo(x0, y0);
  1498. path.close();
  1499. path.end();
  1500. }
  1501. };
  1502. mxCellRenderer.prototype.defaultShapes['component'] = ComponentShape;
  1503. // State Shapes derives from double ellipse
  1504. function StateShape()
  1505. {
  1506. mxDoubleEllipse.call(this);
  1507. };
  1508. mxUtils.extend(StateShape, mxDoubleEllipse);
  1509. StateShape.prototype.outerStroke = true;
  1510. StateShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1511. {
  1512. var inset = Math.min(4, Math.min(w / 5, h / 5));
  1513. if (w > 0 && h > 0)
  1514. {
  1515. c.ellipse(x + inset, y + inset, w - 2 * inset, h - 2 * inset);
  1516. c.fillAndStroke();
  1517. }
  1518. c.setShadow(false);
  1519. if (this.outerStroke)
  1520. {
  1521. c.ellipse(x, y, w, h);
  1522. c.stroke();
  1523. }
  1524. };
  1525. mxCellRenderer.prototype.defaultShapes['endState'] = StateShape;
  1526. function StartStateShape()
  1527. {
  1528. StateShape.call(this);
  1529. };
  1530. mxUtils.extend(StartStateShape, StateShape);
  1531. StartStateShape.prototype.outerStroke = false;
  1532. mxCellRenderer.prototype.defaultShapes['startState'] = StartStateShape;
  1533. // Link shape
  1534. function LinkShape()
  1535. {
  1536. mxArrowConnector.call(this);
  1537. this.spacing = 0;
  1538. };
  1539. mxUtils.extend(LinkShape, mxArrowConnector);
  1540. LinkShape.prototype.defaultWidth = 4;
  1541. LinkShape.prototype.isOpenEnded = function()
  1542. {
  1543. return true;
  1544. };
  1545. LinkShape.prototype.getEdgeWidth = function()
  1546. {
  1547. return mxUtils.getNumber(this.style, 'width', this.defaultWidth) + Math.max(0, this.strokewidth - 1);
  1548. };
  1549. LinkShape.prototype.isArrowRounded = function()
  1550. {
  1551. return this.isRounded;
  1552. };
  1553. // Registers the link shape
  1554. mxCellRenderer.prototype.defaultShapes['link'] = LinkShape;
  1555. // Generic arrow
  1556. function FlexArrowShape()
  1557. {
  1558. mxArrowConnector.call(this);
  1559. this.spacing = 0;
  1560. };
  1561. mxUtils.extend(FlexArrowShape, mxArrowConnector);
  1562. FlexArrowShape.prototype.defaultWidth = 10;
  1563. FlexArrowShape.prototype.defaultArrowWidth = 20;
  1564. FlexArrowShape.prototype.getStartArrowWidth = function()
  1565. {
  1566. return this.getEdgeWidth() + mxUtils.getNumber(this.style, 'startWidth', this.defaultArrowWidth);
  1567. };
  1568. FlexArrowShape.prototype.getEndArrowWidth = function()
  1569. {
  1570. return this.getEdgeWidth() + mxUtils.getNumber(this.style, 'endWidth', this.defaultArrowWidth);;
  1571. };
  1572. FlexArrowShape.prototype.getEdgeWidth = function()
  1573. {
  1574. return mxUtils.getNumber(this.style, 'width', this.defaultWidth) + Math.max(0, this.strokewidth - 1);
  1575. };
  1576. // Registers the link shape
  1577. mxCellRenderer.prototype.defaultShapes['flexArrow'] = FlexArrowShape;
  1578. // Manual Input shape
  1579. function ManualInputShape()
  1580. {
  1581. mxActor.call(this);
  1582. };
  1583. mxUtils.extend(ManualInputShape, mxActor);
  1584. ManualInputShape.prototype.size = 30;
  1585. ManualInputShape.prototype.redrawPath = function(c, x, y, w, h)
  1586. {
  1587. var s = Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size)));
  1588. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  1589. this.addPoints(c, [new mxPoint(0, h), new mxPoint(0, s), new mxPoint(w, 0), new mxPoint(w, h)],
  1590. this.isRounded, arcSize, true);
  1591. c.end();
  1592. };
  1593. mxCellRenderer.prototype.defaultShapes['manualInput'] = ManualInputShape;
  1594. // Internal storage
  1595. function InternalStorageShape()
  1596. {
  1597. mxRectangleShape.call(this);
  1598. };
  1599. mxUtils.extend(InternalStorageShape, mxRectangleShape);
  1600. InternalStorageShape.prototype.dx = 20;
  1601. InternalStorageShape.prototype.dy = 20;
  1602. InternalStorageShape.prototype.isHtmlAllowed = function()
  1603. {
  1604. return false;
  1605. };
  1606. InternalStorageShape.prototype.paintForeground = function(c, x, y, w, h)
  1607. {
  1608. mxRectangleShape.prototype.paintForeground.apply(this, arguments);
  1609. var inset = 0;
  1610. if (this.isRounded)
  1611. {
  1612. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  1613. mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  1614. inset = Math.max(inset, Math.min(w * f, h * f));
  1615. }
  1616. var dx = Math.max(inset, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  1617. var dy = Math.max(inset, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))));
  1618. c.begin();
  1619. c.moveTo(x, y + dy);
  1620. c.lineTo(x + w, y + dy);
  1621. c.end();
  1622. c.stroke();
  1623. c.begin();
  1624. c.moveTo(x + dx, y);
  1625. c.lineTo(x + dx, y + h);
  1626. c.end();
  1627. c.stroke();
  1628. };
  1629. mxCellRenderer.prototype.defaultShapes['internalStorage'] = InternalStorageShape;
  1630. // Internal storage
  1631. function CornerShape()
  1632. {
  1633. mxActor.call(this);
  1634. };
  1635. mxUtils.extend(CornerShape, mxActor);
  1636. CornerShape.prototype.dx = 20;
  1637. CornerShape.prototype.dy = 20;
  1638. // Corner
  1639. CornerShape.prototype.redrawPath = function(c, x, y, w, h)
  1640. {
  1641. var dx = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  1642. var dy = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))));
  1643. var s = Math.min(w / 2, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  1644. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  1645. this.addPoints(c, [new mxPoint(0, 0), new mxPoint(w, 0), new mxPoint(w, dy), new mxPoint(dx, dy),
  1646. new mxPoint(dx, h), new mxPoint(0, h)], this.isRounded, arcSize, true);
  1647. c.end();
  1648. };
  1649. mxCellRenderer.prototype.defaultShapes['corner'] = CornerShape;
  1650. // Crossbar shape
  1651. function CrossbarShape()
  1652. {
  1653. mxActor.call(this);
  1654. };
  1655. mxUtils.extend(CrossbarShape, mxActor);
  1656. CrossbarShape.prototype.redrawPath = function(c, x, y, w, h)
  1657. {
  1658. c.moveTo(0, 0);
  1659. c.lineTo(0, h);
  1660. c.end();
  1661. c.moveTo(w, 0);
  1662. c.lineTo(w, h);
  1663. c.end();
  1664. c.moveTo(0, h / 2);
  1665. c.lineTo(w, h / 2);
  1666. c.end();
  1667. };
  1668. mxCellRenderer.prototype.defaultShapes['crossbar'] = CrossbarShape;
  1669. // Internal storage
  1670. function TeeShape()
  1671. {
  1672. mxActor.call(this);
  1673. };
  1674. mxUtils.extend(TeeShape, mxActor);
  1675. TeeShape.prototype.dx = 20;
  1676. TeeShape.prototype.dy = 20;
  1677. // Corner
  1678. TeeShape.prototype.redrawPath = function(c, x, y, w, h)
  1679. {
  1680. var dx = Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  1681. var dy = Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))));
  1682. var w2 = Math.abs(w - dx) / 2;
  1683. var s = Math.min(w / 2, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  1684. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  1685. this.addPoints(c, [new mxPoint(0, 0), new mxPoint(w, 0), new mxPoint(w, dy), new mxPoint((w + dx) / 2, dy),
  1686. new mxPoint((w + dx) / 2, h), new mxPoint((w - dx) / 2, h), new mxPoint((w - dx) / 2, dy),
  1687. new mxPoint(0, dy)], this.isRounded, arcSize, true);
  1688. c.end();
  1689. };
  1690. mxCellRenderer.prototype.defaultShapes['tee'] = TeeShape;
  1691. // Arrow
  1692. function SingleArrowShape()
  1693. {
  1694. mxActor.call(this);
  1695. };
  1696. mxUtils.extend(SingleArrowShape, mxActor);
  1697. SingleArrowShape.prototype.arrowWidth = 0.3;
  1698. SingleArrowShape.prototype.arrowSize = 0.2;
  1699. SingleArrowShape.prototype.redrawPath = function(c, x, y, w, h)
  1700. {
  1701. var aw = h * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'arrowWidth', this.arrowWidth))));
  1702. var as = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'arrowSize', this.arrowSize))));
  1703. var at = (h - aw) / 2;
  1704. var ab = at + aw;
  1705. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  1706. this.addPoints(c, [new mxPoint(0, at), new mxPoint(w - as, at), new mxPoint(w - as, 0), new mxPoint(w, h / 2),
  1707. new mxPoint(w - as, h), new mxPoint(w - as, ab), new mxPoint(0, ab)],
  1708. this.isRounded, arcSize, true);
  1709. c.end();
  1710. };
  1711. mxCellRenderer.prototype.defaultShapes['singleArrow'] = SingleArrowShape;
  1712. // Arrow
  1713. function DoubleArrowShape()
  1714. {
  1715. mxActor.call(this);
  1716. };
  1717. mxUtils.extend(DoubleArrowShape, mxActor);
  1718. DoubleArrowShape.prototype.redrawPath = function(c, x, y, w, h)
  1719. {
  1720. var aw = h * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'arrowWidth', SingleArrowShape.prototype.arrowWidth))));
  1721. var as = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'arrowSize', SingleArrowShape.prototype.arrowSize))));
  1722. var at = (h - aw) / 2;
  1723. var ab = at + aw;
  1724. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  1725. this.addPoints(c, [new mxPoint(0, h / 2), new mxPoint(as, 0), new mxPoint(as, at), new mxPoint(w - as, at),
  1726. new mxPoint(w - as, 0), new mxPoint(w, h / 2), new mxPoint(w - as, h),
  1727. new mxPoint(w - as, ab), new mxPoint(as, ab), new mxPoint(as, h)],
  1728. this.isRounded, arcSize, true);
  1729. c.end();
  1730. };
  1731. mxCellRenderer.prototype.defaultShapes['doubleArrow'] = DoubleArrowShape;
  1732. // Data storage
  1733. function DataStorageShape()
  1734. {
  1735. mxActor.call(this);
  1736. };
  1737. mxUtils.extend(DataStorageShape, mxActor);
  1738. DataStorageShape.prototype.size = 0.1;
  1739. DataStorageShape.prototype.redrawPath = function(c, x, y, w, h)
  1740. {
  1741. var s = w * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  1742. c.moveTo(s, 0);
  1743. c.lineTo(w, 0);
  1744. c.quadTo(w - s * 2, h / 2, w, h);
  1745. c.lineTo(s, h);
  1746. c.quadTo(s - s * 2, h / 2, s, 0);
  1747. c.close();
  1748. c.end();
  1749. };
  1750. mxCellRenderer.prototype.defaultShapes['dataStorage'] = DataStorageShape;
  1751. // Or
  1752. function OrShape()
  1753. {
  1754. mxActor.call(this);
  1755. };
  1756. mxUtils.extend(OrShape, mxActor);
  1757. OrShape.prototype.redrawPath = function(c, x, y, w, h)
  1758. {
  1759. c.moveTo(0, 0);
  1760. c.quadTo(w, 0, w, h / 2);
  1761. c.quadTo(w, h, 0, h);
  1762. c.close();
  1763. c.end();
  1764. };
  1765. mxCellRenderer.prototype.defaultShapes['or'] = OrShape;
  1766. // Xor
  1767. function XorShape()
  1768. {
  1769. mxActor.call(this);
  1770. };
  1771. mxUtils.extend(XorShape, mxActor);
  1772. XorShape.prototype.redrawPath = function(c, x, y, w, h)
  1773. {
  1774. c.moveTo(0, 0);
  1775. c.quadTo(w, 0, w, h / 2);
  1776. c.quadTo(w, h, 0, h);
  1777. c.quadTo(w / 2, h / 2, 0, 0);
  1778. c.close();
  1779. c.end();
  1780. };
  1781. mxCellRenderer.prototype.defaultShapes['xor'] = XorShape;
  1782. // Loop limit
  1783. function LoopLimitShape()
  1784. {
  1785. mxActor.call(this);
  1786. };
  1787. mxUtils.extend(LoopLimitShape, mxActor);
  1788. LoopLimitShape.prototype.size = 20;
  1789. LoopLimitShape.prototype.redrawPath = function(c, x, y, w, h)
  1790. {
  1791. var s = Math.min(w / 2, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  1792. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  1793. this.addPoints(c, [new mxPoint(s, 0), new mxPoint(w - s, 0), new mxPoint(w, s * 0.8), new mxPoint(w, h),
  1794. new mxPoint(0, h), new mxPoint(0, s * 0.8)], this.isRounded, arcSize, true);
  1795. c.end();
  1796. };
  1797. mxCellRenderer.prototype.defaultShapes['loopLimit'] = LoopLimitShape;
  1798. // Off page connector
  1799. function OffPageConnectorShape()
  1800. {
  1801. mxActor.call(this);
  1802. };
  1803. mxUtils.extend(OffPageConnectorShape, mxActor);
  1804. OffPageConnectorShape.prototype.size = 3 / 8;
  1805. OffPageConnectorShape.prototype.redrawPath = function(c, x, y, w, h)
  1806. {
  1807. var s = h * Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  1808. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  1809. this.addPoints(c, [new mxPoint(0, 0), new mxPoint(w, 0), new mxPoint(w, h - s), new mxPoint(w / 2, h),
  1810. new mxPoint(0, h - s)], this.isRounded, arcSize, true);
  1811. c.end();
  1812. };
  1813. mxCellRenderer.prototype.defaultShapes['offPageConnector'] = OffPageConnectorShape;
  1814. // Internal storage
  1815. function TapeDataShape()
  1816. {
  1817. mxEllipse.call(this);
  1818. };
  1819. mxUtils.extend(TapeDataShape, mxEllipse);
  1820. TapeDataShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1821. {
  1822. mxEllipse.prototype.paintVertexShape.apply(this, arguments);
  1823. c.begin();
  1824. c.moveTo(x + w / 2, y + h);
  1825. c.lineTo(x + w, y + h);
  1826. c.end();
  1827. c.stroke();
  1828. };
  1829. mxCellRenderer.prototype.defaultShapes['tapeData'] = TapeDataShape;
  1830. // OrEllipseShape
  1831. function OrEllipseShape()
  1832. {
  1833. mxEllipse.call(this);
  1834. };
  1835. mxUtils.extend(OrEllipseShape, mxEllipse);
  1836. OrEllipseShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1837. {
  1838. mxEllipse.prototype.paintVertexShape.apply(this, arguments);
  1839. c.setShadow(false);
  1840. c.begin();
  1841. c.moveTo(x, y + h / 2);
  1842. c.lineTo(x + w, y + h / 2);
  1843. c.end();
  1844. c.stroke();
  1845. c.begin();
  1846. c.moveTo(x + w / 2, y);
  1847. c.lineTo(x + w / 2, y + h);
  1848. c.end();
  1849. c.stroke();
  1850. };
  1851. mxCellRenderer.prototype.defaultShapes['orEllipse'] = OrEllipseShape;
  1852. // SumEllipseShape
  1853. function SumEllipseShape()
  1854. {
  1855. mxEllipse.call(this);
  1856. };
  1857. mxUtils.extend(SumEllipseShape, mxEllipse);
  1858. SumEllipseShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1859. {
  1860. mxEllipse.prototype.paintVertexShape.apply(this, arguments);
  1861. var s2 = 0.145;
  1862. c.setShadow(false);
  1863. c.begin();
  1864. c.moveTo(x + w * s2, y + h * s2);
  1865. c.lineTo(x + w * (1 - s2), y + h * (1 - s2));
  1866. c.end();
  1867. c.stroke();
  1868. c.begin();
  1869. c.moveTo(x + w * (1 - s2), y + h * s2);
  1870. c.lineTo(x + w * s2, y + h * (1 - s2));
  1871. c.end();
  1872. c.stroke();
  1873. };
  1874. mxCellRenderer.prototype.defaultShapes['sumEllipse'] = SumEllipseShape;
  1875. // SortShape
  1876. function SortShape()
  1877. {
  1878. mxRhombus.call(this);
  1879. };
  1880. mxUtils.extend(SortShape, mxRhombus);
  1881. SortShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1882. {
  1883. mxRhombus.prototype.paintVertexShape.apply(this, arguments);
  1884. c.setShadow(false);
  1885. c.begin();
  1886. c.moveTo(x, y + h / 2);
  1887. c.lineTo(x + w, y + h / 2);
  1888. c.end();
  1889. c.stroke();
  1890. };
  1891. mxCellRenderer.prototype.defaultShapes['sortShape'] = SortShape;
  1892. // CollateShape
  1893. function CollateShape()
  1894. {
  1895. mxEllipse.call(this);
  1896. };
  1897. mxUtils.extend(CollateShape, mxEllipse);
  1898. CollateShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1899. {
  1900. c.begin();
  1901. c.moveTo(x, y);
  1902. c.lineTo(x + w, y);
  1903. c.lineTo(x + w / 2, y + h / 2);
  1904. c.close();
  1905. c.fillAndStroke();
  1906. c.begin();
  1907. c.moveTo(x, y + h);
  1908. c.lineTo(x + w, y + h);
  1909. c.lineTo(x + w / 2, y + h / 2);
  1910. c.close();
  1911. c.fillAndStroke();
  1912. };
  1913. mxCellRenderer.prototype.defaultShapes['collate'] = CollateShape;
  1914. // DimensionShape
  1915. function DimensionShape()
  1916. {
  1917. mxEllipse.call(this);
  1918. };
  1919. mxUtils.extend(DimensionShape, mxEllipse);
  1920. DimensionShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1921. {
  1922. // Arrow size
  1923. var al = 10;
  1924. var cy = y + h - al / 2;
  1925. c.begin();
  1926. c.moveTo(x, y);
  1927. c.lineTo(x, y + h);
  1928. c.moveTo(x, cy);
  1929. c.lineTo(x + al, cy - al / 2);
  1930. c.moveTo(x, cy);
  1931. c.lineTo(x + al, cy + al / 2);
  1932. c.moveTo(x, cy);
  1933. c.lineTo(x + w, cy);
  1934. // Opposite side
  1935. c.moveTo(x + w, y);
  1936. c.lineTo(x + w, y + h);
  1937. c.moveTo(x + w, cy);
  1938. c.lineTo(x + w - al, cy - al / 2);
  1939. c.moveTo(x + w, cy);
  1940. c.lineTo(x + w - al, cy + al / 2);
  1941. c.end();
  1942. c.stroke();
  1943. };
  1944. mxCellRenderer.prototype.defaultShapes['dimension'] = DimensionShape;
  1945. // PartialRectangleShape
  1946. function PartialRectangleShape()
  1947. {
  1948. mxEllipse.call(this);
  1949. };
  1950. mxUtils.extend(PartialRectangleShape, mxEllipse);
  1951. PartialRectangleShape.prototype.paintVertexShape = function(c, x, y, w, h)
  1952. {
  1953. if (!this.outline)
  1954. {
  1955. c.setStrokeColor(null);
  1956. }
  1957. mxRectangleShape.prototype.paintBackground.apply(this, arguments);
  1958. if (this.style != null)
  1959. {
  1960. c.setStrokeColor(this.stroke);
  1961. c.rect(x, y, w, h);
  1962. c.fill();
  1963. if (mxUtils.getValue(this.style, 'top', '1') == '1')
  1964. {
  1965. c.begin();
  1966. c.moveTo(x, y);
  1967. c.lineTo(x + w, y);
  1968. c.end();
  1969. c.stroke();
  1970. }
  1971. if (mxUtils.getValue(this.style, 'right', '1') == '1')
  1972. {
  1973. c.begin();
  1974. c.moveTo(x + w, y);
  1975. c.lineTo(x + w, y + h);
  1976. c.end();
  1977. c.stroke();
  1978. }
  1979. if (mxUtils.getValue(this.style, 'bottom', '1') == '1')
  1980. {
  1981. c.begin();
  1982. c.moveTo(x + w, y + h);
  1983. c.lineTo(x, y + h);
  1984. c.end();
  1985. c.stroke();
  1986. }
  1987. if (mxUtils.getValue(this.style, 'left', '1') == '1')
  1988. {
  1989. c.begin();
  1990. c.moveTo(x, y + h);
  1991. c.lineTo(x, y);
  1992. c.end();
  1993. c.stroke();
  1994. }
  1995. }
  1996. };
  1997. mxCellRenderer.prototype.defaultShapes['partialRectangle'] = PartialRectangleShape;
  1998. // LineEllipseShape
  1999. function LineEllipseShape()
  2000. {
  2001. mxEllipse.call(this);
  2002. };
  2003. mxUtils.extend(LineEllipseShape, mxEllipse);
  2004. LineEllipseShape.prototype.paintVertexShape = function(c, x, y, w, h)
  2005. {
  2006. mxEllipse.prototype.paintVertexShape.apply(this, arguments);
  2007. c.setShadow(false);
  2008. c.begin();
  2009. if (mxUtils.getValue(this.style, 'line') == 'vertical')
  2010. {
  2011. c.moveTo(x + w / 2, y);
  2012. c.lineTo(x + w / 2, y + h);
  2013. }
  2014. else
  2015. {
  2016. c.moveTo(x, y + h / 2);
  2017. c.lineTo(x + w, y + h / 2);
  2018. }
  2019. c.end();
  2020. c.stroke();
  2021. };
  2022. mxCellRenderer.prototype.defaultShapes['lineEllipse'] = LineEllipseShape;
  2023. // Delay
  2024. function DelayShape()
  2025. {
  2026. mxActor.call(this);
  2027. };
  2028. mxUtils.extend(DelayShape, mxActor);
  2029. DelayShape.prototype.redrawPath = function(c, x, y, w, h)
  2030. {
  2031. var dx = Math.min(w, h / 2);
  2032. c.moveTo(0, 0);
  2033. c.lineTo(w - dx, 0);
  2034. c.quadTo(w, 0, w, h / 2);
  2035. c.quadTo(w, h, w - dx, h);
  2036. c.lineTo(0, h);
  2037. c.close();
  2038. c.end();
  2039. };
  2040. mxCellRenderer.prototype.defaultShapes['delay'] = DelayShape;
  2041. // Cross Shape
  2042. function CrossShape()
  2043. {
  2044. mxActor.call(this);
  2045. };
  2046. mxUtils.extend(CrossShape, mxActor);
  2047. CrossShape.prototype.size = 0.2;
  2048. CrossShape.prototype.redrawPath = function(c, x, y, w, h)
  2049. {
  2050. var m = Math.min(h, w);
  2051. var size = Math.max(0, Math.min(m, m * parseFloat(mxUtils.getValue(this.style, 'size', this.size))));
  2052. var t = (h - size) / 2;
  2053. var b = t + size;
  2054. var l = (w - size) / 2;
  2055. var r = l + size;
  2056. c.moveTo(0, t);
  2057. c.lineTo(l, t);
  2058. c.lineTo(l, 0);
  2059. c.lineTo(r, 0);
  2060. c.lineTo(r, t);
  2061. c.lineTo(w, t);
  2062. c.lineTo(w, b);
  2063. c.lineTo(r, b);
  2064. c.lineTo(r, h);
  2065. c.lineTo(l, h);
  2066. c.lineTo(l, b);
  2067. c.lineTo(0, b);
  2068. c.close();
  2069. c.end();
  2070. };
  2071. mxCellRenderer.prototype.defaultShapes['cross'] = CrossShape;
  2072. // Display
  2073. function DisplayShape()
  2074. {
  2075. mxActor.call(this);
  2076. };
  2077. mxUtils.extend(DisplayShape, mxActor);
  2078. DisplayShape.prototype.size = 0.25;
  2079. DisplayShape.prototype.redrawPath = function(c, x, y, w, h)
  2080. {
  2081. var dx = Math.min(w, h / 2);
  2082. var s = Math.min(w - dx, Math.max(0, parseFloat(mxUtils.getValue(this.style, 'size', this.size))) * w);
  2083. c.moveTo(0, h / 2);
  2084. c.lineTo(s, 0);
  2085. c.lineTo(w - dx, 0);
  2086. c.quadTo(w, 0, w, h / 2);
  2087. c.quadTo(w, h, w - dx, h);
  2088. c.lineTo(s, h);
  2089. c.close();
  2090. c.end();
  2091. };
  2092. mxCellRenderer.prototype.defaultShapes['display'] = DisplayShape;
  2093. // FilledEdge shape
  2094. function FilledEdge()
  2095. {
  2096. mxConnector.call(this);
  2097. };
  2098. mxUtils.extend(FilledEdge, mxConnector);
  2099. FilledEdge.prototype.origPaintEdgeShape = FilledEdge.prototype.paintEdgeShape;
  2100. FilledEdge.prototype.paintEdgeShape = function(c, pts, rounded)
  2101. {
  2102. //paintEdgeShape reset dashed to false
  2103. var dashed = c.state.dashed;
  2104. var fixDash = c.state.fixDash;
  2105. FilledEdge.prototype.origPaintEdgeShape.apply(this, arguments);
  2106. if (c.state.strokeWidth >= 3)
  2107. {
  2108. var fillClr = mxUtils.getValue(this.style, 'fillColor', null);
  2109. if (fillClr != null)
  2110. {
  2111. c.setStrokeColor(fillClr);
  2112. c.setStrokeWidth(c.state.strokeWidth - 2);
  2113. c.setDashed(dashed, fixDash);
  2114. FilledEdge.prototype.origPaintEdgeShape.apply(this, arguments);
  2115. }
  2116. }
  2117. };
  2118. // Registers the link shape
  2119. mxCellRenderer.prototype.defaultShapes['filledEdge'] = FilledEdge;
  2120. // Registers and defines the custom marker
  2121. mxMarker.addMarker('dash', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  2122. {
  2123. var nx = unitX * (size + sw + 1);
  2124. var ny = unitY * (size + sw + 1);
  2125. return function()
  2126. {
  2127. c.begin();
  2128. c.moveTo(pe.x - nx / 2 - ny / 2, pe.y - ny / 2 + nx / 2);
  2129. c.lineTo(pe.x + ny / 2 - 3 * nx / 2, pe.y - 3 * ny / 2 - nx / 2);
  2130. c.stroke();
  2131. };
  2132. });
  2133. // Registers and defines the custom marker
  2134. mxMarker.addMarker('cross', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  2135. {
  2136. var nx = unitX * (size + sw + 1);
  2137. var ny = unitY * (size + sw + 1);
  2138. return function()
  2139. {
  2140. c.begin();
  2141. c.moveTo(pe.x - nx / 2 - ny / 2, pe.y - ny / 2 + nx / 2);
  2142. c.lineTo(pe.x + ny / 2 - 3 * nx / 2, pe.y - 3 * ny / 2 - nx / 2);
  2143. c.moveTo(pe.x - nx / 2 + ny / 2, pe.y - ny / 2 - nx / 2);
  2144. c.lineTo(pe.x - ny / 2 - 3 * nx / 2, pe.y - 3 * ny / 2 + nx / 2);
  2145. c.stroke();
  2146. };
  2147. });
  2148. function circleMarker(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  2149. {
  2150. var a = size / 2;
  2151. var size = size + sw;
  2152. var pt = pe.clone();
  2153. pe.x -= unitX * (2 * size + sw);
  2154. pe.y -= unitY * (2 * size + sw);
  2155. unitX = unitX * (size + sw);
  2156. unitY = unitY * (size + sw);
  2157. return function()
  2158. {
  2159. c.ellipse(pt.x - unitX - size, pt.y - unitY - size, 2 * size, 2 * size);
  2160. if (filled)
  2161. {
  2162. c.fillAndStroke();
  2163. }
  2164. else
  2165. {
  2166. c.stroke();
  2167. }
  2168. };
  2169. };
  2170. mxMarker.addMarker('circle', circleMarker);
  2171. mxMarker.addMarker('circlePlus', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  2172. {
  2173. var pt = pe.clone();
  2174. var fn = circleMarker.apply(this, arguments);
  2175. var nx = unitX * (size + 2 * sw); // (size + sw + 1);
  2176. var ny = unitY * (size + 2 * sw); //(size + sw + 1);
  2177. return function()
  2178. {
  2179. fn.apply(this, arguments);
  2180. c.begin();
  2181. c.moveTo(pt.x - unitX * (sw), pt.y - unitY * (sw));
  2182. c.lineTo(pt.x - 2 * nx + unitX * (sw), pt.y - 2 * ny + unitY * (sw));
  2183. c.moveTo(pt.x - nx - ny + unitY * sw, pt.y - ny + nx - unitX * sw);
  2184. c.lineTo(pt.x + ny - nx - unitY * sw, pt.y - ny - nx + unitX * sw);
  2185. c.stroke();
  2186. };
  2187. });
  2188. mxMarker.addMarker('async', function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  2189. {
  2190. // The angle of the forward facing arrow sides against the x axis is
  2191. // 26.565 degrees, 1/sin(26.565) = 2.236 / 2 = 1.118 ( / 2 allows for
  2192. // only half the strokewidth is processed ).
  2193. var endOffsetX = unitX * sw * 1.118;
  2194. var endOffsetY = unitY * sw * 1.118;
  2195. unitX = unitX * (size + sw);
  2196. unitY = unitY * (size + sw);
  2197. var pt = pe.clone();
  2198. pt.x -= endOffsetX;
  2199. pt.y -= endOffsetY;
  2200. var f = 1;
  2201. pe.x += -unitX * f - endOffsetX;
  2202. pe.y += -unitY * f - endOffsetY;
  2203. return function()
  2204. {
  2205. c.begin();
  2206. c.moveTo(pt.x, pt.y);
  2207. if (source)
  2208. {
  2209. c.lineTo(pt.x - unitX - unitY / 2, pt.y - unitY + unitX / 2);
  2210. }
  2211. else
  2212. {
  2213. c.lineTo(pt.x + unitY / 2 - unitX, pt.y - unitY - unitX / 2);
  2214. }
  2215. c.lineTo(pt.x - unitX, pt.y - unitY);
  2216. c.close();
  2217. if (filled)
  2218. {
  2219. c.fillAndStroke();
  2220. }
  2221. else
  2222. {
  2223. c.stroke();
  2224. }
  2225. };
  2226. });
  2227. function createOpenAsyncArrow(widthFactor)
  2228. {
  2229. widthFactor = (widthFactor != null) ? widthFactor : 2;
  2230. return function(c, shape, type, pe, unitX, unitY, size, source, sw, filled)
  2231. {
  2232. unitX = unitX * (size + sw);
  2233. unitY = unitY * (size + sw);
  2234. var pt = pe.clone();
  2235. return function()
  2236. {
  2237. c.begin();
  2238. c.moveTo(pt.x, pt.y);
  2239. if (source)
  2240. {
  2241. c.lineTo(pt.x - unitX - unitY / widthFactor, pt.y - unitY + unitX / widthFactor);
  2242. }
  2243. else
  2244. {
  2245. c.lineTo(pt.x + unitY / widthFactor - unitX, pt.y - unitY - unitX / widthFactor);
  2246. }
  2247. c.stroke();
  2248. };
  2249. }
  2250. };
  2251. mxMarker.addMarker('openAsync', createOpenAsyncArrow(2));
  2252. function arrow(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  2253. {
  2254. // The angle of the forward facing arrow sides against the x axis is
  2255. // 26.565 degrees, 1/sin(26.565) = 2.236 / 2 = 1.118 ( / 2 allows for
  2256. // only half the strokewidth is processed ).
  2257. var endOffsetX = unitX * sw * 1.118;
  2258. var endOffsetY = unitY * sw * 1.118;
  2259. unitX = unitX * (size + sw);
  2260. unitY = unitY * (size + sw);
  2261. var pt = pe.clone();
  2262. pt.x -= endOffsetX;
  2263. pt.y -= endOffsetY;
  2264. var f = (type != mxConstants.ARROW_CLASSIC && type != mxConstants.ARROW_CLASSIC_THIN) ? 1 : 3 / 4;
  2265. pe.x += -unitX * f - endOffsetX;
  2266. pe.y += -unitY * f - endOffsetY;
  2267. return function()
  2268. {
  2269. canvas.begin();
  2270. canvas.moveTo(pt.x, pt.y);
  2271. canvas.lineTo(pt.x - unitX - unitY / widthFactor, pt.y - unitY + unitX / widthFactor);
  2272. if (type == mxConstants.ARROW_CLASSIC || type == mxConstants.ARROW_CLASSIC_THIN)
  2273. {
  2274. canvas.lineTo(pt.x - unitX * 3 / 4, pt.y - unitY * 3 / 4);
  2275. }
  2276. canvas.lineTo(pt.x + unitY / widthFactor - unitX, pt.y - unitY - unitX / widthFactor);
  2277. canvas.close();
  2278. if (filled)
  2279. {
  2280. canvas.fillAndStroke();
  2281. }
  2282. else
  2283. {
  2284. canvas.stroke();
  2285. }
  2286. };
  2287. }
  2288. // Handlers are only added if mxVertexHandler is defined (ie. not in embedded graph)
  2289. if (typeof mxVertexHandler !== 'undefined')
  2290. {
  2291. function createHandle(state, keys, getPositionFn, setPositionFn, ignoreGrid, redrawEdges)
  2292. {
  2293. var handle = new mxHandle(state, null, mxVertexHandler.prototype.secondaryHandleImage);
  2294. handle.execute = function()
  2295. {
  2296. for (var i = 0; i < keys.length; i++)
  2297. {
  2298. this.copyStyle(keys[i]);
  2299. }
  2300. };
  2301. handle.getPosition = getPositionFn;
  2302. handle.setPosition = setPositionFn;
  2303. handle.ignoreGrid = (ignoreGrid != null) ? ignoreGrid : true;
  2304. // Overridden to update connected edges
  2305. if (redrawEdges)
  2306. {
  2307. var positionChanged = handle.positionChanged;
  2308. handle.positionChanged = function()
  2309. {
  2310. positionChanged.apply(this, arguments);
  2311. // Redraws connected edges TODO: Include child edges
  2312. state.view.invalidate(this.state.cell);
  2313. state.view.validate();
  2314. };
  2315. }
  2316. return handle;
  2317. };
  2318. function createArcHandle(state, yOffset)
  2319. {
  2320. return createHandle(state, [mxConstants.STYLE_ARCSIZE], function(bounds)
  2321. {
  2322. var arcSize = Math.max(0, parseFloat(mxUtils.getValue(state.style,
  2323. mxConstants.STYLE_ARCSIZE, mxConstants.RECTANGLE_ROUNDING_FACTOR * 100))) / 100;
  2324. var tmp = (yOffset != null) ? yOffset : bounds.height / 8;
  2325. return new mxPoint(bounds.x + bounds.width - Math.min(Math.max(bounds.width / 2, bounds.height / 2),
  2326. Math.min(bounds.width, bounds.height) * arcSize), bounds.y + tmp);
  2327. }, function(bounds, pt, me)
  2328. {
  2329. var f = Math.min(50, Math.max(0, (bounds.width - pt.x + bounds.x) * 100 /
  2330. Math.min(bounds.width, bounds.height)));
  2331. this.state.style[mxConstants.STYLE_ARCSIZE] = Math.round(f);
  2332. });
  2333. }
  2334. function createArcHandleFunction()
  2335. {
  2336. return function(state)
  2337. {
  2338. var handles = [];
  2339. if (mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2340. {
  2341. handles.push(createArcHandle(state));
  2342. }
  2343. return handles;
  2344. };
  2345. };
  2346. function createTrapezoidHandleFunction(max)
  2347. {
  2348. return function(state)
  2349. {
  2350. var handles = [createHandle(state, ['size'], function(bounds)
  2351. {
  2352. var size = Math.max(0, Math.min(max, parseFloat(mxUtils.getValue(this.state.style, 'size', TrapezoidShape.prototype.size))));
  2353. return new mxPoint(bounds.x + size * bounds.width * 0.75, bounds.y + bounds.height / 4);
  2354. }, function(bounds, pt)
  2355. {
  2356. this.state.style['size'] = Math.max(0, Math.min(max, (pt.x - bounds.x) / (bounds.width * 0.75)));
  2357. }, null, true)];
  2358. if (mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2359. {
  2360. handles.push(createArcHandle(state));
  2361. }
  2362. return handles;
  2363. };
  2364. };
  2365. function createDisplayHandleFunction(defaultValue, allowArcHandle, max, redrawEdges)
  2366. {
  2367. max = (max != null) ? max : 1;
  2368. return function(state)
  2369. {
  2370. var handles = [createHandle(state, ['size'], function(bounds)
  2371. {
  2372. var size = parseFloat(mxUtils.getValue(this.state.style, 'size', defaultValue));
  2373. return new mxPoint(bounds.x + size * bounds.width, bounds.getCenterY());
  2374. }, function(bounds, pt)
  2375. {
  2376. this.state.style['size'] = Math.max(0, Math.min(max, (pt.x - bounds.x) / bounds.width));
  2377. }, null, redrawEdges)];
  2378. if (allowArcHandle && mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2379. {
  2380. handles.push(createArcHandle(state));
  2381. }
  2382. return handles;
  2383. };
  2384. };
  2385. function createCubeHandleFunction(factor, defaultValue, allowArcHandle)
  2386. {
  2387. return function(state)
  2388. {
  2389. var handles = [createHandle(state, ['size'], function(bounds)
  2390. {
  2391. var size = Math.max(0, Math.min(bounds.width, Math.min(bounds.height, parseFloat(
  2392. mxUtils.getValue(this.state.style, 'size', defaultValue))))) * factor;
  2393. return new mxPoint(bounds.x + size, bounds.y + size);
  2394. }, function(bounds, pt)
  2395. {
  2396. this.state.style['size'] = Math.round(Math.max(0, Math.min(Math.min(bounds.width, pt.x - bounds.x),
  2397. Math.min(bounds.height, pt.y - bounds.y))) / factor);
  2398. })];
  2399. if (allowArcHandle && mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2400. {
  2401. handles.push(createArcHandle(state));
  2402. }
  2403. return handles;
  2404. };
  2405. };
  2406. function createArrowHandleFunction(maxSize)
  2407. {
  2408. return function(state)
  2409. {
  2410. return [createHandle(state, ['arrowWidth', 'arrowSize'], function(bounds)
  2411. {
  2412. var aw = Math.max(0, Math.min(1, mxUtils.getValue(this.state.style, 'arrowWidth', SingleArrowShape.prototype.arrowWidth)));
  2413. var as = Math.max(0, Math.min(maxSize, mxUtils.getValue(this.state.style, 'arrowSize', SingleArrowShape.prototype.arrowSize)));
  2414. return new mxPoint(bounds.x + (1 - as) * bounds.width, bounds.y + (1 - aw) * bounds.height / 2);
  2415. }, function(bounds, pt)
  2416. {
  2417. this.state.style['arrowWidth'] = Math.max(0, Math.min(1, Math.abs(bounds.y + bounds.height / 2 - pt.y) / bounds.height * 2));
  2418. this.state.style['arrowSize'] = Math.max(0, Math.min(maxSize, (bounds.x + bounds.width - pt.x) / (bounds.width)));
  2419. })];
  2420. };
  2421. };
  2422. function createEdgeHandle(state, keys, start, getPosition, setPosition)
  2423. {
  2424. var pts = state.absolutePoints;
  2425. var n = pts.length - 1;
  2426. var tr = state.view.translate;
  2427. var s = state.view.scale;
  2428. var p0 = (start) ? pts[0] : pts[n];
  2429. var p1 = (start) ? pts[1] : pts[n - 1];
  2430. var dx = (start) ? p1.x - p0.x : p1.x - p0.x;
  2431. var dy = (start) ? p1.y - p0.y : p1.y - p0.y;
  2432. var dist = Math.sqrt(dx * dx + dy * dy);
  2433. return createHandle(state, keys, function(bounds)
  2434. {
  2435. var pt = getPosition.call(this, dist, dx / dist, dy / dist, p0, p1);
  2436. return new mxPoint(pt.x / s - tr.x, pt.y / s - tr.y);
  2437. }, function(bounds, pt, me)
  2438. {
  2439. var dist = Math.sqrt(dx * dx + dy * dy);
  2440. pt.x = (pt.x + tr.x) * s;
  2441. pt.y = (pt.y + tr.y) * s;
  2442. setPosition.call(this, dist, dx / dist, dy / dist, p0, p1, pt, me);
  2443. });
  2444. };
  2445. function createEdgeWidthHandle(state, start, spacing)
  2446. {
  2447. return createEdgeHandle(state, ['width'], start, function(dist, nx, ny, p0, p1)
  2448. {
  2449. var w = state.shape.getEdgeWidth() * state.view.scale + spacing;
  2450. return new mxPoint(p0.x + nx * dist / 4 + ny * w / 2, p0.y + ny * dist / 4 - nx * w / 2);
  2451. }, function(dist, nx, ny, p0, p1, pt)
  2452. {
  2453. var w = Math.sqrt(mxUtils.ptSegDistSq(p0.x, p0.y, p1.x, p1.y, pt.x, pt.y));
  2454. state.style['width'] = Math.round(w * 2) / state.view.scale - spacing;
  2455. });
  2456. };
  2457. function ptLineDistance(x1, y1, x2, y2, x0, y0)
  2458. {
  2459. return Math.abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) / Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
  2460. }
  2461. var handleFactory = {
  2462. 'link': function(state)
  2463. {
  2464. var spacing = 10;
  2465. return [createEdgeWidthHandle(state, true, spacing), createEdgeWidthHandle(state, false, spacing)];
  2466. },
  2467. 'flexArrow': function(state)
  2468. {
  2469. // Do not use state.shape.startSize/endSize since it is cached
  2470. var tol = state.view.graph.gridSize / state.view.scale;
  2471. var handles = [];
  2472. if (mxUtils.getValue(state.style, mxConstants.STYLE_STARTARROW, mxConstants.NONE) != mxConstants.NONE)
  2473. {
  2474. handles.push(createEdgeHandle(state, ['width', mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE], true, function(dist, nx, ny, p0, p1)
  2475. {
  2476. var w = (state.shape.getEdgeWidth() - state.shape.strokewidth) * state.view.scale;
  2477. var l = mxUtils.getNumber(state.style, mxConstants.STYLE_STARTSIZE, mxConstants.ARROW_SIZE / 5) * 3 * state.view.scale;
  2478. return new mxPoint(p0.x + nx * (l + state.shape.strokewidth * state.view.scale) + ny * w / 2,
  2479. p0.y + ny * (l + state.shape.strokewidth * state.view.scale) - nx * w / 2);
  2480. }, function(dist, nx, ny, p0, p1, pt, me)
  2481. {
  2482. var w = Math.sqrt(mxUtils.ptSegDistSq(p0.x, p0.y, p1.x, p1.y, pt.x, pt.y));
  2483. var l = mxUtils.ptLineDist(p0.x, p0.y, p0.x + ny, p0.y - nx, pt.x, pt.y);
  2484. state.style[mxConstants.STYLE_STARTSIZE] = Math.round((l - state.shape.strokewidth) * 100 / 3) / 100 / state.view.scale;
  2485. state.style['width'] = Math.round(w * 2) / state.view.scale;
  2486. // Applies to opposite side
  2487. if (mxEvent.isControlDown(me.getEvent()))
  2488. {
  2489. state.style[mxConstants.STYLE_ENDSIZE] = state.style[mxConstants.STYLE_STARTSIZE];
  2490. }
  2491. // Snaps to end geometry
  2492. if (!mxEvent.isAltDown(me.getEvent()))
  2493. {
  2494. if (Math.abs(parseFloat(state.style[mxConstants.STYLE_STARTSIZE]) - parseFloat(state.style[mxConstants.STYLE_ENDSIZE])) < tol / 6)
  2495. {
  2496. state.style[mxConstants.STYLE_STARTSIZE] = state.style[mxConstants.STYLE_ENDSIZE];
  2497. }
  2498. }
  2499. }));
  2500. handles.push(createEdgeHandle(state, ['startWidth', 'endWidth', mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE], true, function(dist, nx, ny, p0, p1)
  2501. {
  2502. var w = (state.shape.getStartArrowWidth() - state.shape.strokewidth) * state.view.scale;
  2503. var l = mxUtils.getNumber(state.style, mxConstants.STYLE_STARTSIZE, mxConstants.ARROW_SIZE / 5) * 3 * state.view.scale;
  2504. return new mxPoint(p0.x + nx * (l + state.shape.strokewidth * state.view.scale) + ny * w / 2,
  2505. p0.y + ny * (l + state.shape.strokewidth * state.view.scale) - nx * w / 2);
  2506. }, function(dist, nx, ny, p0, p1, pt, me)
  2507. {
  2508. var w = Math.sqrt(mxUtils.ptSegDistSq(p0.x, p0.y, p1.x, p1.y, pt.x, pt.y));
  2509. var l = mxUtils.ptLineDist(p0.x, p0.y, p0.x + ny, p0.y - nx, pt.x, pt.y);
  2510. state.style[mxConstants.STYLE_STARTSIZE] = Math.round((l - state.shape.strokewidth) * 100 / 3) / 100 / state.view.scale;
  2511. state.style['startWidth'] = Math.max(0, Math.round(w * 2) - state.shape.getEdgeWidth()) / state.view.scale;
  2512. // Applies to opposite side
  2513. if (mxEvent.isControlDown(me.getEvent()))
  2514. {
  2515. state.style[mxConstants.STYLE_ENDSIZE] = state.style[mxConstants.STYLE_STARTSIZE];
  2516. state.style['endWidth'] = state.style['startWidth'];
  2517. }
  2518. // Snaps to endWidth
  2519. if (!mxEvent.isAltDown(me.getEvent()))
  2520. {
  2521. if (Math.abs(parseFloat(state.style[mxConstants.STYLE_STARTSIZE]) - parseFloat(state.style[mxConstants.STYLE_ENDSIZE])) < tol / 6)
  2522. {
  2523. state.style[mxConstants.STYLE_STARTSIZE] = state.style[mxConstants.STYLE_ENDSIZE];
  2524. }
  2525. if (Math.abs(parseFloat(state.style['startWidth']) - parseFloat(state.style['endWidth'])) < tol)
  2526. {
  2527. state.style['startWidth'] = state.style['endWidth'];
  2528. }
  2529. }
  2530. }));
  2531. }
  2532. if (mxUtils.getValue(state.style, mxConstants.STYLE_ENDARROW, mxConstants.NONE) != mxConstants.NONE)
  2533. {
  2534. handles.push(createEdgeHandle(state, ['width', mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE], false, function(dist, nx, ny, p0, p1)
  2535. {
  2536. var w = (state.shape.getEdgeWidth() - state.shape.strokewidth) * state.view.scale;
  2537. var l = mxUtils.getNumber(state.style, mxConstants.STYLE_ENDSIZE, mxConstants.ARROW_SIZE / 5) * 3 * state.view.scale;
  2538. return new mxPoint(p0.x + nx * (l + state.shape.strokewidth * state.view.scale) - ny * w / 2,
  2539. p0.y + ny * (l + state.shape.strokewidth * state.view.scale) + nx * w / 2);
  2540. }, function(dist, nx, ny, p0, p1, pt, me)
  2541. {
  2542. var w = Math.sqrt(mxUtils.ptSegDistSq(p0.x, p0.y, p1.x, p1.y, pt.x, pt.y));
  2543. var l = mxUtils.ptLineDist(p0.x, p0.y, p0.x + ny, p0.y - nx, pt.x, pt.y);
  2544. state.style[mxConstants.STYLE_ENDSIZE] = Math.round((l - state.shape.strokewidth) * 100 / 3) / 100 / state.view.scale;
  2545. state.style['width'] = Math.round(w * 2) / state.view.scale;
  2546. // Applies to opposite side
  2547. if (mxEvent.isControlDown(me.getEvent()))
  2548. {
  2549. state.style[mxConstants.STYLE_STARTSIZE] = state.style[mxConstants.STYLE_ENDSIZE];
  2550. }
  2551. // Snaps to start geometry
  2552. if (!mxEvent.isAltDown(me.getEvent()))
  2553. {
  2554. if (Math.abs(parseFloat(state.style[mxConstants.STYLE_ENDSIZE]) - parseFloat(state.style[mxConstants.STYLE_STARTSIZE])) < tol / 6)
  2555. {
  2556. state.style[mxConstants.STYLE_ENDSIZE] = state.style[mxConstants.STYLE_STARTSIZE];
  2557. }
  2558. }
  2559. }));
  2560. handles.push(createEdgeHandle(state, ['startWidth', 'endWidth', mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE], false, function(dist, nx, ny, p0, p1)
  2561. {
  2562. var w = (state.shape.getEndArrowWidth() - state.shape.strokewidth) * state.view.scale;
  2563. var l = mxUtils.getNumber(state.style, mxConstants.STYLE_ENDSIZE, mxConstants.ARROW_SIZE / 5) * 3 * state.view.scale;
  2564. return new mxPoint(p0.x + nx * (l + state.shape.strokewidth * state.view.scale) - ny * w / 2,
  2565. p0.y + ny * (l + state.shape.strokewidth * state.view.scale) + nx * w / 2);
  2566. }, function(dist, nx, ny, p0, p1, pt, me)
  2567. {
  2568. var w = Math.sqrt(mxUtils.ptSegDistSq(p0.x, p0.y, p1.x, p1.y, pt.x, pt.y));
  2569. var l = mxUtils.ptLineDist(p0.x, p0.y, p0.x + ny, p0.y - nx, pt.x, pt.y);
  2570. state.style[mxConstants.STYLE_ENDSIZE] = Math.round((l - state.shape.strokewidth) * 100 / 3) / 100 / state.view.scale;
  2571. state.style['endWidth'] = Math.max(0, Math.round(w * 2) - state.shape.getEdgeWidth()) / state.view.scale;
  2572. // Applies to opposite side
  2573. if (mxEvent.isControlDown(me.getEvent()))
  2574. {
  2575. state.style[mxConstants.STYLE_STARTSIZE] = state.style[mxConstants.STYLE_ENDSIZE];
  2576. state.style['startWidth'] = state.style['endWidth'];
  2577. }
  2578. // Snaps to start geometry
  2579. if (!mxEvent.isAltDown(me.getEvent()))
  2580. {
  2581. if (Math.abs(parseFloat(state.style[mxConstants.STYLE_ENDSIZE]) - parseFloat(state.style[mxConstants.STYLE_STARTSIZE])) < tol / 6)
  2582. {
  2583. state.style[mxConstants.STYLE_ENDSIZE] = state.style[mxConstants.STYLE_STARTSIZE];
  2584. }
  2585. if (Math.abs(parseFloat(state.style['endWidth']) - parseFloat(state.style['startWidth'])) < tol)
  2586. {
  2587. state.style['endWidth'] = state.style['startWidth'];
  2588. }
  2589. }
  2590. }));
  2591. }
  2592. return handles;
  2593. },
  2594. 'swimlane': function(state)
  2595. {
  2596. var handles = [createHandle(state, [mxConstants.STYLE_STARTSIZE], function(bounds)
  2597. {
  2598. var size = parseFloat(mxUtils.getValue(state.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE));
  2599. if (mxUtils.getValue(state.style, mxConstants.STYLE_HORIZONTAL, 1) == 1)
  2600. {
  2601. return new mxPoint(bounds.getCenterX(), bounds.y + Math.max(0, Math.min(bounds.height, size)));
  2602. }
  2603. else
  2604. {
  2605. return new mxPoint(bounds.x + Math.max(0, Math.min(bounds.width, size)), bounds.getCenterY());
  2606. }
  2607. }, function(bounds, pt)
  2608. {
  2609. state.style[mxConstants.STYLE_STARTSIZE] =
  2610. (mxUtils.getValue(this.state.style, mxConstants.STYLE_HORIZONTAL, 1) == 1) ?
  2611. Math.round(Math.max(0, Math.min(bounds.height, pt.y - bounds.y))) :
  2612. Math.round(Math.max(0, Math.min(bounds.width, pt.x - bounds.x)));
  2613. })];
  2614. if (mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED))
  2615. {
  2616. var size = parseFloat(mxUtils.getValue(state.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE));
  2617. handles.push(createArcHandle(state, size / 2));
  2618. }
  2619. return handles;
  2620. },
  2621. 'label': createArcHandleFunction(),
  2622. 'ext': createArcHandleFunction(),
  2623. 'rectangle': createArcHandleFunction(),
  2624. 'triangle': createArcHandleFunction(),
  2625. 'rhombus': createArcHandleFunction(),
  2626. 'umlLifeline': function(state)
  2627. {
  2628. return [createHandle(state, ['size'], function(bounds)
  2629. {
  2630. var size = Math.max(0, Math.min(bounds.height, parseFloat(mxUtils.getValue(this.state.style, 'size', UmlLifeline.prototype.size))));
  2631. return new mxPoint(bounds.getCenterX(), bounds.y + size);
  2632. }, function(bounds, pt)
  2633. {
  2634. this.state.style['size'] = Math.round(Math.max(0, Math.min(bounds.height, pt.y - bounds.y)));
  2635. }, false)];
  2636. },
  2637. 'umlFrame': function(state)
  2638. {
  2639. var handles = [createHandle(state, ['width', 'height'], function(bounds)
  2640. {
  2641. var w0 = Math.max(UmlFrame.prototype.corner, Math.min(bounds.width, mxUtils.getValue(this.state.style, 'width', UmlFrame.prototype.width)));
  2642. var h0 = Math.max(UmlFrame.prototype.corner * 1.5, Math.min(bounds.height, mxUtils.getValue(this.state.style, 'height', UmlFrame.prototype.height)));
  2643. return new mxPoint(bounds.x + w0, bounds.y + h0);
  2644. }, function(bounds, pt)
  2645. {
  2646. this.state.style['width'] = Math.round(Math.max(UmlFrame.prototype.corner, Math.min(bounds.width, pt.x - bounds.x)));
  2647. this.state.style['height'] = Math.round(Math.max(UmlFrame.prototype.corner * 1.5, Math.min(bounds.height, pt.y - bounds.y)));
  2648. }, false)];
  2649. if (mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2650. {
  2651. handles.push(createArcHandle(state));
  2652. }
  2653. return handles;
  2654. },
  2655. 'process': function(state)
  2656. {
  2657. var handles = [createHandle(state, ['size'], function(bounds)
  2658. {
  2659. var size = Math.max(0, Math.min(0.5, parseFloat(mxUtils.getValue(this.state.style, 'size', ProcessShape.prototype.size))));
  2660. return new mxPoint(bounds.x + bounds.width * size, bounds.y + bounds.height / 4);
  2661. }, function(bounds, pt)
  2662. {
  2663. this.state.style['size'] = Math.max(0, Math.min(0.5, (pt.x - bounds.x) / bounds.width));
  2664. })];
  2665. if (mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2666. {
  2667. handles.push(createArcHandle(state));
  2668. }
  2669. return handles;
  2670. },
  2671. 'cross': function(state)
  2672. {
  2673. return [createHandle(state, ['size'], function(bounds)
  2674. {
  2675. var m = Math.min(bounds.width, bounds.height);
  2676. var size = Math.max(0, Math.min(1, mxUtils.getValue(this.state.style, 'size', CrossShape.prototype.size))) * m / 2;
  2677. return new mxPoint(bounds.getCenterX() - size, bounds.getCenterY() - size);
  2678. }, function(bounds, pt)
  2679. {
  2680. var m = Math.min(bounds.width, bounds.height);
  2681. this.state.style['size'] = Math.max(0, Math.min(1, Math.min((Math.max(0, bounds.getCenterY() - pt.y) / m) * 2,
  2682. (Math.max(0, bounds.getCenterX() - pt.x) / m) * 2)));
  2683. })];
  2684. },
  2685. 'note': function(state)
  2686. {
  2687. return [createHandle(state, ['size'], function(bounds)
  2688. {
  2689. var size = Math.max(0, Math.min(bounds.width, Math.min(bounds.height, parseFloat(
  2690. mxUtils.getValue(this.state.style, 'size', NoteShape.prototype.size)))));
  2691. return new mxPoint(bounds.x + bounds.width - size, bounds.y + size);
  2692. }, function(bounds, pt)
  2693. {
  2694. this.state.style['size'] = Math.round(Math.max(0, Math.min(Math.min(bounds.width, bounds.x + bounds.width - pt.x),
  2695. Math.min(bounds.height, pt.y - bounds.y))));
  2696. })];
  2697. },
  2698. 'manualInput': function(state)
  2699. {
  2700. var handles = [createHandle(state, ['size'], function(bounds)
  2701. {
  2702. var size = Math.max(0, Math.min(bounds.height, mxUtils.getValue(this.state.style, 'size', ManualInputShape.prototype.size)));
  2703. return new mxPoint(bounds.x + bounds.width / 4, bounds.y + size * 3 / 4);
  2704. }, function(bounds, pt)
  2705. {
  2706. this.state.style['size'] = Math.round(Math.max(0, Math.min(bounds.height, (pt.y - bounds.y) * 4 / 3)));
  2707. })];
  2708. if (mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2709. {
  2710. handles.push(createArcHandle(state));
  2711. }
  2712. return handles;
  2713. },
  2714. 'dataStorage': function(state)
  2715. {
  2716. return [createHandle(state, ['size'], function(bounds)
  2717. {
  2718. var size = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'size', DataStorageShape.prototype.size))));
  2719. return new mxPoint(bounds.x + (1 - size) * bounds.width, bounds.getCenterY());
  2720. }, function(bounds, pt)
  2721. {
  2722. this.state.style['size'] = Math.max(0, Math.min(1, (bounds.x + bounds.width - pt.x) / bounds.width));
  2723. })];
  2724. },
  2725. 'internalStorage': function(state)
  2726. {
  2727. var handles = [createHandle(state, ['dx', 'dy'], function(bounds)
  2728. {
  2729. var dx = Math.max(0, Math.min(bounds.width, mxUtils.getValue(this.state.style, 'dx', InternalStorageShape.prototype.dx)));
  2730. var dy = Math.max(0, Math.min(bounds.height, mxUtils.getValue(this.state.style, 'dy', InternalStorageShape.prototype.dy)));
  2731. return new mxPoint(bounds.x + dx, bounds.y + dy);
  2732. }, function(bounds, pt)
  2733. {
  2734. this.state.style['dx'] = Math.round(Math.max(0, Math.min(bounds.width, pt.x - bounds.x)));
  2735. this.state.style['dy'] = Math.round(Math.max(0, Math.min(bounds.height, pt.y - bounds.y)));
  2736. })];
  2737. if (mxUtils.getValue(state.style, mxConstants.STYLE_ROUNDED, false))
  2738. {
  2739. handles.push(createArcHandle(state));
  2740. }
  2741. return handles;
  2742. },
  2743. 'corner': function(state)
  2744. {
  2745. return [createHandle(state, ['dx', 'dy'], function(bounds)
  2746. {
  2747. var dx = Math.max(0, Math.min(bounds.width, mxUtils.getValue(this.state.style, 'dx', CornerShape.prototype.dx)));
  2748. var dy = Math.max(0, Math.min(bounds.height, mxUtils.getValue(this.state.style, 'dy', CornerShape.prototype.dy)));
  2749. return new mxPoint(bounds.x + dx, bounds.y + dy);
  2750. }, function(bounds, pt)
  2751. {
  2752. this.state.style['dx'] = Math.round(Math.max(0, Math.min(bounds.width, pt.x - bounds.x)));
  2753. this.state.style['dy'] = Math.round(Math.max(0, Math.min(bounds.height, pt.y - bounds.y)));
  2754. })];
  2755. },
  2756. 'tee': function(state)
  2757. {
  2758. return [createHandle(state, ['dx', 'dy'], function(bounds)
  2759. {
  2760. var dx = Math.max(0, Math.min(bounds.width, mxUtils.getValue(this.state.style, 'dx', TeeShape.prototype.dx)));
  2761. var dy = Math.max(0, Math.min(bounds.height, mxUtils.getValue(this.state.style, 'dy', TeeShape.prototype.dy)));
  2762. return new mxPoint(bounds.x + (bounds.width + dx) / 2, bounds.y + dy);
  2763. }, function(bounds, pt)
  2764. {
  2765. this.state.style['dx'] = Math.round(Math.max(0, Math.min(bounds.width / 2, (pt.x - bounds.x - bounds.width / 2)) * 2));
  2766. this.state.style['dy'] = Math.round(Math.max(0, Math.min(bounds.height, pt.y - bounds.y)));
  2767. })];
  2768. },
  2769. 'singleArrow': createArrowHandleFunction(1),
  2770. 'doubleArrow': createArrowHandleFunction(0.5),
  2771. 'folder': function(state)
  2772. {
  2773. return [createHandle(state, ['tabWidth', 'tabHeight'], function(bounds)
  2774. {
  2775. var tw = Math.max(0, Math.min(bounds.width, mxUtils.getValue(this.state.style, 'tabWidth', FolderShape.prototype.tabWidth)));
  2776. var th = Math.max(0, Math.min(bounds.height, mxUtils.getValue(this.state.style, 'tabHeight', FolderShape.prototype.tabHeight)));
  2777. if (mxUtils.getValue(this.state.style, 'tabPosition', FolderShape.prototype.tabPosition) == mxConstants.ALIGN_RIGHT)
  2778. {
  2779. tw = bounds.width - tw;
  2780. }
  2781. return new mxPoint(bounds.x + tw, bounds.y + th);
  2782. }, function(bounds, pt)
  2783. {
  2784. var tw = Math.max(0, Math.min(bounds.width, pt.x - bounds.x));
  2785. if (mxUtils.getValue(this.state.style, 'tabPosition', FolderShape.prototype.tabPosition) == mxConstants.ALIGN_RIGHT)
  2786. {
  2787. tw = bounds.width - tw;
  2788. }
  2789. this.state.style['tabWidth'] = Math.round(tw);
  2790. this.state.style['tabHeight'] = Math.round(Math.max(0, Math.min(bounds.height, pt.y - bounds.y)));
  2791. })];
  2792. },
  2793. 'document': function(state)
  2794. {
  2795. return [createHandle(state, ['size'], function(bounds)
  2796. {
  2797. var size = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'size', DocumentShape.prototype.size))));
  2798. return new mxPoint(bounds.x + 3 * bounds.width / 4, bounds.y + (1 - size) * bounds.height);
  2799. }, function(bounds, pt)
  2800. {
  2801. this.state.style['size'] = Math.max(0, Math.min(1, (bounds.y + bounds.height - pt.y) / bounds.height));
  2802. })];
  2803. },
  2804. 'tape': function(state)
  2805. {
  2806. return [createHandle(state, ['size'], function(bounds)
  2807. {
  2808. var size = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'size', TapeShape.prototype.size))));
  2809. return new mxPoint(bounds.getCenterX(), bounds.y + size * bounds.height / 2);
  2810. }, function(bounds, pt)
  2811. {
  2812. this.state.style['size'] = Math.max(0, Math.min(1, ((pt.y - bounds.y) / bounds.height) * 2));
  2813. })];
  2814. },
  2815. 'offPageConnector': function(state)
  2816. {
  2817. return [createHandle(state, ['size'], function(bounds)
  2818. {
  2819. var size = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'size', OffPageConnectorShape.prototype.size))));
  2820. return new mxPoint(bounds.getCenterX(), bounds.y + (1 - size) * bounds.height);
  2821. }, function(bounds, pt)
  2822. {
  2823. this.state.style['size'] = Math.max(0, Math.min(1, (bounds.y + bounds.height - pt.y) / bounds.height));
  2824. })];
  2825. },
  2826. 'step': createDisplayHandleFunction(StepShape.prototype.size, true, null, true),
  2827. 'hexagon': createDisplayHandleFunction(HexagonShape.prototype.size, true, 0.5, true),
  2828. 'curlyBracket': createDisplayHandleFunction(CurlyBracketShape.prototype.size, false),
  2829. 'display': createDisplayHandleFunction(DisplayShape.prototype.size, false),
  2830. 'cube': createCubeHandleFunction(1, CubeShape.prototype.size, false),
  2831. 'card': createCubeHandleFunction(0.5, CardShape.prototype.size, true),
  2832. 'loopLimit': createCubeHandleFunction(0.5, LoopLimitShape.prototype.size, true),
  2833. 'trapezoid': createTrapezoidHandleFunction(0.5),
  2834. 'parallelogram': createTrapezoidHandleFunction(1)
  2835. };
  2836. // Exposes custom handles
  2837. Graph.createHandle = createHandle;
  2838. Graph.handleFactory = handleFactory;
  2839. mxVertexHandler.prototype.createCustomHandles = function()
  2840. {
  2841. // Not rotatable means locked
  2842. if (this.state.view.graph.getSelectionCount() == 1)
  2843. {
  2844. if (this.graph.isCellRotatable(this.state.cell))
  2845. // LATER: Make locked state independent of rotatable flag, fix toggle if default is false
  2846. //if (this.graph.isCellResizable(this.state.cell) || this.graph.isCellMovable(this.state.cell))
  2847. {
  2848. var name = this.state.style['shape'];
  2849. if (this.state.view.graph.cellRenderer.defaultShapes[name] == null &&
  2850. mxStencilRegistry.getStencil(name) == null)
  2851. {
  2852. name = mxConstants.SHAPE_RECTANGLE;
  2853. }
  2854. var fn = handleFactory[name];
  2855. if (fn != null)
  2856. {
  2857. return fn(this.state);
  2858. }
  2859. }
  2860. }
  2861. return null;
  2862. };
  2863. mxEdgeHandler.prototype.createCustomHandles = function()
  2864. {
  2865. if (this.state.view.graph.getSelectionCount() == 1)
  2866. {
  2867. var name = this.state.style['shape'];
  2868. if (this.state.view.graph.cellRenderer.defaultShapes[name] == null &&
  2869. mxStencilRegistry.getStencil(name) == null)
  2870. {
  2871. name = mxConstants.SHAPE_CONNECTOR;
  2872. }
  2873. var fn = handleFactory[name];
  2874. if (fn != null)
  2875. {
  2876. return fn(this.state);
  2877. }
  2878. }
  2879. return null;
  2880. }
  2881. }
  2882. else
  2883. {
  2884. // Dummy entries to avoid NPE in embed mode
  2885. Graph.createHandle = function() {};
  2886. Graph.handleFactory = {};
  2887. }
  2888. var isoHVector = new mxPoint(1, 0);
  2889. var isoVVector = new mxPoint(1, 0);
  2890. var alpha1 = mxUtils.toRadians(-30);
  2891. var cos1 = Math.cos(alpha1);
  2892. var sin1 = Math.sin(alpha1);
  2893. isoHVector = mxUtils.getRotatedPoint(isoHVector, cos1, sin1);
  2894. var alpha2 = mxUtils.toRadians(-150);
  2895. var cos2 = Math.cos(alpha2);
  2896. var sin2 = Math.sin(alpha2);
  2897. isoVVector = mxUtils.getRotatedPoint(isoVVector, cos2, sin2);
  2898. mxEdgeStyle.IsometricConnector = function (state, source, target, points, result)
  2899. {
  2900. var view = state.view;
  2901. var pt = (points != null && points.length > 0) ? points[0] : null;
  2902. var pts = state.absolutePoints;
  2903. var p0 = pts[0];
  2904. var pe = pts[pts.length-1];
  2905. if (pt != null)
  2906. {
  2907. pt = view.transformControlPoint(state, pt);
  2908. }
  2909. if (p0 == null)
  2910. {
  2911. if (source != null)
  2912. {
  2913. p0 = new mxPoint(source.getCenterX(), source.getCenterY());
  2914. }
  2915. }
  2916. if (pe == null)
  2917. {
  2918. if (target != null)
  2919. {
  2920. pe = new mxPoint(target.getCenterX(), target.getCenterY());
  2921. }
  2922. }
  2923. var a1 = isoHVector.x;
  2924. var a2 = isoHVector.y;
  2925. var b1 = isoVVector.x;
  2926. var b2 = isoVVector.y;
  2927. var elbow = mxUtils.getValue(state.style, 'elbow', 'horizontal') == 'horizontal';
  2928. if (pe != null && p0 != null)
  2929. {
  2930. var last = p0;
  2931. function isoLineTo(x, y, ignoreFirst)
  2932. {
  2933. var c1 = x - last.x;
  2934. var c2 = y - last.y;
  2935. // Solves for isometric base vectors
  2936. var h = (b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1);
  2937. var v = (a2 * c1 - a1 * c2) / (a2 * b1 - a1 * b2);
  2938. if (elbow)
  2939. {
  2940. if (ignoreFirst)
  2941. {
  2942. last = new mxPoint(last.x + a1 * h, last.y + a2 * h);
  2943. result.push(last);
  2944. }
  2945. last = new mxPoint(last.x + b1 * v, last.y + b2 * v);
  2946. result.push(last);
  2947. }
  2948. else
  2949. {
  2950. if (ignoreFirst)
  2951. {
  2952. last = new mxPoint(last.x + b1 * v, last.y + b2 * v);
  2953. result.push(last);
  2954. }
  2955. last = new mxPoint(last.x + a1 * h, last.y + a2 * h);
  2956. result.push(last);
  2957. }
  2958. };
  2959. if (pt == null)
  2960. {
  2961. pt = new mxPoint(p0.x + (pe.x - p0.x) / 2, p0.y + (pe.y - p0.y) / 2);
  2962. }
  2963. isoLineTo(pt.x, pt.y, true);
  2964. isoLineTo(pe.x, pe.y, false);
  2965. }
  2966. };
  2967. mxStyleRegistry.putValue('isometricEdgeStyle', mxEdgeStyle.IsometricConnector);
  2968. var graphCreateEdgeHandler = Graph.prototype.createEdgeHandler;
  2969. Graph.prototype.createEdgeHandler = function(state, edgeStyle)
  2970. {
  2971. if (edgeStyle == mxEdgeStyle.IsometricConnector)
  2972. {
  2973. var handler = new mxElbowEdgeHandler(state);
  2974. handler.snapToTerminals = false;
  2975. return handler;
  2976. }
  2977. return graphCreateEdgeHandler.apply(this, arguments);
  2978. };
  2979. // Defines connection points for all shapes
  2980. IsoRectangleShape.prototype.constraints = [];
  2981. IsoCubeShape.prototype.constraints = [];
  2982. mxRectangleShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  2983. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  2984. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  2985. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  2986. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  2987. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  2988. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  2989. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  2990. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  2991. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  2992. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  2993. new mxConnectionConstraint(new mxPoint(0.75, 1), true)];
  2994. mxEllipse.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0), true), new mxConnectionConstraint(new mxPoint(1, 0), true),
  2995. new mxConnectionConstraint(new mxPoint(0, 1), true), new mxConnectionConstraint(new mxPoint(1, 1), true),
  2996. new mxConnectionConstraint(new mxPoint(0.5, 0), true), new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  2997. new mxConnectionConstraint(new mxPoint(0, 0.5), true), new mxConnectionConstraint(new mxPoint(1, 0.5))];
  2998. mxLabel.prototype.constraints = mxRectangleShape.prototype.constraints;
  2999. mxImageShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3000. mxSwimlane.prototype.constraints = mxRectangleShape.prototype.constraints;
  3001. PlusShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3002. NoteShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3003. CardShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3004. CubeShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3005. FolderShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3006. InternalStorageShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3007. DataStorageShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3008. TapeDataShape.prototype.constraints = mxEllipse.prototype.constraints;
  3009. OrEllipseShape.prototype.constraints = mxEllipse.prototype.constraints;
  3010. SumEllipseShape.prototype.constraints = mxEllipse.prototype.constraints;
  3011. LineEllipseShape.prototype.constraints = mxEllipse.prototype.constraints;
  3012. ManualInputShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3013. DelayShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3014. DisplayShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3015. LoopLimitShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3016. OffPageConnectorShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3017. mxCylinder.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.15, 0.05), false),
  3018. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  3019. new mxConnectionConstraint(new mxPoint(0.85, 0.05), false),
  3020. new mxConnectionConstraint(new mxPoint(0, 0.3), true),
  3021. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  3022. new mxConnectionConstraint(new mxPoint(0, 0.7), true),
  3023. new mxConnectionConstraint(new mxPoint(1, 0.3), true),
  3024. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  3025. new mxConnectionConstraint(new mxPoint(1, 0.7), true),
  3026. new mxConnectionConstraint(new mxPoint(0.15, 0.95), false),
  3027. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  3028. new mxConnectionConstraint(new mxPoint(0.85, 0.95), false)];
  3029. UmlActorShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.25, 0.1), false),
  3030. new mxConnectionConstraint(new mxPoint(0.5, 0), false),
  3031. new mxConnectionConstraint(new mxPoint(0.75, 0.1), false),
  3032. new mxConnectionConstraint(new mxPoint(0, 1/3), false),
  3033. new mxConnectionConstraint(new mxPoint(0, 1), false),
  3034. new mxConnectionConstraint(new mxPoint(1, 1/3), false),
  3035. new mxConnectionConstraint(new mxPoint(1, 1), false),
  3036. new mxConnectionConstraint(new mxPoint(0.5, 0.5), false)];
  3037. ComponentShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  3038. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  3039. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  3040. new mxConnectionConstraint(new mxPoint(0, 0.3), true),
  3041. new mxConnectionConstraint(new mxPoint(0, 0.7), true),
  3042. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  3043. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  3044. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  3045. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  3046. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  3047. new mxConnectionConstraint(new mxPoint(0.75, 1), true)];
  3048. mxActor.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  3049. new mxConnectionConstraint(new mxPoint(0.25, 0.2), false),
  3050. new mxConnectionConstraint(new mxPoint(0.1, 0.5), false),
  3051. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  3052. new mxConnectionConstraint(new mxPoint(0.75, 0.25), false),
  3053. new mxConnectionConstraint(new mxPoint(0.9, 0.5), false),
  3054. new mxConnectionConstraint(new mxPoint(1, 0.75), true),
  3055. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  3056. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  3057. new mxConnectionConstraint(new mxPoint(0.75, 1), true)];
  3058. SwitchShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0), false),
  3059. new mxConnectionConstraint(new mxPoint(0.5, 0.25), false),
  3060. new mxConnectionConstraint(new mxPoint(1, 0), false),
  3061. new mxConnectionConstraint(new mxPoint(0.25, 0.5), false),
  3062. new mxConnectionConstraint(new mxPoint(0.75, 0.5), false),
  3063. new mxConnectionConstraint(new mxPoint(0, 1), false),
  3064. new mxConnectionConstraint(new mxPoint(0.5, 0.75), false),
  3065. new mxConnectionConstraint(new mxPoint(1, 1), false)];
  3066. TapeShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0.35), false),
  3067. new mxConnectionConstraint(new mxPoint(0, 0.5), false),
  3068. new mxConnectionConstraint(new mxPoint(0, 0.65), false),
  3069. new mxConnectionConstraint(new mxPoint(1, 0.35), false),
  3070. new mxConnectionConstraint(new mxPoint(1, 0.5), false),
  3071. new mxConnectionConstraint(new mxPoint(1, 0.65), false),
  3072. new mxConnectionConstraint(new mxPoint(0.25, 1), false),
  3073. new mxConnectionConstraint(new mxPoint(0.75, 0), false)];
  3074. StepShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  3075. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  3076. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  3077. new mxConnectionConstraint(new mxPoint(0.25, 1), true),
  3078. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  3079. new mxConnectionConstraint(new mxPoint(0.75, 1), true),
  3080. new mxConnectionConstraint(new mxPoint(0.1, 0.25), true),
  3081. new mxConnectionConstraint(new mxPoint(0.2, 0.5), true),
  3082. new mxConnectionConstraint(new mxPoint(0.1, 0.75), true),
  3083. new mxConnectionConstraint(new mxPoint(0.9, 0.25), true),
  3084. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  3085. new mxConnectionConstraint(new mxPoint(0.9, 0.75), true)];
  3086. mxLine.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0.5), false),
  3087. new mxConnectionConstraint(new mxPoint(0.25, 0.5), false),
  3088. new mxConnectionConstraint(new mxPoint(0.75, 0.5), false),
  3089. new mxConnectionConstraint(new mxPoint(1, 0.5), false)];
  3090. LollipopShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.5, 0), false),
  3091. new mxConnectionConstraint(new mxPoint(0.5, 1), false)];
  3092. mxDoubleEllipse.prototype.constraints = mxEllipse.prototype.constraints;
  3093. mxRhombus.prototype.constraints = mxEllipse.prototype.constraints;
  3094. mxTriangle.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  3095. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  3096. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  3097. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  3098. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  3099. new mxConnectionConstraint(new mxPoint(1, 0.5), true)];
  3100. mxHexagon.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.375, 0), true),
  3101. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  3102. new mxConnectionConstraint(new mxPoint(0.625, 0), true),
  3103. new mxConnectionConstraint(new mxPoint(0.125, 0.25), true),
  3104. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  3105. new mxConnectionConstraint(new mxPoint(0.125, 0.75), true),
  3106. new mxConnectionConstraint(new mxPoint(0.875, 0.25), true),
  3107. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  3108. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  3109. new mxConnectionConstraint(new mxPoint(0.875, 0.75), true),
  3110. new mxConnectionConstraint(new mxPoint(0.375, 1), true),
  3111. new mxConnectionConstraint(new mxPoint(0.5, 1), true),
  3112. new mxConnectionConstraint(new mxPoint(0.625, 1), true)];
  3113. mxCloud.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.25, 0.25), false),
  3114. new mxConnectionConstraint(new mxPoint(0.4, 0.1), false),
  3115. new mxConnectionConstraint(new mxPoint(0.16, 0.55), false),
  3116. new mxConnectionConstraint(new mxPoint(0.07, 0.4), false),
  3117. new mxConnectionConstraint(new mxPoint(0.31, 0.8), false),
  3118. new mxConnectionConstraint(new mxPoint(0.13, 0.77), false),
  3119. new mxConnectionConstraint(new mxPoint(0.8, 0.8), false),
  3120. new mxConnectionConstraint(new mxPoint(0.55, 0.95), false),
  3121. new mxConnectionConstraint(new mxPoint(0.875, 0.5), false),
  3122. new mxConnectionConstraint(new mxPoint(0.96, 0.7), false),
  3123. new mxConnectionConstraint(new mxPoint(0.625, 0.2), false),
  3124. new mxConnectionConstraint(new mxPoint(0.88, 0.25), false)];
  3125. ParallelogramShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3126. TrapezoidShape.prototype.constraints = mxRectangleShape.prototype.constraints;
  3127. DocumentShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.25, 0), true),
  3128. new mxConnectionConstraint(new mxPoint(0.5, 0), true),
  3129. new mxConnectionConstraint(new mxPoint(0.75, 0), true),
  3130. new mxConnectionConstraint(new mxPoint(0, 0.25), true),
  3131. new mxConnectionConstraint(new mxPoint(0, 0.5), true),
  3132. new mxConnectionConstraint(new mxPoint(0, 0.75), true),
  3133. new mxConnectionConstraint(new mxPoint(1, 0.25), true),
  3134. new mxConnectionConstraint(new mxPoint(1, 0.5), true),
  3135. new mxConnectionConstraint(new mxPoint(1, 0.75), true)];
  3136. mxArrow.prototype.constraints = null;
  3137. TeeShape.prototype.constraints = null;
  3138. CornerShape.prototype.constraints = null;
  3139. CrossbarShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0), false),
  3140. new mxConnectionConstraint(new mxPoint(0, 0.5), false),
  3141. new mxConnectionConstraint(new mxPoint(0, 1), false),
  3142. new mxConnectionConstraint(new mxPoint(0.25, 0.5), false),
  3143. new mxConnectionConstraint(new mxPoint(0.5, 0.5), false),
  3144. new mxConnectionConstraint(new mxPoint(0.75, 0.5), false),
  3145. new mxConnectionConstraint(new mxPoint(1, 0), false),
  3146. new mxConnectionConstraint(new mxPoint(1, 0.5), false),
  3147. new mxConnectionConstraint(new mxPoint(1, 1), false)];
  3148. SingleArrowShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0.5), false),
  3149. new mxConnectionConstraint(new mxPoint(1, 0.5), false)];
  3150. DoubleArrowShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0.5), false),
  3151. new mxConnectionConstraint(new mxPoint(1, 0.5), false)];
  3152. CrossShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0.5), false),
  3153. new mxConnectionConstraint(new mxPoint(1, 0.5), false),
  3154. new mxConnectionConstraint(new mxPoint(0.5, 0), false),
  3155. new mxConnectionConstraint(new mxPoint(0.5, 1), false)];
  3156. UmlLifeline.prototype.constraints = null;
  3157. OrShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0, 0.25), false),
  3158. new mxConnectionConstraint(new mxPoint(0, 0.5), false),
  3159. new mxConnectionConstraint(new mxPoint(0, 0.75), false),
  3160. new mxConnectionConstraint(new mxPoint(1, 0.5), false),
  3161. new mxConnectionConstraint(new mxPoint(0.7, 0.1), false),
  3162. new mxConnectionConstraint(new mxPoint(0.7, 0.9), false)];
  3163. XorShape.prototype.constraints = [new mxConnectionConstraint(new mxPoint(0.175, 0.25), false),
  3164. new mxConnectionConstraint(new mxPoint(0.25, 0.5), false),
  3165. new mxConnectionConstraint(new mxPoint(0.175, 0.75), false),
  3166. new mxConnectionConstraint(new mxPoint(1, 0.5), false),
  3167. new mxConnectionConstraint(new mxPoint(0.7, 0.1), false),
  3168. new mxConnectionConstraint(new mxPoint(0.7, 0.9), false)];
  3169. })();