Graph.js 238 KB

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