Graph.js 202 KB

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