Graph.js 208 KB

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