Graph.js 203 KB

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