Graph.js 222 KB

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