Graph.js 366 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128
  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. var parseXml = mxUtils.parseXml;
  13. mxUtils.parseXml = function(text)
  14. {
  15. for (var i = 0; i < entities.length; i++)
  16. {
  17. text = text.replace(new RegExp(
  18. '&' + entities[i][0] + ';', 'g'),
  19. '&#' + entities[i][1] + ';');
  20. }
  21. return parseXml(text);
  22. };
  23. })();
  24. // Shim for missing toISOString in older versions of IE
  25. // See https://stackoverflow.com/questions/12907862
  26. if (!Date.prototype.toISOString)
  27. {
  28. (function()
  29. {
  30. function pad(number)
  31. {
  32. var r = String(number);
  33. if (r.length === 1)
  34. {
  35. r = '0' + r;
  36. }
  37. return r;
  38. };
  39. Date.prototype.toISOString = function()
  40. {
  41. return this.getUTCFullYear()
  42. + '-' + pad( this.getUTCMonth() + 1 )
  43. + '-' + pad( this.getUTCDate() )
  44. + 'T' + pad( this.getUTCHours() )
  45. + ':' + pad( this.getUTCMinutes() )
  46. + ':' + pad( this.getUTCSeconds() )
  47. + '.' + String( (this.getUTCMilliseconds()/1000).toFixed(3) ).slice( 2, 5 )
  48. + 'Z';
  49. };
  50. }());
  51. }
  52. // Shim for Date.now()
  53. if (!Date.now)
  54. {
  55. Date.now = function()
  56. {
  57. return new Date().getTime();
  58. };
  59. }
  60. // Polyfill for Uint8Array.from in IE11 used in Graph.decompress
  61. // See https://stackoverflow.com/questions/36810940/alternative-or-polyfill-for-array-from-on-the-internet-explorer
  62. if (!Uint8Array.from) {
  63. Uint8Array.from = (function () {
  64. var toStr = Object.prototype.toString;
  65. var isCallable = function (fn) {
  66. return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
  67. };
  68. var toInteger = function (value) {
  69. var number = Number(value);
  70. if (isNaN(number)) { return 0; }
  71. if (number === 0 || !isFinite(number)) { return number; }
  72. return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
  73. };
  74. var maxSafeInteger = Math.pow(2, 53) - 1;
  75. var toLength = function (value) {
  76. var len = toInteger(value);
  77. return Math.min(Math.max(len, 0), maxSafeInteger);
  78. };
  79. // The length property of the from method is 1.
  80. return function from(arrayLike/*, mapFn, thisArg */) {
  81. // 1. Let C be the this value.
  82. var C = this;
  83. // 2. Let items be ToObject(arrayLike).
  84. var items = Object(arrayLike);
  85. // 3. ReturnIfAbrupt(items).
  86. if (arrayLike == null) {
  87. throw new TypeError("Array.from requires an array-like object - not null or undefined");
  88. }
  89. // 4. If mapfn is undefined, then let mapping be false.
  90. var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
  91. var T;
  92. if (typeof mapFn !== 'undefined') {
  93. // 5. else
  94. // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
  95. if (!isCallable(mapFn)) {
  96. throw new TypeError('Array.from: when provided, the second argument must be a function');
  97. }
  98. // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
  99. if (arguments.length > 2) {
  100. T = arguments[2];
  101. }
  102. }
  103. // 10. Let lenValue be Get(items, "length").
  104. // 11. Let len be ToLength(lenValue).
  105. var len = toLength(items.length);
  106. // 13. If IsConstructor(C) is true, then
  107. // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
  108. // 14. a. Else, Let A be ArrayCreate(len).
  109. var A = isCallable(C) ? Object(new C(len)) : new Array(len);
  110. // 16. Let k be 0.
  111. var k = 0;
  112. // 17. Repeat, while k < len… (also steps a - h)
  113. var kValue;
  114. while (k < len) {
  115. kValue = items[k];
  116. if (mapFn) {
  117. A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
  118. } else {
  119. A[k] = kValue;
  120. }
  121. k += 1;
  122. }
  123. // 18. Let putStatus be Put(A, "length", len, true).
  124. A.length = len;
  125. // 20. Return A.
  126. return A;
  127. };
  128. }());
  129. }
  130. // Changes default colors
  131. /**
  132. * Measurements Units
  133. */
  134. mxConstants.POINTS = 1;
  135. mxConstants.MILLIMETERS = 2;
  136. mxConstants.INCHES = 3;
  137. mxConstants.METERS = 4;
  138. /**
  139. * This ratio is with page scale 1
  140. */
  141. mxConstants.PIXELS_PER_MM = 3.937;
  142. mxConstants.PIXELS_PER_INCH = 100;
  143. mxConstants.SHADOW_OPACITY = 0.25;
  144. mxConstants.SHADOWCOLOR = '#000000';
  145. mxConstants.VML_SHADOWCOLOR = '#d0d0d0';
  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 = '#6e6e6e';
  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 = 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. /**
  213. * Constructs a new graph instance. Note that the constructor does not take a
  214. * container because the graph instance is needed for creating the UI, which
  215. * in turn will create the container for the graph. Hence, the container is
  216. * assigned later in EditorUi.
  217. */
  218. /**
  219. * Defines graph class.
  220. */
  221. Graph = function(container, model, renderHint, stylesheet, themes, standalone)
  222. {
  223. mxGraph.call(this, container, model, renderHint, stylesheet);
  224. this.themes = themes || this.defaultThemes;
  225. this.currentEdgeStyle = mxUtils.clone(this.defaultEdgeStyle);
  226. this.currentVertexStyle = mxUtils.clone(this.defaultVertexStyle);
  227. this.standalone = (standalone != null) ? standalone : false;
  228. // Sets the base domain URL and domain path URL for relative links.
  229. var b = this.baseUrl;
  230. var p = b.indexOf('//');
  231. this.domainUrl = '';
  232. this.domainPathUrl = '';
  233. if (p > 0)
  234. {
  235. var d = b.indexOf('/', p + 2);
  236. if (d > 0)
  237. {
  238. this.domainUrl = b.substring(0, d);
  239. }
  240. d = b.lastIndexOf('/');
  241. if (d > 0)
  242. {
  243. this.domainPathUrl = b.substring(0, d + 1);
  244. }
  245. }
  246. // Adds support for HTML labels via style. Note: Currently, only the Java
  247. // backend supports HTML labels but CSS support is limited to the following:
  248. // http://docs.oracle.com/javase/6/docs/api/index.html?javax/swing/text/html/CSS.html
  249. // TODO: Wrap should not affect isHtmlLabel output (should be handled later)
  250. this.isHtmlLabel = function(cell)
  251. {
  252. var style = this.getCurrentCellStyle(cell);
  253. return (style != null) ? (style['html'] == '1' || style[mxConstants.STYLE_WHITE_SPACE] == 'wrap') : false;
  254. };
  255. // Implements a listener for hover and click handling on edges
  256. if (this.edgeMode)
  257. {
  258. var start = {
  259. point: null,
  260. event: null,
  261. state: null,
  262. handle: null,
  263. selected: false
  264. };
  265. // Uses this event to process mouseDown to check the selection state before it is changed
  266. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  267. {
  268. if (evt.getProperty('eventName') == 'mouseDown' && this.isEnabled())
  269. {
  270. var me = evt.getProperty('event');
  271. var state = me.getState();
  272. var s = this.view.scale;
  273. if (!mxEvent.isAltDown(me.getEvent()) && state != null)
  274. {
  275. // Checks if state was removed in call to stopEditing above
  276. if (this.model.isEdge(state.cell))
  277. {
  278. start.point = new mxPoint(me.getGraphX(), me.getGraphY());
  279. start.selected = this.isCellSelected(state.cell);
  280. start.state = state;
  281. start.event = me;
  282. if (state.text != null && state.text.boundingBox != null &&
  283. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  284. {
  285. start.handle = mxEvent.LABEL_HANDLE;
  286. }
  287. else
  288. {
  289. var handler = this.selectionCellsHandler.getHandler(state.cell);
  290. if (handler != null && handler.bends != null && handler.bends.length > 0)
  291. {
  292. start.handle = handler.getHandleForEvent(me);
  293. }
  294. }
  295. }
  296. else if (!this.panningHandler.isActive() && !mxEvent.isControlDown(me.getEvent()))
  297. {
  298. var handler = this.selectionCellsHandler.getHandler(state.cell);
  299. // Cell handles have precedence over row and col resize
  300. if (handler == null || handler.getHandleForEvent(me) == null)
  301. {
  302. var box = new mxRectangle(me.getGraphX() - 1, me.getGraphY() - 1);
  303. var tol = mxEvent.isTouchEvent(me.getEvent()) ?
  304. mxShape.prototype.svgStrokeTolerance - 1 :
  305. (mxShape.prototype.svgStrokeTolerance + 2) / 2;
  306. var t1 = tol + 2;
  307. box.grow(tol);
  308. // Ignores clicks inside cell to avoid delayed selection on
  309. // merged cells when clicking on invisible part of dividers
  310. if (this.isTableCell(state.cell) && !this.isCellSelected(state.cell) &&
  311. (!mxUtils.contains(state, me.getGraphX() - t1, me.getGraphY() - t1) ||
  312. !mxUtils.contains(state, me.getGraphX() - t1, me.getGraphY() + t1) ||
  313. !mxUtils.contains(state, me.getGraphX() + t1, me.getGraphY() + t1) ||
  314. !mxUtils.contains(state, me.getGraphX() + t1, me.getGraphY() - t1)))
  315. {
  316. var row = this.model.getParent(state.cell);
  317. var table = this.model.getParent(row);
  318. if (!this.isCellSelected(table))
  319. {
  320. var b = tol * s;
  321. var b2 = 2 * b;
  322. // Ignores events on top line of top row and left line of left column
  323. if ((this.model.getChildAt(table, 0) != row) && mxUtils.intersects(box,
  324. new mxRectangle(state.x, state.y - b, state.width, b2)) ||
  325. (this.model.getChildAt(row, 0) != state.cell) && mxUtils.intersects(box,
  326. new mxRectangle(state.x - b, state.y, b2, state.height)) ||
  327. mxUtils.intersects(box, new mxRectangle(state.x, state.y + state.height - b, state.width, b2)) ||
  328. mxUtils.intersects(box, new mxRectangle(state.x + state.width - b, state.y, b2, state.height)))
  329. {
  330. var wasSelected = this.selectionCellsHandler.isHandled(table);
  331. this.selectCellForEvent(table, me.getEvent());
  332. handler = this.selectionCellsHandler.getHandler(table);
  333. if (handler != null)
  334. {
  335. var handle = handler.getHandleForEvent(me);
  336. if (handle != null)
  337. {
  338. handler.start(me.getGraphX(), me.getGraphY(), handle);
  339. handler.blockDelayedSelection = !wasSelected;
  340. me.consume();
  341. }
  342. }
  343. }
  344. }
  345. }
  346. // Hover for swimlane start sizes inside tables
  347. var current = state;
  348. while (!me.isConsumed() && current != null && (this.isTableCell(current.cell) ||
  349. this.isTableRow(current.cell) || this.isTable(current.cell)))
  350. {
  351. if (this.isSwimlane(current.cell))
  352. {
  353. var offset = this.getActualStartSize(current.cell);
  354. if (((offset.x > 0 || offset.width > 0) && mxUtils.intersects(box, new mxRectangle(
  355. current.x + (offset.x - offset.width - 1) * s + ((offset.x == 0) ? current.width : 0),
  356. current.y, 1, current.height))) || ((offset.y > 0 || offset.height > 0) &&
  357. mxUtils.intersects(box, new mxRectangle(current.x, current.y + (offset.y -
  358. offset.height - 1) * s + ((offset.y == 0) ? current.height : 0), current.width, 1))))
  359. {
  360. this.selectCellForEvent(current.cell, me.getEvent());
  361. handler = this.selectionCellsHandler.getHandler(current.cell);
  362. if (handler != null)
  363. {
  364. // Swimlane start size handle is last custom handle
  365. var handle = mxEvent.CUSTOM_HANDLE - handler.customHandles.length + 1;
  366. handler.start(me.getGraphX(), me.getGraphY(), handle);
  367. me.consume();
  368. }
  369. }
  370. }
  371. current = this.view.getState(this.model.getParent(current.cell));
  372. }
  373. }
  374. }
  375. }
  376. }
  377. }));
  378. var mouseDown = null;
  379. this.addMouseListener(
  380. {
  381. mouseDown: function(sender, me) {},
  382. mouseMove: mxUtils.bind(this, function(sender, me)
  383. {
  384. // Checks if any other handler is active
  385. var handlerMap = this.selectionCellsHandler.handlers.map;
  386. for (var key in handlerMap)
  387. {
  388. if (handlerMap[key].index != null)
  389. {
  390. return;
  391. }
  392. }
  393. if (this.isEnabled() && !this.panningHandler.isActive() && !mxEvent.isAltDown(me.getEvent()))
  394. {
  395. var tol = this.tolerance;
  396. if (start.point != null && start.state != null && start.event != null)
  397. {
  398. var state = start.state;
  399. if (Math.abs(start.point.x - me.getGraphX()) > tol ||
  400. Math.abs(start.point.y - me.getGraphY()) > tol)
  401. {
  402. var handler = this.selectionCellsHandler.getHandler(state.cell);
  403. if (handler == null && this.model.isEdge(state.cell))
  404. {
  405. handler = this.createHandler(state);
  406. }
  407. if (handler != null && handler.bends != null && handler.bends.length > 0)
  408. {
  409. var handle = handler.getHandleForEvent(start.event);
  410. var edgeStyle = this.view.getEdgeStyle(state);
  411. var entity = edgeStyle == mxEdgeStyle.EntityRelation;
  412. // Handles special case where label was clicked on unselected edge in which
  413. // case the label will be moved regardless of the handle that is returned
  414. if (!start.selected && start.handle == mxEvent.LABEL_HANDLE)
  415. {
  416. handle = start.handle;
  417. }
  418. if (!entity || handle == 0 || handle == handler.bends.length - 1 || handle == mxEvent.LABEL_HANDLE)
  419. {
  420. // Source or target handle or connected for direct handle access or orthogonal line
  421. // with just two points where the central handle is moved regardless of mouse position
  422. if (handle == mxEvent.LABEL_HANDLE || handle == 0 || state.visibleSourceState != null ||
  423. handle == handler.bends.length - 1 || state.visibleTargetState != null)
  424. {
  425. if (!entity && handle != mxEvent.LABEL_HANDLE)
  426. {
  427. var pts = state.absolutePoints;
  428. // Default case where handles are at corner points handles
  429. // drag of corner as drag of existing point
  430. if (pts != null && ((edgeStyle == null && handle == null) ||
  431. edgeStyle == mxEdgeStyle.OrthConnector))
  432. {
  433. // Does not use handles if they were not initially visible
  434. handle = start.handle;
  435. if (handle == null)
  436. {
  437. var box = new mxRectangle(start.point.x, start.point.y);
  438. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  439. if (mxUtils.contains(box, pts[0].x, pts[0].y))
  440. {
  441. // Moves source terminal handle
  442. handle = 0;
  443. }
  444. else if (mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  445. {
  446. // Moves target terminal handle
  447. handle = handler.bends.length - 1;
  448. }
  449. else
  450. {
  451. // Checks if edge has no bends
  452. var nobends = edgeStyle != null && (pts.length == 2 || (pts.length == 3 &&
  453. ((Math.round(pts[0].x - pts[1].x) == 0 && Math.round(pts[1].x - pts[2].x) == 0) ||
  454. (Math.round(pts[0].y - pts[1].y) == 0 && Math.round(pts[1].y - pts[2].y) == 0))));
  455. if (nobends)
  456. {
  457. // Moves central handle for straight orthogonal edges
  458. handle = 2;
  459. }
  460. else
  461. {
  462. // Finds and moves vertical or horizontal segment
  463. handle = mxUtils.findNearestSegment(state, start.point.x, start.point.y);
  464. // Converts segment to virtual handle index
  465. if (edgeStyle == null)
  466. {
  467. handle = mxEvent.VIRTUAL_HANDLE - handle;
  468. }
  469. // Maps segment to handle
  470. else
  471. {
  472. handle += 1;
  473. }
  474. }
  475. }
  476. }
  477. }
  478. // Creates a new waypoint and starts moving it
  479. if (handle == null)
  480. {
  481. handle = mxEvent.VIRTUAL_HANDLE;
  482. }
  483. }
  484. handler.start(me.getGraphX(), me.getGraphX(), handle);
  485. me.consume();
  486. // Removes preview rectangle in graph handler
  487. this.graphHandler.reset();
  488. }
  489. }
  490. else if (entity && (state.visibleSourceState != null || state.visibleTargetState != null))
  491. {
  492. // Disables moves on entity to make it consistent
  493. this.graphHandler.reset();
  494. me.consume();
  495. }
  496. }
  497. if (handler != null)
  498. {
  499. // Lazy selection for edges inside groups
  500. if (this.selectionCellsHandler.isHandlerActive(handler))
  501. {
  502. if (!this.isCellSelected(state.cell))
  503. {
  504. this.selectionCellsHandler.handlers.put(state.cell, handler);
  505. this.selectCellForEvent(state.cell, me.getEvent());
  506. }
  507. }
  508. else if (!this.isCellSelected(state.cell))
  509. {
  510. // Destroy temporary handler
  511. handler.destroy();
  512. }
  513. }
  514. // Reset start state
  515. start.selected = false;
  516. start.handle = null;
  517. start.state = null;
  518. start.event = null;
  519. start.point = null;
  520. }
  521. }
  522. else
  523. {
  524. // Updates cursor for unselected edges under the mouse
  525. var state = me.getState();
  526. if (state != null && this.isCellEditable(state.cell))
  527. {
  528. var cursor = null;
  529. // Checks if state was removed in call to stopEditing above
  530. if (this.model.isEdge(state.cell))
  531. {
  532. var box = new mxRectangle(me.getGraphX(), me.getGraphY());
  533. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  534. var pts = state.absolutePoints;
  535. if (pts != null)
  536. {
  537. if (state.text != null && state.text.boundingBox != null &&
  538. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  539. {
  540. cursor = 'move';
  541. }
  542. else if (mxUtils.contains(box, pts[0].x, pts[0].y) ||
  543. mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  544. {
  545. cursor = 'pointer';
  546. }
  547. else if (state.visibleSourceState != null || state.visibleTargetState != null)
  548. {
  549. // Moving is not allowed for entity relation but still indicate hover state
  550. var tmp = this.view.getEdgeStyle(state);
  551. cursor = 'crosshair';
  552. if (tmp != mxEdgeStyle.EntityRelation && this.isOrthogonal(state))
  553. {
  554. var idx = mxUtils.findNearestSegment(state, me.getGraphX(), me.getGraphY());
  555. if (idx < pts.length - 1 && idx >= 0)
  556. {
  557. cursor = (Math.round(pts[idx].x - pts[idx + 1].x) == 0) ?
  558. 'col-resize' : 'row-resize';
  559. }
  560. }
  561. }
  562. }
  563. }
  564. else if (!mxEvent.isControlDown(me.getEvent()))
  565. {
  566. var tol = mxShape.prototype.svgStrokeTolerance / 2;
  567. var box = new mxRectangle(me.getGraphX(), me.getGraphY());
  568. box.grow(tol);
  569. if (this.isTableCell(state.cell))
  570. {
  571. var row = this.model.getParent(state.cell);
  572. var table = this.model.getParent(row);
  573. if (!this.isCellSelected(table))
  574. {
  575. if ((mxUtils.intersects(box, new mxRectangle(state.x, state.y - 2, state.width, 4)) &&
  576. this.model.getChildAt(table, 0) != row) || mxUtils.intersects(box,
  577. new mxRectangle(state.x, state.y + state.height - 2, state.width, 4)))
  578. {
  579. cursor ='row-resize';
  580. }
  581. else if ((mxUtils.intersects(box, new mxRectangle(state.x - 2, state.y, 4, state.height)) &&
  582. this.model.getChildAt(row, 0) != state.cell) || mxUtils.intersects(box,
  583. new mxRectangle(state.x + state.width - 2, state.y, 4, state.height)))
  584. {
  585. cursor ='col-resize';
  586. }
  587. }
  588. }
  589. // Hover for swimlane start sizes inside tables
  590. var current = state;
  591. while (cursor == null && current != null && (this.isTableCell(current.cell) ||
  592. this.isTableRow(current.cell) || this.isTable(current.cell)))
  593. {
  594. if (this.isSwimlane(current.cell))
  595. {
  596. var offset = this.getActualStartSize(current.cell);
  597. var s = this.view.scale;
  598. if ((offset.x > 0 || offset.width > 0) && mxUtils.intersects(box, new mxRectangle(
  599. current.x + (offset.x - offset.width - 1) * s + ((offset.x == 0) ? current.width * s : 0),
  600. current.y, 1, current.height)))
  601. {
  602. cursor ='col-resize';
  603. }
  604. else if ((offset.y > 0 || offset.height > 0) && mxUtils.intersects(box, new mxRectangle(
  605. current.x, current.y + (offset.y - offset.height - 1) * s + ((offset.y == 0) ? current.height : 0),
  606. current.width, 1)))
  607. {
  608. cursor ='row-resize';
  609. }
  610. }
  611. current = this.view.getState(this.model.getParent(current.cell));
  612. }
  613. }
  614. if (cursor != null)
  615. {
  616. state.setCursor(cursor);
  617. }
  618. }
  619. }
  620. }
  621. }),
  622. mouseUp: mxUtils.bind(this, function(sender, me)
  623. {
  624. start.state = null;
  625. start.event = null;
  626. start.point = null;
  627. start.handle = null;
  628. })
  629. });
  630. }
  631. this.cellRenderer.minSvgStrokeWidth = 0.1;
  632. // HTML entities are displayed as plain text in wrapped plain text labels
  633. this.cellRenderer.getLabelValue = function(state)
  634. {
  635. var result = mxCellRenderer.prototype.getLabelValue.apply(this, arguments);
  636. if (state.view.graph.isHtmlLabel(state.cell))
  637. {
  638. if (state.style['html'] != 1)
  639. {
  640. result = mxUtils.htmlEntities(result, false);
  641. }
  642. else
  643. {
  644. result = state.view.graph.sanitizeHtml(result);
  645. }
  646. }
  647. return result;
  648. };
  649. // All code below not available and not needed in embed mode
  650. if (typeof mxVertexHandler !== 'undefined')
  651. {
  652. this.setConnectable(true);
  653. this.setDropEnabled(true);
  654. this.setPanning(true);
  655. this.setTooltips(true);
  656. this.setAllowLoops(true);
  657. this.allowAutoPanning = true;
  658. this.resetEdgesOnConnect = false;
  659. this.constrainChildren = false;
  660. this.constrainRelativeChildren = true;
  661. // Do not scroll after moving cells
  662. this.graphHandler.scrollOnMove = false;
  663. this.graphHandler.scaleGrid = true;
  664. // Disables cloning of connection sources by default
  665. this.connectionHandler.setCreateTarget(false);
  666. this.connectionHandler.insertBeforeSource = true;
  667. // Disables built-in connection starts
  668. this.connectionHandler.isValidSource = function(cell, me)
  669. {
  670. return false;
  671. };
  672. // Sets the style to be used when an elbow edge is double clicked
  673. this.alternateEdgeStyle = 'vertical';
  674. if (stylesheet == null)
  675. {
  676. this.loadStylesheet();
  677. }
  678. // Adds page centers to the guides for moving cells
  679. var graphHandlerGetGuideStates = this.graphHandler.getGuideStates;
  680. this.graphHandler.getGuideStates = function()
  681. {
  682. var result = graphHandlerGetGuideStates.apply(this, arguments);
  683. // Create virtual cell state for page centers
  684. if (this.graph.pageVisible)
  685. {
  686. var guides = [];
  687. var pf = this.graph.pageFormat;
  688. var ps = this.graph.pageScale;
  689. var pw = pf.width * ps;
  690. var ph = pf.height * ps;
  691. var t = this.graph.view.translate;
  692. var s = this.graph.view.scale;
  693. var layout = this.graph.getPageLayout();
  694. for (var i = 0; i < layout.width; i++)
  695. {
  696. guides.push(new mxRectangle(((layout.x + i) * pw + t.x) * s,
  697. (layout.y * ph + t.y) * s, pw * s, ph * s));
  698. }
  699. for (var j = 1; j < layout.height; j++)
  700. {
  701. guides.push(new mxRectangle((layout.x * pw + t.x) * s,
  702. ((layout.y + j) * ph + t.y) * s, pw * s, ph * s));
  703. }
  704. // Page center guides have precedence over normal guides
  705. result = guides.concat(result);
  706. }
  707. return result;
  708. };
  709. // Overrides zIndex for dragElement
  710. mxDragSource.prototype.dragElementZIndex = mxPopupMenu.prototype.zIndex;
  711. // Overrides color for virtual guides for page centers
  712. mxGuide.prototype.getGuideColor = function(state, horizontal)
  713. {
  714. return (state.cell == null) ? '#ffa500' /* orange */ : mxConstants.GUIDE_COLOR;
  715. };
  716. // Changes color of move preview for black backgrounds
  717. this.graphHandler.createPreviewShape = function(bounds)
  718. {
  719. this.previewColor = (this.graph.background == '#000000') ? '#ffffff' : mxGraphHandler.prototype.previewColor;
  720. return mxGraphHandler.prototype.createPreviewShape.apply(this, arguments);
  721. };
  722. // Handles parts of cells by checking if part=1 is in the style and returning the parent
  723. // if the parent is not already in the list of cells. container style is used to disable
  724. // step into swimlanes and dropTarget style is used to disable acting as a drop target.
  725. // LATER: Handle recursive parts
  726. var graphHandlerGetCells = this.graphHandler.getCells;
  727. this.graphHandler.getCells = function(initialCell)
  728. {
  729. var cells = graphHandlerGetCells.apply(this, arguments);
  730. var lookup = new mxDictionary();
  731. var newCells = [];
  732. for (var i = 0; i < cells.length; i++)
  733. {
  734. // Propagates to composite parents or moves selected table rows
  735. var cell = (this.graph.isTableCell(initialCell) &&
  736. this.graph.isTableCell(cells[i]) &&
  737. this.graph.isCellSelected(cells[i])) ?
  738. this.graph.model.getParent(cells[i]) :
  739. ((this.graph.isTableRow(initialCell) &&
  740. this.graph.isTableRow(cells[i]) &&
  741. this.graph.isCellSelected(cells[i])) ?
  742. cells[i] : this.graph.getCompositeParent(cells[i]));
  743. if (cell != null && !lookup.get(cell))
  744. {
  745. lookup.put(cell, true);
  746. newCells.push(cell);
  747. }
  748. }
  749. return newCells;
  750. };
  751. // Handles parts and selected rows in tables of cells for drag and drop
  752. var graphHandlerStart = this.graphHandler.start;
  753. this.graphHandler.start = function(cell, x, y, cells)
  754. {
  755. // Propagates to selected table row to start move
  756. var ignoreParent = false;
  757. if (this.graph.isTableCell(cell))
  758. {
  759. if (!this.graph.isCellSelected(cell))
  760. {
  761. cell = this.graph.model.getParent(cell);
  762. }
  763. else
  764. {
  765. ignoreParent = true;
  766. }
  767. }
  768. if (!ignoreParent && (!this.graph.isTableRow(cell) || !this.graph.isCellSelected(cell)))
  769. {
  770. cell = this.graph.getCompositeParent(cell);
  771. }
  772. graphHandlerStart.apply(this, arguments);
  773. };
  774. // Handles parts of cells when cloning the source for new connections
  775. this.connectionHandler.createTargetVertex = function(evt, source)
  776. {
  777. source = this.graph.getCompositeParent(source);
  778. return mxConnectionHandler.prototype.createTargetVertex.apply(this, arguments);
  779. };
  780. var rubberband = new mxRubberband(this);
  781. this.getRubberband = function()
  782. {
  783. return rubberband;
  784. };
  785. // Timer-based activation of outline connect in connection handler
  786. var startTime = new Date().getTime();
  787. var timeOnTarget = 0;
  788. var connectionHandlerMouseMove = this.connectionHandler.mouseMove;
  789. this.connectionHandler.mouseMove = function()
  790. {
  791. var prev = this.currentState;
  792. connectionHandlerMouseMove.apply(this, arguments);
  793. if (prev != this.currentState)
  794. {
  795. startTime = new Date().getTime();
  796. timeOnTarget = 0;
  797. }
  798. else
  799. {
  800. timeOnTarget = new Date().getTime() - startTime;
  801. }
  802. };
  803. // Activates outline connect after 1500ms with touch event or if alt is pressed inside the shape
  804. // outlineConnect=0 is a custom style that means do not connect to strokes inside the shape,
  805. // or in other words, connect to the shape's perimeter if the highlight is under the mouse
  806. // (the name is because the highlight, including all strokes, is called outline in the code)
  807. var connectionHandleIsOutlineConnectEvent = this.connectionHandler.isOutlineConnectEvent;
  808. this.connectionHandler.isOutlineConnectEvent = function(me)
  809. {
  810. if (mxEvent.isShiftDown(me.getEvent()) && mxEvent.isAltDown(me.getEvent()))
  811. {
  812. return false;
  813. }
  814. else
  815. {
  816. return (this.currentState != null && me.getState() == this.currentState && timeOnTarget > 2000) ||
  817. ((this.currentState == null || mxUtils.getValue(this.currentState.style, 'outlineConnect', '1') != '0') &&
  818. connectionHandleIsOutlineConnectEvent.apply(this, arguments));
  819. }
  820. };
  821. // Adds shift+click to toggle selection state
  822. var isToggleEvent = this.isToggleEvent;
  823. this.isToggleEvent = function(evt)
  824. {
  825. return isToggleEvent.apply(this, arguments) || (!mxClient.IS_CHROMEOS && mxEvent.isShiftDown(evt));
  826. };
  827. // Workaround for Firefox where first mouse down is received
  828. // after tap and hold if scrollbars are visible, which means
  829. // start rubberband immediately if no cell is under mouse.
  830. var isForceRubberBandEvent = rubberband.isForceRubberbandEvent;
  831. rubberband.isForceRubberbandEvent = function(me)
  832. {
  833. return isForceRubberBandEvent.apply(this, arguments) ||
  834. (mxClient.IS_CHROMEOS && mxEvent.isShiftDown(me.getEvent())) ||
  835. (mxUtils.hasScrollbars(this.graph.container) && mxClient.IS_FF &&
  836. mxClient.IS_WIN && me.getState() == null && mxEvent.isTouchEvent(me.getEvent()));
  837. };
  838. // Shows hand cursor while panning
  839. var prevCursor = null;
  840. this.panningHandler.addListener(mxEvent.PAN_START, mxUtils.bind(this, function()
  841. {
  842. if (this.isEnabled())
  843. {
  844. prevCursor = this.container.style.cursor;
  845. this.container.style.cursor = 'move';
  846. }
  847. }));
  848. this.panningHandler.addListener(mxEvent.PAN_END, mxUtils.bind(this, function()
  849. {
  850. if (this.isEnabled())
  851. {
  852. this.container.style.cursor = prevCursor;
  853. }
  854. }));
  855. this.popupMenuHandler.autoExpand = true;
  856. this.popupMenuHandler.isSelectOnPopup = function(me)
  857. {
  858. return mxEvent.isMouseEvent(me.getEvent());
  859. };
  860. // Handles links if graph is read-only or cell is locked
  861. var click = this.click;
  862. this.click = function(me)
  863. {
  864. var locked = me.state == null && me.sourceState != null &&
  865. this.isCellLocked(me.sourceState.cell);
  866. if ((!this.isEnabled() || locked) && !me.isConsumed())
  867. {
  868. var cell = (locked) ? me.sourceState.cell : me.getCell();
  869. if (cell != null)
  870. {
  871. var link = this.getClickableLinkForCell(cell);
  872. if (link != null)
  873. {
  874. if (this.isCustomLink(link))
  875. {
  876. this.customLinkClicked(link);
  877. }
  878. else
  879. {
  880. this.openLink(link);
  881. }
  882. }
  883. }
  884. if (this.isEnabled() && locked)
  885. {
  886. this.clearSelection();
  887. }
  888. }
  889. else
  890. {
  891. return click.apply(this, arguments);
  892. }
  893. };
  894. // Redirects tooltips for locked cells
  895. this.tooltipHandler.getStateForEvent = function(me)
  896. {
  897. return me.sourceState;
  898. };
  899. // Opens links in tooltips in new windows
  900. var tooltipHandlerShow = this.tooltipHandler.show;
  901. this.tooltipHandler.show = function()
  902. {
  903. tooltipHandlerShow.apply(this, arguments);
  904. if (this.div != null)
  905. {
  906. var links = this.div.getElementsByTagName('a');
  907. for (var i = 0; i < links.length; i++)
  908. {
  909. if (links[i].getAttribute('href') != null &&
  910. links[i].getAttribute('target') == null)
  911. {
  912. links[i].setAttribute('target', '_blank');
  913. }
  914. }
  915. }
  916. };
  917. // Redirects tooltips for locked cells
  918. this.tooltipHandler.getStateForEvent = function(me)
  919. {
  920. return me.sourceState;
  921. };
  922. // Redirects cursor for locked cells
  923. var getCursorForMouseEvent = this.getCursorForMouseEvent;
  924. this.getCursorForMouseEvent = function(me)
  925. {
  926. var locked = me.state == null && me.sourceState != null && this.isCellLocked(me.sourceState.cell);
  927. return this.getCursorForCell((locked) ? me.sourceState.cell : me.getCell());
  928. };
  929. // Shows pointer cursor for clickable cells with links
  930. // ie. if the graph is disabled and cells cannot be selected
  931. var getCursorForCell = this.getCursorForCell;
  932. this.getCursorForCell = function(cell)
  933. {
  934. if (!this.isEnabled() || this.isCellLocked(cell))
  935. {
  936. var link = this.getClickableLinkForCell(cell);
  937. if (link != null)
  938. {
  939. return 'pointer';
  940. }
  941. else if (this.isCellLocked(cell))
  942. {
  943. return 'default';
  944. }
  945. }
  946. return getCursorForCell.apply(this, arguments);
  947. };
  948. // Changes rubberband selection ignore locked cells
  949. this.selectRegion = function(rect, evt)
  950. {
  951. var isect = (mxEvent.isAltDown(evt)) ? rect : null;
  952. var cells = this.getCells(rect.x, rect.y, rect.width, rect.height, null, null, isect, function(state)
  953. {
  954. return mxUtils.getValue(state.style, 'locked', '0') == '1';
  955. }, true);
  956. if (this.isToggleEvent(evt))
  957. {
  958. for (var i = 0; i < cells.length; i++)
  959. {
  960. this.selectCellForEvent(cells[i], evt);
  961. }
  962. }
  963. else
  964. {
  965. this.selectCellsForEvent(cells, evt);
  966. }
  967. return cells;
  968. };
  969. // Never removes cells from parents that are being moved
  970. var graphHandlerShouldRemoveCellsFromParent = this.graphHandler.shouldRemoveCellsFromParent;
  971. this.graphHandler.shouldRemoveCellsFromParent = function(parent, cells, evt)
  972. {
  973. if (this.graph.isCellSelected(parent))
  974. {
  975. return false;
  976. }
  977. return graphHandlerShouldRemoveCellsFromParent.apply(this, arguments);
  978. };
  979. // Unlocks all cells
  980. this.isCellLocked = function(cell)
  981. {
  982. while (cell != null)
  983. {
  984. if (mxUtils.getValue(this.getCurrentCellStyle(cell), 'locked', '0') == '1')
  985. {
  986. return true;
  987. }
  988. cell = this.model.getParent(cell);
  989. }
  990. return false;
  991. };
  992. var tapAndHoldSelection = null;
  993. // Uses this event to process mouseDown to check the selection state before it is changed
  994. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  995. {
  996. if (evt.getProperty('eventName') == 'mouseDown')
  997. {
  998. var me = evt.getProperty('event');
  999. var state = me.getState();
  1000. if (state != null && !this.isSelectionEmpty() && !this.isCellSelected(state.cell))
  1001. {
  1002. tapAndHoldSelection = this.getSelectionCells();
  1003. }
  1004. else
  1005. {
  1006. tapAndHoldSelection = null;
  1007. }
  1008. }
  1009. }));
  1010. // Tap and hold on background starts rubberband for multiple selected
  1011. // cells the cell associated with the event is deselected
  1012. this.addListener(mxEvent.TAP_AND_HOLD, mxUtils.bind(this, function(sender, evt)
  1013. {
  1014. if (!mxEvent.isMultiTouchEvent(evt))
  1015. {
  1016. var me = evt.getProperty('event');
  1017. var cell = evt.getProperty('cell');
  1018. if (cell == null)
  1019. {
  1020. var pt = mxUtils.convertPoint(this.container,
  1021. mxEvent.getClientX(me), mxEvent.getClientY(me));
  1022. rubberband.start(pt.x, pt.y);
  1023. }
  1024. else if (tapAndHoldSelection != null)
  1025. {
  1026. this.addSelectionCells(tapAndHoldSelection);
  1027. }
  1028. else if (this.getSelectionCount() > 1 && this.isCellSelected(cell))
  1029. {
  1030. this.removeSelectionCell(cell);
  1031. }
  1032. // Blocks further processing of the event
  1033. tapAndHoldSelection = null;
  1034. evt.consume();
  1035. }
  1036. }));
  1037. // On connect the target is selected and we clone the cell of the preview edge for insert
  1038. this.connectionHandler.selectCells = function(edge, target)
  1039. {
  1040. this.graph.setSelectionCell(target || edge);
  1041. };
  1042. // Shows connection points only if cell not selected and parent table not handled
  1043. this.connectionHandler.constraintHandler.isStateIgnored = function(state, source)
  1044. {
  1045. var graph = state.view.graph;
  1046. return source && (graph.isCellSelected(state.cell) || (graph.isTableRow(state.cell) &&
  1047. graph.selectionCellsHandler.isHandled(graph.model.getParent(state.cell))));
  1048. };
  1049. // Updates constraint handler if the selection changes
  1050. this.selectionModel.addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  1051. {
  1052. var ch = this.connectionHandler.constraintHandler;
  1053. if (ch.currentFocus != null && ch.isStateIgnored(ch.currentFocus, true))
  1054. {
  1055. ch.currentFocus = null;
  1056. ch.constraints = null;
  1057. ch.destroyIcons();
  1058. }
  1059. ch.destroyFocusHighlight();
  1060. }));
  1061. // Initializes touch interface
  1062. if (Graph.touchStyle)
  1063. {
  1064. this.initTouch();
  1065. }
  1066. /**
  1067. * Adds locking
  1068. */
  1069. var graphUpdateMouseEvent = this.updateMouseEvent;
  1070. this.updateMouseEvent = function(me)
  1071. {
  1072. me = graphUpdateMouseEvent.apply(this, arguments);
  1073. if (me.state != null && this.isCellLocked(me.getCell()))
  1074. {
  1075. me.state = null;
  1076. }
  1077. return me;
  1078. };
  1079. }
  1080. //Create a unique offset object for each graph instance.
  1081. this.currentTranslate = new mxPoint(0, 0);
  1082. };
  1083. /**
  1084. * Specifies if the touch UI should be used (cannot detect touch in FF so always on for Windows/Linux)
  1085. */
  1086. Graph.touchStyle = mxClient.IS_TOUCH || (mxClient.IS_FF && mxClient.IS_WIN) || navigator.maxTouchPoints > 0 ||
  1087. navigator.msMaxTouchPoints > 0 || window.urlParams == null || urlParams['touch'] == '1';
  1088. /**
  1089. * Shortcut for capability check.
  1090. */
  1091. Graph.fileSupport = window.File != null && window.FileReader != null && window.FileList != null &&
  1092. (window.urlParams == null || urlParams['filesupport'] != '0');
  1093. /**
  1094. * Shortcut for capability check.
  1095. */
  1096. Graph.translateDiagram = urlParams['translate-diagram'] == '1';
  1097. /**
  1098. * Shortcut for capability check.
  1099. */
  1100. Graph.diagramLanguage = (urlParams['diagram-language'] != null) ? urlParams['diagram-language'] : mxClient.language;
  1101. /**
  1102. * Default size for line jumps.
  1103. */
  1104. Graph.lineJumpsEnabled = true;
  1105. /**
  1106. * Default size for line jumps.
  1107. */
  1108. Graph.defaultJumpSize = 6;
  1109. /**
  1110. * Specifies if the mouse wheel is used for zoom without any modifiers.
  1111. */
  1112. Graph.zoomWheel = false;
  1113. /**
  1114. * Minimum width for table columns.
  1115. */
  1116. Graph.minTableColumnWidth = 20;
  1117. /**
  1118. * Minimum height for table rows.
  1119. */
  1120. Graph.minTableRowHeight = 20;
  1121. /**
  1122. * Text for foreign object warning.
  1123. */
  1124. Graph.foreignObjectWarningText = 'Text is not SVG - cannot display';
  1125. /**
  1126. * Link for foreign object warning.
  1127. */
  1128. Graph.foreignObjectWarningLink = 'https://www.diagrams.net/doc/faq/svg-export-text-problems';
  1129. /**
  1130. *
  1131. */
  1132. Graph.xmlDeclaration = '<?xml version="1.0" encoding="UTF-8"?>';
  1133. /**
  1134. *
  1135. */
  1136. Graph.svgDoctype = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ' +
  1137. '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
  1138. /**
  1139. *
  1140. */
  1141. Graph.svgFileComment = '<!-- Do not edit this file with editors other than diagrams.net -->'
  1142. /**
  1143. * Minimum height for table rows.
  1144. */
  1145. Graph.pasteStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSource', 'fontSize', 'fontColor', 'fontStyle',
  1146. 'align', 'verticalAlign', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor', 'swimlaneFillColor',
  1147. 'textOpacity', 'gradientDirection', 'glass', 'labelBackgroundColor', 'labelBorderColor', 'opacity',
  1148. 'spacing', 'spacingTop', 'spacingLeft', 'spacingBottom', 'spacingRight', 'endFill', 'endArrow',
  1149. 'endSize', 'targetPerimeterSpacing', 'startFill', 'startArrow', 'startSize', 'sourcePerimeterSpacing',
  1150. 'arcSize', 'comic', 'sketch', 'fillWeight', 'hachureGap', 'hachureAngle', 'jiggle', 'disableMultiStroke',
  1151. 'disableMultiStrokeFill', 'fillStyle', 'curveFitting', 'simplification', 'comicStyle'];
  1152. /**
  1153. * Whitelist for known layout names.
  1154. */
  1155. Graph.layoutNames = ['mxHierarchicalLayout', 'mxCircleLayout',
  1156. 'mxCompactTreeLayout', 'mxEdgeLabelLayout', 'mxFastOrganicLayout',
  1157. 'mxParallelEdgeLayout', 'mxPartitionLayout', 'mxRadialTreeLayout',
  1158. 'mxStackLayout'];
  1159. /**
  1160. * Creates a temporary graph instance for rendering off-screen content.
  1161. */
  1162. Graph.createOffscreenGraph = function(stylesheet)
  1163. {
  1164. var graph = new Graph(document.createElement('div'));
  1165. graph.stylesheet.styles = mxUtils.clone(stylesheet.styles);
  1166. graph.resetViewOnRootChange = false;
  1167. graph.setConnectable(false);
  1168. graph.gridEnabled = false;
  1169. graph.autoScroll = false;
  1170. graph.setTooltips(false);
  1171. graph.setEnabled(false);
  1172. // Container must be in the DOM for correct HTML rendering
  1173. graph.container.style.visibility = 'hidden';
  1174. graph.container.style.position = 'absolute';
  1175. graph.container.style.overflow = 'hidden';
  1176. graph.container.style.height = '1px';
  1177. graph.container.style.width = '1px';
  1178. return graph;
  1179. };
  1180. /**
  1181. * Helper function for creating SVG data URI.
  1182. */
  1183. Graph.createSvgImage = function(w, h, data, coordWidth, coordHeight)
  1184. {
  1185. var tmp = unescape(encodeURIComponent(Graph.svgDoctype +
  1186. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' + w + 'px" height="' + h + 'px" ' +
  1187. ((coordWidth != null && coordHeight != null) ? 'viewBox="0 0 ' + coordWidth + ' ' + coordHeight + '" ' : '') +
  1188. 'version="1.1">' + data + '</svg>'));
  1189. return new mxImage('data:image/svg+xml;base64,' + ((window.btoa) ? btoa(tmp) : Base64.encode(tmp, true)), w, h)
  1190. };
  1191. /**
  1192. * Helper function for creating an SVG node.
  1193. */
  1194. Graph.createSvgNode = function(x, y, w, h, background)
  1195. {
  1196. var svgDoc = mxUtils.createXmlDocument();
  1197. var root = (svgDoc.createElementNS != null) ?
  1198. svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') :
  1199. svgDoc.createElement('svg');
  1200. if (background != null)
  1201. {
  1202. if (root.style != null)
  1203. {
  1204. root.style.backgroundColor = background;
  1205. }
  1206. else
  1207. {
  1208. root.setAttribute('style', 'background-color:' + background);
  1209. }
  1210. }
  1211. if (svgDoc.createElementNS == null)
  1212. {
  1213. root.setAttribute('xmlns', mxConstants.NS_SVG);
  1214. root.setAttribute('xmlns:xlink', mxConstants.NS_XLINK);
  1215. }
  1216. else
  1217. {
  1218. // KNOWN: Ignored in IE9-11, adds namespace for each image element instead. No workaround.
  1219. root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', mxConstants.NS_XLINK);
  1220. }
  1221. root.setAttribute('version', '1.1');
  1222. root.setAttribute('width', w + 'px');
  1223. root.setAttribute('height', h + 'px');
  1224. root.setAttribute('viewBox', x + ' ' + y + ' ' + w + ' ' + h);
  1225. svgDoc.appendChild(root);
  1226. return root;
  1227. };
  1228. /**
  1229. * Helper function for creating an SVG node.
  1230. */
  1231. Graph.htmlToPng = function(html, w, h, fn)
  1232. {
  1233. var canvas = document.createElement('canvas');
  1234. canvas.width = w;
  1235. canvas.height = h;
  1236. var img = document.createElement('img');
  1237. img.onload = mxUtils.bind(this, function()
  1238. {
  1239. var ctx = canvas.getContext('2d');
  1240. ctx.drawImage(img, 0, 0)
  1241. fn(canvas.toDataURL());
  1242. });
  1243. img.src = 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">' +
  1244. '<foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml"><style>em{color:red;}</style><em>I</em> lick <span>cheese</span></div></foreignObject></svg>');
  1245. };
  1246. /**
  1247. * Removes all illegal control characters with ASCII code <32 except TAB, LF
  1248. * and CR.
  1249. */
  1250. Graph.zapGremlins = function(text)
  1251. {
  1252. var lastIndex = 0;
  1253. var checked = [];
  1254. for (var i = 0; i < text.length; i++)
  1255. {
  1256. var code = text.charCodeAt(i);
  1257. // Removes all control chars except TAB, LF and CR
  1258. if (!((code >= 32 || code == 9 || code == 10 || code == 13) &&
  1259. code != 0xFFFF && code != 0xFFFE))
  1260. {
  1261. checked.push(text.substring(lastIndex, i));
  1262. lastIndex = i + 1;
  1263. }
  1264. }
  1265. if (lastIndex > 0 && lastIndex < text.length)
  1266. {
  1267. checked.push(text.substring(lastIndex));
  1268. }
  1269. return (checked.length == 0) ? text : checked.join('');
  1270. };
  1271. /**
  1272. * Turns the given string into an array.
  1273. */
  1274. Graph.stringToBytes = function(str)
  1275. {
  1276. var arr = new Array(str.length);
  1277. for (var i = 0; i < str.length; i++)
  1278. {
  1279. arr[i] = str.charCodeAt(i);
  1280. }
  1281. return arr;
  1282. };
  1283. /**
  1284. * Turns the given array into a string.
  1285. */
  1286. Graph.bytesToString = function(arr)
  1287. {
  1288. var result = new Array(arr.length);
  1289. for (var i = 0; i < arr.length; i++)
  1290. {
  1291. result[i] = String.fromCharCode(arr[i]);
  1292. }
  1293. return result.join('');
  1294. };
  1295. /**
  1296. * Turns the given array into a string.
  1297. */
  1298. Graph.base64EncodeUnicode = function(str)
  1299. {
  1300. return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
  1301. return String.fromCharCode(parseInt(p1, 16))
  1302. }));
  1303. };
  1304. /**
  1305. * Turns the given array into a string.
  1306. */
  1307. Graph.base64DecodeUnicode = function(str)
  1308. {
  1309. return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
  1310. return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
  1311. }).join(''));
  1312. };
  1313. /**
  1314. * Returns a base64 encoded version of the compressed outer XML of the given node.
  1315. */
  1316. Graph.compressNode = function(node, checked)
  1317. {
  1318. var xml = mxUtils.getXml(node);
  1319. return Graph.compress((checked) ? xml : Graph.zapGremlins(xml));
  1320. };
  1321. /**
  1322. * Returns a string for the given array buffer.
  1323. */
  1324. Graph.arrayBufferToString = function(buffer)
  1325. {
  1326. var binary = '';
  1327. var bytes = new Uint8Array(buffer);
  1328. var len = bytes.byteLength;
  1329. for (var i = 0; i < len; i++)
  1330. {
  1331. binary += String.fromCharCode(bytes[i]);
  1332. }
  1333. return binary;
  1334. };
  1335. /**
  1336. * Returns an array buffer for the given string.
  1337. */
  1338. Graph.stringToArrayBuffer = function(data)
  1339. {
  1340. return Uint8Array.from(data, function (c)
  1341. {
  1342. return c.charCodeAt(0);
  1343. });
  1344. };
  1345. /**
  1346. * Returns index of a string in an array buffer (UInt8Array)
  1347. */
  1348. Graph.arrayBufferIndexOfString = function (uint8Array, str, start)
  1349. {
  1350. var c0 = str.charCodeAt(0), j = 1, p = -1;
  1351. //Index of first char
  1352. for (var i = start || 0; i < uint8Array.byteLength; i++)
  1353. {
  1354. if (uint8Array[i] == c0)
  1355. {
  1356. p = i;
  1357. break;
  1358. }
  1359. }
  1360. for (var i = p + 1; p > -1 && i < uint8Array.byteLength && i < p + str.length - 1; i++)
  1361. {
  1362. if (uint8Array[i] != str.charCodeAt(j))
  1363. {
  1364. return Graph.arrayBufferIndexOfString(uint8Array, str, p + 1);
  1365. }
  1366. j++;
  1367. }
  1368. return j == str.length - 1? p : -1;
  1369. };
  1370. /**
  1371. * Returns a base64 encoded version of the compressed string.
  1372. */
  1373. Graph.compress = function(data, deflate)
  1374. {
  1375. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1376. {
  1377. return data;
  1378. }
  1379. else
  1380. {
  1381. var tmp = (deflate) ? pako.deflate(encodeURIComponent(data)) :
  1382. pako.deflateRaw(encodeURIComponent(data));
  1383. return btoa(Graph.arrayBufferToString(new Uint8Array(tmp)));
  1384. }
  1385. };
  1386. /**
  1387. * Returns a decompressed version of the base64 encoded string.
  1388. */
  1389. Graph.decompress = function(data, inflate, checked)
  1390. {
  1391. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1392. {
  1393. return data;
  1394. }
  1395. else
  1396. {
  1397. var tmp = Graph.stringToArrayBuffer(atob(data));
  1398. var inflated = decodeURIComponent((inflate) ?
  1399. pako.inflate(tmp, {to: 'string'}) :
  1400. pako.inflateRaw(tmp, {to: 'string'}));
  1401. return (checked) ? inflated : Graph.zapGremlins(inflated);
  1402. }
  1403. };
  1404. /**
  1405. * Fades the given nodes in or out.
  1406. */
  1407. Graph.fadeNodes = function(nodes, start, end, done, delay)
  1408. {
  1409. delay = (delay != null) ? delay : 1000;
  1410. Graph.setTransitionForNodes(nodes, null);
  1411. Graph.setOpacityForNodes(nodes, start);
  1412. window.setTimeout(function()
  1413. {
  1414. Graph.setTransitionForNodes(nodes,
  1415. 'all ' + delay + 'ms ease-in-out');
  1416. Graph.setOpacityForNodes(nodes, end);
  1417. window.setTimeout(function()
  1418. {
  1419. Graph.setTransitionForNodes(nodes, null);
  1420. if (done != null)
  1421. {
  1422. done();
  1423. }
  1424. }, delay);
  1425. }, 0);
  1426. };
  1427. /**
  1428. * Removes the elements from the map where the given function returns true.
  1429. */
  1430. Graph.removeKeys = function(map, ignoreFn)
  1431. {
  1432. for (var key in map)
  1433. {
  1434. if (ignoreFn(key))
  1435. {
  1436. delete map[key];
  1437. }
  1438. }
  1439. };
  1440. /**
  1441. * Sets the transition for the given nodes.
  1442. */
  1443. Graph.setTransitionForNodes = function(nodes, transition)
  1444. {
  1445. for (var i = 0; i < nodes.length; i++)
  1446. {
  1447. mxUtils.setPrefixedStyle(nodes[i].style, 'transition', transition);
  1448. }
  1449. };
  1450. /**
  1451. * Sets the opacity for the given nodes.
  1452. */
  1453. Graph.setOpacityForNodes = function(nodes, opacity)
  1454. {
  1455. for (var i = 0; i < nodes.length; i++)
  1456. {
  1457. nodes[i].style.opacity = opacity;
  1458. }
  1459. };
  1460. /**
  1461. * Removes formatting from pasted HTML.
  1462. */
  1463. Graph.removePasteFormatting = function(elt)
  1464. {
  1465. while (elt != null)
  1466. {
  1467. if (elt.firstChild != null)
  1468. {
  1469. Graph.removePasteFormatting(elt.firstChild);
  1470. }
  1471. if (elt.nodeType == mxConstants.NODETYPE_ELEMENT && elt.style != null)
  1472. {
  1473. elt.style.whiteSpace = '';
  1474. if (elt.style.color == '#000000')
  1475. {
  1476. elt.style.color = '';
  1477. }
  1478. }
  1479. elt = elt.nextSibling;
  1480. }
  1481. };
  1482. /**
  1483. * Sanitizes the given HTML markup, allowing target attributes and
  1484. * data: protocol links to pages and custom actions.
  1485. */
  1486. Graph.sanitizeHtml = function(value, editing)
  1487. {
  1488. return Graph.domPurify(value, false);
  1489. };
  1490. /**
  1491. * Returns the size of the page format scaled with the page size.
  1492. */
  1493. Graph.sanitizeLink = function(href)
  1494. {
  1495. var a = document.createElement('a');
  1496. a.setAttribute('href', href);
  1497. Graph.sanitizeNode(a);
  1498. return a.getAttribute('href');
  1499. };
  1500. /**
  1501. * Sanitizes the given DOM node in-place.
  1502. */
  1503. Graph.sanitizeNode = function(value)
  1504. {
  1505. return Graph.domPurify(value, true);
  1506. };
  1507. // Allows use tag in SVG with local references only
  1508. DOMPurify.addHook('afterSanitizeAttributes', function(node)
  1509. {
  1510. if (node.nodeName == 'use' && node.hasAttribute('xlink:href') &&
  1511. !node.getAttribute('xlink:href').match(/^#/))
  1512. {
  1513. node.remove();
  1514. }
  1515. });
  1516. /**
  1517. * Sanitizes the given value.
  1518. */
  1519. Graph.domPurify = function(value, inPlace)
  1520. {
  1521. window.DOM_PURIFY_CONFIG.IN_PLACE = inPlace;
  1522. return DOMPurify.sanitize(value, window.DOM_PURIFY_CONFIG);
  1523. };
  1524. /**
  1525. * Updates the viewbox, width and height in the given SVG data URI
  1526. * and returns the updated data URI with all script tags and event
  1527. * handlers removed.
  1528. */
  1529. Graph.clipSvgDataUri = function(dataUri, ignorePreserveAspect)
  1530. {
  1531. // LATER Add workaround for non-default NS declarations with empty URI not allowed in IE11
  1532. if (!mxClient.IS_IE && !mxClient.IS_IE11 && dataUri != null &&
  1533. dataUri.substring(0, 26) == 'data:image/svg+xml;base64,')
  1534. {
  1535. try
  1536. {
  1537. var div = document.createElement('div');
  1538. div.style.position = 'absolute';
  1539. div.style.visibility = 'hidden';
  1540. // Adds the text and inserts into DOM for updating of size
  1541. var data = decodeURIComponent(escape(atob(dataUri.substring(26))));
  1542. var idx = data.indexOf('<svg');
  1543. if (idx >= 0)
  1544. {
  1545. // Strips leading XML declaration and doctypes
  1546. div.innerHTML = Graph.sanitizeHtml(data.substring(idx));
  1547. // Gets the size and removes from DOM
  1548. var svgs = div.getElementsByTagName('svg');
  1549. if (svgs.length > 0)
  1550. {
  1551. // Avoids getBBox as it ignores stroke option
  1552. if (ignorePreserveAspect || svgs[0].getAttribute('preserveAspectRatio') != null)
  1553. {
  1554. document.body.appendChild(div);
  1555. try
  1556. {
  1557. var fx = 1;
  1558. var fy = 1;
  1559. var w = svgs[0].getAttribute('width');
  1560. var h = svgs[0].getAttribute('height');
  1561. if (w != null && w.charAt(w.length - 1) != '%')
  1562. {
  1563. w = parseFloat(w);
  1564. }
  1565. else
  1566. {
  1567. w = NaN;
  1568. }
  1569. if (h != null && h.charAt(h.length - 1) != '%')
  1570. {
  1571. h = parseFloat(h);
  1572. }
  1573. else
  1574. {
  1575. h = NaN;
  1576. }
  1577. var vb = svgs[0].getAttribute('viewBox');
  1578. if (vb != null && !isNaN(w) && !isNaN(h))
  1579. {
  1580. var tokens = vb.split(' ');
  1581. if (vb.length >= 4)
  1582. {
  1583. fx = parseFloat(tokens[2]) / w;
  1584. fy = parseFloat(tokens[3]) / h;
  1585. }
  1586. }
  1587. var size = svgs[0].getBBox();
  1588. if (size.width > 0 && size.height > 0)
  1589. {
  1590. div.getElementsByTagName('svg')[0].setAttribute('viewBox', size.x +
  1591. ' ' + size.y + ' ' + size.width + ' ' + size.height);
  1592. div.getElementsByTagName('svg')[0].setAttribute('width', size.width / fx);
  1593. div.getElementsByTagName('svg')[0].setAttribute('height', size.height / fy);
  1594. }
  1595. }
  1596. catch (e)
  1597. {
  1598. // ignore
  1599. }
  1600. finally
  1601. {
  1602. document.body.removeChild(div);
  1603. }
  1604. }
  1605. dataUri = Editor.createSvgDataUri(mxUtils.getXml(svgs[0]));
  1606. }
  1607. }
  1608. }
  1609. catch (e)
  1610. {
  1611. // ignore
  1612. }
  1613. }
  1614. return dataUri;
  1615. };
  1616. /**
  1617. * Returns the CSS font family from the given computed style.
  1618. */
  1619. Graph.stripQuotes = function(text)
  1620. {
  1621. if (text != null)
  1622. {
  1623. if (text.charAt(0) == '\'')
  1624. {
  1625. text = text.substring(1);
  1626. }
  1627. if (text.charAt(text.length - 1) == '\'')
  1628. {
  1629. text = text.substring(0, text.length - 1);
  1630. }
  1631. if (text.charAt(0) == '"')
  1632. {
  1633. text = text.substring(1);
  1634. }
  1635. if (text.charAt(text.length - 1) == '"')
  1636. {
  1637. text = text.substring(0, text.length - 1);
  1638. }
  1639. }
  1640. return text;
  1641. };
  1642. /**
  1643. * Create remove icon.
  1644. */
  1645. Graph.createRemoveIcon = function(title, onclick)
  1646. {
  1647. var removeLink = document.createElement('img');
  1648. removeLink.setAttribute('src', Dialog.prototype.clearImage);
  1649. removeLink.setAttribute('title', title);
  1650. removeLink.setAttribute('width', '13');
  1651. removeLink.setAttribute('height', '10');
  1652. removeLink.style.marginLeft = '4px';
  1653. removeLink.style.marginBottom = '-1px';
  1654. removeLink.style.cursor = 'pointer';
  1655. mxEvent.addListener(removeLink, 'click', onclick);
  1656. return removeLink;
  1657. };
  1658. /**
  1659. * Returns true if the given string is a page link.
  1660. */
  1661. Graph.isPageLink = function(text)
  1662. {
  1663. return text != null && text.substring(0, 13) == 'data:page/id,';
  1664. };
  1665. /**
  1666. * Returns true if the given string is a link.
  1667. *
  1668. * See https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
  1669. */
  1670. Graph.isLink = function(text)
  1671. {
  1672. return text != null && Graph.linkPattern.test(text);
  1673. };
  1674. /**
  1675. * Regular expression for links.
  1676. */
  1677. Graph.linkPattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
  1678. '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
  1679. '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
  1680. '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
  1681. '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
  1682. '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
  1683. /**
  1684. * Graph inherits from mxGraph.
  1685. */
  1686. mxUtils.extend(Graph, mxGraph);
  1687. /**
  1688. * Allows all values in fit.
  1689. */
  1690. Graph.prototype.minFitScale = null;
  1691. /**
  1692. * Allows all values in fit.
  1693. */
  1694. Graph.prototype.maxFitScale = null;
  1695. /**
  1696. * Sets the policy for links. Possible values are "self" to replace any framesets,
  1697. * "blank" to load the URL in <linkTarget> and "auto" (default).
  1698. */
  1699. Graph.prototype.linkPolicy = (urlParams['target'] == 'frame') ? 'blank' : (urlParams['target'] || 'auto');
  1700. /**
  1701. * Target for links that open in a new window. Default is _blank.
  1702. */
  1703. Graph.prototype.linkTarget = (urlParams['target'] == 'frame') ? '_self' : '_blank';
  1704. /**
  1705. * Value to the rel attribute of links. Default is 'nofollow noopener noreferrer'.
  1706. * NOTE: There are security implications when this is changed and if noopener is removed,
  1707. * then <openLink> must be overridden to allow for the opener to be set by default.
  1708. */
  1709. Graph.prototype.linkRelation = 'nofollow noopener noreferrer';
  1710. /**
  1711. * Scrollbars setting is overriden in the editor, but not in the viewer.
  1712. */
  1713. Graph.prototype.defaultScrollbars = true;
  1714. /**
  1715. * Specifies if the page should be visible for new files. Default is true.
  1716. */
  1717. Graph.prototype.defaultPageVisible = true;
  1718. /**
  1719. * Specifies if the page should be visible for new files. Default is true.
  1720. */
  1721. Graph.prototype.defaultGridEnabled = urlParams['grid'] != '0';
  1722. /**
  1723. * Specifies if the app should run in chromeless mode. Default is false.
  1724. * This default is only used if the contructor argument is null.
  1725. */
  1726. Graph.prototype.lightbox = false;
  1727. /**
  1728. *
  1729. */
  1730. Graph.prototype.defaultPageBackgroundColor = '#ffffff';
  1731. /**
  1732. *
  1733. */
  1734. Graph.prototype.defaultPageBorderColor = '#ffffff';
  1735. /**
  1736. *
  1737. */
  1738. Graph.prototype.shapeForegroundColor = '#000000';
  1739. /**
  1740. *
  1741. */
  1742. Graph.prototype.shapeBackgroundColor = '#ffffff';
  1743. /**
  1744. * Specifies the size of the size for "tiles" to be used for a graph with
  1745. * scrollbars but no visible background page. A good value is large
  1746. * enough to reduce the number of repaints that is caused for auto-
  1747. * translation, which depends on this value, and small enough to give
  1748. * a small empty buffer around the graph. Default is 400x400.
  1749. */
  1750. Graph.prototype.scrollTileSize = new mxRectangle(0, 0, 400, 400);
  1751. /**
  1752. * Overrides the background color and paints a transparent background.
  1753. */
  1754. Graph.prototype.transparentBackground = true;
  1755. /**
  1756. * Sets global constants.
  1757. */
  1758. Graph.prototype.selectParentAfterDelete = false;
  1759. /**
  1760. * Sets the default target for all links in cells.
  1761. */
  1762. Graph.prototype.defaultEdgeLength = 80;
  1763. /**
  1764. * Disables move of bends/segments without selecting.
  1765. */
  1766. Graph.prototype.edgeMode = false;
  1767. /**
  1768. * Allows all values in fit.
  1769. */
  1770. Graph.prototype.connectionArrowsEnabled = true;
  1771. /**
  1772. * Specifies the regular expression for matching placeholders.
  1773. */
  1774. Graph.prototype.placeholderPattern = new RegExp('%(date\{.*\}|[^%^\{^\}^ ^"^ \'^=^;]+)%', 'g');
  1775. /**
  1776. * Specifies the regular expression for matching placeholders.
  1777. */
  1778. Graph.prototype.absoluteUrlPattern = new RegExp('^(?:[a-z]+:)?//', 'i');
  1779. /**
  1780. * Specifies the default name for the theme. Default is 'default'.
  1781. */
  1782. Graph.prototype.defaultThemeName = 'default';
  1783. /**
  1784. * Specifies the default name for the theme. Default is 'default'.
  1785. */
  1786. Graph.prototype.defaultThemes = {};
  1787. /**
  1788. * Base URL for relative links.
  1789. */
  1790. Graph.prototype.baseUrl = (urlParams['base'] != null) ?
  1791. decodeURIComponent(urlParams['base']) :
  1792. (((window != window.top) ? document.referrer :
  1793. document.location.toString()).split('#')[0]);
  1794. /**
  1795. * Specifies if the label should be edited after an insert.
  1796. */
  1797. Graph.prototype.editAfterInsert = false;
  1798. /**
  1799. * Defines the built-in properties to be ignored in tooltips.
  1800. */
  1801. Graph.prototype.builtInProperties = ['label', 'tooltip', 'placeholders', 'placeholder'];
  1802. /**
  1803. * Defines if the graph is part of an EditorUi. If this is false the graph can
  1804. * be used in an EditorUi instance but will not have a UI added, functions
  1805. * overridden or event handlers added.
  1806. */
  1807. Graph.prototype.standalone = false;
  1808. /**
  1809. * Enables move of bends/segments without selecting.
  1810. */
  1811. Graph.prototype.enableFlowAnimation = false;
  1812. /**
  1813. * Background color for inactive tabs.
  1814. */
  1815. Graph.prototype.roundableShapes = ['label', 'rectangle', 'internalStorage', 'corner',
  1816. 'parallelogram', 'swimlane', 'triangle', 'trapezoid', 'ext', 'step', 'tee', 'process',
  1817. 'link', 'rhombus', 'offPageConnector', 'loopLimit', 'hexagon', 'manualInput', 'card',
  1818. 'curlyBracket', 'singleArrow', 'callout', 'doubleArrow', 'flexArrow', 'umlLifeline'];
  1819. /**
  1820. * Installs child layout styles.
  1821. */
  1822. Graph.prototype.init = function(container)
  1823. {
  1824. mxGraph.prototype.init.apply(this, arguments);
  1825. // Intercepts links with no target attribute and opens in new window
  1826. this.cellRenderer.initializeLabel = function(state, shape)
  1827. {
  1828. mxCellRenderer.prototype.initializeLabel.apply(this, arguments);
  1829. // Checks tolerance for clicks on links
  1830. var tol = state.view.graph.tolerance;
  1831. var handleClick = true;
  1832. var first = null;
  1833. var down = mxUtils.bind(this, function(evt)
  1834. {
  1835. handleClick = true;
  1836. first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  1837. });
  1838. var move = mxUtils.bind(this, function(evt)
  1839. {
  1840. handleClick = handleClick && first != null &&
  1841. Math.abs(first.x - mxEvent.getClientX(evt)) < tol &&
  1842. Math.abs(first.y - mxEvent.getClientY(evt)) < tol;
  1843. });
  1844. var up = mxUtils.bind(this, function(evt)
  1845. {
  1846. if (handleClick)
  1847. {
  1848. var elt = mxEvent.getSource(evt)
  1849. while (elt != null && elt != shape.node)
  1850. {
  1851. if (elt.nodeName.toLowerCase() == 'a')
  1852. {
  1853. state.view.graph.labelLinkClicked(state, elt, evt);
  1854. break;
  1855. }
  1856. elt = elt.parentNode;
  1857. }
  1858. }
  1859. });
  1860. mxEvent.addGestureListeners(shape.node, down, move, up);
  1861. mxEvent.addListener(shape.node, 'click', function(evt)
  1862. {
  1863. mxEvent.consume(evt);
  1864. });
  1865. };
  1866. // Handles custom links in tooltips
  1867. if (this.tooltipHandler != null)
  1868. {
  1869. var tooltipHandlerInit = this.tooltipHandler.init;
  1870. this.tooltipHandler.init = function()
  1871. {
  1872. tooltipHandlerInit.apply(this, arguments);
  1873. if (this.div != null)
  1874. {
  1875. mxEvent.addListener(this.div, 'click', mxUtils.bind(this, function(evt)
  1876. {
  1877. var source = mxEvent.getSource(evt);
  1878. if (source.nodeName == 'A')
  1879. {
  1880. var href = source.getAttribute('href');
  1881. if (href != null && this.graph.isCustomLink(href) &&
  1882. (mxEvent.isTouchEvent(evt) || !mxEvent.isPopupTrigger(evt)) &&
  1883. this.graph.customLinkClicked(href))
  1884. {
  1885. mxEvent.consume(evt);
  1886. }
  1887. }
  1888. }));
  1889. }
  1890. };
  1891. }
  1892. // Adds or updates CSS for flowAnimation style
  1893. this.addListener(mxEvent.SIZE, mxUtils.bind(this, function(sender, evt)
  1894. {
  1895. if (this.container != null && this.flowAnimationStyle)
  1896. {
  1897. var id = this.flowAnimationStyle.getAttribute('id');
  1898. this.flowAnimationStyle.innerHTML = this.getFlowAnimationStyleCss(id);
  1899. }
  1900. }));
  1901. this.initLayoutManager();
  1902. };
  1903. /**
  1904. * Implements zoom and offset via CSS transforms. This is currently only used
  1905. * in read-only as there are fewer issues with the mxCellState not being scaled
  1906. * and translated.
  1907. *
  1908. * KNOWN ISSUES TO FIX:
  1909. * - Apply CSS transforms to HTML labels in IE11
  1910. */
  1911. (function()
  1912. {
  1913. /**
  1914. * Uses CSS transforms for scale and translate.
  1915. */
  1916. Graph.prototype.useCssTransforms = false;
  1917. /**
  1918. * Contains the scale.
  1919. */
  1920. Graph.prototype.currentScale = 1;
  1921. /**
  1922. * Contains the offset.
  1923. */
  1924. Graph.prototype.currentTranslate = new mxPoint(0, 0);
  1925. /**
  1926. * Returns information about the current selection.
  1927. */
  1928. Graph.prototype.isFillState = function(state)
  1929. {
  1930. return !this.isSpecialColor(state.style[mxConstants.STYLE_FILLCOLOR]) &&
  1931. mxUtils.getValue(state.style, 'lineShape', null) != '1' &&
  1932. (this.model.isVertex(state.cell) ||
  1933. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'arrow' ||
  1934. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'filledEdge' ||
  1935. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'flexArrow');
  1936. };
  1937. /**
  1938. * Returns information about the current selection.
  1939. */
  1940. Graph.prototype.isStrokeState = function(state)
  1941. {
  1942. return !this.isSpecialColor(state.style[mxConstants.STYLE_STROKECOLOR]);
  1943. };
  1944. /**
  1945. * Returns information about the current selection.
  1946. */
  1947. Graph.prototype.isSpecialColor = function(color)
  1948. {
  1949. return mxUtils.indexOf([mxConstants.STYLE_STROKECOLOR,
  1950. mxConstants.STYLE_FILLCOLOR, 'inherit', 'swimlane',
  1951. 'indicated'], color) >= 0;
  1952. };
  1953. /**
  1954. * Returns information about the current selection.
  1955. */
  1956. Graph.prototype.isGlassState = function(state)
  1957. {
  1958. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  1959. return (shape == 'label' || shape == 'rectangle' || shape == 'internalStorage' ||
  1960. shape == 'ext' || shape == 'umlLifeline' || shape == 'swimlane' ||
  1961. shape == 'process');
  1962. };
  1963. /**
  1964. * Returns information about the current selection.
  1965. */
  1966. Graph.prototype.isRoundedState = function(state)
  1967. {
  1968. return (state.shape != null) ? state.shape.isRoundable() :
  1969. mxUtils.indexOf(this.roundableShapes, mxUtils.getValue(state.style,
  1970. mxConstants.STYLE_SHAPE, null)) >= 0;
  1971. };
  1972. /**
  1973. * Returns information about the current selection.
  1974. */
  1975. Graph.prototype.isLineJumpState = function(state)
  1976. {
  1977. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  1978. var curved = mxUtils.getValue(state.style, mxConstants.STYLE_CURVED, false);
  1979. return !curved && (shape == 'connector' || shape == 'filledEdge');
  1980. };
  1981. /**
  1982. * Returns information about the current selection.
  1983. */
  1984. Graph.prototype.isAutoSizeState = function(state)
  1985. {
  1986. return mxUtils.getValue(state.style, mxConstants.STYLE_AUTOSIZE, null) == '1';
  1987. };
  1988. /**
  1989. * Returns information about the current selection.
  1990. */
  1991. Graph.prototype.isImageState = function(state)
  1992. {
  1993. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  1994. return (shape == 'label' || shape == 'image');
  1995. };
  1996. /**
  1997. * Returns information about the current selection.
  1998. */
  1999. Graph.prototype.isShadowState = function(state)
  2000. {
  2001. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  2002. return (shape != 'image');
  2003. };
  2004. /**
  2005. *
  2006. */
  2007. Graph.prototype.getVerticesAndEdges = function(vertices, edges)
  2008. {
  2009. vertices = (vertices != null) ? vertices : true;
  2010. edges = (edges != null) ? edges : true;
  2011. var model = this.model;
  2012. return model.filterDescendants(function(cell)
  2013. {
  2014. return (vertices && model.isVertex(cell)) || (edges && model.isEdge(cell));
  2015. }, model.getRoot());
  2016. };
  2017. /**
  2018. * Returns information about the current selection.
  2019. */
  2020. Graph.prototype.getCommonStyle = function(cells)
  2021. {
  2022. var style = {};
  2023. for (var i = 0; i < cells.length; i++)
  2024. {
  2025. var state = this.view.getState(cells[i]);
  2026. this.mergeStyle(state.style, style, i == 0);
  2027. }
  2028. return style;
  2029. };
  2030. /**
  2031. * Returns information about the current selection.
  2032. */
  2033. Graph.prototype.mergeStyle = function(style, into, initial)
  2034. {
  2035. if (style != null)
  2036. {
  2037. var keys = {};
  2038. for (var key in style)
  2039. {
  2040. var value = style[key];
  2041. if (value != null)
  2042. {
  2043. keys[key] = true;
  2044. if (into[key] == null && initial)
  2045. {
  2046. into[key] = value;
  2047. }
  2048. else if (into[key] != value)
  2049. {
  2050. delete into[key];
  2051. }
  2052. }
  2053. }
  2054. for (var key in into)
  2055. {
  2056. if (!keys[key])
  2057. {
  2058. delete into[key];
  2059. }
  2060. }
  2061. }
  2062. };
  2063. /**
  2064. * Returns the cell for editing the given cell.
  2065. */
  2066. Graph.prototype.getStartEditingCell = function(cell, trigger)
  2067. {
  2068. // Redirect editing for tables
  2069. var style = this.getCellStyle(cell);
  2070. var size = parseInt(mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE, 0));
  2071. if (this.isTable(cell) && (!this.isSwimlane(cell) ||
  2072. size == 0) && this.getLabel(cell) == '' &&
  2073. this.model.getChildCount(cell) > 0)
  2074. {
  2075. cell = this.model.getChildAt(cell, 0);
  2076. style = this.getCellStyle(cell);
  2077. size = parseInt(mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE, 0));
  2078. }
  2079. // Redirect editing for table rows
  2080. if (this.isTableRow(cell) && (!this.isSwimlane(cell) ||
  2081. size == 0) && this.getLabel(cell) == '' &&
  2082. this.model.getChildCount(cell) > 0)
  2083. {
  2084. for (var i = 0; i < this.model.getChildCount(cell); i++)
  2085. {
  2086. var temp = this.model.getChildAt(cell, i);
  2087. if (this.isCellEditable(temp))
  2088. {
  2089. cell = temp;
  2090. break;
  2091. }
  2092. }
  2093. }
  2094. return cell;
  2095. };
  2096. /**
  2097. * Returns the style of the given cell as an object.
  2098. */
  2099. Graph.prototype.copyStyle = function(cell)
  2100. {
  2101. return this.getCellStyle(cell, false);
  2102. };
  2103. /**
  2104. * Returns true if fast zoom preview should be used.
  2105. */
  2106. Graph.prototype.pasteStyle = function(style, cells, keys)
  2107. {
  2108. keys = (keys != null) ? keys : Graph.pasteStyles;
  2109. Graph.removeKeys(style, function(key)
  2110. {
  2111. return mxUtils.indexOf(keys, key) < 0;
  2112. });
  2113. this.updateCellStyles(style, cells);
  2114. };
  2115. /**
  2116. * Removes implicit styles from cell styles so that dark mode works using the
  2117. * default values from the stylesheet.
  2118. */
  2119. Graph.prototype.updateCellStyles = function(style, cells)
  2120. {
  2121. this.model.beginUpdate();
  2122. try
  2123. {
  2124. for (var i = 0; i < cells.length; i++)
  2125. {
  2126. if (this.model.isVertex(cells[i]) || this.model.isEdge(cells[i]))
  2127. {
  2128. var cellStyle = this.getCellStyle(cells[i], false);
  2129. for (var key in style)
  2130. {
  2131. var value = style[key];
  2132. if (cellStyle[key] != value)
  2133. {
  2134. this.setCellStyles(key, value, [cells[i]]);
  2135. }
  2136. }
  2137. }
  2138. }
  2139. }
  2140. finally
  2141. {
  2142. this.model.endUpdate();
  2143. }
  2144. };
  2145. /**
  2146. * Returns true if fast zoom preview should be used.
  2147. */
  2148. Graph.prototype.isFastZoomEnabled = function()
  2149. {
  2150. return urlParams['zoom'] != 'nocss' && !mxClient.NO_FO && !mxClient.IS_EDGE &&
  2151. !this.useCssTransforms && (this.isCssTransformsSupported() || mxClient.IS_IOS);
  2152. };
  2153. /**
  2154. * Only foreignObject supported for now (no IE11). Safari disabled as it ignores
  2155. * overflow visible on foreignObject in negative space (lightbox and viewer).
  2156. * Check the following test case on page 1 before enabling this in production:
  2157. * https://devhost.jgraph.com/git/drawio/etc/embed/sf-math-fo-clipping.html?dev=1
  2158. */
  2159. Graph.prototype.isCssTransformsSupported = function()
  2160. {
  2161. return this.dialect == mxConstants.DIALECT_SVG && !mxClient.NO_FO &&
  2162. (!this.lightbox || !mxClient.IS_SF);
  2163. };
  2164. /**
  2165. * Function: getCellAt
  2166. *
  2167. * Needs to modify original method for recursive call.
  2168. */
  2169. Graph.prototype.getCellAt = function(x, y, parent, vertices, edges, ignoreFn)
  2170. {
  2171. if (this.useCssTransforms)
  2172. {
  2173. x = x / this.currentScale - this.currentTranslate.x;
  2174. y = y / this.currentScale - this.currentTranslate.y;
  2175. }
  2176. return this.getScaledCellAt.apply(this, arguments);
  2177. };
  2178. /**
  2179. * Function: getScaledCellAt
  2180. *
  2181. * Overridden for recursion.
  2182. */
  2183. Graph.prototype.getScaledCellAt = function(x, y, parent, vertices, edges, ignoreFn)
  2184. {
  2185. vertices = (vertices != null) ? vertices : true;
  2186. edges = (edges != null) ? edges : true;
  2187. if (parent == null)
  2188. {
  2189. parent = this.getCurrentRoot();
  2190. if (parent == null)
  2191. {
  2192. parent = this.getModel().getRoot();
  2193. }
  2194. }
  2195. if (parent != null)
  2196. {
  2197. var childCount = this.model.getChildCount(parent);
  2198. for (var i = childCount - 1; i >= 0; i--)
  2199. {
  2200. var cell = this.model.getChildAt(parent, i);
  2201. var result = this.getScaledCellAt(x, y, cell, vertices, edges, ignoreFn);
  2202. if (result != null)
  2203. {
  2204. return result;
  2205. }
  2206. else if (this.isCellVisible(cell) && (edges && this.model.isEdge(cell) ||
  2207. vertices && this.model.isVertex(cell)))
  2208. {
  2209. var state = this.view.getState(cell);
  2210. if (state != null && (ignoreFn == null || !ignoreFn(state, x, y)) &&
  2211. this.intersects(state, x, y))
  2212. {
  2213. return cell;
  2214. }
  2215. }
  2216. }
  2217. }
  2218. return null;
  2219. };
  2220. /**
  2221. * Returns if the child cells of the given vertex cell state should be resized.
  2222. */
  2223. Graph.prototype.isRecursiveVertexResize = function(state)
  2224. {
  2225. return !this.isSwimlane(state.cell) && this.model.getChildCount(state.cell) > 0 &&
  2226. !this.isCellCollapsed(state.cell) && mxUtils.getValue(state.style, 'recursiveResize', '1') == '1' &&
  2227. mxUtils.getValue(state.style, 'childLayout', null) == null;
  2228. }
  2229. /**
  2230. * Returns the first parent with an absolute or no geometry.
  2231. */
  2232. Graph.prototype.getAbsoluteParent = function(cell)
  2233. {
  2234. var result = cell;
  2235. var geo = this.getCellGeometry(result);
  2236. while (geo != null && geo.relative)
  2237. {
  2238. result = this.getModel().getParent(result);
  2239. geo = this.getCellGeometry(result);
  2240. }
  2241. return result;
  2242. };
  2243. /**
  2244. * Returns the first parent that is not a part.
  2245. */
  2246. Graph.prototype.isPart = function(cell)
  2247. {
  2248. return mxUtils.getValue(this.getCurrentCellStyle(cell), 'part', '0') == '1' ||
  2249. this.isTableCell(cell) || this.isTableRow(cell);
  2250. };
  2251. /**
  2252. * Returns the first parent that is not a part.
  2253. */
  2254. Graph.prototype.getCompositeParents = function(cells)
  2255. {
  2256. var lookup = new mxDictionary();
  2257. var newCells = [];
  2258. for (var i = 0; i < cells.length; i++)
  2259. {
  2260. var cell = this.getCompositeParent(cells[i]);
  2261. if (this.isTableCell(cell))
  2262. {
  2263. cell = this.graph.model.getParent(cell);
  2264. }
  2265. if (this.isTableRow(cell))
  2266. {
  2267. cell = this.graph.model.getParent(cell);
  2268. }
  2269. if (cell != null && !lookup.get(cell))
  2270. {
  2271. lookup.put(cell, true);
  2272. newCells.push(cell);
  2273. }
  2274. }
  2275. return newCells;
  2276. };
  2277. /**
  2278. * Returns the first parent that is not a part.
  2279. */
  2280. Graph.prototype.getCompositeParent = function(cell)
  2281. {
  2282. while (this.isPart(cell))
  2283. {
  2284. var temp = this.model.getParent(cell);
  2285. if (!this.model.isVertex(temp))
  2286. {
  2287. break;
  2288. }
  2289. cell = temp;
  2290. }
  2291. return cell;
  2292. };
  2293. /**
  2294. * Returns the selection cells where the given function returns false.
  2295. */
  2296. Graph.prototype.filterSelectionCells = function(ignoreFn)
  2297. {
  2298. var cells = this.getSelectionCells();
  2299. if (ignoreFn != null)
  2300. {
  2301. var temp = [];
  2302. for (var i = 0; i < cells.length; i++)
  2303. {
  2304. if (!ignoreFn(cells[i]))
  2305. {
  2306. temp.push(cells[i]);
  2307. }
  2308. }
  2309. cells = temp;
  2310. }
  2311. return cells;
  2312. };
  2313. /**
  2314. * Overrides scrollRectToVisible to fix ignored transform.
  2315. */
  2316. var graphScrollRectToVisible = mxGraph.prototype.scrollRectToVisible;
  2317. Graph.prototype.scrollRectToVisible = function(r)
  2318. {
  2319. if (this.useCssTransforms)
  2320. {
  2321. var s = this.currentScale;
  2322. var t = this.currentTranslate;
  2323. r = new mxRectangle((r.x + 2 * t.x) * s - t.x,
  2324. (r.y + 2 * t.y) * s - t.y,
  2325. r.width * s, r.height * s);
  2326. }
  2327. graphScrollRectToVisible.apply(this, arguments);
  2328. };
  2329. /**
  2330. * Function: repaint
  2331. *
  2332. * Updates the highlight after a change of the model or view.
  2333. */
  2334. mxCellHighlight.prototype.getStrokeWidth = function(state)
  2335. {
  2336. var s = this.strokeWidth;
  2337. if (this.graph.useCssTransforms)
  2338. {
  2339. s /= this.graph.currentScale;
  2340. }
  2341. return s;
  2342. };
  2343. /**
  2344. * Function: getGraphBounds
  2345. *
  2346. * Overrides getGraphBounds to use bounding box from SVG.
  2347. */
  2348. mxGraphView.prototype.getGraphBounds = function()
  2349. {
  2350. var b = this.graphBounds;
  2351. if (this.graph.useCssTransforms)
  2352. {
  2353. var t = this.graph.currentTranslate;
  2354. var s = this.graph.currentScale;
  2355. b = new mxRectangle(
  2356. (b.x + t.x) * s, (b.y + t.y) * s,
  2357. b.width * s, b.height * s);
  2358. }
  2359. return b;
  2360. };
  2361. /**
  2362. * Overrides to bypass full cell tree validation.
  2363. * TODO: Check if this improves performance
  2364. */
  2365. mxGraphView.prototype.viewStateChanged = function()
  2366. {
  2367. if (this.graph.useCssTransforms)
  2368. {
  2369. this.validate();
  2370. this.graph.sizeDidChange();
  2371. }
  2372. else
  2373. {
  2374. this.revalidate();
  2375. this.graph.sizeDidChange();
  2376. }
  2377. };
  2378. /**
  2379. * Overrides validate to normalize validation view state and pass
  2380. * current state to CSS transform.
  2381. */
  2382. var graphViewValidate = mxGraphView.prototype.validate;
  2383. mxGraphView.prototype.validate = function(cell)
  2384. {
  2385. if (this.graph.useCssTransforms)
  2386. {
  2387. this.graph.currentScale = this.scale;
  2388. this.graph.currentTranslate.x = this.translate.x;
  2389. this.graph.currentTranslate.y = this.translate.y;
  2390. this.scale = 1;
  2391. this.translate.x = 0;
  2392. this.translate.y = 0;
  2393. }
  2394. graphViewValidate.apply(this, arguments);
  2395. if (this.graph.useCssTransforms)
  2396. {
  2397. this.graph.updateCssTransform();
  2398. this.scale = this.graph.currentScale;
  2399. this.translate.x = this.graph.currentTranslate.x;
  2400. this.translate.y = this.graph.currentTranslate.y;
  2401. }
  2402. };
  2403. /**
  2404. * Overrides function to exclude table cells and rows from groups.
  2405. */
  2406. var graphGetCellsForGroup = mxGraph.prototype.getCellsForGroup;
  2407. Graph.prototype.getCellsForGroup = function(cells)
  2408. {
  2409. cells = graphGetCellsForGroup.apply(this, arguments);
  2410. var result = [];
  2411. // Filters selection cells with the same parent
  2412. for (var i = 0; i < cells.length; i++)
  2413. {
  2414. if (!this.isTableRow(cells[i]) &&
  2415. !this.isTableCell(cells[i]))
  2416. {
  2417. result.push(cells[i]);
  2418. }
  2419. }
  2420. return result;
  2421. };
  2422. /**
  2423. * Overrides function to exclude tables, rows and cells from ungrouping.
  2424. */
  2425. var graphGetCellsForUngroup = mxGraph.prototype.getCellsForUngroup;
  2426. Graph.prototype.getCellsForUngroup = function(cells)
  2427. {
  2428. cells = graphGetCellsForUngroup.apply(this, arguments);
  2429. var result = [];
  2430. // Filters selection cells with the same parent
  2431. for (var i = 0; i < cells.length; i++)
  2432. {
  2433. if (!this.isTable(cells[i]) &&
  2434. !this.isTableRow(cells[i]) &&
  2435. !this.isTableCell(cells[i]))
  2436. {
  2437. result.push(cells[i]);
  2438. }
  2439. }
  2440. return result;
  2441. };
  2442. /**
  2443. * Function: updateCssTransform
  2444. *
  2445. * Zooms out of the graph by <zoomFactor>.
  2446. */
  2447. Graph.prototype.updateCssTransform = function()
  2448. {
  2449. var temp = this.view.getDrawPane();
  2450. if (temp != null)
  2451. {
  2452. var g = temp.parentNode;
  2453. if (!this.useCssTransforms)
  2454. {
  2455. g.removeAttribute('transformOrigin');
  2456. g.removeAttribute('transform');
  2457. }
  2458. else
  2459. {
  2460. var prev = g.getAttribute('transform');
  2461. g.setAttribute('transformOrigin', '0 0');
  2462. var s = Math.round(this.currentScale * 100) / 100;
  2463. var dx = Math.round(this.currentTranslate.x * 100) / 100;
  2464. var dy = Math.round(this.currentTranslate.y * 100) / 100;
  2465. g.setAttribute('transform', 'scale(' + s + ',' + s + ')' +
  2466. 'translate(' + dx + ',' + dy + ')');
  2467. // Applies workarounds only if translate has changed
  2468. if (prev != g.getAttribute('transform'))
  2469. {
  2470. this.fireEvent(new mxEventObject('cssTransformChanged'),
  2471. 'transform', g.getAttribute('transform'));
  2472. }
  2473. }
  2474. }
  2475. };
  2476. var graphViewValidateBackgroundPage = mxGraphView.prototype.validateBackgroundPage;
  2477. mxGraphView.prototype.validateBackgroundPage = function()
  2478. {
  2479. var useCssTranforms = this.graph.useCssTransforms, scale = this.scale,
  2480. translate = this.translate;
  2481. if (useCssTranforms)
  2482. {
  2483. this.scale = this.graph.currentScale;
  2484. this.translate = this.graph.currentTranslate;
  2485. }
  2486. graphViewValidateBackgroundPage.apply(this, arguments);
  2487. if (useCssTranforms)
  2488. {
  2489. this.scale = scale;
  2490. this.translate = translate;
  2491. }
  2492. };
  2493. var graphUpdatePageBreaks = mxGraph.prototype.updatePageBreaks;
  2494. mxGraph.prototype.updatePageBreaks = function(visible, width, height)
  2495. {
  2496. var useCssTranforms = this.useCssTransforms, scale = this.view.scale,
  2497. translate = this.view.translate;
  2498. if (useCssTranforms)
  2499. {
  2500. this.view.scale = 1;
  2501. this.view.translate = new mxPoint(0, 0);
  2502. this.useCssTransforms = false;
  2503. }
  2504. graphUpdatePageBreaks.apply(this, arguments);
  2505. if (useCssTranforms)
  2506. {
  2507. this.view.scale = scale;
  2508. this.view.translate = translate;
  2509. this.useCssTransforms = true;
  2510. }
  2511. };
  2512. })();
  2513. /**
  2514. * Sets the XML node for the current diagram.
  2515. */
  2516. Graph.prototype.isLightboxView = function()
  2517. {
  2518. return this.lightbox;
  2519. };
  2520. /**
  2521. * Sets the XML node for the current diagram.
  2522. */
  2523. Graph.prototype.isViewer = function()
  2524. {
  2525. return false;
  2526. };
  2527. /**
  2528. * Installs automatic layout via styles
  2529. */
  2530. Graph.prototype.labelLinkClicked = function(state, elt, evt)
  2531. {
  2532. var href = elt.getAttribute('href');
  2533. if (href != null && !this.isCustomLink(href) && ((mxEvent.isLeftMouseButton(evt) &&
  2534. !mxEvent.isPopupTrigger(evt)) || mxEvent.isTouchEvent(evt)))
  2535. {
  2536. if (!this.isEnabled() || this.isCellLocked(state.cell))
  2537. {
  2538. var target = this.isBlankLink(href) ? this.linkTarget : '_top';
  2539. this.openLink(this.getAbsoluteUrl(href), target);
  2540. }
  2541. mxEvent.consume(evt);
  2542. }
  2543. };
  2544. /**
  2545. * Returns the size of the page format scaled with the page size.
  2546. */
  2547. Graph.prototype.openLink = function(href, target, allowOpener)
  2548. {
  2549. var result = window;
  2550. try
  2551. {
  2552. href = Graph.sanitizeLink(href);
  2553. if (href != null)
  2554. {
  2555. // Workaround for blocking in same iframe
  2556. if (target == '_self' && window != window.top)
  2557. {
  2558. window.location.href = href;
  2559. }
  2560. else
  2561. {
  2562. // Avoids page reload for anchors (workaround for IE but used everywhere)
  2563. if (href.substring(0, this.baseUrl.length) == this.baseUrl &&
  2564. href.charAt(this.baseUrl.length) == '#' &&
  2565. target == '_top' && window == window.top)
  2566. {
  2567. var hash = href.split('#')[1];
  2568. // Forces navigation if on same hash
  2569. if (window.location.hash == '#' + hash)
  2570. {
  2571. window.location.hash = '';
  2572. }
  2573. window.location.hash = hash;
  2574. }
  2575. else
  2576. {
  2577. result = window.open(href, (target != null) ? target : '_blank');
  2578. if (result != null && !allowOpener)
  2579. {
  2580. result.opener = null;
  2581. }
  2582. }
  2583. }
  2584. }
  2585. }
  2586. catch (e)
  2587. {
  2588. // ignores permission denied
  2589. }
  2590. return result;
  2591. };
  2592. /**
  2593. * Adds support for page links.
  2594. */
  2595. Graph.prototype.getLinkTitle = function(href)
  2596. {
  2597. return href.substring(href.lastIndexOf('/') + 1);
  2598. };
  2599. /**
  2600. * Adds support for page links.
  2601. */
  2602. Graph.prototype.isCustomLink = function(href)
  2603. {
  2604. return href.substring(0, 5) == 'data:';
  2605. };
  2606. /**
  2607. * Adds support for page links.
  2608. */
  2609. Graph.prototype.customLinkClicked = function(link)
  2610. {
  2611. return false;
  2612. };
  2613. /**
  2614. * Returns true if the given href references an external protocol that
  2615. * should never open in a new window. Default returns true for mailto.
  2616. */
  2617. Graph.prototype.isExternalProtocol = function(href)
  2618. {
  2619. return href.substring(0, 7) === 'mailto:';
  2620. };
  2621. /**
  2622. * Hook for links to open in same window. Default returns true for anchors,
  2623. * links to same domain or if target == 'self' in the config.
  2624. */
  2625. Graph.prototype.isBlankLink = function(href)
  2626. {
  2627. return !this.isExternalProtocol(href) &&
  2628. (this.linkPolicy === 'blank' ||
  2629. (this.linkPolicy !== 'self' &&
  2630. !this.isRelativeUrl(href) &&
  2631. href.substring(0, this.domainUrl.length) !== this.domainUrl));
  2632. };
  2633. /**
  2634. *
  2635. */
  2636. Graph.prototype.isRelativeUrl = function(url)
  2637. {
  2638. return url != null && !this.absoluteUrlPattern.test(url) &&
  2639. url.substring(0, 5) !== 'data:' &&
  2640. !this.isExternalProtocol(url);
  2641. };
  2642. /**
  2643. *
  2644. */
  2645. Graph.prototype.getAbsoluteUrl = function(url)
  2646. {
  2647. if (url != null && this.isRelativeUrl(url))
  2648. {
  2649. if (url.charAt(0) == '#')
  2650. {
  2651. url = this.baseUrl + url;
  2652. }
  2653. else if (url.charAt(0) == '/')
  2654. {
  2655. url = this.domainUrl + url;
  2656. }
  2657. else
  2658. {
  2659. url = this.domainPathUrl + url;
  2660. }
  2661. }
  2662. return url;
  2663. };
  2664. /**
  2665. * Installs automatic layout via styles
  2666. */
  2667. Graph.prototype.initLayoutManager = function()
  2668. {
  2669. this.layoutManager = new mxLayoutManager(this);
  2670. this.layoutManager.hasLayout = function(cell)
  2671. {
  2672. return this.graph.getCellStyle(cell)['childLayout'] != null;
  2673. };
  2674. this.layoutManager.getLayout = function(cell, eventName)
  2675. {
  2676. var parent = this.graph.model.getParent(cell);
  2677. // Executes layouts from top to bottom except for nested layouts where
  2678. // child layouts are executed before and after the parent layout runs
  2679. // in case the layout changes the size of the child cell
  2680. if (!this.graph.isCellCollapsed(cell) && (eventName != mxEvent.BEGIN_UPDATE ||
  2681. this.hasLayout(parent, eventName)))
  2682. {
  2683. var style = this.graph.getCellStyle(cell);
  2684. if (style['childLayout'] == 'stackLayout')
  2685. {
  2686. var stackLayout = new mxStackLayout(this.graph, true);
  2687. stackLayout.resizeParentMax = mxUtils.getValue(style, 'resizeParentMax', '1') == '1';
  2688. stackLayout.horizontal = mxUtils.getValue(style, 'horizontalStack', '1') == '1';
  2689. stackLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  2690. stackLayout.resizeLast = mxUtils.getValue(style, 'resizeLast', '0') == '1';
  2691. stackLayout.spacing = style['stackSpacing'] || stackLayout.spacing;
  2692. stackLayout.border = style['stackBorder'] || stackLayout.border;
  2693. stackLayout.marginLeft = style['marginLeft'] || 0;
  2694. stackLayout.marginRight = style['marginRight'] || 0;
  2695. stackLayout.marginTop = style['marginTop'] || 0;
  2696. stackLayout.marginBottom = style['marginBottom'] || 0;
  2697. stackLayout.allowGaps = style['allowGaps'] || 0;
  2698. stackLayout.fill = true;
  2699. if (stackLayout.allowGaps)
  2700. {
  2701. stackLayout.gridSize = parseFloat(mxUtils.getValue(style, 'stackUnitSize', 20));
  2702. }
  2703. return stackLayout;
  2704. }
  2705. else if (style['childLayout'] == 'treeLayout')
  2706. {
  2707. var treeLayout = new mxCompactTreeLayout(this.graph);
  2708. treeLayout.horizontal = mxUtils.getValue(style, 'horizontalTree', '1') == '1';
  2709. treeLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  2710. treeLayout.groupPadding = mxUtils.getValue(style, 'parentPadding', 20);
  2711. treeLayout.levelDistance = mxUtils.getValue(style, 'treeLevelDistance', 30);
  2712. treeLayout.maintainParentLocation = true;
  2713. treeLayout.edgeRouting = false;
  2714. treeLayout.resetEdges = false;
  2715. return treeLayout;
  2716. }
  2717. else if (style['childLayout'] == 'flowLayout')
  2718. {
  2719. var flowLayout = new mxHierarchicalLayout(this.graph, mxUtils.getValue(style,
  2720. 'flowOrientation', mxConstants.DIRECTION_EAST));
  2721. flowLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  2722. flowLayout.parentBorder = mxUtils.getValue(style, 'parentPadding', 20);
  2723. flowLayout.maintainParentLocation = true;
  2724. // Special undocumented styles for changing the hierarchical
  2725. flowLayout.intraCellSpacing = mxUtils.getValue(style, 'intraCellSpacing',
  2726. mxHierarchicalLayout.prototype.intraCellSpacing);
  2727. flowLayout.interRankCellSpacing = mxUtils.getValue(style, 'interRankCellSpacing',
  2728. mxHierarchicalLayout.prototype.interRankCellSpacing);
  2729. flowLayout.interHierarchySpacing = mxUtils.getValue(style, 'interHierarchySpacing',
  2730. mxHierarchicalLayout.prototype.interHierarchySpacing);
  2731. flowLayout.parallelEdgeSpacing = mxUtils.getValue(style, 'parallelEdgeSpacing',
  2732. mxHierarchicalLayout.prototype.parallelEdgeSpacing);
  2733. return flowLayout;
  2734. }
  2735. else if (style['childLayout'] == 'circleLayout')
  2736. {
  2737. return new mxCircleLayout(this.graph);
  2738. }
  2739. else if (style['childLayout'] == 'organicLayout')
  2740. {
  2741. return new mxFastOrganicLayout(this.graph);
  2742. }
  2743. else if (style['childLayout'] == 'tableLayout')
  2744. {
  2745. return new TableLayout(this.graph);
  2746. }
  2747. else if (style['childLayout'] != null && style['childLayout'].charAt(0) == '[')
  2748. {
  2749. try
  2750. {
  2751. return new mxCompositeLayout(this.graph,
  2752. this.graph.createLayouts(JSON.parse(
  2753. style['childLayout'])));
  2754. }
  2755. catch (e)
  2756. {
  2757. if (window.console != null)
  2758. {
  2759. console.error(e);
  2760. }
  2761. }
  2762. }
  2763. }
  2764. return null;
  2765. };
  2766. };
  2767. /**
  2768. * Creates an array of graph layouts from the given array of the form [{layout: name, config: obj}, ...]
  2769. * where name is the layout constructor name and config contains the properties of the layout instance.
  2770. */
  2771. Graph.prototype.createLayouts = function(list)
  2772. {
  2773. var layouts = [];
  2774. for (var i = 0; i < list.length; i++)
  2775. {
  2776. if (mxUtils.indexOf(Graph.layoutNames, list[i].layout) >= 0)
  2777. {
  2778. var layout = new window[list[i].layout](this);
  2779. if (list[i].config != null)
  2780. {
  2781. for (var key in list[i].config)
  2782. {
  2783. layout[key] = list[i].config[key];
  2784. }
  2785. }
  2786. layouts.push(layout);
  2787. }
  2788. else
  2789. {
  2790. throw Error(mxResources.get('invalidCallFnNotFound', [list[i].layout]));
  2791. }
  2792. }
  2793. return layouts;
  2794. };
  2795. /**
  2796. * Returns the metadata of the given cells as a JSON object.
  2797. */
  2798. Graph.prototype.getDataForCells = function(cells)
  2799. {
  2800. var result = [];
  2801. for (var i = 0; i < cells.length; i++)
  2802. {
  2803. var attrs = (cells[i].value != null) ? cells[i].value.attributes : null;
  2804. var row = {};
  2805. row.id = cells[i].id;
  2806. if (attrs != null)
  2807. {
  2808. for (var j = 0; j < attrs.length; j++)
  2809. {
  2810. row[attrs[j].nodeName] = attrs[j].nodeValue;
  2811. }
  2812. }
  2813. else
  2814. {
  2815. row.label = this.convertValueToString(cells[i]);
  2816. }
  2817. result.push(row);
  2818. }
  2819. return result;
  2820. };
  2821. /**
  2822. * Returns the DOM nodes for the given cells.
  2823. */
  2824. Graph.prototype.getNodesForCells = function(cells)
  2825. {
  2826. var nodes = [];
  2827. for (var i = 0; i < cells.length; i++)
  2828. {
  2829. var state = this.view.getState(cells[i]);
  2830. if (state != null)
  2831. {
  2832. var shapes = this.cellRenderer.getShapesForState(state);
  2833. for (var j = 0; j < shapes.length; j++)
  2834. {
  2835. if (shapes[j] != null && shapes[j].node != null)
  2836. {
  2837. nodes.push(shapes[j].node);
  2838. }
  2839. }
  2840. // Adds folding icon
  2841. if (state.control != null && state.control.node != null)
  2842. {
  2843. nodes.push(state.control.node);
  2844. }
  2845. }
  2846. }
  2847. return nodes;
  2848. };
  2849. /**
  2850. * Creates animations for the given cells.
  2851. */
  2852. Graph.prototype.createWipeAnimations = function(cells, wipeIn)
  2853. {
  2854. var animations = [];
  2855. for (var i = 0; i < cells.length; i++)
  2856. {
  2857. var state = this.view.getState(cells[i]);
  2858. if (state != null && state.shape != null)
  2859. {
  2860. // TODO: include descendants
  2861. if (this.model.isEdge(state.cell) &&
  2862. state.absolutePoints != null &&
  2863. state.absolutePoints.length > 1)
  2864. {
  2865. animations.push(this.createEdgeWipeAnimation(state, wipeIn));
  2866. }
  2867. else if (this.model.isVertex(state.cell) &&
  2868. state.shape.bounds != null)
  2869. {
  2870. animations.push(this.createVertexWipeAnimation(state, wipeIn));
  2871. }
  2872. }
  2873. }
  2874. return animations;
  2875. };
  2876. /**
  2877. * Creates an object to show the given edge cell state.
  2878. */
  2879. Graph.prototype.createEdgeWipeAnimation = function(state, wipeIn)
  2880. {
  2881. var pts = state.absolutePoints.slice();
  2882. var segs = state.segments;
  2883. var total = state.length;
  2884. var n = pts.length;
  2885. return {
  2886. execute: mxUtils.bind(this, function(step, steps)
  2887. {
  2888. if (state.shape != null)
  2889. {
  2890. var pts2 = [pts[0]];
  2891. var f = step / steps;
  2892. if (!wipeIn)
  2893. {
  2894. f = 1 - f;
  2895. }
  2896. var dist = total * f;
  2897. for (var i = 1; i < n; i++)
  2898. {
  2899. if (dist <= segs[i - 1])
  2900. {
  2901. pts2.push(new mxPoint(pts[i - 1].x + (pts[i].x - pts[i - 1].x) * dist / segs[i - 1],
  2902. pts[i - 1].y + (pts[i].y - pts[i - 1].y) * dist / segs[i - 1]));
  2903. break;
  2904. }
  2905. else
  2906. {
  2907. dist -= segs[i - 1];
  2908. pts2.push(pts[i]);
  2909. }
  2910. }
  2911. state.shape.points = pts2;
  2912. state.shape.redraw();
  2913. if (step == 0)
  2914. {
  2915. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), 1);
  2916. }
  2917. if (state.text != null && state.text.node != null)
  2918. {
  2919. state.text.node.style.opacity = f;
  2920. }
  2921. }
  2922. }),
  2923. stop: mxUtils.bind(this, function()
  2924. {
  2925. if (state.shape != null)
  2926. {
  2927. state.shape.points = pts;
  2928. state.shape.redraw();
  2929. if (state.text != null && state.text.node != null)
  2930. {
  2931. state.text.node.style.opacity = ''
  2932. }
  2933. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), (wipeIn) ? 1 : 0);
  2934. }
  2935. })
  2936. };
  2937. };
  2938. /**
  2939. * Creates an object to show the given vertex cell state.
  2940. */
  2941. Graph.prototype.createVertexWipeAnimation = function(state, wipeIn)
  2942. {
  2943. var bds = new mxRectangle.fromRectangle(state.shape.bounds);
  2944. return {
  2945. execute: mxUtils.bind(this, function(step, steps)
  2946. {
  2947. if (state.shape != null)
  2948. {
  2949. var f = step / steps;
  2950. if (!wipeIn)
  2951. {
  2952. f = 1 - f;
  2953. }
  2954. state.shape.bounds = new mxRectangle(bds.x, bds.y, bds.width * f, bds.height);
  2955. state.shape.redraw();
  2956. if (step == 0)
  2957. {
  2958. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), 1);
  2959. }
  2960. if (state.text != null && state.text.node != null)
  2961. {
  2962. state.text.node.style.opacity = f;
  2963. }
  2964. }
  2965. }),
  2966. stop: mxUtils.bind(this, function()
  2967. {
  2968. if (state.shape != null)
  2969. {
  2970. state.shape.bounds = bds;
  2971. state.shape.redraw();
  2972. if (state.text != null && state.text.node != null)
  2973. {
  2974. state.text.node.style.opacity = ''
  2975. }
  2976. Graph.setOpacityForNodes(this.getNodesForCells([state.cell]), (wipeIn) ? 1 : 0);
  2977. }
  2978. })
  2979. };
  2980. };
  2981. /**
  2982. * Runs the animations for the given cells.
  2983. */
  2984. Graph.prototype.executeAnimations = function(animations, done, steps, delay)
  2985. {
  2986. steps = (steps != null) ? steps : 30;
  2987. delay = (delay != null) ? delay : 30;
  2988. var thread = null;
  2989. var step = 0;
  2990. var animate = mxUtils.bind(this, function()
  2991. {
  2992. if (step == steps || this.stoppingCustomActions)
  2993. {
  2994. window.clearInterval(thread);
  2995. for (var i = 0; i < animations.length; i++)
  2996. {
  2997. animations[i].stop();
  2998. }
  2999. if (done != null)
  3000. {
  3001. done();
  3002. }
  3003. }
  3004. else
  3005. {
  3006. for (var i = 0; i < animations.length; i++)
  3007. {
  3008. animations[i].execute(step, steps);
  3009. }
  3010. }
  3011. step++;
  3012. });
  3013. thread = window.setInterval(animate, delay);
  3014. animate();
  3015. };
  3016. /**
  3017. * Returns the size of the page format scaled with the page size.
  3018. */
  3019. Graph.prototype.getPageSize = function()
  3020. {
  3021. return (this.pageVisible) ? new mxRectangle(0, 0, this.pageFormat.width * this.pageScale,
  3022. this.pageFormat.height * this.pageScale) : this.scrollTileSize;
  3023. };
  3024. /**
  3025. * Returns a rectangle describing the position and count of the
  3026. * background pages, where x and y are the position of the top,
  3027. * left page and width and height are the vertical and horizontal
  3028. * page count.
  3029. */
  3030. Graph.prototype.getPageLayout = function()
  3031. {
  3032. var size = this.getPageSize();
  3033. var bounds = this.getGraphBounds();
  3034. if (bounds.width == 0 || bounds.height == 0)
  3035. {
  3036. return new mxRectangle(0, 0, 1, 1);
  3037. }
  3038. else
  3039. {
  3040. var x0 = Math.floor(Math.ceil(bounds.x / this.view.scale -
  3041. this.view.translate.x) / size.width);
  3042. var y0 = Math.floor(Math.ceil(bounds.y / this.view.scale -
  3043. this.view.translate.y) / size.height);
  3044. var w0 = Math.ceil((Math.floor((bounds.x + bounds.width) / this.view.scale) -
  3045. this.view.translate.x) / size.width) - x0;
  3046. var h0 = Math.ceil((Math.floor((bounds.y + bounds.height) / this.view.scale) -
  3047. this.view.translate.y) / size.height) - y0;
  3048. return new mxRectangle(x0, y0, w0, h0);
  3049. }
  3050. };
  3051. /**
  3052. * Sanitizes the given HTML markup.
  3053. */
  3054. Graph.prototype.sanitizeHtml = function(value, editing)
  3055. {
  3056. return Graph.sanitizeHtml(value, editing);
  3057. };
  3058. /**
  3059. * Revalidates all cells with placeholders in the current graph model.
  3060. */
  3061. Graph.prototype.updatePlaceholders = function()
  3062. {
  3063. var model = this.model;
  3064. var validate = false;
  3065. for (var key in this.model.cells)
  3066. {
  3067. var cell = this.model.cells[key];
  3068. if (this.isReplacePlaceholders(cell))
  3069. {
  3070. this.view.invalidate(cell, false, false);
  3071. validate = true;
  3072. }
  3073. }
  3074. if (validate)
  3075. {
  3076. this.view.validate();
  3077. }
  3078. };
  3079. /**
  3080. * Adds support for placeholders in labels.
  3081. */
  3082. Graph.prototype.isReplacePlaceholders = function(cell)
  3083. {
  3084. return cell.value != null && typeof(cell.value) == 'object' &&
  3085. cell.value.getAttribute('placeholders') == '1';
  3086. };
  3087. /**
  3088. * Returns true if the given mouse wheel event should be used for zooming. This
  3089. * is invoked if no dialogs are showing and returns true with Alt or Control
  3090. * (or cmd in macOS only) is pressed.
  3091. */
  3092. Graph.prototype.isZoomWheelEvent = function(evt)
  3093. {
  3094. return (Graph.zoomWheel && !mxEvent.isShiftDown(evt) && !mxEvent.isMetaDown(evt) &&
  3095. !mxEvent.isAltDown(evt) && (!mxEvent.isControlDown(evt) || mxClient.IS_MAC)) ||
  3096. (!Graph.zoomWheel && (mxEvent.isAltDown(evt) || mxEvent.isControlDown(evt)));
  3097. };
  3098. /**
  3099. * Returns true if the given scroll wheel event should be used for scrolling.
  3100. */
  3101. Graph.prototype.isScrollWheelEvent = function(evt)
  3102. {
  3103. return !this.isZoomWheelEvent(evt);
  3104. };
  3105. /**
  3106. * Adds Alt+click to select cells behind cells (Shift+Click on Chrome OS).
  3107. */
  3108. Graph.prototype.isTransparentClickEvent = function(evt)
  3109. {
  3110. return mxEvent.isAltDown(evt) || (mxClient.IS_CHROMEOS && mxEvent.isShiftDown(evt));
  3111. };
  3112. /**
  3113. * Adds ctrl+shift+connect to disable connections.
  3114. */
  3115. Graph.prototype.isIgnoreTerminalEvent = function(evt)
  3116. {
  3117. return mxEvent.isAltDown(evt) && !mxEvent.isShiftDown(evt) &&
  3118. !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt);
  3119. };
  3120. /**
  3121. * Returns true if the given edge should be ignored.
  3122. */
  3123. Graph.prototype.isEdgeIgnored = function(cell)
  3124. {
  3125. var result = false;
  3126. if (cell != null)
  3127. {
  3128. var style = this.getCurrentCellStyle(cell);
  3129. result = mxUtils.getValue(style, 'ignoreEdge', '0') == '1';
  3130. }
  3131. return result;
  3132. };
  3133. /**
  3134. * Adds support for placeholders in labels.
  3135. */
  3136. Graph.prototype.isSplitTarget = function(target, cells, evt)
  3137. {
  3138. return !this.model.isEdge(cells[0]) &&
  3139. !mxEvent.isAltDown(evt) && !mxEvent.isShiftDown(evt) &&
  3140. mxGraph.prototype.isSplitTarget.apply(this, arguments);
  3141. };
  3142. /**
  3143. * Adds support for placeholders in labels.
  3144. */
  3145. Graph.prototype.getLabel = function(cell)
  3146. {
  3147. var result = mxGraph.prototype.getLabel.apply(this, arguments);
  3148. if (result != null && this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') == null)
  3149. {
  3150. result = this.replacePlaceholders(cell, result);
  3151. }
  3152. return result;
  3153. };
  3154. /**
  3155. * Adds labelMovable style.
  3156. */
  3157. Graph.prototype.isLabelMovable = function(cell)
  3158. {
  3159. var style = this.getCurrentCellStyle(cell);
  3160. return !this.isCellLocked(cell) &&
  3161. ((this.model.isEdge(cell) && this.edgeLabelsMovable) ||
  3162. (this.model.isVertex(cell) && (this.vertexLabelsMovable ||
  3163. mxUtils.getValue(style, 'labelMovable', '0') == '1')));
  3164. };
  3165. /**
  3166. * Adds event if grid size is changed.
  3167. */
  3168. Graph.prototype.setGridSize = function(value)
  3169. {
  3170. this.gridSize = value;
  3171. this.fireEvent(new mxEventObject('gridSizeChanged'));
  3172. };
  3173. /**
  3174. * Adds event if default parent is changed.
  3175. */
  3176. Graph.prototype.setDefaultParent = function(cell)
  3177. {
  3178. this.defaultParent = cell;
  3179. this.fireEvent(new mxEventObject('defaultParentChanged'));
  3180. };
  3181. /**
  3182. * Function: getClickableLinkForCell
  3183. *
  3184. * Returns the first non-null link for the cell or its ancestors.
  3185. *
  3186. * Parameters:
  3187. *
  3188. * cell - <mxCell> whose link should be returned.
  3189. */
  3190. Graph.prototype.getClickableLinkForCell = function(cell)
  3191. {
  3192. do
  3193. {
  3194. var link = this.getLinkForCell(cell);
  3195. if (link != null)
  3196. {
  3197. return link;
  3198. }
  3199. cell = this.model.getParent(cell);
  3200. } while (cell != null);
  3201. return null;
  3202. };
  3203. /**
  3204. * Private helper method.
  3205. */
  3206. Graph.prototype.getGlobalVariable = function(name)
  3207. {
  3208. var val = null;
  3209. if (name == 'date')
  3210. {
  3211. val = new Date().toLocaleDateString();
  3212. }
  3213. else if (name == 'time')
  3214. {
  3215. val = new Date().toLocaleTimeString();
  3216. }
  3217. else if (name == 'timestamp')
  3218. {
  3219. val = new Date().toLocaleString();
  3220. }
  3221. else if (name.substring(0, 5) == 'date{')
  3222. {
  3223. var fmt = name.substring(5, name.length - 1);
  3224. val = this.formatDate(new Date(), fmt);
  3225. }
  3226. return val;
  3227. };
  3228. /**
  3229. * Formats a date, see http://blog.stevenlevithan.com/archives/date-time-format
  3230. */
  3231. Graph.prototype.formatDate = function(date, mask, utc)
  3232. {
  3233. // LATER: Cache regexs
  3234. if (this.dateFormatCache == null)
  3235. {
  3236. this.dateFormatCache = {
  3237. i18n: {
  3238. dayNames: [
  3239. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
  3240. "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  3241. ],
  3242. monthNames: [
  3243. "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  3244. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  3245. ]
  3246. },
  3247. masks: {
  3248. "default": "ddd mmm dd yyyy HH:MM:ss",
  3249. shortDate: "m/d/yy",
  3250. mediumDate: "mmm d, yyyy",
  3251. longDate: "mmmm d, yyyy",
  3252. fullDate: "dddd, mmmm d, yyyy",
  3253. shortTime: "h:MM TT",
  3254. mediumTime: "h:MM:ss TT",
  3255. longTime: "h:MM:ss TT Z",
  3256. isoDate: "yyyy-mm-dd",
  3257. isoTime: "HH:MM:ss",
  3258. isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
  3259. isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
  3260. }
  3261. };
  3262. }
  3263. var dF = this.dateFormatCache;
  3264. var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
  3265. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  3266. timezoneClip = /[^-+\dA-Z]/g,
  3267. pad = function (val, len) {
  3268. val = String(val);
  3269. len = len || 2;
  3270. while (val.length < len) val = "0" + val;
  3271. return val;
  3272. };
  3273. // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
  3274. if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
  3275. mask = date;
  3276. date = undefined;
  3277. }
  3278. // Passing date through Date applies Date.parse, if necessary
  3279. date = date ? new Date(date) : new Date;
  3280. if (isNaN(date)) throw SyntaxError("invalid date");
  3281. mask = String(dF.masks[mask] || mask || dF.masks["default"]);
  3282. // Allow setting the utc argument via the mask
  3283. if (mask.slice(0, 4) == "UTC:") {
  3284. mask = mask.slice(4);
  3285. utc = true;
  3286. }
  3287. var _ = utc ? "getUTC" : "get",
  3288. d = date[_ + "Date"](),
  3289. D = date[_ + "Day"](),
  3290. m = date[_ + "Month"](),
  3291. y = date[_ + "FullYear"](),
  3292. H = date[_ + "Hours"](),
  3293. M = date[_ + "Minutes"](),
  3294. s = date[_ + "Seconds"](),
  3295. L = date[_ + "Milliseconds"](),
  3296. o = utc ? 0 : date.getTimezoneOffset(),
  3297. flags = {
  3298. d: d,
  3299. dd: pad(d),
  3300. ddd: dF.i18n.dayNames[D],
  3301. dddd: dF.i18n.dayNames[D + 7],
  3302. m: m + 1,
  3303. mm: pad(m + 1),
  3304. mmm: dF.i18n.monthNames[m],
  3305. mmmm: dF.i18n.monthNames[m + 12],
  3306. yy: String(y).slice(2),
  3307. yyyy: y,
  3308. h: H % 12 || 12,
  3309. hh: pad(H % 12 || 12),
  3310. H: H,
  3311. HH: pad(H),
  3312. M: M,
  3313. MM: pad(M),
  3314. s: s,
  3315. ss: pad(s),
  3316. l: pad(L, 3),
  3317. L: pad(L > 99 ? Math.round(L / 10) : L),
  3318. t: H < 12 ? "a" : "p",
  3319. tt: H < 12 ? "am" : "pm",
  3320. T: H < 12 ? "A" : "P",
  3321. TT: H < 12 ? "AM" : "PM",
  3322. Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  3323. o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  3324. S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
  3325. };
  3326. return mask.replace(token, function ($0)
  3327. {
  3328. return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
  3329. });
  3330. };
  3331. /**
  3332. *
  3333. */
  3334. Graph.prototype.getLayerForCells = function(cells)
  3335. {
  3336. var result = null;
  3337. if (cells.length > 0)
  3338. {
  3339. result = cells[0];
  3340. while (!this.model.isLayer(result))
  3341. {
  3342. result = this.model.getParent(result);
  3343. }
  3344. for (var i = 1; i < cells.length; i++)
  3345. {
  3346. if (!this.model.isAncestor(result, cells[i]))
  3347. {
  3348. result = null;
  3349. break;
  3350. }
  3351. }
  3352. }
  3353. return result;
  3354. };
  3355. /**
  3356. *
  3357. */
  3358. Graph.prototype.createLayersDialog = function(onchange, inverted)
  3359. {
  3360. var div = document.createElement('div');
  3361. div.style.position = 'absolute';
  3362. var model = this.getModel();
  3363. var childCount = model.getChildCount(model.root);
  3364. for (var i = 0; i < childCount; i++)
  3365. {
  3366. (mxUtils.bind(this, function(layer)
  3367. {
  3368. var title = this.convertValueToString(layer) ||
  3369. (mxResources.get('background') || 'Background');
  3370. var span = document.createElement('div');
  3371. span.style.overflow = 'hidden';
  3372. span.style.textOverflow = 'ellipsis';
  3373. span.style.padding = '2px';
  3374. span.style.whiteSpace = 'nowrap';
  3375. span.style.cursor = 'pointer';
  3376. span.setAttribute('title', mxResources.get(
  3377. model.isVisible(layer) ?
  3378. 'hideIt' : 'show', [title]));
  3379. var inp = document.createElement('img');
  3380. inp.setAttribute('draggable', 'false');
  3381. inp.setAttribute('align', 'absmiddle');
  3382. inp.setAttribute('border', '0');
  3383. inp.style.position = 'relative';
  3384. inp.style.width = '16px';
  3385. inp.style.padding = '0px 6px 0 4px';
  3386. if (inverted)
  3387. {
  3388. inp.style.filter = 'invert(100%)';
  3389. inp.style.top = '-2px';
  3390. }
  3391. span.appendChild(inp);
  3392. mxUtils.write(span, title);
  3393. div.appendChild(span);
  3394. function update()
  3395. {
  3396. if (model.isVisible(layer))
  3397. {
  3398. inp.setAttribute('src', Editor.visibleImage);
  3399. mxUtils.setOpacity(span, 75);
  3400. }
  3401. else
  3402. {
  3403. inp.setAttribute('src', Editor.hiddenImage);
  3404. mxUtils.setOpacity(span, 25);
  3405. }
  3406. };
  3407. mxEvent.addListener(span, 'click', function()
  3408. {
  3409. model.setVisible(layer, !model.isVisible(layer));
  3410. update();
  3411. if (onchange != null)
  3412. {
  3413. onchange(layer);
  3414. }
  3415. });
  3416. update();
  3417. })(model.getChildAt(model.root, i)));
  3418. }
  3419. return div;
  3420. };
  3421. /**
  3422. * Private helper method.
  3423. */
  3424. Graph.prototype.replacePlaceholders = function(cell, str, vars, translate)
  3425. {
  3426. var result = [];
  3427. if (str != null)
  3428. {
  3429. var last = 0;
  3430. while (match = this.placeholderPattern.exec(str))
  3431. {
  3432. var val = match[0];
  3433. if (val.length > 2 && val != '%label%' && val != '%tooltip%')
  3434. {
  3435. var tmp = null;
  3436. if (match.index > last && str.charAt(match.index - 1) == '%')
  3437. {
  3438. tmp = val.substring(1);
  3439. }
  3440. else
  3441. {
  3442. var name = val.substring(1, val.length - 1);
  3443. // Workaround for invalid char for getting attribute in older versions of IE
  3444. if (name == 'id')
  3445. {
  3446. tmp = cell.id;
  3447. }
  3448. else if (name.indexOf('{') < 0)
  3449. {
  3450. var current = cell;
  3451. while (tmp == null && current != null)
  3452. {
  3453. if (current.value != null && typeof(current.value) == 'object')
  3454. {
  3455. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  3456. {
  3457. tmp = current.getAttribute(name + '_' + Graph.diagramLanguage);
  3458. }
  3459. if (tmp == null)
  3460. {
  3461. tmp = (current.hasAttribute(name)) ? ((current.getAttribute(name) != null) ?
  3462. current.getAttribute(name) : '') : null;
  3463. }
  3464. }
  3465. current = this.model.getParent(current);
  3466. }
  3467. }
  3468. if (tmp == null)
  3469. {
  3470. tmp = this.getGlobalVariable(name);
  3471. }
  3472. if (tmp == null && vars != null)
  3473. {
  3474. tmp = vars[name];
  3475. }
  3476. }
  3477. result.push(str.substring(last, match.index) + ((tmp != null) ? tmp : val));
  3478. last = match.index + val.length;
  3479. }
  3480. }
  3481. result.push(str.substring(last));
  3482. }
  3483. return result.join('');
  3484. };
  3485. /**
  3486. * Resolves the given cells in the model and selects them.
  3487. */
  3488. Graph.prototype.restoreSelection = function(cells)
  3489. {
  3490. if (cells != null && cells.length > 0)
  3491. {
  3492. var temp = [];
  3493. for (var i = 0; i < cells.length; i++)
  3494. {
  3495. var newCell = this.model.getCell(cells[i].id);
  3496. if (newCell != null)
  3497. {
  3498. temp.push(newCell);
  3499. }
  3500. }
  3501. this.setSelectionCells(temp);
  3502. }
  3503. else
  3504. {
  3505. this.clearSelection();
  3506. }
  3507. };
  3508. /**
  3509. * Adds table range selection with Shift+Click.
  3510. */
  3511. Graph.prototype.selectCellForEvent = function(cell, evt)
  3512. {
  3513. if (!mxEvent.isShiftDown(evt) || this.isSelectionEmpty() ||
  3514. !this.selectTableRange(this.getSelectionCell(), cell))
  3515. {
  3516. mxGraph.prototype.selectCellForEvent.apply(this, arguments);
  3517. }
  3518. };
  3519. /**
  3520. * Returns true if
  3521. */
  3522. Graph.prototype.selectTableRange = function(startCell, endCell)
  3523. {
  3524. var result = false;
  3525. if (this.isTableCell(startCell) && this.isTableCell(endCell))
  3526. {
  3527. var startRow = this.model.getParent(startCell);
  3528. var table = this.model.getParent(startRow);
  3529. var endRow = this.model.getParent(endCell);
  3530. if (table == this.model.getParent(endRow))
  3531. {
  3532. var startCellIndex = startRow.getIndex(startCell);
  3533. var startRowIndex = table.getIndex(startRow);
  3534. var endCellIndex = endRow.getIndex(endCell);
  3535. var endRowIndex = table.getIndex(endRow);
  3536. var fromRow = Math.min(startRowIndex, endRowIndex);
  3537. var toRow = Math.max(startRowIndex, endRowIndex);
  3538. var fromCell = Math.min(startCellIndex, endCellIndex);
  3539. var toCell = Math.max(startCellIndex, endCellIndex);
  3540. var cells = [];
  3541. for (var row = fromRow; row <= toRow; row++)
  3542. {
  3543. var currentRow = this.model.getChildAt(table, row);
  3544. for (var col = fromCell; col <= toCell; col++)
  3545. {
  3546. cells.push(this.model.getChildAt(currentRow, col));
  3547. }
  3548. }
  3549. if (cells.length > 0 && (cells.length > 1 ||
  3550. this.getSelectionCount() > 1 ||
  3551. !this.isCellSelected(cells[0])))
  3552. {
  3553. this.setSelectionCells(cells);
  3554. result = true;
  3555. }
  3556. }
  3557. }
  3558. return result;
  3559. };
  3560. /**
  3561. * Returns the cells for the given table range.
  3562. */
  3563. Graph.prototype.snapCellsToGrid = function(cells, gridSize)
  3564. {
  3565. this.getModel().beginUpdate();
  3566. try
  3567. {
  3568. for (var i = 0; i < cells.length; i++)
  3569. {
  3570. var cell = cells[i];
  3571. var geo = this.getCellGeometry(cell);
  3572. if (geo != null)
  3573. {
  3574. geo = geo.clone();
  3575. if (this.getModel().isVertex(cell))
  3576. {
  3577. geo.x = Math.round(geo.x / gridSize) * gridSize;
  3578. geo.y = Math.round(geo.y / gridSize) * gridSize;
  3579. geo.width = Math.round(geo.width / gridSize) * gridSize;
  3580. geo.height = Math.round(geo.height / gridSize) * gridSize;
  3581. }
  3582. else if (this.getModel().isEdge(cell) && geo.points != null)
  3583. {
  3584. for (var j = 0; j < geo.points.length; j++)
  3585. {
  3586. geo.points[j].x = Math.round(geo.points[j].x / gridSize) * gridSize;
  3587. geo.points[j].y = Math.round(geo.points[j].y / gridSize) * gridSize;
  3588. }
  3589. }
  3590. this.getModel().setGeometry(cell, geo);
  3591. }
  3592. }
  3593. }
  3594. finally
  3595. {
  3596. this.getModel().endUpdate();
  3597. }
  3598. };
  3599. /**
  3600. * Selects cells for connect vertex return value.
  3601. */
  3602. Graph.prototype.selectCellsForConnectVertex = function(cells, evt, hoverIcons)
  3603. {
  3604. // Selects only target vertex if one exists
  3605. if (cells.length == 2 && this.model.isVertex(cells[1]))
  3606. {
  3607. this.setSelectionCell(cells[1]);
  3608. this.scrollCellToVisible(cells[1]);
  3609. if (hoverIcons != null)
  3610. {
  3611. // Adds hover icons for cloned vertex or hides icons
  3612. if (mxEvent.isTouchEvent(evt))
  3613. {
  3614. hoverIcons.update(hoverIcons.getState(this.view.getState(cells[1])));
  3615. }
  3616. else
  3617. {
  3618. hoverIcons.reset();
  3619. }
  3620. }
  3621. }
  3622. else
  3623. {
  3624. this.setSelectionCells(cells);
  3625. }
  3626. };
  3627. /**
  3628. * Never connects children in stack layouts or tables.
  3629. */
  3630. Graph.prototype.isCloneConnectSource = function(source)
  3631. {
  3632. var layout = null;
  3633. if (this.layoutManager != null)
  3634. {
  3635. layout = this.layoutManager.getLayout(this.model.getParent(source));
  3636. }
  3637. return this.isTableRow(source) || this.isTableCell(source) ||
  3638. (layout != null && layout.constructor == mxStackLayout);
  3639. };
  3640. /**
  3641. * Adds a connection to the given vertex or clones the vertex in special layout
  3642. * containers without creating a connection.
  3643. */
  3644. Graph.prototype.connectVertex = function(source, direction, length, evt, forceClone, ignoreCellAt, createTarget, done)
  3645. {
  3646. ignoreCellAt = (ignoreCellAt) ? ignoreCellAt : false;
  3647. // Ignores relative edge labels
  3648. if (source.geometry.relative && this.model.isEdge(source.parent))
  3649. {
  3650. return [];
  3651. }
  3652. // Uses parent for relative child cells
  3653. while (source.geometry.relative && this.model.isVertex(source.parent))
  3654. {
  3655. source = source.parent;
  3656. }
  3657. // Handles clone connect sources
  3658. var cloneSource = this.isCloneConnectSource(source);
  3659. var composite = (cloneSource) ? source : this.getCompositeParent(source);
  3660. var pt = (source.geometry.relative && source.parent.geometry != null) ?
  3661. new mxPoint(source.parent.geometry.width * source.geometry.x,
  3662. source.parent.geometry.height * source.geometry.y) :
  3663. new mxPoint(composite.geometry.x, composite.geometry.y);
  3664. if (direction == mxConstants.DIRECTION_NORTH)
  3665. {
  3666. pt.x += composite.geometry.width / 2;
  3667. pt.y -= length ;
  3668. }
  3669. else if (direction == mxConstants.DIRECTION_SOUTH)
  3670. {
  3671. pt.x += composite.geometry.width / 2;
  3672. pt.y += composite.geometry.height + length;
  3673. }
  3674. else if (direction == mxConstants.DIRECTION_WEST)
  3675. {
  3676. pt.x -= length;
  3677. pt.y += composite.geometry.height / 2;
  3678. }
  3679. else
  3680. {
  3681. pt.x += composite.geometry.width + length;
  3682. pt.y += composite.geometry.height / 2;
  3683. }
  3684. var parentState = this.view.getState(this.model.getParent(source));
  3685. var s = this.view.scale;
  3686. var t = this.view.translate;
  3687. var dx = t.x * s;
  3688. var dy = t.y * s;
  3689. if (parentState != null && this.model.isVertex(parentState.cell))
  3690. {
  3691. dx = parentState.x;
  3692. dy = parentState.y;
  3693. }
  3694. // Workaround for relative child cells
  3695. if (this.model.isVertex(source.parent) && source.geometry.relative)
  3696. {
  3697. pt.x += source.parent.geometry.x;
  3698. pt.y += source.parent.geometry.y;
  3699. }
  3700. // Checks end point for target cell and container
  3701. var rect = (!ignoreCellAt) ? new mxRectangle(dx + pt.x * s, dy + pt.y * s).grow(40 * s) : null;
  3702. var tempCells = (rect != null) ? this.getCells(0, 0, 0, 0, null, null, rect, null, true) : null;
  3703. var sourceState = this.view.getState(source);
  3704. var container = null;
  3705. var target = null;
  3706. if (tempCells != null)
  3707. {
  3708. tempCells = tempCells.reverse();
  3709. for (var i = 0; i < tempCells.length; i++)
  3710. {
  3711. if (!this.isCellLocked(tempCells[i]) && !this.model.isEdge(tempCells[i]) && tempCells[i] != source)
  3712. {
  3713. // Direct parent overrides all possible containers
  3714. if (!this.model.isAncestor(source, tempCells[i]) && this.isContainer(tempCells[i]) &&
  3715. (container == null || tempCells[i] == this.model.getParent(source)))
  3716. {
  3717. container = tempCells[i];
  3718. }
  3719. // Containers are used as target cells but swimlanes are used as parents
  3720. else if (target == null && this.isCellConnectable(tempCells[i]) &&
  3721. !this.model.isAncestor(tempCells[i], source) &&
  3722. !this.isSwimlane(tempCells[i]))
  3723. {
  3724. var targetState = this.view.getState(tempCells[i]);
  3725. if (sourceState != null && targetState != null && !mxUtils.intersects(sourceState, targetState))
  3726. {
  3727. target = tempCells[i];
  3728. }
  3729. }
  3730. }
  3731. }
  3732. }
  3733. var duplicate = (!mxEvent.isShiftDown(evt) || mxEvent.isControlDown(evt)) || forceClone;
  3734. if (duplicate && (urlParams['sketch'] != '1' || forceClone))
  3735. {
  3736. if (direction == mxConstants.DIRECTION_NORTH)
  3737. {
  3738. pt.y -= source.geometry.height / 2;
  3739. }
  3740. else if (direction == mxConstants.DIRECTION_SOUTH)
  3741. {
  3742. pt.y += source.geometry.height / 2;
  3743. }
  3744. else if (direction == mxConstants.DIRECTION_WEST)
  3745. {
  3746. pt.x -= source.geometry.width / 2;
  3747. }
  3748. else
  3749. {
  3750. pt.x += source.geometry.width / 2;
  3751. }
  3752. }
  3753. var result = [];
  3754. var realTarget = target;
  3755. target = container;
  3756. var execute = mxUtils.bind(this, function(targetCell)
  3757. {
  3758. if (createTarget == null || targetCell != null || (target == null && cloneSource))
  3759. {
  3760. this.model.beginUpdate();
  3761. try
  3762. {
  3763. if (realTarget == null && duplicate)
  3764. {
  3765. // Handles relative and composite cells
  3766. var cellToClone = this.getAbsoluteParent((targetCell != null) ? targetCell : source);
  3767. cellToClone = (cloneSource) ? source : this.getCompositeParent(cellToClone);
  3768. realTarget = (targetCell != null) ? targetCell : this.duplicateCells([cellToClone], false)[0];
  3769. if (targetCell != null)
  3770. {
  3771. this.addCells([realTarget], this.model.getParent(source), null, null, null, true);
  3772. }
  3773. var geo = this.getCellGeometry(realTarget);
  3774. if (geo != null)
  3775. {
  3776. if (targetCell != null && urlParams['sketch'] == '1')
  3777. {
  3778. if (direction == mxConstants.DIRECTION_NORTH)
  3779. {
  3780. pt.y -= geo.height / 2;
  3781. }
  3782. else if (direction == mxConstants.DIRECTION_SOUTH)
  3783. {
  3784. pt.y += geo.height / 2;
  3785. }
  3786. else if (direction == mxConstants.DIRECTION_WEST)
  3787. {
  3788. pt.x -= geo.width / 2;
  3789. }
  3790. else
  3791. {
  3792. pt.x += geo.width / 2;
  3793. }
  3794. }
  3795. geo.x = pt.x - geo.width / 2;
  3796. geo.y = pt.y - geo.height / 2;
  3797. }
  3798. if (container != null)
  3799. {
  3800. this.addCells([realTarget], container, null, null, null, true);
  3801. target = null;
  3802. }
  3803. else if (duplicate && !cloneSource)
  3804. {
  3805. this.addCells([realTarget], this.getDefaultParent(), null, null, null, true);
  3806. }
  3807. }
  3808. var edge = ((mxEvent.isControlDown(evt) && mxEvent.isShiftDown(evt) && duplicate) ||
  3809. (target == null && cloneSource)) ? null : this.insertEdge(this.model.getParent(source),
  3810. null, '', source, realTarget, this.createCurrentEdgeStyle());
  3811. // Inserts edge before source
  3812. if (edge != null && this.connectionHandler.insertBeforeSource)
  3813. {
  3814. var index = null;
  3815. var tmp = source;
  3816. while (tmp.parent != null && tmp.geometry != null &&
  3817. tmp.geometry.relative && tmp.parent != edge.parent)
  3818. {
  3819. tmp = this.model.getParent(tmp);
  3820. }
  3821. if (tmp != null && tmp.parent != null && tmp.parent == edge.parent)
  3822. {
  3823. var index = tmp.parent.getIndex(tmp);
  3824. this.model.add(tmp.parent, edge, index);
  3825. }
  3826. }
  3827. // Special case: Click on west icon puts clone before cell
  3828. if (target == null && realTarget != null && source.parent != null &&
  3829. cloneSource && direction == mxConstants.DIRECTION_WEST)
  3830. {
  3831. var index = source.parent.getIndex(source);
  3832. this.model.add(source.parent, realTarget, index);
  3833. }
  3834. if (edge != null)
  3835. {
  3836. result.push(edge);
  3837. }
  3838. if (target == null && realTarget != null)
  3839. {
  3840. result.push(realTarget);
  3841. }
  3842. if (realTarget == null && edge != null)
  3843. {
  3844. edge.geometry.setTerminalPoint(pt, false);
  3845. }
  3846. if (edge != null)
  3847. {
  3848. this.fireEvent(new mxEventObject('cellsInserted', 'cells', [edge]));
  3849. }
  3850. }
  3851. finally
  3852. {
  3853. this.model.endUpdate();
  3854. }
  3855. }
  3856. if (done != null)
  3857. {
  3858. done(result);
  3859. }
  3860. else
  3861. {
  3862. return result;
  3863. }
  3864. });
  3865. if (createTarget != null && realTarget == null && duplicate &&
  3866. (target != null || !cloneSource))
  3867. {
  3868. createTarget(dx + pt.x * s, dy + pt.y * s, execute);
  3869. }
  3870. else
  3871. {
  3872. return execute(realTarget);
  3873. }
  3874. };
  3875. /**
  3876. * Returns all labels in the diagram as a string.
  3877. */
  3878. Graph.prototype.getIndexableText = function(cells)
  3879. {
  3880. cells = (cells != null) ? cells : this.model.
  3881. getDescendants(this.model.root);
  3882. var tmp = document.createElement('div');
  3883. var labels = [];
  3884. var label = '';
  3885. for (var i = 0; i < cells.length; i++)
  3886. {
  3887. var cell = cells[i];
  3888. if (this.model.isVertex(cell) || this.model.isEdge(cell))
  3889. {
  3890. if (this.isHtmlLabel(cell))
  3891. {
  3892. tmp.innerHTML = this.sanitizeHtml(this.getLabel(cell));
  3893. label = mxUtils.extractTextWithWhitespace([tmp]);
  3894. }
  3895. else
  3896. {
  3897. label = this.getLabel(cell);
  3898. }
  3899. label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' '));
  3900. if (label.length > 0)
  3901. {
  3902. labels.push(label);
  3903. }
  3904. }
  3905. }
  3906. return labels.join(' ');
  3907. };
  3908. /**
  3909. * Returns the label for the given cell.
  3910. */
  3911. Graph.prototype.convertValueToString = function(cell)
  3912. {
  3913. var value = this.model.getValue(cell);
  3914. if (value != null && typeof(value) == 'object')
  3915. {
  3916. var result = null;
  3917. if (this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') != null)
  3918. {
  3919. var name = cell.getAttribute('placeholder');
  3920. var current = cell;
  3921. while (result == null && current != null)
  3922. {
  3923. if (current.value != null && typeof(current.value) == 'object')
  3924. {
  3925. result = (current.hasAttribute(name)) ? ((current.getAttribute(name) != null) ?
  3926. current.getAttribute(name) : '') : null;
  3927. }
  3928. current = this.model.getParent(current);
  3929. }
  3930. }
  3931. else
  3932. {
  3933. var result = null;
  3934. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  3935. {
  3936. result = value.getAttribute('label_' + Graph.diagramLanguage);
  3937. }
  3938. if (result == null)
  3939. {
  3940. result = value.getAttribute('label') || '';
  3941. }
  3942. }
  3943. return result || '';
  3944. }
  3945. return mxGraph.prototype.convertValueToString.apply(this, arguments);
  3946. };
  3947. /**
  3948. * Returns the link for the given cell.
  3949. */
  3950. Graph.prototype.getLinksForState = function(state)
  3951. {
  3952. if (state != null && state.text != null && state.text.node != null)
  3953. {
  3954. return state.text.node.getElementsByTagName('a');
  3955. }
  3956. return null;
  3957. };
  3958. /**
  3959. * Returns the link for the given cell.
  3960. */
  3961. Graph.prototype.getLinkForCell = function(cell)
  3962. {
  3963. if (cell.value != null && typeof(cell.value) == 'object')
  3964. {
  3965. var link = cell.value.getAttribute('link');
  3966. // Removes links with leading javascript: protocol
  3967. // TODO: Check more possible attack vectors
  3968. if (link != null && link.toLowerCase().substring(0, 11) === 'javascript:')
  3969. {
  3970. link = link.substring(11);
  3971. }
  3972. return link;
  3973. }
  3974. return null;
  3975. };
  3976. /**
  3977. * Returns the link target for the given cell.
  3978. */
  3979. Graph.prototype.getLinkTargetForCell = function(cell)
  3980. {
  3981. if (cell.value != null && typeof(cell.value) == 'object')
  3982. {
  3983. return cell.value.getAttribute('linkTarget');
  3984. }
  3985. return null;
  3986. };
  3987. /**
  3988. * Adds style post processing steps.
  3989. */
  3990. Graph.prototype.postProcessCellStyle = function(cell, style)
  3991. {
  3992. return this.updateHorizontalStyle(cell,this.replaceDefaultColors(cell,
  3993. mxGraph.prototype.postProcessCellStyle.apply(this, arguments)));
  3994. };
  3995. /**
  3996. * Overrides label orientation for collapsed swimlanes inside stack and
  3997. * for partial rectangles inside tables.
  3998. */
  3999. Graph.prototype.updateHorizontalStyle = function(cell, style)
  4000. {
  4001. if (cell != null && style != null && this.layoutManager != null)
  4002. {
  4003. var parent = this.model.getParent(cell);
  4004. if (this.model.isVertex(parent) && this.isCellCollapsed(cell))
  4005. {
  4006. var layout = this.layoutManager.getLayout(parent);
  4007. if (layout != null && layout.constructor == mxStackLayout)
  4008. {
  4009. style[mxConstants.STYLE_HORIZONTAL] = !layout.horizontal;
  4010. }
  4011. }
  4012. }
  4013. return style;
  4014. };
  4015. /**
  4016. * Replaces default colors.
  4017. */
  4018. Graph.prototype.replaceDefaultColors = function(cell, style)
  4019. {
  4020. if (style != null)
  4021. {
  4022. var bg = mxUtils.hex2rgb(this.shapeBackgroundColor);
  4023. var fg = mxUtils.hex2rgb(this.shapeForegroundColor);
  4024. this.replaceDefaultColor(style, mxConstants.STYLE_FONTCOLOR, fg);
  4025. this.replaceDefaultColor(style, mxConstants.STYLE_FILLCOLOR, bg);
  4026. this.replaceDefaultColor(style, mxConstants.STYLE_STROKECOLOR, fg);
  4027. this.replaceDefaultColor(style, mxConstants.STYLE_IMAGE_BORDER, fg);
  4028. this.replaceDefaultColor(style, mxConstants.STYLE_IMAGE_BACKGROUND, bg);
  4029. this.replaceDefaultColor(style, mxConstants.STYLE_LABEL_BORDERCOLOR, fg);
  4030. this.replaceDefaultColor(style, mxConstants.STYLE_SWIMLANE_FILLCOLOR, bg);
  4031. this.replaceDefaultColor(style, mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, bg);
  4032. }
  4033. return style;
  4034. };
  4035. /**
  4036. * Replaces the colors for the given key.
  4037. */
  4038. Graph.prototype.replaceDefaultColor = function(style, key, value)
  4039. {
  4040. if (style != null && style[key] == 'default' && value != null)
  4041. {
  4042. style[key] = value;
  4043. }
  4044. };
  4045. /**
  4046. * Disables alternate width persistence for stack layout parents
  4047. */
  4048. Graph.prototype.updateAlternateBounds = function(cell, geo, willCollapse)
  4049. {
  4050. if (cell != null && geo != null && this.layoutManager != null && geo.alternateBounds != null)
  4051. {
  4052. var layout = this.layoutManager.getLayout(this.model.getParent(cell));
  4053. if (layout != null && layout.constructor == mxStackLayout)
  4054. {
  4055. if (layout.horizontal)
  4056. {
  4057. geo.alternateBounds.height = 0;
  4058. }
  4059. else
  4060. {
  4061. geo.alternateBounds.width = 0;
  4062. }
  4063. }
  4064. }
  4065. mxGraph.prototype.updateAlternateBounds.apply(this, arguments);
  4066. };
  4067. /**
  4068. * Adds Shift+collapse/expand and size management for folding inside stack
  4069. */
  4070. Graph.prototype.isMoveCellsEvent = function(evt, state)
  4071. {
  4072. return mxEvent.isShiftDown(evt) || mxUtils.getValue(state.style, 'moveCells', '0') == '1';
  4073. };
  4074. /**
  4075. * Adds Shift+collapse/expand and size management for folding inside stack
  4076. */
  4077. Graph.prototype.foldCells = function(collapse, recurse, cells, checkFoldable, evt)
  4078. {
  4079. recurse = (recurse != null) ? recurse : false;
  4080. if (cells == null)
  4081. {
  4082. cells = this.getFoldableCells(this.getSelectionCells(), collapse);
  4083. }
  4084. if (cells != null)
  4085. {
  4086. this.model.beginUpdate();
  4087. try
  4088. {
  4089. mxGraph.prototype.foldCells.apply(this, arguments);
  4090. // Resizes all parent stacks if alt is not pressed
  4091. if (this.layoutManager != null)
  4092. {
  4093. for (var i = 0; i < cells.length; i++)
  4094. {
  4095. var state = this.view.getState(cells[i]);
  4096. var geo = this.getCellGeometry(cells[i]);
  4097. if (state != null && geo != null)
  4098. {
  4099. var dx = Math.round(geo.width - state.width / this.view.scale);
  4100. var dy = Math.round(geo.height - state.height / this.view.scale);
  4101. if (dy != 0 || dx != 0)
  4102. {
  4103. var parent = this.model.getParent(cells[i]);
  4104. var layout = this.layoutManager.getLayout(parent);
  4105. if (layout == null)
  4106. {
  4107. // Moves cells to the right and down after collapse/expand
  4108. if (evt != null && this.isMoveCellsEvent(evt, state))
  4109. {
  4110. this.moveSiblings(state, parent, dx, dy);
  4111. }
  4112. }
  4113. else if ((evt == null || !mxEvent.isAltDown(evt)) &&
  4114. layout.constructor == mxStackLayout && !layout.resizeLast)
  4115. {
  4116. this.resizeParentStacks(parent, layout, dx, dy);
  4117. }
  4118. }
  4119. }
  4120. }
  4121. }
  4122. }
  4123. finally
  4124. {
  4125. this.model.endUpdate();
  4126. }
  4127. // Selects cells after folding
  4128. if (this.isEnabled())
  4129. {
  4130. this.setSelectionCells(cells);
  4131. }
  4132. }
  4133. };
  4134. /**
  4135. * Overrides label orientation for collapsed swimlanes inside stack.
  4136. */
  4137. Graph.prototype.moveSiblings = function(state, parent, dx, dy)
  4138. {
  4139. this.model.beginUpdate();
  4140. try
  4141. {
  4142. var cells = this.getCellsBeyond(state.x, state.y, parent, true, true);
  4143. for (var i = 0; i < cells.length; i++)
  4144. {
  4145. if (cells[i] != state.cell)
  4146. {
  4147. var tmp = this.view.getState(cells[i]);
  4148. var geo = this.getCellGeometry(cells[i]);
  4149. if (tmp != null && geo != null)
  4150. {
  4151. geo = geo.clone();
  4152. geo.translate(Math.round(dx * Math.max(0, Math.min(1, (tmp.x - state.x) / state.width))),
  4153. Math.round(dy * Math.max(0, Math.min(1, (tmp.y - state.y) / state.height))));
  4154. this.model.setGeometry(cells[i], geo);
  4155. }
  4156. }
  4157. }
  4158. }
  4159. finally
  4160. {
  4161. this.model.endUpdate();
  4162. }
  4163. };
  4164. /**
  4165. * Overrides label orientation for collapsed swimlanes inside stack.
  4166. */
  4167. Graph.prototype.resizeParentStacks = function(parent, layout, dx, dy)
  4168. {
  4169. if (this.layoutManager != null && layout != null && layout.constructor == mxStackLayout && !layout.resizeLast)
  4170. {
  4171. this.model.beginUpdate();
  4172. try
  4173. {
  4174. var dir = layout.horizontal;
  4175. // Bubble resize up for all parent stack layouts with same orientation
  4176. while (parent != null && layout != null && layout.constructor == mxStackLayout &&
  4177. layout.horizontal == dir && !layout.resizeLast)
  4178. {
  4179. var pgeo = this.getCellGeometry(parent);
  4180. var pstate = this.view.getState(parent);
  4181. if (pstate != null && pgeo != null)
  4182. {
  4183. pgeo = pgeo.clone();
  4184. if (layout.horizontal)
  4185. {
  4186. pgeo.width += dx + Math.min(0, pstate.width / this.view.scale - pgeo.width);
  4187. }
  4188. else
  4189. {
  4190. pgeo.height += dy + Math.min(0, pstate.height / this.view.scale - pgeo.height);
  4191. }
  4192. this.model.setGeometry(parent, pgeo);
  4193. }
  4194. parent = this.model.getParent(parent);
  4195. layout = this.layoutManager.getLayout(parent);
  4196. }
  4197. }
  4198. finally
  4199. {
  4200. this.model.endUpdate();
  4201. }
  4202. }
  4203. };
  4204. /**
  4205. * Disables drill-down for non-swimlanes.
  4206. */
  4207. Graph.prototype.isContainer = function(cell)
  4208. {
  4209. var style = this.getCurrentCellStyle(cell);
  4210. if (this.isSwimlane(cell))
  4211. {
  4212. return style['container'] != '0';
  4213. }
  4214. else
  4215. {
  4216. return style['container'] == '1';
  4217. }
  4218. };
  4219. /**
  4220. * Adds a connectable style.
  4221. */
  4222. Graph.prototype.isCellConnectable = function(cell)
  4223. {
  4224. var style = this.getCurrentCellStyle(cell);
  4225. return (style['connectable'] != null) ? style['connectable'] != '0' :
  4226. mxGraph.prototype.isCellConnectable.apply(this, arguments);
  4227. };
  4228. /**
  4229. * Adds labelMovable style.
  4230. */
  4231. Graph.prototype.isLabelMovable = function(cell)
  4232. {
  4233. var style = this.getCurrentCellStyle(cell);
  4234. return (style['movableLabel'] != null) ? style['movableLabel'] != '0' :
  4235. mxGraph.prototype.isLabelMovable.apply(this, arguments);
  4236. };
  4237. /**
  4238. * Function: selectAll
  4239. *
  4240. * Selects all children of the given parent cell or the children of the
  4241. * default parent if no parent is specified. To select leaf vertices and/or
  4242. * edges use <selectCells>.
  4243. *
  4244. * Parameters:
  4245. *
  4246. * parent - Optional <mxCell> whose children should be selected.
  4247. * Default is <defaultParent>.
  4248. */
  4249. Graph.prototype.selectAll = function(parent)
  4250. {
  4251. parent = parent || this.getDefaultParent();
  4252. if (!this.isCellLocked(parent))
  4253. {
  4254. mxGraph.prototype.selectAll.apply(this, arguments);
  4255. }
  4256. };
  4257. /**
  4258. * Function: selectCells
  4259. *
  4260. * Selects all vertices and/or edges depending on the given boolean
  4261. * arguments recursively, starting at the given parent or the default
  4262. * parent if no parent is specified. Use <selectAll> to select all cells.
  4263. * For vertices, only cells with no children are selected.
  4264. *
  4265. * Parameters:
  4266. *
  4267. * vertices - Boolean indicating if vertices should be selected.
  4268. * edges - Boolean indicating if edges should be selected.
  4269. * parent - Optional <mxCell> that acts as the root of the recursion.
  4270. * Default is <defaultParent>.
  4271. */
  4272. Graph.prototype.selectCells = function(vertices, edges, parent)
  4273. {
  4274. parent = parent || this.getDefaultParent();
  4275. if (!this.isCellLocked(parent))
  4276. {
  4277. mxGraph.prototype.selectCells.apply(this, arguments);
  4278. }
  4279. };
  4280. /**
  4281. * Function: getSwimlaneAt
  4282. *
  4283. * Returns the bottom-most swimlane that intersects the given point (x, y)
  4284. * in the cell hierarchy that starts at the given parent.
  4285. *
  4286. * Parameters:
  4287. *
  4288. * x - X-coordinate of the location to be checked.
  4289. * y - Y-coordinate of the location to be checked.
  4290. * parent - <mxCell> that should be used as the root of the recursion.
  4291. * Default is <defaultParent>.
  4292. */
  4293. Graph.prototype.getSwimlaneAt = function (x, y, parent)
  4294. {
  4295. var result = mxGraph.prototype.getSwimlaneAt.apply(this, arguments);
  4296. if (this.isCellLocked(result))
  4297. {
  4298. result = null;
  4299. }
  4300. return result;
  4301. };
  4302. /**
  4303. * Disables folding for non-swimlanes.
  4304. */
  4305. Graph.prototype.isCellFoldable = function(cell)
  4306. {
  4307. var style = this.getCurrentCellStyle(cell);
  4308. return this.foldingEnabled && mxUtils.getValue(style,
  4309. mxConstants.STYLE_RESIZABLE, '1') != '0' &&
  4310. (style['treeFolding'] == '1' ||
  4311. (!this.isCellLocked(cell) &&
  4312. ((this.isContainer(cell) && style['collapsible'] != '0') ||
  4313. (!this.isContainer(cell) && style['collapsible'] == '1'))));
  4314. };
  4315. /**
  4316. * Stops all interactions and clears the selection.
  4317. */
  4318. Graph.prototype.reset = function()
  4319. {
  4320. if (this.isEditing())
  4321. {
  4322. this.stopEditing(true);
  4323. }
  4324. this.escape();
  4325. if (!this.isSelectionEmpty())
  4326. {
  4327. this.clearSelection();
  4328. }
  4329. };
  4330. /**
  4331. * Overridden to limit zoom to 1% - 16.000%.
  4332. */
  4333. Graph.prototype.zoom = function(factor, center)
  4334. {
  4335. factor = Math.max(0.01, Math.min(this.view.scale * factor, 160)) / this.view.scale;
  4336. mxGraph.prototype.zoom.apply(this, arguments);
  4337. };
  4338. /**
  4339. * Function: zoomIn
  4340. *
  4341. * Zooms into the graph by <zoomFactor>.
  4342. */
  4343. Graph.prototype.zoomIn = function()
  4344. {
  4345. // Switches to 1% zoom steps below 15%
  4346. if (this.view.scale < 0.15)
  4347. {
  4348. this.zoom((this.view.scale + 0.01) / this.view.scale);
  4349. }
  4350. else
  4351. {
  4352. // Uses to 5% zoom steps for better grid rendering in webkit
  4353. // and to avoid rounding errors for zoom steps
  4354. this.zoom((Math.round(this.view.scale * this.zoomFactor * 20) / 20) / this.view.scale);
  4355. }
  4356. };
  4357. /**
  4358. * Function: zoomOut
  4359. *
  4360. * Zooms out of the graph by <zoomFactor>.
  4361. */
  4362. Graph.prototype.zoomOut = function()
  4363. {
  4364. // Switches to 1% zoom steps below 15%
  4365. if (this.view.scale <= 0.15)
  4366. {
  4367. this.zoom((this.view.scale - 0.01) / this.view.scale);
  4368. }
  4369. else
  4370. {
  4371. // Uses to 5% zoom steps for better grid rendering in webkit
  4372. // and to avoid rounding errors for zoom steps
  4373. this.zoom((Math.round(this.view.scale * (1 / this.zoomFactor) * 20) / 20) / this.view.scale);
  4374. }
  4375. };
  4376. /**
  4377. * Function: fitWindow
  4378. *
  4379. * Sets the current visible rectangle of the window in graph coordinates.
  4380. */
  4381. Graph.prototype.fitWindow = function(bounds, border)
  4382. {
  4383. border = (border != null) ? border : 10;
  4384. var cw = this.container.clientWidth - border;
  4385. var ch = this.container.clientHeight - border;
  4386. var scale = Math.floor(20 * Math.min(cw / bounds.width, ch / bounds.height)) / 20;
  4387. this.zoomTo(scale);
  4388. if (mxUtils.hasScrollbars(this.container))
  4389. {
  4390. var t = this.view.translate;
  4391. this.container.scrollTop = (bounds.y + t.y) * scale -
  4392. Math.max((ch - bounds.height * scale) / 2 + border / 2, 0);
  4393. this.container.scrollLeft = (bounds.x + t.x) * scale -
  4394. Math.max((cw - bounds.width * scale) / 2 + border / 2, 0);
  4395. }
  4396. };
  4397. /**
  4398. * Overrides tooltips to show custom tooltip or metadata.
  4399. */
  4400. Graph.prototype.getTooltipForCell = function(cell)
  4401. {
  4402. var tip = '';
  4403. if (mxUtils.isNode(cell.value))
  4404. {
  4405. var tmp = null;
  4406. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  4407. {
  4408. tmp = cell.value.getAttribute('tooltip_' + Graph.diagramLanguage);
  4409. }
  4410. if (tmp == null)
  4411. {
  4412. tmp = cell.value.getAttribute('tooltip');
  4413. }
  4414. if (tmp != null)
  4415. {
  4416. if (tmp != null && this.isReplacePlaceholders(cell))
  4417. {
  4418. tmp = this.replacePlaceholders(cell, tmp);
  4419. }
  4420. tip = this.sanitizeHtml(tmp);
  4421. }
  4422. else
  4423. {
  4424. var ignored = this.builtInProperties;
  4425. var attrs = cell.value.attributes;
  4426. var temp = [];
  4427. // Hides links in edit mode
  4428. if (this.isEnabled())
  4429. {
  4430. ignored.push('linkTarget');
  4431. ignored.push('link');
  4432. }
  4433. for (var i = 0; i < attrs.length; i++)
  4434. {
  4435. if (mxUtils.indexOf(ignored, attrs[i].nodeName) < 0 && attrs[i].nodeValue.length > 0)
  4436. {
  4437. temp.push({name: attrs[i].nodeName, value: attrs[i].nodeValue});
  4438. }
  4439. }
  4440. // Sorts by name
  4441. temp.sort(function(a, b)
  4442. {
  4443. if (a.name < b.name)
  4444. {
  4445. return -1;
  4446. }
  4447. else if (a.name > b.name)
  4448. {
  4449. return 1;
  4450. }
  4451. else
  4452. {
  4453. return 0;
  4454. }
  4455. });
  4456. for (var i = 0; i < temp.length; i++)
  4457. {
  4458. if (temp[i].name != 'link' || !this.isCustomLink(temp[i].value))
  4459. {
  4460. tip += ((temp[i].name != 'link') ? '<b>' + temp[i].name + ':</b> ' : '') +
  4461. mxUtils.htmlEntities(temp[i].value) + '\n';
  4462. }
  4463. }
  4464. if (tip.length > 0)
  4465. {
  4466. tip = tip.substring(0, tip.length - 1);
  4467. if (mxClient.IS_SVG)
  4468. {
  4469. tip = '<div style="max-width:360px;text-overflow:ellipsis;overflow:hidden;">' +
  4470. tip + '</div>';
  4471. }
  4472. }
  4473. }
  4474. }
  4475. return tip;
  4476. };
  4477. /**
  4478. * Adds rack child layout style.
  4479. */
  4480. Graph.prototype.getFlowAnimationStyle = function()
  4481. {
  4482. var head = document.getElementsByTagName('head')[0];
  4483. if (head != null && this.flowAnimationStyle == null)
  4484. {
  4485. this.flowAnimationStyle = document.createElement('style')
  4486. this.flowAnimationStyle.setAttribute('id',
  4487. 'geEditorFlowAnimation-' + Editor.guid());
  4488. this.flowAnimationStyle.type = 'text/css';
  4489. var id = this.flowAnimationStyle.getAttribute('id');
  4490. this.flowAnimationStyle.innerHTML = this.getFlowAnimationStyleCss(id);
  4491. head.appendChild(this.flowAnimationStyle);
  4492. }
  4493. return this.flowAnimationStyle;
  4494. };
  4495. /**
  4496. * Adds rack child layout style.
  4497. */
  4498. Graph.prototype.getFlowAnimationStyleCss = function(id)
  4499. {
  4500. return '.' + id + ' {\n' +
  4501. 'animation: ' + id + ' 0.5s linear;\n' +
  4502. 'animation-iteration-count: infinite;\n' +
  4503. '}\n' +
  4504. '@keyframes ' + id + ' {\n' +
  4505. 'to {\n' +
  4506. 'stroke-dashoffset: ' + (this.view.scale * -16) + ';\n' +
  4507. '}\n' +
  4508. '}';
  4509. };
  4510. /**
  4511. * Turns the given string into an array.
  4512. */
  4513. Graph.prototype.stringToBytes = function(str)
  4514. {
  4515. return Graph.stringToBytes(str);
  4516. };
  4517. /**
  4518. * Turns the given array into a string.
  4519. */
  4520. Graph.prototype.bytesToString = function(arr)
  4521. {
  4522. return Graph.bytesToString(arr);
  4523. };
  4524. /**
  4525. * Returns a base64 encoded version of the compressed outer XML of the given node.
  4526. */
  4527. Graph.prototype.compressNode = function(node)
  4528. {
  4529. return Graph.compressNode(node);
  4530. };
  4531. /**
  4532. * Returns a base64 encoded version of the compressed string.
  4533. */
  4534. Graph.prototype.compress = function(data, deflate)
  4535. {
  4536. return Graph.compress(data, deflate);
  4537. };
  4538. /**
  4539. * Returns a decompressed version of the base64 encoded string.
  4540. */
  4541. Graph.prototype.decompress = function(data, inflate)
  4542. {
  4543. return Graph.decompress(data, inflate);
  4544. };
  4545. /**
  4546. * Redirects to Graph.zapGremlins.
  4547. */
  4548. Graph.prototype.zapGremlins = function(text)
  4549. {
  4550. return Graph.zapGremlins(text);
  4551. };
  4552. /**
  4553. * Hover icons are used for hover, vertex handler and drag from sidebar.
  4554. */
  4555. HoverIcons = function(graph)
  4556. {
  4557. mxEventSource.call(this);
  4558. this.graph = graph;
  4559. this.init();
  4560. };
  4561. // Extends mxEventSource
  4562. mxUtils.extend(HoverIcons, mxEventSource);
  4563. /**
  4564. * Up arrow.
  4565. */
  4566. HoverIcons.prototype.arrowSpacing = 2;
  4567. /**
  4568. * Delay to switch to another state for overlapping bbox. Default is 500ms.
  4569. */
  4570. HoverIcons.prototype.updateDelay = 500;
  4571. /**
  4572. * Delay to switch between states. Default is 140ms.
  4573. */
  4574. HoverIcons.prototype.activationDelay = 140;
  4575. /**
  4576. * Up arrow.
  4577. */
  4578. HoverIcons.prototype.currentState = null;
  4579. /**
  4580. * Up arrow.
  4581. */
  4582. HoverIcons.prototype.activeArrow = null;
  4583. /**
  4584. * Up arrow.
  4585. */
  4586. HoverIcons.prototype.inactiveOpacity = 15;
  4587. /**
  4588. * Up arrow.
  4589. */
  4590. HoverIcons.prototype.cssCursor = 'copy';
  4591. /**
  4592. * Whether to hide arrows that collide with vertices.
  4593. * LATER: Add keyboard override, touch support.
  4594. */
  4595. HoverIcons.prototype.checkCollisions = true;
  4596. /**
  4597. * Up arrow.
  4598. */
  4599. HoverIcons.prototype.arrowFill = '#29b6f2';
  4600. /**
  4601. * Up arrow.
  4602. */
  4603. HoverIcons.prototype.triangleUp = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-up.png', 26, 14) :
  4604. 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" ' +
  4605. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  4606. /**
  4607. * Right arrow.
  4608. */
  4609. HoverIcons.prototype.triangleRight = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-right.png', 14, 26) :
  4610. 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" ' +
  4611. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  4612. /**
  4613. * Down arrow.
  4614. */
  4615. HoverIcons.prototype.triangleDown = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-down.png', 26, 14) :
  4616. 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" ' +
  4617. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  4618. /**
  4619. * Left arrow.
  4620. */
  4621. HoverIcons.prototype.triangleLeft = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-left.png', 14, 26) :
  4622. 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" ' +
  4623. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  4624. /**
  4625. * Round target.
  4626. */
  4627. HoverIcons.prototype.roundDrop = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/round-drop.png', 26, 26) :
  4628. Graph.createSvgImage(26, 26, '<circle cx="13" cy="13" r="12" ' +
  4629. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  4630. /**
  4631. * Refresh target.
  4632. */
  4633. HoverIcons.prototype.refreshTarget = new mxImage((mxClient.IS_SVG) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjM2cHgiIGhlaWdodD0iMzZweCI+PGVsbGlwc2UgZmlsbD0iIzI5YjZmMiIgY3g9IjEyIiBjeT0iMTIiIHJ4PSIxMiIgcnk9IjEyIi8+PHBhdGggdHJhbnNmb3JtPSJzY2FsZSgwLjgpIHRyYW5zbGF0ZSgyLjQsIDIuNCkiIHN0cm9rZT0iI2ZmZiIgZmlsbD0iI2ZmZiIgZD0iTTEyIDZ2M2w0LTQtNC00djNjLTQuNDIgMC04IDMuNTgtOCA4IDAgMS41Ny40NiAzLjAzIDEuMjQgNC4yNkw2LjcgMTQuOGMtLjQ1LS44My0uNy0xLjc5LS43LTIuOCAwLTMuMzEgMi42OS02IDYtNnptNi43NiAxLjc0TDE3LjMgOS4yYy40NC44NC43IDEuNzkuNyAyLjggMCAzLjMxLTIuNjkgNi02IDZ2LTNsLTQgNCA0IDR2LTNjNC40MiAwIDgtMy41OCA4LTggMC0xLjU3LS40Ni0zLjAzLTEuMjQtNC4yNnoiLz48cGF0aCBkPSJNMCAwaDI0djI0SDB6IiBmaWxsPSJub25lIi8+PC9zdmc+Cg==' :
  4634. IMAGE_PATH + '/refresh.png', 38, 38);
  4635. /**
  4636. * Tolerance for hover icon clicks.
  4637. */
  4638. HoverIcons.prototype.tolerance = (mxClient.IS_TOUCH) ? 6 : 0;
  4639. /**
  4640. *
  4641. */
  4642. HoverIcons.prototype.init = function()
  4643. {
  4644. this.arrowUp = this.createArrow(this.triangleUp, mxResources.get('plusTooltip'), mxConstants.DIRECTION_NORTH);
  4645. this.arrowRight = this.createArrow(this.triangleRight, mxResources.get('plusTooltip'), mxConstants.DIRECTION_EAST);
  4646. this.arrowDown = this.createArrow(this.triangleDown, mxResources.get('plusTooltip'), mxConstants.DIRECTION_SOUTH);
  4647. this.arrowLeft = this.createArrow(this.triangleLeft, mxResources.get('plusTooltip'), mxConstants.DIRECTION_WEST);
  4648. this.elts = [this.arrowUp, this.arrowRight, this.arrowDown, this.arrowLeft];
  4649. this.resetHandler = mxUtils.bind(this, function()
  4650. {
  4651. this.reset();
  4652. });
  4653. this.repaintHandler = mxUtils.bind(this, function()
  4654. {
  4655. this.repaint();
  4656. });
  4657. this.graph.selectionModel.addListener(mxEvent.CHANGE, this.resetHandler);
  4658. this.graph.model.addListener(mxEvent.CHANGE, this.repaintHandler);
  4659. this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.repaintHandler);
  4660. this.graph.view.addListener(mxEvent.TRANSLATE, this.repaintHandler);
  4661. this.graph.view.addListener(mxEvent.SCALE, this.repaintHandler);
  4662. this.graph.view.addListener(mxEvent.DOWN, this.repaintHandler);
  4663. this.graph.view.addListener(mxEvent.UP, this.repaintHandler);
  4664. this.graph.addListener(mxEvent.ROOT, this.repaintHandler);
  4665. this.graph.addListener(mxEvent.ESCAPE, this.resetHandler);
  4666. mxEvent.addListener(this.graph.container, 'scroll', this.resetHandler);
  4667. // Resets the mouse point on escape
  4668. this.graph.addListener(mxEvent.ESCAPE, mxUtils.bind(this, function()
  4669. {
  4670. this.mouseDownPoint = null;
  4671. }));
  4672. // Removes hover icons if mouse leaves the container
  4673. mxEvent.addListener(this.graph.container, 'mouseleave', mxUtils.bind(this, function(evt)
  4674. {
  4675. // Workaround for IE11 firing mouseleave for touch in diagram
  4676. if (evt.relatedTarget != null && mxEvent.getSource(evt) == this.graph.container)
  4677. {
  4678. this.setDisplay('none');
  4679. }
  4680. }));
  4681. // Resets current state when in-place editor starts
  4682. this.graph.addListener(mxEvent.START_EDITING, mxUtils.bind(this, function(evt)
  4683. {
  4684. this.reset();
  4685. }));
  4686. // Resets current state after update of selection state for touch events
  4687. var graphClick = this.graph.click;
  4688. this.graph.click = mxUtils.bind(this, function(me)
  4689. {
  4690. graphClick.apply(this.graph, arguments);
  4691. if (this.currentState != null && !this.graph.isCellSelected(this.currentState.cell) &&
  4692. mxEvent.isTouchEvent(me.getEvent()) && !this.graph.model.isVertex(me.getCell()))
  4693. {
  4694. this.reset();
  4695. }
  4696. });
  4697. // Checks if connection handler was active in mouse move
  4698. // as workaround for possible double connection inserted
  4699. var connectionHandlerActive = false;
  4700. // Implements a listener for hover and click handling
  4701. this.graph.addMouseListener(
  4702. {
  4703. mouseDown: mxUtils.bind(this, function(sender, me)
  4704. {
  4705. connectionHandlerActive = false;
  4706. var evt = me.getEvent();
  4707. if (this.isResetEvent(evt))
  4708. {
  4709. this.reset();
  4710. }
  4711. else if (!this.isActive())
  4712. {
  4713. var state = this.getState(me.getState());
  4714. if (state != null || !mxEvent.isTouchEvent(evt))
  4715. {
  4716. this.update(state);
  4717. }
  4718. }
  4719. this.setDisplay('none');
  4720. }),
  4721. mouseMove: mxUtils.bind(this, function(sender, me)
  4722. {
  4723. var evt = me.getEvent();
  4724. if (this.isResetEvent(evt))
  4725. {
  4726. this.reset();
  4727. }
  4728. else if (!this.graph.isMouseDown && !mxEvent.isTouchEvent(evt))
  4729. {
  4730. this.update(this.getState(me.getState()),
  4731. me.getGraphX(), me.getGraphY());
  4732. }
  4733. if (this.graph.connectionHandler != null &&
  4734. this.graph.connectionHandler.shape != null)
  4735. {
  4736. connectionHandlerActive = true;
  4737. }
  4738. }),
  4739. mouseUp: mxUtils.bind(this, function(sender, me)
  4740. {
  4741. var evt = me.getEvent();
  4742. var pt = mxUtils.convertPoint(this.graph.container,
  4743. mxEvent.getClientX(evt), mxEvent.getClientY(evt))
  4744. if (this.isResetEvent(evt))
  4745. {
  4746. this.reset();
  4747. }
  4748. else if (this.isActive() && !connectionHandlerActive &&
  4749. this.mouseDownPoint != null)
  4750. {
  4751. this.click(this.currentState, this.getDirection(), me);
  4752. }
  4753. else if (this.isActive())
  4754. {
  4755. // Selects target vertex after drag and clone if not only new edge was inserted
  4756. if (this.graph.getSelectionCount() != 1 || !this.graph.model.isEdge(
  4757. this.graph.getSelectionCell()))
  4758. {
  4759. this.update(this.getState(this.graph.view.getState(
  4760. this.graph.getCellAt(me.getGraphX(), me.getGraphY()))));
  4761. }
  4762. else
  4763. {
  4764. this.reset();
  4765. }
  4766. }
  4767. else if (mxEvent.isTouchEvent(evt) || (this.bbox != null &&
  4768. mxUtils.contains(this.bbox, me.getGraphX(), me.getGraphY())))
  4769. {
  4770. // Shows existing hover icons if inside bounding box
  4771. this.setDisplay('');
  4772. this.repaint();
  4773. }
  4774. else if (!mxEvent.isTouchEvent(evt))
  4775. {
  4776. this.reset();
  4777. }
  4778. connectionHandlerActive = false;
  4779. this.resetActiveArrow();
  4780. })
  4781. });
  4782. };
  4783. /**
  4784. *
  4785. */
  4786. HoverIcons.prototype.isResetEvent = function(evt, allowShift)
  4787. {
  4788. return mxEvent.isAltDown(evt) || (this.activeArrow == null && mxEvent.isShiftDown(evt)) ||
  4789. (mxEvent.isPopupTrigger(evt) && !this.graph.isCloneEvent(evt));
  4790. };
  4791. /**
  4792. *
  4793. */
  4794. HoverIcons.prototype.createArrow = function(img, tooltip, direction)
  4795. {
  4796. var arrow = null;
  4797. arrow = mxUtils.createImage(img.src);
  4798. arrow.style.width = img.width + 'px';
  4799. arrow.style.height = img.height + 'px';
  4800. arrow.style.padding = this.tolerance + 'px';
  4801. if (tooltip != null)
  4802. {
  4803. arrow.setAttribute('title', tooltip);
  4804. }
  4805. arrow.style.position = 'absolute';
  4806. arrow.style.cursor = this.cssCursor;
  4807. mxEvent.addGestureListeners(arrow, mxUtils.bind(this, function(evt)
  4808. {
  4809. if (this.currentState != null && !this.isResetEvent(evt))
  4810. {
  4811. this.mouseDownPoint = mxUtils.convertPoint(this.graph.container,
  4812. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  4813. this.drag(evt, this.mouseDownPoint.x, this.mouseDownPoint.y);
  4814. this.activeArrow = arrow;
  4815. this.setDisplay('none');
  4816. mxEvent.consume(evt);
  4817. }
  4818. }));
  4819. // Captures mouse events as events on graph
  4820. mxEvent.redirectMouseEvents(arrow, this.graph, this.currentState);
  4821. mxEvent.addListener(arrow, 'mouseenter', mxUtils.bind(this, function(evt)
  4822. {
  4823. // Workaround for Firefox firing mouseenter on touchend
  4824. if (mxEvent.isMouseEvent(evt))
  4825. {
  4826. if (this.activeArrow != null && this.activeArrow != arrow)
  4827. {
  4828. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  4829. }
  4830. this.graph.connectionHandler.constraintHandler.reset();
  4831. mxUtils.setOpacity(arrow, 100);
  4832. this.activeArrow = arrow;
  4833. this.fireEvent(new mxEventObject('focus', 'arrow', arrow,
  4834. 'direction', direction, 'event', evt));
  4835. }
  4836. }));
  4837. mxEvent.addListener(arrow, 'mouseleave', mxUtils.bind(this, function(evt)
  4838. {
  4839. if (mxEvent.isMouseEvent(evt))
  4840. {
  4841. this.fireEvent(new mxEventObject('blur', 'arrow', arrow,
  4842. 'direction', direction, 'event', evt));
  4843. }
  4844. // Workaround for IE11 firing this event on touch
  4845. if (!this.graph.isMouseDown)
  4846. {
  4847. this.resetActiveArrow();
  4848. }
  4849. }));
  4850. return arrow;
  4851. };
  4852. /**
  4853. *
  4854. */
  4855. HoverIcons.prototype.resetActiveArrow = function()
  4856. {
  4857. if (this.activeArrow != null)
  4858. {
  4859. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  4860. this.activeArrow = null;
  4861. }
  4862. };
  4863. /**
  4864. *
  4865. */
  4866. HoverIcons.prototype.getDirection = function()
  4867. {
  4868. var dir = mxConstants.DIRECTION_EAST;
  4869. if (this.activeArrow == this.arrowUp)
  4870. {
  4871. dir = mxConstants.DIRECTION_NORTH;
  4872. }
  4873. else if (this.activeArrow == this.arrowDown)
  4874. {
  4875. dir = mxConstants.DIRECTION_SOUTH;
  4876. }
  4877. else if (this.activeArrow == this.arrowLeft)
  4878. {
  4879. dir = mxConstants.DIRECTION_WEST;
  4880. }
  4881. return dir;
  4882. };
  4883. /**
  4884. *
  4885. */
  4886. HoverIcons.prototype.visitNodes = function(visitor)
  4887. {
  4888. for (var i = 0; i < this.elts.length; i++)
  4889. {
  4890. if (this.elts[i] != null)
  4891. {
  4892. visitor(this.elts[i]);
  4893. }
  4894. }
  4895. };
  4896. /**
  4897. *
  4898. */
  4899. HoverIcons.prototype.removeNodes = function()
  4900. {
  4901. this.visitNodes(function(elt)
  4902. {
  4903. if (elt.parentNode != null)
  4904. {
  4905. elt.parentNode.removeChild(elt);
  4906. }
  4907. });
  4908. };
  4909. /**
  4910. *
  4911. */
  4912. HoverIcons.prototype.setDisplay = function(display)
  4913. {
  4914. this.visitNodes(function(elt)
  4915. {
  4916. elt.style.display = display;
  4917. });
  4918. };
  4919. /**
  4920. *
  4921. */
  4922. HoverIcons.prototype.isActive = function()
  4923. {
  4924. return this.activeArrow != null && this.currentState != null;
  4925. };
  4926. /**
  4927. *
  4928. */
  4929. HoverIcons.prototype.drag = function(evt, x, y)
  4930. {
  4931. this.graph.popupMenuHandler.hideMenu();
  4932. this.graph.stopEditing(false);
  4933. // Checks if state was removed in call to stopEditing above
  4934. if (this.currentState != null)
  4935. {
  4936. this.graph.connectionHandler.start(this.currentState, x, y);
  4937. this.graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  4938. this.graph.isMouseDown = true;
  4939. // Hides handles for selection cell
  4940. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  4941. if (handler != null)
  4942. {
  4943. handler.setHandlesVisible(false);
  4944. }
  4945. // Ctrl+shift drag sets source constraint
  4946. var es = this.graph.connectionHandler.edgeState;
  4947. if (evt != null && mxEvent.isShiftDown(evt) && mxEvent.isControlDown(evt) && es != null &&
  4948. mxUtils.getValue(es.style, mxConstants.STYLE_EDGE, null) === 'orthogonalEdgeStyle')
  4949. {
  4950. var direction = this.getDirection();
  4951. es.cell.style = mxUtils.setStyle(es.cell.style, 'sourcePortConstraint', direction);
  4952. es.style['sourcePortConstraint'] = direction;
  4953. }
  4954. }
  4955. };
  4956. /**
  4957. *
  4958. */
  4959. HoverIcons.prototype.getStateAt = function(state, x, y)
  4960. {
  4961. return this.graph.view.getState(this.graph.getCellAt(x, y));
  4962. };
  4963. /**
  4964. *
  4965. */
  4966. HoverIcons.prototype.click = function(state, dir, me)
  4967. {
  4968. var evt = me.getEvent();
  4969. var x = me.getGraphX();
  4970. var y = me.getGraphY();
  4971. var tmp = this.getStateAt(state, x, y);
  4972. if (tmp != null && this.graph.model.isEdge(tmp.cell) && !this.graph.isCloneEvent(evt) &&
  4973. (tmp.getVisibleTerminalState(true) == state || tmp.getVisibleTerminalState(false) == state))
  4974. {
  4975. this.graph.setSelectionCell(tmp.cell);
  4976. this.reset();
  4977. }
  4978. else if (state != null)
  4979. {
  4980. this.execute(state, dir, me);
  4981. }
  4982. me.consume();
  4983. };
  4984. /**
  4985. *
  4986. */
  4987. HoverIcons.prototype.execute = function(state, dir, me)
  4988. {
  4989. var evt = me.getEvent();
  4990. this.graph.selectCellsForConnectVertex(this.graph.connectVertex(
  4991. state.cell, dir, this.graph.defaultEdgeLength, evt, this.graph.isCloneEvent(evt),
  4992. this.graph.isCloneEvent(evt)), evt, this);
  4993. };
  4994. /**
  4995. *
  4996. */
  4997. HoverIcons.prototype.reset = function(clearTimeout)
  4998. {
  4999. clearTimeout = (clearTimeout == null) ? true : clearTimeout;
  5000. if (clearTimeout && this.updateThread != null)
  5001. {
  5002. window.clearTimeout(this.updateThread);
  5003. }
  5004. this.mouseDownPoint = null;
  5005. this.currentState = null;
  5006. this.activeArrow = null;
  5007. this.removeNodes();
  5008. this.bbox = null;
  5009. this.fireEvent(new mxEventObject('reset'));
  5010. };
  5011. /**
  5012. *
  5013. */
  5014. HoverIcons.prototype.repaint = function()
  5015. {
  5016. this.bbox = null;
  5017. if (this.currentState != null)
  5018. {
  5019. // Checks if cell was deleted
  5020. this.currentState = this.getState(this.currentState);
  5021. // Cell was deleted
  5022. if (this.currentState != null &&
  5023. this.graph.model.isVertex(this.currentState.cell) &&
  5024. this.graph.isCellConnectable(this.currentState.cell))
  5025. {
  5026. var bds = mxRectangle.fromRectangle(this.currentState);
  5027. // Uses outer bounding box to take rotation into account
  5028. if (this.currentState.shape != null && this.currentState.shape.boundingBox != null)
  5029. {
  5030. bds = mxRectangle.fromRectangle(this.currentState.shape.boundingBox);
  5031. }
  5032. bds.grow(this.graph.tolerance);
  5033. bds.grow(this.arrowSpacing);
  5034. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  5035. if (this.graph.isTableRow(this.currentState.cell))
  5036. {
  5037. handler = this.graph.selectionCellsHandler.getHandler(
  5038. this.graph.model.getParent(this.currentState.cell));
  5039. }
  5040. var rotationBbox = null;
  5041. if (handler != null)
  5042. {
  5043. bds.x -= handler.horizontalOffset / 2;
  5044. bds.y -= handler.verticalOffset / 2;
  5045. bds.width += handler.horizontalOffset;
  5046. bds.height += handler.verticalOffset;
  5047. // Adds bounding box of rotation handle to avoid overlap
  5048. if (handler.rotationShape != null && handler.rotationShape.node != null &&
  5049. handler.rotationShape.node.style.visibility != 'hidden' &&
  5050. handler.rotationShape.node.style.display != 'none' &&
  5051. handler.rotationShape.boundingBox != null)
  5052. {
  5053. rotationBbox = handler.rotationShape.boundingBox;
  5054. }
  5055. }
  5056. // Positions arrows avoid collisions with rotation handle
  5057. var positionArrow = mxUtils.bind(this, function(arrow, x, y)
  5058. {
  5059. if (rotationBbox != null)
  5060. {
  5061. var bbox = new mxRectangle(x, y, arrow.clientWidth, arrow.clientHeight);
  5062. if (mxUtils.intersects(bbox, rotationBbox))
  5063. {
  5064. if (arrow == this.arrowUp)
  5065. {
  5066. y -= bbox.y + bbox.height - rotationBbox.y;
  5067. }
  5068. else if (arrow == this.arrowRight)
  5069. {
  5070. x += rotationBbox.x + rotationBbox.width - bbox.x;
  5071. }
  5072. else if (arrow == this.arrowDown)
  5073. {
  5074. y += rotationBbox.y + rotationBbox.height - bbox.y;
  5075. }
  5076. else if (arrow == this.arrowLeft)
  5077. {
  5078. x -= bbox.x + bbox.width - rotationBbox.x;
  5079. }
  5080. }
  5081. }
  5082. arrow.style.left = x + 'px';
  5083. arrow.style.top = y + 'px';
  5084. mxUtils.setOpacity(arrow, this.inactiveOpacity);
  5085. });
  5086. positionArrow(this.arrowUp,
  5087. Math.round(this.currentState.getCenterX() - this.triangleUp.width / 2 - this.tolerance),
  5088. Math.round(bds.y - this.triangleUp.height - this.tolerance));
  5089. positionArrow(this.arrowRight, Math.round(bds.x + bds.width - this.tolerance),
  5090. Math.round(this.currentState.getCenterY() - this.triangleRight.height / 2 - this.tolerance));
  5091. positionArrow(this.arrowDown, parseInt(this.arrowUp.style.left),
  5092. Math.round(bds.y + bds.height - this.tolerance));
  5093. positionArrow(this.arrowLeft, Math.round(bds.x - this.triangleLeft.width - this.tolerance),
  5094. parseInt(this.arrowRight.style.top));
  5095. if (this.checkCollisions)
  5096. {
  5097. var right = this.graph.getCellAt(bds.x + bds.width +
  5098. this.triangleRight.width / 2, this.currentState.getCenterY());
  5099. var left = this.graph.getCellAt(bds.x - this.triangleLeft.width / 2, this.currentState.getCenterY());
  5100. var top = this.graph.getCellAt(this.currentState.getCenterX(), bds.y - this.triangleUp.height / 2);
  5101. var bottom = this.graph.getCellAt(this.currentState.getCenterX(), bds.y + bds.height + this.triangleDown.height / 2);
  5102. // Shows hover icons large cell is behind all directions of current cell
  5103. if (right != null && right == left && left == top && top == bottom)
  5104. {
  5105. right = null;
  5106. left = null;
  5107. top = null;
  5108. bottom = null;
  5109. }
  5110. var currentGeo = this.graph.getCellGeometry(this.currentState.cell);
  5111. var checkCollision = mxUtils.bind(this, function(cell, arrow)
  5112. {
  5113. var geo = this.graph.model.isVertex(cell) && this.graph.getCellGeometry(cell);
  5114. // Ignores collision if vertex is more than 3 times the size of this vertex
  5115. if (cell != null && !this.graph.model.isAncestor(cell, this.currentState.cell) &&
  5116. !this.graph.isSwimlane(cell) && (geo == null || currentGeo == null ||
  5117. (geo.height < 3 * currentGeo.height && geo.width < 3 * currentGeo.width)))
  5118. {
  5119. arrow.style.visibility = 'hidden';
  5120. }
  5121. else
  5122. {
  5123. arrow.style.visibility = 'visible';
  5124. }
  5125. });
  5126. checkCollision(right, this.arrowRight);
  5127. checkCollision(left, this.arrowLeft);
  5128. checkCollision(top, this.arrowUp);
  5129. checkCollision(bottom, this.arrowDown);
  5130. }
  5131. else
  5132. {
  5133. this.arrowLeft.style.visibility = 'visible';
  5134. this.arrowRight.style.visibility = 'visible';
  5135. this.arrowUp.style.visibility = 'visible';
  5136. this.arrowDown.style.visibility = 'visible';
  5137. }
  5138. if (this.graph.tooltipHandler.isEnabled())
  5139. {
  5140. this.arrowLeft.setAttribute('title', mxResources.get('plusTooltip'));
  5141. this.arrowRight.setAttribute('title', mxResources.get('plusTooltip'));
  5142. this.arrowUp.setAttribute('title', mxResources.get('plusTooltip'));
  5143. this.arrowDown.setAttribute('title', mxResources.get('plusTooltip'));
  5144. }
  5145. else
  5146. {
  5147. this.arrowLeft.removeAttribute('title');
  5148. this.arrowRight.removeAttribute('title');
  5149. this.arrowUp.removeAttribute('title');
  5150. this.arrowDown.removeAttribute('title');
  5151. }
  5152. }
  5153. else
  5154. {
  5155. this.reset();
  5156. }
  5157. // Updates bounding box
  5158. if (this.currentState != null)
  5159. {
  5160. this.bbox = this.computeBoundingBox();
  5161. // Adds tolerance for hover
  5162. if (this.bbox != null)
  5163. {
  5164. this.bbox.grow(10);
  5165. }
  5166. }
  5167. }
  5168. };
  5169. /**
  5170. *
  5171. */
  5172. HoverIcons.prototype.computeBoundingBox = function()
  5173. {
  5174. var bbox = (!this.graph.model.isEdge(this.currentState.cell)) ? mxRectangle.fromRectangle(this.currentState) : null;
  5175. this.visitNodes(function(elt)
  5176. {
  5177. if (elt.parentNode != null)
  5178. {
  5179. var tmp = new mxRectangle(elt.offsetLeft, elt.offsetTop, elt.offsetWidth, elt.offsetHeight);
  5180. if (bbox == null)
  5181. {
  5182. bbox = tmp;
  5183. }
  5184. else
  5185. {
  5186. bbox.add(tmp);
  5187. }
  5188. }
  5189. });
  5190. return bbox;
  5191. };
  5192. /**
  5193. *
  5194. */
  5195. HoverIcons.prototype.getState = function(state)
  5196. {
  5197. if (state != null)
  5198. {
  5199. var cell = state.cell;
  5200. if (!this.graph.getModel().contains(cell))
  5201. {
  5202. state = null;
  5203. }
  5204. else
  5205. {
  5206. // Uses connectable parent vertex if child is not connectable
  5207. if (this.graph.getModel().isVertex(cell) && !this.graph.isCellConnectable(cell))
  5208. {
  5209. var parent = this.graph.getModel().getParent(cell);
  5210. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  5211. {
  5212. cell = parent;
  5213. }
  5214. }
  5215. // Ignores locked cells and edges
  5216. if (this.graph.isCellLocked(cell) || this.graph.model.isEdge(cell))
  5217. {
  5218. cell = null;
  5219. }
  5220. state = this.graph.view.getState(cell);
  5221. if (state != null && state.style == null)
  5222. {
  5223. state = null;
  5224. }
  5225. }
  5226. }
  5227. return state;
  5228. };
  5229. /**
  5230. *
  5231. */
  5232. HoverIcons.prototype.update = function(state, x, y)
  5233. {
  5234. if (!this.graph.connectionArrowsEnabled || (state != null &&
  5235. mxUtils.getValue(state.style, 'allowArrows', '1') == '0'))
  5236. {
  5237. this.reset();
  5238. }
  5239. else
  5240. {
  5241. if (state != null && state.cell.geometry != null && state.cell.geometry.relative &&
  5242. this.graph.model.isEdge(state.cell.parent))
  5243. {
  5244. state = null;
  5245. }
  5246. var timeOnTarget = null;
  5247. // Time on target
  5248. if (this.prev != state || this.isActive())
  5249. {
  5250. this.startTime = new Date().getTime();
  5251. this.prev = state;
  5252. timeOnTarget = 0;
  5253. if (this.updateThread != null)
  5254. {
  5255. window.clearTimeout(this.updateThread);
  5256. }
  5257. if (state != null)
  5258. {
  5259. // Starts timer to update current state with no mouse events
  5260. this.updateThread = window.setTimeout(mxUtils.bind(this, function()
  5261. {
  5262. if (!this.isActive() && !this.graph.isMouseDown &&
  5263. !this.graph.panningHandler.isActive())
  5264. {
  5265. this.prev = state;
  5266. this.update(state, x, y);
  5267. }
  5268. }), this.updateDelay + 10);
  5269. }
  5270. }
  5271. else if (this.startTime != null)
  5272. {
  5273. timeOnTarget = new Date().getTime() - this.startTime;
  5274. }
  5275. this.setDisplay('');
  5276. if (this.currentState != null && this.currentState != state && timeOnTarget < this.activationDelay &&
  5277. this.bbox != null && !mxUtils.contains(this.bbox, x, y))
  5278. {
  5279. this.reset(false);
  5280. }
  5281. else if (this.currentState != null || timeOnTarget > this.activationDelay)
  5282. {
  5283. if (this.currentState != state && ((timeOnTarget > this.updateDelay && state != null) ||
  5284. this.bbox == null || x == null || y == null || !mxUtils.contains(this.bbox, x, y)))
  5285. {
  5286. if (state != null && this.graph.isEnabled())
  5287. {
  5288. this.removeNodes();
  5289. this.setCurrentState(state);
  5290. this.repaint();
  5291. // Resets connection points on other focused cells
  5292. if (this.graph.connectionHandler.constraintHandler.currentFocus != state)
  5293. {
  5294. this.graph.connectionHandler.constraintHandler.reset();
  5295. }
  5296. }
  5297. else
  5298. {
  5299. this.reset();
  5300. }
  5301. }
  5302. }
  5303. }
  5304. };
  5305. /**
  5306. *
  5307. */
  5308. HoverIcons.prototype.setCurrentState = function(state)
  5309. {
  5310. if (state.style['portConstraint'] != 'eastwest')
  5311. {
  5312. this.graph.container.appendChild(this.arrowUp);
  5313. this.graph.container.appendChild(this.arrowDown);
  5314. }
  5315. this.graph.container.appendChild(this.arrowRight);
  5316. this.graph.container.appendChild(this.arrowLeft);
  5317. this.currentState = state;
  5318. };
  5319. /**
  5320. * Returns true if the given cell is a table.
  5321. */
  5322. Graph.prototype.createParent = function(parent, child, childCount, dx, dy)
  5323. {
  5324. parent = this.cloneCell(parent);
  5325. for (var i = 0; i < childCount; i++)
  5326. {
  5327. var clone = this.cloneCell(child);
  5328. var geo = this.getCellGeometry(clone)
  5329. if (geo != null)
  5330. {
  5331. geo.x += i * dx;
  5332. geo.y += i * dy;
  5333. }
  5334. parent.insert(clone);
  5335. }
  5336. return parent;
  5337. };
  5338. /**
  5339. * Returns true if the given cell is a table.
  5340. */
  5341. Graph.prototype.createTable = function(rowCount, colCount, w, h, title, startSize, tableStyle, rowStyle, cellStyle)
  5342. {
  5343. w = (w != null) ? w : 60;
  5344. h = (h != null) ? h : 40;
  5345. startSize = (startSize != null) ? startSize : 30;
  5346. tableStyle = (tableStyle != null) ? tableStyle : 'shape=table;startSize=' +
  5347. ((title != null) ? startSize : '0') + ';container=1;collapsible=0;childLayout=tableLayout;';
  5348. rowStyle = (rowStyle != null) ? rowStyle : 'shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;' +
  5349. 'top=0;left=0;bottom=0;right=0;collapsible=0;dropTarget=0;fillColor=none;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;';
  5350. cellStyle = (cellStyle != null) ? cellStyle : 'shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;' +
  5351. 'overflow=hidden;fillColor=none;top=0;left=0;bottom=0;right=0;pointerEvents=1;';
  5352. return this.createParent(this.createVertex(null, null, (title != null) ? title : '',
  5353. 0, 0, colCount * w, rowCount * h + ((title != null) ? startSize : 0), tableStyle),
  5354. this.createParent(this.createVertex(null, null, '', 0, 0, colCount * w, h, rowStyle),
  5355. this.createVertex(null, null, '', 0, 0, w, h, cellStyle),
  5356. colCount, w, 0), rowCount, 0, h);
  5357. };
  5358. /**
  5359. * Sets the values for the cells and rows in the given table and returns the table.
  5360. */
  5361. Graph.prototype.setTableValues = function(table, values, rowValues)
  5362. {
  5363. var rows = this.model.getChildCells(table, true);
  5364. for (var i = 0; i < rows.length; i++)
  5365. {
  5366. if (rowValues != null)
  5367. {
  5368. rows[i].value = rowValues[i];
  5369. }
  5370. if (values != null)
  5371. {
  5372. var cells = this.model.getChildCells(rows[i], true);
  5373. for (var j = 0; j < cells.length; j++)
  5374. {
  5375. if (values[i][j] != null)
  5376. {
  5377. cells[j].value = values[i][j];
  5378. }
  5379. }
  5380. }
  5381. }
  5382. return table;
  5383. };
  5384. /**
  5385. *
  5386. */
  5387. Graph.prototype.createCrossFunctionalSwimlane = function(rowCount, colCount, w, h, title, tableStyle, rowStyle, firstCellStyle, cellStyle)
  5388. {
  5389. w = (w != null) ? w : 120;
  5390. h = (h != null) ? h : 120;
  5391. var s = 'collapsible=0;recursiveResize=0;expand=0;';
  5392. tableStyle = (tableStyle != null) ? tableStyle : 'shape=table;childLayout=tableLayout;' +
  5393. ((title == null) ? 'startSize=0;fillColor=none;' : 'startSize=40;') + s;
  5394. rowStyle = (rowStyle != null) ? rowStyle : 'shape=tableRow;horizontal=0;swimlaneHead=0;swimlaneBody=0;top=0;left=0;' +
  5395. 'bottom=0;right=0;dropTarget=0;fontStyle=0;fillColor=none;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;startSize=40;' + s;
  5396. firstCellStyle = (firstCellStyle != null) ? firstCellStyle : 'swimlane;swimlaneHead=0;swimlaneBody=0;fontStyle=0;' +
  5397. 'connectable=0;fillColor=none;startSize=40;' + s;
  5398. cellStyle = (cellStyle != null) ? cellStyle : 'swimlane;swimlaneHead=0;swimlaneBody=0;fontStyle=0;connectable=0;' +
  5399. 'fillColor=none;startSize=0;' + s;
  5400. var table = this.createVertex(null, null, (title != null) ? title : '', 0, 0,
  5401. colCount * w, rowCount * h, tableStyle);
  5402. var t = mxUtils.getValue(this.getCellStyle(table), mxConstants.STYLE_STARTSIZE,
  5403. mxConstants.DEFAULT_STARTSIZE);
  5404. table.geometry.width += t;
  5405. table.geometry.height += t;
  5406. var row = this.createVertex(null, null, '', 0, t, colCount * w + t, h, rowStyle);
  5407. table.insert(this.createParent(row, this.createVertex(null, null,
  5408. '', t, 0, w, h, firstCellStyle), colCount, w, 0));
  5409. if (rowCount > 1)
  5410. {
  5411. row.geometry.y = h + t;
  5412. return this.createParent(table, this.createParent(row,
  5413. this.createVertex(null, null, '', t, 0, w, h, cellStyle),
  5414. colCount, w, 0), rowCount - 1, 0, h);
  5415. }
  5416. else
  5417. {
  5418. return table;
  5419. }
  5420. };
  5421. /**
  5422. * Returns the row and column lines for the given table.
  5423. */
  5424. Graph.prototype.visitTableCells = function(cell, visitor)
  5425. {
  5426. var lastRow = null;
  5427. var rows = this.model.getChildCells(cell, true);
  5428. var start = this.getActualStartSize(cell, true);
  5429. for (var i = 0; i < rows.length; i++)
  5430. {
  5431. var rowStart = this.getActualStartSize(rows[i], true);
  5432. var cols = this.model.getChildCells(rows[i], true);
  5433. var rowStyle = this.getCellStyle(rows[i], true);
  5434. var lastCol = null;
  5435. var row = [];
  5436. for (var j = 0; j < cols.length; j++)
  5437. {
  5438. var geo = this.getCellGeometry(cols[j]);
  5439. var col = {cell: cols[j], rospan: 1, colspan: 1, row: i, col: j, geo: geo};
  5440. geo = (geo.alternateBounds != null) ? geo.alternateBounds : geo;
  5441. col.point = new mxPoint(geo.width + (lastCol != null ? lastCol.point.x : start.x + rowStart.x),
  5442. geo.height + (lastRow != null && lastRow[0] != null ? lastRow[0].point.y : start.y + rowStart.y));
  5443. col.actual = col;
  5444. if (lastRow != null && lastRow[j] != null && lastRow[j].rowspan > 1)
  5445. {
  5446. col.rowspan = lastRow[j].rowspan - 1;
  5447. col.colspan = lastRow[j].colspan;
  5448. col.actual = lastRow[j].actual;
  5449. }
  5450. else
  5451. {
  5452. if (lastCol != null && lastCol.colspan > 1)
  5453. {
  5454. col.rowspan = lastCol.rowspan;
  5455. col.colspan = lastCol.colspan - 1;
  5456. col.actual = lastCol.actual;
  5457. }
  5458. else
  5459. {
  5460. var style = this.getCurrentCellStyle(cols[j], true);
  5461. if (style != null)
  5462. {
  5463. col.rowspan = parseInt(style['rowspan'] || 1);
  5464. col.colspan = parseInt(style['colspan'] || 1);
  5465. }
  5466. }
  5467. }
  5468. var head = mxUtils.getValue(rowStyle, mxConstants.STYLE_SWIMLANE_HEAD, 1) == 1 &&
  5469. mxUtils.getValue(rowStyle, mxConstants.STYLE_STROKECOLOR,
  5470. mxConstants.NONE) != mxConstants.NONE;
  5471. visitor(col, cols.length, rows.length,
  5472. start.x + ((head) ? rowStart.x : 0),
  5473. start.y + ((head) ? rowStart.y : 0));
  5474. row.push(col);
  5475. lastCol = col;
  5476. }
  5477. lastRow = row;
  5478. }
  5479. };
  5480. /**
  5481. * Returns the row and column lines for the given table.
  5482. */
  5483. Graph.prototype.getTableLines = function(cell, horizontal, vertical)
  5484. {
  5485. var hl = [];
  5486. var vl = [];
  5487. if (horizontal || vertical)
  5488. {
  5489. this.visitTableCells(cell, mxUtils.bind(this, function(iter, colCount, rowCount, x0, y0)
  5490. {
  5491. // Constructs horizontal lines
  5492. if (horizontal && iter.row < rowCount - 1)
  5493. {
  5494. if (hl[iter.row] == null)
  5495. {
  5496. hl[iter.row] = [new mxPoint(x0, iter.point.y)];
  5497. }
  5498. if (iter.rowspan > 1)
  5499. {
  5500. hl[iter.row].push(null);
  5501. }
  5502. hl[iter.row].push(iter.point);
  5503. }
  5504. // Constructs vertical lines
  5505. if (vertical && iter.col < colCount - 1)
  5506. {
  5507. if (vl[iter.col] == null)
  5508. {
  5509. vl[iter.col] = [new mxPoint(iter.point.x, y0)];
  5510. }
  5511. if (iter.colspan > 1)
  5512. {
  5513. vl[iter.col].push(null);
  5514. }
  5515. vl[iter.col].push(iter.point);
  5516. }
  5517. }));
  5518. }
  5519. return hl.concat(vl);
  5520. };
  5521. /**
  5522. * Returns true if the given cell is a table cell.
  5523. */
  5524. Graph.prototype.isTableCell = function(cell)
  5525. {
  5526. return this.model.isVertex(cell) && this.isTableRow(this.model.getParent(cell));
  5527. };
  5528. /**
  5529. * Returns true if the given cell is a table row.
  5530. */
  5531. Graph.prototype.isTableRow = function(cell)
  5532. {
  5533. return this.model.isVertex(cell) && this.isTable(this.model.getParent(cell));
  5534. };
  5535. /**
  5536. * Returns true if the given cell is a table.
  5537. */
  5538. Graph.prototype.isTable = function(cell)
  5539. {
  5540. var style = this.getCellStyle(cell);
  5541. return style != null && style['childLayout'] == 'tableLayout';
  5542. };
  5543. /**
  5544. * Returns true if the given cell is a table.
  5545. */
  5546. Graph.prototype.isStack = function(cell)
  5547. {
  5548. var style = this.getCellStyle(cell);
  5549. return style != null && style['childLayout'] == 'stackLayout';
  5550. };
  5551. /**
  5552. * Returns true if the given cell is a table row.
  5553. */
  5554. Graph.prototype.isStackChild = function(cell)
  5555. {
  5556. return this.model.isVertex(cell) && this.isStack(this.model.getParent(cell));
  5557. };
  5558. /**
  5559. * Updates the row and table heights.
  5560. */
  5561. Graph.prototype.setTableRowHeight = function(row, dy, extend)
  5562. {
  5563. extend = (extend != null) ? extend : true;
  5564. var model = this.getModel();
  5565. model.beginUpdate();
  5566. try
  5567. {
  5568. var rgeo = this.getCellGeometry(row);
  5569. // Sets height of row
  5570. if (rgeo != null)
  5571. {
  5572. rgeo = rgeo.clone();
  5573. rgeo.height += dy;
  5574. model.setGeometry(row, rgeo);
  5575. var table = model.getParent(row);
  5576. var rows = model.getChildCells(table, true);
  5577. // Shifts and resizes neighbor row
  5578. if (!extend)
  5579. {
  5580. var index = mxUtils.indexOf(rows, row);
  5581. if (index < rows.length - 1)
  5582. {
  5583. var nextRow = rows[index + 1];
  5584. var geo = this.getCellGeometry(nextRow);
  5585. if (geo != null)
  5586. {
  5587. geo = geo.clone();
  5588. geo.y += dy;
  5589. geo.height -= dy;
  5590. model.setGeometry(nextRow, geo);
  5591. }
  5592. }
  5593. }
  5594. // Updates height of table
  5595. var tgeo = this.getCellGeometry(table);
  5596. if (tgeo != null)
  5597. {
  5598. // Always extends for last row
  5599. if (!extend)
  5600. {
  5601. extend = row == rows[rows.length - 1];
  5602. }
  5603. if (extend)
  5604. {
  5605. tgeo = tgeo.clone();
  5606. tgeo.height += dy;
  5607. model.setGeometry(table, tgeo);
  5608. }
  5609. }
  5610. }
  5611. }
  5612. finally
  5613. {
  5614. model.endUpdate();
  5615. }
  5616. };
  5617. /**
  5618. * Updates column width and row height.
  5619. */
  5620. Graph.prototype.setTableColumnWidth = function(col, dx, extend)
  5621. {
  5622. extend = (extend != null) ? extend : false;
  5623. var model = this.getModel();
  5624. var row = model.getParent(col);
  5625. var table = model.getParent(row);
  5626. var cells = model.getChildCells(row, true);
  5627. var index = mxUtils.indexOf(cells, col);
  5628. var lastColumn = index == cells.length - 1;
  5629. model.beginUpdate();
  5630. try
  5631. {
  5632. // Sets width of child cell
  5633. var rows = model.getChildCells(table, true);
  5634. for (var i = 0; i < rows.length; i++)
  5635. {
  5636. row = rows[i];
  5637. cells = model.getChildCells(row, true);
  5638. var cell = cells[index];
  5639. var geo = this.getCellGeometry(cell);
  5640. if (geo != null)
  5641. {
  5642. geo = geo.clone();
  5643. geo.width += dx;
  5644. if (geo.alternateBounds != null)
  5645. {
  5646. geo.alternateBounds.width += dx;
  5647. }
  5648. model.setGeometry(cell, geo);
  5649. }
  5650. // Shifts and resizes neighbor column
  5651. if (index < cells.length - 1)
  5652. {
  5653. cell = cells[index + 1];
  5654. var geo = this.getCellGeometry(cell);
  5655. if (geo != null)
  5656. {
  5657. geo = geo.clone();
  5658. geo.x += dx;
  5659. if (!extend)
  5660. {
  5661. geo.width -= dx;
  5662. if (geo.alternateBounds != null)
  5663. {
  5664. geo.alternateBounds.width -= dx;
  5665. }
  5666. }
  5667. model.setGeometry(cell, geo);
  5668. }
  5669. }
  5670. }
  5671. if (lastColumn || extend)
  5672. {
  5673. // Updates width of table
  5674. var tgeo = this.getCellGeometry(table);
  5675. if (tgeo != null)
  5676. {
  5677. tgeo = tgeo.clone();
  5678. tgeo.width += dx;
  5679. model.setGeometry(table, tgeo);
  5680. }
  5681. }
  5682. if (this.layoutManager != null)
  5683. {
  5684. this.layoutManager.executeLayout(table);
  5685. }
  5686. }
  5687. finally
  5688. {
  5689. model.endUpdate();
  5690. }
  5691. };
  5692. /**
  5693. * Special Layout for tables.
  5694. */
  5695. function TableLayout(graph)
  5696. {
  5697. mxGraphLayout.call(this, graph);
  5698. };
  5699. /**
  5700. * Extends mxGraphLayout.
  5701. */
  5702. TableLayout.prototype = new mxStackLayout();
  5703. TableLayout.prototype.constructor = TableLayout;
  5704. /**
  5705. * Function: isHorizontal
  5706. *
  5707. * Overrides stack layout to handle row reorder.
  5708. */
  5709. TableLayout.prototype.isHorizontal = function()
  5710. {
  5711. return false;
  5712. };
  5713. /**
  5714. * Function: isVertexIgnored
  5715. *
  5716. * Overrides to allow for table rows and cells.
  5717. */
  5718. TableLayout.prototype.isVertexIgnored = function(vertex)
  5719. {
  5720. return !this.graph.getModel().isVertex(vertex) ||
  5721. !this.graph.isCellVisible(vertex);
  5722. };
  5723. /**
  5724. * Function: getSize
  5725. *
  5726. * Returns the total vertical or horizontal size of the given cells.
  5727. */
  5728. TableLayout.prototype.getSize = function(cells, horizontal)
  5729. {
  5730. var total = 0;
  5731. for (var i = 0; i < cells.length; i++)
  5732. {
  5733. if (!this.isVertexIgnored(cells[i]))
  5734. {
  5735. var geo = this.graph.getCellGeometry(cells[i]);
  5736. if (geo != null)
  5737. {
  5738. total += (horizontal) ? geo.width : geo.height;
  5739. }
  5740. }
  5741. }
  5742. return total;
  5743. };
  5744. /**
  5745. * Function: getRowLayout
  5746. *
  5747. * Returns the column positions for the given row and table width.
  5748. */
  5749. TableLayout.prototype.getRowLayout = function(row, width)
  5750. {
  5751. var cells = this.graph.model.getChildCells(row, true);
  5752. var off = this.graph.getActualStartSize(row, true);
  5753. var sw = this.getSize(cells, true);
  5754. var rw = width - off.x - off.width;
  5755. var result = [];
  5756. var x = off.x;
  5757. for (var i = 0; i < cells.length; i++)
  5758. {
  5759. var geo = this.graph.getCellGeometry(cells[i]);
  5760. if (geo != null)
  5761. {
  5762. x += (geo.alternateBounds != null ?
  5763. geo.alternateBounds.width :
  5764. geo.width) * rw / sw;
  5765. result.push(Math.round(x));
  5766. }
  5767. }
  5768. return result;
  5769. };
  5770. /**
  5771. * Function: layoutRow
  5772. *
  5773. * Places the cells at the given positions in the given row.
  5774. */
  5775. TableLayout.prototype.layoutRow = function(row, positions, height, tw)
  5776. {
  5777. var model = this.graph.getModel();
  5778. var cells = model.getChildCells(row, true);
  5779. var off = this.graph.getActualStartSize(row, true);
  5780. var x = off.x;
  5781. var sw = 0;
  5782. if (positions != null)
  5783. {
  5784. positions = positions.slice();
  5785. positions.splice(0, 0, off.x);
  5786. }
  5787. for (var i = 0; i < cells.length; i++)
  5788. {
  5789. var geo = this.graph.getCellGeometry(cells[i]);
  5790. if (geo != null)
  5791. {
  5792. geo = geo.clone();
  5793. geo.y = off.y;
  5794. geo.height = height - off.y - off.height;
  5795. if (positions != null)
  5796. {
  5797. geo.x = positions[i];
  5798. geo.width = positions[i + 1] - geo.x;
  5799. // Fills with last geo if not enough cells
  5800. if (i == cells.length - 1 && i < positions.length - 2)
  5801. {
  5802. geo.width = tw - geo.x - off.x - off.width;
  5803. }
  5804. }
  5805. else
  5806. {
  5807. geo.x = x;
  5808. x += geo.width;
  5809. if (i == cells.length - 1)
  5810. {
  5811. geo.width = tw - off.x - off.width - sw;
  5812. }
  5813. else
  5814. {
  5815. sw += geo.width;
  5816. }
  5817. }
  5818. geo.alternateBounds = new mxRectangle(0, 0, geo.width, geo.height);
  5819. model.setGeometry(cells[i], geo);
  5820. }
  5821. }
  5822. return sw;
  5823. };
  5824. /**
  5825. * Function: execute
  5826. *
  5827. * Implements <mxGraphLayout.execute>.
  5828. */
  5829. TableLayout.prototype.execute = function(parent)
  5830. {
  5831. if (parent != null)
  5832. {
  5833. var offset = this.graph.getActualStartSize(parent, true);
  5834. var table = this.graph.getCellGeometry(parent);
  5835. var style = this.graph.getCellStyle(parent);
  5836. var resizeLastRow = mxUtils.getValue(style,
  5837. 'resizeLastRow', '0') == '1';
  5838. var resizeLast = mxUtils.getValue(style,
  5839. 'resizeLast', '0') == '1';
  5840. var fixedRows = mxUtils.getValue(style,
  5841. 'fixedRows', '0') == '1';
  5842. var model = this.graph.getModel();
  5843. var sw = 0;
  5844. model.beginUpdate();
  5845. try
  5846. {
  5847. var th = table.height - offset.y - offset.height;
  5848. var tw = table.width - offset.x - offset.width;
  5849. var rows = model.getChildCells(parent, true);
  5850. // Updates row visibilities
  5851. for (var i = 0; i < rows.length; i++)
  5852. {
  5853. model.setVisible(rows[i], true);
  5854. }
  5855. var sh = this.getSize(rows, false);
  5856. if (th > 0 && tw > 0 && rows.length > 0 && sh > 0)
  5857. {
  5858. if (resizeLastRow)
  5859. {
  5860. var row = this.graph.getCellGeometry(rows[rows.length - 1]);
  5861. if (row != null)
  5862. {
  5863. row = row.clone();
  5864. row.height = th - sh + row.height;
  5865. model.setGeometry(rows[rows.length - 1], row);
  5866. }
  5867. }
  5868. var pos = (resizeLast) ? null : this.getRowLayout(rows[0], tw);
  5869. var lastCells = [];
  5870. var y = offset.y;
  5871. // Updates row geometries
  5872. for (var i = 0; i < rows.length; i++)
  5873. {
  5874. var row = this.graph.getCellGeometry(rows[i]);
  5875. if (row != null)
  5876. {
  5877. row = row.clone();
  5878. row.x = offset.x;
  5879. row.width = tw;
  5880. row.y = Math.round(y);
  5881. if (resizeLastRow || fixedRows)
  5882. {
  5883. y += row.height;
  5884. }
  5885. else
  5886. {
  5887. y += (row.height / sh) * th;
  5888. }
  5889. row.height = Math.round(y) - row.y;
  5890. model.setGeometry(rows[i], row);
  5891. }
  5892. // Updates cell geometries
  5893. sw = Math.max(sw, this.layoutRow(rows[i], pos, row.height, tw, lastCells));
  5894. }
  5895. if (fixedRows && th < sh)
  5896. {
  5897. table = table.clone();
  5898. table.height = y + offset.height;
  5899. model.setGeometry(parent, table);
  5900. }
  5901. if (resizeLast && tw < sw + Graph.minTableColumnWidth)
  5902. {
  5903. table = table.clone();
  5904. table.width = sw + offset.width + offset.x + Graph.minTableColumnWidth;
  5905. model.setGeometry(parent, table);
  5906. }
  5907. // All geometries cloned at this point so can change in-place below
  5908. this.graph.visitTableCells(parent, mxUtils.bind(this, function(iter)
  5909. {
  5910. model.setVisible(iter.cell, iter.actual.cell == iter.cell);
  5911. if (iter.actual.cell != iter.cell)
  5912. {
  5913. if (iter.actual.row == iter.row)
  5914. {
  5915. var g = (iter.geo.alternateBounds != null) ?
  5916. iter.geo.alternateBounds : iter.geo;
  5917. iter.actual.geo.width += g.width;
  5918. }
  5919. if (iter.actual.col == iter.col)
  5920. {
  5921. var g = (iter.geo.alternateBounds != null) ?
  5922. iter.geo.alternateBounds : iter.geo;
  5923. iter.actual.geo.height += g.height;
  5924. }
  5925. }
  5926. }));
  5927. }
  5928. else
  5929. {
  5930. // Updates row visibilities
  5931. for (var i = 0; i < rows.length; i++)
  5932. {
  5933. model.setVisible(rows[i], false);
  5934. }
  5935. }
  5936. }
  5937. finally
  5938. {
  5939. model.endUpdate();
  5940. }
  5941. }
  5942. };
  5943. (function()
  5944. {
  5945. /**
  5946. * Reset the list of processed edges.
  5947. */
  5948. var mxGraphViewResetValidationState = mxGraphView.prototype.resetValidationState;
  5949. mxGraphView.prototype.resetValidationState = function()
  5950. {
  5951. mxGraphViewResetValidationState.apply(this, arguments);
  5952. this.validEdges = [];
  5953. };
  5954. /**
  5955. * Updates jumps for valid edges and repaints if needed.
  5956. */
  5957. var mxGraphViewValidateCellState = mxGraphView.prototype.validateCellState;
  5958. mxGraphView.prototype.validateCellState = function(cell, recurse)
  5959. {
  5960. recurse = (recurse != null) ? recurse : true;
  5961. var state = this.getState(cell);
  5962. // Forces repaint if jumps change on a valid edge
  5963. if (state != null && recurse && this.graph.model.isEdge(state.cell) &&
  5964. state.style != null && state.style[mxConstants.STYLE_CURVED] != 1 &&
  5965. !state.invalid && this.updateLineJumps(state))
  5966. {
  5967. this.graph.cellRenderer.redraw(state, false, this.isRendering());
  5968. }
  5969. state = mxGraphViewValidateCellState.apply(this, arguments);
  5970. // Adds to the list of edges that may intersect with later edges
  5971. if (state != null && recurse && this.graph.model.isEdge(state.cell) &&
  5972. state.style != null && state.style[mxConstants.STYLE_CURVED] != 1)
  5973. {
  5974. // LATER: Reuse jumps for valid edges
  5975. this.validEdges.push(state);
  5976. }
  5977. return state;
  5978. };
  5979. /**
  5980. * Overrides paint to add flowAnimation style.
  5981. */
  5982. var mxShapePaint = mxShape.prototype.paint;
  5983. mxShape.prototype.paint = function()
  5984. {
  5985. mxShapePaint.apply(this, arguments);
  5986. if (this.state != null && this.node != null &&
  5987. this.state.view.graph.enableFlowAnimation &&
  5988. this.state.view.graph.model.isEdge(this.state.cell) &&
  5989. mxUtils.getValue(this.state.style, 'flowAnimation', '0') == '1')
  5990. {
  5991. var paths = this.node.getElementsByTagName('path');
  5992. if (paths.length > 1)
  5993. {
  5994. if (mxUtils.getValue(this.state.style, mxConstants.STYLE_DASHED, '0') != '1')
  5995. {
  5996. paths[1].setAttribute('stroke-dasharray', (this.state.view.scale * 8));
  5997. }
  5998. var anim = this.state.view.graph.getFlowAnimationStyle();
  5999. if (anim != null)
  6000. {
  6001. paths[1].setAttribute('class', anim.getAttribute('id'));
  6002. }
  6003. }
  6004. }
  6005. };
  6006. /**
  6007. * Forces repaint if routed points have changed.
  6008. */
  6009. var mxCellRendererIsShapeInvalid = mxCellRenderer.prototype.isShapeInvalid;
  6010. mxCellRenderer.prototype.isShapeInvalid = function(state, shape)
  6011. {
  6012. return mxCellRendererIsShapeInvalid.apply(this, arguments) ||
  6013. (state.routedPoints != null && shape.routedPoints != null &&
  6014. !mxUtils.equalPoints(shape.routedPoints, state.routedPoints))
  6015. };
  6016. /**
  6017. * Updates jumps for invalid edges.
  6018. */
  6019. var mxGraphViewUpdateCellState = mxGraphView.prototype.updateCellState;
  6020. mxGraphView.prototype.updateCellState = function(state)
  6021. {
  6022. mxGraphViewUpdateCellState.apply(this, arguments);
  6023. // Updates jumps on invalid edge before repaint
  6024. if (this.graph.model.isEdge(state.cell) &&
  6025. state.style[mxConstants.STYLE_CURVED] != 1)
  6026. {
  6027. this.updateLineJumps(state);
  6028. }
  6029. };
  6030. /**
  6031. * Updates the jumps between given state and processed edges.
  6032. */
  6033. mxGraphView.prototype.updateLineJumps = function(state)
  6034. {
  6035. var pts = state.absolutePoints;
  6036. if (Graph.lineJumpsEnabled)
  6037. {
  6038. var changed = state.routedPoints != null;
  6039. var actual = null;
  6040. if (pts != null && this.validEdges != null &&
  6041. mxUtils.getValue(state.style, 'jumpStyle', 'none') !== 'none')
  6042. {
  6043. var thresh = 0.5 * this.scale;
  6044. changed = false;
  6045. actual = [];
  6046. // Type 0 means normal waypoint, 1 means jump
  6047. function addPoint(type, x, y)
  6048. {
  6049. var rpt = new mxPoint(x, y);
  6050. rpt.type = type;
  6051. actual.push(rpt);
  6052. var curr = (state.routedPoints != null) ? state.routedPoints[actual.length - 1] : null;
  6053. return curr == null || curr.type != type || curr.x != x || curr.y != y;
  6054. };
  6055. for (var i = 0; i < pts.length - 1; i++)
  6056. {
  6057. var p1 = pts[i + 1];
  6058. var p0 = pts[i];
  6059. var list = [];
  6060. // Ignores waypoints on straight segments
  6061. var pn = pts[i + 2];
  6062. while (i < pts.length - 2 &&
  6063. mxUtils.ptSegDistSq(p0.x, p0.y, pn.x, pn.y,
  6064. p1.x, p1.y) < 1 * this.scale * this.scale)
  6065. {
  6066. p1 = pn;
  6067. i++;
  6068. pn = pts[i + 2];
  6069. }
  6070. changed = addPoint(0, p0.x, p0.y) || changed;
  6071. // Processes all previous edges
  6072. for (var e = 0; e < this.validEdges.length; e++)
  6073. {
  6074. var state2 = this.validEdges[e];
  6075. var pts2 = state2.absolutePoints;
  6076. if (pts2 != null && mxUtils.intersects(state, state2) && state2.style['noJump'] != '1')
  6077. {
  6078. // Compares each segment of the edge with the current segment
  6079. for (var j = 0; j < pts2.length - 1; j++)
  6080. {
  6081. var p3 = pts2[j + 1];
  6082. var p2 = pts2[j];
  6083. // Ignores waypoints on straight segments
  6084. pn = pts2[j + 2];
  6085. while (j < pts2.length - 2 &&
  6086. mxUtils.ptSegDistSq(p2.x, p2.y, pn.x, pn.y,
  6087. p3.x, p3.y) < 1 * this.scale * this.scale)
  6088. {
  6089. p3 = pn;
  6090. j++;
  6091. pn = pts2[j + 2];
  6092. }
  6093. var pt = mxUtils.intersection(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
  6094. // Handles intersection between two segments
  6095. if (pt != null && (Math.abs(pt.x - p0.x) > thresh ||
  6096. Math.abs(pt.y - p0.y) > thresh) &&
  6097. (Math.abs(pt.x - p1.x) > thresh ||
  6098. Math.abs(pt.y - p1.y) > thresh) &&
  6099. (Math.abs(pt.x - p2.x) > thresh ||
  6100. Math.abs(pt.y - p2.y) > thresh) &&
  6101. (Math.abs(pt.x - p3.x) > thresh ||
  6102. Math.abs(pt.y - p3.y) > thresh))
  6103. {
  6104. var dx = pt.x - p0.x;
  6105. var dy = pt.y - p0.y;
  6106. var temp = {distSq: dx * dx + dy * dy, x: pt.x, y: pt.y};
  6107. // Intersections must be ordered by distance from start of segment
  6108. for (var t = 0; t < list.length; t++)
  6109. {
  6110. if (list[t].distSq > temp.distSq)
  6111. {
  6112. list.splice(t, 0, temp);
  6113. temp = null;
  6114. break;
  6115. }
  6116. }
  6117. // Ignores multiple intersections at segment joint
  6118. if (temp != null && (list.length == 0 ||
  6119. list[list.length - 1].x !== temp.x ||
  6120. list[list.length - 1].y !== temp.y))
  6121. {
  6122. list.push(temp);
  6123. }
  6124. }
  6125. }
  6126. }
  6127. }
  6128. // Adds ordered intersections to routed points
  6129. for (var j = 0; j < list.length; j++)
  6130. {
  6131. changed = addPoint(1, list[j].x, list[j].y) || changed;
  6132. }
  6133. }
  6134. var pt = pts[pts.length - 1];
  6135. changed = addPoint(0, pt.x, pt.y) || changed;
  6136. }
  6137. state.routedPoints = actual;
  6138. return changed;
  6139. }
  6140. else
  6141. {
  6142. return false;
  6143. }
  6144. };
  6145. /**
  6146. * Overrides painting the actual shape for taking into account jump style.
  6147. */
  6148. var mxConnectorPaintLine = mxConnector.prototype.paintLine;
  6149. mxConnector.prototype.paintLine = function (c, absPts, rounded)
  6150. {
  6151. // Required for checking dirty state
  6152. this.routedPoints = (this.state != null) ? this.state.routedPoints : null;
  6153. if (this.outline || this.state == null || this.style == null ||
  6154. this.state.routedPoints == null || this.state.routedPoints.length == 0)
  6155. {
  6156. mxConnectorPaintLine.apply(this, arguments);
  6157. }
  6158. else
  6159. {
  6160. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  6161. mxConstants.LINE_ARCSIZE) / 2;
  6162. var size = (parseInt(mxUtils.getValue(this.style, 'jumpSize',
  6163. Graph.defaultJumpSize)) - 2) / 2 + this.strokewidth;
  6164. var style = mxUtils.getValue(this.style, 'jumpStyle', 'none');
  6165. var moveTo = true;
  6166. var last = null;
  6167. var len = null;
  6168. var pts = [];
  6169. var n = null;
  6170. c.begin();
  6171. for (var i = 0; i < this.state.routedPoints.length; i++)
  6172. {
  6173. var rpt = this.state.routedPoints[i];
  6174. var pt = new mxPoint(rpt.x / this.scale, rpt.y / this.scale);
  6175. // Takes first and last point from passed-in array
  6176. if (i == 0)
  6177. {
  6178. pt = absPts[0];
  6179. }
  6180. else if (i == this.state.routedPoints.length - 1)
  6181. {
  6182. pt = absPts[absPts.length - 1];
  6183. }
  6184. var done = false;
  6185. // Type 1 is an intersection
  6186. if (last != null && rpt.type == 1)
  6187. {
  6188. // Checks if next/previous points are too close
  6189. var next = this.state.routedPoints[i + 1];
  6190. var dx = next.x / this.scale - pt.x;
  6191. var dy = next.y / this.scale - pt.y;
  6192. var dist = dx * dx + dy * dy;
  6193. if (n == null)
  6194. {
  6195. n = new mxPoint(pt.x - last.x, pt.y - last.y);
  6196. len = Math.sqrt(n.x * n.x + n.y * n.y);
  6197. if (len > 0)
  6198. {
  6199. n.x = n.x * size / len;
  6200. n.y = n.y * size / len;
  6201. }
  6202. else
  6203. {
  6204. n = null;
  6205. }
  6206. }
  6207. if (dist > size * size && len > 0)
  6208. {
  6209. var dx = last.x - pt.x;
  6210. var dy = last.y - pt.y;
  6211. var dist = dx * dx + dy * dy;
  6212. if (dist > size * size)
  6213. {
  6214. var p0 = new mxPoint(pt.x - n.x, pt.y - n.y);
  6215. var p1 = new mxPoint(pt.x + n.x, pt.y + n.y);
  6216. pts.push(p0);
  6217. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  6218. var f = (Math.round(n.x) < 0 || (Math.round(n.x) == 0
  6219. && Math.round(n.y) <= 0)) ? 1 : -1;
  6220. moveTo = false;
  6221. if (style == 'sharp')
  6222. {
  6223. c.lineTo(p0.x - n.y * f, p0.y + n.x * f);
  6224. c.lineTo(p1.x - n.y * f, p1.y + n.x * f);
  6225. c.lineTo(p1.x, p1.y);
  6226. }
  6227. else if (style == 'line')
  6228. {
  6229. c.moveTo(p0.x + n.y * f, p0.y - n.x * f);
  6230. c.lineTo(p0.x - n.y * f, p0.y + n.x * f);
  6231. c.moveTo(p1.x - n.y * f, p1.y + n.x * f);
  6232. c.lineTo(p1.x + n.y * f, p1.y - n.x * f);
  6233. c.moveTo(p1.x, p1.y);
  6234. }
  6235. else if (style == 'arc')
  6236. {
  6237. f *= 1.3;
  6238. c.curveTo(p0.x - n.y * f, p0.y + n.x * f,
  6239. p1.x - n.y * f, p1.y + n.x * f,
  6240. p1.x, p1.y);
  6241. }
  6242. else
  6243. {
  6244. c.moveTo(p1.x, p1.y);
  6245. moveTo = true;
  6246. }
  6247. pts = [p1];
  6248. done = true;
  6249. }
  6250. }
  6251. }
  6252. else
  6253. {
  6254. n = null;
  6255. }
  6256. if (!done)
  6257. {
  6258. pts.push(pt);
  6259. last = pt;
  6260. }
  6261. }
  6262. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  6263. c.stroke();
  6264. }
  6265. };
  6266. /**
  6267. * Adds support for centerPerimeter which is a special case of a fixed point perimeter.
  6268. */
  6269. var mxGraphViewGetFixedTerminalPoint = mxGraphView.prototype.getFixedTerminalPoint;
  6270. mxGraphView.prototype.getFixedTerminalPoint = function(edge, terminal, source, constraint)
  6271. {
  6272. if (terminal != null && terminal.style[mxConstants.STYLE_PERIMETER] == 'centerPerimeter')
  6273. {
  6274. return new mxPoint(terminal.getCenterX(), terminal.getCenterY());
  6275. }
  6276. else
  6277. {
  6278. return mxGraphViewGetFixedTerminalPoint.apply(this, arguments);
  6279. }
  6280. };
  6281. /**
  6282. * Adds support for snapToPoint style.
  6283. */
  6284. var mxGraphViewUpdateFloatingTerminalPoint = mxGraphView.prototype.updateFloatingTerminalPoint;
  6285. mxGraphView.prototype.updateFloatingTerminalPoint = function(edge, start, end, source)
  6286. {
  6287. if (start != null && edge != null &&
  6288. (start.style['snapToPoint'] == '1' ||
  6289. edge.style['snapToPoint'] == '1'))
  6290. {
  6291. start = this.getTerminalPort(edge, start, source);
  6292. var next = this.getNextPoint(edge, end, source);
  6293. var orth = this.graph.isOrthogonal(edge);
  6294. var alpha = mxUtils.toRadians(Number(start.style[mxConstants.STYLE_ROTATION] || '0'));
  6295. var center = new mxPoint(start.getCenterX(), start.getCenterY());
  6296. if (alpha != 0)
  6297. {
  6298. var cos = Math.cos(-alpha);
  6299. var sin = Math.sin(-alpha);
  6300. next = mxUtils.getRotatedPoint(next, cos, sin, center);
  6301. }
  6302. var border = parseFloat(edge.style[mxConstants.STYLE_PERIMETER_SPACING] || 0);
  6303. border += parseFloat(edge.style[(source) ?
  6304. mxConstants.STYLE_SOURCE_PERIMETER_SPACING :
  6305. mxConstants.STYLE_TARGET_PERIMETER_SPACING] || 0);
  6306. var pt = this.getPerimeterPoint(start, next, alpha == 0 && orth, border);
  6307. if (alpha != 0)
  6308. {
  6309. var cos = Math.cos(alpha);
  6310. var sin = Math.sin(alpha);
  6311. pt = mxUtils.getRotatedPoint(pt, cos, sin, center);
  6312. }
  6313. edge.setAbsoluteTerminalPoint(this.snapToAnchorPoint(edge, start, end, source, pt), source);
  6314. }
  6315. else
  6316. {
  6317. mxGraphViewUpdateFloatingTerminalPoint.apply(this, arguments);
  6318. }
  6319. };
  6320. mxGraphView.prototype.snapToAnchorPoint = function(edge, start, end, source, pt)
  6321. {
  6322. if (start != null && edge != null)
  6323. {
  6324. var constraints = this.graph.getAllConnectionConstraints(start)
  6325. var nearest = null;
  6326. var dist = null;
  6327. if (constraints != null)
  6328. {
  6329. for (var i = 0; i < constraints.length; i++)
  6330. {
  6331. var cp = this.graph.getConnectionPoint(start, constraints[i]);
  6332. if (cp != null)
  6333. {
  6334. var tmp = (cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
  6335. if (dist == null || tmp < dist)
  6336. {
  6337. nearest = cp;
  6338. dist = tmp;
  6339. }
  6340. }
  6341. }
  6342. }
  6343. if (nearest != null)
  6344. {
  6345. pt = nearest;
  6346. }
  6347. }
  6348. return pt;
  6349. };
  6350. /**
  6351. * Adds support for placeholders in text elements of shapes.
  6352. */
  6353. var mxStencilEvaluateTextAttribute = mxStencil.prototype.evaluateTextAttribute;
  6354. mxStencil.prototype.evaluateTextAttribute = function(node, attribute, shape)
  6355. {
  6356. var result = mxStencilEvaluateTextAttribute.apply(this, arguments);
  6357. var placeholders = node.getAttribute('placeholders');
  6358. if (placeholders == '1' && shape.state != null)
  6359. {
  6360. result = shape.state.view.graph.replacePlaceholders(shape.state.cell, result);
  6361. }
  6362. return result;
  6363. };
  6364. /**
  6365. * Adds custom stencils defined via shape=stencil(value) style. The value is a base64 encoded, compressed and
  6366. * URL encoded XML definition of the shape according to the stencil definition language of mxGraph.
  6367. *
  6368. * Needs to be in this file to make sure its part of the embed client code. Also the check for ZLib is
  6369. * different than for the Editor code.
  6370. */
  6371. var mxCellRendererCreateShape = mxCellRenderer.prototype.createShape;
  6372. mxCellRenderer.prototype.createShape = function(state)
  6373. {
  6374. if (state.style != null && typeof(pako) !== 'undefined')
  6375. {
  6376. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  6377. // Extracts and decodes stencil XML if shape has the form shape=stencil(value)
  6378. if (shape != null && typeof shape === 'string' && shape.substring(0, 8) == 'stencil(')
  6379. {
  6380. try
  6381. {
  6382. var stencil = shape.substring(8, shape.length - 1);
  6383. var doc = mxUtils.parseXml(Graph.decompress(stencil));
  6384. return new mxShape(new mxStencil(doc.documentElement));
  6385. }
  6386. catch (e)
  6387. {
  6388. if (window.console != null)
  6389. {
  6390. console.log('Error in shape: ' + e);
  6391. }
  6392. }
  6393. }
  6394. }
  6395. return mxCellRendererCreateShape.apply(this, arguments);
  6396. };
  6397. })();
  6398. /**
  6399. * Overrides stencil registry for dynamic loading of stencils.
  6400. */
  6401. /**
  6402. * Maps from library names to an array of Javascript filenames,
  6403. * which are synchronously loaded. Currently only stencil files
  6404. * (.xml) and JS files (.js) are supported.
  6405. * IMPORTANT: For embedded diagrams to work entries must also
  6406. * be added in EmbedServlet.java.
  6407. */
  6408. mxStencilRegistry.libraries = {};
  6409. /**
  6410. * Global switch to disable dynamic loading.
  6411. */
  6412. mxStencilRegistry.dynamicLoading = true;
  6413. /**
  6414. * Global switch to disable eval for JS (preload all JS instead).
  6415. */
  6416. mxStencilRegistry.allowEval = true;
  6417. /**
  6418. * Stores all package names that have been dynamically loaded.
  6419. * Each package is only loaded once.
  6420. */
  6421. mxStencilRegistry.packages = [];
  6422. /**
  6423. * Stores all package names that have been dynamically loaded.
  6424. * Each package is only loaded once.
  6425. */
  6426. mxStencilRegistry.filesLoaded = {};
  6427. // Extends the default stencil registry to add dynamic loading
  6428. mxStencilRegistry.getStencil = function(name)
  6429. {
  6430. var result = mxStencilRegistry.stencils[name];
  6431. if (result == null && mxCellRenderer.defaultShapes[name] == null && mxStencilRegistry.dynamicLoading)
  6432. {
  6433. var basename = mxStencilRegistry.getBasenameForStencil(name);
  6434. // Loads stencil files and tries again
  6435. if (basename != null)
  6436. {
  6437. var libs = mxStencilRegistry.libraries[basename];
  6438. if (libs != null)
  6439. {
  6440. if (mxStencilRegistry.packages[basename] == null)
  6441. {
  6442. for (var i = 0; i < libs.length; i++)
  6443. {
  6444. var fname = libs[i];
  6445. if (!mxStencilRegistry.filesLoaded[fname])
  6446. {
  6447. mxStencilRegistry.filesLoaded[fname] = true;
  6448. if (fname.toLowerCase().substring(fname.length - 4, fname.length) == '.xml')
  6449. {
  6450. mxStencilRegistry.loadStencilSet(fname, null);
  6451. }
  6452. else if (fname.toLowerCase().substring(fname.length - 3, fname.length) == '.js')
  6453. {
  6454. try
  6455. {
  6456. if (mxStencilRegistry.allowEval)
  6457. {
  6458. var req = mxUtils.load(fname);
  6459. if (req != null && req.getStatus() >= 200 && req.getStatus() <= 299)
  6460. {
  6461. eval.call(window, req.getText());
  6462. }
  6463. }
  6464. }
  6465. catch (e)
  6466. {
  6467. if (window.console != null)
  6468. {
  6469. console.log('error in getStencil:', name, basename, libs, fname, e);
  6470. }
  6471. }
  6472. }
  6473. else
  6474. {
  6475. // FIXME: This does not yet work as the loading is triggered after
  6476. // the shape was used in the graph, at which point the keys have
  6477. // typically been translated in the calling method.
  6478. //mxResources.add(fname);
  6479. }
  6480. }
  6481. }
  6482. mxStencilRegistry.packages[basename] = 1;
  6483. }
  6484. }
  6485. else
  6486. {
  6487. // Replaces '_-_' with '_'
  6488. basename = basename.replace('_-_', '_');
  6489. mxStencilRegistry.loadStencilSet(STENCIL_PATH + '/' + basename + '.xml', null);
  6490. }
  6491. result = mxStencilRegistry.stencils[name];
  6492. }
  6493. }
  6494. return result;
  6495. };
  6496. // Returns the basename for the given stencil or null if no file must be
  6497. // loaded to render the given stencil.
  6498. mxStencilRegistry.getBasenameForStencil = function(name)
  6499. {
  6500. var tmp = null;
  6501. if (name != null && typeof name === 'string')
  6502. {
  6503. var parts = name.split('.');
  6504. if (parts.length > 0 && parts[0] == 'mxgraph')
  6505. {
  6506. tmp = parts[1];
  6507. for (var i = 2; i < parts.length - 1; i++)
  6508. {
  6509. tmp += '/' + parts[i];
  6510. }
  6511. }
  6512. }
  6513. return tmp;
  6514. };
  6515. // Loads the given stencil set
  6516. mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force, async)
  6517. {
  6518. force = (force != null) ? force : false;
  6519. // Uses additional cache for detecting previous load attempts
  6520. var xmlDoc = mxStencilRegistry.packages[stencilFile];
  6521. if (force || xmlDoc == null)
  6522. {
  6523. var install = false;
  6524. if (xmlDoc == null)
  6525. {
  6526. try
  6527. {
  6528. if (async)
  6529. {
  6530. mxStencilRegistry.loadStencil(stencilFile, mxUtils.bind(this, function(xmlDoc2)
  6531. {
  6532. if (xmlDoc2 != null && xmlDoc2.documentElement != null)
  6533. {
  6534. mxStencilRegistry.packages[stencilFile] = xmlDoc2;
  6535. install = true;
  6536. mxStencilRegistry.parseStencilSet(xmlDoc2.documentElement, postStencilLoad, install);
  6537. }
  6538. }));
  6539. return;
  6540. }
  6541. else
  6542. {
  6543. xmlDoc = mxStencilRegistry.loadStencil(stencilFile);
  6544. mxStencilRegistry.packages[stencilFile] = xmlDoc;
  6545. install = true;
  6546. }
  6547. }
  6548. catch (e)
  6549. {
  6550. if (window.console != null)
  6551. {
  6552. console.log('error in loadStencilSet:', stencilFile, e);
  6553. }
  6554. }
  6555. }
  6556. if (xmlDoc != null && xmlDoc.documentElement != null)
  6557. {
  6558. mxStencilRegistry.parseStencilSet(xmlDoc.documentElement, postStencilLoad, install);
  6559. }
  6560. }
  6561. };
  6562. // Loads the given stencil XML file.
  6563. mxStencilRegistry.loadStencil = function(filename, fn)
  6564. {
  6565. if (fn != null)
  6566. {
  6567. var req = mxUtils.get(filename, mxUtils.bind(this, function(req)
  6568. {
  6569. fn((req.getStatus() >= 200 && req.getStatus() <= 299) ? req.getXml() : null);
  6570. }));
  6571. }
  6572. else
  6573. {
  6574. return mxUtils.load(filename).getXml();
  6575. }
  6576. };
  6577. // Takes array of strings
  6578. mxStencilRegistry.parseStencilSets = function(stencils)
  6579. {
  6580. for (var i = 0; i < stencils.length; i++)
  6581. {
  6582. mxStencilRegistry.parseStencilSet(mxUtils.parseXml(stencils[i]).documentElement);
  6583. }
  6584. };
  6585. // Parses the given stencil set
  6586. mxStencilRegistry.parseStencilSet = function(root, postStencilLoad, install)
  6587. {
  6588. if (root.nodeName == 'stencils')
  6589. {
  6590. var shapes = root.firstChild;
  6591. while (shapes != null)
  6592. {
  6593. if (shapes.nodeName == 'shapes')
  6594. {
  6595. mxStencilRegistry.parseStencilSet(shapes, postStencilLoad, install);
  6596. }
  6597. shapes = shapes.nextSibling;
  6598. }
  6599. }
  6600. else
  6601. {
  6602. install = (install != null) ? install : true;
  6603. var shape = root.firstChild;
  6604. var packageName = '';
  6605. var name = root.getAttribute('name');
  6606. if (name != null)
  6607. {
  6608. packageName = name + '.';
  6609. }
  6610. while (shape != null)
  6611. {
  6612. if (shape.nodeType == mxConstants.NODETYPE_ELEMENT)
  6613. {
  6614. name = shape.getAttribute('name');
  6615. if (name != null)
  6616. {
  6617. packageName = packageName.toLowerCase();
  6618. var stencilName = name.replace(/ /g,"_");
  6619. if (install)
  6620. {
  6621. mxStencilRegistry.addStencil(packageName + stencilName.toLowerCase(), new mxStencil(shape));
  6622. }
  6623. if (postStencilLoad != null)
  6624. {
  6625. var w = shape.getAttribute('w');
  6626. var h = shape.getAttribute('h');
  6627. w = (w == null) ? 80 : parseInt(w, 10);
  6628. h = (h == null) ? 80 : parseInt(h, 10);
  6629. postStencilLoad(packageName, stencilName, name, w, h);
  6630. }
  6631. }
  6632. }
  6633. shape = shape.nextSibling;
  6634. }
  6635. }
  6636. };
  6637. /**
  6638. * These overrides are only added if mxVertexHandler is defined (ie. not in embedded graph)
  6639. */
  6640. if (typeof mxVertexHandler !== 'undefined')
  6641. {
  6642. (function()
  6643. {
  6644. // Sets colors for handles
  6645. mxConstants.HANDLE_FILLCOLOR = '#29b6f2';
  6646. mxConstants.HANDLE_STROKECOLOR = '#0088cf';
  6647. mxConstants.VERTEX_SELECTION_COLOR = '#00a8ff';
  6648. mxConstants.OUTLINE_COLOR = '#00a8ff';
  6649. mxConstants.OUTLINE_HANDLE_FILLCOLOR = '#99ccff';
  6650. mxConstants.OUTLINE_HANDLE_STROKECOLOR = '#00a8ff';
  6651. mxConstants.CONNECT_HANDLE_FILLCOLOR = '#cee7ff';
  6652. mxConstants.EDGE_SELECTION_COLOR = '#00a8ff';
  6653. mxConstants.DEFAULT_VALID_COLOR = '#00a8ff';
  6654. mxConstants.LABEL_HANDLE_FILLCOLOR = '#cee7ff';
  6655. mxConstants.GUIDE_COLOR = '#0088cf';
  6656. mxConstants.HIGHLIGHT_OPACITY = 30;
  6657. mxConstants.HIGHLIGHT_SIZE = 5;
  6658. // Enables snapping to off-grid terminals for edge waypoints
  6659. mxEdgeHandler.prototype.snapToTerminals = true;
  6660. // Enables guides
  6661. mxGraphHandler.prototype.guidesEnabled = true;
  6662. // Removes parents where all child cells are moved out
  6663. mxGraphHandler.prototype.removeEmptyParents = true;
  6664. // Enables fading of rubberband
  6665. mxRubberband.prototype.fadeOut = true;
  6666. // Alt-move disables guides
  6667. mxGuide.prototype.isEnabledForEvent = function(evt)
  6668. {
  6669. return !mxEvent.isAltDown(evt);
  6670. };
  6671. // Ignores all table cells in layouts
  6672. var graphLayoutIsVertexIgnored = mxGraphLayout.prototype.isVertexIgnored;
  6673. mxGraphLayout.prototype.isVertexIgnored = function(vertex)
  6674. {
  6675. return graphLayoutIsVertexIgnored.apply(this, arguments) ||
  6676. this.graph.isTableRow(vertex) || this.graph.isTableCell(vertex);
  6677. };
  6678. // Adds support for ignoreEdge style
  6679. var graphLayoutIsEdgeIgnored = mxGraphLayout.prototype.isEdgeIgnored;
  6680. mxGraphLayout.prototype.isEdgeIgnored = function(edge)
  6681. {
  6682. return graphLayoutIsEdgeIgnored.apply(this, arguments) ||
  6683. this.graph.isEdgeIgnored(edge);
  6684. };
  6685. // Extends connection handler to enable ctrl+drag for cloning source cell
  6686. // since copyOnConnect is now disabled by default
  6687. var mxConnectionHandlerCreateTarget = mxConnectionHandler.prototype.isCreateTarget;
  6688. mxConnectionHandler.prototype.isCreateTarget = function(evt)
  6689. {
  6690. return this.graph.isCloneEvent(evt) != mxConnectionHandlerCreateTarget.apply(this, arguments);
  6691. };
  6692. // Overrides highlight shape for connection points
  6693. mxConstraintHandler.prototype.createHighlightShape = function()
  6694. {
  6695. var hl = new mxEllipse(null, this.highlightColor, this.highlightColor, 0);
  6696. hl.opacity = mxConstants.HIGHLIGHT_OPACITY;
  6697. return hl;
  6698. };
  6699. // Overrides edge preview to use current edge shape and default style
  6700. mxConnectionHandler.prototype.livePreview = true;
  6701. mxConnectionHandler.prototype.cursor = 'crosshair';
  6702. // Uses current edge style for connect preview
  6703. mxConnectionHandler.prototype.createEdgeState = function(me)
  6704. {
  6705. var style = this.graph.createCurrentEdgeStyle();
  6706. var edge = this.graph.createEdge(null, null, null, null, null, style);
  6707. var state = new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  6708. for (var key in this.graph.currentEdgeStyle)
  6709. {
  6710. state.style[key] = this.graph.currentEdgeStyle[key];
  6711. }
  6712. state.style = this.graph.postProcessCellStyle(state.cell, state.style);
  6713. return state;
  6714. };
  6715. // Overrides dashed state with current edge style
  6716. var connectionHandlerCreateShape = mxConnectionHandler.prototype.createShape;
  6717. mxConnectionHandler.prototype.createShape = function()
  6718. {
  6719. var shape = connectionHandlerCreateShape.apply(this, arguments);
  6720. shape.isDashed = this.graph.currentEdgeStyle[mxConstants.STYLE_DASHED] == '1';
  6721. return shape;
  6722. }
  6723. // Overrides live preview to keep current style
  6724. mxConnectionHandler.prototype.updatePreview = function(valid)
  6725. {
  6726. // do not change color of preview
  6727. };
  6728. // Overrides connection handler to ignore edges instead of not allowing connections
  6729. var mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
  6730. mxConnectionHandler.prototype.createMarker = function()
  6731. {
  6732. var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);
  6733. var markerGetCell = marker.getCell;
  6734. marker.getCell = mxUtils.bind(this, function(me)
  6735. {
  6736. var result = markerGetCell.apply(this, arguments);
  6737. this.error = null;
  6738. return result;
  6739. });
  6740. return marker;
  6741. };
  6742. /**
  6743. *
  6744. */
  6745. Graph.prototype.defaultVertexStyle = {};
  6746. /**
  6747. * Contains the default style for edges.
  6748. */
  6749. Graph.prototype.defaultEdgeStyle = {'edgeStyle': 'orthogonalEdgeStyle', 'rounded': '0',
  6750. 'jettySize': 'auto', 'orthogonalLoop': '1'};
  6751. /**
  6752. * Returns the current edge style as a string.
  6753. */
  6754. Graph.prototype.createCurrentEdgeStyle = function()
  6755. {
  6756. var style = 'edgeStyle=' + (this.currentEdgeStyle['edgeStyle'] || 'none') + ';';
  6757. var keys = ['shape', 'curved', 'rounded', 'comic', 'sketch', 'fillWeight', 'hachureGap',
  6758. 'hachureAngle', 'jiggle', 'disableMultiStroke', 'disableMultiStrokeFill', 'fillStyle',
  6759. 'curveFitting', 'simplification', 'comicStyle', 'jumpStyle', 'jumpSize'];
  6760. for (var i = 0; i < keys.length; i++)
  6761. {
  6762. if (this.currentEdgeStyle[keys[i]] != null)
  6763. {
  6764. style += keys[i] + '=' + this.currentEdgeStyle[keys[i]] + ';';
  6765. }
  6766. }
  6767. // Overrides the global default to match the default edge style
  6768. if (this.currentEdgeStyle['orthogonalLoop'] != null)
  6769. {
  6770. style += 'orthogonalLoop=' + this.currentEdgeStyle['orthogonalLoop'] + ';';
  6771. }
  6772. else if (Graph.prototype.defaultEdgeStyle['orthogonalLoop'] != null)
  6773. {
  6774. style += 'orthogonalLoop=' + Graph.prototype.defaultEdgeStyle['orthogonalLoop'] + ';';
  6775. }
  6776. // Overrides the global default to match the default edge style
  6777. if (this.currentEdgeStyle['jettySize'] != null)
  6778. {
  6779. style += 'jettySize=' + this.currentEdgeStyle['jettySize'] + ';';
  6780. }
  6781. else if (Graph.prototype.defaultEdgeStyle['jettySize'] != null)
  6782. {
  6783. style += 'jettySize=' + Graph.prototype.defaultEdgeStyle['jettySize'] + ';';
  6784. }
  6785. // Special logic for custom property of elbowEdgeStyle
  6786. if (this.currentEdgeStyle['edgeStyle'] == 'elbowEdgeStyle' && this.currentEdgeStyle['elbow'] != null)
  6787. {
  6788. style += 'elbow=' + this.currentEdgeStyle['elbow'] + ';';
  6789. }
  6790. if (this.currentEdgeStyle['html'] != null)
  6791. {
  6792. style += 'html=' + this.currentEdgeStyle['html'] + ';';
  6793. }
  6794. else
  6795. {
  6796. style += 'html=1;';
  6797. }
  6798. return style;
  6799. };
  6800. /**
  6801. * Hook for subclassers.
  6802. */
  6803. Graph.prototype.getPagePadding = function()
  6804. {
  6805. return new mxPoint(0, 0);
  6806. };
  6807. /**
  6808. * Loads the stylesheet for this graph.
  6809. */
  6810. Graph.prototype.loadStylesheet = function()
  6811. {
  6812. var node = (this.themes != null) ? this.themes[this.defaultThemeName] :
  6813. (!mxStyleRegistry.dynamicLoading) ? null :
  6814. mxUtils.load(STYLE_PATH + '/default.xml').getDocumentElement();
  6815. if (node != null)
  6816. {
  6817. var dec = new mxCodec(node.ownerDocument);
  6818. dec.decode(node, this.getStylesheet());
  6819. }
  6820. };
  6821. /**
  6822. * Creates lookup from object IDs to cell IDs.
  6823. */
  6824. Graph.prototype.createCellLookup = function(cells, lookup)
  6825. {
  6826. lookup = (lookup != null) ? lookup : new Object();
  6827. for (var i = 0; i < cells.length; i++)
  6828. {
  6829. var cell = cells[i];
  6830. lookup[mxObjectIdentity.get(cell)] = cell.getId();
  6831. var childCount = this.model.getChildCount(cell);
  6832. for (var j = 0; j < childCount; j++)
  6833. {
  6834. this.createCellLookup([this.model.getChildAt(cell, j)], lookup);
  6835. }
  6836. }
  6837. return lookup;
  6838. };
  6839. /**
  6840. * Creates lookup from original to cloned cell IDs where mapping is
  6841. * the mapping used in cloneCells and lookup is a mapping from
  6842. * object IDs to cell IDs.
  6843. */
  6844. Graph.prototype.createCellMapping = function(mapping, lookup, cellMapping)
  6845. {
  6846. cellMapping = (cellMapping != null) ? cellMapping : new Object();
  6847. for (var objectId in mapping)
  6848. {
  6849. var cellId = lookup[objectId];
  6850. if (cellMapping[cellId] == null)
  6851. {
  6852. // Uses empty string if clone ID was null which means
  6853. // the cell was cloned but not inserted into the model.
  6854. cellMapping[cellId] = mapping[objectId].getId() || '';
  6855. }
  6856. }
  6857. return cellMapping;
  6858. };
  6859. /**
  6860. *
  6861. */
  6862. Graph.prototype.importGraphModel = function(node, dx, dy, crop)
  6863. {
  6864. dx = (dx != null) ? dx : 0;
  6865. dy = (dy != null) ? dy : 0;
  6866. var codec = new mxCodec(node.ownerDocument);
  6867. var tempModel = new mxGraphModel();
  6868. codec.decode(node, tempModel);
  6869. var cells = []
  6870. // Clones cells to remove invalid edges
  6871. var cloneMap = new Object();
  6872. var cellMapping = new Object();
  6873. var layers = tempModel.getChildren(this.cloneCell(tempModel.root,
  6874. this.isCloneInvalidEdges(), cloneMap));
  6875. if (layers != null)
  6876. {
  6877. // Creates lookup from object IDs to cell IDs
  6878. var lookup = this.createCellLookup([tempModel.root]);
  6879. // Uses copy as layers are removed from array inside loop
  6880. layers = layers.slice();
  6881. this.model.beginUpdate();
  6882. try
  6883. {
  6884. // Merges into unlocked current layer if one layer is pasted
  6885. if (layers.length == 1 && !this.isCellLocked(this.getDefaultParent()))
  6886. {
  6887. var children = tempModel.getChildren(layers[0]);
  6888. if (children != null)
  6889. {
  6890. cells = this.moveCells(children,
  6891. dx, dy, false, this.getDefaultParent());
  6892. // Imported default parent maps to local default parent
  6893. cellMapping[tempModel.getChildAt(tempModel.root, 0).getId()] =
  6894. this.getDefaultParent().getId();
  6895. }
  6896. }
  6897. else
  6898. {
  6899. for (var i = 0; i < layers.length; i++)
  6900. {
  6901. var children = this.model.getChildren(this.moveCells(
  6902. [layers[i]], dx, dy, false, this.model.getRoot())[0]);
  6903. if (children != null)
  6904. {
  6905. cells = cells.concat(children);
  6906. }
  6907. }
  6908. }
  6909. if (cells != null)
  6910. {
  6911. // Adds mapping for all cloned entries from imported to local cell ID
  6912. this.createCellMapping(cloneMap, lookup, cellMapping);
  6913. this.updateCustomLinks(cellMapping, cells);
  6914. if (crop)
  6915. {
  6916. if (this.isGridEnabled())
  6917. {
  6918. dx = this.snap(dx);
  6919. dy = this.snap(dy);
  6920. }
  6921. var bounds = this.getBoundingBoxFromGeometry(cells, true);
  6922. if (bounds != null)
  6923. {
  6924. this.moveCells(cells, dx - bounds.x, dy - bounds.y);
  6925. }
  6926. }
  6927. }
  6928. }
  6929. finally
  6930. {
  6931. this.model.endUpdate();
  6932. }
  6933. }
  6934. return cells;
  6935. };
  6936. /**
  6937. * Translates this point by the given vector.
  6938. *
  6939. * @param {number} dx X-coordinate of the translation.
  6940. * @param {number} dy Y-coordinate of the translation.
  6941. */
  6942. Graph.prototype.encodeCells = function(cells)
  6943. {
  6944. var cloneMap = new Object();
  6945. var clones = this.cloneCells(cells, null, cloneMap);
  6946. // Creates a dictionary for fast lookups
  6947. var dict = new mxDictionary();
  6948. for (var i = 0; i < cells.length; i++)
  6949. {
  6950. dict.put(cells[i], true);
  6951. }
  6952. var codec = new mxCodec();
  6953. var model = new mxGraphModel();
  6954. var parent = model.getChildAt(model.getRoot(), 0);
  6955. for (var i = 0; i < clones.length; i++)
  6956. {
  6957. model.add(parent, clones[i]);
  6958. // Checks for orphaned relative children and makes absolute
  6959. var state = this.view.getState(cells[i]);
  6960. if (state != null)
  6961. {
  6962. var geo = this.getCellGeometry(clones[i]);
  6963. if (geo != null && geo.relative && !this.model.isEdge(cells[i]) &&
  6964. dict.get(this.model.getParent(cells[i])) == null)
  6965. {
  6966. geo.offset = null;
  6967. geo.relative = false;
  6968. geo.x = state.x / state.view.scale - state.view.translate.x;
  6969. geo.y = state.y / state.view.scale - state.view.translate.y;
  6970. }
  6971. }
  6972. }
  6973. this.updateCustomLinks(this.createCellMapping(cloneMap,
  6974. this.createCellLookup(cells)), clones);
  6975. return codec.encode(model);
  6976. };
  6977. /**
  6978. * Overridden to use table cell instead of table as parent.
  6979. */
  6980. Graph.prototype.isSwimlane = function(cell, ignoreState)
  6981. {
  6982. var shape = null;
  6983. if (cell != null && !this.model.isEdge(cell) &&
  6984. this.model.getParent(cell) !=
  6985. this.model.getRoot())
  6986. {
  6987. var style = this.getCurrentCellStyle(cell, ignoreState)
  6988. shape = style[mxConstants.STYLE_SHAPE];
  6989. }
  6990. return shape == mxConstants.SHAPE_SWIMLANE ||
  6991. shape == 'table' || shape == 'tableRow';
  6992. };
  6993. /**
  6994. * Overridden to add expand style.
  6995. */
  6996. var graphIsExtendParent = Graph.prototype.isExtendParent;
  6997. Graph.prototype.isExtendParent = function(cell)
  6998. {
  6999. var parent = this.model.getParent(cell);
  7000. if (parent != null)
  7001. {
  7002. var style = this.getCurrentCellStyle(parent);
  7003. if (style['expand'] != null)
  7004. {
  7005. return style['expand'] != '0';
  7006. }
  7007. }
  7008. return graphIsExtendParent.apply(this, arguments) &&
  7009. (parent == null || !this.isTable(parent));
  7010. };
  7011. /**
  7012. * Overridden to use table cell instead of table as parent.
  7013. */
  7014. var graphSplitEdge = Graph.prototype.splitEdge;
  7015. Graph.prototype.splitEdge = function(edge, cells, newEdge, dx, dy, x, y, parent)
  7016. {
  7017. if (parent == null)
  7018. {
  7019. parent = this.model.getParent(edge);
  7020. if (this.isTable(parent) || this.isTableRow(parent))
  7021. {
  7022. parent = this.getCellAt(x, y, null, true, false);
  7023. }
  7024. }
  7025. var newEdge = null;
  7026. this.model.beginUpdate();
  7027. try
  7028. {
  7029. var newEdge = graphSplitEdge.apply(this, [edge, cells, newEdge, dx, dy, x, y, parent]);
  7030. // Removes cloned value on first segment
  7031. this.model.setValue(newEdge, '');
  7032. // Removes child labels on first or second segment depending on coordinate
  7033. // LATER: Split and reposition labels based on x and y
  7034. var sourceLabels = this.getChildCells(newEdge, true);
  7035. for (var i = 0; i < sourceLabels.length; i++)
  7036. {
  7037. var geo = this.getCellGeometry(sourceLabels[i]);
  7038. if (geo != null && geo.relative && geo.x > 0)
  7039. {
  7040. this.model.remove(sourceLabels[i]);
  7041. }
  7042. }
  7043. var targetLabels = this.getChildCells(edge, true);
  7044. for (var i = 0; i < targetLabels.length; i++)
  7045. {
  7046. var geo = this.getCellGeometry(targetLabels[i]);
  7047. if (geo != null && geo.relative && geo.x <= 0)
  7048. {
  7049. this.model.remove(targetLabels[i]);
  7050. }
  7051. }
  7052. // Removes end arrow and target perimetr Spacing on first segment, start arrow on second segment
  7053. this.setCellStyles(mxConstants.STYLE_TARGET_PERIMETER_SPACING, null, [newEdge]);
  7054. this.setCellStyles(mxConstants.STYLE_ENDARROW, mxConstants.NONE, [newEdge]);
  7055. // Removes start arrow and source perimeter spacing on second segment
  7056. this.setCellStyles(mxConstants.STYLE_SOURCE_PERIMETER_SPACING, null, [edge]);
  7057. this.setCellStyles(mxConstants.STYLE_STARTARROW, mxConstants.NONE, [edge]);
  7058. // Removes entryX/Y and exitX/Y if snapToPoint is used
  7059. var target = this.model.getTerminal(newEdge, false);
  7060. if (target != null)
  7061. {
  7062. var style = this.getCurrentCellStyle(target);
  7063. if (style != null && style['snapToPoint'] == '1')
  7064. {
  7065. this.setCellStyles(mxConstants.STYLE_EXIT_X, null, [edge]);
  7066. this.setCellStyles(mxConstants.STYLE_EXIT_Y, null, [edge]);
  7067. this.setCellStyles(mxConstants.STYLE_ENTRY_X, null, [newEdge]);
  7068. this.setCellStyles(mxConstants.STYLE_ENTRY_Y, null, [newEdge]);
  7069. }
  7070. }
  7071. }
  7072. finally
  7073. {
  7074. this.model.endUpdate();
  7075. }
  7076. return newEdge;
  7077. };
  7078. /**
  7079. * Overridden to flatten cell hierarchy for selecting next and previous.
  7080. */
  7081. var graphSelectCell = Graph.prototype.selectCell;
  7082. Graph.prototype.selectCell = function(isNext, isParent, isChild)
  7083. {
  7084. if (isParent || isChild)
  7085. {
  7086. graphSelectCell.apply(this, arguments);
  7087. }
  7088. else
  7089. {
  7090. var cell = this.getSelectionCell();
  7091. var index = null;
  7092. var cells = [];
  7093. // LATER: Reverse traverse order for !isNext
  7094. var flatten = mxUtils.bind(this, function(temp)
  7095. {
  7096. if (this.view.getState(temp) != null &&
  7097. (this.model.isVertex(temp) ||
  7098. this.model.isEdge(temp)))
  7099. {
  7100. cells.push(temp);
  7101. if (temp == cell)
  7102. {
  7103. index = cells.length - 1;
  7104. }
  7105. else if ((isNext && cell == null && cells.length > 0) ||
  7106. (index != null && ((isNext && cells.length > index)) ||
  7107. (!isNext && index > 0)))
  7108. {
  7109. return;
  7110. }
  7111. }
  7112. for (var i = 0; i < this.model.getChildCount(temp); i++)
  7113. {
  7114. flatten(this.model.getChildAt(temp, i));
  7115. }
  7116. });
  7117. flatten(this.model.root);
  7118. if (cells.length > 0)
  7119. {
  7120. if (index != null)
  7121. {
  7122. index = mxUtils.mod(index + ((isNext) ? 1 : -1), cells.length)
  7123. }
  7124. else
  7125. {
  7126. index = 0;
  7127. }
  7128. this.setSelectionCell(cells[index]);
  7129. }
  7130. }
  7131. };
  7132. /**
  7133. * Swaps the given shapes.
  7134. */
  7135. Graph.prototype.swapShapes = function(cells, dx, dy, clone, target, evt, mapping)
  7136. {
  7137. var result = false;
  7138. if (!clone && target != null && cells.length == 1)
  7139. {
  7140. var targetState = this.view.getState(target);
  7141. var sourceState = this.view.getState(cells[0]);
  7142. if (targetState != null && sourceState != null &&
  7143. ((evt != null && mxEvent.isShiftDown(evt)) ||
  7144. (targetState.style['shape'] == 'umlLifeline' &&
  7145. sourceState.style['shape'] == 'umlLifeline')))
  7146. {
  7147. var g1 = this.getCellGeometry(target);
  7148. var g2 = this.getCellGeometry(cells[0]);
  7149. if (g1 != null && g2 != null)
  7150. {
  7151. var ng1 = g1.clone();
  7152. var ng2 = g2.clone();
  7153. ng2.x = ng1.x;
  7154. ng2.y = ng1.y;
  7155. ng1.x = g2.x;
  7156. ng1.y = g2.y;
  7157. this.model.beginUpdate();
  7158. try
  7159. {
  7160. this.model.setGeometry(target, ng1);
  7161. this.model.setGeometry(cells[0], ng2);
  7162. }
  7163. finally
  7164. {
  7165. this.model.endUpdate();
  7166. }
  7167. result = true;
  7168. }
  7169. }
  7170. }
  7171. return result;
  7172. };
  7173. /**
  7174. * Overrides cloning cells in moveCells.
  7175. */
  7176. var graphMoveCells = Graph.prototype.moveCells;
  7177. Graph.prototype.moveCells = function(cells, dx, dy, clone, target, evt, mapping)
  7178. {
  7179. if (this.swapShapes(cells, dx, dy, clone, target, evt, mapping))
  7180. {
  7181. return cells;
  7182. }
  7183. mapping = (mapping != null) ? mapping : new Object();
  7184. // Replaces source tables with rows
  7185. if (this.isTable(target))
  7186. {
  7187. var newCells = [];
  7188. for (var i = 0; i < cells.length; i++)
  7189. {
  7190. if (this.isTable(cells[i]))
  7191. {
  7192. newCells = newCells.concat(this.model.getChildCells(cells[i], true).reverse());
  7193. }
  7194. else
  7195. {
  7196. newCells.push(cells[i]);
  7197. }
  7198. }
  7199. cells = newCells;
  7200. }
  7201. this.model.beginUpdate();
  7202. try
  7203. {
  7204. // Updates source and target table heights and matches
  7205. // column count for moving rows between tables
  7206. var sourceTables = [];
  7207. for (var i = 0; i < cells.length; i++)
  7208. {
  7209. if (target != null && this.isTableRow(cells[i]))
  7210. {
  7211. var parent = this.model.getParent(cells[i]);
  7212. var row = this.getCellGeometry(cells[i]);
  7213. if (this.isTable(parent))
  7214. {
  7215. sourceTables.push(parent);
  7216. }
  7217. if (parent != null && row != null &&
  7218. this.isTable(parent) &&
  7219. this.isTable(target) &&
  7220. (clone || parent != target))
  7221. {
  7222. if (!clone)
  7223. {
  7224. var table = this.getCellGeometry(parent);
  7225. if (table != null)
  7226. {
  7227. table = table.clone();
  7228. table.height -= row.height;
  7229. this.model.setGeometry(parent, table);
  7230. }
  7231. }
  7232. var table = this.getCellGeometry(target);
  7233. if (table != null)
  7234. {
  7235. table = table.clone();
  7236. table.height += row.height;
  7237. this.model.setGeometry(target, table);
  7238. }
  7239. // Matches column count
  7240. var rows = this.model.getChildCells(target, true);
  7241. if (rows.length > 0)
  7242. {
  7243. cells[i] = (clone) ? this.cloneCell(cells[i]) : cells[i];
  7244. var sourceCols = this.model.getChildCells(cells[i], true);
  7245. var cols = this.model.getChildCells(rows[0], true);
  7246. var count = cols.length - sourceCols.length;
  7247. if (count > 0)
  7248. {
  7249. for (var j = 0; j < count; j++)
  7250. {
  7251. var col = this.cloneCell(sourceCols[sourceCols.length - 1]);
  7252. if (col != null)
  7253. {
  7254. col.value = '';
  7255. this.model.add(cells[i], col);
  7256. }
  7257. }
  7258. }
  7259. else if (count < 0)
  7260. {
  7261. for (var j = 0; j > count; j--)
  7262. {
  7263. this.model.remove(sourceCols[sourceCols.length + j - 1]);
  7264. }
  7265. }
  7266. // Updates column widths
  7267. sourceCols = this.model.getChildCells(cells[i], true);
  7268. for (var j = 0; j < cols.length; j++)
  7269. {
  7270. var geo = this.getCellGeometry(cols[j]);
  7271. var geo2 = this.getCellGeometry(sourceCols[j]);
  7272. if (geo != null && geo2 != null)
  7273. {
  7274. geo2 = geo2.clone();
  7275. geo2.width = geo.width;
  7276. this.model.setGeometry(sourceCols[j], geo2);
  7277. }
  7278. }
  7279. }
  7280. }
  7281. }
  7282. }
  7283. var result = graphMoveCells.apply(this, arguments);
  7284. // Removes empty tables
  7285. for (var i = 0; i < sourceTables.length; i++)
  7286. {
  7287. if (!clone && this.model.contains(sourceTables[i]) &&
  7288. this.model.getChildCount(sourceTables[i]) == 0)
  7289. {
  7290. this.model.remove(sourceTables[i]);
  7291. }
  7292. }
  7293. if (clone)
  7294. {
  7295. this.updateCustomLinks(this.createCellMapping(mapping,
  7296. this.createCellLookup(cells)), result);
  7297. }
  7298. }
  7299. finally
  7300. {
  7301. this.model.endUpdate();
  7302. }
  7303. return result;
  7304. };
  7305. /**
  7306. * Overriddes to delete label for table cells.
  7307. */
  7308. var graphRemoveCells = Graph.prototype.removeCells;
  7309. Graph.prototype.removeCells = function(cells, includeEdges)
  7310. {
  7311. var result = [];
  7312. this.model.beginUpdate();
  7313. try
  7314. {
  7315. // Clears labels on table cells
  7316. for (var i = 0; i < cells.length; i++)
  7317. {
  7318. if (this.isTableCell(cells[i]))
  7319. {
  7320. var row = this.model.getParent(cells[i]);
  7321. var table = this.model.getParent(row);
  7322. // Removes table if one cell in one row left
  7323. if (this.model.getChildCount(row) == 1 &&
  7324. this.model.getChildCount(table) == 1)
  7325. {
  7326. if (mxUtils.indexOf(cells, table) < 0 &&
  7327. mxUtils.indexOf(result, table) < 0)
  7328. {
  7329. result.push(table);
  7330. }
  7331. }
  7332. else
  7333. {
  7334. this.labelChanged(cells[i], '');
  7335. }
  7336. }
  7337. else
  7338. {
  7339. // Deletes table if all rows are removed
  7340. if (this.isTableRow(cells[i]))
  7341. {
  7342. var table = this.model.getParent(cells[i]);
  7343. if (mxUtils.indexOf(cells, table) < 0 &&
  7344. mxUtils.indexOf(result, table) < 0)
  7345. {
  7346. var rows = this.model.getChildCells(table, true);
  7347. var deleteCount = 0;
  7348. for (var j = 0; j < rows.length; j++)
  7349. {
  7350. if (mxUtils.indexOf(cells, rows[j]) >= 0)
  7351. {
  7352. deleteCount++;
  7353. }
  7354. }
  7355. if (deleteCount == rows.length)
  7356. {
  7357. result.push(table);
  7358. }
  7359. }
  7360. }
  7361. result.push(cells[i]);
  7362. }
  7363. }
  7364. result = graphRemoveCells.apply(this, [result, includeEdges]);
  7365. }
  7366. finally
  7367. {
  7368. this.model.endUpdate();
  7369. }
  7370. return result;
  7371. };
  7372. /**
  7373. * Updates cells IDs for custom links in the given cells using an
  7374. * optional graph to avoid changing the undo history.
  7375. */
  7376. Graph.prototype.updateCustomLinks = function(mapping, cells, graph)
  7377. {
  7378. graph = (graph != null) ? graph : new Graph();
  7379. for (var i = 0; i < cells.length; i++)
  7380. {
  7381. if (cells[i] != null)
  7382. {
  7383. graph.updateCustomLinksForCell(mapping, cells[i], graph);
  7384. }
  7385. }
  7386. };
  7387. /**
  7388. * Updates cell IDs in custom links on the given cell and its label.
  7389. */
  7390. Graph.prototype.updateCustomLinksForCell = function(mapping, cell)
  7391. {
  7392. this.doUpdateCustomLinksForCell(mapping, cell);
  7393. var childCount = this.model.getChildCount(cell);
  7394. for (var i = 0; i < childCount; i++)
  7395. {
  7396. this.updateCustomLinksForCell(mapping,
  7397. this.model.getChildAt(cell, i));
  7398. }
  7399. };
  7400. /**
  7401. * Updates cell IDs in custom links on the given cell and its label.
  7402. */
  7403. Graph.prototype.doUpdateCustomLinksForCell = function(mapping, cell)
  7404. {
  7405. // Hook for subclassers
  7406. };
  7407. /**
  7408. * Overrides method to provide connection constraints for shapes.
  7409. */
  7410. Graph.prototype.getAllConnectionConstraints = function(terminal, source)
  7411. {
  7412. if (terminal != null)
  7413. {
  7414. var constraints = mxUtils.getValue(terminal.style, 'points', null);
  7415. if (constraints != null)
  7416. {
  7417. // Requires an array of arrays with x, y (0..1), an optional
  7418. // [perimeter (0 or 1), dx, and dy] eg. points=[[0,0,1,-10,10],[0,1,0],[1,1]]
  7419. var result = [];
  7420. try
  7421. {
  7422. var c = JSON.parse(constraints);
  7423. for (var i = 0; i < c.length; i++)
  7424. {
  7425. var tmp = c[i];
  7426. result.push(new mxConnectionConstraint(new mxPoint(tmp[0], tmp[1]), (tmp.length > 2) ? tmp[2] != '0' : true,
  7427. null, (tmp.length > 3) ? tmp[3] : 0, (tmp.length > 4) ? tmp[4] : 0));
  7428. }
  7429. }
  7430. catch (e)
  7431. {
  7432. // ignore
  7433. }
  7434. return result;
  7435. }
  7436. else if (terminal.shape != null && terminal.shape.bounds != null)
  7437. {
  7438. var dir = terminal.shape.direction;
  7439. var bounds = terminal.shape.bounds;
  7440. var scale = terminal.shape.scale;
  7441. var w = bounds.width / scale;
  7442. var h = bounds.height / scale;
  7443. if (dir == mxConstants.DIRECTION_NORTH || dir == mxConstants.DIRECTION_SOUTH)
  7444. {
  7445. var tmp = w;
  7446. w = h;
  7447. h = tmp;
  7448. }
  7449. constraints = terminal.shape.getConstraints(terminal.style, w, h);
  7450. if (constraints != null)
  7451. {
  7452. return constraints;
  7453. }
  7454. else if (terminal.shape.stencil != null && terminal.shape.stencil.constraints != null)
  7455. {
  7456. return terminal.shape.stencil.constraints;
  7457. }
  7458. else if (terminal.shape.constraints != null)
  7459. {
  7460. return terminal.shape.constraints;
  7461. }
  7462. }
  7463. }
  7464. return null;
  7465. };
  7466. /**
  7467. * Inverts the elbow edge style without removing existing styles.
  7468. */
  7469. Graph.prototype.flipEdge = function(edge)
  7470. {
  7471. if (edge != null)
  7472. {
  7473. var style = this.getCurrentCellStyle(edge);
  7474. var elbow = mxUtils.getValue(style, mxConstants.STYLE_ELBOW,
  7475. mxConstants.ELBOW_HORIZONTAL);
  7476. var value = (elbow == mxConstants.ELBOW_HORIZONTAL) ?
  7477. mxConstants.ELBOW_VERTICAL : mxConstants.ELBOW_HORIZONTAL;
  7478. this.setCellStyles(mxConstants.STYLE_ELBOW, value, [edge]);
  7479. }
  7480. };
  7481. /**
  7482. * Disables drill-down for non-swimlanes.
  7483. */
  7484. Graph.prototype.isValidRoot = function(cell)
  7485. {
  7486. // Counts non-relative children
  7487. var childCount = this.model.getChildCount(cell);
  7488. var realChildCount = 0;
  7489. for (var i = 0; i < childCount; i++)
  7490. {
  7491. var child = this.model.getChildAt(cell, i);
  7492. if (this.model.isVertex(child))
  7493. {
  7494. var geometry = this.getCellGeometry(child);
  7495. if (geometry != null && !geometry.relative)
  7496. {
  7497. realChildCount++;
  7498. }
  7499. }
  7500. }
  7501. return realChildCount > 0 || this.isContainer(cell);
  7502. };
  7503. /**
  7504. * Disables drill-down for non-swimlanes.
  7505. */
  7506. Graph.prototype.isValidDropTarget = function(cell, cells, evt)
  7507. {
  7508. var style = this.getCurrentCellStyle(cell);
  7509. var tables = true;
  7510. var rows = true;
  7511. for (var i = 0; i < cells.length && rows; i++)
  7512. {
  7513. tables = tables && this.isTable(cells[i]);
  7514. rows = rows && this.isTableRow(cells[i]);
  7515. }
  7516. return ((cells.length == 1 && evt != null && mxEvent.isShiftDown(evt) &&
  7517. !mxEvent.isControlDown(evt) && !mxEvent.isAltDown(evt)) ||
  7518. ((mxUtils.getValue(style, 'part', '0') != '1' || this.isContainer(cell)) &&
  7519. mxUtils.getValue(style, 'dropTarget', '1') != '0' &&
  7520. (mxGraph.prototype.isValidDropTarget.apply(this, arguments) ||
  7521. this.isContainer(cell)) && !this.isTableRow(cell) &&
  7522. (!this.isTable(cell) || rows || tables))) && !this.isCellLocked(cell);
  7523. };
  7524. /**
  7525. * Overrides createGroupCell to set the group style for new groups to 'group'.
  7526. */
  7527. Graph.prototype.createGroupCell = function()
  7528. {
  7529. var group = mxGraph.prototype.createGroupCell.apply(this, arguments);
  7530. group.setStyle('group');
  7531. return group;
  7532. };
  7533. /**
  7534. * Disables extending parents with stack layouts on add
  7535. */
  7536. Graph.prototype.isExtendParentsOnAdd = function(cell)
  7537. {
  7538. var result = mxGraph.prototype.isExtendParentsOnAdd.apply(this, arguments);
  7539. if (result && cell != null && this.layoutManager != null)
  7540. {
  7541. var parent = this.model.getParent(cell);
  7542. if (parent != null)
  7543. {
  7544. var layout = this.layoutManager.getLayout(parent);
  7545. if (layout != null && layout.constructor == mxStackLayout)
  7546. {
  7547. result = false;
  7548. }
  7549. }
  7550. }
  7551. return result;
  7552. };
  7553. /**
  7554. * Overrides autosize to add a border.
  7555. */
  7556. Graph.prototype.getPreferredSizeForCell = function(cell)
  7557. {
  7558. var result = mxGraph.prototype.getPreferredSizeForCell.apply(this, arguments);
  7559. // Adds buffer
  7560. if (result != null)
  7561. {
  7562. result.width += 10;
  7563. result.height += 4;
  7564. if (this.gridEnabled)
  7565. {
  7566. result.width = this.snap(result.width);
  7567. result.height = this.snap(result.height);
  7568. }
  7569. }
  7570. return result;
  7571. }
  7572. /**
  7573. * Turns the given cells and returns the changed cells.
  7574. */
  7575. Graph.prototype.turnShapes = function(cells, backwards)
  7576. {
  7577. var model = this.getModel();
  7578. var select = [];
  7579. model.beginUpdate();
  7580. try
  7581. {
  7582. for (var i = 0; i < cells.length; i++)
  7583. {
  7584. var cell = cells[i];
  7585. if (model.isEdge(cell))
  7586. {
  7587. var src = model.getTerminal(cell, true);
  7588. var trg = model.getTerminal(cell, false);
  7589. model.setTerminal(cell, trg, true);
  7590. model.setTerminal(cell, src, false);
  7591. var geo = model.getGeometry(cell);
  7592. if (geo != null)
  7593. {
  7594. geo = geo.clone();
  7595. if (geo.points != null)
  7596. {
  7597. geo.points.reverse();
  7598. }
  7599. var sp = geo.getTerminalPoint(true);
  7600. var tp = geo.getTerminalPoint(false)
  7601. geo.setTerminalPoint(sp, false);
  7602. geo.setTerminalPoint(tp, true);
  7603. model.setGeometry(cell, geo);
  7604. // Inverts constraints
  7605. var edgeState = this.view.getState(cell);
  7606. var sourceState = this.view.getState(src);
  7607. var targetState = this.view.getState(trg);
  7608. if (edgeState != null)
  7609. {
  7610. var sc = (sourceState != null) ? this.getConnectionConstraint(edgeState, sourceState, true) : null;
  7611. var tc = (targetState != null) ? this.getConnectionConstraint(edgeState, targetState, false) : null;
  7612. this.setConnectionConstraint(cell, src, true, tc);
  7613. this.setConnectionConstraint(cell, trg, false, sc);
  7614. // Inverts perimeter spacings
  7615. var temp = mxUtils.getValue(edgeState.style, mxConstants.STYLE_SOURCE_PERIMETER_SPACING);
  7616. this.setCellStyles(mxConstants.STYLE_SOURCE_PERIMETER_SPACING, mxUtils.getValue(
  7617. edgeState.style, mxConstants.STYLE_TARGET_PERIMETER_SPACING), [cell]);
  7618. this.setCellStyles(mxConstants.STYLE_TARGET_PERIMETER_SPACING, temp, [cell]);
  7619. }
  7620. select.push(cell);
  7621. }
  7622. }
  7623. else if (model.isVertex(cell))
  7624. {
  7625. var geo = this.getCellGeometry(cell);
  7626. if (geo != null)
  7627. {
  7628. // Rotates the size and position in the geometry
  7629. if (!this.isTable(cell) && !this.isTableRow(cell) &&
  7630. !this.isTableCell(cell) && !this.isSwimlane(cell))
  7631. {
  7632. geo = geo.clone();
  7633. geo.x += geo.width / 2 - geo.height / 2;
  7634. geo.y += geo.height / 2 - geo.width / 2;
  7635. var tmp = geo.width;
  7636. geo.width = geo.height;
  7637. geo.height = tmp;
  7638. model.setGeometry(cell, geo);
  7639. }
  7640. // Reads the current direction and advances by 90 degrees
  7641. var state = this.view.getState(cell);
  7642. if (state != null)
  7643. {
  7644. var dirs = [mxConstants.DIRECTION_EAST, mxConstants.DIRECTION_SOUTH,
  7645. mxConstants.DIRECTION_WEST, mxConstants.DIRECTION_NORTH];
  7646. var dir = mxUtils.getValue(state.style, mxConstants.STYLE_DIRECTION,
  7647. mxConstants.DIRECTION_EAST);
  7648. this.setCellStyles(mxConstants.STYLE_DIRECTION,
  7649. dirs[mxUtils.mod(mxUtils.indexOf(dirs, dir) +
  7650. ((backwards) ? -1 : 1), dirs.length)], [cell]);
  7651. }
  7652. select.push(cell);
  7653. }
  7654. }
  7655. }
  7656. }
  7657. finally
  7658. {
  7659. model.endUpdate();
  7660. }
  7661. return select;
  7662. };
  7663. /**
  7664. * Returns true if the given stencil contains any placeholder text.
  7665. */
  7666. Graph.prototype.stencilHasPlaceholders = function(stencil)
  7667. {
  7668. if (stencil != null && stencil.fgNode != null)
  7669. {
  7670. var node = stencil.fgNode.firstChild;
  7671. while (node != null)
  7672. {
  7673. if (node.nodeName == 'text' && node.getAttribute('placeholders') == '1')
  7674. {
  7675. return true;
  7676. }
  7677. node = node.nextSibling;
  7678. }
  7679. }
  7680. return false;
  7681. };
  7682. /**
  7683. * Updates the child cells with placeholders if metadata of a
  7684. * cell has changed and propagates geometry changes in tables.
  7685. */
  7686. var graphProcessChange = Graph.prototype.processChange;
  7687. Graph.prototype.processChange = function(change)
  7688. {
  7689. if (change instanceof mxGeometryChange &&
  7690. (this.isTableCell(change.cell) || this.isTableRow(change.cell)) &&
  7691. ((change.previous == null && change.geometry != null) ||
  7692. (change.previous != null && !change.previous.equals(change.geometry))))
  7693. {
  7694. var cell = change.cell;
  7695. if (this.isTableCell(cell))
  7696. {
  7697. cell = this.model.getParent(cell);
  7698. }
  7699. if (this.isTableRow(cell))
  7700. {
  7701. cell = this.model.getParent(cell);
  7702. }
  7703. // Forces repaint of table with unchanged style and geometry
  7704. var state = this.view.getState(cell);
  7705. if (state != null && state.shape != null)
  7706. {
  7707. this.view.invalidate(cell);
  7708. state.shape.bounds = null;
  7709. }
  7710. }
  7711. graphProcessChange.apply(this, arguments);
  7712. if (change instanceof mxValueChange && change.cell != null &&
  7713. change.cell.value != null && typeof(change.cell.value) == 'object')
  7714. {
  7715. this.invalidateDescendantsWithPlaceholders(change.cell);
  7716. }
  7717. };
  7718. /**
  7719. * Replaces the given element with a span.
  7720. */
  7721. Graph.prototype.invalidateDescendantsWithPlaceholders = function(cell)
  7722. {
  7723. // Invalidates all descendants with placeholders
  7724. var desc = this.model.getDescendants(cell);
  7725. // LATER: Check if only label or tooltip have changed
  7726. if (desc.length > 0)
  7727. {
  7728. for (var i = 0; i < desc.length; i++)
  7729. {
  7730. var state = this.view.getState(desc[i]);
  7731. if (state != null && state.shape != null && state.shape.stencil != null &&
  7732. this.stencilHasPlaceholders(state.shape.stencil))
  7733. {
  7734. this.removeStateForCell(desc[i]);
  7735. }
  7736. else if (this.isReplacePlaceholders(desc[i]))
  7737. {
  7738. this.view.invalidate(desc[i], false, false);
  7739. }
  7740. }
  7741. }
  7742. };
  7743. /**
  7744. * Replaces the given element with a span.
  7745. */
  7746. Graph.prototype.replaceElement = function(elt, tagName)
  7747. {
  7748. var span = elt.ownerDocument.createElement((tagName != null) ? tagName : 'span');
  7749. var attributes = Array.prototype.slice.call(elt.attributes);
  7750. while (attr = attributes.pop())
  7751. {
  7752. span.setAttribute(attr.nodeName, attr.nodeValue);
  7753. }
  7754. span.innerHTML = elt.innerHTML;
  7755. elt.parentNode.replaceChild(span, elt);
  7756. };
  7757. /**
  7758. *
  7759. */
  7760. Graph.prototype.processElements = function(elt, fn)
  7761. {
  7762. if (elt != null)
  7763. {
  7764. var elts = elt.getElementsByTagName('*');
  7765. for (var i = 0; i < elts.length; i++)
  7766. {
  7767. fn(elts[i]);
  7768. }
  7769. }
  7770. };
  7771. /**
  7772. * Handles label changes for XML user objects.
  7773. */
  7774. Graph.prototype.updateLabelElements = function(cells, fn, tagName)
  7775. {
  7776. cells = (cells != null) ? cells : this.getSelectionCells();
  7777. var div = document.createElement('div');
  7778. for (var i = 0; i < cells.length; i++)
  7779. {
  7780. // Changes font tags inside HTML labels
  7781. if (this.isHtmlLabel(cells[i]))
  7782. {
  7783. var label = this.convertValueToString(cells[i]);
  7784. if (label != null && label.length > 0)
  7785. {
  7786. div.innerHTML = label;
  7787. var elts = div.getElementsByTagName((tagName != null) ? tagName : '*');
  7788. for (var j = 0; j < elts.length; j++)
  7789. {
  7790. fn(elts[j]);
  7791. }
  7792. if (div.innerHTML != label)
  7793. {
  7794. this.cellLabelChanged(cells[i], div.innerHTML);
  7795. }
  7796. }
  7797. }
  7798. }
  7799. };
  7800. /**
  7801. * Handles label changes for XML user objects.
  7802. */
  7803. Graph.prototype.cellLabelChanged = function(cell, value, autoSize)
  7804. {
  7805. // Removes all illegal control characters in user input
  7806. value = Graph.zapGremlins(value);
  7807. this.model.beginUpdate();
  7808. try
  7809. {
  7810. if (cell.value != null && typeof cell.value == 'object')
  7811. {
  7812. if (this.isReplacePlaceholders(cell) &&
  7813. cell.getAttribute('placeholder') != null)
  7814. {
  7815. // LATER: Handle delete, name change
  7816. var name = cell.getAttribute('placeholder');
  7817. var current = cell;
  7818. while (current != null)
  7819. {
  7820. if (current == this.model.getRoot() || (current.value != null &&
  7821. typeof(current.value) == 'object' && current.hasAttribute(name)))
  7822. {
  7823. this.setAttributeForCell(current, name, value);
  7824. break;
  7825. }
  7826. current = this.model.getParent(current);
  7827. }
  7828. }
  7829. var tmp = cell.value.cloneNode(true);
  7830. if (Graph.translateDiagram && Graph.diagramLanguage != null &&
  7831. tmp.hasAttribute('label_' + Graph.diagramLanguage))
  7832. {
  7833. tmp.setAttribute('label_' + Graph.diagramLanguage, value);
  7834. }
  7835. else
  7836. {
  7837. tmp.setAttribute('label', value);
  7838. }
  7839. value = tmp;
  7840. }
  7841. mxGraph.prototype.cellLabelChanged.apply(this, arguments);
  7842. }
  7843. finally
  7844. {
  7845. this.model.endUpdate();
  7846. }
  7847. };
  7848. /**
  7849. * Removes transparent empty groups if all children are removed.
  7850. */
  7851. Graph.prototype.cellsRemoved = function(cells)
  7852. {
  7853. if (cells != null)
  7854. {
  7855. var dict = new mxDictionary();
  7856. for (var i = 0; i < cells.length; i++)
  7857. {
  7858. dict.put(cells[i], true);
  7859. }
  7860. // LATER: Recurse up the cell hierarchy
  7861. var parents = [];
  7862. for (var i = 0; i < cells.length; i++)
  7863. {
  7864. var parent = this.model.getParent(cells[i]);
  7865. if (parent != null && !dict.get(parent))
  7866. {
  7867. dict.put(parent, true);
  7868. parents.push(parent);
  7869. }
  7870. }
  7871. for (var i = 0; i < parents.length; i++)
  7872. {
  7873. var state = this.view.getState(parents[i]);
  7874. if (state != null && (this.model.isEdge(state.cell) ||
  7875. this.model.isVertex(state.cell)) &&
  7876. this.isCellDeletable(state.cell) &&
  7877. this.isTransparentState(state))
  7878. {
  7879. var allChildren = true;
  7880. for (var j = 0; j < this.model.getChildCount(state.cell) && allChildren; j++)
  7881. {
  7882. if (!dict.get(this.model.getChildAt(state.cell, j)))
  7883. {
  7884. allChildren = false;
  7885. }
  7886. }
  7887. if (allChildren)
  7888. {
  7889. cells.push(state.cell);
  7890. }
  7891. }
  7892. }
  7893. }
  7894. mxGraph.prototype.cellsRemoved.apply(this, arguments);
  7895. };
  7896. /**
  7897. * Overrides ungroup to check if group should be removed.
  7898. */
  7899. Graph.prototype.removeCellsAfterUngroup = function(cells)
  7900. {
  7901. var cellsToRemove = [];
  7902. for (var i = 0; i < cells.length; i++)
  7903. {
  7904. if (this.isCellDeletable(cells[i]) &&
  7905. this.isTransparentState(
  7906. this.view.getState(cells[i])))
  7907. {
  7908. cellsToRemove.push(cells[i]);
  7909. }
  7910. }
  7911. cells = cellsToRemove;
  7912. mxGraph.prototype.removeCellsAfterUngroup.apply(this, arguments);
  7913. };
  7914. /**
  7915. * Sets the link for the given cell.
  7916. */
  7917. Graph.prototype.setLinkForCell = function(cell, link)
  7918. {
  7919. this.setAttributeForCell(cell, 'link', link);
  7920. };
  7921. /**
  7922. * Sets the link for the given cell.
  7923. */
  7924. Graph.prototype.setTooltipForCell = function(cell, link)
  7925. {
  7926. var key = 'tooltip';
  7927. if (Graph.translateDiagram && Graph.diagramLanguage != null &&
  7928. mxUtils.isNode(cell.value) && cell.value.hasAttribute('tooltip_' + Graph.diagramLanguage))
  7929. {
  7930. key = 'tooltip_' + Graph.diagramLanguage;
  7931. }
  7932. this.setAttributeForCell(cell, key, link);
  7933. };
  7934. /**
  7935. * Returns the cells in the model (or given array) that have all of the
  7936. * given tags in their tags property.
  7937. */
  7938. Graph.prototype.getAttributeForCell = function(cell, attributeName, defaultValue)
  7939. {
  7940. var value = (cell.value != null && typeof cell.value === 'object') ?
  7941. cell.value.getAttribute(attributeName) : null;
  7942. return (value != null) ? value : defaultValue;
  7943. };
  7944. /**
  7945. * Sets the link for the given cell.
  7946. */
  7947. Graph.prototype.setAttributeForCell = function(cell, attributeName, attributeValue)
  7948. {
  7949. var value = null;
  7950. if (cell.value != null && typeof(cell.value) == 'object')
  7951. {
  7952. value = cell.value.cloneNode(true);
  7953. }
  7954. else
  7955. {
  7956. var doc = mxUtils.createXmlDocument();
  7957. value = doc.createElement('UserObject');
  7958. value.setAttribute('label', cell.value || '');
  7959. }
  7960. if (attributeValue != null)
  7961. {
  7962. value.setAttribute(attributeName, attributeValue);
  7963. }
  7964. else
  7965. {
  7966. value.removeAttribute(attributeName);
  7967. }
  7968. this.model.setValue(cell, value);
  7969. };
  7970. /**
  7971. * Overridden to stop moving edge labels between cells.
  7972. */
  7973. var graphGetDropTarget = Graph.prototype.getDropTarget;
  7974. Graph.prototype.getDropTarget = function(cells, evt, cell, clone)
  7975. {
  7976. var model = this.getModel();
  7977. // Disables drop into group if alt is pressed
  7978. if (mxEvent.isAltDown(evt))
  7979. {
  7980. return null;
  7981. }
  7982. // Disables dragging edge labels out of edges
  7983. for (var i = 0; i < cells.length; i++)
  7984. {
  7985. var parent = this.model.getParent(cells[i]);
  7986. if (this.model.isEdge(parent) && mxUtils.indexOf(cells, parent) < 0)
  7987. {
  7988. return null;
  7989. }
  7990. }
  7991. var target = graphGetDropTarget.apply(this, arguments);
  7992. // Always drops rows to tables
  7993. var rows = true;
  7994. for (var i = 0; i < cells.length && rows; i++)
  7995. {
  7996. rows = rows && this.isTableRow(cells[i]);
  7997. }
  7998. if (rows)
  7999. {
  8000. if (this.isTableCell(target))
  8001. {
  8002. target = this.model.getParent(target);
  8003. }
  8004. if (this.isTableRow(target))
  8005. {
  8006. target = this.model.getParent(target);
  8007. }
  8008. if (!this.isTable(target))
  8009. {
  8010. target = null;
  8011. }
  8012. }
  8013. return target;
  8014. };
  8015. /**
  8016. * Overrides double click handling to avoid accidental inserts of new labels in dblClick below.
  8017. */
  8018. Graph.prototype.click = function(me)
  8019. {
  8020. mxGraph.prototype.click.call(this, me);
  8021. // Stores state and source for checking in dblClick
  8022. this.firstClickState = me.getState();
  8023. this.firstClickSource = me.getSource();
  8024. };
  8025. /**
  8026. * Overrides double click handling to add the tolerance and inserting text.
  8027. */
  8028. Graph.prototype.dblClick = function(evt, cell)
  8029. {
  8030. if (this.isEnabled())
  8031. {
  8032. cell = this.insertTextForEvent(evt, cell);
  8033. mxGraph.prototype.dblClick.call(this, evt, cell);
  8034. }
  8035. };
  8036. /**
  8037. * Overrides double click handling to add the tolerance and inserting text.
  8038. */
  8039. Graph.prototype.insertTextForEvent = function(evt, cell)
  8040. {
  8041. var pt = mxUtils.convertPoint(this.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  8042. // Automatically adds new child cells to edges on double click
  8043. if (evt != null && !this.model.isVertex(cell))
  8044. {
  8045. var state = (this.model.isEdge(cell)) ? this.view.getState(cell) : null;
  8046. var src = mxEvent.getSource(evt);
  8047. if ((this.firstClickState == state && this.firstClickSource == src) &&
  8048. (state == null || (state.text == null || state.text.node == null ||
  8049. state.text.boundingBox == null || (!mxUtils.contains(state.text.boundingBox,
  8050. pt.x, pt.y) && !mxUtils.isAncestorNode(state.text.node, mxEvent.getSource(evt))))) &&
  8051. ((state == null && !this.isCellLocked(this.getDefaultParent())) ||
  8052. (state != null && !this.isCellLocked(state.cell))) &&
  8053. (state != null ||
  8054. (mxClient.IS_SVG && src == this.view.getCanvas().ownerSVGElement)))
  8055. {
  8056. if (state == null)
  8057. {
  8058. state = this.view.getState(this.getCellAt(pt.x, pt.y));
  8059. }
  8060. cell = this.addText(pt.x, pt.y, state);
  8061. }
  8062. }
  8063. return cell;
  8064. };
  8065. /**
  8066. * Returns a point that specifies the location for inserting cells.
  8067. */
  8068. Graph.prototype.getInsertPoint = function()
  8069. {
  8070. var gs = this.getGridSize();
  8071. var dx = this.container.scrollLeft / this.view.scale - this.view.translate.x;
  8072. var dy = this.container.scrollTop / this.view.scale - this.view.translate.y;
  8073. if (this.pageVisible)
  8074. {
  8075. var layout = this.getPageLayout();
  8076. var page = this.getPageSize();
  8077. dx = Math.max(dx, layout.x * page.width);
  8078. dy = Math.max(dy, layout.y * page.height);
  8079. }
  8080. return new mxPoint(this.snap(dx + gs), this.snap(dy + gs));
  8081. };
  8082. /**
  8083. *
  8084. */
  8085. Graph.prototype.getFreeInsertPoint = function()
  8086. {
  8087. var view = this.view;
  8088. var bds = this.getGraphBounds();
  8089. var pt = this.getInsertPoint();
  8090. // Places at same x-coord and 2 grid sizes below existing graph
  8091. var x = this.snap(Math.round(Math.max(pt.x, bds.x / view.scale - view.translate.x +
  8092. ((bds.width == 0) ? 2 * this.gridSize : 0))));
  8093. var y = this.snap(Math.round(Math.max(pt.y, (bds.y + bds.height) / view.scale - view.translate.y +
  8094. 2 * this.gridSize)));
  8095. return new mxPoint(x, y);
  8096. };
  8097. /**
  8098. *
  8099. */
  8100. Graph.prototype.getCenterInsertPoint = function(bbox)
  8101. {
  8102. bbox = (bbox != null) ? bbox : new mxRectangle();
  8103. if (mxUtils.hasScrollbars(this.container))
  8104. {
  8105. return new mxPoint(
  8106. this.snap(Math.round((this.container.scrollLeft + this.container.clientWidth / 2) /
  8107. this.view.scale - this.view.translate.x - bbox.width / 2)),
  8108. this.snap(Math.round((this.container.scrollTop + this.container.clientHeight / 2) /
  8109. this.view.scale - this.view.translate.y - bbox.height / 2)));
  8110. }
  8111. else
  8112. {
  8113. return new mxPoint(
  8114. this.snap(Math.round(this.container.clientWidth / 2 / this.view.scale -
  8115. this.view.translate.x - bbox.width / 2)),
  8116. this.snap(Math.round(this.container.clientHeight / 2 / this.view.scale -
  8117. this.view.translate.y - bbox.height / 2)));
  8118. }
  8119. };
  8120. /**
  8121. * Hook for subclassers to return true if the current insert point was defined
  8122. * using a mouse hover event.
  8123. */
  8124. Graph.prototype.isMouseInsertPoint = function()
  8125. {
  8126. return false;
  8127. };
  8128. /**
  8129. * Adds a new label at the given position and returns the new cell. State is
  8130. * an optional edge state to be used as the parent for the label. Vertices
  8131. * are not allowed currently as states.
  8132. */
  8133. Graph.prototype.addText = function(x, y, state)
  8134. {
  8135. // Creates a new edge label with a predefined text
  8136. var label = new mxCell();
  8137. label.value = 'Text';
  8138. label.geometry = new mxGeometry(0, 0, 0, 0);
  8139. label.vertex = true;
  8140. var style = 'html=1;align=center;verticalAlign=middle;resizable=0;points=[];';
  8141. if (state != null && this.model.isEdge(state.cell))
  8142. {
  8143. label.style = 'edgeLabel;' + style;
  8144. label.geometry.relative = true;
  8145. label.connectable = false;
  8146. // Resets the relative location stored inside the geometry
  8147. var pt2 = this.view.getRelativePoint(state, x, y);
  8148. label.geometry.x = Math.round(pt2.x * 10000) / 10000;
  8149. label.geometry.y = Math.round(pt2.y);
  8150. // Resets the offset inside the geometry to find the offset from the resulting point
  8151. label.geometry.offset = new mxPoint(0, 0);
  8152. pt2 = this.view.getPoint(state, label.geometry);
  8153. var scale = this.view.scale;
  8154. label.geometry.offset = new mxPoint(Math.round((x - pt2.x) / scale), Math.round((y - pt2.y) / scale));
  8155. }
  8156. else
  8157. {
  8158. var tr = this.view.translate;
  8159. label.style = 'text;' + style;
  8160. label.geometry.width = 40;
  8161. label.geometry.height = 20;
  8162. label.geometry.x = Math.round(x / this.view.scale) -
  8163. tr.x - ((state != null) ? state.origin.x : 0);
  8164. label.geometry.y = Math.round(y / this.view.scale) -
  8165. tr.y - ((state != null) ? state.origin.y : 0);
  8166. label.style += 'autosize=1;'
  8167. }
  8168. this.getModel().beginUpdate();
  8169. try
  8170. {
  8171. this.addCells([label], (state != null) ? state.cell : null);
  8172. this.fireEvent(new mxEventObject('textInserted', 'cells', [label]));
  8173. // Updates size of text after possible change of style via event
  8174. this.autoSizeCell(label);
  8175. }
  8176. finally
  8177. {
  8178. this.getModel().endUpdate();
  8179. }
  8180. return label;
  8181. };
  8182. /**
  8183. * Adds a handler for clicking on shapes with links. This replaces all links in labels.
  8184. */
  8185. Graph.prototype.addClickHandler = function(highlight, beforeClick, onClick)
  8186. {
  8187. // Replaces links in labels for consistent right-clicks
  8188. var checkLinks = mxUtils.bind(this, function()
  8189. {
  8190. var links = this.container.getElementsByTagName('a');
  8191. if (links != null)
  8192. {
  8193. for (var i = 0; i < links.length; i++)
  8194. {
  8195. var href = this.getAbsoluteUrl(links[i].getAttribute('href'));
  8196. if (href != null)
  8197. {
  8198. links[i].setAttribute('rel', this.linkRelation);
  8199. links[i].setAttribute('href', href);
  8200. if (beforeClick != null)
  8201. {
  8202. mxEvent.addGestureListeners(links[i], null, null, beforeClick);
  8203. }
  8204. }
  8205. }
  8206. }
  8207. });
  8208. this.model.addListener(mxEvent.CHANGE, checkLinks);
  8209. checkLinks();
  8210. var cursor = this.container.style.cursor;
  8211. var tol = this.getTolerance();
  8212. var graph = this;
  8213. var mouseListener =
  8214. {
  8215. currentState: null,
  8216. currentLink: null,
  8217. currentTarget: null,
  8218. highlight: (highlight != null && highlight != '' && highlight != mxConstants.NONE) ?
  8219. new mxCellHighlight(graph, highlight, 4) : null,
  8220. startX: 0,
  8221. startY: 0,
  8222. scrollLeft: 0,
  8223. scrollTop: 0,
  8224. updateCurrentState: function(me)
  8225. {
  8226. var tmp = me.sourceState;
  8227. // Gets first intersecting ancestor with link
  8228. if (tmp == null || graph.getLinkForCell(tmp.cell) == null)
  8229. {
  8230. var cell = graph.getCellAt(me.getGraphX(), me.getGraphY(), null, null, null, function(state, x, y)
  8231. {
  8232. return graph.getLinkForCell(state.cell) == null;
  8233. });
  8234. tmp = (tmp != null && !graph.model.isAncestor(cell, tmp.cell)) ? null : graph.view.getState(cell);
  8235. }
  8236. if (tmp != this.currentState)
  8237. {
  8238. if (this.currentState != null)
  8239. {
  8240. this.clear();
  8241. }
  8242. this.currentState = tmp;
  8243. if (this.currentState != null)
  8244. {
  8245. this.activate(this.currentState);
  8246. }
  8247. }
  8248. },
  8249. mouseDown: function(sender, me)
  8250. {
  8251. this.startX = me.getGraphX();
  8252. this.startY = me.getGraphY();
  8253. this.scrollLeft = graph.container.scrollLeft;
  8254. this.scrollTop = graph.container.scrollTop;
  8255. if (this.currentLink == null && graph.container.style.overflow == 'auto')
  8256. {
  8257. graph.container.style.cursor = 'move';
  8258. }
  8259. this.updateCurrentState(me);
  8260. },
  8261. mouseMove: function(sender, me)
  8262. {
  8263. if (graph.isMouseDown)
  8264. {
  8265. if (this.currentLink != null)
  8266. {
  8267. var dx = Math.abs(this.startX - me.getGraphX());
  8268. var dy = Math.abs(this.startY - me.getGraphY());
  8269. if (dx > tol || dy > tol)
  8270. {
  8271. this.clear();
  8272. }
  8273. }
  8274. }
  8275. else
  8276. {
  8277. // Checks for parent link
  8278. var linkNode = me.getSource();
  8279. while (linkNode != null && linkNode.nodeName.toLowerCase() != 'a')
  8280. {
  8281. linkNode = linkNode.parentNode;
  8282. }
  8283. if (linkNode != null)
  8284. {
  8285. this.clear();
  8286. }
  8287. else
  8288. {
  8289. if (graph.tooltipHandler != null && this.currentLink != null && this.currentState != null)
  8290. {
  8291. graph.tooltipHandler.reset(me, true, this.currentState);
  8292. }
  8293. if (this.currentState != null && (me.getState() == this.currentState || me.sourceState == null) &&
  8294. graph.intersects(this.currentState, me.getGraphX(), me.getGraphY()))
  8295. {
  8296. return;
  8297. }
  8298. this.updateCurrentState(me);
  8299. }
  8300. }
  8301. },
  8302. mouseUp: function(sender, me)
  8303. {
  8304. var source = me.getSource();
  8305. var evt = me.getEvent();
  8306. // Checks for parent link
  8307. var linkNode = source;
  8308. while (linkNode != null && linkNode.nodeName.toLowerCase() != 'a')
  8309. {
  8310. linkNode = linkNode.parentNode;
  8311. }
  8312. // Ignores clicks on links and collapse/expand icon
  8313. if (linkNode == null &&
  8314. (((Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  8315. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  8316. (me.sourceState == null || !me.isSource(me.sourceState.control))) &&
  8317. (((mxEvent.isLeftMouseButton(evt) || mxEvent.isMiddleMouseButton(evt)) &&
  8318. !mxEvent.isPopupTrigger(evt)) || mxEvent.isTouchEvent(evt))))
  8319. {
  8320. if (this.currentLink != null)
  8321. {
  8322. var blank = graph.isBlankLink(this.currentLink);
  8323. if ((this.currentLink.substring(0, 5) === 'data:' ||
  8324. !blank) && beforeClick != null)
  8325. {
  8326. beforeClick(evt, this.currentLink);
  8327. }
  8328. if (!mxEvent.isConsumed(evt))
  8329. {
  8330. var target = (this.currentTarget != null) ?
  8331. this.currentTarget : ((mxEvent.isMiddleMouseButton(evt)) ? '_blank' :
  8332. ((blank) ? graph.linkTarget : '_top'));
  8333. graph.openLink(this.currentLink, target);
  8334. me.consume();
  8335. }
  8336. }
  8337. else if (onClick != null && !me.isConsumed() &&
  8338. (Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  8339. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  8340. (Math.abs(this.startX - me.getGraphX()) < tol &&
  8341. Math.abs(this.startY - me.getGraphY()) < tol))
  8342. {
  8343. onClick(me.getEvent());
  8344. }
  8345. }
  8346. this.clear();
  8347. },
  8348. activate: function(state)
  8349. {
  8350. this.currentLink = graph.getAbsoluteUrl(graph.getLinkForCell(state.cell));
  8351. if (this.currentLink != null)
  8352. {
  8353. this.currentTarget = graph.getLinkTargetForCell(state.cell)
  8354. graph.container.style.cursor = 'pointer';
  8355. if (this.highlight != null)
  8356. {
  8357. this.highlight.highlight(state);
  8358. }
  8359. }
  8360. },
  8361. clear: function()
  8362. {
  8363. if (graph.container != null)
  8364. {
  8365. graph.container.style.cursor = cursor;
  8366. }
  8367. this.currentTarget = null;
  8368. this.currentState = null;
  8369. this.currentLink = null;
  8370. if (this.highlight != null)
  8371. {
  8372. this.highlight.hide();
  8373. }
  8374. if (graph.tooltipHandler != null)
  8375. {
  8376. graph.tooltipHandler.hide();
  8377. }
  8378. }
  8379. };
  8380. // Ignores built-in click handling
  8381. graph.click = function(me) {};
  8382. graph.addMouseListener(mouseListener);
  8383. mxEvent.addListener(document, 'mouseleave', function(evt)
  8384. {
  8385. mouseListener.clear();
  8386. });
  8387. };
  8388. /**
  8389. * Duplicates the given cells and returns the duplicates.
  8390. */
  8391. Graph.prototype.duplicateCells = function(cells, append)
  8392. {
  8393. cells = (cells != null) ? cells : this.getSelectionCells();
  8394. append = (append != null) ? append : true;
  8395. // Duplicates rows for table cells
  8396. for (var i = 0; i < cells.length; i++)
  8397. {
  8398. if (this.isTableCell(cells[i]))
  8399. {
  8400. cells[i] = this.model.getParent(cells[i]);
  8401. }
  8402. }
  8403. cells = this.model.getTopmostCells(cells);
  8404. var model = this.getModel();
  8405. var s = this.gridSize;
  8406. var select = [];
  8407. model.beginUpdate();
  8408. try
  8409. {
  8410. var cloneMap = new Object();
  8411. var lookup = this.createCellLookup(cells);
  8412. var clones = this.cloneCells(cells, false, cloneMap, true);
  8413. for (var i = 0; i < cells.length; i++)
  8414. {
  8415. var parent = model.getParent(cells[i]);
  8416. if (parent != null)
  8417. {
  8418. var child = this.moveCells([clones[i]], s, s, false)[0];
  8419. select.push(child);
  8420. if (append)
  8421. {
  8422. model.add(parent, clones[i]);
  8423. }
  8424. else
  8425. {
  8426. // Maintains child index by inserting after clone in parent
  8427. var index = parent.getIndex(cells[i]);
  8428. model.add(parent, clones[i], index + 1);
  8429. }
  8430. // Extends tables
  8431. if (this.isTable(parent))
  8432. {
  8433. var row = this.getCellGeometry(clones[i]);
  8434. var table = this.getCellGeometry(parent);
  8435. if (row != null && table != null)
  8436. {
  8437. table = table.clone();
  8438. table.height += row.height;
  8439. model.setGeometry(parent, table);
  8440. }
  8441. }
  8442. }
  8443. else
  8444. {
  8445. select.push(clones[i]);
  8446. }
  8447. }
  8448. // Updates custom links after inserting into the model for cells to have new IDs
  8449. this.updateCustomLinks(this.createCellMapping(cloneMap, lookup), clones, this);
  8450. this.fireEvent(new mxEventObject(mxEvent.CELLS_ADDED, 'cells', clones));
  8451. }
  8452. finally
  8453. {
  8454. model.endUpdate();
  8455. }
  8456. return select;
  8457. };
  8458. /**
  8459. * Inserts the given image at the cursor in a content editable text box using
  8460. * the insertimage command on the document instance.
  8461. */
  8462. Graph.prototype.insertImage = function(newValue, w, h)
  8463. {
  8464. // To find the new image, we create a list of all existing links first
  8465. if (newValue != null && this.cellEditor.textarea != null)
  8466. {
  8467. var tmp = this.cellEditor.textarea.getElementsByTagName('img');
  8468. var oldImages = [];
  8469. for (var i = 0; i < tmp.length; i++)
  8470. {
  8471. oldImages.push(tmp[i]);
  8472. }
  8473. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  8474. document.execCommand('insertimage', false, newValue);
  8475. // Sets size of new image
  8476. var newImages = this.cellEditor.textarea.getElementsByTagName('img');
  8477. if (newImages.length == oldImages.length + 1)
  8478. {
  8479. // Inverse order in favor of appended images
  8480. for (var i = newImages.length - 1; i >= 0; i--)
  8481. {
  8482. if (i == 0 || newImages[i] != oldImages[i - 1])
  8483. {
  8484. // Workaround for lost styles during undo and redo is using attributes
  8485. newImages[i].setAttribute('width', w);
  8486. newImages[i].setAttribute('height', h);
  8487. break;
  8488. }
  8489. }
  8490. }
  8491. }
  8492. };
  8493. /**
  8494. * Inserts the given image at the cursor in a content editable text box using
  8495. * the insertimage command on the document instance.
  8496. */
  8497. Graph.prototype.insertLink = function(value)
  8498. {
  8499. if (this.cellEditor.textarea != null)
  8500. {
  8501. if (value.length == 0)
  8502. {
  8503. document.execCommand('unlink', false);
  8504. }
  8505. else if (mxClient.IS_FF)
  8506. {
  8507. // Workaround for Firefox that adds a new link and removes
  8508. // the href from the inner link if its parent is a span is
  8509. // to remove all inner links inside the new outer link
  8510. var tmp = this.cellEditor.textarea.getElementsByTagName('a');
  8511. var oldLinks = [];
  8512. for (var i = 0; i < tmp.length; i++)
  8513. {
  8514. oldLinks.push(tmp[i]);
  8515. }
  8516. document.execCommand('createlink', false, mxUtils.trim(value));
  8517. // Finds the new link element
  8518. var newLinks = this.cellEditor.textarea.getElementsByTagName('a');
  8519. if (newLinks.length == oldLinks.length + 1)
  8520. {
  8521. // Inverse order in favor of appended links
  8522. for (var i = newLinks.length - 1; i >= 0; i--)
  8523. {
  8524. if (newLinks[i] != oldLinks[i - 1])
  8525. {
  8526. // Removes all inner links from the new link and
  8527. // moves the children to the inner link parent
  8528. var tmp = newLinks[i].getElementsByTagName('a');
  8529. while (tmp.length > 0)
  8530. {
  8531. var parent = tmp[0].parentNode;
  8532. while (tmp[0].firstChild != null)
  8533. {
  8534. parent.insertBefore(tmp[0].firstChild, tmp[0]);
  8535. }
  8536. parent.removeChild(tmp[0]);
  8537. }
  8538. break;
  8539. }
  8540. }
  8541. }
  8542. }
  8543. else
  8544. {
  8545. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  8546. document.execCommand('createlink', false, mxUtils.trim(value));
  8547. }
  8548. }
  8549. };
  8550. /**
  8551. *
  8552. * @param cell
  8553. * @returns {Boolean}
  8554. */
  8555. Graph.prototype.isCellResizable = function(cell)
  8556. {
  8557. var result = mxGraph.prototype.isCellResizable.apply(this, arguments);
  8558. var style = this.getCurrentCellStyle(cell);
  8559. return !this.isTableCell(cell) && !this.isTableRow(cell) && (result ||
  8560. (mxUtils.getValue(style, mxConstants.STYLE_RESIZABLE, '1') != '0' &&
  8561. style[mxConstants.STYLE_WHITE_SPACE] == 'wrap'));
  8562. };
  8563. /**
  8564. * Function: distributeCells
  8565. *
  8566. * Distribuets the centers of the given cells equally along the available
  8567. * horizontal or vertical space.
  8568. *
  8569. * Parameters:
  8570. *
  8571. * horizontal - Boolean that specifies the direction of the distribution.
  8572. * cells - Optional array of <mxCells> to be distributed. Edges are ignored.
  8573. */
  8574. Graph.prototype.distributeCells = function(horizontal, cells)
  8575. {
  8576. if (cells == null)
  8577. {
  8578. cells = this.getSelectionCells();
  8579. }
  8580. if (cells != null && cells.length > 1)
  8581. {
  8582. var vertices = [];
  8583. var max = null;
  8584. var min = null;
  8585. for (var i = 0; i < cells.length; i++)
  8586. {
  8587. if (this.getModel().isVertex(cells[i]))
  8588. {
  8589. var state = this.view.getState(cells[i]);
  8590. if (state != null)
  8591. {
  8592. var tmp = (horizontal) ? state.getCenterX() : state.getCenterY();
  8593. max = (max != null) ? Math.max(max, tmp) : tmp;
  8594. min = (min != null) ? Math.min(min, tmp) : tmp;
  8595. vertices.push(state);
  8596. }
  8597. }
  8598. }
  8599. if (vertices.length > 2)
  8600. {
  8601. vertices.sort(function(a, b)
  8602. {
  8603. return (horizontal) ? a.x - b.x : a.y - b.y;
  8604. });
  8605. var t = this.view.translate;
  8606. var s = this.view.scale;
  8607. min = min / s - ((horizontal) ? t.x : t.y);
  8608. max = max / s - ((horizontal) ? t.x : t.y);
  8609. this.getModel().beginUpdate();
  8610. try
  8611. {
  8612. var dt = (max - min) / (vertices.length - 1);
  8613. var t0 = min;
  8614. for (var i = 1; i < vertices.length - 1; i++)
  8615. {
  8616. var pstate = this.view.getState(this.model.getParent(vertices[i].cell));
  8617. var geo = this.getCellGeometry(vertices[i].cell);
  8618. t0 += dt;
  8619. if (geo != null && pstate != null)
  8620. {
  8621. geo = geo.clone();
  8622. if (horizontal)
  8623. {
  8624. geo.x = Math.round(t0 - geo.width / 2) - pstate.origin.x;
  8625. }
  8626. else
  8627. {
  8628. geo.y = Math.round(t0 - geo.height / 2) - pstate.origin.y;
  8629. }
  8630. this.getModel().setGeometry(vertices[i].cell, geo);
  8631. }
  8632. }
  8633. }
  8634. finally
  8635. {
  8636. this.getModel().endUpdate();
  8637. }
  8638. }
  8639. }
  8640. return cells;
  8641. };
  8642. /**
  8643. * Adds meta-drag an Mac.
  8644. * @param evt
  8645. * @returns
  8646. */
  8647. Graph.prototype.isCloneEvent = function(evt)
  8648. {
  8649. return (mxClient.IS_MAC && mxEvent.isMetaDown(evt)) || mxEvent.isControlDown(evt);
  8650. };
  8651. /**
  8652. * Translates this point by the given vector.
  8653. *
  8654. * @param {number} dx X-coordinate of the translation.
  8655. * @param {number} dy Y-coordinate of the translation.
  8656. */
  8657. Graph.prototype.createSvgImageExport = function()
  8658. {
  8659. var exp = new mxImageExport();
  8660. // Adds hyperlinks (experimental)
  8661. exp.getLinkForCellState = mxUtils.bind(this, function(state, canvas)
  8662. {
  8663. return this.getLinkForCell(state.cell);
  8664. });
  8665. return exp;
  8666. };
  8667. /**
  8668. * Parses the given background image.
  8669. */
  8670. Graph.prototype.parseBackgroundImage = function(json)
  8671. {
  8672. var result = null;
  8673. if (json != null && json.length > 0)
  8674. {
  8675. var obj = JSON.parse(json);
  8676. result = new mxImage(obj.src, obj.width, obj.height)
  8677. }
  8678. return result;
  8679. };
  8680. /**
  8681. * Parses the given background image.
  8682. */
  8683. Graph.prototype.getBackgroundImageObject = function(obj)
  8684. {
  8685. return obj;
  8686. };
  8687. /**
  8688. * Translates this point by the given vector.
  8689. *
  8690. * @param {number} dx X-coordinate of the translation.
  8691. * @param {number} dy Y-coordinate of the translation.
  8692. */
  8693. Graph.prototype.getSvg = function(background, scale, border, nocrop, crisp,
  8694. ignoreSelection, showText, imgExport, linkTarget, hasShadow, incExtFonts,
  8695. keepTheme, exportType, cells)
  8696. {
  8697. var lookup = null;
  8698. if (cells != null)
  8699. {
  8700. lookup = new mxDictionary();
  8701. for (var i = 0; i < cells.length; i++)
  8702. {
  8703. lookup.put(cells[i], true);
  8704. }
  8705. }
  8706. //Disable Css Transforms if it is used
  8707. var origUseCssTrans = this.useCssTransforms;
  8708. if (origUseCssTrans)
  8709. {
  8710. this.useCssTransforms = false;
  8711. this.view.revalidate();
  8712. this.sizeDidChange();
  8713. }
  8714. try
  8715. {
  8716. scale = (scale != null) ? scale : 1;
  8717. border = (border != null) ? border : 0;
  8718. crisp = (crisp != null) ? crisp : true;
  8719. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  8720. showText = (showText != null) ? showText : true;
  8721. hasShadow = (hasShadow != null) ? hasShadow : false;
  8722. var bounds = (exportType == 'page') ? this.view.getBackgroundPageBounds() :
  8723. (((ignoreSelection && lookup == null) || nocrop ||
  8724. exportType == 'diagram') ? this.getGraphBounds() :
  8725. this.getBoundingBox(this.getSelectionCells()));
  8726. var vs = this.view.scale;
  8727. if (exportType == 'diagram' && this.backgroundImage != null)
  8728. {
  8729. bounds = mxRectangle.fromRectangle(bounds);
  8730. bounds.add(new mxRectangle(
  8731. (this.view.translate.x + this.backgroundImage.x) * vs,
  8732. (this.view.translate.y + this.backgroundImage.y) * vs,
  8733. this.backgroundImage.width * vs,
  8734. this.backgroundImage.height * vs));
  8735. }
  8736. if (bounds == null)
  8737. {
  8738. throw Error(mxResources.get('drawingEmpty'));
  8739. }
  8740. // Prepares SVG document that holds the output
  8741. var s = scale / vs;
  8742. var w = Math.max(1, Math.ceil(bounds.width * s) + 2 * border) +
  8743. ((hasShadow && border == 0) ? 5 : 0);
  8744. var h = Math.max(1, Math.ceil(bounds.height * s) + 2 * border) +
  8745. ((hasShadow && border == 0) ? 5 : 0);
  8746. var tmp = (crisp) ? -0.5 : 0;
  8747. var root = Graph.createSvgNode(tmp, tmp, w, h, background);
  8748. var svgDoc = root.ownerDocument;
  8749. // Renders graph. Offset will be multiplied with state's scale when painting state.
  8750. // TextOffset only seems to affect FF output but used everywhere for consistency.
  8751. var group = (svgDoc.createElementNS != null) ?
  8752. svgDoc.createElementNS(mxConstants.NS_SVG, 'g') : svgDoc.createElement('g');
  8753. root.appendChild(group);
  8754. var svgCanvas = this.createSvgCanvas(group);
  8755. svgCanvas.foOffset = (crisp) ? -0.5 : 0;
  8756. svgCanvas.textOffset = (crisp) ? -0.5 : 0;
  8757. svgCanvas.imageOffset = (crisp) ? -0.5 : 0;
  8758. svgCanvas.translate(Math.floor(border / scale - bounds.x / vs),
  8759. Math.floor(border / scale - bounds.y / vs));
  8760. // Convert HTML entities
  8761. var htmlConverter = document.createElement('div');
  8762. // Adds simple text fallback for viewers with no support for foreignObjects
  8763. var getAlternateText = svgCanvas.getAlternateText;
  8764. svgCanvas.getAlternateText = function(fo, x, y, w, h, str,
  8765. align, valign, wrap, format, overflow, clip, rotation)
  8766. {
  8767. // Assumes a max character width of 0.5em
  8768. if (str != null && this.state.fontSize > 0)
  8769. {
  8770. try
  8771. {
  8772. if (mxUtils.isNode(str))
  8773. {
  8774. str = str.innerText;
  8775. }
  8776. else
  8777. {
  8778. htmlConverter.innerHTML = str;
  8779. str = mxUtils.extractTextWithWhitespace(htmlConverter.childNodes);
  8780. }
  8781. // Workaround for substring breaking double byte UTF
  8782. var exp = Math.ceil(2 * w / this.state.fontSize);
  8783. var result = [];
  8784. var length = 0;
  8785. var index = 0;
  8786. while ((exp == 0 || length < exp) && index < str.length)
  8787. {
  8788. var char = str.charCodeAt(index);
  8789. if (char == 10 || char == 13)
  8790. {
  8791. if (length > 0)
  8792. {
  8793. break;
  8794. }
  8795. }
  8796. else
  8797. {
  8798. result.push(str.charAt(index));
  8799. if (char < 255)
  8800. {
  8801. length++;
  8802. }
  8803. }
  8804. index++;
  8805. }
  8806. // Uses result and adds ellipsis if more than 1 char remains
  8807. if (result.length < str.length && str.length - result.length > 1)
  8808. {
  8809. str = mxUtils.trim(result.join('')) + '...';
  8810. }
  8811. return str;
  8812. }
  8813. catch (e)
  8814. {
  8815. return getAlternateText.apply(this, arguments);
  8816. }
  8817. }
  8818. else
  8819. {
  8820. return getAlternateText.apply(this, arguments);
  8821. }
  8822. };
  8823. // Paints background image
  8824. var bgImg = this.backgroundImage;
  8825. if (bgImg != null)
  8826. {
  8827. var s2 = vs / scale;
  8828. var tr = this.view.translate;
  8829. var tmp = new mxRectangle((bgImg.x + tr.x) * s2, (bgImg.y + tr.y) * s2,
  8830. bgImg.width * s2, bgImg.height * s2);
  8831. // Checks if visible
  8832. if (mxUtils.intersects(bounds, tmp))
  8833. {
  8834. svgCanvas.image(bgImg.x + tr.x, bgImg.y + tr.y,
  8835. bgImg.width, bgImg.height, bgImg.src, true);
  8836. }
  8837. }
  8838. svgCanvas.scale(s);
  8839. svgCanvas.textEnabled = showText;
  8840. imgExport = (imgExport != null) ? imgExport : this.createSvgImageExport();
  8841. var imgExportDrawCellState = imgExport.drawCellState;
  8842. // Ignores custom links
  8843. var imgExportGetLinkForCellState = imgExport.getLinkForCellState;
  8844. imgExport.getLinkForCellState = function(state, canvas)
  8845. {
  8846. var result = imgExportGetLinkForCellState.apply(this, arguments);
  8847. return (result != null && !state.view.graph.isCustomLink(result)) ? result : null;
  8848. };
  8849. imgExport.getLinkTargetForCellState = function(state, canvas)
  8850. {
  8851. return state.view.graph.getLinkTargetForCell(state.cell);
  8852. };
  8853. // Implements ignoreSelection flag
  8854. imgExport.drawCellState = function(state, canvas)
  8855. {
  8856. var graph = state.view.graph;
  8857. var selected = (lookup != null) ? lookup.get(state.cell) :
  8858. graph.isCellSelected(state.cell);
  8859. var parent = graph.model.getParent(state.cell);
  8860. // Checks if parent cell is selected
  8861. while ((!ignoreSelection || lookup != null) &&
  8862. !selected && parent != null)
  8863. {
  8864. selected = (lookup != null) ? lookup.get(parent) :
  8865. graph.isCellSelected(parent);
  8866. parent = graph.model.getParent(parent);
  8867. }
  8868. if ((ignoreSelection && lookup == null) || selected)
  8869. {
  8870. imgExportDrawCellState.apply(this, arguments);
  8871. }
  8872. };
  8873. imgExport.drawState(this.getView().getState(this.model.root), svgCanvas);
  8874. this.updateSvgLinks(root, linkTarget, true);
  8875. this.addForeignObjectWarning(svgCanvas, root);
  8876. return root;
  8877. }
  8878. finally
  8879. {
  8880. if (origUseCssTrans)
  8881. {
  8882. this.useCssTransforms = true;
  8883. this.view.revalidate();
  8884. this.sizeDidChange();
  8885. }
  8886. }
  8887. };
  8888. /**
  8889. * Adds warning for truncated labels in older viewers.
  8890. */
  8891. Graph.prototype.addForeignObjectWarning = function(canvas, root)
  8892. {
  8893. if (urlParams['svg-warning'] != '0' && root.getElementsByTagName('foreignObject').length > 0)
  8894. {
  8895. var sw = canvas.createElement('switch');
  8896. var g1 = canvas.createElement('g');
  8897. g1.setAttribute('requiredFeatures', 'http://www.w3.org/TR/SVG11/feature#Extensibility');
  8898. var a = canvas.createElement('a');
  8899. a.setAttribute('transform', 'translate(0,-5)');
  8900. // Workaround for implicit namespace handling in HTML5 export, IE adds NS1 namespace so use code below
  8901. // in all IE versions except quirks mode. KNOWN: Adds xlink namespace to each image tag in output.
  8902. if (a.setAttributeNS == null || (root.ownerDocument != document && document.documentMode == null))
  8903. {
  8904. a.setAttribute('xlink:href', Graph.foreignObjectWarningLink);
  8905. a.setAttribute('target', '_blank');
  8906. }
  8907. else
  8908. {
  8909. a.setAttributeNS(mxConstants.NS_XLINK, 'xlink:href', Graph.foreignObjectWarningLink);
  8910. a.setAttributeNS(mxConstants.NS_XLINK, 'target', '_blank');
  8911. }
  8912. var text = canvas.createElement('text');
  8913. text.setAttribute('text-anchor', 'middle');
  8914. text.setAttribute('font-size', '10px');
  8915. text.setAttribute('x', '50%');
  8916. text.setAttribute('y', '100%');
  8917. mxUtils.write(text, Graph.foreignObjectWarningText);
  8918. sw.appendChild(g1);
  8919. a.appendChild(text);
  8920. sw.appendChild(a);
  8921. root.appendChild(sw);
  8922. }
  8923. };
  8924. /**
  8925. * Hook for creating the canvas used in getSvg.
  8926. */
  8927. Graph.prototype.updateSvgLinks = function(node, target, removeCustom)
  8928. {
  8929. var links = node.getElementsByTagName('a');
  8930. for (var i = 0; i < links.length; i++)
  8931. {
  8932. if (links[i].getAttribute('target') == null)
  8933. {
  8934. var href = links[i].getAttribute('href');
  8935. if (href == null)
  8936. {
  8937. href = links[i].getAttribute('xlink:href');
  8938. }
  8939. if (href != null)
  8940. {
  8941. if (target != null && /^https?:\/\//.test(href))
  8942. {
  8943. links[i].setAttribute('target', target);
  8944. }
  8945. else if (removeCustom && this.isCustomLink(href))
  8946. {
  8947. links[i].setAttribute('href', 'javascript:void(0);');
  8948. }
  8949. }
  8950. }
  8951. }
  8952. };
  8953. /**
  8954. * Hook for creating the canvas used in getSvg.
  8955. */
  8956. Graph.prototype.createSvgCanvas = function(node)
  8957. {
  8958. var canvas = new mxSvgCanvas2D(node);
  8959. canvas.minStrokeWidth = this.cellRenderer.minSvgStrokeWidth;
  8960. canvas.pointerEvents = true;
  8961. return canvas;
  8962. };
  8963. /**
  8964. * Returns the first ancestor of the current selection with the given name.
  8965. */
  8966. Graph.prototype.getSelectedElement = function()
  8967. {
  8968. var node = null;
  8969. if (window.getSelection)
  8970. {
  8971. var sel = window.getSelection();
  8972. if (sel.getRangeAt && sel.rangeCount)
  8973. {
  8974. var range = sel.getRangeAt(0);
  8975. node = range.commonAncestorContainer;
  8976. }
  8977. }
  8978. else if (document.selection)
  8979. {
  8980. node = document.selection.createRange().parentElement();
  8981. }
  8982. return node;
  8983. };
  8984. /**
  8985. * Returns the text editing element.
  8986. */
  8987. Graph.prototype.getSelectedEditingElement = function()
  8988. {
  8989. var node = this.getSelectedElement();
  8990. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  8991. {
  8992. node = node.parentNode;
  8993. }
  8994. if (node != null)
  8995. {
  8996. // Workaround for commonAncestor on range in IE11 returning parent of common ancestor
  8997. if (node == this.cellEditor.textarea && this.cellEditor.textarea.children.length == 1 &&
  8998. this.cellEditor.textarea.firstChild.nodeType == mxConstants.NODETYPE_ELEMENT)
  8999. {
  9000. node = this.cellEditor.textarea.firstChild;
  9001. }
  9002. }
  9003. return node;
  9004. };
  9005. /**
  9006. * Returns the first ancestor of the current selection with the given name.
  9007. */
  9008. Graph.prototype.getParentByName = function(node, name, stopAt)
  9009. {
  9010. while (node != null)
  9011. {
  9012. if (node.nodeName == name)
  9013. {
  9014. return node;
  9015. }
  9016. if (node == stopAt)
  9017. {
  9018. return null;
  9019. }
  9020. node = node.parentNode;
  9021. }
  9022. return node;
  9023. };
  9024. /**
  9025. * Returns the first ancestor of the current selection with the given name.
  9026. */
  9027. Graph.prototype.getParentByNames = function(node, names, stopAt)
  9028. {
  9029. while (node != null)
  9030. {
  9031. if (mxUtils.indexOf(names, node.nodeName) >= 0)
  9032. {
  9033. return node;
  9034. }
  9035. if (node == stopAt)
  9036. {
  9037. return null;
  9038. }
  9039. node = node.parentNode;
  9040. }
  9041. return node;
  9042. };
  9043. /**
  9044. * Selects the given node.
  9045. */
  9046. Graph.prototype.selectNode = function(node)
  9047. {
  9048. var sel = null;
  9049. // IE9 and non-IE
  9050. if (window.getSelection)
  9051. {
  9052. sel = window.getSelection();
  9053. if (sel.getRangeAt && sel.rangeCount)
  9054. {
  9055. var range = document.createRange();
  9056. range.selectNode(node);
  9057. sel.removeAllRanges();
  9058. sel.addRange(range);
  9059. }
  9060. }
  9061. // IE < 9
  9062. else if ((sel = document.selection) && sel.type != 'Control')
  9063. {
  9064. var originalRange = sel.createRange();
  9065. originalRange.collapse(true);
  9066. var range = sel.createRange();
  9067. range.setEndPoint('StartToStart', originalRange);
  9068. range.select();
  9069. }
  9070. };
  9071. /**
  9072. * Flips the given cells horizontally or vertically.
  9073. */
  9074. Graph.prototype.flipEdgePoints = function(cell, horizontal, c)
  9075. {
  9076. var geo = this.getCellGeometry(cell);
  9077. if (geo != null)
  9078. {
  9079. geo = geo.clone();
  9080. if (geo.points != null)
  9081. {
  9082. for (var i = 0; i < geo.points.length; i++)
  9083. {
  9084. if (horizontal)
  9085. {
  9086. geo.points[i].x = c + (c - geo.points[i].x);
  9087. }
  9088. else
  9089. {
  9090. geo.points[i].y = c + (c - geo.points[i].y);
  9091. }
  9092. }
  9093. }
  9094. var flipTerminalPoint = function(pt)
  9095. {
  9096. if (pt != null)
  9097. {
  9098. if (horizontal)
  9099. {
  9100. pt.x = c + (c - pt.x);
  9101. }
  9102. else
  9103. {
  9104. pt.y = c + (c - pt.y);
  9105. }
  9106. }
  9107. };
  9108. flipTerminalPoint(geo.getTerminalPoint(true));
  9109. flipTerminalPoint(geo.getTerminalPoint(false));
  9110. this.model.setGeometry(cell, geo);
  9111. }
  9112. };
  9113. /**
  9114. * Flips the given cells horizontally or vertically.
  9115. */
  9116. Graph.prototype.flipChildren = function(cell, horizontal, c)
  9117. {
  9118. this.model.beginUpdate();
  9119. try
  9120. {
  9121. var childCount = this.model.getChildCount(cell);
  9122. for (var i = 0; i < childCount; i++)
  9123. {
  9124. var child = this.model.getChildAt(cell, i);
  9125. if (this.model.isEdge(child))
  9126. {
  9127. this.flipEdgePoints(child, horizontal, c);
  9128. }
  9129. else
  9130. {
  9131. var geo = this.getCellGeometry(child);
  9132. if (geo != null)
  9133. {
  9134. geo = geo.clone();
  9135. if (horizontal)
  9136. {
  9137. geo.x = c + (c - geo.x - geo.width);
  9138. }
  9139. else
  9140. {
  9141. geo.y = c + (c - geo.y - geo.height);
  9142. }
  9143. this.model.setGeometry(child, geo);
  9144. }
  9145. }
  9146. }
  9147. }
  9148. finally
  9149. {
  9150. this.model.endUpdate();
  9151. }
  9152. };
  9153. /**
  9154. * Flips the given cells horizontally or vertically.
  9155. */
  9156. Graph.prototype.flipCells = function(cells, horizontal)
  9157. {
  9158. this.model.beginUpdate();
  9159. try
  9160. {
  9161. cells = this.model.getTopmostCells(cells);
  9162. var vertices = [];
  9163. for (var i = 0; i < cells.length; i++)
  9164. {
  9165. if (this.model.isEdge(cells[i]))
  9166. {
  9167. var state = this.view.getState(cells[i]);
  9168. if (state != null)
  9169. {
  9170. this.flipEdgePoints(cells[i], horizontal, ((horizontal ? state.getCenterX() :
  9171. state.getCenterY()) / this.view.scale) - ((horizontal) ?
  9172. state.origin.x : state.origin.y) - ((horizontal) ?
  9173. this.view.translate.x : this.view.translate.y));
  9174. }
  9175. }
  9176. else
  9177. {
  9178. var geo = this.getCellGeometry(cells[i]);
  9179. if (geo != null)
  9180. {
  9181. this.flipChildren(cells[i], horizontal, horizontal ?
  9182. geo.getCenterX() - geo.x :
  9183. geo.getCenterY() - geo.y);
  9184. }
  9185. vertices.push(cells[i]);
  9186. }
  9187. }
  9188. this.toggleCellStyles(horizontal ? mxConstants.STYLE_FLIPH :
  9189. mxConstants.STYLE_FLIPV, false, vertices);
  9190. }
  9191. finally
  9192. {
  9193. this.model.endUpdate();
  9194. }
  9195. };
  9196. /**
  9197. * Deletes the given cells and returns the cells to be selected.
  9198. */
  9199. Graph.prototype.deleteCells = function(cells, includeEdges)
  9200. {
  9201. var select = null;
  9202. if (cells != null && cells.length > 0)
  9203. {
  9204. this.model.beginUpdate();
  9205. try
  9206. {
  9207. // Shrinks tables
  9208. for (var i = 0; i < cells.length; i++)
  9209. {
  9210. var parent = this.model.getParent(cells[i]);
  9211. if (this.isTable(parent))
  9212. {
  9213. var row = this.getCellGeometry(cells[i]);
  9214. var table = this.getCellGeometry(parent);
  9215. if (row != null && table != null)
  9216. {
  9217. table = table.clone();
  9218. table.height -= row.height;
  9219. this.model.setGeometry(parent, table);
  9220. }
  9221. }
  9222. }
  9223. var parents = (this.selectParentAfterDelete) ? this.model.getParents(cells) : null;
  9224. this.removeCells(cells, includeEdges);
  9225. }
  9226. finally
  9227. {
  9228. this.model.endUpdate();
  9229. }
  9230. // Selects parents for easier editing of groups
  9231. if (parents != null)
  9232. {
  9233. select = [];
  9234. for (var i = 0; i < parents.length; i++)
  9235. {
  9236. if (this.model.contains(parents[i]) &&
  9237. (this.model.isVertex(parents[i]) ||
  9238. this.model.isEdge(parents[i])))
  9239. {
  9240. select.push(parents[i]);
  9241. }
  9242. }
  9243. }
  9244. }
  9245. return select;
  9246. };
  9247. /**
  9248. * Inserts a column in the table for the given cell.
  9249. */
  9250. Graph.prototype.insertTableColumn = function(cell, before)
  9251. {
  9252. var model = this.getModel();
  9253. model.beginUpdate();
  9254. try
  9255. {
  9256. var table = cell;
  9257. var index = 0;
  9258. if (this.isTableCell(cell))
  9259. {
  9260. var row = model.getParent(cell);
  9261. table = model.getParent(row);
  9262. index = mxUtils.indexOf(model.getChildCells(row, true), cell);
  9263. }
  9264. else
  9265. {
  9266. if (this.isTableRow(cell))
  9267. {
  9268. table = model.getParent(cell);
  9269. }
  9270. else
  9271. {
  9272. cell = model.getChildCells(table, true)[0];
  9273. }
  9274. if (!before)
  9275. {
  9276. index = model.getChildCells(cell, true).length - 1;
  9277. }
  9278. }
  9279. var rows = model.getChildCells(table, true);
  9280. var dw = Graph.minTableColumnWidth;
  9281. for (var i = 0; i < rows.length; i++)
  9282. {
  9283. var child = model.getChildCells(rows[i], true)[index];
  9284. var clone = model.cloneCell(child, false);
  9285. var geo = this.getCellGeometry(clone);
  9286. // Removes value, col/rowspan and alternate bounds
  9287. clone.value = null;
  9288. clone.style = mxUtils.setStyle(mxUtils.setStyle(
  9289. clone.style, 'rowspan', null), 'colspan', null);
  9290. if (geo != null)
  9291. {
  9292. if (geo.alternateBounds != null)
  9293. {
  9294. geo.width = geo.alternateBounds.width;
  9295. geo.height = geo.alternateBounds.height;
  9296. geo.alternateBounds = null;
  9297. }
  9298. dw = geo.width;
  9299. var rowGeo = this.getCellGeometry(rows[i]);
  9300. if (rowGeo != null)
  9301. {
  9302. geo.height = rowGeo.height;
  9303. }
  9304. }
  9305. model.add(rows[i], clone, index + ((before) ? 0 : 1));
  9306. }
  9307. var tableGeo = this.getCellGeometry(table);
  9308. if (tableGeo != null)
  9309. {
  9310. tableGeo = tableGeo.clone();
  9311. tableGeo.width += dw;
  9312. model.setGeometry(table, tableGeo);
  9313. }
  9314. }
  9315. finally
  9316. {
  9317. model.endUpdate();
  9318. }
  9319. };
  9320. /**
  9321. * Inserts a row in the table for the given cell.
  9322. */
  9323. Graph.prototype.deleteLane = function(cell)
  9324. {
  9325. var model = this.getModel();
  9326. model.beginUpdate();
  9327. try
  9328. {
  9329. var pool = null;
  9330. var lane = cell;
  9331. var style = this.getCurrentCellStyle(lane);
  9332. if (style['childLayout'] == 'stackLayout')
  9333. {
  9334. pool = lane;
  9335. }
  9336. else
  9337. {
  9338. pool = model.getParent(lane);
  9339. }
  9340. var lanes = model.getChildCells(pool, true);
  9341. if (lanes.length == 0)
  9342. {
  9343. model.remove(pool);
  9344. }
  9345. else
  9346. {
  9347. if (pool == lane)
  9348. {
  9349. lane = lanes[lanes.length - 1];
  9350. }
  9351. model.remove(lane);
  9352. }
  9353. }
  9354. finally
  9355. {
  9356. model.endUpdate();
  9357. }
  9358. };
  9359. /**
  9360. * Inserts a row in the table for the given cell.
  9361. */
  9362. Graph.prototype.insertLane = function(cell, before)
  9363. {
  9364. var model = this.getModel();
  9365. model.beginUpdate();
  9366. try
  9367. {
  9368. var pool = null;
  9369. var lane = cell;
  9370. var style = this.getCurrentCellStyle(lane);
  9371. if (style['childLayout'] == 'stackLayout')
  9372. {
  9373. pool = lane;
  9374. var lanes = model.getChildCells(pool, true);
  9375. lane = lanes[(before) ? 0 : lanes.length - 1];
  9376. }
  9377. else
  9378. {
  9379. pool = model.getParent(lane);
  9380. }
  9381. var index = pool.getIndex(lane);
  9382. lane = model.cloneCell(lane, false);
  9383. lane.value = null;
  9384. model.add(pool, lane, index + ((before) ? 0 : 1));
  9385. }
  9386. finally
  9387. {
  9388. model.endUpdate();
  9389. }
  9390. };
  9391. /**
  9392. * Inserts a row in the table for the given cell.
  9393. */
  9394. Graph.prototype.insertTableRow = function(cell, before)
  9395. {
  9396. var model = this.getModel();
  9397. model.beginUpdate();
  9398. try
  9399. {
  9400. var table = cell;
  9401. var row = cell;
  9402. if (this.isTableCell(cell))
  9403. {
  9404. row = model.getParent(cell);
  9405. table = model.getParent(row);
  9406. }
  9407. else if (this.isTableRow(cell))
  9408. {
  9409. table = model.getParent(cell);
  9410. }
  9411. else
  9412. {
  9413. var rows = model.getChildCells(table, true);
  9414. row = rows[(before) ? 0 : rows.length - 1];
  9415. }
  9416. var cells = model.getChildCells(row, true);
  9417. var index = table.getIndex(row);
  9418. row = model.cloneCell(row, false);
  9419. row.value = null;
  9420. var rowGeo = this.getCellGeometry(row);
  9421. if (rowGeo != null)
  9422. {
  9423. for (var i = 0; i < cells.length; i++)
  9424. {
  9425. var cell = model.cloneCell(cells[i], false);
  9426. // Removes value, col/rowspan and alternate bounds
  9427. cell.value = null;
  9428. cell.style = mxUtils.setStyle(mxUtils.setStyle(
  9429. cell.style, 'rowspan', null), 'colspan', null);
  9430. var geo = this.getCellGeometry(cell);
  9431. if (geo != null)
  9432. {
  9433. if (geo.alternateBounds != null)
  9434. {
  9435. geo.width = geo.alternateBounds.width;
  9436. geo.height = geo.alternateBounds.height;
  9437. geo.alternateBounds = null;
  9438. }
  9439. geo.height = rowGeo.height;
  9440. }
  9441. row.insert(cell);
  9442. }
  9443. model.add(table, row, index + ((before) ? 0 : 1));
  9444. var tableGeo = this.getCellGeometry(table);
  9445. if (tableGeo != null)
  9446. {
  9447. tableGeo = tableGeo.clone();
  9448. tableGeo.height += rowGeo.height;
  9449. model.setGeometry(table, tableGeo);
  9450. }
  9451. }
  9452. }
  9453. finally
  9454. {
  9455. model.endUpdate();
  9456. }
  9457. };
  9458. /**
  9459. *
  9460. */
  9461. Graph.prototype.deleteTableColumn = function(cell)
  9462. {
  9463. var model = this.getModel();
  9464. model.beginUpdate();
  9465. try
  9466. {
  9467. var table = cell;
  9468. var row = cell;
  9469. if (this.isTableCell(cell))
  9470. {
  9471. row = model.getParent(cell);
  9472. }
  9473. if (this.isTableRow(row))
  9474. {
  9475. table = model.getParent(row);
  9476. }
  9477. var rows = model.getChildCells(table, true);
  9478. if (rows.length == 0)
  9479. {
  9480. model.remove(table);
  9481. }
  9482. else
  9483. {
  9484. if (!this.isTableRow(row))
  9485. {
  9486. row = rows[0];
  9487. }
  9488. var cells = model.getChildCells(row, true);
  9489. if (cells.length <= 1)
  9490. {
  9491. model.remove(table);
  9492. }
  9493. else
  9494. {
  9495. var index = cells.length - 1;
  9496. if (this.isTableCell(cell))
  9497. {
  9498. index = mxUtils.indexOf(cells, cell);
  9499. }
  9500. var width = 0;
  9501. for (var i = 0; i < rows.length; i++)
  9502. {
  9503. var child = model.getChildCells(rows[i], true)[index];
  9504. model.remove(child);
  9505. var geo = this.getCellGeometry(child);
  9506. if (geo != null)
  9507. {
  9508. width = Math.max(width, geo.width);
  9509. }
  9510. }
  9511. var tableGeo = this.getCellGeometry(table);
  9512. if (tableGeo != null)
  9513. {
  9514. tableGeo = tableGeo.clone();
  9515. tableGeo.width -= width;
  9516. model.setGeometry(table, tableGeo);
  9517. }
  9518. }
  9519. }
  9520. }
  9521. finally
  9522. {
  9523. model.endUpdate();
  9524. }
  9525. };
  9526. /**
  9527. *
  9528. */
  9529. Graph.prototype.deleteTableRow = function(cell)
  9530. {
  9531. var model = this.getModel();
  9532. model.beginUpdate();
  9533. try
  9534. {
  9535. var table = cell;
  9536. var row = cell;
  9537. if (this.isTableCell(cell))
  9538. {
  9539. row = model.getParent(cell);
  9540. cell = row;
  9541. }
  9542. if (this.isTableRow(cell))
  9543. {
  9544. table = model.getParent(row);
  9545. }
  9546. var rows = model.getChildCells(table, true);
  9547. if (rows.length <= 1)
  9548. {
  9549. model.remove(table);
  9550. }
  9551. else
  9552. {
  9553. if (!this.isTableRow(row))
  9554. {
  9555. row = rows[rows.length - 1];
  9556. }
  9557. model.remove(row);
  9558. var height = 0;
  9559. var geo = this.getCellGeometry(row);
  9560. if (geo != null)
  9561. {
  9562. height = geo.height;
  9563. }
  9564. var tableGeo = this.getCellGeometry(table);
  9565. if (tableGeo != null)
  9566. {
  9567. tableGeo = tableGeo.clone();
  9568. tableGeo.height -= height;
  9569. model.setGeometry(table, tableGeo);
  9570. }
  9571. }
  9572. }
  9573. finally
  9574. {
  9575. model.endUpdate();
  9576. }
  9577. };
  9578. /**
  9579. * Inserts a new row into the given table.
  9580. */
  9581. Graph.prototype.insertRow = function(table, index)
  9582. {
  9583. var bd = table.tBodies[0];
  9584. var cells = bd.rows[0].cells;
  9585. var cols = 0;
  9586. // Counts columns including colspans
  9587. for (var i = 0; i < cells.length; i++)
  9588. {
  9589. var colspan = cells[i].getAttribute('colspan');
  9590. cols += (colspan != null) ? parseInt(colspan) : 1;
  9591. }
  9592. var row = bd.insertRow(index);
  9593. for (var i = 0; i < cols; i++)
  9594. {
  9595. mxUtils.br(row.insertCell(-1));
  9596. }
  9597. return row.cells[0];
  9598. };
  9599. /**
  9600. * Deletes the given column.
  9601. */
  9602. Graph.prototype.deleteRow = function(table, index)
  9603. {
  9604. table.tBodies[0].deleteRow(index);
  9605. };
  9606. /**
  9607. * Deletes the given column.
  9608. */
  9609. Graph.prototype.insertColumn = function(table, index)
  9610. {
  9611. var hd = table.tHead;
  9612. if (hd != null)
  9613. {
  9614. // TODO: use colIndex
  9615. for (var h = 0; h < hd.rows.length; h++)
  9616. {
  9617. var th = document.createElement('th');
  9618. hd.rows[h].appendChild(th);
  9619. mxUtils.br(th);
  9620. }
  9621. }
  9622. var bd = table.tBodies[0];
  9623. for (var i = 0; i < bd.rows.length; i++)
  9624. {
  9625. var cell = bd.rows[i].insertCell(index);
  9626. mxUtils.br(cell);
  9627. }
  9628. return bd.rows[0].cells[(index >= 0) ? index : bd.rows[0].cells.length - 1];
  9629. };
  9630. /**
  9631. * Deletes the given column.
  9632. */
  9633. Graph.prototype.deleteColumn = function(table, index)
  9634. {
  9635. if (index >= 0)
  9636. {
  9637. var bd = table.tBodies[0];
  9638. var rows = bd.rows;
  9639. for (var i = 0; i < rows.length; i++)
  9640. {
  9641. if (rows[i].cells.length > index)
  9642. {
  9643. rows[i].deleteCell(index);
  9644. }
  9645. }
  9646. }
  9647. };
  9648. /**
  9649. * Inserts the given HTML at the caret position (no undo).
  9650. */
  9651. Graph.prototype.pasteHtmlAtCaret = function(html)
  9652. {
  9653. var sel, range;
  9654. // IE9 and non-IE
  9655. if (window.getSelection)
  9656. {
  9657. sel = window.getSelection();
  9658. if (sel.getRangeAt && sel.rangeCount)
  9659. {
  9660. range = sel.getRangeAt(0);
  9661. range.deleteContents();
  9662. // Range.createContextualFragment() would be useful here but is
  9663. // only relatively recently standardized and is not supported in
  9664. // some browsers (IE9, for one)
  9665. var el = document.createElement("div");
  9666. el.innerHTML = html;
  9667. var frag = document.createDocumentFragment(), node;
  9668. while ((node = el.firstChild))
  9669. {
  9670. lastNode = frag.appendChild(node);
  9671. }
  9672. range.insertNode(frag);
  9673. }
  9674. }
  9675. // IE < 9
  9676. else if ((sel = document.selection) && sel.type != "Control")
  9677. {
  9678. // FIXME: Does not work if selection is empty
  9679. sel.createRange().pasteHTML(html);
  9680. }
  9681. };
  9682. /**
  9683. * Creates an anchor elements for handling the given link in the
  9684. * hint that is shown when the cell is selected.
  9685. */
  9686. Graph.prototype.createLinkForHint = function(link, label)
  9687. {
  9688. link = (link != null) ? link : 'javascript:void(0);';
  9689. if (label == null || label.length == 0)
  9690. {
  9691. if (this.isCustomLink(link))
  9692. {
  9693. label = this.getLinkTitle(link);
  9694. }
  9695. else
  9696. {
  9697. label = link;
  9698. }
  9699. }
  9700. // Helper function to shorten strings
  9701. function short(str, max)
  9702. {
  9703. if (str.length > max)
  9704. {
  9705. str = str.substring(0, Math.round(max / 2)) + '...' +
  9706. str.substring(str.length - Math.round(max / 4));
  9707. }
  9708. return str;
  9709. };
  9710. var a = document.createElement('a');
  9711. a.setAttribute('rel', this.linkRelation);
  9712. a.setAttribute('href', this.getAbsoluteUrl(link));
  9713. a.setAttribute('title', short((this.isCustomLink(link)) ?
  9714. this.getLinkTitle(link) : link, 80));
  9715. if (this.linkTarget != null)
  9716. {
  9717. a.setAttribute('target', this.linkTarget);
  9718. }
  9719. // Adds shortened label to link
  9720. mxUtils.write(a, short(label, 40));
  9721. // Handles custom links
  9722. if (this.isCustomLink(link))
  9723. {
  9724. mxEvent.addListener(a, 'click', mxUtils.bind(this, function(evt)
  9725. {
  9726. this.customLinkClicked(link);
  9727. mxEvent.consume(evt);
  9728. }));
  9729. }
  9730. return a;
  9731. };
  9732. /**
  9733. * Customized graph for touch devices.
  9734. */
  9735. Graph.prototype.initTouch = function()
  9736. {
  9737. // Disables new connections via "hotspot"
  9738. this.connectionHandler.marker.isEnabled = function()
  9739. {
  9740. return this.graph.connectionHandler.first != null;
  9741. };
  9742. // Hides menu when editing starts
  9743. this.addListener(mxEvent.START_EDITING, function(sender, evt)
  9744. {
  9745. this.popupMenuHandler.hideMenu();
  9746. });
  9747. // Adds custom hit detection if native hit detection found no cell
  9748. var graphUpdateMouseEvent = this.updateMouseEvent;
  9749. this.updateMouseEvent = function(me)
  9750. {
  9751. me = graphUpdateMouseEvent.apply(this, arguments);
  9752. if (mxEvent.isTouchEvent(me.getEvent()) && me.getState() == null)
  9753. {
  9754. var cell = this.getCellAt(me.graphX, me.graphY);
  9755. if (cell != null && this.isSwimlane(cell) && this.hitsSwimlaneContent(cell, me.graphX, me.graphY))
  9756. {
  9757. cell = null;
  9758. }
  9759. else
  9760. {
  9761. me.state = this.view.getState(cell);
  9762. if (me.state != null && me.state.shape != null)
  9763. {
  9764. this.container.style.cursor = me.state.shape.node.style.cursor;
  9765. }
  9766. }
  9767. }
  9768. if (me.getState() == null && this.isEnabled())
  9769. {
  9770. this.container.style.cursor = 'default';
  9771. }
  9772. return me;
  9773. };
  9774. // Context menu trigger implementation depending on current selection state
  9775. // combined with support for normal popup trigger.
  9776. var cellSelected = false;
  9777. var selectionEmpty = false;
  9778. var menuShowing = false;
  9779. var oldFireMouseEvent = this.fireMouseEvent;
  9780. this.fireMouseEvent = function(evtName, me, sender)
  9781. {
  9782. if (evtName == mxEvent.MOUSE_DOWN)
  9783. {
  9784. // For hit detection on edges
  9785. me = this.updateMouseEvent(me);
  9786. cellSelected = this.isCellSelected(me.getCell());
  9787. selectionEmpty = this.isSelectionEmpty();
  9788. menuShowing = this.popupMenuHandler.isMenuShowing();
  9789. }
  9790. oldFireMouseEvent.apply(this, arguments);
  9791. };
  9792. // Shows popup menu if cell was selected or selection was empty and background was clicked
  9793. // FIXME: Conflicts with mxPopupMenuHandler.prototype.getCellForPopupEvent in Editor.js by
  9794. // selecting parent for selected children in groups before this check can be made.
  9795. this.popupMenuHandler.mouseUp = mxUtils.bind(this, function(sender, me)
  9796. {
  9797. var isMouseEvent = mxEvent.isMouseEvent(me.getEvent());
  9798. this.popupMenuHandler.popupTrigger = !this.isEditing() && this.isEnabled() &&
  9799. (me.getState() == null || !me.isSource(me.getState().control)) &&
  9800. (this.popupMenuHandler.popupTrigger || (!menuShowing && !isMouseEvent &&
  9801. ((selectionEmpty && me.getCell() == null && this.isSelectionEmpty()) ||
  9802. (cellSelected && this.isCellSelected(me.getCell())))));
  9803. // Delays popup menu to allow for double tap to start editing
  9804. var popup = (!cellSelected || isMouseEvent) ? null : mxUtils.bind(this, function(cell)
  9805. {
  9806. window.setTimeout(mxUtils.bind(this, function()
  9807. {
  9808. if (!this.isEditing())
  9809. {
  9810. var origin = mxUtils.getScrollOrigin();
  9811. this.popupMenuHandler.popup(me.getX() + origin.x + 1,
  9812. me.getY() + origin.y + 1, cell, me.getEvent());
  9813. }
  9814. }), 500);
  9815. });
  9816. mxPopupMenuHandler.prototype.mouseUp.apply(this.popupMenuHandler, [sender, me, popup]);
  9817. });
  9818. };
  9819. /**
  9820. * HTML in-place editor
  9821. */
  9822. mxCellEditor.prototype.isContentEditing = function()
  9823. {
  9824. var state = this.graph.view.getState(this.editingCell);
  9825. return state != null && state.style['html'] == 1;
  9826. };
  9827. /**
  9828. * Returns true if all selected text is inside a table element.
  9829. */
  9830. mxCellEditor.prototype.isTableSelected = function()
  9831. {
  9832. return this.graph.getParentByName(
  9833. this.graph.getSelectedElement(),
  9834. 'TABLE', this.textarea) != null;
  9835. };
  9836. /**
  9837. * Returns true if text is selected.
  9838. */
  9839. mxCellEditor.prototype.isTextSelected = function()
  9840. {
  9841. var txt = '';
  9842. if (window.getSelection)
  9843. {
  9844. txt = window.getSelection();
  9845. }
  9846. else if (document.getSelection)
  9847. {
  9848. txt = document.getSelection();
  9849. }
  9850. else if (document.selection)
  9851. {
  9852. txt = document.selection.createRange().text;
  9853. }
  9854. return txt != '';
  9855. };
  9856. /**
  9857. * Inserts a tab at the cursor position.
  9858. */
  9859. mxCellEditor.prototype.insertTab = function(spaces)
  9860. {
  9861. var editor = this.textarea;
  9862. var doc = editor.ownerDocument.defaultView;
  9863. var sel = doc.getSelection();
  9864. var range = sel.getRangeAt(0);
  9865. var str = '\t';
  9866. if (spaces != null)
  9867. {
  9868. str = '';
  9869. while (spaces > 0)
  9870. {
  9871. str += '\xa0';
  9872. spaces--;
  9873. }
  9874. }
  9875. // LATER: Fix normalized tab after editing plain text labels
  9876. var tabNode = document.createElement('span');
  9877. tabNode.style.whiteSpace = 'pre';
  9878. tabNode.appendChild(document.createTextNode(str));
  9879. range.insertNode(tabNode);
  9880. range.setStartAfter(tabNode);
  9881. range.setEndAfter(tabNode);
  9882. sel.removeAllRanges();
  9883. sel.addRange(range);
  9884. };
  9885. /**
  9886. * Sets the alignment of the current selected cell. This sets the
  9887. * alignment in the cell style, removes all alignment within the
  9888. * text and invokes the built-in alignment function.
  9889. *
  9890. * Only the built-in function is invoked if shift is pressed or
  9891. * if table cells are selected and shift is not pressed.
  9892. */
  9893. mxCellEditor.prototype.alignText = function(align, evt)
  9894. {
  9895. var shiftPressed = evt != null && mxEvent.isShiftDown(evt);
  9896. if (shiftPressed || (window.getSelection != null && window.getSelection().containsNode != null))
  9897. {
  9898. var allSelected = true;
  9899. this.graph.processElements(this.textarea, function(node)
  9900. {
  9901. if (shiftPressed || window.getSelection().containsNode(node, true))
  9902. {
  9903. node.removeAttribute('align');
  9904. node.style.textAlign = null;
  9905. }
  9906. else
  9907. {
  9908. allSelected = false;
  9909. }
  9910. });
  9911. if (allSelected)
  9912. {
  9913. this.graph.cellEditor.setAlign(align);
  9914. }
  9915. }
  9916. document.execCommand('justify' + align.toLowerCase(), false, null);
  9917. };
  9918. /**
  9919. * Creates the keyboard event handler for the current graph and history.
  9920. */
  9921. mxCellEditor.prototype.saveSelection = function()
  9922. {
  9923. if (window.getSelection)
  9924. {
  9925. var sel = window.getSelection();
  9926. if (sel.getRangeAt && sel.rangeCount)
  9927. {
  9928. var ranges = [];
  9929. for (var i = 0, len = sel.rangeCount; i < len; ++i)
  9930. {
  9931. ranges.push(sel.getRangeAt(i));
  9932. }
  9933. return ranges;
  9934. }
  9935. }
  9936. else if (document.selection && document.selection.createRange)
  9937. {
  9938. return document.selection.createRange();
  9939. }
  9940. return null;
  9941. };
  9942. /**
  9943. * Creates the keyboard event handler for the current graph and history.
  9944. */
  9945. mxCellEditor.prototype.restoreSelection = function(savedSel)
  9946. {
  9947. try
  9948. {
  9949. if (savedSel)
  9950. {
  9951. if (window.getSelection)
  9952. {
  9953. sel = window.getSelection();
  9954. sel.removeAllRanges();
  9955. for (var i = 0, len = savedSel.length; i < len; ++i)
  9956. {
  9957. sel.addRange(savedSel[i]);
  9958. }
  9959. }
  9960. else if (document.selection && savedSel.select)
  9961. {
  9962. savedSel.select();
  9963. }
  9964. }
  9965. }
  9966. catch (e)
  9967. {
  9968. // ignore
  9969. }
  9970. };
  9971. /**
  9972. * Handling of special nl2Br style for not converting newlines to breaks in HTML labels.
  9973. * NOTE: Since it's easier to set this when the label is created we assume that it does
  9974. * not change during the lifetime of the mxText instance.
  9975. */
  9976. var mxCellRendererInitializeLabel = mxCellRenderer.prototype.initializeLabel;
  9977. mxCellRenderer.prototype.initializeLabel = function(state)
  9978. {
  9979. if (state.text != null)
  9980. {
  9981. state.text.replaceLinefeeds = mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  9982. }
  9983. mxCellRendererInitializeLabel.apply(this, arguments);
  9984. };
  9985. var mxConstraintHandlerUpdate = mxConstraintHandler.prototype.update;
  9986. mxConstraintHandler.prototype.update = function(me, source)
  9987. {
  9988. if (this.isKeepFocusEvent(me) || !mxEvent.isAltDown(me.getEvent()))
  9989. {
  9990. mxConstraintHandlerUpdate.apply(this, arguments);
  9991. }
  9992. else
  9993. {
  9994. this.reset();
  9995. }
  9996. };
  9997. /**
  9998. * No dashed shapes.
  9999. */
  10000. mxGuide.prototype.createGuideShape = function(horizontal)
  10001. {
  10002. var guide = new mxPolyline([], mxConstants.GUIDE_COLOR, mxConstants.GUIDE_STROKEWIDTH);
  10003. return guide;
  10004. };
  10005. /**
  10006. * HTML in-place editor
  10007. */
  10008. mxCellEditor.prototype.escapeCancelsEditing = false;
  10009. /**
  10010. * Overridden to set CSS classes.
  10011. */
  10012. var mxCellEditorStartEditing = mxCellEditor.prototype.startEditing;
  10013. mxCellEditor.prototype.startEditing = function(cell, trigger)
  10014. {
  10015. cell = this.graph.getStartEditingCell(cell, trigger);
  10016. mxCellEditorStartEditing.apply(this, arguments);
  10017. // Overrides class in case of HTML content to add
  10018. // dashed borders for divs and table cells
  10019. var state = this.graph.view.getState(cell);
  10020. if (state != null && state.style['html'] == 1)
  10021. {
  10022. this.textarea.className = 'mxCellEditor geContentEditable';
  10023. }
  10024. else
  10025. {
  10026. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  10027. }
  10028. // Toggles markup vs wysiwyg mode
  10029. this.codeViewMode = false;
  10030. // Stores current selection range when switching between markup and code
  10031. this.switchSelectionState = null;
  10032. // Selects editing cell
  10033. this.graph.setSelectionCell(cell);
  10034. // Enables focus outline for edges and edge labels
  10035. var parent = this.graph.getModel().getParent(cell);
  10036. var geo = this.graph.getCellGeometry(cell);
  10037. if ((this.graph.getModel().isEdge(parent) && geo != null && geo.relative) ||
  10038. this.graph.getModel().isEdge(cell))
  10039. {
  10040. // IE>8 and FF on Windows uses outline default of none
  10041. if (mxClient.IS_IE || mxClient.IS_IE11 || (mxClient.IS_FF && mxClient.IS_WIN))
  10042. {
  10043. this.textarea.style.outline = 'gray dotted 1px';
  10044. }
  10045. else
  10046. {
  10047. this.textarea.style.outline = '';
  10048. }
  10049. }
  10050. }
  10051. /**
  10052. * HTML in-place editor
  10053. */
  10054. var cellEditorInstallListeners = mxCellEditor.prototype.installListeners;
  10055. mxCellEditor.prototype.installListeners = function(elt)
  10056. {
  10057. cellEditorInstallListeners.apply(this, arguments);
  10058. // Adds a reference from the clone to the original node, recursively
  10059. function reference(node, clone)
  10060. {
  10061. clone.originalNode = node;
  10062. node = node.firstChild;
  10063. var child = clone.firstChild;
  10064. while (node != null && child != null)
  10065. {
  10066. reference(node, child);
  10067. node = node.nextSibling;
  10068. child = child.nextSibling;
  10069. }
  10070. return clone;
  10071. };
  10072. // Checks the given node for new nodes, recursively
  10073. function checkNode(node, clone)
  10074. {
  10075. if (node != null)
  10076. {
  10077. if (clone.originalNode != node)
  10078. {
  10079. cleanNode(node);
  10080. }
  10081. else
  10082. {
  10083. node = node.firstChild;
  10084. clone = clone.firstChild;
  10085. while (node != null)
  10086. {
  10087. var nextNode = node.nextSibling;
  10088. if (clone == null)
  10089. {
  10090. cleanNode(node);
  10091. }
  10092. else
  10093. {
  10094. checkNode(node, clone);
  10095. clone = clone.nextSibling;
  10096. }
  10097. node = nextNode;
  10098. }
  10099. }
  10100. }
  10101. };
  10102. // Removes unused DOM nodes and attributes, recursively
  10103. function cleanNode(node)
  10104. {
  10105. var child = node.firstChild;
  10106. while (child != null)
  10107. {
  10108. var next = child.nextSibling;
  10109. cleanNode(child);
  10110. child = next;
  10111. }
  10112. if ((node.nodeType != 1 || (node.nodeName !== 'BR' && node.firstChild == null)) &&
  10113. (node.nodeType != 3 || mxUtils.trim(mxUtils.getTextContent(node)).length == 0))
  10114. {
  10115. node.parentNode.removeChild(node);
  10116. }
  10117. else
  10118. {
  10119. // Removes linefeeds
  10120. if (node.nodeType == 3)
  10121. {
  10122. mxUtils.setTextContent(node, mxUtils.getTextContent(node).replace(/\n|\r/g, ''));
  10123. }
  10124. // Removes CSS classes and styles (for Word and Excel)
  10125. if (node.nodeType == 1)
  10126. {
  10127. node.removeAttribute('style');
  10128. node.removeAttribute('class');
  10129. node.removeAttribute('width');
  10130. node.removeAttribute('cellpadding');
  10131. node.removeAttribute('cellspacing');
  10132. node.removeAttribute('border');
  10133. }
  10134. }
  10135. };
  10136. // Handles paste from Word, Excel etc by removing styles, classnames and unused nodes
  10137. // LATER: Fix undo/redo for paste
  10138. if (document.documentMode !== 7 && document.documentMode !== 8)
  10139. {
  10140. mxEvent.addListener(this.textarea, 'paste', mxUtils.bind(this, function(evt)
  10141. {
  10142. var clone = reference(this.textarea, this.textarea.cloneNode(true));
  10143. window.setTimeout(mxUtils.bind(this, function()
  10144. {
  10145. if (this.textarea != null)
  10146. {
  10147. // Paste from Word or Excel
  10148. if (this.textarea.innerHTML.indexOf('<o:OfficeDocumentSettings>') >= 0 ||
  10149. this.textarea.innerHTML.indexOf('<!--[if !mso]>') >= 0)
  10150. {
  10151. checkNode(this.textarea, clone);
  10152. }
  10153. else
  10154. {
  10155. Graph.removePasteFormatting(this.textarea);
  10156. }
  10157. }
  10158. }), 0);
  10159. }));
  10160. }
  10161. };
  10162. mxCellEditor.prototype.toggleViewMode = function()
  10163. {
  10164. var state = this.graph.view.getState(this.editingCell);
  10165. if (state != null)
  10166. {
  10167. var nl2Br = state != null && mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  10168. var tmp = this.saveSelection();
  10169. if (!this.codeViewMode)
  10170. {
  10171. // Clears the initial empty label on the first keystroke
  10172. if (this.clearOnChange && this.textarea.innerHTML == this.getEmptyLabelText())
  10173. {
  10174. this.clearOnChange = false;
  10175. this.textarea.innerHTML = '';
  10176. }
  10177. // Removes newlines from HTML and converts breaks to newlines
  10178. // to match the HTML output in plain text
  10179. var content = mxUtils.htmlEntities(this.textarea.innerHTML);
  10180. // Workaround for trailing line breaks being ignored in the editor
  10181. if (document.documentMode != 8)
  10182. {
  10183. content = mxUtils.replaceTrailingNewlines(content, '<div><br></div>');
  10184. }
  10185. content = this.graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '').replace(/&lt;br\s*.?&gt;/g, '<br>') : content, true);
  10186. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  10187. var size = mxConstants.DEFAULT_FONTSIZE;
  10188. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  10189. this.textarea.style.fontSize = Math.round(size) + 'px';
  10190. this.textarea.style.textDecoration = '';
  10191. this.textarea.style.fontWeight = 'normal';
  10192. this.textarea.style.fontStyle = '';
  10193. this.textarea.style.fontFamily = mxConstants.DEFAULT_FONTFAMILY;
  10194. this.textarea.style.textAlign = 'left';
  10195. this.textarea.style.width = '';
  10196. // Adds padding to make cursor visible with borders
  10197. this.textarea.style.padding = '2px';
  10198. if (this.textarea.innerHTML != content)
  10199. {
  10200. this.textarea.innerHTML = content;
  10201. }
  10202. this.codeViewMode = true;
  10203. }
  10204. else
  10205. {
  10206. var content = mxUtils.extractTextWithWhitespace(this.textarea.childNodes);
  10207. // Strips trailing line break
  10208. if (content.length > 0 && content.charAt(content.length - 1) == '\n')
  10209. {
  10210. content = content.substring(0, content.length - 1);
  10211. }
  10212. content = this.graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '<br/>') : content, true)
  10213. this.textarea.className = 'mxCellEditor geContentEditable';
  10214. var size = mxUtils.getValue(state.style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  10215. var family = mxUtils.getValue(state.style, mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY);
  10216. var align = mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_LEFT);
  10217. var bold = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  10218. mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD;
  10219. var italic = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  10220. mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC;
  10221. var txtDecor = [];
  10222. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  10223. mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  10224. {
  10225. txtDecor.push('underline');
  10226. }
  10227. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  10228. mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  10229. {
  10230. txtDecor.push('line-through');
  10231. }
  10232. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  10233. this.textarea.style.fontSize = Math.round(size) + 'px';
  10234. this.textarea.style.textDecoration = txtDecor.join(' ');
  10235. this.textarea.style.fontWeight = (bold) ? 'bold' : 'normal';
  10236. this.textarea.style.fontStyle = (italic) ? 'italic' : '';
  10237. this.textarea.style.fontFamily = family;
  10238. this.textarea.style.textAlign = align;
  10239. this.textarea.style.padding = '0px';
  10240. if (this.textarea.innerHTML != content)
  10241. {
  10242. this.textarea.innerHTML = content;
  10243. if (this.textarea.innerHTML.length == 0)
  10244. {
  10245. this.textarea.innerHTML = this.getEmptyLabelText();
  10246. this.clearOnChange = this.textarea.innerHTML.length > 0;
  10247. }
  10248. }
  10249. this.codeViewMode = false;
  10250. }
  10251. this.textarea.focus();
  10252. if (this.switchSelectionState != null)
  10253. {
  10254. this.restoreSelection(this.switchSelectionState);
  10255. }
  10256. this.switchSelectionState = tmp;
  10257. this.resize();
  10258. }
  10259. };
  10260. var mxCellEditorResize = mxCellEditor.prototype.resize;
  10261. mxCellEditor.prototype.resize = function(state, trigger)
  10262. {
  10263. if (this.textarea != null)
  10264. {
  10265. var state = this.graph.getView().getState(this.editingCell);
  10266. if (this.codeViewMode && state != null)
  10267. {
  10268. var scale = state.view.scale;
  10269. this.bounds = mxRectangle.fromRectangle(state);
  10270. // General placement of code editor if cell has no size
  10271. // LATER: Fix HTML editor bounds for edge labels
  10272. if (this.bounds.width == 0 && this.bounds.height == 0)
  10273. {
  10274. this.bounds.width = 160 * scale;
  10275. this.bounds.height = 60 * scale;
  10276. var m = (state.text != null) ? state.text.margin : null;
  10277. if (m == null)
  10278. {
  10279. m = mxUtils.getAlignmentAsPoint(mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER),
  10280. mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE));
  10281. }
  10282. this.bounds.x += m.x * this.bounds.width;
  10283. this.bounds.y += m.y * this.bounds.height;
  10284. }
  10285. this.textarea.style.width = Math.round((this.bounds.width - 4) / scale) + 'px';
  10286. this.textarea.style.height = Math.round((this.bounds.height - 4) / scale) + 'px';
  10287. this.textarea.style.overflow = 'auto';
  10288. // Adds scrollbar offset if visible
  10289. if (this.textarea.clientHeight < this.textarea.offsetHeight)
  10290. {
  10291. this.textarea.style.height = Math.round((this.bounds.height / scale)) + (this.textarea.offsetHeight - this.textarea.clientHeight) + 'px';
  10292. this.bounds.height = parseInt(this.textarea.style.height) * scale;
  10293. }
  10294. if (this.textarea.clientWidth < this.textarea.offsetWidth)
  10295. {
  10296. this.textarea.style.width = Math.round((this.bounds.width / scale)) + (this.textarea.offsetWidth - this.textarea.clientWidth) + 'px';
  10297. this.bounds.width = parseInt(this.textarea.style.width) * scale;
  10298. }
  10299. this.textarea.style.left = Math.round(this.bounds.x) + 'px';
  10300. this.textarea.style.top = Math.round(this.bounds.y) + 'px';
  10301. mxUtils.setPrefixedStyle(this.textarea.style, 'transform', 'scale(' + scale + ',' + scale + ')');
  10302. }
  10303. else
  10304. {
  10305. this.textarea.style.height = '';
  10306. this.textarea.style.overflow = '';
  10307. mxCellEditorResize.apply(this, arguments);
  10308. }
  10309. }
  10310. };
  10311. mxCellEditorGetInitialValue = mxCellEditor.prototype.getInitialValue;
  10312. mxCellEditor.prototype.getInitialValue = function(state, trigger)
  10313. {
  10314. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  10315. {
  10316. return mxCellEditorGetInitialValue.apply(this, arguments);
  10317. }
  10318. else
  10319. {
  10320. var result = this.graph.getEditingValue(state.cell, trigger)
  10321. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  10322. {
  10323. result = result.replace(/\n/g, '<br/>');
  10324. }
  10325. result = this.graph.sanitizeHtml(result, true);
  10326. return result;
  10327. }
  10328. };
  10329. mxCellEditorGetCurrentValue = mxCellEditor.prototype.getCurrentValue;
  10330. mxCellEditor.prototype.getCurrentValue = function(state)
  10331. {
  10332. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  10333. {
  10334. return mxCellEditorGetCurrentValue.apply(this, arguments);
  10335. }
  10336. else
  10337. {
  10338. var result = this.graph.sanitizeHtml(this.textarea.innerHTML, true);
  10339. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  10340. {
  10341. result = result.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
  10342. }
  10343. else
  10344. {
  10345. result = result.replace(/\r\n/g, '').replace(/\n/g, '');
  10346. }
  10347. return result;
  10348. }
  10349. };
  10350. var mxCellEditorStopEditing = mxCellEditor.prototype.stopEditing;
  10351. mxCellEditor.prototype.stopEditing = function(cancel)
  10352. {
  10353. // Restores default view mode before applying value
  10354. if (this.codeViewMode)
  10355. {
  10356. this.toggleViewMode();
  10357. }
  10358. mxCellEditorStopEditing.apply(this, arguments);
  10359. // Tries to move focus back to container after editing if possible
  10360. this.focusContainer();
  10361. };
  10362. mxCellEditor.prototype.focusContainer = function()
  10363. {
  10364. try
  10365. {
  10366. this.graph.container.focus();
  10367. }
  10368. catch (e)
  10369. {
  10370. // ignore
  10371. }
  10372. };
  10373. var mxCellEditorApplyValue = mxCellEditor.prototype.applyValue;
  10374. mxCellEditor.prototype.applyValue = function(state, value)
  10375. {
  10376. // Removes empty relative child labels in edges
  10377. this.graph.getModel().beginUpdate();
  10378. try
  10379. {
  10380. mxCellEditorApplyValue.apply(this, arguments);
  10381. if (value == '' && this.graph.isCellDeletable(state.cell) &&
  10382. this.graph.model.getChildCount(state.cell) == 0 &&
  10383. this.graph.isTransparentState(state))
  10384. {
  10385. this.graph.removeCells([state.cell], false);
  10386. }
  10387. }
  10388. finally
  10389. {
  10390. this.graph.getModel().endUpdate();
  10391. }
  10392. };
  10393. /**
  10394. * Returns the background color to be used for the editing box. This returns
  10395. * the label background for edge labels and null for all other cases.
  10396. */
  10397. mxCellEditor.prototype.getBackgroundColor = function(state)
  10398. {
  10399. var color = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, null);
  10400. if ((color == null || color == mxConstants.NONE) &&
  10401. (state.cell.geometry != null && state.cell.geometry.width > 0) &&
  10402. (mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION, 0) != 0 ||
  10403. mxUtils.getValue(state.style, mxConstants.STYLE_HORIZONTAL, 1) == 0))
  10404. {
  10405. color = mxUtils.getValue(state.style, mxConstants.STYLE_FILLCOLOR, null);
  10406. }
  10407. if (color == mxConstants.NONE)
  10408. {
  10409. color = null;
  10410. }
  10411. return color;
  10412. };
  10413. /**
  10414. * Returns the border color to be used for the editing box. This returns
  10415. * the label border for edge labels and null for all other cases.
  10416. */
  10417. mxCellEditor.prototype.getBorderColor = function(state)
  10418. {
  10419. var color = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_BORDERCOLOR, null);
  10420. if ((color == null || color == mxConstants.NONE) &&
  10421. (state.cell.geometry != null && state.cell.geometry.width > 0) &&
  10422. (mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION, 0) != 0 ||
  10423. mxUtils.getValue(state.style, mxConstants.STYLE_HORIZONTAL, 1) == 0))
  10424. {
  10425. color = mxUtils.getValue(state.style, mxConstants.STYLE_STROKECOLOR, null);
  10426. }
  10427. if (color == mxConstants.NONE)
  10428. {
  10429. color = null;
  10430. }
  10431. return color;
  10432. };
  10433. /**
  10434. * Returns the minimum editing size.
  10435. */
  10436. mxCellEditor.prototype.getMinimumSize = function(state)
  10437. {
  10438. var scale = this.graph.getView().scale;
  10439. return new mxRectangle(0, 0, (state.text == null) ? 30 : state.text.size * scale + 20, 30);
  10440. };
  10441. /**
  10442. * Hold Alt to ignore drop target.
  10443. */
  10444. mxGraphHandlerIsValidDropTarget = mxGraphHandler.prototype.isValidDropTarget;
  10445. mxGraphHandler.prototype.isValidDropTarget = function(target, me)
  10446. {
  10447. return mxGraphHandlerIsValidDropTarget.apply(this, arguments) &&
  10448. !mxEvent.isAltDown(me.getEvent);
  10449. };
  10450. /**
  10451. * Hints on handlers
  10452. */
  10453. function createHint()
  10454. {
  10455. var hint = document.createElement('div');
  10456. hint.className = 'geHint';
  10457. hint.style.whiteSpace = 'nowrap';
  10458. hint.style.position = 'absolute';
  10459. return hint;
  10460. };
  10461. /**
  10462. * Format pixels in the given unit
  10463. */
  10464. function formatHintText(pixels, unit)
  10465. {
  10466. switch(unit)
  10467. {
  10468. case mxConstants.POINTS:
  10469. return pixels;
  10470. case mxConstants.MILLIMETERS:
  10471. return (pixels / mxConstants.PIXELS_PER_MM).toFixed(1);
  10472. case mxConstants.METERS:
  10473. return (pixels / (mxConstants.PIXELS_PER_MM * 1000)).toFixed(4);
  10474. case mxConstants.INCHES:
  10475. return (pixels / mxConstants.PIXELS_PER_INCH).toFixed(2);
  10476. }
  10477. };
  10478. mxGraphView.prototype.formatUnitText = function(pixels)
  10479. {
  10480. return pixels? formatHintText(pixels, this.unit) : pixels;
  10481. };
  10482. /**
  10483. * Updates the hint for the current operation.
  10484. */
  10485. mxGraphHandler.prototype.updateHint = function(me)
  10486. {
  10487. if (this.pBounds != null && (this.shape != null || this.livePreviewActive))
  10488. {
  10489. if (this.hint == null)
  10490. {
  10491. this.hint = createHint();
  10492. this.graph.container.appendChild(this.hint);
  10493. }
  10494. var t = this.graph.view.translate;
  10495. var s = this.graph.view.scale;
  10496. var x = this.roundLength((this.bounds.x + this.currentDx) / s - t.x);
  10497. var y = this.roundLength((this.bounds.y + this.currentDy) / s - t.y);
  10498. var unit = this.graph.view.unit;
  10499. this.hint.innerHTML = formatHintText(x, unit) + ', ' + formatHintText(y, unit);
  10500. this.hint.style.left = (this.pBounds.x + this.currentDx +
  10501. Math.round((this.pBounds.width - this.hint.clientWidth) / 2)) + 'px';
  10502. this.hint.style.top = (this.pBounds.y + this.currentDy +
  10503. this.pBounds.height + Editor.hintOffset) + 'px';
  10504. }
  10505. };
  10506. /**
  10507. * Updates the hint for the current operation.
  10508. */
  10509. mxGraphHandler.prototype.removeHint = function()
  10510. {
  10511. if (this.hint != null)
  10512. {
  10513. this.hint.parentNode.removeChild(this.hint);
  10514. this.hint = null;
  10515. }
  10516. };
  10517. /**
  10518. * Overridden to allow for shrinking pools when lanes are resized.
  10519. */
  10520. var stackLayoutResizeCell = mxStackLayout.prototype.resizeCell;
  10521. mxStackLayout.prototype.resizeCell = function(cell, bounds)
  10522. {
  10523. stackLayoutResizeCell.apply(this, arguments);
  10524. var style = this.graph.getCellStyle(cell);
  10525. if (style['childLayout'] == null)
  10526. {
  10527. var parent = this.graph.model.getParent(cell);
  10528. var geo = (parent != null) ? this.graph.getCellGeometry(parent) : null;
  10529. if (geo != null)
  10530. {
  10531. style = this.graph.getCellStyle(parent);
  10532. if (style['childLayout'] == 'stackLayout')
  10533. {
  10534. var border = parseFloat(mxUtils.getValue(style, 'stackBorder', mxStackLayout.prototype.border));
  10535. var horizontal = mxUtils.getValue(style, 'horizontalStack', '1') == '1';
  10536. var start = this.graph.getActualStartSize(parent);
  10537. geo = geo.clone();
  10538. if (horizontal)
  10539. {
  10540. geo.height = bounds.height + start.y + start.height + 2 * border;
  10541. }
  10542. else
  10543. {
  10544. geo.width = bounds.width + start.x + start.width + 2 * border;
  10545. }
  10546. this.graph.model.setGeometry(parent, geo);
  10547. }
  10548. }
  10549. }
  10550. };
  10551. /**
  10552. * Shows handle for table instead of rows and cells.
  10553. */
  10554. var selectionCellsHandlerGetHandledSelectionCells = mxSelectionCellsHandler.prototype.getHandledSelectionCells;
  10555. mxSelectionCellsHandler.prototype.getHandledSelectionCells = function()
  10556. {
  10557. var cells = selectionCellsHandlerGetHandledSelectionCells.apply(this, arguments);
  10558. var dict = new mxDictionary();
  10559. var model = this.graph.model;
  10560. var result = [];
  10561. function addCell(cell)
  10562. {
  10563. if (!dict.get(cell))
  10564. {
  10565. dict.put(cell, true);
  10566. result.push(cell);
  10567. }
  10568. };
  10569. for (var i = 0; i < cells.length; i++)
  10570. {
  10571. var cell = cells[i];
  10572. if (this.graph.isTableCell(cell))
  10573. {
  10574. addCell(model.getParent(model.getParent(cell)));
  10575. }
  10576. else if (this.graph.isTableRow(cell))
  10577. {
  10578. addCell(model.getParent(cell));
  10579. }
  10580. addCell(cell);
  10581. }
  10582. return result;
  10583. };
  10584. /**
  10585. * Creates the shape used to draw the selection border.
  10586. */
  10587. var vertexHandlerCreateParentHighlightShape = mxVertexHandler.prototype.createParentHighlightShape;
  10588. mxVertexHandler.prototype.createParentHighlightShape = function(bounds)
  10589. {
  10590. var shape = vertexHandlerCreateParentHighlightShape.apply(this, arguments);
  10591. shape.stroke = '#C0C0C0';
  10592. shape.strokewidth = 1;
  10593. return shape;
  10594. };
  10595. /**
  10596. * Creates the shape used to draw the selection border.
  10597. */
  10598. var edgeHandlerCreateParentHighlightShape = mxEdgeHandler.prototype.createParentHighlightShape;
  10599. mxEdgeHandler.prototype.createParentHighlightShape = function(bounds)
  10600. {
  10601. var shape = edgeHandlerCreateParentHighlightShape.apply(this, arguments);
  10602. shape.stroke = '#C0C0C0';
  10603. shape.strokewidth = 1;
  10604. return shape;
  10605. };
  10606. /**
  10607. * Moves rotation handle to top, right corner.
  10608. */
  10609. mxVertexHandler.prototype.rotationHandleVSpacing = -12;
  10610. mxVertexHandler.prototype.getRotationHandlePosition = function()
  10611. {
  10612. var padding = this.getHandlePadding();
  10613. return new mxPoint(this.bounds.x + this.bounds.width - this.rotationHandleVSpacing + padding.x / 2,
  10614. this.bounds.y + this.rotationHandleVSpacing - padding.y / 2)
  10615. };
  10616. /**
  10617. * Enables recursive resize for groups.
  10618. */
  10619. mxVertexHandler.prototype.isRecursiveResize = function(state, me)
  10620. {
  10621. return this.graph.isRecursiveVertexResize(state) &&
  10622. !mxEvent.isAltDown(me.getEvent());
  10623. };
  10624. /**
  10625. * Enables centered resize events.
  10626. */
  10627. mxVertexHandler.prototype.isCenteredEvent = function(state, me)
  10628. {
  10629. return mxEvent.isControlDown(me.getEvent()) ||
  10630. mxEvent.isMetaDown(me.getEvent());
  10631. };
  10632. /**
  10633. * Hides rotation handle for table cells and rows.
  10634. */
  10635. var vertexHandlerIsRotationHandleVisible = mxVertexHandler.prototype.isRotationHandleVisible;
  10636. mxVertexHandler.prototype.isRotationHandleVisible = function()
  10637. {
  10638. return vertexHandlerIsRotationHandleVisible.apply(this, arguments) &&
  10639. !this.graph.isTableCell(this.state.cell) &&
  10640. !this.graph.isTableRow(this.state.cell) &&
  10641. !this.graph.isTable(this.state.cell);
  10642. };
  10643. /**
  10644. * Hides rotation handle for table cells and rows.
  10645. */
  10646. mxVertexHandler.prototype.getSizerBounds = function()
  10647. {
  10648. if (this.graph.isTableCell(this.state.cell))
  10649. {
  10650. return this.graph.view.getState(this.graph.model.getParent(this.graph.model.getParent(this.state.cell)));
  10651. }
  10652. else
  10653. {
  10654. return this.bounds;
  10655. }
  10656. };
  10657. /**
  10658. * Hides rotation handle for table cells and rows.
  10659. */
  10660. var vertexHandlerIsParentHighlightVisible = mxVertexHandler.prototype.isParentHighlightVisible;
  10661. mxVertexHandler.prototype.isParentHighlightVisible = function()
  10662. {
  10663. return vertexHandlerIsParentHighlightVisible.apply(this, arguments) &&
  10664. !this.graph.isTableCell(this.state.cell) &&
  10665. !this.graph.isTableRow(this.state.cell);
  10666. };
  10667. /**
  10668. * Hides rotation handle for table cells and rows.
  10669. */
  10670. var vertexHandlerIsCustomHandleVisible = mxVertexHandler.prototype.isCustomHandleVisible;
  10671. mxVertexHandler.prototype.isCustomHandleVisible = function(handle)
  10672. {
  10673. return handle.tableHandle ||
  10674. (vertexHandlerIsCustomHandleVisible.apply(this, arguments) &&
  10675. (!this.graph.isTable(this.state.cell) ||
  10676. this.graph.isCellSelected(this.state.cell)));
  10677. };
  10678. /**
  10679. * Adds selection border inset for table cells and rows.
  10680. */
  10681. mxVertexHandler.prototype.getSelectionBorderInset = function()
  10682. {
  10683. var result = 0;
  10684. if (this.graph.isTableRow(this.state.cell))
  10685. {
  10686. result = 1;
  10687. }
  10688. else if (this.graph.isTableCell(this.state.cell))
  10689. {
  10690. result = 2;
  10691. }
  10692. return result;
  10693. };
  10694. /**
  10695. * Adds custom handles for table cells.
  10696. */
  10697. var vertexHandlerGetSelectionBorderBounds = mxVertexHandler.prototype.getSelectionBorderBounds;
  10698. mxVertexHandler.prototype.getSelectionBorderBounds = function()
  10699. {
  10700. return vertexHandlerGetSelectionBorderBounds.apply(this, arguments).grow(
  10701. -this.getSelectionBorderInset());
  10702. };
  10703. var TableLineShape = null;
  10704. /**
  10705. * Adds custom handles for table cells.
  10706. */
  10707. var vertexHandlerCreateCustomHandles = mxVertexHandler.prototype.createCustomHandles;
  10708. mxVertexHandler.prototype.createCustomHandles = function()
  10709. {
  10710. // Lazy lookup for shape constructor
  10711. if (TableLineShape == null)
  10712. {
  10713. TableLineShape = mxCellRenderer.defaultShapes['tableLine'];
  10714. }
  10715. var handles = vertexHandlerCreateCustomHandles.apply(this, arguments);
  10716. if (this.graph.isTable(this.state.cell))
  10717. {
  10718. var self = this;
  10719. var graph = this.graph;
  10720. var model = graph.model;
  10721. var s = graph.view.scale;
  10722. var tableState = this.state;
  10723. var sel = this.selectionBorder;
  10724. var x0 = this.state.origin.x + graph.view.translate.x;
  10725. var y0 = this.state.origin.y + graph.view.translate.y;
  10726. if (handles == null)
  10727. {
  10728. handles = [];
  10729. }
  10730. function moveLine(line, dx, dy)
  10731. {
  10732. var result = [];
  10733. for (var i = 0; i < line.length; i++)
  10734. {
  10735. var pt = line[i];
  10736. result.push((pt == null) ? null : new mxPoint(
  10737. (x0 + pt.x + dx) * s, (y0 + pt.y + dy) * s));
  10738. }
  10739. return result;
  10740. };
  10741. // Adds handles for rows and columns
  10742. var rows = graph.view.getCellStates(model.getChildCells(this.state.cell, true));
  10743. if (rows.length > 0)
  10744. {
  10745. var cols = model.getChildCells(rows[0].cell, true);
  10746. var colLines = graph.getTableLines(this.state.cell, false, true);
  10747. var rowLines = graph.getTableLines(this.state.cell, true, false);
  10748. // Adds row height handles
  10749. for (var i = 0; i < rows.length; i++)
  10750. {
  10751. (mxUtils.bind(this, function(index)
  10752. {
  10753. var rowState = rows[index];
  10754. var nextRow = (index < rows.length - 1) ? rows[index + 1] : null;
  10755. var ngeo = (nextRow != null) ? graph.getCellGeometry(nextRow.cell) : null;
  10756. var ng = (ngeo != null && ngeo.alternateBounds != null) ? ngeo.alternateBounds : ngeo;
  10757. var shape = (rowLines[index] != null) ?
  10758. new TableLineShape(rowLines[index], mxConstants.NONE, 1) :
  10759. new mxLine(new mxRectangle(), mxConstants.NONE, 1, false);
  10760. shape.isDashed = sel.isDashed;
  10761. shape.svgStrokeTolerance++;
  10762. var handle = new mxHandle(rowState, 'row-resize', null, shape);
  10763. handle.tableHandle = true;
  10764. var dy = 0;
  10765. handle.shape.node.parentNode.insertBefore(handle.shape.node,
  10766. handle.shape.node.parentNode.firstChild);
  10767. handle.redraw = function()
  10768. {
  10769. if (this.shape != null)
  10770. {
  10771. this.shape.stroke = (dy == 0) ? mxConstants.NONE : sel.stroke;
  10772. if (this.shape.constructor == TableLineShape)
  10773. {
  10774. this.shape.line = moveLine(rowLines[index], 0, dy);
  10775. this.shape.updateBoundsFromLine();
  10776. }
  10777. else
  10778. {
  10779. var start = graph.getActualStartSize(tableState.cell, true);
  10780. this.shape.bounds.height = 1;
  10781. this.shape.bounds.y = this.state.y + this.state.height + dy * s;
  10782. this.shape.bounds.x = tableState.x + ((index == rows.length - 1) ?
  10783. 0 : start.x * s);
  10784. this.shape.bounds.width = tableState.width - ((index == rows.length - 1) ?
  10785. 0 : (start.width + start.x) + s);
  10786. }
  10787. this.shape.redraw();
  10788. }
  10789. };
  10790. var shiftPressed = false;
  10791. handle.setPosition = function(bounds, pt, me)
  10792. {
  10793. dy = Math.max(Graph.minTableRowHeight - bounds.height,
  10794. pt.y - bounds.y - bounds.height);
  10795. shiftPressed = mxEvent.isShiftDown(me.getEvent());
  10796. if (ng != null && shiftPressed)
  10797. {
  10798. dy = Math.min(dy, ng.height - Graph.minTableRowHeight);
  10799. }
  10800. };
  10801. handle.execute = function(me)
  10802. {
  10803. if (dy != 0)
  10804. {
  10805. graph.setTableRowHeight(this.state.cell,
  10806. dy, !shiftPressed);
  10807. }
  10808. else if (!self.blockDelayedSelection)
  10809. {
  10810. var temp = graph.getCellAt(me.getGraphX(),
  10811. me.getGraphY()) || tableState.cell;
  10812. graph.graphHandler.selectCellForEvent(temp, me);
  10813. }
  10814. dy = 0;
  10815. };
  10816. handle.reset = function()
  10817. {
  10818. dy = 0;
  10819. };
  10820. handles.push(handle);
  10821. }))(i);
  10822. }
  10823. // Adds column width handles
  10824. for (var i = 0; i < cols.length; i++)
  10825. {
  10826. (mxUtils.bind(this, function(index)
  10827. {
  10828. var colState = graph.view.getState(cols[index]);
  10829. var geo = graph.getCellGeometry(cols[index]);
  10830. var g = (geo.alternateBounds != null) ? geo.alternateBounds : geo;
  10831. if (colState == null)
  10832. {
  10833. colState = new mxCellState(graph.view, cols[index],
  10834. graph.getCellStyle(cols[index]));
  10835. colState.x = tableState.x + geo.x * s;
  10836. colState.y = tableState.y + geo.y * s;
  10837. colState.width = g.width * s;
  10838. colState.height = g.height * s;
  10839. colState.updateCachedBounds();
  10840. }
  10841. var nextCol = (index < cols.length - 1) ? cols[index + 1] : null;
  10842. var ngeo = (nextCol != null) ? graph.getCellGeometry(nextCol) : null;
  10843. var ng = (ngeo != null && ngeo.alternateBounds != null) ? ngeo.alternateBounds : ngeo;
  10844. var shape = (colLines[index] != null) ?
  10845. new TableLineShape(colLines[index], mxConstants.NONE, 1) :
  10846. new mxLine(new mxRectangle(), mxConstants.NONE, 1, true);
  10847. shape.isDashed = sel.isDashed;
  10848. // Workaround for event handling on overlapping cells with tolerance
  10849. shape.svgStrokeTolerance++;
  10850. var handle = new mxHandle(colState, 'col-resize', null, shape);
  10851. handle.tableHandle = true;
  10852. var dx = 0;
  10853. handle.shape.node.parentNode.insertBefore(handle.shape.node,
  10854. handle.shape.node.parentNode.firstChild);
  10855. handle.redraw = function()
  10856. {
  10857. if (this.shape != null)
  10858. {
  10859. this.shape.stroke = (dx == 0) ? mxConstants.NONE : sel.stroke;
  10860. if (this.shape.constructor == TableLineShape)
  10861. {
  10862. this.shape.line = moveLine(colLines[index], dx, 0);
  10863. this.shape.updateBoundsFromLine();
  10864. }
  10865. else
  10866. {
  10867. var start = graph.getActualStartSize(tableState.cell, true);
  10868. this.shape.bounds.width = 1;
  10869. this.shape.bounds.x = this.state.x + (g.width + dx) * s;
  10870. this.shape.bounds.y = tableState.y + ((index == cols.length - 1) ?
  10871. 0 : start.y * s);
  10872. this.shape.bounds.height = tableState.height - ((index == cols.length - 1) ?
  10873. 0 : (start.height + start.y) * s);
  10874. }
  10875. this.shape.redraw();
  10876. }
  10877. };
  10878. var shiftPressed = false;
  10879. handle.setPosition = function(bounds, pt, me)
  10880. {
  10881. dx = Math.max(Graph.minTableColumnWidth - g.width,
  10882. pt.x - bounds.x - g.width);
  10883. shiftPressed = mxEvent.isShiftDown(me.getEvent());
  10884. if (ng != null && !shiftPressed)
  10885. {
  10886. dx = Math.min(dx, ng.width - Graph.minTableColumnWidth);
  10887. }
  10888. };
  10889. handle.execute = function(me)
  10890. {
  10891. if (dx != 0)
  10892. {
  10893. graph.setTableColumnWidth(this.state.cell,
  10894. dx, shiftPressed);
  10895. }
  10896. else if (!self.blockDelayedSelection)
  10897. {
  10898. var temp = graph.getCellAt(me.getGraphX(),
  10899. me.getGraphY()) || tableState.cell;
  10900. graph.graphHandler.selectCellForEvent(temp, me);
  10901. }
  10902. dx = 0;
  10903. };
  10904. // Stops repaint of text label via vertex handler
  10905. handle.positionChanged = function()
  10906. {
  10907. // do nothing
  10908. };
  10909. handle.reset = function()
  10910. {
  10911. dx = 0;
  10912. };
  10913. handles.push(handle);
  10914. }))(i);
  10915. }
  10916. }
  10917. }
  10918. // Reserve gives point handles precedence over line handles
  10919. return (handles != null) ? handles.reverse() : null;
  10920. };
  10921. var vertexHandlerSetHandlesVisible = mxVertexHandler.prototype.setHandlesVisible;
  10922. mxVertexHandler.prototype.setHandlesVisible = function(visible)
  10923. {
  10924. vertexHandlerSetHandlesVisible.apply(this, arguments);
  10925. if (this.moveHandles != null)
  10926. {
  10927. for (var i = 0; i < this.moveHandles.length; i++)
  10928. {
  10929. this.moveHandles[i].style.visibility = (visible) ? '' : 'hidden';
  10930. }
  10931. }
  10932. if (this.cornerHandles != null)
  10933. {
  10934. for (var i = 0; i < this.cornerHandles.length; i++)
  10935. {
  10936. this.cornerHandles[i].node.style.visibility = (visible) ? '' : 'hidden';
  10937. }
  10938. }
  10939. };
  10940. /**
  10941. * Creates or updates special handles for moving rows.
  10942. */
  10943. mxVertexHandler.prototype.refreshMoveHandles = function()
  10944. {
  10945. var graph = this.graph;
  10946. var model = graph.model;
  10947. // Destroys existing handles
  10948. if (this.moveHandles != null)
  10949. {
  10950. for (var i = 0; i < this.moveHandles.length; i++)
  10951. {
  10952. this.moveHandles[i].parentNode.removeChild(this.moveHandles[i]);
  10953. }
  10954. this.moveHandles = null;
  10955. }
  10956. // Creates new handles
  10957. this.moveHandles = [];
  10958. for (var i = 0; i < model.getChildCount(this.state.cell); i++)
  10959. {
  10960. (mxUtils.bind(this, function(rowState)
  10961. {
  10962. if (rowState != null && model.isVertex(rowState.cell))
  10963. {
  10964. // Adds handle to move row
  10965. // LATER: Move to overlay pane to hide during zoom but keep padding
  10966. var moveHandle = mxUtils.createImage(Editor.rowMoveImage);
  10967. moveHandle.style.position = 'absolute';
  10968. moveHandle.style.cursor = 'pointer';
  10969. moveHandle.style.width = '7px';
  10970. moveHandle.style.height = '4px';
  10971. moveHandle.style.padding = '4px 2px 4px 2px';
  10972. moveHandle.rowState = rowState;
  10973. mxEvent.addGestureListeners(moveHandle, mxUtils.bind(this, function(evt)
  10974. {
  10975. this.graph.popupMenuHandler.hideMenu();
  10976. this.graph.stopEditing(false);
  10977. if (this.graph.isToggleEvent(evt) ||
  10978. !this.graph.isCellSelected(rowState.cell))
  10979. {
  10980. this.graph.selectCellForEvent(rowState.cell, evt);
  10981. }
  10982. if (!mxEvent.isPopupTrigger(evt))
  10983. {
  10984. this.graph.graphHandler.start(this.state.cell,
  10985. mxEvent.getClientX(evt), mxEvent.getClientY(evt),
  10986. this.graph.getSelectionCells());
  10987. this.graph.graphHandler.cellWasClicked = true;
  10988. this.graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  10989. this.graph.isMouseDown = true;
  10990. }
  10991. mxEvent.consume(evt);
  10992. }), null, mxUtils.bind(this, function(evt)
  10993. {
  10994. if (mxEvent.isPopupTrigger(evt))
  10995. {
  10996. this.graph.popupMenuHandler.popup(mxEvent.getClientX(evt),
  10997. mxEvent.getClientY(evt), rowState.cell, evt);
  10998. mxEvent.consume(evt);
  10999. }
  11000. }));
  11001. this.moveHandles.push(moveHandle);
  11002. this.graph.container.appendChild(moveHandle);
  11003. }
  11004. }))(this.graph.view.getState(model.getChildAt(this.state.cell, i)));
  11005. }
  11006. };
  11007. /**
  11008. * Adds handle padding for editing cells and exceptions.
  11009. */
  11010. mxVertexHandler.prototype.refresh = function()
  11011. {
  11012. if (this.customHandles != null)
  11013. {
  11014. for (var i = 0; i < this.customHandles.length; i++)
  11015. {
  11016. this.customHandles[i].destroy();
  11017. }
  11018. this.customHandles = this.createCustomHandles();
  11019. }
  11020. if (this.graph.isTable(this.state.cell))
  11021. {
  11022. this.refreshMoveHandles();
  11023. }
  11024. };
  11025. /**
  11026. * Adds handle padding for editing cells and exceptions.
  11027. */
  11028. var vertexHandlerGetHandlePadding = mxVertexHandler.prototype.getHandlePadding;
  11029. mxVertexHandler.prototype.getHandlePadding = function()
  11030. {
  11031. var result = new mxPoint(0, 0);
  11032. var tol = this.tolerance;
  11033. var name = this.state.style['shape'];
  11034. if (mxCellRenderer.defaultShapes[name] == null &&
  11035. mxStencilRegistry.getStencil(name) == null)
  11036. {
  11037. name = mxConstants.SHAPE_RECTANGLE;
  11038. }
  11039. // Checks if custom handles are overlapping with the shape border
  11040. var handlePadding = this.graph.isTable(this.state.cell) ||
  11041. this.graph.cellEditor.getEditingCell() == this.state.cell;
  11042. if (!handlePadding)
  11043. {
  11044. if (this.customHandles != null)
  11045. {
  11046. for (var i = 0; i < this.customHandles.length; i++)
  11047. {
  11048. if (this.customHandles[i].shape != null &&
  11049. this.customHandles[i].shape.bounds != null)
  11050. {
  11051. var b = this.customHandles[i].shape.bounds;
  11052. var px = b.getCenterX();
  11053. var py = b.getCenterY();
  11054. if ((Math.abs(this.state.x - px) < b.width / 2) ||
  11055. (Math.abs(this.state.y - py) < b.height / 2) ||
  11056. (Math.abs(this.state.x + this.state.width - px) < b.width / 2) ||
  11057. (Math.abs(this.state.y + this.state.height - py) < b.height / 2))
  11058. {
  11059. handlePadding = true;
  11060. break;
  11061. }
  11062. }
  11063. }
  11064. }
  11065. }
  11066. if (handlePadding && this.sizers != null &&
  11067. this.sizers.length > 0 && this.sizers[0] != null)
  11068. {
  11069. tol /= 2;
  11070. // Makes room for row move handle
  11071. if (this.graph.isTable(this.state.cell))
  11072. {
  11073. tol += 7;
  11074. }
  11075. result.x = this.sizers[0].bounds.width + tol;
  11076. result.y = this.sizers[0].bounds.height + tol;
  11077. }
  11078. else
  11079. {
  11080. result = vertexHandlerGetHandlePadding.apply(this, arguments);
  11081. }
  11082. return result;
  11083. };
  11084. /**
  11085. * Updates the hint for the current operation.
  11086. */
  11087. mxVertexHandler.prototype.updateHint = function(me)
  11088. {
  11089. if (this.index != mxEvent.LABEL_HANDLE)
  11090. {
  11091. if (this.hint == null)
  11092. {
  11093. this.hint = createHint();
  11094. this.state.view.graph.container.appendChild(this.hint);
  11095. }
  11096. if (this.index == mxEvent.ROTATION_HANDLE)
  11097. {
  11098. this.hint.innerHTML = this.currentAlpha + '&deg;';
  11099. }
  11100. else
  11101. {
  11102. var s = this.state.view.scale;
  11103. var unit = this.state.view.unit;
  11104. this.hint.innerHTML = formatHintText(this.roundLength(this.bounds.width / s), unit) + ' x ' +
  11105. formatHintText(this.roundLength(this.bounds.height / s), unit);
  11106. }
  11107. var rot = (this.currentAlpha != null) ? this.currentAlpha : this.state.style[mxConstants.STYLE_ROTATION] || '0';
  11108. var bb = mxUtils.getBoundingBox(this.bounds, rot);
  11109. if (bb == null)
  11110. {
  11111. bb = this.bounds;
  11112. }
  11113. this.hint.style.left = bb.x + Math.round((bb.width - this.hint.clientWidth) / 2) + 'px';
  11114. this.hint.style.top = (bb.y + bb.height + Editor.hintOffset) + 'px';
  11115. if (this.linkHint != null)
  11116. {
  11117. this.linkHint.style.display = 'none';
  11118. }
  11119. }
  11120. };
  11121. /**
  11122. * Updates the hint for the current operation.
  11123. */
  11124. mxVertexHandler.prototype.removeHint = function()
  11125. {
  11126. mxGraphHandler.prototype.removeHint.apply(this, arguments);
  11127. if (this.linkHint != null)
  11128. {
  11129. this.linkHint.style.display = '';
  11130. }
  11131. };
  11132. /**
  11133. * Hides link hint while moving cells.
  11134. */
  11135. var edgeHandlerMouseMove = mxEdgeHandler.prototype.mouseMove;
  11136. mxEdgeHandler.prototype.mouseMove = function(sender, me)
  11137. {
  11138. edgeHandlerMouseMove.apply(this, arguments);
  11139. if (this.linkHint != null && this.linkHint.style.display != 'none' &&
  11140. this.graph.graphHandler != null && this.graph.graphHandler.first != null)
  11141. {
  11142. this.linkHint.style.display = 'none';
  11143. }
  11144. }
  11145. /**
  11146. * Hides link hint while moving cells.
  11147. */
  11148. var edgeHandlerMouseUp = mxEdgeHandler.prototype.mouseUp;
  11149. mxEdgeHandler.prototype.mouseUp = function(sender, me)
  11150. {
  11151. edgeHandlerMouseUp.apply(this, arguments);
  11152. if (this.linkHint != null && this.linkHint.style.display == 'none')
  11153. {
  11154. this.linkHint.style.display = '';
  11155. }
  11156. }
  11157. /**
  11158. * Updates the hint for the current operation.
  11159. */
  11160. mxEdgeHandler.prototype.updateHint = function(me, point)
  11161. {
  11162. if (this.hint == null)
  11163. {
  11164. this.hint = createHint();
  11165. this.state.view.graph.container.appendChild(this.hint);
  11166. }
  11167. var t = this.graph.view.translate;
  11168. var s = this.graph.view.scale;
  11169. var x = this.roundLength(point.x / s - t.x);
  11170. var y = this.roundLength(point.y / s - t.y);
  11171. var unit = this.graph.view.unit;
  11172. this.hint.innerHTML = formatHintText(x, unit) + ', ' + formatHintText(y, unit);
  11173. this.hint.style.visibility = 'visible';
  11174. if (this.isSource || this.isTarget)
  11175. {
  11176. if (this.constraintHandler.currentConstraint != null &&
  11177. this.constraintHandler.currentFocus != null)
  11178. {
  11179. var pt = this.constraintHandler.currentConstraint.point;
  11180. this.hint.innerHTML = '[' + Math.round(pt.x * 100) + '%, '+ Math.round(pt.y * 100) + '%]';
  11181. }
  11182. else if (this.marker.hasValidState())
  11183. {
  11184. this.hint.style.visibility = 'hidden';
  11185. }
  11186. }
  11187. this.hint.style.left = Math.round(me.getGraphX() - this.hint.clientWidth / 2) + 'px';
  11188. this.hint.style.top = (Math.max(me.getGraphY(), point.y) + Editor.hintOffset) + 'px';
  11189. if (this.linkHint != null)
  11190. {
  11191. this.linkHint.style.display = 'none';
  11192. }
  11193. };
  11194. /**
  11195. * Replaces folding icons with SVG.
  11196. */
  11197. Graph.prototype.expandedImage = Graph.createSvgImage(9, 9, '<defs><linearGradient id="grad1" x1="50%" y1="0%" x2="50%" y2="100%">' +
  11198. '<stop offset="30%" style="stop-color:#f0f0f0;" /><stop offset="100%" style="stop-color:#AFB0B6;" /></linearGradient></defs>' +
  11199. '<rect x="0" y="0" width="9" height="9" stroke="#8A94A5" fill="url(#grad1)" stroke-width="2"/>' +
  11200. '<path d="M 2 4.5 L 7 4.5 z" stroke="#000"/>');
  11201. Graph.prototype.collapsedImage = Graph.createSvgImage(9, 9, '<defs><linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">' +
  11202. '<stop offset="30%" style="stop-color:#f0f0f0;" /><stop offset="100%" style="stop-color:#AFB0B6;" /></linearGradient></defs>' +
  11203. '<rect x="0" y="0" width="9" height="9" stroke="#8A94A5" fill="url(#grad1)" stroke-width="2"/>' +
  11204. '<path d="M 4.5 2 L 4.5 7 M 2 4.5 L 7 4.5 z" stroke="#000"/>');
  11205. /**
  11206. * Updates the hint for the current operation.
  11207. */
  11208. mxEdgeHandler.prototype.removeHint = mxVertexHandler.prototype.removeHint;
  11209. /**
  11210. * Defines the handles for the UI. Uses data-URIs to speed-up loading time where supported.
  11211. */
  11212. HoverIcons.prototype.mainHandle = Graph.createSvgImage(18, 18, '<circle cx="9" cy="9" r="5" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  11213. HoverIcons.prototype.endMainHandle = Graph.createSvgImage(18, 18, '<circle cx="9" cy="9" r="6" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  11214. 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"/>');
  11215. HoverIcons.prototype.fixedHandle = Graph.createSvgImage(22, 22,
  11216. '<circle cx="11" cy="11" r="6" stroke="#fff" fill="#01bd22"/>' +
  11217. '<path d="m 8 8 L 14 14M 8 14 L 14 8" stroke="#fff"/>');
  11218. HoverIcons.prototype.endFixedHandle = Graph.createSvgImage(22, 22,
  11219. '<circle cx="11" cy="11" r="7" stroke="#fff" fill="#01bd22"/>' +
  11220. '<path d="m 8 8 L 14 14M 8 14 L 14 8" stroke="#fff"/>');
  11221. HoverIcons.prototype.terminalHandle = Graph.createSvgImage(22, 22,
  11222. '<circle cx="11" cy="11" r="6" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill +
  11223. '"/><circle cx="11" cy="11" r="3" stroke="#fff" fill="transparent"/>');
  11224. HoverIcons.prototype.endTerminalHandle = Graph.createSvgImage(22, 22,
  11225. '<circle cx="11" cy="11" r="7" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill +
  11226. '"/><circle cx="11" cy="11" r="3" stroke="#fff" fill="transparent"/>');
  11227. HoverIcons.prototype.rotationHandle = Graph.createSvgImage(16, 16,
  11228. '<path stroke="' + HoverIcons.prototype.arrowFill + '" fill="' + HoverIcons.prototype.arrowFill +
  11229. '" 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"/>',
  11230. 24, 24);
  11231. mxConstraintHandler.prototype.pointImage = Graph.createSvgImage(5, 5,
  11232. '<path d="m 0 0 L 5 5 M 0 5 L 5 0" stroke-width="2" style="stroke-opacity:0.4" stroke="#ffffff"/>' +
  11233. '<path d="m 0 0 L 5 5 M 0 5 L 5 0" stroke="' + HoverIcons.prototype.arrowFill + '"/>');
  11234. mxVertexHandler.TABLE_HANDLE_COLOR = '#fca000';
  11235. mxVertexHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  11236. mxVertexHandler.prototype.secondaryHandleImage = HoverIcons.prototype.secondaryHandle;
  11237. mxEdgeHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  11238. mxEdgeHandler.prototype.endHandleImage = HoverIcons.prototype.endMainHandle;
  11239. mxEdgeHandler.prototype.terminalHandleImage = HoverIcons.prototype.terminalHandle;
  11240. mxEdgeHandler.prototype.endTerminalHandleImage = HoverIcons.prototype.endTerminalHandle;
  11241. mxEdgeHandler.prototype.fixedHandleImage = HoverIcons.prototype.fixedHandle;
  11242. mxEdgeHandler.prototype.endFixedHandleImage = HoverIcons.prototype.endFixedHandle;
  11243. mxEdgeHandler.prototype.labelHandleImage = HoverIcons.prototype.secondaryHandle;
  11244. mxOutline.prototype.sizerImage = HoverIcons.prototype.mainHandle;
  11245. if (window.Sidebar != null)
  11246. {
  11247. Sidebar.prototype.triangleUp = HoverIcons.prototype.triangleUp;
  11248. Sidebar.prototype.triangleRight = HoverIcons.prototype.triangleRight;
  11249. Sidebar.prototype.triangleDown = HoverIcons.prototype.triangleDown;
  11250. Sidebar.prototype.triangleLeft = HoverIcons.prototype.triangleLeft;
  11251. Sidebar.prototype.refreshTarget = HoverIcons.prototype.refreshTarget;
  11252. Sidebar.prototype.roundDrop = HoverIcons.prototype.roundDrop;
  11253. }
  11254. // Adds rotation handle and live preview
  11255. mxVertexHandler.prototype.rotationEnabled = true;
  11256. mxVertexHandler.prototype.manageSizers = true;
  11257. mxVertexHandler.prototype.livePreview = true;
  11258. mxGraphHandler.prototype.maxLivePreview = 16;
  11259. // Increases default rubberband opacity (default is 20)
  11260. mxRubberband.prototype.defaultOpacity = 30;
  11261. // Enables connections along the outline, virtual waypoints, parent highlight etc
  11262. mxConnectionHandler.prototype.outlineConnect = true;
  11263. mxCellHighlight.prototype.keepOnTop = true;
  11264. mxVertexHandler.prototype.parentHighlightEnabled = true;
  11265. mxEdgeHandler.prototype.parentHighlightEnabled = true;
  11266. mxEdgeHandler.prototype.dblClickRemoveEnabled = true;
  11267. mxEdgeHandler.prototype.straightRemoveEnabled = true;
  11268. mxEdgeHandler.prototype.virtualBendsEnabled = true;
  11269. mxEdgeHandler.prototype.mergeRemoveEnabled = true;
  11270. mxEdgeHandler.prototype.manageLabelHandle = true;
  11271. mxEdgeHandler.prototype.outlineConnect = true;
  11272. // Disables adding waypoints if shift is pressed
  11273. mxEdgeHandler.prototype.isAddVirtualBendEvent = function(me)
  11274. {
  11275. return !mxEvent.isShiftDown(me.getEvent());
  11276. };
  11277. // Disables custom handles if shift is pressed
  11278. mxEdgeHandler.prototype.isCustomHandleEvent = function(me)
  11279. {
  11280. return !mxEvent.isShiftDown(me.getEvent());
  11281. };
  11282. /**
  11283. * Implements touch style
  11284. */
  11285. if (Graph.touchStyle)
  11286. {
  11287. // Larger tolerance for real touch devices
  11288. if (mxClient.IS_TOUCH || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0)
  11289. {
  11290. mxShape.prototype.svgStrokeTolerance = 18;
  11291. mxVertexHandler.prototype.tolerance = 12;
  11292. mxEdgeHandler.prototype.tolerance = 12;
  11293. Graph.prototype.tolerance = 12;
  11294. mxVertexHandler.prototype.rotationHandleVSpacing = -16;
  11295. // Implements a smaller tolerance for mouse events and a larger tolerance for touch
  11296. // events on touch devices. The default tolerance (4px) is used for mouse events.
  11297. mxConstraintHandler.prototype.getTolerance = function(me)
  11298. {
  11299. return (mxEvent.isMouseEvent(me.getEvent())) ? 4 : this.graph.getTolerance();
  11300. };
  11301. }
  11302. // One finger pans (no rubberband selection) must start regardless of mouse button
  11303. mxPanningHandler.prototype.isPanningTrigger = function(me)
  11304. {
  11305. var evt = me.getEvent();
  11306. return (me.getState() == null && !mxEvent.isMouseEvent(evt)) ||
  11307. (mxEvent.isPopupTrigger(evt) && (me.getState() == null ||
  11308. mxEvent.isControlDown(evt) || mxEvent.isShiftDown(evt)));
  11309. };
  11310. // Don't clear selection if multiple cells selected
  11311. var graphHandlerMouseDown = mxGraphHandler.prototype.mouseDown;
  11312. mxGraphHandler.prototype.mouseDown = function(sender, me)
  11313. {
  11314. graphHandlerMouseDown.apply(this, arguments);
  11315. if (mxEvent.isTouchEvent(me.getEvent()) && this.graph.isCellSelected(me.getCell()) &&
  11316. this.graph.getSelectionCount() > 1)
  11317. {
  11318. this.delayedSelection = false;
  11319. }
  11320. };
  11321. }
  11322. else
  11323. {
  11324. // Removes ctrl+shift as panning trigger for space splitting
  11325. mxPanningHandler.prototype.isPanningTrigger = function(me)
  11326. {
  11327. var evt = me.getEvent();
  11328. return (mxEvent.isLeftMouseButton(evt) && ((this.useLeftButtonForPanning &&
  11329. me.getState() == null) || (mxEvent.isControlDown(evt) &&
  11330. !mxEvent.isShiftDown(evt)))) || (this.usePopupTrigger &&
  11331. mxEvent.isPopupTrigger(evt));
  11332. };
  11333. }
  11334. // Overrides/extends rubberband for space handling with Ctrl+Shift(+Alt) drag ("scissors tool")
  11335. mxRubberband.prototype.isSpaceEvent = function(me)
  11336. {
  11337. return this.graph.isEnabled() && !this.graph.isCellLocked(this.graph.getDefaultParent()) &&
  11338. (mxEvent.isControlDown(me.getEvent()) || mxEvent.isMetaDown(me.getEvent())) &&
  11339. mxEvent.isShiftDown(me.getEvent()) && mxEvent.isAltDown(me.getEvent());
  11340. };
  11341. // Cancelled state
  11342. mxRubberband.prototype.cancelled = false;
  11343. // Cancels ongoing rubberband selection but consumed event to avoid reset of selection
  11344. mxRubberband.prototype.cancel = function()
  11345. {
  11346. if (this.isActive())
  11347. {
  11348. this.cancelled = true;
  11349. this.reset();
  11350. }
  11351. };
  11352. // Handles moving of cells in both half panes
  11353. mxRubberband.prototype.mouseUp = function(sender, me)
  11354. {
  11355. if (this.cancelled)
  11356. {
  11357. this.cancelled = false;
  11358. me.consume();
  11359. }
  11360. else
  11361. {
  11362. var execute = this.div != null && this.div.style.display != 'none';
  11363. var x0 = null;
  11364. var y0 = null;
  11365. var dx = null;
  11366. var dy = null;
  11367. if (this.first != null && this.currentX != null && this.currentY != null)
  11368. {
  11369. x0 = this.first.x;
  11370. y0 = this.first.y;
  11371. dx = (this.currentX - x0) / this.graph.view.scale;
  11372. dy = (this.currentY - y0) / this.graph.view.scale;
  11373. if (!mxEvent.isAltDown(me.getEvent()))
  11374. {
  11375. dx = this.graph.snap(dx);
  11376. dy = this.graph.snap(dy);
  11377. if (!this.graph.isGridEnabled())
  11378. {
  11379. if (Math.abs(dx) < this.graph.tolerance)
  11380. {
  11381. dx = 0;
  11382. }
  11383. if (Math.abs(dy) < this.graph.tolerance)
  11384. {
  11385. dy = 0;
  11386. }
  11387. }
  11388. }
  11389. }
  11390. this.reset();
  11391. if (execute)
  11392. {
  11393. if (this.isSpaceEvent(me))
  11394. {
  11395. this.graph.model.beginUpdate();
  11396. try
  11397. {
  11398. var cells = this.graph.getCellsBeyond(x0, y0, this.graph.getDefaultParent(), true, true);
  11399. for (var i = 0; i < cells.length; i++)
  11400. {
  11401. if (this.graph.isCellMovable(cells[i]))
  11402. {
  11403. var tmp = this.graph.view.getState(cells[i]);
  11404. var geo = this.graph.getCellGeometry(cells[i]);
  11405. if (tmp != null && geo != null)
  11406. {
  11407. geo = geo.clone();
  11408. geo.translate(dx, dy);
  11409. this.graph.model.setGeometry(cells[i], geo);
  11410. }
  11411. }
  11412. }
  11413. }
  11414. finally
  11415. {
  11416. this.graph.model.endUpdate();
  11417. }
  11418. }
  11419. else
  11420. {
  11421. var rect = new mxRectangle(this.x, this.y, this.width, this.height);
  11422. this.graph.selectRegion(rect, me.getEvent());
  11423. }
  11424. me.consume();
  11425. }
  11426. }
  11427. };
  11428. // Handles preview for creating/removing space in diagram
  11429. mxRubberband.prototype.mouseMove = function(sender, me)
  11430. {
  11431. if (!me.isConsumed() && this.first != null)
  11432. {
  11433. var origin = mxUtils.getScrollOrigin(this.graph.container);
  11434. var offset = mxUtils.getOffset(this.graph.container);
  11435. origin.x -= offset.x;
  11436. origin.y -= offset.y;
  11437. var x = me.getX() + origin.x;
  11438. var y = me.getY() + origin.y;
  11439. var dx = this.first.x - x;
  11440. var dy = this.first.y - y;
  11441. var tol = this.graph.tolerance;
  11442. if (this.div != null || Math.abs(dx) > tol || Math.abs(dy) > tol)
  11443. {
  11444. if (this.div == null)
  11445. {
  11446. this.div = this.createShape();
  11447. }
  11448. // Clears selection while rubberbanding. This is required because
  11449. // the event is not consumed in mouseDown.
  11450. mxUtils.clearSelection();
  11451. this.update(x, y);
  11452. if (this.isSpaceEvent(me))
  11453. {
  11454. var right = this.x + this.width;
  11455. var bottom = this.y + this.height;
  11456. var scale = this.graph.view.scale;
  11457. if (!mxEvent.isAltDown(me.getEvent()))
  11458. {
  11459. this.width = this.graph.snap(this.width / scale) * scale;
  11460. this.height = this.graph.snap(this.height / scale) * scale;
  11461. if (!this.graph.isGridEnabled())
  11462. {
  11463. if (this.width < this.graph.tolerance)
  11464. {
  11465. this.width = 0;
  11466. }
  11467. if (this.height < this.graph.tolerance)
  11468. {
  11469. this.height = 0;
  11470. }
  11471. }
  11472. if (this.x < this.first.x)
  11473. {
  11474. this.x = right - this.width;
  11475. }
  11476. if (this.y < this.first.y)
  11477. {
  11478. this.y = bottom - this.height;
  11479. }
  11480. }
  11481. this.div.style.borderStyle = 'dashed';
  11482. this.div.style.backgroundColor = 'white';
  11483. this.div.style.left = this.x + 'px';
  11484. this.div.style.top = this.y + 'px';
  11485. this.div.style.width = Math.max(0, this.width) + 'px';
  11486. this.div.style.height = this.graph.container.clientHeight + 'px';
  11487. this.div.style.borderWidth = (this.width <= 0) ? '0px 1px 0px 0px' : '0px 1px 0px 1px';
  11488. if (this.secondDiv == null)
  11489. {
  11490. this.secondDiv = this.div.cloneNode(true);
  11491. this.div.parentNode.appendChild(this.secondDiv);
  11492. }
  11493. this.secondDiv.style.left = this.x + 'px';
  11494. this.secondDiv.style.top = this.y + 'px';
  11495. this.secondDiv.style.width = this.graph.container.clientWidth + 'px';
  11496. this.secondDiv.style.height = Math.max(0, this.height) + 'px';
  11497. this.secondDiv.style.borderWidth = (this.height <= 0) ? '1px 0px 0px 0px' : '1px 0px 1px 0px';
  11498. }
  11499. else
  11500. {
  11501. // Hides second div and restores style
  11502. this.div.style.backgroundColor = '';
  11503. this.div.style.borderWidth = '';
  11504. this.div.style.borderStyle = '';
  11505. if (this.secondDiv != null)
  11506. {
  11507. this.secondDiv.parentNode.removeChild(this.secondDiv);
  11508. this.secondDiv = null;
  11509. }
  11510. }
  11511. me.consume();
  11512. }
  11513. }
  11514. };
  11515. // Removes preview
  11516. var mxRubberbandReset = mxRubberband.prototype.reset;
  11517. mxRubberband.prototype.reset = function()
  11518. {
  11519. if (this.secondDiv != null)
  11520. {
  11521. this.secondDiv.parentNode.removeChild(this.secondDiv);
  11522. this.secondDiv = null;
  11523. }
  11524. mxRubberbandReset.apply(this, arguments);
  11525. };
  11526. // Timer-based activation of outline connect in connection handler
  11527. var startTime = new Date().getTime();
  11528. var timeOnTarget = 0;
  11529. var mxEdgeHandlerUpdatePreviewState = mxEdgeHandler.prototype.updatePreviewState;
  11530. mxEdgeHandler.prototype.updatePreviewState = function(edge, point, terminalState, me)
  11531. {
  11532. mxEdgeHandlerUpdatePreviewState.apply(this, arguments);
  11533. if (terminalState != this.currentTerminalState)
  11534. {
  11535. startTime = new Date().getTime();
  11536. timeOnTarget = 0;
  11537. }
  11538. else
  11539. {
  11540. timeOnTarget = new Date().getTime() - startTime;
  11541. }
  11542. this.currentTerminalState = terminalState;
  11543. };
  11544. // Timer-based outline connect
  11545. var mxEdgeHandlerIsOutlineConnectEvent = mxEdgeHandler.prototype.isOutlineConnectEvent;
  11546. mxEdgeHandler.prototype.isOutlineConnectEvent = function(me)
  11547. {
  11548. if (mxEvent.isShiftDown(me.getEvent()) && mxEvent.isAltDown(me.getEvent()))
  11549. {
  11550. return false;
  11551. }
  11552. else
  11553. {
  11554. return (this.currentTerminalState != null && me.getState() == this.currentTerminalState && timeOnTarget > 2000) ||
  11555. ((this.currentTerminalState == null || mxUtils.getValue(this.currentTerminalState.style, 'outlineConnect', '1') != '0') &&
  11556. mxEdgeHandlerIsOutlineConnectEvent.apply(this, arguments));
  11557. }
  11558. };
  11559. // Shows secondary handle for fixed connection points
  11560. mxEdgeHandler.prototype.createHandleShape = function(index, virtual, target)
  11561. {
  11562. var source = index != null && index == 0;
  11563. var terminalState = this.state.getVisibleTerminalState(source);
  11564. var c = (index != null && (index == 0 || index >= this.state.absolutePoints.length - 1 ||
  11565. (this.constructor == mxElbowEdgeHandler && index == 2))) ?
  11566. this.graph.getConnectionConstraint(this.state, terminalState, source) : null;
  11567. var pt = (c != null) ? this.graph.getConnectionPoint(this.state.getVisibleTerminalState(source), c) : null;
  11568. var img = (pt != null) ? (!target ? this.fixedHandleImage : this.endFixedHandleImage) :
  11569. ((c != null && terminalState != null) ? (!target ? this.terminalHandleImage : this.endTerminalHandleImage) :
  11570. (!target ? this.handleImage : this.endHandleImage));
  11571. if (img != null)
  11572. {
  11573. var shape = new mxImageShape(new mxRectangle(0, 0, img.width, img.height), img.src);
  11574. // Allows HTML rendering of the images
  11575. shape.preserveImageAspect = false;
  11576. return shape;
  11577. }
  11578. else
  11579. {
  11580. var s = mxConstants.HANDLE_SIZE;
  11581. if (this.preferHtml)
  11582. {
  11583. s -= 1;
  11584. }
  11585. return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  11586. }
  11587. };
  11588. var vertexHandlerCreateSizerShape = mxVertexHandler.prototype.createSizerShape;
  11589. mxVertexHandler.prototype.createSizerShape = function(bounds, index, fillColor)
  11590. {
  11591. this.handleImage = (index == mxEvent.ROTATION_HANDLE) ? HoverIcons.prototype.rotationHandle : (index == mxEvent.LABEL_HANDLE) ? this.secondaryHandleImage : this.handleImage;
  11592. return vertexHandlerCreateSizerShape.apply(this, arguments);
  11593. };
  11594. // Special case for single edge label handle moving in which case the text bounding box is used
  11595. var mxGraphHandlerGetBoundingBox = mxGraphHandler.prototype.getBoundingBox;
  11596. mxGraphHandler.prototype.getBoundingBox = function(cells)
  11597. {
  11598. if (cells != null && cells.length == 1)
  11599. {
  11600. var model = this.graph.getModel();
  11601. var parent = model.getParent(cells[0]);
  11602. var geo = this.graph.getCellGeometry(cells[0]);
  11603. if (model.isEdge(parent) && geo != null && geo.relative)
  11604. {
  11605. var state = this.graph.view.getState(cells[0]);
  11606. if (state != null && state.width < 2 && state.height < 2 && state.text != null &&
  11607. state.text.boundingBox != null)
  11608. {
  11609. return mxRectangle.fromRectangle(state.text.boundingBox);
  11610. }
  11611. }
  11612. }
  11613. return mxGraphHandlerGetBoundingBox.apply(this, arguments);
  11614. };
  11615. // Ignores child cells with part style as guides
  11616. var mxGraphHandlerGetGuideStates = mxGraphHandler.prototype.getGuideStates;
  11617. mxGraphHandler.prototype.getGuideStates = function()
  11618. {
  11619. var states = mxGraphHandlerGetGuideStates.apply(this, arguments);
  11620. var result = [];
  11621. // NOTE: Could do via isStateIgnored hook
  11622. for (var i = 0; i < states.length; i++)
  11623. {
  11624. if (mxUtils.getValue(states[i].style, 'part', '0') != '1')
  11625. {
  11626. result.push(states[i]);
  11627. }
  11628. }
  11629. return result;
  11630. };
  11631. // Uses text bounding box for edge labels
  11632. var mxVertexHandlerGetSelectionBounds = mxVertexHandler.prototype.getSelectionBounds;
  11633. mxVertexHandler.prototype.getSelectionBounds = function(state)
  11634. {
  11635. var model = this.graph.getModel();
  11636. var parent = model.getParent(state.cell);
  11637. var geo = this.graph.getCellGeometry(state.cell);
  11638. if (model.isEdge(parent) && geo != null && geo.relative && state.width < 2 && state.height < 2 && state.text != null && state.text.boundingBox != null)
  11639. {
  11640. var bbox = state.text.unrotatedBoundingBox || state.text.boundingBox;
  11641. return new mxRectangle(Math.round(bbox.x), Math.round(bbox.y), Math.round(bbox.width), Math.round(bbox.height));
  11642. }
  11643. else
  11644. {
  11645. return mxVertexHandlerGetSelectionBounds.apply(this, arguments);
  11646. }
  11647. };
  11648. // Redirects moving of edge labels to mxGraphHandler by not starting here.
  11649. // This will use the move preview of mxGraphHandler (see above).
  11650. var mxVertexHandlerMouseDown = mxVertexHandler.prototype.mouseDown;
  11651. mxVertexHandler.prototype.mouseDown = function(sender, me)
  11652. {
  11653. var model = this.graph.getModel();
  11654. var parent = model.getParent(this.state.cell);
  11655. var geo = this.graph.getCellGeometry(this.state.cell);
  11656. // Lets rotation events through
  11657. var handle = this.getHandleForEvent(me);
  11658. if (handle == mxEvent.ROTATION_HANDLE || !model.isEdge(parent) || geo == null || !geo.relative ||
  11659. this.state == null || this.state.width >= 2 || this.state.height >= 2)
  11660. {
  11661. mxVertexHandlerMouseDown.apply(this, arguments);
  11662. }
  11663. };
  11664. // Invokes turn on single click on rotation handle
  11665. mxVertexHandler.prototype.rotateClick = function()
  11666. {
  11667. var stroke = mxUtils.getValue(this.state.style, mxConstants.STYLE_STROKECOLOR, mxConstants.NONE);
  11668. var fill = mxUtils.getValue(this.state.style, mxConstants.STYLE_FILLCOLOR, mxConstants.NONE);
  11669. if (this.state.view.graph.model.isVertex(this.state.cell) &&
  11670. stroke == mxConstants.NONE && fill == mxConstants.NONE)
  11671. {
  11672. var angle = mxUtils.mod(mxUtils.getValue(this.state.style, mxConstants.STYLE_ROTATION, 0) + 90, 360);
  11673. this.state.view.graph.setCellStyles(mxConstants.STYLE_ROTATION, angle, [this.state.cell]);
  11674. }
  11675. else
  11676. {
  11677. this.state.view.graph.turnShapes([this.state.cell]);
  11678. }
  11679. };
  11680. var vertexHandlerMouseMove = mxVertexHandler.prototype.mouseMove;
  11681. // Workaround for "isConsumed not defined" in MS Edge is to use arguments
  11682. mxVertexHandler.prototype.mouseMove = function(sender, me)
  11683. {
  11684. vertexHandlerMouseMove.apply(this, arguments);
  11685. if (this.graph.graphHandler.first != null)
  11686. {
  11687. if (this.rotationShape != null && this.rotationShape.node != null)
  11688. {
  11689. this.rotationShape.node.style.display = 'none';
  11690. }
  11691. if (this.linkHint != null && this.linkHint.style.display != 'none')
  11692. {
  11693. this.linkHint.style.display = 'none';
  11694. }
  11695. }
  11696. };
  11697. var vertexHandlerMouseUp = mxVertexHandler.prototype.mouseUp;
  11698. mxVertexHandler.prototype.mouseUp = function(sender, me)
  11699. {
  11700. vertexHandlerMouseUp.apply(this, arguments);
  11701. // Shows rotation handle only if one vertex is selected
  11702. if (this.rotationShape != null && this.rotationShape.node != null)
  11703. {
  11704. this.rotationShape.node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  11705. }
  11706. if (this.linkHint != null && this.linkHint.style.display == 'none')
  11707. {
  11708. this.linkHint.style.display = '';
  11709. }
  11710. // Resets state after gesture
  11711. this.blockDelayedSelection = null;
  11712. };
  11713. var vertexHandlerInit = mxVertexHandler.prototype.init;
  11714. mxVertexHandler.prototype.init = function()
  11715. {
  11716. vertexHandlerInit.apply(this, arguments);
  11717. var redraw = false;
  11718. if (this.rotationShape != null)
  11719. {
  11720. this.rotationShape.node.setAttribute('title', mxResources.get('rotateTooltip'));
  11721. }
  11722. if (this.graph.isTable(this.state.cell))
  11723. {
  11724. this.refreshMoveHandles();
  11725. }
  11726. // Draws corner rectangles for single selected table cells and rows
  11727. else if (this.graph.getSelectionCount() == 1 &&
  11728. (this.graph.isTableCell(this.state.cell) ||
  11729. this.graph.isTableRow(this.state.cell)))
  11730. {
  11731. this.cornerHandles = [];
  11732. for (var i = 0; i < 4; i++)
  11733. {
  11734. var shape = new mxRectangleShape(new mxRectangle(0, 0, 6, 6),
  11735. '#ffffff', mxConstants.HANDLE_STROKECOLOR);
  11736. shape.dialect = mxConstants.DIALECT_SVG;
  11737. shape.init(this.graph.view.getOverlayPane());
  11738. this.cornerHandles.push(shape);
  11739. }
  11740. }
  11741. var update = mxUtils.bind(this, function()
  11742. {
  11743. if (this.specialHandle != null)
  11744. {
  11745. this.specialHandle.node.style.display = (this.graph.isEnabled() &&
  11746. this.graph.getSelectionCount() < this.graph.graphHandler.maxCells) ?
  11747. '' : 'none';
  11748. }
  11749. this.redrawHandles();
  11750. });
  11751. this.changeHandler = mxUtils.bind(this, function(sender, evt)
  11752. {
  11753. this.updateLinkHint(this.graph.getLinkForCell(this.state.cell),
  11754. this.graph.getLinksForState(this.state));
  11755. update();
  11756. });
  11757. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.changeHandler);
  11758. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  11759. // Repaint needed when editing stops and no change event is fired
  11760. this.editingHandler = mxUtils.bind(this, function(sender, evt)
  11761. {
  11762. this.redrawHandles();
  11763. });
  11764. this.graph.addListener(mxEvent.EDITING_STOPPED, this.editingHandler);
  11765. var link = this.graph.getLinkForCell(this.state.cell);
  11766. var links = this.graph.getLinksForState(this.state);
  11767. this.updateLinkHint(link, links);
  11768. if (link != null || (links != null && links.length > 0))
  11769. {
  11770. redraw = true;
  11771. }
  11772. if (redraw)
  11773. {
  11774. this.redrawHandles();
  11775. }
  11776. };
  11777. mxVertexHandler.prototype.updateLinkHint = function(link, links)
  11778. {
  11779. try
  11780. {
  11781. if ((link == null && (links == null || links.length == 0)) ||
  11782. this.graph.getSelectionCount() > 1)
  11783. {
  11784. if (this.linkHint != null)
  11785. {
  11786. this.linkHint.parentNode.removeChild(this.linkHint);
  11787. this.linkHint = null;
  11788. }
  11789. }
  11790. else if (link != null || (links != null && links.length > 0))
  11791. {
  11792. if (this.linkHint == null)
  11793. {
  11794. this.linkHint = createHint();
  11795. this.linkHint.style.padding = '6px 8px 6px 8px';
  11796. this.linkHint.style.opacity = '1';
  11797. this.linkHint.style.filter = '';
  11798. this.graph.container.appendChild(this.linkHint);
  11799. mxEvent.addListener(this.linkHint, 'mouseenter', mxUtils.bind(this, function()
  11800. {
  11801. this.graph.tooltipHandler.hide();
  11802. }));
  11803. }
  11804. this.linkHint.innerHTML = '';
  11805. if (link != null)
  11806. {
  11807. this.linkHint.appendChild(this.graph.createLinkForHint(link));
  11808. if (this.graph.isEnabled() && typeof this.graph.editLink === 'function')
  11809. {
  11810. var changeLink = document.createElement('img');
  11811. changeLink.setAttribute('src', Editor.editImage);
  11812. changeLink.setAttribute('title', mxResources.get('editLink'));
  11813. changeLink.setAttribute('width', '11');
  11814. changeLink.setAttribute('height', '11');
  11815. changeLink.style.marginLeft = '10px';
  11816. changeLink.style.marginBottom = '-1px';
  11817. changeLink.style.cursor = 'pointer';
  11818. this.linkHint.appendChild(changeLink);
  11819. mxEvent.addListener(changeLink, 'click', mxUtils.bind(this, function(evt)
  11820. {
  11821. this.graph.setSelectionCell(this.state.cell);
  11822. this.graph.editLink();
  11823. mxEvent.consume(evt);
  11824. }));
  11825. this.linkHint.appendChild(Graph.createRemoveIcon(mxResources.get('removeIt',
  11826. [mxResources.get('link')]), mxUtils.bind(this, function(evt)
  11827. {
  11828. this.graph.setLinkForCell(this.state.cell, null);
  11829. mxEvent.consume(evt);
  11830. })));
  11831. }
  11832. }
  11833. if (links != null)
  11834. {
  11835. for (var i = 0; i < links.length; i++)
  11836. {
  11837. var div = document.createElement('div');
  11838. div.style.marginTop = (link != null || i > 0) ? '6px' : '0px';
  11839. div.appendChild(this.graph.createLinkForHint(
  11840. links[i].getAttribute('href'),
  11841. mxUtils.getTextContent(links[i])));
  11842. this.linkHint.appendChild(div);
  11843. }
  11844. }
  11845. }
  11846. if (this.linkHint != null)
  11847. {
  11848. Graph.sanitizeNode(this.linkHint);
  11849. }
  11850. }
  11851. catch (e)
  11852. {
  11853. // ignore
  11854. }
  11855. };
  11856. mxEdgeHandler.prototype.updateLinkHint = mxVertexHandler.prototype.updateLinkHint;
  11857. // Creates special handles
  11858. var edgeHandlerInit = mxEdgeHandler.prototype.init;
  11859. mxEdgeHandler.prototype.init = function()
  11860. {
  11861. edgeHandlerInit.apply(this, arguments);
  11862. // Disables connection points
  11863. this.constraintHandler.isEnabled = mxUtils.bind(this, function()
  11864. {
  11865. return this.state.view.graph.connectionHandler.isEnabled();
  11866. });
  11867. var update = mxUtils.bind(this, function()
  11868. {
  11869. if (this.linkHint != null)
  11870. {
  11871. this.linkHint.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  11872. }
  11873. if (this.labelShape != null)
  11874. {
  11875. this.labelShape.node.style.display = (this.graph.isEnabled() &&
  11876. this.graph.getSelectionCount() < this.graph.graphHandler.maxCells) ?
  11877. '' : 'none';
  11878. }
  11879. });
  11880. this.changeHandler = mxUtils.bind(this, function(sender, evt)
  11881. {
  11882. this.updateLinkHint(this.graph.getLinkForCell(this.state.cell),
  11883. this.graph.getLinksForState(this.state));
  11884. update();
  11885. this.redrawHandles();
  11886. });
  11887. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.changeHandler);
  11888. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  11889. var link = this.graph.getLinkForCell(this.state.cell);
  11890. var links = this.graph.getLinksForState(this.state);
  11891. if (link != null || (links != null && links.length > 0))
  11892. {
  11893. this.updateLinkHint(link, links);
  11894. this.redrawHandles();
  11895. }
  11896. };
  11897. // Disables connection points
  11898. var connectionHandlerInit = mxConnectionHandler.prototype.init;
  11899. mxConnectionHandler.prototype.init = function()
  11900. {
  11901. connectionHandlerInit.apply(this, arguments);
  11902. this.constraintHandler.isEnabled = mxUtils.bind(this, function()
  11903. {
  11904. return this.graph.connectionHandler.isEnabled();
  11905. });
  11906. };
  11907. // Updates special handles
  11908. var vertexHandlerRedrawHandles = mxVertexHandler.prototype.redrawHandles;
  11909. mxVertexHandler.prototype.redrawHandles = function()
  11910. {
  11911. if (this.moveHandles != null)
  11912. {
  11913. for (var i = 0; i < this.moveHandles.length; i++)
  11914. {
  11915. this.moveHandles[i].style.left = (this.moveHandles[i].rowState.x +
  11916. this.moveHandles[i].rowState.width - 5) + 'px';
  11917. this.moveHandles[i].style.top = (this.moveHandles[i].rowState.y +
  11918. this.moveHandles[i].rowState.height / 2 - 6) + 'px';
  11919. }
  11920. }
  11921. if (this.cornerHandles != null)
  11922. {
  11923. var inset = this.getSelectionBorderInset();
  11924. var ch = this.cornerHandles;
  11925. var w = ch[0].bounds.width / 2;
  11926. var h = ch[0].bounds.height / 2;
  11927. ch[0].bounds.x = this.state.x - w + inset;
  11928. ch[0].bounds.y = this.state.y - h + inset;
  11929. ch[0].redraw();
  11930. ch[1].bounds.x = ch[0].bounds.x + this.state.width - 2 * inset;
  11931. ch[1].bounds.y = ch[0].bounds.y;
  11932. ch[1].redraw();
  11933. ch[2].bounds.x = ch[0].bounds.x;
  11934. ch[2].bounds.y = this.state.y + this.state.height - 2 * inset;
  11935. ch[2].redraw();
  11936. ch[3].bounds.x = ch[1].bounds.x;
  11937. ch[3].bounds.y = ch[2].bounds.y;
  11938. ch[3].redraw();
  11939. for (var i = 0; i < this.cornerHandles.length; i++)
  11940. {
  11941. this.cornerHandles[i].node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  11942. }
  11943. }
  11944. // Shows rotation handle only if one vertex is selected
  11945. if (this.rotationShape != null && this.rotationShape.node != null)
  11946. {
  11947. this.rotationShape.node.style.display = (this.moveHandles == null &&
  11948. (this.graph.getSelectionCount() == 1 && (this.index == null ||
  11949. this.index == mxEvent.ROTATION_HANDLE))) ? '' : 'none';
  11950. }
  11951. vertexHandlerRedrawHandles.apply(this);
  11952. if (this.state != null && this.linkHint != null)
  11953. {
  11954. var c = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  11955. var tmp = new mxRectangle(this.state.x, this.state.y - 22, this.state.width + 24, this.state.height + 22);
  11956. var bb = mxUtils.getBoundingBox(tmp, this.state.style[mxConstants.STYLE_ROTATION] || '0', c);
  11957. var rs = (bb != null) ? mxUtils.getBoundingBox(this.state,
  11958. this.state.style[mxConstants.STYLE_ROTATION] || '0') : this.state;
  11959. var tb = (this.state.text != null) ? this.state.text.boundingBox : null;
  11960. if (bb == null)
  11961. {
  11962. bb = this.state;
  11963. }
  11964. var b = bb.y + bb.height;
  11965. if (tb != null)
  11966. {
  11967. b = Math.max(b, tb.y + tb.height);
  11968. }
  11969. this.linkHint.style.left = Math.max(0, Math.round(rs.x + (rs.width - this.linkHint.clientWidth) / 2)) + 'px';
  11970. this.linkHint.style.top = Math.round(b + this.verticalOffset / 2 + Editor.hintOffset) + 'px';
  11971. }
  11972. };
  11973. // Destroys special handles
  11974. var vertexHandlerDestroy = mxVertexHandler.prototype.destroy;
  11975. mxVertexHandler.prototype.destroy = function()
  11976. {
  11977. vertexHandlerDestroy.apply(this, arguments);
  11978. if (this.moveHandles != null)
  11979. {
  11980. for (var i = 0; i < this.moveHandles.length; i++)
  11981. {
  11982. if (this.moveHandles[i] != null && this.moveHandles[i].parentNode != null)
  11983. {
  11984. this.moveHandles[i].parentNode.removeChild(this.moveHandles[i]);
  11985. }
  11986. }
  11987. this.moveHandles = null;
  11988. }
  11989. if (this.cornerHandles != null)
  11990. {
  11991. for (var i = 0; i < this.cornerHandles.length; i++)
  11992. {
  11993. if (this.cornerHandles[i] != null && this.cornerHandles[i].node != null &&
  11994. this.cornerHandles[i].node.parentNode != null)
  11995. {
  11996. this.cornerHandles[i].node.parentNode.removeChild(this.cornerHandles[i].node);
  11997. }
  11998. }
  11999. this.cornerHandles = null;
  12000. }
  12001. if (this.linkHint != null)
  12002. {
  12003. if (this.linkHint.parentNode != null)
  12004. {
  12005. this.linkHint.parentNode.removeChild(this.linkHint);
  12006. }
  12007. this.linkHint = null;
  12008. }
  12009. if (this.changeHandler != null)
  12010. {
  12011. this.graph.getSelectionModel().removeListener(this.changeHandler);
  12012. this.graph.getModel().removeListener(this.changeHandler);
  12013. this.changeHandler = null;
  12014. }
  12015. if (this.editingHandler != null)
  12016. {
  12017. this.graph.removeListener(this.editingHandler);
  12018. this.editingHandler = null;
  12019. }
  12020. };
  12021. var edgeHandlerRedrawHandles = mxEdgeHandler.prototype.redrawHandles;
  12022. mxEdgeHandler.prototype.redrawHandles = function()
  12023. {
  12024. // Workaround for special case where handler
  12025. // is reset before this which leads to a NPE
  12026. if (this.marker != null)
  12027. {
  12028. edgeHandlerRedrawHandles.apply(this);
  12029. if (this.state != null && this.linkHint != null)
  12030. {
  12031. var b = this.state;
  12032. if (this.state.text != null && this.state.text.bounds != null)
  12033. {
  12034. b = new mxRectangle(b.x, b.y, b.width, b.height);
  12035. b.add(this.state.text.bounds);
  12036. }
  12037. this.linkHint.style.left = Math.max(0, Math.round(b.x + (b.width - this.linkHint.clientWidth) / 2)) + 'px';
  12038. this.linkHint.style.top = Math.round(b.y + b.height + Editor.hintOffset) + 'px';
  12039. }
  12040. }
  12041. };
  12042. var edgeHandlerReset = mxEdgeHandler.prototype.reset;
  12043. mxEdgeHandler.prototype.reset = function()
  12044. {
  12045. edgeHandlerReset.apply(this, arguments);
  12046. if (this.linkHint != null)
  12047. {
  12048. this.linkHint.style.visibility = '';
  12049. }
  12050. };
  12051. var edgeHandlerDestroy = mxEdgeHandler.prototype.destroy;
  12052. mxEdgeHandler.prototype.destroy = function()
  12053. {
  12054. edgeHandlerDestroy.apply(this, arguments);
  12055. if (this.linkHint != null)
  12056. {
  12057. this.linkHint.parentNode.removeChild(this.linkHint);
  12058. this.linkHint = null;
  12059. }
  12060. if (this.changeHandler != null)
  12061. {
  12062. this.graph.getModel().removeListener(this.changeHandler);
  12063. this.graph.getSelectionModel().removeListener(this.changeHandler);
  12064. this.changeHandler = null;
  12065. }
  12066. };
  12067. })();
  12068. }