Graph.js 222 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. // Workaround for allowing target="_blank" in HTML sanitizer
  5. // see https://code.google.com/p/google-caja/issues/detail?can=2&q=&colspec=ID%20Type%20Status%20Priority%20Owner%20Summary&groupby=&sort=&id=1296
  6. if (typeof html4 !== 'undefined')
  7. {
  8. html4.ATTRIBS["a::target"] = 0;
  9. html4.ATTRIBS["source::src"] = 0;
  10. html4.ATTRIBS["video::src"] = 0;
  11. // Would be nice for tooltips but probably a security risk...
  12. //html4.ATTRIBS["video::autoplay"] = 0;
  13. //html4.ATTRIBS["video::autobuffer"] = 0;
  14. }
  15. /**
  16. * Sets global constants.
  17. */
  18. // Changes default colors
  19. mxConstants.SHADOW_OPACITY = 0.25;
  20. mxConstants.SHADOWCOLOR = '#000000';
  21. mxConstants.VML_SHADOWCOLOR = '#d0d0d0';
  22. mxGraph.prototype.pageBreakColor = '#c0c0c0';
  23. mxGraph.prototype.pageScale = 1;
  24. // Letter page format is default in US, Canada and Mexico
  25. (function()
  26. {
  27. try
  28. {
  29. if (navigator != null && navigator.language != null)
  30. {
  31. var lang = navigator.language.toLowerCase();
  32. mxGraph.prototype.pageFormat = (lang === 'en-us' || lang === 'en-ca' || lang === 'es-mx') ?
  33. mxConstants.PAGE_FORMAT_LETTER_PORTRAIT : mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  34. }
  35. }
  36. catch (e)
  37. {
  38. // ignore
  39. }
  40. })();
  41. // Matches label positions of mxGraph 1.x
  42. mxText.prototype.baseSpacingTop = 5;
  43. mxText.prototype.baseSpacingBottom = 1;
  44. // Keeps edges between relative child cells inside parent
  45. mxGraphModel.prototype.ignoreRelativeEdgeParent = false;
  46. // Defines grid properties
  47. mxGraphView.prototype.gridImage = (mxClient.IS_SVG) ? 'data:image/gif;base64,R0lGODlhCgAKAJEAAAAAAP///8zMzP///yH5BAEAAAMALAAAAAAKAAoAAAIJ1I6py+0Po2wFADs=' :
  48. IMAGE_PATH + '/grid.gif';
  49. mxGraphView.prototype.gridSteps = 4;
  50. mxGraphView.prototype.minGridSize = 4;
  51. // UrlParams is null in embed mode
  52. mxGraphView.prototype.gridColor = '#e0e0e0';
  53. // Alternative text for unsupported foreignObjects
  54. mxSvgCanvas2D.prototype.foAltText = '[Not supported by viewer]';
  55. /**
  56. * Constructs a new graph instance. Note that the constructor does not take a
  57. * container because the graph instance is needed for creating the UI, which
  58. * in turn will create the container for the graph. Hence, the container is
  59. * assigned later in EditorUi.
  60. */
  61. /**
  62. * Defines graph class.
  63. */
  64. Graph = function(container, model, renderHint, stylesheet, themes)
  65. {
  66. mxGraph.call(this, container, model, renderHint, stylesheet);
  67. this.themes = themes || this.defaultThemes;
  68. this.currentEdgeStyle = mxUtils.clone(this.defaultEdgeStyle);
  69. this.currentVertexStyle = mxUtils.clone(this.defaultVertexStyle);
  70. // Sets the base domain URL and domain path URL for relative links.
  71. var b = this.baseUrl;
  72. var p = b.indexOf('//');
  73. this.domainUrl = '';
  74. this.domainPathUrl = '';
  75. if (p > 0)
  76. {
  77. var d = b.indexOf('/', p + 2);
  78. if (d > 0)
  79. {
  80. this.domainUrl = b.substring(0, d);
  81. }
  82. d = b.lastIndexOf('/');
  83. if (d > 0)
  84. {
  85. this.domainPathUrl = b.substring(0, d + 1);
  86. }
  87. }
  88. // Adds support for HTML labels via style. Note: Currently, only the Java
  89. // backend supports HTML labels but CSS support is limited to the following:
  90. // http://docs.oracle.com/javase/6/docs/api/index.html?javax/swing/text/html/CSS.html
  91. // TODO: Wrap should not affect isHtmlLabel output (should be handled later)
  92. this.isHtmlLabel = function(cell)
  93. {
  94. var state = this.view.getState(cell);
  95. var style = (state != null) ? state.style : this.getCellStyle(cell);
  96. return style['html'] == '1' || style[mxConstants.STYLE_WHITE_SPACE] == 'wrap';
  97. };
  98. // Implements a listener for hover and click handling on edges
  99. if (this.edgeMode)
  100. {
  101. var start = {
  102. point: null,
  103. event: null,
  104. state: null,
  105. handle: null,
  106. selected: false
  107. };
  108. // Uses this event to process mouseDown to check the selection state before it is changed
  109. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  110. {
  111. if (evt.getProperty('eventName') == 'mouseDown' && this.isEnabled())
  112. {
  113. var me = evt.getProperty('event');
  114. if (!mxEvent.isControlDown(me.getEvent()) && !mxEvent.isShiftDown(me.getEvent()))
  115. {
  116. var state = me.getState();
  117. if (state != null)
  118. {
  119. // Checks if state was removed in call to stopEditing above
  120. if (this.model.isEdge(state.cell))
  121. {
  122. start.point = new mxPoint(me.getGraphX(), me.getGraphY());
  123. start.selected = this.isCellSelected(state.cell);
  124. start.state = state;
  125. start.event = me;
  126. if (state.text != null && state.text.boundingBox != null &&
  127. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  128. {
  129. start.handle = mxEvent.LABEL_HANDLE;
  130. }
  131. else
  132. {
  133. var handler = this.selectionCellsHandler.getHandler(state.cell);
  134. if (handler != null && handler.bends != null && handler.bends.length > 0)
  135. {
  136. start.handle = handler.getHandleForEvent(me);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }));
  144. var mouseDown = null;
  145. this.addMouseListener(
  146. {
  147. mouseDown: function(sender, me) {},
  148. mouseMove: mxUtils.bind(this, function(sender, me)
  149. {
  150. // Checks if any other handler is active
  151. var handlerMap = this.selectionCellsHandler.handlers.map;
  152. for (var key in handlerMap)
  153. {
  154. if (handlerMap[key].index != null)
  155. {
  156. return;
  157. }
  158. }
  159. if (this.isEnabled() && !this.panningHandler.isActive() && !mxEvent.isControlDown(me.getEvent()) &&
  160. !mxEvent.isShiftDown(me.getEvent()) && !mxEvent.isAltDown(me.getEvent()))
  161. {
  162. var tol = this.tolerance;
  163. if (start.point != null && start.state != null && start.event != null)
  164. {
  165. var state = start.state;
  166. if (Math.abs(start.point.x - me.getGraphX()) > tol ||
  167. Math.abs(start.point.y - me.getGraphY()) > tol)
  168. {
  169. // Lazy selection for edges inside groups
  170. if (!this.isCellSelected(state.cell))
  171. {
  172. this.setSelectionCell(state.cell);
  173. }
  174. var handler = this.selectionCellsHandler.getHandler(state.cell);
  175. if (handler != null && handler.bends != null && handler.bends.length > 0)
  176. {
  177. var handle = handler.getHandleForEvent(start.event);
  178. var edgeStyle = this.view.getEdgeStyle(state);
  179. var entity = edgeStyle == mxEdgeStyle.EntityRelation;
  180. // Handles special case where label was clicked on unselected edge in which
  181. // case the label will be moved regardless of the handle that is returned
  182. if (!start.selected && start.handle == mxEvent.LABEL_HANDLE)
  183. {
  184. handle = start.handle;
  185. }
  186. if (!entity || handle == 0 || handle == handler.bends.length - 1 || handle == mxEvent.LABEL_HANDLE)
  187. {
  188. // Source or target handle or connected for direct handle access or orthogonal line
  189. // with just two points where the central handle is moved regardless of mouse position
  190. if (handle == mxEvent.LABEL_HANDLE || handle == 0 || state.visibleSourceState != null ||
  191. handle == handler.bends.length - 1 || state.visibleTargetState != null)
  192. {
  193. if (!entity && handle != mxEvent.LABEL_HANDLE)
  194. {
  195. var pts = state.absolutePoints;
  196. // Default case where handles are at corner points handles
  197. // drag of corner as drag of existing point
  198. if (pts != null && ((edgeStyle == null && handle == null) ||
  199. edgeStyle == mxEdgeStyle.OrthConnector))
  200. {
  201. // Does not use handles if they were not initially visible
  202. handle = start.handle;
  203. if (handle == null)
  204. {
  205. var box = new mxRectangle(start.point.x, start.point.y);
  206. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  207. if (mxUtils.contains(box, pts[0].x, pts[0].y))
  208. {
  209. // Moves source terminal handle
  210. handle = 0;
  211. }
  212. else if (mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  213. {
  214. // Moves target terminal handle
  215. handle = handler.bends.length - 1;
  216. }
  217. else
  218. {
  219. // Checks if edge has no bends
  220. var nobends = edgeStyle != null && (pts.length == 2 || (pts.length == 3 &&
  221. ((Math.round(pts[0].x - pts[1].x) == 0 && Math.round(pts[1].x - pts[2].x) == 0) ||
  222. (Math.round(pts[0].y - pts[1].y) == 0 && Math.round(pts[1].y - pts[2].y) == 0))));
  223. if (nobends)
  224. {
  225. // Moves central handle for straight orthogonal edges
  226. handle = 2;
  227. }
  228. else
  229. {
  230. // Finds and moves vertical or horizontal segment
  231. handle = mxUtils.findNearestSegment(state, start.point.x, start.point.y);
  232. // Converts segment to virtual handle index
  233. if (edgeStyle == null)
  234. {
  235. handle = mxEvent.VIRTUAL_HANDLE - handle;
  236. }
  237. // Maps segment to handle
  238. else
  239. {
  240. handle += 1;
  241. }
  242. }
  243. }
  244. }
  245. }
  246. // Creates a new waypoint and starts moving it
  247. if (handle == null)
  248. {
  249. handle = mxEvent.VIRTUAL_HANDLE;
  250. }
  251. }
  252. handler.start(me.getGraphX(), me.getGraphX(), handle);
  253. start.state = null;
  254. start.event = null;
  255. start.point = null;
  256. start.handle = null;
  257. start.selected = false;
  258. me.consume();
  259. // Removes preview rectangle in graph handler
  260. this.graphHandler.reset();
  261. }
  262. }
  263. else if (entity && (state.visibleSourceState != null || state.visibleTargetState != null))
  264. {
  265. // Disables moves on entity to make it consistent
  266. this.graphHandler.reset();
  267. me.consume();
  268. }
  269. }
  270. }
  271. }
  272. else
  273. {
  274. // Updates cursor for unselected edges under the mouse
  275. var state = me.getState();
  276. if (state != null)
  277. {
  278. // Checks if state was removed in call to stopEditing above
  279. if (this.model.isEdge(state.cell))
  280. {
  281. var cursor = null;
  282. var pts = state.absolutePoints;
  283. if (pts != null)
  284. {
  285. var box = new mxRectangle(me.getGraphX(), me.getGraphY());
  286. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  287. if (state.text != null && state.text.boundingBox != null &&
  288. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  289. {
  290. cursor = 'move';
  291. }
  292. else if (mxUtils.contains(box, pts[0].x, pts[0].y) ||
  293. mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  294. {
  295. cursor = 'pointer';
  296. }
  297. else if (state.visibleSourceState != null || state.visibleTargetState != null)
  298. {
  299. // Moving is not allowed for entity relation but still indicate hover state
  300. var tmp = this.view.getEdgeStyle(state);
  301. cursor = 'crosshair';
  302. if (tmp != mxEdgeStyle.EntityRelation && this.isOrthogonal(state))
  303. {
  304. var idx = mxUtils.findNearestSegment(state, me.getGraphX(), me.getGraphY());
  305. if (idx < pts.length - 1 && idx >= 0)
  306. {
  307. cursor = (Math.round(pts[idx].x - pts[idx + 1].x) == 0) ?
  308. 'col-resize' : 'row-resize';
  309. }
  310. }
  311. }
  312. }
  313. if (cursor != null)
  314. {
  315. state.setCursor(cursor);
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }),
  322. mouseUp: mxUtils.bind(this, function(sender, me)
  323. {
  324. start.state = null;
  325. start.event = null;
  326. start.point = null;
  327. start.handle = null;
  328. })
  329. });
  330. }
  331. // HTML entities are displayed as plain text in wrapped plain text labels
  332. this.cellRenderer.getLabelValue = function(state)
  333. {
  334. var result = mxCellRenderer.prototype.getLabelValue.apply(this, arguments);
  335. if (state.view.graph.isHtmlLabel(state.cell))
  336. {
  337. if (state.style['html'] != 1)
  338. {
  339. result = mxUtils.htmlEntities(result, false);
  340. }
  341. else
  342. {
  343. result = state.view.graph.sanitizeHtml(result);
  344. }
  345. }
  346. return result;
  347. };
  348. // All code below not available and not needed in embed mode
  349. if (typeof mxVertexHandler !== 'undefined')
  350. {
  351. this.setConnectable(true);
  352. this.setDropEnabled(true);
  353. this.setPanning(true);
  354. this.setTooltips(true);
  355. this.setAllowLoops(true);
  356. this.allowAutoPanning = true;
  357. this.resetEdgesOnConnect = false;
  358. this.constrainChildren = false;
  359. this.constrainRelativeChildren = true;
  360. // Do not scroll after moving cells
  361. this.graphHandler.scrollOnMove = false;
  362. this.graphHandler.scaleGrid = true;
  363. // Disables cloning of connection sources by default
  364. this.connectionHandler.setCreateTarget(false);
  365. this.connectionHandler.insertBeforeSource = true;
  366. // Disables built-in connection starts
  367. this.connectionHandler.isValidSource = function(cell, me)
  368. {
  369. return false;
  370. };
  371. // Sets the style to be used when an elbow edge is double clicked
  372. this.alternateEdgeStyle = 'vertical';
  373. if (stylesheet == null)
  374. {
  375. this.loadStylesheet();
  376. }
  377. // Adds page centers to the guides for moving cells
  378. var graphHandlerGetGuideStates = this.graphHandler.getGuideStates;
  379. this.graphHandler.getGuideStates = function()
  380. {
  381. var result = graphHandlerGetGuideStates.apply(this, arguments);
  382. // Create virtual cell state for page centers
  383. if (this.graph.pageVisible)
  384. {
  385. var guides = [];
  386. var pf = this.graph.pageFormat;
  387. var ps = this.graph.pageScale;
  388. var pw = pf.width * ps;
  389. var ph = pf.height * ps;
  390. var t = this.graph.view.translate;
  391. var s = this.graph.view.scale;
  392. var layout = this.graph.getPageLayout();
  393. for (var i = 0; i < layout.width; i++)
  394. {
  395. guides.push(new mxRectangle(((layout.x + i) * pw + t.x) * s,
  396. (layout.y * ph + t.y) * s, pw * s, ph * s));
  397. }
  398. for (var j = 0; j < layout.height; j++)
  399. {
  400. guides.push(new mxRectangle((layout.x * pw + t.x) * s,
  401. ((layout.y + j) * ph + t.y) * s, pw * s, ph * s));
  402. }
  403. // Page center guides have predence over normal guides
  404. result = guides.concat(result);
  405. }
  406. return result;
  407. };
  408. // Overrides zIndex for dragElement
  409. mxDragSource.prototype.dragElementZIndex = mxPopupMenu.prototype.zIndex;
  410. // Overrides color for virtual guides for page centers
  411. mxGuide.prototype.getGuideColor = function(state, horizontal)
  412. {
  413. return (state.cell == null) ? '#ffa500' /* orange */ : mxConstants.GUIDE_COLOR;
  414. };
  415. // Changes color of move preview for black backgrounds
  416. this.graphHandler.createPreviewShape = function(bounds)
  417. {
  418. this.previewColor = (this.graph.background == '#000000') ? '#ffffff' : mxGraphHandler.prototype.previewColor;
  419. return mxGraphHandler.prototype.createPreviewShape.apply(this, arguments);
  420. };
  421. // Handles parts of cells by checking if part=1 is in the style and returning the parent
  422. // if the parent is not already in the list of cells. container style is used to disable
  423. // step into swimlanes and dropTarget style is used to disable acting as a drop target.
  424. // LATER: Handle recursive parts
  425. this.graphHandler.getCells = function(initialCell)
  426. {
  427. var cells = mxGraphHandler.prototype.getCells.apply(this, arguments);
  428. var newCells = [];
  429. for (var i = 0; i < cells.length; i++)
  430. {
  431. var state = this.graph.view.getState(cells[i]);
  432. var style = (state != null) ? state.style : this.graph.getCellStyle(cells[i]);
  433. if (mxUtils.getValue(style, 'part', '0') == '1')
  434. {
  435. var parent = this.graph.model.getParent(cells[i]);
  436. if (this.graph.model.isVertex(parent) && mxUtils.indexOf(cells, parent) < 0)
  437. {
  438. newCells.push(parent);
  439. }
  440. }
  441. else
  442. {
  443. newCells.push(cells[i]);
  444. }
  445. }
  446. return newCells;
  447. };
  448. // Handles parts of cells when cloning the source for new connections
  449. this.connectionHandler.createTargetVertex = function(evt, source)
  450. {
  451. var state = this.graph.view.getState(source);
  452. var style = (state != null) ? state.style : this.graph.getCellStyle(source);
  453. if (mxUtils.getValue(style, 'part', false))
  454. {
  455. var parent = this.graph.model.getParent(source);
  456. if (this.graph.model.isVertex(parent))
  457. {
  458. source = parent;
  459. }
  460. }
  461. return mxConnectionHandler.prototype.createTargetVertex.apply(this, arguments);
  462. };
  463. var rubberband = new mxRubberband(this);
  464. this.getRubberband = function()
  465. {
  466. return rubberband;
  467. };
  468. // Timer-based activation of outline connect in connection handler
  469. var startTime = new Date().getTime();
  470. var timeOnTarget = 0;
  471. var connectionHandlerMouseMove = this.connectionHandler.mouseMove;
  472. this.connectionHandler.mouseMove = function()
  473. {
  474. var prev = this.currentState;
  475. connectionHandlerMouseMove.apply(this, arguments);
  476. if (prev != this.currentState)
  477. {
  478. startTime = new Date().getTime();
  479. timeOnTarget = 0;
  480. }
  481. else
  482. {
  483. timeOnTarget = new Date().getTime() - startTime;
  484. }
  485. };
  486. // Activates outline connect after 1500ms with touch event or if alt is pressed inside the shape
  487. var connectionHandleIsOutlineConnectEvent = this.connectionHandler.isOutlineConnectEvent;
  488. this.connectionHandler.isOutlineConnectEvent = function(me)
  489. {
  490. return (this.currentState != null && me.getState() == this.currentState && timeOnTarget > 2000) ||
  491. ((this.currentState == null || mxUtils.getValue(this.currentState.style, 'outlineConnect', '1') != '0') &&
  492. connectionHandleIsOutlineConnectEvent.apply(this, arguments));
  493. };
  494. // Adds shift+click to toggle selection state
  495. var isToggleEvent = this.isToggleEvent;
  496. this.isToggleEvent = function(evt)
  497. {
  498. return isToggleEvent.apply(this, arguments) || mxEvent.isShiftDown(evt);
  499. };
  500. // Workaround for Firefox where first mouse down is received
  501. // after tap and hold if scrollbars are visible, which means
  502. // start rubberband immediately if no cell is under mouse.
  503. var isForceRubberBandEvent = rubberband.isForceRubberbandEvent;
  504. rubberband.isForceRubberbandEvent = function(me)
  505. {
  506. return isForceRubberBandEvent.apply(this, arguments) ||
  507. (mxUtils.hasScrollbars(this.graph.container) && mxClient.IS_FF &&
  508. mxClient.IS_WIN && me.getState() == null && mxEvent.isTouchEvent(me.getEvent()));
  509. };
  510. // Shows hand cursor while panning
  511. var prevCursor = null;
  512. this.panningHandler.addListener(mxEvent.PAN_START, mxUtils.bind(this, function()
  513. {
  514. if (this.isEnabled())
  515. {
  516. prevCursor = this.container.style.cursor;
  517. this.container.style.cursor = 'move';
  518. }
  519. }));
  520. this.panningHandler.addListener(mxEvent.PAN_END, mxUtils.bind(this, function()
  521. {
  522. if (this.isEnabled())
  523. {
  524. this.container.style.cursor = prevCursor;
  525. }
  526. }));
  527. this.popupMenuHandler.autoExpand = true;
  528. this.popupMenuHandler.isSelectOnPopup = function(me)
  529. {
  530. return mxEvent.isMouseEvent(me.getEvent());
  531. };
  532. // Enables links if graph is "disabled" (ie. read-only)
  533. var click = this.click;
  534. this.click = function(me)
  535. {
  536. if (!this.isEnabled() && !me.isConsumed())
  537. {
  538. var cell = me.getCell();
  539. if (cell != null)
  540. {
  541. var link = this.getLinkForCell(cell);
  542. if (link != null)
  543. {
  544. window.open(link);
  545. }
  546. }
  547. }
  548. else
  549. {
  550. return click.apply(this, arguments);
  551. }
  552. };
  553. // Shows pointer cursor for clickable cells with links
  554. // ie. if the graph is disabled and cells cannot be selected
  555. var getCursorForCell = this.getCursorForCell;
  556. this.getCursorForCell = function(cell)
  557. {
  558. if (!this.isEnabled())
  559. {
  560. var link = this.getLinkForCell(cell);
  561. if (link != null)
  562. {
  563. return 'pointer';
  564. }
  565. }
  566. else
  567. {
  568. return getCursorForCell.apply(this, arguments);
  569. }
  570. };
  571. // Changes rubberband selection to be recursive
  572. this.selectRegion = function(rect, evt)
  573. {
  574. var cells = this.getAllCells(rect.x, rect.y, rect.width, rect.height);
  575. this.selectCellsForEvent(cells, evt);
  576. return cells;
  577. };
  578. // Recursive implementation for rubberband selection
  579. this.getAllCells = function(x, y, width, height, parent, result)
  580. {
  581. result = (result != null) ? result : [];
  582. if (width > 0 || height > 0)
  583. {
  584. var model = this.getModel();
  585. var right = x + width;
  586. var bottom = y + height;
  587. if (parent == null)
  588. {
  589. parent = this.getCurrentRoot();
  590. if (parent == null)
  591. {
  592. parent = model.getRoot();
  593. }
  594. }
  595. if (parent != null)
  596. {
  597. var childCount = model.getChildCount(parent);
  598. for (var i = 0; i < childCount; i++)
  599. {
  600. var cell = model.getChildAt(parent, i);
  601. var state = this.view.getState(cell);
  602. if (state != null && this.isCellVisible(cell) && mxUtils.getValue(state.style, 'locked', '0') != '1')
  603. {
  604. var deg = mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION) || 0;
  605. var box = state;
  606. if (deg != 0)
  607. {
  608. box = mxUtils.getBoundingBox(box, deg);
  609. }
  610. if ((model.isEdge(cell) || model.isVertex(cell)) &&
  611. box.x >= x && box.y + box.height <= bottom &&
  612. box.y >= y && box.x + box.width <= right)
  613. {
  614. result.push(cell);
  615. }
  616. this.getAllCells(x, y, width, height, cell, result);
  617. }
  618. }
  619. }
  620. }
  621. return result;
  622. };
  623. // Never removes cells from parents that are being moved
  624. var graphHandlerShouldRemoveCellsFromParent = this.graphHandler.shouldRemoveCellsFromParent;
  625. this.graphHandler.shouldRemoveCellsFromParent = function(parent, cells, evt)
  626. {
  627. if (this.graph.isCellSelected(parent))
  628. {
  629. return false;
  630. }
  631. return graphHandlerShouldRemoveCellsFromParent.apply(this, arguments);
  632. };
  633. // Unlocks all cells
  634. this.isCellLocked = function(cell)
  635. {
  636. var pState = this.view.getState(cell);
  637. while (pState != null)
  638. {
  639. if (mxUtils.getValue(pState.style, 'locked', '0') == '1')
  640. {
  641. return true;
  642. }
  643. pState = this.view.getState(this.model.getParent(pState.cell));
  644. }
  645. return false;
  646. };
  647. var tapAndHoldSelection = null;
  648. // Uses this event to process mouseDown to check the selection state before it is changed
  649. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  650. {
  651. if (evt.getProperty('eventName') == 'mouseDown')
  652. {
  653. var me = evt.getProperty('event');
  654. var state = me.getState();
  655. if (state != null && !this.isSelectionEmpty() && !this.isCellSelected(state.cell))
  656. {
  657. tapAndHoldSelection = this.getSelectionCells();
  658. }
  659. else
  660. {
  661. tapAndHoldSelection = null;
  662. }
  663. }
  664. }));
  665. // Tap and hold on background starts rubberband for multiple selected
  666. // cells the cell associated with the event is deselected
  667. this.addListener(mxEvent.TAP_AND_HOLD, mxUtils.bind(this, function(sender, evt)
  668. {
  669. if (!mxEvent.isMultiTouchEvent(evt))
  670. {
  671. var me = evt.getProperty('event');
  672. var cell = evt.getProperty('cell');
  673. if (cell == null)
  674. {
  675. var pt = mxUtils.convertPoint(this.container,
  676. mxEvent.getClientX(me), mxEvent.getClientY(me));
  677. rubberband.start(pt.x, pt.y);
  678. }
  679. else if (tapAndHoldSelection != null)
  680. {
  681. this.addSelectionCells(tapAndHoldSelection);
  682. }
  683. else if (this.getSelectionCount() > 1 && this.isCellSelected(cell))
  684. {
  685. this.removeSelectionCell(cell);
  686. }
  687. // Blocks further processing of the event
  688. tapAndHoldSelection = null;
  689. evt.consume();
  690. }
  691. }));
  692. // On connect the target is selected and we clone the cell of the preview edge for insert
  693. this.connectionHandler.selectCells = function(edge, target)
  694. {
  695. this.graph.setSelectionCell(target || edge);
  696. };
  697. // Shows connection points only if cell not selected
  698. this.connectionHandler.constraintHandler.isStateIgnored = function(state, source)
  699. {
  700. return source && state.view.graph.isCellSelected(state.cell);
  701. };
  702. // Updates constraint handler if the selection changes
  703. this.selectionModel.addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  704. {
  705. var ch = this.connectionHandler.constraintHandler;
  706. if (ch.currentFocus != null && ch.isStateIgnored(ch.currentFocus, true))
  707. {
  708. ch.currentFocus = null;
  709. ch.constraints = null;
  710. ch.destroyIcons();
  711. }
  712. ch.destroyFocusHighlight();
  713. }));
  714. // Initializes touch interface
  715. if (Graph.touchStyle)
  716. {
  717. this.initTouch();
  718. }
  719. /**
  720. * Adds locking
  721. */
  722. var graphUpdateMouseEvent = this.updateMouseEvent;
  723. this.updateMouseEvent = function(me)
  724. {
  725. me = graphUpdateMouseEvent.apply(this, arguments);
  726. if (this.isCellLocked(me.getCell()))
  727. {
  728. me.state = null;
  729. }
  730. return me;
  731. };
  732. }
  733. };
  734. /**
  735. * Specifies if the touch UI should be used (cannot detect touch in FF so always on for Windows/Linux)
  736. */
  737. Graph.touchStyle = mxClient.IS_TOUCH || (mxClient.IS_FF && mxClient.IS_WIN) || navigator.maxTouchPoints > 0 ||
  738. navigator.msMaxTouchPoints > 0 || window.urlParams == null || urlParams['touch'] == '1';
  739. /**
  740. * Shortcut for capability check.
  741. */
  742. Graph.fileSupport = window.File != null && window.FileReader != null && window.FileList != null &&
  743. (window.urlParams == null || urlParams['filesupport'] != '0');
  744. /**
  745. * Default size for line jumps.
  746. */
  747. Graph.lineJumpsEnabled = true;
  748. /**
  749. * Default size for line jumps.
  750. */
  751. Graph.defaultJumpSize = 6;
  752. /**
  753. * Graph inherits from mxGraph.
  754. */
  755. mxUtils.extend(Graph, mxGraph);
  756. /**
  757. * Allows all values in fit.
  758. */
  759. Graph.prototype.minFitScale = null;
  760. /**
  761. * Allows all values in fit.
  762. */
  763. Graph.prototype.maxFitScale = null;
  764. /**
  765. * Sets the policy for links. Possible values are "self" to replace any framesets,
  766. * "blank" to load the URL in <linkTarget> and "auto" (default).
  767. */
  768. Graph.prototype.linkPolicy = (urlParams['target'] == 'frame') ? 'blank' : (urlParams['target'] || 'auto');
  769. /**
  770. * Target for links that open in a new window. Default is _blank.
  771. */
  772. Graph.prototype.linkTarget = (urlParams['target'] == 'frame') ? '_self' : '_blank';
  773. /**
  774. * Scrollbars are enabled on non-touch devices (not including Firefox because touch events
  775. * cannot be detected in Firefox, see above).
  776. */
  777. Graph.prototype.defaultScrollbars = !mxClient.IS_IOS;
  778. /**
  779. * Specifies if the page should be visible for new files. Default is true.
  780. */
  781. Graph.prototype.defaultPageVisible = true;
  782. /**
  783. * Specifies if the app should run in chromeless mode. Default is false.
  784. * This default is only used if the contructor argument is null.
  785. */
  786. Graph.prototype.lightbox = false;
  787. /**
  788. *
  789. */
  790. Graph.prototype.defaultGraphBackground = '#ffffff';
  791. /**
  792. * Specifies the size of the size for "tiles" to be used for a graph with
  793. * scrollbars but no visible background page. A good value is large
  794. * enough to reduce the number of repaints that is caused for auto-
  795. * translation, which depends on this value, and small enough to give
  796. * a small empty buffer around the graph. Default is 400x400.
  797. */
  798. Graph.prototype.scrollTileSize = new mxRectangle(0, 0, 400, 400);
  799. /**
  800. * Overrides the background color and paints a transparent background.
  801. */
  802. Graph.prototype.transparentBackground = true;
  803. /**
  804. * Sets the default target for all links in cells.
  805. */
  806. Graph.prototype.defaultEdgeLength = 80;
  807. /**
  808. * Disables move of bends/segments without selecting.
  809. */
  810. Graph.prototype.edgeMode = false;
  811. /**
  812. * Allows all values in fit.
  813. */
  814. Graph.prototype.connectionArrowsEnabled = true;
  815. /**
  816. * Specifies the regular expression for matching placeholders.
  817. */
  818. Graph.prototype.placeholderPattern = new RegExp('%(date\{.*\}|[^%^\{^\}]+)%', 'g');
  819. /**
  820. * Specifies the regular expression for matching placeholders.
  821. */
  822. Graph.prototype.absoluteUrlPattern = new RegExp('^(?:[a-z]+:)?//', 'i');
  823. /**
  824. * Specifies the default name for the theme. Default is 'default'.
  825. */
  826. Graph.prototype.defaultThemeName = 'default';
  827. /**
  828. * Specifies the default name for the theme. Default is 'default'.
  829. */
  830. Graph.prototype.defaultThemes = {};
  831. /**
  832. * Base URL for relative links.
  833. */
  834. Graph.prototype.baseUrl = ((window != window.top) ? document.referrer : document.location.toString()).split('#')[0];
  835. /**
  836. * Installs child layout styles.
  837. */
  838. Graph.prototype.init = function(container)
  839. {
  840. mxGraph.prototype.init.apply(this, arguments);
  841. // Intercepts links with no target attribute and opens in new window
  842. this.cellRenderer.initializeLabel = function(state, shape)
  843. {
  844. mxCellRenderer.prototype.initializeLabel.apply(this, arguments);
  845. // Checks tolerance for clicks on links
  846. var tol = state.view.graph.tolerance;
  847. var handleClick = true;
  848. var first = null;
  849. var down = mxUtils.bind(this, function(evt)
  850. {
  851. handleClick = true;
  852. first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  853. });
  854. var move = mxUtils.bind(this, function(evt)
  855. {
  856. handleClick = handleClick && first != null &&
  857. Math.abs(first.x - mxEvent.getClientX(evt)) < tol &&
  858. Math.abs(first.y - mxEvent.getClientY(evt)) < tol;
  859. });
  860. var up = mxUtils.bind(this, function(evt)
  861. {
  862. if (handleClick)
  863. {
  864. var elt = mxEvent.getSource(evt)
  865. while (elt != null && elt != shape.node)
  866. {
  867. if (elt.nodeName.toLowerCase() == 'a')
  868. {
  869. state.view.graph.labelLinkClicked(state, elt, evt);
  870. break;
  871. }
  872. elt = elt.parentNode;
  873. }
  874. }
  875. });
  876. mxEvent.addGestureListeners(shape.node, down, move, up);
  877. mxEvent.addListener(shape.node, 'click', function(evt)
  878. {
  879. mxEvent.consume(evt);
  880. });
  881. };
  882. this.initLayoutManager();
  883. };
  884. /**
  885. * Installs automatic layout via styles
  886. */
  887. Graph.prototype.labelLinkClicked = function(state, elt, evt)
  888. {
  889. var href = elt.getAttribute('href');
  890. if (href != null && !this.isPageLink(href))
  891. {
  892. if (!this.isEnabled())
  893. {
  894. var target = state.view.graph.isBlankLink(href) ?
  895. state.view.graph.linkTarget : '_top';
  896. href = state.view.graph.getAbsoluteUrl(href);
  897. // Workaround for blocking in same iframe
  898. if (target == '_self' && window != window.top)
  899. {
  900. window.location.href = href;
  901. }
  902. else
  903. {
  904. // Avoids page reload for anchors (workaround for IE but used everywhere)
  905. if (href.substring(0, this.baseUrl.length) == this.baseUrl &&
  906. href.charAt(this.baseUrl.length) == '#' &&
  907. target == '_top' && window == window.top)
  908. {
  909. window.location.hash = href.split('#')[1];
  910. }
  911. else
  912. {
  913. window.open(href, target);
  914. }
  915. }
  916. }
  917. mxEvent.consume(evt);
  918. }
  919. };
  920. /**
  921. * Installs automatic layout via styles
  922. */
  923. Graph.prototype.initLayoutManager = function()
  924. {
  925. this.layoutManager = new mxLayoutManager(this);
  926. this.layoutManager.getLayout = function(cell)
  927. {
  928. var state = this.graph.view.getState(cell);
  929. var style = (state != null) ? state.style : this.graph.getCellStyle(cell);
  930. if (style['childLayout'] == 'stackLayout')
  931. {
  932. var stackLayout = new mxStackLayout(this.graph, true);
  933. stackLayout.resizeParentMax = mxUtils.getValue(style, 'resizeParentMax', '1') == '1';
  934. stackLayout.horizontal = mxUtils.getValue(style, 'horizontalStack', '1') == '1';
  935. stackLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  936. stackLayout.resizeLast = mxUtils.getValue(style, 'resizeLast', '0') == '1';
  937. stackLayout.marginLeft = style['marginLeft'] || 0;
  938. stackLayout.marginRight = style['marginRight'] || 0;
  939. stackLayout.marginTop = style['marginTop'] || 0;
  940. stackLayout.marginBottom = style['marginBottom'] || 0;
  941. stackLayout.fill = true;
  942. return stackLayout;
  943. }
  944. else if (style['childLayout'] == 'treeLayout')
  945. {
  946. var treeLayout = new mxCompactTreeLayout(this.graph);
  947. treeLayout.horizontal = mxUtils.getValue(style, 'horizontalTree', '1') == '1';
  948. treeLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  949. treeLayout.groupPadding = mxUtils.getValue(style, 'parentPadding', 20);
  950. treeLayout.levelDistance = mxUtils.getValue(style, 'treeLevelDistance', 30);
  951. treeLayout.maintainParentLocation = true;
  952. treeLayout.edgeRouting = false;
  953. treeLayout.resetEdges = false;
  954. return treeLayout;
  955. }
  956. else if (style['childLayout'] == 'flowLayout')
  957. {
  958. var flowLayout = new mxHierarchicalLayout(this.graph, mxUtils.getValue(style,
  959. 'flowOrientation', mxConstants.DIRECTION_EAST));
  960. flowLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  961. flowLayout.parentBorder = mxUtils.getValue(style, 'parentPadding', 20);
  962. flowLayout.maintainParentLocation = true;
  963. // Special undocumented styles for changing the hierarchical
  964. flowLayout.intraCellSpacing = mxUtils.getValue(style, 'intraCellSpacing', mxHierarchicalLayout.prototype.intraCellSpacing);
  965. flowLayout.interRankCellSpacing = mxUtils.getValue(style, 'interRankCellSpacing', mxHierarchicalLayout.prototype.interRankCellSpacing);
  966. flowLayout.interHierarchySpacing = mxUtils.getValue(style, 'interHierarchySpacing', mxHierarchicalLayout.prototype.interHierarchySpacing);
  967. flowLayout.parallelEdgeSpacing = mxUtils.getValue(style, 'parallelEdgeSpacing', mxHierarchicalLayout.prototype.parallelEdgeSpacing);
  968. return flowLayout;
  969. }
  970. return null;
  971. };
  972. };
  973. /**
  974. * Returns the size of the page format scaled with the page size.
  975. */
  976. Graph.prototype.getPageSize = function()
  977. {
  978. return (this.pageVisible) ? new mxRectangle(0, 0, this.pageFormat.width * this.pageScale,
  979. this.pageFormat.height * this.pageScale) : this.scrollTileSize;
  980. };
  981. /**
  982. * Returns a rectangle describing the position and count of the
  983. * background pages, where x and y are the position of the top,
  984. * left page and width and height are the vertical and horizontal
  985. * page count.
  986. */
  987. Graph.prototype.getPageLayout = function()
  988. {
  989. var size = this.getPageSize();
  990. var bounds = this.getGraphBounds();
  991. if (bounds.width == 0 || bounds.height == 0)
  992. {
  993. return new mxRectangle(0, 0, 1, 1);
  994. }
  995. else
  996. {
  997. // Computes untransformed graph bounds
  998. var x = Math.ceil(bounds.x / this.view.scale - this.view.translate.x);
  999. var y = Math.ceil(bounds.y / this.view.scale - this.view.translate.y);
  1000. var w = Math.floor(bounds.width / this.view.scale);
  1001. var h = Math.floor(bounds.height / this.view.scale);
  1002. var x0 = Math.floor(x / size.width);
  1003. var y0 = Math.floor(y / size.height);
  1004. var w0 = Math.ceil((x + w) / size.width) - x0;
  1005. var h0 = Math.ceil((y + h) / size.height) - y0;
  1006. return new mxRectangle(x0, y0, w0, h0);
  1007. }
  1008. };
  1009. /**
  1010. * Sanitizes the given HTML markup.
  1011. */
  1012. Graph.prototype.sanitizeHtml = function(value, editing)
  1013. {
  1014. // Uses https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer
  1015. // NOTE: Original minimized sanitizer was modified to support
  1016. // data URIs for images, and mailto and special data:-links.
  1017. // LATER: Add MathML to whitelisted tags
  1018. function urlX(link)
  1019. {
  1020. if (link != null && link.toString().toLowerCase().substring(0, 11) !== 'javascript:')
  1021. {
  1022. return link;
  1023. }
  1024. return null;
  1025. };
  1026. function idX(id) { return id };
  1027. return html_sanitize(value, urlX, idX);
  1028. };
  1029. /**
  1030. * Revalidates all cells with placeholders in the current graph model.
  1031. */
  1032. Graph.prototype.updatePlaceholders = function()
  1033. {
  1034. var model = this.model;
  1035. var validate = false;
  1036. for (var key in this.model.cells)
  1037. {
  1038. var cell = this.model.cells[key];
  1039. if (this.isReplacePlaceholders(cell))
  1040. {
  1041. this.view.invalidate(cell, false, false);
  1042. validate = true;
  1043. }
  1044. }
  1045. if (validate)
  1046. {
  1047. this.view.validate();
  1048. }
  1049. };
  1050. /**
  1051. * Adds support for placeholders in labels.
  1052. */
  1053. Graph.prototype.isReplacePlaceholders = function(cell)
  1054. {
  1055. return cell.value != null && typeof(cell.value) == 'object' &&
  1056. cell.value.getAttribute('placeholders') == '1';
  1057. };
  1058. /**
  1059. * Adds Alt+click to select cells behind cells.
  1060. */
  1061. Graph.prototype.isTransparentClickEvent = function(evt)
  1062. {
  1063. return mxEvent.isAltDown(evt);
  1064. };
  1065. /**
  1066. * Adds ctrl+shift+connect to disable connections.
  1067. */
  1068. Graph.prototype.isIgnoreTerminalEvent = function(evt)
  1069. {
  1070. return mxEvent.isShiftDown(evt) && mxEvent.isControlDown(evt);
  1071. };
  1072. /**
  1073. * Adds support for placeholders in labels.
  1074. */
  1075. Graph.prototype.isSplitTarget = function(target, cells, evt)
  1076. {
  1077. return !this.model.isEdge(cells[0]) &&
  1078. !mxEvent.isAltDown(evt) && !mxEvent.isShiftDown(evt) &&
  1079. mxGraph.prototype.isSplitTarget.apply(this, arguments);
  1080. };
  1081. /**
  1082. * Adds support for placeholders in labels.
  1083. */
  1084. Graph.prototype.getLabel = function(cell)
  1085. {
  1086. var result = mxGraph.prototype.getLabel.apply(this, arguments);
  1087. if (result != null && this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') == null)
  1088. {
  1089. result = this.replacePlaceholders(cell, result);
  1090. }
  1091. return result;
  1092. };
  1093. /**
  1094. * Adds labelMovable style.
  1095. */
  1096. Graph.prototype.isLabelMovable = function(cell)
  1097. {
  1098. var state = this.view.getState(cell);
  1099. var style = (state != null) ? state.style : this.getCellStyle(cell);
  1100. return !this.isCellLocked(cell) &&
  1101. ((this.model.isEdge(cell) && this.edgeLabelsMovable) ||
  1102. (this.model.isVertex(cell) && (this.vertexLabelsMovable ||
  1103. mxUtils.getValue(style, 'labelMovable', '0') == '1')));
  1104. };
  1105. /**
  1106. * Adds event if grid size is changed.
  1107. */
  1108. Graph.prototype.setGridSize = function(value)
  1109. {
  1110. this.gridSize = value;
  1111. this.fireEvent(new mxEventObject('gridSizeChanged'));
  1112. };
  1113. /**
  1114. * Private helper method.
  1115. */
  1116. Graph.prototype.getGlobalVariable = function(name)
  1117. {
  1118. var val = null;
  1119. if (name == 'date')
  1120. {
  1121. val = new Date().toLocaleDateString();
  1122. }
  1123. else if (name == 'time')
  1124. {
  1125. val = new Date().toLocaleTimeString();
  1126. }
  1127. else if (name == 'timestamp')
  1128. {
  1129. val = new Date().toLocaleString();
  1130. }
  1131. else if (name.substring(0, 5) == 'date{')
  1132. {
  1133. var fmt = name.substring(5, name.length - 1);
  1134. val = this.formatDate(new Date(), fmt);
  1135. }
  1136. return val;
  1137. };
  1138. /**
  1139. * Formats a date, see http://blog.stevenlevithan.com/archives/date-time-format
  1140. */
  1141. Graph.prototype.formatDate = function(date, mask, utc)
  1142. {
  1143. // LATER: Cache regexs
  1144. if (this.dateFormatCache == null)
  1145. {
  1146. this.dateFormatCache = {
  1147. i18n: {
  1148. dayNames: [
  1149. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
  1150. "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  1151. ],
  1152. monthNames: [
  1153. "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  1154. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  1155. ]
  1156. },
  1157. masks: {
  1158. "default": "ddd mmm dd yyyy HH:MM:ss",
  1159. shortDate: "m/d/yy",
  1160. mediumDate: "mmm d, yyyy",
  1161. longDate: "mmmm d, yyyy",
  1162. fullDate: "dddd, mmmm d, yyyy",
  1163. shortTime: "h:MM TT",
  1164. mediumTime: "h:MM:ss TT",
  1165. longTime: "h:MM:ss TT Z",
  1166. isoDate: "yyyy-mm-dd",
  1167. isoTime: "HH:MM:ss",
  1168. isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
  1169. isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
  1170. }
  1171. };
  1172. }
  1173. var dF = this.dateFormatCache;
  1174. var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
  1175. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  1176. timezoneClip = /[^-+\dA-Z]/g,
  1177. pad = function (val, len) {
  1178. val = String(val);
  1179. len = len || 2;
  1180. while (val.length < len) val = "0" + val;
  1181. return val;
  1182. };
  1183. // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
  1184. if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
  1185. mask = date;
  1186. date = undefined;
  1187. }
  1188. // Passing date through Date applies Date.parse, if necessary
  1189. date = date ? new Date(date) : new Date;
  1190. if (isNaN(date)) throw SyntaxError("invalid date");
  1191. mask = String(dF.masks[mask] || mask || dF.masks["default"]);
  1192. // Allow setting the utc argument via the mask
  1193. if (mask.slice(0, 4) == "UTC:") {
  1194. mask = mask.slice(4);
  1195. utc = true;
  1196. }
  1197. var _ = utc ? "getUTC" : "get",
  1198. d = date[_ + "Date"](),
  1199. D = date[_ + "Day"](),
  1200. m = date[_ + "Month"](),
  1201. y = date[_ + "FullYear"](),
  1202. H = date[_ + "Hours"](),
  1203. M = date[_ + "Minutes"](),
  1204. s = date[_ + "Seconds"](),
  1205. L = date[_ + "Milliseconds"](),
  1206. o = utc ? 0 : date.getTimezoneOffset(),
  1207. flags = {
  1208. d: d,
  1209. dd: pad(d),
  1210. ddd: dF.i18n.dayNames[D],
  1211. dddd: dF.i18n.dayNames[D + 7],
  1212. m: m + 1,
  1213. mm: pad(m + 1),
  1214. mmm: dF.i18n.monthNames[m],
  1215. mmmm: dF.i18n.monthNames[m + 12],
  1216. yy: String(y).slice(2),
  1217. yyyy: y,
  1218. h: H % 12 || 12,
  1219. hh: pad(H % 12 || 12),
  1220. H: H,
  1221. HH: pad(H),
  1222. M: M,
  1223. MM: pad(M),
  1224. s: s,
  1225. ss: pad(s),
  1226. l: pad(L, 3),
  1227. L: pad(L > 99 ? Math.round(L / 10) : L),
  1228. t: H < 12 ? "a" : "p",
  1229. tt: H < 12 ? "am" : "pm",
  1230. T: H < 12 ? "A" : "P",
  1231. TT: H < 12 ? "AM" : "PM",
  1232. Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  1233. o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  1234. S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
  1235. };
  1236. return mask.replace(token, function ($0)
  1237. {
  1238. return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
  1239. });
  1240. };
  1241. /**
  1242. *
  1243. */
  1244. Graph.prototype.createLayersDialog = function()
  1245. {
  1246. var div = document.createElement('div');
  1247. div.style.position = 'absolute';
  1248. var model = this.getModel();
  1249. var childCount = model.getChildCount(model.root);
  1250. for (var i = 0; i < childCount; i++)
  1251. {
  1252. (function(layer)
  1253. {
  1254. var span = document.createElement('div');
  1255. span.style.overflow = 'hidden';
  1256. span.style.textOverflow = 'ellipsis';
  1257. span.style.padding = '2px';
  1258. span.style.whiteSpace = 'nowrap';
  1259. var cb = document.createElement('input');
  1260. cb.setAttribute('type', 'checkbox');
  1261. if (model.isVisible(layer))
  1262. {
  1263. cb.setAttribute('checked', 'checked');
  1264. cb.defaultChecked = true;
  1265. }
  1266. span.appendChild(cb);
  1267. var title = layer.value || (mxResources.get('background') || 'Background');
  1268. span.setAttribute('title', title);
  1269. mxUtils.write(span, title);
  1270. div.appendChild(span);
  1271. mxEvent.addListener(cb, 'click', function()
  1272. {
  1273. if (cb.getAttribute('checked') != null)
  1274. {
  1275. cb.removeAttribute('checked');
  1276. }
  1277. else
  1278. {
  1279. cb.setAttribute('checked', 'checked');
  1280. }
  1281. model.setVisible(layer, cb.checked);
  1282. });
  1283. }(model.getChildAt(model.root, i)));
  1284. }
  1285. return div;
  1286. };
  1287. /**
  1288. * Private helper method.
  1289. */
  1290. Graph.prototype.replacePlaceholders = function(cell, str)
  1291. {
  1292. var result = [];
  1293. var last = 0;
  1294. while (match = this.placeholderPattern.exec(str))
  1295. {
  1296. var val = match[0];
  1297. if (val.length > 2 && val != '%label%' && val != '%tooltip%')
  1298. {
  1299. var tmp = null;
  1300. if (match.index > last && str.charAt(match.index - 1) == '%')
  1301. {
  1302. tmp = val.substring(1);
  1303. }
  1304. else
  1305. {
  1306. var name = val.substring(1, val.length - 1);
  1307. // Workaround for invalid char for getting attribute in older versions of IE
  1308. if (name.indexOf('{') < 0)
  1309. {
  1310. var current = cell;
  1311. while (tmp == null && current != null)
  1312. {
  1313. if (current.value != null && typeof(current.value) == 'object')
  1314. {
  1315. tmp = (current.hasAttribute(name)) ? ((current.getAttribute(name) != null) ?
  1316. current.getAttribute(name) : '') : null;
  1317. }
  1318. current = this.model.getParent(current);
  1319. }
  1320. }
  1321. if (tmp == null)
  1322. {
  1323. tmp = this.getGlobalVariable(name);
  1324. }
  1325. }
  1326. result.push(str.substring(last, match.index) + ((tmp != null) ? tmp : val));
  1327. last = match.index + val.length;
  1328. }
  1329. }
  1330. result.push(str.substring(last));
  1331. return result.join('');
  1332. };
  1333. /**
  1334. * Selects cells for connect vertex return value.
  1335. */
  1336. Graph.prototype.selectCellsForConnectVertex = function(cells, evt, hoverIcons)
  1337. {
  1338. // Selects only target vertex if one exists
  1339. if (cells.length == 2 && this.model.isVertex(cells[1]))
  1340. {
  1341. this.setSelectionCell(cells[1]);
  1342. if (hoverIcons != null)
  1343. {
  1344. // Adds hover icons to new target vertex for touch devices
  1345. if (mxEvent.isTouchEvent(evt))
  1346. {
  1347. hoverIcons.update(hoverIcons.getState(this.view.getState(cells[1])));
  1348. }
  1349. else
  1350. {
  1351. // Hides hover icons after click with mouse
  1352. hoverIcons.reset();
  1353. }
  1354. }
  1355. this.scrollCellToVisible(cells[1]);
  1356. }
  1357. else
  1358. {
  1359. this.setSelectionCells(cells);
  1360. }
  1361. };
  1362. /**
  1363. * Adds a connection to the given vertex.
  1364. */
  1365. Graph.prototype.connectVertex = function(source, direction, length, evt, forceClone, ignoreCellAt)
  1366. {
  1367. ignoreCellAt = (ignoreCellAt) ? ignoreCellAt : false;
  1368. var pt = (source.geometry.relative && source.parent.geometry != null) ?
  1369. new mxPoint(source.parent.geometry.width * source.geometry.x, source.parent.geometry.height * source.geometry.y) :
  1370. new mxPoint(source.geometry.x, source.geometry.y);
  1371. if (direction == mxConstants.DIRECTION_NORTH)
  1372. {
  1373. pt.x += source.geometry.width / 2;
  1374. pt.y -= length ;
  1375. }
  1376. else if (direction == mxConstants.DIRECTION_SOUTH)
  1377. {
  1378. pt.x += source.geometry.width / 2;
  1379. pt.y += source.geometry.height + length;
  1380. }
  1381. else if (direction == mxConstants.DIRECTION_WEST)
  1382. {
  1383. pt.x -= length;
  1384. pt.y += source.geometry.height / 2;
  1385. }
  1386. else
  1387. {
  1388. pt.x += source.geometry.width + length;
  1389. pt.y += source.geometry.height / 2;
  1390. }
  1391. var parentState = this.view.getState(this.model.getParent(source));
  1392. var s = this.view.scale;
  1393. var t = this.view.translate;
  1394. var dx = t.x * s;
  1395. var dy = t.y * s;
  1396. if (this.model.isVertex(parentState.cell))
  1397. {
  1398. dx = parentState.x;
  1399. dy = parentState.y;
  1400. }
  1401. // Workaround for relative child cells
  1402. if (this.model.isVertex(source.parent) && source.geometry.relative)
  1403. {
  1404. pt.x += source.parent.geometry.x;
  1405. pt.y += source.parent.geometry.y;
  1406. }
  1407. // Checks actual end point of edge for target cell
  1408. var target = (ignoreCellAt || (mxEvent.isControlDown(evt) && !forceClone)) ?
  1409. null : this.getCellAt(dx + pt.x * s, dy + pt.y * s);
  1410. if (this.model.isAncestor(target, source))
  1411. {
  1412. target = null;
  1413. }
  1414. // Checks if target or ancestor is locked
  1415. var temp = target;
  1416. while (temp != null)
  1417. {
  1418. if (this.isCellLocked(temp))
  1419. {
  1420. target = null;
  1421. break;
  1422. }
  1423. temp = this.model.getParent(temp);
  1424. }
  1425. // Checks if source and target intersect
  1426. if (target != null)
  1427. {
  1428. var sourceState = this.view.getState(source);
  1429. var targetState = this.view.getState(target);
  1430. if (sourceState != null && targetState != null && mxUtils.intersects(sourceState, targetState))
  1431. {
  1432. target = null;
  1433. }
  1434. }
  1435. var duplicate = !mxEvent.isShiftDown(evt) || forceClone;
  1436. if (duplicate)
  1437. {
  1438. if (direction == mxConstants.DIRECTION_NORTH)
  1439. {
  1440. pt.y -= source.geometry.height / 2;
  1441. }
  1442. else if (direction == mxConstants.DIRECTION_SOUTH)
  1443. {
  1444. pt.y += source.geometry.height / 2;
  1445. }
  1446. else if (direction == mxConstants.DIRECTION_WEST)
  1447. {
  1448. pt.x -= source.geometry.width / 2;
  1449. }
  1450. else
  1451. {
  1452. pt.x += source.geometry.width / 2;
  1453. }
  1454. }
  1455. // Uses connectable parent vertex if one exists
  1456. if (target != null && !this.isCellConnectable(target))
  1457. {
  1458. var parent = this.getModel().getParent(target);
  1459. if (this.getModel().isVertex(parent) && this.isCellConnectable(parent))
  1460. {
  1461. target = parent;
  1462. }
  1463. }
  1464. if (target == source || this.model.isEdge(target) || !this.isCellConnectable(target))
  1465. {
  1466. target = null;
  1467. }
  1468. var result = [];
  1469. this.model.beginUpdate();
  1470. try
  1471. {
  1472. var realTarget = target;
  1473. if (realTarget == null && duplicate)
  1474. {
  1475. // Handles relative children
  1476. var cellToClone = source;
  1477. var geo = this.getCellGeometry(source);
  1478. while (geo != null && geo.relative)
  1479. {
  1480. cellToClone = this.getModel().getParent(cellToClone);
  1481. geo = this.getCellGeometry(cellToClone);
  1482. }
  1483. // Handle consistuents for cloning
  1484. var state = this.view.getState(cellToClone);
  1485. var style = (state != null) ? state.style : this.getCellStyle(cellToClone);
  1486. if (mxUtils.getValue(style, 'part', false))
  1487. {
  1488. var tmpParent = this.model.getParent(cellToClone);
  1489. if (this.model.isVertex(tmpParent))
  1490. {
  1491. cellToClone = tmpParent;
  1492. }
  1493. }
  1494. realTarget = this.duplicateCells([cellToClone], false)[0];
  1495. var geo = this.getCellGeometry(realTarget);
  1496. if (geo != null)
  1497. {
  1498. geo.x = pt.x - geo.width / 2;
  1499. geo.y = pt.y - geo.height / 2;
  1500. }
  1501. }
  1502. // Never connects children in stack layouts
  1503. var layout = null;
  1504. if (this.layoutManager != null)
  1505. {
  1506. layout = this.layoutManager.getLayout(this.model.getParent(source));
  1507. }
  1508. var edge = ((mxEvent.isControlDown(evt) && duplicate) || (target == null && layout != null && layout.constructor == mxStackLayout)) ? null :
  1509. this.insertEdge(this.model.getParent(source), null, '', source, realTarget, this.createCurrentEdgeStyle());
  1510. // Inserts edge before source
  1511. if (edge != null && this.connectionHandler.insertBeforeSource)
  1512. {
  1513. var index = null;
  1514. var tmp = source;
  1515. while (tmp.parent != null && tmp.geometry != null &&
  1516. tmp.geometry.relative && tmp.parent != edge.parent)
  1517. {
  1518. tmp = this.model.getParent(tmp);
  1519. }
  1520. if (tmp != null && tmp.parent != null && tmp.parent == edge.parent)
  1521. {
  1522. var index = tmp.parent.getIndex(tmp);
  1523. tmp.parent.insert(edge, index);
  1524. }
  1525. }
  1526. // Special case: Click on west icon puts clone before cell
  1527. if (target == null && realTarget != null && layout != null && source.parent != null &&
  1528. layout.constructor == mxStackLayout && direction == mxConstants.DIRECTION_WEST)
  1529. {
  1530. var index = source.parent.getIndex(source);
  1531. source.parent.insert(realTarget, index);
  1532. }
  1533. if (edge != null)
  1534. {
  1535. // Uses elbow edges with vertical or horizontal direction
  1536. // var elbowValue = (direction == mxConstants.DIRECTION_NORTH || direction == mxConstants.DIRECTION_SOUTH) ? 'vertical' : 'horizontal';
  1537. // edge.style = mxUtils.setStyle(edge.style, 'edgeStyle', 'elbowEdgeStyle');
  1538. // edge.style = mxUtils.setStyle(edge.style, 'elbow', elbowValue);
  1539. result.push(edge);
  1540. }
  1541. if (target == null && realTarget != null)
  1542. {
  1543. result.push(realTarget);
  1544. }
  1545. if (realTarget == null && edge != null)
  1546. {
  1547. edge.geometry.setTerminalPoint(pt, false);
  1548. }
  1549. if (edge != null)
  1550. {
  1551. this.fireEvent(new mxEventObject('cellsInserted', 'cells', [edge]));
  1552. }
  1553. }
  1554. finally
  1555. {
  1556. this.model.endUpdate();
  1557. }
  1558. return result;
  1559. };
  1560. /**
  1561. * Returns all labels in the diagram as a string.
  1562. */
  1563. Graph.prototype.getIndexableText = function()
  1564. {
  1565. var tmp = document.createElement('div');
  1566. var labels = [];
  1567. var label = '';
  1568. for (var key in this.model.cells)
  1569. {
  1570. var cell = this.model.cells[key];
  1571. if (this.model.isVertex(cell) || this.model.isEdge(cell))
  1572. {
  1573. if (this.isHtmlLabel(cell))
  1574. {
  1575. tmp.innerHTML = this.getLabel(cell);
  1576. label = mxUtils.extractTextWithWhitespace([tmp]);
  1577. }
  1578. else
  1579. {
  1580. label = this.getLabel(cell);
  1581. }
  1582. label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' '));
  1583. if (label.length > 0)
  1584. {
  1585. labels.push(label);
  1586. }
  1587. }
  1588. }
  1589. return labels.join(' ');
  1590. };
  1591. /**
  1592. * Returns the label for the given cell.
  1593. */
  1594. Graph.prototype.convertValueToString = function(cell)
  1595. {
  1596. if (cell.value != null && typeof(cell.value) == 'object')
  1597. {
  1598. if (this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') != null)
  1599. {
  1600. var name = cell.getAttribute('placeholder');
  1601. var current = cell;
  1602. var result = null;
  1603. while (result == null && current != null)
  1604. {
  1605. if (current.value != null && typeof(current.value) == 'object')
  1606. {
  1607. result = (current.hasAttribute(name)) ? ((current.getAttribute(name) != null) ?
  1608. current.getAttribute(name) : '') : null;
  1609. }
  1610. current = this.model.getParent(current);
  1611. }
  1612. return result || '';
  1613. }
  1614. else
  1615. {
  1616. return cell.value.getAttribute('label');
  1617. }
  1618. }
  1619. return mxGraph.prototype.convertValueToString.apply(this, arguments);
  1620. };
  1621. /**
  1622. * Returns the link for the given cell.
  1623. */
  1624. Graph.prototype.getLinksForState = function(state)
  1625. {
  1626. if (state != null && state.text != null && state.text.node != null)
  1627. {
  1628. return state.text.node.getElementsByTagName('a');
  1629. }
  1630. return null;
  1631. };
  1632. /**
  1633. * Returns the link for the given cell.
  1634. */
  1635. Graph.prototype.getLinkForCell = function(cell)
  1636. {
  1637. if (cell.value != null && typeof(cell.value) == 'object')
  1638. {
  1639. var link = cell.value.getAttribute('link');
  1640. // Removes links with leading javascript: protocol
  1641. // TODO: Check more possible attack vectors
  1642. if (link != null && link.toLowerCase().substring(0, 11) === 'javascript:')
  1643. {
  1644. link = link.substring(11);
  1645. }
  1646. return link;
  1647. }
  1648. return null;
  1649. };
  1650. /**
  1651. * Overrides label orientation for collapsed swimlanes inside stack.
  1652. */
  1653. Graph.prototype.getCellStyle = function(cell)
  1654. {
  1655. var style = mxGraph.prototype.getCellStyle.apply(this, arguments);
  1656. if (cell != null && this.layoutManager != null)
  1657. {
  1658. var parent = this.model.getParent(cell);
  1659. if (this.model.isVertex(parent) && this.isCellCollapsed(cell))
  1660. {
  1661. var layout = this.layoutManager.getLayout(parent);
  1662. if (layout != null && layout.constructor == mxStackLayout)
  1663. {
  1664. style[mxConstants.STYLE_HORIZONTAL] = !layout.horizontal;
  1665. }
  1666. }
  1667. }
  1668. return style;
  1669. };
  1670. /**
  1671. * Disables alternate width persistence for stack layout parents
  1672. */
  1673. Graph.prototype.updateAlternateBounds = function(cell, geo, willCollapse)
  1674. {
  1675. if (cell != null && geo != null && this.layoutManager != null && geo.alternateBounds != null)
  1676. {
  1677. var layout = this.layoutManager.getLayout(this.model.getParent(cell));
  1678. if (layout != null && layout.constructor == mxStackLayout)
  1679. {
  1680. if (layout.horizontal)
  1681. {
  1682. geo.alternateBounds.height = 0;
  1683. }
  1684. else
  1685. {
  1686. geo.alternateBounds.width = 0;
  1687. }
  1688. }
  1689. }
  1690. mxGraph.prototype.updateAlternateBounds.apply(this, arguments);
  1691. };
  1692. /**
  1693. * Adds Shift+collapse/expand and size management for folding inside stack
  1694. */
  1695. Graph.prototype.isMoveCellsEvent = function(evt)
  1696. {
  1697. return mxEvent.isShiftDown(evt);
  1698. };
  1699. /**
  1700. * Adds Shift+collapse/expand and size management for folding inside stack
  1701. */
  1702. Graph.prototype.foldCells = function(collapse, recurse, cells, checkFoldable, evt)
  1703. {
  1704. recurse = (recurse != null) ? recurse : false;
  1705. if (cells == null)
  1706. {
  1707. cells = this.getFoldableCells(this.getSelectionCells(), collapse);
  1708. }
  1709. if (cells != null)
  1710. {
  1711. this.model.beginUpdate();
  1712. try
  1713. {
  1714. mxGraph.prototype.foldCells.apply(this, arguments);
  1715. // Resizes all parent stacks if alt is not pressed
  1716. if (this.layoutManager != null)
  1717. {
  1718. for (var i = 0; i < cells.length; i++)
  1719. {
  1720. var state = this.view.getState(cells[i]);
  1721. var geo = this.getCellGeometry(cells[i]);
  1722. if (state != null && geo != null)
  1723. {
  1724. var dx = Math.round(geo.width - state.width / this.view.scale);
  1725. var dy = Math.round(geo.height - state.height / this.view.scale);
  1726. if (dy != 0 || dx != 0)
  1727. {
  1728. var parent = this.model.getParent(cells[i]);
  1729. var layout = this.layoutManager.getLayout(parent);
  1730. if (layout == null)
  1731. {
  1732. // Moves cells to the right and down after collapse/expand
  1733. if (evt != null && this.isMoveCellsEvent(evt))
  1734. {
  1735. this.moveSiblings(state, parent, dx, dy);
  1736. }
  1737. }
  1738. else if ((evt == null || !mxEvent.isAltDown(evt)) && layout.constructor == mxStackLayout && !layout.resizeLast)
  1739. {
  1740. this.resizeParentStacks(parent, layout, dx, dy);
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. finally
  1748. {
  1749. this.model.endUpdate();
  1750. }
  1751. // Selects cells after folding
  1752. if (this.isEnabled())
  1753. {
  1754. this.setSelectionCells(cells);
  1755. }
  1756. }
  1757. };
  1758. /**
  1759. * Overrides label orientation for collapsed swimlanes inside stack.
  1760. */
  1761. Graph.prototype.moveSiblings = function(state, parent, dx, dy)
  1762. {
  1763. this.model.beginUpdate();
  1764. try
  1765. {
  1766. var cells = this.getCellsBeyond(state.x, state.y, parent, true, true);
  1767. for (var i = 0; i < cells.length; i++)
  1768. {
  1769. if (cells[i] != state.cell)
  1770. {
  1771. var tmp = this.view.getState(cells[i]);
  1772. var geo = this.getCellGeometry(cells[i]);
  1773. if (tmp != null && geo != null)
  1774. {
  1775. geo = geo.clone();
  1776. geo.translate(Math.round(dx * Math.max(0, Math.min(1, (tmp.x - state.x) / state.width))),
  1777. Math.round(dy * Math.max(0, Math.min(1, (tmp.y - state.y) / state.height))));
  1778. this.model.setGeometry(cells[i], geo);
  1779. }
  1780. }
  1781. }
  1782. }
  1783. finally
  1784. {
  1785. this.model.endUpdate();
  1786. }
  1787. };
  1788. /**
  1789. * Overrides label orientation for collapsed swimlanes inside stack.
  1790. */
  1791. Graph.prototype.resizeParentStacks = function(parent, layout, dx, dy)
  1792. {
  1793. if (this.layoutManager != null && layout != null && layout.constructor == mxStackLayout && !layout.resizeLast)
  1794. {
  1795. this.model.beginUpdate();
  1796. try
  1797. {
  1798. var dir = layout.horizontal;
  1799. // Bubble resize up for all parent stack layouts with same orientation
  1800. while (parent != null && layout != null && layout.constructor == mxStackLayout &&
  1801. layout.horizontal == dir && !layout.resizeLast)
  1802. {
  1803. var pgeo = this.getCellGeometry(parent);
  1804. var pstate = this.view.getState(parent);
  1805. if (pstate != null && pgeo != null)
  1806. {
  1807. pgeo = pgeo.clone();
  1808. if (layout.horizontal)
  1809. {
  1810. pgeo.width += dx + Math.min(0, pstate.width / this.view.scale - pgeo.width);
  1811. }
  1812. else
  1813. {
  1814. pgeo.height += dy + Math.min(0, pstate.height / this.view.scale - pgeo.height);
  1815. }
  1816. this.model.setGeometry(parent, pgeo);
  1817. }
  1818. parent = this.model.getParent(parent);
  1819. layout = this.layoutManager.getLayout(parent);
  1820. }
  1821. }
  1822. finally
  1823. {
  1824. this.model.endUpdate();
  1825. }
  1826. }
  1827. };
  1828. /**
  1829. * Disables drill-down for non-swimlanes.
  1830. */
  1831. Graph.prototype.isContainer = function(cell)
  1832. {
  1833. var state = this.view.getState(cell);
  1834. var style = (state != null) ? state.style : this.getCellStyle(cell);
  1835. if (this.isSwimlane(cell))
  1836. {
  1837. return style['container'] != '0';
  1838. }
  1839. else
  1840. {
  1841. return style['container'] == '1';
  1842. }
  1843. };
  1844. /**
  1845. * Adds a connectable style.
  1846. */
  1847. Graph.prototype.isCellConnectable = function(cell)
  1848. {
  1849. var state = this.view.getState(cell);
  1850. var style = (state != null) ? state.style : this.getCellStyle(cell);
  1851. return (style['connectable'] != null) ? style['connectable'] != '0' :
  1852. mxGraph.prototype.isCellConnectable.apply(this, arguments);
  1853. };
  1854. /**
  1855. * Function: selectAll
  1856. *
  1857. * Selects all children of the given parent cell or the children of the
  1858. * default parent if no parent is specified. To select leaf vertices and/or
  1859. * edges use <selectCells>.
  1860. *
  1861. * Parameters:
  1862. *
  1863. * parent - Optional <mxCell> whose children should be selected.
  1864. * Default is <defaultParent>.
  1865. */
  1866. Graph.prototype.selectAll = function(parent)
  1867. {
  1868. parent = parent || this.getDefaultParent();
  1869. if (!this.isCellLocked(parent))
  1870. {
  1871. mxGraph.prototype.selectAll.apply(this, arguments);
  1872. }
  1873. };
  1874. /**
  1875. * Function: selectCells
  1876. *
  1877. * Selects all vertices and/or edges depending on the given boolean
  1878. * arguments recursively, starting at the given parent or the default
  1879. * parent if no parent is specified. Use <selectAll> to select all cells.
  1880. * For vertices, only cells with no children are selected.
  1881. *
  1882. * Parameters:
  1883. *
  1884. * vertices - Boolean indicating if vertices should be selected.
  1885. * edges - Boolean indicating if edges should be selected.
  1886. * parent - Optional <mxCell> that acts as the root of the recursion.
  1887. * Default is <defaultParent>.
  1888. */
  1889. Graph.prototype.selectCells = function(vertices, edges, parent)
  1890. {
  1891. parent = parent || this.getDefaultParent();
  1892. if (!this.isCellLocked(parent))
  1893. {
  1894. mxGraph.prototype.selectCells.apply(this, arguments);
  1895. }
  1896. };
  1897. /**
  1898. * Function: getSwimlaneAt
  1899. *
  1900. * Returns the bottom-most swimlane that intersects the given point (x, y)
  1901. * in the cell hierarchy that starts at the given parent.
  1902. *
  1903. * Parameters:
  1904. *
  1905. * x - X-coordinate of the location to be checked.
  1906. * y - Y-coordinate of the location to be checked.
  1907. * parent - <mxCell> that should be used as the root of the recursion.
  1908. * Default is <defaultParent>.
  1909. */
  1910. Graph.prototype.getSwimlaneAt = function (x, y, parent)
  1911. {
  1912. parent = parent || this.getDefaultParent();
  1913. if (!this.isCellLocked(parent))
  1914. {
  1915. return mxGraph.prototype.getSwimlaneAt.apply(this, arguments);
  1916. }
  1917. return null;
  1918. };
  1919. /**
  1920. * Disables folding for non-swimlanes.
  1921. */
  1922. Graph.prototype.isCellFoldable = function(cell)
  1923. {
  1924. var state = this.view.getState(cell);
  1925. var style = (state != null) ? state.style : this.getCellStyle(cell);
  1926. return this.foldingEnabled && !this.isCellLocked(cell) &&
  1927. ((this.isContainer(cell) && style['collapsible'] != '0') ||
  1928. (!this.isContainer(cell) && style['collapsible'] == '1'));
  1929. };
  1930. /**
  1931. * Stops all interactions and clears the selection.
  1932. */
  1933. Graph.prototype.reset = function()
  1934. {
  1935. if (this.isEditing())
  1936. {
  1937. this.stopEditing(true);
  1938. }
  1939. this.escape();
  1940. if (!this.isSelectionEmpty())
  1941. {
  1942. this.clearSelection();
  1943. }
  1944. };
  1945. /**
  1946. * Overridden to limit zoom to 1% - 16.000%.
  1947. */
  1948. Graph.prototype.zoom = function(factor, center)
  1949. {
  1950. factor = Math.max(0.01, Math.min(this.view.scale * factor, 160)) / this.view.scale;
  1951. mxGraph.prototype.zoom.apply(this, arguments);
  1952. };
  1953. /**
  1954. * Function: zoomIn
  1955. *
  1956. * Zooms into the graph by <zoomFactor>.
  1957. */
  1958. Graph.prototype.zoomIn = function()
  1959. {
  1960. // Switches to 1% zoom steps below 15%
  1961. if (this.view.scale < 0.15)
  1962. {
  1963. this.zoom((this.view.scale + 0.01) / this.view.scale);
  1964. }
  1965. else
  1966. {
  1967. // Uses to 5% zoom steps for better grid rendering in webkit
  1968. // and to avoid rounding errors for zoom steps
  1969. this.zoom((Math.round(this.view.scale * this.zoomFactor * 20) / 20) / this.view.scale);
  1970. }
  1971. };
  1972. /**
  1973. * Function: zoomOut
  1974. *
  1975. * Zooms out of the graph by <zoomFactor>.
  1976. */
  1977. Graph.prototype.zoomOut = function()
  1978. {
  1979. // Switches to 1% zoom steps below 15%
  1980. if (this.view.scale <= 0.15)
  1981. {
  1982. this.zoom((this.view.scale - 0.01) / this.view.scale);
  1983. }
  1984. else
  1985. {
  1986. // Uses to 5% zoom steps for better grid rendering in webkit
  1987. // and to avoid rounding errors for zoom steps
  1988. this.zoom((Math.round(this.view.scale * (1 / this.zoomFactor) * 20) / 20) / this.view.scale);
  1989. }
  1990. };
  1991. /**
  1992. * Overrides tooltips to show custom tooltip or metadata.
  1993. */
  1994. Graph.prototype.getTooltipForCell = function(cell)
  1995. {
  1996. var tip = '';
  1997. if (mxUtils.isNode(cell.value))
  1998. {
  1999. var tmp = cell.value.getAttribute('tooltip');
  2000. if (tmp != null)
  2001. {
  2002. if (tmp != null && this.isReplacePlaceholders(cell))
  2003. {
  2004. tmp = this.replacePlaceholders(cell, tmp);
  2005. }
  2006. tip = this.sanitizeHtml(tmp);
  2007. }
  2008. else
  2009. {
  2010. var ignored = ['label', 'tooltip', 'placeholders', 'placeholder'];
  2011. var attrs = cell.value.attributes;
  2012. var temp = [];
  2013. // Hides links in edit mode
  2014. if (this.isEnabled())
  2015. {
  2016. ignored.push('link');
  2017. }
  2018. for (var i = 0; i < attrs.length; i++)
  2019. {
  2020. if (mxUtils.indexOf(ignored, attrs[i].nodeName) < 0 && attrs[i].nodeValue.length > 0)
  2021. {
  2022. temp.push({name: attrs[i].nodeName, value: attrs[i].nodeValue});
  2023. }
  2024. }
  2025. // Sorts by name
  2026. temp.sort(function(a, b)
  2027. {
  2028. if (a.name < b.name)
  2029. {
  2030. return -1;
  2031. }
  2032. else if (a.name > b.name)
  2033. {
  2034. return 1;
  2035. }
  2036. else
  2037. {
  2038. return 0;
  2039. }
  2040. });
  2041. for (var i = 0; i < temp.length; i++)
  2042. {
  2043. tip += ((temp[i].name != 'link') ? temp[i].name + ':' : '') +
  2044. mxUtils.htmlEntities(temp[i].value) + '\n';
  2045. }
  2046. if (tip.length > 0)
  2047. {
  2048. tip = tip.substring(0, tip.length - 1);
  2049. }
  2050. }
  2051. }
  2052. return tip;
  2053. };
  2054. /**
  2055. * Turns the given string into an array.
  2056. */
  2057. Graph.prototype.stringToBytes = function(str)
  2058. {
  2059. var arr = new Array(str.length);
  2060. for (var i = 0; i < str.length; i++)
  2061. {
  2062. arr[i] = str.charCodeAt(i);
  2063. }
  2064. return arr;
  2065. };
  2066. /**
  2067. * Turns the given array into a string.
  2068. */
  2069. Graph.prototype.bytesToString = function(arr)
  2070. {
  2071. var result = new Array(arr.length);
  2072. for (var i = 0; i < arr.length; i++)
  2073. {
  2074. result[i] = String.fromCharCode(arr[i]);
  2075. }
  2076. return result.join('');
  2077. };
  2078. /**
  2079. * Returns a base64 encoded version of the compressed string.
  2080. */
  2081. Graph.prototype.compress = function(data)
  2082. {
  2083. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  2084. {
  2085. return data;
  2086. }
  2087. else
  2088. {
  2089. var tmp = this.bytesToString(pako.deflateRaw(encodeURIComponent(data)));
  2090. return (window.btoa) ? btoa(tmp) : Base64.encode(tmp, true);
  2091. }
  2092. };
  2093. /**
  2094. * Returns a decompressed version of the base64 encoded string.
  2095. */
  2096. Graph.prototype.decompress = function(data)
  2097. {
  2098. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  2099. {
  2100. return data;
  2101. }
  2102. else
  2103. {
  2104. var tmp = (window.atob) ? atob(data) : Base64.decode(data, true);
  2105. return this.zapGremlins(decodeURIComponent(
  2106. this.bytesToString(pako.inflateRaw(tmp))));
  2107. }
  2108. };
  2109. /**
  2110. * Removes all illegal control characters with ASCII code <32 except TAB, LF
  2111. * and CR.
  2112. */
  2113. Graph.prototype.zapGremlins = function(text)
  2114. {
  2115. var checked = [];
  2116. for (var i = 0; i < text.length; i++)
  2117. {
  2118. var code = text.charCodeAt(i);
  2119. // Removes all control chars except TAB, LF and CR
  2120. if (code >= 32 || code == 9 || code == 10 || code == 13)
  2121. {
  2122. checked.push(text.charAt(i));
  2123. }
  2124. }
  2125. return checked.join('');
  2126. };
  2127. /**
  2128. * Hover icons are used for hover, vertex handler and drag from sidebar.
  2129. */
  2130. HoverIcons = function(graph)
  2131. {
  2132. this.graph = graph;
  2133. this.init();
  2134. };
  2135. /**
  2136. * Up arrow.
  2137. */
  2138. HoverIcons.prototype.arrowSpacing = 6;
  2139. /**
  2140. * Delay to switch to another state for overlapping bbox. Default is 500ms.
  2141. */
  2142. HoverIcons.prototype.updateDelay = 500;
  2143. /**
  2144. * Delay to switch between states. Default is 140ms.
  2145. */
  2146. HoverIcons.prototype.activationDelay = 140;
  2147. /**
  2148. * Up arrow.
  2149. */
  2150. HoverIcons.prototype.currentState = null;
  2151. /**
  2152. * Up arrow.
  2153. */
  2154. HoverIcons.prototype.activeArrow = null;
  2155. /**
  2156. * Up arrow.
  2157. */
  2158. HoverIcons.prototype.inactiveOpacity = 15;
  2159. /**
  2160. * Whether to hide arrows that collide with vertices.
  2161. * LATER: Add keyboard override, touch support.
  2162. */
  2163. HoverIcons.prototype.checkCollisions = true;
  2164. /**
  2165. * Up arrow.
  2166. */
  2167. HoverIcons.prototype.triangleUp = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAOCAYAAAAxDQxDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6N0ZBN0E3M0U5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6N0ZBN0E3M0Y5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo3RkE3QTczQzk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo3RkE3QTczRDk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pj625P8AAACySURBVHjaYmRY956BROABxF+A+AgpmpjIsGQjEO8CYidaWeQHtYQNiDmBeAspljGRYMlqqCUwALPMg1oWhWCxBNmyjVCHUGQRyJKlOCyBATaoQ/zItSgciFcQsATdshBSLYqC+oSZhMTCBnVYFLEWgRQuItESGGCG6o0iZFECBZagW5aAyyKQxBwKLUG2bD4Qp6FblAyVoIYlyGAmzDIWKGMmA+0AyGw2RjIKVbIAQIABAFJRHSSk2rPoAAAAAElFTkSuQmCC' :
  2168. IMAGE_PATH + '/triangle-up.png', 26, 14);
  2169. /**
  2170. * Right arrow.
  2171. */
  2172. HoverIcons.prototype.triangleRight = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAaCAYAAACHD21cAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NThDQzc5RTU5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NThDQzc5RTY5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo1OENDNzlFMzk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo1OENDNzlFNDk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PrHdKTUAAADDSURBVHjanNTBCgFRFIfxMeTZyEKkiBSRxbwREZGiNFZKWSnvY6OUUv6n7ilZaL459XVXv6a5c+cWovQeaSZqFoGJwzpVozzQZq4GeSDCv7AYcJ9Cx0vVpdDxWrUpdLxVLQr/4jjDBpYDblDoeKdqFDpOHRP4jSsU2rzVg8KnqqpbDFFdXck7vlRTXciuOjqT72ioo07k5Nju9dSRnFVHB/J3GBqqPf0fx2pDbwBDK3Ln2MdN1CLraSiFNcn6JJ+PAAMAbnMl1tyDPD8AAAAASUVORK5CYII=':
  2173. IMAGE_PATH + '/triangle-right.png', 14, 26);
  2174. /**
  2175. * Down arrow.
  2176. */
  2177. HoverIcons.prototype.triangleDown = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAOCAYAAAAxDQxDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NThDQzc5RTk5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NThDQzc5RUE5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo1OENDNzlFNzk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo1OENDNzlFODk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pv9xyy0AAADESURBVHjaYmRY956BHoAJiHOA+D+NcRrIoilAnEVDz6QD8SwWKGc6EP8F4plUtiQRiBfAgg4GZkEl/lLBgr/IlqBbxACViKPQMgxLQIAFi8JlUHoREDOTYUkckhkMuHyEbFkEEP8i0ZJobJbgswgE1gBxKJGW/YI6bCW+fIQPbCLCsl9Qn6whlGEZiLDMH4i/47AklJAlxFoEAjuA2AfNMpglm4gtgogF+5As+wX15SZiNbOQmHxBlrkBMQ/Ul0QDgAADAC8qRII7g4RyAAAAAElFTkSuQmCC' :
  2178. IMAGE_PATH + '/triangle-down.png', 26, 14);
  2179. /**
  2180. * Left arrow.
  2181. */
  2182. HoverIcons.prototype.triangleLeft = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAaCAYAAACHD21cAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6N0ZBN0E3M0E5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6N0ZBN0E3M0I5NjZGMTFFNTg5NTRDNzQwMTgwNDlEQzQiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo1OENDNzlFQjk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo1OENDNzlFQzk2NkYxMUU1ODk1NEM3NDAxODA0OURDNCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pi1fu2cAAADXSURBVHjalNTRB8JQFMfxVROxPyl6iuipRJFS2kv/TU89lY0piyw9pP6r3iP6He7Ndd3de87haxMfd+1ua0TVOxLOCuVNIdqiHZ1I4AbtUUsC6fIO6jzhwoWB/hOCU5Tpy+PCCTq5kA+OfKgODlGJ2r7/YMMBqkLIhn0uMmEP3VGH+zQQ7KKnBGmY+O6eD77QGH2kkOYhxeZdJTzjYnsfb2jOwbHjt6s6ltJHTmNa+SuFNBe0rMOh9/GM1i7M+QIUKLVxzNy2XB0zyYomTqUr6jnqLfoJMADoxSMHt6pxsAAAAABJRU5ErkJggg==' :
  2183. IMAGE_PATH + '/triangle-left.png', 14, 26);
  2184. /**
  2185. * Round target.
  2186. */
  2187. HoverIcons.prototype.roundDrop = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RTgxRjYzRTU1MDRFMTFFNEExQ0VFNDQwNDhGNzg2RDkiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RTgxRjYzRTY1MDRFMTFFNEExQ0VFNDQwNDhGNzg2RDkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpFODFGNjNFMzUwNEUxMUU0QTFDRUU0NDA0OEY3ODZEOSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpFODFGNjNFNDUwNEUxMUU0QTFDRUU0NDA0OEY3ODZEOSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PuJ657wAAAE0SURBVHjaYvz//z8DPQATA50AC4zBuP4DLjXaQOwMxJZArAfE8lDxh0B8CYiPA/FeIL6KTfP/QAFUi7AABSBOAOJoIFbBIq8FxRFAfAeIlwLxAiB+gNdHaMABiIuB2IfIkAE5pB6IjYG4F4gPEBNHIEtaSLAEGfhA9ToQskgB6hNrCuLdGmqGAj6LEsj0CTafJeCySBsa8dQC0VAzMSxyxpG6yAUqUDMxLLKkQT61xGaRHg0s0sNmkTwNLJKne1mHbNFDGpj/EJtFl2hg0SVsFh2ngUXHsVm0F1oKUwvcgZqJYdFVaFFPLbAUuY5CT3Wg+mQLFSzZAjULZ6H6AFqfHKXAkqNQMx4Qqo9AlVYNmT7bAtV7gNga9gDURWfxVOXoEY+3KmeENbdo3ThhHHbtOoAAAwDmEETshQ0fBAAAAABJRU5ErkJggg==' :
  2188. IMAGE_PATH + '/round-drop.png', 26, 26);
  2189. /**
  2190. * Refresh target.
  2191. */
  2192. HoverIcons.prototype.refreshTarget = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAmCAYAAACoPemuAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDQxNERDRTU1QjY1MTFFNDkzNTRFQTVEMTdGMTdBQjciIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDQxNERDRTY1QjY1MTFFNDkzNTRFQTVEMTdGMTdBQjciPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0NDE0RENFMzVCNjUxMUU0OTM1NEVBNUQxN0YxN0FCNyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0NDE0RENFNDVCNjUxMUU0OTM1NEVBNUQxN0YxN0FCNyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsvuX50AAANaSURBVHja7FjRZ1tRGD9ZJ1NCyIQSwrivI4Q8hCpjlFDyFEoYfSp9Ko1QWnmo0If+BSXkIfo0QirTMUpeGo2EPfWllFYjZMLKLDJn53d3biU337m5J223bPbxk5t7v+/c3/2+73znO8fDOWezKM/YjMpz68Lj8ejY+QTeCCwLxOS9qPxtyN+6wAeBTwJ31CCO0cJDjXBGBN4LfIepSwykTUT1bgpuib0SONIgo8KRHOtRiCFcvUcgZeGrHPNBxLIyFPyRgTGz0xLbegJCdmzpElue5KlAIMDX19d5uVzm5+fnfDAYmMA17uEZdOx2Yvb/sHlu2S0xwymn5ufneTab5b1ej08S6EAXNrDd2dnhiUTim21MvMtwQ6yiIrWwsMDPzs64rsBmf3/fvM7n89TYlUnEllSkQqEQv7q64g+Vk5MTVXosORErU0Zer5f0FEIlw2N6MxwO82QyaXql2+2SxDqdjopYWUUsqEp45IldqtWq6UWVh/1+P7+8vCTJ4QMUJSRIEXuneoH96w8PDyeWAnhSJfCqwm6NIlaklFdXV0cGhRcQ2mlJQXK5nMq2YPEZbnteU1U2lUqN/D84OGD9fl+5fgnSrFarsUwmw0qlEru4uBjTicViTk3Cr27HSnxR+Doyz0ZE1CAWiUTusbu7y9rttlZv5fP5WDQavYfIMba4uEipfhF8XtqJoZXx/uH+sC/4vPg7OljZZQbsCmLtYzc3N6zRaJhotVrmfx0xDINtbm6athYUeXpHdbBNaqZUKpWxWXV7e2vex+xaWVnhc3NzjrPUXgexyCt0m67LBV7uJMITjqRE4o8tZeg8FPpFitgapYxiOC0poFgsji1jKNo6BZZckrAGUtJsNk1vqAihCBcKhTE7hNWhqw2qFnGy5UFOUYJVIJ1OjzSE+BCEilon0URavRmBqnbbQ00AXbm+vnZc9O1tj72OnQoc2+cwygRkb2+P1et17ZoEm3g87lRmjgWZ00kbXkNuse6/Bu2wlegIxfb2tuvWGroO4bO2c4bbzUh60mxDXm1sbJhhxkQYnhS4h2fUZoRAWnf7lv8N27f8P7Xhnekjgpk+VKGOoQbsiY+hhhtF3YO7twIJ+ULvUGv+GQ2fQEvWxI/THNx5/p/BaspPAQYAqStgiSQwCDoAAAAASUVORK5CYII=' :
  2193. IMAGE_PATH + '/refresh.png', 38, 38);
  2194. /**
  2195. *
  2196. */
  2197. HoverIcons.prototype.init = function()
  2198. {
  2199. this.arrowUp = this.createArrow(this.triangleUp, mxResources.get('plusTooltip'));
  2200. this.arrowRight = this.createArrow(this.triangleRight, mxResources.get('plusTooltip'));
  2201. this.arrowDown = this.createArrow(this.triangleDown, mxResources.get('plusTooltip'));
  2202. this.arrowLeft = this.createArrow(this.triangleLeft, mxResources.get('plusTooltip'));
  2203. this.elts = [this.arrowUp, this.arrowRight, this.arrowDown, this.arrowLeft];
  2204. this.repaintHandler = mxUtils.bind(this, function()
  2205. {
  2206. this.repaint();
  2207. });
  2208. this.graph.selectionModel.addListener(mxEvent.CHANGE, this.repaintHandler);
  2209. this.graph.model.addListener(mxEvent.CHANGE, this.repaintHandler);
  2210. this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.repaintHandler);
  2211. this.graph.view.addListener(mxEvent.TRANSLATE, this.repaintHandler);
  2212. this.graph.view.addListener(mxEvent.SCALE, this.repaintHandler);
  2213. this.graph.view.addListener(mxEvent.DOWN, this.repaintHandler);
  2214. this.graph.view.addListener(mxEvent.UP, this.repaintHandler);
  2215. this.graph.addListener(mxEvent.ROOT, this.repaintHandler);
  2216. // Resets the mouse point on escape
  2217. this.graph.addListener(mxEvent.ESCAPE, mxUtils.bind(this, function()
  2218. {
  2219. this.mouseDownPoint = null;
  2220. }));
  2221. // Removes hover icons if mouse leaves the container
  2222. mxEvent.addListener(this.graph.container, 'mouseleave', mxUtils.bind(this, function(evt)
  2223. {
  2224. // Workaround for IE11 firing mouseleave for touch in diagram
  2225. if (evt.relatedTarget != null && mxEvent.getSource(evt) == this.graph.container)
  2226. {
  2227. this.setDisplay('none');
  2228. }
  2229. }));
  2230. // Resets current state after update of selection state for touch events
  2231. var graphClick = this.graph.click;
  2232. this.graph.click = mxUtils.bind(this, function(me)
  2233. {
  2234. graphClick.apply(this.graph, arguments);
  2235. if (this.currentState != null && !this.graph.isCellSelected(this.currentState.cell) &&
  2236. mxEvent.isTouchEvent(me.getEvent()) && !this.graph.model.isVertex(me.getCell()))
  2237. {
  2238. this.reset();
  2239. }
  2240. });
  2241. // Checks if connection handler was active in mouse move
  2242. // as workaround for possible double connection inserted
  2243. var connectionHandlerActive = false;
  2244. // Implements a listener for hover and click handling
  2245. this.graph.addMouseListener(
  2246. {
  2247. mouseDown: mxUtils.bind(this, function(sender, me)
  2248. {
  2249. connectionHandlerActive = false;
  2250. var evt = me.getEvent();
  2251. if (this.isResetEvent(evt))
  2252. {
  2253. this.reset();
  2254. }
  2255. else if (!this.isActive())
  2256. {
  2257. var state = this.getState(me.getState());
  2258. if (state != null || !mxEvent.isTouchEvent(evt))
  2259. {
  2260. this.update(state);
  2261. }
  2262. }
  2263. this.setDisplay('none');
  2264. }),
  2265. mouseMove: mxUtils.bind(this, function(sender, me)
  2266. {
  2267. var evt = me.getEvent();
  2268. if (this.isResetEvent(evt))
  2269. {
  2270. this.reset();
  2271. }
  2272. else if (!this.graph.isMouseDown && !mxEvent.isTouchEvent(evt))
  2273. {
  2274. this.update(this.getState(me.getState()), me.getGraphX(), me.getGraphY());
  2275. }
  2276. if (this.graph.connectionHandler != null && this.graph.connectionHandler.shape != null)
  2277. {
  2278. connectionHandlerActive = true;
  2279. }
  2280. }),
  2281. mouseUp: mxUtils.bind(this, function(sender, me)
  2282. {
  2283. var evt = me.getEvent();
  2284. if (this.isResetEvent(evt))
  2285. {
  2286. this.reset();
  2287. }
  2288. else if (this.isActive() && this.mouseDownPoint != null &&
  2289. Math.abs(me.getGraphX() - this.mouseDownPoint.x) < this.graph.tolerance &&
  2290. Math.abs(me.getGraphY() - this.mouseDownPoint.y) < this.graph.tolerance)
  2291. {
  2292. // Executes click event on highlighted arrow
  2293. if (!connectionHandlerActive)
  2294. {
  2295. this.click(this.currentState, this.getDirection(), me);
  2296. }
  2297. }
  2298. else if (this.isActive())
  2299. {
  2300. // Selects target vertex after drag and clone if not only new edge was inserted
  2301. if (this.graph.getSelectionCount() != 1 || !this.graph.model.isEdge(this.graph.getSelectionCell()))
  2302. {
  2303. this.update(this.getState(this.graph.view.getState(this.graph.getCellAt(me.getGraphX(), me.getGraphY()))));
  2304. }
  2305. else
  2306. {
  2307. this.reset();
  2308. }
  2309. }
  2310. else if (mxEvent.isTouchEvent(evt) || (this.bbox != null && mxUtils.contains(this.bbox, me.getGraphX(), me.getGraphY())))
  2311. {
  2312. // Shows existing hover icons if inside bounding box
  2313. this.setDisplay('');
  2314. this.repaint();
  2315. }
  2316. else if (!mxEvent.isTouchEvent(evt))
  2317. {
  2318. this.reset();
  2319. }
  2320. connectionHandlerActive = false;
  2321. this.resetActiveArrow();
  2322. })
  2323. });
  2324. };
  2325. /**
  2326. *
  2327. */
  2328. HoverIcons.prototype.isResetEvent = function(evt, allowShift)
  2329. {
  2330. return mxEvent.isAltDown(evt) || (this.activeArrow == null && mxEvent.isShiftDown(evt)) ||
  2331. mxEvent.isMetaDown(evt) || (mxEvent.isPopupTrigger(evt) && !mxEvent.isControlDown(evt));
  2332. };
  2333. /**
  2334. *
  2335. */
  2336. HoverIcons.prototype.createArrow = function(img, tooltip)
  2337. {
  2338. var arrow = null;
  2339. if (mxClient.IS_IE && !mxClient.IS_SVG)
  2340. {
  2341. // Workaround for PNG images in IE6
  2342. if (mxClient.IS_IE6 && document.compatMode != 'CSS1Compat')
  2343. {
  2344. arrow = document.createElement(mxClient.VML_PREFIX + ':image');
  2345. arrow.setAttribute('src', img.src);
  2346. arrow.style.borderStyle = 'none';
  2347. }
  2348. else
  2349. {
  2350. arrow = document.createElement('div');
  2351. arrow.style.backgroundImage = 'url(' + img.src + ')';
  2352. arrow.style.backgroundPosition = 'center';
  2353. arrow.style.backgroundRepeat = 'no-repeat';
  2354. }
  2355. arrow.style.width = (img.width + 4) + 'px';
  2356. arrow.style.height = (img.height + 4) + 'px';
  2357. arrow.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  2358. }
  2359. else
  2360. {
  2361. arrow = mxUtils.createImage(img.src);
  2362. arrow.style.width = img.width + 'px';
  2363. arrow.style.height = img.height + 'px';
  2364. }
  2365. if (tooltip != null)
  2366. {
  2367. arrow.setAttribute('title', tooltip);
  2368. }
  2369. arrow.style.position = 'absolute';
  2370. arrow.style.cursor = 'crosshair';
  2371. mxEvent.addGestureListeners(arrow, mxUtils.bind(this, function(evt)
  2372. {
  2373. if (this.currentState != null && !this.isResetEvent(evt))
  2374. {
  2375. this.mouseDownPoint = mxUtils.convertPoint(this.graph.container,
  2376. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2377. this.drag(evt, this.mouseDownPoint.x, this.mouseDownPoint.y);
  2378. this.activeArrow = arrow;
  2379. this.setDisplay('none');
  2380. mxEvent.consume(evt);
  2381. }
  2382. }));
  2383. // Captures mouse events as events on graph
  2384. mxEvent.redirectMouseEvents(arrow, this.graph, this.currentState);
  2385. mxEvent.addListener(arrow, 'mouseenter', mxUtils.bind(this, function(evt)
  2386. {
  2387. // Workaround for Firefox firing mouseenter on touchend
  2388. if (mxEvent.isMouseEvent(evt))
  2389. {
  2390. if (this.activeArrow != null && this.activeArrow != arrow)
  2391. {
  2392. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  2393. }
  2394. this.graph.connectionHandler.constraintHandler.reset();
  2395. mxUtils.setOpacity(arrow, 100);
  2396. this.activeArrow = arrow;
  2397. }
  2398. }));
  2399. mxEvent.addListener(arrow, 'mouseleave', mxUtils.bind(this, function(evt)
  2400. {
  2401. // Workaround for IE11 firing this event on touch
  2402. if (!this.graph.isMouseDown)
  2403. {
  2404. this.resetActiveArrow();
  2405. }
  2406. }));
  2407. return arrow;
  2408. };
  2409. /**
  2410. *
  2411. */
  2412. HoverIcons.prototype.resetActiveArrow = function()
  2413. {
  2414. if (this.activeArrow != null)
  2415. {
  2416. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  2417. this.activeArrow = null;
  2418. }
  2419. };
  2420. /**
  2421. *
  2422. */
  2423. HoverIcons.prototype.getDirection = function()
  2424. {
  2425. var dir = mxConstants.DIRECTION_EAST;
  2426. if (this.activeArrow == this.arrowUp)
  2427. {
  2428. dir = mxConstants.DIRECTION_NORTH;
  2429. }
  2430. else if (this.activeArrow == this.arrowDown)
  2431. {
  2432. dir = mxConstants.DIRECTION_SOUTH;
  2433. }
  2434. else if (this.activeArrow == this.arrowLeft)
  2435. {
  2436. dir = mxConstants.DIRECTION_WEST;
  2437. }
  2438. return dir;
  2439. };
  2440. /**
  2441. *
  2442. */
  2443. HoverIcons.prototype.visitNodes = function(visitor)
  2444. {
  2445. for (var i = 0; i < this.elts.length; i++)
  2446. {
  2447. if (this.elts[i] != null)
  2448. {
  2449. visitor(this.elts[i]);
  2450. }
  2451. }
  2452. };
  2453. /**
  2454. *
  2455. */
  2456. HoverIcons.prototype.removeNodes = function()
  2457. {
  2458. this.visitNodes(function(elt)
  2459. {
  2460. if (elt.parentNode != null)
  2461. {
  2462. elt.parentNode.removeChild(elt);
  2463. }
  2464. });
  2465. };
  2466. /**
  2467. *
  2468. */
  2469. HoverIcons.prototype.setDisplay = function(display)
  2470. {
  2471. this.visitNodes(function(elt)
  2472. {
  2473. elt.style.display = display;
  2474. });
  2475. };
  2476. /**
  2477. *
  2478. */
  2479. HoverIcons.prototype.isActive = function()
  2480. {
  2481. return this.activeArrow != null && this.currentState != null;
  2482. };
  2483. /**
  2484. *
  2485. */
  2486. HoverIcons.prototype.drag = function(evt, x, y)
  2487. {
  2488. this.graph.popupMenuHandler.hideMenu();
  2489. this.graph.stopEditing(false);
  2490. // Checks if state was removed in call to stopEditing above
  2491. if (this.currentState != null)
  2492. {
  2493. this.graph.connectionHandler.start(this.currentState, x, y);
  2494. this.graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  2495. this.graph.isMouseDown = true;
  2496. // Hides handles for selection cell
  2497. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  2498. if (handler != null)
  2499. {
  2500. handler.setHandlesVisible(false);
  2501. }
  2502. // Uses elbow edges with vertical or horizontal direction
  2503. // var direction = this.getDirection();
  2504. // var elbowValue = (direction == mxConstants.DIRECTION_NORTH || direction == mxConstants.DIRECTION_SOUTH) ? 'vertical' : 'horizontal';
  2505. //
  2506. // var es = this.graph.connectionHandler.edgeState;
  2507. // es.style['edgeStyle'] = 'elbowEdgeStyle';
  2508. // es.style['elbow'] = elbowValue;
  2509. // es.cell.style = mxUtils.setStyle(es.cell.style, 'edgeStyle', es.style['edgeStyle']);
  2510. // es.cell.style = mxUtils.setStyle(es.cell.style, 'elbow', es.style['elbow']);
  2511. }
  2512. };
  2513. /**
  2514. *
  2515. */
  2516. HoverIcons.prototype.getStateAt = function(state, x, y)
  2517. {
  2518. return this.graph.view.getState(this.graph.getCellAt(x, y));
  2519. };
  2520. /**
  2521. *
  2522. */
  2523. HoverIcons.prototype.click = function(state, dir, me)
  2524. {
  2525. var evt = me.getEvent();
  2526. var x = me.getGraphX();
  2527. var y = me.getGraphY();
  2528. var tmp = this.getStateAt(state, x, y);
  2529. if (tmp != null && this.graph.model.isEdge(tmp.cell) && !mxEvent.isControlDown(evt) &&
  2530. (tmp.getVisibleTerminalState(true) == state || tmp.getVisibleTerminalState(false) == state))
  2531. {
  2532. this.graph.setSelectionCell(tmp.cell);
  2533. this.reset();
  2534. }
  2535. else if (state != null)
  2536. {
  2537. var cells = this.graph.connectVertex(state.cell, dir, this.graph.defaultEdgeLength, evt);
  2538. this.graph.selectCellsForConnectVertex(cells, evt, this);
  2539. // Selects only target vertex if one exists
  2540. if (cells.length == 2 && this.graph.model.isVertex(cells[1]))
  2541. {
  2542. this.graph.setSelectionCell(cells[1]);
  2543. // Adds hover icons to new target vertex for touch devices
  2544. if (mxEvent.isTouchEvent(evt))
  2545. {
  2546. this.update(this.getState(this.graph.view.getState(cells[1])));
  2547. }
  2548. else
  2549. {
  2550. // Hides hover icons after click with mouse
  2551. this.reset();
  2552. }
  2553. this.graph.scrollCellToVisible(cells[1]);
  2554. }
  2555. else
  2556. {
  2557. this.graph.setSelectionCells(cells);
  2558. }
  2559. }
  2560. me.consume();
  2561. };
  2562. /**
  2563. *
  2564. */
  2565. HoverIcons.prototype.reset = function(clearTimeout)
  2566. {
  2567. clearTimeout = (clearTimeout == null) ? true : clearTimeout;
  2568. if (clearTimeout && this.updateThread != null)
  2569. {
  2570. window.clearTimeout(this.updateThread);
  2571. }
  2572. this.mouseDownPoint = null;
  2573. this.currentState = null;
  2574. this.activeArrow = null;
  2575. this.removeNodes();
  2576. this.bbox = null;
  2577. };
  2578. /**
  2579. *
  2580. */
  2581. HoverIcons.prototype.repaint = function()
  2582. {
  2583. this.bbox = null;
  2584. if (this.currentState != null)
  2585. {
  2586. // Checks if cell was deleted
  2587. this.currentState = this.getState(this.currentState);
  2588. // Cell was deleted
  2589. if (this.currentState != null &&
  2590. this.graph.model.isVertex(this.currentState.cell) &&
  2591. this.graph.isCellConnectable(this.currentState.cell))
  2592. {
  2593. var bds = mxRectangle.fromRectangle(this.currentState);
  2594. // Uses outer bounding box to take rotation into account
  2595. if (this.currentState.shape != null && this.currentState.shape.boundingBox != null)
  2596. {
  2597. bds = mxRectangle.fromRectangle(this.currentState.shape.boundingBox);
  2598. }
  2599. bds.grow(this.graph.tolerance);
  2600. bds.grow(this.arrowSpacing);
  2601. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  2602. if (handler != null)
  2603. {
  2604. bds.x -= handler.horizontalOffset / 2;
  2605. bds.y -= handler.verticalOffset / 2;
  2606. bds.width += handler.horizontalOffset;
  2607. bds.height += handler.verticalOffset;
  2608. // Adds bounding box of rotation handle to avoid overlap
  2609. if (handler.rotationShape != null && handler.rotationShape.node != null &&
  2610. handler.rotationShape.node.style.visibility != 'hidden' &&
  2611. handler.rotationShape.node.style.display != 'none' &&
  2612. handler.rotationShape.boundingBox != null)
  2613. {
  2614. bds.add(handler.rotationShape.boundingBox);
  2615. }
  2616. }
  2617. this.arrowUp.style.left = Math.round(this.currentState.getCenterX() - this.triangleUp.width / 2) + 'px';
  2618. this.arrowUp.style.top = Math.round(bds.y - this.triangleUp.height) + 'px';
  2619. mxUtils.setOpacity(this.arrowUp, this.inactiveOpacity);
  2620. this.arrowRight.style.left = Math.round(bds.x + bds.width) + 'px';
  2621. this.arrowRight.style.top = Math.round(this.currentState.getCenterY() - this.triangleRight.height / 2) + 'px';
  2622. mxUtils.setOpacity(this.arrowRight, this.inactiveOpacity);
  2623. this.arrowDown.style.left = this.arrowUp.style.left
  2624. this.arrowDown.style.top = Math.round(bds.y + bds.height) + 'px';
  2625. mxUtils.setOpacity(this.arrowDown, this.inactiveOpacity);
  2626. this.arrowLeft.style.left = Math.round(bds.x - this.triangleLeft.width) + 'px';
  2627. this.arrowLeft.style.top = this.arrowRight.style.top;
  2628. mxUtils.setOpacity(this.arrowLeft, this.inactiveOpacity);
  2629. if (this.checkCollisions)
  2630. {
  2631. var right = this.graph.getCellAt(bds.x + bds.width +
  2632. this.triangleRight.width / 2, this.currentState.getCenterY());
  2633. var left = this.graph.getCellAt(bds.x - this.triangleLeft.width / 2, this.currentState.getCenterY());
  2634. var top = this.graph.getCellAt(this.currentState.getCenterX(), bds.y - this.triangleUp.height / 2);
  2635. var bottom = this.graph.getCellAt(this.currentState.getCenterX(), bds.y + bds.height + this.triangleDown.height / 2);
  2636. // Shows hover icons large cell is behind all directions of current cell
  2637. if (right != null && right == left && left == top && top == bottom)
  2638. {
  2639. right = null;
  2640. left = null;
  2641. top = null;
  2642. bottom = null;
  2643. }
  2644. var currentGeo = this.graph.getCellGeometry(this.currentState.cell);
  2645. var checkCollision = mxUtils.bind(this, function(cell, arrow)
  2646. {
  2647. var geo = this.graph.model.isVertex(cell) && this.graph.getCellGeometry(cell);
  2648. // Ignores collision if vertex is more than 3 times the size of this vertex
  2649. if (cell != null && !this.graph.model.isAncestor(cell, this.currentState.cell) &&
  2650. (geo == null || currentGeo == null || (geo.height < 6 * currentGeo.height &&
  2651. geo.width < 6 * currentGeo.width)))
  2652. {
  2653. arrow.style.visibility = 'hidden';
  2654. }
  2655. else
  2656. {
  2657. arrow.style.visibility = 'visible';
  2658. }
  2659. });
  2660. checkCollision(right, this.arrowRight);
  2661. checkCollision(left, this.arrowLeft);
  2662. checkCollision(top, this.arrowUp);
  2663. checkCollision(bottom, this.arrowDown);
  2664. }
  2665. else
  2666. {
  2667. this.arrowLeft.style.visibility = 'visible';
  2668. this.arrowRight.style.visibility = 'visible';
  2669. this.arrowUp.style.visibility = 'visible';
  2670. this.arrowDown.style.visibility = 'visible';
  2671. }
  2672. if (this.graph.tooltipHandler.isEnabled())
  2673. {
  2674. this.arrowLeft.setAttribute('title', mxResources.get('plusTooltip'));
  2675. this.arrowRight.setAttribute('title', mxResources.get('plusTooltip'));
  2676. this.arrowUp.setAttribute('title', mxResources.get('plusTooltip'));
  2677. this.arrowDown.setAttribute('title', mxResources.get('plusTooltip'));
  2678. }
  2679. else
  2680. {
  2681. this.arrowLeft.removeAttribute('title');
  2682. this.arrowRight.removeAttribute('title');
  2683. this.arrowUp.removeAttribute('title');
  2684. this.arrowDown.removeAttribute('title');
  2685. }
  2686. }
  2687. else
  2688. {
  2689. this.reset();
  2690. }
  2691. // Updates bounding box
  2692. if (this.currentState != null)
  2693. {
  2694. this.bbox = this.computeBoundingBox();
  2695. // Adds tolerance for hover
  2696. if (this.bbox != null)
  2697. {
  2698. this.bbox.grow(10);
  2699. }
  2700. }
  2701. }
  2702. };
  2703. /**
  2704. *
  2705. */
  2706. HoverIcons.prototype.computeBoundingBox = function()
  2707. {
  2708. var bbox = (!this.graph.model.isEdge(this.currentState.cell)) ? mxRectangle.fromRectangle(this.currentState) : null;
  2709. this.visitNodes(function(elt)
  2710. {
  2711. if (elt.parentNode != null)
  2712. {
  2713. var tmp = new mxRectangle(elt.offsetLeft, elt.offsetTop, elt.offsetWidth, elt.offsetHeight);
  2714. if (bbox == null)
  2715. {
  2716. bbox = tmp;
  2717. }
  2718. else
  2719. {
  2720. bbox.add(tmp);
  2721. }
  2722. }
  2723. });
  2724. return bbox;
  2725. };
  2726. /**
  2727. *
  2728. */
  2729. HoverIcons.prototype.getState = function(state)
  2730. {
  2731. if (state != null)
  2732. {
  2733. var cell = state.cell;
  2734. // Uses connectable parent vertex if child is not connectable
  2735. if (this.graph.getModel().isVertex(cell) && !this.graph.isCellConnectable(cell))
  2736. {
  2737. var parent = this.graph.getModel().getParent(cell);
  2738. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  2739. {
  2740. cell = parent;
  2741. }
  2742. }
  2743. // Ignores locked cells and edges
  2744. if (this.graph.isCellLocked(cell) || this.graph.model.isEdge(cell))
  2745. {
  2746. cell = null;
  2747. }
  2748. state = this.graph.view.getState(cell);
  2749. }
  2750. return state;
  2751. };
  2752. /**
  2753. *
  2754. */
  2755. HoverIcons.prototype.update = function(state, x, y)
  2756. {
  2757. if (!this.graph.connectionArrowsEnabled)
  2758. {
  2759. this.reset();
  2760. }
  2761. else
  2762. {
  2763. var timeOnTarget = null;
  2764. // Time on target
  2765. if (this.prev != state || this.isActive())
  2766. {
  2767. this.startTime = new Date().getTime();
  2768. this.prev = state;
  2769. timeOnTarget = 0;
  2770. if (this.updateThread != null)
  2771. {
  2772. window.clearTimeout(this.updateThread);
  2773. }
  2774. if (state != null)
  2775. {
  2776. // Starts timer to update current state with no mouse events
  2777. this.updateThread = window.setTimeout(mxUtils.bind(this, function()
  2778. {
  2779. if (!this.isActive() && !this.graph.isMouseDown &&
  2780. !this.graph.panningHandler.isActive())
  2781. {
  2782. this.prev = state;
  2783. this.update(state, x, y);
  2784. }
  2785. }), this.updateDelay + 10);
  2786. }
  2787. }
  2788. else if (this.startTime != null)
  2789. {
  2790. timeOnTarget = new Date().getTime() - this.startTime;
  2791. }
  2792. this.setDisplay('');
  2793. if (this.currentState != null && this.currentState != state && timeOnTarget < this.activationDelay &&
  2794. this.bbox != null && !mxUtils.contains(this.bbox, x, y))
  2795. {
  2796. this.reset(false);
  2797. }
  2798. else if (this.currentState != null || timeOnTarget > this.activationDelay)
  2799. {
  2800. if (this.currentState != state && ((timeOnTarget > this.updateDelay && state != null) ||
  2801. this.bbox == null || x == null || y == null || !mxUtils.contains(this.bbox, x, y)))
  2802. {
  2803. if (state != null && this.graph.isEnabled())
  2804. {
  2805. this.removeNodes();
  2806. this.setCurrentState(state);
  2807. this.repaint();
  2808. // Resets connection points on other focused cells
  2809. if (this.graph.connectionHandler.constraintHandler.currentFocus != state)
  2810. {
  2811. this.graph.connectionHandler.constraintHandler.reset();
  2812. }
  2813. }
  2814. else
  2815. {
  2816. this.reset();
  2817. }
  2818. }
  2819. }
  2820. }
  2821. };
  2822. /**
  2823. *
  2824. */
  2825. HoverIcons.prototype.setCurrentState = function(state)
  2826. {
  2827. if (state.style['portConstraint'] != 'eastwest')
  2828. {
  2829. this.graph.container.appendChild(this.arrowUp);
  2830. this.graph.container.appendChild(this.arrowDown);
  2831. }
  2832. this.graph.container.appendChild(this.arrowRight);
  2833. this.graph.container.appendChild(this.arrowLeft);
  2834. this.currentState = state;
  2835. };
  2836. (function()
  2837. {
  2838. /**
  2839. * Reset the list of processed edges.
  2840. */
  2841. var mxGraphViewResetValidationState = mxGraphView.prototype.resetValidationState;
  2842. mxGraphView.prototype.resetValidationState = function()
  2843. {
  2844. mxGraphViewResetValidationState.apply(this, arguments);
  2845. this.validEdges = [];
  2846. };
  2847. /**
  2848. * Updates jumps for valid edges and repaints if needed.
  2849. */
  2850. var mxGraphViewValidateCellState = mxGraphView.prototype.validateCellState;
  2851. mxGraphView.prototype.validateCellState = function(cell, recurse)
  2852. {
  2853. var state = this.getState(cell);
  2854. // Forces repaint if jumps change on a valid edge
  2855. if (state != null && this.graph.model.isEdge(state.cell) &&
  2856. state.style != null && state.style[mxConstants.STYLE_CURVED] != 1 &&
  2857. !state.invalid && this.updateLineJumps(state))
  2858. {
  2859. this.graph.cellRenderer.redraw(state, false, this.isRendering());
  2860. }
  2861. state = mxGraphViewValidateCellState.apply(this, arguments);
  2862. // Adds to the list of edges that may intersect with later edges
  2863. if (state != null && this.graph.model.isEdge(state.cell) &&
  2864. state.style[mxConstants.STYLE_CURVED] != 1)
  2865. {
  2866. // LATER: Reuse jumps for valid edges
  2867. this.validEdges.push(state);
  2868. }
  2869. return state;
  2870. };
  2871. /**
  2872. * Forces repaint if routed points have changed.
  2873. */
  2874. var mxCellRendererIsShapeInvalid = mxCellRenderer.prototype.isShapeInvalid;
  2875. mxCellRenderer.prototype.isShapeInvalid = function(state, shape)
  2876. {
  2877. return mxCellRendererIsShapeInvalid.apply(this, arguments) ||
  2878. (state.routedPoints != null && shape.routedPoints != null &&
  2879. !mxUtils.equalPoints(shape.routedPoints, state.routedPoints))
  2880. };
  2881. /**
  2882. * Updates jumps for invalid edges.
  2883. */
  2884. var mxGraphViewUpdateCellState = mxGraphView.prototype.updateCellState;
  2885. mxGraphView.prototype.updateCellState = function(state)
  2886. {
  2887. mxGraphViewUpdateCellState.apply(this, arguments);
  2888. // Updates jumps on invalid edge before repaint
  2889. if (this.graph.model.isEdge(state.cell) &&
  2890. state.style[mxConstants.STYLE_CURVED] != 1)
  2891. {
  2892. this.updateLineJumps(state);
  2893. }
  2894. };
  2895. /**
  2896. * Updates the jumps between given state and processed edges.
  2897. */
  2898. mxGraphView.prototype.updateLineJumps = function(state)
  2899. {
  2900. var pts = state.absolutePoints;
  2901. if (Graph.lineJumpsEnabled)
  2902. {
  2903. var changed = state.routedPoints != null;
  2904. var actual = null;
  2905. if (pts != null && this.validEdges != null &&
  2906. mxUtils.getValue(state.style, 'jumpStyle', 'none') !== 'none')
  2907. {
  2908. var thresh = 0.5 * this.scale;
  2909. changed = false;
  2910. actual = [];
  2911. // Type 0 means normal waypoint, 1 means jump
  2912. function addPoint(type, x, y)
  2913. {
  2914. var rpt = new mxPoint(x, y);
  2915. rpt.type = type;
  2916. actual.push(rpt);
  2917. var curr = (state.routedPoints != null) ? state.routedPoints[actual.length - 1] : null;
  2918. return curr == null || curr.type != type || curr.x != x || curr.y != y;
  2919. };
  2920. for (var i = 0; i < pts.length - 1; i++)
  2921. {
  2922. var p1 = pts[i + 1];
  2923. var p0 = pts[i];
  2924. var list = [];
  2925. // Ignores waypoint on straight segments
  2926. if (i < pts.length - 2)
  2927. {
  2928. var pn = pts[i + 2];
  2929. if (mxUtils.ptSegDistSq(p0.x, p0.y, pn.x, pn.y,
  2930. p1.x, p1.y) < 1 * this.scale * this.scale)
  2931. {
  2932. p1 = pn;
  2933. i++;
  2934. }
  2935. }
  2936. changed = addPoint(0, p0.x, p0.y) || changed;
  2937. // Processes all previous edges
  2938. for (var e = 0; e < this.validEdges.length; e++)
  2939. {
  2940. var state2 = this.validEdges[e];
  2941. var pts2 = state2.absolutePoints;
  2942. var added = false;
  2943. if (pts2 != null)
  2944. {
  2945. // Compares each segment of the edge with the current segment
  2946. for (var j = 0; j < pts2.length - 1; j++)
  2947. {
  2948. var p2 = pts2[j];
  2949. var p3 = pts2[j + 1];
  2950. var pt = mxUtils.intersection(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
  2951. // Handles intersection between two segments
  2952. if (pt != null && (Math.abs(pt.x - p2.x) > thresh ||
  2953. Math.abs(pt.y - p2.y) > thresh) &&
  2954. (Math.abs(pt.x - p3.x) > thresh ||
  2955. Math.abs(pt.y - p3.y) > thresh))
  2956. {
  2957. var dx = pt.x - p0.x;
  2958. var dy = pt.y - p0.y;
  2959. var temp = {distSq: dx * dx + dy * dy, x: pt.x, y: pt.y};
  2960. // Intersections must be ordered by distance from start of segment
  2961. for (var t = 0; t < list.length; t++)
  2962. {
  2963. if (list[t].distSq > temp.distSq)
  2964. {
  2965. list.splice(t, 0, temp);
  2966. temp = null;
  2967. break;
  2968. }
  2969. }
  2970. // Ignores multiple intersections at segment joint
  2971. if (temp != null && (list.length == 0 ||
  2972. list[list.length - 1].x !== temp.x ||
  2973. list[list.length - 1].y !== temp.y))
  2974. {
  2975. list.push(temp);
  2976. }
  2977. }
  2978. }
  2979. }
  2980. }
  2981. // Adds ordered intersections to routed points
  2982. for (var j = 0; j < list.length; j++)
  2983. {
  2984. changed = addPoint(1, list[j].x, list[j].y) || changed;
  2985. }
  2986. }
  2987. var pt = pts[pts.length - 1];
  2988. changed = addPoint(0, pt.x, pt.y) || changed;
  2989. }
  2990. state.routedPoints = actual;
  2991. return changed;
  2992. }
  2993. else
  2994. {
  2995. return false;
  2996. }
  2997. };
  2998. /**
  2999. * Overrides painting the actual shape for taking into account jump style.
  3000. */
  3001. var mxConnectorPaintLine = mxConnector.prototype.paintLine;
  3002. mxConnector.prototype.paintLine = function (c, absPts, rounded)
  3003. {
  3004. // Required for checking dirty state
  3005. this.routedPoints = (this.state != null) ? this.state.routedPoints : null;
  3006. if (this.outline || this.state == null || this.style == null ||
  3007. this.state.routedPoints == null || this.state.routedPoints.length == 0)
  3008. {
  3009. mxConnectorPaintLine.apply(this, arguments);
  3010. }
  3011. else
  3012. {
  3013. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  3014. mxConstants.LINE_ARCSIZE) / 2;
  3015. var size = (parseInt(mxUtils.getValue(this.style, 'jumpSize',
  3016. Graph.defaultJumpSize)) - 2) / 2 + this.strokewidth;
  3017. var style = mxUtils.getValue(this.style, 'jumpStyle', 'none');
  3018. var f = Editor.jumpSizeRatio;
  3019. var moveTo = true;
  3020. var last = null;
  3021. var len = null;
  3022. var pts = [];
  3023. var n = null;
  3024. c.begin();
  3025. for (var i = 0; i < this.state.routedPoints.length; i++)
  3026. {
  3027. var rpt = this.state.routedPoints[i];
  3028. var pt = new mxPoint(rpt.x / this.scale, rpt.y / this.scale);
  3029. // Takes first and last point from passed-in array
  3030. if (i == 0)
  3031. {
  3032. pt = absPts[0];
  3033. }
  3034. else if (i == this.state.routedPoints.length - 1)
  3035. {
  3036. pt = absPts[absPts.length - 1];
  3037. }
  3038. var done = false;
  3039. // Type 1 is an intersection
  3040. if (last != null && rpt.type == 1)
  3041. {
  3042. if (n == null)
  3043. {
  3044. n = new mxPoint(pt.x - last.x, pt.y - last.y);
  3045. len = Math.sqrt(n.x * n.x + n.y * n.y);
  3046. n.x = n.x * size / len;
  3047. n.y = n.y * size / len;
  3048. }
  3049. // Checks if next/previous points are too close
  3050. var next = this.state.routedPoints[i + 1];
  3051. var dx = next.x / this.scale - pt.x;
  3052. var dy = next.y / this.scale - pt.y;
  3053. var dist = dx * dx + dy * dy;
  3054. if (dist > size * size && len > 0)
  3055. {
  3056. var dx = last.x - pt.x;
  3057. var dy = last.y - pt.y;
  3058. var dist = dx * dx + dy * dy;
  3059. if (dist > size * size)
  3060. {
  3061. var p0 = new mxPoint(pt.x - n.x, pt.y - n.y);
  3062. var p1 = new mxPoint(pt.x + n.x, pt.y + n.y);
  3063. pts.push(p0);
  3064. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  3065. var f = (Math.round(n.x) <= 0) ? 1 : -1;
  3066. moveTo = false;
  3067. if (style == 'sharp')
  3068. {
  3069. c.lineTo(p0.x - n.y * f, p0.y + n.x * f);
  3070. c.lineTo(p1.x - n.y * f, p1.y + n.x * f);
  3071. c.lineTo(p1.x, p1.y);
  3072. }
  3073. else if (style == 'arc')
  3074. {
  3075. f *= 1.3;
  3076. c.curveTo(p0.x - n.y * f, p0.y + n.x * f,
  3077. p1.x - n.y * f, p1.y + n.x * f,
  3078. p1.x, p1.y);
  3079. }
  3080. else
  3081. {
  3082. c.moveTo(p1.x, p1.y);
  3083. moveTo = true;
  3084. }
  3085. pts = [p1];
  3086. done = true;
  3087. }
  3088. }
  3089. }
  3090. else
  3091. {
  3092. n = null;
  3093. }
  3094. if (!done)
  3095. {
  3096. pts.push(pt);
  3097. last = pt;
  3098. }
  3099. }
  3100. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  3101. c.stroke();
  3102. }
  3103. };
  3104. /**
  3105. * Adds support for snapToPoint style.
  3106. */
  3107. var mxGraphViewUpdateFloatingTerminalPoint = mxGraphView.prototype.updateFloatingTerminalPoint;
  3108. mxGraphView.prototype.updateFloatingTerminalPoint = function(edge, start, end, source)
  3109. {
  3110. if (start != null && edge != null &&
  3111. (start.style['snapToPoint'] == '1' ||
  3112. edge.style['snapToPoint'] == '1'))
  3113. {
  3114. start = this.getTerminalPort(edge, start, source);
  3115. var next = this.getNextPoint(edge, end, source);
  3116. var orth = this.graph.isOrthogonal(edge);
  3117. var alpha = mxUtils.toRadians(Number(start.style[mxConstants.STYLE_ROTATION] || '0'));
  3118. var center = new mxPoint(start.getCenterX(), start.getCenterY());
  3119. if (alpha != 0)
  3120. {
  3121. var cos = Math.cos(-alpha);
  3122. var sin = Math.sin(-alpha);
  3123. next = mxUtils.getRotatedPoint(next, cos, sin, center);
  3124. }
  3125. var border = parseFloat(edge.style[mxConstants.STYLE_PERIMETER_SPACING] || 0);
  3126. border += parseFloat(edge.style[(source) ?
  3127. mxConstants.STYLE_SOURCE_PERIMETER_SPACING :
  3128. mxConstants.STYLE_TARGET_PERIMETER_SPACING] || 0);
  3129. var pt = this.getPerimeterPoint(start, next, alpha == 0 && orth, border);
  3130. if (alpha != 0)
  3131. {
  3132. var cos = Math.cos(alpha);
  3133. var sin = Math.sin(alpha);
  3134. pt = mxUtils.getRotatedPoint(pt, cos, sin, center);
  3135. }
  3136. edge.setAbsoluteTerminalPoint(this.snapToAnchorPoint(edge, start, end, source, pt), source);
  3137. }
  3138. else
  3139. {
  3140. mxGraphViewUpdateFloatingTerminalPoint.apply(this, arguments);
  3141. }
  3142. };
  3143. mxGraphView.prototype.snapToAnchorPoint = function(edge, start, end, source, pt)
  3144. {
  3145. if (start != null && edge != null)
  3146. {
  3147. var constraints = this.graph.getAllConnectionConstraints(start)
  3148. var nearest = null;
  3149. var dist = null;
  3150. for (var i = 0; i < constraints.length; i++)
  3151. {
  3152. var cp = this.graph.getConnectionPoint(start, constraints[i]);
  3153. if (cp != null)
  3154. {
  3155. var tmp = (cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
  3156. if (dist == null || tmp < dist)
  3157. {
  3158. nearest = cp;
  3159. dist = tmp;
  3160. }
  3161. }
  3162. }
  3163. if (nearest != null)
  3164. {
  3165. pt = nearest;
  3166. }
  3167. }
  3168. return pt;
  3169. };
  3170. /**
  3171. * Adds support for placeholders in text elements of shapes.
  3172. */
  3173. var mxStencilEvaluateTextAttribute = mxStencil.prototype.evaluateTextAttribute;
  3174. mxStencil.prototype.evaluateTextAttribute = function(node, attribute, shape)
  3175. {
  3176. var result = mxStencilEvaluateTextAttribute.apply(this, arguments);
  3177. var placeholders = node.getAttribute('placeholders');
  3178. if (placeholders == '1' && shape.state != null)
  3179. {
  3180. result = shape.state.view.graph.replacePlaceholders(shape.state.cell, result);
  3181. }
  3182. return result;
  3183. };
  3184. /**
  3185. * Adds custom stencils defined via shape=stencil(value) style. The value is a base64 encoded, compressed and
  3186. * URL encoded XML definition of the shape according to the stencil definition language of mxGraph.
  3187. *
  3188. * Needs to be in this file to make sure its part of the embed client code. Also the check for ZLib is
  3189. * different than for the Editor code.
  3190. */
  3191. var mxCellRendererCreateShape = mxCellRenderer.prototype.createShape;
  3192. mxCellRenderer.prototype.createShape = function(state)
  3193. {
  3194. if (state.style != null && typeof(pako) !== 'undefined')
  3195. {
  3196. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  3197. // Extracts and decodes stencil XML if shape has the form shape=stencil(value)
  3198. if (shape != null && shape.substring(0, 8) == 'stencil(')
  3199. {
  3200. try
  3201. {
  3202. var stencil = shape.substring(8, shape.length - 1);
  3203. var doc = mxUtils.parseXml(state.view.graph.decompress(stencil));
  3204. return new mxShape(new mxStencil(doc.documentElement));
  3205. }
  3206. catch (e)
  3207. {
  3208. if (window.console != null)
  3209. {
  3210. console.log('Error in shape: ' + e);
  3211. }
  3212. }
  3213. }
  3214. }
  3215. return mxCellRendererCreateShape.apply(this, arguments);
  3216. };
  3217. })();
  3218. /**
  3219. * Overrides stencil registry for dynamic loading of stencils.
  3220. */
  3221. /**
  3222. * Maps from library names to an array of Javascript filenames,
  3223. * which are synchronously loaded. Currently only stencil files
  3224. * (.xml) and JS files (.js) are supported.
  3225. * IMPORTANT: For embedded diagrams to work entries must also
  3226. * be added in EmbedServlet.java.
  3227. */
  3228. mxStencilRegistry.libraries = {};
  3229. /**
  3230. * Global switch to disable dynamic loading.
  3231. */
  3232. mxStencilRegistry.dynamicLoading = true;
  3233. /**
  3234. * Stores all package names that have been dynamically loaded.
  3235. * Each package is only loaded once.
  3236. */
  3237. mxStencilRegistry.packages = [];
  3238. // Extends the default stencil registry to add dynamic loading
  3239. mxStencilRegistry.getStencil = function(name)
  3240. {
  3241. var result = mxStencilRegistry.stencils[name];
  3242. if (result == null && mxCellRenderer.prototype.defaultShapes[name] == null && mxStencilRegistry.dynamicLoading)
  3243. {
  3244. var basename = mxStencilRegistry.getBasenameForStencil(name);
  3245. // Loads stencil files and tries again
  3246. if (basename != null)
  3247. {
  3248. var libs = mxStencilRegistry.libraries[basename];
  3249. if (libs != null)
  3250. {
  3251. if (mxStencilRegistry.packages[basename] == null)
  3252. {
  3253. mxStencilRegistry.packages[basename] = 1;
  3254. for (var i = 0; i < libs.length; i++)
  3255. {
  3256. var fname = libs[i];
  3257. if (fname.toLowerCase().substring(fname.length - 4, fname.length) == '.xml')
  3258. {
  3259. mxStencilRegistry.loadStencilSet(fname, null);
  3260. }
  3261. else if (fname.toLowerCase().substring(fname.length - 3, fname.length) == '.js')
  3262. {
  3263. try
  3264. {
  3265. var req = mxUtils.load(fname);
  3266. if (req != null && req.getStatus() >= 200 && req.getStatus() <= 299)
  3267. {
  3268. eval.call(window, req.getText());
  3269. }
  3270. }
  3271. catch (e)
  3272. {
  3273. if (window.console != null)
  3274. {
  3275. console.log('error in getStencil:', fname, e);
  3276. }
  3277. }
  3278. }
  3279. else
  3280. {
  3281. // FIXME: This does not yet work as the loading is triggered after
  3282. // the shape was used in the graph, at which point the keys have
  3283. // typically been translated in the calling method.
  3284. //mxResources.add(fname);
  3285. }
  3286. }
  3287. }
  3288. }
  3289. else
  3290. {
  3291. // Replaces '_-_' with '_'
  3292. basename = basename.replace('_-_', '_');
  3293. mxStencilRegistry.loadStencilSet(STENCIL_PATH + '/' + basename + '.xml', null);
  3294. }
  3295. result = mxStencilRegistry.stencils[name];
  3296. }
  3297. }
  3298. return result;
  3299. };
  3300. // Returns the basename for the given stencil or null if no file must be
  3301. // loaded to render the given stencil.
  3302. mxStencilRegistry.getBasenameForStencil = function(name)
  3303. {
  3304. var tmp = null;
  3305. if (name != null)
  3306. {
  3307. var parts = name.split('.');
  3308. if (parts.length > 0 && parts[0] == 'mxgraph')
  3309. {
  3310. tmp = parts[1];
  3311. for (var i = 2; i < parts.length - 1; i++)
  3312. {
  3313. tmp += '/' + parts[i];
  3314. }
  3315. }
  3316. }
  3317. return tmp;
  3318. };
  3319. // Loads the given stencil set
  3320. mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force, async)
  3321. {
  3322. force = (force != null) ? force : false;
  3323. // Uses additional cache for detecting previous load attempts
  3324. var xmlDoc = mxStencilRegistry.packages[stencilFile];
  3325. if (force || xmlDoc == null)
  3326. {
  3327. var install = false;
  3328. if (xmlDoc == null)
  3329. {
  3330. try
  3331. {
  3332. if (async)
  3333. {
  3334. var req = mxUtils.get(stencilFile, mxUtils.bind(this, function(req)
  3335. {
  3336. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3337. {
  3338. xmlDoc = req.getXml();
  3339. mxStencilRegistry.packages[stencilFile] = xmlDoc;
  3340. install = true;
  3341. if (xmlDoc != null && xmlDoc.documentElement != null)
  3342. {
  3343. mxStencilRegistry.parseStencilSet(xmlDoc.documentElement, postStencilLoad, install);
  3344. }
  3345. }
  3346. }));
  3347. return;
  3348. }
  3349. else
  3350. {
  3351. var req = mxUtils.load(stencilFile);
  3352. xmlDoc = req.getXml();
  3353. mxStencilRegistry.packages[stencilFile] = xmlDoc;
  3354. install = true;
  3355. }
  3356. }
  3357. catch (e)
  3358. {
  3359. if (window.console != null)
  3360. {
  3361. console.log('error in loadStencilSet:', stencilFile, e);
  3362. }
  3363. }
  3364. }
  3365. if (xmlDoc != null && xmlDoc.documentElement != null)
  3366. {
  3367. mxStencilRegistry.parseStencilSet(xmlDoc.documentElement, postStencilLoad, install);
  3368. }
  3369. }
  3370. };
  3371. // Takes array of strings
  3372. mxStencilRegistry.parseStencilSets = function(stencils)
  3373. {
  3374. for (var i = 0; i < stencils.length; i++)
  3375. {
  3376. mxStencilRegistry.parseStencilSet(mxUtils.parseXml(stencils[i]).documentElement);
  3377. }
  3378. };
  3379. // Parses the given stencil set
  3380. mxStencilRegistry.parseStencilSet = function(root, postStencilLoad, install)
  3381. {
  3382. if (root.nodeName == 'stencils')
  3383. {
  3384. var shapes = root.firstChild;
  3385. while (shapes != null)
  3386. {
  3387. if (shapes.nodeName == 'shapes')
  3388. {
  3389. mxStencilRegistry.parseStencilSet(shapes, postStencilLoad, install);
  3390. }
  3391. shapes = shapes.nextSibling;
  3392. }
  3393. }
  3394. else
  3395. {
  3396. install = (install != null) ? install : true;
  3397. var shape = root.firstChild;
  3398. var packageName = '';
  3399. var name = root.getAttribute('name');
  3400. if (name != null)
  3401. {
  3402. packageName = name + '.';
  3403. }
  3404. while (shape != null)
  3405. {
  3406. if (shape.nodeType == mxConstants.NODETYPE_ELEMENT)
  3407. {
  3408. name = shape.getAttribute('name');
  3409. if (name != null)
  3410. {
  3411. packageName = packageName.toLowerCase();
  3412. var stencilName = name.replace(/ /g,"_");
  3413. if (install)
  3414. {
  3415. mxStencilRegistry.addStencil(packageName + stencilName.toLowerCase(), new mxStencil(shape));
  3416. }
  3417. if (postStencilLoad != null)
  3418. {
  3419. var w = shape.getAttribute('w');
  3420. var h = shape.getAttribute('h');
  3421. w = (w == null) ? 80 : parseInt(w, 10);
  3422. h = (h == null) ? 80 : parseInt(h, 10);
  3423. postStencilLoad(packageName, stencilName, name, w, h);
  3424. }
  3425. }
  3426. }
  3427. shape = shape.nextSibling;
  3428. }
  3429. }
  3430. };
  3431. /**
  3432. * These overrides are only added if mxVertexHandler is defined (ie. not in embedded graph)
  3433. */
  3434. if (typeof mxVertexHandler != 'undefined')
  3435. {
  3436. (function()
  3437. {
  3438. // Sets colors for handles
  3439. mxConstants.HANDLE_FILLCOLOR = '#99ccff';
  3440. mxConstants.HANDLE_STROKECOLOR = '#0088cf';
  3441. mxConstants.VERTEX_SELECTION_COLOR = '#00a8ff';
  3442. mxConstants.OUTLINE_COLOR = '#00a8ff';
  3443. mxConstants.OUTLINE_HANDLE_FILLCOLOR = '#99ccff';
  3444. mxConstants.OUTLINE_HANDLE_STROKECOLOR = '#00a8ff';
  3445. mxConstants.CONNECT_HANDLE_FILLCOLOR = '#cee7ff';
  3446. mxConstants.EDGE_SELECTION_COLOR = '#00a8ff';
  3447. mxConstants.DEFAULT_VALID_COLOR = '#00a8ff';
  3448. mxConstants.LABEL_HANDLE_FILLCOLOR = '#cee7ff';
  3449. mxConstants.GUIDE_COLOR = '#0088cf';
  3450. mxConstants.HIGHLIGHT_OPACITY = 30;
  3451. mxConstants.HIGHLIGHT_SIZE = 8;
  3452. //Enables snapping to off-grid terminals for edge waypoints
  3453. mxEdgeHandler.prototype.snapToTerminals = true;
  3454. //Enables guides
  3455. mxGraphHandler.prototype.guidesEnabled = true;
  3456. //Alt-move disables guides
  3457. mxGuide.prototype.isEnabledForEvent = function(evt)
  3458. {
  3459. return !mxEvent.isAltDown(evt);
  3460. };
  3461. // Extends connection handler to enable ctrl+drag for cloning source cell
  3462. // since copyOnConnect is now disabled by default
  3463. var mxConnectionHandlerCreateTarget = mxConnectionHandler.prototype.isCreateTarget;
  3464. mxConnectionHandler.prototype.isCreateTarget = function(evt)
  3465. {
  3466. return mxEvent.isControlDown(evt) || mxConnectionHandlerCreateTarget.apply(this, arguments);
  3467. };
  3468. // Overrides highlight shape for connection points
  3469. mxConstraintHandler.prototype.createHighlightShape = function()
  3470. {
  3471. var hl = new mxEllipse(null, this.highlightColor, this.highlightColor, 0);
  3472. hl.opacity = mxConstants.HIGHLIGHT_OPACITY;
  3473. return hl;
  3474. };
  3475. // Overrides edge preview to use current edge shape and default style
  3476. mxConnectionHandler.prototype.livePreview = true;
  3477. mxConnectionHandler.prototype.cursor = 'crosshair';
  3478. // Uses current edge style for connect preview
  3479. mxConnectionHandler.prototype.createEdgeState = function(me)
  3480. {
  3481. var style = this.graph.createCurrentEdgeStyle();
  3482. var edge = this.graph.createEdge(null, null, null, null, null, style);
  3483. var state = new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  3484. for (var key in this.graph.currentEdgeStyle)
  3485. {
  3486. state.style[key] = this.graph.currentEdgeStyle[key];
  3487. }
  3488. return state;
  3489. };
  3490. // Overrides dashed state with current edge style
  3491. var connectionHandlerCreateShape = mxConnectionHandler.prototype.createShape;
  3492. mxConnectionHandler.prototype.createShape = function()
  3493. {
  3494. var shape = connectionHandlerCreateShape.apply(this, arguments);
  3495. shape.isDashed = this.graph.currentEdgeStyle[mxConstants.STYLE_DASHED] == '1';
  3496. return shape;
  3497. }
  3498. // Overrides live preview to keep current style
  3499. mxConnectionHandler.prototype.updatePreview = function(valid)
  3500. {
  3501. // do not change color of preview
  3502. };
  3503. // Overrides connection handler to ignore edges instead of not allowing connections
  3504. var mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
  3505. mxConnectionHandler.prototype.createMarker = function()
  3506. {
  3507. var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);
  3508. var markerGetCell = marker.getCell;
  3509. marker.getCell = mxUtils.bind(this, function(me)
  3510. {
  3511. var result = markerGetCell.apply(this, arguments);
  3512. this.error = null;
  3513. return result;
  3514. });
  3515. return marker;
  3516. };
  3517. /**
  3518. *
  3519. */
  3520. Graph.prototype.defaultVertexStyle = {};
  3521. /**
  3522. * Contains the default style for edges.
  3523. */
  3524. Graph.prototype.defaultEdgeStyle = {'edgeStyle': 'orthogonalEdgeStyle', 'rounded': '0',
  3525. 'jettySize': 'auto', 'orthogonalLoop': '1'};
  3526. /**
  3527. * Returns the current edge style as a string.
  3528. */
  3529. Graph.prototype.createCurrentEdgeStyle = function()
  3530. {
  3531. var style = 'edgeStyle=' + (this.currentEdgeStyle['edgeStyle'] || 'none') + ';';
  3532. if (this.currentEdgeStyle['shape'] != null)
  3533. {
  3534. style += 'shape=' + this.currentEdgeStyle['shape'] + ';';
  3535. }
  3536. if (this.currentEdgeStyle['curved'] != null)
  3537. {
  3538. style += 'curved=' + this.currentEdgeStyle['curved'] + ';';
  3539. }
  3540. if (this.currentEdgeStyle['rounded'] != null)
  3541. {
  3542. style += 'rounded=' + this.currentEdgeStyle['rounded'] + ';';
  3543. }
  3544. if (this.currentEdgeStyle['comic'] != null)
  3545. {
  3546. style += 'comic=' + this.currentEdgeStyle['comic'] + ';';
  3547. }
  3548. if (this.currentEdgeStyle['jumpStyle'] != null)
  3549. {
  3550. style += 'jumpStyle=' + this.currentEdgeStyle['jumpStyle'] + ';';
  3551. }
  3552. if (this.currentEdgeStyle['jumpSize'] != null)
  3553. {
  3554. style += 'jumpSize=' + this.currentEdgeStyle['jumpSize'] + ';';
  3555. }
  3556. // Special logic for custom property of elbowEdgeStyle
  3557. if (this.currentEdgeStyle['edgeStyle'] == 'elbowEdgeStyle' && this.currentEdgeStyle['elbow'] != null)
  3558. {
  3559. style += 'elbow=' + this.currentEdgeStyle['elbow'] + ';';
  3560. }
  3561. if (this.currentEdgeStyle['html'] != null)
  3562. {
  3563. style += 'html=' + this.currentEdgeStyle['html'] + ';';
  3564. }
  3565. else
  3566. {
  3567. style += 'html=1;';
  3568. }
  3569. return style;
  3570. };
  3571. /**
  3572. * Hook for subclassers.
  3573. */
  3574. Graph.prototype.getPagePadding = function()
  3575. {
  3576. return new mxPoint(0, 0);
  3577. };
  3578. /**
  3579. * Loads the stylesheet for this graph.
  3580. */
  3581. Graph.prototype.loadStylesheet = function()
  3582. {
  3583. var node = (this.themes != null) ? this.themes[this.defaultThemeName] :
  3584. (!mxStyleRegistry.dynamicLoading) ? null :
  3585. mxUtils.load(STYLE_PATH + '/default.xml').getDocumentElement();
  3586. if (node != null)
  3587. {
  3588. var dec = new mxCodec(node.ownerDocument);
  3589. dec.decode(node, this.getStylesheet());
  3590. }
  3591. };
  3592. /**
  3593. * Overrides method to provide connection constraints for shapes.
  3594. */
  3595. Graph.prototype.getAllConnectionConstraints = function(terminal, source)
  3596. {
  3597. if (terminal != null)
  3598. {
  3599. var constraints = mxUtils.getValue(terminal.style, 'points', null);
  3600. if (constraints != null)
  3601. {
  3602. // Requires an array of arrays with x, y (0..1) and an optional
  3603. // perimeter (0 or 1), eg. points=[[0,0,1],[0,1,0],[1,1]]
  3604. var result = [];
  3605. try
  3606. {
  3607. var c = JSON.parse(constraints);
  3608. for (var i = 0; i < c.length; i++)
  3609. {
  3610. var tmp = c[i];
  3611. result.push(new mxConnectionConstraint(new mxPoint(tmp[0], tmp[1]), (tmp.length > 2) ? tmp[2] != '0' : true));
  3612. }
  3613. }
  3614. catch (e)
  3615. {
  3616. // ignore
  3617. }
  3618. return result;
  3619. }
  3620. else
  3621. {
  3622. if (terminal.shape != null)
  3623. {
  3624. if (terminal.shape.stencil != null)
  3625. {
  3626. if (terminal.shape.stencil != null)
  3627. {
  3628. return terminal.shape.stencil.constraints;
  3629. }
  3630. }
  3631. else if (terminal.shape.constraints != null)
  3632. {
  3633. return terminal.shape.constraints;
  3634. }
  3635. }
  3636. }
  3637. }
  3638. return null;
  3639. };
  3640. /**
  3641. * Inverts the elbow edge style without removing existing styles.
  3642. */
  3643. Graph.prototype.flipEdge = function(edge)
  3644. {
  3645. if (edge != null)
  3646. {
  3647. var state = this.view.getState(edge);
  3648. var style = (state != null) ? state.style : this.getCellStyle(edge);
  3649. if (style != null)
  3650. {
  3651. var elbow = mxUtils.getValue(style, mxConstants.STYLE_ELBOW,
  3652. mxConstants.ELBOW_HORIZONTAL);
  3653. var value = (elbow == mxConstants.ELBOW_HORIZONTAL) ?
  3654. mxConstants.ELBOW_VERTICAL : mxConstants.ELBOW_HORIZONTAL;
  3655. this.setCellStyles(mxConstants.STYLE_ELBOW, value, [edge]);
  3656. }
  3657. }
  3658. };
  3659. /**
  3660. * Disables drill-down for non-swimlanes.
  3661. */
  3662. Graph.prototype.isValidRoot = function(cell)
  3663. {
  3664. // Counts non-relative children
  3665. var childCount = this.model.getChildCount(cell);
  3666. var realChildCount = 0;
  3667. for (var i = 0; i < childCount; i++)
  3668. {
  3669. var child = this.model.getChildAt(cell, i);
  3670. if (this.model.isVertex(child))
  3671. {
  3672. var geometry = this.getCellGeometry(child);
  3673. if (geometry != null && !geometry.relative)
  3674. {
  3675. realChildCount++;
  3676. }
  3677. }
  3678. }
  3679. return realChildCount > 0 || this.isContainer(cell);
  3680. };
  3681. /**
  3682. * Disables drill-down for non-swimlanes.
  3683. */
  3684. Graph.prototype.isValidDropTarget = function(cell)
  3685. {
  3686. var state = this.view.getState(cell);
  3687. var style = (state != null) ? state.style : this.getCellStyle(cell);
  3688. return mxUtils.getValue(style, 'part', '0') != '1' && (this.isContainer(cell) ||
  3689. (mxGraph.prototype.isValidDropTarget.apply(this, arguments) &&
  3690. mxUtils.getValue(style, 'dropTarget', '1') != '0'));
  3691. };
  3692. /**
  3693. * Overrides createGroupCell to set the group style for new groups to 'group'.
  3694. */
  3695. Graph.prototype.createGroupCell = function()
  3696. {
  3697. var group = mxGraph.prototype.createGroupCell.apply(this, arguments);
  3698. group.setStyle('group');
  3699. return group;
  3700. };
  3701. /**
  3702. * Disables extending parents with stack layouts on add
  3703. */
  3704. Graph.prototype.isExtendParentsOnAdd = function(cell)
  3705. {
  3706. var result = mxGraph.prototype.isExtendParentsOnAdd.apply(this, arguments);
  3707. if (result && cell != null && this.layoutManager != null)
  3708. {
  3709. var parent = this.model.getParent(cell);
  3710. if (parent != null)
  3711. {
  3712. var layout = this.layoutManager.getLayout(parent);
  3713. if (layout != null && layout.constructor == mxStackLayout)
  3714. {
  3715. result = false;
  3716. }
  3717. }
  3718. }
  3719. return result;
  3720. };
  3721. /**
  3722. * Overrides autosize to add a border.
  3723. */
  3724. Graph.prototype.getPreferredSizeForCell = function(cell)
  3725. {
  3726. var result = mxGraph.prototype.getPreferredSizeForCell.apply(this, arguments);
  3727. // Adds buffer
  3728. if (result != null)
  3729. {
  3730. result.width += 10;
  3731. result.height += 4;
  3732. if (this.gridEnabled)
  3733. {
  3734. result.width = this.snap(result.width);
  3735. result.height = this.snap(result.height);
  3736. }
  3737. }
  3738. return result;
  3739. }
  3740. /**
  3741. * Turns the given cells and returns the changed cells.
  3742. */
  3743. Graph.prototype.turnShapes = function(cells)
  3744. {
  3745. var model = this.getModel();
  3746. var select = [];
  3747. model.beginUpdate();
  3748. try
  3749. {
  3750. for (var i = 0; i < cells.length; i++)
  3751. {
  3752. var cell = cells[i];
  3753. if (model.isEdge(cell))
  3754. {
  3755. var src = model.getTerminal(cell, true);
  3756. var trg = model.getTerminal(cell, false);
  3757. model.setTerminal(cell, trg, true);
  3758. model.setTerminal(cell, src, false);
  3759. var geo = model.getGeometry(cell);
  3760. if (geo != null)
  3761. {
  3762. geo = geo.clone();
  3763. if (geo.points != null)
  3764. {
  3765. geo.points.reverse();
  3766. }
  3767. var sp = geo.getTerminalPoint(true);
  3768. var tp = geo.getTerminalPoint(false)
  3769. geo.setTerminalPoint(sp, false);
  3770. geo.setTerminalPoint(tp, true);
  3771. model.setGeometry(cell, geo);
  3772. // Inverts constraints
  3773. var edgeState = this.view.getState(cell);
  3774. var sourceState = this.view.getState(src);
  3775. var targetState = this.view.getState(trg);
  3776. if (edgeState != null)
  3777. {
  3778. var sc = (sourceState != null) ? this.getConnectionConstraint(edgeState, sourceState, true) : null;
  3779. var tc = (targetState != null) ? this.getConnectionConstraint(edgeState, targetState, false) : null;
  3780. this.setConnectionConstraint(cell, src, true, tc);
  3781. this.setConnectionConstraint(cell, trg, false, sc);
  3782. }
  3783. select.push(cell);
  3784. }
  3785. }
  3786. else if (model.isVertex(cell))
  3787. {
  3788. var geo = this.getCellGeometry(cell);
  3789. if (geo != null)
  3790. {
  3791. // Rotates the size and position in the geometry
  3792. geo = geo.clone();
  3793. geo.x += geo.width / 2 - geo.height / 2;
  3794. geo.y += geo.height / 2 - geo.width / 2;
  3795. var tmp = geo.width;
  3796. geo.width = geo.height;
  3797. geo.height = tmp;
  3798. model.setGeometry(cell, geo);
  3799. // Reads the current direction and advances by 90 degrees
  3800. var state = this.view.getState(cell);
  3801. if (state != null)
  3802. {
  3803. var dir = state.style[mxConstants.STYLE_DIRECTION] || 'east'/*default*/;
  3804. if (dir == 'east')
  3805. {
  3806. dir = 'south';
  3807. }
  3808. else if (dir == 'south')
  3809. {
  3810. dir = 'west';
  3811. }
  3812. else if (dir == 'west')
  3813. {
  3814. dir = 'north';
  3815. }
  3816. else if (dir == 'north')
  3817. {
  3818. dir = 'east';
  3819. }
  3820. this.setCellStyles(mxConstants.STYLE_DIRECTION, dir, [cell]);
  3821. }
  3822. select.push(cell);
  3823. }
  3824. }
  3825. }
  3826. }
  3827. finally
  3828. {
  3829. model.endUpdate();
  3830. }
  3831. return select;
  3832. };
  3833. /**
  3834. * Updates the child cells with placeholders if metadata of a cell has changed.
  3835. */
  3836. Graph.prototype.processChange = function(change)
  3837. {
  3838. mxGraph.prototype.processChange.apply(this, arguments);
  3839. if (change instanceof mxValueChange && change.cell.value != null &&
  3840. typeof(change.cell.value) == 'object')
  3841. {
  3842. // Invalidates all descendants with placeholders
  3843. var desc = this.model.getDescendants(change.cell);
  3844. // LATER: Check if only label or tooltip have changed
  3845. if (desc.length > 0)
  3846. {
  3847. for (var i = 0; i < desc.length; i++)
  3848. {
  3849. if (this.isReplacePlaceholders(desc[i]))
  3850. {
  3851. this.view.invalidate(desc[i], false, false);
  3852. }
  3853. }
  3854. }
  3855. }
  3856. };
  3857. /**
  3858. * Handles label changes for XML user objects.
  3859. */
  3860. Graph.prototype.cellLabelChanged = function(cell, value, autoSize)
  3861. {
  3862. // Removes all illegal control characters in user input
  3863. value = this.zapGremlins(value);
  3864. this.model.beginUpdate();
  3865. try
  3866. {
  3867. if (cell.value != null && typeof cell.value == 'object')
  3868. {
  3869. if (this.isReplacePlaceholders(cell) &&
  3870. cell.getAttribute('placeholder') != null)
  3871. {
  3872. // LATER: Handle delete, name change
  3873. var name = cell.getAttribute('placeholder');
  3874. var current = cell;
  3875. while (current != null)
  3876. {
  3877. if (current == this.model.getRoot() || (current.value != null &&
  3878. typeof(current.value) == 'object' && current.hasAttribute(name)))
  3879. {
  3880. this.setAttributeForCell(current, name, value);
  3881. break;
  3882. }
  3883. current = this.model.getParent(current);
  3884. }
  3885. }
  3886. var tmp = cell.value.cloneNode(true);
  3887. tmp.setAttribute('label', value);
  3888. value = tmp;
  3889. }
  3890. mxGraph.prototype.cellLabelChanged.apply(this, arguments);
  3891. }
  3892. finally
  3893. {
  3894. this.model.endUpdate();
  3895. }
  3896. };
  3897. /**
  3898. * Overrides ungroup to check if group should be removed.
  3899. */
  3900. Graph.prototype.removeCellsAfterUngroup = function(cells)
  3901. {
  3902. var cellsToRemove = [];
  3903. for (var i = 0; i < cells.length; i++)
  3904. {
  3905. if (this.isCellDeletable(cells[i]))
  3906. {
  3907. var state = this.view.getState(cells[i]);
  3908. if (state != null)
  3909. {
  3910. var stroke = mxUtils.getValue(state.style, mxConstants.STYLE_STROKECOLOR, mxConstants.NONE);
  3911. var fill = mxUtils.getValue(state.style, mxConstants.STYLE_FILLCOLOR, mxConstants.NONE);
  3912. if (stroke == mxConstants.NONE && fill == mxConstants.NONE)
  3913. {
  3914. cellsToRemove.push(cells[i]);
  3915. }
  3916. }
  3917. }
  3918. }
  3919. cells = cellsToRemove;
  3920. mxGraph.prototype.removeCellsAfterUngroup.apply(this, arguments);
  3921. };
  3922. /**
  3923. * Sets the link for the given cell.
  3924. */
  3925. Graph.prototype.setLinkForCell = function(cell, link)
  3926. {
  3927. this.setAttributeForCell(cell, 'link', link);
  3928. };
  3929. /**
  3930. * Sets the link for the given cell.
  3931. */
  3932. Graph.prototype.setTooltipForCell = function(cell, link)
  3933. {
  3934. this.setAttributeForCell(cell, 'tooltip', link);
  3935. };
  3936. /**
  3937. * Sets the link for the given cell.
  3938. */
  3939. Graph.prototype.setAttributeForCell = function(cell, attributeName, attributeValue)
  3940. {
  3941. var value = null;
  3942. if (cell.value != null && typeof(cell.value) == 'object')
  3943. {
  3944. value = cell.value.cloneNode(true);
  3945. }
  3946. else
  3947. {
  3948. var doc = mxUtils.createXmlDocument();
  3949. value = doc.createElement('UserObject');
  3950. value.setAttribute('label', cell.value || '');
  3951. }
  3952. if (attributeValue != null && attributeValue.length > 0)
  3953. {
  3954. value.setAttribute(attributeName, attributeValue);
  3955. }
  3956. else
  3957. {
  3958. value.removeAttribute(attributeName);
  3959. }
  3960. this.model.setValue(cell, value);
  3961. };
  3962. /**
  3963. * Overridden to stop moving edge labels between cells.
  3964. */
  3965. Graph.prototype.getDropTarget = function(cells, evt, cell, clone)
  3966. {
  3967. var model = this.getModel();
  3968. // Disables drop into group if alt is pressed
  3969. if (mxEvent.isAltDown(evt))
  3970. {
  3971. return null;
  3972. }
  3973. // Disables dragging edge labels out of edges
  3974. for (var i = 0; i < cells.length; i++)
  3975. {
  3976. if (this.model.isEdge(this.model.getParent(cells[i])))
  3977. {
  3978. return null;
  3979. }
  3980. }
  3981. return mxGraph.prototype.getDropTarget.apply(this, arguments);
  3982. };
  3983. /**
  3984. * Overrides double click handling to avoid accidental inserts of new labels in dblClick below.
  3985. */
  3986. Graph.prototype.click = function(me)
  3987. {
  3988. mxGraph.prototype.click.call(this, me);
  3989. // Stores state and source for checking in dblClick
  3990. this.firstClickState = me.getState();
  3991. this.firstClickSource = me.getSource();
  3992. };
  3993. /**
  3994. * Overrides double click handling to add the tolerance and inserting text.
  3995. */
  3996. Graph.prototype.dblClick = function(evt, cell)
  3997. {
  3998. if (this.isEnabled())
  3999. {
  4000. var pt = mxUtils.convertPoint(this.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  4001. // Automatically adds new child cells to edges on double click
  4002. if (evt != null && !this.model.isVertex(cell))
  4003. {
  4004. var state = (this.model.isEdge(cell)) ? this.view.getState(cell) : null;
  4005. var src = mxEvent.getSource(evt);
  4006. if (this.firstClickState == state && this.firstClickSource == src)
  4007. {
  4008. if (state == null || (state.text == null || state.text.node == null ||
  4009. (!mxUtils.contains(state.text.boundingBox, pt.x, pt.y) &&
  4010. !mxUtils.isAncestorNode(state.text.node, mxEvent.getSource(evt)))))
  4011. {
  4012. if ((state == null && !this.isCellLocked(this.getDefaultParent())) ||
  4013. (state != null && !this.isCellLocked(state.cell)))
  4014. {
  4015. // Avoids accidental inserts on background
  4016. if (state != null || (mxClient.IS_VML && src == this.view.getCanvas()) ||
  4017. (mxClient.IS_SVG && src == this.view.getCanvas().ownerSVGElement))
  4018. {
  4019. cell = this.addText(pt.x, pt.y, state);
  4020. }
  4021. }
  4022. }
  4023. }
  4024. }
  4025. mxGraph.prototype.dblClick.call(this, evt, cell);
  4026. }
  4027. };
  4028. /**
  4029. * Returns a point that specifies the location for inserting cells.
  4030. */
  4031. Graph.prototype.getInsertPoint = function()
  4032. {
  4033. var gs = this.getGridSize();
  4034. var dx = this.container.scrollLeft / this.view.scale - this.view.translate.x;
  4035. var dy = this.container.scrollTop / this.view.scale - this.view.translate.y;
  4036. if (this.pageVisible)
  4037. {
  4038. var layout = this.getPageLayout();
  4039. var page = this.getPageSize();
  4040. dx = Math.max(dx, layout.x * page.width);
  4041. dy = Math.max(dy, layout.y * page.height);
  4042. }
  4043. return new mxPoint(this.snap(dx + gs), this.snap(dy + gs));
  4044. };
  4045. /**
  4046. *
  4047. */
  4048. Graph.prototype.getFreeInsertPoint = function()
  4049. {
  4050. var view = this.view;
  4051. var bds = this.getGraphBounds();
  4052. var pt = this.getInsertPoint();
  4053. // Places at same x-coord and 2 grid sizes below existing graph
  4054. var x = this.snap(Math.round(Math.max(pt.x, bds.x / view.scale - view.translate.x +
  4055. ((bds.width == 0) ? this.gridSize : 0))));
  4056. var y = this.snap(Math.round(Math.max(pt.y, (bds.y + bds.height) / view.scale - view.translate.y +
  4057. ((bds.height == 0) ? 1 : 2) * this.gridSize)));
  4058. return new mxPoint(x, y);
  4059. };
  4060. /**
  4061. * Hook for subclassers to return true if the current insert point was defined
  4062. * using a mouse hover event.
  4063. */
  4064. Graph.prototype.isMouseInsertPoint = function()
  4065. {
  4066. return false;
  4067. };
  4068. /**
  4069. * Adds a new label at the given position and returns the new cell. State is
  4070. * an optional edge state to be used as the parent for the label. Vertices
  4071. * are not allowed currently as states.
  4072. */
  4073. Graph.prototype.addText = function(x, y, state)
  4074. {
  4075. // Creates a new edge label with a predefined text
  4076. var label = new mxCell();
  4077. label.value = 'Text';
  4078. label.style = 'text;html=1;resizable=0;points=[];'
  4079. label.geometry = new mxGeometry(0, 0, 0, 0);
  4080. label.vertex = true;
  4081. if (state != null)
  4082. {
  4083. label.style += 'align=center;verticalAlign=middle;labelBackgroundColor=#ffffff;'
  4084. label.geometry.relative = true;
  4085. label.connectable = false;
  4086. // Resets the relative location stored inside the geometry
  4087. var pt2 = this.view.getRelativePoint(state, x, y);
  4088. label.geometry.x = Math.round(pt2.x * 10000) / 10000;
  4089. label.geometry.y = Math.round(pt2.y);
  4090. // Resets the offset inside the geometry to find the offset from the resulting point
  4091. label.geometry.offset = new mxPoint(0, 0);
  4092. pt2 = this.view.getPoint(state, label.geometry);
  4093. var scale = this.view.scale;
  4094. label.geometry.offset = new mxPoint(Math.round((x - pt2.x) / scale), Math.round((y - pt2.y) / scale));
  4095. }
  4096. else
  4097. {
  4098. label.style += 'autosize=1;align=left;verticalAlign=top;spacingTop=-4;'
  4099. var tr = this.view.translate;
  4100. label.geometry.width = 40;
  4101. label.geometry.height = 20;
  4102. label.geometry.x = Math.round(x / this.view.scale) - tr.x;
  4103. label.geometry.y = Math.round(y / this.view.scale) - tr.y;
  4104. }
  4105. this.getModel().beginUpdate();
  4106. try
  4107. {
  4108. this.addCells([label], (state != null) ? state.cell : null);
  4109. this.fireEvent(new mxEventObject('textInserted', 'cells', [label]));
  4110. // Updates size of text after possible change of style via event
  4111. this.autoSizeCell(label);
  4112. }
  4113. finally
  4114. {
  4115. this.getModel().endUpdate();
  4116. }
  4117. return label;
  4118. };
  4119. /**
  4120. *
  4121. */
  4122. Graph.prototype.getAbsoluteUrl = function(url)
  4123. {
  4124. if (url != null && this.isRelativeUrl(url))
  4125. {
  4126. if (url.charAt(0) == '#')
  4127. {
  4128. url = this.baseUrl + url;
  4129. }
  4130. else if (url.charAt(0) == '/')
  4131. {
  4132. url = this.domainUrl + url;
  4133. }
  4134. else
  4135. {
  4136. url = this.domainPathUrl + url;
  4137. }
  4138. }
  4139. return url;
  4140. };
  4141. /**
  4142. * Returns true if the fiven href references an external protocol that
  4143. * should never open in a new window. Default returns true for mailto.
  4144. */
  4145. Graph.prototype.isExternalProtocol = function(href)
  4146. {
  4147. return href.substring(0, 7) === 'mailto:';
  4148. };
  4149. /**
  4150. * Hook for links to open in same window. Default returns true for anchors,
  4151. * links to same domain or if target == 'self' in the config.
  4152. */
  4153. Graph.prototype.isBlankLink = function(href)
  4154. {
  4155. return !this.isExternalProtocol(href) &&
  4156. (this.linkPolicy === 'blank' ||
  4157. (this.linkPolicy !== 'self' &&
  4158. !this.isRelativeUrl(href) &&
  4159. href.substring(0, this.domainUrl.length) !== this.domainUrl));
  4160. };
  4161. /**
  4162. *
  4163. */
  4164. Graph.prototype.isRelativeUrl = function(url)
  4165. {
  4166. return url != null && !this.absoluteUrlPattern.test(url) &&
  4167. url.substring(0, 5) !== 'data:' &&
  4168. !this.isExternalProtocol(url);
  4169. };
  4170. /**
  4171. * Adds a handler for clicking on shapes with links. This replaces all links in labels.
  4172. */
  4173. Graph.prototype.addClickHandler = function(highlight, beforeClick, onClick)
  4174. {
  4175. // Replaces links in labels for consistent right-clicks
  4176. var checkLinks = mxUtils.bind(this, function()
  4177. {
  4178. var links = this.container.getElementsByTagName('a');
  4179. if (links != null)
  4180. {
  4181. for (var i = 0; i < links.length; i++)
  4182. {
  4183. var href = this.getAbsoluteUrl(links[i].getAttribute('href'));
  4184. if (href != null)
  4185. {
  4186. links[i].setAttribute('href', href);
  4187. if (beforeClick != null)
  4188. {
  4189. mxEvent.addGestureListeners(links[i], null, null, beforeClick);
  4190. }
  4191. }
  4192. }
  4193. }
  4194. });
  4195. this.model.addListener(mxEvent.CHANGE, checkLinks);
  4196. checkLinks();
  4197. var cursor = this.container.style.cursor;
  4198. var tol = this.getTolerance();
  4199. var graph = this;
  4200. var mouseListener =
  4201. {
  4202. currentState: null,
  4203. currentLink: null,
  4204. highlight: (highlight != null && highlight != '' && highlight != mxConstants.NONE) ?
  4205. new mxCellHighlight(graph, highlight, 4) : null,
  4206. startX: 0,
  4207. startY: 0,
  4208. scrollLeft: 0,
  4209. scrollTop: 0,
  4210. updateCurrentState: function(me)
  4211. {
  4212. var tmp = graph.view.getState(me.getCell());
  4213. if (tmp != this.currentState)
  4214. {
  4215. if (this.currentState != null)
  4216. {
  4217. this.clear();
  4218. }
  4219. this.currentState = tmp;
  4220. if (this.currentState != null)
  4221. {
  4222. this.activate(this.currentState);
  4223. }
  4224. }
  4225. },
  4226. mouseDown: function(sender, me)
  4227. {
  4228. this.startX = me.getGraphX();
  4229. this.startY = me.getGraphY();
  4230. this.scrollLeft = graph.container.scrollLeft;
  4231. this.scrollTop = graph.container.scrollTop;
  4232. if (this.currentLink == null && graph.container.style.overflow == 'auto')
  4233. {
  4234. graph.container.style.cursor = 'move';
  4235. }
  4236. this.updateCurrentState(me);
  4237. },
  4238. mouseMove: function(sender, me)
  4239. {
  4240. if (graph.isMouseDown)
  4241. {
  4242. if (this.currentLink != null)
  4243. {
  4244. var dx = Math.abs(this.startX - me.getGraphX());
  4245. var dy = Math.abs(this.startY - me.getGraphY());
  4246. if (dx > tol || dy > tol)
  4247. {
  4248. this.clear();
  4249. }
  4250. }
  4251. }
  4252. else
  4253. {
  4254. if (me.getSource().nodeName.toLowerCase() == 'a')
  4255. {
  4256. this.clear();
  4257. }
  4258. else
  4259. {
  4260. if (this.currentState != null && (me.getState() == this.currentState || me.getState() == null) &&
  4261. graph.intersects(this.currentState, me.getGraphX(), me.getGraphY()))
  4262. {
  4263. return;
  4264. }
  4265. this.updateCurrentState(me);
  4266. }
  4267. }
  4268. },
  4269. mouseUp: function(sender, me)
  4270. {
  4271. var source = me.getSource();
  4272. // Ignores clicks on links and collapse/expand icon
  4273. if (source.nodeName.toLowerCase() != 'a' &&
  4274. (Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  4275. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  4276. (me.getState() == null || !me.isSource(me.getState().control)) &&
  4277. (mxEvent.isLeftMouseButton(me.getEvent()) ||
  4278. mxEvent.isTouchEvent(me.getEvent())))
  4279. {
  4280. if (this.currentLink != null)
  4281. {
  4282. var blank = graph.isBlankLink(this.currentLink);
  4283. if ((this.currentLink.substring(0, 5) === 'data:' ||
  4284. !blank) && beforeClick != null)
  4285. {
  4286. beforeClick(me.getEvent(), this.currentLink);
  4287. }
  4288. if (!mxEvent.isConsumed(me.getEvent()))
  4289. {
  4290. var target = (blank) ? graph.linkTarget : '_top';
  4291. // Workaround for blocking in same iframe
  4292. if (target == '_self' && window != window.top)
  4293. {
  4294. window.location.href = this.currentLink;
  4295. }
  4296. else
  4297. {
  4298. // Avoids page reload for anchors (workaround for IE but used everywhere)
  4299. if (this.currentLink.substring(0, graph.baseUrl.length) == graph.baseUrl &&
  4300. this.currentLink.charAt(graph.baseUrl.length) == '#' &&
  4301. target == '_top' && window == window.top)
  4302. {
  4303. window.location.hash = this.currentLink.split('#')[1];
  4304. }
  4305. else
  4306. {
  4307. window.open(this.currentLink, target);
  4308. }
  4309. }
  4310. me.consume();
  4311. }
  4312. }
  4313. else if (onClick != null && !me.isConsumed() &&
  4314. (Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  4315. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  4316. (Math.abs(this.startX - me.getGraphX()) < tol &&
  4317. Math.abs(this.startY - me.getGraphY()) < tol))
  4318. {
  4319. onClick(me.getEvent());
  4320. }
  4321. }
  4322. this.clear();
  4323. },
  4324. activate: function(state)
  4325. {
  4326. this.currentLink = graph.getAbsoluteUrl(graph.getLinkForCell(state.cell));
  4327. if (this.currentLink != null)
  4328. {
  4329. graph.container.style.cursor = 'pointer';
  4330. if (this.highlight != null)
  4331. {
  4332. this.highlight.highlight(state);
  4333. }
  4334. }
  4335. },
  4336. clear: function()
  4337. {
  4338. if (graph.container != null)
  4339. {
  4340. graph.container.style.cursor = cursor;
  4341. }
  4342. this.currentState = null;
  4343. this.currentLink = null;
  4344. if (this.highlight != null)
  4345. {
  4346. this.highlight.hide();
  4347. }
  4348. }
  4349. };
  4350. // Ignores built-in click handling
  4351. graph.click = function(me) {};
  4352. graph.addMouseListener(mouseListener);
  4353. mxEvent.addListener(document, 'mouseleave', function(evt)
  4354. {
  4355. mouseListener.clear();
  4356. });
  4357. };
  4358. /**
  4359. * Duplicates the given cells and returns the duplicates.
  4360. */
  4361. Graph.prototype.duplicateCells = function(cells, append)
  4362. {
  4363. cells = (cells != null) ? cells : this.getSelectionCells();
  4364. append = (append != null) ? append : true;
  4365. cells = this.model.getTopmostCells(cells);
  4366. var model = this.getModel();
  4367. var s = this.gridSize;
  4368. var select = [];
  4369. model.beginUpdate();
  4370. try
  4371. {
  4372. var clones = this.cloneCells(cells, false);
  4373. for (var i = 0; i < cells.length; i++)
  4374. {
  4375. var parent = model.getParent(cells[i]);
  4376. var child = this.moveCells([clones[i]], s, s, false, parent)[0];
  4377. select.push(child);
  4378. if (append)
  4379. {
  4380. model.add(parent, clones[i]);
  4381. }
  4382. else
  4383. {
  4384. // Maintains child index by inserting after cloned in parent
  4385. var index = parent.getIndex(cells[i]);
  4386. model.add(parent, clones[i], index + 1);
  4387. }
  4388. }
  4389. }
  4390. finally
  4391. {
  4392. model.endUpdate();
  4393. }
  4394. return select;
  4395. };
  4396. /**
  4397. * Inserts the given image at the cursor in a content editable text box using
  4398. * the insertimage command on the document instance.
  4399. */
  4400. Graph.prototype.insertImage = function(newValue, w, h)
  4401. {
  4402. // To find the new image, we create a list of all existing links first
  4403. if (newValue != null)
  4404. {
  4405. var tmp = this.cellEditor.textarea.getElementsByTagName('img');
  4406. var oldImages = [];
  4407. for (var i = 0; i < tmp.length; i++)
  4408. {
  4409. oldImages.push(tmp[i]);
  4410. }
  4411. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  4412. document.execCommand('insertimage', false, newValue);
  4413. // Sets size of new image
  4414. var newImages = this.cellEditor.textarea.getElementsByTagName('img');
  4415. if (newImages.length == oldImages.length + 1)
  4416. {
  4417. // Inverse order in favor of appended images
  4418. for (var i = newImages.length - 1; i >= 0; i--)
  4419. {
  4420. if (i == 0 || newImages[i] != oldImages[i - 1])
  4421. {
  4422. // Workaround for lost styles during undo and redo is using attributes
  4423. newImages[i].setAttribute('width', w);
  4424. newImages[i].setAttribute('height', h);
  4425. break;
  4426. }
  4427. }
  4428. }
  4429. }
  4430. };
  4431. /**
  4432. * Inserts the given image at the cursor in a content editable text box using
  4433. * the insertimage command on the document instance.
  4434. */
  4435. Graph.prototype.insertLink = function(value)
  4436. {
  4437. if (value.length == 0)
  4438. {
  4439. document.execCommand('unlink', false);
  4440. }
  4441. else
  4442. {
  4443. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  4444. document.execCommand('createlink', false, mxUtils.trim(value));
  4445. }
  4446. };
  4447. /**
  4448. *
  4449. * @param cell
  4450. * @returns {Boolean}
  4451. */
  4452. Graph.prototype.isCellResizable = function(cell)
  4453. {
  4454. var result = mxGraph.prototype.isCellResizable.apply(this, arguments);
  4455. var state = this.view.getState(cell);
  4456. var style = (state != null) ? state.style : this.getCellStyle(cell);
  4457. return result || (mxUtils.getValue(style, mxConstants.STYLE_RESIZABLE, '1') != '0' &&
  4458. style[mxConstants.STYLE_WHITE_SPACE] == 'wrap');
  4459. };
  4460. /**
  4461. * Function: distributeCells
  4462. *
  4463. * Distribuets the centers of the given cells equally along the available
  4464. * horizontal or vertical space.
  4465. *
  4466. * Parameters:
  4467. *
  4468. * horizontal - Boolean that specifies the direction of the distribution.
  4469. * cells - Optional array of <mxCells> to be distributed. Edges are ignored.
  4470. */
  4471. Graph.prototype.distributeCells = function(horizontal, cells)
  4472. {
  4473. if (cells == null)
  4474. {
  4475. cells = this.getSelectionCells();
  4476. }
  4477. if (cells != null && cells.length > 1)
  4478. {
  4479. var vertices = [];
  4480. var max = null;
  4481. var min = null;
  4482. for (var i = 0; i < cells.length; i++)
  4483. {
  4484. if (this.getModel().isVertex(cells[i]))
  4485. {
  4486. var state = this.view.getState(cells[i]);
  4487. if (state != null)
  4488. {
  4489. var tmp = (horizontal) ? state.getCenterX() : state.getCenterY();
  4490. max = (max != null) ? Math.max(max, tmp) : tmp;
  4491. min = (min != null) ? Math.min(min, tmp) : tmp;
  4492. vertices.push(state);
  4493. }
  4494. }
  4495. }
  4496. if (vertices.length > 2)
  4497. {
  4498. vertices.sort(function(a, b)
  4499. {
  4500. return (horizontal) ? a.x - b.x : a.y - b.y;
  4501. });
  4502. var t = this.view.translate;
  4503. var s = this.view.scale;
  4504. min = min / s - ((horizontal) ? t.x : t.y);
  4505. max = max / s - ((horizontal) ? t.x : t.y);
  4506. this.getModel().beginUpdate();
  4507. try
  4508. {
  4509. var dt = (max - min) / (vertices.length - 1);
  4510. var t0 = min;
  4511. for (var i = 1; i < vertices.length - 1; i++)
  4512. {
  4513. var pstate = this.view.getState(this.model.getParent(vertices[i].cell));
  4514. var geo = this.getCellGeometry(vertices[i].cell);
  4515. t0 += dt;
  4516. if (geo != null && pstate != null)
  4517. {
  4518. geo = geo.clone();
  4519. if (horizontal)
  4520. {
  4521. geo.x = Math.round(t0 - geo.width / 2) - pstate.origin.x;
  4522. }
  4523. else
  4524. {
  4525. geo.y = Math.round(t0 - geo.height / 2) - pstate.origin.y;
  4526. }
  4527. this.getModel().setGeometry(vertices[i].cell, geo);
  4528. }
  4529. }
  4530. }
  4531. finally
  4532. {
  4533. this.getModel().endUpdate();
  4534. }
  4535. }
  4536. }
  4537. return cells;
  4538. };
  4539. /**
  4540. * Adds meta-drag an Mac.
  4541. * @param evt
  4542. * @returns
  4543. */
  4544. Graph.prototype.isCloneEvent = function(evt)
  4545. {
  4546. return (mxClient.IS_MAC && mxEvent.isMetaDown(evt)) || mxEvent.isControlDown(evt);
  4547. };
  4548. /**
  4549. * Translates this point by the given vector.
  4550. *
  4551. * @param {number} dx X-coordinate of the translation.
  4552. * @param {number} dy Y-coordinate of the translation.
  4553. */
  4554. Graph.prototype.encodeCells = function(cells)
  4555. {
  4556. var clones = this.cloneCells(cells);
  4557. // Creates a dictionary for fast lookups
  4558. var dict = new mxDictionary();
  4559. for (var i = 0; i < cells.length; i++)
  4560. {
  4561. dict.put(cells[i], true);
  4562. }
  4563. // Checks for orphaned relative children and makes absolute
  4564. for (var i = 0; i < clones.length; i++)
  4565. {
  4566. var state = this.view.getState(cells[i]);
  4567. if (state != null)
  4568. {
  4569. var geo = this.getCellGeometry(clones[i]);
  4570. if (geo != null && geo.relative && !this.model.isEdge(cells[i]) &&
  4571. !dict.get(this.model.getParent(cells[i])))
  4572. {
  4573. geo.relative = false;
  4574. geo.x = state.x / state.view.scale - state.view.translate.x;
  4575. geo.y = state.y / state.view.scale - state.view.translate.y;
  4576. }
  4577. }
  4578. }
  4579. var codec = new mxCodec();
  4580. var model = new mxGraphModel();
  4581. var parent = model.getChildAt(model.getRoot(), 0);
  4582. for (var i = 0; i < cells.length; i++)
  4583. {
  4584. model.add(parent, clones[i]);
  4585. }
  4586. return codec.encode(model);
  4587. };
  4588. /**
  4589. * Translates this point by the given vector.
  4590. *
  4591. * @param {number} dx X-coordinate of the translation.
  4592. * @param {number} dy Y-coordinate of the translation.
  4593. */
  4594. Graph.prototype.createSvgImageExport = function()
  4595. {
  4596. var exp = new mxImageExport();
  4597. // Adds hyperlinks (experimental)
  4598. exp.getLinkForCellState = mxUtils.bind(this, function(state, canvas)
  4599. {
  4600. return this.getLinkForCell(state.cell);
  4601. });
  4602. return exp;
  4603. };
  4604. /**
  4605. * Translates this point by the given vector.
  4606. *
  4607. * @param {number} dx X-coordinate of the translation.
  4608. * @param {number} dy Y-coordinate of the translation.
  4609. */
  4610. Graph.prototype.getSvg = function(background, scale, border, nocrop, crisp, ignoreSelection, showText)
  4611. {
  4612. scale = (scale != null) ? scale : 1;
  4613. border = (border != null) ? border : 0;
  4614. crisp = (crisp != null) ? crisp : true;
  4615. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  4616. showText = (showText != null) ? showText : true;
  4617. var bounds = (ignoreSelection || nocrop) ?
  4618. this.getGraphBounds() : this.getBoundingBox(this.getSelectionCells());
  4619. if (bounds == null)
  4620. {
  4621. throw Error(mxResources.get('drawingEmpty'));
  4622. }
  4623. var vs = this.view.scale;
  4624. // Prepares SVG document that holds the output
  4625. var svgDoc = mxUtils.createXmlDocument();
  4626. var root = (svgDoc.createElementNS != null) ?
  4627. svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') : svgDoc.createElement('svg');
  4628. if (background != null)
  4629. {
  4630. if (root.style != null)
  4631. {
  4632. root.style.backgroundColor = background;
  4633. }
  4634. else
  4635. {
  4636. root.setAttribute('style', 'background-color:' + background);
  4637. }
  4638. }
  4639. if (svgDoc.createElementNS == null)
  4640. {
  4641. root.setAttribute('xmlns', mxConstants.NS_SVG);
  4642. root.setAttribute('xmlns:xlink', mxConstants.NS_XLINK);
  4643. }
  4644. else
  4645. {
  4646. // KNOWN: Ignored in IE9-11, adds namespace for each image element instead. No workaround.
  4647. root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', mxConstants.NS_XLINK);
  4648. }
  4649. var s = scale / vs;
  4650. root.setAttribute('width', Math.max(1, Math.ceil(bounds.width * s) + 2 * border) + 'px');
  4651. root.setAttribute('height', Math.max(1, Math.ceil(bounds.height * s) + 2 * border) + 'px');
  4652. root.setAttribute('version', '1.1');
  4653. // Adds group for anti-aliasing via transform
  4654. var node = root;
  4655. if (crisp)
  4656. {
  4657. var group = (svgDoc.createElementNS != null) ?
  4658. svgDoc.createElementNS(mxConstants.NS_SVG, 'g') : svgDoc.createElement('g');
  4659. group.setAttribute('transform', 'translate(0.5,0.5)');
  4660. root.appendChild(group);
  4661. svgDoc.appendChild(root);
  4662. node = group;
  4663. }
  4664. else
  4665. {
  4666. svgDoc.appendChild(root);
  4667. }
  4668. // Renders graph. Offset will be multiplied with state's scale when painting state.
  4669. // TextOffset only seems to affect FF output but used everywhere for consistency.
  4670. var svgCanvas = this.createSvgCanvas(node);
  4671. svgCanvas.foOffset = (crisp) ? -0.5 : 0;
  4672. svgCanvas.textOffset = (crisp) ? -0.5 : 0;
  4673. svgCanvas.imageOffset = (crisp) ? -0.5 : 0;
  4674. svgCanvas.translate(Math.floor((border / scale - bounds.x) / vs), Math.floor((border / scale - bounds.y) / vs));
  4675. // Adds simple text fallback for viewers with no support for foreignObjects
  4676. var createAlternateContent = svgCanvas.createAlternateContent;
  4677. svgCanvas.createAlternateContent = function(fo, x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation)
  4678. {
  4679. var s = this.state;
  4680. // Assumes a max character width of 0.2em
  4681. if (this.foAltText != null && (w == 0 || (s.fontSize != 0 && str.length < (w * 5) / s.fontSize)))
  4682. {
  4683. var alt = this.createElement('text');
  4684. alt.setAttribute('x', Math.round(w / 2));
  4685. alt.setAttribute('y', Math.round((h + s.fontSize) / 2));
  4686. alt.setAttribute('fill', s.fontColor || 'black');
  4687. alt.setAttribute('text-anchor', 'middle');
  4688. alt.setAttribute('font-size', Math.round(s.fontSize) + 'px');
  4689. alt.setAttribute('font-family', s.fontFamily);
  4690. if ((s.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  4691. {
  4692. alt.setAttribute('font-weight', 'bold');
  4693. }
  4694. if ((s.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  4695. {
  4696. alt.setAttribute('font-style', 'italic');
  4697. }
  4698. if ((s.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  4699. {
  4700. alt.setAttribute('text-decoration', 'underline');
  4701. }
  4702. mxUtils.write(alt, str);
  4703. return alt;
  4704. }
  4705. else
  4706. {
  4707. return createAlternateContent.apply(this, arguments);
  4708. }
  4709. };
  4710. // Paints background image
  4711. var bgImg = this.backgroundImage;
  4712. if (bgImg != null)
  4713. {
  4714. var s2 = vs / scale;
  4715. var tr = this.view.translate;
  4716. var tmp = new mxRectangle(tr.x * s2, tr.y * s2, bgImg.width * s2, bgImg.height * s2);
  4717. // Checks if visible
  4718. if (mxUtils.intersects(bounds, tmp))
  4719. {
  4720. svgCanvas.image(tr.x, tr.y, bgImg.width, bgImg.height, bgImg.src, true);
  4721. }
  4722. }
  4723. svgCanvas.scale(s);
  4724. svgCanvas.textEnabled = showText;
  4725. var imgExport = this.createSvgImageExport();
  4726. var imgExportDrawCellState = imgExport.drawCellState;
  4727. // Implements ignoreSelection flag
  4728. imgExport.drawCellState = function(state, canvas)
  4729. {
  4730. if (ignoreSelection || state.view.graph.isCellSelected(state.cell))
  4731. {
  4732. imgExportDrawCellState.apply(this, arguments);
  4733. }
  4734. };
  4735. imgExport.drawState(this.getView().getState(this.model.root), svgCanvas);
  4736. return root;
  4737. };
  4738. /**
  4739. * Hook for creating the canvas used in getSvg.
  4740. */
  4741. Graph.prototype.createSvgCanvas = function(node)
  4742. {
  4743. return new mxSvgCanvas2D(node);
  4744. };
  4745. /**
  4746. * Returns the first ancestor of the current selection with the given name.
  4747. */
  4748. Graph.prototype.getSelectedElement = function()
  4749. {
  4750. var node = null;
  4751. if (window.getSelection)
  4752. {
  4753. var sel = window.getSelection();
  4754. if (sel.getRangeAt && sel.rangeCount)
  4755. {
  4756. var range = sel.getRangeAt(0);
  4757. node = range.commonAncestorContainer;
  4758. }
  4759. }
  4760. else if (document.selection)
  4761. {
  4762. node = document.selection.createRange().parentElement();
  4763. }
  4764. return node;
  4765. };
  4766. /**
  4767. * Returns the first ancestor of the current selection with the given name.
  4768. */
  4769. Graph.prototype.getParentByName = function(node, name, stopAt)
  4770. {
  4771. while (node != null)
  4772. {
  4773. if (node.nodeName == name)
  4774. {
  4775. return node;
  4776. }
  4777. if (node == stopAt)
  4778. {
  4779. return null;
  4780. }
  4781. node = node.parentNode;
  4782. }
  4783. return node;
  4784. };
  4785. /**
  4786. * Selects the given node.
  4787. */
  4788. Graph.prototype.selectNode = function(node)
  4789. {
  4790. var sel = null;
  4791. // IE9 and non-IE
  4792. if (window.getSelection)
  4793. {
  4794. sel = window.getSelection();
  4795. if (sel.getRangeAt && sel.rangeCount)
  4796. {
  4797. var range = document.createRange();
  4798. range.selectNode(node);
  4799. sel.removeAllRanges();
  4800. sel.addRange(range);
  4801. }
  4802. }
  4803. // IE < 9
  4804. else if ((sel = document.selection) && sel.type != 'Control')
  4805. {
  4806. var originalRange = sel.createRange();
  4807. originalRange.collapse(true);
  4808. var range = sel.createRange();
  4809. range.setEndPoint('StartToStart', originalRange);
  4810. range.select();
  4811. }
  4812. };
  4813. /**
  4814. * Inserts a new row into the given table.
  4815. */
  4816. Graph.prototype.insertRow = function(table, index)
  4817. {
  4818. var bd = table.tBodies[0];
  4819. var cols = (bd.rows.length > 0) ? bd.rows[0].cells.length : 1;
  4820. var row = bd.insertRow(index);
  4821. for (var i = 0; i < cols; i++)
  4822. {
  4823. mxUtils.br(row.insertCell(-1));
  4824. }
  4825. return row.cells[0];
  4826. };
  4827. /**
  4828. * Deletes the given column.
  4829. */
  4830. Graph.prototype.deleteRow = function(table, index)
  4831. {
  4832. table.tBodies[0].deleteRow(index);
  4833. };
  4834. /**
  4835. * Deletes the given column.
  4836. */
  4837. Graph.prototype.insertColumn = function(table, index)
  4838. {
  4839. var hd = table.tHead;
  4840. if (hd != null)
  4841. {
  4842. // TODO: use colIndex
  4843. for (var h = 0; h < hd.rows.length; h++)
  4844. {
  4845. var th = document.createElement('th');
  4846. hd.rows[h].appendChild(th);
  4847. mxUtils.br(th);
  4848. }
  4849. }
  4850. var bd = table.tBodies[0];
  4851. for (var i = 0; i < bd.rows.length; i++)
  4852. {
  4853. var cell = bd.rows[i].insertCell(index);
  4854. mxUtils.br(cell);
  4855. }
  4856. return bd.rows[0].cells[(index >= 0) ? index : bd.rows[0].cells.length - 1];
  4857. };
  4858. /**
  4859. * Deletes the given column.
  4860. */
  4861. Graph.prototype.deleteColumn = function(table, index)
  4862. {
  4863. if (index >= 0)
  4864. {
  4865. var bd = table.tBodies[0];
  4866. var rows = bd.rows;
  4867. for (var i = 0; i < rows.length; i++)
  4868. {
  4869. if (rows[i].cells.length > index)
  4870. {
  4871. rows[i].deleteCell(index);
  4872. }
  4873. }
  4874. }
  4875. };
  4876. /**
  4877. * Inserts the given HTML at the caret position (no undo).
  4878. */
  4879. Graph.prototype.pasteHtmlAtCaret = function(html)
  4880. {
  4881. var sel, range;
  4882. // IE9 and non-IE
  4883. if (window.getSelection)
  4884. {
  4885. sel = window.getSelection();
  4886. if (sel.getRangeAt && sel.rangeCount)
  4887. {
  4888. range = sel.getRangeAt(0);
  4889. range.deleteContents();
  4890. // Range.createContextualFragment() would be useful here but is
  4891. // only relatively recently standardized and is not supported in
  4892. // some browsers (IE9, for one)
  4893. var el = document.createElement("div");
  4894. el.innerHTML = html;
  4895. var frag = document.createDocumentFragment(), node;
  4896. while ((node = el.firstChild))
  4897. {
  4898. lastNode = frag.appendChild(node);
  4899. }
  4900. range.insertNode(frag);
  4901. }
  4902. }
  4903. // IE < 9
  4904. else if ((sel = document.selection) && sel.type != "Control")
  4905. {
  4906. // FIXME: Does not work if selection is empty
  4907. sel.createRange().pasteHTML(html);
  4908. }
  4909. };
  4910. /**
  4911. * Creates an anchor elements for handling the given link in the
  4912. * hint that is shown when the cell is selected.
  4913. */
  4914. Graph.prototype.createLinkForHint = function(link, label)
  4915. {
  4916. label = (label != null) ? label : link;
  4917. var a = document.createElement('a');
  4918. a.setAttribute('href', this.getAbsoluteUrl(link));
  4919. a.setAttribute('title', link);
  4920. if (this.linkTarget != null)
  4921. {
  4922. a.setAttribute('target', this.linkTarget);
  4923. }
  4924. // Adds shortened label to link
  4925. var max = 60;
  4926. var head = 36;
  4927. var tail = 20;
  4928. if (label.length > max)
  4929. {
  4930. label = label.substring(0, head) + '...' + label.substring(label.length - tail);
  4931. }
  4932. mxUtils.write(a, label);
  4933. return a;
  4934. };
  4935. /**
  4936. * Customized graph for touch devices.
  4937. */
  4938. Graph.prototype.initTouch = function()
  4939. {
  4940. // Disables new connections via "hotspot"
  4941. this.connectionHandler.marker.isEnabled = function()
  4942. {
  4943. return this.graph.connectionHandler.first != null;
  4944. };
  4945. // Hides menu when editing starts
  4946. this.addListener(mxEvent.START_EDITING, function(sender, evt)
  4947. {
  4948. this.popupMenuHandler.hideMenu();
  4949. });
  4950. // Adds custom hit detection if native hit detection found no cell
  4951. var graphUpdateMouseEvent = this.updateMouseEvent;
  4952. this.updateMouseEvent = function(me)
  4953. {
  4954. me = graphUpdateMouseEvent.apply(this, arguments);
  4955. if (mxEvent.isTouchEvent(me.getEvent()) && me.getState() == null)
  4956. {
  4957. var cell = this.getCellAt(me.graphX, me.graphY);
  4958. if (cell != null && this.isSwimlane(cell) && this.hitsSwimlaneContent(cell, me.graphX, me.graphY))
  4959. {
  4960. cell = null;
  4961. }
  4962. else
  4963. {
  4964. me.state = this.view.getState(cell);
  4965. if (me.state != null && me.state.shape != null)
  4966. {
  4967. this.container.style.cursor = me.state.shape.node.style.cursor;
  4968. }
  4969. }
  4970. }
  4971. if (me.getState() == null && this.isEnabled())
  4972. {
  4973. this.container.style.cursor = 'default';
  4974. }
  4975. return me;
  4976. };
  4977. // Context menu trigger implementation depending on current selection state
  4978. // combined with support for normal popup trigger.
  4979. var cellSelected = false;
  4980. var selectionEmpty = false;
  4981. var menuShowing = false;
  4982. var oldFireMouseEvent = this.fireMouseEvent;
  4983. this.fireMouseEvent = function(evtName, me, sender)
  4984. {
  4985. if (evtName == mxEvent.MOUSE_DOWN)
  4986. {
  4987. // For hit detection on edges
  4988. me = this.updateMouseEvent(me);
  4989. cellSelected = this.isCellSelected(me.getCell());
  4990. selectionEmpty = this.isSelectionEmpty();
  4991. menuShowing = this.popupMenuHandler.isMenuShowing();
  4992. }
  4993. oldFireMouseEvent.apply(this, arguments);
  4994. };
  4995. // Shows popup menu if cell was selected or selection was empty and background was clicked
  4996. // FIXME: Conflicts with mxPopupMenuHandler.prototype.getCellForPopupEvent in Editor.js by
  4997. // selecting parent for selected children in groups before this check can be made.
  4998. this.popupMenuHandler.mouseUp = mxUtils.bind(this, function(sender, me)
  4999. {
  5000. this.popupMenuHandler.popupTrigger = !this.isEditing() && this.isEnabled() &&
  5001. (me.getState() == null || !me.isSource(me.getState().control)) &&
  5002. (this.popupMenuHandler.popupTrigger || (!menuShowing && !mxEvent.isMouseEvent(me.getEvent()) &&
  5003. ((selectionEmpty && me.getCell() == null && this.isSelectionEmpty()) ||
  5004. (cellSelected && this.isCellSelected(me.getCell())))));
  5005. mxPopupMenuHandler.prototype.mouseUp.apply(this.popupMenuHandler, arguments);
  5006. });
  5007. };
  5008. /**
  5009. * HTML in-place editor
  5010. */
  5011. mxCellEditor.prototype.isContentEditing = function()
  5012. {
  5013. var state = this.graph.view.getState(this.editingCell);
  5014. return state != null && state.style['html'] == 1;
  5015. };
  5016. /**
  5017. * Creates the keyboard event handler for the current graph and history.
  5018. */
  5019. mxCellEditor.prototype.saveSelection = function()
  5020. {
  5021. if (window.getSelection)
  5022. {
  5023. sel = window.getSelection();
  5024. if (sel.getRangeAt && sel.rangeCount)
  5025. {
  5026. var ranges = [];
  5027. for (var i = 0, len = sel.rangeCount; i < len; ++i)
  5028. {
  5029. ranges.push(sel.getRangeAt(i));
  5030. }
  5031. return ranges;
  5032. }
  5033. }
  5034. else if (document.selection && document.selection.createRange)
  5035. {
  5036. return document.selection.createRange();
  5037. }
  5038. return null;
  5039. };
  5040. /**
  5041. * Creates the keyboard event handler for the current graph and history.
  5042. */
  5043. mxCellEditor.prototype.restoreSelection = function(savedSel)
  5044. {
  5045. try
  5046. {
  5047. if (savedSel)
  5048. {
  5049. if (window.getSelection)
  5050. {
  5051. sel = window.getSelection();
  5052. sel.removeAllRanges();
  5053. for (var i = 0, len = savedSel.length; i < len; ++i)
  5054. {
  5055. sel.addRange(savedSel[i]);
  5056. }
  5057. }
  5058. else if (document.selection && savedSel.select)
  5059. {
  5060. savedSel.select();
  5061. }
  5062. }
  5063. }
  5064. catch (e)
  5065. {
  5066. // ignore
  5067. }
  5068. };
  5069. /**
  5070. * Handling of special nl2Br style for not converting newlines to breaks in HTML labels.
  5071. * NOTE: Since it's easier to set this when the label is created we assume that it does
  5072. * not change during the lifetime of the mxText instance.
  5073. */
  5074. var mxCellRendererInitializeLabel = mxCellRenderer.prototype.initializeLabel;
  5075. mxCellRenderer.prototype.initializeLabel = function(state)
  5076. {
  5077. if (state.text != null)
  5078. {
  5079. state.text.replaceLinefeeds = mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  5080. }
  5081. mxCellRendererInitializeLabel.apply(this, arguments);
  5082. };
  5083. var mxConstraintHandlerUpdate = mxConstraintHandler.prototype.update;
  5084. mxConstraintHandler.prototype.update = function(me, source)
  5085. {
  5086. if (this.isKeepFocusEvent(me) || !mxEvent.isAltDown(me.getEvent()))
  5087. {
  5088. mxConstraintHandlerUpdate.apply(this, arguments);
  5089. }
  5090. else
  5091. {
  5092. this.reset();
  5093. }
  5094. };
  5095. /**
  5096. * No dashed shapes.
  5097. */
  5098. mxGuide.prototype.createGuideShape = function(horizontal)
  5099. {
  5100. var guide = new mxPolyline([], mxConstants.GUIDE_COLOR, mxConstants.GUIDE_STROKEWIDTH);
  5101. return guide;
  5102. };
  5103. /**
  5104. * HTML in-place editor
  5105. */
  5106. mxCellEditor.prototype.escapeCancelsEditing = false;
  5107. var mxCellEditorStartEditing = mxCellEditor.prototype.startEditing;
  5108. mxCellEditor.prototype.startEditing = function(cell, trigger)
  5109. {
  5110. mxCellEditorStartEditing.apply(this, arguments);
  5111. // Overrides class in case of HTML content to add
  5112. // dashed borders for divs and table cells
  5113. var state = this.graph.view.getState(cell);
  5114. if (state != null && state.style['html'] == 1)
  5115. {
  5116. this.textarea.className = 'mxCellEditor geContentEditable';
  5117. }
  5118. else
  5119. {
  5120. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  5121. }
  5122. // Toggles markup vs wysiwyg mode
  5123. this.codeViewMode = false;
  5124. // Stores current selection range when switching between markup and code
  5125. this.switchSelectionState = null;
  5126. // Selects editing cell
  5127. this.graph.setSelectionCell(cell);
  5128. // Enables focus outline for edges and edge labels
  5129. var parent = this.graph.getModel().getParent(cell);
  5130. var geo = this.graph.getCellGeometry(cell);
  5131. if ((this.graph.getModel().isEdge(parent) && geo != null && geo.relative) ||
  5132. this.graph.getModel().isEdge(cell))
  5133. {
  5134. // Quirks does not support outline at all so use border instead
  5135. if (mxClient.IS_QUIRKS)
  5136. {
  5137. this.textarea.style.border = 'gray dotted 1px';
  5138. }
  5139. // IE>8 and FF on Windows uses outline default of none
  5140. else if (mxClient.IS_IE || mxClient.IS_IE11 || (mxClient.IS_FF && mxClient.IS_WIN))
  5141. {
  5142. this.textarea.style.outline = 'gray dotted 1px';
  5143. }
  5144. else
  5145. {
  5146. this.textarea.style.outline = '';
  5147. }
  5148. }
  5149. else if (mxClient.IS_QUIRKS)
  5150. {
  5151. this.textarea.style.outline = 'none';
  5152. this.textarea.style.border = '';
  5153. }
  5154. }
  5155. /**
  5156. * HTML in-place editor
  5157. */
  5158. var cellEditorInstallListeners = mxCellEditor.prototype.installListeners;
  5159. mxCellEditor.prototype.installListeners = function(elt)
  5160. {
  5161. cellEditorInstallListeners.apply(this, arguments);
  5162. // Adds a reference from the clone to the original node, recursively
  5163. function reference(node, clone)
  5164. {
  5165. clone.originalNode = node;
  5166. node = node.firstChild;
  5167. var child = clone.firstChild;
  5168. while (node != null && child != null)
  5169. {
  5170. reference(node, child);
  5171. node = node.nextSibling;
  5172. child = child.nextSibling;
  5173. }
  5174. return clone;
  5175. };
  5176. // Checks the given node for new nodes, recursively
  5177. function checkNode(node, clone)
  5178. {
  5179. if (node != null)
  5180. {
  5181. if (clone.originalNode != node)
  5182. {
  5183. cleanNode(node);
  5184. }
  5185. else
  5186. {
  5187. node = node.firstChild;
  5188. clone = clone.firstChild;
  5189. while (node != null)
  5190. {
  5191. var nextNode = node.nextSibling;
  5192. if (clone == null)
  5193. {
  5194. cleanNode(node);
  5195. }
  5196. else
  5197. {
  5198. checkNode(node, clone);
  5199. clone = clone.nextSibling;
  5200. }
  5201. node = nextNode;
  5202. }
  5203. }
  5204. }
  5205. };
  5206. // Removes unused DOM nodes and attributes, recursively
  5207. function cleanNode(node)
  5208. {
  5209. var child = node.firstChild;
  5210. while (child != null)
  5211. {
  5212. var next = child.nextSibling;
  5213. cleanNode(child);
  5214. child = next;
  5215. }
  5216. if ((node.nodeType != 1 || (node.nodeName !== 'BR' && node.firstChild == null)) &&
  5217. (node.nodeType != 3 || mxUtils.trim(mxUtils.getTextContent(node)).length == 0))
  5218. {
  5219. node.parentNode.removeChild(node);
  5220. }
  5221. else
  5222. {
  5223. // Removes linefeeds
  5224. if (node.nodeType == 3)
  5225. {
  5226. mxUtils.setTextContent(node, mxUtils.getTextContent(node).replace(/\n|\r/g, ''));
  5227. }
  5228. // Removes CSS classes and styles (for Word and Excel)
  5229. if (node.nodeType == 1)
  5230. {
  5231. node.removeAttribute('style');
  5232. node.removeAttribute('class');
  5233. node.removeAttribute('width');
  5234. node.removeAttribute('cellpadding');
  5235. node.removeAttribute('cellspacing');
  5236. node.removeAttribute('border');
  5237. }
  5238. }
  5239. };
  5240. // Handles paste from Word, Excel etc by removing styles, classnames and unused nodes
  5241. // LATER: Fix undo/redo for paste
  5242. if (!mxClient.IS_QUIRKS && document.documentMode !== 7 && document.documentMode !== 8)
  5243. {
  5244. mxEvent.addListener(this.textarea, 'paste', mxUtils.bind(this, function(evt)
  5245. {
  5246. var clone = reference(this.textarea, this.textarea.cloneNode(true));
  5247. window.setTimeout(mxUtils.bind(this, function()
  5248. {
  5249. checkNode(this.textarea, clone);
  5250. }), 0);
  5251. }));
  5252. }
  5253. };
  5254. mxCellEditor.prototype.toggleViewMode = function()
  5255. {
  5256. var state = this.graph.view.getState(this.editingCell);
  5257. var nl2Br = state != null && mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  5258. var tmp = this.saveSelection();
  5259. if (!this.codeViewMode)
  5260. {
  5261. // Clears the initial empty label on the first keystroke
  5262. if (this.clearOnChange && this.textarea.innerHTML == this.getEmptyLabelText())
  5263. {
  5264. this.clearOnChange = false;
  5265. this.textarea.innerHTML = '';
  5266. }
  5267. // Removes newlines from HTML and converts breaks to newlines
  5268. // to match the HTML output in plain text
  5269. var content = mxUtils.htmlEntities(this.textarea.innerHTML);
  5270. // Workaround for trailing line breaks being ignored in the editor
  5271. if (!mxClient.IS_QUIRKS && document.documentMode != 8)
  5272. {
  5273. content = mxUtils.replaceTrailingNewlines(content, '<div><br></div>');
  5274. }
  5275. content = this.graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '').replace(/&lt;br\s*.?&gt;/g, '<br>') : content, true);
  5276. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  5277. var size = mxConstants.DEFAULT_FONTSIZE;
  5278. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  5279. this.textarea.style.fontSize = Math.round(size) + 'px';
  5280. this.textarea.style.textDecoration = '';
  5281. this.textarea.style.fontWeight = 'normal';
  5282. this.textarea.style.fontStyle = '';
  5283. this.textarea.style.fontFamily = mxConstants.DEFAULT_FONTFAMILY;
  5284. this.textarea.style.textAlign = 'left';
  5285. // Adds padding to make cursor visible with borders
  5286. this.textarea.style.padding = '2px';
  5287. if (this.textarea.innerHTML != content)
  5288. {
  5289. this.textarea.innerHTML = content;
  5290. }
  5291. this.codeViewMode = true;
  5292. }
  5293. else
  5294. {
  5295. var content = mxUtils.extractTextWithWhitespace(this.textarea.childNodes);
  5296. // Strips trailing line break
  5297. if (content.length > 0 && content.charAt(content.length - 1) == '\n')
  5298. {
  5299. content = content.substring(0, content.length - 1);
  5300. }
  5301. content = this.graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '<br/>') : content, true)
  5302. this.textarea.className = 'mxCellEditor geContentEditable';
  5303. var size = mxUtils.getValue(state.style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  5304. var family = mxUtils.getValue(state.style, mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY);
  5305. var align = mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_LEFT);
  5306. var bold = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  5307. mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD;
  5308. var italic = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  5309. mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC;
  5310. var uline = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  5311. mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE;
  5312. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  5313. this.textarea.style.fontSize = Math.round(size) + 'px';
  5314. this.textarea.style.textDecoration = (uline) ? 'underline' : '';
  5315. this.textarea.style.fontWeight = (bold) ? 'bold' : 'normal';
  5316. this.textarea.style.fontStyle = (italic) ? 'italic' : '';
  5317. this.textarea.style.fontFamily = family;
  5318. this.textarea.style.textAlign = align;
  5319. this.textarea.style.padding = '0px';
  5320. if (this.textarea.innerHTML != content)
  5321. {
  5322. this.textarea.innerHTML = content;
  5323. if (this.textarea.innerHTML.length == 0)
  5324. {
  5325. this.textarea.innerHTML = this.getEmptyLabelText();
  5326. this.clearOnChange = this.textarea.innerHTML.length > 0;
  5327. }
  5328. }
  5329. this.codeViewMode = false;
  5330. }
  5331. this.textarea.focus();
  5332. if (this.switchSelectionState != null)
  5333. {
  5334. this.restoreSelection(this.switchSelectionState);
  5335. }
  5336. this.switchSelectionState = tmp;
  5337. this.resize();
  5338. };
  5339. var mxCellEditorResize = mxCellEditor.prototype.resize;
  5340. mxCellEditor.prototype.resize = function(state, trigger)
  5341. {
  5342. if (this.textarea != null)
  5343. {
  5344. var state = this.graph.getView().getState(this.editingCell);
  5345. if (this.codeViewMode && state != null)
  5346. {
  5347. var scale = state.view.scale;
  5348. this.bounds = mxRectangle.fromRectangle(state);
  5349. // General placement of code editor if cell has no size
  5350. // LATER: Fix HTML editor bounds for edge labels
  5351. if (this.bounds.width == 0 && this.bounds.height == 0)
  5352. {
  5353. this.bounds.width = 160 * scale;
  5354. this.bounds.height = 60 * scale;
  5355. var m = (state.text != null) ? state.text.margin : null;
  5356. if (m == null)
  5357. {
  5358. m = mxUtils.getAlignmentAsPoint(mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER),
  5359. mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE));
  5360. }
  5361. this.bounds.x += m.x * this.bounds.width;
  5362. this.bounds.y += m.y * this.bounds.height;
  5363. }
  5364. this.textarea.style.width = Math.round((this.bounds.width - 4) / scale) + 'px';
  5365. this.textarea.style.height = Math.round((this.bounds.height - 4) / scale) + 'px';
  5366. this.textarea.style.overflow = 'auto';
  5367. // Adds scrollbar offset if visible
  5368. if (this.textarea.clientHeight < this.textarea.offsetHeight)
  5369. {
  5370. this.textarea.style.height = Math.round((this.bounds.height / scale)) + (this.textarea.offsetHeight - this.textarea.clientHeight) + 'px';
  5371. this.bounds.height = parseInt(this.textarea.style.height) * scale;
  5372. }
  5373. if (this.textarea.clientWidth < this.textarea.offsetWidth)
  5374. {
  5375. this.textarea.style.width = Math.round((this.bounds.width / scale)) + (this.textarea.offsetWidth - this.textarea.clientWidth) + 'px';
  5376. this.bounds.width = parseInt(this.textarea.style.width) * scale;
  5377. }
  5378. this.textarea.style.left = Math.round(this.bounds.x) + 'px';
  5379. this.textarea.style.top = Math.round(this.bounds.y) + 'px';
  5380. if (mxClient.IS_VML)
  5381. {
  5382. this.textarea.style.zoom = scale;
  5383. }
  5384. else
  5385. {
  5386. mxUtils.setPrefixedStyle(this.textarea.style, 'transform', 'scale(' + scale + ',' + scale + ')');
  5387. }
  5388. }
  5389. else
  5390. {
  5391. this.textarea.style.height = '';
  5392. this.textarea.style.overflow = '';
  5393. mxCellEditorResize.apply(this, arguments);
  5394. }
  5395. }
  5396. };
  5397. mxCellEditorGetInitialValue = mxCellEditor.prototype.getInitialValue;
  5398. mxCellEditor.prototype.getInitialValue = function(state, trigger)
  5399. {
  5400. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  5401. {
  5402. return mxCellEditorGetInitialValue.apply(this, arguments);
  5403. }
  5404. else
  5405. {
  5406. var result = this.graph.getEditingValue(state.cell, trigger)
  5407. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  5408. {
  5409. result = result.replace(/\n/g, '<br/>');
  5410. }
  5411. result = this.graph.sanitizeHtml(result, true);
  5412. return result;
  5413. }
  5414. };
  5415. mxCellEditorGetCurrentValue = mxCellEditor.prototype.getCurrentValue;
  5416. mxCellEditor.prototype.getCurrentValue = function(state)
  5417. {
  5418. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  5419. {
  5420. return mxCellEditorGetCurrentValue.apply(this, arguments);
  5421. }
  5422. else
  5423. {
  5424. var result = this.graph.sanitizeHtml(this.textarea.innerHTML, true);
  5425. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  5426. {
  5427. result = result.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
  5428. }
  5429. else
  5430. {
  5431. result = result.replace(/\r\n/g, '').replace(/\n/g, '');
  5432. }
  5433. return result;
  5434. }
  5435. };
  5436. var mxCellEditorStopEditing = mxCellEditor.prototype.stopEditing;
  5437. mxCellEditor.prototype.stopEditing = function(cancel)
  5438. {
  5439. // Restores default view mode before applying value
  5440. if (this.codeViewMode)
  5441. {
  5442. this.toggleViewMode();
  5443. }
  5444. mxCellEditorStopEditing.apply(this, arguments);
  5445. // Tries to move focus back to container after editing if possible
  5446. try
  5447. {
  5448. this.graph.container.focus();
  5449. }
  5450. catch (e)
  5451. {
  5452. // ignore
  5453. }
  5454. };
  5455. var mxCellEditorApplyValue = mxCellEditor.prototype.applyValue;
  5456. mxCellEditor.prototype.applyValue = function(state, value)
  5457. {
  5458. // Removes empty relative child labels in edges
  5459. this.graph.getModel().beginUpdate();
  5460. try
  5461. {
  5462. mxCellEditorApplyValue.apply(this, arguments);
  5463. if (this.graph.isCellDeletable(state.cell) && this.graph.model.getChildCount(state.cell) == 0)
  5464. {
  5465. var stroke = mxUtils.getValue(state.style, mxConstants.STYLE_STROKECOLOR, mxConstants.NONE);
  5466. var fill = mxUtils.getValue(state.style, mxConstants.STYLE_FILLCOLOR, mxConstants.NONE);
  5467. if (value == '' && stroke == mxConstants.NONE && fill == mxConstants.NONE)
  5468. {
  5469. this.graph.removeCells([state.cell], false);
  5470. }
  5471. }
  5472. }
  5473. finally
  5474. {
  5475. this.graph.getModel().endUpdate();
  5476. }
  5477. };
  5478. /**
  5479. * Returns the background color to be used for the editing box. This returns
  5480. * the label background for edge labels and null for all other cases.
  5481. */
  5482. mxCellEditor.prototype.getBackgroundColor = function(state)
  5483. {
  5484. var color = null;
  5485. if (this.graph.getModel().isEdge(state.cell) || this.graph.getModel().isEdge(this.graph.getModel().getParent(state.cell)))
  5486. {
  5487. var color = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, null);
  5488. if (color == mxConstants.NONE)
  5489. {
  5490. color = null;
  5491. }
  5492. }
  5493. return color;
  5494. };
  5495. mxCellEditor.prototype.getMinimumSize = function(state)
  5496. {
  5497. var scale = this.graph.getView().scale;
  5498. return new mxRectangle(0, 0, (state.text == null) ? 30 : state.text.size * scale + 20, 30);
  5499. };
  5500. // Hold alt to ignore drop target
  5501. var mxGraphHandlerMoveCells = mxGraphHandler.prototype.moveCells;
  5502. mxGraphHandler.prototype.moveCells = function(cells, dx, dy, clone, target, evt)
  5503. {
  5504. if (mxEvent.isAltDown(evt))
  5505. {
  5506. target = null;
  5507. }
  5508. mxGraphHandlerMoveCells.apply(this, arguments);
  5509. };
  5510. /**
  5511. * Hints on handlers
  5512. */
  5513. function createHint()
  5514. {
  5515. var hint = document.createElement('div');
  5516. hint.className = 'geHint';
  5517. hint.style.whiteSpace = 'nowrap';
  5518. hint.style.position = 'absolute';
  5519. return hint;
  5520. };
  5521. /**
  5522. * Updates the hint for the current operation.
  5523. */
  5524. mxGraphHandler.prototype.updateHint = function(me)
  5525. {
  5526. if (this.shape != null)
  5527. {
  5528. if (this.hint == null)
  5529. {
  5530. this.hint = createHint();
  5531. this.graph.container.appendChild(this.hint);
  5532. }
  5533. var t = this.graph.view.translate;
  5534. var s = this.graph.view.scale;
  5535. var x = this.roundLength((this.bounds.x + this.currentDx) / s - t.x);
  5536. var y = this.roundLength((this.bounds.y + this.currentDy) / s - t.y);
  5537. this.hint.innerHTML = x + ', ' + y;
  5538. this.hint.style.left = (this.shape.bounds.x + Math.round((this.shape.bounds.width - this.hint.clientWidth) / 2)) + 'px';
  5539. this.hint.style.top = (this.shape.bounds.y + this.shape.bounds.height + 12) + 'px';
  5540. }
  5541. };
  5542. /**
  5543. * Updates the hint for the current operation.
  5544. */
  5545. mxGraphHandler.prototype.removeHint = function()
  5546. {
  5547. if (this.hint != null)
  5548. {
  5549. this.hint.parentNode.removeChild(this.hint);
  5550. this.hint = null;
  5551. }
  5552. };
  5553. /**
  5554. * Enables recursive resize for groups.
  5555. */
  5556. mxVertexHandler.prototype.isRecursiveResize = function(state, me)
  5557. {
  5558. return !this.graph.isSwimlane(state.cell) && this.graph.model.getChildCount(state.cell) > 0 &&
  5559. !mxEvent.isControlDown(me.getEvent()) && !this.graph.isCellCollapsed(state.cell) &&
  5560. mxUtils.getValue(state.style, 'recursiveResize', '1') == '1' &&
  5561. mxUtils.getValue(state.style, 'childLayout', null) == null;
  5562. };
  5563. /**
  5564. * Enables centered resize events.
  5565. */
  5566. mxVertexHandler.prototype.isCenteredEvent = function(state, me)
  5567. {
  5568. return (!(!this.graph.isSwimlane(state.cell) && this.graph.model.getChildCount(state.cell) > 0 &&
  5569. !this.graph.isCellCollapsed(state.cell) &&
  5570. mxUtils.getValue(state.style, 'recursiveResize', '1') == '1' &&
  5571. mxUtils.getValue(state.style, 'childLayout', null) == null) &&
  5572. mxEvent.isControlDown(me.getEvent())) ||
  5573. mxEvent.isMetaDown(me.getEvent());
  5574. };
  5575. var vertexHandlerGetHandlePadding = mxVertexHandler.prototype.getHandlePadding;
  5576. mxVertexHandler.prototype.getHandlePadding = function()
  5577. {
  5578. var result = new mxPoint(0, 0);
  5579. var tol = this.tolerance;
  5580. if (this.graph.cellEditor.getEditingCell() == this.state.cell &&
  5581. this.sizers != null && this.sizers.length > 0 && this.sizers[0] != null)
  5582. {
  5583. tol /= 2;
  5584. result.x = this.sizers[0].bounds.width + tol;
  5585. result.y = this.sizers[0].bounds.height + tol;
  5586. }
  5587. else
  5588. {
  5589. result = vertexHandlerGetHandlePadding.apply(this, arguments);
  5590. }
  5591. return result;
  5592. };
  5593. /**
  5594. * Updates the hint for the current operation.
  5595. */
  5596. mxVertexHandler.prototype.updateHint = function(me)
  5597. {
  5598. if (this.index != mxEvent.LABEL_HANDLE)
  5599. {
  5600. if (this.hint == null)
  5601. {
  5602. this.hint = createHint();
  5603. this.state.view.graph.container.appendChild(this.hint);
  5604. }
  5605. if (this.index == mxEvent.ROTATION_HANDLE)
  5606. {
  5607. this.hint.innerHTML = this.currentAlpha + '&deg;';
  5608. }
  5609. else
  5610. {
  5611. var s = this.state.view.scale;
  5612. this.hint.innerHTML = this.roundLength(this.bounds.width / s) + ' x ' + this.roundLength(this.bounds.height / s);
  5613. }
  5614. var rot = (this.currentAlpha != null) ? this.currentAlpha : this.state.style[mxConstants.STYLE_ROTATION] || '0';
  5615. var bb = mxUtils.getBoundingBox(this.bounds, rot);
  5616. if (bb == null)
  5617. {
  5618. bb = this.bounds;
  5619. }
  5620. this.hint.style.left = bb.x + Math.round((bb.width - this.hint.clientWidth) / 2) + 'px';
  5621. this.hint.style.top = (bb.y + bb.height + 12) + 'px';
  5622. }
  5623. };
  5624. /**
  5625. * Updates the hint for the current operation.
  5626. */
  5627. mxVertexHandler.prototype.removeHint = mxGraphHandler.prototype.removeHint;
  5628. /**
  5629. * Updates the hint for the current operation.
  5630. */
  5631. mxEdgeHandler.prototype.updateHint = function(me, point)
  5632. {
  5633. if (this.hint == null)
  5634. {
  5635. this.hint = createHint();
  5636. this.state.view.graph.container.appendChild(this.hint);
  5637. }
  5638. var t = this.graph.view.translate;
  5639. var s = this.graph.view.scale;
  5640. var x = this.roundLength(point.x / s - t.x);
  5641. var y = this.roundLength(point.y / s - t.y);
  5642. this.hint.innerHTML = x + ', ' + y;
  5643. this.hint.style.visibility = 'visible';
  5644. if (this.isSource || this.isTarget)
  5645. {
  5646. if (this.constraintHandler.currentConstraint != null &&
  5647. this.constraintHandler.currentFocus != null)
  5648. {
  5649. var pt = this.constraintHandler.currentConstraint.point;
  5650. this.hint.innerHTML = '[' + Math.round(pt.x * 100) + '%, '+ Math.round(pt.y * 100) + '%]';
  5651. }
  5652. else if (this.marker.hasValidState())
  5653. {
  5654. this.hint.style.visibility = 'hidden';
  5655. }
  5656. }
  5657. this.hint.style.left = Math.round(me.getGraphX() - this.hint.clientWidth / 2) + 'px';
  5658. this.hint.style.top = (Math.max(me.getGraphY(), point.y) + this.state.view.graph.gridSize) + 'px';
  5659. if (this.hideEdgeHintThread != null)
  5660. {
  5661. window.clearTimeout(this.hideEdgeHintThread);
  5662. }
  5663. this.hideEdgeHintThread = window.setTimeout(mxUtils.bind(this, function()
  5664. {
  5665. if (this.hint != null)
  5666. {
  5667. this.hint.style.visibility = 'hidden';
  5668. }
  5669. }), 500);
  5670. };
  5671. /**
  5672. * Updates the hint for the current operation.
  5673. */
  5674. mxEdgeHandler.prototype.removeHint = mxGraphHandler.prototype.removeHint;
  5675. /**
  5676. * Defines the handles for the UI. Uses data-URIs to speed-up loading time where supported.
  5677. */
  5678. HoverIcons.prototype.mainHandle = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAACXBIWXMAAAsTAAALEwEAmpwYAAABLUlEQVQ4y61US4rCQBBNeojiRrLSnbMOWWU3V1FPouARcgc9hyLOCSSbYZw5gRCIkM9KbevJaycS4zCOBY+iq6pf1y+xrNtiE6oEY/tVzMUXgSNoCJrUDu3qHpldutwSuIKOoEvt0m7I7DoCvNj2fb8XRdEojuN5lmVraJxhh59xFSLFF9phGL7lef6hRb63R73aHM8aAjv8JHJ47yqLlud5r0VRbHa51sPZQVuT/QU4ww4/4ljaJRubrC5SxouD6TWBQV/sEIkbs0eOIVGssSO1L5D6LQID+BHHZjdMSYpj7KZpun7/uk8CP5rNqTXLJP/OpNyTMWruP9CTP08nCILKdCp7gkCzJ8vPnz2BvW5PKhuLjJBykiQLaWIEjTP3o3Zjn/LtPO0rfvh/cgKu7z6wtPPltQAAAABJRU5ErkJggg==' :
  5679. IMAGE_PATH + '/handle-main.png', 17, 17);
  5680. HoverIcons.prototype.fixedHandle = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NkE1NkU4Njk2QjI1MTFFNEFDMjFGQTcyODkzNTc3NkYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NkE1NkU4NkE2QjI1MTFFNEFDMjFGQTcyODkzNTc3NkYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo2QTU2RTg2NzZCMjUxMUU0QUMyMUZBNzI4OTM1Nzc2RiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo2QTU2RTg2ODZCMjUxMUU0QUMyMUZBNzI4OTM1Nzc2RiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pmuk6K8AAAGBSURBVHjarFRBSsNQEM3/atNs6qLowixcKELoqjuXoqfQeoF6BMEj9BCC1YIXcCGlV8hGLNZlBKWlCk1JSs13Xvw/nca6UDrwmMzMy8tk/iTCWmwi52Eq53+QeWwg2bXSSNi1WiRibgRWCTahwEQmhJgw1WJGML2BC6wQnEqlsuH7fr3f7zdHo9EdPGLkUdc8mX8TJNYIpUajsR+G4YMie3pNVKebpB6GPOrgab7kr5F24Hne9ng87r6HStUuP5V1Mc2AGHnUwWMdCck6sVut1onjOHtnt4nV7M0fAuI65VEnXk3PTFq5Eyi4rnvUe1PW9fO3QOdUzvkbyqNOvEM2dMEHK2zbLr98zJ5+cJWkAvDGUC8Wi2X28Gww6bnHcTzYWp+JGAHTCQz1KIoGfFckCyZBELR3N4V1vCOyTrhHHnXw9N5kQn8+nWq1Onc6C/cERLMn7cfZniD/257wbjDxEjqiDT0fDof3tLE+PGK9HyXNy7pYyrez9K/43/+TLwEGAMb7AY6w980DAAAAAElFTkSuQmCC' :
  5681. IMAGE_PATH + '/handle-fixed.png', 17, 17);
  5682. HoverIcons.prototype.terminalHandle = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MEMzRUVERTk2NzU1MTFFNTg5NjNEMjREQ0FFNENFQzgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MEMzRUVERUE2NzU1MTFFNTg5NjNEMjREQ0FFNENFQzgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowQzNFRURFNzY3NTUxMUU1ODk2M0QyNERDQUU0Q0VDOCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowQzNFRURFODY3NTUxMUU1ODk2M0QyNERDQUU0Q0VDOCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Poj8AGUAAAF6SURBVHjarFTBSsNAEM2u2jSXeCh6sAcPilB6ys2j6Fdo/YH6CYKf0I8QrBb8AQ9S+gu5iMV6jKC0VCEJTalZ54VNnMR4ULrwmJ2Zt5PZmdkIo3yJgsRSBfmDzPUUku2VRsz2qixIehBYJZiECgsyJ0SEhQ6WBkwO8AArBKvZbG64rtsej8dd3/fvIKHDDr/myeJNYFgj2J1OZz8IggdF6+k1VoNhnEgs2OEHT/Mlv0aSQaPR2A7DcPgeKNW6/FTGxSIDdNjhB49lJCTLxOz1eieWZe2d3cZGd5RvAvQ22eEnXkvXTBqFDlTq9frR6E0Z18+qtO83ZIefeIes6IIXVpimWXv5yB8cnMqcDn+1Wq2xj2eFSfoeRdFkaz0f5OAqzunwz2azCZ8VyZS553n93U1hHO+I0uvADj94em6yQH/ujuM4ue6UzgmI6Zz0H7/nBPbf5oRng4rbyIgm9Hw6nd7TxLqQ0PV82JqXZbGUt7P0V/zv/8mXAAMASSz1f9Cd7ycAAAAASUVORK5CYII=' :
  5683. IMAGE_PATH + '/handle-terminal.png', 17, 17);
  5684. HoverIcons.prototype.secondaryHandle = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MEJBMUVERjNEMkZDMTFFM0I0Qzc5RkE1RTc2NjI0OUIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MEJBMUVERjREMkZDMTFFM0I0Qzc5RkE1RTc2NjI0OUIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowQkExRURGMUQyRkMxMUUzQjRDNzlGQTVFNzY2MjQ5QiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowQkExRURGMkQyRkMxMUUzQjRDNzlGQTVFNzY2MjQ5QiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PvXDOj4AAAFqSURBVHjarFTNToNAEN5FLeiBmDRe7MGLF4IXbp71KapP4CPoO/QdvKiv4ME0PkAvJI2J0SueIHgAAk3b7XxkwSlgE38mmSwz8+3HsPMtUnSbbKww1VhbYB5XbrBnpX3JnlUXSbURvk1ukvcYyYy8IJ9rsoqw3MAJtsh3Xdc98H3/KgzDuyRJHrEiRh51jTOaX4LEDrk9Go1O0zR9UWTL9E0to+dyhSGPOnAab/DPKDtwHOcoy7LXz1SpxeRSzW9F7YiRRx041pGsSMC6Ty1f442LycUawRfRsOyIcDfA632ST6A3GAzOVfYu1PS+c+5q+iBQJ9wZO3TJD1aaptkX+YfYaFS3LKvPXl4fTDn3oigiYR1uJqF6nucR14rBglkQBGO5dyzkybBbxpRHHTitm5rox9PxPK81nZZOAKx1Eo5rnSD/nU54NzhxGx1hjHEcP5FifayItT5sjVvTyJ/vzr/f4l//T1YCDAC4VAdLL1OIRAAAAABJRU5ErkJggg==' :
  5685. IMAGE_PATH + '/handle-secondary.png', 17, 17);
  5686. HoverIcons.prototype.rotationHandle = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAVCAYAAACkCdXRAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAA6ZJREFUeNqM001IY1cUB/D/fYmm2sbR2lC1zYlgoRG6MpEyBlpxM9iFIGKFIm3s0lCKjOByhCLZCFqLBF1YFVJdSRbdFHRhBbULtRuFVBTzYRpJgo2mY5OX5N9Fo2TG+eiFA/dd3vvd8+65ByTxshARTdf1JySp6/oTEdFe9T5eg5lIcnBwkCSZyWS+exX40oyur68/KxaLf5Okw+H4X+A9JBaLfUySZ2dnnJqaosPhIAACeC34DJRKpb7IZrMcHx+nwWCgUopGo/EOKwf9fn/1CzERUevr6+9ls1mOjIwQAH0+H4PBIKPR6D2ofAQCgToRUeVYJUkuLy8TANfW1kiS8/PzCy84Mw4MDBAAZ2dnmc/nub+/X0MSEBF1cHDwMJVKsaGhgV6vl+l0mqOjo1+KyKfl1dze3l4NBoM/PZ+diFSLiIKIGBOJxA9bW1sEwNXVVSaTyQMRaRaRxrOzs+9J8ujoaE5EPhQRq67rcZ/PRwD0+/3Udf03EdEgIqZisZibnJykwWDg4eEhd3Z2xkXELCJvPpdBrYjUiEhL+Xo4HH4sIhUaAKNSqiIcDsNkMqG+vh6RSOQQQM7tdhsAQCkFAHC73UUATxcWFqypVApmsxnDw8OwWq2TADQNgAYAFosF+XweyWQSdru9BUBxcXFRB/4rEgDcPouIIx6P4+bmBi0tLSCpAzBqAIqnp6c/dnZ2IpfLYXNzE62traMADACKNputpr+/v8lms9UAKAAwiMjXe3t7KBQKqKurQy6Xi6K0i2l6evpROp1mbW0t29vbGY/Hb8/IVIqq2zlJXl1dsaOjg2azmefn5wwEAl+JSBVExCgi75PkzMwMlVJsbGxkIpFgPp8PX15ePopEIs3JZPITXdf/iEajbGpqolKKExMT1HWdHo/nIxGpgIgoEXnQ3d39kCTHxsYIgC6Xi3NzcwyHw8xkMozFYlxaWmJbWxuVUuzt7WUul6PX6/1cRN4WEe2uA0SkaWVl5XGpRVhdXU0A1DSNlZWVdz3qdDrZ09PDWCzG4+Pjn0XEWvp9KJKw2WwKwBsA3gHQHAqFfr24uMDGxgZ2d3cRiUQAAHa7HU6nE319fTg5Ofmlq6vrGwB/AngaCoWK6rbsNptNA1AJoA7Aux6Pp3NoaMhjsVg+QNmIRqO/u1yubwFEASRKUAEA7rASqABUAKgC8KAUb5XWCOAfAFcA/gJwDSB7C93DylCtdM8qABhLc5TumV6KQigUeubjfwcAHkQJ94ndWeYAAAAASUVORK5CYII=' :
  5687. IMAGE_PATH + '/handle-rotate.png', 19, 21);
  5688. mxVertexHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  5689. mxVertexHandler.prototype.secondaryHandleImage = HoverIcons.prototype.secondaryHandle;
  5690. mxEdgeHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  5691. mxEdgeHandler.prototype.terminalHandleImage = HoverIcons.prototype.terminalHandle;
  5692. mxEdgeHandler.prototype.fixedHandleImage = HoverIcons.prototype.fixedHandle;
  5693. mxEdgeHandler.prototype.labelHandleImage = HoverIcons.prototype.secondaryHandle;
  5694. mxOutline.prototype.sizerImage = HoverIcons.prototype.mainHandle;
  5695. if (window.Sidebar != null)
  5696. {
  5697. Sidebar.prototype.triangleUp = HoverIcons.prototype.triangleUp;
  5698. Sidebar.prototype.triangleRight = HoverIcons.prototype.triangleRight;
  5699. Sidebar.prototype.triangleDown = HoverIcons.prototype.triangleDown;
  5700. Sidebar.prototype.triangleLeft = HoverIcons.prototype.triangleLeft;
  5701. Sidebar.prototype.refreshTarget = HoverIcons.prototype.refreshTarget;
  5702. Sidebar.prototype.roundDrop = HoverIcons.prototype.roundDrop;
  5703. }
  5704. // Pre-fetches images (only needed for non data-uris)
  5705. if (!mxClient.IS_SVG)
  5706. {
  5707. new Image().src = HoverIcons.prototype.mainHandle.src;
  5708. new Image().src = HoverIcons.prototype.fixedHandle.src;
  5709. new Image().src = HoverIcons.prototype.terminalHandle.src;
  5710. new Image().src = HoverIcons.prototype.secondaryHandle.src;
  5711. new Image().src = HoverIcons.prototype.rotationHandle.src;
  5712. new Image().src = HoverIcons.prototype.triangleUp.src;
  5713. new Image().src = HoverIcons.prototype.triangleRight.src;
  5714. new Image().src = HoverIcons.prototype.triangleDown.src;
  5715. new Image().src = HoverIcons.prototype.triangleLeft.src;
  5716. new Image().src = HoverIcons.prototype.refreshTarget.src;
  5717. new Image().src = HoverIcons.prototype.roundDrop.src;
  5718. }
  5719. // Adds rotation handle and live preview
  5720. mxVertexHandler.prototype.rotationEnabled = true;
  5721. mxVertexHandler.prototype.manageSizers = true;
  5722. mxVertexHandler.prototype.livePreview = true;
  5723. // Increases default rubberband opacity (default is 20)
  5724. mxRubberband.prototype.defaultOpacity = 30;
  5725. // Enables connections along the outline, virtual waypoints, parent highlight etc
  5726. mxConnectionHandler.prototype.outlineConnect = true;
  5727. mxCellHighlight.prototype.keepOnTop = true;
  5728. mxVertexHandler.prototype.parentHighlightEnabled = true;
  5729. mxVertexHandler.prototype.rotationHandleVSpacing = -20;
  5730. mxEdgeHandler.prototype.parentHighlightEnabled = true;
  5731. mxEdgeHandler.prototype.dblClickRemoveEnabled = true;
  5732. mxEdgeHandler.prototype.straightRemoveEnabled = true;
  5733. mxEdgeHandler.prototype.virtualBendsEnabled = true;
  5734. mxEdgeHandler.prototype.mergeRemoveEnabled = true;
  5735. mxEdgeHandler.prototype.manageLabelHandle = true;
  5736. mxEdgeHandler.prototype.outlineConnect = true;
  5737. // Disables adding waypoints if shift is pressed
  5738. mxEdgeHandler.prototype.isAddVirtualBendEvent = function(me)
  5739. {
  5740. return !mxEvent.isShiftDown(me.getEvent());
  5741. };
  5742. // Disables custom handles if shift is pressed
  5743. mxEdgeHandler.prototype.isCustomHandleEvent = function(me)
  5744. {
  5745. return !mxEvent.isShiftDown(me.getEvent());
  5746. };
  5747. /**
  5748. * Implements touch style
  5749. */
  5750. if (Graph.touchStyle)
  5751. {
  5752. // Larger tolerance for real touch devices
  5753. if (mxClient.IS_TOUCH || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0)
  5754. {
  5755. mxShape.prototype.svgStrokeTolerance = 18;
  5756. mxVertexHandler.prototype.tolerance = 12;
  5757. mxEdgeHandler.prototype.tolerance = 12;
  5758. Graph.prototype.tolerance = 12;
  5759. mxVertexHandler.prototype.rotationHandleVSpacing = -24;
  5760. // Implements a smaller tolerance for mouse events and a larger tolerance for touch
  5761. // events on touch devices. The default tolerance (4px) is used for mouse events.
  5762. mxConstraintHandler.prototype.getTolerance = function(me)
  5763. {
  5764. return (mxEvent.isMouseEvent(me.getEvent())) ? 4 : this.graph.getTolerance();
  5765. };
  5766. }
  5767. // One finger pans (no rubberband selection) must start regardless of mouse button
  5768. mxPanningHandler.prototype.isPanningTrigger = function(me)
  5769. {
  5770. var evt = me.getEvent();
  5771. return (me.getState() == null && !mxEvent.isMouseEvent(evt)) ||
  5772. (mxEvent.isPopupTrigger(evt) && (me.getState() == null ||
  5773. mxEvent.isControlDown(evt) || mxEvent.isShiftDown(evt)));
  5774. };
  5775. // Don't clear selection if multiple cells selected
  5776. var graphHandlerMouseDown = mxGraphHandler.prototype.mouseDown;
  5777. mxGraphHandler.prototype.mouseDown = function(sender, me)
  5778. {
  5779. graphHandlerMouseDown.apply(this, arguments);
  5780. if (mxEvent.isTouchEvent(me.getEvent()) && this.graph.isCellSelected(me.getCell()) &&
  5781. this.graph.getSelectionCount() > 1)
  5782. {
  5783. this.delayedSelection = false;
  5784. }
  5785. };
  5786. }
  5787. else
  5788. {
  5789. // Removes ctrl+shift as panning trigger for space splitting
  5790. mxPanningHandler.prototype.isPanningTrigger = function(me)
  5791. {
  5792. var evt = me.getEvent();
  5793. return (mxEvent.isLeftMouseButton(evt) && ((this.useLeftButtonForPanning &&
  5794. me.getState() == null) || (mxEvent.isControlDown(evt) &&
  5795. !mxEvent.isShiftDown(evt)))) || (this.usePopupTrigger &&
  5796. mxEvent.isPopupTrigger(evt));
  5797. };
  5798. }
  5799. // Overrides/extends rubberband for space handling with Ctrl+Shift(+Alt) drag ("scissors tool")
  5800. mxRubberband.prototype.isSpaceEvent = function(me)
  5801. {
  5802. return this.graph.isEnabled() && !this.graph.isCellLocked(this.graph.getDefaultParent()) &&
  5803. mxEvent.isControlDown(me.getEvent()) && mxEvent.isShiftDown(me.getEvent());
  5804. };
  5805. // Handles moving of cells in both half panes
  5806. mxRubberband.prototype.mouseUp = function(sender, me)
  5807. {
  5808. var execute = this.div != null && this.div.style.display != 'none';
  5809. var x0 = null;
  5810. var y0 = null;
  5811. var dx = null;
  5812. var dy = null;
  5813. if (this.first != null && this.currentX != null && this.currentY != null)
  5814. {
  5815. x0 = this.first.x;
  5816. y0 = this.first.y;
  5817. dx = (this.currentX - x0) / this.graph.view.scale;
  5818. dy = (this.currentY - y0) / this.graph.view.scale;
  5819. if (!mxEvent.isAltDown(me.getEvent()))
  5820. {
  5821. dx = this.graph.snap(dx);
  5822. dy = this.graph.snap(dy);
  5823. if (!this.graph.isGridEnabled())
  5824. {
  5825. if (Math.abs(dx) < this.graph.tolerance)
  5826. {
  5827. dx = 0;
  5828. }
  5829. if (Math.abs(dy) < this.graph.tolerance)
  5830. {
  5831. dy = 0;
  5832. }
  5833. }
  5834. }
  5835. }
  5836. this.reset();
  5837. if (execute)
  5838. {
  5839. if (mxEvent.isAltDown(me.getEvent()) && this.graph.isToggleEvent(me.getEvent()))
  5840. {
  5841. var rect = new mxRectangle(this.x, this.y, this.width, this.height);
  5842. var cells = this.graph.getCells(rect.x, rect.y, rect.width, rect.height);
  5843. this.graph.removeSelectionCells(cells);
  5844. }
  5845. else if (this.isSpaceEvent(me))
  5846. {
  5847. this.graph.model.beginUpdate();
  5848. try
  5849. {
  5850. var cells = this.graph.getCellsBeyond(x0, y0, this.graph.getDefaultParent(), true, true);
  5851. for (var i = 0; i < cells.length; i++)
  5852. {
  5853. if (this.graph.isCellMovable(cells[i]))
  5854. {
  5855. var tmp = this.graph.view.getState(cells[i]);
  5856. var geo = this.graph.getCellGeometry(cells[i]);
  5857. if (tmp != null && geo != null)
  5858. {
  5859. geo = geo.clone();
  5860. geo.translate(dx, dy);
  5861. this.graph.model.setGeometry(cells[i], geo);
  5862. }
  5863. }
  5864. }
  5865. }
  5866. finally
  5867. {
  5868. this.graph.model.endUpdate();
  5869. }
  5870. }
  5871. else
  5872. {
  5873. var rect = new mxRectangle(this.x, this.y, this.width, this.height);
  5874. this.graph.selectRegion(rect, me.getEvent());
  5875. }
  5876. me.consume();
  5877. }
  5878. };
  5879. // Handles preview for creating/removing space in diagram
  5880. mxRubberband.prototype.mouseMove = function(sender, me)
  5881. {
  5882. if (!me.isConsumed() && this.first != null)
  5883. {
  5884. var origin = mxUtils.getScrollOrigin(this.graph.container);
  5885. var offset = mxUtils.getOffset(this.graph.container);
  5886. origin.x -= offset.x;
  5887. origin.y -= offset.y;
  5888. var x = me.getX() + origin.x;
  5889. var y = me.getY() + origin.y;
  5890. var dx = this.first.x - x;
  5891. var dy = this.first.y - y;
  5892. var tol = this.graph.tolerance;
  5893. if (this.div != null || Math.abs(dx) > tol || Math.abs(dy) > tol)
  5894. {
  5895. if (this.div == null)
  5896. {
  5897. this.div = this.createShape();
  5898. }
  5899. // Clears selection while rubberbanding. This is required because
  5900. // the event is not consumed in mouseDown.
  5901. mxUtils.clearSelection();
  5902. this.update(x, y);
  5903. if (this.isSpaceEvent(me))
  5904. {
  5905. var right = this.x + this.width;
  5906. var bottom = this.y + this.height;
  5907. var scale = this.graph.view.scale;
  5908. if (!mxEvent.isAltDown(me.getEvent()))
  5909. {
  5910. this.width = this.graph.snap(this.width / scale) * scale;
  5911. this.height = this.graph.snap(this.height / scale) * scale;
  5912. if (!this.graph.isGridEnabled())
  5913. {
  5914. if (this.width < this.graph.tolerance)
  5915. {
  5916. this.width = 0;
  5917. }
  5918. if (this.height < this.graph.tolerance)
  5919. {
  5920. this.height = 0;
  5921. }
  5922. }
  5923. if (this.x < this.first.x)
  5924. {
  5925. this.x = right - this.width;
  5926. }
  5927. if (this.y < this.first.y)
  5928. {
  5929. this.y = bottom - this.height;
  5930. }
  5931. }
  5932. this.div.style.borderStyle = 'dashed';
  5933. this.div.style.backgroundColor = 'white';
  5934. this.div.style.left = this.x + 'px';
  5935. this.div.style.top = this.y + 'px';
  5936. this.div.style.width = Math.max(0, this.width) + 'px';
  5937. this.div.style.height = this.graph.container.clientHeight + 'px';
  5938. this.div.style.borderWidth = (this.width <= 0) ? '0px 1px 0px 0px' : '0px 1px 0px 1px';
  5939. if (this.secondDiv == null)
  5940. {
  5941. this.secondDiv = this.div.cloneNode(true);
  5942. this.div.parentNode.appendChild(this.secondDiv);
  5943. }
  5944. this.secondDiv.style.left = this.x + 'px';
  5945. this.secondDiv.style.top = this.y + 'px';
  5946. this.secondDiv.style.width = this.graph.container.clientWidth + 'px';
  5947. this.secondDiv.style.height = Math.max(0, this.height) + 'px';
  5948. this.secondDiv.style.borderWidth = (this.height <= 0) ? '1px 0px 0px 0px' : '1px 0px 1px 0px';
  5949. }
  5950. else
  5951. {
  5952. // Hides second div and restores style
  5953. this.div.style.backgroundColor = '';
  5954. this.div.style.borderWidth = '';
  5955. this.div.style.borderStyle = '';
  5956. if (this.secondDiv != null)
  5957. {
  5958. this.secondDiv.parentNode.removeChild(this.secondDiv);
  5959. this.secondDiv = null;
  5960. }
  5961. }
  5962. me.consume();
  5963. }
  5964. }
  5965. };
  5966. // Removes preview
  5967. var mxRubberbandReset = mxRubberband.prototype.reset;
  5968. mxRubberband.prototype.reset = function()
  5969. {
  5970. if (this.secondDiv != null)
  5971. {
  5972. this.secondDiv.parentNode.removeChild(this.secondDiv);
  5973. this.secondDiv = null;
  5974. }
  5975. mxRubberbandReset.apply(this, arguments);
  5976. };
  5977. // Timer-based activation of outline connect in connection handler
  5978. var startTime = new Date().getTime();
  5979. var timeOnTarget = 0;
  5980. var mxEdgeHandlerUpdatePreviewState = mxEdgeHandler.prototype.updatePreviewState;
  5981. mxEdgeHandler.prototype.updatePreviewState = function(edge, point, terminalState, me)
  5982. {
  5983. mxEdgeHandlerUpdatePreviewState.apply(this, arguments);
  5984. if (terminalState != this.currentTerminalState)
  5985. {
  5986. startTime = new Date().getTime();
  5987. timeOnTarget = 0;
  5988. }
  5989. else
  5990. {
  5991. timeOnTarget = new Date().getTime() - startTime;
  5992. }
  5993. this.currentTerminalState = terminalState;
  5994. };
  5995. // Timer-based outline connect
  5996. var mxEdgeHandlerIsOutlineConnectEvent = mxEdgeHandler.prototype.isOutlineConnectEvent;
  5997. mxEdgeHandler.prototype.isOutlineConnectEvent = function(me)
  5998. {
  5999. return (this.currentTerminalState != null && me.getState() == this.currentTerminalState && timeOnTarget > 2000) ||
  6000. ((this.currentTerminalState == null || mxUtils.getValue(this.currentTerminalState.style, 'outlineConnect', '1') != '0') &&
  6001. mxEdgeHandlerIsOutlineConnectEvent.apply(this, arguments));
  6002. };
  6003. // Disables custom handles if shift is pressed
  6004. mxVertexHandler.prototype.isCustomHandleEvent = function(me)
  6005. {
  6006. return !mxEvent.isShiftDown(me.getEvent());
  6007. };
  6008. // Shows secondary handle for fixed connection points
  6009. mxEdgeHandler.prototype.createHandleShape = function(index, virtual)
  6010. {
  6011. var source = index != null && index == 0;
  6012. var terminalState = this.state.getVisibleTerminalState(source);
  6013. var c = (index != null && (index == 0 || index >= this.state.absolutePoints.length - 1 ||
  6014. (this.constructor == mxElbowEdgeHandler && index == 2))) ?
  6015. this.graph.getConnectionConstraint(this.state, terminalState, source) : null;
  6016. var pt = (c != null) ? this.graph.getConnectionPoint(this.state.getVisibleTerminalState(source), c) : null;
  6017. var img = (pt != null) ? this.fixedHandleImage : ((c != null && terminalState != null) ?
  6018. this.terminalHandleImage : this.handleImage);
  6019. if (img != null)
  6020. {
  6021. var shape = new mxImageShape(new mxRectangle(0, 0, img.width, img.height), img.src);
  6022. // Allows HTML rendering of the images
  6023. shape.preserveImageAspect = false;
  6024. return shape;
  6025. }
  6026. else
  6027. {
  6028. var s = mxConstants.HANDLE_SIZE;
  6029. if (this.preferHtml)
  6030. {
  6031. s -= 1;
  6032. }
  6033. return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  6034. }
  6035. };
  6036. var vertexHandlerCreateSizerShape = mxVertexHandler.prototype.createSizerShape;
  6037. mxVertexHandler.prototype.createSizerShape = function(bounds, index, fillColor)
  6038. {
  6039. this.handleImage = (index == mxEvent.ROTATION_HANDLE) ? HoverIcons.prototype.rotationHandle : (index == mxEvent.LABEL_HANDLE) ? this.secondaryHandleImage : this.handleImage;
  6040. return vertexHandlerCreateSizerShape.apply(this, arguments);
  6041. };
  6042. // Special case for single edge label handle moving in which case the text bounding box is used
  6043. var mxGraphHandlerGetBoundingBox = mxGraphHandler.prototype.getBoundingBox;
  6044. mxGraphHandler.prototype.getBoundingBox = function(cells)
  6045. {
  6046. if (cells != null && cells.length == 1)
  6047. {
  6048. var model = this.graph.getModel();
  6049. var parent = model.getParent(cells[0]);
  6050. var geo = this.graph.getCellGeometry(cells[0]);
  6051. if (model.isEdge(parent) && geo != null && geo.relative)
  6052. {
  6053. var state = this.graph.view.getState(cells[0]);
  6054. if (state != null && state.width < 2 && state.height < 2 && state.text != null && state.text.boundingBox != null)
  6055. {
  6056. return mxRectangle.fromRectangle(state.text.boundingBox);
  6057. }
  6058. }
  6059. }
  6060. return mxGraphHandlerGetBoundingBox.apply(this, arguments);
  6061. };
  6062. // Uses text bounding box for edge labels
  6063. var mxVertexHandlerGetSelectionBounds = mxVertexHandler.prototype.getSelectionBounds;
  6064. mxVertexHandler.prototype.getSelectionBounds = function(state)
  6065. {
  6066. var model = this.graph.getModel();
  6067. var parent = model.getParent(state.cell);
  6068. var geo = this.graph.getCellGeometry(state.cell);
  6069. if (model.isEdge(parent) && geo != null && geo.relative && state.width < 2 && state.height < 2 && state.text != null && state.text.boundingBox != null)
  6070. {
  6071. var bbox = state.text.unrotatedBoundingBox || state.text.boundingBox;
  6072. return new mxRectangle(Math.round(bbox.x), Math.round(bbox.y), Math.round(bbox.width), Math.round(bbox.height));
  6073. }
  6074. else
  6075. {
  6076. return mxVertexHandlerGetSelectionBounds.apply(this, arguments);
  6077. }
  6078. };
  6079. // Redirects moving of edge labels to mxGraphHandler by not starting here.
  6080. // This will use the move preview of mxGraphHandler (see above).
  6081. var mxVertexHandlerMouseDown = mxVertexHandler.prototype.mouseDown;
  6082. mxVertexHandler.prototype.mouseDown = function(sender, me)
  6083. {
  6084. var model = this.graph.getModel();
  6085. var parent = model.getParent(this.state.cell);
  6086. var geo = this.graph.getCellGeometry(this.state.cell);
  6087. // Lets rotation events through
  6088. var handle = this.getHandleForEvent(me);
  6089. if (handle == mxEvent.ROTATION_HANDLE || !model.isEdge(parent) || geo == null || !geo.relative ||
  6090. this.state == null || this.state.width >= 2 || this.state.height >= 2)
  6091. {
  6092. mxVertexHandlerMouseDown.apply(this, arguments);
  6093. }
  6094. };
  6095. // Shows rotation handle for edge labels.
  6096. mxVertexHandler.prototype.isRotationHandleVisible = function()
  6097. {
  6098. return this.graph.isEnabled() && this.rotationEnabled && this.graph.isCellRotatable(this.state.cell) &&
  6099. (mxGraphHandler.prototype.maxCells <= 0 || this.graph.getSelectionCount() < mxGraphHandler.prototype.maxCells);
  6100. };
  6101. // Invokes turn on single click on rotation handle
  6102. mxVertexHandler.prototype.rotateClick = function()
  6103. {
  6104. this.state.view.graph.turnShapes([this.state.cell]);
  6105. };
  6106. var vertexHandlerMouseMove = mxVertexHandler.prototype.mouseMove;
  6107. // Workaround for "isConsumed not defined" in MS Edge is to use arguments
  6108. mxVertexHandler.prototype.mouseMove = function(sender, me)
  6109. {
  6110. vertexHandlerMouseMove.apply(this, arguments);
  6111. if (this.graph.graphHandler.first != null)
  6112. {
  6113. if (this.rotationShape != null && this.rotationShape.node != null)
  6114. {
  6115. this.rotationShape.node.style.display = 'none';
  6116. }
  6117. }
  6118. };
  6119. var vertexHandlerMouseUp = mxVertexHandler.prototype.mouseUp;
  6120. mxVertexHandler.prototype.mouseUp = function(sender, me)
  6121. {
  6122. vertexHandlerMouseUp.apply(this, arguments);
  6123. // Shows rotation handle only if one vertex is selected
  6124. if (this.rotationShape != null && this.rotationShape.node != null)
  6125. {
  6126. this.rotationShape.node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  6127. }
  6128. };
  6129. var vertexHandlerInit = mxVertexHandler.prototype.init;
  6130. mxVertexHandler.prototype.init = function()
  6131. {
  6132. vertexHandlerInit.apply(this, arguments);
  6133. var redraw = false;
  6134. if (this.rotationShape != null)
  6135. {
  6136. this.rotationShape.node.setAttribute('title', mxResources.get('rotateTooltip'));
  6137. }
  6138. var update = mxUtils.bind(this, function()
  6139. {
  6140. // Shows rotation handle only if one vertex is selected
  6141. if (this.rotationShape != null && this.rotationShape.node != null)
  6142. {
  6143. this.rotationShape.node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  6144. }
  6145. if (this.specialHandle != null)
  6146. {
  6147. this.specialHandle.node.style.display = (this.graph.isEnabled() && this.graph.getSelectionCount() < this.graph.graphHandler.maxCells) ? '' : 'none';
  6148. }
  6149. this.redrawHandles();
  6150. });
  6151. this.selectionHandler = mxUtils.bind(this, function(sender, evt)
  6152. {
  6153. update();
  6154. });
  6155. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.selectionHandler);
  6156. this.changeHandler = mxUtils.bind(this, function(sender, evt)
  6157. {
  6158. this.updateLinkHint(this.graph.getLinkForCell(this.state.cell),
  6159. this.graph.getLinksForState(this.state));
  6160. update();
  6161. });
  6162. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  6163. // Repaint needed when editing stops and no change event is fired
  6164. this.editingHandler = mxUtils.bind(this, function(sender, evt)
  6165. {
  6166. this.redrawHandles();
  6167. });
  6168. this.graph.addListener(mxEvent.EDITING_STOPPED, this.editingHandler);
  6169. var link = this.graph.getLinkForCell(this.state.cell);
  6170. var links = this.graph.getLinksForState(this.state);
  6171. this.updateLinkHint(link, links);
  6172. if (link != null || (links != null && links.length > 0))
  6173. {
  6174. redraw = true;
  6175. }
  6176. if (redraw)
  6177. {
  6178. this.redrawHandles();
  6179. }
  6180. };
  6181. mxVertexHandler.prototype.updateLinkHint = function(link, links)
  6182. {
  6183. if ((link == null && (links == null || links.length == 0)) ||
  6184. this.graph.getSelectionCount() > 1)
  6185. {
  6186. if (this.linkHint != null)
  6187. {
  6188. this.linkHint.parentNode.removeChild(this.linkHint);
  6189. this.linkHint = null;
  6190. }
  6191. }
  6192. else if (link != null || (links != null && links.length > 0))
  6193. {
  6194. if (this.linkHint == null)
  6195. {
  6196. this.linkHint = createHint();
  6197. this.linkHint.style.padding = '4px 10px 6px 10px';
  6198. this.linkHint.style.fontSize = '90%';
  6199. this.linkHint.style.opacity = '1';
  6200. this.linkHint.style.filter = '';
  6201. this.graph.container.appendChild(this.linkHint);
  6202. }
  6203. this.linkHint.innerHTML = '';
  6204. if (link != null)
  6205. {
  6206. this.linkHint.appendChild(this.graph.createLinkForHint(link));
  6207. if (this.graph.isEnabled() && typeof this.graph.editLink === 'function')
  6208. {
  6209. var changeLink = document.createElement('img');
  6210. changeLink.setAttribute('src', IMAGE_PATH + '/edit.gif');
  6211. changeLink.setAttribute('title', mxResources.get('editLink'));
  6212. changeLink.setAttribute('width', '11');
  6213. changeLink.setAttribute('height', '11');
  6214. changeLink.style.marginLeft = '10px';
  6215. changeLink.style.marginBottom = '-1px';
  6216. changeLink.style.cursor = 'pointer';
  6217. this.linkHint.appendChild(changeLink);
  6218. mxEvent.addListener(changeLink, 'click', mxUtils.bind(this, function(evt)
  6219. {
  6220. this.graph.setSelectionCell(this.state.cell);
  6221. this.graph.editLink();
  6222. mxEvent.consume(evt);
  6223. }));
  6224. }
  6225. }
  6226. if (links != null)
  6227. {
  6228. for (var i = 0; i < links.length; i++)
  6229. {
  6230. var div = document.createElement('div');
  6231. div.style.marginTop = '6px';
  6232. div.appendChild(this.graph.createLinkForHint(
  6233. links[i].getAttribute('href'),
  6234. mxUtils.getTextContent(links[i])));
  6235. this.linkHint.appendChild(div);
  6236. }
  6237. }
  6238. }
  6239. };
  6240. mxEdgeHandler.prototype.updateLinkHint = mxVertexHandler.prototype.updateLinkHint;
  6241. var edgeHandlerInit = mxEdgeHandler.prototype.init;
  6242. mxEdgeHandler.prototype.init = function()
  6243. {
  6244. edgeHandlerInit.apply(this, arguments);
  6245. // Disables connection points
  6246. this.constraintHandler.isEnabled = mxUtils.bind(this, function()
  6247. {
  6248. return this.state.view.graph.connectionHandler.isEnabled();
  6249. });
  6250. var update = mxUtils.bind(this, function()
  6251. {
  6252. if (this.linkHint != null)
  6253. {
  6254. this.linkHint.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  6255. }
  6256. if (this.labelShape != null)
  6257. {
  6258. this.labelShape.node.style.display = (this.graph.isEnabled() && this.graph.getSelectionCount() < this.graph.graphHandler.maxCells) ? '' : 'none';
  6259. }
  6260. });
  6261. this.selectionHandler = mxUtils.bind(this, function(sender, evt)
  6262. {
  6263. update();
  6264. });
  6265. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.selectionHandler);
  6266. this.changeHandler = mxUtils.bind(this, function(sender, evt)
  6267. {
  6268. this.updateLinkHint(this.graph.getLinkForCell(this.state.cell),
  6269. this.graph.getLinksForState(this.state));
  6270. update();
  6271. this.redrawHandles();
  6272. });
  6273. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  6274. var link = this.graph.getLinkForCell(this.state.cell);
  6275. var links = this.graph.getLinksForState(this.state);
  6276. if (link != null || (links != null && links.length > 0))
  6277. {
  6278. this.updateLinkHint(link, links);
  6279. this.redrawHandles();
  6280. }
  6281. };
  6282. // Disables connection points
  6283. var connectionHandlerInit = mxConnectionHandler.prototype.init;
  6284. mxConnectionHandler.prototype.init = function()
  6285. {
  6286. connectionHandlerInit.apply(this, arguments);
  6287. this.constraintHandler.isEnabled = mxUtils.bind(this, function()
  6288. {
  6289. return this.graph.connectionHandler.isEnabled();
  6290. });
  6291. };
  6292. var vertexHandlerRedrawHandles = mxVertexHandler.prototype.redrawHandles;
  6293. mxVertexHandler.prototype.redrawHandles = function()
  6294. {
  6295. vertexHandlerRedrawHandles.apply(this);
  6296. if (this.state != null && this.linkHint != null)
  6297. {
  6298. var c = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  6299. var tmp = new mxRectangle(this.state.x, this.state.y - 22, this.state.width + 24, this.state.height + 22);
  6300. var bb = mxUtils.getBoundingBox(tmp, this.state.style[mxConstants.STYLE_ROTATION] || '0', c);
  6301. var rs = (bb != null) ? mxUtils.getBoundingBox(this.state,
  6302. this.state.style[mxConstants.STYLE_ROTATION] || '0') : this.state;
  6303. var tb = (this.state.text != null) ? this.state.text.boundingBox : null;
  6304. if (bb == null)
  6305. {
  6306. bb = this.state;
  6307. }
  6308. var b = bb.y + bb.height;
  6309. if (tb != null)
  6310. {
  6311. b = Math.max(b, tb.y + tb.height);
  6312. }
  6313. this.linkHint.style.left = Math.round(rs.x + (rs.width - this.linkHint.clientWidth) / 2) + 'px';
  6314. this.linkHint.style.top = Math.round(b + this.verticalOffset / 2 + 6 +
  6315. this.state.view.graph.tolerance) + 'px';
  6316. }
  6317. };
  6318. var vertexHandlerReset = mxVertexHandler.prototype.reset;
  6319. mxVertexHandler.prototype.reset = function()
  6320. {
  6321. vertexHandlerReset.apply(this, arguments);
  6322. // Shows rotation handle only if one vertex is selected
  6323. if (this.rotationShape != null && this.rotationShape.node != null)
  6324. {
  6325. this.rotationShape.node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  6326. }
  6327. };
  6328. var vertexHandlerDestroy = mxVertexHandler.prototype.destroy;
  6329. mxVertexHandler.prototype.destroy = function()
  6330. {
  6331. vertexHandlerDestroy.apply(this, arguments);
  6332. if (this.linkHint != null)
  6333. {
  6334. this.linkHint.parentNode.removeChild(this.linkHint);
  6335. this.linkHint = null;
  6336. }
  6337. if (this.selectionHandler != null)
  6338. {
  6339. this.graph.getSelectionModel().removeListener(this.selectionHandler);
  6340. this.selectionHandler = null;
  6341. }
  6342. if (this.changeHandler != null)
  6343. {
  6344. this.graph.getModel().removeListener(this.changeHandler);
  6345. this.changeHandler = null;
  6346. }
  6347. if (this.editingHandler != null)
  6348. {
  6349. this.graph.removeListener(this.editingHandler);
  6350. this.editingHandler = null;
  6351. }
  6352. };
  6353. var edgeHandlerRedrawHandles = mxEdgeHandler.prototype.redrawHandles;
  6354. mxEdgeHandler.prototype.redrawHandles = function()
  6355. {
  6356. // Workaround for special case where handler
  6357. // is reset before this which leads to a NPE
  6358. if (this.marker != null)
  6359. {
  6360. edgeHandlerRedrawHandles.apply(this);
  6361. if (this.state != null && this.linkHint != null)
  6362. {
  6363. var b = this.state;
  6364. if (this.state.text != null && this.state.text.bounds != null)
  6365. {
  6366. b = new mxRectangle(b.x, b.y, b.width, b.height);
  6367. b.add(this.state.text.bounds);
  6368. }
  6369. this.linkHint.style.left = Math.round(b.x + (b.width - this.linkHint.clientWidth) / 2) + 'px';
  6370. this.linkHint.style.top = Math.round(b.y + b.height + 6 + this.state.view.graph.tolerance) + 'px';
  6371. }
  6372. }
  6373. };
  6374. var edgeHandlerReset = mxEdgeHandler.prototype.reset;
  6375. mxEdgeHandler.prototype.reset = function()
  6376. {
  6377. edgeHandlerReset.apply(this, arguments);
  6378. if (this.linkHint != null)
  6379. {
  6380. this.linkHint.style.visibility = '';
  6381. }
  6382. };
  6383. var edgeHandlerDestroy = mxEdgeHandler.prototype.destroy;
  6384. mxEdgeHandler.prototype.destroy = function()
  6385. {
  6386. edgeHandlerDestroy.apply(this, arguments);
  6387. if (this.linkHint != null)
  6388. {
  6389. this.linkHint.parentNode.removeChild(this.linkHint);
  6390. this.linkHint = null;
  6391. }
  6392. if (this.selectionHandler != null)
  6393. {
  6394. this.graph.getSelectionModel().removeListener(this.selectionHandler);
  6395. this.selectionHandler = null;
  6396. }
  6397. if (this.changeHandler != null)
  6398. {
  6399. this.graph.getModel().removeListener(this.changeHandler);
  6400. this.changeHandler = null;
  6401. }
  6402. };
  6403. })();
  6404. }