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