Graph.js 209 KB

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