Graph.js 212 KB

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