Graph.js 207 KB

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