Graph.js 210 KB

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