Graph.js 220 KB

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