Graph.js 211 KB

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