Shapes.js 115 KB

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