Graph.js 411 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. // Workaround for handling named HTML entities in mxUtils.parseXml
  5. // LATER: How to configure DOMParser to just ignore all entities?
  6. (function()
  7. {
  8. var entities = [
  9. ['nbsp', '160'],
  10. ['shy', '173']
  11. ];
  12. // Converts HTML entites for parsing XML
  13. var parseXml = mxUtils.parseXml;
  14. mxUtils.parseXml = function(text)
  15. {
  16. for (var i = 0; i < entities.length; i++)
  17. {
  18. text = text.replace(new RegExp(
  19. '&' + entities[i][0] + ';', 'g'),
  20. '&#' + entities[i][1] + ';');
  21. }
  22. return parseXml(text);
  23. };
  24. // Sanitizes text for HTML string size measure
  25. var getSizeForString = mxUtils.getSizeForString;
  26. mxUtils.getSizeForString = function(text, fontSize, fontFamily, textWidth)
  27. {
  28. return getSizeForString(Graph.sanitizeHtml(text), fontSize, fontFamily, textWidth);
  29. }
  30. })();
  31. // Shim for missing toISOString in older versions of IE
  32. // See https://stackoverflow.com/questions/12907862
  33. if (!Date.prototype.toISOString)
  34. {
  35. (function()
  36. {
  37. function pad(number)
  38. {
  39. var r = String(number);
  40. if (r.length === 1)
  41. {
  42. r = '0' + r;
  43. }
  44. return r;
  45. };
  46. Date.prototype.toISOString = function()
  47. {
  48. return this.getUTCFullYear()
  49. + '-' + pad( this.getUTCMonth() + 1 )
  50. + '-' + pad( this.getUTCDate() )
  51. + 'T' + pad( this.getUTCHours() )
  52. + ':' + pad( this.getUTCMinutes() )
  53. + ':' + pad( this.getUTCSeconds() )
  54. + '.' + String( (this.getUTCMilliseconds()/1000).toFixed(3) ).slice( 2, 5 )
  55. + 'Z';
  56. };
  57. }());
  58. }
  59. // Shim for Date.now()
  60. if (!Date.now)
  61. {
  62. Date.now = function()
  63. {
  64. return new Date().getTime();
  65. };
  66. }
  67. // Polyfill for Uint8Array.from in IE11 used in Graph.decompress
  68. // See https://stackoverflow.com/questions/36810940/alternative-or-polyfill-for-array-from-on-the-internet-explorer
  69. if (!Uint8Array.from) {
  70. Uint8Array.from = (function () {
  71. var toStr = Object.prototype.toString;
  72. var isCallable = function (fn) {
  73. return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
  74. };
  75. var toInteger = function (value) {
  76. var number = Number(value);
  77. if (isNaN(number)) { return 0; }
  78. if (number === 0 || !isFinite(number)) { return number; }
  79. return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
  80. };
  81. var maxSafeInteger = Math.pow(2, 53) - 1;
  82. var toLength = function (value) {
  83. var len = toInteger(value);
  84. return Math.min(Math.max(len, 0), maxSafeInteger);
  85. };
  86. // The length property of the from method is 1.
  87. return function from(arrayLike/*, mapFn, thisArg */) {
  88. // 1. Let C be the this value.
  89. var C = this;
  90. // 2. Let items be ToObject(arrayLike).
  91. var items = Object(arrayLike);
  92. // 3. ReturnIfAbrupt(items).
  93. if (arrayLike == null) {
  94. throw new TypeError("Array.from requires an array-like object - not null or undefined");
  95. }
  96. // 4. If mapfn is undefined, then let mapping be false.
  97. var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
  98. var T;
  99. if (typeof mapFn !== 'undefined') {
  100. // 5. else
  101. // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
  102. if (!isCallable(mapFn)) {
  103. throw new TypeError('Array.from: when provided, the second argument must be a function');
  104. }
  105. // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
  106. if (arguments.length > 2) {
  107. T = arguments[2];
  108. }
  109. }
  110. // 10. Let lenValue be Get(items, "length").
  111. // 11. Let len be ToLength(lenValue).
  112. var len = toLength(items.length);
  113. // 13. If IsConstructor(C) is true, then
  114. // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
  115. // 14. a. Else, Let A be ArrayCreate(len).
  116. var A = isCallable(C) ? Object(new C(len)) : new Array(len);
  117. // 16. Let k be 0.
  118. var k = 0;
  119. // 17. Repeat, while k < len… (also steps a - h)
  120. var kValue;
  121. while (k < len) {
  122. kValue = items[k];
  123. if (mapFn) {
  124. A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
  125. } else {
  126. A[k] = kValue;
  127. }
  128. k += 1;
  129. }
  130. // 18. Let putStatus be Put(A, "length", len, true).
  131. A.length = len;
  132. // 20. Return A.
  133. return A;
  134. };
  135. }());
  136. }
  137. // Overrides global constants
  138. mxConstants.SHADOW_OPACITY = 0.25;
  139. mxConstants.SHADOWCOLOR = '#000000';
  140. mxConstants.VML_SHADOWCOLOR = '#d0d0d0';
  141. mxCodec.allowlist = ['mxStylesheet', 'Array', 'mxGraphModel',
  142. 'mxCell', 'mxGeometry', 'mxRectangle', 'mxPoint',
  143. 'mxChildChange', 'mxRootChange', 'mxTerminalChange',
  144. 'mxValueChange', 'mxStyleChange', 'mxGeometryChange',
  145. 'mxCollapseChange', 'mxVisibleChange', 'mxCellAttributeChange'];
  146. mxGraph.prototype.pageBreakColor = '#c0c0c0';
  147. mxGraph.prototype.pageScale = 1;
  148. // Letter page format is default in US, Canada and Mexico
  149. (function()
  150. {
  151. try
  152. {
  153. if (navigator != null && navigator.language != null)
  154. {
  155. var lang = navigator.language.toLowerCase();
  156. mxGraph.prototype.pageFormat = (lang === 'en-us' || lang === 'en-ca' || lang === 'es-mx') ?
  157. mxConstants.PAGE_FORMAT_LETTER_PORTRAIT : mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  158. }
  159. }
  160. catch (e)
  161. {
  162. // ignore
  163. }
  164. })();
  165. // Matches label positions of mxGraph 1.x
  166. mxText.prototype.baseSpacingTop = 5;
  167. mxText.prototype.baseSpacingBottom = 1;
  168. // Keeps edges between relative child cells inside parent
  169. mxGraphModel.prototype.ignoreRelativeEdgeParent = false;
  170. // Defines grid properties
  171. mxGraphView.prototype.gridImage = (mxClient.IS_SVG) ? 'data:image/gif;base64,R0lGODlhCgAKAJEAAAAAAP///8zMzP///yH5BAEAAAMALAAAAAAKAAoAAAIJ1I6py+0Po2wFADs=' :
  172. IMAGE_PATH + '/grid.gif';
  173. mxGraphView.prototype.gridSteps = 4;
  174. mxGraphView.prototype.minGridSize = 4;
  175. // UrlParams is null in embed mode
  176. mxGraphView.prototype.defaultGridColor = '#d0d0d0';
  177. mxGraphView.prototype.defaultDarkGridColor = '#424242';
  178. mxGraphView.prototype.gridColor = mxGraphView.prototype.defaultGridColor;
  179. // Units
  180. mxGraphView.prototype.unit = mxConstants.POINTS;
  181. mxGraphView.prototype.setUnit = function(unit)
  182. {
  183. if (this.unit != unit)
  184. {
  185. this.unit = unit;
  186. this.fireEvent(new mxEventObject('unitChanged', 'unit', unit));
  187. }
  188. };
  189. // Alternative text for unsupported foreignObjects
  190. mxSvgCanvas2D.prototype.foAltText = '[Not supported by viewer]';
  191. // Hook for custom constraints
  192. mxShape.prototype.getConstraints = function(style, w, h)
  193. {
  194. return null;
  195. };
  196. // Override for clipSvg style
  197. mxImageShape.prototype.getImageDataUri = function()
  198. {
  199. var src = String(this.image);
  200. if (src.substring(0, 26) == 'data:image/svg+xml;base64,' && this.style != null &&
  201. mxUtils.getValue(this.style, 'clipSvg', '0') == '1')
  202. {
  203. if (this.clippedSvg == null || this.clippedImage != src)
  204. {
  205. this.clippedSvg = Graph.clipSvgDataUri(src, true);
  206. this.clippedImage = src;
  207. }
  208. src = this.clippedSvg;
  209. }
  210. return src;
  211. };
  212. // Override to use key as fallback
  213. (function()
  214. {
  215. var mxResourcesGet = mxResources.get;
  216. mxResources.get = function(key, params, defaultValue)
  217. {
  218. if (defaultValue == null)
  219. {
  220. defaultValue = key;
  221. }
  222. return mxResourcesGet.apply(this, [key, params, defaultValue]);
  223. };
  224. })();
  225. /**
  226. * Constructs a new graph instance. Note that the constructor does not take a
  227. * container because the graph instance is needed for creating the UI, which
  228. * in turn will create the container for the graph. Hence, the container is
  229. * assigned later in EditorUi.
  230. */
  231. /**
  232. * Defines graph class.
  233. */
  234. Graph = function(container, model, renderHint, stylesheet, themes, standalone)
  235. {
  236. mxGraph.call(this, container, model, renderHint, stylesheet);
  237. this.themes = themes || this.defaultThemes;
  238. this.currentEdgeStyle = mxUtils.clone(this.defaultEdgeStyle);
  239. this.currentVertexStyle = mxUtils.clone(this.defaultVertexStyle);
  240. this.standalone = (standalone != null) ? standalone : false;
  241. // Sets the base domain URL and domain path URL for relative links.
  242. var b = this.baseUrl;
  243. var p = b.indexOf('//');
  244. this.domainUrl = '';
  245. this.domainPathUrl = '';
  246. if (p > 0)
  247. {
  248. var d = b.indexOf('/', p + 2);
  249. if (d > 0)
  250. {
  251. this.domainUrl = b.substring(0, d);
  252. }
  253. d = b.lastIndexOf('/');
  254. if (d > 0)
  255. {
  256. this.domainPathUrl = b.substring(0, d + 1);
  257. }
  258. }
  259. // Adds support for HTML labels via style. Note: Currently, only the Java
  260. // backend supports HTML labels but CSS support is limited to the following:
  261. // http://docs.oracle.com/javase/6/docs/api/index.html?javax/swing/text/html/CSS.html
  262. // TODO: Wrap should not affect isHtmlLabel output (should be handled later)
  263. this.isHtmlLabel = function(cell)
  264. {
  265. var style = this.getCurrentCellStyle(cell);
  266. return (style != null) ? (style['html'] == '1' || style[mxConstants.STYLE_WHITE_SPACE] == 'wrap') : false;
  267. };
  268. // Implements a listener for hover and click handling on edges and tables
  269. if (this.immediateHandling)
  270. {
  271. var start = {
  272. point: null,
  273. event: null,
  274. state: null,
  275. handle: null,
  276. selected: false
  277. };
  278. var initialSelected = false;
  279. // Uses this event to process mouseDown to check the selection state before it is changed
  280. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  281. {
  282. if (evt.getProperty('eventName') == 'mouseDown' && this.isEnabled())
  283. {
  284. var me = evt.getProperty('event');
  285. var state = me.getState();
  286. var s = this.view.scale;
  287. if (!mxEvent.isAltDown(me.getEvent()) && state != null)
  288. {
  289. initialSelected = this.isCellSelected(state.cell);
  290. if (!this.panningHandler.isActive() && !mxEvent.isControlDown(me.getEvent()))
  291. {
  292. var handler = this.selectionCellsHandler.getHandler(state.cell);
  293. // Cell handles have precedence over row and col resize
  294. if (handler == null || handler.getHandleForEvent(me) == null)
  295. {
  296. var box = new mxRectangle(me.getGraphX() - 1, me.getGraphY() - 1);
  297. var tol = mxEvent.isTouchEvent(me.getEvent()) ?
  298. mxShape.prototype.svgStrokeTolerance - 1 :
  299. (mxShape.prototype.svgStrokeTolerance + 2) / 2;
  300. var t1 = tol + 2;
  301. box.grow(tol);
  302. // Ignores clicks inside cell to avoid delayed selection on
  303. // merged cells when clicking on invisible part of dividers
  304. if (this.isTableCell(state.cell) && this.isCellMovable(state.cell) &&
  305. !this.isCellSelected(state.cell) &&
  306. (!mxUtils.contains(state, me.getGraphX() - t1, me.getGraphY() - t1) ||
  307. !mxUtils.contains(state, me.getGraphX() - t1, me.getGraphY() + t1) ||
  308. !mxUtils.contains(state, me.getGraphX() + t1, me.getGraphY() + t1) ||
  309. !mxUtils.contains(state, me.getGraphX() + t1, me.getGraphY() - t1)))
  310. {
  311. var row = this.model.getParent(state.cell);
  312. var table = this.model.getParent(row);
  313. if (!this.isCellSelected(table))
  314. {
  315. var b = tol * s;
  316. var b2 = 2 * b;
  317. // Ignores events on top line of top row and left line of left column
  318. if ((this.model.getChildAt(table, 0) != row) && mxUtils.intersects(box,
  319. new mxRectangle(state.x, state.y - b, state.width, b2)) ||
  320. (this.model.getChildAt(row, 0) != state.cell) && mxUtils.intersects(box,
  321. new mxRectangle(state.x - b, state.y, b2, state.height)) ||
  322. mxUtils.intersects(box, new mxRectangle(state.x, state.y + state.height - b, state.width, b2)) ||
  323. mxUtils.intersects(box, new mxRectangle(state.x + state.width - b, state.y, b2, state.height)))
  324. {
  325. var wasSelected = this.selectionCellsHandler.isHandled(table);
  326. this.selectCellForEvent(table, me.getEvent());
  327. handler = this.selectionCellsHandler.getHandler(table);
  328. if (handler != null)
  329. {
  330. var handle = handler.getHandleForEvent(me);
  331. if (handle != null)
  332. {
  333. handler.start(me.getGraphX(), me.getGraphY(), handle);
  334. handler.blockDelayedSelection = !wasSelected;
  335. me.consume();
  336. }
  337. }
  338. }
  339. }
  340. }
  341. // Hover for swimlane start sizes inside tables
  342. var current = state;
  343. while (!me.isConsumed() && current != null && (this.isTableCell(current.cell) ||
  344. this.isTableRow(current.cell) || this.isTable(current.cell)))
  345. {
  346. if (this.isSwimlane(current.cell) && this.isCellMovable(current.cell))
  347. {
  348. var offset = this.getActualStartSize(current.cell);
  349. if (((offset.x > 0 || offset.width > 0) && mxUtils.intersects(box, new mxRectangle(
  350. current.x + (offset.x - offset.width - 1) * s + ((offset.x == 0) ? current.width : 0),
  351. current.y, 1, current.height))) || ((offset.y > 0 || offset.height > 0) &&
  352. mxUtils.intersects(box, new mxRectangle(current.x, current.y + (offset.y -
  353. offset.height - 1) * s + ((offset.y == 0) ? current.height : 0), current.width, 1))))
  354. {
  355. this.selectCellForEvent(current.cell, me.getEvent());
  356. handler = this.selectionCellsHandler.getHandler(current.cell);
  357. if (handler != null && handler.customHandles != null)
  358. {
  359. // Swimlane start size handle is last custom handle
  360. var handle = mxEvent.CUSTOM_HANDLE - handler.customHandles.length + 1;
  361. handler.start(me.getGraphX(), me.getGraphY(), handle);
  362. me.consume();
  363. }
  364. }
  365. }
  366. current = this.view.getState(this.model.getParent(current.cell));
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }));
  373. // Uses this event to process mouseDown to check the selection state before it is changed
  374. this.addListener(mxEvent.CONSUME_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  375. {
  376. if (evt.getProperty('eventName') == 'mouseDown' && this.isEnabled())
  377. {
  378. var me = evt.getProperty('event');
  379. var state = me.getState();
  380. if (!mxEvent.isAltDown(me.getEvent()) && !mxEvent.isControlDown(evt) &&
  381. !mxEvent.isShiftDown(evt) && !initialSelected &&
  382. state != null && this.model.isEdge(state.cell))
  383. {
  384. start.point = new mxPoint(me.getGraphX(), me.getGraphY());
  385. start.selected = this.isCellSelected(state.cell);
  386. start.state = state;
  387. start.event = me;
  388. if (state.text != null && state.text.boundingBox != null &&
  389. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  390. {
  391. start.handle = mxEvent.LABEL_HANDLE;
  392. }
  393. else
  394. {
  395. var handler = this.selectionCellsHandler.getHandler(state.cell);
  396. if (handler != null && handler.bends != null && handler.bends.length > 0)
  397. {
  398. start.handle = handler.getHandleForEvent(me);
  399. }
  400. }
  401. }
  402. }
  403. }));
  404. this.addMouseListener(
  405. {
  406. mouseDown: function(sender, me) {},
  407. mouseMove: mxUtils.bind(this, function(sender, me)
  408. {
  409. // Checks if any other handler is active
  410. var handlerMap = this.selectionCellsHandler.handlers.map;
  411. for (var key in handlerMap)
  412. {
  413. if (handlerMap[key].index != null)
  414. {
  415. return;
  416. }
  417. }
  418. if (this.isEnabled() && !this.panningHandler.isActive() && !mxEvent.isAltDown(me.getEvent()))
  419. {
  420. var tol = this.tolerance;
  421. if (start.point != null && start.state != null && start.event != null)
  422. {
  423. var state = start.state;
  424. if (start.handle != null || Math.abs(start.point.x - me.getGraphX()) > tol ||
  425. Math.abs(start.point.y - me.getGraphY()) > tol)
  426. {
  427. var handler = null;
  428. if (!mxEvent.isShiftDown(me.getEvent()))
  429. {
  430. handler = this.selectionCellsHandler.getHandler(state.cell);
  431. }
  432. if (handler != null && handler.bends != null && handler.bends.length > 0)
  433. {
  434. handler.redrawHandles();
  435. var handle = (start.handle != null) ? start.handle :
  436. handler.getHandleForEvent(start.event);
  437. var edgeStyle = this.view.getEdgeStyle(state);
  438. var entity = edgeStyle == mxEdgeStyle.EntityRelation;
  439. var pts = state.absolutePoints;
  440. // Handles special case where label was clicked on unselected edge in which
  441. // case the label will be moved regardless of the handle that is returned
  442. if (!start.selected)// && start.handle == mxEvent.LABEL_HANDLE)
  443. {
  444. handle = start.handle;
  445. }
  446. if (handle != mxEvent.LABEL_HANDLE && pts != null)
  447. {
  448. // Does not use handles if they were not initially visible
  449. handle = start.handle;
  450. if (handle == null)
  451. {
  452. var box = new mxRectangle(start.point.x, start.point.y);
  453. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  454. if (mxUtils.contains(box, pts[0].x, pts[0].y))
  455. {
  456. // Moves source terminal handle
  457. handle = 0;
  458. }
  459. else if (mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  460. {
  461. // Moves target terminal handle
  462. handle = handler.bends.length - 1;
  463. }
  464. else if (pts != null && ((edgeStyle == null && handle == null) ||
  465. edgeStyle == mxEdgeStyle.SegmentConnector ||
  466. edgeStyle == mxEdgeStyle.OrthConnector))
  467. {
  468. // Checks if edge has no bends
  469. var nobends = edgeStyle != null && (pts.length == 2 || (pts.length == 3 &&
  470. ((Math.round(pts[0].x - pts[1].x) == 0 && Math.round(pts[1].x - pts[2].x) == 0) ||
  471. (Math.round(pts[0].y - pts[1].y) == 0 && Math.round(pts[1].y - pts[2].y) == 0))));
  472. if (nobends)
  473. {
  474. // Moves central handle for straight orthogonal edges
  475. handle = 2;
  476. }
  477. else
  478. {
  479. // Finds and moves vertical or horizontal segment
  480. handle = mxUtils.findNearestSegment(state, start.point.x, start.point.y);
  481. // Converts segment to virtual handle index
  482. if (edgeStyle == null)
  483. {
  484. handle = mxEvent.VIRTUAL_HANDLE - handle;
  485. }
  486. // Maps segment to handle
  487. else
  488. {
  489. handle += 1;
  490. }
  491. }
  492. }
  493. }
  494. // Creates a new waypoint and starts moving it
  495. if (handle == null)
  496. {
  497. handle = mxEvent.VIRTUAL_HANDLE;
  498. }
  499. }
  500. var validEdge = !entity && (state.visibleSourceState != null ||
  501. state.visibleTargetState != null);
  502. var validHandle = handle == mxEvent.LABEL_HANDLE ||
  503. handle == 0 || handle == handler.bends.length - 1;
  504. if (validEdge || validHandle)
  505. {
  506. handler.start(me.getGraphX(), me.getGraphX(), handle);
  507. me.consume();
  508. // Removes preview rectangle in graph handler
  509. this.graphHandler.reset();
  510. }
  511. }
  512. if (handler != null)
  513. {
  514. // Lazy selection for edges inside groups
  515. if (this.selectionCellsHandler.isHandlerActive(handler))
  516. {
  517. if (!this.isCellSelected(state.cell))
  518. {
  519. this.selectionCellsHandler.handlers.put(state.cell, handler);
  520. this.selectCellForEvent(state.cell, me.getEvent());
  521. }
  522. }
  523. else if (!this.isCellSelected(state.cell))
  524. {
  525. // Destroy temporary handler
  526. handler.destroy();
  527. }
  528. }
  529. // Reset start state
  530. start.selected = false;
  531. start.handle = null;
  532. start.state = null;
  533. start.event = null;
  534. start.point = null;
  535. }
  536. }
  537. else
  538. {
  539. // Updates cursor for unselected edges under the mouse
  540. var state = me.getState();
  541. if (state != null && this.isCellEditable(state.cell))
  542. {
  543. var parent = this.model.getParent(state.cell);
  544. var cursor = null;
  545. // Checks if state was removed in call to stopEditing above
  546. if (this.model.isEdge(state.cell) &&
  547. !this.isCellSelected(state.cell) &&
  548. !mxEvent.isAltDown(me.getEvent()) &&
  549. !mxEvent.isShiftDown(me.getEvent()) &&
  550. // Immediate edge handling unavailable
  551. // in groups and selected ancestors
  552. !this.isAncestorSelected(state.cell) &&
  553. (this.isSwimlane(parent) ||
  554. this.model.isLayer(parent) ||
  555. this.getCurrentRoot() == parent))
  556. {
  557. var box = new mxRectangle(me.getGraphX(), me.getGraphY());
  558. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  559. var pts = state.absolutePoints;
  560. if (pts != null)
  561. {
  562. if (state.text != null && state.text.boundingBox != null &&
  563. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  564. {
  565. cursor = 'move';
  566. }
  567. else if (mxUtils.contains(box, pts[0].x, pts[0].y) ||
  568. mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  569. {
  570. cursor = 'pointer';
  571. }
  572. else
  573. {
  574. var edgeStyle = this.view.getEdgeStyle(state);
  575. if (edgeStyle != mxEdgeStyle.EntityRelation &&
  576. (state.visibleSourceState != null ||
  577. state.visibleTargetState != null))
  578. {
  579. cursor = 'crosshair';
  580. if (edgeStyle == mxEdgeStyle.SegmentConnector ||
  581. edgeStyle == mxEdgeStyle.OrthConnector)
  582. {
  583. var idx = mxUtils.findNearestSegment(state, me.getGraphX(), me.getGraphY());
  584. if (idx < pts.length - 1 && idx >= 0)
  585. {
  586. cursor = (Math.round(pts[idx].x - pts[idx + 1].x) == 0) ?
  587. 'col-resize' : 'row-resize';
  588. }
  589. }
  590. }
  591. }
  592. }
  593. }
  594. else if (!mxEvent.isControlDown(me.getEvent()))
  595. {
  596. var tol = mxShape.prototype.svgStrokeTolerance / 2;
  597. var box = new mxRectangle(me.getGraphX(), me.getGraphY());
  598. box.grow(tol);
  599. if (this.isTableCell(state.cell) && this.isCellMovable(state.cell))
  600. {
  601. var row = this.model.getParent(state.cell);
  602. var table = this.model.getParent(row);
  603. if (!this.isCellSelected(table))
  604. {
  605. if ((mxUtils.intersects(box, new mxRectangle(state.x, state.y - 2, state.width, 4)) &&
  606. this.model.getChildAt(table, 0) != row) || mxUtils.intersects(box,
  607. new mxRectangle(state.x, state.y + state.height - 2, state.width, 4)))
  608. {
  609. cursor ='row-resize';
  610. }
  611. else if ((mxUtils.intersects(box, new mxRectangle(state.x - 2, state.y, 4, state.height)) &&
  612. this.model.getChildAt(row, 0) != state.cell) || mxUtils.intersects(box,
  613. new mxRectangle(state.x + state.width - 2, state.y, 4, state.height)))
  614. {
  615. cursor ='col-resize';
  616. }
  617. }
  618. }
  619. // Hover for swimlane start sizes inside tables
  620. var current = state;
  621. while (cursor == null && current != null && (this.isTableCell(current.cell) ||
  622. this.isTableRow(current.cell) || this.isTable(current.cell)))
  623. {
  624. if (this.isSwimlane(current.cell) && this.isCellMovable(current.cell))
  625. {
  626. var offset = this.getActualStartSize(current.cell);
  627. var s = this.view.scale;
  628. if ((offset.x > 0 || offset.width > 0) && mxUtils.intersects(box, new mxRectangle(
  629. current.x + (offset.x - offset.width - 1) * s + ((offset.x == 0) ? current.width * s : 0),
  630. current.y, 1, current.height)))
  631. {
  632. cursor ='col-resize';
  633. }
  634. else if ((offset.y > 0 || offset.height > 0) && mxUtils.intersects(box, new mxRectangle(
  635. current.x, current.y + (offset.y - offset.height - 1) * s + ((offset.y == 0) ? current.height : 0),
  636. current.width, 1)))
  637. {
  638. cursor ='row-resize';
  639. }
  640. }
  641. current = this.view.getState(this.model.getParent(current.cell));
  642. }
  643. }
  644. if (cursor != null)
  645. {
  646. state.setCursor(cursor);
  647. }
  648. }
  649. }
  650. }
  651. }),
  652. mouseUp: mxUtils.bind(this, function(sender, me)
  653. {
  654. start.state = null;
  655. start.event = null;
  656. start.point = null;
  657. start.handle = null;
  658. })
  659. });
  660. }
  661. this.cellRenderer.minSvgStrokeWidth = 0.1;
  662. // HTML entities are displayed as plain text in wrapped plain text labels
  663. this.cellRenderer.getLabelValue = function(state)
  664. {
  665. var result = mxCellRenderer.prototype.getLabelValue.apply(this, arguments);
  666. if (state.view.graph.isHtmlLabel(state.cell))
  667. {
  668. if (state.style['html'] != 1)
  669. {
  670. result = mxUtils.htmlEntities(result, false);
  671. }
  672. else
  673. {
  674. // Skips sanitizeHtml for unchanged labels
  675. if (state.lastLabelValue != result)
  676. {
  677. state.lastLabelValue = result;
  678. state.lastSanitizedLabelValue = Graph.sanitizeHtml(result);
  679. }
  680. result = state.lastSanitizedLabelValue;
  681. }
  682. }
  683. return result;
  684. };
  685. // All code below not available and not needed in embed mode
  686. if (typeof mxVertexHandler !== 'undefined')
  687. {
  688. this.setConnectable(true);
  689. this.setDropEnabled(true);
  690. this.setPanning(true);
  691. this.setTooltips(true);
  692. this.setAllowLoops(true);
  693. this.allowAutoPanning = true;
  694. this.resetEdgesOnConnect = false;
  695. this.constrainChildren = false;
  696. this.constrainRelativeChildren = true;
  697. // Do not scroll after moving cells
  698. this.graphHandler.scrollOnMove = false;
  699. this.graphHandler.scaleGrid = true;
  700. // Disables cloning of connection sources by default
  701. this.connectionHandler.setCreateTarget(false);
  702. this.connectionHandler.insertBeforeSource = true;
  703. // Disables built-in connection starts
  704. this.connectionHandler.isValidSource = function(cell, me)
  705. {
  706. return false;
  707. };
  708. // Sets the style to be used when an elbow edge is double clicked
  709. this.alternateEdgeStyle = 'vertical';
  710. if (stylesheet == null)
  711. {
  712. this.loadStylesheet();
  713. }
  714. // Adds page centers to the guides for moving cells
  715. var graphHandlerGetGuideStates = this.graphHandler.getGuideStates;
  716. this.graphHandler.getGuideStates = function()
  717. {
  718. var result = graphHandlerGetGuideStates.apply(this, arguments);
  719. // Create virtual cell state for page centers
  720. if (this.graph.pageVisible)
  721. {
  722. var guides = [];
  723. var pf = this.graph.pageFormat;
  724. var ps = this.graph.pageScale;
  725. var pw = pf.width * ps;
  726. var ph = pf.height * ps;
  727. var t = this.graph.view.translate;
  728. var s = this.graph.view.scale;
  729. var layout = this.graph.getPageLayout();
  730. for (var i = 0; i < layout.width; i++)
  731. {
  732. guides.push(new mxRectangle(((layout.x + i) * pw + t.x) * s,
  733. (layout.y * ph + t.y) * s, pw * s, ph * s));
  734. }
  735. for (var j = 1; j < layout.height; j++)
  736. {
  737. guides.push(new mxRectangle((layout.x * pw + t.x) * s,
  738. ((layout.y + j) * ph + t.y) * s, pw * s, ph * s));
  739. }
  740. // Page center guides have precedence over normal guides
  741. result = guides.concat(result);
  742. }
  743. return result;
  744. };
  745. // Overrides zIndex for dragElement
  746. mxDragSource.prototype.dragElementZIndex = mxPopupMenu.prototype.zIndex;
  747. // Overrides color for virtual guides for page centers
  748. mxGuide.prototype.getGuideColor = function(state, horizontal)
  749. {
  750. return (state.cell == null) ? '#ffa500' /* orange */ : mxConstants.GUIDE_COLOR;
  751. };
  752. // Changes color of move preview for black backgrounds
  753. this.graphHandler.createPreviewShape = function(bounds)
  754. {
  755. this.previewColor = (this.graph.background == '#000000') ? '#ffffff' : mxGraphHandler.prototype.previewColor;
  756. return mxGraphHandler.prototype.createPreviewShape.apply(this, arguments);
  757. };
  758. // Handles parts of cells by checking if part=1 is in the style and returning the parent
  759. // if the parent is not already in the list of cells. container style is used to disable
  760. // step into swimlanes and dropTarget style is used to disable acting as a drop target.
  761. // LATER: Handle recursive parts
  762. var graphHandlerGetCells = this.graphHandler.getCells;
  763. this.graphHandler.getCells = function(initialCell)
  764. {
  765. var cells = graphHandlerGetCells.apply(this, arguments);
  766. var lookup = new mxDictionary();
  767. var newCells = [];
  768. for (var i = 0; i < cells.length; i++)
  769. {
  770. // Propagates to composite parents or moves selected table rows
  771. var cell = (this.graph.isTableCell(initialCell) &&
  772. this.graph.isTableCell(cells[i]) &&
  773. this.graph.isCellSelected(cells[i])) ?
  774. this.graph.model.getParent(cells[i]) :
  775. ((this.graph.isTableRow(initialCell) &&
  776. this.graph.isTableRow(cells[i]) &&
  777. this.graph.isCellSelected(cells[i])) ?
  778. cells[i] : this.graph.getCompositeParent(cells[i]));
  779. if (cell != null && !lookup.get(cell))
  780. {
  781. lookup.put(cell, true);
  782. newCells.push(cell);
  783. }
  784. }
  785. return newCells;
  786. };
  787. // Handles parts and selected rows in tables of cells for drag and drop
  788. var graphHandlerStart = this.graphHandler.start;
  789. this.graphHandler.start = function(cell, x, y, cells)
  790. {
  791. // Propagates to selected table row to start move
  792. var ignoreParent = false;
  793. if (this.graph.isTableCell(cell))
  794. {
  795. if (!this.graph.isCellSelected(cell))
  796. {
  797. cell = this.graph.model.getParent(cell);
  798. }
  799. else
  800. {
  801. ignoreParent = true;
  802. }
  803. }
  804. if (!ignoreParent && (!this.graph.isTableRow(cell) || !this.graph.isCellSelected(cell)))
  805. {
  806. cell = this.graph.getCompositeParent(cell);
  807. }
  808. graphHandlerStart.apply(this, arguments);
  809. };
  810. // Handles parts of cells when cloning the source for new connections
  811. this.connectionHandler.createTargetVertex = function(evt, source)
  812. {
  813. source = this.graph.getCompositeParent(source);
  814. return mxConnectionHandler.prototype.createTargetVertex.apply(this, arguments);
  815. };
  816. // Applies newEdgeStyle
  817. this.connectionHandler.insertEdge = function(parent, id, value, source, target, style)
  818. {
  819. var edge = mxConnectionHandler.prototype.insertEdge.apply(this, arguments);
  820. if (source != null)
  821. {
  822. this.graph.applyNewEdgeStyle(source, [edge]);
  823. }
  824. return edge
  825. };
  826. // Creates rubberband selection and associates with graph instance
  827. var rubberband = new mxRubberband(this);
  828. this.getRubberband = function()
  829. {
  830. return rubberband;
  831. };
  832. // Timer-based activation of outline connect in connection handler
  833. var startTime = new Date().getTime();
  834. var timeOnTarget = 0;
  835. var connectionHandlerMouseMove = this.connectionHandler.mouseMove;
  836. this.connectionHandler.mouseMove = function()
  837. {
  838. var prev = this.currentState;
  839. connectionHandlerMouseMove.apply(this, arguments);
  840. if (prev != this.currentState)
  841. {
  842. startTime = new Date().getTime();
  843. timeOnTarget = 0;
  844. }
  845. else
  846. {
  847. timeOnTarget = new Date().getTime() - startTime;
  848. }
  849. };
  850. // Activates outline connect after 1500ms with touch event or if alt is pressed inside the shape
  851. // outlineConnect=0 is a custom style that means do not connect to strokes inside the shape,
  852. // or in other words, connect to the shape's perimeter if the highlight is under the mouse
  853. // (the name is because the highlight, including all strokes, is called outline in the code)
  854. var connectionHandleIsOutlineConnectEvent = this.connectionHandler.isOutlineConnectEvent;
  855. this.connectionHandler.isOutlineConnectEvent = function(me)
  856. {
  857. if (mxEvent.isShiftDown(me.getEvent()) && mxEvent.isAltDown(me.getEvent()))
  858. {
  859. return false;
  860. }
  861. else
  862. {
  863. return (this.currentState != null && me.getState() == this.currentState && timeOnTarget > 2000) ||
  864. ((this.currentState == null || mxUtils.getValue(this.currentState.style, 'outlineConnect', '1') != '0') &&
  865. connectionHandleIsOutlineConnectEvent.apply(this, arguments));
  866. }
  867. };
  868. // Adds shift+click to toggle selection state
  869. var isToggleEvent = this.isToggleEvent;
  870. this.isToggleEvent = function(evt)
  871. {
  872. return isToggleEvent.apply(this, arguments) || (!mxClient.IS_CHROMEOS && mxEvent.isShiftDown(evt));
  873. };
  874. // Workaround for Firefox where first mouse down is received
  875. // after tap and hold if scrollbars are visible, which means
  876. // start rubberband immediately if no cell is under mouse.
  877. var isForceRubberBandEvent = rubberband.isForceRubberbandEvent;
  878. rubberband.isForceRubberbandEvent = function(me)
  879. {
  880. return isForceRubberBandEvent.apply(this, arguments) ||
  881. (mxClient.IS_CHROMEOS && mxEvent.isShiftDown(me.getEvent())) ||
  882. (mxUtils.hasScrollbars(this.graph.container) && mxClient.IS_FF &&
  883. mxClient.IS_WIN && me.getState() == null && mxEvent.isTouchEvent(me.getEvent()));
  884. };
  885. // Shows hand cursor while panning
  886. var prevCursor = null;
  887. this.panningHandler.addListener(mxEvent.PAN_START, mxUtils.bind(this, function()
  888. {
  889. if (this.isEnabled())
  890. {
  891. prevCursor = this.container.style.cursor;
  892. this.container.style.cursor = 'move';
  893. }
  894. }));
  895. this.panningHandler.addListener(mxEvent.PAN_END, mxUtils.bind(this, function()
  896. {
  897. if (this.isEnabled())
  898. {
  899. this.container.style.cursor = prevCursor;
  900. }
  901. }));
  902. this.popupMenuHandler.autoExpand = true;
  903. this.popupMenuHandler.isSelectOnPopup = function(me)
  904. {
  905. return mxEvent.isMouseEvent(me.getEvent());
  906. };
  907. // Handles links in read-only graphs
  908. // and cells in locked layers
  909. var click = this.click;
  910. this.click = function(me)
  911. {
  912. var locked = me.state == null && me.sourceState != null &&
  913. this.isCellLocked(this.getLayerForCell(
  914. me.sourceState.cell));
  915. if ((!this.isEnabled() || locked) && !me.isConsumed())
  916. {
  917. var cell = (locked) ? me.sourceState.cell : me.getCell();
  918. if (cell != null)
  919. {
  920. var link = this.getClickableLinkForCell(cell);
  921. if (link != null)
  922. {
  923. if (this.isCustomLink(link))
  924. {
  925. this.customLinkClicked(link, cell);
  926. }
  927. else
  928. {
  929. this.openLink(link);
  930. }
  931. }
  932. else if (locked)
  933. {
  934. this.clearSelection();
  935. }
  936. }
  937. }
  938. else
  939. {
  940. return click.apply(this, arguments);
  941. }
  942. };
  943. // Redirects tooltips for locked cells
  944. this.tooltipHandler.getStateForEvent = function(me)
  945. {
  946. return me.sourceState;
  947. };
  948. // Opens links in tooltips in new windows
  949. var tooltipHandlerShow = this.tooltipHandler.show;
  950. this.tooltipHandler.show = function()
  951. {
  952. tooltipHandlerShow.apply(this, arguments);
  953. if (this.div != null)
  954. {
  955. var links = this.div.getElementsByTagName('a');
  956. for (var i = 0; i < links.length; i++)
  957. {
  958. if (links[i].getAttribute('href') != null &&
  959. links[i].getAttribute('target') == null)
  960. {
  961. links[i].setAttribute('target', '_blank');
  962. }
  963. }
  964. }
  965. };
  966. // Redirects tooltips for locked cells
  967. this.tooltipHandler.getStateForEvent = function(me)
  968. {
  969. return me.sourceState;
  970. };
  971. // Redirects cursor for locked cells
  972. this.getCursorForMouseEvent = function(me)
  973. {
  974. var locked = me.state == null && me.sourceState != null && this.isCellLocked(me.sourceState.cell);
  975. return this.getCursorForCell((locked) ? me.sourceState.cell : me.getCell());
  976. };
  977. // Shows pointer cursor for clickable cells with links
  978. // ie. if the graph is disabled and cells cannot be selected
  979. var getCursorForCell = this.getCursorForCell;
  980. this.getCursorForCell = function(cell)
  981. {
  982. if (!this.isEnabled() || this.isCellLocked(cell))
  983. {
  984. var link = this.getClickableLinkForCell(cell);
  985. if (link != null)
  986. {
  987. return 'pointer';
  988. }
  989. else if (this.isCellLocked(cell))
  990. {
  991. return 'default';
  992. }
  993. }
  994. return getCursorForCell.apply(this, arguments);
  995. };
  996. // Changes rubberband selection ignore locked cells
  997. this.selectRegion = function(rect, evt)
  998. {
  999. var isect = (mxEvent.isAltDown(evt)) ? rect : null;
  1000. var cells = this.getCells(rect.x, rect.y,
  1001. rect.width, rect.height, null, null,
  1002. isect, null, true);
  1003. if (this.isToggleEvent(evt))
  1004. {
  1005. for (var i = 0; i < cells.length; i++)
  1006. {
  1007. this.selectCellForEvent(cells[i], evt);
  1008. }
  1009. }
  1010. else
  1011. {
  1012. this.selectCellsForEvent(cells, evt);
  1013. }
  1014. return cells;
  1015. };
  1016. // Never removes cells from parents that are being moved
  1017. var graphHandlerShouldRemoveCellsFromParent = this.graphHandler.shouldRemoveCellsFromParent;
  1018. this.graphHandler.shouldRemoveCellsFromParent = function(parent, cells, evt)
  1019. {
  1020. if (this.graph.isCellSelected(parent))
  1021. {
  1022. return false;
  1023. }
  1024. return graphHandlerShouldRemoveCellsFromParent.apply(this, arguments);
  1025. };
  1026. // Enables rubberband selection on cells in locked layers
  1027. var graphUpdateMouseEvent = this.updateMouseEvent;
  1028. this.updateMouseEvent = function(me)
  1029. {
  1030. me = graphUpdateMouseEvent.apply(this, arguments);
  1031. if (me.state != null && this.isCellLocked(this.getLayerForCell(me.getCell())))
  1032. {
  1033. if (this.getLinkForCell(me.getCell()) == null)
  1034. {
  1035. me.state = this.view.getState(this.getCellAt(me.getGraphX(), me.getGraphY(),
  1036. null, null, null, mxUtils.bind(this, function(state, x, y)
  1037. {
  1038. return me.state == state || (this.isCellLocked(this.getLayerForCell(state.cell)) &&
  1039. this.getLinkForCell(state.cell) == null);
  1040. })));
  1041. }
  1042. else
  1043. {
  1044. me.state = null;
  1045. }
  1046. }
  1047. return me;
  1048. };
  1049. // Cells in locked layers are not selectable
  1050. var graphIsCellSelectable = this.isCellSelectable;
  1051. this.isCellSelectable = function(cell)
  1052. {
  1053. return graphIsCellSelectable.apply(this, arguments) &&
  1054. !this.isCellLocked(this.getLayerForCell(cell));
  1055. };
  1056. // Returns true if the given cell is locked
  1057. this.isCellLocked = function(cell)
  1058. {
  1059. while (cell != null)
  1060. {
  1061. if (mxUtils.getValue(this.getCurrentCellStyle(cell), 'locked', '0') == '1')
  1062. {
  1063. return true;
  1064. }
  1065. cell = this.model.getParent(cell);
  1066. }
  1067. return false;
  1068. };
  1069. var tapAndHoldSelection = null;
  1070. // Uses this event to process mouseDown to check the selection state before it is changed
  1071. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  1072. {
  1073. if (evt.getProperty('eventName') == 'mouseDown')
  1074. {
  1075. var me = evt.getProperty('event');
  1076. var state = me.getState();
  1077. if (state != null && !this.isSelectionEmpty() && !this.isCellSelected(state.cell))
  1078. {
  1079. tapAndHoldSelection = this.getSelectionCells();
  1080. }
  1081. else
  1082. {
  1083. tapAndHoldSelection = null;
  1084. }
  1085. }
  1086. }));
  1087. // Tap and hold on background starts rubberband for multiple selected
  1088. // cells the cell associated with the event is deselected
  1089. this.addListener(mxEvent.TAP_AND_HOLD, mxUtils.bind(this, function(sender, evt)
  1090. {
  1091. if (!mxEvent.isMultiTouchEvent(evt))
  1092. {
  1093. var me = evt.getProperty('event');
  1094. var cell = evt.getProperty('cell');
  1095. if (cell == null)
  1096. {
  1097. var pt = mxUtils.convertPoint(this.container,
  1098. mxEvent.getClientX(me), mxEvent.getClientY(me));
  1099. rubberband.start(pt.x, pt.y);
  1100. }
  1101. else if (tapAndHoldSelection != null)
  1102. {
  1103. this.addSelectionCells(tapAndHoldSelection);
  1104. }
  1105. else if (this.getSelectionCount() > 1 && this.isCellSelected(cell))
  1106. {
  1107. this.removeSelectionCell(cell);
  1108. }
  1109. // Blocks further processing of the event
  1110. tapAndHoldSelection = null;
  1111. evt.consume();
  1112. }
  1113. }));
  1114. // On connect the target is selected and we clone the cell of the preview edge for insert
  1115. this.connectionHandler.selectCells = function(edge, target)
  1116. {
  1117. this.graph.setSelectionCell(target || edge);
  1118. };
  1119. // Shows connection points only if cell not selected and parent table not handled
  1120. this.connectionHandler.constraintHandler.isStateIgnored = function(state, source)
  1121. {
  1122. var graph = state.view.graph;
  1123. return source && (graph.isCellSelected(state.cell) || (graph.isTableRow(state.cell) &&
  1124. graph.selectionCellsHandler.isHandled(graph.model.getParent(state.cell))));
  1125. };
  1126. // Updates constraint handler if the selection changes
  1127. this.selectionModel.addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  1128. {
  1129. var ch = this.connectionHandler.constraintHandler;
  1130. if (ch.currentFocus != null && ch.isStateIgnored(ch.currentFocus, true))
  1131. {
  1132. ch.currentFocus = null;
  1133. ch.constraints = null;
  1134. ch.destroyIcons();
  1135. }
  1136. ch.destroyFocusHighlight();
  1137. }));
  1138. // Initializes touch interface
  1139. if (Graph.touchStyle)
  1140. {
  1141. this.initTouch();
  1142. }
  1143. }
  1144. //Create a unique offset object for each graph instance.
  1145. this.currentTranslate = new mxPoint(0, 0);
  1146. };
  1147. /**
  1148. * Specifies if the touch UI should be used (cannot detect touch in FF so always on for Windows/Linux)
  1149. */
  1150. Graph.touchStyle = mxClient.IS_TOUCH || (mxClient.IS_FF && mxClient.IS_WIN) || navigator.maxTouchPoints > 0 ||
  1151. navigator.msMaxTouchPoints > 0 || window.urlParams == null || urlParams['touch'] == '1';
  1152. /**
  1153. * Shortcut for capability check.
  1154. */
  1155. Graph.fileSupport = window.File != null && window.FileReader != null && window.FileList != null &&
  1156. (window.urlParams == null || urlParams['filesupport'] != '0');
  1157. /**
  1158. * Shortcut for capability check.
  1159. */
  1160. Graph.translateDiagram = urlParams['translate-diagram'] == '1';
  1161. /**
  1162. * Shortcut for capability check.
  1163. */
  1164. Graph.diagramLanguage = (urlParams['diagram-language'] != null) ? urlParams['diagram-language'] : mxClient.language;
  1165. /**
  1166. * Default size for line jumps.
  1167. */
  1168. Graph.lineJumpsEnabled = true;
  1169. /**
  1170. * Default size for line jumps.
  1171. */
  1172. Graph.defaultJumpSize = 6;
  1173. /**
  1174. * Specifies if the mouse wheel is used for zoom without any modifiers.
  1175. */
  1176. Graph.zoomWheel = false;
  1177. /**
  1178. * Specifies if the parent layer should be selected when the selection changes.
  1179. * Default is false.
  1180. */
  1181. Graph.selectParentLayer = false;
  1182. /**
  1183. * Minimum width for table columns.
  1184. */
  1185. Graph.minTableColumnWidth = 20;
  1186. /**
  1187. * Minimum height for table rows.
  1188. */
  1189. Graph.minTableRowHeight = 20;
  1190. /**
  1191. * Text for foreign object warning.
  1192. */
  1193. Graph.foreignObjectWarningText = 'Text is not SVG - cannot display';
  1194. /**
  1195. * Link for foreign object warning.
  1196. */
  1197. Graph.foreignObjectWarningLink = 'https://www.drawio.com/doc/faq/svg-export-text-problems';
  1198. /**
  1199. *
  1200. */
  1201. Graph.xmlDeclaration = '<?xml version="1.0" encoding="UTF-8"?>';
  1202. /**
  1203. *
  1204. */
  1205. Graph.svgDoctype = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ' +
  1206. '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
  1207. /**
  1208. *
  1209. */
  1210. Graph.svgFileComment = '<!-- Do not edit this file with editors other than draw.io -->'
  1211. /**
  1212. * Styles that are used for text.
  1213. */
  1214. Graph.textStyles = ['fontFamily', 'fontSource', 'fontSize', 'fontColor', 'fontStyle',
  1215. 'textOpacity', 'labelBorderColor', 'labelBackgroundColor', 'autosize', 'resizable'];
  1216. /**
  1217. * Styles that are used for edges.
  1218. */
  1219. Graph.edgeStyles = ['edgeStyle', 'elbow', 'jumpStyle', 'jumpSize', 'startArrow',
  1220. 'startFill', 'startSize', 'endArrow', 'endFill', 'endSize', 'flowAnimation',
  1221. 'flowAnimationDirection', 'flowAnimationTimingFunction', 'flowAnimationDuration',
  1222. 'sourcePerimeterSpacing', 'targetPerimeterSpacing', 'curved'];
  1223. /**
  1224. * Styles that are ignored together (if one appears all are ignored).
  1225. */
  1226. Graph.cellStyleGroups = [
  1227. ['startArrow', 'startFill', 'endArrow', 'endFill'],
  1228. ['startSize', 'endSize'],
  1229. ['sourcePerimeterSpacing', 'targetPerimeterSpacing'],
  1230. ['fillColor', 'gradientColor', 'gradientDirection']];
  1231. /**
  1232. * List of all known cell styles.
  1233. */
  1234. Graph.cellStyles = mxUtils.addItems(mxUtils.addItems(mxUtils.addItems(
  1235. ['rounded', 'shadow', 'glass', 'dashed', 'dashPattern', 'comic', 'sketch', 'fillWeight',
  1236. 'hachureGap', 'hachureAngle', 'jiggle', 'disableMultiStroke', 'disableMultiStrokeFill',
  1237. 'fillStyle', 'curveFitting', 'simplification', 'sketchStyle', 'pointerEvents', 'opacity',
  1238. 'strokeColor', 'strokeWidth', 'align', 'verticalAlign', 'spacingLeft', 'spacingRight',
  1239. 'spacingTop', 'spacingBottom', 'spacing', 'arcSize', 'comicStyle', 'swimlaneFillColor',
  1240. 'shadowOffsetX', 'shadowOffsetY', 'shadowBlur', 'shadowColor', 'shadowOpacity'],
  1241. Graph.textStyles), Graph.edgeStyles), Graph.cellStyleGroups);
  1242. /**
  1243. * Whitelist for known layout names.
  1244. */
  1245. Graph.layoutNames = ['mxHierarchicalLayout', 'mxCircleLayout', 'mxCompactTreeLayout',
  1246. 'mxEdgeLabelLayout', 'mxFastOrganicLayout', 'mxParallelEdgeLayout',
  1247. 'mxPartitionLayout', 'mxRadialTreeLayout', 'mxStackLayout'];
  1248. /**
  1249. * Creates a temporary graph instance for rendering off-screen content.
  1250. */
  1251. Graph.createOffscreenGraph = function(stylesheet)
  1252. {
  1253. var graph = new Graph(document.createElement('div'));
  1254. graph.stylesheet.styles = mxUtils.clone(stylesheet.styles);
  1255. graph.resetViewOnRootChange = false;
  1256. graph.setConnectable(false);
  1257. graph.gridEnabled = false;
  1258. graph.autoScroll = false;
  1259. graph.setTooltips(false);
  1260. graph.setEnabled(false);
  1261. // Container must be in the DOM for correct HTML rendering
  1262. graph.container.style.visibility = 'hidden';
  1263. graph.container.style.position = 'absolute';
  1264. graph.container.style.overflow = 'hidden';
  1265. graph.container.style.height = '1px';
  1266. graph.container.style.width = '1px';
  1267. return graph;
  1268. };
  1269. /**
  1270. * Helper function for creating SVG data URI.
  1271. */
  1272. Graph.createSvgImage = function(w, h, data, coordWidth, coordHeight)
  1273. {
  1274. var tmp = unescape(encodeURIComponent(Graph.svgDoctype +
  1275. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' + w + 'px" height="' + h + 'px" ' +
  1276. ((coordWidth != null && coordHeight != null) ? 'viewBox="0 0 ' + coordWidth + ' ' + coordHeight + '" ' : '') +
  1277. 'version="1.1">' + data + '</svg>'));
  1278. return new mxImage('data:image/svg+xml;base64,' + ((window.btoa) ? btoa(tmp) : Base64.encode(tmp, true)), w, h)
  1279. };
  1280. /**
  1281. *
  1282. */
  1283. Graph.createSvgDarkModeCss = function(cssClass)
  1284. {
  1285. cssClass = (cssClass != null) ? '.' + cssClass : '';
  1286. return 'svg' + cssClass + ':not(mjx-container > svg) { filter: invert(100%) hue-rotate(180deg); }\n' +
  1287. 'svg' + cssClass + ' foreignObject img,\n' +
  1288. 'svg' + cssClass + ' image:not(svg' + cssClass + ' switch image),\n' +
  1289. 'svg' + cssClass + ' svg:not(mjx-container > svg)\n' +
  1290. '{ filter: invert(100%) hue-rotate(180deg) }';
  1291. };
  1292. /**
  1293. *
  1294. */
  1295. Graph.createSvgDarkModeStyle = function(svgDoc, theme, cssClass, bg)
  1296. {
  1297. var style = mxUtils.createElementNs(svgDoc, mxConstants.NS_SVG, 'style');
  1298. svgDoc.setAttributeNS != null? style.setAttributeNS('type', 'text/css') :
  1299. style.setAttribute('type', 'text/css');
  1300. var css = Graph.createSvgDarkModeCss(cssClass);
  1301. if (theme == 'auto')
  1302. {
  1303. cssClass = (cssClass != null) ? '.' + cssClass : '';
  1304. css = '@media (prefers-color-scheme: dark) {\n' + css + '\n';
  1305. if (bg != null)
  1306. {
  1307. css += 'svg' + cssClass + ' { background-color: ' +
  1308. Graph.invertColor(bg) + ' !important; }\n';
  1309. }
  1310. css += '}';
  1311. }
  1312. style.appendChild(svgDoc.createTextNode(css));
  1313. return style;
  1314. };
  1315. /**
  1316. * Returns information about the current selection.
  1317. */
  1318. Graph.invertColor = function(value, ctx)
  1319. {
  1320. if (ctx == null)
  1321. {
  1322. var canvas = document.createElement('canvas');
  1323. canvas.width = 1;
  1324. canvas.height = 1;
  1325. var ctx = canvas.getContext('2d');
  1326. ctx.filter = 'invert(100%) hue-rotate(180deg)';
  1327. }
  1328. ctx.fillStyle = value;
  1329. ctx.fillRect(0, 0, 1, 1);
  1330. var imgData = ctx.getImageData(0, 0, 1, 1);
  1331. var r = imgData.data[0];
  1332. var g = imgData.data[1];
  1333. var b = imgData.data[2];
  1334. var rgb = b | (g << 8) | (r << 16);
  1335. return '#' + (0x1000000 | rgb).toString(16).substring(1);
  1336. };
  1337. /**
  1338. *
  1339. */
  1340. Graph.getSvgFromDataUri = function(uri)
  1341. {
  1342. if (uri != null && uri.substring(0, 14) == 'data:image/svg')
  1343. {
  1344. return Graph.xmlDeclaration + '\n' + Graph.svgDoctype + '\n' +
  1345. decodeURIComponent(escape(atob(uri.substring(
  1346. uri.indexOf(',') + 1))));
  1347. }
  1348. else
  1349. {
  1350. return null;
  1351. }
  1352. };
  1353. /**
  1354. * Helper function for creating an SVG node.
  1355. */
  1356. Graph.createSvgNode = function(x, y, w, h, background)
  1357. {
  1358. var svgDoc = mxUtils.createXmlDocument();
  1359. var root = (svgDoc.createElementNS != null) ?
  1360. svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') :
  1361. svgDoc.createElement('svg');
  1362. if (background != null)
  1363. {
  1364. if (root.style != null)
  1365. {
  1366. root.style.backgroundColor = background;
  1367. }
  1368. else
  1369. {
  1370. root.setAttribute('style', 'background-color:' + background);
  1371. }
  1372. }
  1373. if (svgDoc.createElementNS == null)
  1374. {
  1375. root.setAttribute('xmlns', mxConstants.NS_SVG);
  1376. root.setAttribute('xmlns:xlink', mxConstants.NS_XLINK);
  1377. }
  1378. else
  1379. {
  1380. // KNOWN: Ignored in IE9-11, adds namespace for each image element instead. No workaround.
  1381. root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', mxConstants.NS_XLINK);
  1382. }
  1383. root.setAttribute('version', '1.1');
  1384. root.setAttribute('width', w + 'px');
  1385. root.setAttribute('height', h + 'px');
  1386. root.setAttribute('viewBox', x + ' ' + y + ' ' + w + ' ' + h);
  1387. svgDoc.appendChild(root);
  1388. return root;
  1389. };
  1390. /**
  1391. * Helper function for creating an SVG node.
  1392. */
  1393. Graph.htmlToPng = function(html, w, h, fn, css, scale)
  1394. {
  1395. css = (css != null) ? css : '';
  1396. scale = (scale != null) ? scale : Editor.htmlRasterScale;
  1397. var canvas = document.createElement('canvas');
  1398. canvas.width = w * scale;
  1399. canvas.height = h * scale;
  1400. var img = document.createElement('img');
  1401. img.onload = mxUtils.bind(this, function()
  1402. {
  1403. try
  1404. {
  1405. var ctx = canvas.getContext('2d');
  1406. ctx.scale(scale, scale);
  1407. ctx.drawImage(img, 0, 0)
  1408. fn(canvas.toDataURL());
  1409. }
  1410. catch (e)
  1411. {
  1412. fn(null);
  1413. }
  1414. });
  1415. // Converts HTML to XHTML
  1416. var svgDoc = mxUtils.createXmlDocument();
  1417. var root = (svgDoc.createElementNS != null) ?
  1418. svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') : svgDoc.createElement('svg');
  1419. var svgCanvas = new mxSvgCanvas2D(root);
  1420. html = svgCanvas.convertHtml(html);
  1421. var svg = '<svg xmlns="http://www.w3.org/2000/svg" width="' + w + '" height="' + h + '">' +
  1422. ((css != '') ? '<defs xmlns="http://www.w3.org/2000/svg"><style type="text/css">' + css + '</style></defs>' : '') +
  1423. '<foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml">' + html + '</div></foreignObject></svg>';
  1424. img.onerror = function(err)
  1425. {
  1426. fn(null);
  1427. };
  1428. img.src = 'data:image/svg+xml,' + encodeURIComponent(svg);
  1429. };
  1430. /**
  1431. * Removes all illegal control characters with ASCII code <32 except TAB, LF
  1432. * and CR.
  1433. */
  1434. Graph.zapGremlins = function(text)
  1435. {
  1436. return mxUtils.zapGremlins(text);
  1437. };
  1438. /**
  1439. * Turns the given string into an array.
  1440. */
  1441. Graph.stringToBytes = function(str)
  1442. {
  1443. var arr = new Array(str.length);
  1444. for (var i = 0; i < str.length; i++)
  1445. {
  1446. arr[i] = str.charCodeAt(i);
  1447. }
  1448. return arr;
  1449. };
  1450. /**
  1451. * Turns the given array into a string.
  1452. */
  1453. Graph.bytesToString = function(arr)
  1454. {
  1455. var result = new Array(arr.length);
  1456. for (var i = 0; i < arr.length; i++)
  1457. {
  1458. result[i] = String.fromCharCode(arr[i]);
  1459. }
  1460. return result.join('');
  1461. };
  1462. /**
  1463. * Turns the given array into a string.
  1464. */
  1465. Graph.base64EncodeUnicode = function(str)
  1466. {
  1467. return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
  1468. return String.fromCharCode(parseInt(p1, 16))
  1469. }));
  1470. };
  1471. /**
  1472. * Turns the given array into a string.
  1473. */
  1474. Graph.base64DecodeUnicode = function(str)
  1475. {
  1476. return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
  1477. return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
  1478. }).join(''));
  1479. };
  1480. /**
  1481. * Returns a base64 encoded version of the compressed outer XML of the given node.
  1482. */
  1483. Graph.compressNode = function(node, checked)
  1484. {
  1485. var xml = mxUtils.getXml(node);
  1486. return Graph.compress((checked) ? xml : Graph.zapGremlins(xml));
  1487. };
  1488. /**
  1489. * Returns a string for the given array buffer.
  1490. */
  1491. Graph.arrayBufferToString = function(buffer)
  1492. {
  1493. var binary = '';
  1494. var bytes = new Uint8Array(buffer);
  1495. var len = bytes.byteLength;
  1496. for (var i = 0; i < len; i++)
  1497. {
  1498. binary += String.fromCharCode(bytes[i]);
  1499. }
  1500. return binary;
  1501. };
  1502. /**
  1503. * Returns an array buffer for the given string.
  1504. */
  1505. Graph.stringToArrayBuffer = function(data)
  1506. {
  1507. return Uint8Array.from(data, function (c)
  1508. {
  1509. return c.charCodeAt(0);
  1510. });
  1511. };
  1512. /**
  1513. * Returns index of a string in an array buffer (UInt8Array)
  1514. */
  1515. Graph.arrayBufferIndexOfString = function (uint8Array, str, start)
  1516. {
  1517. var c0 = str.charCodeAt(0), j = 1, p = -1;
  1518. //Index of first char
  1519. for (var i = start || 0; i < uint8Array.byteLength; i++)
  1520. {
  1521. if (uint8Array[i] == c0)
  1522. {
  1523. p = i;
  1524. break;
  1525. }
  1526. }
  1527. for (var i = p + 1; p > -1 && i < uint8Array.byteLength && i < p + str.length - 1; i++)
  1528. {
  1529. if (uint8Array[i] != str.charCodeAt(j))
  1530. {
  1531. return Graph.arrayBufferIndexOfString(uint8Array, str, p + 1);
  1532. }
  1533. j++;
  1534. }
  1535. return j == str.length - 1? p : -1;
  1536. };
  1537. /**
  1538. * Returns a base64 encoded version of the compressed string.
  1539. */
  1540. Graph.compress = function(data, deflate)
  1541. {
  1542. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1543. {
  1544. return data;
  1545. }
  1546. else
  1547. {
  1548. var tmp = (deflate) ? pako.deflate(encodeURIComponent(data)) :
  1549. pako.deflateRaw(encodeURIComponent(data));
  1550. return btoa(Graph.arrayBufferToString(new Uint8Array(tmp)));
  1551. }
  1552. };
  1553. /**
  1554. * Returns a decompressed version of the base64 encoded string.
  1555. */
  1556. Graph.decompress = function(data, inflate, checked)
  1557. {
  1558. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1559. {
  1560. return data;
  1561. }
  1562. else
  1563. {
  1564. var tmp = Graph.stringToArrayBuffer(atob(data));
  1565. var inflated = decodeURIComponent((inflate) ?
  1566. pako.inflate(tmp, {to: 'string'}) :
  1567. pako.inflateRaw(tmp, {to: 'string'}));
  1568. return (checked) ? inflated : Graph.zapGremlins(inflated);
  1569. }
  1570. };
  1571. /**
  1572. * Fades the given nodes in or out.
  1573. */
  1574. Graph.fadeNodes = function(nodes, start, end, done, delay)
  1575. {
  1576. delay = (delay != null) ? delay : 1000;
  1577. Graph.setTransitionForNodes(nodes, null);
  1578. Graph.setOpacityForNodes(nodes, start);
  1579. window.setTimeout(function()
  1580. {
  1581. Graph.setTransitionForNodes(nodes,
  1582. 'all ' + delay + 'ms ease-in-out');
  1583. Graph.setOpacityForNodes(nodes, end);
  1584. window.setTimeout(function()
  1585. {
  1586. Graph.setTransitionForNodes(nodes, null);
  1587. if (done != null)
  1588. {
  1589. done();
  1590. }
  1591. }, delay);
  1592. }, 0);
  1593. };
  1594. /**
  1595. * Adds the label menu items to the given menu and parent.
  1596. */
  1597. Graph.exploreFromCell = function(sourceGraph, selectionCell, config)
  1598. {
  1599. pageSize = (config != null && config.pageSize != null) ? config.pageSize : 8;
  1600. minSize = (config != null && config.minSize != null) ? config.minSize : 180;
  1601. //
  1602. // Main function
  1603. //
  1604. function exploreFromHere(sourceGraph, selectionCell)
  1605. {
  1606. var container = document.createElement('div');
  1607. container.style.position = 'absolute';
  1608. container.style.display = 'block';
  1609. container.style.background = (Editor.isDarkMode()) ?
  1610. Editor.darkColor : '#ffffff';
  1611. container.style.width = '100%';
  1612. container.style.height = '100%';
  1613. container.style.left = '0px';
  1614. container.style.top = '0px';
  1615. container.style.zIndex = 2;
  1616. var deleteImage = document.createElement('img');
  1617. deleteImage.setAttribute('src', Editor.closeBlackImage);
  1618. deleteImage.style.position = 'absolute';
  1619. deleteImage.style.cursor = 'pointer';
  1620. deleteImage.style.right = '10px';
  1621. deleteImage.style.top = '10px';
  1622. container.appendChild(deleteImage);
  1623. var closeLabel = document.createElement('div');
  1624. closeLabel.style.position = 'absolute';
  1625. closeLabel.style.cursor = 'pointer';
  1626. closeLabel.style.right = '38px';
  1627. closeLabel.style.top = '14px';
  1628. closeLabel.style.textAlign = 'right';
  1629. closeLabel.style.verticalAlign = 'top';
  1630. mxUtils.write(closeLabel, mxResources.get('close'));
  1631. container.appendChild(closeLabel);
  1632. document.body.appendChild(container);
  1633. var keyHandler = function(evt)
  1634. {
  1635. if (evt.keyCode == 27)
  1636. {
  1637. deleteImage.click();
  1638. }
  1639. };
  1640. mxEvent.addListener(document, 'keydown', keyHandler);
  1641. function main(container)
  1642. {
  1643. // Checks if browser is supported
  1644. if (!mxClient.isBrowserSupported())
  1645. {
  1646. // Displays an error message if the browser is
  1647. // not supported.
  1648. mxUtils.error('Browser is not supported!', 200, false);
  1649. }
  1650. else
  1651. {
  1652. // Creates the graph inside the given container
  1653. var graph = new Graph(container);
  1654. graph.keepEdgesInBackground = true;
  1655. graph.isCellResizable = function()
  1656. {
  1657. return false;
  1658. };
  1659. // Workaround to hide custom handles
  1660. graph.isCellRotatable = function()
  1661. {
  1662. return false;
  1663. };
  1664. // Shows hand cursor for all vertices
  1665. graph.getCursorForCell = function(cell)
  1666. {
  1667. if (this.model.isVertex(cell))
  1668. {
  1669. return 'pointer';
  1670. }
  1671. return null;
  1672. };
  1673. graph.getFoldingImage = function()
  1674. {
  1675. return null;
  1676. };
  1677. var closeHandler = function()
  1678. {
  1679. mxEvent.removeListener(document, 'keydown', keyHandler);
  1680. container.parentNode.removeChild(container);
  1681. // FIXME: Does not work
  1682. sourceGraph.scrollCellToVisible(selectionCell);
  1683. };
  1684. mxEvent.addListener(deleteImage, 'click', closeHandler);
  1685. mxEvent.addListener(closeLabel, 'click', closeHandler);
  1686. // Disables all built-in interactions
  1687. graph.setEnabled(false);
  1688. var graphClick = graph.click;
  1689. // Handles clicks on cells
  1690. graph.click = function(me)
  1691. {
  1692. var cell = me.getCell();
  1693. var realCell = (cell != null) ? ((cell.referenceCell != null) ?
  1694. cell.referenceCell : cell) : null;
  1695. if (cell != null && graph.rootCell != cell &&
  1696. graph.getEdges(realCell).length > 0)
  1697. {
  1698. load(graph, cell);
  1699. }
  1700. else
  1701. {
  1702. graphClick.apply(this, arguments);
  1703. }
  1704. };
  1705. var cx = graph.container.scrollWidth / 2;
  1706. var cy = graph.container.scrollHeight / 3;
  1707. graph.model.beginUpdate();
  1708. var cell = graph.importCells([selectionCell])[0];
  1709. cell.sourceCellId = selectionCell.id;
  1710. cell.geometry.x = cx - cell.geometry.width / 2;
  1711. cell.geometry.y = cy - cell.geometry.height / 2;
  1712. graph.model.endUpdate();
  1713. // Animates the changes in the graph model
  1714. var ignored = false;
  1715. graph.getModel().addListener(mxEvent.CHANGE, function(sender, evt)
  1716. {
  1717. if (!ignored)
  1718. {
  1719. var changes = evt.getProperty('edit').changes;
  1720. mxText.prototype.enableBoundingBox = false;
  1721. graph.labelsVisible = false;
  1722. ignored = true;
  1723. mxEffects.animateChanges(graph, changes, function()
  1724. {
  1725. // Keeps parallel edges apart
  1726. var layout = new mxParallelEdgeLayout(graph);
  1727. layout.spacing = 60;
  1728. var prevLayout = layout.layout;
  1729. // Dynamic spacing based on number of parallels
  1730. layout.layout = function(parallels)
  1731. {
  1732. layout.spacing = Math.min(60, Math.max(30, 60 - parallels.length * 5));
  1733. prevLayout.apply(this, arguments);
  1734. };
  1735. layout.execute(graph.getDefaultParent());
  1736. mxText.prototype.enableBoundingBox = true;
  1737. graph.labelsVisible = true;
  1738. graph.tooltipHandler.hide();
  1739. graph.refresh();
  1740. ignored = false;
  1741. });
  1742. }
  1743. });
  1744. load(graph, cell);
  1745. }
  1746. };
  1747. // Loads the links for the given cell into the given graph
  1748. // by requesting the respective data in the server-side
  1749. // (implemented for this demo using the server-function)
  1750. function load(graph, cell)
  1751. {
  1752. if (graph.getModel().isVertex(cell))
  1753. {
  1754. var cx = graph.container.scrollWidth / 2;
  1755. var cy = graph.container.scrollHeight / 2;
  1756. // Gets the default parent for inserting new cells. This
  1757. // is normally the first child of the root (ie. layer 0).
  1758. // var parent = graph.getDefaultParent();
  1759. graph.rootCell = cell.referenceCell || cell;
  1760. // Adds cells to the model in a single step
  1761. graph.getModel().beginUpdate();
  1762. try
  1763. {
  1764. var cells = rootChanged(graph, cell);
  1765. // Removes all cells except the new root
  1766. for (var key in graph.getModel().cells)
  1767. {
  1768. var tmp = graph.getModel().getCell(key);
  1769. if (tmp != graph.rootCell && !graph.getModel().isAncestor(
  1770. graph.rootCell, tmp) && graph.getModel().isVertex(tmp))
  1771. {
  1772. graph.removeCells([tmp]);
  1773. }
  1774. }
  1775. // Merges the response model with the client model
  1776. //graph.getModel().mergeChildren(model.getRoot().getChildAt(0), parent);
  1777. graph.addCells(cells);
  1778. // Moves the given cell to the center
  1779. var geo = graph.getModel().getGeometry(graph.rootCell);
  1780. if (geo != null)
  1781. {
  1782. geo = geo.clone();
  1783. geo.x = cx - geo.width / 2;
  1784. geo.y = cy - geo.height / 3;
  1785. graph.getModel().setGeometry(graph.rootCell, geo);
  1786. }
  1787. // Creates a list of the new vertices, if there is more
  1788. // than the center vertex which might have existed
  1789. // previously, then this needs to be changed to analyze
  1790. // the target model before calling mergeChildren above
  1791. var vertices = [];
  1792. for (var key in graph.getModel().cells)
  1793. {
  1794. var tmp = graph.getModel().getCell(key);
  1795. if (tmp != graph.rootCell && graph.getModel().isVertex(tmp) &&
  1796. graph.getModel().getParent(tmp) == graph.getDefaultParent())
  1797. {
  1798. vertices.push(tmp);
  1799. // Changes the initial location "in-place"
  1800. // to get a nice animation effect from the
  1801. // center to the radius of the circle
  1802. var geo = graph.getModel().getGeometry(tmp);
  1803. if (geo != null)
  1804. {
  1805. geo.x = cx - geo.width / 2;
  1806. geo.y = cy - geo.height / 2;
  1807. }
  1808. }
  1809. }
  1810. // Arranges the response in a circle
  1811. var cellCount = vertices.length;
  1812. var phi = 2 * Math.PI / cellCount;
  1813. var r = Math.max(minSize, Math.min(graph.container.scrollWidth / 2.5 - 80,
  1814. graph.container.scrollHeight / 2.5 - 80));
  1815. for (var i = 0; i < cellCount; i++)
  1816. {
  1817. var geo = graph.getModel().getGeometry(vertices[i]);
  1818. if (geo != null)
  1819. {
  1820. geo = geo.clone();
  1821. geo.x += r * Math.sin(i * phi);
  1822. geo.y += r * Math.cos(i * phi);
  1823. graph.getModel().setGeometry(vertices[i], geo);
  1824. }
  1825. }
  1826. }
  1827. finally
  1828. {
  1829. // Updates the display
  1830. graph.getModel().endUpdate();
  1831. }
  1832. }
  1833. };
  1834. // Gets the edges from the source cell and adds the targets
  1835. function rootChanged(graph, cell)
  1836. {
  1837. // TODO: Keep existing cells, probably best via XML to redirect IDs
  1838. var realCell = cell.referenceCell || cell;
  1839. var sourceCell = sourceGraph.model.getCell(realCell.sourceCellId);
  1840. var edges = sourceGraph.getEdges(sourceCell, null, true, true, false, true);
  1841. // Removes edges with no opposite
  1842. var validEdges = [];
  1843. for (var i = 0; i < edges.length; i++)
  1844. {
  1845. if (edges[i].getTerminal(true) != null &&
  1846. edges[i].getTerminal(false) != null &&
  1847. sourceGraph.isCellVisible(edges[i]) &&
  1848. !sourceGraph.isEdgeIgnored(edges[i]) &&
  1849. sourceGraph.isCellVisible(edges[i].getTerminal(true)) &&
  1850. sourceGraph.isCellVisible(edges[i].getTerminal(false)) &&
  1851. sourceGraph.isCellVisible(sourceGraph.getLayerForCell(edges[i])))
  1852. {
  1853. validEdges.push(edges[i]);
  1854. }
  1855. }
  1856. edges = validEdges;
  1857. var cells = edges;
  1858. // Paging by selecting a window in the edges array
  1859. if (cell.startIndex != null || (pageSize > 0 && edges.length > pageSize))
  1860. {
  1861. var start = cell.startIndex || 0;
  1862. cells = edges.slice(Math.max(0, start), Math.min(edges.length, start + pageSize));
  1863. }
  1864. cells = sourceGraph.getOpposites(cells, sourceCell).concat(cells);
  1865. var clones = graph.cloneCells(cells);
  1866. var edgeStyle = ';curved=1;noEdgeStyle=1;entryX=none;entryY=none;exitX=none;exitY=none;labelBackgroundColor=#ffffffc0;textOpacity=100;';
  1867. var btnStyle = 'fillColor=green;fontColor=white;strokeColor=green;rounded=1;';
  1868. for (var i = 0; i < cells.length; i++)
  1869. {
  1870. clones[i].sourceCellId = cells[i].id;
  1871. if (graph.model.isEdge(clones[i]))
  1872. {
  1873. // Removes waypoints, edge styles, constraints
  1874. // and centers the main label
  1875. clones[i].geometry.x = 0;
  1876. clones[i].geometry.y = 0;
  1877. clones[i].geometry.points = null;
  1878. clones[i].setStyle(clones[i].getStyle() + edgeStyle);
  1879. clones[i].setTerminal(realCell, clones[i].getTerminal(true) == null);
  1880. // Puts child labels at start/end/center of edge
  1881. for (var j = 0; j < clones[i].getChildCount(); j++)
  1882. {
  1883. var child = clones[i].getChildAt(j);
  1884. if (child.geometry != null)
  1885. {
  1886. if (child.geometry.relative)
  1887. {
  1888. child.setStyle(child.getStyle() + ';labelBackgroundColor=#ffffffc0;textOpacity=100;');
  1889. child.geometry.offset = new mxPoint(0, 0);
  1890. child.geometry.y = 0;
  1891. if (child.geometry.x < 0.5)
  1892. {
  1893. child.geometry.x = -0.8;
  1894. }
  1895. else if (child.geometry.x > 0.5)
  1896. {
  1897. child.geometry.x = 0.8;
  1898. }
  1899. else
  1900. {
  1901. child.geometry.x = 0;
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. if (cell.startIndex > 0)
  1909. {
  1910. var backCell = graph.createVertex(null, null, mxResources.get('previousPage') + ' (' +
  1911. Math.ceil((cell.startIndex || 0) / pageSize) + '/' +
  1912. Math.ceil(edges.length / pageSize) + ')',
  1913. 0, 0, 120, 30, btnStyle);
  1914. backCell.referenceCell = realCell;
  1915. backCell.startIndex = Math.max(0, (cell.startIndex || 0) - pageSize);
  1916. clones.splice(0, 0, backCell);
  1917. }
  1918. if (edges.length > (cell.startIndex || 0) + pageSize)
  1919. {
  1920. var moreCell = graph.createVertex(null, null, mxResources.get('nextPage') + ' (' +
  1921. (Math.ceil((cell.startIndex || 0) / pageSize) + 2) + '/' +
  1922. Math.ceil(edges.length / pageSize) + ')', 0, 0, 120, 30, btnStyle);
  1923. moreCell.referenceCell = realCell;
  1924. moreCell.startIndex = (cell.startIndex || 0) + pageSize;
  1925. clones.splice(0, 0, moreCell);
  1926. }
  1927. return clones;
  1928. };
  1929. main(container);
  1930. };
  1931. exploreFromHere(sourceGraph, selectionCell);
  1932. };
  1933. /**
  1934. * Removes the elements from the map where the given function returns true.
  1935. */
  1936. Graph.removeKeys = function(map, ignoreFn)
  1937. {
  1938. for (var key in map)
  1939. {
  1940. if (ignoreFn(key))
  1941. {
  1942. delete map[key];
  1943. }
  1944. }
  1945. };
  1946. /**
  1947. * Sets the transition for the given nodes.
  1948. */
  1949. Graph.setTransitionForNodes = function(nodes, transition)
  1950. {
  1951. for (var i = 0; i < nodes.length; i++)
  1952. {
  1953. mxUtils.setPrefixedStyle(nodes[i].style, 'transition', transition);
  1954. }
  1955. };
  1956. /**
  1957. * Sets the opacity for the given nodes.
  1958. */
  1959. Graph.setOpacityForNodes = function(nodes, opacity)
  1960. {
  1961. for (var i = 0; i < nodes.length; i++)
  1962. {
  1963. nodes[i].style.opacity = opacity;
  1964. }
  1965. };
  1966. /**
  1967. * Removes formatting from pasted HTML.
  1968. */
  1969. Graph.removePasteFormatting = function(elt, ignoreTabs)
  1970. {
  1971. while (elt != null)
  1972. {
  1973. if (elt.firstChild != null)
  1974. {
  1975. Graph.removePasteFormatting(elt.firstChild, true);
  1976. }
  1977. var next = elt.nextSibling;
  1978. if (elt.nodeType == mxConstants.NODETYPE_ELEMENT && elt.style != null)
  1979. {
  1980. if (elt.style.color == '#000000')
  1981. {
  1982. elt.style.color = '';
  1983. }
  1984. // Replaces tabs from macOS TextEdit
  1985. if (elt.nodeName == 'SPAN' && elt.className == 'Apple-tab-span')
  1986. {
  1987. var temp = Graph.createTabNode(4);
  1988. elt.parentNode.replaceChild(temp, elt);
  1989. elt = temp;
  1990. }
  1991. // Replaces paragraphs from macOS TextEdit
  1992. if (elt.nodeName == 'P' && elt.className == 'p1')
  1993. {
  1994. while (elt.firstChild != null)
  1995. {
  1996. elt.parentNode.insertBefore(elt.firstChild, elt);
  1997. }
  1998. if (next != null && next.nodeName == 'P' &&
  1999. next.className == 'p1')
  2000. {
  2001. elt.parentNode.insertBefore(elt.ownerDocument.
  2002. createElement('br'), elt);
  2003. }
  2004. elt.parentNode.removeChild(elt);
  2005. }
  2006. // Replaces tabs
  2007. if (!ignoreTabs && elt.innerHTML != null &&
  2008. elt.innerHTML.indexOf('\t') >= 0)
  2009. {
  2010. var tabNode = Graph.createTabNode(4);
  2011. elt.innerHTML = elt.innerHTML.replace(/\t/g,
  2012. tabNode.outerHTML);
  2013. }
  2014. }
  2015. elt = next;
  2016. }
  2017. };
  2018. /**
  2019. * Removes formatting from pasted HTML.
  2020. */
  2021. Graph.createTabNode = function(spaces)
  2022. {
  2023. var str = '\t';
  2024. if (spaces != null)
  2025. {
  2026. str = '';
  2027. while (spaces > 0)
  2028. {
  2029. str += '\xa0';
  2030. spaces--;
  2031. }
  2032. }
  2033. // LATER: Fix normalized tab after editing plain text labels
  2034. var tabNode = document.createElement('span');
  2035. tabNode.style.whiteSpace = 'pre';
  2036. tabNode.appendChild(document.createTextNode(str));
  2037. return tabNode;
  2038. };
  2039. /**
  2040. * Sanitizes the given HTML markup, allowing target attributes and
  2041. * data: protocol links to pages and custom actions.
  2042. */
  2043. Graph.sanitizeHtml = function(value, editing)
  2044. {
  2045. return Graph.domPurify(value, false);
  2046. };
  2047. /**
  2048. * Returns the size of the page format scaled with the page size.
  2049. */
  2050. Graph.sanitizeLink = function(href)
  2051. {
  2052. if (href == null)
  2053. {
  2054. return null;
  2055. }
  2056. else
  2057. {
  2058. var a = document.createElement('a');
  2059. a.setAttribute('href', href);
  2060. Graph.sanitizeNode(a);
  2061. return a.getAttribute('href');
  2062. }
  2063. };
  2064. /**
  2065. * Sanitizes the given DOM node in-place.
  2066. */
  2067. Graph.sanitizeNode = function(value)
  2068. {
  2069. return Graph.domPurify(value, true);
  2070. };
  2071. // Allows use tag in SVG with local references only
  2072. DOMPurify.addHook('afterSanitizeAttributes', function(node)
  2073. {
  2074. if (node.nodeName == 'use' && ((node.getAttribute('xlink:href') != null &&
  2075. !node.getAttribute('xlink:href').startsWith('#')) ||
  2076. (node.getAttribute('href') != null && !node.getAttribute('href').startsWith('#'))))
  2077. {
  2078. node.remove();
  2079. }
  2080. });
  2081. /**
  2082. * Sanitizes the given value.
  2083. */
  2084. Graph.domPurify = function(value, inPlace)
  2085. {
  2086. window.DOM_PURIFY_CONFIG.IN_PLACE = inPlace;
  2087. return DOMPurify.sanitize(value, window.DOM_PURIFY_CONFIG);
  2088. };
  2089. /**
  2090. * Updates the viewbox, width and height in the given SVG data URI
  2091. * and returns the updated data URI with all script tags and event
  2092. * handlers removed.
  2093. */
  2094. Graph.clipSvgDataUri = function(dataUri, ignorePreserveAspect)
  2095. {
  2096. // LATER Add workaround for non-default NS declarations with empty URI not allowed in IE11
  2097. if (!mxClient.IS_IE && !mxClient.IS_IE11 && dataUri != null &&
  2098. dataUri.substring(0, 26) == 'data:image/svg+xml;base64,')
  2099. {
  2100. try
  2101. {
  2102. var div = document.createElement('div');
  2103. div.style.position = 'absolute';
  2104. div.style.visibility = 'hidden';
  2105. // Adds the text and inserts into DOM for updating of size
  2106. var data = decodeURIComponent(escape(atob(dataUri.substring(26))));
  2107. var idx = data.indexOf('<svg');
  2108. if (idx >= 0)
  2109. {
  2110. // Strips leading XML declaration and doctypes
  2111. div.innerHTML = Graph.sanitizeHtml(data.substring(idx));
  2112. // Gets the size and removes from DOM
  2113. var svgs = div.getElementsByTagName('svg');
  2114. if (svgs.length > 0)
  2115. {
  2116. // Avoids getBBox as it ignores stroke option
  2117. if (ignorePreserveAspect || svgs[0].getAttribute('preserveAspectRatio') != null)
  2118. {
  2119. document.body.appendChild(div);
  2120. try
  2121. {
  2122. var fx = 1;
  2123. var fy = 1;
  2124. var w = svgs[0].getAttribute('width');
  2125. var h = svgs[0].getAttribute('height');
  2126. if (w != null && w.charAt(w.length - 1) != '%')
  2127. {
  2128. w = parseFloat(w);
  2129. }
  2130. else
  2131. {
  2132. w = NaN;
  2133. }
  2134. if (h != null && h.charAt(h.length - 1) != '%')
  2135. {
  2136. h = parseFloat(h);
  2137. }
  2138. else
  2139. {
  2140. h = NaN;
  2141. }
  2142. var vb = svgs[0].getAttribute('viewBox');
  2143. var viewBox = null;
  2144. if (vb != null && !isNaN(w) && !isNaN(h))
  2145. {
  2146. var tokens = vb.split(' ');
  2147. if (vb.length >= 4)
  2148. {
  2149. fx = parseFloat(tokens[2]) / w;
  2150. fy = parseFloat(tokens[3]) / h;
  2151. viewBox = new mxRectangle(parseFloat(tokens[0]), parseFloat(tokens[1]),
  2152. parseFloat(tokens[2]), parseFloat(tokens[3]));
  2153. }
  2154. }
  2155. var size = svgs[0].getBBox();
  2156. if (size.width > 0 && size.height > 0)
  2157. {
  2158. // SVG is only updated if area is less than 70%
  2159. if (viewBox == null || (size.width * size.height) <
  2160. (viewBox.width * viewBox.height * 0.7))
  2161. {
  2162. div.getElementsByTagName('svg')[0].setAttribute('viewBox', size.x +
  2163. ' ' + size.y + ' ' + size.width + ' ' + size.height);
  2164. div.getElementsByTagName('svg')[0].setAttribute('width', size.width / fx);
  2165. div.getElementsByTagName('svg')[0].setAttribute('height', size.height / fy);
  2166. }
  2167. }
  2168. }
  2169. catch (e)
  2170. {
  2171. // ignore
  2172. }
  2173. finally
  2174. {
  2175. document.body.removeChild(div);
  2176. }
  2177. }
  2178. dataUri = Editor.createSvgDataUri(mxUtils.getXml(svgs[0]));
  2179. }
  2180. }
  2181. }
  2182. catch (e)
  2183. {
  2184. // ignore
  2185. }
  2186. }
  2187. return dataUri;
  2188. };
  2189. /**
  2190. * Create remove icon.
  2191. */
  2192. Graph.createRemoveIcon = function(title, onclick)
  2193. {
  2194. var removeLink = document.createElement('img');
  2195. removeLink.setAttribute('src', Dialog.prototype.clearImage);
  2196. removeLink.setAttribute('title', title);
  2197. removeLink.setAttribute('width', '13');
  2198. removeLink.setAttribute('height', '10');
  2199. removeLink.style.marginLeft = '4px';
  2200. removeLink.style.marginBottom = '-1px';
  2201. removeLink.style.cursor = 'pointer';
  2202. mxEvent.addListener(removeLink, 'click', onclick);
  2203. return removeLink;
  2204. };
  2205. /**
  2206. * Returns true if the given string is a page link.
  2207. */
  2208. Graph.isPageLink = function(text)
  2209. {
  2210. return text != null && text.substring(0, 13) == 'data:page/id,';
  2211. };
  2212. /**
  2213. * Returns true if the given string is a page link.
  2214. */
  2215. Graph.rewritePageLinks = function(doc, removeNamespace)
  2216. {
  2217. var links = doc.getElementsByTagName('a');
  2218. function rewriteLink(link, attrib)
  2219. {
  2220. var href = link.getAttribute(attrib);
  2221. if (href != null)
  2222. {
  2223. if (Graph.isPageLink(href))
  2224. {
  2225. href = '#' + href.substring(href.indexOf(':') + 1);
  2226. }
  2227. var newAttrib = attrib;
  2228. if (removeNamespace && attrib == 'xlink:href')
  2229. {
  2230. link.removeAttribute(attrib);
  2231. newAttrib = 'href';
  2232. }
  2233. link.setAttribute(newAttrib, href);
  2234. }
  2235. };
  2236. if (links != null)
  2237. {
  2238. for (var i = 0; i < links.length; i++)
  2239. {
  2240. rewriteLink(links[i], 'href');
  2241. rewriteLink(links[i], 'xlink:href');
  2242. }
  2243. }
  2244. };
  2245. /**
  2246. * Returns true if the given string is a link.
  2247. *
  2248. * See https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
  2249. */
  2250. Graph.isLink = function(text)
  2251. {
  2252. return text != null && text.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
  2253. };
  2254. /**
  2255. * Graph inherits from mxGraph.
  2256. */
  2257. mxUtils.extend(Graph, mxGraph);
  2258. /**
  2259. * Allows all values in fit.
  2260. */
  2261. Graph.prototype.minFitScale = null;
  2262. /**
  2263. * Allows all values in fit.
  2264. */
  2265. Graph.prototype.maxFitScale = null;
  2266. /**
  2267. * Sets the policy for links. Possible values are "self" to replace any framesets,
  2268. * "blank" to load the URL in <linkTarget> and "auto" (default).
  2269. */
  2270. Graph.prototype.linkPolicy = (urlParams['target'] == 'frame') ? 'blank' : (urlParams['target'] || 'auto');
  2271. /**
  2272. * Target for links that open in a new window. Default is _blank.
  2273. */
  2274. Graph.prototype.linkTarget = (urlParams['target'] == 'frame') ? '_self' : '_blank';
  2275. /**
  2276. * Value to the rel attribute of links. Default is 'nofollow noopener noreferrer'.
  2277. * NOTE: There are security implications when this is changed and if noopener is removed,
  2278. * then <openLink> must be overridden to allow for the opener to be set by default.
  2279. */
  2280. Graph.prototype.linkRelation = 'nofollow noopener noreferrer';
  2281. /**
  2282. * Scrollbars setting is overriden in the editor, but not in the viewer.
  2283. */
  2284. Graph.prototype.defaultScrollbars = true;
  2285. /**
  2286. * Specifies if the page should be visible for new files. Default is true.
  2287. */
  2288. Graph.prototype.defaultPageVisible = true;
  2289. /**
  2290. * Specifies if the page should be visible for new files. Default is true.
  2291. */
  2292. Graph.prototype.defaultGridEnabled = urlParams['grid'] != '0';
  2293. /**
  2294. * Specifies if the app should run in chromeless mode. Default is false.
  2295. * This default is only used if the contructor argument is null.
  2296. */
  2297. Graph.prototype.lightbox = false;
  2298. /**
  2299. *
  2300. */
  2301. Graph.prototype.defaultPageBackgroundColor = '#ffffff';
  2302. /**
  2303. *
  2304. */
  2305. Graph.prototype.diagramBackgroundColor = '#f0f0f0';
  2306. /**
  2307. * Whether to use diagramBackgroundColor for no page views.
  2308. */
  2309. Graph.prototype.enableDiagramBackground = false;
  2310. /**
  2311. *
  2312. */
  2313. Graph.prototype.defaultPageBorderColor = '#ffffff';
  2314. /**
  2315. *
  2316. */
  2317. Graph.prototype.shapeForegroundColor = '#000000';
  2318. /**
  2319. *
  2320. */
  2321. Graph.prototype.shapeBackgroundColor = '#ffffff';
  2322. /**
  2323. * Specifies the size of the size for "tiles" to be used for a graph with
  2324. * scrollbars but no visible background page. A good value is large
  2325. * enough to reduce the number of repaints that is caused for auto-
  2326. * translation, which depends on this value, and small enough to give
  2327. * a small empty buffer around the graph. Default is 400x400.
  2328. */
  2329. Graph.prototype.scrollTileSize = new mxRectangle(0, 0, 400, 400);
  2330. /**
  2331. * Overrides the background color and paints a transparent background.
  2332. */
  2333. Graph.prototype.transparentBackground = true;
  2334. /**
  2335. * Sets global constants.
  2336. */
  2337. Graph.prototype.selectParentAfterDelete = false;
  2338. /**
  2339. * Sets the default target for all links in cells.
  2340. */
  2341. Graph.prototype.defaultEdgeLength = 80;
  2342. /**
  2343. * Enables activation of special handles on unselected cells.
  2344. */
  2345. Graph.prototype.immediateHandling = true;
  2346. /**
  2347. * Allows all values in fit.
  2348. */
  2349. Graph.prototype.connectionArrowsEnabled = true;
  2350. /**
  2351. * Specifies the regular expression for matching placeholders.
  2352. */
  2353. Graph.prototype.placeholderPattern = new RegExp('%(date\{.*\}|[^%^\{^\}^ ^"^ \'^=^;]+)%', 'g');
  2354. /**
  2355. * Specifies the regular expression for matching placeholders.
  2356. */
  2357. Graph.prototype.absoluteUrlPattern = new RegExp('^(?:[a-z]+:)?//', 'i');
  2358. /**
  2359. * Specifies the default name for the theme. Default is 'default'.
  2360. */
  2361. Graph.prototype.defaultThemeName = 'default';
  2362. /**
  2363. * Specifies the default name for the theme. Default is 'default'.
  2364. */
  2365. Graph.prototype.defaultThemes = {};
  2366. /**
  2367. * Base URL for relative links.
  2368. */
  2369. Graph.prototype.baseUrl = (urlParams['base'] != null) ?
  2370. mxUtils.removeJavascriptProtocol(
  2371. decodeURIComponent(urlParams['base'])) :
  2372. (((window != window.top) ? document.referrer :
  2373. document.location.toString()).split('#')[0]);
  2374. /**
  2375. * Specifies if the label should be edited after an insert.
  2376. */
  2377. Graph.prototype.editAfterInsert = false;
  2378. /**
  2379. * Defines the built-in properties to be ignored in tooltips.
  2380. */
  2381. Graph.prototype.builtInProperties = ['label', 'tooltip', 'placeholders', 'placeholder'];
  2382. /**
  2383. * Defines if the graph is part of an EditorUi. If this is false the graph can
  2384. * be used in an EditorUi instance but will not have a UI added, functions
  2385. * overridden or event handlers added.
  2386. */
  2387. Graph.prototype.standalone = false;
  2388. /**
  2389. * Enables move of bends/segments without selecting.
  2390. */
  2391. Graph.prototype.enableFlowAnimation = false;
  2392. /**
  2393. * Background color for inactive tabs.
  2394. */
  2395. Graph.prototype.roundableShapes = ['label', 'rectangle', 'internalStorage', 'corner',
  2396. 'parallelogram', 'swimlane', 'triangle', 'trapezoid', 'ext', 'step', 'tee', 'process',
  2397. 'link', 'rhombus', 'offPageConnector', 'loopLimit', 'hexagon', 'manualInput', 'card',
  2398. 'curlyBracket', 'singleArrow', 'callout', 'doubleArrow', 'flexArrow', 'umlLifeline'];
  2399. /**
  2400. * Font size for simple text. Default is null to force the global default.
  2401. */
  2402. Graph.prototype.vertexFontSize = null;
  2403. /**
  2404. * Font size for edge labels. Default is null to force the global default.
  2405. */
  2406. Graph.prototype.edgeFontSize = null;
  2407. /**
  2408. * Installs child layout styles.
  2409. */
  2410. Graph.prototype.init = function(container)
  2411. {
  2412. mxGraph.prototype.init.apply(this, arguments);
  2413. // Intercepts links with no target attribute and opens in new window
  2414. this.cellRenderer.initializeLabel = function(state, shape)
  2415. {
  2416. mxCellRenderer.prototype.initializeLabel.apply(this, arguments);
  2417. // Checks tolerance for clicks on links
  2418. var tol = state.view.graph.tolerance;
  2419. var handleClick = true;
  2420. var first = null;
  2421. var down = mxUtils.bind(this, function(evt)
  2422. {
  2423. handleClick = true;
  2424. first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2425. });
  2426. var move = mxUtils.bind(this, function(evt)
  2427. {
  2428. handleClick = handleClick && first != null &&
  2429. Math.abs(first.x - mxEvent.getClientX(evt)) < tol &&
  2430. Math.abs(first.y - mxEvent.getClientY(evt)) < tol;
  2431. });
  2432. var up = mxUtils.bind(this, function(evt)
  2433. {
  2434. if (handleClick)
  2435. {
  2436. var elt = mxEvent.getSource(evt)
  2437. while (elt != null && elt != shape.node)
  2438. {
  2439. if (elt.nodeName.toLowerCase() == 'a')
  2440. {
  2441. state.view.graph.labelLinkClicked(state, elt, evt);
  2442. break;
  2443. }
  2444. elt = elt.parentNode;
  2445. }
  2446. }
  2447. });
  2448. mxEvent.addGestureListeners(shape.node, down, move, up);
  2449. mxEvent.addListener(shape.node, 'click', function(evt)
  2450. {
  2451. mxEvent.consume(evt);
  2452. });
  2453. };
  2454. // Handles custom links in tooltips
  2455. if (this.tooltipHandler != null)
  2456. {
  2457. var tooltipHandlerInit = this.tooltipHandler.init;
  2458. this.tooltipHandler.init = function()
  2459. {
  2460. tooltipHandlerInit.apply(this, arguments);
  2461. if (this.div != null)
  2462. {
  2463. mxEvent.addListener(this.div, 'click', mxUtils.bind(this, function(evt)
  2464. {
  2465. var source = mxEvent.getSource(evt);
  2466. if (source.nodeName == 'A')
  2467. {
  2468. var href = source.getAttribute('href');
  2469. if (href != null && this.graph.isCustomLink(href) &&
  2470. (mxEvent.isTouchEvent(evt) || !mxEvent.isPopupTrigger(evt)) &&
  2471. this.graph.customLinkClicked(href))
  2472. {
  2473. mxEvent.consume(evt);
  2474. }
  2475. }
  2476. }));
  2477. }
  2478. };
  2479. }
  2480. this.initLayoutManager();
  2481. };
  2482. /**
  2483. * Implements zoom and offset via CSS transforms. This is currently only used
  2484. * in read-only as there are fewer issues with the mxCellState not being scaled
  2485. * and translated.
  2486. *
  2487. * KNOWN ISSUES TO FIX:
  2488. * - Apply CSS transforms to HTML labels in IE11
  2489. */
  2490. (function()
  2491. {
  2492. /**
  2493. * Uses CSS transforms for scale and translate.
  2494. */
  2495. Graph.prototype.useCssTransforms = false;
  2496. /**
  2497. * Contains the scale.
  2498. */
  2499. Graph.prototype.currentScale = 1;
  2500. /**
  2501. * Contains the offset.
  2502. */
  2503. Graph.prototype.currentTranslate = new mxPoint(0, 0);
  2504. /**
  2505. * Contains the offset.
  2506. */
  2507. Graph.prototype.pasteEdgeStyle = false;
  2508. /**
  2509. * Returns information about the current selection.
  2510. */
  2511. Graph.prototype.isFillState = function(state)
  2512. {
  2513. return !this.isSpecialColor(state.style[mxConstants.STYLE_FILLCOLOR]) &&
  2514. mxUtils.getValue(state.style, 'lineShape', null) != '1' &&
  2515. (this.model.isVertex(state.cell) ||
  2516. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'arrow' ||
  2517. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'wire' ||
  2518. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'filledEdge' ||
  2519. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'flexArrow' ||
  2520. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'mxgraph.arrows2.wedgeArrow');
  2521. };
  2522. /**
  2523. * Returns information about the current selection.
  2524. */
  2525. Graph.prototype.isGradientState = function(state)
  2526. {
  2527. return this.isFillState(state) && mxUtils.getValue(state.style,
  2528. mxConstants.STYLE_SHAPE, null) != 'wire';
  2529. };
  2530. /**
  2531. * Returns information about the current selection.
  2532. */
  2533. Graph.prototype.isStrokeState = function(state)
  2534. {
  2535. return true;
  2536. };
  2537. /**
  2538. * Returns information about the current selection.
  2539. */
  2540. Graph.prototype.isSpecialColor = function(color)
  2541. {
  2542. return mxUtils.indexOf([mxConstants.STYLE_STROKECOLOR,
  2543. mxConstants.STYLE_FILLCOLOR, 'inherit', 'swimlane',
  2544. 'indicated'], color) >= 0;
  2545. };
  2546. /**
  2547. * Returns information about the current selection.
  2548. */
  2549. Graph.prototype.isGlassState = function(state)
  2550. {
  2551. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  2552. return (shape == 'label' || shape == 'rectangle' || shape == 'internalStorage' ||
  2553. shape == 'ext' || shape == 'umlLifeline' || shape == 'swimlane' ||
  2554. shape == 'process');
  2555. };
  2556. /**
  2557. * Returns information about the current selection.
  2558. */
  2559. Graph.prototype.isRoundedState = function(state)
  2560. {
  2561. return (state.shape != null) ? state.shape.isRoundable() :
  2562. mxUtils.indexOf(this.roundableShapes, mxUtils.getValue(state.style,
  2563. mxConstants.STYLE_SHAPE, null)) >= 0;
  2564. };
  2565. /**
  2566. * Returns information about the current selection.
  2567. */
  2568. Graph.prototype.isLineJumpState = function(state)
  2569. {
  2570. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  2571. var curved = mxUtils.getValue(state.style, mxConstants.STYLE_CURVED, false);
  2572. return !curved && (shape == 'connector' || shape == 'filledEdge' || shape == 'wire');
  2573. };
  2574. /**
  2575. * Returns information about the current selection.
  2576. */
  2577. Graph.prototype.isAutoSizeState = function(state)
  2578. {
  2579. return mxUtils.getValue(state.style, mxConstants.STYLE_AUTOSIZE, null) == '1';
  2580. };
  2581. /**
  2582. * Returns information about the current selection.
  2583. */
  2584. Graph.prototype.isImageState = function(state)
  2585. {
  2586. return mxUtils.getValue(state.style, mxConstants.STYLE_IMAGE, null) != null;
  2587. };
  2588. /**
  2589. * Returns information about the current selection.
  2590. */
  2591. Graph.prototype.isShadowState = function(state)
  2592. {
  2593. return true;
  2594. };
  2595. /**
  2596. *
  2597. */
  2598. Graph.prototype.getVerticesAndEdges = function(vertices, edges)
  2599. {
  2600. vertices = (vertices != null) ? vertices : true;
  2601. edges = (edges != null) ? edges : true;
  2602. var model = this.model;
  2603. return model.filterDescendants(function(cell)
  2604. {
  2605. return (vertices && model.isVertex(cell)) || (edges && model.isEdge(cell));
  2606. }, model.getRoot());
  2607. };
  2608. /**
  2609. * Returns information about the current selection.
  2610. */
  2611. Graph.prototype.applyNewEdgeStyle = function(source, edges, dir)
  2612. {
  2613. var style = this.getCellStyle(source);
  2614. var temp = style['newEdgeStyle'];
  2615. if (temp != null)
  2616. {
  2617. this.model.beginUpdate();
  2618. try
  2619. {
  2620. var styles = JSON.parse(temp);
  2621. for (var key in styles)
  2622. {
  2623. this.setCellStyles(key, styles[key], edges);
  2624. // Sets elbow direction
  2625. if (key == 'edgeStyle' && styles[key] == 'elbowEdgeStyle' && dir != null)
  2626. {
  2627. this.setCellStyles('elbow', (dir == mxConstants.DIRECTION_SOUTH ||
  2628. dir == mxConstants.DIRECTION_NOTH) ? 'vertical' : 'horizontal',
  2629. edges);
  2630. }
  2631. }
  2632. }
  2633. finally
  2634. {
  2635. this.model.endUpdate();
  2636. }
  2637. }
  2638. };
  2639. /**
  2640. * Returns information about the current selection.
  2641. */
  2642. Graph.prototype.getCommonStyle = function(cells)
  2643. {
  2644. var style = {};
  2645. for (var i = 0; i < cells.length; i++)
  2646. {
  2647. var state = this.view.getState(cells[i]);
  2648. if (state != null)
  2649. {
  2650. this.mergeStyle(state.style, style, i == 0);
  2651. }
  2652. }
  2653. return style;
  2654. };
  2655. /**
  2656. * Returns information about the current selection.
  2657. */
  2658. Graph.prototype.mergeStyle = function(style, into, initial)
  2659. {
  2660. if (style != null)
  2661. {
  2662. var keys = {};
  2663. for (var key in style)
  2664. {
  2665. var value = style[key];
  2666. if (value != null)
  2667. {
  2668. keys[key] = true;
  2669. if (into[key] == null && initial)
  2670. {
  2671. into[key] = value;
  2672. }
  2673. else if (into[key] != value)
  2674. {
  2675. delete into[key];
  2676. }
  2677. }
  2678. }
  2679. for (var key in into)
  2680. {
  2681. if (!keys[key])
  2682. {
  2683. delete into[key];
  2684. }
  2685. }
  2686. }
  2687. };
  2688. /**
  2689. * Returns the cell for editing the given cell.
  2690. */
  2691. Graph.prototype.getStartEditingCell = function(cell, trigger)
  2692. {
  2693. // Redirect editing for tables
  2694. var style = this.getCellStyle(cell);
  2695. var size = parseInt(mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE, 0));
  2696. if (this.isTable(cell) && (!this.isSwimlane(cell) ||
  2697. size == 0) && this.getLabel(cell) == '' &&
  2698. this.model.getChildCount(cell) > 0)
  2699. {
  2700. cell = this.model.getChildAt(cell, 0);
  2701. style = this.getCellStyle(cell);
  2702. size = parseInt(mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE, 0));
  2703. }
  2704. // Redirect editing for table rows
  2705. if (this.isTableRow(cell) && (!this.isSwimlane(cell) ||
  2706. size == 0) && this.getLabel(cell) == '' &&
  2707. this.model.getChildCount(cell) > 0)
  2708. {
  2709. for (var i = 0; i < this.model.getChildCount(cell); i++)
  2710. {
  2711. var temp = this.model.getChildAt(cell, i);
  2712. if (this.isCellEditable(temp))
  2713. {
  2714. cell = temp;
  2715. break;
  2716. }
  2717. }
  2718. }
  2719. return cell;
  2720. };
  2721. /**
  2722. * Returns the style of the given cell as an object.
  2723. */
  2724. Graph.prototype.copyStyle = function(cell)
  2725. {
  2726. return this.getCellStyle(cell, false);
  2727. };
  2728. /**
  2729. * Returns true if fast zoom preview should be used.
  2730. */
  2731. Graph.prototype.pasteStyle = function(style, cells, keys, replaceAll)
  2732. {
  2733. if (style != null)
  2734. {
  2735. if (!replaceAll)
  2736. {
  2737. keys = (keys != null) ? keys : Graph.cellStyles;
  2738. Graph.removeKeys(style, function(key)
  2739. {
  2740. return mxUtils.indexOf(keys, key) < 0;
  2741. });
  2742. }
  2743. this.updateCellStyles(style, cells);
  2744. }
  2745. };
  2746. /**
  2747. * Copies the style of the given cells to the given vertex and edge style.
  2748. */
  2749. Graph.prototype.copyCellStyles = function(cells, keys, values, vertexStyle, edgeStyle, vertexStyleIgnored, edgeStyleIgnored)
  2750. {
  2751. var vertex = false;
  2752. var edge = false;
  2753. if (cells.length > 0)
  2754. {
  2755. for (var i = 0; i < cells.length; i++)
  2756. {
  2757. vertex = this.getModel().isVertex(cells[i]) || vertex;
  2758. edge = this.getModel().isEdge(cells[i]) || edge;
  2759. if (edge && vertex)
  2760. {
  2761. break;
  2762. }
  2763. }
  2764. }
  2765. else
  2766. {
  2767. vertex = true;
  2768. edge = true;
  2769. }
  2770. vertex = vertex && !vertexStyleIgnored;
  2771. edge = edge && !edgeStyleIgnored;
  2772. for (var i = 0; i < keys.length; i++)
  2773. {
  2774. var common = mxUtils.indexOf(Graph.textStyles, keys[i]) >= 0;
  2775. // Ignores transparent stroke colors
  2776. if (keys[i] != 'strokeColor' || (values[i] != null && values[i] != 'none'))
  2777. {
  2778. if (mxUtils.indexOf(Graph.cellStyles, keys[i]) >= 0 || keys[i] == 'shape')
  2779. {
  2780. if (keys[i] != 'shape' && (vertex || common))
  2781. {
  2782. if (values[i] == null)
  2783. {
  2784. delete vertexStyle[keys[i]];
  2785. }
  2786. else
  2787. {
  2788. vertexStyle[keys[i]] = values[i];
  2789. }
  2790. }
  2791. if (edge || common)
  2792. {
  2793. if (values[i] == null)
  2794. {
  2795. delete edgeStyle[keys[i]];
  2796. }
  2797. else
  2798. {
  2799. edgeStyle[keys[i]] = values[i];
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. };
  2806. /**
  2807. *
  2808. */
  2809. Graph.prototype.includeDescendants = function(cells)
  2810. {
  2811. var result = [];
  2812. for (var i = 0; i < cells.length; i++)
  2813. {
  2814. result = result.concat(this.model.getDescendants(cells[i]));
  2815. }
  2816. return result;
  2817. };
  2818. /**
  2819. *
  2820. */
  2821. Graph.prototype.pasteCellStyles = function(cells, vertexStyle, edgeStyle, force, pasteEdgeStyle)
  2822. {
  2823. vertexStyle = (vertexStyle != null) ? vertexStyle : this.currentVertexStyle;
  2824. edgeStyle = (edgeStyle != null) ? edgeStyle : this.currentEdgeStyle;
  2825. pasteEdgeStyle = (pasteEdgeStyle != null) ? pasteEdgeStyle : this.pasteEdgeStyle;
  2826. this.model.beginUpdate();
  2827. try
  2828. {
  2829. for (var i = 0; i < cells.length; i++)
  2830. {
  2831. var cell = cells[i];
  2832. var cellStyle = this.model.getStyle(cell);
  2833. var isText = false;
  2834. var appliedStyles;
  2835. // Applies basic text styles for cells with text class
  2836. if (cell.style != null)
  2837. {
  2838. pairs = cell.style.split(';');
  2839. isText = isText || mxUtils.indexOf(pairs, 'text') >= 0;
  2840. }
  2841. if (isText)
  2842. {
  2843. // Applies only basic text styles
  2844. appliedStyles = Graph.textStyles;
  2845. }
  2846. else
  2847. {
  2848. appliedStyles = Graph.cellStyles.slice();
  2849. if (!force)
  2850. {
  2851. // Removes styles defined in the cell style from the styles to be applied
  2852. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  2853. for (var j = 0; j < tokens.length; j++)
  2854. {
  2855. var tmp = tokens[j];
  2856. var pos = tmp.indexOf('=');
  2857. if (pos >= 0)
  2858. {
  2859. var key = tmp.substring(0, pos);
  2860. var index = mxUtils.indexOf(appliedStyles, key);
  2861. if (index >= 0)
  2862. {
  2863. appliedStyles.splice(index, 1);
  2864. }
  2865. // Handles special cases where one defined style ignores other styles
  2866. for (var k = 0; k < Graph.cellStyleGroups.length; k++)
  2867. {
  2868. var group = Graph.cellStyleGroups[k];
  2869. if (mxUtils.indexOf(group, key) >= 0)
  2870. {
  2871. for (var l = 0; l < group.length; l++)
  2872. {
  2873. var index2 = mxUtils.indexOf(appliedStyles, group[l]);
  2874. if (index2 >= 0)
  2875. {
  2876. appliedStyles.splice(index2, 1);
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. }
  2883. }
  2884. }
  2885. // Applies the current style to the cell
  2886. var edge = this.model.isEdge(cell);
  2887. var current = (edge) ? edgeStyle : vertexStyle;
  2888. for (var j = 0; j < appliedStyles.length; j++)
  2889. {
  2890. var key = appliedStyles[j];
  2891. var styleValue = current[key];
  2892. // Edge style is only applied if user assigned a default style using
  2893. // the UI but not if the edge style is globally configured
  2894. if (styleValue != null && (key != 'edgeStyle' || pasteEdgeStyle))
  2895. {
  2896. // Edge styles are never assigned to vertices
  2897. if (edge || (!edge && mxUtils.indexOf(Graph.edgeStyles, key) < 0))
  2898. {
  2899. cellStyle = mxUtils.setStyle(cellStyle, key, styleValue);
  2900. // Removes fontSource if fontFamily is assigned
  2901. if (key == 'fontFamily' && current['fontSource'] == null)
  2902. {
  2903. cellStyle = mxUtils.setStyle(cellStyle, 'fontSource', null);
  2904. }
  2905. // Removes curved for edges if rounded is assigned
  2906. if (edge && key == 'rounded' && styleValue == '1' && current['curved'] == null)
  2907. {
  2908. cellStyle = mxUtils.setStyle(cellStyle, 'curved', null);
  2909. }
  2910. }
  2911. }
  2912. }
  2913. if (Editor.simpleLabels)
  2914. {
  2915. cellStyle = mxUtils.setStyle(mxUtils.setStyle(
  2916. cellStyle, 'html', null), 'whiteSpace', null);
  2917. }
  2918. this.model.setStyle(cell, cellStyle);
  2919. }
  2920. }
  2921. finally
  2922. {
  2923. this.model.endUpdate();
  2924. }
  2925. return cells;
  2926. };
  2927. /**
  2928. * Removes implicit styles from cell styles so that dark mode works using the
  2929. * default values from the stylesheet.
  2930. */
  2931. Graph.prototype.updateCellStyles = function(style, cells)
  2932. {
  2933. this.model.beginUpdate();
  2934. try
  2935. {
  2936. for (var i = 0; i < cells.length; i++)
  2937. {
  2938. if (this.model.isVertex(cells[i]) || this.model.isEdge(cells[i]))
  2939. {
  2940. var cellStyle = this.getCellStyle(cells[i], false);
  2941. var perimeter = cellStyle[mxConstants.STYLE_PERIMETER];
  2942. var restorePerimeter = false;
  2943. for (var key in style)
  2944. {
  2945. var value = style[key];
  2946. if (cellStyle[key] != value)
  2947. {
  2948. // Handles paste of shape to UML lifeline
  2949. if (key == mxConstants.STYLE_SHAPE &&
  2950. cellStyle[key] == 'umlLifeline' &&
  2951. value != 'umlLifeline')
  2952. {
  2953. restorePerimeter = true;
  2954. key = 'participant';
  2955. }
  2956. this.setCellStyles(key, value, [cells[i]]);
  2957. }
  2958. }
  2959. if (restorePerimeter)
  2960. {
  2961. this.setCellStyles(mxConstants.STYLE_PERIMETER, perimeter, [cells[i]]);
  2962. }
  2963. }
  2964. }
  2965. }
  2966. finally
  2967. {
  2968. this.model.endUpdate();
  2969. }
  2970. };
  2971. /**
  2972. * Returns true if fast zoom preview should be used.
  2973. */
  2974. Graph.prototype.isFastZoomEnabled = function()
  2975. {
  2976. return urlParams['zoom'] != 'nocss' && !mxClient.NO_FO && !mxClient.IS_EDGE &&
  2977. !this.useCssTransforms && (this.isCssTransformsSupported() || mxClient.IS_IOS);
  2978. };
  2979. /**
  2980. * Only foreignObject supported for now (no IE11). Safari disabled as it ignores
  2981. * overflow visible on foreignObject in negative space (lightbox and viewer).
  2982. * Check the following test case on page 1 before enabling this in production:
  2983. * https://devhost.jgraph.com/git/drawio/etc/embed/sf-math-fo-clipping.html?dev=1
  2984. */
  2985. Graph.prototype.isCssTransformsSupported = function()
  2986. {
  2987. return this.dialect == mxConstants.DIALECT_SVG && !mxClient.NO_FO &&
  2988. (!this.lightbox || !mxClient.IS_SF);
  2989. };
  2990. /**
  2991. * Function: getCellAt
  2992. *
  2993. * Needs to modify original method for recursive call.
  2994. */
  2995. Graph.prototype.getCellAt = function(x, y, parent, vertices, edges, ignoreFn)
  2996. {
  2997. if (this.useCssTransforms)
  2998. {
  2999. x = x / this.currentScale - this.currentTranslate.x;
  3000. y = y / this.currentScale - this.currentTranslate.y;
  3001. }
  3002. return this.getScaledCellAt.apply(this, arguments);
  3003. };
  3004. /**
  3005. * Function: getScaledCellAt
  3006. *
  3007. * Overridden for recursion.
  3008. */
  3009. Graph.prototype.getScaledCellAt = function(x, y, parent, vertices, edges, ignoreFn)
  3010. {
  3011. vertices = (vertices != null) ? vertices : true;
  3012. edges = (edges != null) ? edges : true;
  3013. if (parent == null)
  3014. {
  3015. parent = this.getCurrentRoot();
  3016. if (parent == null)
  3017. {
  3018. parent = this.getModel().getRoot();
  3019. }
  3020. }
  3021. if (parent != null)
  3022. {
  3023. var childCount = this.model.getChildCount(parent);
  3024. for (var i = childCount - 1; i >= 0; i--)
  3025. {
  3026. var cell = this.model.getChildAt(parent, i);
  3027. var result = this.getScaledCellAt(x, y, cell, vertices, edges, ignoreFn);
  3028. if (result != null)
  3029. {
  3030. return result;
  3031. }
  3032. else if (this.isCellVisible(cell) && (edges && this.model.isEdge(cell) ||
  3033. vertices && this.model.isVertex(cell)))
  3034. {
  3035. var state = this.view.getState(cell);
  3036. if (state != null && (ignoreFn == null || !ignoreFn(state, x, y)) &&
  3037. this.intersects(state, x, y))
  3038. {
  3039. return cell;
  3040. }
  3041. }
  3042. }
  3043. }
  3044. return null;
  3045. };
  3046. /**
  3047. * Returns if the child cells of the given vertex cell state should be resized.
  3048. */
  3049. Graph.prototype.isRecursiveVertexResize = function(state)
  3050. {
  3051. return !this.isSwimlane(state.cell) && this.model.getChildCount(state.cell) > 0 &&
  3052. !this.isCellCollapsed(state.cell) && mxUtils.getValue(state.style, 'recursiveResize', '1') == '1' &&
  3053. mxUtils.getValue(state.style, 'childLayout', null) == null;
  3054. }
  3055. /**
  3056. * Returns the first parent with an absolute or no geometry.
  3057. */
  3058. Graph.prototype.getAbsoluteParent = function(cell)
  3059. {
  3060. var result = cell;
  3061. var geo = this.getCellGeometry(result);
  3062. while (geo != null && geo.relative)
  3063. {
  3064. result = this.getModel().getParent(result);
  3065. geo = this.getCellGeometry(result);
  3066. }
  3067. return result;
  3068. };
  3069. /**
  3070. * Returns the first parent that is not a part.
  3071. */
  3072. Graph.prototype.isPart = function(cell)
  3073. {
  3074. return mxUtils.getValue(this.getCurrentCellStyle(cell), 'part', '0') == '1' ||
  3075. this.isTableCell(cell) || this.isTableRow(cell);
  3076. };
  3077. /**
  3078. * Returns the first parent that is not a part.
  3079. */
  3080. Graph.prototype.getCompositeParents = function(cells)
  3081. {
  3082. var lookup = new mxDictionary();
  3083. var newCells = [];
  3084. for (var i = 0; i < cells.length; i++)
  3085. {
  3086. var cell = this.getCompositeParent(cells[i]);
  3087. if (this.isTableCell(cell))
  3088. {
  3089. cell = this.graph.model.getParent(cell);
  3090. }
  3091. if (this.isTableRow(cell))
  3092. {
  3093. cell = this.graph.model.getParent(cell);
  3094. }
  3095. if (cell != null && !lookup.get(cell))
  3096. {
  3097. lookup.put(cell, true);
  3098. newCells.push(cell);
  3099. }
  3100. }
  3101. return newCells;
  3102. };
  3103. /**
  3104. * Returns the given terminal that is not relative, an edge or a part.
  3105. */
  3106. Graph.prototype.getReferenceTerminal = function(terminal)
  3107. {
  3108. if (terminal != null)
  3109. {
  3110. var geo = this.getCellGeometry(terminal);
  3111. if (geo != null && geo.relative)
  3112. {
  3113. terminal = this.model.getParent(terminal);
  3114. }
  3115. }
  3116. if (terminal != null && this.model.isEdge(terminal))
  3117. {
  3118. terminal = this.model.getParent(terminal);
  3119. }
  3120. if (terminal != null)
  3121. {
  3122. terminal = this.getCompositeParent(terminal);
  3123. }
  3124. return terminal;
  3125. };
  3126. /**
  3127. * Returns the first parent that is not a part.
  3128. */
  3129. Graph.prototype.getCompositeParent = function(cell)
  3130. {
  3131. while (this.isPart(cell))
  3132. {
  3133. var temp = this.model.getParent(cell);
  3134. if (!this.model.isVertex(temp))
  3135. {
  3136. break;
  3137. }
  3138. cell = temp;
  3139. }
  3140. return cell;
  3141. };
  3142. /**
  3143. * Returns the selection cells where the given function returns false.
  3144. */
  3145. Graph.prototype.filterSelectionCells = function(ignoreFn)
  3146. {
  3147. var cells = this.getSelectionCells();
  3148. if (ignoreFn != null)
  3149. {
  3150. var temp = [];
  3151. for (var i = 0; i < cells.length; i++)
  3152. {
  3153. if (!ignoreFn(cells[i]))
  3154. {
  3155. temp.push(cells[i]);
  3156. }
  3157. }
  3158. cells = temp;
  3159. }
  3160. return cells;
  3161. };
  3162. /**
  3163. * Overrides scrollRectToVisible to fix ignored transform.
  3164. */
  3165. var graphScrollRectToVisible = mxGraph.prototype.scrollRectToVisible;
  3166. Graph.prototype.scrollRectToVisible = function(r)
  3167. {
  3168. if (this.useCssTransforms)
  3169. {
  3170. var s = this.currentScale;
  3171. var t = this.currentTranslate;
  3172. r = new mxRectangle((r.x + 2 * t.x) * s - t.x,
  3173. (r.y + 2 * t.y) * s - t.y,
  3174. r.width * s, r.height * s);
  3175. }
  3176. graphScrollRectToVisible.apply(this, arguments);
  3177. };
  3178. /**
  3179. * Function: repaint
  3180. *
  3181. * Updates the highlight after a change of the model or view.
  3182. */
  3183. mxCellHighlight.prototype.getStrokeWidth = function(state)
  3184. {
  3185. var s = this.strokeWidth;
  3186. if (this.graph.useCssTransforms)
  3187. {
  3188. s /= this.graph.currentScale;
  3189. }
  3190. return s;
  3191. };
  3192. /**
  3193. * Function: getGraphBounds
  3194. *
  3195. * Overrides getGraphBounds to use bounding box from SVG.
  3196. */
  3197. mxGraphView.prototype.getGraphBounds = function()
  3198. {
  3199. var b = this.graphBounds;
  3200. if (this.graph.useCssTransforms)
  3201. {
  3202. var t = this.graph.currentTranslate;
  3203. var s = this.graph.currentScale;
  3204. b = new mxRectangle(
  3205. (b.x + t.x) * s, (b.y + t.y) * s,
  3206. b.width * s, b.height * s);
  3207. }
  3208. return b;
  3209. };
  3210. /**
  3211. * Overrides to bypass full cell tree validation.
  3212. * TODO: Check if this improves performance
  3213. */
  3214. mxGraphView.prototype.viewStateChanged = function()
  3215. {
  3216. if (this.graph.useCssTransforms)
  3217. {
  3218. this.validate();
  3219. this.graph.sizeDidChange();
  3220. }
  3221. else
  3222. {
  3223. this.revalidate();
  3224. this.graph.sizeDidChange();
  3225. }
  3226. };
  3227. /**
  3228. * Overrides validate to normalize validation view state and pass
  3229. * current state to CSS transform.
  3230. */
  3231. var graphViewValidate = mxGraphView.prototype.validate;
  3232. mxGraphView.prototype.validate = function(cell)
  3233. {
  3234. if (this.graph.useCssTransforms)
  3235. {
  3236. this.graph.currentScale = this.scale;
  3237. this.graph.currentTranslate.x = this.translate.x;
  3238. this.graph.currentTranslate.y = this.translate.y;
  3239. this.scale = 1;
  3240. this.translate.x = 0;
  3241. this.translate.y = 0;
  3242. }
  3243. graphViewValidate.apply(this, arguments);
  3244. if (this.graph.useCssTransforms)
  3245. {
  3246. this.graph.updateCssTransform();
  3247. this.scale = this.graph.currentScale;
  3248. this.translate.x = this.graph.currentTranslate.x;
  3249. this.translate.y = this.graph.currentTranslate.y;
  3250. }
  3251. };
  3252. /**
  3253. * Overrides function to exclude table cells and rows from groups.
  3254. */
  3255. var graphGetCellsForGroup = mxGraph.prototype.getCellsForGroup;
  3256. Graph.prototype.getCellsForGroup = function(cells)
  3257. {
  3258. cells = graphGetCellsForGroup.apply(this, arguments);
  3259. var result = [];
  3260. // Filters selection cells with the same parent
  3261. for (var i = 0; i < cells.length; i++)
  3262. {
  3263. if (!this.isTableRow(cells[i]) &&
  3264. !this.isTableCell(cells[i]))
  3265. {
  3266. result.push(cells[i]);
  3267. }
  3268. }
  3269. return result;
  3270. };
  3271. /**
  3272. * Overrides function to exclude tables, rows and cells from ungrouping.
  3273. */
  3274. var graphGetCellsForUngroup = mxGraph.prototype.getCellsForUngroup;
  3275. Graph.prototype.getCellsForUngroup = function(cells)
  3276. {
  3277. cells = graphGetCellsForUngroup.apply(this, arguments);
  3278. var result = [];
  3279. // Filters selection cells with the same parent
  3280. for (var i = 0; i < cells.length; i++)
  3281. {
  3282. if (!this.isTable(cells[i]) &&
  3283. !this.isTableRow(cells[i]) &&
  3284. !this.isTableCell(cells[i]))
  3285. {
  3286. result.push(cells[i]);
  3287. }
  3288. }
  3289. return result;
  3290. };
  3291. /**
  3292. * Function: updateCssTransform
  3293. *
  3294. * Zooms out of the graph by <zoomFactor>.
  3295. */
  3296. Graph.prototype.updateCssTransform = function()
  3297. {
  3298. var temp = this.view.getDrawPane();
  3299. if (temp != null)
  3300. {
  3301. var g = temp.parentNode;
  3302. if (!this.useCssTransforms)
  3303. {
  3304. g.removeAttribute('transformOrigin');
  3305. g.removeAttribute('transform');
  3306. }
  3307. else
  3308. {
  3309. var prev = g.getAttribute('transform');
  3310. g.setAttribute('transformOrigin', '0 0');
  3311. var s = Math.round(this.currentScale * 100) / 100;
  3312. var dx = Math.round(this.currentTranslate.x * 100) / 100;
  3313. var dy = Math.round(this.currentTranslate.y * 100) / 100;
  3314. g.setAttribute('transform', 'scale(' + s + ',' + s + ')' +
  3315. 'translate(' + dx + ',' + dy + ')');
  3316. // Applies workarounds only if translate has changed
  3317. if (prev != g.getAttribute('transform'))
  3318. {
  3319. this.fireEvent(new mxEventObject('cssTransformChanged'),
  3320. 'transform', g.getAttribute('transform'));
  3321. }
  3322. }
  3323. }
  3324. };
  3325. var graphViewValidateBackgroundPage = mxGraphView.prototype.validateBackgroundPage;
  3326. mxGraphView.prototype.validateBackgroundPage = function()
  3327. {
  3328. var useCssTranforms = this.graph.useCssTransforms, scale = this.scale,
  3329. translate = this.translate;
  3330. if (useCssTranforms)
  3331. {
  3332. this.scale = this.graph.currentScale;
  3333. this.translate = this.graph.currentTranslate;
  3334. }
  3335. graphViewValidateBackgroundPage.apply(this, arguments);
  3336. if (useCssTranforms)
  3337. {
  3338. this.scale = scale;
  3339. this.translate = translate;
  3340. }
  3341. };
  3342. var graphUpdatePageBreaks = mxGraph.prototype.updatePageBreaks;
  3343. mxGraph.prototype.updatePageBreaks = function(visible, width, height)
  3344. {
  3345. var useCssTranforms = this.useCssTransforms, scale = this.view.scale,
  3346. translate = this.view.translate;
  3347. if (useCssTranforms)
  3348. {
  3349. this.view.scale = 1;
  3350. this.view.translate = new mxPoint(0, 0);
  3351. this.useCssTransforms = false;
  3352. }
  3353. graphUpdatePageBreaks.apply(this, arguments);
  3354. if (useCssTranforms)
  3355. {
  3356. this.view.scale = scale;
  3357. this.view.translate = translate;
  3358. this.useCssTransforms = true;
  3359. }
  3360. };
  3361. })();
  3362. /**
  3363. * Sets the XML node for the current diagram.
  3364. */
  3365. Graph.prototype.isLightboxView = function()
  3366. {
  3367. return this.lightbox;
  3368. };
  3369. /**
  3370. * Sets the XML node for the current diagram.
  3371. */
  3372. Graph.prototype.isViewer = function()
  3373. {
  3374. return false;
  3375. };
  3376. /**
  3377. * Installs automatic layout via styles
  3378. */
  3379. Graph.prototype.labelLinkClicked = function(state, elt, evt)
  3380. {
  3381. var href = elt.getAttribute('href');
  3382. // Blocks and removes unsafe links in labels
  3383. if (href != Graph.sanitizeLink(href))
  3384. {
  3385. Graph.sanitizeNode(elt);
  3386. }
  3387. if (href != null && !this.isCustomLink(href) && ((mxEvent.isLeftMouseButton(evt) &&
  3388. !mxEvent.isPopupTrigger(evt)) || mxEvent.isTouchEvent(evt)))
  3389. {
  3390. if (!this.isEnabled() || this.isCellLocked(state.cell))
  3391. {
  3392. var target = this.isBlankLink(href) ? this.linkTarget : '_top';
  3393. this.openLink(this.getAbsoluteUrl(href), target);
  3394. }
  3395. mxEvent.consume(evt);
  3396. }
  3397. };
  3398. /**
  3399. * Returns the size of the page format scaled with the page size.
  3400. */
  3401. Graph.prototype.openLink = function(href, target, allowOpener)
  3402. {
  3403. var result = window;
  3404. try
  3405. {
  3406. href = Graph.sanitizeLink(href);
  3407. if (href != null)
  3408. {
  3409. // Workaround for blocking in same iframe
  3410. if (target == '_self' && window != window.top)
  3411. {
  3412. window.location.href = href;
  3413. }
  3414. else
  3415. {
  3416. // Avoids page reload for anchors (workaround for IE but used everywhere)
  3417. if (href.substring(0, this.baseUrl.length) == this.baseUrl &&
  3418. href.charAt(this.baseUrl.length) == '#' &&
  3419. target == '_top' && window == window.top)
  3420. {
  3421. var hash = href.split('#')[1];
  3422. // Forces navigation if on same hash
  3423. if (window.location.hash == '#' + hash)
  3424. {
  3425. window.location.hash = '';
  3426. }
  3427. window.location.hash = hash;
  3428. }
  3429. else
  3430. {
  3431. result = window.open(href, (target != null) ?
  3432. target : '_blank', (!allowOpener) ?
  3433. 'noopener,noreferrer' : null);
  3434. if (result != null && !allowOpener)
  3435. {
  3436. result.opener = null;
  3437. }
  3438. }
  3439. }
  3440. }
  3441. }
  3442. catch (e)
  3443. {
  3444. // ignores permission denied
  3445. }
  3446. return result;
  3447. };
  3448. /**
  3449. * Adds support for page links.
  3450. */
  3451. Graph.prototype.getLinkTitle = function(href)
  3452. {
  3453. return href.substring(href.lastIndexOf('/') + 1);
  3454. };
  3455. /**
  3456. * Adds support for page links.
  3457. */
  3458. Graph.prototype.isCustomLink = function(href)
  3459. {
  3460. return href.substring(0, 5) == 'data:';
  3461. };
  3462. /**
  3463. * Adds support for page links.
  3464. */
  3465. Graph.prototype.customLinkClicked = function(link, associatedCell)
  3466. {
  3467. return false;
  3468. };
  3469. /**
  3470. * Returns true if the given href references an external protocol that
  3471. * should never open in a new window. Default returns true for mailto.
  3472. */
  3473. Graph.prototype.isExternalProtocol = function(href)
  3474. {
  3475. return href.substring(0, 7) === 'mailto:';
  3476. };
  3477. /**
  3478. * Hook for links to open in same window. Default returns true for anchors,
  3479. * links to same domain or if target == 'self' in the config.
  3480. */
  3481. Graph.prototype.isBlankLink = function(href)
  3482. {
  3483. return !this.isExternalProtocol(href) &&
  3484. (this.linkPolicy === 'blank' ||
  3485. (this.linkPolicy !== 'self' &&
  3486. !this.isRelativeUrl(href) &&
  3487. href.substring(0, this.domainUrl.length) !== this.domainUrl));
  3488. };
  3489. /**
  3490. *
  3491. */
  3492. Graph.prototype.isRelativeUrl = function(url)
  3493. {
  3494. return url != null && !this.absoluteUrlPattern.test(url) &&
  3495. url.substring(0, 5) !== 'data:' &&
  3496. !this.isExternalProtocol(url);
  3497. };
  3498. /**
  3499. *
  3500. */
  3501. Graph.prototype.getAbsoluteUrl = function(url)
  3502. {
  3503. if (url != null && this.isRelativeUrl(url))
  3504. {
  3505. if (url.charAt(0) == '#')
  3506. {
  3507. url = this.baseUrl + url;
  3508. }
  3509. else if (url.charAt(0) == '/')
  3510. {
  3511. url = this.domainUrl + url;
  3512. }
  3513. else
  3514. {
  3515. url = this.domainPathUrl + url;
  3516. }
  3517. }
  3518. return url;
  3519. };
  3520. /**
  3521. * Installs automatic layout via styles
  3522. */
  3523. Graph.prototype.initLayoutManager = function()
  3524. {
  3525. this.layoutManager = new mxLayoutManager(this);
  3526. this.layoutManager.hasLayout = function(cell)
  3527. {
  3528. return this.graph.getCellStyle(cell)['childLayout'] != null;
  3529. };
  3530. this.layoutManager.getLayout = function(cell, eventName)
  3531. {
  3532. var parent = this.graph.model.getParent(cell);
  3533. // Executes layouts from top to bottom except for nested layouts where
  3534. // child layouts are executed before and after the parent layout runs
  3535. // in case the layout changes the size of the child cell
  3536. if (!this.graph.isCellCollapsed(cell) && (eventName != mxEvent.BEGIN_UPDATE ||
  3537. this.hasLayout(parent, eventName)))
  3538. {
  3539. var style = this.graph.getCellStyle(cell);
  3540. if (style['childLayout'] == 'stackLayout')
  3541. {
  3542. var stackLayout = new mxStackLayout(this.graph, true);
  3543. stackLayout.resizeParentMax = mxUtils.getValue(style, 'resizeParentMax', '1') == '1';
  3544. stackLayout.horizontal = mxUtils.getValue(style, 'horizontalStack', '1') == '1';
  3545. stackLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  3546. stackLayout.resizeLast = mxUtils.getValue(style, 'resizeLast', '0') == '1';
  3547. stackLayout.spacing = style['stackSpacing'] || stackLayout.spacing;
  3548. stackLayout.border = style['stackBorder'] || stackLayout.border;
  3549. stackLayout.marginLeft = style['marginLeft'] || 0;
  3550. stackLayout.marginRight = style['marginRight'] || 0;
  3551. stackLayout.marginTop = style['marginTop'] || 0;
  3552. stackLayout.marginBottom = style['marginBottom'] || 0;
  3553. stackLayout.allowGaps = style['allowGaps'] || 0;
  3554. stackLayout.fill = true;
  3555. if (stackLayout.allowGaps)
  3556. {
  3557. stackLayout.gridSize = parseFloat(mxUtils.getValue(style, 'stackUnitSize', 20));
  3558. }
  3559. return stackLayout;
  3560. }
  3561. else if (style['childLayout'] == 'treeLayout')
  3562. {
  3563. var treeLayout = new mxCompactTreeLayout(this.graph);
  3564. treeLayout.horizontal = mxUtils.getValue(style, 'horizontalTree', '1') == '1';
  3565. treeLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  3566. treeLayout.sortEdges = mxUtils.getValue(style, 'sortEdges', '0') == '1';
  3567. treeLayout.groupPadding = mxUtils.getValue(style, 'parentPadding', 20);
  3568. treeLayout.levelDistance = mxUtils.getValue(style, 'treeLevelDistance', 30);
  3569. treeLayout.maintainParentLocation = true;
  3570. treeLayout.edgeRouting = false;
  3571. treeLayout.resetEdges = false;
  3572. return treeLayout;
  3573. }
  3574. else if (style['childLayout'] == 'flowLayout')
  3575. {
  3576. var flowLayout = new mxHierarchicalLayout(this.graph, mxUtils.getValue(style,
  3577. 'flowOrientation', mxConstants.DIRECTION_EAST));
  3578. flowLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  3579. flowLayout.parentBorder = mxUtils.getValue(style, 'parentPadding', 20);
  3580. flowLayout.maintainParentLocation = true;
  3581. // Special undocumented styles for changing the hierarchical
  3582. flowLayout.intraCellSpacing = mxUtils.getValue(style, 'intraCellSpacing',
  3583. mxHierarchicalLayout.prototype.intraCellSpacing);
  3584. flowLayout.interRankCellSpacing = mxUtils.getValue(style, 'interRankCellSpacing',
  3585. mxHierarchicalLayout.prototype.interRankCellSpacing);
  3586. flowLayout.interHierarchySpacing = mxUtils.getValue(style, 'interHierarchySpacing',
  3587. mxHierarchicalLayout.prototype.interHierarchySpacing);
  3588. flowLayout.parallelEdgeSpacing = mxUtils.getValue(style, 'parallelEdgeSpacing',
  3589. mxHierarchicalLayout.prototype.parallelEdgeSpacing);
  3590. return flowLayout;
  3591. }
  3592. else if (style['childLayout'] == 'circleLayout')
  3593. {
  3594. return new mxCircleLayout(this.graph);
  3595. }
  3596. else if (style['childLayout'] == 'organicLayout')
  3597. {
  3598. return new mxFastOrganicLayout(this.graph);
  3599. }
  3600. else if (style['childLayout'] == 'tableLayout')
  3601. {
  3602. return new TableLayout(this.graph);
  3603. }
  3604. else if (style['childLayout'] != null &&
  3605. String(style['childLayout']).charAt(0) == '[')
  3606. {
  3607. try
  3608. {
  3609. return new mxCompositeLayout(this.graph,
  3610. this.graph.createLayouts(JSON.parse(
  3611. style['childLayout'])));
  3612. }
  3613. catch (e)
  3614. {
  3615. if (window.console != null)
  3616. {
  3617. console.error(e);
  3618. }
  3619. }
  3620. }
  3621. }
  3622. return null;
  3623. };
  3624. };
  3625. /**
  3626. * Creates an array of graph layouts from the given array of the form [{layout: name, config: obj}, ...]
  3627. * where name is the layout constructor name and config contains the properties of the layout instance.
  3628. */
  3629. Graph.prototype.createLayouts = function(list)
  3630. {
  3631. var layouts = [];
  3632. for (var i = 0; i < list.length; i++)
  3633. {
  3634. if (mxUtils.indexOf(Graph.layoutNames, list[i].layout) >= 0)
  3635. {
  3636. // Handles special case of branch optimizer in orgchart
  3637. var layout = (list[i].layout == 'mxOrgChartLayout' && list[i].config != null) ?
  3638. new window[list[i].layout](this, list[i].config['branchOptimizer']) :
  3639. new window[list[i].layout](this);
  3640. if (list[i].config != null)
  3641. {
  3642. for (var key in list[i].config)
  3643. {
  3644. // Ignores branch optimizer in orgchart (handled above)
  3645. if (list[i].layout != 'mxOrgChartLayout' ||
  3646. key != 'branchOptimizer')
  3647. {
  3648. layout[key] = list[i].config[key];
  3649. }
  3650. }
  3651. }
  3652. layouts.push(layout);
  3653. }
  3654. else
  3655. {
  3656. throw Error(mxResources.get('invalidCallFnNotFound', [list[i].layout]));
  3657. }
  3658. }
  3659. return layouts;
  3660. };
  3661. /**
  3662. * Returns the metadata of the given cells as a JSON object. The value with
  3663. * resolved placeholders for the label is included if includeValues is true.
  3664. */
  3665. Graph.prototype.getDataForCells = function(cells, includeValues)
  3666. {
  3667. var result = [];
  3668. for (var i = 0; i < cells.length; i++)
  3669. {
  3670. var row = {};
  3671. row.id = cells[i].id;
  3672. var attrs = (cells[i].value != null) ? cells[i].value.attributes : null;
  3673. if (this.isReplacePlaceholders(cells[i]) && includeValues)
  3674. {
  3675. row.value = this.getLabel(cells[i]);
  3676. }
  3677. if (attrs != null)
  3678. {
  3679. for (var j = 0; j < attrs.length; j++)
  3680. {
  3681. row[attrs[j].nodeName] = attrs[j].nodeValue;
  3682. }
  3683. }
  3684. else
  3685. {
  3686. row.label = this.convertValueToString(cells[i]);
  3687. }
  3688. result.push(row);
  3689. }
  3690. return result;
  3691. };
  3692. /**
  3693. * Returns the DOM nodes for the given cells.
  3694. */
  3695. Graph.prototype.getNodesForCells = function(cells)
  3696. {
  3697. var nodes = [];
  3698. for (var i = 0; i < cells.length; i++)
  3699. {
  3700. var state = this.view.getState(cells[i]);
  3701. if (state != null)
  3702. {
  3703. var shapes = this.cellRenderer.getShapesForState(state);
  3704. for (var j = 0; j < shapes.length; j++)
  3705. {
  3706. if (shapes[j] != null && shapes[j].node != null)
  3707. {
  3708. nodes.push(shapes[j].node);
  3709. }
  3710. }
  3711. // Adds folding icon
  3712. if (state.control != null && state.control.node != null)
  3713. {
  3714. nodes.push(state.control.node);
  3715. }
  3716. }
  3717. }
  3718. return nodes;
  3719. };
  3720. /**
  3721. * Creates animations for the given cells.
  3722. */
  3723. Graph.prototype.createWipeAnimations = function(cells, wipeIn)
  3724. {
  3725. var animations = [];
  3726. for (var i = 0; i < cells.length; i++)
  3727. {
  3728. var state = this.view.getState(cells[i]);
  3729. if (state != null && state.shape != null)
  3730. {
  3731. // TODO: include descendants
  3732. if (this.model.isEdge(state.cell) &&
  3733. state.absolutePoints != null &&
  3734. state.absolutePoints.length > 1)
  3735. {
  3736. animations.push(this.createEdgeWipeAnimation(state, wipeIn));
  3737. }
  3738. else if (this.model.isVertex(state.cell) &&
  3739. state.shape.bounds != null)
  3740. {
  3741. animations.push(this.createVertexWipeAnimation(state, wipeIn));
  3742. }
  3743. }
  3744. }
  3745. return animations;
  3746. };
  3747. /**
  3748. * Creates an object to show the given edge cell state.
  3749. */
  3750. Graph.prototype.createEdgeWipeAnimation = function(state, wipeIn)
  3751. {
  3752. var pts = state.absolutePoints.slice();
  3753. var segs = state.segments;
  3754. var total = state.length;
  3755. var n = pts.length;
  3756. return {
  3757. execute: mxUtils.bind(this, function(step, steps)
  3758. {
  3759. if (state.shape != null)
  3760. {
  3761. var pts2 = [pts[0]];
  3762. var f = step / steps;
  3763. if (!wipeIn)
  3764. {
  3765. f = 1 - f;
  3766. }
  3767. var dist = total * f;
  3768. for (var i = 1; i < n; i++)
  3769. {
  3770. if (dist <= segs[i - 1])
  3771. {
  3772. pts2.push(new mxPoint(pts[i - 1].x + (pts[i].x - pts[i - 1].x) * dist / segs[i - 1],
  3773. pts[i - 1].y + (pts[i].y - pts[i - 1].y) * dist / segs[i - 1]));
  3774. break;
  3775. }
  3776. else
  3777. {
  3778. dist -= segs[i - 1];
  3779. pts2.push(pts[i]);
  3780. }
  3781. }
  3782. state.shape.points = pts2;
  3783. state.shape.redraw();
  3784. if (step == 0)
  3785. {
  3786. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), 1);
  3787. }
  3788. if (state.text != null && state.text.node != null)
  3789. {
  3790. state.text.node.style.opacity = f;
  3791. }
  3792. }
  3793. }),
  3794. stop: mxUtils.bind(this, function()
  3795. {
  3796. if (state.shape != null)
  3797. {
  3798. state.shape.points = pts;
  3799. state.shape.redraw();
  3800. if (state.text != null && state.text.node != null)
  3801. {
  3802. state.text.node.style.opacity = ''
  3803. }
  3804. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), (wipeIn) ? 1 : 0);
  3805. }
  3806. })
  3807. };
  3808. };
  3809. /**
  3810. * Creates an object to show the given vertex cell state.
  3811. */
  3812. Graph.prototype.createVertexWipeAnimation = function(state, wipeIn)
  3813. {
  3814. var bds = new mxRectangle.fromRectangle(state.shape.bounds);
  3815. return {
  3816. execute: mxUtils.bind(this, function(step, steps)
  3817. {
  3818. if (state.shape != null)
  3819. {
  3820. var f = step / steps;
  3821. if (!wipeIn)
  3822. {
  3823. f = 1 - f;
  3824. }
  3825. state.shape.bounds = new mxRectangle(bds.x, bds.y, bds.width * f, bds.height);
  3826. state.shape.redraw();
  3827. if (step == 0)
  3828. {
  3829. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), 1);
  3830. }
  3831. if (state.text != null && state.text.node != null)
  3832. {
  3833. state.text.node.style.opacity = f;
  3834. }
  3835. }
  3836. }),
  3837. stop: mxUtils.bind(this, function()
  3838. {
  3839. if (state.shape != null)
  3840. {
  3841. state.shape.bounds = bds;
  3842. state.shape.redraw();
  3843. if (state.text != null && state.text.node != null)
  3844. {
  3845. state.text.node.style.opacity = ''
  3846. }
  3847. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), (wipeIn) ? 1 : 0);
  3848. }
  3849. })
  3850. };
  3851. };
  3852. /**
  3853. * Runs the animations for the given cells.
  3854. */
  3855. Graph.prototype.executeAnimations = function(animations, done, steps, delay)
  3856. {
  3857. steps = (steps != null) ? steps : 30;
  3858. delay = (delay != null) ? delay : 30;
  3859. var thread = null;
  3860. var step = 0;
  3861. var animate = mxUtils.bind(this, function()
  3862. {
  3863. if (step == steps || this.stoppingCustomActions)
  3864. {
  3865. window.clearInterval(thread);
  3866. for (var i = 0; i < animations.length; i++)
  3867. {
  3868. animations[i].stop();
  3869. }
  3870. if (done != null)
  3871. {
  3872. done();
  3873. }
  3874. }
  3875. else
  3876. {
  3877. for (var i = 0; i < animations.length; i++)
  3878. {
  3879. animations[i].execute(step, steps);
  3880. }
  3881. }
  3882. step++;
  3883. });
  3884. thread = window.setInterval(animate, delay);
  3885. animate();
  3886. };
  3887. /**
  3888. * Returns the size of the page format scaled with the page size.
  3889. */
  3890. Graph.prototype.getPageSize = function()
  3891. {
  3892. return (this.pageVisible && this.pageFormat != null) ?
  3893. new mxRectangle(0, 0, this.pageFormat.width * this.pageScale,
  3894. this.pageFormat.height * this.pageScale) : this.scrollTileSize;
  3895. };
  3896. /**
  3897. * Returns a rectangle describing the position and count of the
  3898. * background pages, where x and y are the position of the top,
  3899. * left page and width and height are the vertical and horizontal
  3900. * page count.
  3901. */
  3902. Graph.prototype.getPageLayout = function(bounds, tr, s)
  3903. {
  3904. bounds = (bounds != null) ? bounds : this.getGraphBounds();
  3905. tr = (tr != null) ? tr : this.view.translate;
  3906. s = (s != null) ? s : this.view.scale;
  3907. var size = this.getPageSize();
  3908. if (bounds.width == 0 || bounds.height == 0)
  3909. {
  3910. return new mxRectangle(0, 0, 1, 1);
  3911. }
  3912. else
  3913. {
  3914. var x0 = Math.floor(Math.ceil(bounds.x / s - tr.x) / size.width);
  3915. var y0 = Math.floor(Math.ceil(bounds.y / s - tr.y) / size.height);
  3916. var w0 = Math.ceil((Math.floor((bounds.x + bounds.width) /
  3917. s) - tr.x) / size.width) - x0;
  3918. var h0 = Math.ceil((Math.floor((bounds.y + bounds.height) /
  3919. s) - tr.y) / size.height) - y0;
  3920. return new mxRectangle(x0, y0, w0, h0);
  3921. }
  3922. };
  3923. /**
  3924. * Returns the default view translation for the given page layout.
  3925. */
  3926. Graph.prototype.getDefaultTranslate = function(pageLayout)
  3927. {
  3928. var pad = this.getPagePadding();
  3929. var size = this.getPageSize();
  3930. return new mxPoint(pad.x - pageLayout.x * size.width,
  3931. pad.y - pageLayout.y * size.height);
  3932. };
  3933. /**
  3934. * Updates the minimum graph size
  3935. */
  3936. Graph.prototype.updateMinimumSize = function()
  3937. {
  3938. var pageLayout = this.getPageLayout();
  3939. var pad = this.getPagePadding();
  3940. var size = this.getPageSize();
  3941. var minw = Math.ceil(2 * pad.x + pageLayout.width * size.width);
  3942. var minh = Math.ceil(2 * pad.y + pageLayout.height * size.height);
  3943. if (this.minimumGraphSize == null ||
  3944. this.minimumGraphSize.width != minw ||
  3945. this.minimumGraphSize.height != minh)
  3946. {
  3947. this.minimumGraphSize = new mxRectangle(0, 0, minw, minh);
  3948. }
  3949. };
  3950. /**
  3951. * Sanitizes the given HTML markup.
  3952. */
  3953. Graph.prototype.sanitizeHtml = function(value, editing)
  3954. {
  3955. return Graph.sanitizeHtml(value, editing);
  3956. };
  3957. /**
  3958. * Revalidates all cells with placeholders in the current graph model.
  3959. */
  3960. Graph.prototype.updatePlaceholders = function()
  3961. {
  3962. var validate = false;
  3963. for (var key in this.model.cells)
  3964. {
  3965. var cell = this.model.cells[key];
  3966. if (this.isReplacePlaceholders(cell))
  3967. {
  3968. this.view.invalidate(cell, false, false);
  3969. validate = true;
  3970. }
  3971. }
  3972. if (validate)
  3973. {
  3974. this.view.validate();
  3975. }
  3976. };
  3977. /**
  3978. * Adds support for placeholders in labels.
  3979. */
  3980. Graph.prototype.isReplacePlaceholders = function(cell)
  3981. {
  3982. return cell.value != null && typeof(cell.value) == 'object' &&
  3983. cell.value.getAttribute('placeholders') == '1';
  3984. };
  3985. /**
  3986. * Returns true if the given mouse wheel event should be used for zooming. This
  3987. * is invoked if no dialogs are showing and returns true with Alt or Control
  3988. * (or cmd in macOS only) is pressed.
  3989. */
  3990. Graph.prototype.isZoomWheelEvent = function(evt)
  3991. {
  3992. return (Graph.zoomWheel && !mxEvent.isShiftDown(evt) && !mxEvent.isMetaDown(evt) &&
  3993. !mxEvent.isAltDown(evt) && (!mxEvent.isControlDown(evt) || mxClient.IS_MAC)) ||
  3994. (!Graph.zoomWheel && (mxEvent.isAltDown(evt) || mxEvent.isControlDown(evt)));
  3995. };
  3996. /**
  3997. * Returns true if the given scroll wheel event should be used for scrolling.
  3998. */
  3999. Graph.prototype.isScrollWheelEvent = function(evt)
  4000. {
  4001. return !this.isZoomWheelEvent(evt);
  4002. };
  4003. /**
  4004. * Adds Alt+click to select cells behind cells (Shift+Click on Chrome OS).
  4005. */
  4006. Graph.prototype.isTransparentClickEvent = function(evt)
  4007. {
  4008. return mxEvent.isAltDown(evt) || (mxClient.IS_CHROMEOS && mxEvent.isShiftDown(evt));
  4009. };
  4010. /**
  4011. * Adds ctrl+shift+connect to disable connections.
  4012. */
  4013. Graph.prototype.isIgnoreTerminalEvent = function(evt)
  4014. {
  4015. return mxEvent.isAltDown(evt) && !mxEvent.isShiftDown(evt) &&
  4016. !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt);
  4017. };
  4018. /**
  4019. * Returns true if the given edge should be ignored.
  4020. */
  4021. Graph.prototype.isEdgeIgnored = function(cell)
  4022. {
  4023. var result = false;
  4024. if (cell != null)
  4025. {
  4026. var style = this.getCurrentCellStyle(cell);
  4027. result = mxUtils.getValue(style, 'ignoreEdge', '0') == '1';
  4028. }
  4029. return result;
  4030. };
  4031. /**
  4032. * Adds support for placeholders in labels.
  4033. */
  4034. Graph.prototype.isSplitTarget = function(target, cells, evt)
  4035. {
  4036. return !this.model.isEdge(cells[0]) &&
  4037. !mxEvent.isAltDown(evt) && !mxEvent.isShiftDown(evt) &&
  4038. !this.isCellLocked(this.getLayerForCell(target)) &&
  4039. mxGraph.prototype.isSplitTarget.apply(this, arguments);
  4040. };
  4041. /**
  4042. * Adds support for placeholders in labels.
  4043. */
  4044. Graph.prototype.getLabel = function(cell)
  4045. {
  4046. var result = mxGraph.prototype.getLabel.apply(this, arguments);
  4047. if (result != null && this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') == null)
  4048. {
  4049. result = this.replacePlaceholders(cell, result);
  4050. }
  4051. return result;
  4052. };
  4053. /**
  4054. * Adds labelMovable style.
  4055. */
  4056. Graph.prototype.isLabelMovable = function(cell)
  4057. {
  4058. var style = this.getCurrentCellStyle(cell);
  4059. return !this.isCellLocked(cell) &&
  4060. ((this.model.isEdge(cell) && this.edgeLabelsMovable) ||
  4061. (this.model.isVertex(cell) && (this.vertexLabelsMovable ||
  4062. mxUtils.getValue(style, 'labelMovable', '0') == '1')));
  4063. };
  4064. /**
  4065. * Adds event if grid size is changed.
  4066. */
  4067. Graph.prototype.setGridSize = function(value)
  4068. {
  4069. this.gridSize = value;
  4070. this.fireEvent(new mxEventObject('gridSizeChanged'));
  4071. };
  4072. /**
  4073. * Adds event if default parent is changed.
  4074. */
  4075. Graph.prototype.setDefaultParent = function(cell)
  4076. {
  4077. this.defaultParent = cell;
  4078. this.fireEvent(new mxEventObject('defaultParentChanged'));
  4079. };
  4080. /**
  4081. * Function: getClickableLinkForCell
  4082. *
  4083. * Returns the first non-null link for the cell or its ancestors.
  4084. *
  4085. * Parameters:
  4086. *
  4087. * cell - <mxCell> whose link should be returned.
  4088. */
  4089. Graph.prototype.getClickableLinkForCell = function(cell)
  4090. {
  4091. do
  4092. {
  4093. var link = this.getLinkForCell(cell);
  4094. if (link != null)
  4095. {
  4096. return link;
  4097. }
  4098. cell = this.model.getParent(cell);
  4099. } while (cell != null);
  4100. return null;
  4101. };
  4102. /**
  4103. * Private helper method.
  4104. */
  4105. Graph.prototype.getGlobalVariable = function(name)
  4106. {
  4107. var val = null;
  4108. if (name == 'date')
  4109. {
  4110. val = new Date().toLocaleDateString();
  4111. }
  4112. else if (name == 'time')
  4113. {
  4114. val = new Date().toLocaleTimeString();
  4115. }
  4116. else if (name == 'timestamp')
  4117. {
  4118. val = new Date().toLocaleString();
  4119. }
  4120. else if (name.substring(0, 5) == 'date{')
  4121. {
  4122. var fmt = name.substring(5, name.length - 1);
  4123. val = this.formatDate(new Date(), fmt);
  4124. }
  4125. return val;
  4126. };
  4127. /**
  4128. * Formats a date, see http://blog.stevenlevithan.com/archives/date-time-format
  4129. */
  4130. Graph.prototype.formatDate = function(date, mask, utc)
  4131. {
  4132. // LATER: Cache regexs
  4133. if (this.dateFormatCache == null)
  4134. {
  4135. this.dateFormatCache = {
  4136. i18n: {
  4137. dayNames: [
  4138. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
  4139. "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  4140. ],
  4141. monthNames: [
  4142. "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  4143. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  4144. ]
  4145. },
  4146. masks: {
  4147. "default": "ddd mmm dd yyyy HH:MM:ss",
  4148. shortDate: "m/d/yy",
  4149. mediumDate: "mmm d, yyyy",
  4150. longDate: "mmmm d, yyyy",
  4151. fullDate: "dddd, mmmm d, yyyy",
  4152. shortTime: "h:MM TT",
  4153. mediumTime: "h:MM:ss TT",
  4154. longTime: "h:MM:ss TT Z",
  4155. isoDate: "yyyy-mm-dd",
  4156. isoTime: "HH:MM:ss",
  4157. isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
  4158. isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
  4159. }
  4160. };
  4161. }
  4162. var dF = this.dateFormatCache;
  4163. var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
  4164. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  4165. timezoneClip = /[^-+\dA-Z]/g,
  4166. pad = function (val, len) {
  4167. val = String(val);
  4168. len = len || 2;
  4169. while (val.length < len) val = "0" + val;
  4170. return val;
  4171. };
  4172. // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
  4173. if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
  4174. mask = date;
  4175. date = undefined;
  4176. }
  4177. // Passing date through Date applies Date.parse, if necessary
  4178. date = date ? new Date(date) : new Date;
  4179. if (isNaN(date)) throw SyntaxError("invalid date");
  4180. mask = String(dF.masks[mask] || mask || dF.masks["default"]);
  4181. // Allow setting the utc argument via the mask
  4182. if (mask.slice(0, 4) == "UTC:") {
  4183. mask = mask.slice(4);
  4184. utc = true;
  4185. }
  4186. var _ = utc ? "getUTC" : "get",
  4187. d = date[_ + "Date"](),
  4188. D = date[_ + "Day"](),
  4189. m = date[_ + "Month"](),
  4190. y = date[_ + "FullYear"](),
  4191. H = date[_ + "Hours"](),
  4192. M = date[_ + "Minutes"](),
  4193. s = date[_ + "Seconds"](),
  4194. L = date[_ + "Milliseconds"](),
  4195. o = utc ? 0 : date.getTimezoneOffset(),
  4196. flags = {
  4197. d: d,
  4198. dd: pad(d),
  4199. ddd: dF.i18n.dayNames[D],
  4200. dddd: dF.i18n.dayNames[D + 7],
  4201. m: m + 1,
  4202. mm: pad(m + 1),
  4203. mmm: dF.i18n.monthNames[m],
  4204. mmmm: dF.i18n.monthNames[m + 12],
  4205. yy: String(y).slice(2),
  4206. yyyy: y,
  4207. h: H % 12 || 12,
  4208. hh: pad(H % 12 || 12),
  4209. H: H,
  4210. HH: pad(H),
  4211. M: M,
  4212. MM: pad(M),
  4213. s: s,
  4214. ss: pad(s),
  4215. l: pad(L, 3),
  4216. L: pad(L > 99 ? Math.round(L / 10) : L),
  4217. t: H < 12 ? "a" : "p",
  4218. tt: H < 12 ? "am" : "pm",
  4219. T: H < 12 ? "A" : "P",
  4220. TT: H < 12 ? "AM" : "PM",
  4221. Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  4222. o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  4223. S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
  4224. };
  4225. return mask.replace(token, function ($0)
  4226. {
  4227. return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
  4228. });
  4229. };
  4230. /**
  4231. *
  4232. */
  4233. Graph.prototype.getLayerForCell = function(cell)
  4234. {
  4235. while (cell != null && !this.model.isLayer(cell))
  4236. {
  4237. cell = this.model.getParent(cell);
  4238. }
  4239. return cell;
  4240. };
  4241. /**
  4242. *
  4243. */
  4244. Graph.prototype.getLayerForCells = function(cells)
  4245. {
  4246. var result = null;
  4247. if (cells.length > 0)
  4248. {
  4249. result = this.getLayerForCell(cells[0]);
  4250. for (var i = 1; i < cells.length; i++)
  4251. {
  4252. if (!this.model.isAncestor(result, cells[i]))
  4253. {
  4254. result = null;
  4255. break;
  4256. }
  4257. }
  4258. }
  4259. return result;
  4260. };
  4261. /**
  4262. *
  4263. */
  4264. Graph.prototype.createLayersDialog = function(onchange, inverted)
  4265. {
  4266. var div = document.createElement('div');
  4267. div.style.position = 'absolute';
  4268. var model = this.getModel();
  4269. var childCount = model.getChildCount(model.root);
  4270. for (var i = 0; i < childCount; i++)
  4271. {
  4272. (mxUtils.bind(this, function(layer)
  4273. {
  4274. var title = this.convertValueToString(layer) ||
  4275. (mxResources.get('background') || 'Background');
  4276. var span = document.createElement('div');
  4277. span.style.overflow = 'hidden';
  4278. span.style.textOverflow = 'ellipsis';
  4279. span.style.padding = '2px';
  4280. span.style.whiteSpace = 'nowrap';
  4281. span.style.cursor = 'pointer';
  4282. span.setAttribute('title', mxResources.get(
  4283. model.isVisible(layer) ?
  4284. 'hideIt' : 'show', [title]));
  4285. var inp = document.createElement('img');
  4286. inp.setAttribute('draggable', 'false');
  4287. inp.setAttribute('align', 'absmiddle');
  4288. inp.setAttribute('border', '0');
  4289. inp.style.position = 'relative';
  4290. inp.style.width = '16px';
  4291. inp.style.padding = '0px 6px 0 4px';
  4292. if (inverted)
  4293. {
  4294. inp.style.filter = 'invert(100%)';
  4295. inp.style.top = '-2px';
  4296. }
  4297. span.appendChild(inp);
  4298. mxUtils.write(span, title);
  4299. div.appendChild(span);
  4300. function update()
  4301. {
  4302. if (model.isVisible(layer))
  4303. {
  4304. inp.setAttribute('src', Editor.visibleImage);
  4305. mxUtils.setOpacity(span, 75);
  4306. }
  4307. else
  4308. {
  4309. inp.setAttribute('src', Editor.hiddenImage);
  4310. mxUtils.setOpacity(span, 25);
  4311. }
  4312. };
  4313. mxEvent.addListener(span, 'click', function()
  4314. {
  4315. model.setVisible(layer, !model.isVisible(layer));
  4316. update();
  4317. if (onchange != null)
  4318. {
  4319. onchange(layer);
  4320. }
  4321. });
  4322. update();
  4323. })(model.getChildAt(model.root, i)));
  4324. }
  4325. return div;
  4326. };
  4327. /**
  4328. * Private helper method.
  4329. */
  4330. Graph.prototype.replacePlaceholders = function(cell, str, vars, translate)
  4331. {
  4332. var result = [];
  4333. if (str != null)
  4334. {
  4335. var last = 0;
  4336. while (match = this.placeholderPattern.exec(str))
  4337. {
  4338. var val = match[0];
  4339. if (val.length > 2 && val != '%label%' && val != '%tooltip%')
  4340. {
  4341. var tmp = null;
  4342. if (match.index > last && str.charAt(match.index - 1) == '%')
  4343. {
  4344. tmp = val.substring(1);
  4345. }
  4346. else
  4347. {
  4348. var name = val.substring(1, val.length - 1);
  4349. // Workaround for invalid char for getting attribute in older versions of IE
  4350. if (name == 'id')
  4351. {
  4352. tmp = cell.id;
  4353. }
  4354. else if (name == 'width' && this.model.isVertex(cell))
  4355. {
  4356. var geo = this.getCellGeometry(cell);
  4357. if (geo != null)
  4358. {
  4359. tmp = geo.width;
  4360. }
  4361. }
  4362. else if (name == 'height' && this.model.isVertex(cell))
  4363. {
  4364. var geo = this.getCellGeometry(cell);
  4365. if (geo != null)
  4366. {
  4367. tmp = geo.height;
  4368. }
  4369. }
  4370. else if (name == 'length')
  4371. {
  4372. // Gets ancestor edge
  4373. var edge = cell;
  4374. while (edge != null && !this.model.isEdge(edge))
  4375. {
  4376. edge = this.model.getParent(edge);
  4377. }
  4378. var state = this.view.getState(edge);
  4379. if (state != null)
  4380. {
  4381. tmp = Math.round(state.length / this.view.scale);
  4382. }
  4383. }
  4384. else if (name.indexOf('{') < 0)
  4385. {
  4386. var current = cell;
  4387. while (tmp == null && current != null)
  4388. {
  4389. if (current.value != null && typeof(current.value) == 'object')
  4390. {
  4391. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  4392. {
  4393. tmp = current.getAttribute(name + '_' + Graph.diagramLanguage);
  4394. }
  4395. if (tmp == null)
  4396. {
  4397. tmp = (current.hasAttribute(name)) ? ((current.getAttribute(name) != null) ?
  4398. current.getAttribute(name) : '') : null;
  4399. }
  4400. }
  4401. current = this.model.getParent(current);
  4402. }
  4403. }
  4404. if (tmp == null)
  4405. {
  4406. tmp = this.getGlobalVariable(name);
  4407. }
  4408. if (tmp == null && vars != null)
  4409. {
  4410. tmp = vars[name];
  4411. }
  4412. }
  4413. result.push(str.substring(last, match.index) + ((tmp != null) ? tmp : val));
  4414. last = match.index + val.length;
  4415. }
  4416. }
  4417. result.push(str.substring(last));
  4418. }
  4419. return result.join('');
  4420. };
  4421. /**
  4422. * Resolves the given cells in the model and selects them.
  4423. */
  4424. Graph.prototype.restoreSelection = function(cells)
  4425. {
  4426. if (cells != null && cells.length > 0)
  4427. {
  4428. var temp = [];
  4429. for (var i = 0; i < cells.length; i++)
  4430. {
  4431. var newCell = this.model.getCell(cells[i].id);
  4432. if (newCell != null)
  4433. {
  4434. temp.push(newCell);
  4435. }
  4436. }
  4437. this.setSelectionCells(temp);
  4438. }
  4439. else
  4440. {
  4441. this.clearSelection();
  4442. }
  4443. };
  4444. /**
  4445. * Adds table range selection with Shift+Click.
  4446. */
  4447. Graph.prototype.selectCellForEvent = function(cell, evt)
  4448. {
  4449. if (!mxEvent.isShiftDown(evt) || this.isSelectionEmpty() ||
  4450. !this.selectTableRange(this.getSelectionCell(), cell))
  4451. {
  4452. mxGraph.prototype.selectCellForEvent.apply(this, arguments);
  4453. }
  4454. };
  4455. /**
  4456. * Returns true if
  4457. */
  4458. Graph.prototype.selectTableRange = function(startCell, endCell)
  4459. {
  4460. var result = false;
  4461. if (this.isTableCell(startCell) && this.isTableCell(endCell))
  4462. {
  4463. var startRow = this.model.getParent(startCell);
  4464. var table = this.model.getParent(startRow);
  4465. var endRow = this.model.getParent(endCell);
  4466. if (table == this.model.getParent(endRow))
  4467. {
  4468. var startCellIndex = startRow.getIndex(startCell);
  4469. var startRowIndex = table.getIndex(startRow);
  4470. var endCellIndex = endRow.getIndex(endCell);
  4471. var endRowIndex = table.getIndex(endRow);
  4472. var fromRow = Math.min(startRowIndex, endRowIndex);
  4473. var toRow = Math.max(startRowIndex, endRowIndex);
  4474. var fromCell = Math.min(startCellIndex, endCellIndex);
  4475. var toCell = Math.max(startCellIndex, endCellIndex);
  4476. var cells = [];
  4477. for (var row = fromRow; row <= toRow; row++)
  4478. {
  4479. var currentRow = this.model.getChildAt(table, row);
  4480. for (var col = fromCell; col <= toCell; col++)
  4481. {
  4482. cells.push(this.model.getChildAt(currentRow, col));
  4483. }
  4484. }
  4485. if (cells.length > 0 && (cells.length > 1 ||
  4486. this.getSelectionCount() > 1 ||
  4487. !this.isCellSelected(cells[0])))
  4488. {
  4489. this.setSelectionCells(cells);
  4490. result = true;
  4491. }
  4492. }
  4493. }
  4494. return result;
  4495. };
  4496. /**
  4497. * Returns the cells for the given table range.
  4498. */
  4499. Graph.prototype.snapCellsToGrid = function(cells, gridSize)
  4500. {
  4501. this.getModel().beginUpdate();
  4502. try
  4503. {
  4504. for (var i = 0; i < cells.length; i++)
  4505. {
  4506. var cell = cells[i];
  4507. var geo = this.getCellGeometry(cell);
  4508. if (geo != null)
  4509. {
  4510. geo = geo.clone();
  4511. if (this.getModel().isVertex(cell))
  4512. {
  4513. geo.x = Math.round(geo.x / gridSize) * gridSize;
  4514. geo.y = Math.round(geo.y / gridSize) * gridSize;
  4515. geo.width = Math.round(geo.width / gridSize) * gridSize;
  4516. geo.height = Math.round(geo.height / gridSize) * gridSize;
  4517. }
  4518. else if (this.getModel().isEdge(cell) && geo.points != null)
  4519. {
  4520. for (var j = 0; j < geo.points.length; j++)
  4521. {
  4522. geo.points[j].x = Math.round(geo.points[j].x / gridSize) * gridSize;
  4523. geo.points[j].y = Math.round(geo.points[j].y / gridSize) * gridSize;
  4524. }
  4525. }
  4526. this.getModel().setGeometry(cell, geo);
  4527. }
  4528. }
  4529. }
  4530. finally
  4531. {
  4532. this.getModel().endUpdate();
  4533. }
  4534. };
  4535. /**
  4536. * Creates a drop handler for inserting the given cells.
  4537. */
  4538. Graph.prototype.removeChildCells = function(cell)
  4539. {
  4540. this.model.beginUpdate();
  4541. try
  4542. {
  4543. var childCount = this.model.getChildCount(cell);
  4544. for (var j = childCount; j >= 0; j--)
  4545. {
  4546. this.model.remove(this.model.getChildAt(cell, j));
  4547. }
  4548. }
  4549. finally
  4550. {
  4551. this.model.endUpdate();
  4552. }
  4553. };
  4554. /**
  4555. * Creates a drop handler for inserting the given cells.
  4556. */
  4557. Graph.prototype.updateShapes = function(source, targets, replaceStyles)
  4558. {
  4559. this.model.beginUpdate();
  4560. try
  4561. {
  4562. var sourceStyle = this.model.getStyle(source);
  4563. var style = (replaceStyles) ? this.stylesheet.getCellStyle(sourceStyle, {}, false) : null;
  4564. // Handles special case of default shape
  4565. if (style != null && style[mxConstants.STYLE_SHAPE] == null)
  4566. {
  4567. if (this.model.isVertex(source))
  4568. {
  4569. style[mxConstants.STYLE_SHAPE] = this.stylesheet.
  4570. getDefaultVertexStyle()[mxConstants.STYLE_SHAPE];
  4571. }
  4572. else if (this.model.isEdge(source))
  4573. {
  4574. style[mxConstants.STYLE_SHAPE] = this.stylesheet.
  4575. getDefaultEdgeStyle()[mxConstants.STYLE_SHAPE];
  4576. }
  4577. }
  4578. // Replaces target styles and removes composite childs
  4579. for (var i = 0; i < targets.length; i++)
  4580. {
  4581. if ((this.model.isVertex(source) && this.model.isVertex(targets[i])) ||
  4582. this.model.isEdge(source) && this.model.isEdge(targets[i]))
  4583. {
  4584. if (replaceStyles)
  4585. {
  4586. // Removes style classes
  4587. var cellStyle = this.model.getStyle(targets[i]);
  4588. if (cellStyle != null)
  4589. {
  4590. var tokens = cellStyle.split(';');
  4591. if (tokens.length > 0 && tokens[0].indexOf('=') < 0)
  4592. {
  4593. tokens = tokens.slice(1);
  4594. }
  4595. this.model.setStyle(targets[i], tokens.join(';'));
  4596. }
  4597. // Removes perimeter and points styles
  4598. this.setCellStyles(mxConstants.STYLE_PERIMETER, null, [targets[i]]);
  4599. this.setCellStyles('points', null, [targets[i]]);
  4600. this.pasteStyle(style, [targets[i]], null, true);
  4601. }
  4602. else
  4603. {
  4604. style = this.copyStyle(targets[i]);
  4605. this.model.setStyle(targets[i], sourceStyle);
  4606. this.pasteStyle(style, [targets[i]]);
  4607. }
  4608. }
  4609. if (mxUtils.getValue(this.getCellStyle(targets[i],
  4610. false), 'composite', '0') == '1')
  4611. {
  4612. this.removeChildCells(targets[i]);
  4613. }
  4614. }
  4615. }
  4616. finally
  4617. {
  4618. this.model.endUpdate();
  4619. }
  4620. };
  4621. /**
  4622. * Selects cells for connect vertex return value.
  4623. */
  4624. Graph.prototype.selectCellsForConnectVertex = function(cells, evt, hoverIcons)
  4625. {
  4626. // Selects only target vertex if one exists
  4627. if (cells.length == 2 && this.model.isVertex(cells[1]))
  4628. {
  4629. this.setSelectionCell(cells[1]);
  4630. this.scrollCellToVisible(cells[1]);
  4631. if (hoverIcons != null)
  4632. {
  4633. // Adds hover icons for cloned vertex or hides icons
  4634. if (mxEvent.isTouchEvent(evt))
  4635. {
  4636. hoverIcons.update(hoverIcons.getState(this.view.getState(cells[1])));
  4637. }
  4638. else
  4639. {
  4640. hoverIcons.reset();
  4641. }
  4642. }
  4643. }
  4644. else
  4645. {
  4646. this.setSelectionCells(cells);
  4647. }
  4648. };
  4649. /**
  4650. * Never connects children in stack layouts or tables.
  4651. */
  4652. Graph.prototype.isCloneConnectSource = function(source)
  4653. {
  4654. var layout = null;
  4655. if (this.layoutManager != null)
  4656. {
  4657. layout = this.layoutManager.getLayout(this.model.getParent(source));
  4658. }
  4659. return this.isTableRow(source) || this.isTableCell(source) ||
  4660. (layout != null && layout.constructor == mxStackLayout);
  4661. };
  4662. /**
  4663. * Inserts the given edge before the given cell.
  4664. */
  4665. Graph.prototype.insertEdgeBeforeCell = function(edge, cell)
  4666. {
  4667. var index = null;
  4668. var tmp = cell;
  4669. while (tmp.parent != null && tmp.geometry != null &&
  4670. tmp.geometry.relative && tmp.parent != edge.parent)
  4671. {
  4672. tmp = this.model.getParent(tmp);
  4673. }
  4674. if (tmp != null && tmp.parent != null && tmp.parent == edge.parent)
  4675. {
  4676. var index = tmp.parent.getIndex(tmp);
  4677. this.model.add(tmp.parent, edge, index);
  4678. }
  4679. };
  4680. /**
  4681. * Adds a connection to the given vertex or clones the vertex in special layout
  4682. * containers without creating a connection.
  4683. */
  4684. Graph.prototype.connectVertex = function(source, direction, length, evt, forceClone, ignoreCellAt, createTarget, done)
  4685. {
  4686. ignoreCellAt = (ignoreCellAt) ? ignoreCellAt : false;
  4687. // Ignores relative edge labels
  4688. if (source.geometry.relative && this.model.isEdge(source.parent))
  4689. {
  4690. return [];
  4691. }
  4692. // Uses parent for relative child cells
  4693. while (source.geometry.relative && this.model.isVertex(source.parent))
  4694. {
  4695. source = source.parent;
  4696. }
  4697. // Handles clone connect sources
  4698. var cloneSource = this.isCloneConnectSource(source);
  4699. var composite = (cloneSource) ? source : this.getCompositeParent(source);
  4700. var pt = (source.geometry.relative && source.parent.geometry != null) ?
  4701. new mxPoint(source.parent.geometry.width * source.geometry.x,
  4702. source.parent.geometry.height * source.geometry.y) :
  4703. new mxPoint(composite.geometry.x, composite.geometry.y);
  4704. if (direction == mxConstants.DIRECTION_NORTH)
  4705. {
  4706. pt.x += composite.geometry.width / 2;
  4707. pt.y -= length ;
  4708. }
  4709. else if (direction == mxConstants.DIRECTION_SOUTH)
  4710. {
  4711. pt.x += composite.geometry.width / 2;
  4712. pt.y += composite.geometry.height + length;
  4713. }
  4714. else if (direction == mxConstants.DIRECTION_WEST)
  4715. {
  4716. pt.x -= length;
  4717. pt.y += composite.geometry.height / 2;
  4718. }
  4719. else
  4720. {
  4721. pt.x += composite.geometry.width + length;
  4722. pt.y += composite.geometry.height / 2;
  4723. }
  4724. var parentState = this.view.getState(this.model.getParent(source));
  4725. var s = this.view.scale;
  4726. var t = this.view.translate;
  4727. var dx = t.x * s;
  4728. var dy = t.y * s;
  4729. if (parentState != null && this.model.isVertex(parentState.cell))
  4730. {
  4731. dx = parentState.x;
  4732. dy = parentState.y;
  4733. }
  4734. // Workaround for relative child cells
  4735. if (this.model.isVertex(source.parent) && source.geometry.relative)
  4736. {
  4737. pt.x += source.parent.geometry.x;
  4738. pt.y += source.parent.geometry.y;
  4739. }
  4740. // Checks end point for target cell and container
  4741. var rect = (!ignoreCellAt) ? new mxRectangle(dx + pt.x * s, dy + pt.y * s).grow(40 * s) : null;
  4742. var tempCells = (rect != null) ? this.getCells(0, 0, 0, 0, null, null, rect, null, true) : null;
  4743. var sourceState = this.view.getState(source);
  4744. var container = null;
  4745. var target = null;
  4746. if (tempCells != null)
  4747. {
  4748. tempCells = tempCells.reverse();
  4749. for (var i = 0; i < tempCells.length; i++)
  4750. {
  4751. if (!this.isCellLocked(tempCells[i]) && !this.model.isEdge(tempCells[i]) && tempCells[i] != source)
  4752. {
  4753. // Direct parent overrides all possible containers
  4754. if (!this.model.isAncestor(source, tempCells[i]) && this.isContainer(tempCells[i]) &&
  4755. (container == null || tempCells[i] == this.model.getParent(source)))
  4756. {
  4757. container = tempCells[i];
  4758. }
  4759. // Containers are used as target cells but swimlanes are used as parents
  4760. else if (target == null && this.isCellConnectable(tempCells[i]) &&
  4761. !this.model.isAncestor(tempCells[i], source) &&
  4762. !this.isSwimlane(tempCells[i]))
  4763. {
  4764. var targetState = this.view.getState(tempCells[i]);
  4765. if (sourceState != null && targetState != null && !mxUtils.intersects(sourceState, targetState))
  4766. {
  4767. target = tempCells[i];
  4768. }
  4769. }
  4770. }
  4771. }
  4772. }
  4773. var duplicate = (!mxEvent.isShiftDown(evt) || mxEvent.isControlDown(evt)) || forceClone;
  4774. if (duplicate && (urlParams['sketch'] != '1' || forceClone))
  4775. {
  4776. if (direction == mxConstants.DIRECTION_NORTH)
  4777. {
  4778. pt.y -= source.geometry.height / 2;
  4779. }
  4780. else if (direction == mxConstants.DIRECTION_SOUTH)
  4781. {
  4782. pt.y += source.geometry.height / 2;
  4783. }
  4784. else if (direction == mxConstants.DIRECTION_WEST)
  4785. {
  4786. pt.x -= source.geometry.width / 2;
  4787. }
  4788. else
  4789. {
  4790. pt.x += source.geometry.width / 2;
  4791. }
  4792. }
  4793. var result = [];
  4794. var realTarget = target;
  4795. target = container;
  4796. var execute = mxUtils.bind(this, function(targetCell)
  4797. {
  4798. if (createTarget == null || targetCell != null || (target == null && cloneSource))
  4799. {
  4800. this.model.beginUpdate();
  4801. try
  4802. {
  4803. if (realTarget == null && duplicate)
  4804. {
  4805. // Handles relative and composite cells
  4806. var cellToClone = this.getAbsoluteParent((targetCell != null) ? targetCell : source);
  4807. cellToClone = (cloneSource) ? source : this.getCompositeParent(cellToClone);
  4808. realTarget = (targetCell != null) ? targetCell : this.duplicateCells([cellToClone], false)[0];
  4809. if (targetCell != null)
  4810. {
  4811. this.addCells([realTarget], this.model.getParent(source), null, null, null, true);
  4812. }
  4813. var geo = this.getCellGeometry(realTarget);
  4814. if (geo != null)
  4815. {
  4816. if (targetCell != null && urlParams['sketch'] == '1')
  4817. {
  4818. if (direction == mxConstants.DIRECTION_NORTH)
  4819. {
  4820. pt.y -= geo.height / 2;
  4821. }
  4822. else if (direction == mxConstants.DIRECTION_SOUTH)
  4823. {
  4824. pt.y += geo.height / 2;
  4825. }
  4826. else if (direction == mxConstants.DIRECTION_WEST)
  4827. {
  4828. pt.x -= geo.width / 2;
  4829. }
  4830. else
  4831. {
  4832. pt.x += geo.width / 2;
  4833. }
  4834. }
  4835. geo.x = pt.x - geo.width / 2;
  4836. geo.y = pt.y - geo.height / 2;
  4837. }
  4838. if (container != null)
  4839. {
  4840. this.addCells([realTarget], container, null, null, null, true);
  4841. target = null;
  4842. }
  4843. else if (duplicate && !cloneSource)
  4844. {
  4845. this.addCells([realTarget], this.getDefaultParent(), null, null, null, true);
  4846. }
  4847. }
  4848. var edge = ((mxEvent.isControlDown(evt) && mxEvent.isShiftDown(evt) && duplicate) ||
  4849. (target == null && cloneSource)) ? null : this.insertEdge(this.model.getParent(source),
  4850. null, '', source, realTarget, this.createCurrentEdgeStyle());
  4851. if (edge != null)
  4852. {
  4853. result.push(edge);
  4854. this.applyNewEdgeStyle(source, [edge], direction);
  4855. if (this.connectionHandler.insertBeforeSource)
  4856. {
  4857. this.insertEdgeBeforeCell(edge, source);
  4858. }
  4859. }
  4860. // Special case: Click on west icon puts clone before cell
  4861. if (target == null && realTarget != null && source.parent != null &&
  4862. cloneSource && direction == mxConstants.DIRECTION_WEST)
  4863. {
  4864. var index = source.parent.getIndex(source);
  4865. this.model.add(source.parent, realTarget, index);
  4866. }
  4867. if (target == null && realTarget != null)
  4868. {
  4869. result.push(realTarget);
  4870. }
  4871. if (realTarget == null && edge != null)
  4872. {
  4873. edge.geometry.setTerminalPoint(pt, false);
  4874. }
  4875. if (edge != null)
  4876. {
  4877. this.fireEvent(new mxEventObject('cellsInserted', 'cells', [edge]));
  4878. }
  4879. }
  4880. finally
  4881. {
  4882. this.model.endUpdate();
  4883. }
  4884. }
  4885. if (done != null)
  4886. {
  4887. done(result);
  4888. }
  4889. else
  4890. {
  4891. return result;
  4892. }
  4893. });
  4894. if (createTarget != null && realTarget == null && duplicate &&
  4895. (target != null || !cloneSource))
  4896. {
  4897. createTarget(dx + pt.x * s, dy + pt.y * s, execute);
  4898. }
  4899. else
  4900. {
  4901. return execute(realTarget);
  4902. }
  4903. };
  4904. /**
  4905. * Returns all labels in the diagram as a string.
  4906. */
  4907. Graph.prototype.getIndexableText = function(cells)
  4908. {
  4909. cells = (cells != null) ? cells : this.model.
  4910. getDescendants(this.model.root);
  4911. var tmp = document.createElement('div');
  4912. var labels = [];
  4913. var label = '';
  4914. for (var i = 0; i < cells.length; i++)
  4915. {
  4916. var cell = cells[i];
  4917. if (this.model.isVertex(cell) || this.model.isEdge(cell))
  4918. {
  4919. if (this.isHtmlLabel(cell))
  4920. {
  4921. tmp.innerHTML = Graph.sanitizeHtml(this.getLabel(cell));
  4922. label = mxUtils.extractTextWithWhitespace([tmp]);
  4923. }
  4924. else
  4925. {
  4926. label = this.getLabel(cell);
  4927. }
  4928. label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' '));
  4929. if (label.length > 0)
  4930. {
  4931. labels.push(label);
  4932. }
  4933. }
  4934. }
  4935. return labels.join(' ');
  4936. };
  4937. /**
  4938. * Returns the label for the given cell.
  4939. */
  4940. Graph.prototype.convertValueToString = function(cell)
  4941. {
  4942. var value = this.model.getValue(cell);
  4943. if (value != null && typeof(value) == 'object')
  4944. {
  4945. var result = null;
  4946. if (this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') != null)
  4947. {
  4948. var name = cell.getAttribute('placeholder');
  4949. var current = cell;
  4950. while (result == null && current != null)
  4951. {
  4952. if (current.value != null && typeof(current.value) == 'object')
  4953. {
  4954. result = (current.hasAttribute(name)) ?
  4955. ((current.getAttribute(name) != null) ?
  4956. current.getAttribute(name) : '') : null;
  4957. }
  4958. current = this.model.getParent(current);
  4959. }
  4960. }
  4961. else
  4962. {
  4963. var result = null;
  4964. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  4965. {
  4966. result = value.getAttribute('label_' + Graph.diagramLanguage);
  4967. }
  4968. if (result == null)
  4969. {
  4970. result = value.getAttribute('label') || '';
  4971. }
  4972. }
  4973. return result || '';
  4974. }
  4975. return mxGraph.prototype.convertValueToString.apply(this, arguments);
  4976. };
  4977. /**
  4978. * Returns the link for the given cell.
  4979. */
  4980. Graph.prototype.getLinksForState = function(state)
  4981. {
  4982. if (state != null && state.text != null && state.text.node != null)
  4983. {
  4984. return state.text.node.getElementsByTagName('a');
  4985. }
  4986. else
  4987. {
  4988. return null;
  4989. }
  4990. };
  4991. /**
  4992. * Returns the link for the given cell.
  4993. */
  4994. Graph.prototype.getLinkForCell = function(cell, allowUnsafe)
  4995. {
  4996. if (cell.value != null && typeof(cell.value) == 'object')
  4997. {
  4998. var link = cell.value.getAttribute('link');
  4999. if (!allowUnsafe)
  5000. {
  5001. link = mxUtils.removeJavascriptProtocol(link);
  5002. }
  5003. return link;
  5004. }
  5005. else
  5006. {
  5007. return null;
  5008. }
  5009. };
  5010. /**
  5011. * Returns the link target for the given cell.
  5012. */
  5013. Graph.prototype.getLinkTargetForCell = function(cell)
  5014. {
  5015. if (cell.value != null && typeof(cell.value) == 'object')
  5016. {
  5017. return cell.value.getAttribute('linkTarget');
  5018. }
  5019. else
  5020. {
  5021. return null;
  5022. }
  5023. };
  5024. /**
  5025. * Adds style post processing steps.
  5026. */
  5027. Graph.prototype.postProcessCellStyle = function(cell, style)
  5028. {
  5029. return this.updateHorizontalStyle(cell,this.replaceDefaultColors(cell,
  5030. mxGraph.prototype.postProcessCellStyle.apply(this, arguments)));
  5031. };
  5032. /**
  5033. * Overrides label orientation for collapsed swimlanes inside stack and
  5034. * for partial rectangles inside tables.
  5035. */
  5036. Graph.prototype.updateHorizontalStyle = function(cell, style)
  5037. {
  5038. if (cell != null && style != null && this.layoutManager != null)
  5039. {
  5040. var parent = this.model.getParent(cell);
  5041. if (this.model.isVertex(parent) && this.isCellCollapsed(cell))
  5042. {
  5043. var layout = this.layoutManager.getLayout(parent);
  5044. if (layout != null && layout.constructor == mxStackLayout)
  5045. {
  5046. style[mxConstants.STYLE_HORIZONTAL] = !layout.horizontal;
  5047. }
  5048. }
  5049. }
  5050. return style;
  5051. };
  5052. /**
  5053. * Replaces default colors.
  5054. */
  5055. Graph.prototype.replaceDefaultColors = function(cell, style)
  5056. {
  5057. if (style != null)
  5058. {
  5059. var bg = mxUtils.hex2rgb(this.shapeBackgroundColor);
  5060. var fg = mxUtils.hex2rgb(this.shapeForegroundColor);
  5061. this.replaceDefaultColor(style, mxConstants.STYLE_FONTCOLOR, fg, bg);
  5062. this.replaceDefaultColor(style, mxConstants.STYLE_FILLCOLOR, bg, fg);
  5063. this.replaceDefaultColor(style, mxConstants.STYLE_GRADIENTCOLOR, fg, bg);
  5064. this.replaceDefaultColor(style, mxConstants.STYLE_STROKECOLOR, fg, bg);
  5065. this.replaceDefaultColor(style, mxConstants.STYLE_IMAGE_BORDER, fg, bg);
  5066. this.replaceDefaultColor(style, mxConstants.STYLE_IMAGE_BACKGROUND, bg, fg);
  5067. this.replaceDefaultColor(style, mxConstants.STYLE_LABEL_BORDERCOLOR, fg, bg);
  5068. this.replaceDefaultColor(style, mxConstants.STYLE_SWIMLANE_FILLCOLOR, bg, fg);
  5069. this.replaceDefaultColor(style, mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, bg, fg);
  5070. }
  5071. return style;
  5072. };
  5073. /**
  5074. * Replaces the colors for the given key.
  5075. */
  5076. Graph.prototype.replaceDefaultColor = function(style, key, value, inverseValue)
  5077. {
  5078. if (style != null && style[key] == 'default' && value != null)
  5079. {
  5080. style[key] = this.getDefaultColor(style, key, value, inverseValue);
  5081. }
  5082. };
  5083. /**
  5084. * Replaces the colors for the given key.
  5085. */
  5086. Graph.prototype.getDefaultColor = function(style, key, defaultValue, inverseDefaultValue)
  5087. {
  5088. var temp = 'default' + key.charAt(0).toUpperCase() + key.substring(1);
  5089. if (style[temp] == 'invert')
  5090. {
  5091. defaultValue = inverseDefaultValue;
  5092. }
  5093. return defaultValue;
  5094. };
  5095. /**
  5096. * Disables alternate width persistence for stack layout parents
  5097. */
  5098. Graph.prototype.updateAlternateBounds = function(cell, geo, willCollapse)
  5099. {
  5100. if (cell != null && geo != null && this.layoutManager != null && geo.alternateBounds != null)
  5101. {
  5102. var layout = this.layoutManager.getLayout(this.model.getParent(cell));
  5103. if (layout != null && layout.constructor == mxStackLayout)
  5104. {
  5105. if (layout.horizontal)
  5106. {
  5107. geo.alternateBounds.height = 0;
  5108. }
  5109. else
  5110. {
  5111. geo.alternateBounds.width = 0;
  5112. }
  5113. }
  5114. }
  5115. mxGraph.prototype.updateAlternateBounds.apply(this, arguments);
  5116. };
  5117. /**
  5118. * Adds Shift+collapse/expand and size management for folding inside stack
  5119. */
  5120. Graph.prototype.isMoveCellsEvent = function(evt, state)
  5121. {
  5122. return mxEvent.isShiftDown(evt) || mxUtils.getValue(state.style, 'moveCells', '0') == '1';
  5123. };
  5124. /**
  5125. * Adds Shift+collapse/expand and size management for folding inside stack
  5126. */
  5127. Graph.prototype.foldCells = function(collapse, recurse, cells, checkFoldable, evt)
  5128. {
  5129. recurse = (recurse != null) ? recurse : false;
  5130. if (cells == null)
  5131. {
  5132. cells = this.getFoldableCells(this.getSelectionCells(), collapse);
  5133. }
  5134. if (cells != null)
  5135. {
  5136. this.model.beginUpdate();
  5137. try
  5138. {
  5139. mxGraph.prototype.foldCells.apply(this, arguments);
  5140. // Resizes all parent stacks if alt is not pressed
  5141. if (this.layoutManager != null)
  5142. {
  5143. for (var i = 0; i < cells.length; i++)
  5144. {
  5145. var state = this.view.getState(cells[i]);
  5146. var geo = this.getCellGeometry(cells[i]);
  5147. if (state != null && geo != null)
  5148. {
  5149. var dx = 0;
  5150. var dy = 0;
  5151. if (geo.alternateBounds)
  5152. {
  5153. dx = geo.width - geo.alternateBounds.width;
  5154. dy = geo.height - geo.alternateBounds.height;
  5155. }
  5156. else
  5157. {
  5158. var s = (this.useCssTransforms) ? 1 : this.view.scale;
  5159. dx = Math.round(geo.width - state.width / s);
  5160. dy = Math.round(geo.height - state.height / s);
  5161. }
  5162. if (dy != 0 || dx != 0)
  5163. {
  5164. var parent = this.model.getParent(cells[i]);
  5165. var layout = this.layoutManager.getLayout(parent);
  5166. if (layout == null)
  5167. {
  5168. // Moves cells to the right and down after collapse/expand
  5169. if (evt != null && this.isMoveCellsEvent(evt, state))
  5170. {
  5171. this.moveSiblings(state, parent, dx, dy);
  5172. }
  5173. }
  5174. else if ((evt == null || !mxEvent.isAltDown(evt)) &&
  5175. layout.constructor == mxStackLayout && !layout.resizeLast)
  5176. {
  5177. this.resizeParentStacks(parent, layout, dx, dy);
  5178. }
  5179. }
  5180. }
  5181. }
  5182. }
  5183. }
  5184. finally
  5185. {
  5186. this.model.endUpdate();
  5187. }
  5188. // Selects cells after folding
  5189. if (this.isEnabled())
  5190. {
  5191. this.setSelectionCells(cells);
  5192. }
  5193. }
  5194. };
  5195. /**
  5196. * Overrides label orientation for collapsed swimlanes inside stack.
  5197. */
  5198. Graph.prototype.moveSiblings = function(state, parent, dx, dy)
  5199. {
  5200. this.model.beginUpdate();
  5201. try
  5202. {
  5203. var cells = this.getCellsBeyond(state.x, state.y, parent, true, true);
  5204. for (var i = 0; i < cells.length; i++)
  5205. {
  5206. if (cells[i] != state.cell)
  5207. {
  5208. var tmp = this.view.getState(cells[i]);
  5209. var geo = this.getCellGeometry(cells[i]);
  5210. if (tmp != null && geo != null)
  5211. {
  5212. geo = geo.clone();
  5213. geo.translate(Math.round(dx * Math.max(0, Math.min(1, (tmp.x - state.x) / state.width))),
  5214. Math.round(dy * Math.max(0, Math.min(1, (tmp.y - state.y) / state.height))));
  5215. this.model.setGeometry(cells[i], geo);
  5216. }
  5217. }
  5218. }
  5219. }
  5220. finally
  5221. {
  5222. this.model.endUpdate();
  5223. }
  5224. };
  5225. /**
  5226. * Overrides label orientation for collapsed swimlanes inside stack.
  5227. */
  5228. Graph.prototype.resizeParentStacks = function(parent, layout, dx, dy)
  5229. {
  5230. if (this.layoutManager != null && layout != null && layout.constructor == mxStackLayout && !layout.resizeLast)
  5231. {
  5232. this.model.beginUpdate();
  5233. try
  5234. {
  5235. var dir = layout.horizontal;
  5236. // Bubble resize up for all parent stack layouts with same orientation
  5237. while (parent != null && layout != null && layout.constructor == mxStackLayout &&
  5238. layout.horizontal == dir && !layout.resizeLast)
  5239. {
  5240. var pgeo = this.getCellGeometry(parent);
  5241. var pstate = this.view.getState(parent);
  5242. if (pstate != null && pgeo != null)
  5243. {
  5244. pgeo = pgeo.clone();
  5245. if (layout.horizontal)
  5246. {
  5247. pgeo.width += dx + Math.min(0, pstate.width / this.view.scale - pgeo.width);
  5248. }
  5249. else
  5250. {
  5251. pgeo.height += dy + Math.min(0, pstate.height / this.view.scale - pgeo.height);
  5252. }
  5253. this.model.setGeometry(parent, pgeo);
  5254. }
  5255. parent = this.model.getParent(parent);
  5256. layout = this.layoutManager.getLayout(parent);
  5257. }
  5258. }
  5259. finally
  5260. {
  5261. this.model.endUpdate();
  5262. }
  5263. }
  5264. };
  5265. /**
  5266. * Disables drill-down for non-swimlanes.
  5267. */
  5268. Graph.prototype.isContainer = function(cell)
  5269. {
  5270. var style = this.getCurrentCellStyle(cell);
  5271. if (this.isSwimlane(cell))
  5272. {
  5273. return style['container'] != '0';
  5274. }
  5275. else
  5276. {
  5277. return style['container'] == '1';
  5278. }
  5279. };
  5280. /**
  5281. * Adds a connectable style.
  5282. */
  5283. Graph.prototype.isCellConnectable = function(cell)
  5284. {
  5285. var style = this.getCurrentCellStyle(cell);
  5286. return !this.isCellLocked(this.getLayerForCell(cell)) &&
  5287. ((style['connectable'] != null) ? style['connectable'] != '0' :
  5288. mxGraph.prototype.isCellConnectable.apply(this, arguments));
  5289. };
  5290. /**
  5291. * Adds labelMovable style.
  5292. */
  5293. Graph.prototype.isLabelMovable = function(cell)
  5294. {
  5295. var style = this.getCurrentCellStyle(cell);
  5296. return (style['movableLabel'] != null) ? style['movableLabel'] != '0' :
  5297. mxGraph.prototype.isLabelMovable.apply(this, arguments);
  5298. };
  5299. /**
  5300. * Function: selectAll
  5301. *
  5302. * Selects all children of the given parent cell or the children of the
  5303. * default parent if no parent is specified. To select leaf vertices and/or
  5304. * edges use <selectCells>.
  5305. *
  5306. * Parameters:
  5307. *
  5308. * parent - Optional <mxCell> whose children should be selected.
  5309. * Default is <defaultParent>.
  5310. */
  5311. Graph.prototype.selectAll = function(parent)
  5312. {
  5313. parent = parent || this.getDefaultParent();
  5314. if (!this.isCellLocked(parent))
  5315. {
  5316. mxGraph.prototype.selectAll.apply(this, arguments);
  5317. }
  5318. };
  5319. /**
  5320. * Function: selectCells
  5321. *
  5322. * Selects all vertices and/or edges depending on the given boolean
  5323. * arguments recursively, starting at the given parent or the default
  5324. * parent if no parent is specified. Use <selectAll> to select all cells.
  5325. * For vertices, only cells with no children are selected.
  5326. *
  5327. * Parameters:
  5328. *
  5329. * vertices - Boolean indicating if vertices should be selected.
  5330. * edges - Boolean indicating if edges should be selected.
  5331. * parent - Optional <mxCell> that acts as the root of the recursion.
  5332. * Default is <defaultParent>.
  5333. */
  5334. Graph.prototype.selectCells = function(vertices, edges, parent)
  5335. {
  5336. parent = parent || this.getDefaultParent();
  5337. if (!this.isCellLocked(parent))
  5338. {
  5339. mxGraph.prototype.selectCells.apply(this, arguments);
  5340. }
  5341. };
  5342. /**
  5343. * Function: getSwimlaneAt
  5344. *
  5345. * Returns the bottom-most swimlane that intersects the given point (x, y)
  5346. * in the cell hierarchy that starts at the given parent.
  5347. *
  5348. * Parameters:
  5349. *
  5350. * x - X-coordinate of the location to be checked.
  5351. * y - Y-coordinate of the location to be checked.
  5352. * parent - <mxCell> that should be used as the root of the recursion.
  5353. * Default is <defaultParent>.
  5354. */
  5355. Graph.prototype.getSwimlaneAt = function (x, y, parent)
  5356. {
  5357. var result = mxGraph.prototype.getSwimlaneAt.apply(this, arguments);
  5358. if (this.isCellLocked(result))
  5359. {
  5360. result = null;
  5361. }
  5362. return result;
  5363. };
  5364. /**
  5365. * Disables folding for non-swimlanes.
  5366. */
  5367. Graph.prototype.isCellFoldable = function(cell)
  5368. {
  5369. var style = this.getCurrentCellStyle(cell);
  5370. return this.foldingEnabled && mxUtils.getValue(style,
  5371. mxConstants.STYLE_RESIZABLE, '1') != '0' &&
  5372. (style['treeFolding'] == '1' ||
  5373. (!this.isCellLocked(cell) &&
  5374. ((this.isContainer(cell) && style['collapsible'] != '0') ||
  5375. (!this.isContainer(cell) && style['collapsible'] == '1'))));
  5376. };
  5377. /**
  5378. * Stops all interactions and clears the selection.
  5379. */
  5380. Graph.prototype.reset = function()
  5381. {
  5382. if (this.isEditing())
  5383. {
  5384. this.stopEditing(true);
  5385. }
  5386. this.escape();
  5387. if (!this.isSelectionEmpty())
  5388. {
  5389. this.clearSelection();
  5390. }
  5391. };
  5392. /**
  5393. * Overridden to limit zoom to 1% - 16.000%.
  5394. */
  5395. Graph.prototype.zoom = function(factor, center)
  5396. {
  5397. factor = Math.max(0.01, Math.min(this.view.scale * factor, 160)) / this.view.scale;
  5398. mxGraph.prototype.zoom.apply(this, arguments);
  5399. };
  5400. /**
  5401. * Function: zoomIn
  5402. *
  5403. * Zooms into the graph by <zoomFactor>.
  5404. */
  5405. Graph.prototype.zoomIn = function()
  5406. {
  5407. // Switches to 1% zoom steps below 15%
  5408. if (this.view.scale < 0.15)
  5409. {
  5410. this.zoom((this.view.scale + 0.01) / this.view.scale);
  5411. }
  5412. else
  5413. {
  5414. // Uses to 5% zoom steps for better grid rendering in webkit
  5415. // and to avoid rounding errors for zoom steps
  5416. this.zoom((Math.round(this.view.scale * this.zoomFactor * 20) / 20) / this.view.scale);
  5417. }
  5418. };
  5419. /**
  5420. * Function: zoomOut
  5421. *
  5422. * Zooms out of the graph by <zoomFactor>.
  5423. */
  5424. Graph.prototype.zoomOut = function()
  5425. {
  5426. // Switches to 1% zoom steps below 15%
  5427. if (this.view.scale <= 0.15)
  5428. {
  5429. this.zoom((this.view.scale - 0.01) / this.view.scale);
  5430. }
  5431. else
  5432. {
  5433. // Uses to 5% zoom steps for better grid rendering in webkit
  5434. // and to avoid rounding errors for zoom steps
  5435. this.zoom((Math.round(this.view.scale * (1 / this.zoomFactor) * 20) / 20) / this.view.scale);
  5436. }
  5437. };
  5438. /**
  5439. * Function: fitPages
  5440. *
  5441. * Fits the given number of pages to the current view horizontally.
  5442. * If pageCount is null then all pages will be used. This should not
  5443. * be called if pages are not visible.
  5444. */
  5445. Graph.prototype.fitPages = function(pageCount, ignoreHeight)
  5446. {
  5447. var vcount = 1;
  5448. if (pageCount == null)
  5449. {
  5450. var layout = this.getPageLayout();
  5451. pageCount = layout.width;
  5452. vcount = layout.height;
  5453. }
  5454. var ps = this.pageScale;
  5455. var fmt = this.pageFormat;
  5456. var cw = this.container.clientWidth - 10;
  5457. var ch = this.container.clientHeight - 10;
  5458. var sx = cw / (pageCount * fmt.width) / ps;
  5459. var scale = Math.floor(20 * ((ignoreHeight) ? sx :
  5460. Math.min(sx, ch / (vcount * fmt.height) / ps))) / 20;
  5461. this.zoomTo(scale);
  5462. if (mxUtils.hasScrollbars(this.container))
  5463. {
  5464. var pad = this.getPagePadding();
  5465. this.container.scrollLeft = Math.min(pad.x * this.view.scale,
  5466. (this.container.scrollWidth - this.container.clientWidth) / 2) - 1;
  5467. if (!ignoreHeight)
  5468. {
  5469. if (pageCount >= 2)
  5470. {
  5471. this.container.scrollTop = Math.min(pad.y,
  5472. (this.container.scrollHeight -
  5473. this.container.clientHeight) / 2);
  5474. }
  5475. else
  5476. {
  5477. this.container.scrollTop = pad.y * this.view.scale - 1;
  5478. }
  5479. }
  5480. }
  5481. };
  5482. /**
  5483. * Function: fitWindow
  5484. *
  5485. * Sets the current visible rectangle of the window in graph coordinates.
  5486. */
  5487. Graph.prototype.fitWindow = function(bounds, border)
  5488. {
  5489. border = (border != null) ? border : 10;
  5490. var cw = this.container.clientWidth - border;
  5491. var ch = this.container.clientHeight - border;
  5492. var scale = Math.floor(20 * Math.min(cw / bounds.width, ch / bounds.height)) / 20;
  5493. this.zoomTo(scale);
  5494. if (mxUtils.hasScrollbars(this.container))
  5495. {
  5496. // Call to zoom above may trigger an asynchronous update of the scrollbars
  5497. // as setting scrollTop/-Left is executed asynchronously so the code below
  5498. // ensures that the final state of the scrollbars is as intended.
  5499. window.setTimeout(mxUtils.bind(this, function()
  5500. {
  5501. var t = this.view.translate;
  5502. this.container.scrollLeft = (bounds.x + t.x) * this.view.scale -
  5503. Math.max((cw - bounds.width * this.view.scale) / 2 + border / 2, 0);
  5504. this.container.scrollTop = (bounds.y + t.y) * this.view.scale -
  5505. Math.max((ch - bounds.height * this.view.scale) / 2 + border / 2, 0);
  5506. }), 0);
  5507. }
  5508. };
  5509. /**
  5510. * Overrides tooltips to show custom tooltip or metadata.
  5511. */
  5512. Graph.prototype.convertValueToTooltip = function(cell)
  5513. {
  5514. var tmp = null;
  5515. if (mxUtils.isNode(cell.value))
  5516. {
  5517. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  5518. {
  5519. tmp = cell.value.getAttribute('tooltip_' + Graph.diagramLanguage);
  5520. }
  5521. if (tmp == null)
  5522. {
  5523. tmp = cell.value.getAttribute('tooltip');
  5524. }
  5525. if (tmp != null)
  5526. {
  5527. if (tmp != null && this.isReplacePlaceholders(cell))
  5528. {
  5529. tmp = this.replacePlaceholders(cell, tmp);
  5530. }
  5531. tmp = Graph.sanitizeHtml(tmp);
  5532. }
  5533. }
  5534. return tmp;
  5535. };
  5536. /**
  5537. * Overrides tooltips to show custom tooltip or metadata.
  5538. */
  5539. Graph.prototype.getTooltipForCell = function(cell)
  5540. {
  5541. var tip = '';
  5542. if (mxUtils.isNode(cell.value))
  5543. {
  5544. tip = this.convertValueToTooltip(cell);
  5545. if (tip == null)
  5546. {
  5547. var ignored = this.builtInProperties;
  5548. var attrs = cell.value.attributes;
  5549. var temp = [];
  5550. tip = '';
  5551. // Hides links in edit mode
  5552. if (this.isEnabled())
  5553. {
  5554. ignored.push('linkTarget');
  5555. ignored.push('link');
  5556. }
  5557. for (var i = 0; i < attrs.length; i++)
  5558. {
  5559. if (((Graph.translateDiagram && attrs[i].nodeName == 'label') ||
  5560. mxUtils.indexOf(ignored, attrs[i].nodeName) < 0) &&
  5561. attrs[i].nodeValue.length > 0)
  5562. {
  5563. temp.push({name: attrs[i].nodeName, value: attrs[i].nodeValue});
  5564. }
  5565. }
  5566. // Sorts by name
  5567. temp.sort(function(a, b)
  5568. {
  5569. if (a.name < b.name)
  5570. {
  5571. return -1;
  5572. }
  5573. else if (a.name > b.name)
  5574. {
  5575. return 1;
  5576. }
  5577. else
  5578. {
  5579. return 0;
  5580. }
  5581. });
  5582. for (var i = 0; i < temp.length; i++)
  5583. {
  5584. if (temp[i].name != 'link' || !this.isCustomLink(temp[i].value))
  5585. {
  5586. tip += ((temp[i].name != 'link') ? '<b>' + mxUtils.htmlEntities(temp[i].name) +
  5587. ':</b> ' : '') + mxUtils.htmlEntities(temp[i].value) + '\n';
  5588. }
  5589. }
  5590. if (tip.length > 0)
  5591. {
  5592. tip = tip.substring(0, tip.length - 1);
  5593. if (mxClient.IS_SVG)
  5594. {
  5595. tip = '<div style="max-width:360px;text-overflow:ellipsis;overflow:hidden;">' +
  5596. tip + '</div>';
  5597. }
  5598. }
  5599. }
  5600. }
  5601. return tip;
  5602. };
  5603. /**
  5604. *
  5605. */
  5606. Graph.prototype.addFlowAnimationToNode = function(node, style, scale, id)
  5607. {
  5608. if (node != null && id != null)
  5609. {
  5610. var dashArray = node.getAttribute('stroke-dasharray');
  5611. var tokens = [];
  5612. if (dashArray == '' || dashArray == null)
  5613. {
  5614. tokens = String(mxUtils.getValue(style, mxConstants.STYLE_DASH_PATTERN, '8')).split(' ');
  5615. var sw = (mxUtils.getValue(style, mxConstants.STYLE_FIX_DASH, false) == 1 ||
  5616. style['dashPattern'] == null) ? 1 : mxUtils.getNumber(style,
  5617. mxConstants.STYLE_STROKEWIDTH, 1);
  5618. if (tokens.length > 0)
  5619. {
  5620. for (var i = 0; i < tokens.length; i++)
  5621. {
  5622. tokens[i] = Math.round(Number(tokens[i]) * scale * sw * 100) / 100;
  5623. }
  5624. }
  5625. node.setAttribute('stroke-dasharray', tokens.join(' '));
  5626. }
  5627. else
  5628. {
  5629. tokens = dashArray.split(' ');
  5630. }
  5631. if (tokens.length > 0)
  5632. {
  5633. var sum = 0;
  5634. for (var i = 0; i < tokens.length; i++)
  5635. {
  5636. var temp = parseFloat(tokens[i]);
  5637. if (!isNaN(temp))
  5638. {
  5639. sum += parseFloat(tokens[i]);
  5640. }
  5641. }
  5642. // If an odd number of values is provided, then the list of
  5643. // values is repeated to yield an even number of values
  5644. if (tokens.length % 2 != 0)
  5645. {
  5646. sum *= 2;
  5647. }
  5648. var d = Math.round((sum / scale / 16) * parseInt(mxUtils.getValue(
  5649. style, 'flowAnimationDuration', 500)));
  5650. var tf = mxUtils.getValue(style, 'flowAnimationTimingFunction', 'linear');
  5651. var ad = mxUtils.getValue(style, 'flowAnimationDirection', 'normal');
  5652. node.style.animation = id + ' ' + d + 'ms ' + mxUtils.htmlEntities(tf) +
  5653. ' infinite ' + mxUtils.htmlEntities(ad);
  5654. node.style.strokeDashoffset = sum;
  5655. }
  5656. }
  5657. };
  5658. /**
  5659. * Adds rack child layout style.
  5660. */
  5661. Graph.prototype.addFlowAnimationStyle = function()
  5662. {
  5663. var head = document.getElementsByTagName('head')[0];
  5664. if (head != null && this.flowAnimationId == null)
  5665. {
  5666. this.flowAnimationId = 'ge-flow-animation-' + Editor.guid();
  5667. var style = document.createElement('style');
  5668. style.innerHTML = this.createFlowAnimationCss(
  5669. this.flowAnimationId);
  5670. head.appendChild(style);
  5671. }
  5672. return this.flowAnimationId;
  5673. };
  5674. /**
  5675. * Adds rack child layout style.
  5676. */
  5677. Graph.prototype.createFlowAnimationCss = function(id)
  5678. {
  5679. return '@keyframes ' + id + ' {\n' +
  5680. ' to {\n' +
  5681. ' stroke-dashoffset: 0;\n' +
  5682. ' }\n' +
  5683. '}';
  5684. };
  5685. /**
  5686. * Turns the given string into an array.
  5687. */
  5688. Graph.prototype.stringToBytes = function(str)
  5689. {
  5690. return Graph.stringToBytes(str);
  5691. };
  5692. /**
  5693. * Turns the given array into a string.
  5694. */
  5695. Graph.prototype.bytesToString = function(arr)
  5696. {
  5697. return Graph.bytesToString(arr);
  5698. };
  5699. /**
  5700. * Returns a base64 encoded version of the compressed outer XML of the given node.
  5701. */
  5702. Graph.prototype.compressNode = function(node)
  5703. {
  5704. return Graph.compressNode(node);
  5705. };
  5706. /**
  5707. * Returns a base64 encoded version of the compressed string.
  5708. */
  5709. Graph.prototype.compress = function(data, deflate)
  5710. {
  5711. return Graph.compress(data, deflate);
  5712. };
  5713. /**
  5714. * Returns a decompressed version of the base64 encoded string.
  5715. */
  5716. Graph.prototype.decompress = function(data, inflate)
  5717. {
  5718. return Graph.decompress(data, inflate);
  5719. };
  5720. /**
  5721. * Redirects to Graph.zapGremlins.
  5722. */
  5723. Graph.prototype.zapGremlins = function(text)
  5724. {
  5725. return Graph.zapGremlins(text);
  5726. };
  5727. /**
  5728. * Hover icons are used for hover, vertex handler and drag from sidebar.
  5729. */
  5730. HoverIcons = function(graph)
  5731. {
  5732. mxEventSource.call(this);
  5733. this.graph = graph;
  5734. this.init();
  5735. };
  5736. // Extends mxEventSource
  5737. mxUtils.extend(HoverIcons, mxEventSource);
  5738. /**
  5739. * Up arrow.
  5740. */
  5741. HoverIcons.prototype.arrowSpacing = 2;
  5742. /**
  5743. * Delay to switch to another state for overlapping bbox. Default is 500ms.
  5744. */
  5745. HoverIcons.prototype.updateDelay = 500;
  5746. /**
  5747. * Delay to switch between states. Default is 140ms.
  5748. */
  5749. HoverIcons.prototype.activationDelay = 140;
  5750. /**
  5751. * Up arrow.
  5752. */
  5753. HoverIcons.prototype.currentState = null;
  5754. /**
  5755. * Up arrow.
  5756. */
  5757. HoverIcons.prototype.activeArrow = null;
  5758. /**
  5759. * Up arrow.
  5760. */
  5761. HoverIcons.prototype.inactiveOpacity = 15;
  5762. /**
  5763. * Up arrow.
  5764. */
  5765. HoverIcons.prototype.cssCursor = 'copy';
  5766. /**
  5767. * Whether to hide arrows that collide with vertices.
  5768. * LATER: Add keyboard override, touch support.
  5769. */
  5770. HoverIcons.prototype.checkCollisions = true;
  5771. /**
  5772. * Up arrow.
  5773. */
  5774. HoverIcons.prototype.arrowFill = '#29b6f2';
  5775. /**
  5776. * Up arrow.
  5777. */
  5778. HoverIcons.prototype.triangleUp = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-up.png', 26, 14) :
  5779. 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" ' +
  5780. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  5781. /**
  5782. * Right arrow.
  5783. */
  5784. HoverIcons.prototype.triangleRight = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-right.png', 14, 26) :
  5785. 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" ' +
  5786. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  5787. /**
  5788. * Down arrow.
  5789. */
  5790. HoverIcons.prototype.triangleDown = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-down.png', 26, 14) :
  5791. 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" ' +
  5792. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  5793. /**
  5794. * Left arrow.
  5795. */
  5796. HoverIcons.prototype.triangleLeft = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-left.png', 14, 26) :
  5797. 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" ' +
  5798. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  5799. /**
  5800. * Round target.
  5801. */
  5802. HoverIcons.prototype.roundDrop = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/round-drop.png', 26, 26) :
  5803. Graph.createSvgImage(26, 26, '<circle cx="13" cy="13" r="12" ' +
  5804. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  5805. /**
  5806. * Refresh target.
  5807. */
  5808. HoverIcons.prototype.refreshTarget = new mxImage((mxClient.IS_SVG) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjM2cHgiIGhlaWdodD0iMzZweCI+PGVsbGlwc2UgZmlsbD0iIzI5YjZmMiIgY3g9IjEyIiBjeT0iMTIiIHJ4PSIxMiIgcnk9IjEyIi8+PHBhdGggdHJhbnNmb3JtPSJzY2FsZSgwLjgpIHRyYW5zbGF0ZSgyLjQsIDIuNCkiIHN0cm9rZT0iI2ZmZiIgZmlsbD0iI2ZmZiIgZD0iTTEyIDZ2M2w0LTQtNC00djNjLTQuNDIgMC04IDMuNTgtOCA4IDAgMS41Ny40NiAzLjAzIDEuMjQgNC4yNkw2LjcgMTQuOGMtLjQ1LS44My0uNy0xLjc5LS43LTIuOCAwLTMuMzEgMi42OS02IDYtNnptNi43NiAxLjc0TDE3LjMgOS4yYy40NC44NC43IDEuNzkuNyAyLjggMCAzLjMxLTIuNjkgNi02IDZ2LTNsLTQgNCA0IDR2LTNjNC40MiAwIDgtMy41OCA4LTggMC0xLjU3LS40Ni0zLjAzLTEuMjQtNC4yNnoiLz48cGF0aCBkPSJNMCAwaDI0djI0SDB6IiBmaWxsPSJub25lIi8+PC9zdmc+Cg==' :
  5809. IMAGE_PATH + '/refresh.png', 38, 38);
  5810. /**
  5811. * Tolerance for hover icon clicks.
  5812. */
  5813. HoverIcons.prototype.tolerance = (mxClient.IS_TOUCH) ? 6 : 0;
  5814. /**
  5815. *
  5816. */
  5817. HoverIcons.prototype.init = function()
  5818. {
  5819. this.arrowUp = this.createArrow(this.triangleUp, mxResources.get('plusTooltip'), mxConstants.DIRECTION_NORTH);
  5820. this.arrowRight = this.createArrow(this.triangleRight, mxResources.get('plusTooltip'), mxConstants.DIRECTION_EAST);
  5821. this.arrowDown = this.createArrow(this.triangleDown, mxResources.get('plusTooltip'), mxConstants.DIRECTION_SOUTH);
  5822. this.arrowLeft = this.createArrow(this.triangleLeft, mxResources.get('plusTooltip'), mxConstants.DIRECTION_WEST);
  5823. this.elts = [this.arrowUp, this.arrowRight, this.arrowDown, this.arrowLeft];
  5824. this.resetHandler = mxUtils.bind(this, function()
  5825. {
  5826. this.reset();
  5827. });
  5828. this.repaintHandler = mxUtils.bind(this, function()
  5829. {
  5830. this.repaint();
  5831. });
  5832. this.graph.selectionModel.addListener(mxEvent.CHANGE, this.resetHandler);
  5833. this.graph.model.addListener(mxEvent.CHANGE, this.repaintHandler);
  5834. this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.repaintHandler);
  5835. this.graph.view.addListener(mxEvent.TRANSLATE, this.repaintHandler);
  5836. this.graph.view.addListener(mxEvent.SCALE, this.repaintHandler);
  5837. this.graph.view.addListener(mxEvent.DOWN, this.repaintHandler);
  5838. this.graph.view.addListener(mxEvent.UP, this.repaintHandler);
  5839. this.graph.addListener(mxEvent.ROOT, this.repaintHandler);
  5840. this.graph.addListener(mxEvent.ESCAPE, this.resetHandler);
  5841. mxEvent.addListener(this.graph.container, 'scroll', this.resetHandler);
  5842. // Resets the mouse point on escape
  5843. this.graph.addListener(mxEvent.ESCAPE, mxUtils.bind(this, function()
  5844. {
  5845. this.mouseDownPoint = null;
  5846. }));
  5847. // Removes hover icons if mouse leaves the container
  5848. mxEvent.addListener(this.graph.container, 'mouseleave', mxUtils.bind(this, function(evt)
  5849. {
  5850. // Workaround for IE11 firing mouseleave for touch in diagram
  5851. if (evt.relatedTarget != null && mxEvent.getSource(evt) == this.graph.container)
  5852. {
  5853. this.setDisplay('none');
  5854. }
  5855. }));
  5856. // Resets current state when in-place editor starts
  5857. this.graph.addListener(mxEvent.START_EDITING, mxUtils.bind(this, function(evt)
  5858. {
  5859. this.reset();
  5860. }));
  5861. // Resets current state after update of selection state for touch events
  5862. var graphClick = this.graph.click;
  5863. this.graph.click = mxUtils.bind(this, function(me)
  5864. {
  5865. graphClick.apply(this.graph, arguments);
  5866. if (this.currentState != null && !this.graph.isCellSelected(this.currentState.cell) &&
  5867. mxEvent.isTouchEvent(me.getEvent()) && !this.graph.model.isVertex(me.getCell()))
  5868. {
  5869. this.reset();
  5870. }
  5871. });
  5872. // Checks if connection handler was active in mouse move
  5873. // as workaround for possible double connection inserted
  5874. var connectionHandlerActive = false;
  5875. // Implements a listener for hover and click handling
  5876. this.graph.addMouseListener(
  5877. {
  5878. mouseDown: mxUtils.bind(this, function(sender, me)
  5879. {
  5880. connectionHandlerActive = false;
  5881. var evt = me.getEvent();
  5882. if (this.isResetEvent(evt))
  5883. {
  5884. this.reset();
  5885. }
  5886. else if (!this.isActive())
  5887. {
  5888. var state = this.getState(me.getState());
  5889. if (state != null || !mxEvent.isTouchEvent(evt))
  5890. {
  5891. this.update(state);
  5892. }
  5893. }
  5894. this.setDisplay('none');
  5895. }),
  5896. mouseMove: mxUtils.bind(this, function(sender, me)
  5897. {
  5898. var evt = me.getEvent();
  5899. if (this.isResetEvent(evt))
  5900. {
  5901. this.reset();
  5902. }
  5903. else if (!this.graph.isMouseDown && !mxEvent.isTouchEvent(evt))
  5904. {
  5905. this.update(this.getState(me.getState()),
  5906. me.getGraphX(), me.getGraphY());
  5907. }
  5908. if (this.graph.connectionHandler != null &&
  5909. this.graph.connectionHandler.shape != null)
  5910. {
  5911. connectionHandlerActive = true;
  5912. }
  5913. }),
  5914. mouseUp: mxUtils.bind(this, function(sender, me)
  5915. {
  5916. var evt = me.getEvent();
  5917. var pt = mxUtils.convertPoint(this.graph.container,
  5918. mxEvent.getClientX(evt), mxEvent.getClientY(evt))
  5919. if (this.isResetEvent(evt))
  5920. {
  5921. this.reset();
  5922. }
  5923. else if (this.isActive() && !connectionHandlerActive &&
  5924. this.mouseDownPoint != null)
  5925. {
  5926. this.click(this.currentState, this.getDirection(), me);
  5927. }
  5928. else if (this.isActive())
  5929. {
  5930. // Selects target vertex after drag and clone if not only new edge was inserted
  5931. if (this.graph.getSelectionCount() != 1 || !this.graph.model.isEdge(
  5932. this.graph.getSelectionCell()))
  5933. {
  5934. this.update(this.getState(this.graph.view.getState(
  5935. this.graph.getCellAt(me.getGraphX(), me.getGraphY()))));
  5936. }
  5937. else
  5938. {
  5939. this.reset();
  5940. }
  5941. }
  5942. else if (mxEvent.isTouchEvent(evt) || (this.bbox != null &&
  5943. mxUtils.contains(this.bbox, me.getGraphX(), me.getGraphY())))
  5944. {
  5945. // Shows existing hover icons if inside bounding box
  5946. this.setDisplay('');
  5947. this.repaint();
  5948. }
  5949. else if (!mxEvent.isTouchEvent(evt))
  5950. {
  5951. this.reset();
  5952. }
  5953. connectionHandlerActive = false;
  5954. this.resetActiveArrow();
  5955. })
  5956. });
  5957. };
  5958. /**
  5959. *
  5960. */
  5961. HoverIcons.prototype.isResetEvent = function(evt, allowShift)
  5962. {
  5963. return mxEvent.isAltDown(evt) || (this.activeArrow == null && mxEvent.isShiftDown(evt)) ||
  5964. (mxEvent.isPopupTrigger(evt) && !this.graph.isCloneEvent(evt));
  5965. };
  5966. /**
  5967. *
  5968. */
  5969. HoverIcons.prototype.createArrow = function(img, tooltip, direction)
  5970. {
  5971. var arrow = null;
  5972. arrow = mxUtils.createImage(img.src);
  5973. arrow.style.width = img.width + 'px';
  5974. arrow.style.height = img.height + 'px';
  5975. arrow.style.padding = this.tolerance + 'px';
  5976. if (tooltip != null)
  5977. {
  5978. arrow.setAttribute('title', tooltip);
  5979. }
  5980. arrow.style.position = 'absolute';
  5981. arrow.style.cursor = this.cssCursor;
  5982. mxEvent.addGestureListeners(arrow, mxUtils.bind(this, function(evt)
  5983. {
  5984. if (this.currentState != null && !this.isResetEvent(evt))
  5985. {
  5986. this.mouseDownPoint = mxUtils.convertPoint(this.graph.container,
  5987. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  5988. this.drag(evt, this.mouseDownPoint.x, this.mouseDownPoint.y);
  5989. this.activeArrow = arrow;
  5990. this.setDisplay('none');
  5991. mxEvent.consume(evt);
  5992. }
  5993. }));
  5994. // Captures mouse events as events on graph
  5995. mxEvent.redirectMouseEvents(arrow, this.graph, this.currentState);
  5996. mxEvent.addListener(arrow, 'mouseenter', mxUtils.bind(this, function(evt)
  5997. {
  5998. // Workaround for Firefox firing mouseenter on touchend
  5999. if (mxEvent.isMouseEvent(evt))
  6000. {
  6001. if (this.activeArrow != null && this.activeArrow != arrow)
  6002. {
  6003. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  6004. }
  6005. this.graph.connectionHandler.constraintHandler.reset();
  6006. mxUtils.setOpacity(arrow, 100);
  6007. this.activeArrow = arrow;
  6008. this.fireEvent(new mxEventObject('focus', 'arrow', arrow,
  6009. 'direction', direction, 'event', evt));
  6010. }
  6011. }));
  6012. mxEvent.addListener(arrow, 'mouseleave', mxUtils.bind(this, function(evt)
  6013. {
  6014. if (mxEvent.isMouseEvent(evt))
  6015. {
  6016. this.fireEvent(new mxEventObject('blur', 'arrow', arrow,
  6017. 'direction', direction, 'event', evt));
  6018. }
  6019. // Workaround for IE11 firing this event on touch
  6020. if (!this.graph.isMouseDown)
  6021. {
  6022. this.resetActiveArrow();
  6023. }
  6024. }));
  6025. return arrow;
  6026. };
  6027. /**
  6028. *
  6029. */
  6030. HoverIcons.prototype.resetActiveArrow = function()
  6031. {
  6032. if (this.activeArrow != null)
  6033. {
  6034. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  6035. this.activeArrow = null;
  6036. }
  6037. };
  6038. /**
  6039. *
  6040. */
  6041. HoverIcons.prototype.getDirection = function()
  6042. {
  6043. var dir = mxConstants.DIRECTION_EAST;
  6044. if (this.activeArrow == this.arrowUp)
  6045. {
  6046. dir = mxConstants.DIRECTION_NORTH;
  6047. }
  6048. else if (this.activeArrow == this.arrowDown)
  6049. {
  6050. dir = mxConstants.DIRECTION_SOUTH;
  6051. }
  6052. else if (this.activeArrow == this.arrowLeft)
  6053. {
  6054. dir = mxConstants.DIRECTION_WEST;
  6055. }
  6056. return dir;
  6057. };
  6058. /**
  6059. *
  6060. */
  6061. HoverIcons.prototype.visitNodes = function(visitor)
  6062. {
  6063. for (var i = 0; i < this.elts.length; i++)
  6064. {
  6065. if (this.elts[i] != null)
  6066. {
  6067. visitor(this.elts[i]);
  6068. }
  6069. }
  6070. };
  6071. /**
  6072. *
  6073. */
  6074. HoverIcons.prototype.removeNodes = function()
  6075. {
  6076. this.visitNodes(function(elt)
  6077. {
  6078. if (elt.parentNode != null)
  6079. {
  6080. elt.parentNode.removeChild(elt);
  6081. }
  6082. });
  6083. };
  6084. /**
  6085. *
  6086. */
  6087. HoverIcons.prototype.setDisplay = function(display)
  6088. {
  6089. this.visitNodes(function(elt)
  6090. {
  6091. elt.style.display = display;
  6092. });
  6093. };
  6094. /**
  6095. *
  6096. */
  6097. HoverIcons.prototype.isActive = function()
  6098. {
  6099. return this.activeArrow != null && this.currentState != null;
  6100. };
  6101. /**
  6102. *
  6103. */
  6104. HoverIcons.prototype.drag = function(evt, x, y)
  6105. {
  6106. this.graph.popupMenuHandler.hideMenu();
  6107. this.graph.stopEditing(false);
  6108. // Checks if state was removed in call to stopEditing above
  6109. if (this.currentState != null)
  6110. {
  6111. this.graph.connectionHandler.start(this.currentState, x, y);
  6112. this.graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  6113. this.graph.isMouseDown = true;
  6114. // Hides handles for selection cell
  6115. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  6116. if (handler != null)
  6117. {
  6118. handler.setHandlesVisible(false);
  6119. }
  6120. // Ctrl+shift drag sets source constraint
  6121. var es = this.graph.connectionHandler.edgeState;
  6122. if (evt != null && mxEvent.isShiftDown(evt) && mxEvent.isControlDown(evt) && es != null &&
  6123. mxUtils.getValue(es.style, mxConstants.STYLE_EDGE, null) === 'orthogonalEdgeStyle')
  6124. {
  6125. var direction = this.getDirection();
  6126. es.cell.style = mxUtils.setStyle(es.cell.style, 'sourcePortConstraint', direction);
  6127. es.style['sourcePortConstraint'] = direction;
  6128. }
  6129. }
  6130. };
  6131. /**
  6132. *
  6133. */
  6134. HoverIcons.prototype.getStateAt = function(state, x, y)
  6135. {
  6136. return this.graph.view.getState(this.graph.getCellAt(x, y));
  6137. };
  6138. /**
  6139. *
  6140. */
  6141. HoverIcons.prototype.click = function(state, dir, me)
  6142. {
  6143. var evt = me.getEvent();
  6144. var x = me.getGraphX();
  6145. var y = me.getGraphY();
  6146. var tmp = this.getStateAt(state, x, y);
  6147. if (tmp != null && this.graph.model.isEdge(tmp.cell) && !this.graph.isCloneEvent(evt) &&
  6148. (tmp.getVisibleTerminalState(true) == state || tmp.getVisibleTerminalState(false) == state))
  6149. {
  6150. this.graph.setSelectionCell(tmp.cell);
  6151. this.reset();
  6152. }
  6153. else if (state != null)
  6154. {
  6155. this.execute(state, dir, me);
  6156. }
  6157. me.consume();
  6158. };
  6159. /**
  6160. *
  6161. */
  6162. HoverIcons.prototype.execute = function(state, dir, me)
  6163. {
  6164. var evt = me.getEvent();
  6165. this.graph.selectCellsForConnectVertex(this.graph.connectVertex(
  6166. state.cell, dir, this.graph.defaultEdgeLength, evt, this.graph.isCloneEvent(evt),
  6167. this.graph.isCloneEvent(evt)), evt, this);
  6168. };
  6169. /**
  6170. *
  6171. */
  6172. HoverIcons.prototype.reset = function(clearTimeout)
  6173. {
  6174. clearTimeout = (clearTimeout == null) ? true : clearTimeout;
  6175. if (clearTimeout && this.updateThread != null)
  6176. {
  6177. window.clearTimeout(this.updateThread);
  6178. }
  6179. this.mouseDownPoint = null;
  6180. this.currentState = null;
  6181. this.activeArrow = null;
  6182. this.removeNodes();
  6183. this.bbox = null;
  6184. this.fireEvent(new mxEventObject('reset'));
  6185. };
  6186. /**
  6187. *
  6188. */
  6189. HoverIcons.prototype.repaint = function()
  6190. {
  6191. this.bbox = null;
  6192. if (this.currentState != null)
  6193. {
  6194. // Checks if cell was deleted
  6195. this.currentState = this.getState(this.currentState);
  6196. // Cell was deleted
  6197. if (this.currentState != null &&
  6198. this.graph.model.isVertex(this.currentState.cell) &&
  6199. this.graph.isCellConnectable(this.currentState.cell))
  6200. {
  6201. var bds = mxRectangle.fromRectangle(this.currentState);
  6202. // Uses outer bounding box to take rotation into account
  6203. if (this.currentState.shape != null && this.currentState.shape.boundingBox != null)
  6204. {
  6205. bds = mxRectangle.fromRectangle(this.currentState.shape.boundingBox);
  6206. }
  6207. bds.grow(this.graph.tolerance);
  6208. bds.grow(this.arrowSpacing);
  6209. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  6210. if (this.graph.isTableRow(this.currentState.cell))
  6211. {
  6212. handler = this.graph.selectionCellsHandler.getHandler(
  6213. this.graph.model.getParent(this.currentState.cell));
  6214. }
  6215. var rotationBbox = null;
  6216. if (handler != null)
  6217. {
  6218. bds.x -= handler.horizontalOffset / 2;
  6219. bds.y -= handler.verticalOffset / 2;
  6220. bds.width += handler.horizontalOffset;
  6221. bds.height += handler.verticalOffset;
  6222. // Adds bounding box of rotation handle to avoid overlap
  6223. if (handler.rotationShape != null && handler.rotationShape.node != null &&
  6224. handler.rotationShape.node.style.visibility != 'hidden' &&
  6225. handler.rotationShape.node.style.display != 'none' &&
  6226. handler.rotationShape.boundingBox != null)
  6227. {
  6228. rotationBbox = handler.rotationShape.boundingBox;
  6229. }
  6230. }
  6231. // Positions arrows avoid collisions with rotation handle
  6232. var positionArrow = mxUtils.bind(this, function(arrow, x, y)
  6233. {
  6234. if (rotationBbox != null)
  6235. {
  6236. var bbox = new mxRectangle(x, y, arrow.clientWidth, arrow.clientHeight);
  6237. if (mxUtils.intersects(bbox, rotationBbox))
  6238. {
  6239. if (arrow == this.arrowUp)
  6240. {
  6241. y -= bbox.y + bbox.height - rotationBbox.y;
  6242. }
  6243. else if (arrow == this.arrowRight)
  6244. {
  6245. x += rotationBbox.x + rotationBbox.width - bbox.x;
  6246. }
  6247. else if (arrow == this.arrowDown)
  6248. {
  6249. y += rotationBbox.y + rotationBbox.height - bbox.y;
  6250. }
  6251. else if (arrow == this.arrowLeft)
  6252. {
  6253. x -= bbox.x + bbox.width - rotationBbox.x;
  6254. }
  6255. }
  6256. }
  6257. arrow.style.left = x + 'px';
  6258. arrow.style.top = y + 'px';
  6259. mxUtils.setOpacity(arrow, this.inactiveOpacity);
  6260. });
  6261. positionArrow(this.arrowUp,
  6262. Math.round(this.currentState.getCenterX() - this.triangleUp.width / 2 - this.tolerance),
  6263. Math.round(bds.y - this.triangleUp.height - this.tolerance));
  6264. positionArrow(this.arrowRight, Math.round(bds.x + bds.width - this.tolerance),
  6265. Math.round(this.currentState.getCenterY() - this.triangleRight.height / 2 - this.tolerance));
  6266. positionArrow(this.arrowDown, parseInt(this.arrowUp.style.left),
  6267. Math.round(bds.y + bds.height - this.tolerance));
  6268. positionArrow(this.arrowLeft, Math.round(bds.x - this.triangleLeft.width - this.tolerance),
  6269. parseInt(this.arrowRight.style.top));
  6270. if (this.checkCollisions)
  6271. {
  6272. var right = this.graph.getCellAt(bds.x + bds.width +
  6273. this.triangleRight.width / 2, this.currentState.getCenterY());
  6274. var left = this.graph.getCellAt(bds.x - this.triangleLeft.width / 2, this.currentState.getCenterY());
  6275. var top = this.graph.getCellAt(this.currentState.getCenterX(), bds.y - this.triangleUp.height / 2);
  6276. var bottom = this.graph.getCellAt(this.currentState.getCenterX(), bds.y + bds.height + this.triangleDown.height / 2);
  6277. // Shows hover icons large cell is behind all directions of current cell
  6278. if (right != null && right == left && left == top && top == bottom)
  6279. {
  6280. right = null;
  6281. left = null;
  6282. top = null;
  6283. bottom = null;
  6284. }
  6285. var currentGeo = this.graph.getCellGeometry(this.currentState.cell);
  6286. var checkCollision = mxUtils.bind(this, function(cell, arrow)
  6287. {
  6288. var geo = this.graph.model.isVertex(cell) && this.graph.getCellGeometry(cell);
  6289. // Ignores collision if vertex is more than 3 times the size of this vertex
  6290. if (cell != null && !this.graph.model.isAncestor(cell, this.currentState.cell) &&
  6291. !this.graph.isSwimlane(cell) && (geo == null || currentGeo == null ||
  6292. (geo.height < 3 * currentGeo.height && geo.width < 3 * currentGeo.width)))
  6293. {
  6294. arrow.style.visibility = 'hidden';
  6295. }
  6296. else
  6297. {
  6298. arrow.style.visibility = 'visible';
  6299. }
  6300. });
  6301. checkCollision(right, this.arrowRight);
  6302. checkCollision(left, this.arrowLeft);
  6303. checkCollision(top, this.arrowUp);
  6304. checkCollision(bottom, this.arrowDown);
  6305. }
  6306. else
  6307. {
  6308. this.arrowLeft.style.visibility = 'visible';
  6309. this.arrowRight.style.visibility = 'visible';
  6310. this.arrowUp.style.visibility = 'visible';
  6311. this.arrowDown.style.visibility = 'visible';
  6312. }
  6313. if (this.graph.tooltipHandler.isEnabled())
  6314. {
  6315. this.arrowLeft.setAttribute('title', mxResources.get('plusTooltip'));
  6316. this.arrowRight.setAttribute('title', mxResources.get('plusTooltip'));
  6317. this.arrowUp.setAttribute('title', mxResources.get('plusTooltip'));
  6318. this.arrowDown.setAttribute('title', mxResources.get('plusTooltip'));
  6319. }
  6320. else
  6321. {
  6322. this.arrowLeft.removeAttribute('title');
  6323. this.arrowRight.removeAttribute('title');
  6324. this.arrowUp.removeAttribute('title');
  6325. this.arrowDown.removeAttribute('title');
  6326. }
  6327. }
  6328. else
  6329. {
  6330. this.reset();
  6331. }
  6332. // Updates bounding box
  6333. if (this.currentState != null)
  6334. {
  6335. this.bbox = this.computeBoundingBox();
  6336. // Adds tolerance for hover
  6337. if (this.bbox != null)
  6338. {
  6339. this.bbox.grow(10);
  6340. }
  6341. }
  6342. }
  6343. };
  6344. /**
  6345. *
  6346. */
  6347. HoverIcons.prototype.computeBoundingBox = function()
  6348. {
  6349. var bbox = (!this.graph.model.isEdge(this.currentState.cell)) ? mxRectangle.fromRectangle(this.currentState) : null;
  6350. this.visitNodes(function(elt)
  6351. {
  6352. if (elt.parentNode != null)
  6353. {
  6354. var tmp = new mxRectangle(elt.offsetLeft, elt.offsetTop, elt.offsetWidth, elt.offsetHeight);
  6355. if (bbox == null)
  6356. {
  6357. bbox = tmp;
  6358. }
  6359. else
  6360. {
  6361. bbox.add(tmp);
  6362. }
  6363. }
  6364. });
  6365. return bbox;
  6366. };
  6367. /**
  6368. *
  6369. */
  6370. HoverIcons.prototype.getState = function(state)
  6371. {
  6372. if (state != null)
  6373. {
  6374. var cell = state.cell;
  6375. if (!this.graph.getModel().contains(cell))
  6376. {
  6377. state = null;
  6378. }
  6379. else
  6380. {
  6381. // Uses connectable parent vertex if child is not connectable
  6382. if (this.graph.getModel().isVertex(cell) && !this.graph.isCellConnectable(cell))
  6383. {
  6384. var parent = this.graph.getModel().getParent(cell);
  6385. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  6386. {
  6387. cell = parent;
  6388. }
  6389. }
  6390. // Ignores locked cells and edges
  6391. if (this.graph.isCellLocked(cell) || this.graph.model.isEdge(cell))
  6392. {
  6393. cell = null;
  6394. }
  6395. state = this.graph.view.getState(cell);
  6396. if (state != null && state.style == null)
  6397. {
  6398. state = null;
  6399. }
  6400. }
  6401. }
  6402. return state;
  6403. };
  6404. /**
  6405. *
  6406. */
  6407. HoverIcons.prototype.update = function(state, x, y)
  6408. {
  6409. if (!this.graph.connectionArrowsEnabled ||
  6410. (this.graph.freehand != null && this.graph.freehand.isDrawing()) ||
  6411. (state != null && mxUtils.getValue(state.style, 'allowArrows', '1') == '0'))
  6412. {
  6413. this.reset();
  6414. }
  6415. else
  6416. {
  6417. if (state != null && state.cell.geometry != null && state.cell.geometry.relative &&
  6418. this.graph.model.isEdge(state.cell.parent))
  6419. {
  6420. state = null;
  6421. }
  6422. var timeOnTarget = null;
  6423. // Time on target
  6424. if (this.prev != state || this.isActive())
  6425. {
  6426. this.startTime = new Date().getTime();
  6427. this.prev = state;
  6428. timeOnTarget = 0;
  6429. if (this.updateThread != null)
  6430. {
  6431. window.clearTimeout(this.updateThread);
  6432. }
  6433. if (state != null)
  6434. {
  6435. // Starts timer to update current state with no mouse events
  6436. this.updateThread = window.setTimeout(mxUtils.bind(this, function()
  6437. {
  6438. if (!this.isActive() && !this.graph.isMouseDown &&
  6439. !this.graph.panningHandler.isActive())
  6440. {
  6441. this.prev = state;
  6442. this.update(state, x, y);
  6443. }
  6444. }), this.updateDelay + 10);
  6445. }
  6446. }
  6447. else if (this.startTime != null)
  6448. {
  6449. timeOnTarget = new Date().getTime() - this.startTime;
  6450. }
  6451. this.setDisplay('');
  6452. if (this.currentState != null && this.currentState != state && timeOnTarget < this.activationDelay &&
  6453. this.bbox != null && !mxUtils.contains(this.bbox, x, y))
  6454. {
  6455. this.reset(false);
  6456. }
  6457. else if (this.currentState != null || timeOnTarget > this.activationDelay)
  6458. {
  6459. if (this.currentState != state && ((timeOnTarget > this.updateDelay && state != null) ||
  6460. this.bbox == null || x == null || y == null || !mxUtils.contains(this.bbox, x, y)))
  6461. {
  6462. if (state != null && this.graph.isEnabled())
  6463. {
  6464. this.removeNodes();
  6465. this.setCurrentState(state);
  6466. this.repaint();
  6467. // Resets connection points on other focused cells
  6468. if (this.graph.connectionHandler.constraintHandler.currentFocus != state)
  6469. {
  6470. this.graph.connectionHandler.constraintHandler.reset();
  6471. }
  6472. }
  6473. else
  6474. {
  6475. this.reset();
  6476. }
  6477. }
  6478. }
  6479. }
  6480. };
  6481. /**
  6482. *
  6483. */
  6484. HoverIcons.prototype.setCurrentState = function(state)
  6485. {
  6486. if (state.style['portConstraint'] != 'eastwest')
  6487. {
  6488. this.graph.container.appendChild(this.arrowUp);
  6489. this.graph.container.appendChild(this.arrowDown);
  6490. }
  6491. this.graph.container.appendChild(this.arrowRight);
  6492. this.graph.container.appendChild(this.arrowLeft);
  6493. this.currentState = state;
  6494. };
  6495. /**
  6496. * Returns true if the given cell is a table.
  6497. */
  6498. Graph.prototype.removeTextStyleForCell = function(cell, removeCellStyles)
  6499. {
  6500. var style = this.getCurrentCellStyle(cell);
  6501. var result = false;
  6502. this.getModel().beginUpdate();
  6503. try
  6504. {
  6505. if (mxUtils.getValue(style, 'html', '0') == '1')
  6506. {
  6507. var label = this.convertValueToString(cell);
  6508. if (mxUtils.getValue(style, 'nl2Br', '1') != '0')
  6509. {
  6510. // Removes newlines from HTML and converts breaks to newlines
  6511. // to match the HTML output in plain text
  6512. label = label.replace(/\n/g, '').replace(/<br\s*.?>/g, '\n');
  6513. }
  6514. label = Editor.convertHtmlToText(label);
  6515. this.cellLabelChanged(cell, label);
  6516. result = true;
  6517. }
  6518. if (removeCellStyles)
  6519. {
  6520. this.setCellStyles('fontSource', null, [cell]);
  6521. this.setCellStyles(mxConstants.STYLE_FONTFAMILY, null, [cell]);
  6522. this.setCellStyles(mxConstants.STYLE_FONTSIZE, null, [cell]);
  6523. this.setCellStyles(mxConstants.STYLE_FONTSTYLE, null, [cell]);
  6524. this.setCellStyles(mxConstants.STYLE_FONTCOLOR, null, [cell]);
  6525. this.setCellStyles(mxConstants.STYLE_LABEL_BORDERCOLOR, null, [cell]);
  6526. this.setCellStyles(mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, null, [cell]);
  6527. }
  6528. }
  6529. finally
  6530. {
  6531. this.getModel().endUpdate();
  6532. }
  6533. return result;
  6534. };
  6535. /**
  6536. * Returns true if the given cell is a table.
  6537. */
  6538. Graph.prototype.createParent = function(parent, child, childCount, dx, dy)
  6539. {
  6540. parent = this.cloneCell(parent);
  6541. for (var i = 0; i < childCount; i++)
  6542. {
  6543. var clone = this.cloneCell(child);
  6544. var geo = this.getCellGeometry(clone)
  6545. if (geo != null)
  6546. {
  6547. geo.x += i * dx;
  6548. geo.y += i * dy;
  6549. }
  6550. parent.insert(clone);
  6551. }
  6552. return parent;
  6553. };
  6554. /**
  6555. * Returns true if the given cell is a table.
  6556. */
  6557. Graph.prototype.createTable = function(rowCount, colCount, w, h, title, startSize, tableStyle, rowStyle, cellStyle)
  6558. {
  6559. w = (w != null) ? w : 60;
  6560. h = (h != null) ? h : 40;
  6561. startSize = (startSize != null) ? startSize : 30;
  6562. tableStyle = (tableStyle != null) ? tableStyle : 'shape=table;startSize=' +
  6563. ((title != null) ? startSize : '0') + ';container=1;collapsible=0;childLayout=tableLayout;';
  6564. rowStyle = (rowStyle != null) ? rowStyle : 'shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;strokeColor=inherit;' +
  6565. 'top=0;left=0;bottom=0;right=0;collapsible=0;dropTarget=0;fillColor=none;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;';
  6566. cellStyle = (cellStyle != null) ? cellStyle : 'shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;strokeColor=inherit;' +
  6567. 'overflow=hidden;fillColor=none;top=0;left=0;bottom=0;right=0;pointerEvents=1;';
  6568. return this.createParent(this.createVertex(null, null, (title != null) ? title : '',
  6569. 0, 0, colCount * w, rowCount * h + ((title != null) ? startSize : 0), tableStyle),
  6570. this.createParent(this.createVertex(null, null, '', 0, 0, colCount * w, h, rowStyle),
  6571. this.createVertex(null, null, '', 0, 0, w, h, cellStyle),
  6572. colCount, w, 0), rowCount, 0, h);
  6573. };
  6574. /**
  6575. * Sets the values for the cells and rows in the given table and returns the table.
  6576. */
  6577. Graph.prototype.setTableValues = function(table, values, rowValues)
  6578. {
  6579. var rows = this.model.getChildCells(table, true);
  6580. for (var i = 0; i < rows.length; i++)
  6581. {
  6582. if (rowValues != null)
  6583. {
  6584. rows[i].value = rowValues[i];
  6585. }
  6586. if (values != null)
  6587. {
  6588. var cells = this.model.getChildCells(rows[i], true);
  6589. for (var j = 0; j < cells.length; j++)
  6590. {
  6591. if (values[i][j] != null)
  6592. {
  6593. cells[j].value = values[i][j];
  6594. }
  6595. }
  6596. }
  6597. }
  6598. return table;
  6599. };
  6600. /**
  6601. *
  6602. */
  6603. Graph.prototype.createCrossFunctionalSwimlane = function(rowCount, colCount, w, h, title, tableStyle, rowStyle, firstCellStyle, cellStyle)
  6604. {
  6605. w = (w != null) ? w : 120;
  6606. h = (h != null) ? h : 120;
  6607. var s = 'collapsible=0;recursiveResize=0;expand=0;';
  6608. tableStyle = (tableStyle != null) ? tableStyle : 'shape=table;childLayout=tableLayout;' +
  6609. ((title == null) ? 'startSize=0;fillColor=none;' : 'startSize=40;') + s;
  6610. rowStyle = (rowStyle != null) ? rowStyle : 'shape=tableRow;horizontal=0;swimlaneHead=0;swimlaneBody=0;top=0;left=0;strokeColor=inherit;' +
  6611. 'bottom=0;right=0;dropTarget=0;fontStyle=0;fillColor=none;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;startSize=40;' + s;
  6612. firstCellStyle = (firstCellStyle != null) ? firstCellStyle : 'swimlane;swimlaneHead=0;swimlaneBody=0;fontStyle=0;strokeColor=inherit;' +
  6613. 'connectable=0;fillColor=none;startSize=40;' + s;
  6614. cellStyle = (cellStyle != null) ? cellStyle : 'swimlane;swimlaneHead=0;swimlaneBody=0;fontStyle=0;connectable=0;strokeColor=inherit;' +
  6615. 'fillColor=none;startSize=0;' + s;
  6616. var table = this.createVertex(null, null, (title != null) ? title : '', 0, 0,
  6617. colCount * w, rowCount * h, tableStyle);
  6618. var t = mxUtils.getValue(this.getCellStyle(table), mxConstants.STYLE_STARTSIZE,
  6619. mxConstants.DEFAULT_STARTSIZE);
  6620. table.geometry.width += t;
  6621. table.geometry.height += t;
  6622. var row = this.createVertex(null, null, '', 0, t, colCount * w + t, h, rowStyle);
  6623. table.insert(this.createParent(row, this.createVertex(null, null,
  6624. '', t, 0, w, h, firstCellStyle), colCount, w, 0));
  6625. if (rowCount > 1)
  6626. {
  6627. row.geometry.y = h + t;
  6628. return this.createParent(table, this.createParent(row,
  6629. this.createVertex(null, null, '', t, 0, w, h, cellStyle),
  6630. colCount, w, 0), rowCount - 1, 0, h);
  6631. }
  6632. else
  6633. {
  6634. return table;
  6635. }
  6636. };
  6637. /**
  6638. * Returns the row and column lines for the given table.
  6639. */
  6640. Graph.prototype.visitTableCells = function(cell, visitor)
  6641. {
  6642. var lastRow = null;
  6643. var rows = this.model.getChildCells(cell, true);
  6644. var start = this.getActualStartSize(cell, true);
  6645. for (var i = 0; i < rows.length; i++)
  6646. {
  6647. var rowStart = this.getActualStartSize(rows[i], true);
  6648. var cols = this.model.getChildCells(rows[i], true);
  6649. var rowStyle = this.getCellStyle(rows[i], true);
  6650. var lastCol = null;
  6651. var row = [];
  6652. for (var j = 0; j < cols.length; j++)
  6653. {
  6654. var geo = this.getCellGeometry(cols[j]);
  6655. var col = {cell: cols[j], rospan: 1, colspan: 1, row: i, col: j, geo: geo};
  6656. geo = (geo.alternateBounds != null) ? geo.alternateBounds : geo;
  6657. col.point = new mxPoint(geo.width + (lastCol != null ? lastCol.point.x : start.x + rowStart.x),
  6658. geo.height + (lastRow != null && lastRow[0] != null ? lastRow[0].point.y : start.y + rowStart.y));
  6659. col.actual = col;
  6660. if (lastRow != null && lastRow[j] != null && lastRow[j].rowspan > 1)
  6661. {
  6662. col.rowspan = lastRow[j].rowspan - 1;
  6663. col.colspan = lastRow[j].colspan;
  6664. col.actual = lastRow[j].actual;
  6665. }
  6666. else
  6667. {
  6668. if (lastCol != null && lastCol.colspan > 1)
  6669. {
  6670. col.rowspan = lastCol.rowspan;
  6671. col.colspan = lastCol.colspan - 1;
  6672. col.actual = lastCol.actual;
  6673. }
  6674. else
  6675. {
  6676. var style = this.getCurrentCellStyle(cols[j], true);
  6677. if (style != null)
  6678. {
  6679. col.rowspan = parseInt(style['rowspan'] || 1);
  6680. col.colspan = parseInt(style['colspan'] || 1);
  6681. }
  6682. }
  6683. }
  6684. var head = mxUtils.getValue(rowStyle, mxConstants.STYLE_SWIMLANE_HEAD, 1) == 1 &&
  6685. mxUtils.getValue(rowStyle, mxConstants.STYLE_STROKECOLOR,
  6686. mxConstants.NONE) != mxConstants.NONE;
  6687. visitor(col, cols.length, rows.length,
  6688. start.x + ((head) ? rowStart.x : 0),
  6689. start.y + ((head) ? rowStart.y : 0));
  6690. row.push(col);
  6691. lastCol = col;
  6692. }
  6693. lastRow = row;
  6694. }
  6695. };
  6696. /**
  6697. * Returns the row and column lines for the given table.
  6698. */
  6699. Graph.prototype.getTableLines = function(cell, horizontal, vertical)
  6700. {
  6701. var hl = [];
  6702. var vl = [];
  6703. if (horizontal || vertical)
  6704. {
  6705. this.visitTableCells(cell, mxUtils.bind(this, function(iter, colCount, rowCount, x0, y0)
  6706. {
  6707. // Constructs horizontal lines
  6708. if (horizontal && iter.row < rowCount - 1)
  6709. {
  6710. if (hl[iter.row] == null)
  6711. {
  6712. hl[iter.row] = [new mxPoint(x0, iter.point.y)];
  6713. }
  6714. if (iter.rowspan > 1)
  6715. {
  6716. hl[iter.row].push(null);
  6717. }
  6718. hl[iter.row].push(iter.point);
  6719. }
  6720. // Constructs vertical lines
  6721. if (vertical && iter.col < colCount - 1)
  6722. {
  6723. if (vl[iter.col] == null)
  6724. {
  6725. vl[iter.col] = [new mxPoint(iter.point.x, y0)];
  6726. }
  6727. if (iter.colspan > 1)
  6728. {
  6729. vl[iter.col].push(null);
  6730. }
  6731. vl[iter.col].push(iter.point);
  6732. }
  6733. }));
  6734. }
  6735. return hl.concat(vl);
  6736. };
  6737. /**
  6738. * Returns true if the given cell is a table cell.
  6739. */
  6740. Graph.prototype.isTableCell = function(cell)
  6741. {
  6742. return this.model.isVertex(cell) && this.isTableRow(this.model.getParent(cell));
  6743. };
  6744. /**
  6745. * Returns true if the given cell is a table row.
  6746. */
  6747. Graph.prototype.isTableRow = function(cell)
  6748. {
  6749. return this.model.isVertex(cell) && this.isTable(this.model.getParent(cell));
  6750. };
  6751. /**
  6752. * Returns true if the given cell is a table.
  6753. */
  6754. Graph.prototype.isTable = function(cell)
  6755. {
  6756. var style = this.getCellStyle(cell);
  6757. return style != null && style['childLayout'] == 'tableLayout';
  6758. };
  6759. /**
  6760. * Returns true if the given cell is a table.
  6761. */
  6762. Graph.prototype.isStack = function(cell)
  6763. {
  6764. var style = this.getCellStyle(cell);
  6765. return style != null && style['childLayout'] == 'stackLayout';
  6766. };
  6767. /**
  6768. * Returns true if the given cell is a table row.
  6769. */
  6770. Graph.prototype.isStackChild = function(cell)
  6771. {
  6772. return this.model.isVertex(cell) && this.isStack(this.model.getParent(cell));
  6773. };
  6774. /**
  6775. * Updates the row and table heights.
  6776. */
  6777. Graph.prototype.setTableRowHeight = function(row, dy, extend)
  6778. {
  6779. extend = (extend != null) ? extend : true;
  6780. var model = this.getModel();
  6781. model.beginUpdate();
  6782. try
  6783. {
  6784. var rgeo = this.getCellGeometry(row);
  6785. // Sets height of row
  6786. if (rgeo != null)
  6787. {
  6788. rgeo = rgeo.clone();
  6789. rgeo.height += dy;
  6790. model.setGeometry(row, rgeo);
  6791. var table = model.getParent(row);
  6792. var rows = model.getChildCells(table, true);
  6793. // Shifts and resizes neighbor row
  6794. if (!extend)
  6795. {
  6796. var index = mxUtils.indexOf(rows, row);
  6797. if (index < rows.length - 1)
  6798. {
  6799. var nextRow = rows[index + 1];
  6800. var geo = this.getCellGeometry(nextRow);
  6801. if (geo != null)
  6802. {
  6803. geo = geo.clone();
  6804. geo.y += dy;
  6805. geo.height -= dy;
  6806. model.setGeometry(nextRow, geo);
  6807. }
  6808. }
  6809. }
  6810. // Updates height of table
  6811. var tgeo = this.getCellGeometry(table);
  6812. if (tgeo != null)
  6813. {
  6814. // Always extends for last row
  6815. if (!extend)
  6816. {
  6817. extend = row == rows[rows.length - 1];
  6818. }
  6819. if (extend)
  6820. {
  6821. tgeo = tgeo.clone();
  6822. tgeo.height += dy;
  6823. model.setGeometry(table, tgeo);
  6824. }
  6825. }
  6826. }
  6827. }
  6828. finally
  6829. {
  6830. model.endUpdate();
  6831. }
  6832. };
  6833. /**
  6834. * Updates column width and row height.
  6835. */
  6836. Graph.prototype.setTableColumnWidth = function(col, dx, extend)
  6837. {
  6838. extend = (extend != null) ? extend : false;
  6839. var model = this.getModel();
  6840. var row = model.getParent(col);
  6841. var table = model.getParent(row);
  6842. var cells = model.getChildCells(row, true);
  6843. var index = mxUtils.indexOf(cells, col);
  6844. var lastColumn = index == cells.length - 1;
  6845. model.beginUpdate();
  6846. try
  6847. {
  6848. // Sets width of child cell
  6849. var rows = model.getChildCells(table, true);
  6850. for (var i = 0; i < rows.length; i++)
  6851. {
  6852. row = rows[i];
  6853. cells = model.getChildCells(row, true);
  6854. var cell = cells[index];
  6855. var geo = this.getCellGeometry(cell);
  6856. if (geo != null)
  6857. {
  6858. geo = geo.clone();
  6859. geo.width += dx;
  6860. if (geo.alternateBounds != null)
  6861. {
  6862. geo.alternateBounds.width += dx;
  6863. }
  6864. model.setGeometry(cell, geo);
  6865. }
  6866. // Shifts and resizes neighbor column
  6867. if (index < cells.length - 1)
  6868. {
  6869. cell = cells[index + 1];
  6870. var geo = this.getCellGeometry(cell);
  6871. if (geo != null)
  6872. {
  6873. geo = geo.clone();
  6874. geo.x += dx;
  6875. if (!extend)
  6876. {
  6877. geo.width -= dx;
  6878. if (geo.alternateBounds != null)
  6879. {
  6880. geo.alternateBounds.width -= dx;
  6881. }
  6882. }
  6883. model.setGeometry(cell, geo);
  6884. }
  6885. }
  6886. }
  6887. if (lastColumn || extend)
  6888. {
  6889. // Updates width of table
  6890. var tgeo = this.getCellGeometry(table);
  6891. if (tgeo != null)
  6892. {
  6893. tgeo = tgeo.clone();
  6894. tgeo.width += dx;
  6895. model.setGeometry(table, tgeo);
  6896. }
  6897. }
  6898. if (this.layoutManager != null)
  6899. {
  6900. this.layoutManager.executeLayout(table);
  6901. }
  6902. }
  6903. finally
  6904. {
  6905. model.endUpdate();
  6906. }
  6907. };
  6908. /**
  6909. * Special Layout for tables.
  6910. */
  6911. function TableLayout(graph)
  6912. {
  6913. mxGraphLayout.call(this, graph);
  6914. };
  6915. /**
  6916. * Extends mxGraphLayout.
  6917. */
  6918. TableLayout.prototype = new mxStackLayout();
  6919. TableLayout.prototype.constructor = TableLayout;
  6920. /**
  6921. * Function: isHorizontal
  6922. *
  6923. * Overrides stack layout to handle row reorder.
  6924. */
  6925. TableLayout.prototype.isHorizontal = function()
  6926. {
  6927. return false;
  6928. };
  6929. /**
  6930. * Function: isVertexIgnored
  6931. *
  6932. * Overrides to allow for table rows and cells.
  6933. */
  6934. TableLayout.prototype.isVertexIgnored = function(vertex)
  6935. {
  6936. return !this.graph.getModel().isVertex(vertex) ||
  6937. !this.graph.isCellVisible(vertex);
  6938. };
  6939. /**
  6940. * Function: getSize
  6941. *
  6942. * Returns the total vertical or horizontal size of the given cells.
  6943. */
  6944. TableLayout.prototype.getSize = function(cells, horizontal)
  6945. {
  6946. var total = 0;
  6947. for (var i = 0; i < cells.length; i++)
  6948. {
  6949. if (!this.isVertexIgnored(cells[i]))
  6950. {
  6951. var geo = this.graph.getCellGeometry(cells[i]);
  6952. if (geo != null)
  6953. {
  6954. total += (horizontal) ? geo.width : geo.height;
  6955. }
  6956. }
  6957. }
  6958. return total;
  6959. };
  6960. /**
  6961. * Function: getRowLayout
  6962. *
  6963. * Returns the column positions for the given row and table width.
  6964. */
  6965. TableLayout.prototype.getRowLayout = function(row, width)
  6966. {
  6967. var cells = this.graph.model.getChildCells(row, true);
  6968. var off = this.graph.getActualStartSize(row, true);
  6969. var sw = this.getSize(cells, true);
  6970. var rw = width - off.x - off.width;
  6971. var result = [];
  6972. var x = off.x;
  6973. for (var i = 0; i < cells.length; i++)
  6974. {
  6975. var geo = this.graph.getCellGeometry(cells[i]);
  6976. if (geo != null)
  6977. {
  6978. x += (geo.alternateBounds != null ?
  6979. geo.alternateBounds.width :
  6980. geo.width) * rw / sw;
  6981. result.push(Math.round(x));
  6982. }
  6983. }
  6984. return result;
  6985. };
  6986. /**
  6987. * Function: layoutRow
  6988. *
  6989. * Places the cells at the given positions in the given row.
  6990. */
  6991. TableLayout.prototype.layoutRow = function(row, positions, height, tw)
  6992. {
  6993. var model = this.graph.getModel();
  6994. var cells = model.getChildCells(row, true);
  6995. var off = this.graph.getActualStartSize(row, true);
  6996. var x = off.x;
  6997. var sw = 0;
  6998. if (positions != null)
  6999. {
  7000. positions = positions.slice();
  7001. positions.splice(0, 0, off.x);
  7002. }
  7003. for (var i = 0; i < cells.length; i++)
  7004. {
  7005. var geo = this.graph.getCellGeometry(cells[i]);
  7006. if (geo != null)
  7007. {
  7008. geo = geo.clone();
  7009. geo.y = off.y;
  7010. geo.height = height - off.y - off.height;
  7011. if (positions != null)
  7012. {
  7013. geo.x = positions[i];
  7014. geo.width = positions[i + 1] - geo.x;
  7015. // Fills with last geo if not enough cells
  7016. if (i == cells.length - 1 && i < positions.length - 2)
  7017. {
  7018. geo.width = tw - geo.x - off.x - off.width;
  7019. }
  7020. }
  7021. else
  7022. {
  7023. geo.x = x;
  7024. x += geo.width;
  7025. if (i == cells.length - 1)
  7026. {
  7027. geo.width = tw - off.x - off.width - sw;
  7028. }
  7029. else
  7030. {
  7031. sw += geo.width;
  7032. }
  7033. }
  7034. geo.alternateBounds = new mxRectangle(0, 0, geo.width, geo.height);
  7035. model.setGeometry(cells[i], geo);
  7036. }
  7037. }
  7038. return sw;
  7039. };
  7040. /**
  7041. * Function: execute
  7042. *
  7043. * Implements <mxGraphLayout.execute>.
  7044. */
  7045. TableLayout.prototype.execute = function(parent)
  7046. {
  7047. if (parent != null)
  7048. {
  7049. var offset = this.graph.getActualStartSize(parent, true);
  7050. var table = this.graph.getCellGeometry(parent);
  7051. var style = this.graph.getCellStyle(parent);
  7052. var resizeLastRow = mxUtils.getValue(style,
  7053. 'resizeLastRow', '0') == '1';
  7054. var resizeLast = mxUtils.getValue(style,
  7055. 'resizeLast', '0') == '1';
  7056. var fixedRows = mxUtils.getValue(style,
  7057. 'fixedRows', '0') == '1';
  7058. var model = this.graph.getModel();
  7059. var sw = 0;
  7060. model.beginUpdate();
  7061. try
  7062. {
  7063. var th = table.height - offset.y - offset.height;
  7064. var tw = table.width - offset.x - offset.width;
  7065. var rows = model.getChildCells(parent, true);
  7066. // Updates row visibilities
  7067. for (var i = 0; i < rows.length; i++)
  7068. {
  7069. model.setVisible(rows[i], true);
  7070. }
  7071. var sh = this.getSize(rows, false);
  7072. if (th > 0 && tw > 0 && rows.length > 0 && sh > 0)
  7073. {
  7074. if (resizeLastRow)
  7075. {
  7076. var row = this.graph.getCellGeometry(rows[rows.length - 1]);
  7077. if (row != null)
  7078. {
  7079. row = row.clone();
  7080. row.height = th - sh + row.height;
  7081. model.setGeometry(rows[rows.length - 1], row);
  7082. }
  7083. }
  7084. var pos = (resizeLast) ? null : this.getRowLayout(rows[0], tw);
  7085. var lastCells = [];
  7086. var y = offset.y;
  7087. // Updates row geometries
  7088. for (var i = 0; i < rows.length; i++)
  7089. {
  7090. var row = this.graph.getCellGeometry(rows[i]);
  7091. if (row != null)
  7092. {
  7093. row = row.clone();
  7094. row.x = offset.x;
  7095. row.width = tw;
  7096. row.y = Math.round(y);
  7097. if (resizeLastRow || fixedRows)
  7098. {
  7099. y += row.height;
  7100. }
  7101. else
  7102. {
  7103. y += (row.height / sh) * th;
  7104. }
  7105. row.height = Math.round(y) - row.y;
  7106. model.setGeometry(rows[i], row);
  7107. }
  7108. // Updates cell geometries
  7109. sw = Math.max(sw, this.layoutRow(rows[i], pos, row.height, tw, lastCells));
  7110. }
  7111. if (fixedRows && th < sh)
  7112. {
  7113. table = table.clone();
  7114. table.height = y + offset.height;
  7115. model.setGeometry(parent, table);
  7116. }
  7117. if (resizeLast && tw < sw + Graph.minTableColumnWidth)
  7118. {
  7119. table = table.clone();
  7120. table.width = sw + offset.width + offset.x + Graph.minTableColumnWidth;
  7121. model.setGeometry(parent, table);
  7122. }
  7123. // All geometries cloned at this point so can change in-place below
  7124. this.graph.visitTableCells(parent, mxUtils.bind(this, function(iter)
  7125. {
  7126. model.setVisible(iter.cell, iter.actual.cell == iter.cell);
  7127. if (iter.actual.cell != iter.cell)
  7128. {
  7129. if (iter.actual.row == iter.row)
  7130. {
  7131. var g = (iter.geo.alternateBounds != null) ?
  7132. iter.geo.alternateBounds : iter.geo;
  7133. iter.actual.geo.width += g.width;
  7134. }
  7135. if (iter.actual.col == iter.col)
  7136. {
  7137. var g = (iter.geo.alternateBounds != null) ?
  7138. iter.geo.alternateBounds : iter.geo;
  7139. iter.actual.geo.height += g.height;
  7140. }
  7141. }
  7142. }));
  7143. }
  7144. else
  7145. {
  7146. // Updates row visibilities
  7147. for (var i = 0; i < rows.length; i++)
  7148. {
  7149. model.setVisible(rows[i], false);
  7150. }
  7151. }
  7152. }
  7153. finally
  7154. {
  7155. model.endUpdate();
  7156. }
  7157. }
  7158. };
  7159. (function()
  7160. {
  7161. /**
  7162. * Reset the list of processed edges.
  7163. */
  7164. var mxGraphViewResetValidationState = mxGraphView.prototype.resetValidationState;
  7165. mxGraphView.prototype.resetValidationState = function()
  7166. {
  7167. mxGraphViewResetValidationState.apply(this, arguments);
  7168. this.validEdges = [];
  7169. };
  7170. /**
  7171. * Updates jumps for valid edges and repaints if needed.
  7172. */
  7173. var mxGraphViewValidateCellState = mxGraphView.prototype.validateCellState;
  7174. mxGraphView.prototype.validateCellState = function(cell, recurse)
  7175. {
  7176. recurse = (recurse != null) ? recurse : true;
  7177. var state = this.getState(cell);
  7178. // Forces repaint if jumps change on a valid edge
  7179. if (state != null && recurse && this.graph.model.isEdge(state.cell) &&
  7180. state.style != null && state.style[mxConstants.STYLE_CURVED] != 1 &&
  7181. !state.invalid && this.updateLineJumps(state))
  7182. {
  7183. this.graph.cellRenderer.redraw(state, false, this.isRendering());
  7184. }
  7185. state = mxGraphViewValidateCellState.apply(this, arguments);
  7186. // Adds to the list of edges that may intersect with later edges
  7187. if (state != null && recurse && this.graph.model.isEdge(state.cell) &&
  7188. state.style != null && state.style[mxConstants.STYLE_CURVED] != 1)
  7189. {
  7190. // LATER: Reuse jumps for valid edges
  7191. this.validEdges.push(state);
  7192. }
  7193. return state;
  7194. };
  7195. /**
  7196. * Overrides paint to add flowAnimation style.
  7197. */
  7198. var mxShapePaint = mxShape.prototype.paint;
  7199. mxShape.prototype.isFlowAnimationEnabled = function()
  7200. {
  7201. return this.state != null && this.state.view.graph.enableFlowAnimation &&
  7202. this.state.view.graph.model.isEdge(this.state.cell) &&
  7203. mxUtils.getValue(this.state.style, 'flowAnimation', '0') == '1';
  7204. };
  7205. mxShape.prototype.getFlowAnimationPath = function()
  7206. {
  7207. var paths = (this.node != null) ? this.node.
  7208. getElementsByTagName('path') : null;
  7209. if (paths != null)
  7210. {
  7211. // Returns the first visible path
  7212. for (var i = 0; i < paths.length; i++)
  7213. {
  7214. if (paths[i].getAttribute('visibility') != 'hidden')
  7215. {
  7216. return paths[i];
  7217. }
  7218. }
  7219. }
  7220. return null;
  7221. };
  7222. mxShape.prototype.addFlowAnimationToShape = function()
  7223. {
  7224. if (this.state != null)
  7225. {
  7226. this.state.view.graph.addFlowAnimationToNode(
  7227. this.getFlowAnimationPath(), this.state.style, this.state.view.scale,
  7228. this.state.view.graph.addFlowAnimationStyle());
  7229. }
  7230. };
  7231. mxShape.prototype.paint = function(canvas)
  7232. {
  7233. mxShapePaint.apply(this, arguments);
  7234. if (this.isFlowAnimationEnabled())
  7235. {
  7236. this.addFlowAnimationToShape();
  7237. }
  7238. };
  7239. /**
  7240. * Forces repaint if routed points have changed.
  7241. */
  7242. var mxCellRendererIsShapeInvalid = mxCellRenderer.prototype.isShapeInvalid;
  7243. mxCellRenderer.prototype.isShapeInvalid = function(state, shape)
  7244. {
  7245. return mxCellRendererIsShapeInvalid.apply(this, arguments) ||
  7246. (state.routedPoints != null && shape.routedPoints != null &&
  7247. !mxUtils.equalPoints(shape.routedPoints, state.routedPoints))
  7248. };
  7249. /**
  7250. * Updates jumps for invalid edges.
  7251. */
  7252. var mxGraphViewUpdateCellState = mxGraphView.prototype.updateCellState;
  7253. mxGraphView.prototype.updateCellState = function(state)
  7254. {
  7255. mxGraphViewUpdateCellState.apply(this, arguments);
  7256. // Updates jumps on invalid edge before repaint
  7257. if (this.graph.model.isEdge(state.cell) &&
  7258. state.style[mxConstants.STYLE_CURVED] != 1)
  7259. {
  7260. this.updateLineJumps(state);
  7261. }
  7262. };
  7263. /**
  7264. * Updates the jumps between given state and processed edges.
  7265. */
  7266. mxGraphView.prototype.updateLineJumps = function(state)
  7267. {
  7268. var pts = state.absolutePoints;
  7269. if (Graph.lineJumpsEnabled)
  7270. {
  7271. var changed = state.routedPoints != null;
  7272. var actual = null;
  7273. if (pts != null && this.validEdges != null &&
  7274. mxUtils.getValue(state.style, 'jumpStyle', 'none') !== 'none')
  7275. {
  7276. var thresh = 0.5 * this.scale;
  7277. changed = false;
  7278. actual = [];
  7279. // Type 0 means normal waypoint, 1 means jump
  7280. function addPoint(type, x, y)
  7281. {
  7282. var rpt = new mxPoint(x, y);
  7283. rpt.type = type;
  7284. actual.push(rpt);
  7285. var curr = (state.routedPoints != null) ? state.routedPoints[actual.length - 1] : null;
  7286. return curr == null || curr.type != type || curr.x != x || curr.y != y;
  7287. };
  7288. for (var i = 0; i < pts.length - 1; i++)
  7289. {
  7290. var p1 = pts[i + 1];
  7291. var p0 = pts[i];
  7292. var list = [];
  7293. // Ignores waypoints on straight segments
  7294. var pn = pts[i + 2];
  7295. while (i < pts.length - 2 &&
  7296. mxUtils.ptSegDistSq(p0.x, p0.y, pn.x, pn.y,
  7297. p1.x, p1.y) < 1 * this.scale * this.scale)
  7298. {
  7299. p1 = pn;
  7300. i++;
  7301. pn = pts[i + 2];
  7302. }
  7303. changed = addPoint(0, p0.x, p0.y) || changed;
  7304. // Processes all previous edges
  7305. for (var e = 0; e < this.validEdges.length; e++)
  7306. {
  7307. var state2 = this.validEdges[e];
  7308. var pts2 = state2.absolutePoints;
  7309. if (pts2 != null && mxUtils.intersects(state, state2) && state2.style['noJump'] != '1')
  7310. {
  7311. var pl = null;
  7312. // Compares each segment of the edge with the current segment
  7313. for (var j = 0; j < pts2.length - 1; j++)
  7314. {
  7315. var p3 = pts2[j + 1];
  7316. var p2 = pts2[j];
  7317. // Ignores waypoints on straight segments
  7318. pn = pts2[j + 2];
  7319. while (j < pts2.length - 2 &&
  7320. mxUtils.ptSegDistSq(p2.x, p2.y, pn.x, pn.y,
  7321. p3.x, p3.y) < 1 * this.scale * this.scale)
  7322. {
  7323. p3 = pn;
  7324. j++;
  7325. pn = pts2[j + 2];
  7326. }
  7327. var pt = mxUtils.intersection(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
  7328. // Handles intersection between two segments
  7329. if (pt != null && (Math.abs(pt.x - p0.x) > thresh ||
  7330. Math.abs(pt.y - p0.y) > thresh) &&
  7331. (Math.abs(pt.x - p1.x) > thresh ||
  7332. Math.abs(pt.y - p1.y) > thresh) &&
  7333. // Removes jumps on overlapping incoming segments
  7334. (pl == null || mxUtils.ptLineDist(p0.x, p0.y, p1.x, p1.y, pl.x, pl.y) > thresh ||
  7335. mxUtils.ptLineDist(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y) > thresh) &&
  7336. // Removes jumps on overlapping outgoing segments
  7337. (pn == null || mxUtils.ptLineDist(p0.x, p0.y, p1.x, p1.y, pn.x, pn.y) > thresh ||
  7338. mxUtils.ptLineDist(p0.x, p0.y, p1.x, p1.y, p3.x, p3.y) > thresh))
  7339. {
  7340. var dx = pt.x - p0.x;
  7341. var dy = pt.y - p0.y;
  7342. var temp = {distSq: dx * dx + dy * dy, x: pt.x, y: pt.y};
  7343. // Intersections must be ordered by distance from start of segment
  7344. for (var t = 0; t < list.length; t++)
  7345. {
  7346. if (list[t].distSq > temp.distSq)
  7347. {
  7348. list.splice(t, 0, temp);
  7349. temp = null;
  7350. break;
  7351. }
  7352. }
  7353. // Ignores multiple intersections at segment joint
  7354. if (temp != null && (list.length == 0 ||
  7355. list[list.length - 1].x !== temp.x ||
  7356. list[list.length - 1].y !== temp.y))
  7357. {
  7358. list.push(temp);
  7359. }
  7360. }
  7361. pl = p2;
  7362. }
  7363. }
  7364. }
  7365. // Adds ordered intersections to routed points
  7366. for (var j = 0; j < list.length; j++)
  7367. {
  7368. changed = addPoint(1, list[j].x, list[j].y) || changed;
  7369. }
  7370. }
  7371. var pt = pts[pts.length - 1];
  7372. changed = addPoint(0, pt.x, pt.y) || changed;
  7373. }
  7374. state.routedPoints = actual;
  7375. return changed;
  7376. }
  7377. else
  7378. {
  7379. return false;
  7380. }
  7381. };
  7382. /**
  7383. * Overrides painting the actual shape for taking into account jump style.
  7384. */
  7385. var mxConnectorPaintLine = mxConnector.prototype.paintLine;
  7386. mxConnector.prototype.paintLine = function (c, absPts, rounded)
  7387. {
  7388. // Required for checking dirty state
  7389. this.routedPoints = (this.state != null) ? this.state.routedPoints : null;
  7390. if (this.outline || this.state == null || this.style == null ||
  7391. this.state.routedPoints == null || this.state.routedPoints.length == 0)
  7392. {
  7393. mxConnectorPaintLine.apply(this, arguments);
  7394. }
  7395. else
  7396. {
  7397. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  7398. mxConstants.LINE_ARCSIZE) / 2;
  7399. var size = (parseInt(mxUtils.getValue(this.style, 'jumpSize',
  7400. Graph.defaultJumpSize)) - 2) / 2 + this.strokewidth;
  7401. var style = mxUtils.getValue(this.style, 'jumpStyle', 'none');
  7402. var moveTo = true;
  7403. var last = null;
  7404. var len = null;
  7405. var pts = [];
  7406. var n = null;
  7407. c.begin();
  7408. for (var i = 0; i < this.state.routedPoints.length; i++)
  7409. {
  7410. var rpt = this.state.routedPoints[i];
  7411. var pt = new mxPoint(rpt.x / this.scale, rpt.y / this.scale);
  7412. // Takes first and last point from passed-in array
  7413. if (i == 0)
  7414. {
  7415. pt = absPts[0];
  7416. }
  7417. else if (i == this.state.routedPoints.length - 1)
  7418. {
  7419. pt = absPts[absPts.length - 1];
  7420. }
  7421. var done = false;
  7422. // Type 1 is an intersection
  7423. if (last != null && rpt.type == 1)
  7424. {
  7425. // Checks if next/previous points are too close
  7426. var next = this.state.routedPoints[i + 1];
  7427. var dx = next.x / this.scale - pt.x;
  7428. var dy = next.y / this.scale - pt.y;
  7429. var dist = dx * dx + dy * dy;
  7430. if (n == null)
  7431. {
  7432. n = new mxPoint(pt.x - last.x, pt.y - last.y);
  7433. len = Math.sqrt(n.x * n.x + n.y * n.y);
  7434. if (len > 0)
  7435. {
  7436. n.x = n.x * size / len;
  7437. n.y = n.y * size / len;
  7438. }
  7439. else
  7440. {
  7441. n = null;
  7442. }
  7443. }
  7444. if (dist > size * size && len > 0)
  7445. {
  7446. var dx = last.x - pt.x;
  7447. var dy = last.y - pt.y;
  7448. var dist = dx * dx + dy * dy;
  7449. if (dist > size * size)
  7450. {
  7451. var p0 = new mxPoint(pt.x - n.x, pt.y - n.y);
  7452. var p1 = new mxPoint(pt.x + n.x, pt.y + n.y);
  7453. pts.push(p0);
  7454. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  7455. var f = (Math.round(n.x) < 0 || (Math.round(n.x) == 0
  7456. && Math.round(n.y) <= 0)) ? 1 : -1;
  7457. moveTo = false;
  7458. if (style == 'sharp')
  7459. {
  7460. c.lineTo(p0.x - n.y * f, p0.y + n.x * f);
  7461. c.lineTo(p1.x - n.y * f, p1.y + n.x * f);
  7462. c.lineTo(p1.x, p1.y);
  7463. }
  7464. else if (style == 'line')
  7465. {
  7466. c.moveTo(p0.x + n.y * f, p0.y - n.x * f);
  7467. c.lineTo(p0.x - n.y * f, p0.y + n.x * f);
  7468. c.moveTo(p1.x - n.y * f, p1.y + n.x * f);
  7469. c.lineTo(p1.x + n.y * f, p1.y - n.x * f);
  7470. c.moveTo(p1.x, p1.y);
  7471. }
  7472. else if (style == 'arc')
  7473. {
  7474. f *= 1.3;
  7475. c.curveTo(p0.x - n.y * f, p0.y + n.x * f,
  7476. p1.x - n.y * f, p1.y + n.x * f,
  7477. p1.x, p1.y);
  7478. }
  7479. else
  7480. {
  7481. c.moveTo(p1.x, p1.y);
  7482. moveTo = true;
  7483. }
  7484. pts = [p1];
  7485. done = true;
  7486. }
  7487. }
  7488. }
  7489. else
  7490. {
  7491. n = null;
  7492. }
  7493. if (!done)
  7494. {
  7495. pts.push(pt);
  7496. last = pt;
  7497. }
  7498. }
  7499. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  7500. c.stroke();
  7501. }
  7502. };
  7503. /**
  7504. * Adds support for centerPerimeter which is a special case of a fixed point perimeter.
  7505. */
  7506. var mxGraphViewGetFixedTerminalPoint = mxGraphView.prototype.getFixedTerminalPoint;
  7507. mxGraphView.prototype.getFixedTerminalPoint = function(edge, terminal, source, constraint)
  7508. {
  7509. if (terminal != null && terminal.style[mxConstants.STYLE_PERIMETER] == 'centerPerimeter')
  7510. {
  7511. return new mxPoint(terminal.getCenterX(), terminal.getCenterY());
  7512. }
  7513. else
  7514. {
  7515. return mxGraphViewGetFixedTerminalPoint.apply(this, arguments);
  7516. }
  7517. };
  7518. /**
  7519. * Adds support for snapToPoint style.
  7520. */
  7521. var mxGraphViewUpdateFloatingTerminalPoint = mxGraphView.prototype.updateFloatingTerminalPoint;
  7522. mxGraphView.prototype.updateFloatingTerminalPoint = function(edge, start, end, source)
  7523. {
  7524. if (start != null && edge != null &&
  7525. (start.style['snapToPoint'] == '1' ||
  7526. edge.style['snapToPoint'] == '1'))
  7527. {
  7528. start = this.getTerminalPort(edge, start, source);
  7529. var next = this.getNextPoint(edge, end, source);
  7530. var orth = this.graph.isOrthogonal(edge);
  7531. var alpha = mxUtils.toRadians(Number(start.style[mxConstants.STYLE_ROTATION] || '0'));
  7532. var center = new mxPoint(start.getCenterX(), start.getCenterY());
  7533. if (alpha != 0)
  7534. {
  7535. var cos = Math.cos(-alpha);
  7536. var sin = Math.sin(-alpha);
  7537. next = mxUtils.getRotatedPoint(next, cos, sin, center);
  7538. }
  7539. var border = parseFloat(edge.style[mxConstants.STYLE_PERIMETER_SPACING] || 0);
  7540. border += parseFloat(edge.style[(source) ?
  7541. mxConstants.STYLE_SOURCE_PERIMETER_SPACING :
  7542. mxConstants.STYLE_TARGET_PERIMETER_SPACING] || 0);
  7543. var pt = this.getPerimeterPoint(start, next, alpha == 0 && orth, border);
  7544. if (alpha != 0)
  7545. {
  7546. var cos = Math.cos(alpha);
  7547. var sin = Math.sin(alpha);
  7548. pt = mxUtils.getRotatedPoint(pt, cos, sin, center);
  7549. }
  7550. edge.setAbsoluteTerminalPoint(this.snapToAnchorPoint(edge, start, end, source, pt), source);
  7551. }
  7552. else
  7553. {
  7554. mxGraphViewUpdateFloatingTerminalPoint.apply(this, arguments);
  7555. }
  7556. };
  7557. mxGraphView.prototype.snapToAnchorPoint = function(edge, start, end, source, pt)
  7558. {
  7559. if (start != null && edge != null)
  7560. {
  7561. var constraints = this.graph.getAllConnectionConstraints(start)
  7562. var nearest = null;
  7563. var dist = null;
  7564. if (constraints != null)
  7565. {
  7566. for (var i = 0; i < constraints.length; i++)
  7567. {
  7568. var cp = this.graph.getConnectionPoint(start, constraints[i]);
  7569. if (cp != null)
  7570. {
  7571. var tmp = (cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
  7572. if (dist == null || tmp < dist)
  7573. {
  7574. nearest = cp;
  7575. dist = tmp;
  7576. }
  7577. }
  7578. }
  7579. }
  7580. if (nearest != null)
  7581. {
  7582. pt = nearest;
  7583. }
  7584. }
  7585. return pt;
  7586. };
  7587. /**
  7588. * Adds support for placeholders in text elements of shapes.
  7589. */
  7590. var mxStencilEvaluateTextAttribute = mxStencil.prototype.evaluateTextAttribute;
  7591. mxStencil.prototype.evaluateTextAttribute = function(node, attribute, shape)
  7592. {
  7593. var result = mxStencilEvaluateTextAttribute.apply(this, arguments);
  7594. var placeholders = node.getAttribute('placeholders');
  7595. if (placeholders == '1' && shape.state != null)
  7596. {
  7597. result = shape.state.view.graph.replacePlaceholders(shape.state.cell, result);
  7598. }
  7599. return result;
  7600. };
  7601. /**
  7602. * Adds custom stencils defined via shape=stencil(value) style. The value is a base64 encoded, compressed and
  7603. * URL encoded XML definition of the shape according to the stencil definition language of mxGraph.
  7604. *
  7605. * Needs to be in this file to make sure its part of the embed client code. Also the check for ZLib is
  7606. * different than for the Editor code.
  7607. */
  7608. var mxCellRendererCreateShape = mxCellRenderer.prototype.createShape;
  7609. mxCellRenderer.prototype.createShape = function(state)
  7610. {
  7611. if (state.style != null && typeof(pako) !== 'undefined')
  7612. {
  7613. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  7614. // Extracts and decodes stencil XML if shape has the form shape=stencil(value)
  7615. if (shape != null && typeof shape === 'string' && shape.substring(0, 8) == 'stencil(')
  7616. {
  7617. try
  7618. {
  7619. var stencil = shape.substring(8, shape.length - 1);
  7620. var doc = mxUtils.parseXml(Graph.decompress(stencil));
  7621. return new mxShape(new mxStencil(doc.documentElement));
  7622. }
  7623. catch (e)
  7624. {
  7625. if (window.console != null)
  7626. {
  7627. console.log('Error in shape: ' + e);
  7628. }
  7629. }
  7630. }
  7631. }
  7632. return mxCellRendererCreateShape.apply(this, arguments);
  7633. };
  7634. })();
  7635. /**
  7636. * Overrides stencil registry for dynamic loading of stencils.
  7637. */
  7638. /**
  7639. * Maps from library names to an array of Javascript filenames,
  7640. * which are synchronously loaded. Currently only stencil files
  7641. * (.xml) and JS files (.js) are supported.
  7642. * IMPORTANT: For embedded diagrams to work entries must also
  7643. * be added in EmbedServlet.java.
  7644. */
  7645. mxStencilRegistry.libraries = {};
  7646. /**
  7647. * Global switch to disable dynamic loading.
  7648. */
  7649. mxStencilRegistry.dynamicLoading = true;
  7650. /**
  7651. * Global switch to disable eval for JS (preload all JS instead).
  7652. */
  7653. mxStencilRegistry.allowEval = true;
  7654. /**
  7655. * Stores all package names that have been dynamically loaded.
  7656. * Each package is only loaded once.
  7657. */
  7658. mxStencilRegistry.packages = [];
  7659. /**
  7660. * Stores all package names that have been dynamically loaded.
  7661. * Each package is only loaded once.
  7662. */
  7663. mxStencilRegistry.filesLoaded = {};
  7664. /**
  7665. * Returns true if the given file has been loaded.
  7666. */
  7667. mxStencilRegistry.isFileLoaded = function(name)
  7668. {
  7669. // Workaround for asynchronous loading of stencils in Firefox
  7670. // even if the XML request was marked as being synchronous
  7671. return !mxClient.IS_FF && mxStencilRegistry.filesLoaded[name];
  7672. };
  7673. /**
  7674. * Marks the given file as loaded.
  7675. */
  7676. mxStencilRegistry.setFileLoaded = function(name)
  7677. {
  7678. mxStencilRegistry.filesLoaded[name] = true;
  7679. };
  7680. // Extends the default stencil registry to add dynamic loading
  7681. mxStencilRegistry.getStencil = function(name)
  7682. {
  7683. var result = mxStencilRegistry.stencils[name];
  7684. if (result == null && mxCellRenderer.defaultShapes[name] == null && mxStencilRegistry.dynamicLoading)
  7685. {
  7686. var basename = mxStencilRegistry.getBasenameForStencil(name);
  7687. // Loads stencil files and tries again
  7688. if (basename != null)
  7689. {
  7690. var libs = mxStencilRegistry.libraries[basename];
  7691. if (libs != null)
  7692. {
  7693. if (mxStencilRegistry.packages[basename] == null)
  7694. {
  7695. for (var i = 0; i < libs.length; i++)
  7696. {
  7697. var fname = libs[i];
  7698. if (!mxStencilRegistry.isFileLoaded(fname))
  7699. {
  7700. mxStencilRegistry.setFileLoaded(fname);
  7701. if (fname.toLowerCase().substring(fname.length - 4, fname.length) == '.xml')
  7702. {
  7703. mxStencilRegistry.loadStencilSet(fname, null);
  7704. }
  7705. else if (fname.toLowerCase().substring(fname.length - 3, fname.length) == '.js')
  7706. {
  7707. try
  7708. {
  7709. if (mxStencilRegistry.allowEval)
  7710. {
  7711. var req = mxUtils.load(fname);
  7712. if (req != null && req.getStatus() >= 200 && req.getStatus() <= 299)
  7713. {
  7714. eval.call(window, req.getText());
  7715. }
  7716. }
  7717. }
  7718. catch (e)
  7719. {
  7720. if (window.console != null)
  7721. {
  7722. console.log('error in getStencil:', name, basename, libs, fname, e);
  7723. }
  7724. }
  7725. }
  7726. else
  7727. {
  7728. // FIXME: This does not yet work as the loading is triggered after
  7729. // the shape was used in the graph, at which point the keys have
  7730. // typically been translated in the calling method.
  7731. //mxResources.add(fname);
  7732. }
  7733. }
  7734. }
  7735. mxStencilRegistry.packages[basename] = 1;
  7736. }
  7737. }
  7738. else
  7739. {
  7740. // Replaces '_-_' with '_'
  7741. basename = basename.replace('_-_', '_');
  7742. mxStencilRegistry.loadStencilSet(STENCIL_PATH + '/' + basename + '.xml', null);
  7743. }
  7744. result = mxStencilRegistry.stencils[name];
  7745. }
  7746. }
  7747. return result;
  7748. };
  7749. // Returns the basename for the given stencil or null if no file must be
  7750. // loaded to render the given stencil.
  7751. mxStencilRegistry.getBasenameForStencil = function(name)
  7752. {
  7753. var tmp = null;
  7754. if (name != null && typeof name === 'string')
  7755. {
  7756. var parts = name.split('.');
  7757. if (parts.length > 0 && parts[0] == 'mxgraph')
  7758. {
  7759. tmp = parts[1];
  7760. for (var i = 2; i < parts.length - 1; i++)
  7761. {
  7762. tmp += '/' + parts[i];
  7763. }
  7764. }
  7765. }
  7766. return tmp;
  7767. };
  7768. // Loads the given stencil set
  7769. mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force, async)
  7770. {
  7771. force = (force != null) ? force : false;
  7772. // Uses additional cache for detecting previous load attempts
  7773. var xmlDoc = mxStencilRegistry.packages[stencilFile];
  7774. if (force || xmlDoc == null)
  7775. {
  7776. var install = false;
  7777. if (xmlDoc == null)
  7778. {
  7779. try
  7780. {
  7781. if (async)
  7782. {
  7783. mxStencilRegistry.loadStencil(stencilFile, mxUtils.bind(this, function(xmlDoc2)
  7784. {
  7785. if (xmlDoc2 != null && xmlDoc2.documentElement != null)
  7786. {
  7787. mxStencilRegistry.packages[stencilFile] = xmlDoc2;
  7788. install = true;
  7789. mxStencilRegistry.parseStencilSet(xmlDoc2.documentElement, postStencilLoad, install);
  7790. }
  7791. }));
  7792. return;
  7793. }
  7794. else
  7795. {
  7796. xmlDoc = mxStencilRegistry.loadStencil(stencilFile);
  7797. mxStencilRegistry.packages[stencilFile] = xmlDoc;
  7798. install = true;
  7799. }
  7800. }
  7801. catch (e)
  7802. {
  7803. if (window.console != null)
  7804. {
  7805. console.log('error in loadStencilSet:', stencilFile, e);
  7806. }
  7807. }
  7808. }
  7809. if (xmlDoc != null && xmlDoc.documentElement != null)
  7810. {
  7811. mxStencilRegistry.parseStencilSet(xmlDoc.documentElement, postStencilLoad, install);
  7812. }
  7813. }
  7814. };
  7815. // Loads the given stencil XML file.
  7816. mxStencilRegistry.loadStencil = function(filename, fn)
  7817. {
  7818. if (fn != null)
  7819. {
  7820. var req = mxUtils.get(filename, mxUtils.bind(this, function(req)
  7821. {
  7822. fn((req.getStatus() >= 200 && req.getStatus() <= 299) ? req.getXml() : null);
  7823. }), mxUtils.bind(this, function(req)
  7824. {
  7825. fn(null);
  7826. }));
  7827. }
  7828. else
  7829. {
  7830. return mxUtils.load(filename).getXml();
  7831. }
  7832. };
  7833. // Takes array of strings
  7834. mxStencilRegistry.parseStencilSets = function(stencils)
  7835. {
  7836. for (var i = 0; i < stencils.length; i++)
  7837. {
  7838. mxStencilRegistry.parseStencilSet(mxUtils.parseXml(stencils[i]).documentElement);
  7839. }
  7840. };
  7841. // Parses the given stencil set
  7842. mxStencilRegistry.parseStencilSet = function(root, postStencilLoad, install)
  7843. {
  7844. if (root.nodeName == 'stencils')
  7845. {
  7846. var shapes = root.firstChild;
  7847. while (shapes != null)
  7848. {
  7849. if (shapes.nodeName == 'shapes')
  7850. {
  7851. mxStencilRegistry.parseStencilSet(shapes, postStencilLoad, install);
  7852. }
  7853. shapes = shapes.nextSibling;
  7854. }
  7855. }
  7856. else
  7857. {
  7858. install = (install != null) ? install : true;
  7859. var shape = root.firstChild;
  7860. var packageName = '';
  7861. var name = root.getAttribute('name');
  7862. if (name != null)
  7863. {
  7864. packageName = name + '.';
  7865. }
  7866. while (shape != null)
  7867. {
  7868. if (shape.nodeType == mxConstants.NODETYPE_ELEMENT)
  7869. {
  7870. name = shape.getAttribute('name');
  7871. if (name != null)
  7872. {
  7873. packageName = packageName.toLowerCase();
  7874. var stencilName = name.replace(/ /g,"_");
  7875. if (install)
  7876. {
  7877. mxStencilRegistry.addStencil(packageName + stencilName.toLowerCase(), new mxStencil(shape));
  7878. }
  7879. if (postStencilLoad != null)
  7880. {
  7881. var w = shape.getAttribute('w');
  7882. var h = shape.getAttribute('h');
  7883. w = (w == null) ? 80 : parseInt(w, 10);
  7884. h = (h == null) ? 80 : parseInt(h, 10);
  7885. postStencilLoad(packageName, stencilName, name, w, h);
  7886. }
  7887. }
  7888. }
  7889. shape = shape.nextSibling;
  7890. }
  7891. }
  7892. };
  7893. /**
  7894. * These overrides are only added if mxVertexHandler is defined (ie. not in embedded graph)
  7895. */
  7896. if (typeof mxVertexHandler !== 'undefined')
  7897. {
  7898. (function()
  7899. {
  7900. // Sets colors for handles
  7901. mxConstants.HANDLE_FILLCOLOR = '#29b6f2';
  7902. mxConstants.HANDLE_STROKECOLOR = '#0088cf';
  7903. mxConstants.VERTEX_SELECTION_COLOR = '#00a8ff';
  7904. mxConstants.OUTLINE_COLOR = '#00a8ff';
  7905. mxConstants.OUTLINE_HANDLE_FILLCOLOR = '#99ccff';
  7906. mxConstants.OUTLINE_HANDLE_STROKECOLOR = '#00a8ff';
  7907. mxConstants.CONNECT_HANDLE_FILLCOLOR = '#cee7ff';
  7908. mxConstants.EDGE_SELECTION_COLOR = '#00a8ff';
  7909. mxConstants.DEFAULT_VALID_COLOR = '#00a8ff';
  7910. mxConstants.LABEL_HANDLE_FILLCOLOR = '#cee7ff';
  7911. mxConstants.GUIDE_COLOR = '#0088cf';
  7912. mxConstants.HIGHLIGHT_STROKEWIDTH = 5;
  7913. mxConstants.HIGHLIGHT_OPACITY = 50;
  7914. mxConstants.HIGHLIGHT_SIZE = 5;
  7915. // Sets window decoration icons
  7916. mxWindow.prototype.closeImage = Graph.createSvgImage(18, 10,
  7917. '<path d="M 5 1 L 13 9 M 13 1 L 5 9" stroke="#707070" stroke-width="2"/>').src;
  7918. mxWindow.prototype.minimizeImage = Graph.createSvgImage(14, 10,
  7919. '<path d="M 3 7 L 7 3 L 11 7" stroke="#707070" stroke-width="2" fill="none"/>').src;
  7920. mxWindow.prototype.normalizeImage = Graph.createSvgImage(14, 10,
  7921. '<path d="M 3 3 L 7 7 L 11 3" stroke="#707070" stroke-width="2" fill="none"/>').src;
  7922. mxWindow.prototype.resizeImage = Graph.createSvgImage(10, 10,
  7923. '<path d="Z" stroke="#C0C0C0" stroke-width="1" fill="none"/>').src;
  7924. // Enables snapping to off-grid terminals for edge waypoints
  7925. mxEdgeHandler.prototype.snapToTerminals = true;
  7926. // Enables guides
  7927. mxGraphHandler.prototype.guidesEnabled = true;
  7928. // Removes parents where all child cells are moved out
  7929. mxGraphHandler.prototype.removeEmptyParents = true;
  7930. // Enables fading of rubberband
  7931. mxRubberband.prototype.fadeOut = true;
  7932. // Alt-move disables guides
  7933. mxGuide.prototype.isEnabledForEvent = function(evt)
  7934. {
  7935. return !mxEvent.isAltDown(evt) || mxEvent.isShiftDown(evt);
  7936. };
  7937. // Ignores all table cells in layouts
  7938. var graphLayoutIsVertexIgnored = mxGraphLayout.prototype.isVertexIgnored;
  7939. mxGraphLayout.prototype.isVertexIgnored = function(vertex)
  7940. {
  7941. return graphLayoutIsVertexIgnored.apply(this, arguments) ||
  7942. this.graph.isTableRow(vertex) || this.graph.isTableCell(vertex);
  7943. };
  7944. // Adds support for ignoreEdge style
  7945. var graphLayoutIsEdgeIgnored = mxGraphLayout.prototype.isEdgeIgnored;
  7946. mxGraphLayout.prototype.isEdgeIgnored = function(edge)
  7947. {
  7948. return graphLayoutIsEdgeIgnored.apply(this, arguments) ||
  7949. this.graph.isEdgeIgnored(edge);
  7950. };
  7951. // Extends connection handler to enable ctrl+drag for cloning source cell
  7952. // since copyOnConnect is now disabled by default
  7953. var mxConnectionHandlerCreateTarget = mxConnectionHandler.prototype.isCreateTarget;
  7954. mxConnectionHandler.prototype.isCreateTarget = function(evt)
  7955. {
  7956. return this.graph.isCloneEvent(evt) != mxConnectionHandlerCreateTarget.apply(this, arguments);
  7957. };
  7958. // Overrides highlight shape for connection points
  7959. mxConstraintHandler.prototype.createHighlightShape = function()
  7960. {
  7961. var hl = new mxEllipse(null, this.highlightColor, this.highlightColor, 0);
  7962. hl.opacity = mxConstants.HIGHLIGHT_OPACITY;
  7963. return hl;
  7964. };
  7965. // Overrides edge preview to use current edge shape and default style
  7966. mxConnectionHandler.prototype.livePreview = true;
  7967. mxConnectionHandler.prototype.cursor = 'crosshair';
  7968. // Uses current edge style for connect preview
  7969. mxConnectionHandler.prototype.createEdgeState = function(me)
  7970. {
  7971. var style = this.graph.createCurrentEdgeStyle();
  7972. var edge = this.graph.createEdge(null, null, null, null, null, style);
  7973. var state = new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  7974. for (var key in this.graph.currentEdgeStyle)
  7975. {
  7976. state.style[key] = this.graph.currentEdgeStyle[key];
  7977. }
  7978. // Applies newEdgeStyle for preview
  7979. if (this.previous != null)
  7980. {
  7981. var temp = this.previous.style['newEdgeStyle'];
  7982. if (temp != null)
  7983. {
  7984. try
  7985. {
  7986. var styles = JSON.parse(temp);
  7987. for (var key in styles)
  7988. {
  7989. state.style[key] = styles[key];
  7990. }
  7991. }
  7992. catch (e)
  7993. {
  7994. // ignore
  7995. }
  7996. }
  7997. }
  7998. state.style = this.graph.postProcessCellStyle(state.cell, state.style);
  7999. return state;
  8000. };
  8001. // Overrides dashed state with current edge style
  8002. var connectionHandlerCreateShape = mxConnectionHandler.prototype.createShape;
  8003. mxConnectionHandler.prototype.createShape = function()
  8004. {
  8005. var shape = connectionHandlerCreateShape.apply(this, arguments);
  8006. shape.isDashed = this.graph.currentEdgeStyle[mxConstants.STYLE_DASHED] == '1';
  8007. return shape;
  8008. }
  8009. // Overrides live preview to keep current style
  8010. mxConnectionHandler.prototype.updatePreview = function(valid)
  8011. {
  8012. // do not change color of preview
  8013. };
  8014. // Overrides connection handler to ignore edges instead of not allowing connections
  8015. var mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
  8016. mxConnectionHandler.prototype.createMarker = function()
  8017. {
  8018. var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);
  8019. var markerGetCell = marker.getCell;
  8020. marker.getCell = mxUtils.bind(this, function(me)
  8021. {
  8022. var result = markerGetCell.apply(this, arguments);
  8023. this.error = null;
  8024. return result;
  8025. });
  8026. return marker;
  8027. };
  8028. /**
  8029. *
  8030. */
  8031. Graph.prototype.defaultVertexStyle = {};
  8032. /**
  8033. * Contains the default style for edges.
  8034. */
  8035. Graph.prototype.defaultEdgeStyle = {'edgeStyle': 'orthogonalEdgeStyle', 'rounded': '0',
  8036. 'jettySize': 'auto', 'orthogonalLoop': '1'};
  8037. /**
  8038. * Returns the current edge style as a string.
  8039. */
  8040. Graph.prototype.createCurrentEdgeStyle = function()
  8041. {
  8042. var style = 'edgeStyle=' + (this.currentEdgeStyle['edgeStyle'] || 'none') + ';';
  8043. var keys = ['shape', 'curved', 'rounded', 'comic', 'sketch', 'fillWeight', 'hachureGap',
  8044. 'hachureAngle', 'jiggle', 'disableMultiStroke', 'disableMultiStrokeFill', 'fillStyle',
  8045. 'curveFitting', 'simplification', 'comicStyle', 'jumpStyle', 'jumpSize'];
  8046. for (var i = 0; i < keys.length; i++)
  8047. {
  8048. if (this.currentEdgeStyle[keys[i]] != null)
  8049. {
  8050. style += keys[i] + '=' + this.currentEdgeStyle[keys[i]] + ';';
  8051. }
  8052. }
  8053. // Overrides the global default to match the default edge style
  8054. if (this.currentEdgeStyle['orthogonalLoop'] != null)
  8055. {
  8056. style += 'orthogonalLoop=' + this.currentEdgeStyle['orthogonalLoop'] + ';';
  8057. }
  8058. else if (Graph.prototype.defaultEdgeStyle['orthogonalLoop'] != null)
  8059. {
  8060. style += 'orthogonalLoop=' + Graph.prototype.defaultEdgeStyle['orthogonalLoop'] + ';';
  8061. }
  8062. // Overrides the global default to match the default edge style
  8063. if (this.currentEdgeStyle['jettySize'] != null)
  8064. {
  8065. style += 'jettySize=' + this.currentEdgeStyle['jettySize'] + ';';
  8066. }
  8067. else if (Graph.prototype.defaultEdgeStyle['jettySize'] != null)
  8068. {
  8069. style += 'jettySize=' + Graph.prototype.defaultEdgeStyle['jettySize'] + ';';
  8070. }
  8071. // Special logic for custom property of elbowEdgeStyle
  8072. if (this.currentEdgeStyle['edgeStyle'] == 'elbowEdgeStyle' && this.currentEdgeStyle['elbow'] != null)
  8073. {
  8074. style += 'elbow=' + this.currentEdgeStyle['elbow'] + ';';
  8075. }
  8076. if (this.currentEdgeStyle['html'] != null)
  8077. {
  8078. style += 'html=' + this.currentEdgeStyle['html'] + ';';
  8079. }
  8080. else
  8081. {
  8082. style += 'html=1;';
  8083. }
  8084. return style;
  8085. };
  8086. /**
  8087. * Hook for subclassers.
  8088. */
  8089. Graph.prototype.getPagePadding = function()
  8090. {
  8091. return new mxPoint(0, 0);
  8092. };
  8093. /**
  8094. * Loads the stylesheet for this graph.
  8095. */
  8096. Graph.prototype.loadStylesheet = function()
  8097. {
  8098. var node = (this.themes != null) ? this.themes[this.defaultThemeName] :
  8099. (!mxStyleRegistry.dynamicLoading) ? null :
  8100. mxUtils.load(STYLE_PATH + '/default.xml').getDocumentElement();
  8101. if (node != null)
  8102. {
  8103. var dec = new mxCodec(node.ownerDocument);
  8104. dec.decode(node, this.getStylesheet());
  8105. }
  8106. };
  8107. /**
  8108. * Creates lookup from object IDs to cell IDs.
  8109. */
  8110. Graph.prototype.createCellLookup = function(cells, lookup)
  8111. {
  8112. lookup = (lookup != null) ? lookup : new Object();
  8113. for (var i = 0; i < cells.length; i++)
  8114. {
  8115. var cell = cells[i];
  8116. lookup[mxObjectIdentity.get(cell)] = cell.getId();
  8117. var childCount = this.model.getChildCount(cell);
  8118. for (var j = 0; j < childCount; j++)
  8119. {
  8120. this.createCellLookup([this.model.getChildAt(cell, j)], lookup);
  8121. }
  8122. }
  8123. return lookup;
  8124. };
  8125. /**
  8126. * Creates lookup from original to cloned cell IDs where mapping is
  8127. * the mapping used in cloneCells and lookup is a mapping from
  8128. * object IDs to cell IDs.
  8129. */
  8130. Graph.prototype.createCellMapping = function(mapping, lookup, cellMapping)
  8131. {
  8132. cellMapping = (cellMapping != null) ? cellMapping : new Object();
  8133. for (var objectId in mapping)
  8134. {
  8135. var cellId = lookup[objectId];
  8136. if (cellMapping[cellId] == null)
  8137. {
  8138. // Uses empty string if clone ID was null which means
  8139. // the cell was cloned but not inserted into the model.
  8140. cellMapping[cellId] = mapping[objectId].getId() || '';
  8141. }
  8142. }
  8143. return cellMapping;
  8144. };
  8145. /**
  8146. *
  8147. */
  8148. Graph.prototype.importGraphModel = function(node, dx, dy, crop)
  8149. {
  8150. dx = (dx != null) ? dx : 0;
  8151. dy = (dy != null) ? dy : 0;
  8152. var codec = new mxCodec(node.ownerDocument);
  8153. var tempModel = new mxGraphModel();
  8154. codec.decode(node, tempModel);
  8155. var cells = []
  8156. // Clones cells to remove invalid edges
  8157. var cloneMap = new Object();
  8158. var cellMapping = new Object();
  8159. var layers = tempModel.getChildren(this.cloneCell(tempModel.root,
  8160. this.isCloneInvalidEdges(), cloneMap));
  8161. if (layers != null)
  8162. {
  8163. // Creates lookup from object IDs to cell IDs
  8164. var lookup = this.createCellLookup([tempModel.root]);
  8165. // Uses copy as layers are removed from array inside loop
  8166. layers = layers.slice();
  8167. this.model.beginUpdate();
  8168. try
  8169. {
  8170. // Merges into unlocked current layer if one layer is pasted
  8171. if (layers.length == 1 && !this.isCellLocked(this.getDefaultParent()))
  8172. {
  8173. var children = tempModel.getChildren(layers[0]);
  8174. if (children != null)
  8175. {
  8176. cells = this.moveCells(children,
  8177. dx, dy, false, this.getDefaultParent());
  8178. // Imported default parent maps to local default parent
  8179. cellMapping[tempModel.getChildAt(tempModel.root, 0).getId()] =
  8180. this.getDefaultParent().getId();
  8181. }
  8182. }
  8183. else
  8184. {
  8185. for (var i = 0; i < layers.length; i++)
  8186. {
  8187. var children = this.model.getChildren(this.moveCells(
  8188. [layers[i]], dx, dy, false, this.model.getRoot())[0]);
  8189. if (children != null)
  8190. {
  8191. cells = cells.concat(children);
  8192. }
  8193. }
  8194. }
  8195. if (cells != null)
  8196. {
  8197. // Adds mapping for all cloned entries from imported to local cell ID
  8198. this.createCellMapping(cloneMap, lookup, cellMapping);
  8199. this.updateCustomLinks(cellMapping, cells);
  8200. if (crop)
  8201. {
  8202. if (this.isGridEnabled())
  8203. {
  8204. dx = this.snap(dx);
  8205. dy = this.snap(dy);
  8206. }
  8207. var bounds = this.getBoundingBoxFromGeometry(cells, true);
  8208. if (bounds != null)
  8209. {
  8210. this.moveCells(cells, dx - bounds.x, dy - bounds.y);
  8211. }
  8212. }
  8213. }
  8214. }
  8215. finally
  8216. {
  8217. this.model.endUpdate();
  8218. }
  8219. }
  8220. return cells;
  8221. };
  8222. /**
  8223. * Translates this point by the given vector.
  8224. *
  8225. * @param {number} dx X-coordinate of the translation.
  8226. * @param {number} dy Y-coordinate of the translation.
  8227. */
  8228. Graph.prototype.encodeCells = function(cells)
  8229. {
  8230. var cloneMap = new Object();
  8231. var clones = this.cloneCells(cells, null, cloneMap);
  8232. // Creates a dictionary for fast lookups
  8233. var dict = new mxDictionary();
  8234. for (var i = 0; i < cells.length; i++)
  8235. {
  8236. dict.put(cells[i], true);
  8237. }
  8238. var codec = new mxCodec();
  8239. var model = new mxGraphModel();
  8240. var parent = model.getChildAt(model.getRoot(), 0);
  8241. for (var i = 0; i < clones.length; i++)
  8242. {
  8243. model.add(parent, clones[i]);
  8244. // Checks for orphaned relative children and makes absolute
  8245. var state = this.view.getState(cells[i]);
  8246. if (state != null)
  8247. {
  8248. var geo = this.getCellGeometry(clones[i]);
  8249. if (geo != null && geo.relative && !this.model.isEdge(cells[i]) &&
  8250. dict.get(this.model.getParent(cells[i])) == null)
  8251. {
  8252. geo.offset = null;
  8253. geo.relative = false;
  8254. geo.x = state.x / state.view.scale - state.view.translate.x;
  8255. geo.y = state.y / state.view.scale - state.view.translate.y;
  8256. }
  8257. }
  8258. }
  8259. this.updateCustomLinks(this.createCellMapping(cloneMap,
  8260. this.createCellLookup(cells)), clones);
  8261. return codec.encode(model);
  8262. };
  8263. /**
  8264. * Overridden to use table cell instead of table as parent.
  8265. */
  8266. Graph.prototype.isSwimlane = function(cell, ignoreState)
  8267. {
  8268. var shape = null;
  8269. if (cell != null && !this.model.isEdge(cell) &&
  8270. this.model.getParent(cell) !=
  8271. this.model.getRoot())
  8272. {
  8273. var style = this.getCurrentCellStyle(cell, ignoreState)
  8274. shape = style[mxConstants.STYLE_SHAPE];
  8275. }
  8276. return shape == mxConstants.SHAPE_SWIMLANE ||
  8277. shape == 'table' || shape == 'tableRow';
  8278. };
  8279. /**
  8280. * Overridden to check table cells and rows.
  8281. */
  8282. var graphIsCellEditable = Graph.prototype.isCellEditable;
  8283. Graph.prototype.isCellEditable = function(cell)
  8284. {
  8285. if (cell == null || !graphIsCellEditable.apply(this, arguments))
  8286. {
  8287. return false;
  8288. }
  8289. else if (this.isTableCell(cell) || this.isTableRow(cell))
  8290. {
  8291. return this.isCellEditable(this.model.getParent(cell));
  8292. }
  8293. else
  8294. {
  8295. return true;
  8296. }
  8297. };
  8298. /**
  8299. * Overridden to check table cells and rows.
  8300. */
  8301. var graphIsCellMovable = Graph.prototype.isCellMovable;
  8302. Graph.prototype.isCellMovable = function(cell)
  8303. {
  8304. if (cell == null || !graphIsCellMovable.apply(this, arguments))
  8305. {
  8306. return false;
  8307. }
  8308. else if (this.isTableCell(cell) || this.isTableRow(cell))
  8309. {
  8310. return this.isCellMovable(this.model.getParent(cell));
  8311. }
  8312. else
  8313. {
  8314. return true;
  8315. }
  8316. };
  8317. /**
  8318. * Overridden to add expand style.
  8319. */
  8320. var graphIsExtendParent = Graph.prototype.isExtendParent;
  8321. Graph.prototype.isExtendParent = function(cell)
  8322. {
  8323. var parent = this.model.getParent(cell);
  8324. if (parent != null)
  8325. {
  8326. var style = this.getCurrentCellStyle(parent);
  8327. if (style['expand'] != null)
  8328. {
  8329. return style['expand'] != '0';
  8330. }
  8331. }
  8332. return graphIsExtendParent.apply(this, arguments) &&
  8333. (parent == null || !this.isTable(parent));
  8334. };
  8335. /**
  8336. * Overridden to use table cell instead of table as parent.
  8337. */
  8338. var graphSplitEdge = Graph.prototype.splitEdge;
  8339. Graph.prototype.splitEdge = function(edge, cells, newEdge, dx, dy, x, y, parent)
  8340. {
  8341. if (parent == null)
  8342. {
  8343. parent = this.model.getParent(edge);
  8344. if (this.isTable(parent) || this.isTableRow(parent))
  8345. {
  8346. parent = this.getCellAt(x, y, null, true, false);
  8347. }
  8348. }
  8349. var newEdge = null;
  8350. this.model.beginUpdate();
  8351. try
  8352. {
  8353. var newEdge = graphSplitEdge.apply(this, [edge, cells, newEdge, dx, dy, x, y, parent]);
  8354. // Removes cloned value on first segment
  8355. this.model.setValue(newEdge, '');
  8356. // Removes child labels on first or second segment depending on coordinate
  8357. // LATER: Split and reposition labels based on x and y
  8358. var sourceLabels = this.getChildCells(newEdge, true);
  8359. for (var i = 0; i < sourceLabels.length; i++)
  8360. {
  8361. var geo = this.getCellGeometry(sourceLabels[i]);
  8362. if (geo != null && geo.relative && geo.x > 0)
  8363. {
  8364. this.model.remove(sourceLabels[i]);
  8365. }
  8366. }
  8367. var targetLabels = this.getChildCells(edge, true);
  8368. for (var i = 0; i < targetLabels.length; i++)
  8369. {
  8370. var geo = this.getCellGeometry(targetLabels[i]);
  8371. if (geo != null && geo.relative && geo.x <= 0)
  8372. {
  8373. this.model.remove(targetLabels[i]);
  8374. }
  8375. }
  8376. // Removes entryX/Y and exitX/Y if snapToPoint is used
  8377. var target = this.model.getTerminal(newEdge, false);
  8378. if (target != null)
  8379. {
  8380. var style = this.getCurrentCellStyle(target);
  8381. if (style != null && style['snapToPoint'] == '1')
  8382. {
  8383. this.setCellStyles(mxConstants.STYLE_EXIT_X, null, [edge]);
  8384. this.setCellStyles(mxConstants.STYLE_EXIT_Y, null, [edge]);
  8385. this.setCellStyles(mxConstants.STYLE_ENTRY_X, null, [newEdge]);
  8386. this.setCellStyles(mxConstants.STYLE_ENTRY_Y, null, [newEdge]);
  8387. }
  8388. }
  8389. }
  8390. finally
  8391. {
  8392. this.model.endUpdate();
  8393. }
  8394. return newEdge;
  8395. };
  8396. /**
  8397. * Overridden to flatten cell hierarchy for selecting next and previous.
  8398. */
  8399. var graphSelectCell = Graph.prototype.selectCell;
  8400. Graph.prototype.selectCell = function(isNext, isParent, isChild)
  8401. {
  8402. if (isParent || isChild)
  8403. {
  8404. graphSelectCell.apply(this, arguments);
  8405. }
  8406. else
  8407. {
  8408. var cell = this.getSelectionCell();
  8409. var index = null;
  8410. var cells = [];
  8411. // LATER: Reverse traverse order for !isNext
  8412. var flatten = mxUtils.bind(this, function(temp)
  8413. {
  8414. if (this.view.getState(temp) != null &&
  8415. (this.model.isVertex(temp) ||
  8416. this.model.isEdge(temp)))
  8417. {
  8418. cells.push(temp);
  8419. if (temp == cell)
  8420. {
  8421. index = cells.length - 1;
  8422. }
  8423. else if ((isNext && cell == null && cells.length > 0) ||
  8424. (index != null && ((isNext && cells.length > index)) ||
  8425. (!isNext && index > 0)))
  8426. {
  8427. return;
  8428. }
  8429. }
  8430. for (var i = 0; i < this.model.getChildCount(temp); i++)
  8431. {
  8432. flatten(this.model.getChildAt(temp, i));
  8433. }
  8434. });
  8435. flatten(this.model.root);
  8436. if (cells.length > 0)
  8437. {
  8438. if (index != null)
  8439. {
  8440. index = mxUtils.mod(index + ((isNext) ? 1 : -1), cells.length)
  8441. }
  8442. else
  8443. {
  8444. index = 0;
  8445. }
  8446. this.setSelectionCell(cells[index]);
  8447. }
  8448. }
  8449. };
  8450. /**
  8451. * Swaps the given shapes.
  8452. */
  8453. Graph.prototype.swapShapes = function(source, target)
  8454. {
  8455. if (this.model.isVertex(source) && this.model.isVertex(target) &&
  8456. this.getMovableCells([source, target]).length == 2)
  8457. {
  8458. var geo1 = this.getCellGeometry(source);
  8459. var geo2 = this.getCellGeometry(target);
  8460. if (geo1 != null && geo2 != null)
  8461. {
  8462. var g1 = geo1.clone();
  8463. var g2 = geo2.clone();
  8464. this.model.beginUpdate();
  8465. try
  8466. {
  8467. g1.x = geo2.getCenterX() - geo1.width / 2;
  8468. g1.y = geo2.getCenterY() - geo1.height / 2;
  8469. g2.x = geo1.getCenterX() - geo2.width / 2;
  8470. g2.y = geo1.getCenterY() - geo2.height / 2;
  8471. this.model.setGeometry(source, g1);
  8472. this.model.setGeometry(target, g2);
  8473. }
  8474. finally
  8475. {
  8476. this.model.endUpdate();
  8477. }
  8478. }
  8479. }
  8480. };
  8481. /**
  8482. * Overrides cloning cells in moveCells.
  8483. */
  8484. var graphMoveCells = Graph.prototype.moveCells;
  8485. Graph.prototype.moveCells = function(cells, dx, dy, clone, target, evt, mapping)
  8486. {
  8487. mapping = (mapping != null) ? mapping : new Object();
  8488. // Replaces source tables with rows
  8489. if (this.isTable(target))
  8490. {
  8491. var newCells = [];
  8492. for (var i = 0; i < cells.length; i++)
  8493. {
  8494. if (this.isTable(cells[i]))
  8495. {
  8496. newCells = newCells.concat(this.model.getChildCells(cells[i], true).reverse());
  8497. }
  8498. else
  8499. {
  8500. newCells.push(cells[i]);
  8501. }
  8502. }
  8503. cells = newCells;
  8504. }
  8505. this.model.beginUpdate();
  8506. try
  8507. {
  8508. // Updates source and target table heights and matches
  8509. // column count for moving rows between tables
  8510. var sourceTables = [];
  8511. for (var i = 0; i < cells.length; i++)
  8512. {
  8513. if (target != null && this.isTableRow(cells[i]))
  8514. {
  8515. var parent = this.model.getParent(cells[i]);
  8516. var row = this.getCellGeometry(cells[i]);
  8517. if (this.isTable(parent))
  8518. {
  8519. sourceTables.push(parent);
  8520. }
  8521. if (parent != null && row != null &&
  8522. this.isTable(parent) &&
  8523. this.isTable(target) &&
  8524. (clone || parent != target))
  8525. {
  8526. if (!clone)
  8527. {
  8528. var table = this.getCellGeometry(parent);
  8529. if (table != null)
  8530. {
  8531. table = table.clone();
  8532. table.height -= row.height;
  8533. this.model.setGeometry(parent, table);
  8534. }
  8535. }
  8536. var table = this.getCellGeometry(target);
  8537. if (table != null)
  8538. {
  8539. table = table.clone();
  8540. table.height += row.height;
  8541. this.model.setGeometry(target, table);
  8542. }
  8543. // Matches column count
  8544. var rows = this.model.getChildCells(target, true);
  8545. if (rows.length > 0)
  8546. {
  8547. cells[i] = (clone) ? this.cloneCell(cells[i]) : cells[i];
  8548. var sourceCols = this.model.getChildCells(cells[i], true);
  8549. var cols = this.model.getChildCells(rows[0], true);
  8550. var count = cols.length - sourceCols.length;
  8551. if (count > 0)
  8552. {
  8553. for (var j = 0; j < count; j++)
  8554. {
  8555. var col = this.cloneCell(sourceCols[sourceCols.length - 1]);
  8556. if (col != null)
  8557. {
  8558. col.value = '';
  8559. this.model.add(cells[i], col);
  8560. }
  8561. }
  8562. }
  8563. else if (count < 0)
  8564. {
  8565. for (var j = 0; j > count; j--)
  8566. {
  8567. this.model.remove(sourceCols[sourceCols.length + j - 1]);
  8568. }
  8569. }
  8570. // Updates column widths
  8571. sourceCols = this.model.getChildCells(cells[i], true);
  8572. for (var j = 0; j < cols.length; j++)
  8573. {
  8574. var geo = this.getCellGeometry(cols[j]);
  8575. var geo2 = this.getCellGeometry(sourceCols[j]);
  8576. if (geo != null && geo2 != null)
  8577. {
  8578. geo2 = geo2.clone();
  8579. geo2.width = geo.width;
  8580. this.model.setGeometry(sourceCols[j], geo2);
  8581. }
  8582. }
  8583. }
  8584. }
  8585. }
  8586. }
  8587. var result = graphMoveCells.apply(this, arguments);
  8588. // Removes empty tables
  8589. for (var i = 0; i < sourceTables.length; i++)
  8590. {
  8591. if (!clone && this.model.contains(sourceTables[i]) &&
  8592. this.model.getChildCount(sourceTables[i]) == 0)
  8593. {
  8594. this.model.remove(sourceTables[i]);
  8595. }
  8596. }
  8597. if (clone)
  8598. {
  8599. this.updateCustomLinks(this.createCellMapping(mapping,
  8600. this.createCellLookup(cells)), result);
  8601. }
  8602. }
  8603. finally
  8604. {
  8605. this.model.endUpdate();
  8606. }
  8607. return result;
  8608. };
  8609. /**
  8610. * Overriddes to delete label for table cells.
  8611. */
  8612. var graphRemoveCells = Graph.prototype.removeCells;
  8613. Graph.prototype.removeCells = function(cells, includeEdges)
  8614. {
  8615. var result = [];
  8616. this.model.beginUpdate();
  8617. try
  8618. {
  8619. // Clears labels on table cells
  8620. for (var i = 0; i < cells.length; i++)
  8621. {
  8622. if (this.isTableCell(cells[i]))
  8623. {
  8624. var row = this.model.getParent(cells[i]);
  8625. var table = this.model.getParent(row);
  8626. // Removes table if one cell in one row left
  8627. if (this.model.getChildCount(row) == 1 &&
  8628. this.model.getChildCount(table) == 1)
  8629. {
  8630. if (mxUtils.indexOf(cells, table) < 0 &&
  8631. mxUtils.indexOf(result, table) < 0)
  8632. {
  8633. result.push(table);
  8634. }
  8635. }
  8636. else
  8637. {
  8638. this.labelChanged(cells[i], '');
  8639. }
  8640. }
  8641. else
  8642. {
  8643. // Deletes table if all rows are removed
  8644. if (this.isTableRow(cells[i]))
  8645. {
  8646. var table = this.model.getParent(cells[i]);
  8647. if (mxUtils.indexOf(cells, table) < 0 &&
  8648. mxUtils.indexOf(result, table) < 0)
  8649. {
  8650. var rows = this.model.getChildCells(table, true);
  8651. var deleteCount = 0;
  8652. for (var j = 0; j < rows.length; j++)
  8653. {
  8654. if (mxUtils.indexOf(cells, rows[j]) >= 0)
  8655. {
  8656. deleteCount++;
  8657. }
  8658. }
  8659. if (deleteCount == rows.length)
  8660. {
  8661. result.push(table);
  8662. }
  8663. }
  8664. }
  8665. result.push(cells[i]);
  8666. }
  8667. }
  8668. result = graphRemoveCells.apply(this, [result, includeEdges]);
  8669. }
  8670. finally
  8671. {
  8672. this.model.endUpdate();
  8673. }
  8674. return result;
  8675. };
  8676. /**
  8677. * Updates cells IDs for custom links in the given cells using an
  8678. * optional graph to avoid changing the undo history.
  8679. */
  8680. Graph.prototype.updateCustomLinks = function(mapping, cells, graph)
  8681. {
  8682. graph = (graph != null) ? graph : new Graph();
  8683. for (var i = 0; i < cells.length; i++)
  8684. {
  8685. if (cells[i] != null)
  8686. {
  8687. graph.updateCustomLinksForCell(mapping, cells[i], graph);
  8688. }
  8689. }
  8690. };
  8691. /**
  8692. * Updates cell IDs in custom links on the given cell and its label.
  8693. */
  8694. Graph.prototype.updateCustomLinksForCell = function(mapping, cell)
  8695. {
  8696. this.doUpdateCustomLinksForCell(mapping, cell);
  8697. var childCount = this.model.getChildCount(cell);
  8698. for (var i = 0; i < childCount; i++)
  8699. {
  8700. this.updateCustomLinksForCell(mapping,
  8701. this.model.getChildAt(cell, i));
  8702. }
  8703. };
  8704. /**
  8705. * Updates cell IDs in custom links on the given cell and its label.
  8706. */
  8707. Graph.prototype.doUpdateCustomLinksForCell = function(mapping, cell)
  8708. {
  8709. // Hook for subclassers
  8710. };
  8711. /**
  8712. * Overrides method to provide connection constraints for shapes.
  8713. */
  8714. Graph.prototype.getAllConnectionConstraints = function(terminal, source)
  8715. {
  8716. if (terminal != null)
  8717. {
  8718. var constraints = mxUtils.getValue(terminal.style, 'points', null);
  8719. if (constraints != null)
  8720. {
  8721. // Requires an array of arrays with x, y (0..1), an optional
  8722. // [perimeter (0 or 1), dx, and dy] eg. points=[[0,0,1,-10,10],[0,1,0],[1,1]]
  8723. var result = [];
  8724. try
  8725. {
  8726. var c = JSON.parse(constraints);
  8727. for (var i = 0; i < c.length; i++)
  8728. {
  8729. var tmp = c[i];
  8730. result.push(new mxConnectionConstraint(new mxPoint(tmp[0], tmp[1]), (tmp.length > 2) ? tmp[2] != '0' : true,
  8731. null, (tmp.length > 3) ? tmp[3] : 0, (tmp.length > 4) ? tmp[4] : 0));
  8732. }
  8733. }
  8734. catch (e)
  8735. {
  8736. // ignore
  8737. }
  8738. return result;
  8739. }
  8740. else if (terminal.shape != null && terminal.shape.bounds != null)
  8741. {
  8742. var dir = terminal.shape.direction;
  8743. var bounds = terminal.shape.bounds;
  8744. var scale = terminal.shape.scale;
  8745. var w = bounds.width / scale;
  8746. var h = bounds.height / scale;
  8747. if (dir == mxConstants.DIRECTION_NORTH || dir == mxConstants.DIRECTION_SOUTH)
  8748. {
  8749. var tmp = w;
  8750. w = h;
  8751. h = tmp;
  8752. }
  8753. constraints = terminal.shape.getConstraints(terminal.style, w, h);
  8754. if (constraints != null)
  8755. {
  8756. return constraints;
  8757. }
  8758. else if (terminal.shape.stencil != null && terminal.shape.stencil.constraints != null)
  8759. {
  8760. return terminal.shape.stencil.constraints;
  8761. }
  8762. else if (terminal.shape.constraints != null)
  8763. {
  8764. return terminal.shape.constraints;
  8765. }
  8766. }
  8767. }
  8768. return null;
  8769. };
  8770. /**
  8771. * Inverts the elbow edge style without removing existing styles.
  8772. */
  8773. Graph.prototype.flipEdge = function(edge)
  8774. {
  8775. if (edge != null)
  8776. {
  8777. var style = this.getCurrentCellStyle(edge);
  8778. var elbow = mxUtils.getValue(style, mxConstants.STYLE_ELBOW,
  8779. mxConstants.ELBOW_HORIZONTAL);
  8780. var value = (elbow == mxConstants.ELBOW_HORIZONTAL) ?
  8781. mxConstants.ELBOW_VERTICAL : mxConstants.ELBOW_HORIZONTAL;
  8782. this.setCellStyles(mxConstants.STYLE_ELBOW, value, [edge]);
  8783. }
  8784. };
  8785. /**
  8786. * Disables drill-down for non-swimlanes.
  8787. */
  8788. Graph.prototype.isValidRoot = function(cell)
  8789. {
  8790. // Counts non-relative children
  8791. var childCount = this.model.getChildCount(cell);
  8792. var realChildCount = 0;
  8793. for (var i = 0; i < childCount; i++)
  8794. {
  8795. var child = this.model.getChildAt(cell, i);
  8796. if (this.model.isVertex(child))
  8797. {
  8798. var geometry = this.getCellGeometry(child);
  8799. if (geometry != null && !geometry.relative)
  8800. {
  8801. realChildCount++;
  8802. }
  8803. }
  8804. }
  8805. return realChildCount > 0 || this.isContainer(cell);
  8806. };
  8807. /**
  8808. * Disables drill-down for non-swimlanes.
  8809. */
  8810. Graph.prototype.isValidDropTarget = function(cell, cells, evt)
  8811. {
  8812. var style = this.getCurrentCellStyle(cell);
  8813. var tables = true;
  8814. var rows = true;
  8815. for (var i = 0; i < cells.length && rows; i++)
  8816. {
  8817. tables = tables && this.isTable(cells[i]);
  8818. rows = rows && this.isTableRow(cells[i]);
  8819. }
  8820. return !this.isCellLocked(cell) && (this.isTargetShape(cell, cells, evt) ||
  8821. ((mxUtils.getValue(style, 'part', '0') != '1' || this.isContainer(cell)) &&
  8822. mxUtils.getValue(style, 'dropTarget', '1') != '0' && (mxGraph.prototype.
  8823. isValidDropTarget.apply(this, arguments) || this.isContainer(cell)) &&
  8824. !this.isTableRow(cell) && (!this.isTable(cell) || rows || tables)));
  8825. };
  8826. /**
  8827. * Overrides createGroupCell to set the group style for new groups to 'group'.
  8828. */
  8829. Graph.prototype.createGroupCell = function()
  8830. {
  8831. var group = mxGraph.prototype.createGroupCell.apply(this, arguments);
  8832. group.setStyle('group');
  8833. return group;
  8834. };
  8835. /**
  8836. * Disables extending parents with stack layouts on add
  8837. */
  8838. Graph.prototype.isExtendParentsOnAdd = function(cell)
  8839. {
  8840. var result = mxGraph.prototype.isExtendParentsOnAdd.apply(this, arguments);
  8841. if (result && cell != null && this.layoutManager != null)
  8842. {
  8843. var parent = this.model.getParent(cell);
  8844. if (parent != null)
  8845. {
  8846. var layout = this.layoutManager.getLayout(parent);
  8847. if (layout != null && layout.constructor == mxStackLayout)
  8848. {
  8849. result = false;
  8850. }
  8851. }
  8852. }
  8853. return result;
  8854. };
  8855. /**
  8856. * Overrides autosize to add a border.
  8857. */
  8858. Graph.prototype.getPreferredSizeForCell = function(cell, w, gridEnabled)
  8859. {
  8860. gridEnabled = (gridEnabled != null) ? gridEnabled : this.gridEnabled;
  8861. var result = mxGraph.prototype.getPreferredSizeForCell.apply(this, arguments);
  8862. // Adds buffer
  8863. if (result != null)
  8864. {
  8865. result.width += 10;
  8866. result.height += 4;
  8867. if (gridEnabled)
  8868. {
  8869. result.width = this.snap(result.width);
  8870. result.height = this.snap(result.height);
  8871. }
  8872. }
  8873. return result;
  8874. }
  8875. /**
  8876. * Turns the given cells and returns the changed cells.
  8877. */
  8878. Graph.prototype.turnShapes = function(cells, backwards)
  8879. {
  8880. var model = this.getModel();
  8881. var select = [];
  8882. model.beginUpdate();
  8883. try
  8884. {
  8885. for (var i = 0; i < cells.length; i++)
  8886. {
  8887. var cell = cells[i];
  8888. if (model.isEdge(cell))
  8889. {
  8890. var src = model.getTerminal(cell, true);
  8891. var trg = model.getTerminal(cell, false);
  8892. model.setTerminal(cell, trg, true);
  8893. model.setTerminal(cell, src, false);
  8894. var geo = model.getGeometry(cell);
  8895. if (geo != null)
  8896. {
  8897. geo = geo.clone();
  8898. if (geo.points != null)
  8899. {
  8900. geo.points.reverse();
  8901. }
  8902. var sp = geo.getTerminalPoint(true);
  8903. var tp = geo.getTerminalPoint(false)
  8904. geo.setTerminalPoint(sp, false);
  8905. geo.setTerminalPoint(tp, true);
  8906. model.setGeometry(cell, geo);
  8907. // Inverts constraints
  8908. var edgeState = this.view.getState(cell);
  8909. var sourceState = this.view.getState(src);
  8910. var targetState = this.view.getState(trg);
  8911. if (edgeState != null)
  8912. {
  8913. var sc = (sourceState != null) ? this.getConnectionConstraint(edgeState, sourceState, true) : null;
  8914. var tc = (targetState != null) ? this.getConnectionConstraint(edgeState, targetState, false) : null;
  8915. this.setConnectionConstraint(cell, src, true, tc);
  8916. this.setConnectionConstraint(cell, trg, false, sc);
  8917. // Inverts perimeter spacings
  8918. var temp = mxUtils.getValue(edgeState.style, mxConstants.STYLE_SOURCE_PERIMETER_SPACING);
  8919. this.setCellStyles(mxConstants.STYLE_SOURCE_PERIMETER_SPACING, mxUtils.getValue(
  8920. edgeState.style, mxConstants.STYLE_TARGET_PERIMETER_SPACING), [cell]);
  8921. this.setCellStyles(mxConstants.STYLE_TARGET_PERIMETER_SPACING, temp, [cell]);
  8922. }
  8923. select.push(cell);
  8924. }
  8925. }
  8926. else if (model.isVertex(cell))
  8927. {
  8928. var geo = this.getCellGeometry(cell);
  8929. if (geo != null)
  8930. {
  8931. // Rotates the size and position in the geometry
  8932. if (!this.isTable(cell) && !this.isTableRow(cell) &&
  8933. !this.isTableCell(cell) && !this.isSwimlane(cell))
  8934. {
  8935. geo = geo.clone();
  8936. geo.x += geo.width / 2 - geo.height / 2;
  8937. geo.y += geo.height / 2 - geo.width / 2;
  8938. var tmp = geo.width;
  8939. geo.width = geo.height;
  8940. geo.height = tmp;
  8941. model.setGeometry(cell, geo);
  8942. }
  8943. // Reads the current direction and advances by 90 degrees
  8944. var state = this.view.getState(cell);
  8945. if (state != null)
  8946. {
  8947. var dirs = [mxConstants.DIRECTION_EAST, mxConstants.DIRECTION_SOUTH,
  8948. mxConstants.DIRECTION_WEST, mxConstants.DIRECTION_NORTH];
  8949. var dir = mxUtils.getValue(state.style, mxConstants.STYLE_DIRECTION,
  8950. mxConstants.DIRECTION_EAST);
  8951. this.setCellStyles(mxConstants.STYLE_DIRECTION,
  8952. dirs[mxUtils.mod(mxUtils.indexOf(dirs, dir) +
  8953. ((backwards) ? -1 : 1), dirs.length)], [cell]);
  8954. }
  8955. select.push(cell);
  8956. }
  8957. }
  8958. }
  8959. }
  8960. finally
  8961. {
  8962. model.endUpdate();
  8963. }
  8964. return select;
  8965. };
  8966. /**
  8967. * Returns true if the given stencil contains any placeholder text.
  8968. */
  8969. Graph.prototype.stencilHasPlaceholders = function(stencil)
  8970. {
  8971. if (stencil != null && stencil.fgNode != null)
  8972. {
  8973. var node = stencil.fgNode.firstChild;
  8974. while (node != null)
  8975. {
  8976. if (node.nodeName == 'text' && node.getAttribute('placeholders') == '1')
  8977. {
  8978. return true;
  8979. }
  8980. node = node.nextSibling;
  8981. }
  8982. }
  8983. return false;
  8984. };
  8985. /**
  8986. * Updates the child cells with placeholders if metadata of a
  8987. * cell has changed and propagates geometry changes in tables.
  8988. */
  8989. var graphProcessChange = Graph.prototype.processChange;
  8990. Graph.prototype.processChange = function(change)
  8991. {
  8992. if (change instanceof mxGeometryChange &&
  8993. (this.isTableCell(change.cell) || this.isTableRow(change.cell)) &&
  8994. ((change.previous == null && change.geometry != null) ||
  8995. (change.previous != null && !change.previous.equals(change.geometry))))
  8996. {
  8997. var cell = change.cell;
  8998. if (this.isTableCell(cell))
  8999. {
  9000. cell = this.model.getParent(cell);
  9001. }
  9002. if (this.isTableRow(cell))
  9003. {
  9004. cell = this.model.getParent(cell);
  9005. }
  9006. // Forces repaint of table with unchanged style and geometry
  9007. var state = this.view.getState(cell);
  9008. if (state != null && state.shape != null)
  9009. {
  9010. this.view.invalidate(cell);
  9011. state.shape.bounds = null;
  9012. }
  9013. }
  9014. graphProcessChange.apply(this, arguments);
  9015. if (change instanceof mxValueChange && change.cell != null &&
  9016. change.cell.value != null && typeof(change.cell.value) == 'object')
  9017. {
  9018. this.invalidateDescendantsWithPlaceholders(change.cell);
  9019. }
  9020. };
  9021. /**
  9022. * Replaces the given element with a span.
  9023. */
  9024. Graph.prototype.invalidateDescendantsWithPlaceholders = function(cell)
  9025. {
  9026. // Invalidates all descendants with placeholders
  9027. var desc = this.model.getDescendants(cell);
  9028. // LATER: Check if only label or tooltip have changed
  9029. if (desc.length > 0)
  9030. {
  9031. for (var i = 0; i < desc.length; i++)
  9032. {
  9033. var state = this.view.getState(desc[i]);
  9034. if (state != null && state.shape != null && state.shape.stencil != null &&
  9035. this.stencilHasPlaceholders(state.shape.stencil))
  9036. {
  9037. this.removeStateForCell(desc[i]);
  9038. }
  9039. else if (this.isReplacePlaceholders(desc[i]))
  9040. {
  9041. this.view.invalidate(desc[i], false, false);
  9042. }
  9043. }
  9044. }
  9045. };
  9046. /**
  9047. * Replaces the given element with a span.
  9048. */
  9049. Graph.prototype.replaceElement = function(elt, tagName)
  9050. {
  9051. var span = elt.ownerDocument.createElement((tagName != null) ? tagName : 'span');
  9052. var attributes = Array.prototype.slice.call(elt.attributes);
  9053. while (attr = attributes.pop())
  9054. {
  9055. span.setAttribute(attr.nodeName, attr.nodeValue);
  9056. }
  9057. span.innerHTML = elt.innerHTML;
  9058. elt.parentNode.replaceChild(span, elt);
  9059. };
  9060. /**
  9061. *
  9062. */
  9063. Graph.prototype.processElements = function(elt, fn)
  9064. {
  9065. if (elt != null)
  9066. {
  9067. var elts = elt.getElementsByTagName('*');
  9068. for (var i = 0; i < elts.length; i++)
  9069. {
  9070. if (elts[i] != null)
  9071. {
  9072. fn(elts[i]);
  9073. }
  9074. }
  9075. }
  9076. };
  9077. /**
  9078. * Handles label changes for XML user objects.
  9079. */
  9080. Graph.prototype.updateLabelElements = function(cells, fn, tagName)
  9081. {
  9082. cells = (cells != null) ? cells : this.getSelectionCells();
  9083. var div = document.createElement('div');
  9084. for (var i = 0; i < cells.length; i++)
  9085. {
  9086. // Changes font tags inside HTML labels
  9087. var style = this.getCurrentCellStyle(cells[i]);
  9088. if (style != null && style['html'] == '1')
  9089. {
  9090. var label = this.convertValueToString(cells[i]);
  9091. if (label != null && label.length > 0)
  9092. {
  9093. div.innerHTML = Graph.sanitizeHtml(label);
  9094. var elts = div.getElementsByTagName((tagName != null) ? tagName : '*');
  9095. for (var j = 0; j < elts.length; j++)
  9096. {
  9097. fn(elts[j]);
  9098. }
  9099. if (div.innerHTML != label)
  9100. {
  9101. this.cellLabelChanged(cells[i], div.innerHTML);
  9102. }
  9103. }
  9104. }
  9105. }
  9106. };
  9107. /**
  9108. * Handles label changes for XML user objects.
  9109. */
  9110. Graph.prototype.cellLabelChanged = function(cell, value, autoSize)
  9111. {
  9112. // Removes all illegal control characters in user input
  9113. value = Graph.zapGremlins(value);
  9114. this.model.beginUpdate();
  9115. try
  9116. {
  9117. if (cell.value != null && typeof cell.value == 'object')
  9118. {
  9119. if (this.isReplacePlaceholders(cell) &&
  9120. cell.getAttribute('placeholder') != null)
  9121. {
  9122. // LATER: Handle delete, name change
  9123. var name = cell.getAttribute('placeholder');
  9124. var current = cell;
  9125. while (current != null)
  9126. {
  9127. if (current == this.model.getRoot() || (current.value != null &&
  9128. typeof(current.value) == 'object' && current.hasAttribute(name)))
  9129. {
  9130. this.setAttributeForCell(current, name, value);
  9131. break;
  9132. }
  9133. current = this.model.getParent(current);
  9134. }
  9135. }
  9136. var tmp = cell.value.cloneNode(true);
  9137. if (Graph.translateDiagram && Graph.diagramLanguage != null &&
  9138. tmp.hasAttribute('label_' + Graph.diagramLanguage))
  9139. {
  9140. tmp.setAttribute('label_' + Graph.diagramLanguage, value);
  9141. }
  9142. else
  9143. {
  9144. tmp.setAttribute('label', value);
  9145. }
  9146. value = tmp;
  9147. }
  9148. mxGraph.prototype.cellLabelChanged.apply(this, arguments);
  9149. }
  9150. finally
  9151. {
  9152. this.model.endUpdate();
  9153. }
  9154. };
  9155. /**
  9156. * Removes transparent empty groups if all children are removed.
  9157. */
  9158. Graph.prototype.cellsRemoved = function(cells)
  9159. {
  9160. if (cells != null)
  9161. {
  9162. var dict = new mxDictionary();
  9163. for (var i = 0; i < cells.length; i++)
  9164. {
  9165. dict.put(cells[i], true);
  9166. }
  9167. // LATER: Recurse up the cell hierarchy
  9168. var parents = [];
  9169. for (var i = 0; i < cells.length; i++)
  9170. {
  9171. var parent = this.model.getParent(cells[i]);
  9172. if (parent != null && !dict.get(parent))
  9173. {
  9174. dict.put(parent, true);
  9175. parents.push(parent);
  9176. }
  9177. }
  9178. for (var i = 0; i < parents.length; i++)
  9179. {
  9180. var state = this.view.getState(parents[i]);
  9181. if (state != null && (this.model.isEdge(state.cell) ||
  9182. this.model.isVertex(state.cell)) &&
  9183. this.isCellDeletable(state.cell) &&
  9184. this.isTransparentState(state))
  9185. {
  9186. var allChildren = true;
  9187. for (var j = 0; j < this.model.getChildCount(state.cell) && allChildren; j++)
  9188. {
  9189. if (!dict.get(this.model.getChildAt(state.cell, j)))
  9190. {
  9191. allChildren = false;
  9192. }
  9193. }
  9194. if (allChildren)
  9195. {
  9196. cells.push(state.cell);
  9197. }
  9198. }
  9199. }
  9200. }
  9201. mxGraph.prototype.cellsRemoved.apply(this, arguments);
  9202. };
  9203. /**
  9204. * Overrides ungroup to check if group should be removed.
  9205. */
  9206. Graph.prototype.removeCellsAfterUngroup = function(cells)
  9207. {
  9208. var cellsToRemove = [];
  9209. for (var i = 0; i < cells.length; i++)
  9210. {
  9211. if (this.isCellDeletable(cells[i]) &&
  9212. this.isTransparentState(
  9213. this.view.getState(cells[i])))
  9214. {
  9215. cellsToRemove.push(cells[i]);
  9216. }
  9217. }
  9218. cells = cellsToRemove;
  9219. mxGraph.prototype.removeCellsAfterUngroup.apply(this, arguments);
  9220. };
  9221. /**
  9222. * Sets the link for the given cell.
  9223. */
  9224. Graph.prototype.setLinkForCell = function(cell, link)
  9225. {
  9226. this.setAttributeForCell(cell, 'link', link);
  9227. };
  9228. /**
  9229. * Sets the link for the given cell.
  9230. */
  9231. Graph.prototype.setTooltipForCell = function(cell, link)
  9232. {
  9233. var key = 'tooltip';
  9234. if (Graph.translateDiagram && Graph.diagramLanguage != null &&
  9235. mxUtils.isNode(cell.value) && cell.value.hasAttribute('tooltip_' + Graph.diagramLanguage))
  9236. {
  9237. key = 'tooltip_' + Graph.diagramLanguage;
  9238. }
  9239. this.setAttributeForCell(cell, key, link);
  9240. };
  9241. /**
  9242. * Returns the cells in the model (or given array) that have all of the
  9243. * given tags in their tags property.
  9244. */
  9245. Graph.prototype.getAttributeForCell = function(cell, attributeName, defaultValue)
  9246. {
  9247. var value = (cell.value != null && typeof cell.value === 'object') ?
  9248. cell.value.getAttribute(attributeName) : null;
  9249. return (value != null) ? value : defaultValue;
  9250. };
  9251. /**
  9252. * Sets the link for the given cell.
  9253. */
  9254. Graph.prototype.setAttributeForCell = function(cell, attributeName, attributeValue)
  9255. {
  9256. var value = null;
  9257. if (cell.value != null && typeof(cell.value) == 'object')
  9258. {
  9259. value = cell.value.cloneNode(true);
  9260. }
  9261. else
  9262. {
  9263. var doc = mxUtils.createXmlDocument();
  9264. value = doc.createElement('UserObject');
  9265. value.setAttribute('label', cell.value || '');
  9266. }
  9267. if (attributeValue != null)
  9268. {
  9269. value.setAttribute(attributeName, attributeValue);
  9270. }
  9271. else
  9272. {
  9273. value.removeAttribute(attributeName);
  9274. }
  9275. this.model.setValue(cell, value);
  9276. };
  9277. /**
  9278. *
  9279. */
  9280. Graph.prototype.isTargetShape = function(target, cells, evt)
  9281. {
  9282. var shape = mxUtils.getValue(
  9283. this.getCurrentCellStyle(target),
  9284. mxConstants.STYLE_SHAPE, '');
  9285. for (var i = 0; i < cells.length; i++)
  9286. {
  9287. var shapes = mxUtils.getValue(
  9288. this.getCurrentCellStyle(cells[i]),
  9289. 'targetShapes', '').split(',');
  9290. if (mxUtils.indexOf(shapes, shape) >= 0)
  9291. {
  9292. return true;
  9293. }
  9294. }
  9295. return false;
  9296. };
  9297. /**
  9298. * Overridden to stop moving edge labels between cells.
  9299. */
  9300. var graphGetDropTarget = Graph.prototype.getDropTarget;
  9301. Graph.prototype.getDropTarget = function(cells, evt, cell, clone)
  9302. {
  9303. // Disables drop into group if alt is pressed
  9304. if (mxEvent.isAltDown(evt))
  9305. {
  9306. return null;
  9307. }
  9308. // Disables dragging edge labels out of edges
  9309. for (var i = 0; i < cells.length; i++)
  9310. {
  9311. var parent = this.model.getParent(cells[i]);
  9312. if (this.model.isEdge(parent) && mxUtils.indexOf(cells, parent) < 0)
  9313. {
  9314. return null;
  9315. }
  9316. }
  9317. var target = graphGetDropTarget.apply(this, arguments);
  9318. // Always drops rows to tables
  9319. var rows = true;
  9320. for (var i = 0; i < cells.length && rows; i++)
  9321. {
  9322. rows = rows && this.isTableRow(cells[i]);
  9323. }
  9324. if (rows)
  9325. {
  9326. if (this.isTableCell(target))
  9327. {
  9328. target = this.model.getParent(target);
  9329. }
  9330. if (this.isTableRow(target))
  9331. {
  9332. target = this.model.getParent(target);
  9333. }
  9334. if (!this.isTable(target))
  9335. {
  9336. target = null;
  9337. }
  9338. }
  9339. return target;
  9340. };
  9341. /**
  9342. * Overrides double click handling to avoid accidental inserts of new labels in dblClick below.
  9343. */
  9344. Graph.prototype.click = function(me)
  9345. {
  9346. mxGraph.prototype.click.call(this, me);
  9347. // Stores state and source for checking in dblClick
  9348. this.firstClickState = me.getState();
  9349. this.firstClickSource = me.getSource();
  9350. };
  9351. /**
  9352. * Overrides double click handling to add the tolerance and inserting text.
  9353. */
  9354. Graph.prototype.dblClick = function(evt, cell)
  9355. {
  9356. if (this.isEnabled())
  9357. {
  9358. cell = this.insertTextForEvent(evt, cell);
  9359. mxGraph.prototype.dblClick.call(this, evt, cell);
  9360. }
  9361. };
  9362. /**
  9363. * Overrides double click handling to add the tolerance and inserting text.
  9364. */
  9365. Graph.prototype.insertTextForEvent = function(evt, cell)
  9366. {
  9367. var pt = mxUtils.convertPoint(this.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  9368. // Automatically adds new child cells to edges on double click
  9369. if (evt != null && !this.model.isVertex(cell))
  9370. {
  9371. var state = (this.model.isEdge(cell)) ? this.view.getState(cell) : null;
  9372. var src = mxEvent.getSource(evt);
  9373. if ((this.firstClickState == state && this.firstClickSource == src) &&
  9374. (state == null || (state.text == null || state.text.node == null ||
  9375. state.text.boundingBox == null || (!mxUtils.contains(state.text.boundingBox,
  9376. pt.x, pt.y) && !mxUtils.isAncestorNode(state.text.node, mxEvent.getSource(evt))))) &&
  9377. ((state == null && !this.isCellLocked(this.getDefaultParent())) ||
  9378. (state != null && !this.isCellLocked(state.cell))) &&
  9379. (state != null ||
  9380. (mxClient.IS_SVG && src == this.view.getCanvas().ownerSVGElement)))
  9381. {
  9382. if (state == null)
  9383. {
  9384. state = this.view.getState(this.getCellAt(pt.x, pt.y));
  9385. }
  9386. cell = this.addText(pt.x, pt.y, state);
  9387. }
  9388. }
  9389. return cell;
  9390. };
  9391. /**
  9392. * Returns a point that specifies the location for inserting cells.
  9393. */
  9394. Graph.prototype.getInsertPoint = function()
  9395. {
  9396. var gs = this.getGridSize();
  9397. var dx = this.container.scrollLeft / this.view.scale - this.view.translate.x;
  9398. var dy = this.container.scrollTop / this.view.scale - this.view.translate.y;
  9399. if (this.pageVisible)
  9400. {
  9401. var layout = this.getPageLayout();
  9402. var page = this.getPageSize();
  9403. dx = Math.max(dx, layout.x * page.width);
  9404. dy = Math.max(dy, layout.y * page.height);
  9405. }
  9406. return new mxPoint(this.snap(dx + gs), this.snap(dy + gs));
  9407. };
  9408. /**
  9409. *
  9410. */
  9411. Graph.prototype.getFreeInsertPoint = function()
  9412. {
  9413. var view = this.view;
  9414. var bds = this.getGraphBounds();
  9415. var pt = this.getInsertPoint();
  9416. // Places at same x-coord and 2 grid sizes below existing graph
  9417. var x = this.snap(Math.round(Math.max(pt.x, bds.x / view.scale - view.translate.x +
  9418. ((bds.width == 0) ? 2 * this.gridSize : 0))));
  9419. var y = this.snap(Math.round(Math.max(pt.y, (bds.y + bds.height) / view.scale - view.translate.y +
  9420. 2 * this.gridSize)));
  9421. return new mxPoint(x, y);
  9422. };
  9423. /**
  9424. *
  9425. */
  9426. Graph.prototype.getCenterInsertPoint = function(bbox)
  9427. {
  9428. bbox = (bbox != null) ? bbox : new mxRectangle();
  9429. if (mxUtils.hasScrollbars(this.container))
  9430. {
  9431. return new mxPoint(
  9432. this.snap(Math.round((this.container.scrollLeft + this.container.clientWidth / 2) /
  9433. this.view.scale - this.view.translate.x - bbox.width / 2)),
  9434. this.snap(Math.round((this.container.scrollTop + this.container.clientHeight / 2) /
  9435. this.view.scale - this.view.translate.y - bbox.height / 2)));
  9436. }
  9437. else
  9438. {
  9439. return new mxPoint(
  9440. this.snap(Math.round(this.container.clientWidth / 2 / this.view.scale -
  9441. this.view.translate.x - bbox.width / 2)),
  9442. this.snap(Math.round(this.container.clientHeight / 2 / this.view.scale -
  9443. this.view.translate.y - bbox.height / 2)));
  9444. }
  9445. };
  9446. /**
  9447. * Hook for subclassers to return true if the current insert point was defined
  9448. * using a mouse hover event.
  9449. */
  9450. Graph.prototype.isMouseInsertPoint = function()
  9451. {
  9452. return false;
  9453. };
  9454. /**
  9455. * Appends the given font size to the given style.
  9456. */
  9457. Graph.prototype.appendFontSize = function(style, fontSize)
  9458. {
  9459. style = (style != null) ? style : '';
  9460. if (fontSize != null)
  9461. {
  9462. if (style.length > 0 && style.charAt(style.length - 1) != ';')
  9463. {
  9464. style += ';';
  9465. }
  9466. style += 'fontSize=' + fontSize + ';';
  9467. }
  9468. return style;
  9469. };
  9470. /**
  9471. * Adds a new label at the given position and returns the new cell. State is
  9472. * an optional edge state to be used as the parent for the label. Vertices
  9473. * are not allowed currently as states.
  9474. */
  9475. Graph.prototype.addText = function(x, y, state)
  9476. {
  9477. // Creates a new edge label with a predefined text
  9478. var label = new mxCell();
  9479. label.value = 'Text';
  9480. label.geometry = new mxGeometry(0, 0, 0, 0);
  9481. label.vertex = true;
  9482. var style = 'html=1;align=center;verticalAlign=middle;resizable=0;points=[];';
  9483. if (state != null && this.model.isEdge(state.cell))
  9484. {
  9485. label.style = 'edgeLabel;' + this.appendFontSize(style, this.edgeFontSize);
  9486. label.geometry.relative = true;
  9487. label.connectable = false;
  9488. // Resets the relative location stored inside the geometry
  9489. var pt2 = this.view.getRelativePoint(state, x, y);
  9490. label.geometry.x = Math.round(pt2.x * 10000) / 10000;
  9491. label.geometry.y = Math.round(pt2.y);
  9492. // Resets the offset inside the geometry to find the offset from the resulting point
  9493. label.geometry.offset = new mxPoint(0, 0);
  9494. pt2 = this.view.getPoint(state, label.geometry);
  9495. var scale = this.view.scale;
  9496. label.geometry.offset = new mxPoint(Math.round((x - pt2.x) / scale), Math.round((y - pt2.y) / scale));
  9497. }
  9498. else
  9499. {
  9500. var tr = this.view.translate;
  9501. label.style = 'text;' + this.appendFontSize(style, this.vertexFontSize);
  9502. label.geometry.width = 40;
  9503. label.geometry.height = 20;
  9504. label.geometry.x = Math.round(x / this.view.scale) -
  9505. tr.x - ((state != null) ? state.origin.x : 0);
  9506. label.geometry.y = Math.round(y / this.view.scale) -
  9507. tr.y - ((state != null) ? state.origin.y : 0);
  9508. label.style += 'autosize=1;'
  9509. }
  9510. this.getModel().beginUpdate();
  9511. try
  9512. {
  9513. this.addCells([label], (state != null) ? state.cell : null);
  9514. this.fireEvent(new mxEventObject('textInserted', 'cells', [label]));
  9515. // Updates size of text after possible change of style via event
  9516. this.autoSizeCell(label);
  9517. }
  9518. finally
  9519. {
  9520. this.getModel().endUpdate();
  9521. }
  9522. return label;
  9523. };
  9524. /**
  9525. * Adds a handler for clicking on shapes with links. This replaces all links in labels.
  9526. */
  9527. Graph.prototype.addClickHandler = function(highlight, beforeClick, onClick)
  9528. {
  9529. // Replaces links in labels for consistent right-clicks
  9530. var checkLinks = mxUtils.bind(this, function()
  9531. {
  9532. var links = this.container.getElementsByTagName('a');
  9533. if (links != null)
  9534. {
  9535. for (var i = 0; i < links.length; i++)
  9536. {
  9537. var href = this.getAbsoluteUrl(links[i].getAttribute('href'));
  9538. if (href != null)
  9539. {
  9540. links[i].setAttribute('rel', this.linkRelation);
  9541. links[i].setAttribute('href', href);
  9542. if (beforeClick != null)
  9543. {
  9544. mxEvent.addGestureListeners(links[i], null, null, beforeClick);
  9545. }
  9546. }
  9547. }
  9548. }
  9549. });
  9550. this.model.addListener(mxEvent.CHANGE, checkLinks);
  9551. checkLinks();
  9552. var cursor = this.container.style.cursor;
  9553. var tol = this.getTolerance();
  9554. var graph = this;
  9555. var mouseListener =
  9556. {
  9557. currentState: null,
  9558. currentLink: null,
  9559. currentTarget: null,
  9560. highlight: (highlight != null && highlight != '' && highlight != mxConstants.NONE) ?
  9561. new mxCellHighlight(graph, highlight, 4) : null,
  9562. startX: 0,
  9563. startY: 0,
  9564. scrollLeft: 0,
  9565. scrollTop: 0,
  9566. updateCurrentState: function(me)
  9567. {
  9568. var tmp = me.sourceState;
  9569. // Gets first intersecting ancestor with link
  9570. if (tmp == null || graph.getLinkForCell(tmp.cell) == null)
  9571. {
  9572. var cell = graph.getCellAt(me.getGraphX(), me.getGraphY(), null, null, null, function(state, x, y)
  9573. {
  9574. return graph.getLinkForCell(state.cell) == null;
  9575. });
  9576. tmp = (tmp != null && !graph.model.isAncestor(cell, tmp.cell)) ? null : graph.view.getState(cell);
  9577. }
  9578. if (tmp != this.currentState)
  9579. {
  9580. if (this.currentState != null)
  9581. {
  9582. this.clear();
  9583. }
  9584. this.currentState = tmp;
  9585. if (this.currentState != null)
  9586. {
  9587. this.activate(this.currentState);
  9588. }
  9589. }
  9590. },
  9591. mouseDown: function(sender, me)
  9592. {
  9593. this.startX = me.getGraphX();
  9594. this.startY = me.getGraphY();
  9595. this.scrollLeft = graph.container.scrollLeft;
  9596. this.scrollTop = graph.container.scrollTop;
  9597. if (this.currentLink == null && graph.container.style.overflow == 'auto')
  9598. {
  9599. graph.container.style.cursor = 'move';
  9600. }
  9601. this.updateCurrentState(me);
  9602. },
  9603. mouseMove: function(sender, me)
  9604. {
  9605. if (graph.isMouseDown)
  9606. {
  9607. if (this.currentLink != null)
  9608. {
  9609. var dx = Math.abs(this.startX - me.getGraphX());
  9610. var dy = Math.abs(this.startY - me.getGraphY());
  9611. if (dx > tol || dy > tol)
  9612. {
  9613. this.clear();
  9614. }
  9615. }
  9616. }
  9617. else
  9618. {
  9619. // Checks for parent link
  9620. var linkNode = me.getSource();
  9621. while (linkNode != null && linkNode.nodeName.toLowerCase() != 'a')
  9622. {
  9623. linkNode = linkNode.parentNode;
  9624. }
  9625. if (linkNode != null)
  9626. {
  9627. this.clear();
  9628. }
  9629. else
  9630. {
  9631. if (graph.tooltipHandler != null && this.currentLink != null && this.currentState != null)
  9632. {
  9633. graph.tooltipHandler.reset(me, true, this.currentState);
  9634. }
  9635. if (this.currentState != null && (me.getState() == this.currentState || me.sourceState == null) &&
  9636. graph.intersects(this.currentState, me.getGraphX(), me.getGraphY()))
  9637. {
  9638. return;
  9639. }
  9640. this.updateCurrentState(me);
  9641. }
  9642. }
  9643. },
  9644. mouseUp: function(sender, me)
  9645. {
  9646. var source = me.getSource();
  9647. var evt = me.getEvent();
  9648. // Checks for parent link
  9649. var linkNode = source;
  9650. while (linkNode != null && linkNode.nodeName.toLowerCase() != 'a')
  9651. {
  9652. linkNode = linkNode.parentNode;
  9653. }
  9654. // Ignores clicks on links and collapse/expand icon
  9655. if (linkNode == null &&
  9656. (((Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  9657. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  9658. (me.sourceState == null || !me.isSource(me.sourceState.control))) &&
  9659. (((mxEvent.isLeftMouseButton(evt) || mxEvent.isMiddleMouseButton(evt)) &&
  9660. !mxEvent.isPopupTrigger(evt)) || mxEvent.isTouchEvent(evt))))
  9661. {
  9662. if (this.currentLink != null)
  9663. {
  9664. var blank = graph.isBlankLink(this.currentLink);
  9665. if ((this.currentLink.substring(0, 5) === 'data:' ||
  9666. !blank) && beforeClick != null)
  9667. {
  9668. beforeClick(evt, this.currentLink, (this.currentState != null) ?
  9669. this.currentState.cell : null);
  9670. }
  9671. if (!mxEvent.isConsumed(evt))
  9672. {
  9673. var target = (this.currentTarget != null) ?
  9674. this.currentTarget : ((mxEvent.isMiddleMouseButton(evt)) ? '_blank' :
  9675. ((blank) ? graph.linkTarget : '_top'));
  9676. graph.openLink(this.currentLink, target);
  9677. me.consume();
  9678. }
  9679. }
  9680. else if (onClick != null && !me.isConsumed() &&
  9681. (Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  9682. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  9683. (Math.abs(this.startX - me.getGraphX()) < tol &&
  9684. Math.abs(this.startY - me.getGraphY()) < tol))
  9685. {
  9686. onClick(me.getEvent());
  9687. }
  9688. }
  9689. this.clear();
  9690. },
  9691. activate: function(state)
  9692. {
  9693. this.currentLink = graph.getAbsoluteUrl(graph.getLinkForCell(state.cell));
  9694. if (this.currentLink != null)
  9695. {
  9696. this.currentTarget = graph.getLinkTargetForCell(state.cell)
  9697. graph.container.style.cursor = 'pointer';
  9698. if (this.highlight != null)
  9699. {
  9700. this.highlight.highlight(state);
  9701. }
  9702. }
  9703. },
  9704. clear: function()
  9705. {
  9706. if (graph.container != null)
  9707. {
  9708. graph.container.style.cursor = cursor;
  9709. }
  9710. this.currentTarget = null;
  9711. this.currentState = null;
  9712. this.currentLink = null;
  9713. if (this.highlight != null)
  9714. {
  9715. this.highlight.hide();
  9716. }
  9717. if (graph.tooltipHandler != null)
  9718. {
  9719. graph.tooltipHandler.hide();
  9720. }
  9721. }
  9722. };
  9723. // Ignores built-in click handling
  9724. graph.click = function(me) {};
  9725. graph.addMouseListener(mouseListener);
  9726. mxEvent.addListener(document, 'mouseleave', function(evt)
  9727. {
  9728. mouseListener.clear();
  9729. });
  9730. };
  9731. /**
  9732. * Duplicates the given cells and returns the duplicates.
  9733. */
  9734. Graph.prototype.duplicateCells = function(cells, append)
  9735. {
  9736. cells = (cells != null) ? cells : this.getSelectionCells();
  9737. append = (append != null) ? append : true;
  9738. // Duplicates rows for table cells
  9739. for (var i = 0; i < cells.length; i++)
  9740. {
  9741. if (this.isTableCell(cells[i]))
  9742. {
  9743. cells[i] = this.model.getParent(cells[i]);
  9744. }
  9745. }
  9746. cells = this.model.getTopmostCells(cells);
  9747. var model = this.getModel();
  9748. var s = this.gridSize;
  9749. var select = [];
  9750. model.beginUpdate();
  9751. try
  9752. {
  9753. var cloneMap = new Object();
  9754. var lookup = this.createCellLookup(cells);
  9755. var clones = this.cloneCells(cells, false, cloneMap, true);
  9756. for (var i = 0; i < cells.length; i++)
  9757. {
  9758. var parent = model.getParent(cells[i]);
  9759. if (parent != null)
  9760. {
  9761. var child = this.moveCells([clones[i]], s, s, false)[0];
  9762. select.push(child);
  9763. if (append)
  9764. {
  9765. model.add(parent, clones[i]);
  9766. }
  9767. else
  9768. {
  9769. // Maintains child index by inserting after clone in parent
  9770. var index = parent.getIndex(cells[i]);
  9771. model.add(parent, clones[i], index + 1);
  9772. }
  9773. // Extends tables
  9774. if (this.isTable(parent))
  9775. {
  9776. var row = this.getCellGeometry(clones[i]);
  9777. var table = this.getCellGeometry(parent);
  9778. if (row != null && table != null)
  9779. {
  9780. table = table.clone();
  9781. table.height += row.height;
  9782. model.setGeometry(parent, table);
  9783. }
  9784. }
  9785. }
  9786. else
  9787. {
  9788. select.push(clones[i]);
  9789. }
  9790. }
  9791. // Updates custom links after inserting into the model for cells to have new IDs
  9792. this.updateCustomLinks(this.createCellMapping(cloneMap, lookup), clones, this);
  9793. this.fireEvent(new mxEventObject(mxEvent.CELLS_ADDED, 'cells', clones));
  9794. }
  9795. finally
  9796. {
  9797. model.endUpdate();
  9798. }
  9799. return select;
  9800. };
  9801. /**
  9802. * Inserts the given image at the cursor in a content editable text box using
  9803. * the insertimage command on the document instance.
  9804. */
  9805. Graph.prototype.insertImage = function(newValue, w, h)
  9806. {
  9807. // To find the new image, we create a list of all existing links first
  9808. if (newValue != null && this.cellEditor.textarea != null)
  9809. {
  9810. var tmp = this.cellEditor.textarea.getElementsByTagName('img');
  9811. var oldImages = [];
  9812. for (var i = 0; i < tmp.length; i++)
  9813. {
  9814. oldImages.push(tmp[i]);
  9815. }
  9816. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  9817. document.execCommand('insertimage', false, newValue);
  9818. // Sets size of new image
  9819. var newImages = this.cellEditor.textarea.getElementsByTagName('img');
  9820. if (newImages.length == oldImages.length + 1)
  9821. {
  9822. // Inverse order in favor of appended images
  9823. for (var i = newImages.length - 1; i >= 0; i--)
  9824. {
  9825. if (i == 0 || newImages[i] != oldImages[i - 1])
  9826. {
  9827. // Workaround for lost styles during undo and redo is using attributes
  9828. newImages[i].setAttribute('width', w);
  9829. newImages[i].setAttribute('height', h);
  9830. break;
  9831. }
  9832. }
  9833. }
  9834. }
  9835. };
  9836. /**
  9837. * Inserts the given image at the cursor in a content editable text box using
  9838. * the insertimage command on the document instance.
  9839. */
  9840. Graph.prototype.insertLink = function(value)
  9841. {
  9842. if (this.cellEditor.textarea != null)
  9843. {
  9844. if (value.length == 0)
  9845. {
  9846. document.execCommand('unlink', false);
  9847. }
  9848. else if (mxClient.IS_FF)
  9849. {
  9850. // Workaround for Firefox that adds a new link and removes
  9851. // the href from the inner link if its parent is a span is
  9852. // to remove all inner links inside the new outer link
  9853. var tmp = this.cellEditor.textarea.getElementsByTagName('a');
  9854. var oldLinks = [];
  9855. for (var i = 0; i < tmp.length; i++)
  9856. {
  9857. oldLinks.push(tmp[i]);
  9858. }
  9859. document.execCommand('createlink', false, mxUtils.trim(value));
  9860. // Finds the new link element
  9861. var newLinks = this.cellEditor.textarea.getElementsByTagName('a');
  9862. if (newLinks.length == oldLinks.length + 1)
  9863. {
  9864. // Inverse order in favor of appended links
  9865. for (var i = newLinks.length - 1; i >= 0; i--)
  9866. {
  9867. if (newLinks[i] != oldLinks[i - 1])
  9868. {
  9869. // Removes all inner links from the new link and
  9870. // moves the children to the inner link parent
  9871. var tmp = newLinks[i].getElementsByTagName('a');
  9872. while (tmp.length > 0)
  9873. {
  9874. var parent = tmp[0].parentNode;
  9875. while (tmp[0].firstChild != null)
  9876. {
  9877. parent.insertBefore(tmp[0].firstChild, tmp[0]);
  9878. }
  9879. parent.removeChild(tmp[0]);
  9880. }
  9881. break;
  9882. }
  9883. }
  9884. }
  9885. }
  9886. else
  9887. {
  9888. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  9889. document.execCommand('createlink', false, mxUtils.trim(value));
  9890. }
  9891. }
  9892. };
  9893. /**
  9894. *
  9895. * @param cell
  9896. * @returns {Boolean}
  9897. */
  9898. Graph.prototype.isCellResizable = function(cell)
  9899. {
  9900. var result = mxGraph.prototype.isCellResizable.apply(this, arguments);
  9901. var style = this.getCurrentCellStyle(cell);
  9902. return !this.isTableCell(cell) && !this.isTableRow(cell) && (result ||
  9903. (mxUtils.getValue(style, mxConstants.STYLE_RESIZABLE, '1') != '0' &&
  9904. style[mxConstants.STYLE_WHITE_SPACE] == 'wrap'));
  9905. };
  9906. /**
  9907. * Function: distributeCells
  9908. *
  9909. * Distribuets the centers of the given cells equally along the available
  9910. * horizontal or vertical space.
  9911. *
  9912. * Parameters:
  9913. *
  9914. * horizontal - Boolean that specifies the direction of the distribution.
  9915. * cells - Optional array of <mxCells> to be distributed. Edges are ignored.
  9916. */
  9917. Graph.prototype.distributeCells = function(horizontal, cells, spacing)
  9918. {
  9919. if (cells == null)
  9920. {
  9921. cells = this.getSelectionCells();
  9922. }
  9923. if (cells != null && cells.length > 1)
  9924. {
  9925. var vertices = [];
  9926. var max = null;
  9927. var min = null;
  9928. var cellsSize = 0;
  9929. for (var i = 0; i < cells.length; i++)
  9930. {
  9931. if (this.getModel().isVertex(cells[i]))
  9932. {
  9933. var state = this.view.getState(cells[i]);
  9934. if (state != null)
  9935. {
  9936. var tmp = (horizontal) ? state.getCenterX() : state.getCenterY();
  9937. max = (max != null) ? Math.max(max, tmp) : tmp;
  9938. min = (min != null) ? Math.min(min, tmp) : tmp;
  9939. if (spacing)
  9940. {
  9941. cellsSize += (horizontal) ? state.width : state.height;
  9942. }
  9943. vertices.push(state);
  9944. }
  9945. }
  9946. }
  9947. if (vertices.length > 2)
  9948. {
  9949. vertices.sort(function(a, b)
  9950. {
  9951. return (horizontal) ? a.x - b.x : a.y - b.y;
  9952. });
  9953. if (spacing)
  9954. {
  9955. cellsSize -= (horizontal? (vertices[0].width / 2 + vertices[vertices.length - 1].width / 2) :
  9956. (vertices[0].height / 2 + vertices[vertices.length - 1].height / 2))
  9957. }
  9958. var t = this.view.translate;
  9959. var s = this.view.scale;
  9960. min = min / s - ((horizontal) ? t.x : t.y);
  9961. max = max / s - ((horizontal) ? t.x : t.y);
  9962. this.getModel().beginUpdate();
  9963. try
  9964. {
  9965. var dt = (max - min - cellsSize) / (vertices.length - 1);
  9966. var t0 = min + (spacing? (horizontal? vertices[0].width / 2 : vertices[0].height / 2) : 0);
  9967. for (var i = 1; i < vertices.length - 1; i++)
  9968. {
  9969. var pstate = this.view.getState(this.model.getParent(vertices[i].cell));
  9970. var geo = this.getCellGeometry(vertices[i].cell);
  9971. t0 += dt;
  9972. if (geo != null && pstate != null)
  9973. {
  9974. geo = geo.clone();
  9975. if (horizontal)
  9976. {
  9977. geo.x = Math.round(t0 - (spacing? 0 : geo.width / 2)) - pstate.origin.x;
  9978. }
  9979. else
  9980. {
  9981. geo.y = Math.round(t0 - (spacing? 0 : geo.height / 2)) - pstate.origin.y;
  9982. }
  9983. this.getModel().setGeometry(vertices[i].cell, geo);
  9984. }
  9985. if (spacing)
  9986. {
  9987. t0 += horizontal? vertices[i].width : vertices[i].height;
  9988. }
  9989. }
  9990. }
  9991. finally
  9992. {
  9993. this.getModel().endUpdate();
  9994. }
  9995. }
  9996. }
  9997. return cells;
  9998. };
  9999. /**
  10000. * Adds meta-drag an Mac.
  10001. * @param evt
  10002. * @returns
  10003. */
  10004. Graph.prototype.isCloneEvent = function(evt)
  10005. {
  10006. return (mxClient.IS_MAC && mxEvent.isMetaDown(evt)) || mxEvent.isControlDown(evt);
  10007. };
  10008. /**
  10009. * Translates this point by the given vector.
  10010. *
  10011. * @param {number} dx X-coordinate of the translation.
  10012. * @param {number} dy Y-coordinate of the translation.
  10013. */
  10014. Graph.prototype.createSvgImageExport = function()
  10015. {
  10016. var exp = new mxImageExport();
  10017. // Adds cell ID to SVG group
  10018. exp.addCellData = function(cell, group, includeValue)
  10019. {
  10020. group.setAttribute('data-cell-id', cell.id);
  10021. if (includeValue)
  10022. {
  10023. if (mxUtils.isNode(cell.value))
  10024. {
  10025. for (var i = 0; i < cell.value.attributes.length; i++)
  10026. {
  10027. var attrib = cell.value.attributes[i];
  10028. group.setAttribute('data-cell-' + attrib.name, attrib.value);
  10029. }
  10030. }
  10031. else if (typeof cell.value === 'object')
  10032. {
  10033. for (var key in cell.value)
  10034. {
  10035. group.setAttribute('data-cell-' + key, cell.value[key]);
  10036. }
  10037. }
  10038. else if (cell.value != null)
  10039. {
  10040. group.setAttribute('data-cell-value', cell.value);
  10041. }
  10042. }
  10043. return group;
  10044. };
  10045. // Maps cell hierarchy to SVG group structure
  10046. var visitStatesRecursive = exp.visitStatesRecursive;
  10047. exp.visitStatesRecursive = function(state, canvas, visitor)
  10048. {
  10049. if (state != null)
  10050. {
  10051. var root = canvas.root;
  10052. var svgDoc = canvas.root.ownerDocument;
  10053. canvas.root = this.addCellData(state.cell,
  10054. (svgDoc.createElementNS != null) ?
  10055. svgDoc.createElementNS(mxConstants.NS_SVG, 'g') :
  10056. svgDoc.createElement('g'), Editor.addSvgMetadata);
  10057. root.appendChild(canvas.root);
  10058. visitStatesRecursive.apply(this, arguments);
  10059. canvas.root = root;
  10060. }
  10061. };
  10062. // Adds hyperlinks (experimental)
  10063. exp.getLinkForCellState = mxUtils.bind(this, function(state, canvas)
  10064. {
  10065. return this.getLinkForCell(state.cell);
  10066. });
  10067. // Adds tooltips (experimental)
  10068. exp.getTitleForCellState = mxUtils.bind(this, function(state, canvas)
  10069. {
  10070. return Editor.convertHtmlToText(this.convertValueToTooltip(state.cell));
  10071. });
  10072. return exp;
  10073. };
  10074. /**
  10075. * Parses the given background image.
  10076. */
  10077. Graph.prototype.parseBackgroundImage = function(json)
  10078. {
  10079. var result = null;
  10080. if (json != null && json.length > 0)
  10081. {
  10082. var obj = JSON.parse(json);
  10083. result = new mxImage(obj.src, obj.width, obj.height)
  10084. }
  10085. return result;
  10086. };
  10087. /**
  10088. * Parses the given background image.
  10089. */
  10090. Graph.prototype.getBackgroundImageObject = function(obj)
  10091. {
  10092. return obj;
  10093. };
  10094. /**
  10095. * Translates this point by the given vector.
  10096. *
  10097. * @param {number} dx X-coordinate of the translation.
  10098. * @param {number} dy Y-coordinate of the translation.
  10099. */
  10100. Graph.prototype.getSvg = function(background, scale, border, nocrop, crisp,
  10101. ignoreSelection, showText, imgExport, linkTarget, hasShadow, incExtFonts,
  10102. theme, exportType, cells, noCssClass, disableLinks)
  10103. {
  10104. var lookup = null;
  10105. if (cells != null)
  10106. {
  10107. lookup = new mxDictionary();
  10108. for (var i = 0; i < cells.length; i++)
  10109. {
  10110. lookup.put(cells[i], true);
  10111. }
  10112. }
  10113. //Disable Css Transforms if it is used
  10114. var origUseCssTrans = this.useCssTransforms;
  10115. var origEnabledFlowAnimation = this.enableFlowAnimation;
  10116. this.enableFlowAnimation = false;
  10117. if (origUseCssTrans)
  10118. {
  10119. this.useCssTransforms = false;
  10120. this.view.revalidate();
  10121. this.sizeDidChange();
  10122. }
  10123. try
  10124. {
  10125. scale = (scale != null) ? scale : 1;
  10126. border = (border != null) ? border : 0;
  10127. crisp = (crisp != null) ? crisp : true;
  10128. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  10129. showText = (showText != null) ? showText : true;
  10130. hasShadow = (hasShadow != null) ? hasShadow : false;
  10131. var bounds = (exportType == 'page') ? this.view.getBackgroundPageBounds() :
  10132. (((ignoreSelection && lookup == null) || nocrop ||
  10133. exportType == 'diagram') ? this.getGraphBounds() :
  10134. this.getBoundingBox(this.getSelectionCells()));
  10135. var bgImg = this.backgroundImage;
  10136. var tr = this.view.translate;
  10137. var vs = this.view.scale;
  10138. if (exportType == 'diagram' && bgImg != null &&
  10139. bgImg.width != null && bgImg.height != null)
  10140. {
  10141. bounds = mxRectangle.fromRectangle(bounds);
  10142. bounds.add(new mxRectangle((tr.x + bgImg.x) * vs,
  10143. (tr.y + bgImg.y) * vs, bgImg.width * vs,
  10144. bgImg.height * vs));
  10145. }
  10146. if (bounds == null)
  10147. {
  10148. throw Error(mxResources.get('drawingEmpty'));
  10149. }
  10150. // Converts CSS background color as it is excluded from the filter
  10151. var svgBackground = background;
  10152. if (svgBackground != null && theme == 'dark' &&
  10153. Editor.enableCssDarkMode)
  10154. {
  10155. svgBackground = Graph.invertColor(background);
  10156. }
  10157. // Prepares SVG document that holds the output
  10158. var s = scale / vs;
  10159. var w = Math.max(1, Math.ceil(bounds.width * s) + 2 * border) +
  10160. ((hasShadow && border == 0) ? 5 : 0);
  10161. var h = Math.max(1, Math.ceil(bounds.height * s) + 2 * border) +
  10162. ((hasShadow && border == 0) ? 5 : 0);
  10163. var tmp = (crisp) ? -0.5 : 0;
  10164. var root = Graph.createSvgNode(tmp, tmp, w, h, svgBackground);
  10165. var svgDoc = root.ownerDocument;
  10166. // Adds background as an additional rectangle for
  10167. // compatiblity with MS Office and event handling
  10168. if (background != null)
  10169. {
  10170. var rect = mxUtils.createElementNs(
  10171. svgDoc, mxConstants.NS_SVG, 'rect');
  10172. rect.setAttribute('fill', background);
  10173. rect.setAttribute('width', '100%');
  10174. rect.setAttribute('height', '100%');
  10175. rect.setAttribute('x', '0');
  10176. rect.setAttribute('y', '0');
  10177. root.appendChild(rect);
  10178. }
  10179. // Renders graph. Offset will be multiplied with state's scale when painting state.
  10180. // TextOffset only seems to affect FF output but used everywhere for consistency.
  10181. var group = mxUtils.createElementNs(
  10182. svgDoc, mxConstants.NS_SVG, 'g');
  10183. root.appendChild(group);
  10184. var svgCanvas = this.createSvgCanvas(group);
  10185. svgCanvas.foOffset = (crisp) ? -0.5 : 0;
  10186. svgCanvas.textOffset = (crisp) ? -0.5 : 0;
  10187. svgCanvas.imageOffset = (crisp) ? -0.5 : 0;
  10188. svgCanvas.translate(Math.floor(border / scale - bounds.x / vs),
  10189. Math.floor(border / scale - bounds.y / vs));
  10190. // Convert HTML entities
  10191. var htmlConverter = document.createElement('div');
  10192. // Adds simple text fallback for viewers with no support for foreignObjects
  10193. var getAlternateText = svgCanvas.getAlternateText;
  10194. svgCanvas.getAlternateText = function(fo, x, y, w, h, str,
  10195. align, valign, wrap, format, overflow, clip, rotation)
  10196. {
  10197. // Assumes a max character width of 0.5em
  10198. if (str != null && this.state.fontSize > 0)
  10199. {
  10200. try
  10201. {
  10202. if (mxUtils.isNode(str))
  10203. {
  10204. str = str.innerText;
  10205. }
  10206. else
  10207. {
  10208. htmlConverter.innerHTML = str;
  10209. str = mxUtils.extractTextWithWhitespace(htmlConverter.childNodes);
  10210. }
  10211. // Workaround for substring breaking double byte UTF
  10212. var exp = Math.ceil(2 * w / this.state.fontSize);
  10213. var result = [];
  10214. var length = 0;
  10215. var index = 0;
  10216. while ((exp == 0 || length < exp) && index < str.length)
  10217. {
  10218. var char = str.charCodeAt(index);
  10219. if (char == 10 || char == 13)
  10220. {
  10221. if (length > 0)
  10222. {
  10223. break;
  10224. }
  10225. }
  10226. else
  10227. {
  10228. result.push(str.charAt(index));
  10229. if (char < 255)
  10230. {
  10231. length++;
  10232. }
  10233. }
  10234. index++;
  10235. }
  10236. // Uses result and adds ellipsis if more than 1 char remains
  10237. if (result.length < str.length && str.length - result.length > 1)
  10238. {
  10239. str = mxUtils.trim(result.join('')) + '...';
  10240. }
  10241. return str;
  10242. }
  10243. catch (e)
  10244. {
  10245. return getAlternateText.apply(this, arguments);
  10246. }
  10247. }
  10248. else
  10249. {
  10250. return getAlternateText.apply(this, arguments);
  10251. }
  10252. };
  10253. // Paints background image
  10254. if (bgImg != null && bgImg.width != null && bgImg.height != null)
  10255. {
  10256. var s2 = vs / scale;
  10257. var tmp = new mxRectangle((bgImg.x + tr.x) * s2,
  10258. (bgImg.y + tr.y) * s2, bgImg.width * s2,
  10259. bgImg.height * s2);
  10260. // Checks if visible
  10261. if (mxUtils.intersects(bounds, tmp))
  10262. {
  10263. svgCanvas.image(bgImg.x + tr.x, bgImg.y + tr.y,
  10264. bgImg.width, bgImg.height, bgImg.src, true);
  10265. }
  10266. }
  10267. svgCanvas.scale(s);
  10268. svgCanvas.textEnabled = showText;
  10269. imgExport = (imgExport != null) ? imgExport : this.createSvgImageExport();
  10270. // Ignores custom links
  10271. var imgExportGetLinkForCellState = imgExport.getLinkForCellState;
  10272. imgExport.getLinkForCellState = function(state, canvas)
  10273. {
  10274. var result = state.view.graph.getAbsoluteUrl(imgExportGetLinkForCellState.apply(this, arguments));
  10275. return (result != null && !state.view.graph.isCustomLink(result)) ? result : null;
  10276. };
  10277. imgExport.getLinkTargetForCellState = function(state, canvas)
  10278. {
  10279. return state.view.graph.getLinkTargetForCell(state.cell);
  10280. };
  10281. // Implements ignoreSelection flag and flow animation
  10282. var imgExportDrawCellState = imgExport.drawCellState;
  10283. var flowAnimationId = null;
  10284. var addFlowAnimationStyle = mxUtils.bind(this, function()
  10285. {
  10286. if (flowAnimationId == null)
  10287. {
  10288. flowAnimationId = 'ge-flow-animation-' + Editor.guid();
  10289. var style = (svgDoc.createElementNS != null) ?
  10290. svgDoc.createElementNS(mxConstants.NS_SVG, 'style') :
  10291. svgDoc.createElement('style');
  10292. style.innerHTML = this.createFlowAnimationCss(flowAnimationId);
  10293. svgDoc.getElementsByTagName('defs')[0].appendChild(style);
  10294. }
  10295. return flowAnimationId;
  10296. });
  10297. imgExport.drawCellState = function(state, canvas)
  10298. {
  10299. var graph = state.view.graph;
  10300. var selected = (lookup != null) ? lookup.get(state.cell) :
  10301. graph.isCellSelected(state.cell);
  10302. var parent = graph.model.getParent(state.cell);
  10303. // Checks if parent cell is selected
  10304. while ((!ignoreSelection || lookup != null) &&
  10305. !selected && parent != null)
  10306. {
  10307. selected = (lookup != null) ? lookup.get(parent) :
  10308. graph.isCellSelected(parent);
  10309. parent = graph.model.getParent(parent);
  10310. }
  10311. // Adds flow animation
  10312. if (state.shape != null)
  10313. {
  10314. try
  10315. {
  10316. var isFlowAnimationEnabled = state.shape.isFlowAnimationEnabled;
  10317. var addFlowAnimationToShape = state.shape.addFlowAnimationToShape;
  10318. state.shape.isFlowAnimationEnabled = function()
  10319. {
  10320. return origEnabledFlowAnimation && graph.model.isEdge(state.cell) &&
  10321. mxUtils.getValue(state.style, 'flowAnimation', '0') == '1';
  10322. };
  10323. state.shape.addFlowAnimationToShape = function()
  10324. {
  10325. graph.addFlowAnimationToNode(this.getFlowAnimationPath(),
  10326. state.style, scale, addFlowAnimationStyle());
  10327. };
  10328. if ((ignoreSelection && lookup == null) || selected)
  10329. {
  10330. graph.view.redrawEnumerationState(state);
  10331. imgExportDrawCellState.apply(this, arguments);
  10332. this.doDrawShape(state.secondLabel, canvas);
  10333. }
  10334. }
  10335. finally
  10336. {
  10337. state.shape.isFlowAnimationEnabled = isFlowAnimationEnabled;
  10338. state.shape.addFlowAnimationToShape = addFlowAnimationToShape;
  10339. }
  10340. }
  10341. };
  10342. var viewRoot = (this.view.currentRoot != null) ?
  10343. this.view.currentRoot : this.model.root;
  10344. imgExport.drawState(this.getView().getState(viewRoot), svgCanvas);
  10345. this.addForeignObjectWarning(svgCanvas, root);
  10346. // Disables links
  10347. if (disableLinks)
  10348. {
  10349. this.disableSvgLinks(root);
  10350. }
  10351. else
  10352. {
  10353. this.updateSvgLinks(root, linkTarget, true);
  10354. }
  10355. return root;
  10356. }
  10357. finally
  10358. {
  10359. this.enableFlowAnimation = origEnabledFlowAnimation;
  10360. if (origUseCssTrans)
  10361. {
  10362. this.useCssTransforms = true;
  10363. this.view.revalidate();
  10364. this.sizeDidChange();
  10365. }
  10366. }
  10367. };
  10368. /**
  10369. * Adds warning for truncated labels in older viewers.
  10370. */
  10371. Graph.prototype.addForeignObjectWarning = function(canvas, root)
  10372. {
  10373. if (urlParams['svg-warning'] != '0' && root.getElementsByTagName('foreignObject').length > 0)
  10374. {
  10375. var sw = canvas.createElement('switch');
  10376. var g1 = canvas.createElement('g');
  10377. g1.setAttribute('requiredFeatures', 'http://www.w3.org/TR/SVG11/feature#Extensibility');
  10378. var a = canvas.createElement('a');
  10379. a.setAttribute('transform', 'translate(0,-5)');
  10380. // Workaround for implicit namespace handling in HTML5 export, IE adds NS1 namespace so use code below
  10381. // in all IE versions except quirks mode. KNOWN: Adds xlink namespace to each image tag in output.
  10382. if (a.setAttributeNS == null || (root.ownerDocument != document && document.documentMode == null))
  10383. {
  10384. a.setAttribute('xlink:href', Graph.foreignObjectWarningLink);
  10385. a.setAttribute('target', '_blank');
  10386. }
  10387. else
  10388. {
  10389. a.setAttributeNS(mxConstants.NS_XLINK, 'xlink:href', Graph.foreignObjectWarningLink);
  10390. a.setAttributeNS(mxConstants.NS_XLINK, 'target', '_blank');
  10391. }
  10392. var text = canvas.createElement('text');
  10393. text.setAttribute('text-anchor', 'middle');
  10394. text.setAttribute('font-size', '10px');
  10395. text.setAttribute('x', '50%');
  10396. text.setAttribute('y', '100%');
  10397. mxUtils.write(text, Graph.foreignObjectWarningText);
  10398. sw.appendChild(g1);
  10399. a.appendChild(text);
  10400. sw.appendChild(a);
  10401. root.appendChild(sw);
  10402. }
  10403. };
  10404. /**
  10405. * Hook for creating the canvas used in getSvg.
  10406. */
  10407. Graph.prototype.disableSvgLinks = function(node, visit)
  10408. {
  10409. var links = node.getElementsByTagName('a');
  10410. for (var i = 0; i < links.length; i++)
  10411. {
  10412. var href = links[i].getAttribute('href');
  10413. if (href == null)
  10414. {
  10415. href = links[i].getAttribute('xlink:href');
  10416. }
  10417. if (href != null)
  10418. {
  10419. links[i].style.pointerEvents = 'none';
  10420. links[i].setAttribute('href', '');
  10421. }
  10422. if (visit)
  10423. {
  10424. visit(links[i]);
  10425. }
  10426. }
  10427. };
  10428. /**
  10429. * Hook for creating the canvas used in getSvg.
  10430. */
  10431. Graph.prototype.updateSvgLinks = function(node, target, removeCustom)
  10432. {
  10433. var links = node.getElementsByTagName('a');
  10434. for (var i = 0; i < links.length; i++)
  10435. {
  10436. if (links[i].getAttribute('target') == null)
  10437. {
  10438. var href = links[i].getAttribute('href');
  10439. if (href == null)
  10440. {
  10441. href = links[i].getAttribute('xlink:href');
  10442. }
  10443. if (href != null)
  10444. {
  10445. if (target != null && /^https?:\/\//.test(href))
  10446. {
  10447. links[i].setAttribute('target', target);
  10448. }
  10449. else if (removeCustom && this.isCustomLink(href))
  10450. {
  10451. links[i].setAttribute('href', 'javascript:void(0);');
  10452. }
  10453. }
  10454. }
  10455. }
  10456. };
  10457. /**
  10458. * Hook for creating the canvas used in getSvg.
  10459. */
  10460. Graph.prototype.createSvgCanvas = function(node)
  10461. {
  10462. var canvas = new mxSvgCanvas2D(node);
  10463. canvas.minStrokeWidth = this.cellRenderer.minSvgStrokeWidth;
  10464. canvas.pointerEvents = true;
  10465. return canvas;
  10466. };
  10467. /**
  10468. *
  10469. */
  10470. Graph.prototype.getSelectedTextBlocks = function()
  10471. {
  10472. // See https://stackoverflow.com/questions/667951/how-to-get-nodes-lying-inside-a-range-with-javascript
  10473. function getNextNode(node)
  10474. {
  10475. if (node.firstChild)
  10476. return node.firstChild;
  10477. while (node)
  10478. {
  10479. if (node.nextSibling)
  10480. return node.nextSibling;
  10481. node = node.parentNode;
  10482. }
  10483. };
  10484. function getNodesInRange(range)
  10485. {
  10486. var start = range.startContainer;
  10487. var end = range.endContainer;
  10488. var commonAncestor = range.commonAncestorContainer;
  10489. var nodes = [];
  10490. var node;
  10491. // walk parent nodes from start to common ancestor
  10492. for (node = start.parentNode; node; node = node.parentNode)
  10493. {
  10494. nodes.push(node);
  10495. if (node == commonAncestor)
  10496. break;
  10497. }
  10498. nodes.reverse();
  10499. // walk children and siblings from start until end is found
  10500. for (node = start; node; node = getNextNode(node))
  10501. {
  10502. nodes.push(node);
  10503. if (node == end)
  10504. break;
  10505. }
  10506. return nodes;
  10507. };
  10508. var nodes = [this.getSelectedElement()];
  10509. if (window.getSelection)
  10510. {
  10511. var sel = window.getSelection();
  10512. if (sel.getRangeAt && sel.rangeCount)
  10513. {
  10514. nodes = getNodesInRange(sel.getRangeAt(0));
  10515. }
  10516. }
  10517. var result = [];
  10518. for (var i = 0; i < nodes.length; i++)
  10519. {
  10520. var node = nodes[i];
  10521. while (this.cellEditor.textarea != null &&
  10522. this.cellEditor.textarea.contains(node) &&
  10523. node != this.cellEditor.textarea &&
  10524. node.parentNode != null)
  10525. {
  10526. if (node.nodeType == mxConstants.NODETYPE_ELEMENT &&
  10527. mxUtils.getCurrentStyle(node).display == 'block')
  10528. {
  10529. if (mxUtils.indexOf(result, node) < 0)
  10530. {
  10531. result.push(node);
  10532. }
  10533. break;
  10534. }
  10535. else
  10536. {
  10537. node = node.parentNode;
  10538. }
  10539. }
  10540. }
  10541. return result;
  10542. };
  10543. /**
  10544. * Returns the first ancestor of the current selection with the given name.
  10545. */
  10546. Graph.prototype.getSelectedElement = function()
  10547. {
  10548. var node = null;
  10549. if (window.getSelection)
  10550. {
  10551. var sel = window.getSelection();
  10552. if (sel.getRangeAt && sel.rangeCount)
  10553. {
  10554. var range = sel.getRangeAt(0);
  10555. node = range.commonAncestorContainer;
  10556. }
  10557. }
  10558. else if (document.selection)
  10559. {
  10560. node = document.selection.createRange().parentElement();
  10561. }
  10562. return node;
  10563. };
  10564. /**
  10565. * Returns the text editing element.
  10566. */
  10567. Graph.prototype.getSelectedEditingElement = function()
  10568. {
  10569. var node = this.getSelectedElement();
  10570. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  10571. {
  10572. node = node.parentNode;
  10573. }
  10574. if (node != null)
  10575. {
  10576. // Workaround for commonAncestor on range in IE11 returning parent of common ancestor
  10577. if (node == this.cellEditor.textarea && this.cellEditor.textarea.children.length == 1 &&
  10578. this.cellEditor.textarea.firstChild.nodeType == mxConstants.NODETYPE_ELEMENT)
  10579. {
  10580. node = this.cellEditor.textarea.firstChild;
  10581. }
  10582. }
  10583. return node;
  10584. };
  10585. /**
  10586. * Returns the first ancestor of the current selection with the given name.
  10587. */
  10588. Graph.prototype.getParentByName = function(node, name, stopAt)
  10589. {
  10590. while (node != null)
  10591. {
  10592. if (node.nodeName == name)
  10593. {
  10594. return node;
  10595. }
  10596. if (node == stopAt)
  10597. {
  10598. return null;
  10599. }
  10600. node = node.parentNode;
  10601. }
  10602. return node;
  10603. };
  10604. /**
  10605. * Returns the first ancestor of the current selection with the given name.
  10606. */
  10607. Graph.prototype.getParentByNames = function(node, names, stopAt)
  10608. {
  10609. while (node != null)
  10610. {
  10611. if (mxUtils.indexOf(names, node.nodeName) >= 0)
  10612. {
  10613. return node;
  10614. }
  10615. if (node == stopAt)
  10616. {
  10617. return null;
  10618. }
  10619. node = node.parentNode;
  10620. }
  10621. return node;
  10622. };
  10623. /**
  10624. * Selects the given node.
  10625. */
  10626. Graph.prototype.selectNode = function(node)
  10627. {
  10628. var sel = null;
  10629. // IE9 and non-IE
  10630. if (window.getSelection)
  10631. {
  10632. sel = window.getSelection();
  10633. if (sel.getRangeAt && sel.rangeCount)
  10634. {
  10635. var range = document.createRange();
  10636. range.selectNode(node);
  10637. sel.removeAllRanges();
  10638. sel.addRange(range);
  10639. }
  10640. }
  10641. // IE < 9
  10642. else if ((sel = document.selection) && sel.type != 'Control')
  10643. {
  10644. var originalRange = sel.createRange();
  10645. originalRange.collapse(true);
  10646. var range = sel.createRange();
  10647. range.setEndPoint('StartToStart', originalRange);
  10648. range.select();
  10649. }
  10650. };
  10651. /**
  10652. * Flips the given cells horizontally or vertically.
  10653. */
  10654. Graph.prototype.flipEdgePoints = function(cell, horizontal, c)
  10655. {
  10656. var geo = this.getCellGeometry(cell);
  10657. if (geo != null)
  10658. {
  10659. geo = geo.clone();
  10660. if (geo.points != null)
  10661. {
  10662. for (var i = 0; i < geo.points.length; i++)
  10663. {
  10664. if (horizontal)
  10665. {
  10666. geo.points[i].x = c + (c - geo.points[i].x);
  10667. }
  10668. else
  10669. {
  10670. geo.points[i].y = c + (c - geo.points[i].y);
  10671. }
  10672. }
  10673. }
  10674. var flipTerminalPoint = function(pt)
  10675. {
  10676. if (pt != null)
  10677. {
  10678. if (horizontal)
  10679. {
  10680. pt.x = c + (c - pt.x);
  10681. }
  10682. else
  10683. {
  10684. pt.y = c + (c - pt.y);
  10685. }
  10686. }
  10687. };
  10688. flipTerminalPoint(geo.getTerminalPoint(true));
  10689. flipTerminalPoint(geo.getTerminalPoint(false));
  10690. this.model.setGeometry(cell, geo);
  10691. }
  10692. };
  10693. /**
  10694. * Flips the given cells horizontally or vertically.
  10695. */
  10696. Graph.prototype.flipChildren = function(cell, horizontal, c)
  10697. {
  10698. this.model.beginUpdate();
  10699. try
  10700. {
  10701. var childCount = this.model.getChildCount(cell);
  10702. for (var i = 0; i < childCount; i++)
  10703. {
  10704. var child = this.model.getChildAt(cell, i);
  10705. if (this.model.isEdge(child))
  10706. {
  10707. this.flipEdgePoints(child, horizontal, c);
  10708. }
  10709. else
  10710. {
  10711. var geo = this.getCellGeometry(child);
  10712. if (geo != null)
  10713. {
  10714. geo = geo.clone();
  10715. if (horizontal)
  10716. {
  10717. geo.x = c + (c - geo.x - geo.width);
  10718. }
  10719. else
  10720. {
  10721. geo.y = c + (c - geo.y - geo.height);
  10722. }
  10723. this.model.setGeometry(child, geo);
  10724. }
  10725. }
  10726. }
  10727. }
  10728. finally
  10729. {
  10730. this.model.endUpdate();
  10731. }
  10732. };
  10733. /**
  10734. * Flips the given cells horizontally or vertically.
  10735. */
  10736. Graph.prototype.flipCells = function(cells, horizontal)
  10737. {
  10738. this.model.beginUpdate();
  10739. try
  10740. {
  10741. cells = this.model.getTopmostCells(cells);
  10742. var vertices = [];
  10743. for (var i = 0; i < cells.length; i++)
  10744. {
  10745. if (this.model.isEdge(cells[i]))
  10746. {
  10747. var state = this.view.getState(cells[i]);
  10748. if (state != null)
  10749. {
  10750. this.flipEdgePoints(cells[i], horizontal, ((horizontal ? state.getCenterX() :
  10751. state.getCenterY()) / this.view.scale) - ((horizontal) ?
  10752. state.origin.x : state.origin.y) - ((horizontal) ?
  10753. this.view.translate.x : this.view.translate.y));
  10754. }
  10755. }
  10756. else
  10757. {
  10758. var geo = this.getCellGeometry(cells[i]);
  10759. if (geo != null)
  10760. {
  10761. this.flipChildren(cells[i], horizontal, horizontal ?
  10762. geo.getCenterX() - geo.x :
  10763. geo.getCenterY() - geo.y);
  10764. }
  10765. vertices.push(cells[i]);
  10766. }
  10767. }
  10768. this.toggleCellStyles(horizontal ? mxConstants.STYLE_FLIPH :
  10769. mxConstants.STYLE_FLIPV, false, vertices);
  10770. }
  10771. finally
  10772. {
  10773. this.model.endUpdate();
  10774. }
  10775. };
  10776. /**
  10777. * Deletes the given cells and returns the cells to be selected.
  10778. */
  10779. Graph.prototype.deleteCells = function(cells, includeEdges)
  10780. {
  10781. var select = null;
  10782. if (cells != null && cells.length > 0)
  10783. {
  10784. this.model.beginUpdate();
  10785. try
  10786. {
  10787. // Shrinks tables
  10788. for (var i = 0; i < cells.length; i++)
  10789. {
  10790. var parent = this.model.getParent(cells[i]);
  10791. if (this.isTable(parent))
  10792. {
  10793. var row = this.getCellGeometry(cells[i]);
  10794. var table = this.getCellGeometry(parent);
  10795. if (row != null && table != null)
  10796. {
  10797. table = table.clone();
  10798. table.height -= row.height;
  10799. this.model.setGeometry(parent, table);
  10800. }
  10801. }
  10802. }
  10803. var parents = (this.selectParentAfterDelete) ? this.model.getParents(cells) : null;
  10804. this.removeCells(cells, includeEdges);
  10805. }
  10806. finally
  10807. {
  10808. this.model.endUpdate();
  10809. }
  10810. // Selects parents for easier editing of groups
  10811. if (parents != null)
  10812. {
  10813. select = [];
  10814. for (var i = 0; i < parents.length; i++)
  10815. {
  10816. if (this.model.contains(parents[i]) &&
  10817. (this.model.isVertex(parents[i]) ||
  10818. this.model.isEdge(parents[i])))
  10819. {
  10820. select.push(parents[i]);
  10821. }
  10822. }
  10823. }
  10824. }
  10825. return select;
  10826. };
  10827. /**
  10828. * Inserts a column in the table for the given cell.
  10829. */
  10830. Graph.prototype.insertTableColumn = function(cell, before)
  10831. {
  10832. var model = this.getModel();
  10833. model.beginUpdate();
  10834. try
  10835. {
  10836. var table = cell;
  10837. var index = 0;
  10838. if (this.isTableCell(cell))
  10839. {
  10840. var row = model.getParent(cell);
  10841. table = model.getParent(row);
  10842. index = mxUtils.indexOf(model.getChildCells(row, true), cell);
  10843. }
  10844. else
  10845. {
  10846. if (this.isTableRow(cell))
  10847. {
  10848. table = model.getParent(cell);
  10849. }
  10850. else
  10851. {
  10852. cell = model.getChildCells(table, true)[0];
  10853. }
  10854. if (!before)
  10855. {
  10856. index = model.getChildCells(cell, true).length - 1;
  10857. }
  10858. }
  10859. var rows = model.getChildCells(table, true);
  10860. var dw = Graph.minTableColumnWidth;
  10861. for (var i = 0; i < rows.length; i++)
  10862. {
  10863. var child = model.getChildCells(rows[i], true)[index];
  10864. var clone = model.cloneCell(child, false);
  10865. // Handles possible missing child in row
  10866. if (clone == null)
  10867. {
  10868. clone = this.createVertex();
  10869. }
  10870. var geo = this.getCellGeometry(clone);
  10871. // Removes value, col/rowspan and alternate bounds
  10872. clone.value = null;
  10873. clone.style = mxUtils.setStyle(mxUtils.setStyle(
  10874. clone.style, 'rowspan', null), 'colspan', null);
  10875. if (geo != null)
  10876. {
  10877. if (geo.alternateBounds != null)
  10878. {
  10879. geo.width = geo.alternateBounds.width;
  10880. geo.height = geo.alternateBounds.height;
  10881. geo.alternateBounds = null;
  10882. }
  10883. dw = geo.width;
  10884. var rowGeo = this.getCellGeometry(rows[i]);
  10885. if (rowGeo != null)
  10886. {
  10887. geo.height = rowGeo.height;
  10888. }
  10889. }
  10890. model.add(rows[i], clone, index + ((before) ? 0 : 1));
  10891. }
  10892. var tableGeo = this.getCellGeometry(table);
  10893. if (tableGeo != null)
  10894. {
  10895. tableGeo = tableGeo.clone();
  10896. tableGeo.width += dw;
  10897. model.setGeometry(table, tableGeo);
  10898. }
  10899. }
  10900. finally
  10901. {
  10902. model.endUpdate();
  10903. }
  10904. };
  10905. /**
  10906. * Inserts a row in the table for the given cell.
  10907. */
  10908. Graph.prototype.deleteLane = function(cell)
  10909. {
  10910. var model = this.getModel();
  10911. model.beginUpdate();
  10912. try
  10913. {
  10914. var pool = null;
  10915. var lane = cell;
  10916. var style = this.getCurrentCellStyle(lane);
  10917. if (style['childLayout'] == 'stackLayout')
  10918. {
  10919. pool = lane;
  10920. }
  10921. else
  10922. {
  10923. pool = model.getParent(lane);
  10924. }
  10925. var lanes = model.getChildCells(pool, true);
  10926. if (lanes.length == 0)
  10927. {
  10928. model.remove(pool);
  10929. }
  10930. else
  10931. {
  10932. if (pool == lane)
  10933. {
  10934. lane = lanes[lanes.length - 1];
  10935. }
  10936. model.remove(lane);
  10937. }
  10938. }
  10939. finally
  10940. {
  10941. model.endUpdate();
  10942. }
  10943. };
  10944. /**
  10945. * Inserts a row in the table for the given cell.
  10946. */
  10947. Graph.prototype.insertLane = function(cell, before)
  10948. {
  10949. var model = this.getModel();
  10950. model.beginUpdate();
  10951. try
  10952. {
  10953. var pool = null;
  10954. var lane = cell;
  10955. var style = this.getCurrentCellStyle(lane);
  10956. if (style['childLayout'] == 'stackLayout')
  10957. {
  10958. pool = lane;
  10959. var lanes = model.getChildCells(pool, true);
  10960. lane = lanes[(before) ? 0 : lanes.length - 1];
  10961. }
  10962. else
  10963. {
  10964. pool = model.getParent(lane);
  10965. }
  10966. var index = pool.getIndex(lane);
  10967. lane = model.cloneCell(lane, false);
  10968. lane.value = null;
  10969. model.add(pool, lane, index + ((before) ? 0 : 1));
  10970. }
  10971. finally
  10972. {
  10973. model.endUpdate();
  10974. }
  10975. };
  10976. /**
  10977. * Inserts a row in the table for the given cell.
  10978. */
  10979. Graph.prototype.insertTableRow = function(cell, before)
  10980. {
  10981. var model = this.getModel();
  10982. model.beginUpdate();
  10983. try
  10984. {
  10985. var table = cell;
  10986. var row = cell;
  10987. if (this.isTableCell(cell))
  10988. {
  10989. row = model.getParent(cell);
  10990. table = model.getParent(row);
  10991. }
  10992. else if (this.isTableRow(cell))
  10993. {
  10994. table = model.getParent(cell);
  10995. }
  10996. else
  10997. {
  10998. var rows = model.getChildCells(table, true);
  10999. row = rows[(before) ? 0 : rows.length - 1];
  11000. }
  11001. var cells = model.getChildCells(row, true);
  11002. var index = table.getIndex(row);
  11003. row = model.cloneCell(row, false);
  11004. row.value = null;
  11005. var rowGeo = this.getCellGeometry(row);
  11006. if (rowGeo != null)
  11007. {
  11008. for (var i = 0; i < cells.length; i++)
  11009. {
  11010. var cell = model.cloneCell(cells[i], false);
  11011. // Removes value, col/rowspan and alternate bounds
  11012. cell.value = null;
  11013. cell.style = mxUtils.setStyle(mxUtils.setStyle(
  11014. cell.style, 'rowspan', null), 'colspan', null);
  11015. var geo = this.getCellGeometry(cell);
  11016. if (geo != null)
  11017. {
  11018. if (geo.alternateBounds != null)
  11019. {
  11020. geo.width = geo.alternateBounds.width;
  11021. geo.height = geo.alternateBounds.height;
  11022. geo.alternateBounds = null;
  11023. }
  11024. geo.height = rowGeo.height;
  11025. }
  11026. row.insert(cell);
  11027. }
  11028. model.add(table, row, index + ((before) ? 0 : 1));
  11029. var tableGeo = this.getCellGeometry(table);
  11030. if (tableGeo != null)
  11031. {
  11032. tableGeo = tableGeo.clone();
  11033. tableGeo.height += rowGeo.height;
  11034. model.setGeometry(table, tableGeo);
  11035. }
  11036. }
  11037. }
  11038. finally
  11039. {
  11040. model.endUpdate();
  11041. }
  11042. };
  11043. /**
  11044. *
  11045. */
  11046. Graph.prototype.deleteTableColumn = function(cell)
  11047. {
  11048. var model = this.getModel();
  11049. model.beginUpdate();
  11050. try
  11051. {
  11052. var table = cell;
  11053. var row = cell;
  11054. if (this.isTableCell(cell))
  11055. {
  11056. row = model.getParent(cell);
  11057. }
  11058. if (this.isTableRow(row))
  11059. {
  11060. table = model.getParent(row);
  11061. }
  11062. var rows = model.getChildCells(table, true);
  11063. if (rows.length == 0)
  11064. {
  11065. model.remove(table);
  11066. }
  11067. else
  11068. {
  11069. if (!this.isTableRow(row))
  11070. {
  11071. row = rows[0];
  11072. }
  11073. var cells = model.getChildCells(row, true);
  11074. if (cells.length <= 1)
  11075. {
  11076. model.remove(table);
  11077. }
  11078. else
  11079. {
  11080. var index = cells.length - 1;
  11081. if (this.isTableCell(cell))
  11082. {
  11083. index = mxUtils.indexOf(cells, cell);
  11084. }
  11085. var width = 0;
  11086. for (var i = 0; i < rows.length; i++)
  11087. {
  11088. var child = model.getChildCells(rows[i], true)[index];
  11089. model.remove(child);
  11090. var geo = this.getCellGeometry(child);
  11091. if (geo != null)
  11092. {
  11093. width = Math.max(width, geo.width);
  11094. }
  11095. }
  11096. var tableGeo = this.getCellGeometry(table);
  11097. if (tableGeo != null)
  11098. {
  11099. tableGeo = tableGeo.clone();
  11100. tableGeo.width -= width;
  11101. model.setGeometry(table, tableGeo);
  11102. }
  11103. }
  11104. }
  11105. }
  11106. finally
  11107. {
  11108. model.endUpdate();
  11109. }
  11110. };
  11111. /**
  11112. *
  11113. */
  11114. Graph.prototype.deleteTableRow = function(cell)
  11115. {
  11116. var model = this.getModel();
  11117. model.beginUpdate();
  11118. try
  11119. {
  11120. var table = cell;
  11121. var row = cell;
  11122. if (this.isTableCell(cell))
  11123. {
  11124. row = model.getParent(cell);
  11125. cell = row;
  11126. }
  11127. if (this.isTableRow(cell))
  11128. {
  11129. table = model.getParent(row);
  11130. }
  11131. var rows = model.getChildCells(table, true);
  11132. if (rows.length <= 1)
  11133. {
  11134. model.remove(table);
  11135. }
  11136. else
  11137. {
  11138. if (!this.isTableRow(row))
  11139. {
  11140. row = rows[rows.length - 1];
  11141. }
  11142. model.remove(row);
  11143. var height = 0;
  11144. var geo = this.getCellGeometry(row);
  11145. if (geo != null)
  11146. {
  11147. height = geo.height;
  11148. }
  11149. var tableGeo = this.getCellGeometry(table);
  11150. if (tableGeo != null)
  11151. {
  11152. tableGeo = tableGeo.clone();
  11153. tableGeo.height -= height;
  11154. model.setGeometry(table, tableGeo);
  11155. }
  11156. }
  11157. }
  11158. finally
  11159. {
  11160. model.endUpdate();
  11161. }
  11162. };
  11163. /**
  11164. * Inserts a new row into the given table.
  11165. */
  11166. Graph.prototype.insertRow = function(table, index)
  11167. {
  11168. var bd = table.tBodies[0];
  11169. var cells = bd.rows[0].cells;
  11170. var cols = 0;
  11171. // Counts columns including colspans
  11172. for (var i = 0; i < cells.length; i++)
  11173. {
  11174. var colspan = cells[i].getAttribute('colspan');
  11175. cols += (colspan != null) ? parseInt(colspan) : 1;
  11176. }
  11177. var row = bd.insertRow(index);
  11178. for (var i = 0; i < cols; i++)
  11179. {
  11180. mxUtils.br(row.insertCell(-1));
  11181. }
  11182. return row.cells[0];
  11183. };
  11184. /**
  11185. * Deletes the given column.
  11186. */
  11187. Graph.prototype.deleteRow = function(table, index)
  11188. {
  11189. table.tBodies[0].deleteRow(index);
  11190. };
  11191. /**
  11192. * Deletes the given column.
  11193. */
  11194. Graph.prototype.insertColumn = function(table, index)
  11195. {
  11196. var hd = table.tHead;
  11197. if (hd != null)
  11198. {
  11199. // TODO: use colIndex
  11200. for (var h = 0; h < hd.rows.length; h++)
  11201. {
  11202. var th = document.createElement('th');
  11203. hd.rows[h].appendChild(th);
  11204. mxUtils.br(th);
  11205. }
  11206. }
  11207. var bd = table.tBodies[0];
  11208. for (var i = 0; i < bd.rows.length; i++)
  11209. {
  11210. var cell = bd.rows[i].insertCell(index);
  11211. mxUtils.br(cell);
  11212. }
  11213. return bd.rows[0].cells[(index >= 0) ? index : bd.rows[0].cells.length - 1];
  11214. };
  11215. /**
  11216. * Deletes the given column.
  11217. */
  11218. Graph.prototype.deleteColumn = function(table, index)
  11219. {
  11220. if (index >= 0)
  11221. {
  11222. var bd = table.tBodies[0];
  11223. var rows = bd.rows;
  11224. for (var i = 0; i < rows.length; i++)
  11225. {
  11226. if (rows[i].cells.length > index)
  11227. {
  11228. rows[i].deleteCell(index);
  11229. }
  11230. }
  11231. }
  11232. };
  11233. /**
  11234. * Inserts the given HTML at the caret position (no undo).
  11235. */
  11236. Graph.prototype.pasteHtmlAtCaret = function(html)
  11237. {
  11238. var sel, range;
  11239. // IE9 and non-IE
  11240. if (window.getSelection)
  11241. {
  11242. sel = window.getSelection();
  11243. if (sel.getRangeAt && sel.rangeCount)
  11244. {
  11245. range = sel.getRangeAt(0);
  11246. range.deleteContents();
  11247. // Range.createContextualFragment() would be useful here but is
  11248. // only relatively recently standardized and is not supported in
  11249. // some browsers (IE9, for one)
  11250. var el = document.createElement("div");
  11251. el.innerHTML = html;
  11252. var frag = document.createDocumentFragment(), node;
  11253. while ((node = el.firstChild))
  11254. {
  11255. lastNode = frag.appendChild(node);
  11256. }
  11257. range.insertNode(frag);
  11258. }
  11259. }
  11260. // IE < 9
  11261. else if ((sel = document.selection) && sel.type != "Control")
  11262. {
  11263. // FIXME: Does not work if selection is empty
  11264. sel.createRange().pasteHTML(html);
  11265. }
  11266. };
  11267. /**
  11268. * Creates an anchor elements for handling the given link in the
  11269. * hint that is shown when the cell is selected.
  11270. */
  11271. Graph.prototype.createLinkForHint = function(link, label, associatedCell)
  11272. {
  11273. link = (link != null) ? link : 'javascript:void(0);';
  11274. if (label == null || label.length == 0)
  11275. {
  11276. if (this.isCustomLink(link))
  11277. {
  11278. label = this.getLinkTitle(link);
  11279. }
  11280. else
  11281. {
  11282. label = link;
  11283. }
  11284. }
  11285. // Helper function to shorten strings
  11286. function short(str, max)
  11287. {
  11288. if (str.length > max)
  11289. {
  11290. str = str.substring(0, Math.round(max / 2)) + '...' +
  11291. str.substring(str.length - Math.round(max / 4));
  11292. }
  11293. return str;
  11294. };
  11295. var a = document.createElement('a');
  11296. a.setAttribute('rel', this.linkRelation);
  11297. a.setAttribute('href', this.getAbsoluteUrl(link));
  11298. a.setAttribute('title', short((this.isCustomLink(link)) ?
  11299. this.getLinkTitle(link) : link, 80));
  11300. if (this.linkTarget != null)
  11301. {
  11302. a.setAttribute('target', this.linkTarget);
  11303. }
  11304. // Adds shortened label to link
  11305. mxUtils.write(a, short(label, 40));
  11306. // Handles custom links
  11307. if (this.isCustomLink(link))
  11308. {
  11309. mxEvent.addListener(a, 'click', mxUtils.bind(this, function(evt)
  11310. {
  11311. this.customLinkClicked(link, associatedCell);
  11312. mxEvent.consume(evt);
  11313. }));
  11314. }
  11315. return a;
  11316. };
  11317. /**
  11318. * Customized graph for touch devices.
  11319. */
  11320. Graph.prototype.initTouch = function()
  11321. {
  11322. // Disables new connections via "hotspot"
  11323. this.connectionHandler.marker.isEnabled = function()
  11324. {
  11325. return this.graph.connectionHandler.first != null;
  11326. };
  11327. // Hides menu when editing starts
  11328. this.addListener(mxEvent.START_EDITING, function(sender, evt)
  11329. {
  11330. this.popupMenuHandler.hideMenu();
  11331. });
  11332. // Adds custom hit detection if native hit detection found no cell
  11333. var graphUpdateMouseEvent = this.updateMouseEvent;
  11334. this.updateMouseEvent = function(me)
  11335. {
  11336. me = graphUpdateMouseEvent.apply(this, arguments);
  11337. if (mxEvent.isTouchEvent(me.getEvent()) && me.getState() == null)
  11338. {
  11339. var cell = this.getCellAt(me.graphX, me.graphY);
  11340. if (cell != null && this.isSwimlane(cell) && this.hitsSwimlaneContent(cell, me.graphX, me.graphY))
  11341. {
  11342. cell = null;
  11343. }
  11344. else
  11345. {
  11346. me.state = this.view.getState(cell);
  11347. if (me.state != null && me.state.shape != null)
  11348. {
  11349. this.container.style.cursor = me.state.shape.node.style.cursor;
  11350. }
  11351. }
  11352. }
  11353. if (me.getState() == null && this.isEnabled())
  11354. {
  11355. this.container.style.cursor = 'default';
  11356. }
  11357. return me;
  11358. };
  11359. // Context menu trigger implementation depending on current selection state
  11360. // combined with support for normal popup trigger.
  11361. var cellSelected = false;
  11362. var selectionEmpty = false;
  11363. var menuShowing = false;
  11364. var oldFireMouseEvent = this.fireMouseEvent;
  11365. this.fireMouseEvent = function(evtName, me, sender)
  11366. {
  11367. if (evtName == mxEvent.MOUSE_DOWN)
  11368. {
  11369. // For hit detection on edges
  11370. me = this.updateMouseEvent(me);
  11371. cellSelected = this.isCellSelected(me.getCell());
  11372. selectionEmpty = this.isSelectionEmpty();
  11373. menuShowing = this.popupMenuHandler.isMenuShowing();
  11374. }
  11375. oldFireMouseEvent.apply(this, arguments);
  11376. };
  11377. // Shows popup menu if cell was selected or selection was empty and background was clicked
  11378. // FIXME: Conflicts with mxPopupMenuHandler.prototype.getCellForPopupEvent in Editor.js by
  11379. // selecting parent for selected children in groups before this check can be made.
  11380. this.popupMenuHandler.mouseUp = mxUtils.bind(this, function(sender, me)
  11381. {
  11382. if (this.freehand != null && (!this.freehand.isDrawing()))
  11383. {
  11384. var isMouseEvent = mxEvent.isMouseEvent(me.getEvent());
  11385. this.popupMenuHandler.popupTrigger = !this.isEditing() && this.isEnabled() &&
  11386. (me.getState() == null || !me.isSource(me.getState().control)) &&
  11387. (this.popupMenuHandler.popupTrigger || (!menuShowing && !isMouseEvent &&
  11388. ((selectionEmpty && me.getCell() == null && this.isSelectionEmpty()) ||
  11389. (cellSelected && this.isCellSelected(me.getCell())))));
  11390. // Delays popup menu to allow for double tap to start editing
  11391. var popup = (!cellSelected || isMouseEvent) ? null : mxUtils.bind(this, function(cell)
  11392. {
  11393. window.setTimeout(mxUtils.bind(this, function()
  11394. {
  11395. if (!this.isEditing())
  11396. {
  11397. var origin = mxUtils.getScrollOrigin();
  11398. this.popupMenuHandler.popup(me.getX() + origin.x + 1,
  11399. me.getY() + origin.y + 1, cell, me.getEvent());
  11400. }
  11401. }), 300);
  11402. });
  11403. mxPopupMenuHandler.prototype.mouseUp.apply(this.popupMenuHandler, [sender, me, popup]);
  11404. }
  11405. });
  11406. };
  11407. /**
  11408. * HTML in-place editor
  11409. */
  11410. mxCellEditor.prototype.isContentEditing = function()
  11411. {
  11412. var state = this.graph.view.getState(this.editingCell);
  11413. return state != null && state.style['html'] == 1;
  11414. };
  11415. /**
  11416. * Returns true if all selected text is inside a table element.
  11417. */
  11418. mxCellEditor.prototype.isTableSelected = function()
  11419. {
  11420. return this.graph.getParentByName(
  11421. this.graph.getSelectedElement(),
  11422. 'TABLE', this.textarea) != null;
  11423. };
  11424. /**
  11425. * Returns true if text is selected.
  11426. */
  11427. mxCellEditor.prototype.isTextSelected = function()
  11428. {
  11429. var txt = '';
  11430. if (window.getSelection)
  11431. {
  11432. txt = window.getSelection();
  11433. }
  11434. else if (document.getSelection)
  11435. {
  11436. txt = document.getSelection();
  11437. }
  11438. else if (document.selection)
  11439. {
  11440. txt = document.selection.createRange().text;
  11441. }
  11442. return txt != '';
  11443. };
  11444. /**
  11445. * Inserts a tab at the cursor position.
  11446. */
  11447. mxCellEditor.prototype.insertTab = function(spaces)
  11448. {
  11449. var editor = this.textarea;
  11450. var doc = editor.ownerDocument.defaultView;
  11451. var sel = doc.getSelection();
  11452. var range = sel.getRangeAt(0);
  11453. var tabNode = Graph.createTabNode(spaces);
  11454. range.insertNode(tabNode);
  11455. range.setStartAfter(tabNode);
  11456. range.setEndAfter(tabNode);
  11457. sel.removeAllRanges();
  11458. sel.addRange(range);
  11459. };
  11460. /**
  11461. * Sets the alignment of the current selected cell. This sets the
  11462. * alignment in the cell style, removes all alignment within the
  11463. * text and invokes the built-in alignment function.
  11464. *
  11465. * Only the built-in function is invoked if shift is pressed or
  11466. * if table cells are selected and shift is not pressed.
  11467. */
  11468. mxCellEditor.prototype.alignText = function(align, evt)
  11469. {
  11470. var state = this.graph.getView().getState(this.editingCell);
  11471. if (state != null)
  11472. {
  11473. var dir = mxUtils.getValue(state.style, mxConstants.STYLE_TEXT_DIRECTION,
  11474. mxConstants.DEFAULT_TEXT_DIRECTION);
  11475. var vertical = dir != null && dir.substring(0, 9) == 'vertical-';
  11476. var shiftPressed = evt != null && mxEvent.isShiftDown(evt);
  11477. if (shiftPressed || (window.getSelection != null &&
  11478. window.getSelection().containsNode != null))
  11479. {
  11480. var allSelected = true;
  11481. this.graph.processElements(this.textarea, function(node)
  11482. {
  11483. if (shiftPressed || vertical ||
  11484. window.getSelection().containsNode(node, true))
  11485. {
  11486. node.removeAttribute('align');
  11487. node.style.textAlign = null;
  11488. }
  11489. else
  11490. {
  11491. allSelected = false;
  11492. }
  11493. });
  11494. if (allSelected || vertical)
  11495. {
  11496. this.graph.cellEditor.setAlign(align);
  11497. }
  11498. }
  11499. if (!vertical)
  11500. {
  11501. document.execCommand('justify' + align.toLowerCase(), false, null);
  11502. }
  11503. }
  11504. };
  11505. /**
  11506. * Creates the keyboard event handler for the current graph and history.
  11507. */
  11508. mxCellEditor.prototype.saveSelection = function()
  11509. {
  11510. if (window.getSelection)
  11511. {
  11512. var sel = window.getSelection();
  11513. if (sel.getRangeAt && sel.rangeCount)
  11514. {
  11515. var ranges = [];
  11516. for (var i = 0, len = sel.rangeCount; i < len; ++i)
  11517. {
  11518. ranges.push(sel.getRangeAt(i));
  11519. }
  11520. return ranges;
  11521. }
  11522. }
  11523. else if (document.selection && document.selection.createRange)
  11524. {
  11525. return document.selection.createRange();
  11526. }
  11527. return null;
  11528. };
  11529. /**
  11530. * Creates the keyboard event handler for the current graph and history.
  11531. */
  11532. mxCellEditor.prototype.restoreSelection = function(savedSel)
  11533. {
  11534. try
  11535. {
  11536. if (savedSel)
  11537. {
  11538. if (window.getSelection)
  11539. {
  11540. sel = window.getSelection();
  11541. sel.removeAllRanges();
  11542. for (var i = 0, len = savedSel.length; i < len; ++i)
  11543. {
  11544. sel.addRange(savedSel[i]);
  11545. }
  11546. }
  11547. else if (document.selection && savedSel.select)
  11548. {
  11549. savedSel.select();
  11550. }
  11551. }
  11552. }
  11553. catch (e)
  11554. {
  11555. // ignore
  11556. }
  11557. };
  11558. /**
  11559. * Handling of special nl2Br style for not converting newlines to breaks in HTML labels.
  11560. * NOTE: Since it's easier to set this when the label is created we assume that it does
  11561. * not change during the lifetime of the mxText instance.
  11562. */
  11563. var mxCellRendererInitializeLabel = mxCellRenderer.prototype.initializeLabel;
  11564. mxCellRenderer.prototype.initializeLabel = function(state)
  11565. {
  11566. if (state.text != null)
  11567. {
  11568. state.text.replaceLinefeeds = mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  11569. }
  11570. mxCellRendererInitializeLabel.apply(this, arguments);
  11571. };
  11572. var mxConstraintHandlerUpdate = mxConstraintHandler.prototype.update;
  11573. mxConstraintHandler.prototype.update = function(me, source)
  11574. {
  11575. if (this.isKeepFocusEvent(me) || !mxEvent.isAltDown(me.getEvent()))
  11576. {
  11577. mxConstraintHandlerUpdate.apply(this, arguments);
  11578. }
  11579. else
  11580. {
  11581. this.reset();
  11582. }
  11583. };
  11584. /**
  11585. * No dashed shapes.
  11586. */
  11587. mxGuide.prototype.createGuideShape = function(horizontal)
  11588. {
  11589. var guide = new mxPolyline([], mxConstants.GUIDE_COLOR, mxConstants.GUIDE_STROKEWIDTH);
  11590. return guide;
  11591. };
  11592. /**
  11593. * HTML in-place editor
  11594. */
  11595. mxCellEditor.prototype.escapeCancelsEditing = false;
  11596. /**
  11597. * Overridden to set CSS classes.
  11598. */
  11599. var mxCellEditorStartEditing = mxCellEditor.prototype.startEditing;
  11600. mxCellEditor.prototype.startEditing = function(cell, trigger)
  11601. {
  11602. cell = this.graph.getStartEditingCell(cell, trigger);
  11603. mxCellEditorStartEditing.apply(this, arguments);
  11604. // Overrides class in case of HTML content to add
  11605. // dashed borders for divs and table cells
  11606. var state = this.graph.view.getState(cell);
  11607. if (state != null && state.style['html'] == 1)
  11608. {
  11609. this.textarea.className = 'mxCellEditor geContentEditable';
  11610. }
  11611. else
  11612. {
  11613. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  11614. }
  11615. // Toggles markup vs wysiwyg mode
  11616. this.codeViewMode = false;
  11617. // Stores current selection range when switching between markup and code
  11618. this.switchSelectionState = null;
  11619. // Selects editing cell
  11620. this.graph.setSelectionCell(cell);
  11621. }
  11622. mxCellEditor.prototype.toggleViewMode = function()
  11623. {
  11624. var state = this.graph.view.getState(this.editingCell);
  11625. if (state != null)
  11626. {
  11627. var nl2Br = state != null && mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  11628. var tmp = this.saveSelection();
  11629. if (!this.codeViewMode)
  11630. {
  11631. // Clears the initial empty label on the first keystroke
  11632. if (this.clearOnChange && this.textarea.innerHTML == this.getEmptyLabelText())
  11633. {
  11634. this.clearOnChange = false;
  11635. this.textarea.innerText = '';
  11636. }
  11637. // Removes newlines from HTML and converts breaks to newlines
  11638. // to match the HTML output in plain text
  11639. var content = mxUtils.htmlEntities(this.textarea.innerHTML);
  11640. // Workaround for trailing line breaks being ignored in the editor
  11641. if (document.documentMode != 8)
  11642. {
  11643. content = mxUtils.replaceTrailingNewlines(content, '<div><br></div>');
  11644. }
  11645. content = Graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '').
  11646. replace(/&lt;br\s*.?&gt;/g, '<br>') : content, true);
  11647. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  11648. var size = mxConstants.DEFAULT_FONTSIZE;
  11649. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ?
  11650. Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  11651. this.textarea.style.fontSize = Math.round(size) + 'px';
  11652. this.textarea.style.textDecoration = '';
  11653. this.textarea.style.fontWeight = 'normal';
  11654. this.textarea.style.fontStyle = '';
  11655. this.textarea.style.fontFamily = mxConstants.DEFAULT_FONTFAMILY;
  11656. this.textarea.style.textAlign = 'left';
  11657. this.textarea.style.width = '';
  11658. // Adds padding to make cursor visible with borders
  11659. this.textarea.style.padding = '2px';
  11660. if (this.textarea.innerHTML != content)
  11661. {
  11662. this.textarea.innerHTML = content;
  11663. }
  11664. this.codeViewMode = true;
  11665. }
  11666. else
  11667. {
  11668. var content = mxUtils.extractTextWithWhitespace(this.textarea.childNodes);
  11669. // Strips trailing line break
  11670. if (content.length > 0 && content.charAt(content.length - 1) == '\n')
  11671. {
  11672. content = content.substring(0, content.length - 1);
  11673. }
  11674. content = Graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '<br/>') : content, true)
  11675. this.textarea.className = 'mxCellEditor geContentEditable';
  11676. var size = mxUtils.getValue(state.style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  11677. var family = mxUtils.getValue(state.style, mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY);
  11678. var align = mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_LEFT);
  11679. var bold = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  11680. mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD;
  11681. var italic = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  11682. mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC;
  11683. var txtDecor = [];
  11684. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  11685. mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  11686. {
  11687. txtDecor.push('underline');
  11688. }
  11689. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  11690. mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  11691. {
  11692. txtDecor.push('line-through');
  11693. }
  11694. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  11695. this.textarea.style.fontSize = Math.round(size) + 'px';
  11696. this.textarea.style.textDecoration = txtDecor.join(' ');
  11697. this.textarea.style.fontWeight = (bold) ? 'bold' : 'normal';
  11698. this.textarea.style.fontStyle = (italic) ? 'italic' : '';
  11699. this.textarea.style.fontFamily = family;
  11700. this.textarea.style.textAlign = align;
  11701. this.textarea.style.padding = '0px';
  11702. if (this.textarea.innerHTML != content)
  11703. {
  11704. this.textarea.innerHTML = content;
  11705. if (this.textarea.innerHTML.length == 0)
  11706. {
  11707. this.textarea.innerHTML = this.getEmptyLabelText();
  11708. this.clearOnChange = this.textarea.innerHTML.length > 0;
  11709. }
  11710. }
  11711. this.codeViewMode = false;
  11712. }
  11713. this.textarea.focus();
  11714. if (this.switchSelectionState != null)
  11715. {
  11716. this.restoreSelection(this.switchSelectionState);
  11717. }
  11718. this.switchSelectionState = tmp;
  11719. this.resize();
  11720. }
  11721. };
  11722. var mxCellEditorResize = mxCellEditor.prototype.resize;
  11723. mxCellEditor.prototype.resize = function(state, trigger)
  11724. {
  11725. if (this.textarea != null)
  11726. {
  11727. var state = this.graph.getView().getState(this.editingCell);
  11728. if (this.codeViewMode && state != null)
  11729. {
  11730. var scale = state.view.scale;
  11731. this.bounds = mxRectangle.fromRectangle(state);
  11732. // General placement of code editor if cell has no size
  11733. // LATER: Fix HTML editor bounds for edge labels
  11734. if (this.bounds.width == 0 && this.bounds.height == 0)
  11735. {
  11736. this.bounds.width = 160 * scale;
  11737. this.bounds.height = 60 * scale;
  11738. var m = (state.text != null) ? state.text.margin : null;
  11739. if (m == null)
  11740. {
  11741. m = mxUtils.getAlignmentAsPoint(mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER),
  11742. mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE));
  11743. }
  11744. this.bounds.x += m.x * this.bounds.width;
  11745. this.bounds.y += m.y * this.bounds.height;
  11746. }
  11747. this.textarea.style.width = Math.round((this.bounds.width - 4) / scale) + 'px';
  11748. this.textarea.style.height = Math.round((this.bounds.height - 4) / scale) + 'px';
  11749. this.textarea.style.overflow = 'auto';
  11750. // Adds scrollbar offset if visible
  11751. if (this.textarea.clientHeight < this.textarea.offsetHeight)
  11752. {
  11753. this.textarea.style.height = Math.round((this.bounds.height / scale)) + (this.textarea.offsetHeight - this.textarea.clientHeight) + 'px';
  11754. this.bounds.height = parseInt(this.textarea.style.height) * scale;
  11755. }
  11756. if (this.textarea.clientWidth < this.textarea.offsetWidth)
  11757. {
  11758. this.textarea.style.width = Math.round((this.bounds.width / scale)) + (this.textarea.offsetWidth - this.textarea.clientWidth) + 'px';
  11759. this.bounds.width = parseInt(this.textarea.style.width) * scale;
  11760. }
  11761. this.textarea.style.left = Math.round(this.bounds.x) + 'px';
  11762. this.textarea.style.top = Math.round(this.bounds.y) + 'px';
  11763. mxUtils.setPrefixedStyle(this.textarea.style, 'transform', 'scale(' + scale + ',' + scale + ')');
  11764. }
  11765. else
  11766. {
  11767. this.textarea.style.height = '';
  11768. this.textarea.style.overflow = '';
  11769. mxCellEditorResize.apply(this, arguments);
  11770. }
  11771. }
  11772. };
  11773. mxCellEditorGetInitialValue = mxCellEditor.prototype.getInitialValue;
  11774. mxCellEditor.prototype.getInitialValue = function(state, trigger)
  11775. {
  11776. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  11777. {
  11778. return mxCellEditorGetInitialValue.apply(this, arguments);
  11779. }
  11780. else
  11781. {
  11782. var result = this.graph.getEditingValue(state.cell, trigger)
  11783. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  11784. {
  11785. result = result.replace(/\n/g, '<br/>');
  11786. }
  11787. result = Graph.sanitizeHtml(result, true);
  11788. return result;
  11789. }
  11790. };
  11791. mxCellEditorGetCurrentValue = mxCellEditor.prototype.getCurrentValue;
  11792. mxCellEditor.prototype.getCurrentValue = function(state)
  11793. {
  11794. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  11795. {
  11796. return mxCellEditorGetCurrentValue.apply(this, arguments);
  11797. }
  11798. else
  11799. {
  11800. var result = Graph.sanitizeHtml(this.textarea.innerHTML, true);
  11801. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  11802. {
  11803. result = result.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
  11804. // Workaround for trailing line breaks being ignored in the output
  11805. if (result.length > 0 && (result.substring(result.length - 5) == '<br/>' ||
  11806. result.substring(result.length - 4) == '<br>'))
  11807. {
  11808. result = result.substring(0, result.lastIndexOf('<br')) + '<div><br/></div>';
  11809. }
  11810. }
  11811. else
  11812. {
  11813. result = result.replace(/\r\n/g, '').replace(/\n/g, '');
  11814. }
  11815. return result;
  11816. }
  11817. };
  11818. var mxCellEditorStopEditing = mxCellEditor.prototype.stopEditing;
  11819. mxCellEditor.prototype.stopEditing = function(cancel)
  11820. {
  11821. // Restores default view mode before applying value
  11822. if (this.codeViewMode)
  11823. {
  11824. this.toggleViewMode();
  11825. }
  11826. mxCellEditorStopEditing.apply(this, arguments);
  11827. // Tries to move focus back to container after editing if possible
  11828. this.focusContainer();
  11829. };
  11830. mxCellEditor.prototype.focusContainer = function()
  11831. {
  11832. try
  11833. {
  11834. this.graph.container.focus();
  11835. }
  11836. catch (e)
  11837. {
  11838. // ignore
  11839. }
  11840. };
  11841. var mxCellEditorApplyValue = mxCellEditor.prototype.applyValue;
  11842. mxCellEditor.prototype.applyValue = function(state, value)
  11843. {
  11844. // Removes empty relative child labels in edges
  11845. this.graph.getModel().beginUpdate();
  11846. try
  11847. {
  11848. mxCellEditorApplyValue.apply(this, arguments);
  11849. if (value == '' && this.graph.isCellDeletable(state.cell) &&
  11850. this.graph.model.getChildCount(state.cell) == 0 &&
  11851. this.graph.isTransparentState(state))
  11852. {
  11853. this.graph.removeCells([state.cell], false);
  11854. }
  11855. }
  11856. finally
  11857. {
  11858. this.graph.getModel().endUpdate();
  11859. }
  11860. };
  11861. /**
  11862. * Returns the background color to be used for the editing box. This returns
  11863. * the label background for edge labels and null for all other cases.
  11864. */
  11865. mxCellEditor.prototype.getBackgroundColor = function(state)
  11866. {
  11867. var color = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, null);
  11868. if (color == mxConstants.NONE)
  11869. {
  11870. color = null;
  11871. }
  11872. return color;
  11873. };
  11874. /**
  11875. * Returns the border color to be used for the editing box. This returns
  11876. * the label border for edge labels and null for all other cases.
  11877. */
  11878. mxCellEditor.prototype.getBorderColor = function(state)
  11879. {
  11880. var color = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_BORDERCOLOR, null);
  11881. if (color == mxConstants.NONE)
  11882. {
  11883. color = null;
  11884. }
  11885. return color;
  11886. };
  11887. /**
  11888. * Returns the minimum editing size.
  11889. */
  11890. mxCellEditor.prototype.getMinimumSize = function(state)
  11891. {
  11892. var scale = this.graph.getView().scale;
  11893. return new mxRectangle(0, 0, (state.text == null) ? 30 : state.text.size * scale + 20, 30);
  11894. };
  11895. /**
  11896. * Hold Alt to ignore drop target.
  11897. */
  11898. mxGraphHandlerIsValidDropTarget = mxGraphHandler.prototype.isValidDropTarget;
  11899. mxGraphHandler.prototype.isValidDropTarget = function(target, me)
  11900. {
  11901. return mxGraphHandlerIsValidDropTarget.apply(this, arguments) &&
  11902. !mxEvent.isAltDown(me.getEvent);
  11903. };
  11904. /**
  11905. * Hints on handlers
  11906. */
  11907. function createHint()
  11908. {
  11909. var hint = document.createElement('div');
  11910. hint.className = 'geHint';
  11911. hint.style.whiteSpace = 'nowrap';
  11912. hint.style.position = 'absolute';
  11913. return hint;
  11914. };
  11915. /**
  11916. * Format pixels in the given unit
  11917. */
  11918. function formatHintText(pixels, unit)
  11919. {
  11920. switch(unit)
  11921. {
  11922. case mxConstants.POINTS:
  11923. return pixels;
  11924. case mxConstants.MILLIMETERS:
  11925. return (pixels / mxConstants.PIXELS_PER_MM).toFixed(1);
  11926. case mxConstants.METERS:
  11927. return (pixels / (mxConstants.PIXELS_PER_MM * 1000)).toFixed(4);
  11928. case mxConstants.INCHES:
  11929. return (pixels / mxConstants.PIXELS_PER_INCH).toFixed(3);
  11930. }
  11931. };
  11932. /**
  11933. * Format pixels in the given unit
  11934. */
  11935. mxGraphView.prototype.formatUnitText = function(pixels)
  11936. {
  11937. return pixels? formatHintText(pixels, this.unit) : pixels;
  11938. };
  11939. /**
  11940. * Updates the hint for the current operation.
  11941. */
  11942. mxGraphHandler.prototype.updateHint = function(me)
  11943. {
  11944. if (this.pBounds != null && (this.shape != null || this.livePreviewActive))
  11945. {
  11946. if (this.hint == null)
  11947. {
  11948. this.hint = createHint();
  11949. this.graph.container.appendChild(this.hint);
  11950. }
  11951. var t = this.graph.view.translate;
  11952. var s = this.graph.view.scale;
  11953. var x = this.roundLength((this.bounds.x + this.currentDx) / s - t.x);
  11954. var y = this.roundLength((this.bounds.y + this.currentDy) / s - t.y);
  11955. var unit = this.graph.view.unit;
  11956. this.hint.innerHTML = formatHintText(x, unit) + ', ' + formatHintText(y, unit);
  11957. this.hint.style.left = (this.pBounds.x + this.currentDx +
  11958. Math.round((this.pBounds.width - this.hint.clientWidth) / 2)) + 'px';
  11959. this.hint.style.top = (this.pBounds.y + this.currentDy +
  11960. this.pBounds.height + Editor.hintOffset) + 'px';
  11961. }
  11962. };
  11963. /**
  11964. * Updates the hint for the current operation.
  11965. */
  11966. mxGraphHandler.prototype.removeHint = function()
  11967. {
  11968. if (this.hint != null)
  11969. {
  11970. if (this.hint.parentNode != null)
  11971. {
  11972. this.hint.parentNode.removeChild(this.hint);
  11973. }
  11974. this.hint = null;
  11975. }
  11976. };
  11977. /**
  11978. * Overridden to allow for shrinking pools when lanes are resized.
  11979. */
  11980. var stackLayoutResizeCell = mxStackLayout.prototype.resizeCell;
  11981. mxStackLayout.prototype.resizeCell = function(cell, bounds)
  11982. {
  11983. stackLayoutResizeCell.apply(this, arguments);
  11984. var style = this.graph.getCellStyle(cell);
  11985. if (style['childLayout'] == null)
  11986. {
  11987. var parent = this.graph.model.getParent(cell);
  11988. var geo = (parent != null) ? this.graph.getCellGeometry(parent) : null;
  11989. if (geo != null)
  11990. {
  11991. style = this.graph.getCellStyle(parent);
  11992. if (style['childLayout'] == 'stackLayout')
  11993. {
  11994. var border = parseFloat(mxUtils.getValue(style, 'stackBorder', mxStackLayout.prototype.border));
  11995. var horizontal = mxUtils.getValue(style, 'horizontalStack', '1') == '1';
  11996. var start = this.graph.getActualStartSize(parent);
  11997. geo = geo.clone();
  11998. if (horizontal)
  11999. {
  12000. geo.height = bounds.height + start.y + start.height + 2 * border;
  12001. }
  12002. else
  12003. {
  12004. geo.width = bounds.width + start.x + start.width + 2 * border;
  12005. }
  12006. this.graph.model.setGeometry(parent, geo);
  12007. }
  12008. }
  12009. }
  12010. };
  12011. /**
  12012. * Shows handle for table instead of rows and cells.
  12013. */
  12014. var selectionCellsHandlerGetHandledSelectionCells = mxSelectionCellsHandler.prototype.getHandledSelectionCells;
  12015. mxSelectionCellsHandler.prototype.getHandledSelectionCells = function()
  12016. {
  12017. var cells = selectionCellsHandlerGetHandledSelectionCells.apply(this, arguments);
  12018. var dict = new mxDictionary();
  12019. var model = this.graph.model;
  12020. var result = [];
  12021. function addCell(cell)
  12022. {
  12023. if (!dict.get(cell))
  12024. {
  12025. dict.put(cell, true);
  12026. result.push(cell);
  12027. }
  12028. };
  12029. for (var i = 0; i < cells.length; i++)
  12030. {
  12031. var cell = cells[i];
  12032. if (this.graph.isTableCell(cell))
  12033. {
  12034. addCell(model.getParent(model.getParent(cell)));
  12035. }
  12036. else if (this.graph.isTableRow(cell))
  12037. {
  12038. addCell(model.getParent(cell));
  12039. }
  12040. addCell(cell);
  12041. }
  12042. return result;
  12043. };
  12044. /**
  12045. * Disables starting new connections if control is pressed.
  12046. */
  12047. var connectionHandlerIsStartEvent = mxConnectionHandler.prototype.isStartEvent;
  12048. mxConnectionHandler.prototype.isStartEvent = function(me)
  12049. {
  12050. return connectionHandlerIsStartEvent.apply(this, arguments) &&
  12051. !mxEvent.isControlDown(me.getEvent()) &&
  12052. !mxEvent.isShiftDown(me.getEvent());
  12053. };
  12054. /**
  12055. * Forces preview for title size in tables, table rows, table cells and swimlanes.
  12056. */
  12057. var vertexHandlerIsGhostPreview = mxVertexHandler.prototype.isGhostPreview;
  12058. mxVertexHandler.prototype.isGhostPreview = function()
  12059. {
  12060. return vertexHandlerIsGhostPreview.apply(this, arguments) && !this.graph.isTable(this.state.cell) &&
  12061. !this.graph.isTableRow(this.state.cell) && !this.graph.isTableCell(this.state.cell) &&
  12062. !this.graph.isSwimlane(this.state.cell);
  12063. };
  12064. /**
  12065. * Creates the shape used to draw the selection border.
  12066. */
  12067. var vertexHandlerCreateParentHighlightShape = mxVertexHandler.prototype.createParentHighlightShape;
  12068. mxVertexHandler.prototype.createParentHighlightShape = function(bounds)
  12069. {
  12070. var shape = vertexHandlerCreateParentHighlightShape.apply(this, arguments);
  12071. shape.stroke = '#C0C0C0';
  12072. shape.strokewidth = 1;
  12073. return shape;
  12074. };
  12075. /**
  12076. * Creates the shape used to draw the selection border.
  12077. */
  12078. var edgeHandlerCreateParentHighlightShape = mxEdgeHandler.prototype.createParentHighlightShape;
  12079. mxEdgeHandler.prototype.createParentHighlightShape = function(bounds)
  12080. {
  12081. var shape = edgeHandlerCreateParentHighlightShape.apply(this, arguments);
  12082. shape.stroke = '#C0C0C0';
  12083. shape.strokewidth = 1;
  12084. return shape;
  12085. };
  12086. /**
  12087. * Moves rotation handle to top, right corner.
  12088. */
  12089. mxVertexHandler.prototype.rotationHandleVSpacing = -12;
  12090. mxVertexHandler.prototype.getRotationHandlePosition = function()
  12091. {
  12092. var padding = this.getHandlePadding();
  12093. return new mxPoint(this.bounds.x + this.bounds.width - this.rotationHandleVSpacing + padding.x / 2,
  12094. this.bounds.y + this.rotationHandleVSpacing - padding.y / 2)
  12095. };
  12096. /**
  12097. * Enables recursive resize for groups.
  12098. */
  12099. mxVertexHandler.prototype.isRecursiveResize = function(state, me)
  12100. {
  12101. return this.graph.isRecursiveVertexResize(state) &&
  12102. !mxEvent.isAltDown(me.getEvent());
  12103. };
  12104. /**
  12105. * Enables centered resize events.
  12106. */
  12107. mxVertexHandler.prototype.isCenteredEvent = function(state, me)
  12108. {
  12109. return mxEvent.isControlDown(me.getEvent()) ||
  12110. mxEvent.isMetaDown(me.getEvent());
  12111. };
  12112. /**
  12113. * Hides rotation handle for table cells and rows.
  12114. */
  12115. var vertexHandlerIsRotationHandleVisible = mxVertexHandler.prototype.isRotationHandleVisible;
  12116. mxVertexHandler.prototype.isRotationHandleVisible = function()
  12117. {
  12118. return vertexHandlerIsRotationHandleVisible.apply(this, arguments) &&
  12119. !this.graph.isTableCell(this.state.cell) &&
  12120. !this.graph.isTableRow(this.state.cell) &&
  12121. !this.graph.isTable(this.state.cell);
  12122. };
  12123. /**
  12124. * Hides rotation handle for table cells and rows.
  12125. */
  12126. mxVertexHandler.prototype.getSizerBounds = function()
  12127. {
  12128. if (this.graph.isTableCell(this.state.cell))
  12129. {
  12130. return this.graph.view.getState(this.graph.model.getParent(this.graph.model.getParent(this.state.cell)));
  12131. }
  12132. else
  12133. {
  12134. return this.bounds;
  12135. }
  12136. };
  12137. /**
  12138. * Hides rotation handle for table cells and rows.
  12139. */
  12140. var vertexHandlerIsParentHighlightVisible = mxVertexHandler.prototype.isParentHighlightVisible;
  12141. mxVertexHandler.prototype.isParentHighlightVisible = function()
  12142. {
  12143. return vertexHandlerIsParentHighlightVisible.apply(this, arguments) &&
  12144. !this.graph.isTableCell(this.state.cell) &&
  12145. !this.graph.isTableRow(this.state.cell);
  12146. };
  12147. /**
  12148. * Hides rotation handle for table cells and rows.
  12149. */
  12150. var vertexHandlerIsCustomHandleVisible = mxVertexHandler.prototype.isCustomHandleVisible;
  12151. mxVertexHandler.prototype.isCustomHandleVisible = function(handle)
  12152. {
  12153. return handle.tableHandle ||
  12154. (vertexHandlerIsCustomHandleVisible.apply(this, arguments) &&
  12155. (!this.graph.isTable(this.state.cell) ||
  12156. this.graph.isCellSelected(this.state.cell)));
  12157. };
  12158. /**
  12159. * Adds selection border inset for table cells and rows.
  12160. */
  12161. mxVertexHandler.prototype.getSelectionBorderInset = function()
  12162. {
  12163. var result = 0;
  12164. if (this.graph.isTableRow(this.state.cell))
  12165. {
  12166. result = 1;
  12167. }
  12168. else if (this.graph.isTableCell(this.state.cell))
  12169. {
  12170. result = 2;
  12171. }
  12172. return result;
  12173. };
  12174. /**
  12175. * Adds custom handles for table cells.
  12176. */
  12177. var vertexHandlerGetSelectionBorderBounds = mxVertexHandler.prototype.getSelectionBorderBounds;
  12178. mxVertexHandler.prototype.getSelectionBorderBounds = function()
  12179. {
  12180. return vertexHandlerGetSelectionBorderBounds.apply(this, arguments).grow(
  12181. -this.getSelectionBorderInset());
  12182. };
  12183. var TableLineShape = null;
  12184. /**
  12185. * Adds custom handles for table cells.
  12186. */
  12187. var vertexHandlerCreateCustomHandles = mxVertexHandler.prototype.createCustomHandles;
  12188. mxVertexHandler.prototype.createCustomHandles = function()
  12189. {
  12190. // Lazy lookup for shape constructor
  12191. if (TableLineShape == null)
  12192. {
  12193. TableLineShape = mxCellRenderer.defaultShapes['tableLine'];
  12194. }
  12195. var handles = vertexHandlerCreateCustomHandles.apply(this, arguments);
  12196. if (this.graph.isTable(this.state.cell) && this.graph.isCellMovable(this.state.cell))
  12197. {
  12198. var self = this;
  12199. var graph = this.graph;
  12200. var model = graph.model;
  12201. var s = graph.view.scale;
  12202. var tableState = this.state;
  12203. var sel = this.selectionBorder;
  12204. var x0 = this.state.origin.x + graph.view.translate.x;
  12205. var y0 = this.state.origin.y + graph.view.translate.y;
  12206. if (handles == null)
  12207. {
  12208. handles = [];
  12209. }
  12210. function moveLine(line, dx, dy)
  12211. {
  12212. var result = [];
  12213. for (var i = 0; i < line.length; i++)
  12214. {
  12215. var pt = line[i];
  12216. result.push((pt == null) ? null : new mxPoint(
  12217. (x0 + pt.x + dx) * s, (y0 + pt.y + dy) * s));
  12218. }
  12219. return result;
  12220. };
  12221. // Adds handles for rows and columns
  12222. var rows = graph.view.getCellStates(model.getChildCells(this.state.cell, true));
  12223. if (rows.length > 0)
  12224. {
  12225. var cols = model.getChildCells(rows[0].cell, true);
  12226. var colLines = graph.getTableLines(this.state.cell, false, true);
  12227. var rowLines = graph.getTableLines(this.state.cell, true, false);
  12228. // Adds row height handles
  12229. for (var i = 0; i < rows.length; i++)
  12230. {
  12231. (mxUtils.bind(this, function(index)
  12232. {
  12233. var rowState = rows[index];
  12234. var handle = null;
  12235. if (graph.isCellMovable(rowState.cell))
  12236. {
  12237. var nextRow = (index < rows.length - 1) ? rows[index + 1] : null;
  12238. var ngeo = (nextRow != null) ? graph.getCellGeometry(nextRow.cell) : null;
  12239. var ng = (ngeo != null && ngeo.alternateBounds != null) ? ngeo.alternateBounds : ngeo;
  12240. var shape = (rowLines[index] != null) ?
  12241. new TableLineShape(rowLines[index], mxConstants.NONE, 1) :
  12242. new mxLine(new mxRectangle(), mxConstants.NONE, 1, false);
  12243. shape.isDashed = sel.isDashed;
  12244. shape.svgStrokeTolerance++;
  12245. handle = new mxHandle(rowState, 'row-resize', null, shape);
  12246. handle.tableHandle = true;
  12247. var dy = 0;
  12248. handle.shape.node.parentNode.insertBefore(handle.shape.node,
  12249. handle.shape.node.parentNode.firstChild);
  12250. handle.redraw = function()
  12251. {
  12252. if (this.shape != null)
  12253. {
  12254. this.shape.stroke = (dy == 0) ? mxConstants.NONE : sel.stroke;
  12255. if (this.shape.constructor == TableLineShape)
  12256. {
  12257. this.shape.line = moveLine(rowLines[index], 0, dy);
  12258. this.shape.updateBoundsFromLine();
  12259. }
  12260. else
  12261. {
  12262. var start = graph.getActualStartSize(tableState.cell, true);
  12263. this.shape.bounds.height = 1;
  12264. this.shape.bounds.y = this.state.y + this.state.height + dy * s;
  12265. this.shape.bounds.x = tableState.x + ((index == rows.length - 1) ?
  12266. 0 : start.x * s);
  12267. this.shape.bounds.width = tableState.width - ((index == rows.length - 1) ?
  12268. 0 : (start.width + start.x) + s);
  12269. }
  12270. this.shape.redraw();
  12271. }
  12272. };
  12273. var shiftPressed = false;
  12274. handle.setPosition = function(bounds, pt, me)
  12275. {
  12276. dy = Math.max(Graph.minTableRowHeight - bounds.height,
  12277. pt.y - bounds.y - bounds.height);
  12278. shiftPressed = mxEvent.isShiftDown(me.getEvent());
  12279. if (ng != null && shiftPressed)
  12280. {
  12281. dy = Math.min(dy, ng.height - Graph.minTableRowHeight);
  12282. }
  12283. };
  12284. handle.execute = function(me)
  12285. {
  12286. if (dy != 0)
  12287. {
  12288. graph.setTableRowHeight(this.state.cell,
  12289. dy, !shiftPressed);
  12290. }
  12291. else if (!self.blockDelayedSelection)
  12292. {
  12293. var temp = graph.getCellAt(me.getGraphX(),
  12294. me.getGraphY()) || tableState.cell;
  12295. graph.graphHandler.selectCellForEvent(temp, me);
  12296. }
  12297. dy = 0;
  12298. };
  12299. handle.reset = function()
  12300. {
  12301. dy = 0;
  12302. };
  12303. }
  12304. handles.push(handle);
  12305. }))(i);
  12306. }
  12307. // Adds column width handles
  12308. for (var i = 0; i < cols.length; i++)
  12309. {
  12310. (mxUtils.bind(this, function(index)
  12311. {
  12312. var colState = graph.view.getState(cols[index]);
  12313. var geo = graph.getCellGeometry(cols[index]);
  12314. var g = (geo.alternateBounds != null) ? geo.alternateBounds : geo;
  12315. if (colState == null)
  12316. {
  12317. colState = new mxCellState(graph.view, cols[index],
  12318. graph.getCellStyle(cols[index]));
  12319. colState.x = tableState.x + geo.x * s;
  12320. colState.y = tableState.y + geo.y * s;
  12321. colState.width = g.width * s;
  12322. colState.height = g.height * s;
  12323. colState.updateCachedBounds();
  12324. }
  12325. var nextCol = (index < cols.length - 1) ? cols[index + 1] : null;
  12326. var ngeo = (nextCol != null) ? graph.getCellGeometry(nextCol) : null;
  12327. var ng = (ngeo != null && ngeo.alternateBounds != null) ? ngeo.alternateBounds : ngeo;
  12328. var shape = (colLines[index] != null) ?
  12329. new TableLineShape(colLines[index], mxConstants.NONE, 1) :
  12330. new mxLine(new mxRectangle(), mxConstants.NONE, 1, true);
  12331. shape.isDashed = sel.isDashed;
  12332. // Workaround for event handling on overlapping cells with tolerance
  12333. shape.svgStrokeTolerance++;
  12334. var handle = new mxHandle(colState, 'col-resize', null, shape);
  12335. handle.tableHandle = true;
  12336. var dx = 0;
  12337. handle.shape.node.parentNode.insertBefore(handle.shape.node,
  12338. handle.shape.node.parentNode.firstChild);
  12339. handle.redraw = function()
  12340. {
  12341. if (this.shape != null)
  12342. {
  12343. this.shape.stroke = (dx == 0) ? mxConstants.NONE : sel.stroke;
  12344. if (this.shape.constructor == TableLineShape)
  12345. {
  12346. this.shape.line = moveLine(colLines[index], dx, 0);
  12347. this.shape.updateBoundsFromLine();
  12348. }
  12349. else
  12350. {
  12351. var start = graph.getActualStartSize(tableState.cell, true);
  12352. this.shape.bounds.width = 1;
  12353. this.shape.bounds.x = this.state.x + (g.width + dx) * s;
  12354. this.shape.bounds.y = tableState.y + ((index == cols.length - 1) ?
  12355. 0 : start.y * s);
  12356. this.shape.bounds.height = tableState.height - ((index == cols.length - 1) ?
  12357. 0 : (start.height + start.y) * s);
  12358. }
  12359. this.shape.redraw();
  12360. }
  12361. };
  12362. var shiftPressed = false;
  12363. handle.setPosition = function(bounds, pt, me)
  12364. {
  12365. dx = Math.max(Graph.minTableColumnWidth - g.width,
  12366. pt.x - bounds.x - g.width);
  12367. shiftPressed = mxEvent.isShiftDown(me.getEvent());
  12368. if (ng != null && !shiftPressed)
  12369. {
  12370. dx = Math.min(dx, ng.width - Graph.minTableColumnWidth);
  12371. }
  12372. };
  12373. handle.execute = function(me)
  12374. {
  12375. if (dx != 0)
  12376. {
  12377. graph.setTableColumnWidth(this.state.cell,
  12378. dx, shiftPressed);
  12379. }
  12380. else if (!self.blockDelayedSelection)
  12381. {
  12382. var temp = graph.getCellAt(me.getGraphX(),
  12383. me.getGraphY()) || tableState.cell;
  12384. graph.graphHandler.selectCellForEvent(temp, me);
  12385. }
  12386. dx = 0;
  12387. };
  12388. // Stops repaint of text label via vertex handler
  12389. handle.positionChanged = function()
  12390. {
  12391. // do nothing
  12392. };
  12393. handle.reset = function()
  12394. {
  12395. dx = 0;
  12396. };
  12397. handles.push(handle);
  12398. }))(i);
  12399. }
  12400. }
  12401. }
  12402. // Reserve gives point handles precedence over line handles
  12403. return (handles != null) ? handles.reverse() : null;
  12404. };
  12405. /**
  12406. * Hides additional handles
  12407. */
  12408. var vertexHandlerSetHandlesVisible = mxVertexHandler.prototype.setHandlesVisible;
  12409. mxVertexHandler.prototype.setHandlesVisible = function(visible)
  12410. {
  12411. vertexHandlerSetHandlesVisible.apply(this, arguments);
  12412. if (this.moveHandles != null)
  12413. {
  12414. for (var i = 0; i < this.moveHandles.length; i++)
  12415. {
  12416. if (this.moveHandles[i] != null)
  12417. {
  12418. this.moveHandles[i].node.style.visibility = (visible) ? '' : 'hidden';
  12419. }
  12420. }
  12421. }
  12422. if (this.cornerHandles != null)
  12423. {
  12424. for (var i = 0; i < this.cornerHandles.length; i++)
  12425. {
  12426. this.cornerHandles[i].node.style.visibility = (visible) ? '' : 'hidden';
  12427. }
  12428. }
  12429. };
  12430. /**
  12431. * Function: isMoveHandlesVisible
  12432. *
  12433. * Initializes the shapes required for this vertex handler.
  12434. */
  12435. mxVertexHandler.prototype.isMoveHandlesVisible = function()
  12436. {
  12437. return this.graph.isTable(this.state.cell) &&
  12438. this.graph.isCellMovable(this.state.cell);
  12439. };
  12440. /**
  12441. * Creates or updates special handles for moving rows.
  12442. */
  12443. mxVertexHandler.prototype.refreshMoveHandles = function()
  12444. {
  12445. var showMoveHandles = this.isMoveHandlesVisible();
  12446. if (showMoveHandles && this.moveHandles == null)
  12447. {
  12448. this.moveHandles = this.createMoveHandles();
  12449. }
  12450. else if (!showMoveHandles && this.moveHandles != null)
  12451. {
  12452. this.destroyMoveHandles();
  12453. }
  12454. // Destroys existing handles
  12455. if (showMoveHandles && this.moveHandles == null)
  12456. {
  12457. for (var i = 0; i < this.moveHandles.length; i++)
  12458. {
  12459. if (this.moveHandles[i] != null)
  12460. {
  12461. this.moveHandles[i].parentNode.removeChild(this.moveHandles[i]);
  12462. }
  12463. }
  12464. this.moveHandles = null;
  12465. }
  12466. };
  12467. /**
  12468. * Creates or updates special handles for moving rows.
  12469. */
  12470. mxVertexHandler.prototype.createMoveHandles = function()
  12471. {
  12472. var graph = this.graph;
  12473. var model = graph.model;
  12474. var handles = [];
  12475. for (var i = 0; i < model.getChildCount(this.state.cell); i++)
  12476. {
  12477. (mxUtils.bind(this, function(rowState)
  12478. {
  12479. if (rowState != null && model.isVertex(rowState.cell) &&
  12480. graph.isCellMovable(rowState.cell))
  12481. {
  12482. var bounds = new mxRectangle(0, 0, this.rowHandleImage.width, this.rowHandleImage.height);
  12483. var moveHandle = new mxImageShape(bounds, this.rowHandleImage.src);
  12484. moveHandle.rowState = rowState;
  12485. moveHandle.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  12486. mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
  12487. moveHandle.init(this.graph.getView().getOverlayPane());
  12488. moveHandle.node.style.cursor = 'move';
  12489. mxEvent.addGestureListeners(moveHandle.node, mxUtils.bind(this, function(evt)
  12490. {
  12491. this.graph.popupMenuHandler.hideMenu();
  12492. this.graph.stopEditing(false);
  12493. if (this.graph.isToggleEvent(evt) ||
  12494. !this.graph.isCellSelected(rowState.cell))
  12495. {
  12496. this.graph.selectCellForEvent(rowState.cell, evt);
  12497. }
  12498. if (!mxEvent.isPopupTrigger(evt))
  12499. {
  12500. this.graph.graphHandler.start(this.state.cell,
  12501. mxEvent.getClientX(evt), mxEvent.getClientY(evt),
  12502. this.graph.getSelectionCells());
  12503. this.graph.graphHandler.cellWasClicked = true;
  12504. this.graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  12505. this.graph.isMouseDown = true;
  12506. }
  12507. mxEvent.consume(evt);
  12508. }), null, mxUtils.bind(this, function(evt)
  12509. {
  12510. if (mxEvent.isPopupTrigger(evt))
  12511. {
  12512. this.graph.popupMenuHandler.popup(mxEvent.getClientX(evt),
  12513. mxEvent.getClientY(evt), rowState.cell, evt);
  12514. mxEvent.consume(evt);
  12515. }
  12516. }));
  12517. handles.push(moveHandle);
  12518. }
  12519. else
  12520. {
  12521. handles.push(null);
  12522. }
  12523. }))(this.graph.view.getState(model.getChildAt(this.state.cell, i)));
  12524. }
  12525. return handles;
  12526. };
  12527. /**
  12528. * Function: destroyMoveHandles
  12529. *
  12530. * Destroys the handler and all its resources and DOM nodes.
  12531. */
  12532. mxVertexHandler.prototype.destroyMoveHandles = function()
  12533. {
  12534. if (this.moveHandles != null)
  12535. {
  12536. for (var i = 0; i < this.moveHandles.length; i++)
  12537. {
  12538. if (this.moveHandles[i] != null)
  12539. {
  12540. this.moveHandles[i].destroy();
  12541. }
  12542. }
  12543. this.moveHandles = null;
  12544. }
  12545. };
  12546. /**
  12547. * Function: destroyCornerHandles
  12548. *
  12549. * Destroys the handler and all its resources and DOM nodes.
  12550. */
  12551. mxVertexHandler.prototype.destroyCornerHandles = function()
  12552. {
  12553. if (this.cornerHandles != null)
  12554. {
  12555. for (var i = 0; i < this.cornerHandles.length; i++)
  12556. {
  12557. if (this.cornerHandles[i] != null && this.cornerHandles[i].node != null &&
  12558. this.cornerHandles[i].node.parentNode != null)
  12559. {
  12560. this.cornerHandles[i].node.parentNode.removeChild(this.cornerHandles[i].node);
  12561. }
  12562. }
  12563. this.cornerHandles = null;
  12564. }
  12565. };
  12566. /**
  12567. * Adds handle padding for editing cells and exceptions.
  12568. */
  12569. var vertexHandlerRefresh = mxVertexHandler.prototype.refresh;
  12570. mxVertexHandler.prototype.refresh = function()
  12571. {
  12572. vertexHandlerRefresh.apply(this, arguments);
  12573. this.destroyMoveHandles();
  12574. this.destroyCornerHandles();
  12575. if (this.graph.isTable(this.state.cell) &&
  12576. this.graph.isCellMovable(this.state.cell))
  12577. {
  12578. this.refreshMoveHandles();
  12579. }
  12580. // Draws corner rectangles for single selected table cells and rows
  12581. else if (this.graph.getSelectionCount() == 1 &&
  12582. this.graph.isCellMovable(this.state.cell) &&
  12583. (this.graph.isTableCell(this.state.cell) ||
  12584. this.graph.isTableRow(this.state.cell)))
  12585. {
  12586. this.cornerHandles = [];
  12587. for (var i = 0; i < 4; i++)
  12588. {
  12589. var shape = new mxRectangleShape(new mxRectangle(0, 0, 6, 6),
  12590. '#ffffff', mxConstants.HANDLE_STROKECOLOR);
  12591. shape.dialect = mxConstants.DIALECT_SVG;
  12592. shape.init(this.graph.view.getOverlayPane());
  12593. this.cornerHandles.push(shape);
  12594. }
  12595. }
  12596. if (this.graph.isTable(this.state.cell) &&
  12597. this.graph.isCellMovable(this.state.cell))
  12598. {
  12599. this.refreshMoveHandles();
  12600. }
  12601. var link = this.graph.getLinkForCell(this.state.cell);
  12602. var links = this.graph.getLinksForState(this.state);
  12603. this.updateLinkHint(link, links);
  12604. };
  12605. /**
  12606. * Adds handle padding for editing cells and exceptions.
  12607. */
  12608. var vertexHandlerGetHandlePadding = mxVertexHandler.prototype.getHandlePadding;
  12609. mxVertexHandler.prototype.getHandlePadding = function()
  12610. {
  12611. var result = new mxPoint(0, 0);
  12612. var tol = this.tolerance;
  12613. var name = this.state.style['shape'];
  12614. if (mxCellRenderer.defaultShapes[name] == null &&
  12615. mxStencilRegistry.getStencil(name) == null)
  12616. {
  12617. name = mxConstants.SHAPE_RECTANGLE;
  12618. }
  12619. // Checks if custom handles are overlapping with the shape border
  12620. var handlePadding = this.graph.isTable(this.state.cell) ||
  12621. this.graph.cellEditor.getEditingCell() == this.state.cell;
  12622. if (!handlePadding)
  12623. {
  12624. if (this.customHandles != null)
  12625. {
  12626. for (var i = 0; i < this.customHandles.length; i++)
  12627. {
  12628. if (this.customHandles[i] != null &&
  12629. this.customHandles[i].shape != null &&
  12630. this.customHandles[i].shape.bounds != null)
  12631. {
  12632. var b = this.customHandles[i].shape.bounds;
  12633. var px = b.getCenterX();
  12634. var py = b.getCenterY();
  12635. if ((Math.abs(this.state.x - px) < b.width / 2) ||
  12636. (Math.abs(this.state.y - py) < b.height / 2) ||
  12637. (Math.abs(this.state.x + this.state.width - px) < b.width / 2) ||
  12638. (Math.abs(this.state.y + this.state.height - py) < b.height / 2))
  12639. {
  12640. handlePadding = true;
  12641. break;
  12642. }
  12643. }
  12644. }
  12645. }
  12646. }
  12647. if (handlePadding && this.sizers != null &&
  12648. this.sizers.length > 0 && this.sizers[0] != null)
  12649. {
  12650. tol /= 2;
  12651. // Makes room for row move handle
  12652. if (this.graph.isTable(this.state.cell))
  12653. {
  12654. tol += 7;
  12655. }
  12656. result.x = this.sizers[0].bounds.width + tol;
  12657. result.y = this.sizers[0].bounds.height + tol;
  12658. }
  12659. else
  12660. {
  12661. result = vertexHandlerGetHandlePadding.apply(this, arguments);
  12662. }
  12663. return result;
  12664. };
  12665. /**
  12666. * Updates the hint for the current operation.
  12667. */
  12668. mxVertexHandler.prototype.updateHint = function(me)
  12669. {
  12670. if (this.index != mxEvent.LABEL_HANDLE)
  12671. {
  12672. if (this.hint == null)
  12673. {
  12674. this.hint = createHint();
  12675. this.state.view.graph.container.appendChild(this.hint);
  12676. }
  12677. if (this.index == mxEvent.ROTATION_HANDLE)
  12678. {
  12679. this.hint.innerHTML = this.currentAlpha + '&deg;';
  12680. }
  12681. else
  12682. {
  12683. var s = this.state.view.scale;
  12684. var unit = this.state.view.unit;
  12685. this.hint.innerHTML = formatHintText(this.roundLength(this.bounds.width / s), unit) + ' x ' +
  12686. formatHintText(this.roundLength(this.bounds.height / s), unit);
  12687. }
  12688. var rot = (this.currentAlpha != null) ? this.currentAlpha : this.state.style[mxConstants.STYLE_ROTATION] || '0';
  12689. var bb = mxUtils.getBoundingBox(this.bounds, rot);
  12690. if (bb == null)
  12691. {
  12692. bb = this.bounds;
  12693. }
  12694. this.hint.style.left = bb.x + Math.round((bb.width - this.hint.clientWidth) / 2) + 'px';
  12695. this.hint.style.top = (bb.y + bb.height + Editor.hintOffset) + 'px';
  12696. if (this.linkHint != null)
  12697. {
  12698. this.linkHint.style.display = 'none';
  12699. }
  12700. }
  12701. };
  12702. /**
  12703. * Updates the hint for the current operation.
  12704. */
  12705. mxVertexHandler.prototype.removeHint = function()
  12706. {
  12707. mxGraphHandler.prototype.removeHint.apply(this, arguments);
  12708. if (this.linkHint != null)
  12709. {
  12710. this.linkHint.style.display = '';
  12711. }
  12712. };
  12713. /**
  12714. * Adds handle padding for editing cells and exceptions.
  12715. */
  12716. var edgeHandlerRefresh = mxEdgeHandler.prototype.refresh;
  12717. mxEdgeHandler.prototype.refresh = function()
  12718. {
  12719. edgeHandlerRefresh.apply(this, arguments);
  12720. var link = this.graph.getLinkForCell(this.state.cell);
  12721. var links = this.graph.getLinksForState(this.state);
  12722. this.updateLinkHint(link, links);
  12723. };
  12724. /**
  12725. * Hides link hint while moving cells.
  12726. */
  12727. var edgeHandlerMouseMove = mxEdgeHandler.prototype.mouseMove;
  12728. mxEdgeHandler.prototype.mouseMove = function(sender, me)
  12729. {
  12730. edgeHandlerMouseMove.apply(this, arguments);
  12731. if (this.linkHint != null && this.linkHint.style.display != 'none' &&
  12732. this.graph.graphHandler != null && this.graph.graphHandler.first != null)
  12733. {
  12734. this.linkHint.style.display = 'none';
  12735. }
  12736. }
  12737. /**
  12738. * Hides link hint while moving cells.
  12739. */
  12740. var edgeHandlerMouseUp = mxEdgeHandler.prototype.mouseUp;
  12741. mxEdgeHandler.prototype.mouseUp = function(sender, me)
  12742. {
  12743. edgeHandlerMouseUp.apply(this, arguments);
  12744. if (this.linkHint != null && this.linkHint.style.display == 'none' &&
  12745. this.graph.getSelectionCount() == 1)
  12746. {
  12747. this.linkHint.style.display = '';
  12748. }
  12749. }
  12750. /**
  12751. * Updates the hint for the current operation.
  12752. */
  12753. mxEdgeHandler.prototype.updateHint = function(me, point, edge)
  12754. {
  12755. if (this.hint == null)
  12756. {
  12757. this.hint = createHint();
  12758. this.state.view.graph.container.appendChild(this.hint);
  12759. }
  12760. var t = this.graph.view.translate;
  12761. var s = this.graph.view.scale;
  12762. var x = this.roundLength(point.x / s - t.x);
  12763. var y = this.roundLength(point.y / s - t.y);
  12764. var unit = this.graph.view.unit;
  12765. this.hint.innerHTML = formatHintText(x, unit) + ', ' + formatHintText(y, unit);
  12766. this.hint.style.visibility = 'visible';
  12767. if (edge != null)
  12768. {
  12769. edge.view.updateEdgeBounds(edge);
  12770. this.hint.innerHTML += ' (' + ((unit == mxConstants.POINTS) ?
  12771. Math.round(edge.length / s) : formatHintText(
  12772. edge.length / s, unit)) + ')';
  12773. }
  12774. if (this.isSource || this.isTarget)
  12775. {
  12776. if (this.constraintHandler != null &&
  12777. this.constraintHandler.currentConstraint != null &&
  12778. this.constraintHandler.currentFocus != null)
  12779. {
  12780. var pt = this.constraintHandler.currentConstraint.point;
  12781. this.hint.innerHTML = '[' + Math.round(pt.x * 100) + '%, '+ Math.round(pt.y * 100) + '%]';
  12782. }
  12783. else if (this.marker.hasValidState())
  12784. {
  12785. this.hint.style.visibility = 'hidden';
  12786. }
  12787. }
  12788. this.hint.style.left = Math.round(me.getGraphX() - this.hint.clientWidth / 2) + 'px';
  12789. this.hint.style.top = (Math.max(me.getGraphY(), point.y) + Editor.hintOffset) + 'px';
  12790. if (this.linkHint != null)
  12791. {
  12792. this.linkHint.style.display = 'none';
  12793. }
  12794. };
  12795. /**
  12796. * Replaces folding icons with SVG.
  12797. */
  12798. Graph.prototype.expandedImage = Graph.createSvgImage(9, 9, '<defs><linearGradient id="grad1" x1="50%" y1="0%" x2="50%" y2="100%">' +
  12799. '<stop offset="30%" style="stop-color:#f0f0f0;" /><stop offset="100%" style="stop-color:#AFB0B6;" /></linearGradient></defs>' +
  12800. '<rect x="0" y="0" width="9" height="9" stroke="#8A94A5" fill="url(#grad1)" stroke-width="2"/>' +
  12801. '<path d="M 2 4.5 L 7 4.5 z" stroke="#000"/>');
  12802. Graph.prototype.collapsedImage = Graph.createSvgImage(9, 9, '<defs><linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">' +
  12803. '<stop offset="30%" style="stop-color:#f0f0f0;" /><stop offset="100%" style="stop-color:#AFB0B6;" /></linearGradient></defs>' +
  12804. '<rect x="0" y="0" width="9" height="9" stroke="#8A94A5" fill="url(#grad1)" stroke-width="2"/>' +
  12805. '<path d="M 4.5 2 L 4.5 7 M 2 4.5 L 7 4.5 z" stroke="#000"/>');
  12806. /**
  12807. * Updates the hint for the current operation.
  12808. */
  12809. mxEdgeHandler.prototype.removeHint = mxVertexHandler.prototype.removeHint;
  12810. /**
  12811. * Defines the handles for the UI. Uses data-URIs to speed-up loading time where supported.
  12812. */
  12813. HoverIcons.prototype.mainHandle = Graph.createSvgImage(18, 18, '<circle cx="9" cy="9" r="5" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  12814. HoverIcons.prototype.endMainHandle = Graph.createSvgImage(18, 18, '<circle cx="9" cy="9" r="6" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  12815. HoverIcons.prototype.secondaryHandle = Graph.createSvgImage(16, 16, '<path d="m 8 3 L 13 8 L 8 13 L 3 8 z" stroke="#fff" fill="#fca000"/>');
  12816. HoverIcons.prototype.fixedHandle = Graph.createSvgImage(22, 22,
  12817. '<circle cx="11" cy="11" r="6" stroke="#fff" fill="#01bd22"/>' +
  12818. '<path d="m 8 8 L 14 14M 8 14 L 14 8" stroke="#fff"/>');
  12819. HoverIcons.prototype.endFixedHandle = Graph.createSvgImage(22, 22,
  12820. '<circle cx="11" cy="11" r="7" stroke="#fff" fill="#01bd22"/>' +
  12821. '<path d="m 8 8 L 14 14M 8 14 L 14 8" stroke="#fff"/>');
  12822. HoverIcons.prototype.terminalHandle = Graph.createSvgImage(22, 22,
  12823. '<circle cx="11" cy="11" r="6" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill +
  12824. '"/><circle cx="11" cy="11" r="3" stroke="#fff" fill="transparent"/>');
  12825. HoverIcons.prototype.endTerminalHandle = Graph.createSvgImage(22, 22,
  12826. '<circle cx="11" cy="11" r="7" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill +
  12827. '"/><circle cx="11" cy="11" r="3" stroke="#fff" fill="transparent"/>');
  12828. HoverIcons.prototype.rotationHandle = Graph.createSvgImage(16, 16,
  12829. '<path stroke="' + HoverIcons.prototype.arrowFill + '" fill="' + HoverIcons.prototype.arrowFill +
  12830. '" d="M15.55 5.55L11 1v3.07C7.06 4.56 4 7.92 4 12s3.05 7.44 7 7.93v-2.02c-2.84-.48-5-2.94-5-5.91s2.16-5.43 5-5.91V10l4.55-4.45zM19.93 11c-.17-1.39-.72-2.73-1.62-3.89l-1.42 1.42c.54.75.88 1.6 1.02 2.47h2.02zM13 17.9v2.02c1.39-.17 2.74-.71 3.9-1.61l-1.44-1.44c-.75.54-1.59.89-2.46 1.03zm3.89-2.42l1.42 1.41c.9-1.16 1.45-2.5 1.62-3.89h-2.02c-.14.87-.48 1.72-1.02 2.48z"/>',
  12831. 24, 24);
  12832. mxConstraintHandler.prototype.pointImage = Graph.createSvgImage(5, 5,
  12833. '<path d="m 0 0 L 5 5 M 0 5 L 5 0" stroke-width="2" style="stroke-opacity:0.4" stroke="#ffffff"/>' +
  12834. '<path d="m 0 0 L 5 5 M 0 5 L 5 0" stroke="' + HoverIcons.prototype.arrowFill + '"/>');
  12835. mxVertexHandler.TABLE_HANDLE_COLOR = '#fca000';
  12836. mxVertexHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  12837. mxVertexHandler.prototype.secondaryHandleImage = HoverIcons.prototype.secondaryHandle;
  12838. mxVertexHandler.prototype.rowHandleImage = Graph.createSvgImage(14, 12,
  12839. '<rect x="2" y="2" width="10" height="3" stroke-width="1" stroke="#ffffff" fill="' + HoverIcons.prototype.arrowFill + '"/>' +
  12840. '<rect x="2" y="7" width="10" height="3" stroke-width="1" stroke="#ffffff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  12841. mxEdgeHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  12842. mxEdgeHandler.prototype.endHandleImage = HoverIcons.prototype.endMainHandle;
  12843. mxEdgeHandler.prototype.terminalHandleImage = HoverIcons.prototype.terminalHandle;
  12844. mxEdgeHandler.prototype.endTerminalHandleImage = HoverIcons.prototype.endTerminalHandle;
  12845. mxEdgeHandler.prototype.fixedHandleImage = HoverIcons.prototype.fixedHandle;
  12846. mxEdgeHandler.prototype.endFixedHandleImage = HoverIcons.prototype.endFixedHandle;
  12847. mxEdgeHandler.prototype.labelHandleImage = HoverIcons.prototype.secondaryHandle;
  12848. mxOutline.prototype.sizerImage = HoverIcons.prototype.mainHandle;
  12849. if (window.Sidebar != null)
  12850. {
  12851. Sidebar.prototype.triangleUp = HoverIcons.prototype.triangleUp;
  12852. Sidebar.prototype.triangleRight = HoverIcons.prototype.triangleRight;
  12853. Sidebar.prototype.triangleDown = HoverIcons.prototype.triangleDown;
  12854. Sidebar.prototype.triangleLeft = HoverIcons.prototype.triangleLeft;
  12855. Sidebar.prototype.refreshTarget = HoverIcons.prototype.refreshTarget;
  12856. Sidebar.prototype.roundDrop = HoverIcons.prototype.roundDrop;
  12857. }
  12858. // Adds rotation handle and live preview
  12859. mxVertexHandler.prototype.rotationEnabled = true;
  12860. mxVertexHandler.prototype.manageSizers = true;
  12861. mxVertexHandler.prototype.livePreview = true;
  12862. mxGraphHandler.prototype.maxLivePreview = 16;
  12863. // Increases default rubberband opacity (default is 20)
  12864. mxRubberband.prototype.defaultOpacity = 30;
  12865. // Enables connections along the outline, virtual waypoints, parent highlight etc
  12866. mxConnectionHandler.prototype.outlineConnect = true;
  12867. mxCellHighlight.prototype.keepOnTop = true;
  12868. mxVertexHandler.prototype.parentHighlightEnabled = true;
  12869. mxEdgeHandler.prototype.parentHighlightEnabled = true;
  12870. mxEdgeHandler.prototype.dblClickRemoveEnabled = true;
  12871. mxEdgeHandler.prototype.straightRemoveEnabled = true;
  12872. mxEdgeHandler.prototype.virtualBendsEnabled = true;
  12873. mxEdgeHandler.prototype.mergeRemoveEnabled = true;
  12874. mxEdgeHandler.prototype.manageLabelHandle = true;
  12875. mxEdgeHandler.prototype.outlineConnect = true;
  12876. // Disables adding waypoints if shift is pressed
  12877. mxEdgeHandler.prototype.isAddVirtualBendEvent = function(me)
  12878. {
  12879. return !mxEvent.isShiftDown(me.getEvent());
  12880. };
  12881. // Disables custom handles if shift is pressed
  12882. mxEdgeHandler.prototype.isCustomHandleEvent = function(me)
  12883. {
  12884. return !mxEvent.isShiftDown(me.getEvent());
  12885. };
  12886. /**
  12887. * Implements touch style
  12888. */
  12889. if (Graph.touchStyle)
  12890. {
  12891. // Larger tolerance for real touch devices
  12892. if (mxClient.IS_TOUCH || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0)
  12893. {
  12894. mxShape.prototype.svgStrokeTolerance = 18;
  12895. mxVertexHandler.prototype.tolerance = 12;
  12896. mxEdgeHandler.prototype.tolerance = 12;
  12897. Graph.prototype.tolerance = 12;
  12898. mxVertexHandler.prototype.rotationHandleVSpacing = -16;
  12899. // Implements a smaller tolerance for mouse events and a larger tolerance for touch
  12900. // events on touch devices. The default tolerance (4px) is used for mouse events.
  12901. mxConstraintHandler.prototype.getTolerance = function(me)
  12902. {
  12903. return (mxEvent.isMouseEvent(me.getEvent())) ? 4 : this.graph.getTolerance();
  12904. };
  12905. }
  12906. // One finger pans (no rubberband selection) must start regardless of mouse button
  12907. mxPanningHandler.prototype.isPanningTrigger = function(me)
  12908. {
  12909. var evt = me.getEvent();
  12910. return (me.getState() == null && !mxEvent.isMouseEvent(evt)) ||
  12911. (mxEvent.isPopupTrigger(evt) && (me.getState() == null ||
  12912. mxEvent.isControlDown(evt) || mxEvent.isShiftDown(evt)));
  12913. };
  12914. }
  12915. else
  12916. {
  12917. // Removes ctrl+shift as panning trigger for space splitting
  12918. mxPanningHandler.prototype.isPanningTrigger = function(me)
  12919. {
  12920. var evt = me.getEvent();
  12921. return (mxEvent.isLeftMouseButton(evt) && ((this.useLeftButtonForPanning &&
  12922. me.getState() == null) || (mxEvent.isControlDown(evt) &&
  12923. !mxEvent.isShiftDown(evt)))) || (this.usePopupTrigger &&
  12924. mxEvent.isPopupTrigger(evt));
  12925. };
  12926. }
  12927. // Overrides/extends rubberband for space handling with Ctrl+Shift(+Alt) drag ("scissors tool")
  12928. mxRubberband.prototype.isSpaceEvent = function(me)
  12929. {
  12930. return this.graph.isEnabled() && !this.graph.isCellLocked(this.graph.getDefaultParent()) &&
  12931. (mxEvent.isControlDown(me.getEvent()) || mxEvent.isMetaDown(me.getEvent())) &&
  12932. mxEvent.isShiftDown(me.getEvent()) && mxEvent.isAltDown(me.getEvent());
  12933. };
  12934. // Cancelled state
  12935. mxRubberband.prototype.cancelled = false;
  12936. // Cancels ongoing rubberband selection but consumed event to avoid reset of selection
  12937. mxRubberband.prototype.cancel = function()
  12938. {
  12939. if (this.isActive())
  12940. {
  12941. this.cancelled = true;
  12942. this.reset();
  12943. }
  12944. };
  12945. // Handles moving of cells in both half panes
  12946. mxRubberband.prototype.mouseUp = function(sender, me)
  12947. {
  12948. if (this.cancelled)
  12949. {
  12950. this.cancelled = false;
  12951. me.consume();
  12952. }
  12953. else
  12954. {
  12955. var execute = this.div != null && this.div.style.display != 'none';
  12956. var x0 = null;
  12957. var y0 = null;
  12958. var dx = null;
  12959. var dy = null;
  12960. if (this.first != null && this.currentX != null && this.currentY != null)
  12961. {
  12962. x0 = this.first.x;
  12963. y0 = this.first.y;
  12964. dx = (this.currentX - x0) / this.graph.view.scale;
  12965. dy = (this.currentY - y0) / this.graph.view.scale;
  12966. if (!mxEvent.isAltDown(me.getEvent()))
  12967. {
  12968. dx = this.graph.snap(dx);
  12969. dy = this.graph.snap(dy);
  12970. if (!this.graph.isGridEnabled())
  12971. {
  12972. if (Math.abs(dx) < this.graph.tolerance)
  12973. {
  12974. dx = 0;
  12975. }
  12976. if (Math.abs(dy) < this.graph.tolerance)
  12977. {
  12978. dy = 0;
  12979. }
  12980. }
  12981. }
  12982. }
  12983. this.reset();
  12984. if (execute)
  12985. {
  12986. if (this.isSpaceEvent(me))
  12987. {
  12988. this.graph.model.beginUpdate();
  12989. try
  12990. {
  12991. var cells = this.graph.getCellsBeyond(x0, y0, this.graph.getDefaultParent(), true, true);
  12992. for (var i = 0; i < cells.length; i++)
  12993. {
  12994. if (this.graph.isCellMovable(cells[i]))
  12995. {
  12996. var tmp = this.graph.view.getState(cells[i]);
  12997. var geo = this.graph.getCellGeometry(cells[i]);
  12998. if (tmp != null && geo != null)
  12999. {
  13000. geo = geo.clone();
  13001. geo.translate(dx, dy);
  13002. this.graph.model.setGeometry(cells[i], geo);
  13003. }
  13004. }
  13005. }
  13006. }
  13007. finally
  13008. {
  13009. this.graph.model.endUpdate();
  13010. }
  13011. }
  13012. else
  13013. {
  13014. var rect = new mxRectangle(this.x, this.y, this.width, this.height);
  13015. this.graph.selectRegion(rect, me.getEvent());
  13016. }
  13017. me.consume();
  13018. }
  13019. }
  13020. };
  13021. // Handles preview for creating/removing space in diagram
  13022. mxRubberband.prototype.mouseMove = function(sender, me)
  13023. {
  13024. if (!me.isConsumed() && this.first != null)
  13025. {
  13026. var origin = mxUtils.getScrollOrigin(this.graph.container);
  13027. var offset = mxUtils.getOffset(this.graph.container);
  13028. origin.x -= offset.x;
  13029. origin.y -= offset.y;
  13030. var x = me.getX() + origin.x;
  13031. var y = me.getY() + origin.y;
  13032. var dx = this.first.x - x;
  13033. var dy = this.first.y - y;
  13034. var tol = this.graph.tolerance;
  13035. if (this.div != null || Math.abs(dx) > tol || Math.abs(dy) > tol)
  13036. {
  13037. if (this.div == null)
  13038. {
  13039. this.div = this.createShape();
  13040. }
  13041. // Clears selection while rubberbanding. This is required because
  13042. // the event is not consumed in mouseDown.
  13043. mxUtils.clearSelection();
  13044. this.update(x, y);
  13045. if (this.isSpaceEvent(me))
  13046. {
  13047. var right = this.x + this.width;
  13048. var bottom = this.y + this.height;
  13049. var scale = this.graph.view.scale;
  13050. if (!mxEvent.isAltDown(me.getEvent()))
  13051. {
  13052. this.width = this.graph.snap(this.width / scale) * scale;
  13053. this.height = this.graph.snap(this.height / scale) * scale;
  13054. if (!this.graph.isGridEnabled())
  13055. {
  13056. if (this.width < this.graph.tolerance)
  13057. {
  13058. this.width = 0;
  13059. }
  13060. if (this.height < this.graph.tolerance)
  13061. {
  13062. this.height = 0;
  13063. }
  13064. }
  13065. if (this.x < this.first.x)
  13066. {
  13067. this.x = right - this.width;
  13068. }
  13069. if (this.y < this.first.y)
  13070. {
  13071. this.y = bottom - this.height;
  13072. }
  13073. }
  13074. this.div.style.borderStyle = 'dashed';
  13075. this.div.style.backgroundColor = 'white';
  13076. this.div.style.left = this.x + 'px';
  13077. this.div.style.top = this.y + 'px';
  13078. this.div.style.width = Math.max(0, this.width) + 'px';
  13079. this.div.style.height = this.graph.container.clientHeight + 'px';
  13080. this.div.style.borderWidth = (this.width <= 0) ? '0px 1px 0px 0px' : '0px 1px 0px 1px';
  13081. if (this.secondDiv == null)
  13082. {
  13083. this.secondDiv = this.div.cloneNode(true);
  13084. this.div.parentNode.appendChild(this.secondDiv);
  13085. }
  13086. this.secondDiv.style.left = this.x + 'px';
  13087. this.secondDiv.style.top = this.y + 'px';
  13088. this.secondDiv.style.width = this.graph.container.clientWidth + 'px';
  13089. this.secondDiv.style.height = Math.max(0, this.height) + 'px';
  13090. this.secondDiv.style.borderWidth = (this.height <= 0) ? '1px 0px 0px 0px' : '1px 0px 1px 0px';
  13091. }
  13092. else
  13093. {
  13094. // Hides second div and restores style
  13095. this.div.style.backgroundColor = '';
  13096. this.div.style.borderWidth = '';
  13097. this.div.style.borderStyle = '';
  13098. if (this.secondDiv != null)
  13099. {
  13100. this.secondDiv.parentNode.removeChild(this.secondDiv);
  13101. this.secondDiv = null;
  13102. }
  13103. }
  13104. me.consume();
  13105. }
  13106. }
  13107. };
  13108. // Removes preview
  13109. var mxRubberbandReset = mxRubberband.prototype.reset;
  13110. mxRubberband.prototype.reset = function()
  13111. {
  13112. if (this.secondDiv != null)
  13113. {
  13114. this.secondDiv.parentNode.removeChild(this.secondDiv);
  13115. this.secondDiv = null;
  13116. }
  13117. mxRubberbandReset.apply(this, arguments);
  13118. };
  13119. // Timer-based activation of outline connect in connection handler
  13120. var startTime = new Date().getTime();
  13121. var timeOnTarget = 0;
  13122. var mxEdgeHandlerUpdatePreviewState = mxEdgeHandler.prototype.updatePreviewState;
  13123. mxEdgeHandler.prototype.updatePreviewState = function(edge, point, terminalState, me)
  13124. {
  13125. mxEdgeHandlerUpdatePreviewState.apply(this, arguments);
  13126. if (terminalState != this.currentTerminalState)
  13127. {
  13128. startTime = new Date().getTime();
  13129. timeOnTarget = 0;
  13130. }
  13131. else
  13132. {
  13133. timeOnTarget = new Date().getTime() - startTime;
  13134. }
  13135. this.currentTerminalState = terminalState;
  13136. };
  13137. // Timer-based outline connect
  13138. var mxEdgeHandlerIsOutlineConnectEvent = mxEdgeHandler.prototype.isOutlineConnectEvent;
  13139. mxEdgeHandler.prototype.isOutlineConnectEvent = function(me)
  13140. {
  13141. if (mxEvent.isShiftDown(me.getEvent()) && mxEvent.isAltDown(me.getEvent()))
  13142. {
  13143. return false;
  13144. }
  13145. else
  13146. {
  13147. return (this.currentTerminalState != null && me.getState() == this.currentTerminalState && timeOnTarget > 2000) ||
  13148. ((this.currentTerminalState == null || mxUtils.getValue(this.currentTerminalState.style, 'outlineConnect', '1') != '0') &&
  13149. mxEdgeHandlerIsOutlineConnectEvent.apply(this, arguments));
  13150. }
  13151. };
  13152. // Shows secondary handle for fixed connection points
  13153. mxEdgeHandler.prototype.createHandleShape = function(index, virtual, target)
  13154. {
  13155. var source = index != null && index == 0;
  13156. var terminalState = this.state.getVisibleTerminalState(source);
  13157. var c = (index != null && (index == 0 || index >= this.state.absolutePoints.length - 1 ||
  13158. (this.constructor == mxElbowEdgeHandler && index == 2))) ?
  13159. this.graph.getConnectionConstraint(this.state, terminalState, source) : null;
  13160. var pt = (c != null) ? this.graph.getConnectionPoint(this.state.getVisibleTerminalState(source), c) : null;
  13161. var img = (pt != null) ? (!target ? this.fixedHandleImage : this.endFixedHandleImage) :
  13162. ((c != null && terminalState != null) ? (!target ? this.terminalHandleImage : this.endTerminalHandleImage) :
  13163. (!target ? this.handleImage : this.endHandleImage));
  13164. if (img != null)
  13165. {
  13166. var shape = new mxImageShape(new mxRectangle(0, 0, img.width, img.height), img.src);
  13167. // Allows HTML rendering of the images
  13168. shape.preserveImageAspect = false;
  13169. return shape;
  13170. }
  13171. else
  13172. {
  13173. var s = mxConstants.HANDLE_SIZE;
  13174. if (this.preferHtml)
  13175. {
  13176. s -= 1;
  13177. }
  13178. return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  13179. }
  13180. };
  13181. var vertexHandlerCreateSizerShape = mxVertexHandler.prototype.createSizerShape;
  13182. mxVertexHandler.prototype.createSizerShape = function(bounds, index, fillColor, image)
  13183. {
  13184. image = (index == mxEvent.ROTATION_HANDLE) ? HoverIcons.prototype.rotationHandle :
  13185. (index == mxEvent.LABEL_HANDLE) ? this.secondaryHandleImage : image;
  13186. return vertexHandlerCreateSizerShape.apply(this, arguments);
  13187. };
  13188. // Special case for single edge label handle moving in which case the text bounding box is used
  13189. var mxGraphHandlerGetBoundingBox = mxGraphHandler.prototype.getBoundingBox;
  13190. mxGraphHandler.prototype.getBoundingBox = function(cells)
  13191. {
  13192. if (cells != null && cells.length == 1)
  13193. {
  13194. var model = this.graph.getModel();
  13195. var parent = model.getParent(cells[0]);
  13196. var geo = this.graph.getCellGeometry(cells[0]);
  13197. if (model.isEdge(parent) && geo != null && geo.relative)
  13198. {
  13199. var state = this.graph.view.getState(cells[0]);
  13200. if (state != null && state.width < 2 && state.height < 2 && state.text != null &&
  13201. state.text.boundingBox != null)
  13202. {
  13203. return mxRectangle.fromRectangle(state.text.boundingBox);
  13204. }
  13205. }
  13206. }
  13207. return mxGraphHandlerGetBoundingBox.apply(this, arguments);
  13208. };
  13209. // Ignores child cells with part style as guides
  13210. var mxGraphHandlerGetGuideStates = mxGraphHandler.prototype.getGuideStates;
  13211. mxGraphHandler.prototype.getGuideStates = function()
  13212. {
  13213. var states = mxGraphHandlerGetGuideStates.apply(this, arguments);
  13214. var result = [];
  13215. // NOTE: Could do via isStateIgnored hook
  13216. for (var i = 0; i < states.length; i++)
  13217. {
  13218. if (mxUtils.getValue(states[i].style, 'part', '0') != '1')
  13219. {
  13220. result.push(states[i]);
  13221. }
  13222. }
  13223. return result;
  13224. };
  13225. // Uses text bounding box for edge labels
  13226. var mxVertexHandlerGetSelectionBounds = mxVertexHandler.prototype.getSelectionBounds;
  13227. mxVertexHandler.prototype.getSelectionBounds = function(state)
  13228. {
  13229. var model = this.graph.getModel();
  13230. var parent = model.getParent(state.cell);
  13231. var geo = this.graph.getCellGeometry(state.cell);
  13232. if (model.isEdge(parent) && geo != null && geo.relative && state.width < 2 && state.height < 2 && state.text != null && state.text.boundingBox != null)
  13233. {
  13234. var bbox = state.text.unrotatedBoundingBox || state.text.boundingBox;
  13235. return new mxRectangle(Math.round(bbox.x), Math.round(bbox.y), Math.round(bbox.width), Math.round(bbox.height));
  13236. }
  13237. else
  13238. {
  13239. return mxVertexHandlerGetSelectionBounds.apply(this, arguments);
  13240. }
  13241. };
  13242. // Redirects moving of edge labels to mxGraphHandler by not starting here.
  13243. // This will use the move preview of mxGraphHandler (see above).
  13244. var mxVertexHandlerMouseDown = mxVertexHandler.prototype.mouseDown;
  13245. mxVertexHandler.prototype.mouseDown = function(sender, me)
  13246. {
  13247. var model = this.graph.getModel();
  13248. var parent = model.getParent(this.state.cell);
  13249. var geo = this.graph.getCellGeometry(this.state.cell);
  13250. // Lets rotation events through
  13251. var handle = this.getHandleForEvent(me);
  13252. if (handle == mxEvent.ROTATION_HANDLE || !model.isEdge(parent) || geo == null || !geo.relative ||
  13253. this.state == null || this.state.width >= 2 || this.state.height >= 2)
  13254. {
  13255. mxVertexHandlerMouseDown.apply(this, arguments);
  13256. }
  13257. };
  13258. // Invokes turn on single click on rotation handle
  13259. mxVertexHandler.prototype.rotateClick = function()
  13260. {
  13261. var stroke = mxUtils.getValue(this.state.style, mxConstants.STYLE_STROKECOLOR, mxConstants.NONE);
  13262. var fill = mxUtils.getValue(this.state.style, mxConstants.STYLE_FILLCOLOR, mxConstants.NONE);
  13263. if (this.state.view.graph.model.isVertex(this.state.cell) &&
  13264. stroke == mxConstants.NONE && fill == mxConstants.NONE)
  13265. {
  13266. var angle = mxUtils.mod(mxUtils.getValue(this.state.style, mxConstants.STYLE_ROTATION, 0) + 90, 360);
  13267. this.state.view.graph.setCellStyles(mxConstants.STYLE_ROTATION, angle, [this.state.cell]);
  13268. }
  13269. else
  13270. {
  13271. this.state.view.graph.turnShapes([this.state.cell]);
  13272. }
  13273. };
  13274. var vertexHandlerMouseMove = mxVertexHandler.prototype.mouseMove;
  13275. // Workaround for "isConsumed not defined" in MS Edge is to use arguments
  13276. mxVertexHandler.prototype.mouseMove = function(sender, me)
  13277. {
  13278. vertexHandlerMouseMove.apply(this, arguments);
  13279. if (this.graph.graphHandler.first != null)
  13280. {
  13281. if (this.rotationShape != null && this.rotationShape.node != null)
  13282. {
  13283. this.rotationShape.node.style.display = 'none';
  13284. }
  13285. if (this.linkHint != null && this.linkHint.style.display != 'none')
  13286. {
  13287. this.linkHint.style.display = 'none';
  13288. }
  13289. }
  13290. };
  13291. var vertexHandlerMouseUp = mxVertexHandler.prototype.mouseUp;
  13292. mxVertexHandler.prototype.mouseUp = function(sender, me)
  13293. {
  13294. vertexHandlerMouseUp.apply(this, arguments);
  13295. // Shows rotation handle only if one vertex is selected
  13296. if (this.rotationShape != null && this.rotationShape.node != null)
  13297. {
  13298. this.rotationShape.node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  13299. }
  13300. if (this.linkHint != null && this.linkHint.style.display == 'none' &&
  13301. this.graph.getSelectionCount() == 1)
  13302. {
  13303. this.linkHint.style.display = '';
  13304. }
  13305. // Resets state after gesture
  13306. this.blockDelayedSelection = null;
  13307. };
  13308. mxVertexHandler.prototype.updateLinkHint = function(link, links)
  13309. {
  13310. try
  13311. {
  13312. if (link == null && (links == null || links.length == 0))
  13313. {
  13314. if (this.linkHint != null)
  13315. {
  13316. this.linkHint.parentNode.removeChild(this.linkHint);
  13317. this.linkHint = null;
  13318. }
  13319. }
  13320. else if (link != null || (links != null && links.length > 0))
  13321. {
  13322. var img = document.createElement('img');
  13323. img.className = 'geAdaptiveAsset';
  13324. img.setAttribute('src', Editor.editImage);
  13325. img.setAttribute('title', mxResources.get('editLink'));
  13326. img.setAttribute('width', '14');
  13327. img.setAttribute('height', '14');
  13328. img.style.paddingLeft = '8px';
  13329. img.style.marginLeft = 'auto';
  13330. img.style.marginBottom = '-1px';
  13331. img.style.cursor = 'pointer';
  13332. var trash = img.cloneNode(true);
  13333. trash.setAttribute('src', Editor.trashImage);
  13334. trash.setAttribute('title', mxResources.get('removeIt',
  13335. [mxResources.get('link')]));
  13336. trash.style.paddingLeft = '4px';
  13337. trash.style.marginLeft = '0';
  13338. if (this.linkHint == null)
  13339. {
  13340. this.linkHint = createHint();
  13341. mxUtils.setPrefixedStyle(this.linkHint.style, 'transform', 'translate(-50%,0)');
  13342. this.linkHint.style.padding = '6px 8px 6px 8px';
  13343. this.linkHint.style.opacity = '1';
  13344. this.linkHint.style.filter = '';
  13345. this.graph.container.appendChild(this.linkHint);
  13346. mxEvent.addListener(this.linkHint, 'mouseenter', mxUtils.bind(this, function()
  13347. {
  13348. this.graph.tooltipHandler.hide();
  13349. }));
  13350. }
  13351. this.linkHint.innerText = '';
  13352. if (link != null)
  13353. {
  13354. var wrapper = document.createElement('div');
  13355. wrapper.style.display = 'flex';
  13356. wrapper.style.alignItems = 'center';
  13357. wrapper.appendChild(this.graph.createLinkForHint(link, null, this.state.cell));
  13358. this.linkHint.appendChild(wrapper);
  13359. if (this.graph.isEnabled() && typeof this.graph.editLink === 'function' &&
  13360. !this.graph.isCellLocked(this.state.cell))
  13361. {
  13362. var changeLink = img.cloneNode(true);
  13363. wrapper.appendChild(changeLink);
  13364. mxEvent.addListener(changeLink, 'click', mxUtils.bind(this, function(evt)
  13365. {
  13366. this.graph.setSelectionCell(this.state.cell);
  13367. this.graph.editLink();
  13368. mxEvent.consume(evt);
  13369. }));
  13370. var trashLink = trash.cloneNode(true);
  13371. wrapper.appendChild(trashLink);
  13372. mxEvent.addListener(trashLink, 'click', mxUtils.bind(this, function(evt)
  13373. {
  13374. this.graph.setLinkForCell(this.state.cell, null);
  13375. mxEvent.consume(evt);
  13376. }));
  13377. }
  13378. }
  13379. if (links != null)
  13380. {
  13381. for (var i = 0; i < links.length; i++)
  13382. {
  13383. (mxUtils.bind(this, function(currentLink, index)
  13384. {
  13385. var div = document.createElement('div');
  13386. div.style.display = 'flex';
  13387. div.style.alignItems = 'center';
  13388. div.style.marginTop = (link != null || index > 0) ? '6px' : '0px';
  13389. div.appendChild(this.graph.createLinkForHint(
  13390. currentLink.getAttribute('href'),
  13391. mxUtils.getTextContent(currentLink),
  13392. this.state.cell));
  13393. var changeLink = img.cloneNode(true);
  13394. div.appendChild(changeLink);
  13395. var updateLink = mxUtils.bind(this, function(value)
  13396. {
  13397. var tmp = document.createElement('div');
  13398. tmp.innerHTML = Graph.sanitizeHtml(this.graph.getLabel(this.state.cell));
  13399. var anchor = tmp.getElementsByTagName('a')[index];
  13400. if (anchor != null)
  13401. {
  13402. if (value == null || value == '')
  13403. {
  13404. var child = anchor.cloneNode(true).firstChild;
  13405. while (child != null)
  13406. {
  13407. anchor.parentNode.insertBefore(child.cloneNode(true), anchor);
  13408. child = child.nextSibling;
  13409. }
  13410. anchor.parentNode.removeChild(anchor);
  13411. }
  13412. else
  13413. {
  13414. anchor.setAttribute('href', value);
  13415. }
  13416. this.graph.labelChanged(this.state.cell, tmp.innerHTML);
  13417. }
  13418. });
  13419. mxEvent.addListener(changeLink, 'click', mxUtils.bind(this, function(evt)
  13420. {
  13421. this.graph.showLinkDialog(currentLink.getAttribute('href') || '',
  13422. mxResources.get('ok'), updateLink);
  13423. mxEvent.consume(evt);
  13424. }));
  13425. var trashLink = trash.cloneNode(true);
  13426. div.appendChild(trashLink);
  13427. mxEvent.addListener(trashLink, 'click', mxUtils.bind(this, function(evt)
  13428. {
  13429. updateLink();
  13430. mxEvent.consume(evt);
  13431. }));
  13432. this.linkHint.appendChild(div);
  13433. }))(links[i], i);
  13434. }
  13435. }
  13436. }
  13437. if (this.linkHint != null)
  13438. {
  13439. Graph.sanitizeNode(this.linkHint);
  13440. }
  13441. }
  13442. catch (e)
  13443. {
  13444. // ignore
  13445. }
  13446. };
  13447. mxEdgeHandler.prototype.updateLinkHint = mxVertexHandler.prototype.updateLinkHint;
  13448. // Extends constraint handler
  13449. var edgeHandlerCreateConstraintHandler = mxEdgeHandler.prototype.createConstraintHandler;
  13450. mxEdgeHandler.prototype.createConstraintHandler = function()
  13451. {
  13452. var handler = edgeHandlerCreateConstraintHandler.apply(this, arguments);
  13453. // Disables connection points
  13454. handler.isEnabled = mxUtils.bind(this, function()
  13455. {
  13456. return this.state.view.graph.connectionHandler.isEnabled();
  13457. });
  13458. return handler;
  13459. };
  13460. // Disables connection points
  13461. var connectionHandlerInit = mxConnectionHandler.prototype.init;
  13462. mxConnectionHandler.prototype.init = function()
  13463. {
  13464. connectionHandlerInit.apply(this, arguments);
  13465. this.constraintHandler.isEnabled = mxUtils.bind(this, function()
  13466. {
  13467. return this.graph.connectionHandler.isEnabled();
  13468. });
  13469. };
  13470. // Updates special handles
  13471. var vertexHandlerRedrawHandles = mxVertexHandler.prototype.redrawHandles;
  13472. mxVertexHandler.prototype.redrawHandles = function()
  13473. {
  13474. if (this.moveHandles != null)
  13475. {
  13476. for (var i = 0; i < this.moveHandles.length; i++)
  13477. {
  13478. if (this.moveHandles[i] != null)
  13479. {
  13480. this.moveHandles[i].bounds.x = Math.round(this.moveHandles[i].rowState.x +
  13481. this.moveHandles[i].rowState.width - this.moveHandles[i].bounds.width / 2);
  13482. this.moveHandles[i].bounds.y = Math.round(this.moveHandles[i].rowState.y +
  13483. (this.moveHandles[i].rowState.height - this.moveHandles[i].bounds.height) / 2);
  13484. this.moveHandles[i].redraw();
  13485. }
  13486. }
  13487. }
  13488. if (this.cornerHandles != null)
  13489. {
  13490. var inset = this.getSelectionBorderInset();
  13491. var ch = this.cornerHandles;
  13492. var w = ch[0].bounds.width / 2;
  13493. var h = ch[0].bounds.height / 2;
  13494. ch[0].bounds.x = this.state.x - w + inset;
  13495. ch[0].bounds.y = this.state.y - h + inset;
  13496. ch[0].redraw();
  13497. ch[1].bounds.x = ch[0].bounds.x + this.state.width - 2 * inset;
  13498. ch[1].bounds.y = ch[0].bounds.y;
  13499. ch[1].redraw();
  13500. ch[2].bounds.x = ch[0].bounds.x;
  13501. ch[2].bounds.y = this.state.y + this.state.height - 2 * inset;
  13502. ch[2].redraw();
  13503. ch[3].bounds.x = ch[1].bounds.x;
  13504. ch[3].bounds.y = ch[2].bounds.y;
  13505. ch[3].redraw();
  13506. for (var i = 0; i < this.cornerHandles.length; i++)
  13507. {
  13508. this.cornerHandles[i].node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  13509. }
  13510. }
  13511. // Shows rotation handle only if one vertex is selected
  13512. if (this.rotationShape != null && this.rotationShape.node != null)
  13513. {
  13514. this.rotationShape.node.setAttribute('title', mxResources.get('rotateTooltip'));
  13515. this.rotationShape.node.style.display = (this.moveHandles == null &&
  13516. (this.graph.getSelectionCount() == 1 && (this.index == null ||
  13517. this.index == mxEvent.ROTATION_HANDLE))) ? '' : 'none';
  13518. }
  13519. vertexHandlerRedrawHandles.apply(this);
  13520. if (this.state != null && this.linkHint != null)
  13521. {
  13522. var c = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  13523. var tmp = new mxRectangle(this.state.x, this.state.y - 22, this.state.width + 24, this.state.height + 22);
  13524. var bb = mxUtils.getBoundingBox(tmp, this.state.style[mxConstants.STYLE_ROTATION] || '0', c);
  13525. var rs = (bb != null) ? mxUtils.getBoundingBox(this.state,
  13526. this.state.style[mxConstants.STYLE_ROTATION] || '0') : this.state;
  13527. var tb = (this.state.text != null) ? this.state.text.boundingBox : null;
  13528. if (bb == null)
  13529. {
  13530. bb = this.state;
  13531. }
  13532. var b = bb.y + bb.height;
  13533. if (tb != null)
  13534. {
  13535. b = Math.max(b, tb.y + tb.height);
  13536. }
  13537. this.linkHint.style.left = (rs.x + rs.width / 2) + 'px';
  13538. this.linkHint.style.top = Math.round(b + this.verticalOffset / 2 + Editor.hintOffset) + 'px';
  13539. this.linkHint.style.display = (this.graph.getSelectionCount() > 1) ? 'none' : '';
  13540. }
  13541. };
  13542. // Destroys special handles
  13543. var vertexHandlerDestroy = mxVertexHandler.prototype.destroy;
  13544. mxVertexHandler.prototype.destroy = function()
  13545. {
  13546. vertexHandlerDestroy.apply(this, arguments);
  13547. this.destroyMoveHandles();
  13548. this.destroyCornerHandles();
  13549. if (this.linkHint != null)
  13550. {
  13551. if (this.linkHint.parentNode != null)
  13552. {
  13553. this.linkHint.parentNode.removeChild(this.linkHint);
  13554. }
  13555. this.linkHint = null;
  13556. }
  13557. if (this.changeHandler != null)
  13558. {
  13559. this.graph.getSelectionModel().removeListener(this.changeHandler);
  13560. this.graph.getModel().removeListener(this.changeHandler);
  13561. this.changeHandler = null;
  13562. }
  13563. if (this.editingHandler != null)
  13564. {
  13565. this.graph.removeListener(this.editingHandler);
  13566. this.editingHandler = null;
  13567. }
  13568. };
  13569. var edgeHandlerRedrawHandles = mxEdgeHandler.prototype.redrawHandles;
  13570. mxEdgeHandler.prototype.redrawHandles = function()
  13571. {
  13572. // Workaround for special case where handler
  13573. // is reset before this which leads to a NPE
  13574. if (this.marker != null)
  13575. {
  13576. edgeHandlerRedrawHandles.apply(this);
  13577. if (this.state != null && this.linkHint != null)
  13578. {
  13579. var b = this.state;
  13580. if (this.state.text != null && this.state.text.bounds != null)
  13581. {
  13582. b = new mxRectangle(b.x, b.y, b.width, b.height);
  13583. b.add(this.state.text.bounds);
  13584. }
  13585. this.linkHint.style.left = (b.x + b.width / 2) + 'px';
  13586. this.linkHint.style.top = Math.round(b.y + b.height + Editor.hintOffset) + 'px';
  13587. this.linkHint.style.display = (this.graph.getSelectionCount() > 1) ? 'none' : '';
  13588. }
  13589. }
  13590. };
  13591. var edgeHandlerReset = mxEdgeHandler.prototype.reset;
  13592. mxEdgeHandler.prototype.reset = function()
  13593. {
  13594. edgeHandlerReset.apply(this, arguments);
  13595. if (this.linkHint != null)
  13596. {
  13597. this.linkHint.style.visibility = '';
  13598. }
  13599. };
  13600. var edgeHandlerDestroy = mxEdgeHandler.prototype.destroy;
  13601. mxEdgeHandler.prototype.destroy = function()
  13602. {
  13603. edgeHandlerDestroy.apply(this, arguments);
  13604. if (this.linkHint != null)
  13605. {
  13606. this.linkHint.parentNode.removeChild(this.linkHint);
  13607. this.linkHint = null;
  13608. }
  13609. if (this.changeHandler != null)
  13610. {
  13611. this.graph.getModel().removeListener(this.changeHandler);
  13612. this.graph.getSelectionModel().removeListener(this.changeHandler);
  13613. this.changeHandler = null;
  13614. }
  13615. };
  13616. })();
  13617. }