Graph.js 218 KB

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