Graph.js 208 KB

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