Shapes.js 115 KB

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