Graph.js 211 KB

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