Graph.js 241 KB

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