Graph.js 202 KB

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