Graph.js 314 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. // Workaround for allowing target="_blank" in HTML sanitizer
  5. // see https://code.google.com/p/google-caja/issues/detail?can=2&q=&colspec=ID%20Type%20Status%20Priority%20Owner%20Summary&groupby=&sort=&id=1296
  6. if (typeof html4 !== 'undefined')
  7. {
  8. html4.ATTRIBS['a::target'] = 0;
  9. html4.ATTRIBS['source::src'] = 0;
  10. html4.ATTRIBS['video::src'] = 0;
  11. // Would be nice for tooltips but probably a security risk...
  12. //html4.ATTRIBS['video::autoplay'] = 0;
  13. //html4.ATTRIBS['video::autobuffer'] = 0;
  14. }
  15. // Workaround for handling named HTML entities in mxUtils.parseXml
  16. // LATER: How to configure DOMParser to just ignore all entities?
  17. (function()
  18. {
  19. var entities = [
  20. ['nbsp', '160'],
  21. ['shy', '173']
  22. ];
  23. var parseXml = mxUtils.parseXml;
  24. mxUtils.parseXml = function(text)
  25. {
  26. for (var i = 0; i < entities.length; i++)
  27. {
  28. text = text.replace(new RegExp(
  29. '&' + entities[i][0] + ';', 'g'),
  30. '&#' + entities[i][1] + ';');
  31. }
  32. return parseXml(text);
  33. };
  34. })();
  35. // Shim for missing toISOString in older versions of IE
  36. // See https://stackoverflow.com/questions/12907862
  37. if (!Date.prototype.toISOString)
  38. {
  39. (function()
  40. {
  41. function pad(number)
  42. {
  43. var r = String(number);
  44. if (r.length === 1)
  45. {
  46. r = '0' + r;
  47. }
  48. return r;
  49. };
  50. Date.prototype.toISOString = function()
  51. {
  52. return this.getUTCFullYear()
  53. + '-' + pad( this.getUTCMonth() + 1 )
  54. + '-' + pad( this.getUTCDate() )
  55. + 'T' + pad( this.getUTCHours() )
  56. + ':' + pad( this.getUTCMinutes() )
  57. + ':' + pad( this.getUTCSeconds() )
  58. + '.' + String( (this.getUTCMilliseconds()/1000).toFixed(3) ).slice( 2, 5 )
  59. + 'Z';
  60. };
  61. }());
  62. }
  63. // Shim for Date.now()
  64. if (!Date.now)
  65. {
  66. Date.now = function()
  67. {
  68. return new Date().getTime();
  69. };
  70. }
  71. // Changes default colors
  72. /**
  73. * Measurements Units
  74. */
  75. mxConstants.POINTS = 1;
  76. mxConstants.MILLIMETERS = 2;
  77. mxConstants.INCHES = 3;
  78. /**
  79. * This ratio is with page scale 1
  80. */
  81. mxConstants.PIXELS_PER_MM = 3.937;
  82. mxConstants.PIXELS_PER_INCH = 100;
  83. mxConstants.SHADOW_OPACITY = 0.25;
  84. mxConstants.SHADOWCOLOR = '#000000';
  85. mxConstants.VML_SHADOWCOLOR = '#d0d0d0';
  86. mxGraph.prototype.pageBreakColor = '#c0c0c0';
  87. mxGraph.prototype.pageScale = 1;
  88. // Letter page format is default in US, Canada and Mexico
  89. (function()
  90. {
  91. try
  92. {
  93. if (navigator != null && navigator.language != null)
  94. {
  95. var lang = navigator.language.toLowerCase();
  96. mxGraph.prototype.pageFormat = (lang === 'en-us' || lang === 'en-ca' || lang === 'es-mx') ?
  97. mxConstants.PAGE_FORMAT_LETTER_PORTRAIT : mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  98. }
  99. }
  100. catch (e)
  101. {
  102. // ignore
  103. }
  104. })();
  105. // Matches label positions of mxGraph 1.x
  106. mxText.prototype.baseSpacingTop = 5;
  107. mxText.prototype.baseSpacingBottom = 1;
  108. // Keeps edges between relative child cells inside parent
  109. mxGraphModel.prototype.ignoreRelativeEdgeParent = false;
  110. // Defines grid properties
  111. mxGraphView.prototype.gridImage = (mxClient.IS_SVG) ? 'data:image/gif;base64,R0lGODlhCgAKAJEAAAAAAP///8zMzP///yH5BAEAAAMALAAAAAAKAAoAAAIJ1I6py+0Po2wFADs=' :
  112. IMAGE_PATH + '/grid.gif';
  113. mxGraphView.prototype.gridSteps = 4;
  114. mxGraphView.prototype.minGridSize = 4;
  115. // UrlParams is null in embed mode
  116. mxGraphView.prototype.defaultGridColor = '#d0d0d0';
  117. mxGraphView.prototype.gridColor = mxGraphView.prototype.defaultGridColor;
  118. //Units
  119. mxGraphView.prototype.unit = mxConstants.POINTS;
  120. mxGraphView.prototype.setUnit = function(unit)
  121. {
  122. if (this.unit != unit)
  123. {
  124. this.unit = unit;
  125. this.fireEvent(new mxEventObject('unitChanged', 'unit', unit));
  126. }
  127. };
  128. // Alternative text for unsupported foreignObjects
  129. mxSvgCanvas2D.prototype.foAltText = '[Not supported by viewer]';
  130. // Hook for custom constraints
  131. mxShape.prototype.getConstraints = function(style, w, h)
  132. {
  133. return null;
  134. };
  135. /**
  136. * Constructs a new graph instance. Note that the constructor does not take a
  137. * container because the graph instance is needed for creating the UI, which
  138. * in turn will create the container for the graph. Hence, the container is
  139. * assigned later in EditorUi.
  140. */
  141. /**
  142. * Defines graph class.
  143. */
  144. Graph = function(container, model, renderHint, stylesheet, themes, standalone)
  145. {
  146. mxGraph.call(this, container, model, renderHint, stylesheet);
  147. this.themes = themes || this.defaultThemes;
  148. this.currentEdgeStyle = mxUtils.clone(this.defaultEdgeStyle);
  149. this.currentVertexStyle = mxUtils.clone(this.defaultVertexStyle);
  150. this.standalone = (standalone != null) ? standalone : false;
  151. // Sets the base domain URL and domain path URL for relative links.
  152. var b = this.baseUrl;
  153. var p = b.indexOf('//');
  154. this.domainUrl = '';
  155. this.domainPathUrl = '';
  156. if (p > 0)
  157. {
  158. var d = b.indexOf('/', p + 2);
  159. if (d > 0)
  160. {
  161. this.domainUrl = b.substring(0, d);
  162. }
  163. d = b.lastIndexOf('/');
  164. if (d > 0)
  165. {
  166. this.domainPathUrl = b.substring(0, d + 1);
  167. }
  168. }
  169. // Adds support for HTML labels via style. Note: Currently, only the Java
  170. // backend supports HTML labels but CSS support is limited to the following:
  171. // http://docs.oracle.com/javase/6/docs/api/index.html?javax/swing/text/html/CSS.html
  172. // TODO: Wrap should not affect isHtmlLabel output (should be handled later)
  173. this.isHtmlLabel = function(cell)
  174. {
  175. var style = this.getCurrentCellStyle(cell);
  176. return (style != null) ? (style['html'] == '1' || style[mxConstants.STYLE_WHITE_SPACE] == 'wrap') : false;
  177. };
  178. // Implements a listener for hover and click handling on edges
  179. if (this.edgeMode)
  180. {
  181. var start = {
  182. point: null,
  183. event: null,
  184. state: null,
  185. handle: null,
  186. selected: false
  187. };
  188. // Uses this event to process mouseDown to check the selection state before it is changed
  189. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  190. {
  191. if (evt.getProperty('eventName') == 'mouseDown' && this.isEnabled())
  192. {
  193. var me = evt.getProperty('event');
  194. var state = me.getState();
  195. if (!mxEvent.isAltDown(me.getEvent()) && state != null)
  196. {
  197. // Checks if state was removed in call to stopEditing above
  198. if (this.model.isEdge(state.cell))
  199. {
  200. start.point = new mxPoint(me.getGraphX(), me.getGraphY());
  201. start.selected = this.isCellSelected(state.cell);
  202. start.state = state;
  203. start.event = me;
  204. if (state.text != null && state.text.boundingBox != null &&
  205. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  206. {
  207. start.handle = mxEvent.LABEL_HANDLE;
  208. }
  209. else
  210. {
  211. var handler = this.selectionCellsHandler.getHandler(state.cell);
  212. if (handler != null && handler.bends != null && handler.bends.length > 0)
  213. {
  214. start.handle = handler.getHandleForEvent(me);
  215. }
  216. }
  217. }
  218. else if (!this.panningHandler.isActive() && !mxEvent.isControlDown(me.getEvent()))
  219. {
  220. var handler = this.selectionCellsHandler.getHandler(state.cell);
  221. // Cell handles have precedence over row and col resize
  222. if (handler == null || handler.getHandleForEvent(me) == null)
  223. {
  224. var box = new mxRectangle(me.getGraphX() - 1, me.getGraphY() - 1);
  225. box.grow(mxEvent.isTouchEvent(me.getEvent()) ?
  226. mxShape.prototype.svgStrokeTolerance - 1 :
  227. (mxShape.prototype.svgStrokeTolerance + 1) / 2);
  228. if (this.isTableCell(state.cell) && !this.isCellSelected(state.cell))
  229. {
  230. var row = this.model.getParent(state.cell);
  231. var table = this.model.getParent(row);
  232. if (!this.isCellSelected(table))
  233. {
  234. if ((mxUtils.intersects(box, new mxRectangle(state.x, state.y - 2, state.width, 3)) &&
  235. this.model.getChildAt(table, 0) != row) || mxUtils.intersects(box, new mxRectangle(
  236. state.x, state.y + state.height - 2, state.width, 3)) ||
  237. (mxUtils.intersects(box, new mxRectangle(state.x - 2, state.y, 2, state.height)) &&
  238. this.model.getChildAt(row, 0) != state.cell) || mxUtils.intersects(box, new mxRectangle(
  239. state.x + state.width - 2, state.y, 2, state.height)))
  240. {
  241. var wasSelected = this.selectionCellsHandler.isHandled(table);
  242. this.selectCellForEvent(table, me.getEvent());
  243. handler = this.selectionCellsHandler.getHandler(table);
  244. if (handler != null)
  245. {
  246. var handle = handler.getHandleForEvent(me);
  247. if (handle != null)
  248. {
  249. handler.start(me.getGraphX(), me.getGraphY(), handle);
  250. handler.blockDelayedSelection = !wasSelected;
  251. me.consume();
  252. }
  253. }
  254. }
  255. }
  256. }
  257. // Hover for swimlane start sizes inside tables
  258. var current = state;
  259. while (!me.isConsumed() && current != null && (this.isTableCell(current.cell) ||
  260. this.isTableRow(current.cell) || this.isTable(current.cell)))
  261. {
  262. if (this.isSwimlane(current.cell))
  263. {
  264. var offset = this.getActualStartSize(current.cell);
  265. var s = this.view.scale;
  266. if (((offset.x > 0 || offset.width > 0) && mxUtils.intersects(box, new mxRectangle(
  267. current.x + (offset.x - offset.width - 1) * s + ((offset.x == 0) ? current.width : 0),
  268. current.y, 1, current.height))) || ((offset.y > 0 || offset.height > 0) &&
  269. mxUtils.intersects(box, new mxRectangle(current.x, current.y + (offset.y -
  270. offset.height - 1) * s + ((offset.y == 0) ? current.height : 0), current.width, 1))))
  271. {
  272. this.selectCellForEvent(current.cell, me.getEvent());
  273. handler = this.selectionCellsHandler.getHandler(current.cell);
  274. if (handler != null)
  275. {
  276. // Swimlane start size handle is last custom handle
  277. var handle = mxEvent.CUSTOM_HANDLE - handler.customHandles.length + 1;
  278. handler.start(me.getGraphX(), me.getGraphY(), handle);
  279. me.consume();
  280. }
  281. }
  282. }
  283. current = this.view.getState(this.model.getParent(current.cell));
  284. }
  285. }
  286. }
  287. }
  288. }
  289. }));
  290. var mouseDown = null;
  291. this.addMouseListener(
  292. {
  293. mouseDown: function(sender, me) {},
  294. mouseMove: mxUtils.bind(this, function(sender, me)
  295. {
  296. // Checks if any other handler is active
  297. var handlerMap = this.selectionCellsHandler.handlers.map;
  298. for (var key in handlerMap)
  299. {
  300. if (handlerMap[key].index != null)
  301. {
  302. return;
  303. }
  304. }
  305. if (this.isEnabled() && !this.panningHandler.isActive() && !mxEvent.isAltDown(me.getEvent()))
  306. {
  307. var tol = this.tolerance;
  308. if (start.point != null && start.state != null && start.event != null)
  309. {
  310. var state = start.state;
  311. if (Math.abs(start.point.x - me.getGraphX()) > tol ||
  312. Math.abs(start.point.y - me.getGraphY()) > tol)
  313. {
  314. var handler = this.selectionCellsHandler.getHandler(state.cell);
  315. if (handler == null && this.model.isEdge(state.cell))
  316. {
  317. handler = this.createHandler(state);
  318. }
  319. if (handler != null && handler.bends != null && handler.bends.length > 0)
  320. {
  321. var handle = handler.getHandleForEvent(start.event);
  322. var edgeStyle = this.view.getEdgeStyle(state);
  323. var entity = edgeStyle == mxEdgeStyle.EntityRelation;
  324. // Handles special case where label was clicked on unselected edge in which
  325. // case the label will be moved regardless of the handle that is returned
  326. if (!start.selected && start.handle == mxEvent.LABEL_HANDLE)
  327. {
  328. handle = start.handle;
  329. }
  330. if (!entity || handle == 0 || handle == handler.bends.length - 1 || handle == mxEvent.LABEL_HANDLE)
  331. {
  332. // Source or target handle or connected for direct handle access or orthogonal line
  333. // with just two points where the central handle is moved regardless of mouse position
  334. if (handle == mxEvent.LABEL_HANDLE || handle == 0 || state.visibleSourceState != null ||
  335. handle == handler.bends.length - 1 || state.visibleTargetState != null)
  336. {
  337. if (!entity && handle != mxEvent.LABEL_HANDLE)
  338. {
  339. var pts = state.absolutePoints;
  340. // Default case where handles are at corner points handles
  341. // drag of corner as drag of existing point
  342. if (pts != null && ((edgeStyle == null && handle == null) ||
  343. edgeStyle == mxEdgeStyle.OrthConnector))
  344. {
  345. // Does not use handles if they were not initially visible
  346. handle = start.handle;
  347. if (handle == null)
  348. {
  349. var box = new mxRectangle(start.point.x, start.point.y);
  350. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  351. if (mxUtils.contains(box, pts[0].x, pts[0].y))
  352. {
  353. // Moves source terminal handle
  354. handle = 0;
  355. }
  356. else if (mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  357. {
  358. // Moves target terminal handle
  359. handle = handler.bends.length - 1;
  360. }
  361. else
  362. {
  363. // Checks if edge has no bends
  364. var nobends = edgeStyle != null && (pts.length == 2 || (pts.length == 3 &&
  365. ((Math.round(pts[0].x - pts[1].x) == 0 && Math.round(pts[1].x - pts[2].x) == 0) ||
  366. (Math.round(pts[0].y - pts[1].y) == 0 && Math.round(pts[1].y - pts[2].y) == 0))));
  367. if (nobends)
  368. {
  369. // Moves central handle for straight orthogonal edges
  370. handle = 2;
  371. }
  372. else
  373. {
  374. // Finds and moves vertical or horizontal segment
  375. handle = mxUtils.findNearestSegment(state, start.point.x, start.point.y);
  376. // Converts segment to virtual handle index
  377. if (edgeStyle == null)
  378. {
  379. handle = mxEvent.VIRTUAL_HANDLE - handle;
  380. }
  381. // Maps segment to handle
  382. else
  383. {
  384. handle += 1;
  385. }
  386. }
  387. }
  388. }
  389. }
  390. // Creates a new waypoint and starts moving it
  391. if (handle == null)
  392. {
  393. handle = mxEvent.VIRTUAL_HANDLE;
  394. }
  395. }
  396. handler.start(me.getGraphX(), me.getGraphX(), handle);
  397. me.consume();
  398. // Removes preview rectangle in graph handler
  399. this.graphHandler.reset();
  400. }
  401. }
  402. else if (entity && (state.visibleSourceState != null || state.visibleTargetState != null))
  403. {
  404. // Disables moves on entity to make it consistent
  405. this.graphHandler.reset();
  406. me.consume();
  407. }
  408. }
  409. if (handler != null)
  410. {
  411. // Lazy selection for edges inside groups
  412. if (this.selectionCellsHandler.isHandlerActive(handler))
  413. {
  414. if (!this.isCellSelected(state.cell))
  415. {
  416. this.selectionCellsHandler.handlers.put(state.cell, handler);
  417. this.selectCellForEvent(state.cell, me.getEvent());
  418. }
  419. }
  420. else if (!this.isCellSelected(state.cell))
  421. {
  422. // Destroy temporary handler
  423. handler.destroy();
  424. }
  425. }
  426. // Reset start state
  427. start.selected = false;
  428. start.handle = null;
  429. start.state = null;
  430. start.event = null;
  431. start.point = null;
  432. }
  433. }
  434. else
  435. {
  436. // Updates cursor for unselected edges under the mouse
  437. var state = me.getState();
  438. if (state != null)
  439. {
  440. var cursor = null;
  441. // Checks if state was removed in call to stopEditing above
  442. if (this.model.isEdge(state.cell))
  443. {
  444. var box = new mxRectangle(me.getGraphX(), me.getGraphY());
  445. box.grow(mxEdgeHandler.prototype.handleImage.width / 2);
  446. var pts = state.absolutePoints;
  447. if (pts != null)
  448. {
  449. if (state.text != null && state.text.boundingBox != null &&
  450. mxUtils.contains(state.text.boundingBox, me.getGraphX(), me.getGraphY()))
  451. {
  452. cursor = 'move';
  453. }
  454. else if (mxUtils.contains(box, pts[0].x, pts[0].y) ||
  455. mxUtils.contains(box, pts[pts.length - 1].x, pts[pts.length - 1].y))
  456. {
  457. cursor = 'pointer';
  458. }
  459. else if (state.visibleSourceState != null || state.visibleTargetState != null)
  460. {
  461. // Moving is not allowed for entity relation but still indicate hover state
  462. var tmp = this.view.getEdgeStyle(state);
  463. cursor = 'crosshair';
  464. if (tmp != mxEdgeStyle.EntityRelation && this.isOrthogonal(state))
  465. {
  466. var idx = mxUtils.findNearestSegment(state, me.getGraphX(), me.getGraphY());
  467. if (idx < pts.length - 1 && idx >= 0)
  468. {
  469. cursor = (Math.round(pts[idx].x - pts[idx + 1].x) == 0) ?
  470. 'col-resize' : 'row-resize';
  471. }
  472. }
  473. }
  474. }
  475. }
  476. else if (!mxEvent.isControlDown(me.getEvent()))
  477. {
  478. var box = new mxRectangle(me.getGraphX() - 1, me.getGraphY() - 1);
  479. box.grow(mxShape.prototype.svgStrokeTolerance / 2);
  480. if (this.isTableCell(state.cell))
  481. {
  482. var row = this.model.getParent(state.cell);
  483. var table = this.model.getParent(row);
  484. if (!this.isCellSelected(table))
  485. {
  486. if ((mxUtils.intersects(box, new mxRectangle(state.x - 2, state.y, 2, state.height)) &&
  487. this.model.getChildAt(row, 0) != state.cell) || mxUtils.intersects(box,
  488. new mxRectangle(state.x + state.width - 2, state.y, 2, state.height)))
  489. {
  490. cursor ='col-resize';
  491. }
  492. else if ((mxUtils.intersects(box, new mxRectangle(state.x, state.y - 2, state.width, 3)) &&
  493. this.model.getChildAt(table, 0) != row) || mxUtils.intersects(box,
  494. new mxRectangle(state.x, state.y + state.height - 2, state.width, 3)))
  495. {
  496. cursor ='row-resize';
  497. }
  498. }
  499. }
  500. // Hover for swimlane start sizes inside tables
  501. var current = state;
  502. while (cursor == null && current != null && (this.isTableCell(current.cell) ||
  503. this.isTableRow(current.cell) || this.isTable(current.cell)))
  504. {
  505. if (this.isSwimlane(current.cell))
  506. {
  507. var offset = this.getActualStartSize(current.cell);
  508. var s = this.view.scale;
  509. if ((offset.x > 0 || offset.width > 0) && mxUtils.intersects(box, new mxRectangle(
  510. current.x + (offset.x - offset.width - 1) * s + ((offset.x == 0) ? current.width * s : 0),
  511. current.y, 1, current.height)))
  512. {
  513. cursor ='col-resize';
  514. }
  515. else if ((offset.y > 0 || offset.height > 0) && mxUtils.intersects(box, new mxRectangle(
  516. current.x, current.y + (offset.y - offset.height - 1) * s + ((offset.y == 0) ? current.height : 0),
  517. current.width, 1)))
  518. {
  519. cursor ='row-resize';
  520. }
  521. }
  522. current = this.view.getState(this.model.getParent(current.cell));
  523. }
  524. }
  525. if (cursor != null)
  526. {
  527. state.setCursor(cursor);
  528. }
  529. }
  530. }
  531. }
  532. }),
  533. mouseUp: mxUtils.bind(this, function(sender, me)
  534. {
  535. start.state = null;
  536. start.event = null;
  537. start.point = null;
  538. start.handle = null;
  539. })
  540. });
  541. }
  542. // HTML entities are displayed as plain text in wrapped plain text labels
  543. this.cellRenderer.getLabelValue = function(state)
  544. {
  545. var result = mxCellRenderer.prototype.getLabelValue.apply(this, arguments);
  546. if (state.view.graph.isHtmlLabel(state.cell))
  547. {
  548. if (state.style['html'] != 1)
  549. {
  550. result = mxUtils.htmlEntities(result, false);
  551. }
  552. else
  553. {
  554. result = state.view.graph.sanitizeHtml(result);
  555. }
  556. }
  557. return result;
  558. };
  559. // All code below not available and not needed in embed mode
  560. if (typeof mxVertexHandler !== 'undefined')
  561. {
  562. this.setConnectable(true);
  563. this.setDropEnabled(true);
  564. this.setPanning(true);
  565. this.setTooltips(true);
  566. this.setAllowLoops(true);
  567. this.allowAutoPanning = true;
  568. this.resetEdgesOnConnect = false;
  569. this.constrainChildren = false;
  570. this.constrainRelativeChildren = true;
  571. // Do not scroll after moving cells
  572. this.graphHandler.scrollOnMove = false;
  573. this.graphHandler.scaleGrid = true;
  574. // Disables cloning of connection sources by default
  575. this.connectionHandler.setCreateTarget(false);
  576. this.connectionHandler.insertBeforeSource = true;
  577. // Disables built-in connection starts
  578. this.connectionHandler.isValidSource = function(cell, me)
  579. {
  580. return false;
  581. };
  582. // Sets the style to be used when an elbow edge is double clicked
  583. this.alternateEdgeStyle = 'vertical';
  584. if (stylesheet == null)
  585. {
  586. this.loadStylesheet();
  587. }
  588. // Adds page centers to the guides for moving cells
  589. var graphHandlerGetGuideStates = this.graphHandler.getGuideStates;
  590. this.graphHandler.getGuideStates = function()
  591. {
  592. var result = graphHandlerGetGuideStates.apply(this, arguments);
  593. // Create virtual cell state for page centers
  594. if (this.graph.pageVisible)
  595. {
  596. var guides = [];
  597. var pf = this.graph.pageFormat;
  598. var ps = this.graph.pageScale;
  599. var pw = pf.width * ps;
  600. var ph = pf.height * ps;
  601. var t = this.graph.view.translate;
  602. var s = this.graph.view.scale;
  603. var layout = this.graph.getPageLayout();
  604. for (var i = 0; i < layout.width; i++)
  605. {
  606. guides.push(new mxRectangle(((layout.x + i) * pw + t.x) * s,
  607. (layout.y * ph + t.y) * s, pw * s, ph * s));
  608. }
  609. for (var j = 1; j < layout.height; j++)
  610. {
  611. guides.push(new mxRectangle((layout.x * pw + t.x) * s,
  612. ((layout.y + j) * ph + t.y) * s, pw * s, ph * s));
  613. }
  614. // Page center guides have precedence over normal guides
  615. result = guides.concat(result);
  616. }
  617. return result;
  618. };
  619. // Overrides zIndex for dragElement
  620. mxDragSource.prototype.dragElementZIndex = mxPopupMenu.prototype.zIndex;
  621. // Overrides color for virtual guides for page centers
  622. mxGuide.prototype.getGuideColor = function(state, horizontal)
  623. {
  624. return (state.cell == null) ? '#ffa500' /* orange */ : mxConstants.GUIDE_COLOR;
  625. };
  626. // Changes color of move preview for black backgrounds
  627. this.graphHandler.createPreviewShape = function(bounds)
  628. {
  629. this.previewColor = (this.graph.background == '#000000') ? '#ffffff' : mxGraphHandler.prototype.previewColor;
  630. return mxGraphHandler.prototype.createPreviewShape.apply(this, arguments);
  631. };
  632. // Handles parts of cells by checking if part=1 is in the style and returning the parent
  633. // if the parent is not already in the list of cells. container style is used to disable
  634. // step into swimlanes and dropTarget style is used to disable acting as a drop target.
  635. // LATER: Handle recursive parts
  636. var graphHandlerGetCells = this.graphHandler.getCells;
  637. this.graphHandler.getCells = function(initialCell)
  638. {
  639. var cells = graphHandlerGetCells.apply(this, arguments);
  640. var lookup = new mxDictionary();
  641. var newCells = [];
  642. for (var i = 0; i < cells.length; i++)
  643. {
  644. // Propagates to composite parents or moves selected table rows
  645. var cell = (this.graph.isTableCell(initialCell) &&
  646. this.graph.isTableCell(cells[i]) &&
  647. this.graph.isCellSelected(cells[i])) ?
  648. this.graph.model.getParent(cells[i]) :
  649. ((this.graph.isTableRow(initialCell) &&
  650. this.graph.isTableRow(cells[i]) &&
  651. this.graph.isCellSelected(cells[i])) ?
  652. cells[i] : this.graph.getCompositeParent(cells[i]));
  653. if (cell != null && !lookup.get(cell))
  654. {
  655. lookup.put(cell, true);
  656. newCells.push(cell);
  657. }
  658. }
  659. return newCells;
  660. };
  661. // Handles parts and selected rows in tables of cells for drag and drop
  662. var graphHandlerStart = this.graphHandler.start;
  663. this.graphHandler.start = function(cell, x, y, cells)
  664. {
  665. // Propagates to selected table row to start move
  666. var ignoreParent = false;
  667. if (this.graph.isTableCell(cell))
  668. {
  669. if (!this.graph.isCellSelected(cell))
  670. {
  671. cell = this.graph.model.getParent(cell);
  672. }
  673. else
  674. {
  675. ignoreParent = true;
  676. }
  677. }
  678. if (!ignoreParent && (!this.graph.isTableRow(cell) || !this.graph.isCellSelected(cell)))
  679. {
  680. cell = this.graph.getCompositeParent(cell);
  681. }
  682. graphHandlerStart.apply(this, arguments);
  683. };
  684. // Handles parts of cells when cloning the source for new connections
  685. this.connectionHandler.createTargetVertex = function(evt, source)
  686. {
  687. source = this.graph.getCompositeParent(source);
  688. return mxConnectionHandler.prototype.createTargetVertex.apply(this, arguments);
  689. };
  690. var rubberband = new mxRubberband(this);
  691. this.getRubberband = function()
  692. {
  693. return rubberband;
  694. };
  695. // Timer-based activation of outline connect in connection handler
  696. var startTime = new Date().getTime();
  697. var timeOnTarget = 0;
  698. var connectionHandlerMouseMove = this.connectionHandler.mouseMove;
  699. this.connectionHandler.mouseMove = function()
  700. {
  701. var prev = this.currentState;
  702. connectionHandlerMouseMove.apply(this, arguments);
  703. if (prev != this.currentState)
  704. {
  705. startTime = new Date().getTime();
  706. timeOnTarget = 0;
  707. }
  708. else
  709. {
  710. timeOnTarget = new Date().getTime() - startTime;
  711. }
  712. };
  713. // Activates outline connect after 1500ms with touch event or if alt is pressed inside the shape
  714. // outlineConnect=0 is a custom style that means do not connect to strokes inside the shape,
  715. // or in other words, connect to the shape's perimeter if the highlight is under the mouse
  716. // (the name is because the highlight, including all strokes, is called outline in the code)
  717. var connectionHandleIsOutlineConnectEvent = this.connectionHandler.isOutlineConnectEvent;
  718. this.connectionHandler.isOutlineConnectEvent = function(me)
  719. {
  720. return (this.currentState != null && me.getState() == this.currentState && timeOnTarget > 2000) ||
  721. ((this.currentState == null || mxUtils.getValue(this.currentState.style, 'outlineConnect', '1') != '0') &&
  722. connectionHandleIsOutlineConnectEvent.apply(this, arguments));
  723. };
  724. // Adds shift+click to toggle selection state
  725. var isToggleEvent = this.isToggleEvent;
  726. this.isToggleEvent = function(evt)
  727. {
  728. return isToggleEvent.apply(this, arguments) || (!mxClient.IS_CHROMEOS && mxEvent.isShiftDown(evt));
  729. };
  730. // Workaround for Firefox where first mouse down is received
  731. // after tap and hold if scrollbars are visible, which means
  732. // start rubberband immediately if no cell is under mouse.
  733. var isForceRubberBandEvent = rubberband.isForceRubberbandEvent;
  734. rubberband.isForceRubberbandEvent = function(me)
  735. {
  736. return (isForceRubberBandEvent.apply(this, arguments) && !mxEvent.isShiftDown(me.getEvent()) &&
  737. !mxEvent.isControlDown(me.getEvent())) || (mxClient.IS_CHROMEOS && mxEvent.isShiftDown(me.getEvent())) ||
  738. (mxUtils.hasScrollbars(this.graph.container) && mxClient.IS_FF &&
  739. mxClient.IS_WIN && me.getState() == null && mxEvent.isTouchEvent(me.getEvent()));
  740. };
  741. // Shows hand cursor while panning
  742. var prevCursor = null;
  743. this.panningHandler.addListener(mxEvent.PAN_START, mxUtils.bind(this, function()
  744. {
  745. if (this.isEnabled())
  746. {
  747. prevCursor = this.container.style.cursor;
  748. this.container.style.cursor = 'move';
  749. }
  750. }));
  751. this.panningHandler.addListener(mxEvent.PAN_END, mxUtils.bind(this, function()
  752. {
  753. if (this.isEnabled())
  754. {
  755. this.container.style.cursor = prevCursor;
  756. }
  757. }));
  758. this.popupMenuHandler.autoExpand = true;
  759. this.popupMenuHandler.isSelectOnPopup = function(me)
  760. {
  761. return mxEvent.isMouseEvent(me.getEvent());
  762. };
  763. // Handles links if graph is read-only or cell is locked
  764. var click = this.click;
  765. this.click = function(me)
  766. {
  767. var locked = me.state == null && me.sourceState != null &&
  768. this.isCellLocked(me.sourceState.cell);
  769. if ((!this.isEnabled() || locked) && !me.isConsumed())
  770. {
  771. var cell = (locked) ? me.sourceState.cell : me.getCell();
  772. if (cell != null)
  773. {
  774. var link = this.getClickableLinkForCell(cell);
  775. if (link != null)
  776. {
  777. if (this.isCustomLink(link))
  778. {
  779. this.customLinkClicked(link);
  780. }
  781. else
  782. {
  783. this.openLink(link);
  784. }
  785. }
  786. }
  787. if (this.isEnabled() && locked)
  788. {
  789. this.clearSelection();
  790. }
  791. }
  792. else
  793. {
  794. return click.apply(this, arguments);
  795. }
  796. };
  797. // Redirects tooltips for locked cells
  798. this.tooltipHandler.getStateForEvent = function(me)
  799. {
  800. return me.sourceState;
  801. };
  802. // Opens links in tooltips in new windows
  803. var tooltipHandlerShow = this.tooltipHandler.show;
  804. this.tooltipHandler.show = function()
  805. {
  806. tooltipHandlerShow.apply(this, arguments);
  807. if (this.div != null)
  808. {
  809. var links = this.div.getElementsByTagName('a');
  810. for (var i = 0; i < links.length; i++)
  811. {
  812. if (links[i].getAttribute('href') != null &&
  813. links[i].getAttribute('target') == null)
  814. {
  815. links[i].setAttribute('target', '_blank');
  816. }
  817. }
  818. }
  819. };
  820. // Redirects tooltips for locked cells
  821. this.tooltipHandler.getStateForEvent = function(me)
  822. {
  823. return me.sourceState;
  824. };
  825. // Redirects cursor for locked cells
  826. var getCursorForMouseEvent = this.getCursorForMouseEvent;
  827. this.getCursorForMouseEvent = function(me)
  828. {
  829. var locked = me.state == null && me.sourceState != null && this.isCellLocked(me.sourceState.cell);
  830. return this.getCursorForCell((locked) ? me.sourceState.cell : me.getCell());
  831. };
  832. // Shows pointer cursor for clickable cells with links
  833. // ie. if the graph is disabled and cells cannot be selected
  834. var getCursorForCell = this.getCursorForCell;
  835. this.getCursorForCell = function(cell)
  836. {
  837. if (!this.isEnabled() || this.isCellLocked(cell))
  838. {
  839. var link = this.getClickableLinkForCell(cell);
  840. if (link != null)
  841. {
  842. return 'pointer';
  843. }
  844. else if (this.isCellLocked(cell))
  845. {
  846. return 'default';
  847. }
  848. }
  849. return getCursorForCell.apply(this, arguments);
  850. };
  851. // Changes rubberband selection ignore locked cells
  852. this.selectRegion = function(rect, evt)
  853. {
  854. var cells = this.getCells(rect.x, rect.y, rect.width, rect.height, null, null, null, function(state)
  855. {
  856. return mxUtils.getValue(state.style, 'locked', '0') == '1';
  857. }, true);
  858. this.selectCellsForEvent(cells, evt);
  859. return cells;
  860. };
  861. // Never removes cells from parents that are being moved
  862. var graphHandlerShouldRemoveCellsFromParent = this.graphHandler.shouldRemoveCellsFromParent;
  863. this.graphHandler.shouldRemoveCellsFromParent = function(parent, cells, evt)
  864. {
  865. if (this.graph.isCellSelected(parent))
  866. {
  867. return false;
  868. }
  869. return graphHandlerShouldRemoveCellsFromParent.apply(this, arguments);
  870. };
  871. // Unlocks all cells
  872. this.isCellLocked = function(cell)
  873. {
  874. var pState = this.view.getState(cell);
  875. while (pState != null)
  876. {
  877. if (mxUtils.getValue(pState.style, 'locked', '0') == '1')
  878. {
  879. return true;
  880. }
  881. pState = this.view.getState(this.model.getParent(pState.cell));
  882. }
  883. return false;
  884. };
  885. var tapAndHoldSelection = null;
  886. // Uses this event to process mouseDown to check the selection state before it is changed
  887. this.addListener(mxEvent.FIRE_MOUSE_EVENT, mxUtils.bind(this, function(sender, evt)
  888. {
  889. if (evt.getProperty('eventName') == 'mouseDown')
  890. {
  891. var me = evt.getProperty('event');
  892. var state = me.getState();
  893. if (state != null && !this.isSelectionEmpty() && !this.isCellSelected(state.cell))
  894. {
  895. tapAndHoldSelection = this.getSelectionCells();
  896. }
  897. else
  898. {
  899. tapAndHoldSelection = null;
  900. }
  901. }
  902. }));
  903. // Tap and hold on background starts rubberband for multiple selected
  904. // cells the cell associated with the event is deselected
  905. this.addListener(mxEvent.TAP_AND_HOLD, mxUtils.bind(this, function(sender, evt)
  906. {
  907. if (!mxEvent.isMultiTouchEvent(evt))
  908. {
  909. var me = evt.getProperty('event');
  910. var cell = evt.getProperty('cell');
  911. if (cell == null)
  912. {
  913. var pt = mxUtils.convertPoint(this.container,
  914. mxEvent.getClientX(me), mxEvent.getClientY(me));
  915. rubberband.start(pt.x, pt.y);
  916. }
  917. else if (tapAndHoldSelection != null)
  918. {
  919. this.addSelectionCells(tapAndHoldSelection);
  920. }
  921. else if (this.getSelectionCount() > 1 && this.isCellSelected(cell))
  922. {
  923. this.removeSelectionCell(cell);
  924. }
  925. // Blocks further processing of the event
  926. tapAndHoldSelection = null;
  927. evt.consume();
  928. }
  929. }));
  930. // On connect the target is selected and we clone the cell of the preview edge for insert
  931. this.connectionHandler.selectCells = function(edge, target)
  932. {
  933. this.graph.setSelectionCell(target || edge);
  934. };
  935. // Shows connection points only if cell not selected and parent table not handled
  936. this.connectionHandler.constraintHandler.isStateIgnored = function(state, source)
  937. {
  938. var graph = state.view.graph;
  939. return source && (graph.isCellSelected(state.cell) || (graph.isTableRow(state.cell) &&
  940. graph.selectionCellsHandler.isHandled(graph.model.getParent(state.cell))));
  941. };
  942. // Updates constraint handler if the selection changes
  943. this.selectionModel.addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  944. {
  945. var ch = this.connectionHandler.constraintHandler;
  946. if (ch.currentFocus != null && ch.isStateIgnored(ch.currentFocus, true))
  947. {
  948. ch.currentFocus = null;
  949. ch.constraints = null;
  950. ch.destroyIcons();
  951. }
  952. ch.destroyFocusHighlight();
  953. }));
  954. // Initializes touch interface
  955. if (Graph.touchStyle)
  956. {
  957. this.initTouch();
  958. }
  959. /**
  960. * Adds locking
  961. */
  962. var graphUpdateMouseEvent = this.updateMouseEvent;
  963. this.updateMouseEvent = function(me)
  964. {
  965. me = graphUpdateMouseEvent.apply(this, arguments);
  966. if (me.state != null && this.isCellLocked(me.getCell()))
  967. {
  968. me.state = null;
  969. }
  970. return me;
  971. };
  972. }
  973. //Create a unique offset object for each graph instance.
  974. this.currentTranslate = new mxPoint(0, 0);
  975. };
  976. /**
  977. * Specifies if the touch UI should be used (cannot detect touch in FF so always on for Windows/Linux)
  978. */
  979. Graph.touchStyle = mxClient.IS_TOUCH || (mxClient.IS_FF && mxClient.IS_WIN) || navigator.maxTouchPoints > 0 ||
  980. navigator.msMaxTouchPoints > 0 || window.urlParams == null || urlParams['touch'] == '1';
  981. /**
  982. * Shortcut for capability check.
  983. */
  984. Graph.fileSupport = window.File != null && window.FileReader != null && window.FileList != null &&
  985. (window.urlParams == null || urlParams['filesupport'] != '0');
  986. /**
  987. * Shortcut for capability check.
  988. */
  989. Graph.translateDiagram = urlParams['translate-diagram'] == '1';
  990. /**
  991. * Shortcut for capability check.
  992. */
  993. Graph.diagramLanguage = (urlParams['diagram-language'] != null) ? urlParams['diagram-language'] : mxClient.language;
  994. /**
  995. * Default size for line jumps.
  996. */
  997. Graph.lineJumpsEnabled = true;
  998. /**
  999. * Default size for line jumps.
  1000. */
  1001. Graph.defaultJumpSize = 6;
  1002. /**
  1003. * Minimum width for table columns.
  1004. */
  1005. Graph.minTableColumnWidth = 20;
  1006. /**
  1007. * Minimum height for table rows.
  1008. */
  1009. Graph.minTableRowHeight = 20;
  1010. /**
  1011. * Text for foreign object warning.
  1012. */
  1013. Graph.foreignObjectWarningText = 'Viewer does not support full SVG 1.1';
  1014. /**
  1015. * Link for foreign object warning.
  1016. */
  1017. Graph.foreignObjectWarningLink = 'https://desk.draw.io/support/solutions/articles/16000042487';
  1018. /**
  1019. * Minimum height for table rows.
  1020. */
  1021. Graph.pasteStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSource', 'fontSize', 'fontColor', 'fontStyle',
  1022. 'align', 'verticalAlign', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor', 'swimlaneFillColor',
  1023. 'textOpacity', 'gradientDirection', 'glass', 'labelBackgroundColor', 'labelBorderColor', 'opacity',
  1024. 'spacing', 'spacingTop', 'spacingLeft', 'spacingBottom', 'spacingRight', 'endFill', 'endArrow',
  1025. 'endSize', 'targetPerimeterSpacing', 'startFill', 'startArrow', 'startSize', 'sourcePerimeterSpacing',
  1026. 'arcSize', 'comic', 'sketch', 'fillWeight', 'hachureGap', 'hachureAngle', 'jiggle', 'disableMultiStroke',
  1027. 'disableMultiStrokeFill', 'fillStyle', 'curveFitting', 'simplification', 'comicStyle'];
  1028. /**
  1029. * Helper function for creating SVG data URI.
  1030. */
  1031. Graph.createSvgImage = function(w, h, data, coordWidth, coordHeight)
  1032. {
  1033. var tmp = unescape(encodeURIComponent(
  1034. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' +
  1035. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' + w + 'px" height="' + h + 'px" ' +
  1036. ((coordWidth != null && coordHeight != null) ? 'viewBox="0 0 ' + coordWidth + ' ' + coordHeight + '" ' : '') +
  1037. 'version="1.1">' + data + '</svg>'));
  1038. return new mxImage('data:image/svg+xml;base64,' + ((window.btoa) ? btoa(tmp) : Base64.encode(tmp, true)), w, h)
  1039. };
  1040. /**
  1041. * Removes all illegal control characters with ASCII code <32 except TAB, LF
  1042. * and CR.
  1043. */
  1044. Graph.zapGremlins = function(text)
  1045. {
  1046. var lastIndex = 0;
  1047. var checked = [];
  1048. for (var i = 0; i < text.length; i++)
  1049. {
  1050. var code = text.charCodeAt(i);
  1051. // Removes all control chars except TAB, LF and CR
  1052. if (!((code >= 32 || code == 9 || code == 10 || code == 13) &&
  1053. code != 0xFFFF && code != 0xFFFE))
  1054. {
  1055. checked.push(text.substring(lastIndex, i));
  1056. lastIndex = i + 1;
  1057. }
  1058. }
  1059. if (lastIndex > 0 && lastIndex < text.length)
  1060. {
  1061. checked.push(text.substring(lastIndex));
  1062. }
  1063. return (checked.length == 0) ? text : checked.join('');
  1064. };
  1065. /**
  1066. * Turns the given string into an array.
  1067. */
  1068. Graph.stringToBytes = function(str)
  1069. {
  1070. var arr = new Array(str.length);
  1071. for (var i = 0; i < str.length; i++)
  1072. {
  1073. arr[i] = str.charCodeAt(i);
  1074. }
  1075. return arr;
  1076. };
  1077. /**
  1078. * Turns the given array into a string.
  1079. */
  1080. Graph.bytesToString = function(arr)
  1081. {
  1082. var result = new Array(arr.length);
  1083. for (var i = 0; i < arr.length; i++)
  1084. {
  1085. result[i] = String.fromCharCode(arr[i]);
  1086. }
  1087. return result.join('');
  1088. };
  1089. /**
  1090. * Turns the given array into a string.
  1091. */
  1092. Graph.base64EncodeUnicode = function(str)
  1093. {
  1094. return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
  1095. return String.fromCharCode(parseInt(p1, 16))
  1096. }));
  1097. };
  1098. /**
  1099. * Turns the given array into a string.
  1100. */
  1101. Graph.base64DecodeUnicode = function(str)
  1102. {
  1103. return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
  1104. return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
  1105. }).join(''));
  1106. };
  1107. /**
  1108. * Returns a base64 encoded version of the compressed outer XML of the given node.
  1109. */
  1110. Graph.compressNode = function(node, checked)
  1111. {
  1112. var xml = mxUtils.getXml(node);
  1113. return Graph.compress((checked) ? xml : Graph.zapGremlins(xml));
  1114. };
  1115. /**
  1116. * Returns a base64 encoded version of the compressed string.
  1117. */
  1118. Graph.compress = function(data, deflate)
  1119. {
  1120. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1121. {
  1122. return data;
  1123. }
  1124. else
  1125. {
  1126. var tmp = (deflate) ? pako.deflate(encodeURIComponent(data), {to: 'string'}) :
  1127. pako.deflateRaw(encodeURIComponent(data), {to: 'string'});
  1128. return (window.btoa) ? btoa(tmp) : Base64.encode(tmp, true);
  1129. }
  1130. };
  1131. /**
  1132. * Returns a decompressed version of the base64 encoded string.
  1133. */
  1134. Graph.decompress = function(data, inflate, checked)
  1135. {
  1136. if (data == null || data.length == 0 || typeof(pako) === 'undefined')
  1137. {
  1138. return data;
  1139. }
  1140. else
  1141. {
  1142. var tmp = (window.atob) ? atob(data) : Base64.decode(data, true);
  1143. var inflated = decodeURIComponent((inflate) ?
  1144. pako.inflate(tmp, {to: 'string'}) :
  1145. pako.inflateRaw(tmp, {to: 'string'}));
  1146. return (checked) ? inflated : Graph.zapGremlins(inflated);
  1147. }
  1148. };
  1149. /**
  1150. * Removes formatting from pasted HTML.
  1151. */
  1152. Graph.removePasteFormatting = function(elt)
  1153. {
  1154. while (elt != null)
  1155. {
  1156. if (elt.firstChild != null)
  1157. {
  1158. Graph.removePasteFormatting(elt.firstChild);
  1159. }
  1160. if (elt.nodeType == mxConstants.NODETYPE_ELEMENT && elt.style != null)
  1161. {
  1162. elt.style.whiteSpace = '';
  1163. if (elt.style.color == '#000000')
  1164. {
  1165. elt.style.color = '';
  1166. }
  1167. }
  1168. elt = elt.nextSibling;
  1169. }
  1170. };
  1171. /**
  1172. * Sanitizes the given HTML markup.
  1173. */
  1174. Graph.sanitizeHtml = function(value, editing)
  1175. {
  1176. // Uses https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer
  1177. // NOTE: Original minimized sanitizer was modified to support
  1178. // data URIs for images, mailto and special data:-links.
  1179. // LATER: Add MathML to whitelisted tags
  1180. function urlX(link)
  1181. {
  1182. if (link != null && link.toString().toLowerCase().substring(0, 11) !== 'javascript:')
  1183. {
  1184. return link;
  1185. }
  1186. return null;
  1187. };
  1188. function idX(id) { return id };
  1189. return html_sanitize(value, urlX, idX);
  1190. };
  1191. /**
  1192. * Returns the CSS font family from the given computed style.
  1193. */
  1194. Graph.stripQuotes = function(text)
  1195. {
  1196. if (text != null)
  1197. {
  1198. if (text.charAt(0) == '\'')
  1199. {
  1200. text = text.substring(1);
  1201. }
  1202. if (text.charAt(text.length - 1) == '\'')
  1203. {
  1204. text = text.substring(0, text.length - 1);
  1205. }
  1206. if (text.charAt(0) == '"')
  1207. {
  1208. text = text.substring(1);
  1209. }
  1210. if (text.charAt(text.length - 1) == '"')
  1211. {
  1212. text = text.substring(0, text.length - 1);
  1213. }
  1214. }
  1215. return text;
  1216. };
  1217. /**
  1218. * Returns true if the given string is a link.
  1219. *
  1220. * See https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
  1221. */
  1222. Graph.isLink = function(text)
  1223. {
  1224. return text != null && Graph.linkPattern.test(text);
  1225. };
  1226. /**
  1227. * Regular expression for links.
  1228. */
  1229. Graph.linkPattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
  1230. '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
  1231. '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
  1232. '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
  1233. '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
  1234. '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
  1235. /**
  1236. * Graph inherits from mxGraph.
  1237. */
  1238. mxUtils.extend(Graph, mxGraph);
  1239. /**
  1240. * Allows all values in fit.
  1241. */
  1242. Graph.prototype.minFitScale = null;
  1243. /**
  1244. * Allows all values in fit.
  1245. */
  1246. Graph.prototype.maxFitScale = null;
  1247. /**
  1248. * Sets the policy for links. Possible values are "self" to replace any framesets,
  1249. * "blank" to load the URL in <linkTarget> and "auto" (default).
  1250. */
  1251. Graph.prototype.linkPolicy = (urlParams['target'] == 'frame') ? 'blank' : (urlParams['target'] || 'auto');
  1252. /**
  1253. * Target for links that open in a new window. Default is _blank.
  1254. */
  1255. Graph.prototype.linkTarget = (urlParams['target'] == 'frame') ? '_self' : '_blank';
  1256. /**
  1257. * Value to the rel attribute of links. Default is 'nofollow noopener noreferrer'.
  1258. * NOTE: There are security implications when this is changed and if noopener is removed,
  1259. * then <openLink> must be overridden to allow for the opener to be set by default.
  1260. */
  1261. Graph.prototype.linkRelation = 'nofollow noopener noreferrer';
  1262. /**
  1263. * Scrollbars are enabled on non-touch devices (not including Firefox because touch events
  1264. * cannot be detected in Firefox, see above).
  1265. */
  1266. Graph.prototype.defaultScrollbars = !mxClient.IS_IOS;
  1267. /**
  1268. * Specifies if the page should be visible for new files. Default is true.
  1269. */
  1270. Graph.prototype.defaultPageVisible = true;
  1271. /**
  1272. * Specifies if the app should run in chromeless mode. Default is false.
  1273. * This default is only used if the contructor argument is null.
  1274. */
  1275. Graph.prototype.lightbox = false;
  1276. /**
  1277. *
  1278. */
  1279. Graph.prototype.defaultPageBackgroundColor = '#ffffff';
  1280. /**
  1281. *
  1282. */
  1283. Graph.prototype.defaultPageBorderColor = '#ffffff';
  1284. /**
  1285. * Specifies the size of the size for "tiles" to be used for a graph with
  1286. * scrollbars but no visible background page. A good value is large
  1287. * enough to reduce the number of repaints that is caused for auto-
  1288. * translation, which depends on this value, and small enough to give
  1289. * a small empty buffer around the graph. Default is 400x400.
  1290. */
  1291. Graph.prototype.scrollTileSize = new mxRectangle(0, 0, 400, 400);
  1292. /**
  1293. * Overrides the background color and paints a transparent background.
  1294. */
  1295. Graph.prototype.transparentBackground = true;
  1296. /**
  1297. * Sets global constants.
  1298. */
  1299. Graph.prototype.selectParentAfterDelete = false;
  1300. /**
  1301. * Sets the default target for all links in cells.
  1302. */
  1303. Graph.prototype.defaultEdgeLength = 80;
  1304. /**
  1305. * Disables move of bends/segments without selecting.
  1306. */
  1307. Graph.prototype.edgeMode = false;
  1308. /**
  1309. * Allows all values in fit.
  1310. */
  1311. Graph.prototype.connectionArrowsEnabled = true;
  1312. /**
  1313. * Specifies the regular expression for matching placeholders.
  1314. */
  1315. Graph.prototype.placeholderPattern = new RegExp('%(date\{.*\}|[^%^\{^\}]+)%', 'g');
  1316. /**
  1317. * Specifies the regular expression for matching placeholders.
  1318. */
  1319. Graph.prototype.absoluteUrlPattern = new RegExp('^(?:[a-z]+:)?//', 'i');
  1320. /**
  1321. * Specifies the default name for the theme. Default is 'default'.
  1322. */
  1323. Graph.prototype.defaultThemeName = 'default';
  1324. /**
  1325. * Specifies the default name for the theme. Default is 'default'.
  1326. */
  1327. Graph.prototype.defaultThemes = {};
  1328. /**
  1329. * Base URL for relative links.
  1330. */
  1331. Graph.prototype.baseUrl = (urlParams['base'] != null) ?
  1332. decodeURIComponent(urlParams['base']) :
  1333. (((window != window.top) ? document.referrer :
  1334. document.location.toString()).split('#')[0]);
  1335. /**
  1336. * Specifies if the label should be edited after an insert.
  1337. */
  1338. Graph.prototype.editAfterInsert = false;
  1339. /**
  1340. * Defines the built-in properties to be ignored in tooltips.
  1341. */
  1342. Graph.prototype.builtInProperties = ['label', 'tooltip', 'placeholders', 'placeholder'];
  1343. /**
  1344. * Defines if the graph is part of an EditorUi. If this is false the graph can
  1345. * be used in an EditorUi instance but will not have a UI added, functions
  1346. * overridden or event handlers added.
  1347. */
  1348. Graph.prototype.standalone = false;
  1349. /**
  1350. * Installs child layout styles.
  1351. */
  1352. Graph.prototype.init = function(container)
  1353. {
  1354. mxGraph.prototype.init.apply(this, arguments);
  1355. // Intercepts links with no target attribute and opens in new window
  1356. this.cellRenderer.initializeLabel = function(state, shape)
  1357. {
  1358. mxCellRenderer.prototype.initializeLabel.apply(this, arguments);
  1359. // Checks tolerance for clicks on links
  1360. var tol = state.view.graph.tolerance;
  1361. var handleClick = true;
  1362. var first = null;
  1363. var down = mxUtils.bind(this, function(evt)
  1364. {
  1365. handleClick = true;
  1366. first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  1367. });
  1368. var move = mxUtils.bind(this, function(evt)
  1369. {
  1370. handleClick = handleClick && first != null &&
  1371. Math.abs(first.x - mxEvent.getClientX(evt)) < tol &&
  1372. Math.abs(first.y - mxEvent.getClientY(evt)) < tol;
  1373. });
  1374. var up = mxUtils.bind(this, function(evt)
  1375. {
  1376. if (handleClick)
  1377. {
  1378. var elt = mxEvent.getSource(evt)
  1379. while (elt != null && elt != shape.node)
  1380. {
  1381. if (elt.nodeName.toLowerCase() == 'a')
  1382. {
  1383. state.view.graph.labelLinkClicked(state, elt, evt);
  1384. break;
  1385. }
  1386. elt = elt.parentNode;
  1387. }
  1388. }
  1389. });
  1390. mxEvent.addGestureListeners(shape.node, down, move, up);
  1391. mxEvent.addListener(shape.node, 'click', function(evt)
  1392. {
  1393. mxEvent.consume(evt);
  1394. });
  1395. };
  1396. this.initLayoutManager();
  1397. };
  1398. /**
  1399. * Implements zoom and offset via CSS transforms. This is currently only used
  1400. * in read-only as there are fewer issues with the mxCellState not being scaled
  1401. * and translated.
  1402. *
  1403. * KNOWN ISSUES TO FIX:
  1404. * - Apply CSS transforms to HTML labels in IE11
  1405. */
  1406. (function()
  1407. {
  1408. /**
  1409. * Uses CSS transforms for scale and translate.
  1410. */
  1411. Graph.prototype.useCssTransforms = false;
  1412. /**
  1413. * Contains the scale.
  1414. */
  1415. Graph.prototype.currentScale = 1;
  1416. /**
  1417. * Contains the offset.
  1418. */
  1419. Graph.prototype.currentTranslate = new mxPoint(0, 0);
  1420. /**
  1421. *
  1422. */
  1423. Graph.prototype.getVerticesAndEdges = function(vertices, edges)
  1424. {
  1425. vertices = (vertices != null) ? vertices : true;
  1426. edges = (edges != null) ? edges : true;
  1427. var model = this.model;
  1428. return model.filterDescendants(function(cell)
  1429. {
  1430. return (vertices && model.isVertex(cell)) || (edges && model.isEdge(cell));
  1431. }, model.getRoot());
  1432. };
  1433. /**
  1434. * Returns the cell for editing the given cell.
  1435. */
  1436. Graph.prototype.getStartEditingCell = function(cell, trigger)
  1437. {
  1438. // Redirect editing for tables
  1439. var style = this.getCellStyle(cell);
  1440. var size = parseInt(mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE, 0));
  1441. if (this.isTable(cell) && (!this.isSwimlane(cell) ||
  1442. size == 0) && this.getLabel(cell) == '' &&
  1443. this.model.getChildCount(cell) > 0)
  1444. {
  1445. cell = this.model.getChildAt(cell, 0);
  1446. style = this.getCellStyle(cell);
  1447. size = parseInt(mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE, 0));
  1448. }
  1449. // Redirect editing for table rows
  1450. if (this.isTableRow(cell) && (!this.isSwimlane(cell) ||
  1451. size == 0) && this.getLabel(cell) == '' &&
  1452. this.model.getChildCount(cell) > 0)
  1453. {
  1454. for (var i = 0; i < this.model.getChildCount(cell); i++)
  1455. {
  1456. var temp = this.model.getChildAt(cell, i);
  1457. if (this.isCellEditable(temp))
  1458. {
  1459. cell = temp;
  1460. break;
  1461. }
  1462. }
  1463. }
  1464. return cell;
  1465. };
  1466. /**
  1467. * Returns true if fast zoom preview should be used.
  1468. */
  1469. Graph.prototype.copyStyle = function(cell)
  1470. {
  1471. var style = null;
  1472. if (cell != null)
  1473. {
  1474. style = mxUtils.clone(this.getCurrentCellStyle(cell));
  1475. // Handles special case for value "none"
  1476. var cellStyle = this.model.getStyle(cell);
  1477. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  1478. for (var j = 0; j < tokens.length; j++)
  1479. {
  1480. var tmp = tokens[j];
  1481. var pos = tmp.indexOf('=');
  1482. if (pos >= 0)
  1483. {
  1484. var key = tmp.substring(0, pos);
  1485. var value = tmp.substring(pos + 1);
  1486. if (style[key] == null && value == mxConstants.NONE)
  1487. {
  1488. style[key] = mxConstants.NONE;
  1489. }
  1490. }
  1491. }
  1492. }
  1493. return style;
  1494. };
  1495. /**
  1496. * Returns true if fast zoom preview should be used.
  1497. */
  1498. Graph.prototype.pasteStyle = function(style, cells, keys)
  1499. {
  1500. keys = (keys != null) ? keys : Graph.pasteStyles;
  1501. this.model.beginUpdate();
  1502. try
  1503. {
  1504. for (var i = 0; i < cells.length; i++)
  1505. {
  1506. var temp = this.getCurrentCellStyle(cells[i]);
  1507. for (var j = 0; j < keys.length; j++)
  1508. {
  1509. var current = temp[keys[j]];
  1510. var value = style[keys[j]];
  1511. if (current != value && (current != null || value != mxConstants.NONE))
  1512. {
  1513. this.setCellStyles(keys[j], value, [cells[i]]);
  1514. }
  1515. }
  1516. }
  1517. }
  1518. finally
  1519. {
  1520. this.model.endUpdate();
  1521. }
  1522. };
  1523. /**
  1524. * Returns true if fast zoom preview should be used.
  1525. */
  1526. Graph.prototype.isFastZoomEnabled = function()
  1527. {
  1528. return urlParams['zoom'] != 'nocss' && !mxClient.NO_FO && !mxClient.IS_EDGE &&
  1529. !this.useCssTransforms && this.isCssTransformsSupported();
  1530. };
  1531. /**
  1532. * Only foreignObject supported for now (no IE11). Safari disabled as it ignores
  1533. * overflow visible on foreignObject in negative space (lightbox and viewer).
  1534. * Check the following test case on page 1 before enabling this in production:
  1535. * https://devhost.jgraph.com/git/drawio/etc/embed/sf-math-fo-clipping.html?dev=1
  1536. */
  1537. Graph.prototype.isCssTransformsSupported = function()
  1538. {
  1539. return this.dialect == mxConstants.DIALECT_SVG && !mxClient.NO_FO &&
  1540. (!this.lightbox || !mxClient.IS_SF);
  1541. };
  1542. /**
  1543. * Function: getCellAt
  1544. *
  1545. * Needs to modify original method for recursive call.
  1546. */
  1547. Graph.prototype.getCellAt = function(x, y, parent, vertices, edges, ignoreFn)
  1548. {
  1549. if (this.useCssTransforms)
  1550. {
  1551. x = x / this.currentScale - this.currentTranslate.x;
  1552. y = y / this.currentScale - this.currentTranslate.y;
  1553. }
  1554. return this.getScaledCellAt.apply(this, arguments);
  1555. };
  1556. /**
  1557. * Function: getScaledCellAt
  1558. *
  1559. * Overridden for recursion.
  1560. */
  1561. Graph.prototype.getScaledCellAt = function(x, y, parent, vertices, edges, ignoreFn)
  1562. {
  1563. vertices = (vertices != null) ? vertices : true;
  1564. edges = (edges != null) ? edges : true;
  1565. if (parent == null)
  1566. {
  1567. parent = this.getCurrentRoot();
  1568. if (parent == null)
  1569. {
  1570. parent = this.getModel().getRoot();
  1571. }
  1572. }
  1573. if (parent != null)
  1574. {
  1575. var childCount = this.model.getChildCount(parent);
  1576. for (var i = childCount - 1; i >= 0; i--)
  1577. {
  1578. var cell = this.model.getChildAt(parent, i);
  1579. var result = this.getScaledCellAt(x, y, cell, vertices, edges, ignoreFn);
  1580. if (result != null)
  1581. {
  1582. return result;
  1583. }
  1584. else if (this.isCellVisible(cell) && (edges && this.model.isEdge(cell) ||
  1585. vertices && this.model.isVertex(cell)))
  1586. {
  1587. var state = this.view.getState(cell);
  1588. if (state != null && (ignoreFn == null || !ignoreFn(state, x, y)) &&
  1589. this.intersects(state, x, y))
  1590. {
  1591. return cell;
  1592. }
  1593. }
  1594. }
  1595. }
  1596. return null;
  1597. };
  1598. /**
  1599. * Returns if the child cells of the given vertex cell state should be resized.
  1600. */
  1601. Graph.prototype.isRecursiveVertexResize = function(state)
  1602. {
  1603. return !this.isSwimlane(state.cell) && this.model.getChildCount(state.cell) > 0 &&
  1604. !this.isCellCollapsed(state.cell) && mxUtils.getValue(state.style, 'recursiveResize', '1') == '1' &&
  1605. mxUtils.getValue(state.style, 'childLayout', null) == null;
  1606. }
  1607. /**
  1608. * Returns the first parent that is not a part.
  1609. */
  1610. Graph.prototype.isPart = function(cell)
  1611. {
  1612. return mxUtils.getValue(this.getCurrentCellStyle(cell), 'part', '0') == '1' ||
  1613. this.isTableCell(cell) || this.isTableRow(cell);
  1614. };
  1615. /**
  1616. * Returns the first parent that is not a part.
  1617. */
  1618. Graph.prototype.getCompositeParent = function(cell)
  1619. {
  1620. while (this.isPart(cell))
  1621. {
  1622. var temp = this.model.getParent(cell);
  1623. if (!this.model.isVertex(temp))
  1624. {
  1625. break;
  1626. }
  1627. cell = temp;
  1628. }
  1629. return cell;
  1630. };
  1631. /**
  1632. * Function: repaint
  1633. *
  1634. * Updates the highlight after a change of the model or view.
  1635. */
  1636. mxCellHighlight.prototype.getStrokeWidth = function(state)
  1637. {
  1638. var s = this.strokeWidth;
  1639. if (this.graph.useCssTransforms)
  1640. {
  1641. s /= this.graph.currentScale;
  1642. }
  1643. return s;
  1644. };
  1645. /**
  1646. * Function: getGraphBounds
  1647. *
  1648. * Overrides getGraphBounds to use bounding box from SVG.
  1649. */
  1650. mxGraphView.prototype.getGraphBounds = function()
  1651. {
  1652. var b = this.graphBounds;
  1653. if (this.graph.useCssTransforms)
  1654. {
  1655. var t = this.graph.currentTranslate;
  1656. var s = this.graph.currentScale;
  1657. b = new mxRectangle(
  1658. (b.x + t.x) * s, (b.y + t.y) * s,
  1659. b.width * s, b.height * s);
  1660. }
  1661. return b;
  1662. };
  1663. /**
  1664. * Overrides to bypass full cell tree validation.
  1665. * TODO: Check if this improves performance
  1666. */
  1667. mxGraphView.prototype.viewStateChanged = function()
  1668. {
  1669. if (this.graph.useCssTransforms)
  1670. {
  1671. this.validate();
  1672. this.graph.sizeDidChange();
  1673. }
  1674. else
  1675. {
  1676. this.revalidate();
  1677. this.graph.sizeDidChange();
  1678. }
  1679. };
  1680. /**
  1681. * Overrides validate to normalize validation view state and pass
  1682. * current state to CSS transform.
  1683. */
  1684. var graphViewValidate = mxGraphView.prototype.validate;
  1685. mxGraphView.prototype.validate = function(cell)
  1686. {
  1687. if (this.graph.useCssTransforms)
  1688. {
  1689. this.graph.currentScale = this.scale;
  1690. this.graph.currentTranslate.x = this.translate.x;
  1691. this.graph.currentTranslate.y = this.translate.y;
  1692. this.scale = 1;
  1693. this.translate.x = 0;
  1694. this.translate.y = 0;
  1695. }
  1696. graphViewValidate.apply(this, arguments);
  1697. if (this.graph.useCssTransforms)
  1698. {
  1699. this.graph.updateCssTransform();
  1700. this.scale = this.graph.currentScale;
  1701. this.translate.x = this.graph.currentTranslate.x;
  1702. this.translate.y = this.graph.currentTranslate.y;
  1703. }
  1704. };
  1705. /**
  1706. * Overrides function to exclude table cells and rows from groups.
  1707. */
  1708. var graphGetCellsForGroup = mxGraph.prototype.getCellsForGroup;
  1709. Graph.prototype.getCellsForGroup = function(cells)
  1710. {
  1711. cells = graphGetCellsForGroup.apply(this, arguments);
  1712. var result = [];
  1713. // Filters selection cells with the same parent
  1714. for (var i = 0; i < cells.length; i++)
  1715. {
  1716. if (!this.isTableRow(cells[i]) &&
  1717. !this.isTableCell(cells[i]))
  1718. {
  1719. result.push(cells[i]);
  1720. }
  1721. }
  1722. return result;
  1723. };
  1724. /**
  1725. * Overrides function to exclude tables, rows and cells from ungrouping.
  1726. */
  1727. var graphGetCellsForUngroup = mxGraph.prototype.getCellsForUngroup;
  1728. Graph.prototype.getCellsForUngroup = function(cells)
  1729. {
  1730. cells = graphGetCellsForUngroup.apply(this, arguments);
  1731. var result = [];
  1732. // Filters selection cells with the same parent
  1733. for (var i = 0; i < cells.length; i++)
  1734. {
  1735. if (!this.isTable(cells[i]) &&
  1736. !this.isTableRow(cells[i]) &&
  1737. !this.isTableCell(cells[i]))
  1738. {
  1739. result.push(cells[i]);
  1740. }
  1741. }
  1742. return result;
  1743. };
  1744. /**
  1745. * Function: updateCssTransform
  1746. *
  1747. * Zooms out of the graph by <zoomFactor>.
  1748. */
  1749. Graph.prototype.updateCssTransform = function()
  1750. {
  1751. var temp = this.view.getDrawPane();
  1752. if (temp != null)
  1753. {
  1754. var g = temp.parentNode;
  1755. if (!this.useCssTransforms)
  1756. {
  1757. g.removeAttribute('transformOrigin');
  1758. g.removeAttribute('transform');
  1759. }
  1760. else
  1761. {
  1762. var prev = g.getAttribute('transform');
  1763. g.setAttribute('transformOrigin', '0 0');
  1764. var s = Math.round(this.currentScale * 100) / 100;
  1765. var dx = Math.round(this.currentTranslate.x * 100) / 100;
  1766. var dy = Math.round(this.currentTranslate.y * 100) / 100;
  1767. g.setAttribute('transform', 'scale(' + s + ',' + s + ')' +
  1768. 'translate(' + dx + ',' + dy + ')');
  1769. // Applies workarounds only if translate has changed
  1770. if (prev != g.getAttribute('transform'))
  1771. {
  1772. try
  1773. {
  1774. // Applies transform to labels outside of the SVG DOM
  1775. // Excluded via isCssTransformsSupported
  1776. // if (mxClient.NO_FO)
  1777. // {
  1778. // var transform = 'scale(' + this.currentScale + ')' + 'translate(' +
  1779. // this.currentTranslate.x + 'px,' + this.currentTranslate.y + 'px)';
  1780. //
  1781. // this.view.states.visit(mxUtils.bind(this, function(cell, state)
  1782. // {
  1783. // if (state.text != null && state.text.node != null)
  1784. // {
  1785. // // Stores initial CSS transform that is used for the label alignment
  1786. // if (state.text.originalTransform == null)
  1787. // {
  1788. // state.text.originalTransform = state.text.node.style.transform;
  1789. // }
  1790. //
  1791. // state.text.node.style.transform = transform + state.text.originalTransform;
  1792. // }
  1793. // }));
  1794. // }
  1795. // Workaround for https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/4320441/
  1796. if (mxClient.IS_EDGE)
  1797. {
  1798. // Recommended workaround is to do this on all
  1799. // foreignObjects, but this seems to be faster
  1800. var val = g.style.display;
  1801. g.style.display = 'none';
  1802. g.getBBox();
  1803. g.style.display = val;
  1804. }
  1805. }
  1806. catch (e)
  1807. {
  1808. // ignore
  1809. }
  1810. }
  1811. }
  1812. }
  1813. };
  1814. var graphViewValidateBackgroundPage = mxGraphView.prototype.validateBackgroundPage;
  1815. mxGraphView.prototype.validateBackgroundPage = function()
  1816. {
  1817. var useCssTranforms = this.graph.useCssTransforms, scale = this.scale,
  1818. translate = this.translate;
  1819. if (useCssTranforms)
  1820. {
  1821. this.scale = this.graph.currentScale;
  1822. this.translate = this.graph.currentTranslate;
  1823. }
  1824. graphViewValidateBackgroundPage.apply(this, arguments);
  1825. if (useCssTranforms)
  1826. {
  1827. this.scale = scale;
  1828. this.translate = translate;
  1829. }
  1830. };
  1831. var graphUpdatePageBreaks = mxGraph.prototype.updatePageBreaks;
  1832. mxGraph.prototype.updatePageBreaks = function(visible, width, height)
  1833. {
  1834. var useCssTranforms = this.useCssTransforms, scale = this.view.scale,
  1835. translate = this.view.translate;
  1836. if (useCssTranforms)
  1837. {
  1838. this.view.scale = 1;
  1839. this.view.translate = new mxPoint(0, 0);
  1840. this.useCssTransforms = false;
  1841. }
  1842. graphUpdatePageBreaks.apply(this, arguments);
  1843. if (useCssTranforms)
  1844. {
  1845. this.view.scale = scale;
  1846. this.view.translate = translate;
  1847. this.useCssTransforms = true;
  1848. }
  1849. };
  1850. })();
  1851. /**
  1852. * Sets the XML node for the current diagram.
  1853. */
  1854. Graph.prototype.isLightboxView = function()
  1855. {
  1856. return this.lightbox;
  1857. };
  1858. /**
  1859. * Sets the XML node for the current diagram.
  1860. */
  1861. Graph.prototype.isViewer = function()
  1862. {
  1863. return false;
  1864. };
  1865. /**
  1866. * Installs automatic layout via styles
  1867. */
  1868. Graph.prototype.labelLinkClicked = function(state, elt, evt)
  1869. {
  1870. var href = elt.getAttribute('href');
  1871. if (href != null && !this.isCustomLink(href) && ((mxEvent.isLeftMouseButton(evt) &&
  1872. !mxEvent.isPopupTrigger(evt)) || mxEvent.isTouchEvent(evt)))
  1873. {
  1874. if (!this.isEnabled() || this.isCellLocked(state.cell))
  1875. {
  1876. var target = this.isBlankLink(href) ? this.linkTarget : '_top';
  1877. this.openLink(this.getAbsoluteUrl(href), target);
  1878. }
  1879. mxEvent.consume(evt);
  1880. }
  1881. };
  1882. /**
  1883. * Returns the size of the page format scaled with the page size.
  1884. */
  1885. Graph.prototype.openLink = function(href, target, allowOpener)
  1886. {
  1887. var result = window;
  1888. try
  1889. {
  1890. // Workaround for blocking in same iframe
  1891. if (target == '_self' && window != window.top)
  1892. {
  1893. window.location.href = href;
  1894. }
  1895. else
  1896. {
  1897. // Avoids page reload for anchors (workaround for IE but used everywhere)
  1898. if (href.substring(0, this.baseUrl.length) == this.baseUrl &&
  1899. href.charAt(this.baseUrl.length) == '#' &&
  1900. target == '_top' && window == window.top)
  1901. {
  1902. var hash = href.split('#')[1];
  1903. // Forces navigation if on same hash
  1904. if (window.location.hash == '#' + hash)
  1905. {
  1906. window.location.hash = '';
  1907. }
  1908. window.location.hash = hash;
  1909. }
  1910. else
  1911. {
  1912. result = window.open(href, (target != null) ? target : '_blank');
  1913. if (result != null && !allowOpener)
  1914. {
  1915. result.opener = null;
  1916. }
  1917. }
  1918. }
  1919. }
  1920. catch (e)
  1921. {
  1922. // ignores permission denied
  1923. }
  1924. return result;
  1925. };
  1926. /**
  1927. * Adds support for page links.
  1928. */
  1929. Graph.prototype.getLinkTitle = function(href)
  1930. {
  1931. return href.substring(href.lastIndexOf('/') + 1);
  1932. };
  1933. /**
  1934. * Adds support for page links.
  1935. */
  1936. Graph.prototype.isCustomLink = function(href)
  1937. {
  1938. return href.substring(0, 5) == 'data:';
  1939. };
  1940. /**
  1941. * Adds support for page links.
  1942. */
  1943. Graph.prototype.customLinkClicked = function(link)
  1944. {
  1945. return false;
  1946. };
  1947. /**
  1948. * Returns true if the given href references an external protocol that
  1949. * should never open in a new window. Default returns true for mailto.
  1950. */
  1951. Graph.prototype.isExternalProtocol = function(href)
  1952. {
  1953. return href.substring(0, 7) === 'mailto:';
  1954. };
  1955. /**
  1956. * Hook for links to open in same window. Default returns true for anchors,
  1957. * links to same domain or if target == 'self' in the config.
  1958. */
  1959. Graph.prototype.isBlankLink = function(href)
  1960. {
  1961. return !this.isExternalProtocol(href) &&
  1962. (this.linkPolicy === 'blank' ||
  1963. (this.linkPolicy !== 'self' &&
  1964. !this.isRelativeUrl(href) &&
  1965. href.substring(0, this.domainUrl.length) !== this.domainUrl));
  1966. };
  1967. /**
  1968. *
  1969. */
  1970. Graph.prototype.isRelativeUrl = function(url)
  1971. {
  1972. return url != null && !this.absoluteUrlPattern.test(url) &&
  1973. url.substring(0, 5) !== 'data:' &&
  1974. !this.isExternalProtocol(url);
  1975. };
  1976. /**
  1977. *
  1978. */
  1979. Graph.prototype.getAbsoluteUrl = function(url)
  1980. {
  1981. if (url != null && this.isRelativeUrl(url))
  1982. {
  1983. if (url.charAt(0) == '#')
  1984. {
  1985. url = this.baseUrl + url;
  1986. }
  1987. else if (url.charAt(0) == '/')
  1988. {
  1989. url = this.domainUrl + url;
  1990. }
  1991. else
  1992. {
  1993. url = this.domainPathUrl + url;
  1994. }
  1995. }
  1996. return url;
  1997. };
  1998. /**
  1999. * Installs automatic layout via styles
  2000. */
  2001. Graph.prototype.initLayoutManager = function()
  2002. {
  2003. this.layoutManager = new mxLayoutManager(this);
  2004. this.layoutManager.hasLayout = function(cell, eventName)
  2005. {
  2006. return this.graph.getCellStyle(cell)['childLayout'] != null;
  2007. };
  2008. this.layoutManager.getLayout = function(cell, eventName)
  2009. {
  2010. var parent = this.graph.model.getParent(cell);
  2011. // Executes layouts from top to bottom except for nested layouts where
  2012. // child layouts are executed before and after the parent layout runs
  2013. // in case the layout changes the size of the child cell
  2014. if (eventName != mxEvent.BEGIN_UPDATE || this.hasLayout(parent, eventName))
  2015. {
  2016. var style = this.graph.getCellStyle(cell);
  2017. if (style['childLayout'] == 'stackLayout')
  2018. {
  2019. var stackLayout = new mxStackLayout(this.graph, true);
  2020. stackLayout.resizeParentMax = mxUtils.getValue(style, 'resizeParentMax', '1') == '1';
  2021. stackLayout.horizontal = mxUtils.getValue(style, 'horizontalStack', '1') == '1';
  2022. stackLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  2023. stackLayout.resizeLast = mxUtils.getValue(style, 'resizeLast', '0') == '1';
  2024. stackLayout.spacing = style['stackSpacing'] || stackLayout.spacing;
  2025. stackLayout.border = style['stackBorder'] || stackLayout.border;
  2026. stackLayout.marginLeft = style['marginLeft'] || 0;
  2027. stackLayout.marginRight = style['marginRight'] || 0;
  2028. stackLayout.marginTop = style['marginTop'] || 0;
  2029. stackLayout.marginBottom = style['marginBottom'] || 0;
  2030. stackLayout.allowGaps = style['allowGaps'] || 0;
  2031. stackLayout.fill = true;
  2032. if (stackLayout.allowGaps)
  2033. {
  2034. stackLayout.gridSize = parseFloat(mxUtils.getValue(style, 'stackUnitSize', 20));
  2035. }
  2036. return stackLayout;
  2037. }
  2038. else if (style['childLayout'] == 'treeLayout')
  2039. {
  2040. var treeLayout = new mxCompactTreeLayout(this.graph);
  2041. treeLayout.horizontal = mxUtils.getValue(style, 'horizontalTree', '1') == '1';
  2042. treeLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  2043. treeLayout.groupPadding = mxUtils.getValue(style, 'parentPadding', 20);
  2044. treeLayout.levelDistance = mxUtils.getValue(style, 'treeLevelDistance', 30);
  2045. treeLayout.maintainParentLocation = true;
  2046. treeLayout.edgeRouting = false;
  2047. treeLayout.resetEdges = false;
  2048. return treeLayout;
  2049. }
  2050. else if (style['childLayout'] == 'flowLayout')
  2051. {
  2052. var flowLayout = new mxHierarchicalLayout(this.graph, mxUtils.getValue(style,
  2053. 'flowOrientation', mxConstants.DIRECTION_EAST));
  2054. flowLayout.resizeParent = mxUtils.getValue(style, 'resizeParent', '1') == '1';
  2055. flowLayout.parentBorder = mxUtils.getValue(style, 'parentPadding', 20);
  2056. flowLayout.maintainParentLocation = true;
  2057. // Special undocumented styles for changing the hierarchical
  2058. flowLayout.intraCellSpacing = mxUtils.getValue(style, 'intraCellSpacing',
  2059. mxHierarchicalLayout.prototype.intraCellSpacing);
  2060. flowLayout.interRankCellSpacing = mxUtils.getValue(style, 'interRankCellSpacing',
  2061. mxHierarchicalLayout.prototype.interRankCellSpacing);
  2062. flowLayout.interHierarchySpacing = mxUtils.getValue(style, 'interHierarchySpacing',
  2063. mxHierarchicalLayout.prototype.interHierarchySpacing);
  2064. flowLayout.parallelEdgeSpacing = mxUtils.getValue(style, 'parallelEdgeSpacing',
  2065. mxHierarchicalLayout.prototype.parallelEdgeSpacing);
  2066. return flowLayout;
  2067. }
  2068. else if (style['childLayout'] == 'circleLayout')
  2069. {
  2070. return new mxCircleLayout(this.graph);
  2071. }
  2072. else if (style['childLayout'] == 'organicLayout')
  2073. {
  2074. return new mxFastOrganicLayout(this.graph);
  2075. }
  2076. else if (style['childLayout'] == 'tableLayout')
  2077. {
  2078. return new TableLayout(this.graph);
  2079. }
  2080. }
  2081. return null;
  2082. };
  2083. };
  2084. /**
  2085. * Returns the size of the page format scaled with the page size.
  2086. */
  2087. Graph.prototype.getPageSize = function()
  2088. {
  2089. return (this.pageVisible) ? new mxRectangle(0, 0, this.pageFormat.width * this.pageScale,
  2090. this.pageFormat.height * this.pageScale) : this.scrollTileSize;
  2091. };
  2092. /**
  2093. * Returns a rectangle describing the position and count of the
  2094. * background pages, where x and y are the position of the top,
  2095. * left page and width and height are the vertical and horizontal
  2096. * page count.
  2097. */
  2098. Graph.prototype.getPageLayout = function()
  2099. {
  2100. var size = this.getPageSize();
  2101. var bounds = this.getGraphBounds();
  2102. if (bounds.width == 0 || bounds.height == 0)
  2103. {
  2104. return new mxRectangle(0, 0, 1, 1);
  2105. }
  2106. else
  2107. {
  2108. var x0 = Math.floor(Math.ceil(bounds.x / this.view.scale -
  2109. this.view.translate.x) / size.width);
  2110. var y0 = Math.floor(Math.ceil(bounds.y / this.view.scale -
  2111. this.view.translate.y) / size.height);
  2112. var w0 = Math.ceil((Math.floor((bounds.x + bounds.width) / this.view.scale) -
  2113. this.view.translate.x) / size.width) - x0;
  2114. var h0 = Math.ceil((Math.floor((bounds.y + bounds.height) / this.view.scale) -
  2115. this.view.translate.y) / size.height) - y0;
  2116. return new mxRectangle(x0, y0, w0, h0);
  2117. }
  2118. };
  2119. /**
  2120. * Sanitizes the given HTML markup.
  2121. */
  2122. Graph.prototype.sanitizeHtml = function(value, editing)
  2123. {
  2124. return Graph.sanitizeHtml(value, editing);
  2125. };
  2126. /**
  2127. * Revalidates all cells with placeholders in the current graph model.
  2128. */
  2129. Graph.prototype.updatePlaceholders = function()
  2130. {
  2131. var model = this.model;
  2132. var validate = false;
  2133. for (var key in this.model.cells)
  2134. {
  2135. var cell = this.model.cells[key];
  2136. if (this.isReplacePlaceholders(cell))
  2137. {
  2138. this.view.invalidate(cell, false, false);
  2139. validate = true;
  2140. }
  2141. }
  2142. if (validate)
  2143. {
  2144. this.view.validate();
  2145. }
  2146. };
  2147. /**
  2148. * Adds support for placeholders in labels.
  2149. */
  2150. Graph.prototype.isReplacePlaceholders = function(cell)
  2151. {
  2152. return cell.value != null && typeof(cell.value) == 'object' &&
  2153. cell.value.getAttribute('placeholders') == '1';
  2154. };
  2155. /**
  2156. * Returns true if the given mouse wheel event should be used for zooming. This
  2157. * is invoked if no dialogs are showing and returns true with Alt or Control
  2158. * (or cmd in macOS only) is pressed.
  2159. */
  2160. Graph.prototype.isZoomWheelEvent = function(evt)
  2161. {
  2162. return mxEvent.isAltDown(evt) || (mxEvent.isMetaDown(evt) && mxClient.IS_MAC) ||
  2163. mxEvent.isControlDown(evt);
  2164. };
  2165. /**
  2166. * Returns true if the given scroll wheel event should be used for scrolling.
  2167. */
  2168. Graph.prototype.isScrollWheelEvent = function(evt)
  2169. {
  2170. return !this.isZoomWheelEvent(evt);
  2171. };
  2172. /**
  2173. * Adds Alt+click to select cells behind cells (Shift+Click on Chrome OS).
  2174. */
  2175. Graph.prototype.isTransparentClickEvent = function(evt)
  2176. {
  2177. return mxEvent.isAltDown(evt) || (mxClient.IS_CHROMEOS && mxEvent.isShiftDown(evt));
  2178. };
  2179. /**
  2180. * Adds ctrl+shift+connect to disable connections.
  2181. */
  2182. Graph.prototype.isIgnoreTerminalEvent = function(evt)
  2183. {
  2184. return mxEvent.isShiftDown(evt) && mxEvent.isControlDown(evt);
  2185. };
  2186. /**
  2187. * Adds support for placeholders in labels.
  2188. */
  2189. Graph.prototype.isSplitTarget = function(target, cells, evt)
  2190. {
  2191. return !this.model.isEdge(cells[0]) &&
  2192. !mxEvent.isAltDown(evt) && !mxEvent.isShiftDown(evt) &&
  2193. mxGraph.prototype.isSplitTarget.apply(this, arguments);
  2194. };
  2195. /**
  2196. * Adds support for placeholders in labels.
  2197. */
  2198. Graph.prototype.getLabel = function(cell)
  2199. {
  2200. var result = mxGraph.prototype.getLabel.apply(this, arguments);
  2201. if (result != null && this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') == null)
  2202. {
  2203. result = this.replacePlaceholders(cell, result);
  2204. }
  2205. return result;
  2206. };
  2207. /**
  2208. * Adds labelMovable style.
  2209. */
  2210. Graph.prototype.isLabelMovable = function(cell)
  2211. {
  2212. var style = this.getCurrentCellStyle(cell);
  2213. return !this.isCellLocked(cell) &&
  2214. ((this.model.isEdge(cell) && this.edgeLabelsMovable) ||
  2215. (this.model.isVertex(cell) && (this.vertexLabelsMovable ||
  2216. mxUtils.getValue(style, 'labelMovable', '0') == '1')));
  2217. };
  2218. /**
  2219. * Adds event if grid size is changed.
  2220. */
  2221. Graph.prototype.setGridSize = function(value)
  2222. {
  2223. this.gridSize = value;
  2224. this.fireEvent(new mxEventObject('gridSizeChanged'));
  2225. };
  2226. /**
  2227. * Adds event if default parent is changed.
  2228. */
  2229. Graph.prototype.setDefaultParent = function(cell)
  2230. {
  2231. this.defaultParent = cell;
  2232. this.fireEvent(new mxEventObject('defaultParentChanged'));
  2233. };
  2234. /**
  2235. * Function: getClickableLinkForCell
  2236. *
  2237. * Returns the first non-null link for the cell or its ancestors.
  2238. *
  2239. * Parameters:
  2240. *
  2241. * cell - <mxCell> whose link should be returned.
  2242. */
  2243. Graph.prototype.getClickableLinkForCell = function(cell)
  2244. {
  2245. do
  2246. {
  2247. var link = this.getLinkForCell(cell);
  2248. if (link != null)
  2249. {
  2250. return link;
  2251. }
  2252. cell = this.model.getParent(cell);
  2253. } while (cell != null);
  2254. return null;
  2255. };
  2256. /**
  2257. * Private helper method.
  2258. */
  2259. Graph.prototype.getGlobalVariable = function(name)
  2260. {
  2261. var val = null;
  2262. if (name == 'date')
  2263. {
  2264. val = new Date().toLocaleDateString();
  2265. }
  2266. else if (name == 'time')
  2267. {
  2268. val = new Date().toLocaleTimeString();
  2269. }
  2270. else if (name == 'timestamp')
  2271. {
  2272. val = new Date().toLocaleString();
  2273. }
  2274. else if (name.substring(0, 5) == 'date{')
  2275. {
  2276. var fmt = name.substring(5, name.length - 1);
  2277. val = this.formatDate(new Date(), fmt);
  2278. }
  2279. return val;
  2280. };
  2281. /**
  2282. * Formats a date, see http://blog.stevenlevithan.com/archives/date-time-format
  2283. */
  2284. Graph.prototype.formatDate = function(date, mask, utc)
  2285. {
  2286. // LATER: Cache regexs
  2287. if (this.dateFormatCache == null)
  2288. {
  2289. this.dateFormatCache = {
  2290. i18n: {
  2291. dayNames: [
  2292. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
  2293. "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  2294. ],
  2295. monthNames: [
  2296. "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  2297. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  2298. ]
  2299. },
  2300. masks: {
  2301. "default": "ddd mmm dd yyyy HH:MM:ss",
  2302. shortDate: "m/d/yy",
  2303. mediumDate: "mmm d, yyyy",
  2304. longDate: "mmmm d, yyyy",
  2305. fullDate: "dddd, mmmm d, yyyy",
  2306. shortTime: "h:MM TT",
  2307. mediumTime: "h:MM:ss TT",
  2308. longTime: "h:MM:ss TT Z",
  2309. isoDate: "yyyy-mm-dd",
  2310. isoTime: "HH:MM:ss",
  2311. isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
  2312. isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
  2313. }
  2314. };
  2315. }
  2316. var dF = this.dateFormatCache;
  2317. var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
  2318. timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
  2319. timezoneClip = /[^-+\dA-Z]/g,
  2320. pad = function (val, len) {
  2321. val = String(val);
  2322. len = len || 2;
  2323. while (val.length < len) val = "0" + val;
  2324. return val;
  2325. };
  2326. // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
  2327. if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
  2328. mask = date;
  2329. date = undefined;
  2330. }
  2331. // Passing date through Date applies Date.parse, if necessary
  2332. date = date ? new Date(date) : new Date;
  2333. if (isNaN(date)) throw SyntaxError("invalid date");
  2334. mask = String(dF.masks[mask] || mask || dF.masks["default"]);
  2335. // Allow setting the utc argument via the mask
  2336. if (mask.slice(0, 4) == "UTC:") {
  2337. mask = mask.slice(4);
  2338. utc = true;
  2339. }
  2340. var _ = utc ? "getUTC" : "get",
  2341. d = date[_ + "Date"](),
  2342. D = date[_ + "Day"](),
  2343. m = date[_ + "Month"](),
  2344. y = date[_ + "FullYear"](),
  2345. H = date[_ + "Hours"](),
  2346. M = date[_ + "Minutes"](),
  2347. s = date[_ + "Seconds"](),
  2348. L = date[_ + "Milliseconds"](),
  2349. o = utc ? 0 : date.getTimezoneOffset(),
  2350. flags = {
  2351. d: d,
  2352. dd: pad(d),
  2353. ddd: dF.i18n.dayNames[D],
  2354. dddd: dF.i18n.dayNames[D + 7],
  2355. m: m + 1,
  2356. mm: pad(m + 1),
  2357. mmm: dF.i18n.monthNames[m],
  2358. mmmm: dF.i18n.monthNames[m + 12],
  2359. yy: String(y).slice(2),
  2360. yyyy: y,
  2361. h: H % 12 || 12,
  2362. hh: pad(H % 12 || 12),
  2363. H: H,
  2364. HH: pad(H),
  2365. M: M,
  2366. MM: pad(M),
  2367. s: s,
  2368. ss: pad(s),
  2369. l: pad(L, 3),
  2370. L: pad(L > 99 ? Math.round(L / 10) : L),
  2371. t: H < 12 ? "a" : "p",
  2372. tt: H < 12 ? "am" : "pm",
  2373. T: H < 12 ? "A" : "P",
  2374. TT: H < 12 ? "AM" : "PM",
  2375. Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
  2376. o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
  2377. S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
  2378. };
  2379. return mask.replace(token, function ($0)
  2380. {
  2381. return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
  2382. });
  2383. };
  2384. /**
  2385. *
  2386. */
  2387. Graph.prototype.createLayersDialog = function()
  2388. {
  2389. var div = document.createElement('div');
  2390. div.style.position = 'absolute';
  2391. var model = this.getModel();
  2392. var childCount = model.getChildCount(model.root);
  2393. for (var i = 0; i < childCount; i++)
  2394. {
  2395. (mxUtils.bind(this, function(layer)
  2396. {
  2397. var span = document.createElement('div');
  2398. span.style.overflow = 'hidden';
  2399. span.style.textOverflow = 'ellipsis';
  2400. span.style.padding = '2px';
  2401. span.style.whiteSpace = 'nowrap';
  2402. var cb = document.createElement('input');
  2403. cb.style.display = 'inline-block';
  2404. cb.setAttribute('type', 'checkbox');
  2405. if (model.isVisible(layer))
  2406. {
  2407. cb.setAttribute('checked', 'checked');
  2408. cb.defaultChecked = true;
  2409. }
  2410. span.appendChild(cb);
  2411. var title = this.convertValueToString(layer) || (mxResources.get('background') || 'Background');
  2412. span.setAttribute('title', title);
  2413. mxUtils.write(span, title);
  2414. div.appendChild(span);
  2415. mxEvent.addListener(cb, 'click', function()
  2416. {
  2417. if (cb.getAttribute('checked') != null)
  2418. {
  2419. cb.removeAttribute('checked');
  2420. }
  2421. else
  2422. {
  2423. cb.setAttribute('checked', 'checked');
  2424. }
  2425. model.setVisible(layer, cb.checked);
  2426. });
  2427. })(model.getChildAt(model.root, i)));
  2428. }
  2429. return div;
  2430. };
  2431. /**
  2432. * Private helper method.
  2433. */
  2434. Graph.prototype.replacePlaceholders = function(cell, str, vars, translate)
  2435. {
  2436. var result = [];
  2437. if (str != null)
  2438. {
  2439. var last = 0;
  2440. while (match = this.placeholderPattern.exec(str))
  2441. {
  2442. var val = match[0];
  2443. if (val.length > 2 && val != '%label%' && val != '%tooltip%')
  2444. {
  2445. var tmp = null;
  2446. if (match.index > last && str.charAt(match.index - 1) == '%')
  2447. {
  2448. tmp = val.substring(1);
  2449. }
  2450. else
  2451. {
  2452. var name = val.substring(1, val.length - 1);
  2453. // Workaround for invalid char for getting attribute in older versions of IE
  2454. if (name == 'id')
  2455. {
  2456. tmp = cell.id;
  2457. }
  2458. else if (name.indexOf('{') < 0)
  2459. {
  2460. var current = cell;
  2461. while (tmp == null && current != null)
  2462. {
  2463. if (current.value != null && typeof(current.value) == 'object')
  2464. {
  2465. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  2466. {
  2467. tmp = current.getAttribute(name + '_' + Graph.diagramLanguage);
  2468. }
  2469. if (tmp == null)
  2470. {
  2471. tmp = (current.hasAttribute(name)) ? ((current.getAttribute(name) != null) ?
  2472. current.getAttribute(name) : '') : null;
  2473. }
  2474. }
  2475. current = this.model.getParent(current);
  2476. }
  2477. }
  2478. if (tmp == null)
  2479. {
  2480. tmp = this.getGlobalVariable(name);
  2481. }
  2482. if (tmp == null && vars != null)
  2483. {
  2484. tmp = vars[name];
  2485. }
  2486. }
  2487. result.push(str.substring(last, match.index) + ((tmp != null) ? tmp : val));
  2488. last = match.index + val.length;
  2489. }
  2490. }
  2491. result.push(str.substring(last));
  2492. }
  2493. return result.join('');
  2494. };
  2495. /**
  2496. * Resolves the given cells in the model and selects them.
  2497. */
  2498. Graph.prototype.restoreSelection = function(cells)
  2499. {
  2500. if (cells != null && cells.length > 0)
  2501. {
  2502. var temp = [];
  2503. for (var i = 0; i < cells.length; i++)
  2504. {
  2505. var newCell = this.model.getCell(cells[i].id);
  2506. if (newCell != null)
  2507. {
  2508. temp.push(newCell);
  2509. }
  2510. }
  2511. this.setSelectionCells(temp);
  2512. }
  2513. else
  2514. {
  2515. this.clearSelection();
  2516. }
  2517. };
  2518. /**
  2519. * Selects cells for connect vertex return value.
  2520. */
  2521. Graph.prototype.selectCellsForConnectVertex = function(cells, evt, hoverIcons)
  2522. {
  2523. // Selects only target vertex if one exists
  2524. if (cells.length == 2 && this.model.isVertex(cells[1]))
  2525. {
  2526. this.setSelectionCell(cells[1]);
  2527. this.scrollCellToVisible(cells[1]);
  2528. if (hoverIcons != null)
  2529. {
  2530. // Adds hover icons for cloned vertex or hides icons
  2531. if (mxEvent.isTouchEvent(evt))
  2532. {
  2533. hoverIcons.update(hoverIcons.getState(this.view.getState(cells[1])));
  2534. }
  2535. else
  2536. {
  2537. hoverIcons.reset();
  2538. }
  2539. }
  2540. }
  2541. else
  2542. {
  2543. this.setSelectionCells(cells);
  2544. }
  2545. };
  2546. /**
  2547. * Never connects children in stack layouts or tables.
  2548. */
  2549. Graph.prototype.isCloneConnectSource = function(source)
  2550. {
  2551. var layout = null;
  2552. if (this.layoutManager != null)
  2553. {
  2554. layout = this.layoutManager.getLayout(this.model.getParent(source));
  2555. }
  2556. return this.isTableRow(source) || this.isTableCell(source) ||
  2557. (layout != null && layout.constructor == mxStackLayout);
  2558. };
  2559. /**
  2560. * Adds a connection to the given vertex.
  2561. */
  2562. Graph.prototype.connectVertex = function(source, direction, length, evt, forceClone, ignoreCellAt, createTarget, done)
  2563. {
  2564. ignoreCellAt = (ignoreCellAt) ? ignoreCellAt : false;
  2565. // Ignores relative edge labels
  2566. if (source.geometry.relative && this.model.isEdge(source.parent))
  2567. {
  2568. return [];
  2569. }
  2570. // Uses parent for relative child cells
  2571. while (source.geometry.relative && this.model.isVertex(source.parent))
  2572. {
  2573. source = source.parent;
  2574. }
  2575. // Handles clone connect sources
  2576. var cloneSource = this.isCloneConnectSource(source);
  2577. var composite = (cloneSource) ? source : this.getCompositeParent(source);
  2578. var pt = (source.geometry.relative && source.parent.geometry != null) ?
  2579. new mxPoint(source.parent.geometry.width * source.geometry.x,
  2580. source.parent.geometry.height * source.geometry.y) :
  2581. new mxPoint(composite.geometry.x, composite.geometry.y);
  2582. if (direction == mxConstants.DIRECTION_NORTH)
  2583. {
  2584. pt.x += composite.geometry.width / 2;
  2585. pt.y -= length ;
  2586. }
  2587. else if (direction == mxConstants.DIRECTION_SOUTH)
  2588. {
  2589. pt.x += composite.geometry.width / 2;
  2590. pt.y += composite.geometry.height + length;
  2591. }
  2592. else if (direction == mxConstants.DIRECTION_WEST)
  2593. {
  2594. pt.x -= length;
  2595. pt.y += composite.geometry.height / 2;
  2596. }
  2597. else
  2598. {
  2599. pt.x += composite.geometry.width + length;
  2600. pt.y += composite.geometry.height / 2;
  2601. }
  2602. var parentState = this.view.getState(this.model.getParent(source));
  2603. var s = this.view.scale;
  2604. var t = this.view.translate;
  2605. var dx = t.x * s;
  2606. var dy = t.y * s;
  2607. if (parentState != null && this.model.isVertex(parentState.cell))
  2608. {
  2609. dx = parentState.x;
  2610. dy = parentState.y;
  2611. }
  2612. // Workaround for relative child cells
  2613. if (this.model.isVertex(source.parent) && source.geometry.relative)
  2614. {
  2615. pt.x += source.parent.geometry.x;
  2616. pt.y += source.parent.geometry.y;
  2617. }
  2618. // Checks actual end point of edge for target cell
  2619. var rect = (!ignoreCellAt) ? new mxRectangle(dx + pt.x * s, dy + pt.y * s).grow(40) : null;
  2620. var tempCells = (rect != null) ? this.getCells(0, 0, 0, 0, null, null, rect) : null;
  2621. var target = (tempCells != null && tempCells.length > 0) ? tempCells.reverse()[0] : null;
  2622. var keepParent = false;
  2623. if (target != null && this.model.isAncestor(target, source))
  2624. {
  2625. keepParent = true;
  2626. target = null;
  2627. }
  2628. // Checks for swimlane at drop location
  2629. if (target == null)
  2630. {
  2631. var temp = this.getSwimlaneAt(dx + pt.x * s, dy + pt.y * s);
  2632. if (temp != null)
  2633. {
  2634. keepParent = false;
  2635. target = temp;
  2636. }
  2637. }
  2638. // Checks if target or ancestor is locked
  2639. var temp = target;
  2640. while (temp != null)
  2641. {
  2642. if (this.isCellLocked(temp))
  2643. {
  2644. target = null;
  2645. break;
  2646. }
  2647. temp = this.model.getParent(temp);
  2648. }
  2649. // Checks if source and target intersect
  2650. if (target != null)
  2651. {
  2652. var sourceState = this.view.getState(source);
  2653. var targetState = this.view.getState(target);
  2654. if (sourceState != null && targetState != null && mxUtils.intersects(sourceState, targetState))
  2655. {
  2656. target = null;
  2657. }
  2658. }
  2659. var duplicate = (!mxEvent.isShiftDown(evt) || mxEvent.isControlDown(evt)) || forceClone;
  2660. if (duplicate)
  2661. {
  2662. if (direction == mxConstants.DIRECTION_NORTH)
  2663. {
  2664. pt.y -= source.geometry.height / 2;
  2665. }
  2666. else if (direction == mxConstants.DIRECTION_SOUTH)
  2667. {
  2668. pt.y += source.geometry.height / 2;
  2669. }
  2670. else if (direction == mxConstants.DIRECTION_WEST)
  2671. {
  2672. pt.x -= source.geometry.width / 2;
  2673. }
  2674. else
  2675. {
  2676. pt.x += source.geometry.width / 2;
  2677. }
  2678. }
  2679. // Uses connectable parent vertex if one exists
  2680. // TODO: Fix using target as parent for swimlane
  2681. if (target != null && !this.isCellConnectable(target) && !this.isSwimlane(target))
  2682. {
  2683. var parent = this.getModel().getParent(target);
  2684. if (this.getModel().isVertex(parent) && this.isCellConnectable(parent))
  2685. {
  2686. target = parent;
  2687. }
  2688. }
  2689. if (target == source || this.model.isEdge(target) ||
  2690. !this.isCellConnectable(target) &&
  2691. !this.isSwimlane(target))
  2692. {
  2693. target = null;
  2694. }
  2695. var result = [];
  2696. var swimlane = target != null && this.isSwimlane(target);
  2697. var realTarget = (!swimlane) ? target : null;
  2698. var execute = mxUtils.bind(this, function(targetCell)
  2699. {
  2700. if (createTarget == null || targetCell != null || (target == null && cloneSource))
  2701. {
  2702. this.model.beginUpdate();
  2703. try
  2704. {
  2705. if (realTarget == null && duplicate)
  2706. {
  2707. // Handles relative children
  2708. var cellToClone = (targetCell != null) ? targetCell : source;
  2709. var geo = this.getCellGeometry(cellToClone);
  2710. while (geo != null && geo.relative)
  2711. {
  2712. cellToClone = this.getModel().getParent(cellToClone);
  2713. geo = this.getCellGeometry(cellToClone);
  2714. }
  2715. // Handles composite cells for cloning
  2716. cellToClone = (cloneSource) ? source : this.getCompositeParent(cellToClone);
  2717. realTarget = (targetCell != null) ? targetCell : this.duplicateCells([cellToClone], false)[0];
  2718. if (targetCell != null)
  2719. {
  2720. this.addCells([realTarget], this.model.getParent(source), null, null, null, true);
  2721. }
  2722. var geo = this.getCellGeometry(realTarget);
  2723. if (geo != null)
  2724. {
  2725. geo.x = pt.x - geo.width / 2;
  2726. geo.y = pt.y - geo.height / 2;
  2727. }
  2728. if (swimlane)
  2729. {
  2730. this.addCells([realTarget], target, null, null, null, true);
  2731. target = null;
  2732. }
  2733. else if (duplicate && target == null && !keepParent && !cloneSource)
  2734. {
  2735. this.addCells([realTarget], this.getDefaultParent(), null, null, null, true);
  2736. }
  2737. }
  2738. var edge = ((mxEvent.isControlDown(evt) && mxEvent.isShiftDown(evt) && duplicate) ||
  2739. (target == null && cloneSource)) ? null : this.insertEdge(this.model.getParent(source),
  2740. null, '', source, realTarget, this.createCurrentEdgeStyle());
  2741. // Inserts edge before source
  2742. if (edge != null && this.connectionHandler.insertBeforeSource)
  2743. {
  2744. var index = null;
  2745. var tmp = source;
  2746. while (tmp.parent != null && tmp.geometry != null &&
  2747. tmp.geometry.relative && tmp.parent != edge.parent)
  2748. {
  2749. tmp = this.model.getParent(tmp);
  2750. }
  2751. if (tmp != null && tmp.parent != null && tmp.parent == edge.parent)
  2752. {
  2753. var index = tmp.parent.getIndex(tmp);
  2754. this.model.add(tmp.parent, edge, index);
  2755. }
  2756. }
  2757. // Special case: Click on west icon puts clone before cell
  2758. if (target == null && realTarget != null && source.parent != null &&
  2759. cloneSource && direction == mxConstants.DIRECTION_WEST)
  2760. {
  2761. var index = source.parent.getIndex(source);
  2762. this.model.add(source.parent, realTarget, index);
  2763. }
  2764. if (edge != null)
  2765. {
  2766. result.push(edge);
  2767. }
  2768. if (target == null && realTarget != null)
  2769. {
  2770. result.push(realTarget);
  2771. }
  2772. if (realTarget == null && edge != null)
  2773. {
  2774. edge.geometry.setTerminalPoint(pt, false);
  2775. }
  2776. if (edge != null)
  2777. {
  2778. this.fireEvent(new mxEventObject('cellsInserted', 'cells', [edge]));
  2779. }
  2780. }
  2781. finally
  2782. {
  2783. this.model.endUpdate();
  2784. }
  2785. }
  2786. if (done != null)
  2787. {
  2788. done(result);
  2789. }
  2790. else
  2791. {
  2792. return result;
  2793. }
  2794. });
  2795. if (createTarget != null && realTarget == null && duplicate &&
  2796. (target != null || !cloneSource))
  2797. {
  2798. createTarget(dx + pt.x * s, dy + pt.y * s, execute);
  2799. }
  2800. else
  2801. {
  2802. return execute(realTarget);
  2803. }
  2804. };
  2805. /**
  2806. * Returns all labels in the diagram as a string.
  2807. */
  2808. Graph.prototype.getIndexableText = function()
  2809. {
  2810. var tmp = document.createElement('div');
  2811. var labels = [];
  2812. var label = '';
  2813. for (var key in this.model.cells)
  2814. {
  2815. var cell = this.model.cells[key];
  2816. if (this.model.isVertex(cell) || this.model.isEdge(cell))
  2817. {
  2818. if (this.isHtmlLabel(cell))
  2819. {
  2820. tmp.innerHTML = this.sanitizeHtml(this.getLabel(cell));
  2821. label = mxUtils.extractTextWithWhitespace([tmp]);
  2822. }
  2823. else
  2824. {
  2825. label = this.getLabel(cell);
  2826. }
  2827. label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' '));
  2828. if (label.length > 0)
  2829. {
  2830. labels.push(label);
  2831. }
  2832. }
  2833. }
  2834. return labels.join(' ');
  2835. };
  2836. /**
  2837. * Returns the label for the given cell.
  2838. */
  2839. Graph.prototype.convertValueToString = function(cell)
  2840. {
  2841. var value = this.model.getValue(cell);
  2842. if (value != null && typeof(value) == 'object')
  2843. {
  2844. var result = null;
  2845. if (this.isReplacePlaceholders(cell) && cell.getAttribute('placeholder') != null)
  2846. {
  2847. var name = cell.getAttribute('placeholder');
  2848. var current = cell;
  2849. while (result == null && current != null)
  2850. {
  2851. if (current.value != null && typeof(current.value) == 'object')
  2852. {
  2853. result = (current.hasAttribute(name)) ? ((current.getAttribute(name) != null) ?
  2854. current.getAttribute(name) : '') : null;
  2855. }
  2856. current = this.model.getParent(current);
  2857. }
  2858. }
  2859. else
  2860. {
  2861. var result = null;
  2862. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  2863. {
  2864. result = value.getAttribute('label_' + Graph.diagramLanguage);
  2865. }
  2866. if (result == null)
  2867. {
  2868. result = value.getAttribute('label') || '';
  2869. }
  2870. }
  2871. return result || '';
  2872. }
  2873. return mxGraph.prototype.convertValueToString.apply(this, arguments);
  2874. };
  2875. /**
  2876. * Returns the link for the given cell.
  2877. */
  2878. Graph.prototype.getLinksForState = function(state)
  2879. {
  2880. if (state != null && state.text != null && state.text.node != null)
  2881. {
  2882. return state.text.node.getElementsByTagName('a');
  2883. }
  2884. return null;
  2885. };
  2886. /**
  2887. * Returns the link for the given cell.
  2888. */
  2889. Graph.prototype.getLinkForCell = function(cell)
  2890. {
  2891. if (cell.value != null && typeof(cell.value) == 'object')
  2892. {
  2893. var link = cell.value.getAttribute('link');
  2894. // Removes links with leading javascript: protocol
  2895. // TODO: Check more possible attack vectors
  2896. if (link != null && link.toLowerCase().substring(0, 11) === 'javascript:')
  2897. {
  2898. link = link.substring(11);
  2899. }
  2900. return link;
  2901. }
  2902. return null;
  2903. };
  2904. /**
  2905. * Overrides label orientation for collapsed swimlanes inside stack and
  2906. * for partial rectangles inside tables.
  2907. */
  2908. Graph.prototype.getCellStyle = function(cell)
  2909. {
  2910. var style = mxGraph.prototype.getCellStyle.apply(this, arguments);
  2911. if (cell != null && this.layoutManager != null)
  2912. {
  2913. var parent = this.model.getParent(cell);
  2914. if (this.model.isVertex(parent) && this.isCellCollapsed(cell))
  2915. {
  2916. var layout = this.layoutManager.getLayout(parent);
  2917. if (layout != null && layout.constructor == mxStackLayout)
  2918. {
  2919. style[mxConstants.STYLE_HORIZONTAL] = !layout.horizontal;
  2920. }
  2921. }
  2922. }
  2923. return style;
  2924. };
  2925. /**
  2926. * Disables alternate width persistence for stack layout parents
  2927. */
  2928. Graph.prototype.updateAlternateBounds = function(cell, geo, willCollapse)
  2929. {
  2930. if (cell != null && geo != null && this.layoutManager != null && geo.alternateBounds != null)
  2931. {
  2932. var layout = this.layoutManager.getLayout(this.model.getParent(cell));
  2933. if (layout != null && layout.constructor == mxStackLayout)
  2934. {
  2935. if (layout.horizontal)
  2936. {
  2937. geo.alternateBounds.height = 0;
  2938. }
  2939. else
  2940. {
  2941. geo.alternateBounds.width = 0;
  2942. }
  2943. }
  2944. }
  2945. mxGraph.prototype.updateAlternateBounds.apply(this, arguments);
  2946. };
  2947. /**
  2948. * Adds Shift+collapse/expand and size management for folding inside stack
  2949. */
  2950. Graph.prototype.isMoveCellsEvent = function(evt, state)
  2951. {
  2952. return mxEvent.isShiftDown(evt) || mxUtils.getValue(state.style, 'moveCells', '0') == '1';
  2953. };
  2954. /**
  2955. * Adds Shift+collapse/expand and size management for folding inside stack
  2956. */
  2957. Graph.prototype.foldCells = function(collapse, recurse, cells, checkFoldable, evt)
  2958. {
  2959. recurse = (recurse != null) ? recurse : false;
  2960. if (cells == null)
  2961. {
  2962. cells = this.getFoldableCells(this.getSelectionCells(), collapse);
  2963. }
  2964. if (cells != null)
  2965. {
  2966. this.model.beginUpdate();
  2967. try
  2968. {
  2969. mxGraph.prototype.foldCells.apply(this, arguments);
  2970. // Resizes all parent stacks if alt is not pressed
  2971. if (this.layoutManager != null)
  2972. {
  2973. for (var i = 0; i < cells.length; i++)
  2974. {
  2975. var state = this.view.getState(cells[i]);
  2976. var geo = this.getCellGeometry(cells[i]);
  2977. if (state != null && geo != null)
  2978. {
  2979. var dx = Math.round(geo.width - state.width / this.view.scale);
  2980. var dy = Math.round(geo.height - state.height / this.view.scale);
  2981. if (dy != 0 || dx != 0)
  2982. {
  2983. var parent = this.model.getParent(cells[i]);
  2984. var layout = this.layoutManager.getLayout(parent);
  2985. if (layout == null)
  2986. {
  2987. // Moves cells to the right and down after collapse/expand
  2988. if (evt != null && this.isMoveCellsEvent(evt, state))
  2989. {
  2990. this.moveSiblings(state, parent, dx, dy);
  2991. }
  2992. }
  2993. else if ((evt == null || !mxEvent.isAltDown(evt)) &&
  2994. layout.constructor == mxStackLayout && !layout.resizeLast)
  2995. {
  2996. this.resizeParentStacks(parent, layout, dx, dy);
  2997. }
  2998. }
  2999. }
  3000. }
  3001. }
  3002. }
  3003. finally
  3004. {
  3005. this.model.endUpdate();
  3006. }
  3007. // Selects cells after folding
  3008. if (this.isEnabled())
  3009. {
  3010. this.setSelectionCells(cells);
  3011. }
  3012. }
  3013. };
  3014. /**
  3015. * Overrides label orientation for collapsed swimlanes inside stack.
  3016. */
  3017. Graph.prototype.moveSiblings = function(state, parent, dx, dy)
  3018. {
  3019. this.model.beginUpdate();
  3020. try
  3021. {
  3022. var cells = this.getCellsBeyond(state.x, state.y, parent, true, true);
  3023. for (var i = 0; i < cells.length; i++)
  3024. {
  3025. if (cells[i] != state.cell)
  3026. {
  3027. var tmp = this.view.getState(cells[i]);
  3028. var geo = this.getCellGeometry(cells[i]);
  3029. if (tmp != null && geo != null)
  3030. {
  3031. geo = geo.clone();
  3032. geo.translate(Math.round(dx * Math.max(0, Math.min(1, (tmp.x - state.x) / state.width))),
  3033. Math.round(dy * Math.max(0, Math.min(1, (tmp.y - state.y) / state.height))));
  3034. this.model.setGeometry(cells[i], geo);
  3035. }
  3036. }
  3037. }
  3038. }
  3039. finally
  3040. {
  3041. this.model.endUpdate();
  3042. }
  3043. };
  3044. /**
  3045. * Overrides label orientation for collapsed swimlanes inside stack.
  3046. */
  3047. Graph.prototype.resizeParentStacks = function(parent, layout, dx, dy)
  3048. {
  3049. if (this.layoutManager != null && layout != null && layout.constructor == mxStackLayout && !layout.resizeLast)
  3050. {
  3051. this.model.beginUpdate();
  3052. try
  3053. {
  3054. var dir = layout.horizontal;
  3055. // Bubble resize up for all parent stack layouts with same orientation
  3056. while (parent != null && layout != null && layout.constructor == mxStackLayout &&
  3057. layout.horizontal == dir && !layout.resizeLast)
  3058. {
  3059. var pgeo = this.getCellGeometry(parent);
  3060. var pstate = this.view.getState(parent);
  3061. if (pstate != null && pgeo != null)
  3062. {
  3063. pgeo = pgeo.clone();
  3064. if (layout.horizontal)
  3065. {
  3066. pgeo.width += dx + Math.min(0, pstate.width / this.view.scale - pgeo.width);
  3067. }
  3068. else
  3069. {
  3070. pgeo.height += dy + Math.min(0, pstate.height / this.view.scale - pgeo.height);
  3071. }
  3072. this.model.setGeometry(parent, pgeo);
  3073. }
  3074. parent = this.model.getParent(parent);
  3075. layout = this.layoutManager.getLayout(parent);
  3076. }
  3077. }
  3078. finally
  3079. {
  3080. this.model.endUpdate();
  3081. }
  3082. }
  3083. };
  3084. /**
  3085. * Disables drill-down for non-swimlanes.
  3086. */
  3087. Graph.prototype.isContainer = function(cell)
  3088. {
  3089. var style = this.getCurrentCellStyle(cell);
  3090. if (this.isSwimlane(cell))
  3091. {
  3092. return style['container'] != '0';
  3093. }
  3094. else
  3095. {
  3096. return style['container'] == '1';
  3097. }
  3098. };
  3099. /**
  3100. * Adds a connectable style.
  3101. */
  3102. Graph.prototype.isCellConnectable = function(cell)
  3103. {
  3104. var style = this.getCurrentCellStyle(cell);
  3105. return (style['connectable'] != null) ? style['connectable'] != '0' :
  3106. mxGraph.prototype.isCellConnectable.apply(this, arguments);
  3107. };
  3108. /**
  3109. * Adds labelMovable style.
  3110. */
  3111. Graph.prototype.isLabelMovable = function(cell)
  3112. {
  3113. var style = this.getCurrentCellStyle(cell);
  3114. return (style['movableLabel'] != null) ? style['movableLabel'] != '0' :
  3115. mxGraph.prototype.isLabelMovable.apply(this, arguments);
  3116. };
  3117. /**
  3118. * Function: selectAll
  3119. *
  3120. * Selects all children of the given parent cell or the children of the
  3121. * default parent if no parent is specified. To select leaf vertices and/or
  3122. * edges use <selectCells>.
  3123. *
  3124. * Parameters:
  3125. *
  3126. * parent - Optional <mxCell> whose children should be selected.
  3127. * Default is <defaultParent>.
  3128. */
  3129. Graph.prototype.selectAll = function(parent)
  3130. {
  3131. parent = parent || this.getDefaultParent();
  3132. if (!this.isCellLocked(parent))
  3133. {
  3134. mxGraph.prototype.selectAll.apply(this, arguments);
  3135. }
  3136. };
  3137. /**
  3138. * Function: selectCells
  3139. *
  3140. * Selects all vertices and/or edges depending on the given boolean
  3141. * arguments recursively, starting at the given parent or the default
  3142. * parent if no parent is specified. Use <selectAll> to select all cells.
  3143. * For vertices, only cells with no children are selected.
  3144. *
  3145. * Parameters:
  3146. *
  3147. * vertices - Boolean indicating if vertices should be selected.
  3148. * edges - Boolean indicating if edges should be selected.
  3149. * parent - Optional <mxCell> that acts as the root of the recursion.
  3150. * Default is <defaultParent>.
  3151. */
  3152. Graph.prototype.selectCells = function(vertices, edges, parent)
  3153. {
  3154. parent = parent || this.getDefaultParent();
  3155. if (!this.isCellLocked(parent))
  3156. {
  3157. mxGraph.prototype.selectCells.apply(this, arguments);
  3158. }
  3159. };
  3160. /**
  3161. * Function: getSwimlaneAt
  3162. *
  3163. * Returns the bottom-most swimlane that intersects the given point (x, y)
  3164. * in the cell hierarchy that starts at the given parent.
  3165. *
  3166. * Parameters:
  3167. *
  3168. * x - X-coordinate of the location to be checked.
  3169. * y - Y-coordinate of the location to be checked.
  3170. * parent - <mxCell> that should be used as the root of the recursion.
  3171. * Default is <defaultParent>.
  3172. */
  3173. Graph.prototype.getSwimlaneAt = function (x, y, parent)
  3174. {
  3175. var result = mxGraph.prototype.getSwimlaneAt.apply(this, arguments);
  3176. if (this.isCellLocked(result))
  3177. {
  3178. result = null;
  3179. }
  3180. return result;
  3181. };
  3182. /**
  3183. * Disables folding for non-swimlanes.
  3184. */
  3185. Graph.prototype.isCellFoldable = function(cell)
  3186. {
  3187. var style = this.getCurrentCellStyle(cell);
  3188. return this.foldingEnabled && (style['treeFolding'] == '1' ||
  3189. (!this.isCellLocked(cell) &&
  3190. ((this.isContainer(cell) && style['collapsible'] != '0') ||
  3191. (!this.isContainer(cell) && style['collapsible'] == '1'))));
  3192. };
  3193. /**
  3194. * Stops all interactions and clears the selection.
  3195. */
  3196. Graph.prototype.reset = function()
  3197. {
  3198. if (this.isEditing())
  3199. {
  3200. this.stopEditing(true);
  3201. }
  3202. this.escape();
  3203. if (!this.isSelectionEmpty())
  3204. {
  3205. this.clearSelection();
  3206. }
  3207. };
  3208. /**
  3209. * Overridden to limit zoom to 1% - 16.000%.
  3210. */
  3211. Graph.prototype.zoom = function(factor, center)
  3212. {
  3213. factor = Math.max(0.01, Math.min(this.view.scale * factor, 160)) / this.view.scale;
  3214. mxGraph.prototype.zoom.apply(this, arguments);
  3215. };
  3216. /**
  3217. * Function: zoomIn
  3218. *
  3219. * Zooms into the graph by <zoomFactor>.
  3220. */
  3221. Graph.prototype.zoomIn = function()
  3222. {
  3223. // Switches to 1% zoom steps below 15%
  3224. if (this.view.scale < 0.15)
  3225. {
  3226. this.zoom((this.view.scale + 0.01) / this.view.scale);
  3227. }
  3228. else
  3229. {
  3230. // Uses to 5% zoom steps for better grid rendering in webkit
  3231. // and to avoid rounding errors for zoom steps
  3232. this.zoom((Math.round(this.view.scale * this.zoomFactor * 20) / 20) / this.view.scale);
  3233. }
  3234. };
  3235. /**
  3236. * Function: zoomOut
  3237. *
  3238. * Zooms out of the graph by <zoomFactor>.
  3239. */
  3240. Graph.prototype.zoomOut = function()
  3241. {
  3242. // Switches to 1% zoom steps below 15%
  3243. if (this.view.scale <= 0.15)
  3244. {
  3245. this.zoom((this.view.scale - 0.01) / this.view.scale);
  3246. }
  3247. else
  3248. {
  3249. // Uses to 5% zoom steps for better grid rendering in webkit
  3250. // and to avoid rounding errors for zoom steps
  3251. this.zoom((Math.round(this.view.scale * (1 / this.zoomFactor) * 20) / 20) / this.view.scale);
  3252. }
  3253. };
  3254. /**
  3255. * Function: fitWindow
  3256. *
  3257. * Sets the current visible rectangle of the window in graph coordinates.
  3258. */
  3259. Graph.prototype.fitWindow = function(bounds, border)
  3260. {
  3261. border = (border != null) ? border : 10;
  3262. var cw = this.container.clientWidth - border;
  3263. var ch = this.container.clientHeight - border;
  3264. var scale = Math.floor(20 * Math.min(cw / bounds.width, ch / bounds.height)) / 20;
  3265. this.zoomTo(scale);
  3266. if (mxUtils.hasScrollbars(this.container))
  3267. {
  3268. var t = this.view.translate;
  3269. this.container.scrollTop = (bounds.y + t.y) * scale -
  3270. Math.max((ch - bounds.height * scale) / 2 + border / 2, 0);
  3271. this.container.scrollLeft = (bounds.x + t.x) * scale -
  3272. Math.max((cw - bounds.width * scale) / 2 + border / 2, 0);
  3273. }
  3274. };
  3275. /**
  3276. * Overrides tooltips to show custom tooltip or metadata.
  3277. */
  3278. Graph.prototype.getTooltipForCell = function(cell)
  3279. {
  3280. var tip = '';
  3281. if (mxUtils.isNode(cell.value))
  3282. {
  3283. var tmp = null;
  3284. if (Graph.translateDiagram && Graph.diagramLanguage != null)
  3285. {
  3286. tmp = cell.value.getAttribute('tooltip_' + Graph.diagramLanguage);
  3287. }
  3288. if (tmp == null)
  3289. {
  3290. tmp = cell.value.getAttribute('tooltip');
  3291. }
  3292. if (tmp != null)
  3293. {
  3294. if (tmp != null && this.isReplacePlaceholders(cell))
  3295. {
  3296. tmp = this.replacePlaceholders(cell, tmp);
  3297. }
  3298. tip = this.sanitizeHtml(tmp);
  3299. }
  3300. else
  3301. {
  3302. var ignored = this.builtInProperties;
  3303. var attrs = cell.value.attributes;
  3304. var temp = [];
  3305. // Hides links in edit mode
  3306. if (this.isEnabled())
  3307. {
  3308. ignored.push('link');
  3309. }
  3310. for (var i = 0; i < attrs.length; i++)
  3311. {
  3312. if (mxUtils.indexOf(ignored, attrs[i].nodeName) < 0 && attrs[i].nodeValue.length > 0)
  3313. {
  3314. temp.push({name: attrs[i].nodeName, value: attrs[i].nodeValue});
  3315. }
  3316. }
  3317. // Sorts by name
  3318. temp.sort(function(a, b)
  3319. {
  3320. if (a.name < b.name)
  3321. {
  3322. return -1;
  3323. }
  3324. else if (a.name > b.name)
  3325. {
  3326. return 1;
  3327. }
  3328. else
  3329. {
  3330. return 0;
  3331. }
  3332. });
  3333. for (var i = 0; i < temp.length; i++)
  3334. {
  3335. if (temp[i].name != 'link' || !this.isCustomLink(temp[i].value))
  3336. {
  3337. tip += ((temp[i].name != 'link') ? '<b>' + temp[i].name + ':</b> ' : '') +
  3338. mxUtils.htmlEntities(temp[i].value) + '\n';
  3339. }
  3340. }
  3341. if (tip.length > 0)
  3342. {
  3343. tip = tip.substring(0, tip.length - 1);
  3344. if (mxClient.IS_SVG)
  3345. {
  3346. tip = '<div style="max-width:360px;">' + tip + '</div>';
  3347. }
  3348. }
  3349. }
  3350. }
  3351. return tip;
  3352. };
  3353. /**
  3354. * Turns the given string into an array.
  3355. */
  3356. Graph.prototype.stringToBytes = function(str)
  3357. {
  3358. return Graph.stringToBytes(str);
  3359. };
  3360. /**
  3361. * Turns the given array into a string.
  3362. */
  3363. Graph.prototype.bytesToString = function(arr)
  3364. {
  3365. return Graph.bytesToString(arr);
  3366. };
  3367. /**
  3368. * Returns a base64 encoded version of the compressed outer XML of the given node.
  3369. */
  3370. Graph.prototype.compressNode = function(node)
  3371. {
  3372. return Graph.compressNode(node);
  3373. };
  3374. /**
  3375. * Returns a base64 encoded version of the compressed string.
  3376. */
  3377. Graph.prototype.compress = function(data, deflate)
  3378. {
  3379. return Graph.compress(data, deflate);
  3380. };
  3381. /**
  3382. * Returns a decompressed version of the base64 encoded string.
  3383. */
  3384. Graph.prototype.decompress = function(data, inflate)
  3385. {
  3386. return Graph.decompress(data, inflate);
  3387. };
  3388. /**
  3389. * Redirects to Graph.zapGremlins.
  3390. */
  3391. Graph.prototype.zapGremlins = function(text)
  3392. {
  3393. return Graph.zapGremlins(text);
  3394. };
  3395. /**
  3396. * Hover icons are used for hover, vertex handler and drag from sidebar.
  3397. */
  3398. HoverIcons = function(graph)
  3399. {
  3400. this.graph = graph;
  3401. this.init();
  3402. };
  3403. /**
  3404. * Up arrow.
  3405. */
  3406. HoverIcons.prototype.arrowSpacing = 2;
  3407. /**
  3408. * Delay to switch to another state for overlapping bbox. Default is 500ms.
  3409. */
  3410. HoverIcons.prototype.updateDelay = 500;
  3411. /**
  3412. * Delay to switch between states. Default is 140ms.
  3413. */
  3414. HoverIcons.prototype.activationDelay = 140;
  3415. /**
  3416. * Up arrow.
  3417. */
  3418. HoverIcons.prototype.currentState = null;
  3419. /**
  3420. * Up arrow.
  3421. */
  3422. HoverIcons.prototype.activeArrow = null;
  3423. /**
  3424. * Up arrow.
  3425. */
  3426. HoverIcons.prototype.inactiveOpacity = 15;
  3427. /**
  3428. * Up arrow.
  3429. */
  3430. HoverIcons.prototype.cssCursor = 'copy';
  3431. /**
  3432. * Whether to hide arrows that collide with vertices.
  3433. * LATER: Add keyboard override, touch support.
  3434. */
  3435. HoverIcons.prototype.checkCollisions = true;
  3436. /**
  3437. * Up arrow.
  3438. */
  3439. HoverIcons.prototype.arrowFill = '#29b6f2';
  3440. /**
  3441. * Up arrow.
  3442. */
  3443. HoverIcons.prototype.triangleUp = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-up.png', 26, 14) :
  3444. 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" ' +
  3445. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  3446. /**
  3447. * Right arrow.
  3448. */
  3449. HoverIcons.prototype.triangleRight = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-right.png', 14, 26) :
  3450. 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" ' +
  3451. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  3452. /**
  3453. * Down arrow.
  3454. */
  3455. HoverIcons.prototype.triangleDown = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-down.png', 26, 14) :
  3456. 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" ' +
  3457. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  3458. /**
  3459. * Left arrow.
  3460. */
  3461. HoverIcons.prototype.triangleLeft = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/triangle-left.png', 14, 26) :
  3462. 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" ' +
  3463. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  3464. /**
  3465. * Round target.
  3466. */
  3467. HoverIcons.prototype.roundDrop = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/round-drop.png', 26, 26) :
  3468. Graph.createSvgImage(26, 26, '<circle cx="13" cy="13" r="12" ' +
  3469. 'stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '"/>');
  3470. /**
  3471. * Refresh target.
  3472. */
  3473. HoverIcons.prototype.refreshTarget = new mxImage((mxClient.IS_SVG) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjM2cHgiIGhlaWdodD0iMzZweCI+PGVsbGlwc2UgZmlsbD0iIzI5YjZmMiIgY3g9IjEyIiBjeT0iMTIiIHJ4PSIxMiIgcnk9IjEyIi8+PHBhdGggdHJhbnNmb3JtPSJzY2FsZSgwLjgpIHRyYW5zbGF0ZSgyLjQsIDIuNCkiIHN0cm9rZT0iI2ZmZiIgZmlsbD0iI2ZmZiIgZD0iTTEyIDZ2M2w0LTQtNC00djNjLTQuNDIgMC04IDMuNTgtOCA4IDAgMS41Ny40NiAzLjAzIDEuMjQgNC4yNkw2LjcgMTQuOGMtLjQ1LS44My0uNy0xLjc5LS43LTIuOCAwLTMuMzEgMi42OS02IDYtNnptNi43NiAxLjc0TDE3LjMgOS4yYy40NC44NC43IDEuNzkuNyAyLjggMCAzLjMxLTIuNjkgNi02IDZ2LTNsLTQgNCA0IDR2LTNjNC40MiAwIDgtMy41OCA4LTggMC0xLjU3LS40Ni0zLjAzLTEuMjQtNC4yNnoiLz48cGF0aCBkPSJNMCAwaDI0djI0SDB6IiBmaWxsPSJub25lIi8+PC9zdmc+Cg==' :
  3474. IMAGE_PATH + '/refresh.png', 38, 38);
  3475. /**
  3476. * Tolerance for hover icon clicks.
  3477. */
  3478. HoverIcons.prototype.tolerance = (mxClient.IS_TOUCH) ? 6 : 0;
  3479. /**
  3480. *
  3481. */
  3482. HoverIcons.prototype.init = function()
  3483. {
  3484. this.arrowUp = this.createArrow(this.triangleUp, mxResources.get('plusTooltip'));
  3485. this.arrowRight = this.createArrow(this.triangleRight, mxResources.get('plusTooltip'));
  3486. this.arrowDown = this.createArrow(this.triangleDown, mxResources.get('plusTooltip'));
  3487. this.arrowLeft = this.createArrow(this.triangleLeft, mxResources.get('plusTooltip'));
  3488. this.elts = [this.arrowUp, this.arrowRight, this.arrowDown, this.arrowLeft];
  3489. this.resetHandler = mxUtils.bind(this, function()
  3490. {
  3491. this.reset();
  3492. });
  3493. this.repaintHandler = mxUtils.bind(this, function()
  3494. {
  3495. this.repaint();
  3496. });
  3497. this.graph.selectionModel.addListener(mxEvent.CHANGE, this.resetHandler);
  3498. this.graph.model.addListener(mxEvent.CHANGE, this.repaintHandler);
  3499. this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.repaintHandler);
  3500. this.graph.view.addListener(mxEvent.TRANSLATE, this.repaintHandler);
  3501. this.graph.view.addListener(mxEvent.SCALE, this.repaintHandler);
  3502. this.graph.view.addListener(mxEvent.DOWN, this.repaintHandler);
  3503. this.graph.view.addListener(mxEvent.UP, this.repaintHandler);
  3504. this.graph.addListener(mxEvent.ROOT, this.repaintHandler);
  3505. this.graph.addListener(mxEvent.ESCAPE, this.resetHandler);
  3506. mxEvent.addListener(this.graph.container, 'scroll', this.resetHandler);
  3507. // Resets the mouse point on escape
  3508. this.graph.addListener(mxEvent.ESCAPE, mxUtils.bind(this, function()
  3509. {
  3510. this.mouseDownPoint = null;
  3511. }));
  3512. // Removes hover icons if mouse leaves the container
  3513. mxEvent.addListener(this.graph.container, 'mouseleave', mxUtils.bind(this, function(evt)
  3514. {
  3515. // Workaround for IE11 firing mouseleave for touch in diagram
  3516. if (evt.relatedTarget != null && mxEvent.getSource(evt) == this.graph.container)
  3517. {
  3518. this.setDisplay('none');
  3519. }
  3520. }));
  3521. // Resets current state when in-place editor starts
  3522. this.graph.addListener(mxEvent.START_EDITING, mxUtils.bind(this, function(evt)
  3523. {
  3524. this.reset();
  3525. }));
  3526. // Resets current state after update of selection state for touch events
  3527. var graphClick = this.graph.click;
  3528. this.graph.click = mxUtils.bind(this, function(me)
  3529. {
  3530. graphClick.apply(this.graph, arguments);
  3531. if (this.currentState != null && !this.graph.isCellSelected(this.currentState.cell) &&
  3532. mxEvent.isTouchEvent(me.getEvent()) && !this.graph.model.isVertex(me.getCell()))
  3533. {
  3534. this.reset();
  3535. }
  3536. });
  3537. // Checks if connection handler was active in mouse move
  3538. // as workaround for possible double connection inserted
  3539. var connectionHandlerActive = false;
  3540. // Implements a listener for hover and click handling
  3541. this.graph.addMouseListener(
  3542. {
  3543. mouseDown: mxUtils.bind(this, function(sender, me)
  3544. {
  3545. connectionHandlerActive = false;
  3546. var evt = me.getEvent();
  3547. if (this.isResetEvent(evt))
  3548. {
  3549. this.reset();
  3550. }
  3551. else if (!this.isActive())
  3552. {
  3553. var state = this.getState(me.getState());
  3554. if (state != null || !mxEvent.isTouchEvent(evt))
  3555. {
  3556. this.update(state);
  3557. }
  3558. }
  3559. this.setDisplay('none');
  3560. }),
  3561. mouseMove: mxUtils.bind(this, function(sender, me)
  3562. {
  3563. var evt = me.getEvent();
  3564. if (this.isResetEvent(evt))
  3565. {
  3566. this.reset();
  3567. }
  3568. else if (!this.graph.isMouseDown && !mxEvent.isTouchEvent(evt))
  3569. {
  3570. this.update(this.getState(me.getState()),
  3571. me.getGraphX(), me.getGraphY());
  3572. }
  3573. if (this.graph.connectionHandler != null &&
  3574. this.graph.connectionHandler.shape != null)
  3575. {
  3576. connectionHandlerActive = true;
  3577. }
  3578. }),
  3579. mouseUp: mxUtils.bind(this, function(sender, me)
  3580. {
  3581. var evt = me.getEvent();
  3582. var pt = mxUtils.convertPoint(this.graph.container,
  3583. mxEvent.getClientX(evt), mxEvent.getClientY(evt))
  3584. if (this.isResetEvent(evt))
  3585. {
  3586. this.reset();
  3587. }
  3588. else if (this.isActive() && !connectionHandlerActive &&
  3589. this.mouseDownPoint != null)
  3590. {
  3591. this.click(this.currentState, this.getDirection(), me);
  3592. }
  3593. else if (this.isActive())
  3594. {
  3595. // Selects target vertex after drag and clone if not only new edge was inserted
  3596. if (this.graph.getSelectionCount() != 1 || !this.graph.model.isEdge(
  3597. this.graph.getSelectionCell()))
  3598. {
  3599. this.update(this.getState(this.graph.view.getState(
  3600. this.graph.getCellAt(me.getGraphX(), me.getGraphY()))));
  3601. }
  3602. else
  3603. {
  3604. this.reset();
  3605. }
  3606. }
  3607. else if (mxEvent.isTouchEvent(evt) || (this.bbox != null &&
  3608. mxUtils.contains(this.bbox, me.getGraphX(), me.getGraphY())))
  3609. {
  3610. // Shows existing hover icons if inside bounding box
  3611. this.setDisplay('');
  3612. this.repaint();
  3613. }
  3614. else if (!mxEvent.isTouchEvent(evt))
  3615. {
  3616. this.reset();
  3617. }
  3618. connectionHandlerActive = false;
  3619. this.resetActiveArrow();
  3620. })
  3621. });
  3622. };
  3623. /**
  3624. *
  3625. */
  3626. HoverIcons.prototype.isResetEvent = function(evt, allowShift)
  3627. {
  3628. return mxEvent.isAltDown(evt) || (this.activeArrow == null && mxEvent.isShiftDown(evt)) ||
  3629. (mxEvent.isPopupTrigger(evt) && !this.graph.isCloneEvent(evt));
  3630. };
  3631. /**
  3632. *
  3633. */
  3634. HoverIcons.prototype.createArrow = function(img, tooltip)
  3635. {
  3636. var arrow = null;
  3637. if (mxClient.IS_IE && !mxClient.IS_SVG)
  3638. {
  3639. // Workaround for PNG images in IE6
  3640. if (mxClient.IS_IE6 && document.compatMode != 'CSS1Compat')
  3641. {
  3642. arrow = document.createElement(mxClient.VML_PREFIX + ':image');
  3643. arrow.setAttribute('src', img.src);
  3644. arrow.style.borderStyle = 'none';
  3645. }
  3646. else
  3647. {
  3648. arrow = document.createElement('div');
  3649. arrow.style.backgroundImage = 'url(' + img.src + ')';
  3650. arrow.style.backgroundPosition = 'center';
  3651. arrow.style.backgroundRepeat = 'no-repeat';
  3652. }
  3653. arrow.style.width = (img.width + 4) + 'px';
  3654. arrow.style.height = (img.height + 4) + 'px';
  3655. arrow.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  3656. }
  3657. else
  3658. {
  3659. arrow = mxUtils.createImage(img.src);
  3660. arrow.style.width = img.width + 'px';
  3661. arrow.style.height = img.height + 'px';
  3662. arrow.style.padding = this.tolerance + 'px';
  3663. }
  3664. if (tooltip != null)
  3665. {
  3666. arrow.setAttribute('title', tooltip);
  3667. }
  3668. arrow.style.position = 'absolute';
  3669. arrow.style.cursor = this.cssCursor;
  3670. mxEvent.addGestureListeners(arrow, mxUtils.bind(this, function(evt)
  3671. {
  3672. if (this.currentState != null && !this.isResetEvent(evt))
  3673. {
  3674. this.mouseDownPoint = mxUtils.convertPoint(this.graph.container,
  3675. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  3676. this.drag(evt, this.mouseDownPoint.x, this.mouseDownPoint.y);
  3677. this.activeArrow = arrow;
  3678. this.setDisplay('none');
  3679. mxEvent.consume(evt);
  3680. }
  3681. }));
  3682. // Captures mouse events as events on graph
  3683. mxEvent.redirectMouseEvents(arrow, this.graph, this.currentState);
  3684. mxEvent.addListener(arrow, 'mouseenter', mxUtils.bind(this, function(evt)
  3685. {
  3686. // Workaround for Firefox firing mouseenter on touchend
  3687. if (mxEvent.isMouseEvent(evt))
  3688. {
  3689. if (this.activeArrow != null && this.activeArrow != arrow)
  3690. {
  3691. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  3692. }
  3693. this.graph.connectionHandler.constraintHandler.reset();
  3694. mxUtils.setOpacity(arrow, 100);
  3695. this.activeArrow = arrow;
  3696. }
  3697. }));
  3698. mxEvent.addListener(arrow, 'mouseleave', mxUtils.bind(this, function(evt)
  3699. {
  3700. // Workaround for IE11 firing this event on touch
  3701. if (!this.graph.isMouseDown)
  3702. {
  3703. this.resetActiveArrow();
  3704. }
  3705. }));
  3706. return arrow;
  3707. };
  3708. /**
  3709. *
  3710. */
  3711. HoverIcons.prototype.resetActiveArrow = function()
  3712. {
  3713. if (this.activeArrow != null)
  3714. {
  3715. mxUtils.setOpacity(this.activeArrow, this.inactiveOpacity);
  3716. this.activeArrow = null;
  3717. }
  3718. };
  3719. /**
  3720. *
  3721. */
  3722. HoverIcons.prototype.getDirection = function()
  3723. {
  3724. var dir = mxConstants.DIRECTION_EAST;
  3725. if (this.activeArrow == this.arrowUp)
  3726. {
  3727. dir = mxConstants.DIRECTION_NORTH;
  3728. }
  3729. else if (this.activeArrow == this.arrowDown)
  3730. {
  3731. dir = mxConstants.DIRECTION_SOUTH;
  3732. }
  3733. else if (this.activeArrow == this.arrowLeft)
  3734. {
  3735. dir = mxConstants.DIRECTION_WEST;
  3736. }
  3737. return dir;
  3738. };
  3739. /**
  3740. *
  3741. */
  3742. HoverIcons.prototype.visitNodes = function(visitor)
  3743. {
  3744. for (var i = 0; i < this.elts.length; i++)
  3745. {
  3746. if (this.elts[i] != null)
  3747. {
  3748. visitor(this.elts[i]);
  3749. }
  3750. }
  3751. };
  3752. /**
  3753. *
  3754. */
  3755. HoverIcons.prototype.removeNodes = function()
  3756. {
  3757. this.visitNodes(function(elt)
  3758. {
  3759. if (elt.parentNode != null)
  3760. {
  3761. elt.parentNode.removeChild(elt);
  3762. }
  3763. });
  3764. };
  3765. /**
  3766. *
  3767. */
  3768. HoverIcons.prototype.setDisplay = function(display)
  3769. {
  3770. this.visitNodes(function(elt)
  3771. {
  3772. elt.style.display = display;
  3773. });
  3774. };
  3775. /**
  3776. *
  3777. */
  3778. HoverIcons.prototype.isActive = function()
  3779. {
  3780. return this.activeArrow != null && this.currentState != null;
  3781. };
  3782. /**
  3783. *
  3784. */
  3785. HoverIcons.prototype.drag = function(evt, x, y)
  3786. {
  3787. this.graph.popupMenuHandler.hideMenu();
  3788. this.graph.stopEditing(false);
  3789. // Checks if state was removed in call to stopEditing above
  3790. if (this.currentState != null)
  3791. {
  3792. this.graph.connectionHandler.start(this.currentState, x, y);
  3793. this.graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  3794. this.graph.isMouseDown = true;
  3795. // Hides handles for selection cell
  3796. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  3797. if (handler != null)
  3798. {
  3799. handler.setHandlesVisible(false);
  3800. }
  3801. // Ctrl+shift drag sets source constraint
  3802. var es = this.graph.connectionHandler.edgeState;
  3803. if (evt != null && mxEvent.isShiftDown(evt) && mxEvent.isControlDown(evt) && es != null &&
  3804. mxUtils.getValue(es.style, mxConstants.STYLE_EDGE, null) === 'orthogonalEdgeStyle')
  3805. {
  3806. var direction = this.getDirection();
  3807. es.cell.style = mxUtils.setStyle(es.cell.style, 'sourcePortConstraint', direction);
  3808. es.style['sourcePortConstraint'] = direction;
  3809. }
  3810. }
  3811. };
  3812. /**
  3813. *
  3814. */
  3815. HoverIcons.prototype.getStateAt = function(state, x, y)
  3816. {
  3817. return this.graph.view.getState(this.graph.getCellAt(x, y));
  3818. };
  3819. /**
  3820. *
  3821. */
  3822. HoverIcons.prototype.click = function(state, dir, me)
  3823. {
  3824. var evt = me.getEvent();
  3825. var x = me.getGraphX();
  3826. var y = me.getGraphY();
  3827. var tmp = this.getStateAt(state, x, y);
  3828. if (tmp != null && this.graph.model.isEdge(tmp.cell) && !this.graph.isCloneEvent(evt) &&
  3829. (tmp.getVisibleTerminalState(true) == state || tmp.getVisibleTerminalState(false) == state))
  3830. {
  3831. this.graph.setSelectionCell(tmp.cell);
  3832. this.reset();
  3833. }
  3834. else if (state != null)
  3835. {
  3836. this.execute(state, dir, me);
  3837. }
  3838. me.consume();
  3839. };
  3840. /**
  3841. *
  3842. */
  3843. HoverIcons.prototype.execute = function(state, dir, me)
  3844. {
  3845. var evt = me.getEvent();
  3846. this.graph.selectCellsForConnectVertex(this.graph.connectVertex(
  3847. state.cell, dir, this.graph.defaultEdgeLength, evt, this.graph.isCloneEvent(evt),
  3848. this.graph.isCloneEvent(evt)), evt, this);
  3849. };
  3850. /**
  3851. *
  3852. */
  3853. HoverIcons.prototype.reset = function(clearTimeout)
  3854. {
  3855. clearTimeout = (clearTimeout == null) ? true : clearTimeout;
  3856. if (clearTimeout && this.updateThread != null)
  3857. {
  3858. window.clearTimeout(this.updateThread);
  3859. }
  3860. this.mouseDownPoint = null;
  3861. this.currentState = null;
  3862. this.activeArrow = null;
  3863. this.removeNodes();
  3864. this.bbox = null;
  3865. };
  3866. /**
  3867. *
  3868. */
  3869. HoverIcons.prototype.repaint = function()
  3870. {
  3871. this.bbox = null;
  3872. if (this.currentState != null)
  3873. {
  3874. // Checks if cell was deleted
  3875. this.currentState = this.getState(this.currentState);
  3876. // Cell was deleted
  3877. if (this.currentState != null &&
  3878. this.graph.model.isVertex(this.currentState.cell) &&
  3879. this.graph.isCellConnectable(this.currentState.cell))
  3880. {
  3881. var bds = mxRectangle.fromRectangle(this.currentState);
  3882. // Uses outer bounding box to take rotation into account
  3883. if (this.currentState.shape != null && this.currentState.shape.boundingBox != null)
  3884. {
  3885. bds = mxRectangle.fromRectangle(this.currentState.shape.boundingBox);
  3886. }
  3887. bds.grow(this.graph.tolerance);
  3888. bds.grow(this.arrowSpacing);
  3889. var handler = this.graph.selectionCellsHandler.getHandler(this.currentState.cell);
  3890. if (this.graph.isTableRow(this.currentState.cell))
  3891. {
  3892. handler = this.graph.selectionCellsHandler.getHandler(
  3893. this.graph.model.getParent(this.currentState.cell));
  3894. }
  3895. var rotationBbox = null;
  3896. if (handler != null)
  3897. {
  3898. bds.x -= handler.horizontalOffset / 2;
  3899. bds.y -= handler.verticalOffset / 2;
  3900. bds.width += handler.horizontalOffset;
  3901. bds.height += handler.verticalOffset;
  3902. // Adds bounding box of rotation handle to avoid overlap
  3903. if (handler.rotationShape != null && handler.rotationShape.node != null &&
  3904. handler.rotationShape.node.style.visibility != 'hidden' &&
  3905. handler.rotationShape.node.style.display != 'none' &&
  3906. handler.rotationShape.boundingBox != null)
  3907. {
  3908. rotationBbox = handler.rotationShape.boundingBox;
  3909. }
  3910. }
  3911. // Positions arrows avoid collisions with rotation handle
  3912. var positionArrow = mxUtils.bind(this, function(arrow, x, y)
  3913. {
  3914. if (rotationBbox != null)
  3915. {
  3916. var bbox = new mxRectangle(x, y, arrow.clientWidth, arrow.clientHeight);
  3917. if (mxUtils.intersects(bbox, rotationBbox))
  3918. {
  3919. if (arrow == this.arrowUp)
  3920. {
  3921. y -= bbox.y + bbox.height - rotationBbox.y;
  3922. }
  3923. else if (arrow == this.arrowRight)
  3924. {
  3925. x += rotationBbox.x + rotationBbox.width - bbox.x;
  3926. }
  3927. else if (arrow == this.arrowDown)
  3928. {
  3929. y += rotationBbox.y + rotationBbox.height - bbox.y;
  3930. }
  3931. else if (arrow == this.arrowLeft)
  3932. {
  3933. x -= bbox.x + bbox.width - rotationBbox.x;
  3934. }
  3935. }
  3936. }
  3937. arrow.style.left = x + 'px';
  3938. arrow.style.top = y + 'px';
  3939. mxUtils.setOpacity(arrow, this.inactiveOpacity);
  3940. });
  3941. positionArrow(this.arrowUp,
  3942. Math.round(this.currentState.getCenterX() - this.triangleUp.width / 2 - this.tolerance),
  3943. Math.round(bds.y - this.triangleUp.height - this.tolerance));
  3944. positionArrow(this.arrowRight, Math.round(bds.x + bds.width - this.tolerance),
  3945. Math.round(this.currentState.getCenterY() - this.triangleRight.height / 2 - this.tolerance));
  3946. positionArrow(this.arrowDown, parseInt(this.arrowUp.style.left),
  3947. Math.round(bds.y + bds.height - this.tolerance));
  3948. positionArrow(this.arrowLeft, Math.round(bds.x - this.triangleLeft.width - this.tolerance),
  3949. parseInt(this.arrowRight.style.top));
  3950. if (this.checkCollisions)
  3951. {
  3952. var right = this.graph.getCellAt(bds.x + bds.width +
  3953. this.triangleRight.width / 2, this.currentState.getCenterY());
  3954. var left = this.graph.getCellAt(bds.x - this.triangleLeft.width / 2, this.currentState.getCenterY());
  3955. var top = this.graph.getCellAt(this.currentState.getCenterX(), bds.y - this.triangleUp.height / 2);
  3956. var bottom = this.graph.getCellAt(this.currentState.getCenterX(), bds.y + bds.height + this.triangleDown.height / 2);
  3957. // Shows hover icons large cell is behind all directions of current cell
  3958. if (right != null && right == left && left == top && top == bottom)
  3959. {
  3960. right = null;
  3961. left = null;
  3962. top = null;
  3963. bottom = null;
  3964. }
  3965. var currentGeo = this.graph.getCellGeometry(this.currentState.cell);
  3966. var checkCollision = mxUtils.bind(this, function(cell, arrow)
  3967. {
  3968. var geo = this.graph.model.isVertex(cell) && this.graph.getCellGeometry(cell);
  3969. // Ignores collision if vertex is more than 3 times the size of this vertex
  3970. if (cell != null && !this.graph.model.isAncestor(cell, this.currentState.cell) &&
  3971. !this.graph.isSwimlane(cell) && (geo == null || currentGeo == null ||
  3972. (geo.height < 3 * currentGeo.height && geo.width < 3 * currentGeo.width)))
  3973. {
  3974. arrow.style.visibility = 'hidden';
  3975. }
  3976. else
  3977. {
  3978. arrow.style.visibility = 'visible';
  3979. }
  3980. });
  3981. checkCollision(right, this.arrowRight);
  3982. checkCollision(left, this.arrowLeft);
  3983. checkCollision(top, this.arrowUp);
  3984. checkCollision(bottom, this.arrowDown);
  3985. }
  3986. else
  3987. {
  3988. this.arrowLeft.style.visibility = 'visible';
  3989. this.arrowRight.style.visibility = 'visible';
  3990. this.arrowUp.style.visibility = 'visible';
  3991. this.arrowDown.style.visibility = 'visible';
  3992. }
  3993. if (this.graph.tooltipHandler.isEnabled())
  3994. {
  3995. this.arrowLeft.setAttribute('title', mxResources.get('plusTooltip'));
  3996. this.arrowRight.setAttribute('title', mxResources.get('plusTooltip'));
  3997. this.arrowUp.setAttribute('title', mxResources.get('plusTooltip'));
  3998. this.arrowDown.setAttribute('title', mxResources.get('plusTooltip'));
  3999. }
  4000. else
  4001. {
  4002. this.arrowLeft.removeAttribute('title');
  4003. this.arrowRight.removeAttribute('title');
  4004. this.arrowUp.removeAttribute('title');
  4005. this.arrowDown.removeAttribute('title');
  4006. }
  4007. }
  4008. else
  4009. {
  4010. this.reset();
  4011. }
  4012. // Updates bounding box
  4013. if (this.currentState != null)
  4014. {
  4015. this.bbox = this.computeBoundingBox();
  4016. // Adds tolerance for hover
  4017. if (this.bbox != null)
  4018. {
  4019. this.bbox.grow(10);
  4020. }
  4021. }
  4022. }
  4023. };
  4024. /**
  4025. *
  4026. */
  4027. HoverIcons.prototype.computeBoundingBox = function()
  4028. {
  4029. var bbox = (!this.graph.model.isEdge(this.currentState.cell)) ? mxRectangle.fromRectangle(this.currentState) : null;
  4030. this.visitNodes(function(elt)
  4031. {
  4032. if (elt.parentNode != null)
  4033. {
  4034. var tmp = new mxRectangle(elt.offsetLeft, elt.offsetTop, elt.offsetWidth, elt.offsetHeight);
  4035. if (bbox == null)
  4036. {
  4037. bbox = tmp;
  4038. }
  4039. else
  4040. {
  4041. bbox.add(tmp);
  4042. }
  4043. }
  4044. });
  4045. return bbox;
  4046. };
  4047. /**
  4048. *
  4049. */
  4050. HoverIcons.prototype.getState = function(state)
  4051. {
  4052. if (state != null)
  4053. {
  4054. var cell = state.cell;
  4055. if (!this.graph.getModel().contains(cell))
  4056. {
  4057. state = null;
  4058. }
  4059. else
  4060. {
  4061. // Uses connectable parent vertex if child is not connectable
  4062. if (this.graph.getModel().isVertex(cell) && !this.graph.isCellConnectable(cell))
  4063. {
  4064. var parent = this.graph.getModel().getParent(cell);
  4065. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  4066. {
  4067. cell = parent;
  4068. }
  4069. }
  4070. // Ignores locked cells and edges
  4071. if (this.graph.isCellLocked(cell) || this.graph.model.isEdge(cell))
  4072. {
  4073. cell = null;
  4074. }
  4075. state = this.graph.view.getState(cell);
  4076. if (state != null && state.style == null)
  4077. {
  4078. state = null;
  4079. }
  4080. }
  4081. }
  4082. return state;
  4083. };
  4084. /**
  4085. *
  4086. */
  4087. HoverIcons.prototype.update = function(state, x, y)
  4088. {
  4089. if (!this.graph.connectionArrowsEnabled || (state != null &&
  4090. mxUtils.getValue(state.style, 'allowArrows', '1') == '0'))
  4091. {
  4092. this.reset();
  4093. }
  4094. else
  4095. {
  4096. if (state != null && state.cell.geometry != null && state.cell.geometry.relative &&
  4097. this.graph.model.isEdge(state.cell.parent))
  4098. {
  4099. state = null;
  4100. }
  4101. var timeOnTarget = null;
  4102. // Time on target
  4103. if (this.prev != state || this.isActive())
  4104. {
  4105. this.startTime = new Date().getTime();
  4106. this.prev = state;
  4107. timeOnTarget = 0;
  4108. if (this.updateThread != null)
  4109. {
  4110. window.clearTimeout(this.updateThread);
  4111. }
  4112. if (state != null)
  4113. {
  4114. // Starts timer to update current state with no mouse events
  4115. this.updateThread = window.setTimeout(mxUtils.bind(this, function()
  4116. {
  4117. if (!this.isActive() && !this.graph.isMouseDown &&
  4118. !this.graph.panningHandler.isActive())
  4119. {
  4120. this.prev = state;
  4121. this.update(state, x, y);
  4122. }
  4123. }), this.updateDelay + 10);
  4124. }
  4125. }
  4126. else if (this.startTime != null)
  4127. {
  4128. timeOnTarget = new Date().getTime() - this.startTime;
  4129. }
  4130. this.setDisplay('');
  4131. if (this.currentState != null && this.currentState != state && timeOnTarget < this.activationDelay &&
  4132. this.bbox != null && !mxUtils.contains(this.bbox, x, y))
  4133. {
  4134. this.reset(false);
  4135. }
  4136. else if (this.currentState != null || timeOnTarget > this.activationDelay)
  4137. {
  4138. if (this.currentState != state && ((timeOnTarget > this.updateDelay && state != null) ||
  4139. this.bbox == null || x == null || y == null || !mxUtils.contains(this.bbox, x, y)))
  4140. {
  4141. if (state != null && this.graph.isEnabled())
  4142. {
  4143. this.removeNodes();
  4144. this.setCurrentState(state);
  4145. this.repaint();
  4146. // Resets connection points on other focused cells
  4147. if (this.graph.connectionHandler.constraintHandler.currentFocus != state)
  4148. {
  4149. this.graph.connectionHandler.constraintHandler.reset();
  4150. }
  4151. }
  4152. else
  4153. {
  4154. this.reset();
  4155. }
  4156. }
  4157. }
  4158. }
  4159. };
  4160. /**
  4161. *
  4162. */
  4163. HoverIcons.prototype.setCurrentState = function(state)
  4164. {
  4165. if (state.style['portConstraint'] != 'eastwest')
  4166. {
  4167. this.graph.container.appendChild(this.arrowUp);
  4168. this.graph.container.appendChild(this.arrowDown);
  4169. }
  4170. this.graph.container.appendChild(this.arrowRight);
  4171. this.graph.container.appendChild(this.arrowLeft);
  4172. this.currentState = state;
  4173. };
  4174. /**
  4175. * Returns true if the given cell is a table.
  4176. */
  4177. Graph.prototype.createParent = function(parent, child, childCount, dx, dy)
  4178. {
  4179. parent = this.cloneCell(parent);
  4180. for (var i = 0; i < childCount; i++)
  4181. {
  4182. var clone = this.cloneCell(child);
  4183. var geo = this.getCellGeometry(clone)
  4184. if (geo != null)
  4185. {
  4186. geo.x += i * dx;
  4187. geo.y += i * dy;
  4188. }
  4189. parent.insert(clone);
  4190. }
  4191. return parent;
  4192. };
  4193. /**
  4194. * Returns true if the given cell is a table.
  4195. */
  4196. Graph.prototype.createTable = function(rowCount, colCount, w, h, title, startSize, tableStyle, rowStyle, cellStyle)
  4197. {
  4198. w = (w != null) ? w : 60;
  4199. h = (h != null) ? h : 40;
  4200. startSize = (startSize != null) ? startSize : 30;
  4201. tableStyle = (tableStyle != null) ? tableStyle : 'shape=table;html=1;whiteSpace=wrap;startSize=' +
  4202. ((title != null) ? startSize : '0') + ';container=1;collapsible=0;childLayout=tableLayout;';
  4203. rowStyle = (rowStyle != null) ? rowStyle : 'shape=partialRectangle;html=1;whiteSpace=wrap;collapsible=0;dropTarget=0;' +
  4204. 'pointerEvents=0;fillColor=none;top=0;left=0;bottom=0;right=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;';
  4205. cellStyle = (cellStyle != null) ? cellStyle : 'shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;' +
  4206. 'overflow=hidden;fillColor=none;top=0;left=0;bottom=0;right=0;';
  4207. return this.createParent(this.createVertex(null, null, (title != null) ? title : '',
  4208. 0, 0, colCount * w, rowCount * h + ((title != null) ? startSize : 0), tableStyle),
  4209. this.createParent(this.createVertex(null, null, '', 0, 0, colCount * w, h, rowStyle),
  4210. this.createVertex(null, null, '', 0, 0, w, h, cellStyle),
  4211. colCount, w, 0), rowCount, 0, h);
  4212. };
  4213. /**
  4214. * Sets the values for the cells and rows in the given table and returns the table.
  4215. */
  4216. Graph.prototype.setTableValues = function(table, values, rowValues)
  4217. {
  4218. var rows = this.model.getChildCells(table, true);
  4219. for (var i = 0; i < rows.length; i++)
  4220. {
  4221. if (rowValues != null)
  4222. {
  4223. rows[i].value = rowValues[i];
  4224. }
  4225. if (values != null)
  4226. {
  4227. var cells = this.model.getChildCells(rows[i], true);
  4228. for (var j = 0; j < cells.length; j++)
  4229. {
  4230. if (values[i][j] != null)
  4231. {
  4232. cells[j].value = values[i][j];
  4233. }
  4234. }
  4235. }
  4236. }
  4237. return table;
  4238. };
  4239. /**
  4240. *
  4241. */
  4242. Graph.prototype.createCrossFunctionalSwimlane = function(rowCount, colCount, w, h, startSize, tableStyle, rowStyle, firstCellStyle, cellStyle)
  4243. {
  4244. w = (w != null) ? w : 120;
  4245. h = (h != null) ? h : 120;
  4246. startSize = (startSize != null) ? startSize : 40;
  4247. var s = 'html=1;whiteSpace=wrap;collapsible=0;recursiveResize=0;expand=0;pointerEvents=0;';
  4248. tableStyle = (tableStyle != null) ? tableStyle : 'shape=table;childLayout=tableLayout;' +
  4249. 'rowLines=0;columnLines=0;startSize=' + startSize + ';' + s;
  4250. rowStyle = (rowStyle != null) ? rowStyle : 'swimlane;horizontal=0;points=[[0,0.5],[1,0.5]];' +
  4251. 'portConstraint=eastwest;startSize=' + startSize + ';' + s;
  4252. firstCellStyle = (firstCellStyle != null) ? firstCellStyle : 'swimlane;connectable=0;startSize=40;' + s;
  4253. cellStyle = (cellStyle != null) ? cellStyle : 'swimlane;connectable=0;startSize=0;' + s;
  4254. var table = this.createVertex(null, null, '', 0, 0,
  4255. colCount * w, rowCount * h, tableStyle);
  4256. var t = mxUtils.getValue(this.getCellStyle(table), mxConstants.STYLE_STARTSIZE,
  4257. mxConstants.DEFAULT_STARTSIZE);
  4258. table.geometry.width += t;
  4259. table.geometry.height += t;
  4260. var row = this.createVertex(null, null, '', 0, t, colCount * w + t, h, rowStyle);
  4261. table.insert(this.createParent(row, this.createVertex(null, null,
  4262. '', t, 0, w, h, firstCellStyle), colCount, w, 0));
  4263. if (rowCount > 1)
  4264. {
  4265. row.geometry.y = h + t;
  4266. return this.createParent(table, this.createParent(row,
  4267. this.createVertex(null, null, '', t, 0, w, h, cellStyle),
  4268. colCount, w, 0), rowCount - 1, 0, h);
  4269. }
  4270. else
  4271. {
  4272. return table;
  4273. }
  4274. };
  4275. /**
  4276. * Returns true if the given cell is a table cell.
  4277. */
  4278. Graph.prototype.isTableCell = function(cell)
  4279. {
  4280. return this.model.isVertex(cell) && this.isTableRow(this.model.getParent(cell));
  4281. };
  4282. /**
  4283. * Returns true if the given cell is a table row.
  4284. */
  4285. Graph.prototype.isTableRow = function(cell)
  4286. {
  4287. return this.model.isVertex(cell) && this.isTable(this.model.getParent(cell));
  4288. };
  4289. /**
  4290. * Returns true if the given cell is a table.
  4291. */
  4292. Graph.prototype.isTable = function(cell)
  4293. {
  4294. var style = this.getCellStyle(cell);
  4295. return style != null && style['childLayout'] == 'tableLayout';
  4296. };
  4297. /**
  4298. * Updates the row and table heights.
  4299. */
  4300. Graph.prototype.setTableRowHeight = function(row, dy, extend)
  4301. {
  4302. extend = (extend != null) ? extend : true;
  4303. var model = this.getModel();
  4304. model.beginUpdate();
  4305. try
  4306. {
  4307. var rgeo = this.getCellGeometry(row);
  4308. // Sets height of row
  4309. if (rgeo != null)
  4310. {
  4311. rgeo = rgeo.clone();
  4312. rgeo.height += dy;
  4313. model.setGeometry(row, rgeo);
  4314. var table = model.getParent(row);
  4315. var rows = model.getChildCells(table, true);
  4316. // Shifts and resizes neighbor row
  4317. if (!extend)
  4318. {
  4319. var index = mxUtils.indexOf(rows, row);
  4320. if (index < rows.length - 1)
  4321. {
  4322. var nextRow = rows[index + 1];
  4323. var geo = this.getCellGeometry(nextRow);
  4324. if (geo != null)
  4325. {
  4326. geo = geo.clone();
  4327. geo.y += dy;
  4328. geo.height -= dy;
  4329. model.setGeometry(nextRow, geo);
  4330. }
  4331. }
  4332. }
  4333. // Updates height of table
  4334. var tgeo = this.getCellGeometry(table);
  4335. if (tgeo != null)
  4336. {
  4337. // Always extends for last row
  4338. if (!extend)
  4339. {
  4340. extend = row == rows[rows.length - 1];
  4341. }
  4342. if (extend)
  4343. {
  4344. tgeo = tgeo.clone();
  4345. tgeo.height += dy;
  4346. model.setGeometry(table, tgeo);
  4347. }
  4348. }
  4349. if (this.layoutManager != null)
  4350. {
  4351. this.layoutManager.executeLayout(table, true);
  4352. }
  4353. }
  4354. }
  4355. finally
  4356. {
  4357. model.endUpdate();
  4358. }
  4359. };
  4360. /**
  4361. * Updates column width and row height.
  4362. */
  4363. Graph.prototype.setTableColumnWidth = function(col, dx, extend)
  4364. {
  4365. extend = (extend != null) ? extend : false;
  4366. var model = this.getModel();
  4367. var row = model.getParent(col);
  4368. var table = model.getParent(row);
  4369. var cells = model.getChildCells(row, true);
  4370. var index = mxUtils.indexOf(cells, col);
  4371. var lastColumn = index == cells.length - 1;
  4372. model.beginUpdate();
  4373. try
  4374. {
  4375. // Sets width of child cell
  4376. var rows = model.getChildCells(table, true);
  4377. for (var i = 0; i < rows.length; i++)
  4378. {
  4379. row = rows[i];
  4380. cells = model.getChildCells(row, true);
  4381. var cell = cells[index];
  4382. var geo = this.getCellGeometry(cell);
  4383. if (geo != null)
  4384. {
  4385. geo = geo.clone();
  4386. geo.width += dx;
  4387. model.setGeometry(cell, geo);
  4388. }
  4389. // Shifts and resizes neighbor column
  4390. if (index < cells.length - 1)
  4391. {
  4392. cell = cells[index + 1];
  4393. var geo = this.getCellGeometry(cell);
  4394. if (geo != null)
  4395. {
  4396. geo = geo.clone();
  4397. geo.x += dx;
  4398. if (!extend)
  4399. {
  4400. geo.width -= dx;
  4401. }
  4402. model.setGeometry(cell, geo);
  4403. }
  4404. }
  4405. }
  4406. if (lastColumn || extend)
  4407. {
  4408. // Updates width of table
  4409. var tgeo = this.getCellGeometry(table);
  4410. if (tgeo != null)
  4411. {
  4412. tgeo = tgeo.clone();
  4413. tgeo.width += dx;
  4414. model.setGeometry(table, tgeo);
  4415. }
  4416. }
  4417. if (this.layoutManager != null)
  4418. {
  4419. this.layoutManager.executeLayout(table, true);
  4420. }
  4421. }
  4422. finally
  4423. {
  4424. model.endUpdate();
  4425. }
  4426. };
  4427. /**
  4428. * Special Layout for tables.
  4429. */
  4430. function TableLayout(graph)
  4431. {
  4432. mxGraphLayout.call(this, graph);
  4433. };
  4434. /**
  4435. * Extends mxGraphLayout.
  4436. */
  4437. TableLayout.prototype = new mxStackLayout();
  4438. TableLayout.prototype.constructor = TableLayout;
  4439. /**
  4440. * Function: isHorizontal
  4441. *
  4442. * Overrides stack layout to handle row reorder.
  4443. */
  4444. TableLayout.prototype.isHorizontal = function()
  4445. {
  4446. return false;
  4447. };
  4448. /**
  4449. * Function: isVertexIgnored
  4450. *
  4451. * Overrides to allow for table rows and cells.
  4452. */
  4453. TableLayout.prototype.isVertexIgnored = function(vertex)
  4454. {
  4455. return !this.graph.getModel().isVertex(vertex) ||
  4456. !this.graph.isCellVisible(vertex);
  4457. };
  4458. /**
  4459. * Function: getSize
  4460. *
  4461. * Returns the total vertical or horizontal size of the given cells.
  4462. */
  4463. TableLayout.prototype.getSize = function(cells, horizontal)
  4464. {
  4465. var total = 0;
  4466. for (var i = 0; i < cells.length; i++)
  4467. {
  4468. if (!this.isVertexIgnored(cells[i]))
  4469. {
  4470. var geo = this.graph.getCellGeometry(cells[i]);
  4471. if (geo != null)
  4472. {
  4473. total += (horizontal) ? geo.width : geo.height;
  4474. }
  4475. }
  4476. }
  4477. return total;
  4478. };
  4479. /**
  4480. * Function: getRowLayout
  4481. *
  4482. * Returns the column positions for the given row and table width.
  4483. */
  4484. TableLayout.prototype.getRowLayout = function(row, width)
  4485. {
  4486. var cells = this.graph.model.getChildCells(row, true);
  4487. var off = this.graph.getActualStartSize(row, true);
  4488. var sw = this.getSize(cells, true);
  4489. var rw = width - off.x - off.width;
  4490. var result = [];
  4491. var x = off.x;
  4492. for (var i = 0; i < cells.length; i++)
  4493. {
  4494. var cell = this.graph.getCellGeometry(cells[i]);
  4495. if (cell != null)
  4496. {
  4497. x += cell.width * rw / sw;
  4498. result.push(Math.round(x));
  4499. }
  4500. }
  4501. return result;
  4502. };
  4503. /**
  4504. * Function: layoutRow
  4505. *
  4506. * Places the cells at the given positions in the given row.
  4507. */
  4508. TableLayout.prototype.layoutRow = function(row, positions, height, tw)
  4509. {
  4510. var model = this.graph.getModel();
  4511. var cells = model.getChildCells(row, true);
  4512. var off = this.graph.getActualStartSize(row, true);
  4513. var x = off.x;
  4514. var sw = 0;
  4515. if (positions != null)
  4516. {
  4517. positions = positions.slice();
  4518. positions.splice(0, 0, off.x);
  4519. }
  4520. for (var i = 0; i < cells.length; i++)
  4521. {
  4522. var cell = this.graph.getCellGeometry(cells[i]);
  4523. if (cell != null)
  4524. {
  4525. cell = cell.clone();
  4526. cell.y = off.y;
  4527. cell.height = height - off.y - off.height;
  4528. if (positions != null)
  4529. {
  4530. cell.x = positions[i];
  4531. cell.width = positions[i + 1] - cell.x;
  4532. // Fills with last cell if not enough cells
  4533. if (i == cells.length - 1 && i < positions.length - 2)
  4534. {
  4535. cell.width = tw - cell.x - off.x - off.width;
  4536. }
  4537. }
  4538. else
  4539. {
  4540. cell.x = x;
  4541. x += cell.width;
  4542. if (i == cells.length - 1)
  4543. {
  4544. cell.width = tw - off.x - off.width - sw;
  4545. }
  4546. else
  4547. {
  4548. sw += cell.width;
  4549. }
  4550. }
  4551. model.setGeometry(cells[i], cell);
  4552. }
  4553. }
  4554. return sw;
  4555. };
  4556. /**
  4557. * Function: execute
  4558. *
  4559. * Implements <mxGraphLayout.execute>.
  4560. */
  4561. TableLayout.prototype.execute = function(parent)
  4562. {
  4563. if (parent != null)
  4564. {
  4565. var offset = this.graph.getActualStartSize(parent, true);
  4566. var table = this.graph.getCellGeometry(parent);
  4567. var style = this.graph.getCellStyle(parent);
  4568. var resizeLastRow = mxUtils.getValue(style,
  4569. 'resizeLastRow', '0') == '1';
  4570. var resizeLast = mxUtils.getValue(style,
  4571. 'resizeLast', '0') == '1';
  4572. var fixedRows = mxUtils.getValue(style,
  4573. 'fixedRows', '0') == '1';
  4574. var model = this.graph.getModel();
  4575. var sw = 0;
  4576. model.beginUpdate();
  4577. try
  4578. {
  4579. var th = table.height - offset.y - offset.height;
  4580. var tw = table.width - offset.x - offset.width;
  4581. var rows = model.getChildCells(parent, true);
  4582. var sh = this.getSize(rows, false);
  4583. if (th > 0 && tw > 0 && rows.length > 0 && sh > 0)
  4584. {
  4585. if (resizeLastRow)
  4586. {
  4587. var row = this.graph.getCellGeometry(rows[rows.length - 1]);
  4588. if (row != null)
  4589. {
  4590. row = row.clone();
  4591. row.height = th - sh + row.height;
  4592. model.setGeometry(rows[rows.length - 1], row);
  4593. }
  4594. }
  4595. var pos = (resizeLast) ? null : this.getRowLayout(rows[0], tw);
  4596. var y = offset.y;
  4597. // Updates row geometries
  4598. for (var i = 0; i < rows.length; i++)
  4599. {
  4600. var row = this.graph.getCellGeometry(rows[i]);
  4601. if (row != null)
  4602. {
  4603. row = row.clone();
  4604. row.x = offset.x;
  4605. row.width = tw;
  4606. row.y = Math.round(y);
  4607. if (resizeLastRow || fixedRows)
  4608. {
  4609. y += row.height;
  4610. }
  4611. else
  4612. {
  4613. y += (row.height / sh) * th;
  4614. }
  4615. row.height = Math.round(y) - row.y;
  4616. model.setGeometry(rows[i], row);
  4617. }
  4618. // Updates cell geometries
  4619. sw = Math.max(sw, this.layoutRow(rows[i], pos, row.height, tw));
  4620. }
  4621. if (fixedRows && th < sh)
  4622. {
  4623. table = table.clone();
  4624. table.height = y + offset.height;
  4625. model.setGeometry(parent, table);
  4626. }
  4627. if (resizeLast && tw < sw + Graph.minTableColumnWidth)
  4628. {
  4629. table = table.clone();
  4630. table.width = sw + offset.width + offset.x + Graph.minTableColumnWidth;
  4631. model.setGeometry(parent, table);
  4632. }
  4633. }
  4634. }
  4635. finally
  4636. {
  4637. model.endUpdate();
  4638. }
  4639. }
  4640. };
  4641. (function()
  4642. {
  4643. /**
  4644. * Reset the list of processed edges.
  4645. */
  4646. var mxGraphViewResetValidationState = mxGraphView.prototype.resetValidationState;
  4647. mxGraphView.prototype.resetValidationState = function()
  4648. {
  4649. mxGraphViewResetValidationState.apply(this, arguments);
  4650. this.validEdges = [];
  4651. };
  4652. /**
  4653. * Updates jumps for valid edges and repaints if needed.
  4654. */
  4655. var mxGraphViewValidateCellState = mxGraphView.prototype.validateCellState;
  4656. mxGraphView.prototype.validateCellState = function(cell, recurse)
  4657. {
  4658. recurse = (recurse != null) ? recurse : true;
  4659. var state = this.getState(cell);
  4660. // Forces repaint if jumps change on a valid edge
  4661. if (state != null && recurse && this.graph.model.isEdge(state.cell) &&
  4662. state.style != null && state.style[mxConstants.STYLE_CURVED] != 1 &&
  4663. !state.invalid && this.updateLineJumps(state))
  4664. {
  4665. this.graph.cellRenderer.redraw(state, false, this.isRendering());
  4666. }
  4667. state = mxGraphViewValidateCellState.apply(this, arguments);
  4668. // Adds to the list of edges that may intersect with later edges
  4669. if (state != null && recurse && this.graph.model.isEdge(state.cell) &&
  4670. state.style != null && state.style[mxConstants.STYLE_CURVED] != 1)
  4671. {
  4672. // LATER: Reuse jumps for valid edges
  4673. this.validEdges.push(state);
  4674. }
  4675. return state;
  4676. };
  4677. /**
  4678. * Forces repaint if routed points have changed.
  4679. */
  4680. var mxCellRendererIsShapeInvalid = mxCellRenderer.prototype.isShapeInvalid;
  4681. mxCellRenderer.prototype.isShapeInvalid = function(state, shape)
  4682. {
  4683. return mxCellRendererIsShapeInvalid.apply(this, arguments) ||
  4684. (state.routedPoints != null && shape.routedPoints != null &&
  4685. !mxUtils.equalPoints(shape.routedPoints, state.routedPoints))
  4686. };
  4687. /**
  4688. * Updates jumps for invalid edges.
  4689. */
  4690. var mxGraphViewUpdateCellState = mxGraphView.prototype.updateCellState;
  4691. mxGraphView.prototype.updateCellState = function(state)
  4692. {
  4693. mxGraphViewUpdateCellState.apply(this, arguments);
  4694. // Updates jumps on invalid edge before repaint
  4695. if (this.graph.model.isEdge(state.cell) &&
  4696. state.style[mxConstants.STYLE_CURVED] != 1)
  4697. {
  4698. this.updateLineJumps(state);
  4699. }
  4700. };
  4701. /**
  4702. * Updates the jumps between given state and processed edges.
  4703. */
  4704. mxGraphView.prototype.updateLineJumps = function(state)
  4705. {
  4706. var pts = state.absolutePoints;
  4707. if (Graph.lineJumpsEnabled)
  4708. {
  4709. var changed = state.routedPoints != null;
  4710. var actual = null;
  4711. if (pts != null && this.validEdges != null &&
  4712. mxUtils.getValue(state.style, 'jumpStyle', 'none') !== 'none')
  4713. {
  4714. var thresh = 0.5 * this.scale;
  4715. changed = false;
  4716. actual = [];
  4717. // Type 0 means normal waypoint, 1 means jump
  4718. function addPoint(type, x, y)
  4719. {
  4720. var rpt = new mxPoint(x, y);
  4721. rpt.type = type;
  4722. actual.push(rpt);
  4723. var curr = (state.routedPoints != null) ? state.routedPoints[actual.length - 1] : null;
  4724. return curr == null || curr.type != type || curr.x != x || curr.y != y;
  4725. };
  4726. for (var i = 0; i < pts.length - 1; i++)
  4727. {
  4728. var p1 = pts[i + 1];
  4729. var p0 = pts[i];
  4730. var list = [];
  4731. // Ignores waypoints on straight segments
  4732. var pn = pts[i + 2];
  4733. while (i < pts.length - 2 &&
  4734. mxUtils.ptSegDistSq(p0.x, p0.y, pn.x, pn.y,
  4735. p1.x, p1.y) < 1 * this.scale * this.scale)
  4736. {
  4737. p1 = pn;
  4738. i++;
  4739. pn = pts[i + 2];
  4740. }
  4741. changed = addPoint(0, p0.x, p0.y) || changed;
  4742. // Processes all previous edges
  4743. for (var e = 0; e < this.validEdges.length; e++)
  4744. {
  4745. var state2 = this.validEdges[e];
  4746. var pts2 = state2.absolutePoints;
  4747. if (pts2 != null && mxUtils.intersects(state, state2) && state2.style['noJump'] != '1')
  4748. {
  4749. // Compares each segment of the edge with the current segment
  4750. for (var j = 0; j < pts2.length - 1; j++)
  4751. {
  4752. var p3 = pts2[j + 1];
  4753. var p2 = pts2[j];
  4754. // Ignores waypoints on straight segments
  4755. pn = pts2[j + 2];
  4756. while (j < pts2.length - 2 &&
  4757. mxUtils.ptSegDistSq(p2.x, p2.y, pn.x, pn.y,
  4758. p3.x, p3.y) < 1 * this.scale * this.scale)
  4759. {
  4760. p3 = pn;
  4761. j++;
  4762. pn = pts2[j + 2];
  4763. }
  4764. var pt = mxUtils.intersection(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
  4765. // Handles intersection between two segments
  4766. if (pt != null && (Math.abs(pt.x - p0.x) > thresh ||
  4767. Math.abs(pt.y - p0.y) > thresh) &&
  4768. (Math.abs(pt.x - p1.x) > thresh ||
  4769. Math.abs(pt.y - p1.y) > thresh) &&
  4770. (Math.abs(pt.x - p2.x) > thresh ||
  4771. Math.abs(pt.y - p2.y) > thresh) &&
  4772. (Math.abs(pt.x - p3.x) > thresh ||
  4773. Math.abs(pt.y - p3.y) > thresh))
  4774. {
  4775. var dx = pt.x - p0.x;
  4776. var dy = pt.y - p0.y;
  4777. var temp = {distSq: dx * dx + dy * dy, x: pt.x, y: pt.y};
  4778. // Intersections must be ordered by distance from start of segment
  4779. for (var t = 0; t < list.length; t++)
  4780. {
  4781. if (list[t].distSq > temp.distSq)
  4782. {
  4783. list.splice(t, 0, temp);
  4784. temp = null;
  4785. break;
  4786. }
  4787. }
  4788. // Ignores multiple intersections at segment joint
  4789. if (temp != null && (list.length == 0 ||
  4790. list[list.length - 1].x !== temp.x ||
  4791. list[list.length - 1].y !== temp.y))
  4792. {
  4793. list.push(temp);
  4794. }
  4795. }
  4796. }
  4797. }
  4798. }
  4799. // Adds ordered intersections to routed points
  4800. for (var j = 0; j < list.length; j++)
  4801. {
  4802. changed = addPoint(1, list[j].x, list[j].y) || changed;
  4803. }
  4804. }
  4805. var pt = pts[pts.length - 1];
  4806. changed = addPoint(0, pt.x, pt.y) || changed;
  4807. }
  4808. state.routedPoints = actual;
  4809. return changed;
  4810. }
  4811. else
  4812. {
  4813. return false;
  4814. }
  4815. };
  4816. /**
  4817. * Overrides painting the actual shape for taking into account jump style.
  4818. */
  4819. var mxConnectorPaintLine = mxConnector.prototype.paintLine;
  4820. mxConnector.prototype.paintLine = function (c, absPts, rounded)
  4821. {
  4822. // Required for checking dirty state
  4823. this.routedPoints = (this.state != null) ? this.state.routedPoints : null;
  4824. if (this.outline || this.state == null || this.style == null ||
  4825. this.state.routedPoints == null || this.state.routedPoints.length == 0)
  4826. {
  4827. mxConnectorPaintLine.apply(this, arguments);
  4828. }
  4829. else
  4830. {
  4831. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  4832. mxConstants.LINE_ARCSIZE) / 2;
  4833. var size = (parseInt(mxUtils.getValue(this.style, 'jumpSize',
  4834. Graph.defaultJumpSize)) - 2) / 2 + this.strokewidth;
  4835. var style = mxUtils.getValue(this.style, 'jumpStyle', 'none');
  4836. var moveTo = true;
  4837. var last = null;
  4838. var len = null;
  4839. var pts = [];
  4840. var n = null;
  4841. c.begin();
  4842. for (var i = 0; i < this.state.routedPoints.length; i++)
  4843. {
  4844. var rpt = this.state.routedPoints[i];
  4845. var pt = new mxPoint(rpt.x / this.scale, rpt.y / this.scale);
  4846. // Takes first and last point from passed-in array
  4847. if (i == 0)
  4848. {
  4849. pt = absPts[0];
  4850. }
  4851. else if (i == this.state.routedPoints.length - 1)
  4852. {
  4853. pt = absPts[absPts.length - 1];
  4854. }
  4855. var done = false;
  4856. // Type 1 is an intersection
  4857. if (last != null && rpt.type == 1)
  4858. {
  4859. // Checks if next/previous points are too close
  4860. var next = this.state.routedPoints[i + 1];
  4861. var dx = next.x / this.scale - pt.x;
  4862. var dy = next.y / this.scale - pt.y;
  4863. var dist = dx * dx + dy * dy;
  4864. if (n == null)
  4865. {
  4866. n = new mxPoint(pt.x - last.x, pt.y - last.y);
  4867. len = Math.sqrt(n.x * n.x + n.y * n.y);
  4868. if (len > 0)
  4869. {
  4870. n.x = n.x * size / len;
  4871. n.y = n.y * size / len;
  4872. }
  4873. else
  4874. {
  4875. n = null;
  4876. }
  4877. }
  4878. if (dist > size * size && len > 0)
  4879. {
  4880. var dx = last.x - pt.x;
  4881. var dy = last.y - pt.y;
  4882. var dist = dx * dx + dy * dy;
  4883. if (dist > size * size)
  4884. {
  4885. var p0 = new mxPoint(pt.x - n.x, pt.y - n.y);
  4886. var p1 = new mxPoint(pt.x + n.x, pt.y + n.y);
  4887. pts.push(p0);
  4888. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  4889. var f = (Math.round(n.x) < 0 || (Math.round(n.x) == 0
  4890. && Math.round(n.y) <= 0)) ? 1 : -1;
  4891. moveTo = false;
  4892. if (style == 'sharp')
  4893. {
  4894. c.lineTo(p0.x - n.y * f, p0.y + n.x * f);
  4895. c.lineTo(p1.x - n.y * f, p1.y + n.x * f);
  4896. c.lineTo(p1.x, p1.y);
  4897. }
  4898. else if (style == 'arc')
  4899. {
  4900. f *= 1.3;
  4901. c.curveTo(p0.x - n.y * f, p0.y + n.x * f,
  4902. p1.x - n.y * f, p1.y + n.x * f,
  4903. p1.x, p1.y);
  4904. }
  4905. else
  4906. {
  4907. c.moveTo(p1.x, p1.y);
  4908. moveTo = true;
  4909. }
  4910. pts = [p1];
  4911. done = true;
  4912. }
  4913. }
  4914. }
  4915. else
  4916. {
  4917. n = null;
  4918. }
  4919. if (!done)
  4920. {
  4921. pts.push(pt);
  4922. last = pt;
  4923. }
  4924. }
  4925. this.addPoints(c, pts, rounded, arcSize, false, null, moveTo);
  4926. c.stroke();
  4927. }
  4928. };
  4929. /**
  4930. * Adds support for snapToPoint style.
  4931. */
  4932. var mxGraphViewUpdateFloatingTerminalPoint = mxGraphView.prototype.updateFloatingTerminalPoint;
  4933. mxGraphView.prototype.updateFloatingTerminalPoint = function(edge, start, end, source)
  4934. {
  4935. if (start != null && edge != null &&
  4936. (start.style['snapToPoint'] == '1' ||
  4937. edge.style['snapToPoint'] == '1'))
  4938. {
  4939. start = this.getTerminalPort(edge, start, source);
  4940. var next = this.getNextPoint(edge, end, source);
  4941. var orth = this.graph.isOrthogonal(edge);
  4942. var alpha = mxUtils.toRadians(Number(start.style[mxConstants.STYLE_ROTATION] || '0'));
  4943. var center = new mxPoint(start.getCenterX(), start.getCenterY());
  4944. if (alpha != 0)
  4945. {
  4946. var cos = Math.cos(-alpha);
  4947. var sin = Math.sin(-alpha);
  4948. next = mxUtils.getRotatedPoint(next, cos, sin, center);
  4949. }
  4950. var border = parseFloat(edge.style[mxConstants.STYLE_PERIMETER_SPACING] || 0);
  4951. border += parseFloat(edge.style[(source) ?
  4952. mxConstants.STYLE_SOURCE_PERIMETER_SPACING :
  4953. mxConstants.STYLE_TARGET_PERIMETER_SPACING] || 0);
  4954. var pt = this.getPerimeterPoint(start, next, alpha == 0 && orth, border);
  4955. if (alpha != 0)
  4956. {
  4957. var cos = Math.cos(alpha);
  4958. var sin = Math.sin(alpha);
  4959. pt = mxUtils.getRotatedPoint(pt, cos, sin, center);
  4960. }
  4961. edge.setAbsoluteTerminalPoint(this.snapToAnchorPoint(edge, start, end, source, pt), source);
  4962. }
  4963. else
  4964. {
  4965. mxGraphViewUpdateFloatingTerminalPoint.apply(this, arguments);
  4966. }
  4967. };
  4968. mxGraphView.prototype.snapToAnchorPoint = function(edge, start, end, source, pt)
  4969. {
  4970. if (start != null && edge != null)
  4971. {
  4972. var constraints = this.graph.getAllConnectionConstraints(start)
  4973. var nearest = null;
  4974. var dist = null;
  4975. if (constraints != null)
  4976. {
  4977. for (var i = 0; i < constraints.length; i++)
  4978. {
  4979. var cp = this.graph.getConnectionPoint(start, constraints[i]);
  4980. if (cp != null)
  4981. {
  4982. var tmp = (cp.x - pt.x) * (cp.x - pt.x) + (cp.y - pt.y) * (cp.y - pt.y);
  4983. if (dist == null || tmp < dist)
  4984. {
  4985. nearest = cp;
  4986. dist = tmp;
  4987. }
  4988. }
  4989. }
  4990. }
  4991. if (nearest != null)
  4992. {
  4993. pt = nearest;
  4994. }
  4995. }
  4996. return pt;
  4997. };
  4998. /**
  4999. * Adds support for placeholders in text elements of shapes.
  5000. */
  5001. var mxStencilEvaluateTextAttribute = mxStencil.prototype.evaluateTextAttribute;
  5002. mxStencil.prototype.evaluateTextAttribute = function(node, attribute, shape)
  5003. {
  5004. var result = mxStencilEvaluateTextAttribute.apply(this, arguments);
  5005. var placeholders = node.getAttribute('placeholders');
  5006. if (placeholders == '1' && shape.state != null)
  5007. {
  5008. result = shape.state.view.graph.replacePlaceholders(shape.state.cell, result);
  5009. }
  5010. return result;
  5011. };
  5012. /**
  5013. * Adds custom stencils defined via shape=stencil(value) style. The value is a base64 encoded, compressed and
  5014. * URL encoded XML definition of the shape according to the stencil definition language of mxGraph.
  5015. *
  5016. * Needs to be in this file to make sure its part of the embed client code. Also the check for ZLib is
  5017. * different than for the Editor code.
  5018. */
  5019. var mxCellRendererCreateShape = mxCellRenderer.prototype.createShape;
  5020. mxCellRenderer.prototype.createShape = function(state)
  5021. {
  5022. if (state.style != null && typeof(pako) !== 'undefined')
  5023. {
  5024. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  5025. // Extracts and decodes stencil XML if shape has the form shape=stencil(value)
  5026. if (shape != null && typeof shape === 'string' && shape.substring(0, 8) == 'stencil(')
  5027. {
  5028. try
  5029. {
  5030. var stencil = shape.substring(8, shape.length - 1);
  5031. var doc = mxUtils.parseXml(Graph.decompress(stencil));
  5032. return new mxShape(new mxStencil(doc.documentElement));
  5033. }
  5034. catch (e)
  5035. {
  5036. if (window.console != null)
  5037. {
  5038. console.log('Error in shape: ' + e);
  5039. }
  5040. }
  5041. }
  5042. }
  5043. return mxCellRendererCreateShape.apply(this, arguments);
  5044. };
  5045. })();
  5046. /**
  5047. * Overrides stencil registry for dynamic loading of stencils.
  5048. */
  5049. /**
  5050. * Maps from library names to an array of Javascript filenames,
  5051. * which are synchronously loaded. Currently only stencil files
  5052. * (.xml) and JS files (.js) are supported.
  5053. * IMPORTANT: For embedded diagrams to work entries must also
  5054. * be added in EmbedServlet.java.
  5055. */
  5056. mxStencilRegistry.libraries = {};
  5057. /**
  5058. * Global switch to disable dynamic loading.
  5059. */
  5060. mxStencilRegistry.dynamicLoading = true;
  5061. /**
  5062. * Global switch to disable eval for JS (preload all JS instead).
  5063. */
  5064. mxStencilRegistry.allowEval = true;
  5065. /**
  5066. * Stores all package names that have been dynamically loaded.
  5067. * Each package is only loaded once.
  5068. */
  5069. mxStencilRegistry.packages = [];
  5070. // Extends the default stencil registry to add dynamic loading
  5071. mxStencilRegistry.getStencil = function(name)
  5072. {
  5073. var result = mxStencilRegistry.stencils[name];
  5074. if (result == null && mxCellRenderer.defaultShapes[name] == null && mxStencilRegistry.dynamicLoading)
  5075. {
  5076. var basename = mxStencilRegistry.getBasenameForStencil(name);
  5077. // Loads stencil files and tries again
  5078. if (basename != null)
  5079. {
  5080. var libs = mxStencilRegistry.libraries[basename];
  5081. if (libs != null)
  5082. {
  5083. if (mxStencilRegistry.packages[basename] == null)
  5084. {
  5085. for (var i = 0; i < libs.length; i++)
  5086. {
  5087. var fname = libs[i];
  5088. if (fname.toLowerCase().substring(fname.length - 4, fname.length) == '.xml')
  5089. {
  5090. mxStencilRegistry.loadStencilSet(fname, null);
  5091. }
  5092. else if (fname.toLowerCase().substring(fname.length - 3, fname.length) == '.js')
  5093. {
  5094. try
  5095. {
  5096. if (mxStencilRegistry.allowEval)
  5097. {
  5098. var req = mxUtils.load(fname);
  5099. if (req != null && req.getStatus() >= 200 && req.getStatus() <= 299)
  5100. {
  5101. eval.call(window, req.getText());
  5102. }
  5103. }
  5104. }
  5105. catch (e)
  5106. {
  5107. if (window.console != null)
  5108. {
  5109. console.log('error in getStencil:', fname, e);
  5110. }
  5111. }
  5112. }
  5113. else
  5114. {
  5115. // FIXME: This does not yet work as the loading is triggered after
  5116. // the shape was used in the graph, at which point the keys have
  5117. // typically been translated in the calling method.
  5118. //mxResources.add(fname);
  5119. }
  5120. }
  5121. mxStencilRegistry.packages[basename] = 1;
  5122. }
  5123. }
  5124. else
  5125. {
  5126. // Replaces '_-_' with '_'
  5127. basename = basename.replace('_-_', '_');
  5128. mxStencilRegistry.loadStencilSet(STENCIL_PATH + '/' + basename + '.xml', null);
  5129. }
  5130. result = mxStencilRegistry.stencils[name];
  5131. }
  5132. }
  5133. return result;
  5134. };
  5135. // Returns the basename for the given stencil or null if no file must be
  5136. // loaded to render the given stencil.
  5137. mxStencilRegistry.getBasenameForStencil = function(name)
  5138. {
  5139. var tmp = null;
  5140. if (name != null && typeof name === 'string')
  5141. {
  5142. var parts = name.split('.');
  5143. if (parts.length > 0 && parts[0] == 'mxgraph')
  5144. {
  5145. tmp = parts[1];
  5146. for (var i = 2; i < parts.length - 1; i++)
  5147. {
  5148. tmp += '/' + parts[i];
  5149. }
  5150. }
  5151. }
  5152. return tmp;
  5153. };
  5154. // Loads the given stencil set
  5155. mxStencilRegistry.loadStencilSet = function(stencilFile, postStencilLoad, force, async)
  5156. {
  5157. force = (force != null) ? force : false;
  5158. // Uses additional cache for detecting previous load attempts
  5159. var xmlDoc = mxStencilRegistry.packages[stencilFile];
  5160. if (force || xmlDoc == null)
  5161. {
  5162. var install = false;
  5163. if (xmlDoc == null)
  5164. {
  5165. try
  5166. {
  5167. if (async)
  5168. {
  5169. mxStencilRegistry.loadStencil(stencilFile, mxUtils.bind(this, function(xmlDoc2)
  5170. {
  5171. if (xmlDoc2 != null && xmlDoc2.documentElement != null)
  5172. {
  5173. mxStencilRegistry.packages[stencilFile] = xmlDoc2;
  5174. install = true;
  5175. mxStencilRegistry.parseStencilSet(xmlDoc2.documentElement, postStencilLoad, install);
  5176. }
  5177. }));
  5178. return;
  5179. }
  5180. else
  5181. {
  5182. xmlDoc = mxStencilRegistry.loadStencil(stencilFile);
  5183. mxStencilRegistry.packages[stencilFile] = xmlDoc;
  5184. install = true;
  5185. }
  5186. }
  5187. catch (e)
  5188. {
  5189. if (window.console != null)
  5190. {
  5191. console.log('error in loadStencilSet:', stencilFile, e);
  5192. }
  5193. }
  5194. }
  5195. if (xmlDoc != null && xmlDoc.documentElement != null)
  5196. {
  5197. mxStencilRegistry.parseStencilSet(xmlDoc.documentElement, postStencilLoad, install);
  5198. }
  5199. }
  5200. };
  5201. // Loads the given stencil XML file.
  5202. mxStencilRegistry.loadStencil = function(filename, fn)
  5203. {
  5204. if (fn != null)
  5205. {
  5206. var req = mxUtils.get(filename, mxUtils.bind(this, function(req)
  5207. {
  5208. fn((req.getStatus() >= 200 && req.getStatus() <= 299) ? req.getXml() : null);
  5209. }));
  5210. }
  5211. else
  5212. {
  5213. return mxUtils.load(filename).getXml();
  5214. }
  5215. };
  5216. // Takes array of strings
  5217. mxStencilRegistry.parseStencilSets = function(stencils)
  5218. {
  5219. for (var i = 0; i < stencils.length; i++)
  5220. {
  5221. mxStencilRegistry.parseStencilSet(mxUtils.parseXml(stencils[i]).documentElement);
  5222. }
  5223. };
  5224. // Parses the given stencil set
  5225. mxStencilRegistry.parseStencilSet = function(root, postStencilLoad, install)
  5226. {
  5227. if (root.nodeName == 'stencils')
  5228. {
  5229. var shapes = root.firstChild;
  5230. while (shapes != null)
  5231. {
  5232. if (shapes.nodeName == 'shapes')
  5233. {
  5234. mxStencilRegistry.parseStencilSet(shapes, postStencilLoad, install);
  5235. }
  5236. shapes = shapes.nextSibling;
  5237. }
  5238. }
  5239. else
  5240. {
  5241. install = (install != null) ? install : true;
  5242. var shape = root.firstChild;
  5243. var packageName = '';
  5244. var name = root.getAttribute('name');
  5245. if (name != null)
  5246. {
  5247. packageName = name + '.';
  5248. }
  5249. while (shape != null)
  5250. {
  5251. if (shape.nodeType == mxConstants.NODETYPE_ELEMENT)
  5252. {
  5253. name = shape.getAttribute('name');
  5254. if (name != null)
  5255. {
  5256. packageName = packageName.toLowerCase();
  5257. var stencilName = name.replace(/ /g,"_");
  5258. if (install)
  5259. {
  5260. mxStencilRegistry.addStencil(packageName + stencilName.toLowerCase(), new mxStencil(shape));
  5261. }
  5262. if (postStencilLoad != null)
  5263. {
  5264. var w = shape.getAttribute('w');
  5265. var h = shape.getAttribute('h');
  5266. w = (w == null) ? 80 : parseInt(w, 10);
  5267. h = (h == null) ? 80 : parseInt(h, 10);
  5268. postStencilLoad(packageName, stencilName, name, w, h);
  5269. }
  5270. }
  5271. }
  5272. shape = shape.nextSibling;
  5273. }
  5274. }
  5275. };
  5276. /**
  5277. * These overrides are only added if mxVertexHandler is defined (ie. not in embedded graph)
  5278. */
  5279. if (typeof mxVertexHandler != 'undefined')
  5280. {
  5281. (function()
  5282. {
  5283. // Sets colors for handles
  5284. mxConstants.HANDLE_FILLCOLOR = '#29b6f2';
  5285. mxConstants.HANDLE_STROKECOLOR = '#0088cf';
  5286. mxConstants.VERTEX_SELECTION_COLOR = '#00a8ff';
  5287. mxConstants.OUTLINE_COLOR = '#00a8ff';
  5288. mxConstants.OUTLINE_HANDLE_FILLCOLOR = '#99ccff';
  5289. mxConstants.OUTLINE_HANDLE_STROKECOLOR = '#00a8ff';
  5290. mxConstants.CONNECT_HANDLE_FILLCOLOR = '#cee7ff';
  5291. mxConstants.EDGE_SELECTION_COLOR = '#00a8ff';
  5292. mxConstants.DEFAULT_VALID_COLOR = '#00a8ff';
  5293. mxConstants.LABEL_HANDLE_FILLCOLOR = '#cee7ff';
  5294. mxConstants.GUIDE_COLOR = '#0088cf';
  5295. mxConstants.HIGHLIGHT_OPACITY = 30;
  5296. mxConstants.HIGHLIGHT_SIZE = 5;
  5297. // Enables snapping to off-grid terminals for edge waypoints
  5298. mxEdgeHandler.prototype.snapToTerminals = true;
  5299. // Enables guides
  5300. mxGraphHandler.prototype.guidesEnabled = true;
  5301. // Removes parents where all child cells are moved out
  5302. mxGraphHandler.prototype.removeEmptyParents = true;
  5303. // Enables fading of rubberband
  5304. mxRubberband.prototype.fadeOut = true;
  5305. // Alt-move disables guides
  5306. mxGuide.prototype.isEnabledForEvent = function(evt)
  5307. {
  5308. return !mxEvent.isAltDown(evt);
  5309. };
  5310. // Ignores all table cells in layouts
  5311. var graphLayoutIsVertexIgnored = mxGraphLayout.prototype.isVertexIgnored;
  5312. mxGraphLayout.prototype.isVertexIgnored = function(vertex)
  5313. {
  5314. return graphLayoutIsVertexIgnored.apply(this, arguments) ||
  5315. this.graph.isTableRow(vertex) || this.graph.isTableCell(vertex);
  5316. };
  5317. // Extends connection handler to enable ctrl+drag for cloning source cell
  5318. // since copyOnConnect is now disabled by default
  5319. var mxConnectionHandlerCreateTarget = mxConnectionHandler.prototype.isCreateTarget;
  5320. mxConnectionHandler.prototype.isCreateTarget = function(evt)
  5321. {
  5322. return this.graph.isCloneEvent(evt) || mxConnectionHandlerCreateTarget.apply(this, arguments);
  5323. };
  5324. // Overrides highlight shape for connection points
  5325. mxConstraintHandler.prototype.createHighlightShape = function()
  5326. {
  5327. var hl = new mxEllipse(null, this.highlightColor, this.highlightColor, 0);
  5328. hl.opacity = mxConstants.HIGHLIGHT_OPACITY;
  5329. return hl;
  5330. };
  5331. // Overrides edge preview to use current edge shape and default style
  5332. mxConnectionHandler.prototype.livePreview = true;
  5333. mxConnectionHandler.prototype.cursor = 'crosshair';
  5334. // Uses current edge style for connect preview
  5335. mxConnectionHandler.prototype.createEdgeState = function(me)
  5336. {
  5337. var style = this.graph.createCurrentEdgeStyle();
  5338. var edge = this.graph.createEdge(null, null, null, null, null, style);
  5339. var state = new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  5340. for (var key in this.graph.currentEdgeStyle)
  5341. {
  5342. state.style[key] = this.graph.currentEdgeStyle[key];
  5343. }
  5344. return state;
  5345. };
  5346. // Overrides dashed state with current edge style
  5347. var connectionHandlerCreateShape = mxConnectionHandler.prototype.createShape;
  5348. mxConnectionHandler.prototype.createShape = function()
  5349. {
  5350. var shape = connectionHandlerCreateShape.apply(this, arguments);
  5351. shape.isDashed = this.graph.currentEdgeStyle[mxConstants.STYLE_DASHED] == '1';
  5352. return shape;
  5353. }
  5354. // Overrides live preview to keep current style
  5355. mxConnectionHandler.prototype.updatePreview = function(valid)
  5356. {
  5357. // do not change color of preview
  5358. };
  5359. // Overrides connection handler to ignore edges instead of not allowing connections
  5360. var mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
  5361. mxConnectionHandler.prototype.createMarker = function()
  5362. {
  5363. var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);
  5364. var markerGetCell = marker.getCell;
  5365. marker.getCell = mxUtils.bind(this, function(me)
  5366. {
  5367. var result = markerGetCell.apply(this, arguments);
  5368. this.error = null;
  5369. return result;
  5370. });
  5371. return marker;
  5372. };
  5373. /**
  5374. *
  5375. */
  5376. Graph.prototype.defaultVertexStyle = {};
  5377. /**
  5378. * Contains the default style for edges.
  5379. */
  5380. Graph.prototype.defaultEdgeStyle = {'edgeStyle': 'orthogonalEdgeStyle', 'rounded': '0',
  5381. 'jettySize': 'auto', 'orthogonalLoop': '1'};
  5382. /**
  5383. * Returns the current edge style as a string.
  5384. */
  5385. Graph.prototype.createCurrentEdgeStyle = function()
  5386. {
  5387. var style = 'edgeStyle=' + (this.currentEdgeStyle['edgeStyle'] || 'none') + ';';
  5388. var keys = ['shape', 'curved', 'rounded', 'comic', 'sketch', 'fillWeight', 'hachureGap',
  5389. 'hachureAngle', 'jiggle', 'disableMultiStroke', 'disableMultiStrokeFill', 'fillStyle',
  5390. 'curveFitting', 'simplification', 'comicStyle', 'jumpStyle', 'jumpSize'];
  5391. for (var i = 0; i < keys.length; i++)
  5392. {
  5393. if (this.currentEdgeStyle[keys[i]] != null)
  5394. {
  5395. style += keys[i] + '=' + this.currentEdgeStyle[keys[i]] + ';';
  5396. }
  5397. }
  5398. // Overrides the global default to match the default edge style
  5399. if (this.currentEdgeStyle['orthogonalLoop'] != null)
  5400. {
  5401. style += 'orthogonalLoop=' + this.currentEdgeStyle['orthogonalLoop'] + ';';
  5402. }
  5403. else if (Graph.prototype.defaultEdgeStyle['orthogonalLoop'] != null)
  5404. {
  5405. style += 'orthogonalLoop=' + Graph.prototype.defaultEdgeStyle['orthogonalLoop'] + ';';
  5406. }
  5407. // Overrides the global default to match the default edge style
  5408. if (this.currentEdgeStyle['jettySize'] != null)
  5409. {
  5410. style += 'jettySize=' + this.currentEdgeStyle['jettySize'] + ';';
  5411. }
  5412. else if (Graph.prototype.defaultEdgeStyle['jettySize'] != null)
  5413. {
  5414. style += 'jettySize=' + Graph.prototype.defaultEdgeStyle['jettySize'] + ';';
  5415. }
  5416. // Special logic for custom property of elbowEdgeStyle
  5417. if (this.currentEdgeStyle['edgeStyle'] == 'elbowEdgeStyle' && this.currentEdgeStyle['elbow'] != null)
  5418. {
  5419. style += 'elbow=' + this.currentEdgeStyle['elbow'] + ';';
  5420. }
  5421. if (this.currentEdgeStyle['html'] != null)
  5422. {
  5423. style += 'html=' + this.currentEdgeStyle['html'] + ';';
  5424. }
  5425. else
  5426. {
  5427. style += 'html=1;';
  5428. }
  5429. return style;
  5430. };
  5431. /**
  5432. * Removes implicit styles from cell styles so that dark mode works using the
  5433. * default values from the stylesheet.
  5434. */
  5435. Graph.prototype.updateCellStyles = function(key, value, cells)
  5436. {
  5437. this.model.beginUpdate();
  5438. try
  5439. {
  5440. for (var i = 0; i < cells.length; i++)
  5441. {
  5442. if (this.model.isVertex(cells[i]) || this.model.isEdge(cells[i]))
  5443. {
  5444. this.setCellStyles(key, null, [cells[i]]);
  5445. var style = this.getCellStyle(cells[i]);
  5446. var temp = style[key];
  5447. if (value != ((temp == null) ? mxConstants.NONE : temp))
  5448. {
  5449. this.setCellStyles(key, value, [cells[i]]);
  5450. }
  5451. }
  5452. }
  5453. }
  5454. finally
  5455. {
  5456. this.model.endUpdate();
  5457. }
  5458. };
  5459. /**
  5460. * Hook for subclassers.
  5461. */
  5462. Graph.prototype.getPagePadding = function()
  5463. {
  5464. return new mxPoint(0, 0);
  5465. };
  5466. /**
  5467. * Loads the stylesheet for this graph.
  5468. */
  5469. Graph.prototype.loadStylesheet = function()
  5470. {
  5471. var node = (this.themes != null) ? this.themes[this.defaultThemeName] :
  5472. (!mxStyleRegistry.dynamicLoading) ? null :
  5473. mxUtils.load(STYLE_PATH + '/default.xml').getDocumentElement();
  5474. if (node != null)
  5475. {
  5476. var dec = new mxCodec(node.ownerDocument);
  5477. dec.decode(node, this.getStylesheet());
  5478. }
  5479. };
  5480. /**
  5481. * Creates lookup from object IDs to cell IDs.
  5482. */
  5483. Graph.prototype.createCellLookup = function(cells, lookup)
  5484. {
  5485. lookup = (lookup != null) ? lookup : new Object();
  5486. for (var i = 0; i < cells.length; i++)
  5487. {
  5488. var cell = cells[i];
  5489. lookup[mxObjectIdentity.get(cell)] = cell.getId();
  5490. var childCount = this.model.getChildCount(cell);
  5491. for (var j = 0; j < childCount; j++)
  5492. {
  5493. this.createCellLookup([this.model.getChildAt(cell, j)], lookup);
  5494. }
  5495. }
  5496. return lookup;
  5497. };
  5498. /**
  5499. * Creates lookup from original to cloned cell IDs where mapping is
  5500. * the mapping used in cloneCells and lookup is a mapping from
  5501. * object IDs to cell IDs.
  5502. */
  5503. Graph.prototype.createCellMapping = function(mapping, lookup, cellMapping)
  5504. {
  5505. cellMapping = (cellMapping != null) ? cellMapping : new Object();
  5506. for (var objectId in mapping)
  5507. {
  5508. var cellId = lookup[objectId];
  5509. if (cellMapping[cellId] == null)
  5510. {
  5511. // Uses empty string if clone ID was null which means
  5512. // the cell was cloned but not inserted into the model.
  5513. cellMapping[cellId] = mapping[objectId].getId() || '';
  5514. }
  5515. }
  5516. return cellMapping;
  5517. };
  5518. /**
  5519. *
  5520. */
  5521. Graph.prototype.importGraphModel = function(node, dx, dy, crop)
  5522. {
  5523. dx = (dx != null) ? dx : 0;
  5524. dy = (dy != null) ? dy : 0;
  5525. var codec = new mxCodec(node.ownerDocument);
  5526. var tempModel = new mxGraphModel();
  5527. codec.decode(node, tempModel);
  5528. var cells = []
  5529. // Clones cells to remove invalid edges
  5530. var cloneMap = new Object();
  5531. var cellMapping = new Object();
  5532. var layers = tempModel.getChildren(this.cloneCell(tempModel.root,
  5533. this.isCloneInvalidEdges(), cloneMap));
  5534. if (layers != null)
  5535. {
  5536. // Creates lookup from object IDs to cell IDs
  5537. var lookup = this.createCellLookup([tempModel.root]);
  5538. // Uses copy as layers are removed from array inside loop
  5539. layers = layers.slice();
  5540. this.model.beginUpdate();
  5541. try
  5542. {
  5543. // Merges into unlocked current layer if one layer is pasted
  5544. if (layers.length == 1 && !this.isCellLocked(this.getDefaultParent()))
  5545. {
  5546. var children = tempModel.getChildren(layers[0]);
  5547. if (children != null)
  5548. {
  5549. cells = this.moveCells(children,
  5550. dx, dy, false, this.getDefaultParent());
  5551. // Imported default parent maps to local default parent
  5552. cellMapping[tempModel.getChildAt(tempModel.root, 0).getId()] =
  5553. this.getDefaultParent().getId();
  5554. }
  5555. }
  5556. else
  5557. {
  5558. for (var i = 0; i < layers.length; i++)
  5559. {
  5560. var children = this.model.getChildren(this.moveCells(
  5561. [layers[i]], dx, dy, false, this.model.getRoot())[0]);
  5562. if (children != null)
  5563. {
  5564. cells = cells.concat(children);
  5565. }
  5566. }
  5567. }
  5568. if (cells != null)
  5569. {
  5570. // Adds mapping for all cloned entries from imported to local cell ID
  5571. this.createCellMapping(cloneMap, lookup, cellMapping);
  5572. this.updateCustomLinks(cellMapping, cells);
  5573. if (crop)
  5574. {
  5575. if (this.isGridEnabled())
  5576. {
  5577. dx = this.snap(dx);
  5578. dy = this.snap(dy);
  5579. }
  5580. var bounds = this.getBoundingBoxFromGeometry(cells, true);
  5581. if (bounds != null)
  5582. {
  5583. this.moveCells(cells, dx - bounds.x, dy - bounds.y);
  5584. }
  5585. }
  5586. }
  5587. }
  5588. finally
  5589. {
  5590. this.model.endUpdate();
  5591. }
  5592. }
  5593. return cells;
  5594. };
  5595. /**
  5596. * Translates this point by the given vector.
  5597. *
  5598. * @param {number} dx X-coordinate of the translation.
  5599. * @param {number} dy Y-coordinate of the translation.
  5600. */
  5601. Graph.prototype.encodeCells = function(cells)
  5602. {
  5603. var cloneMap = new Object();
  5604. var clones = this.cloneCells(cells, null, cloneMap);
  5605. // Creates a dictionary for fast lookups
  5606. var dict = new mxDictionary();
  5607. for (var i = 0; i < cells.length; i++)
  5608. {
  5609. dict.put(cells[i], true);
  5610. }
  5611. var codec = new mxCodec();
  5612. var model = new mxGraphModel();
  5613. var parent = model.getChildAt(model.getRoot(), 0);
  5614. for (var i = 0; i < clones.length; i++)
  5615. {
  5616. model.add(parent, clones[i]);
  5617. // Checks for orphaned relative children and makes absolute
  5618. var state = this.view.getState(cells[i]);
  5619. if (state != null)
  5620. {
  5621. var geo = this.getCellGeometry(clones[i]);
  5622. if (geo != null && geo.relative && !this.model.isEdge(cells[i]) &&
  5623. dict.get(this.model.getParent(cells[i])) == null)
  5624. {
  5625. geo.offset = null;
  5626. geo.relative = false;
  5627. geo.x = state.x / state.view.scale - state.view.translate.x;
  5628. geo.y = state.y / state.view.scale - state.view.translate.y;
  5629. }
  5630. }
  5631. }
  5632. this.updateCustomLinks(this.createCellMapping(cloneMap,
  5633. this.createCellLookup(cells)), clones);
  5634. return codec.encode(model);
  5635. };
  5636. /**
  5637. * Overridden to check for table shape.
  5638. */
  5639. Graph.prototype.isSwimlane = function(cell, ignoreState)
  5640. {
  5641. if (cell != null && this.model.getParent(cell) != this.model.getRoot() &&
  5642. !this.model.isEdge(cell))
  5643. {
  5644. var shape = this.getCurrentCellStyle(cell, ignoreState)
  5645. [mxConstants.STYLE_SHAPE];
  5646. return shape == mxConstants.SHAPE_SWIMLANE || shape == 'table';
  5647. }
  5648. return false;
  5649. };
  5650. /**
  5651. * Overridden to add expand style.
  5652. */
  5653. var graphIsExtendParent = Graph.prototype.isExtendParent;
  5654. Graph.prototype.isExtendParent = function(cell)
  5655. {
  5656. var parent = this.model.getParent(cell);
  5657. if (parent != null)
  5658. {
  5659. var style = this.getCurrentCellStyle(parent);
  5660. if (style['expand'] != null)
  5661. {
  5662. return style['expand'] != '0';
  5663. }
  5664. }
  5665. return graphIsExtendParent.apply(this, arguments) &&
  5666. (parent == null || !this.isTable(parent));
  5667. };
  5668. /**
  5669. * Overridden to use table cell instead of table as parent.
  5670. */
  5671. var graphSplitEdge = Graph.prototype.splitEdge;
  5672. Graph.prototype.splitEdge = function(edge, cells, newEdge, dx, dy, x, y, parent)
  5673. {
  5674. if (parent == null)
  5675. {
  5676. parent = this.model.getParent(edge);
  5677. if (this.isTable(parent) || this.isTableRow(parent))
  5678. {
  5679. parent = this.getCellAt(x, y, null, true, false);
  5680. }
  5681. }
  5682. graphSplitEdge.apply(this, [edge, cells, newEdge, dx, dy, x, y, parent]);
  5683. };
  5684. /**
  5685. * Overridden to flatten cell hierarchy for selecting next and previous.
  5686. */
  5687. var graphSelectCell = Graph.prototype.selectCell;
  5688. Graph.prototype.selectCell = function(isNext, isParent, isChild)
  5689. {
  5690. if (isParent || isChild)
  5691. {
  5692. graphSelectCell.apply(this, arguments);
  5693. }
  5694. else
  5695. {
  5696. var cell = this.getSelectionCell();
  5697. var index = null;
  5698. var cells = [];
  5699. // LATER: Reverse traverse order for !isNext
  5700. var flatten = mxUtils.bind(this, function(temp)
  5701. {
  5702. if (this.view.getState(temp) != null &&
  5703. (this.model.isVertex(temp) ||
  5704. this.model.isEdge(temp)))
  5705. {
  5706. cells.push(temp);
  5707. if (temp == cell)
  5708. {
  5709. index = cells.length - 1;
  5710. }
  5711. else if ((isNext && cell == null && cells.length > 0) ||
  5712. (index != null && ((isNext && cells.length > index)) ||
  5713. (!isNext && index > 0)))
  5714. {
  5715. return;
  5716. }
  5717. }
  5718. for (var i = 0; i < this.model.getChildCount(temp); i++)
  5719. {
  5720. flatten(this.model.getChildAt(temp, i));
  5721. }
  5722. });
  5723. flatten(this.model.root);
  5724. if (cells.length > 0)
  5725. {
  5726. if (index != null)
  5727. {
  5728. index = mxUtils.mod(index + ((isNext) ? 1 : -1), cells.length)
  5729. }
  5730. else
  5731. {
  5732. index = 0;
  5733. }
  5734. this.setSelectionCell(cells[index]);
  5735. }
  5736. }
  5737. };
  5738. /**
  5739. * Overrides cloning cells in moveCells.
  5740. */
  5741. var graphMoveCells = Graph.prototype.moveCells;
  5742. Graph.prototype.moveCells = function(cells, dx, dy, clone, target, evt, mapping)
  5743. {
  5744. mapping = (mapping != null) ? mapping : new Object();
  5745. // Replaces source tables with rows
  5746. if (this.isTable(target))
  5747. {
  5748. var newCells = [];
  5749. for (var i = 0; i < cells.length; i++)
  5750. {
  5751. if (this.isTable(cells[i]))
  5752. {
  5753. newCells = newCells.concat(this.model.getChildCells(cells[i], true).reverse());
  5754. }
  5755. else
  5756. {
  5757. newCells.push(cells[i]);
  5758. }
  5759. }
  5760. cells = newCells;
  5761. }
  5762. this.model.beginUpdate();
  5763. try
  5764. {
  5765. // Updates source and target table heights and matches
  5766. // column count for moving rows between tables
  5767. var sourceTables = [];
  5768. for (var i = 0; i < cells.length; i++)
  5769. {
  5770. if (target != null && this.isTableRow(cells[i]))
  5771. {
  5772. var parent = this.model.getParent(cells[i]);
  5773. var row = this.getCellGeometry(cells[i]);
  5774. if (this.isTable(parent))
  5775. {
  5776. sourceTables.push(parent);
  5777. }
  5778. if (parent != null && row != null &&
  5779. this.isTable(parent) &&
  5780. this.isTable(target) &&
  5781. (clone || parent != target))
  5782. {
  5783. if (!clone)
  5784. {
  5785. var table = this.getCellGeometry(parent);
  5786. if (table != null)
  5787. {
  5788. table = table.clone();
  5789. table.height -= row.height;
  5790. this.model.setGeometry(parent, table);
  5791. }
  5792. }
  5793. var table = this.getCellGeometry(target);
  5794. if (table != null)
  5795. {
  5796. table = table.clone();
  5797. table.height += row.height;
  5798. this.model.setGeometry(target, table);
  5799. }
  5800. // Matches column count
  5801. var rows = this.model.getChildCells(target, true);
  5802. if (rows.length > 0)
  5803. {
  5804. var cell = (clone) ? this.cloneCell(cells[i]) : cells[i];
  5805. var sourceCols = this.model.getChildCells(cell, true);
  5806. var cols = this.model.getChildCells(rows[0], true);
  5807. var count = cols.length - sourceCols.length;
  5808. if (count > 0)
  5809. {
  5810. for (var j = 0; j < count; j++)
  5811. {
  5812. var col = this.cloneCell(sourceCols[sourceCols.length - 1]);
  5813. if (col != null)
  5814. {
  5815. col.value = '';
  5816. this.model.add(cell, col);
  5817. }
  5818. }
  5819. }
  5820. else if (count < 0)
  5821. {
  5822. for (var j = 0; j > count; j--)
  5823. {
  5824. this.model.remove(sourceCols[sourceCols.length + j - 1]);
  5825. }
  5826. }
  5827. // Updates column widths
  5828. sourceCols = this.model.getChildCells(cell, true);
  5829. for (var j = 0; j < cols.length; j++)
  5830. {
  5831. var geo = this.getCellGeometry(cols[j]);
  5832. var geo2 = this.getCellGeometry(sourceCols[j]);
  5833. if (geo != null && geo2 != null)
  5834. {
  5835. geo2 = geo2.clone();
  5836. geo2.width = geo.width;
  5837. this.model.setGeometry(sourceCols[j], geo2);
  5838. }
  5839. }
  5840. }
  5841. }
  5842. }
  5843. }
  5844. var result = graphMoveCells.apply(this, arguments);
  5845. // Removes empty tables
  5846. for (var i = 0; i < sourceTables.length; i++)
  5847. {
  5848. if (!clone && this.model.contains(sourceTables[i]) &&
  5849. this.model.getChildCount(sourceTables[i]) == 0)
  5850. {
  5851. this.model.remove(sourceTables[i]);
  5852. }
  5853. }
  5854. if (clone)
  5855. {
  5856. this.updateCustomLinks(this.createCellMapping(mapping,
  5857. this.createCellLookup(cells)), result);
  5858. }
  5859. }
  5860. finally
  5861. {
  5862. this.model.endUpdate();
  5863. }
  5864. return result;
  5865. };
  5866. /**
  5867. * Overriddes to delete label for table cells.
  5868. */
  5869. var graphRemoveCells = Graph.prototype.removeCells;
  5870. Graph.prototype.removeCells = function(cells, includeEdges)
  5871. {
  5872. var result = [];
  5873. this.model.beginUpdate();
  5874. try
  5875. {
  5876. // Clears labels on table cells
  5877. for (var i = 0; i < cells.length; i++)
  5878. {
  5879. if (this.isTableCell(cells[i]))
  5880. {
  5881. var row = this.model.getParent(cells[i]);
  5882. var table = this.model.getParent(row);
  5883. // Removes table if one cell in one row left
  5884. if (this.model.getChildCount(row) == 1 &&
  5885. this.model.getChildCount(table) == 1)
  5886. {
  5887. if (mxUtils.indexOf(cells, table) < 0 &&
  5888. mxUtils.indexOf(result, table) < 0)
  5889. {
  5890. result.push(table);
  5891. }
  5892. }
  5893. else
  5894. {
  5895. this.labelChanged(cells[i], '');
  5896. }
  5897. }
  5898. else
  5899. {
  5900. // Deletes table if all rows are removed
  5901. if (this.isTableRow(cells[i]))
  5902. {
  5903. var table = this.model.getParent(cells[i]);
  5904. if (mxUtils.indexOf(cells, table) < 0 &&
  5905. mxUtils.indexOf(result, table) < 0)
  5906. {
  5907. var rows = this.model.getChildCells(table, true);
  5908. var deleteCount = 0;
  5909. for (var j = 0; j < rows.length; j++)
  5910. {
  5911. if (mxUtils.indexOf(cells, rows[j]) >= 0)
  5912. {
  5913. deleteCount++;
  5914. }
  5915. }
  5916. if (deleteCount == rows.length)
  5917. {
  5918. result.push(table);
  5919. }
  5920. }
  5921. }
  5922. result.push(cells[i]);
  5923. }
  5924. }
  5925. result = graphRemoveCells.apply(this, [result, includeEdges]);
  5926. }
  5927. finally
  5928. {
  5929. this.model.endUpdate();
  5930. }
  5931. return result;
  5932. };
  5933. /**
  5934. * Updates cells IDs for custom links in the given cells.
  5935. */
  5936. Graph.prototype.updateCustomLinks = function(mapping, cells)
  5937. {
  5938. for (var i = 0; i < cells.length; i++)
  5939. {
  5940. if (cells[i] != null)
  5941. {
  5942. this.updateCustomLinksForCell(mapping, cells[i]);
  5943. }
  5944. }
  5945. };
  5946. /**
  5947. * Updates cell IDs in custom links on the given cell and its label.
  5948. */
  5949. Graph.prototype.updateCustomLinksForCell = function(mapping, cell)
  5950. {
  5951. // Hook for subclassers
  5952. };
  5953. /**
  5954. * Overrides method to provide connection constraints for shapes.
  5955. */
  5956. Graph.prototype.getAllConnectionConstraints = function(terminal, source)
  5957. {
  5958. if (terminal != null)
  5959. {
  5960. var constraints = mxUtils.getValue(terminal.style, 'points', null);
  5961. if (constraints != null)
  5962. {
  5963. // Requires an array of arrays with x, y (0..1), an optional
  5964. // [perimeter (0 or 1), dx, and dy] eg. points=[[0,0,1,-10,10],[0,1,0],[1,1]]
  5965. var result = [];
  5966. try
  5967. {
  5968. var c = JSON.parse(constraints);
  5969. for (var i = 0; i < c.length; i++)
  5970. {
  5971. var tmp = c[i];
  5972. result.push(new mxConnectionConstraint(new mxPoint(tmp[0], tmp[1]), (tmp.length > 2) ? tmp[2] != '0' : true,
  5973. null, (tmp.length > 3) ? tmp[3] : 0, (tmp.length > 4) ? tmp[4] : 0));
  5974. }
  5975. }
  5976. catch (e)
  5977. {
  5978. // ignore
  5979. }
  5980. return result;
  5981. }
  5982. else if (terminal.shape != null && terminal.shape.bounds != null)
  5983. {
  5984. var dir = terminal.shape.direction;
  5985. var bounds = terminal.shape.bounds;
  5986. var scale = terminal.shape.scale;
  5987. var w = bounds.width / scale;
  5988. var h = bounds.height / scale;
  5989. if (dir == mxConstants.DIRECTION_NORTH || dir == mxConstants.DIRECTION_SOUTH)
  5990. {
  5991. var tmp = w;
  5992. w = h;
  5993. h = tmp;
  5994. }
  5995. constraints = terminal.shape.getConstraints(terminal.style, w, h);
  5996. if (constraints != null)
  5997. {
  5998. return constraints;
  5999. }
  6000. else if (terminal.shape.stencil != null && terminal.shape.stencil.constraints != null)
  6001. {
  6002. return terminal.shape.stencil.constraints;
  6003. }
  6004. else if (terminal.shape.constraints != null)
  6005. {
  6006. return terminal.shape.constraints;
  6007. }
  6008. }
  6009. }
  6010. return null;
  6011. };
  6012. /**
  6013. * Inverts the elbow edge style without removing existing styles.
  6014. */
  6015. Graph.prototype.flipEdge = function(edge)
  6016. {
  6017. if (edge != null)
  6018. {
  6019. var style = this.getCurrentCellStyle(edge);
  6020. var elbow = mxUtils.getValue(style, mxConstants.STYLE_ELBOW,
  6021. mxConstants.ELBOW_HORIZONTAL);
  6022. var value = (elbow == mxConstants.ELBOW_HORIZONTAL) ?
  6023. mxConstants.ELBOW_VERTICAL : mxConstants.ELBOW_HORIZONTAL;
  6024. this.setCellStyles(mxConstants.STYLE_ELBOW, value, [edge]);
  6025. }
  6026. };
  6027. /**
  6028. * Disables drill-down for non-swimlanes.
  6029. */
  6030. Graph.prototype.isValidRoot = function(cell)
  6031. {
  6032. // Counts non-relative children
  6033. var childCount = this.model.getChildCount(cell);
  6034. var realChildCount = 0;
  6035. for (var i = 0; i < childCount; i++)
  6036. {
  6037. var child = this.model.getChildAt(cell, i);
  6038. if (this.model.isVertex(child))
  6039. {
  6040. var geometry = this.getCellGeometry(child);
  6041. if (geometry != null && !geometry.relative)
  6042. {
  6043. realChildCount++;
  6044. }
  6045. }
  6046. }
  6047. return realChildCount > 0 || this.isContainer(cell);
  6048. };
  6049. /**
  6050. * Disables drill-down for non-swimlanes.
  6051. */
  6052. Graph.prototype.isValidDropTarget = function(cell, cells, evt)
  6053. {
  6054. var style = this.getCurrentCellStyle(cell);
  6055. var tables = true;
  6056. var rows = true;
  6057. for (var i = 0; i < cells.length && rows; i++)
  6058. {
  6059. tables = tables && this.isTable(cells[i]);
  6060. rows = rows && this.isTableRow(cells[i]);
  6061. }
  6062. return (mxUtils.getValue(style, 'part', '0') != '1' || this.isContainer(cell)) &&
  6063. mxUtils.getValue(style, 'dropTarget', '1') != '0' &&
  6064. (mxGraph.prototype.isValidDropTarget.apply(this, arguments) ||
  6065. this.isContainer(cell)) && !this.isTableRow(cell) &&
  6066. (!this.isTable(cell) || rows || tables);
  6067. };
  6068. /**
  6069. * Overrides createGroupCell to set the group style for new groups to 'group'.
  6070. */
  6071. Graph.prototype.createGroupCell = function()
  6072. {
  6073. var group = mxGraph.prototype.createGroupCell.apply(this, arguments);
  6074. group.setStyle('group');
  6075. return group;
  6076. };
  6077. /**
  6078. * Disables extending parents with stack layouts on add
  6079. */
  6080. Graph.prototype.isExtendParentsOnAdd = function(cell)
  6081. {
  6082. var result = mxGraph.prototype.isExtendParentsOnAdd.apply(this, arguments);
  6083. if (result && cell != null && this.layoutManager != null)
  6084. {
  6085. var parent = this.model.getParent(cell);
  6086. if (parent != null)
  6087. {
  6088. var layout = this.layoutManager.getLayout(parent);
  6089. if (layout != null && layout.constructor == mxStackLayout)
  6090. {
  6091. result = false;
  6092. }
  6093. }
  6094. }
  6095. return result;
  6096. };
  6097. /**
  6098. * Overrides autosize to add a border.
  6099. */
  6100. Graph.prototype.getPreferredSizeForCell = function(cell)
  6101. {
  6102. var result = mxGraph.prototype.getPreferredSizeForCell.apply(this, arguments);
  6103. // Adds buffer
  6104. if (result != null)
  6105. {
  6106. result.width += 10;
  6107. result.height += 4;
  6108. if (this.gridEnabled)
  6109. {
  6110. result.width = this.snap(result.width);
  6111. result.height = this.snap(result.height);
  6112. }
  6113. }
  6114. return result;
  6115. }
  6116. /**
  6117. * Turns the given cells and returns the changed cells.
  6118. */
  6119. Graph.prototype.turnShapes = function(cells, backwards)
  6120. {
  6121. var model = this.getModel();
  6122. var select = [];
  6123. model.beginUpdate();
  6124. try
  6125. {
  6126. for (var i = 0; i < cells.length; i++)
  6127. {
  6128. var cell = cells[i];
  6129. if (model.isEdge(cell))
  6130. {
  6131. var src = model.getTerminal(cell, true);
  6132. var trg = model.getTerminal(cell, false);
  6133. model.setTerminal(cell, trg, true);
  6134. model.setTerminal(cell, src, false);
  6135. var geo = model.getGeometry(cell);
  6136. if (geo != null)
  6137. {
  6138. geo = geo.clone();
  6139. if (geo.points != null)
  6140. {
  6141. geo.points.reverse();
  6142. }
  6143. var sp = geo.getTerminalPoint(true);
  6144. var tp = geo.getTerminalPoint(false)
  6145. geo.setTerminalPoint(sp, false);
  6146. geo.setTerminalPoint(tp, true);
  6147. model.setGeometry(cell, geo);
  6148. // Inverts constraints
  6149. var edgeState = this.view.getState(cell);
  6150. var sourceState = this.view.getState(src);
  6151. var targetState = this.view.getState(trg);
  6152. if (edgeState != null)
  6153. {
  6154. var sc = (sourceState != null) ? this.getConnectionConstraint(edgeState, sourceState, true) : null;
  6155. var tc = (targetState != null) ? this.getConnectionConstraint(edgeState, targetState, false) : null;
  6156. this.setConnectionConstraint(cell, src, true, tc);
  6157. this.setConnectionConstraint(cell, trg, false, sc);
  6158. }
  6159. select.push(cell);
  6160. }
  6161. }
  6162. else if (model.isVertex(cell))
  6163. {
  6164. var geo = this.getCellGeometry(cell);
  6165. if (geo != null)
  6166. {
  6167. // Rotates the size and position in the geometry
  6168. if (!this.isTable(cell) && !this.isTableRow(cell) &&
  6169. !this.isTableCell(cell) && !this.isSwimlane(cell))
  6170. {
  6171. geo = geo.clone();
  6172. geo.x += geo.width / 2 - geo.height / 2;
  6173. geo.y += geo.height / 2 - geo.width / 2;
  6174. var tmp = geo.width;
  6175. geo.width = geo.height;
  6176. geo.height = tmp;
  6177. model.setGeometry(cell, geo);
  6178. }
  6179. // Reads the current direction and advances by 90 degrees
  6180. var state = this.view.getState(cell);
  6181. if (state != null)
  6182. {
  6183. var dirs = [mxConstants.DIRECTION_EAST, mxConstants.DIRECTION_SOUTH,
  6184. mxConstants.DIRECTION_WEST, mxConstants.DIRECTION_NORTH];
  6185. var dir = mxUtils.getValue(state.style, mxConstants.STYLE_DIRECTION,
  6186. mxConstants.DIRECTION_EAST);
  6187. this.setCellStyles(mxConstants.STYLE_DIRECTION,
  6188. dirs[mxUtils.mod(mxUtils.indexOf(dirs, dir) +
  6189. ((backwards) ? -1 : 1), dirs.length)], [cell]);
  6190. }
  6191. select.push(cell);
  6192. }
  6193. }
  6194. }
  6195. }
  6196. finally
  6197. {
  6198. model.endUpdate();
  6199. }
  6200. return select;
  6201. };
  6202. /**
  6203. * Returns true if the given stencil contains any placeholder text.
  6204. */
  6205. Graph.prototype.stencilHasPlaceholders = function(stencil)
  6206. {
  6207. if (stencil != null && stencil.fgNode != null)
  6208. {
  6209. var node = stencil.fgNode.firstChild;
  6210. while (node != null)
  6211. {
  6212. if (node.nodeName == 'text' && node.getAttribute('placeholders') == '1')
  6213. {
  6214. return true;
  6215. }
  6216. node = node.nextSibling;
  6217. }
  6218. }
  6219. return false;
  6220. };
  6221. /**
  6222. * Updates the child cells with placeholders if metadata of a
  6223. * cell has changed and propagates geometry changes in tables.
  6224. */
  6225. var graphProcessChange = Graph.prototype.processChange;
  6226. Graph.prototype.processChange = function(change)
  6227. {
  6228. if (change instanceof mxGeometryChange &&
  6229. (this.isTableCell(change.cell) || this.isTableRow(change.cell)) &&
  6230. ((change.previous == null && change.geometry != null) ||
  6231. (change.previous != null && !change.previous.equals(change.geometry))))
  6232. {
  6233. var cell = change.cell;
  6234. if (this.isTableCell(cell))
  6235. {
  6236. cell = this.model.getParent(cell);
  6237. }
  6238. if (this.isTableRow(cell))
  6239. {
  6240. cell = this.model.getParent(cell);
  6241. }
  6242. // Forces repaint of table with unchanged style and geometry
  6243. var state = this.view.getState(cell);
  6244. if (state != null && state.shape != null)
  6245. {
  6246. this.view.invalidate(cell);
  6247. state.shape.bounds = null;
  6248. }
  6249. }
  6250. graphProcessChange.apply(this, arguments);
  6251. if (change instanceof mxValueChange && change.cell != null &&
  6252. change.cell.value != null && typeof(change.cell.value) == 'object')
  6253. {
  6254. this.invalidateDescendantsWithPlaceholders(change.cell);
  6255. }
  6256. };
  6257. /**
  6258. * Replaces the given element with a span.
  6259. */
  6260. Graph.prototype.invalidateDescendantsWithPlaceholders = function(cell)
  6261. {
  6262. // Invalidates all descendants with placeholders
  6263. var desc = this.model.getDescendants(cell);
  6264. // LATER: Check if only label or tooltip have changed
  6265. if (desc.length > 0)
  6266. {
  6267. for (var i = 0; i < desc.length; i++)
  6268. {
  6269. var state = this.view.getState(desc[i]);
  6270. if (state != null && state.shape != null && state.shape.stencil != null &&
  6271. this.stencilHasPlaceholders(state.shape.stencil))
  6272. {
  6273. this.removeStateForCell(desc[i]);
  6274. }
  6275. else if (this.isReplacePlaceholders(desc[i]))
  6276. {
  6277. this.view.invalidate(desc[i], false, false);
  6278. }
  6279. }
  6280. }
  6281. };
  6282. /**
  6283. * Replaces the given element with a span.
  6284. */
  6285. Graph.prototype.replaceElement = function(elt, tagName)
  6286. {
  6287. var span = elt.ownerDocument.createElement((tagName != null) ? tagName : 'span');
  6288. var attributes = Array.prototype.slice.call(elt.attributes);
  6289. while (attr = attributes.pop())
  6290. {
  6291. span.setAttribute(attr.nodeName, attr.nodeValue);
  6292. }
  6293. span.innerHTML = elt.innerHTML;
  6294. elt.parentNode.replaceChild(span, elt);
  6295. };
  6296. /**
  6297. *
  6298. */
  6299. Graph.prototype.processElements = function(elt, fn)
  6300. {
  6301. if (elt != null)
  6302. {
  6303. var elts = elt.getElementsByTagName('*');
  6304. for (var i = 0; i < elts.length; i++)
  6305. {
  6306. fn(elts[i]);
  6307. }
  6308. }
  6309. };
  6310. /**
  6311. * Handles label changes for XML user objects.
  6312. */
  6313. Graph.prototype.updateLabelElements = function(cells, fn, tagName)
  6314. {
  6315. cells = (cells != null) ? cells : this.getSelectionCells();
  6316. var div = document.createElement('div');
  6317. for (var i = 0; i < cells.length; i++)
  6318. {
  6319. // Changes font tags inside HTML labels
  6320. if (this.isHtmlLabel(cells[i]))
  6321. {
  6322. var label = this.convertValueToString(cells[i]);
  6323. if (label != null && label.length > 0)
  6324. {
  6325. div.innerHTML = label;
  6326. var elts = div.getElementsByTagName((tagName != null) ? tagName : '*');
  6327. for (var j = 0; j < elts.length; j++)
  6328. {
  6329. fn(elts[j]);
  6330. }
  6331. if (div.innerHTML != label)
  6332. {
  6333. this.cellLabelChanged(cells[i], div.innerHTML);
  6334. }
  6335. }
  6336. }
  6337. }
  6338. };
  6339. /**
  6340. * Handles label changes for XML user objects.
  6341. */
  6342. Graph.prototype.cellLabelChanged = function(cell, value, autoSize)
  6343. {
  6344. // Removes all illegal control characters in user input
  6345. value = Graph.zapGremlins(value);
  6346. this.model.beginUpdate();
  6347. try
  6348. {
  6349. if (cell.value != null && typeof cell.value == 'object')
  6350. {
  6351. if (this.isReplacePlaceholders(cell) &&
  6352. cell.getAttribute('placeholder') != null)
  6353. {
  6354. // LATER: Handle delete, name change
  6355. var name = cell.getAttribute('placeholder');
  6356. var current = cell;
  6357. while (current != null)
  6358. {
  6359. if (current == this.model.getRoot() || (current.value != null &&
  6360. typeof(current.value) == 'object' && current.hasAttribute(name)))
  6361. {
  6362. this.setAttributeForCell(current, name, value);
  6363. break;
  6364. }
  6365. current = this.model.getParent(current);
  6366. }
  6367. }
  6368. var tmp = cell.value.cloneNode(true);
  6369. if (Graph.translateDiagram && Graph.diagramLanguage != null &&
  6370. tmp.hasAttribute('label_' + Graph.diagramLanguage))
  6371. {
  6372. tmp.setAttribute('label_' + Graph.diagramLanguage, value);
  6373. }
  6374. else
  6375. {
  6376. tmp.setAttribute('label', value);
  6377. }
  6378. value = tmp;
  6379. }
  6380. mxGraph.prototype.cellLabelChanged.apply(this, arguments);
  6381. }
  6382. finally
  6383. {
  6384. this.model.endUpdate();
  6385. }
  6386. };
  6387. /**
  6388. * Removes transparent empty groups if all children are removed.
  6389. */
  6390. Graph.prototype.cellsRemoved = function(cells)
  6391. {
  6392. if (cells != null)
  6393. {
  6394. var dict = new mxDictionary();
  6395. for (var i = 0; i < cells.length; i++)
  6396. {
  6397. dict.put(cells[i], true);
  6398. }
  6399. // LATER: Recurse up the cell hierarchy
  6400. var parents = [];
  6401. for (var i = 0; i < cells.length; i++)
  6402. {
  6403. var parent = this.model.getParent(cells[i]);
  6404. if (parent != null && !dict.get(parent))
  6405. {
  6406. dict.put(parent, true);
  6407. parents.push(parent);
  6408. }
  6409. }
  6410. for (var i = 0; i < parents.length; i++)
  6411. {
  6412. var state = this.view.getState(parents[i]);
  6413. if (state != null && (this.model.isEdge(state.cell) ||
  6414. this.model.isVertex(state.cell)) &&
  6415. this.isCellDeletable(state.cell) &&
  6416. this.isTransparentState(state))
  6417. {
  6418. var allChildren = true;
  6419. for (var j = 0; j < this.model.getChildCount(state.cell) && allChildren; j++)
  6420. {
  6421. if (!dict.get(this.model.getChildAt(state.cell, j)))
  6422. {
  6423. allChildren = false;
  6424. }
  6425. }
  6426. if (allChildren)
  6427. {
  6428. cells.push(state.cell);
  6429. }
  6430. }
  6431. }
  6432. }
  6433. mxGraph.prototype.cellsRemoved.apply(this, arguments);
  6434. };
  6435. /**
  6436. * Overrides ungroup to check if group should be removed.
  6437. */
  6438. Graph.prototype.removeCellsAfterUngroup = function(cells)
  6439. {
  6440. var cellsToRemove = [];
  6441. for (var i = 0; i < cells.length; i++)
  6442. {
  6443. if (this.isCellDeletable(cells[i]) &&
  6444. this.isTransparentState(
  6445. this.view.getState(cells[i])))
  6446. {
  6447. cellsToRemove.push(cells[i]);
  6448. }
  6449. }
  6450. cells = cellsToRemove;
  6451. mxGraph.prototype.removeCellsAfterUngroup.apply(this, arguments);
  6452. };
  6453. /**
  6454. * Sets the link for the given cell.
  6455. */
  6456. Graph.prototype.setLinkForCell = function(cell, link)
  6457. {
  6458. this.setAttributeForCell(cell, 'link', link);
  6459. };
  6460. /**
  6461. * Sets the link for the given cell.
  6462. */
  6463. Graph.prototype.setTooltipForCell = function(cell, link)
  6464. {
  6465. var key = 'tooltip';
  6466. if (Graph.translateDiagram && Graph.diagramLanguage != null &&
  6467. mxUtils.isNode(cell.value) && cell.value.hasAttribute('tooltip_' + Graph.diagramLanguage))
  6468. {
  6469. key = 'tooltip_' + Graph.diagramLanguage;
  6470. }
  6471. this.setAttributeForCell(cell, key, link);
  6472. };
  6473. /**
  6474. * Returns the cells in the model (or given array) that have all of the
  6475. * given tags in their tags property.
  6476. */
  6477. Graph.prototype.getAttributeForCell = function(cell, attributeName, defaultValue)
  6478. {
  6479. var value = (cell.value != null && typeof cell.value === 'object') ?
  6480. cell.value.getAttribute(attributeName) : null;
  6481. return (value != null) ? value : defaultValue;
  6482. };
  6483. /**
  6484. * Sets the link for the given cell.
  6485. */
  6486. Graph.prototype.setAttributeForCell = function(cell, attributeName, attributeValue)
  6487. {
  6488. var value = null;
  6489. if (cell.value != null && typeof(cell.value) == 'object')
  6490. {
  6491. value = cell.value.cloneNode(true);
  6492. }
  6493. else
  6494. {
  6495. var doc = mxUtils.createXmlDocument();
  6496. value = doc.createElement('UserObject');
  6497. value.setAttribute('label', cell.value || '');
  6498. }
  6499. if (attributeValue != null)
  6500. {
  6501. value.setAttribute(attributeName, attributeValue);
  6502. }
  6503. else
  6504. {
  6505. value.removeAttribute(attributeName);
  6506. }
  6507. this.model.setValue(cell, value);
  6508. };
  6509. /**
  6510. * Overridden to stop moving edge labels between cells.
  6511. */
  6512. var graphGetDropTarget = Graph.prototype.getDropTarget;
  6513. Graph.prototype.getDropTarget = function(cells, evt, cell, clone)
  6514. {
  6515. var model = this.getModel();
  6516. // Disables drop into group if alt is pressed
  6517. if (mxEvent.isAltDown(evt))
  6518. {
  6519. return null;
  6520. }
  6521. // Disables dragging edge labels out of edges
  6522. for (var i = 0; i < cells.length; i++)
  6523. {
  6524. if (this.model.isEdge(this.model.getParent(cells[i])))
  6525. {
  6526. return null;
  6527. }
  6528. }
  6529. var target = graphGetDropTarget.apply(this, arguments);
  6530. // Always drops rows to tables
  6531. var rows = true;
  6532. for (var i = 0; i < cells.length && rows; i++)
  6533. {
  6534. rows = rows && this.isTableRow(cells[i]);
  6535. }
  6536. if (rows)
  6537. {
  6538. if (this.isTableCell(target))
  6539. {
  6540. target = this.model.getParent(target);
  6541. }
  6542. if (this.isTableRow(target))
  6543. {
  6544. target = this.model.getParent(target);
  6545. }
  6546. if (!this.isTable(target))
  6547. {
  6548. target = null;
  6549. }
  6550. }
  6551. return target;
  6552. };
  6553. /**
  6554. * Overrides double click handling to avoid accidental inserts of new labels in dblClick below.
  6555. */
  6556. Graph.prototype.click = function(me)
  6557. {
  6558. mxGraph.prototype.click.call(this, me);
  6559. // Stores state and source for checking in dblClick
  6560. this.firstClickState = me.getState();
  6561. this.firstClickSource = me.getSource();
  6562. };
  6563. /**
  6564. * Overrides double click handling to add the tolerance and inserting text.
  6565. */
  6566. Graph.prototype.dblClick = function(evt, cell)
  6567. {
  6568. if (this.isEnabled())
  6569. {
  6570. cell = this.insertTextForEvent(evt, cell);
  6571. mxGraph.prototype.dblClick.call(this, evt, cell);
  6572. }
  6573. };
  6574. /**
  6575. * Overrides double click handling to add the tolerance and inserting text.
  6576. */
  6577. Graph.prototype.insertTextForEvent = function(evt, cell)
  6578. {
  6579. var pt = mxUtils.convertPoint(this.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  6580. // Automatically adds new child cells to edges on double click
  6581. if (evt != null && !this.model.isVertex(cell))
  6582. {
  6583. var state = (this.model.isEdge(cell)) ? this.view.getState(cell) : null;
  6584. var src = mxEvent.getSource(evt);
  6585. if ((this.firstClickState == state && this.firstClickSource == src) &&
  6586. (state == null || (state.text == null || state.text.node == null ||
  6587. state.text.boundingBox == null || (!mxUtils.contains(state.text.boundingBox,
  6588. pt.x, pt.y) && !mxUtils.isAncestorNode(state.text.node, mxEvent.getSource(evt))))) &&
  6589. ((state == null && !this.isCellLocked(this.getDefaultParent())) ||
  6590. (state != null && !this.isCellLocked(state.cell))) &&
  6591. (state != null || (mxClient.IS_VML && src == this.view.getCanvas()) ||
  6592. (mxClient.IS_SVG && src == this.view.getCanvas().ownerSVGElement)))
  6593. {
  6594. if (state == null)
  6595. {
  6596. state = this.view.getState(this.getCellAt(pt.x, pt.y));
  6597. }
  6598. cell = this.addText(pt.x, pt.y, state);
  6599. }
  6600. }
  6601. return cell;
  6602. };
  6603. /**
  6604. * Returns a point that specifies the location for inserting cells.
  6605. */
  6606. Graph.prototype.getInsertPoint = function()
  6607. {
  6608. var gs = this.getGridSize();
  6609. var dx = this.container.scrollLeft / this.view.scale - this.view.translate.x;
  6610. var dy = this.container.scrollTop / this.view.scale - this.view.translate.y;
  6611. if (this.pageVisible)
  6612. {
  6613. var layout = this.getPageLayout();
  6614. var page = this.getPageSize();
  6615. dx = Math.max(dx, layout.x * page.width);
  6616. dy = Math.max(dy, layout.y * page.height);
  6617. }
  6618. return new mxPoint(this.snap(dx + gs), this.snap(dy + gs));
  6619. };
  6620. /**
  6621. *
  6622. */
  6623. Graph.prototype.getFreeInsertPoint = function()
  6624. {
  6625. var view = this.view;
  6626. var bds = this.getGraphBounds();
  6627. var pt = this.getInsertPoint();
  6628. // Places at same x-coord and 2 grid sizes below existing graph
  6629. var x = this.snap(Math.round(Math.max(pt.x, bds.x / view.scale - view.translate.x +
  6630. ((bds.width == 0) ? 2 * this.gridSize : 0))));
  6631. var y = this.snap(Math.round(Math.max(pt.y, (bds.y + bds.height) / view.scale - view.translate.y +
  6632. 2 * this.gridSize)));
  6633. return new mxPoint(x, y);
  6634. };
  6635. /**
  6636. *
  6637. */
  6638. Graph.prototype.getCenterInsertPoint = function(bbox)
  6639. {
  6640. bbox = (bbox != null) ? bbox : new mxRectangle();
  6641. if (mxUtils.hasScrollbars(this.container))
  6642. {
  6643. return new mxPoint(
  6644. this.snap(Math.round((this.container.scrollLeft + this.container.clientWidth / 2) /
  6645. this.view.scale - this.view.translate.x - bbox.width / 2)),
  6646. this.snap(Math.round((this.container.scrollTop + this.container.clientHeight / 2) /
  6647. this.view.scale - this.view.translate.y - bbox.height / 2)));
  6648. }
  6649. else
  6650. {
  6651. return new mxPoint(
  6652. this.snap(Math.round(this.container.clientWidth / 2 / this.view.scale -
  6653. this.view.translate.x - bbox.width / 2)),
  6654. this.snap(Math.round(this.container.clientHeight / 2 / this.view.scale -
  6655. this.view.translate.y - bbox.height / 2)));
  6656. }
  6657. };
  6658. /**
  6659. * Hook for subclassers to return true if the current insert point was defined
  6660. * using a mouse hover event.
  6661. */
  6662. Graph.prototype.isMouseInsertPoint = function()
  6663. {
  6664. return false;
  6665. };
  6666. /**
  6667. * Adds a new label at the given position and returns the new cell. State is
  6668. * an optional edge state to be used as the parent for the label. Vertices
  6669. * are not allowed currently as states.
  6670. */
  6671. Graph.prototype.addText = function(x, y, state)
  6672. {
  6673. // Creates a new edge label with a predefined text
  6674. var label = new mxCell();
  6675. label.value = 'Text';
  6676. label.geometry = new mxGeometry(0, 0, 0, 0);
  6677. label.vertex = true;
  6678. var style = 'html=1;align=center;verticalAlign=middle;resizable=0;points=[];';
  6679. if (state != null && this.model.isEdge(state.cell))
  6680. {
  6681. label.style = 'edgeLabel;' + style;
  6682. label.geometry.relative = true;
  6683. label.connectable = false;
  6684. // Resets the relative location stored inside the geometry
  6685. var pt2 = this.view.getRelativePoint(state, x, y);
  6686. label.geometry.x = Math.round(pt2.x * 10000) / 10000;
  6687. label.geometry.y = Math.round(pt2.y);
  6688. // Resets the offset inside the geometry to find the offset from the resulting point
  6689. label.geometry.offset = new mxPoint(0, 0);
  6690. pt2 = this.view.getPoint(state, label.geometry);
  6691. var scale = this.view.scale;
  6692. label.geometry.offset = new mxPoint(Math.round((x - pt2.x) / scale), Math.round((y - pt2.y) / scale));
  6693. }
  6694. else
  6695. {
  6696. var tr = this.view.translate;
  6697. label.style = 'text;' + style;
  6698. label.geometry.width = 40;
  6699. label.geometry.height = 20;
  6700. label.geometry.x = Math.round(x / this.view.scale) -
  6701. tr.x - ((state != null) ? state.origin.x : 0);
  6702. label.geometry.y = Math.round(y / this.view.scale) -
  6703. tr.y - ((state != null) ? state.origin.y : 0);
  6704. label.style += 'autosize=1;'
  6705. }
  6706. this.getModel().beginUpdate();
  6707. try
  6708. {
  6709. this.addCells([label], (state != null) ? state.cell : null);
  6710. this.fireEvent(new mxEventObject('textInserted', 'cells', [label]));
  6711. // Updates size of text after possible change of style via event
  6712. this.autoSizeCell(label);
  6713. }
  6714. finally
  6715. {
  6716. this.getModel().endUpdate();
  6717. }
  6718. return label;
  6719. };
  6720. /**
  6721. * Adds a handler for clicking on shapes with links. This replaces all links in labels.
  6722. */
  6723. Graph.prototype.addClickHandler = function(highlight, beforeClick, onClick)
  6724. {
  6725. // Replaces links in labels for consistent right-clicks
  6726. var checkLinks = mxUtils.bind(this, function()
  6727. {
  6728. var links = this.container.getElementsByTagName('a');
  6729. if (links != null)
  6730. {
  6731. for (var i = 0; i < links.length; i++)
  6732. {
  6733. var href = this.getAbsoluteUrl(links[i].getAttribute('href'));
  6734. if (href != null)
  6735. {
  6736. links[i].setAttribute('rel', this.linkRelation);
  6737. links[i].setAttribute('href', href);
  6738. if (beforeClick != null)
  6739. {
  6740. mxEvent.addGestureListeners(links[i], null, null, beforeClick);
  6741. }
  6742. }
  6743. }
  6744. }
  6745. });
  6746. this.model.addListener(mxEvent.CHANGE, checkLinks);
  6747. checkLinks();
  6748. var cursor = this.container.style.cursor;
  6749. var tol = this.getTolerance();
  6750. var graph = this;
  6751. var mouseListener =
  6752. {
  6753. currentState: null,
  6754. currentLink: null,
  6755. highlight: (highlight != null && highlight != '' && highlight != mxConstants.NONE) ?
  6756. new mxCellHighlight(graph, highlight, 4) : null,
  6757. startX: 0,
  6758. startY: 0,
  6759. scrollLeft: 0,
  6760. scrollTop: 0,
  6761. updateCurrentState: function(me)
  6762. {
  6763. var tmp = me.sourceState;
  6764. // Gets topmost intersecting cell with link
  6765. if (tmp == null || graph.getLinkForCell(tmp.cell) == null)
  6766. {
  6767. var cell = graph.getCellAt(me.getGraphX(), me.getGraphY(), null, null, null, function(state, x, y)
  6768. {
  6769. return graph.getLinkForCell(state.cell) == null;
  6770. });
  6771. tmp = graph.view.getState(cell);
  6772. }
  6773. if (tmp != this.currentState)
  6774. {
  6775. if (this.currentState != null)
  6776. {
  6777. this.clear();
  6778. }
  6779. this.currentState = tmp;
  6780. if (this.currentState != null)
  6781. {
  6782. this.activate(this.currentState);
  6783. }
  6784. }
  6785. },
  6786. mouseDown: function(sender, me)
  6787. {
  6788. this.startX = me.getGraphX();
  6789. this.startY = me.getGraphY();
  6790. this.scrollLeft = graph.container.scrollLeft;
  6791. this.scrollTop = graph.container.scrollTop;
  6792. if (this.currentLink == null && graph.container.style.overflow == 'auto')
  6793. {
  6794. graph.container.style.cursor = 'move';
  6795. }
  6796. this.updateCurrentState(me);
  6797. },
  6798. mouseMove: function(sender, me)
  6799. {
  6800. if (graph.isMouseDown)
  6801. {
  6802. if (this.currentLink != null)
  6803. {
  6804. var dx = Math.abs(this.startX - me.getGraphX());
  6805. var dy = Math.abs(this.startY - me.getGraphY());
  6806. if (dx > tol || dy > tol)
  6807. {
  6808. this.clear();
  6809. }
  6810. }
  6811. }
  6812. else
  6813. {
  6814. // Checks for parent link
  6815. var linkNode = me.getSource();
  6816. while (linkNode != null && linkNode.nodeName.toLowerCase() != 'a')
  6817. {
  6818. linkNode = linkNode.parentNode;
  6819. }
  6820. if (linkNode != null)
  6821. {
  6822. this.clear();
  6823. }
  6824. else
  6825. {
  6826. if (graph.tooltipHandler != null && this.currentLink != null && this.currentState != null)
  6827. {
  6828. graph.tooltipHandler.reset(me, true, this.currentState);
  6829. }
  6830. if (this.currentState != null && (me.getState() == this.currentState || me.sourceState == null) &&
  6831. graph.intersects(this.currentState, me.getGraphX(), me.getGraphY()))
  6832. {
  6833. return;
  6834. }
  6835. this.updateCurrentState(me);
  6836. }
  6837. }
  6838. },
  6839. mouseUp: function(sender, me)
  6840. {
  6841. var source = me.getSource();
  6842. var evt = me.getEvent();
  6843. // Checks for parent link
  6844. var linkNode = source;
  6845. while (linkNode != null && linkNode.nodeName.toLowerCase() != 'a')
  6846. {
  6847. linkNode = linkNode.parentNode;
  6848. }
  6849. // Ignores clicks on links and collapse/expand icon
  6850. if (linkNode == null &&
  6851. (((Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  6852. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  6853. (me.sourceState == null || !me.isSource(me.sourceState.control))) &&
  6854. (((mxEvent.isLeftMouseButton(evt) || mxEvent.isMiddleMouseButton(evt)) &&
  6855. !mxEvent.isPopupTrigger(evt)) || mxEvent.isTouchEvent(evt))))
  6856. {
  6857. if (this.currentLink != null)
  6858. {
  6859. var blank = graph.isBlankLink(this.currentLink);
  6860. if ((this.currentLink.substring(0, 5) === 'data:' ||
  6861. !blank) && beforeClick != null)
  6862. {
  6863. beforeClick(evt, this.currentLink);
  6864. }
  6865. if (!mxEvent.isConsumed(evt))
  6866. {
  6867. var target = (mxEvent.isMiddleMouseButton(evt)) ? '_blank' :
  6868. ((blank) ? graph.linkTarget : '_top');
  6869. graph.openLink(this.currentLink, target);
  6870. me.consume();
  6871. }
  6872. }
  6873. else if (onClick != null && !me.isConsumed() &&
  6874. (Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  6875. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  6876. (Math.abs(this.startX - me.getGraphX()) < tol &&
  6877. Math.abs(this.startY - me.getGraphY()) < tol))
  6878. {
  6879. onClick(me.getEvent());
  6880. }
  6881. }
  6882. this.clear();
  6883. },
  6884. activate: function(state)
  6885. {
  6886. this.currentLink = graph.getAbsoluteUrl(graph.getLinkForCell(state.cell));
  6887. if (this.currentLink != null)
  6888. {
  6889. graph.container.style.cursor = 'pointer';
  6890. if (this.highlight != null)
  6891. {
  6892. this.highlight.highlight(state);
  6893. }
  6894. }
  6895. },
  6896. clear: function()
  6897. {
  6898. if (graph.container != null)
  6899. {
  6900. graph.container.style.cursor = cursor;
  6901. }
  6902. this.currentState = null;
  6903. this.currentLink = null;
  6904. if (this.highlight != null)
  6905. {
  6906. this.highlight.hide();
  6907. }
  6908. if (graph.tooltipHandler != null)
  6909. {
  6910. graph.tooltipHandler.hide();
  6911. }
  6912. }
  6913. };
  6914. // Ignores built-in click handling
  6915. graph.click = function(me) {};
  6916. graph.addMouseListener(mouseListener);
  6917. mxEvent.addListener(document, 'mouseleave', function(evt)
  6918. {
  6919. mouseListener.clear();
  6920. });
  6921. };
  6922. /**
  6923. * Duplicates the given cells and returns the duplicates.
  6924. */
  6925. Graph.prototype.duplicateCells = function(cells, append)
  6926. {
  6927. cells = (cells != null) ? cells : this.getSelectionCells();
  6928. append = (append != null) ? append : true;
  6929. // Duplicates rows for table cells
  6930. for (var i = 0; i < cells.length; i++)
  6931. {
  6932. if (this.isTableCell(cells[i]))
  6933. {
  6934. cells[i] = this.model.getParent(cells[i]);
  6935. }
  6936. }
  6937. cells = this.model.getTopmostCells(cells);
  6938. var model = this.getModel();
  6939. var s = this.gridSize;
  6940. var select = [];
  6941. model.beginUpdate();
  6942. try
  6943. {
  6944. var clones = this.cloneCells(cells, false, null, true);
  6945. for (var i = 0; i < cells.length; i++)
  6946. {
  6947. var parent = model.getParent(cells[i]);
  6948. var child = this.moveCells([clones[i]], s, s, false)[0];
  6949. select.push(child);
  6950. if (append)
  6951. {
  6952. model.add(parent, clones[i]);
  6953. }
  6954. else
  6955. {
  6956. // Maintains child index by inserting after clone in parent
  6957. var index = parent.getIndex(cells[i]);
  6958. model.add(parent, clones[i], index + 1);
  6959. }
  6960. // Extends tables
  6961. if (this.isTable(parent))
  6962. {
  6963. var row = this.getCellGeometry(clones[i]);
  6964. var table = this.getCellGeometry(parent);
  6965. if (row != null && table != null)
  6966. {
  6967. table = table.clone();
  6968. table.height += row.height;
  6969. model.setGeometry(parent, table);
  6970. }
  6971. }
  6972. }
  6973. }
  6974. finally
  6975. {
  6976. model.endUpdate();
  6977. }
  6978. return select;
  6979. };
  6980. /**
  6981. * Inserts the given image at the cursor in a content editable text box using
  6982. * the insertimage command on the document instance.
  6983. */
  6984. Graph.prototype.insertImage = function(newValue, w, h)
  6985. {
  6986. // To find the new image, we create a list of all existing links first
  6987. if (newValue != null && this.cellEditor.textarea != null)
  6988. {
  6989. var tmp = this.cellEditor.textarea.getElementsByTagName('img');
  6990. var oldImages = [];
  6991. for (var i = 0; i < tmp.length; i++)
  6992. {
  6993. oldImages.push(tmp[i]);
  6994. }
  6995. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  6996. document.execCommand('insertimage', false, newValue);
  6997. // Sets size of new image
  6998. var newImages = this.cellEditor.textarea.getElementsByTagName('img');
  6999. if (newImages.length == oldImages.length + 1)
  7000. {
  7001. // Inverse order in favor of appended images
  7002. for (var i = newImages.length - 1; i >= 0; i--)
  7003. {
  7004. if (i == 0 || newImages[i] != oldImages[i - 1])
  7005. {
  7006. // Workaround for lost styles during undo and redo is using attributes
  7007. newImages[i].setAttribute('width', w);
  7008. newImages[i].setAttribute('height', h);
  7009. break;
  7010. }
  7011. }
  7012. }
  7013. }
  7014. };
  7015. /**
  7016. * Inserts the given image at the cursor in a content editable text box using
  7017. * the insertimage command on the document instance.
  7018. */
  7019. Graph.prototype.insertLink = function(value)
  7020. {
  7021. if (this.cellEditor.textarea != null)
  7022. {
  7023. if (value.length == 0)
  7024. {
  7025. document.execCommand('unlink', false);
  7026. }
  7027. else if (mxClient.IS_FF)
  7028. {
  7029. // Workaround for Firefox that adds a new link and removes
  7030. // the href from the inner link if its parent is a span is
  7031. // to remove all inner links inside the new outer link
  7032. var tmp = this.cellEditor.textarea.getElementsByTagName('a');
  7033. var oldLinks = [];
  7034. for (var i = 0; i < tmp.length; i++)
  7035. {
  7036. oldLinks.push(tmp[i]);
  7037. }
  7038. document.execCommand('createlink', false, mxUtils.trim(value));
  7039. // Finds the new link element
  7040. var newLinks = this.cellEditor.textarea.getElementsByTagName('a');
  7041. if (newLinks.length == oldLinks.length + 1)
  7042. {
  7043. // Inverse order in favor of appended links
  7044. for (var i = newLinks.length - 1; i >= 0; i--)
  7045. {
  7046. if (newLinks[i] != oldLinks[i - 1])
  7047. {
  7048. // Removes all inner links from the new link and
  7049. // moves the children to the inner link parent
  7050. var tmp = newLinks[i].getElementsByTagName('a');
  7051. while (tmp.length > 0)
  7052. {
  7053. var parent = tmp[0].parentNode;
  7054. while (tmp[0].firstChild != null)
  7055. {
  7056. parent.insertBefore(tmp[0].firstChild, tmp[0]);
  7057. }
  7058. parent.removeChild(tmp[0]);
  7059. }
  7060. break;
  7061. }
  7062. }
  7063. }
  7064. }
  7065. else
  7066. {
  7067. // LATER: Fix inserting link/image in IE8/quirks after focus lost
  7068. document.execCommand('createlink', false, mxUtils.trim(value));
  7069. }
  7070. }
  7071. };
  7072. /**
  7073. *
  7074. * @param cell
  7075. * @returns {Boolean}
  7076. */
  7077. Graph.prototype.isCellResizable = function(cell)
  7078. {
  7079. var result = mxGraph.prototype.isCellResizable.apply(this, arguments);
  7080. var style = this.getCurrentCellStyle(cell);
  7081. return !this.isTableCell(cell) && !this.isTableRow(cell) && (result ||
  7082. (mxUtils.getValue(style, mxConstants.STYLE_RESIZABLE, '1') != '0' &&
  7083. style[mxConstants.STYLE_WHITE_SPACE] == 'wrap'));
  7084. };
  7085. /**
  7086. * Function: distributeCells
  7087. *
  7088. * Distribuets the centers of the given cells equally along the available
  7089. * horizontal or vertical space.
  7090. *
  7091. * Parameters:
  7092. *
  7093. * horizontal - Boolean that specifies the direction of the distribution.
  7094. * cells - Optional array of <mxCells> to be distributed. Edges are ignored.
  7095. */
  7096. Graph.prototype.distributeCells = function(horizontal, cells)
  7097. {
  7098. if (cells == null)
  7099. {
  7100. cells = this.getSelectionCells();
  7101. }
  7102. if (cells != null && cells.length > 1)
  7103. {
  7104. var vertices = [];
  7105. var max = null;
  7106. var min = null;
  7107. for (var i = 0; i < cells.length; i++)
  7108. {
  7109. if (this.getModel().isVertex(cells[i]))
  7110. {
  7111. var state = this.view.getState(cells[i]);
  7112. if (state != null)
  7113. {
  7114. var tmp = (horizontal) ? state.getCenterX() : state.getCenterY();
  7115. max = (max != null) ? Math.max(max, tmp) : tmp;
  7116. min = (min != null) ? Math.min(min, tmp) : tmp;
  7117. vertices.push(state);
  7118. }
  7119. }
  7120. }
  7121. if (vertices.length > 2)
  7122. {
  7123. vertices.sort(function(a, b)
  7124. {
  7125. return (horizontal) ? a.x - b.x : a.y - b.y;
  7126. });
  7127. var t = this.view.translate;
  7128. var s = this.view.scale;
  7129. min = min / s - ((horizontal) ? t.x : t.y);
  7130. max = max / s - ((horizontal) ? t.x : t.y);
  7131. this.getModel().beginUpdate();
  7132. try
  7133. {
  7134. var dt = (max - min) / (vertices.length - 1);
  7135. var t0 = min;
  7136. for (var i = 1; i < vertices.length - 1; i++)
  7137. {
  7138. var pstate = this.view.getState(this.model.getParent(vertices[i].cell));
  7139. var geo = this.getCellGeometry(vertices[i].cell);
  7140. t0 += dt;
  7141. if (geo != null && pstate != null)
  7142. {
  7143. geo = geo.clone();
  7144. if (horizontal)
  7145. {
  7146. geo.x = Math.round(t0 - geo.width / 2) - pstate.origin.x;
  7147. }
  7148. else
  7149. {
  7150. geo.y = Math.round(t0 - geo.height / 2) - pstate.origin.y;
  7151. }
  7152. this.getModel().setGeometry(vertices[i].cell, geo);
  7153. }
  7154. }
  7155. }
  7156. finally
  7157. {
  7158. this.getModel().endUpdate();
  7159. }
  7160. }
  7161. }
  7162. return cells;
  7163. };
  7164. /**
  7165. * Adds meta-drag an Mac.
  7166. * @param evt
  7167. * @returns
  7168. */
  7169. Graph.prototype.isCloneEvent = function(evt)
  7170. {
  7171. return (mxClient.IS_MAC && mxEvent.isMetaDown(evt)) || mxEvent.isControlDown(evt);
  7172. };
  7173. /**
  7174. * Translates this point by the given vector.
  7175. *
  7176. * @param {number} dx X-coordinate of the translation.
  7177. * @param {number} dy Y-coordinate of the translation.
  7178. */
  7179. Graph.prototype.createSvgImageExport = function()
  7180. {
  7181. var exp = new mxImageExport();
  7182. // Adds hyperlinks (experimental)
  7183. exp.getLinkForCellState = mxUtils.bind(this, function(state, canvas)
  7184. {
  7185. return this.getLinkForCell(state.cell);
  7186. });
  7187. return exp;
  7188. };
  7189. /**
  7190. * Translates this point by the given vector.
  7191. *
  7192. * @param {number} dx X-coordinate of the translation.
  7193. * @param {number} dy Y-coordinate of the translation.
  7194. */
  7195. Graph.prototype.getSvg = function(background, scale, border, nocrop, crisp,
  7196. ignoreSelection, showText, imgExport, linkTarget, hasShadow)
  7197. {
  7198. //Disable Css Transforms if it is used
  7199. var origUseCssTrans = this.useCssTransforms;
  7200. if (origUseCssTrans)
  7201. {
  7202. this.useCssTransforms = false;
  7203. this.view.revalidate();
  7204. this.sizeDidChange();
  7205. }
  7206. try
  7207. {
  7208. scale = (scale != null) ? scale : 1;
  7209. border = (border != null) ? border : 0;
  7210. crisp = (crisp != null) ? crisp : true;
  7211. ignoreSelection = (ignoreSelection != null) ? ignoreSelection : true;
  7212. showText = (showText != null) ? showText : true;
  7213. var bounds = (ignoreSelection || nocrop) ?
  7214. this.getGraphBounds() : this.getBoundingBox(
  7215. this.getSelectionCells());
  7216. if (bounds == null)
  7217. {
  7218. throw Error(mxResources.get('drawingEmpty'));
  7219. }
  7220. var vs = this.view.scale;
  7221. // Prepares SVG document that holds the output
  7222. var svgDoc = mxUtils.createXmlDocument();
  7223. var root = (svgDoc.createElementNS != null) ?
  7224. svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') : svgDoc.createElement('svg');
  7225. if (background != null)
  7226. {
  7227. if (root.style != null)
  7228. {
  7229. root.style.backgroundColor = background;
  7230. }
  7231. else
  7232. {
  7233. root.setAttribute('style', 'background-color:' + background);
  7234. }
  7235. }
  7236. if (svgDoc.createElementNS == null)
  7237. {
  7238. root.setAttribute('xmlns', mxConstants.NS_SVG);
  7239. root.setAttribute('xmlns:xlink', mxConstants.NS_XLINK);
  7240. }
  7241. else
  7242. {
  7243. // KNOWN: Ignored in IE9-11, adds namespace for each image element instead. No workaround.
  7244. root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', mxConstants.NS_XLINK);
  7245. }
  7246. var s = scale / vs;
  7247. var w = Math.max(1, Math.ceil(bounds.width * s) + 2 * border) + ((hasShadow) ? 5 : 0);
  7248. var h = Math.max(1, Math.ceil(bounds.height * s) + 2 * border) + ((hasShadow) ? 5 : 0);
  7249. root.setAttribute('version', '1.1');
  7250. root.setAttribute('width', w + 'px');
  7251. root.setAttribute('height', h + 'px');
  7252. root.setAttribute('viewBox', ((crisp) ? '-0.5 -0.5' : '0 0') + ' ' + w + ' ' + h);
  7253. svgDoc.appendChild(root);
  7254. // Renders graph. Offset will be multiplied with state's scale when painting state.
  7255. // TextOffset only seems to affect FF output but used everywhere for consistency.
  7256. var group = (svgDoc.createElementNS != null) ?
  7257. svgDoc.createElementNS(mxConstants.NS_SVG, 'g') : svgDoc.createElement('g');
  7258. root.appendChild(group);
  7259. var svgCanvas = this.createSvgCanvas(group);
  7260. svgCanvas.foOffset = (crisp) ? -0.5 : 0;
  7261. svgCanvas.textOffset = (crisp) ? -0.5 : 0;
  7262. svgCanvas.imageOffset = (crisp) ? -0.5 : 0;
  7263. svgCanvas.translate(Math.floor((border / scale - bounds.x) / vs),
  7264. Math.floor((border / scale - bounds.y) / vs));
  7265. // Convert HTML entities
  7266. var htmlConverter = document.createElement('div');
  7267. // Adds simple text fallback for viewers with no support for foreignObjects
  7268. var getAlternateText = svgCanvas.getAlternateText;
  7269. svgCanvas.getAlternateText = function(fo, x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation)
  7270. {
  7271. // Assumes a max character width of 0.5em
  7272. if (str != null && this.state.fontSize > 0)
  7273. {
  7274. try
  7275. {
  7276. if (mxUtils.isNode(str))
  7277. {
  7278. str = str.innerText;
  7279. }
  7280. else
  7281. {
  7282. htmlConverter.innerHTML = str;
  7283. str = mxUtils.extractTextWithWhitespace(htmlConverter.childNodes);
  7284. }
  7285. // Workaround for substring breaking double byte UTF
  7286. var exp = Math.ceil(2 * w / this.state.fontSize);
  7287. var result = [];
  7288. var length = 0;
  7289. var index = 0;
  7290. while ((exp == 0 || length < exp) && index < str.length)
  7291. {
  7292. var char = str.charCodeAt(index);
  7293. if (char == 10 || char == 13)
  7294. {
  7295. if (length > 0)
  7296. {
  7297. break;
  7298. }
  7299. }
  7300. else
  7301. {
  7302. result.push(str.charAt(index));
  7303. if (char < 255)
  7304. {
  7305. length++;
  7306. }
  7307. }
  7308. index++;
  7309. }
  7310. // Uses result and adds ellipsis if more than 1 char remains
  7311. if (result.length < str.length && str.length - result.length > 1)
  7312. {
  7313. str = mxUtils.trim(result.join('')) + '...';
  7314. }
  7315. return str;
  7316. }
  7317. catch (e)
  7318. {
  7319. return getAlternateText.apply(this, arguments);
  7320. }
  7321. }
  7322. else
  7323. {
  7324. return getAlternateText.apply(this, arguments);
  7325. }
  7326. };
  7327. // Paints background image
  7328. var bgImg = this.backgroundImage;
  7329. if (bgImg != null)
  7330. {
  7331. var s2 = vs / scale;
  7332. var tr = this.view.translate;
  7333. var tmp = new mxRectangle(tr.x * s2, tr.y * s2, bgImg.width * s2, bgImg.height * s2);
  7334. // Checks if visible
  7335. if (mxUtils.intersects(bounds, tmp))
  7336. {
  7337. svgCanvas.image(tr.x, tr.y, bgImg.width, bgImg.height, bgImg.src, true);
  7338. }
  7339. }
  7340. svgCanvas.scale(s);
  7341. svgCanvas.textEnabled = showText;
  7342. imgExport = (imgExport != null) ? imgExport : this.createSvgImageExport();
  7343. var imgExportDrawCellState = imgExport.drawCellState;
  7344. // Ignores custom links
  7345. var imgExportGetLinkForCellState = imgExport.getLinkForCellState;
  7346. imgExport.getLinkForCellState = function(state, canvas)
  7347. {
  7348. var result = imgExportGetLinkForCellState.apply(this, arguments);
  7349. return (result != null && !state.view.graph.isCustomLink(result)) ? result : null;
  7350. };
  7351. // Implements ignoreSelection flag
  7352. imgExport.drawCellState = function(state, canvas)
  7353. {
  7354. var graph = state.view.graph;
  7355. var selected = graph.isCellSelected(state.cell);
  7356. var parent = graph.model.getParent(state.cell);
  7357. // Checks if parent cell is selected
  7358. while (!ignoreSelection && !selected && parent != null)
  7359. {
  7360. selected = graph.isCellSelected(parent);
  7361. parent = graph.model.getParent(parent);
  7362. }
  7363. if (ignoreSelection || selected)
  7364. {
  7365. imgExportDrawCellState.apply(this, arguments);
  7366. }
  7367. };
  7368. imgExport.drawState(this.getView().getState(this.model.root), svgCanvas);
  7369. this.updateSvgLinks(root, linkTarget, true);
  7370. this.addForeignObjectWarning(svgCanvas, root);
  7371. return root;
  7372. }
  7373. finally
  7374. {
  7375. if (origUseCssTrans)
  7376. {
  7377. this.useCssTransforms = true;
  7378. this.view.revalidate();
  7379. this.sizeDidChange();
  7380. }
  7381. }
  7382. };
  7383. /**
  7384. * Adds warning for truncated labels in older viewers.
  7385. */
  7386. Graph.prototype.addForeignObjectWarning = function(canvas, root)
  7387. {
  7388. if (root.getElementsByTagName('foreignObject').length > 0)
  7389. {
  7390. var sw = canvas.createElement('switch');
  7391. var g1 = canvas.createElement('g');
  7392. g1.setAttribute('requiredFeatures', 'http://www.w3.org/TR/SVG11/feature#Extensibility');
  7393. var a = canvas.createElement('a');
  7394. a.setAttribute('transform', 'translate(0,-5)');
  7395. // Workaround for implicit namespace handling in HTML5 export, IE adds NS1 namespace so use code below
  7396. // in all IE versions except quirks mode. KNOWN: Adds xlink namespace to each image tag in output.
  7397. if (a.setAttributeNS == null || (root.ownerDocument != document && document.documentMode == null))
  7398. {
  7399. a.setAttribute('xlink:href', Graph.foreignObjectWarningLink);
  7400. a.setAttribute('target', '_blank');
  7401. }
  7402. else
  7403. {
  7404. a.setAttributeNS(mxConstants.NS_XLINK, 'xlink:href', Graph.foreignObjectWarningLink);
  7405. a.setAttributeNS(mxConstants.NS_XLINK, 'target', '_blank');
  7406. }
  7407. var text = canvas.createElement('text');
  7408. text.setAttribute('text-anchor', 'middle');
  7409. text.setAttribute('font-size', '10px');
  7410. text.setAttribute('x', '50%');
  7411. text.setAttribute('y', '100%');
  7412. mxUtils.write(text, Graph.foreignObjectWarningText);
  7413. sw.appendChild(g1);
  7414. a.appendChild(text);
  7415. sw.appendChild(a);
  7416. root.appendChild(sw);
  7417. }
  7418. };
  7419. /**
  7420. * Hook for creating the canvas used in getSvg.
  7421. */
  7422. Graph.prototype.updateSvgLinks = function(node, target, removeCustom)
  7423. {
  7424. var links = node.getElementsByTagName('a');
  7425. for (var i = 0; i < links.length; i++)
  7426. {
  7427. var href = links[i].getAttribute('href');
  7428. if (href == null)
  7429. {
  7430. href = links[i].getAttribute('xlink:href');
  7431. }
  7432. if (href != null)
  7433. {
  7434. if (target != null && /^https?:\/\//.test(href))
  7435. {
  7436. links[i].setAttribute('target', target);
  7437. }
  7438. else if (removeCustom && this.isCustomLink(href))
  7439. {
  7440. links[i].setAttribute('href', 'javascript:void(0);');
  7441. }
  7442. }
  7443. }
  7444. };
  7445. /**
  7446. * Hook for creating the canvas used in getSvg.
  7447. */
  7448. Graph.prototype.createSvgCanvas = function(node)
  7449. {
  7450. var canvas = new mxSvgCanvas2D(node);
  7451. canvas.pointerEvents = true;
  7452. return canvas;
  7453. };
  7454. /**
  7455. * Returns the first ancestor of the current selection with the given name.
  7456. */
  7457. Graph.prototype.getSelectedElement = function()
  7458. {
  7459. var node = null;
  7460. if (window.getSelection)
  7461. {
  7462. var sel = window.getSelection();
  7463. if (sel.getRangeAt && sel.rangeCount)
  7464. {
  7465. var range = sel.getRangeAt(0);
  7466. node = range.commonAncestorContainer;
  7467. }
  7468. }
  7469. else if (document.selection)
  7470. {
  7471. node = document.selection.createRange().parentElement();
  7472. }
  7473. return node;
  7474. };
  7475. /**
  7476. * Returns the text editing element.
  7477. */
  7478. Graph.prototype.getSelectedEditingElement = function()
  7479. {
  7480. var node = this.getSelectedElement();
  7481. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  7482. {
  7483. node = node.parentNode;
  7484. }
  7485. if (node != null)
  7486. {
  7487. // Workaround for commonAncestor on range in IE11 returning parent of common ancestor
  7488. if (node == this.cellEditor.textarea && this.cellEditor.textarea.children.length == 1 &&
  7489. this.cellEditor.textarea.firstChild.nodeType == mxConstants.NODETYPE_ELEMENT)
  7490. {
  7491. node = this.cellEditor.textarea.firstChild;
  7492. }
  7493. }
  7494. return node;
  7495. };
  7496. /**
  7497. * Returns the first ancestor of the current selection with the given name.
  7498. */
  7499. Graph.prototype.getParentByName = function(node, name, stopAt)
  7500. {
  7501. while (node != null)
  7502. {
  7503. if (node.nodeName == name)
  7504. {
  7505. return node;
  7506. }
  7507. if (node == stopAt)
  7508. {
  7509. return null;
  7510. }
  7511. node = node.parentNode;
  7512. }
  7513. return node;
  7514. };
  7515. /**
  7516. * Returns the first ancestor of the current selection with the given name.
  7517. */
  7518. Graph.prototype.getParentByNames = function(node, names, stopAt)
  7519. {
  7520. while (node != null)
  7521. {
  7522. if (mxUtils.indexOf(names, node.nodeName) >= 0)
  7523. {
  7524. return node;
  7525. }
  7526. if (node == stopAt)
  7527. {
  7528. return null;
  7529. }
  7530. node = node.parentNode;
  7531. }
  7532. return node;
  7533. };
  7534. /**
  7535. * Selects the given node.
  7536. */
  7537. Graph.prototype.selectNode = function(node)
  7538. {
  7539. var sel = null;
  7540. // IE9 and non-IE
  7541. if (window.getSelection)
  7542. {
  7543. sel = window.getSelection();
  7544. if (sel.getRangeAt && sel.rangeCount)
  7545. {
  7546. var range = document.createRange();
  7547. range.selectNode(node);
  7548. sel.removeAllRanges();
  7549. sel.addRange(range);
  7550. }
  7551. }
  7552. // IE < 9
  7553. else if ((sel = document.selection) && sel.type != 'Control')
  7554. {
  7555. var originalRange = sel.createRange();
  7556. originalRange.collapse(true);
  7557. var range = sel.createRange();
  7558. range.setEndPoint('StartToStart', originalRange);
  7559. range.select();
  7560. }
  7561. };
  7562. /**
  7563. * Deletes the given cells and returns the cells to be selected.
  7564. */
  7565. Graph.prototype.deleteCells = function(cells, includeEdges)
  7566. {
  7567. var select = null;
  7568. if (cells != null && cells.length > 0)
  7569. {
  7570. this.model.beginUpdate();
  7571. try
  7572. {
  7573. // Shrinks tables
  7574. for (var i = 0; i < cells.length; i++)
  7575. {
  7576. var parent = this.model.getParent(cells[i]);
  7577. if (this.isTable(parent))
  7578. {
  7579. var row = this.getCellGeometry(cells[i]);
  7580. var table = this.getCellGeometry(parent);
  7581. if (row != null && table != null)
  7582. {
  7583. table = table.clone();
  7584. table.height -= row.height;
  7585. this.model.setGeometry(parent, table);
  7586. }
  7587. }
  7588. }
  7589. var parents = (this.selectParentAfterDelete) ? this.model.getParents(cells) : null;
  7590. this.removeCells(cells, includeEdges);
  7591. }
  7592. finally
  7593. {
  7594. this.model.endUpdate();
  7595. }
  7596. // Selects parents for easier editing of groups
  7597. if (parents != null)
  7598. {
  7599. select = [];
  7600. for (var i = 0; i < parents.length; i++)
  7601. {
  7602. if (this.model.contains(parents[i]) &&
  7603. (this.model.isVertex(parents[i]) ||
  7604. this.model.isEdge(parents[i])))
  7605. {
  7606. select.push(parents[i]);
  7607. }
  7608. }
  7609. }
  7610. }
  7611. return select;
  7612. };
  7613. /**
  7614. * Inserts a column in the table for the given cell.
  7615. */
  7616. Graph.prototype.insertTableColumn = function(cell, before)
  7617. {
  7618. var model = this.getModel();
  7619. model.beginUpdate();
  7620. try
  7621. {
  7622. var table = cell;
  7623. var index = 0;
  7624. if (this.isTableCell(cell))
  7625. {
  7626. var row = model.getParent(cell);
  7627. table = model.getParent(row);
  7628. index = mxUtils.indexOf(model.getChildCells(row, true), cell);
  7629. }
  7630. else
  7631. {
  7632. if (this.isTableRow(cell))
  7633. {
  7634. table = model.getParent(cell);
  7635. }
  7636. else
  7637. {
  7638. cell = model.getChildCells(table, true)[0];
  7639. }
  7640. if (!before)
  7641. {
  7642. index = model.getChildCells(cell, true).length - 1;
  7643. }
  7644. }
  7645. var rows = model.getChildCells(table, true);
  7646. var dw = Graph.minTableColumnWidth;
  7647. for (var i = 0; i < rows.length; i++)
  7648. {
  7649. var child = model.getChildCells(rows[i], true)[index];
  7650. var clone = model.cloneCell(child, false);
  7651. var geo = this.getCellGeometry(clone);
  7652. clone.value = null;
  7653. if (geo != null)
  7654. {
  7655. dw = geo.width;
  7656. var rowGeo = this.getCellGeometry(rows[i]);
  7657. if (rowGeo != null)
  7658. {
  7659. geo.height = rowGeo.height;
  7660. }
  7661. }
  7662. model.add(rows[i], clone, index + ((before) ? 0 : 1));
  7663. }
  7664. var tableGeo = this.getCellGeometry(table);
  7665. if (tableGeo != null)
  7666. {
  7667. tableGeo = tableGeo.clone();
  7668. tableGeo.width += dw;
  7669. model.setGeometry(table, tableGeo);
  7670. }
  7671. }
  7672. finally
  7673. {
  7674. model.endUpdate();
  7675. }
  7676. };
  7677. /**
  7678. * Inserts a row in the table for the given cell.
  7679. */
  7680. Graph.prototype.insertTableRow = function(cell, before)
  7681. {
  7682. var model = this.getModel();
  7683. model.beginUpdate();
  7684. try
  7685. {
  7686. var table = cell;
  7687. var row = cell;
  7688. if (this.isTableCell(cell))
  7689. {
  7690. row = model.getParent(cell);
  7691. table = model.getParent(row);
  7692. }
  7693. else if (this.isTableRow(cell))
  7694. {
  7695. table = model.getParent(cell);
  7696. }
  7697. else
  7698. {
  7699. var rows = model.getChildCells(table, true);
  7700. row = rows[(before) ? 0 : rows.length - 1];
  7701. }
  7702. var cells = model.getChildCells(row, true);
  7703. var index = table.getIndex(row);
  7704. row = model.cloneCell(row, false);
  7705. row.value = null;
  7706. var rowGeo = this.getCellGeometry(row);
  7707. if (rowGeo != null)
  7708. {
  7709. for (var i = 0; i < cells.length; i++)
  7710. {
  7711. var cell = model.cloneCell(cells[i], false);
  7712. row.insert(cell);
  7713. cell.value = null;
  7714. var geo = this.getCellGeometry(cell);
  7715. if (geo != null)
  7716. {
  7717. geo.height = rowGeo.height;
  7718. }
  7719. }
  7720. model.add(table, row, index + ((before) ? 0 : 1));
  7721. var tableGeo = this.getCellGeometry(table);
  7722. if (tableGeo != null)
  7723. {
  7724. tableGeo = tableGeo.clone();
  7725. tableGeo.height += rowGeo.height;
  7726. model.setGeometry(table, tableGeo);
  7727. }
  7728. }
  7729. }
  7730. finally
  7731. {
  7732. model.endUpdate();
  7733. }
  7734. };
  7735. /**
  7736. *
  7737. */
  7738. Graph.prototype.deleteTableColumn = function(cell)
  7739. {
  7740. var model = this.getModel();
  7741. model.beginUpdate();
  7742. try
  7743. {
  7744. var table = cell;
  7745. var row = cell;
  7746. if (this.isTableCell(cell))
  7747. {
  7748. row = model.getParent(cell);
  7749. }
  7750. if (this.isTableRow(row))
  7751. {
  7752. table = model.getParent(row);
  7753. }
  7754. var rows = model.getChildCells(table, true);
  7755. if (rows.length == 0)
  7756. {
  7757. model.remove(table);
  7758. }
  7759. else
  7760. {
  7761. if (!this.isTableRow(row))
  7762. {
  7763. row = rows[0];
  7764. }
  7765. var cells = model.getChildCells(row, true);
  7766. if (cells.length <= 1)
  7767. {
  7768. model.remove(table);
  7769. }
  7770. else
  7771. {
  7772. var index = cells.length - 1;
  7773. if (this.isTableCell(cell))
  7774. {
  7775. index = mxUtils.indexOf(cells, cell);
  7776. }
  7777. var width = 0;
  7778. for (var i = 0; i < rows.length; i++)
  7779. {
  7780. var child = model.getChildCells(rows[i], true)[index];
  7781. model.remove(child);
  7782. var geo = this.getCellGeometry(child);
  7783. if (geo != null)
  7784. {
  7785. width = Math.max(width, geo.width);
  7786. }
  7787. }
  7788. var tableGeo = this.getCellGeometry(table);
  7789. if (tableGeo != null)
  7790. {
  7791. tableGeo = tableGeo.clone();
  7792. tableGeo.width -= width;
  7793. model.setGeometry(table, tableGeo);
  7794. }
  7795. }
  7796. }
  7797. }
  7798. finally
  7799. {
  7800. model.endUpdate();
  7801. }
  7802. };
  7803. /**
  7804. *
  7805. */
  7806. Graph.prototype.deleteTableRow = function(cell)
  7807. {
  7808. var model = this.getModel();
  7809. model.beginUpdate();
  7810. try
  7811. {
  7812. var table = cell;
  7813. var row = cell;
  7814. if (this.isTableCell(cell))
  7815. {
  7816. row = model.getParent(cell);
  7817. cell = row;
  7818. }
  7819. if (this.isTableRow(cell))
  7820. {
  7821. table = model.getParent(row);
  7822. }
  7823. var rows = model.getChildCells(table, true);
  7824. if (rows.length <= 1)
  7825. {
  7826. model.remove(table);
  7827. }
  7828. else
  7829. {
  7830. if (!this.isTableRow(row))
  7831. {
  7832. row = rows[rows.length - 1];
  7833. }
  7834. model.remove(row);
  7835. var height = 0;
  7836. var geo = this.getCellGeometry(row);
  7837. if (geo != null)
  7838. {
  7839. height = geo.height;
  7840. }
  7841. var tableGeo = this.getCellGeometry(table);
  7842. if (tableGeo != null)
  7843. {
  7844. tableGeo = tableGeo.clone();
  7845. tableGeo.height -= height;
  7846. model.setGeometry(table, tableGeo);
  7847. }
  7848. }
  7849. }
  7850. finally
  7851. {
  7852. model.endUpdate();
  7853. }
  7854. };
  7855. /**
  7856. * Inserts a new row into the given table.
  7857. */
  7858. Graph.prototype.insertRow = function(table, index)
  7859. {
  7860. var bd = table.tBodies[0];
  7861. var cells = bd.rows[0].cells;
  7862. var cols = 0;
  7863. // Counts columns including colspans
  7864. for (var i = 0; i < cells.length; i++)
  7865. {
  7866. var colspan = cells[i].getAttribute('colspan');
  7867. cols += (colspan != null) ? parseInt(colspan) : 1;
  7868. }
  7869. var row = bd.insertRow(index);
  7870. for (var i = 0; i < cols; i++)
  7871. {
  7872. mxUtils.br(row.insertCell(-1));
  7873. }
  7874. return row.cells[0];
  7875. };
  7876. /**
  7877. * Deletes the given column.
  7878. */
  7879. Graph.prototype.deleteRow = function(table, index)
  7880. {
  7881. table.tBodies[0].deleteRow(index);
  7882. };
  7883. /**
  7884. * Deletes the given column.
  7885. */
  7886. Graph.prototype.insertColumn = function(table, index)
  7887. {
  7888. var hd = table.tHead;
  7889. if (hd != null)
  7890. {
  7891. // TODO: use colIndex
  7892. for (var h = 0; h < hd.rows.length; h++)
  7893. {
  7894. var th = document.createElement('th');
  7895. hd.rows[h].appendChild(th);
  7896. mxUtils.br(th);
  7897. }
  7898. }
  7899. var bd = table.tBodies[0];
  7900. for (var i = 0; i < bd.rows.length; i++)
  7901. {
  7902. var cell = bd.rows[i].insertCell(index);
  7903. mxUtils.br(cell);
  7904. }
  7905. return bd.rows[0].cells[(index >= 0) ? index : bd.rows[0].cells.length - 1];
  7906. };
  7907. /**
  7908. * Deletes the given column.
  7909. */
  7910. Graph.prototype.deleteColumn = function(table, index)
  7911. {
  7912. if (index >= 0)
  7913. {
  7914. var bd = table.tBodies[0];
  7915. var rows = bd.rows;
  7916. for (var i = 0; i < rows.length; i++)
  7917. {
  7918. if (rows[i].cells.length > index)
  7919. {
  7920. rows[i].deleteCell(index);
  7921. }
  7922. }
  7923. }
  7924. };
  7925. /**
  7926. * Inserts the given HTML at the caret position (no undo).
  7927. */
  7928. Graph.prototype.pasteHtmlAtCaret = function(html)
  7929. {
  7930. var sel, range;
  7931. // IE9 and non-IE
  7932. if (window.getSelection)
  7933. {
  7934. sel = window.getSelection();
  7935. if (sel.getRangeAt && sel.rangeCount)
  7936. {
  7937. range = sel.getRangeAt(0);
  7938. range.deleteContents();
  7939. // Range.createContextualFragment() would be useful here but is
  7940. // only relatively recently standardized and is not supported in
  7941. // some browsers (IE9, for one)
  7942. var el = document.createElement("div");
  7943. el.innerHTML = html;
  7944. var frag = document.createDocumentFragment(), node;
  7945. while ((node = el.firstChild))
  7946. {
  7947. lastNode = frag.appendChild(node);
  7948. }
  7949. range.insertNode(frag);
  7950. }
  7951. }
  7952. // IE < 9
  7953. else if ((sel = document.selection) && sel.type != "Control")
  7954. {
  7955. // FIXME: Does not work if selection is empty
  7956. sel.createRange().pasteHTML(html);
  7957. }
  7958. };
  7959. /**
  7960. * Creates an anchor elements for handling the given link in the
  7961. * hint that is shown when the cell is selected.
  7962. */
  7963. Graph.prototype.createLinkForHint = function(link, label)
  7964. {
  7965. link = (link != null) ? link : 'javascript:void(0);';
  7966. if (label == null || label.length == 0)
  7967. {
  7968. if (this.isCustomLink(link))
  7969. {
  7970. label = this.getLinkTitle(link);
  7971. }
  7972. else
  7973. {
  7974. label = link;
  7975. }
  7976. }
  7977. // Helper function to shorten strings
  7978. function short(str, max)
  7979. {
  7980. if (str.length > max)
  7981. {
  7982. str = str.substring(0, Math.round(max / 2)) + '...' +
  7983. str.substring(str.length - Math.round(max / 4));
  7984. }
  7985. return str;
  7986. };
  7987. var a = document.createElement('a');
  7988. a.setAttribute('rel', this.linkRelation);
  7989. a.setAttribute('href', this.getAbsoluteUrl(link));
  7990. a.setAttribute('title', short((this.isCustomLink(link)) ?
  7991. this.getLinkTitle(link) : link, 80));
  7992. if (this.linkTarget != null)
  7993. {
  7994. a.setAttribute('target', this.linkTarget);
  7995. }
  7996. // Adds shortened label to link
  7997. mxUtils.write(a, short(label, 40));
  7998. // Handles custom links
  7999. if (this.isCustomLink(link))
  8000. {
  8001. mxEvent.addListener(a, 'click', mxUtils.bind(this, function(evt)
  8002. {
  8003. this.customLinkClicked(link);
  8004. mxEvent.consume(evt);
  8005. }));
  8006. }
  8007. return a;
  8008. };
  8009. /**
  8010. * Customized graph for touch devices.
  8011. */
  8012. Graph.prototype.initTouch = function()
  8013. {
  8014. // Disables new connections via "hotspot"
  8015. this.connectionHandler.marker.isEnabled = function()
  8016. {
  8017. return this.graph.connectionHandler.first != null;
  8018. };
  8019. // Hides menu when editing starts
  8020. this.addListener(mxEvent.START_EDITING, function(sender, evt)
  8021. {
  8022. this.popupMenuHandler.hideMenu();
  8023. });
  8024. // Adds custom hit detection if native hit detection found no cell
  8025. var graphUpdateMouseEvent = this.updateMouseEvent;
  8026. this.updateMouseEvent = function(me)
  8027. {
  8028. me = graphUpdateMouseEvent.apply(this, arguments);
  8029. if (mxEvent.isTouchEvent(me.getEvent()) && me.getState() == null)
  8030. {
  8031. var cell = this.getCellAt(me.graphX, me.graphY);
  8032. if (cell != null && this.isSwimlane(cell) && this.hitsSwimlaneContent(cell, me.graphX, me.graphY))
  8033. {
  8034. cell = null;
  8035. }
  8036. else
  8037. {
  8038. me.state = this.view.getState(cell);
  8039. if (me.state != null && me.state.shape != null)
  8040. {
  8041. this.container.style.cursor = me.state.shape.node.style.cursor;
  8042. }
  8043. }
  8044. }
  8045. if (me.getState() == null && this.isEnabled())
  8046. {
  8047. this.container.style.cursor = 'default';
  8048. }
  8049. return me;
  8050. };
  8051. // Context menu trigger implementation depending on current selection state
  8052. // combined with support for normal popup trigger.
  8053. var cellSelected = false;
  8054. var selectionEmpty = false;
  8055. var menuShowing = false;
  8056. var oldFireMouseEvent = this.fireMouseEvent;
  8057. this.fireMouseEvent = function(evtName, me, sender)
  8058. {
  8059. if (evtName == mxEvent.MOUSE_DOWN)
  8060. {
  8061. // For hit detection on edges
  8062. me = this.updateMouseEvent(me);
  8063. cellSelected = this.isCellSelected(me.getCell());
  8064. selectionEmpty = this.isSelectionEmpty();
  8065. menuShowing = this.popupMenuHandler.isMenuShowing();
  8066. }
  8067. oldFireMouseEvent.apply(this, arguments);
  8068. };
  8069. // Shows popup menu if cell was selected or selection was empty and background was clicked
  8070. // FIXME: Conflicts with mxPopupMenuHandler.prototype.getCellForPopupEvent in Editor.js by
  8071. // selecting parent for selected children in groups before this check can be made.
  8072. this.popupMenuHandler.mouseUp = mxUtils.bind(this, function(sender, me)
  8073. {
  8074. this.popupMenuHandler.popupTrigger = !this.isEditing() && this.isEnabled() &&
  8075. (me.getState() == null || !me.isSource(me.getState().control)) &&
  8076. (this.popupMenuHandler.popupTrigger || (!menuShowing && !mxEvent.isMouseEvent(me.getEvent()) &&
  8077. ((selectionEmpty && me.getCell() == null && this.isSelectionEmpty()) ||
  8078. (cellSelected && this.isCellSelected(me.getCell())))));
  8079. mxPopupMenuHandler.prototype.mouseUp.apply(this.popupMenuHandler, arguments);
  8080. });
  8081. };
  8082. /**
  8083. * HTML in-place editor
  8084. */
  8085. mxCellEditor.prototype.isContentEditing = function()
  8086. {
  8087. var state = this.graph.view.getState(this.editingCell);
  8088. return state != null && state.style['html'] == 1;
  8089. };
  8090. /**
  8091. * Returns true if all selected text is inside a table element.
  8092. */
  8093. mxCellEditor.prototype.isTableSelected = function()
  8094. {
  8095. return this.graph.getParentByName(
  8096. this.graph.getSelectedElement(),
  8097. 'TABLE', this.textarea) != null;
  8098. };
  8099. /**
  8100. * Sets the alignment of the current selected cell. This sets the
  8101. * alignment in the cell style, removes all alignment within the
  8102. * text and invokes the built-in alignment function.
  8103. *
  8104. * Only the built-in function is invoked if shift is pressed or
  8105. * if table cells are selected and shift is not pressed.
  8106. */
  8107. mxCellEditor.prototype.alignText = function(align, evt)
  8108. {
  8109. var shiftPressed = evt != null && mxEvent.isShiftDown(evt);
  8110. if (shiftPressed || (window.getSelection != null && window.getSelection().containsNode != null))
  8111. {
  8112. var allSelected = true;
  8113. this.graph.processElements(this.textarea, function(node)
  8114. {
  8115. if (shiftPressed || window.getSelection().containsNode(node, true))
  8116. {
  8117. node.removeAttribute('align');
  8118. node.style.textAlign = null;
  8119. }
  8120. else
  8121. {
  8122. allSelected = false;
  8123. }
  8124. });
  8125. if (allSelected)
  8126. {
  8127. this.graph.cellEditor.setAlign(align);
  8128. }
  8129. }
  8130. document.execCommand('justify' + align.toLowerCase(), false, null);
  8131. };
  8132. /**
  8133. * Creates the keyboard event handler for the current graph and history.
  8134. */
  8135. mxCellEditor.prototype.saveSelection = function()
  8136. {
  8137. if (window.getSelection)
  8138. {
  8139. var sel = window.getSelection();
  8140. if (sel.getRangeAt && sel.rangeCount)
  8141. {
  8142. var ranges = [];
  8143. for (var i = 0, len = sel.rangeCount; i < len; ++i)
  8144. {
  8145. ranges.push(sel.getRangeAt(i));
  8146. }
  8147. return ranges;
  8148. }
  8149. }
  8150. else if (document.selection && document.selection.createRange)
  8151. {
  8152. return document.selection.createRange();
  8153. }
  8154. return null;
  8155. };
  8156. /**
  8157. * Creates the keyboard event handler for the current graph and history.
  8158. */
  8159. mxCellEditor.prototype.restoreSelection = function(savedSel)
  8160. {
  8161. try
  8162. {
  8163. if (savedSel)
  8164. {
  8165. if (window.getSelection)
  8166. {
  8167. sel = window.getSelection();
  8168. sel.removeAllRanges();
  8169. for (var i = 0, len = savedSel.length; i < len; ++i)
  8170. {
  8171. sel.addRange(savedSel[i]);
  8172. }
  8173. }
  8174. else if (document.selection && savedSel.select)
  8175. {
  8176. savedSel.select();
  8177. }
  8178. }
  8179. }
  8180. catch (e)
  8181. {
  8182. // ignore
  8183. }
  8184. };
  8185. /**
  8186. * Handling of special nl2Br style for not converting newlines to breaks in HTML labels.
  8187. * NOTE: Since it's easier to set this when the label is created we assume that it does
  8188. * not change during the lifetime of the mxText instance.
  8189. */
  8190. var mxCellRendererInitializeLabel = mxCellRenderer.prototype.initializeLabel;
  8191. mxCellRenderer.prototype.initializeLabel = function(state)
  8192. {
  8193. if (state.text != null)
  8194. {
  8195. state.text.replaceLinefeeds = mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  8196. }
  8197. mxCellRendererInitializeLabel.apply(this, arguments);
  8198. };
  8199. var mxConstraintHandlerUpdate = mxConstraintHandler.prototype.update;
  8200. mxConstraintHandler.prototype.update = function(me, source)
  8201. {
  8202. if (this.isKeepFocusEvent(me) || !mxEvent.isAltDown(me.getEvent()))
  8203. {
  8204. mxConstraintHandlerUpdate.apply(this, arguments);
  8205. }
  8206. else
  8207. {
  8208. this.reset();
  8209. }
  8210. };
  8211. /**
  8212. * No dashed shapes.
  8213. */
  8214. mxGuide.prototype.createGuideShape = function(horizontal)
  8215. {
  8216. var guide = new mxPolyline([], mxConstants.GUIDE_COLOR, mxConstants.GUIDE_STROKEWIDTH);
  8217. return guide;
  8218. };
  8219. /**
  8220. * HTML in-place editor
  8221. */
  8222. mxCellEditor.prototype.escapeCancelsEditing = false;
  8223. /**
  8224. * Overridden to set CSS classes.
  8225. */
  8226. var mxCellEditorStartEditing = mxCellEditor.prototype.startEditing;
  8227. mxCellEditor.prototype.startEditing = function(cell, trigger)
  8228. {
  8229. cell = this.graph.getStartEditingCell(cell, trigger);
  8230. mxCellEditorStartEditing.apply(this, arguments);
  8231. // Overrides class in case of HTML content to add
  8232. // dashed borders for divs and table cells
  8233. var state = this.graph.view.getState(cell);
  8234. if (state != null && state.style['html'] == 1)
  8235. {
  8236. this.textarea.className = 'mxCellEditor geContentEditable';
  8237. }
  8238. else
  8239. {
  8240. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  8241. }
  8242. // Toggles markup vs wysiwyg mode
  8243. this.codeViewMode = false;
  8244. // Stores current selection range when switching between markup and code
  8245. this.switchSelectionState = null;
  8246. // Selects editing cell
  8247. this.graph.setSelectionCell(cell);
  8248. // Enables focus outline for edges and edge labels
  8249. var parent = this.graph.getModel().getParent(cell);
  8250. var geo = this.graph.getCellGeometry(cell);
  8251. if ((this.graph.getModel().isEdge(parent) && geo != null && geo.relative) ||
  8252. this.graph.getModel().isEdge(cell))
  8253. {
  8254. // Quirks does not support outline at all so use border instead
  8255. if (mxClient.IS_QUIRKS)
  8256. {
  8257. this.textarea.style.border = 'gray dotted 1px';
  8258. }
  8259. // IE>8 and FF on Windows uses outline default of none
  8260. else if (mxClient.IS_IE || mxClient.IS_IE11 || (mxClient.IS_FF && mxClient.IS_WIN))
  8261. {
  8262. this.textarea.style.outline = 'gray dotted 1px';
  8263. }
  8264. else
  8265. {
  8266. this.textarea.style.outline = '';
  8267. }
  8268. }
  8269. else if (mxClient.IS_QUIRKS)
  8270. {
  8271. this.textarea.style.outline = 'none';
  8272. this.textarea.style.border = '';
  8273. }
  8274. }
  8275. /**
  8276. * HTML in-place editor
  8277. */
  8278. var cellEditorInstallListeners = mxCellEditor.prototype.installListeners;
  8279. mxCellEditor.prototype.installListeners = function(elt)
  8280. {
  8281. cellEditorInstallListeners.apply(this, arguments);
  8282. // Adds a reference from the clone to the original node, recursively
  8283. function reference(node, clone)
  8284. {
  8285. clone.originalNode = node;
  8286. node = node.firstChild;
  8287. var child = clone.firstChild;
  8288. while (node != null && child != null)
  8289. {
  8290. reference(node, child);
  8291. node = node.nextSibling;
  8292. child = child.nextSibling;
  8293. }
  8294. return clone;
  8295. };
  8296. // Checks the given node for new nodes, recursively
  8297. function checkNode(node, clone)
  8298. {
  8299. if (node != null)
  8300. {
  8301. if (clone.originalNode != node)
  8302. {
  8303. cleanNode(node);
  8304. }
  8305. else
  8306. {
  8307. node = node.firstChild;
  8308. clone = clone.firstChild;
  8309. while (node != null)
  8310. {
  8311. var nextNode = node.nextSibling;
  8312. if (clone == null)
  8313. {
  8314. cleanNode(node);
  8315. }
  8316. else
  8317. {
  8318. checkNode(node, clone);
  8319. clone = clone.nextSibling;
  8320. }
  8321. node = nextNode;
  8322. }
  8323. }
  8324. }
  8325. };
  8326. // Removes unused DOM nodes and attributes, recursively
  8327. function cleanNode(node)
  8328. {
  8329. var child = node.firstChild;
  8330. while (child != null)
  8331. {
  8332. var next = child.nextSibling;
  8333. cleanNode(child);
  8334. child = next;
  8335. }
  8336. if ((node.nodeType != 1 || (node.nodeName !== 'BR' && node.firstChild == null)) &&
  8337. (node.nodeType != 3 || mxUtils.trim(mxUtils.getTextContent(node)).length == 0))
  8338. {
  8339. node.parentNode.removeChild(node);
  8340. }
  8341. else
  8342. {
  8343. // Removes linefeeds
  8344. if (node.nodeType == 3)
  8345. {
  8346. mxUtils.setTextContent(node, mxUtils.getTextContent(node).replace(/\n|\r/g, ''));
  8347. }
  8348. // Removes CSS classes and styles (for Word and Excel)
  8349. if (node.nodeType == 1)
  8350. {
  8351. node.removeAttribute('style');
  8352. node.removeAttribute('class');
  8353. node.removeAttribute('width');
  8354. node.removeAttribute('cellpadding');
  8355. node.removeAttribute('cellspacing');
  8356. node.removeAttribute('border');
  8357. }
  8358. }
  8359. };
  8360. // Handles paste from Word, Excel etc by removing styles, classnames and unused nodes
  8361. // LATER: Fix undo/redo for paste
  8362. if (!mxClient.IS_QUIRKS && document.documentMode !== 7 && document.documentMode !== 8)
  8363. {
  8364. mxEvent.addListener(this.textarea, 'paste', mxUtils.bind(this, function(evt)
  8365. {
  8366. var clone = reference(this.textarea, this.textarea.cloneNode(true));
  8367. window.setTimeout(mxUtils.bind(this, function()
  8368. {
  8369. if (this.textarea != null)
  8370. {
  8371. // Paste from Word or Excel
  8372. if (this.textarea.innerHTML.indexOf('<o:OfficeDocumentSettings>') >= 0 ||
  8373. this.textarea.innerHTML.indexOf('<!--[if !mso]>') >= 0)
  8374. {
  8375. checkNode(this.textarea, clone);
  8376. }
  8377. else
  8378. {
  8379. Graph.removePasteFormatting(this.textarea);
  8380. }
  8381. }
  8382. }), 0);
  8383. }));
  8384. }
  8385. };
  8386. mxCellEditor.prototype.toggleViewMode = function()
  8387. {
  8388. var state = this.graph.view.getState(this.editingCell);
  8389. if (state != null)
  8390. {
  8391. var nl2Br = state != null && mxUtils.getValue(state.style, 'nl2Br', '1') != '0';
  8392. var tmp = this.saveSelection();
  8393. if (!this.codeViewMode)
  8394. {
  8395. // Clears the initial empty label on the first keystroke
  8396. if (this.clearOnChange && this.textarea.innerHTML == this.getEmptyLabelText())
  8397. {
  8398. this.clearOnChange = false;
  8399. this.textarea.innerHTML = '';
  8400. }
  8401. // Removes newlines from HTML and converts breaks to newlines
  8402. // to match the HTML output in plain text
  8403. var content = mxUtils.htmlEntities(this.textarea.innerHTML);
  8404. // Workaround for trailing line breaks being ignored in the editor
  8405. if (!mxClient.IS_QUIRKS && document.documentMode != 8)
  8406. {
  8407. content = mxUtils.replaceTrailingNewlines(content, '<div><br></div>');
  8408. }
  8409. content = this.graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '').replace(/&lt;br\s*.?&gt;/g, '<br>') : content, true);
  8410. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  8411. var size = mxConstants.DEFAULT_FONTSIZE;
  8412. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  8413. this.textarea.style.fontSize = Math.round(size) + 'px';
  8414. this.textarea.style.textDecoration = '';
  8415. this.textarea.style.fontWeight = 'normal';
  8416. this.textarea.style.fontStyle = '';
  8417. this.textarea.style.fontFamily = mxConstants.DEFAULT_FONTFAMILY;
  8418. this.textarea.style.textAlign = 'left';
  8419. // Adds padding to make cursor visible with borders
  8420. this.textarea.style.padding = '2px';
  8421. if (this.textarea.innerHTML != content)
  8422. {
  8423. this.textarea.innerHTML = content;
  8424. }
  8425. this.codeViewMode = true;
  8426. }
  8427. else
  8428. {
  8429. var content = mxUtils.extractTextWithWhitespace(this.textarea.childNodes);
  8430. // Strips trailing line break
  8431. if (content.length > 0 && content.charAt(content.length - 1) == '\n')
  8432. {
  8433. content = content.substring(0, content.length - 1);
  8434. }
  8435. content = this.graph.sanitizeHtml((nl2Br) ? content.replace(/\n/g, '<br/>') : content, true)
  8436. this.textarea.className = 'mxCellEditor geContentEditable';
  8437. var size = mxUtils.getValue(state.style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  8438. var family = mxUtils.getValue(state.style, mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY);
  8439. var align = mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_LEFT);
  8440. var bold = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  8441. mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD;
  8442. var italic = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  8443. mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC;
  8444. var txtDecor = [];
  8445. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  8446. mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  8447. {
  8448. txtDecor.push('underline');
  8449. }
  8450. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  8451. mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  8452. {
  8453. txtDecor.push('line-through');
  8454. }
  8455. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  8456. this.textarea.style.fontSize = Math.round(size) + 'px';
  8457. this.textarea.style.textDecoration = txtDecor.join(' ');
  8458. this.textarea.style.fontWeight = (bold) ? 'bold' : 'normal';
  8459. this.textarea.style.fontStyle = (italic) ? 'italic' : '';
  8460. this.textarea.style.fontFamily = family;
  8461. this.textarea.style.textAlign = align;
  8462. this.textarea.style.padding = '0px';
  8463. if (this.textarea.innerHTML != content)
  8464. {
  8465. this.textarea.innerHTML = content;
  8466. if (this.textarea.innerHTML.length == 0)
  8467. {
  8468. this.textarea.innerHTML = this.getEmptyLabelText();
  8469. this.clearOnChange = this.textarea.innerHTML.length > 0;
  8470. }
  8471. }
  8472. this.codeViewMode = false;
  8473. }
  8474. this.textarea.focus();
  8475. if (this.switchSelectionState != null)
  8476. {
  8477. this.restoreSelection(this.switchSelectionState);
  8478. }
  8479. this.switchSelectionState = tmp;
  8480. this.resize();
  8481. }
  8482. };
  8483. var mxCellEditorResize = mxCellEditor.prototype.resize;
  8484. mxCellEditor.prototype.resize = function(state, trigger)
  8485. {
  8486. if (this.textarea != null)
  8487. {
  8488. var state = this.graph.getView().getState(this.editingCell);
  8489. if (this.codeViewMode && state != null)
  8490. {
  8491. var scale = state.view.scale;
  8492. this.bounds = mxRectangle.fromRectangle(state);
  8493. // General placement of code editor if cell has no size
  8494. // LATER: Fix HTML editor bounds for edge labels
  8495. if (this.bounds.width == 0 && this.bounds.height == 0)
  8496. {
  8497. this.bounds.width = 160 * scale;
  8498. this.bounds.height = 60 * scale;
  8499. var m = (state.text != null) ? state.text.margin : null;
  8500. if (m == null)
  8501. {
  8502. m = mxUtils.getAlignmentAsPoint(mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER),
  8503. mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE));
  8504. }
  8505. this.bounds.x += m.x * this.bounds.width;
  8506. this.bounds.y += m.y * this.bounds.height;
  8507. }
  8508. this.textarea.style.width = Math.round((this.bounds.width - 4) / scale) + 'px';
  8509. this.textarea.style.height = Math.round((this.bounds.height - 4) / scale) + 'px';
  8510. this.textarea.style.overflow = 'auto';
  8511. // Adds scrollbar offset if visible
  8512. if (this.textarea.clientHeight < this.textarea.offsetHeight)
  8513. {
  8514. this.textarea.style.height = Math.round((this.bounds.height / scale)) + (this.textarea.offsetHeight - this.textarea.clientHeight) + 'px';
  8515. this.bounds.height = parseInt(this.textarea.style.height) * scale;
  8516. }
  8517. if (this.textarea.clientWidth < this.textarea.offsetWidth)
  8518. {
  8519. this.textarea.style.width = Math.round((this.bounds.width / scale)) + (this.textarea.offsetWidth - this.textarea.clientWidth) + 'px';
  8520. this.bounds.width = parseInt(this.textarea.style.width) * scale;
  8521. }
  8522. this.textarea.style.left = Math.round(this.bounds.x) + 'px';
  8523. this.textarea.style.top = Math.round(this.bounds.y) + 'px';
  8524. if (mxClient.IS_VML)
  8525. {
  8526. this.textarea.style.zoom = scale;
  8527. }
  8528. else
  8529. {
  8530. mxUtils.setPrefixedStyle(this.textarea.style, 'transform', 'scale(' + scale + ',' + scale + ')');
  8531. }
  8532. }
  8533. else
  8534. {
  8535. this.textarea.style.height = '';
  8536. this.textarea.style.overflow = '';
  8537. mxCellEditorResize.apply(this, arguments);
  8538. }
  8539. }
  8540. };
  8541. mxCellEditorGetInitialValue = mxCellEditor.prototype.getInitialValue;
  8542. mxCellEditor.prototype.getInitialValue = function(state, trigger)
  8543. {
  8544. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  8545. {
  8546. return mxCellEditorGetInitialValue.apply(this, arguments);
  8547. }
  8548. else
  8549. {
  8550. var result = this.graph.getEditingValue(state.cell, trigger)
  8551. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  8552. {
  8553. result = result.replace(/\n/g, '<br/>');
  8554. }
  8555. result = this.graph.sanitizeHtml(result, true);
  8556. return result;
  8557. }
  8558. };
  8559. mxCellEditorGetCurrentValue = mxCellEditor.prototype.getCurrentValue;
  8560. mxCellEditor.prototype.getCurrentValue = function(state)
  8561. {
  8562. if (mxUtils.getValue(state.style, 'html', '0') == '0')
  8563. {
  8564. return mxCellEditorGetCurrentValue.apply(this, arguments);
  8565. }
  8566. else
  8567. {
  8568. var result = this.graph.sanitizeHtml(this.textarea.innerHTML, true);
  8569. if (mxUtils.getValue(state.style, 'nl2Br', '1') == '1')
  8570. {
  8571. result = result.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
  8572. }
  8573. else
  8574. {
  8575. result = result.replace(/\r\n/g, '').replace(/\n/g, '');
  8576. }
  8577. return result;
  8578. }
  8579. };
  8580. var mxCellEditorStopEditing = mxCellEditor.prototype.stopEditing;
  8581. mxCellEditor.prototype.stopEditing = function(cancel)
  8582. {
  8583. // Restores default view mode before applying value
  8584. if (this.codeViewMode)
  8585. {
  8586. this.toggleViewMode();
  8587. }
  8588. mxCellEditorStopEditing.apply(this, arguments);
  8589. // Tries to move focus back to container after editing if possible
  8590. this.focusContainer();
  8591. };
  8592. mxCellEditor.prototype.focusContainer = function()
  8593. {
  8594. try
  8595. {
  8596. this.graph.container.focus();
  8597. }
  8598. catch (e)
  8599. {
  8600. // ignore
  8601. }
  8602. };
  8603. var mxCellEditorApplyValue = mxCellEditor.prototype.applyValue;
  8604. mxCellEditor.prototype.applyValue = function(state, value)
  8605. {
  8606. // Removes empty relative child labels in edges
  8607. this.graph.getModel().beginUpdate();
  8608. try
  8609. {
  8610. mxCellEditorApplyValue.apply(this, arguments);
  8611. if (value == '' && this.graph.isCellDeletable(state.cell) &&
  8612. this.graph.model.getChildCount(state.cell) == 0 &&
  8613. this.graph.isTransparentState(state))
  8614. {
  8615. this.graph.removeCells([state.cell], false);
  8616. }
  8617. }
  8618. finally
  8619. {
  8620. this.graph.getModel().endUpdate();
  8621. }
  8622. };
  8623. /**
  8624. * Returns the background color to be used for the editing box. This returns
  8625. * the label background for edge labels and null for all other cases.
  8626. */
  8627. mxCellEditor.prototype.getBackgroundColor = function(state)
  8628. {
  8629. var color = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, null);
  8630. if ((color == null || color == mxConstants.NONE) &&
  8631. (state.cell.geometry != null && state.cell.geometry.width > 0) &&
  8632. (mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION, 0) != 0 ||
  8633. mxUtils.getValue(state.style, mxConstants.STYLE_HORIZONTAL, 1) == 0))
  8634. {
  8635. color = mxUtils.getValue(state.style, mxConstants.STYLE_FILLCOLOR, null);
  8636. }
  8637. if (color == mxConstants.NONE)
  8638. {
  8639. color = null;
  8640. }
  8641. return color;
  8642. };
  8643. mxCellEditor.prototype.getMinimumSize = function(state)
  8644. {
  8645. var scale = this.graph.getView().scale;
  8646. return new mxRectangle(0, 0, (state.text == null) ? 30 : state.text.size * scale + 20, 30);
  8647. };
  8648. /**
  8649. * Hold Alt to ignore drop target.
  8650. */
  8651. mxGraphHandlerIsValidDropTarget = mxGraphHandler.prototype.isValidDropTarget;
  8652. mxGraphHandler.prototype.isValidDropTarget = function(target, me)
  8653. {
  8654. return mxGraphHandlerIsValidDropTarget.apply(this, arguments) &&
  8655. !mxEvent.isAltDown(me.getEvent);
  8656. };
  8657. /**
  8658. * Hints on handlers
  8659. */
  8660. function createHint()
  8661. {
  8662. var hint = document.createElement('div');
  8663. hint.className = 'geHint';
  8664. hint.style.whiteSpace = 'nowrap';
  8665. hint.style.position = 'absolute';
  8666. return hint;
  8667. };
  8668. /**
  8669. * Format pixels in the given unit
  8670. */
  8671. function formatHintText(pixels, unit)
  8672. {
  8673. switch(unit)
  8674. {
  8675. case mxConstants.POINTS:
  8676. return pixels;
  8677. case mxConstants.MILLIMETERS:
  8678. return (pixels / mxConstants.PIXELS_PER_MM).toFixed(1);
  8679. case mxConstants.INCHES:
  8680. return (pixels / mxConstants.PIXELS_PER_INCH).toFixed(2);
  8681. }
  8682. };
  8683. mxGraphView.prototype.formatUnitText = function(pixels)
  8684. {
  8685. return pixels? formatHintText(pixels, this.unit) : pixels;
  8686. };
  8687. /**
  8688. * Updates the hint for the current operation.
  8689. */
  8690. mxGraphHandler.prototype.updateHint = function(me)
  8691. {
  8692. if (this.pBounds != null && (this.shape != null || this.livePreviewActive))
  8693. {
  8694. if (this.hint == null)
  8695. {
  8696. this.hint = createHint();
  8697. this.graph.container.appendChild(this.hint);
  8698. }
  8699. var t = this.graph.view.translate;
  8700. var s = this.graph.view.scale;
  8701. var x = this.roundLength((this.bounds.x + this.currentDx) / s - t.x);
  8702. var y = this.roundLength((this.bounds.y + this.currentDy) / s - t.y);
  8703. var unit = this.graph.view.unit;
  8704. this.hint.innerHTML = formatHintText(x, unit) + ', ' + formatHintText(y, unit);
  8705. this.hint.style.left = (this.pBounds.x + this.currentDx +
  8706. Math.round((this.pBounds.width - this.hint.clientWidth) / 2)) + 'px';
  8707. this.hint.style.top = (this.pBounds.y + this.currentDy +
  8708. this.pBounds.height + Editor.hintOffset) + 'px';
  8709. }
  8710. };
  8711. /**
  8712. * Updates the hint for the current operation.
  8713. */
  8714. mxGraphHandler.prototype.removeHint = function()
  8715. {
  8716. if (this.hint != null)
  8717. {
  8718. this.hint.parentNode.removeChild(this.hint);
  8719. this.hint = null;
  8720. }
  8721. };
  8722. /**
  8723. * Overridden to allow for shrinking pools when lanes are resized.
  8724. */
  8725. var stackLayoutResizeCell = mxStackLayout.prototype.resizeCell;
  8726. mxStackLayout.prototype.resizeCell = function(cell, bounds)
  8727. {
  8728. stackLayoutResizeCell.apply(this, arguments);
  8729. var style = this.graph.getCellStyle(cell);
  8730. if (style['childLayout'] == null)
  8731. {
  8732. var parent = this.graph.model.getParent(cell);
  8733. var geo = (parent != null) ? this.graph.getCellGeometry(parent) : null;
  8734. if (geo != null)
  8735. {
  8736. style = this.graph.getCellStyle(parent);
  8737. if (style['childLayout'] == 'stackLayout')
  8738. {
  8739. var border = parseFloat(mxUtils.getValue(style, 'stackBorder', mxStackLayout.prototype.border));
  8740. var horizontal = mxUtils.getValue(style, 'horizontalStack', '1') == '1';
  8741. var start = this.graph.getActualStartSize(parent);
  8742. geo = geo.clone();
  8743. if (horizontal)
  8744. {
  8745. geo.height = bounds.height + start.y + start.height + 2 * border;
  8746. }
  8747. else
  8748. {
  8749. geo.width = bounds.width + start.x + start.width + 2 * border;
  8750. }
  8751. this.graph.model.setGeometry(parent, geo);
  8752. }
  8753. }
  8754. }
  8755. };
  8756. /**
  8757. * Shows handle for table instead of rows and cells.
  8758. */
  8759. var selectionCellsHandlerGetHandledSelectionCells = mxSelectionCellsHandler.prototype.getHandledSelectionCells;
  8760. mxSelectionCellsHandler.prototype.getHandledSelectionCells = function()
  8761. {
  8762. var cells = selectionCellsHandlerGetHandledSelectionCells.apply(this, arguments);
  8763. var dict = new mxDictionary();
  8764. var model = this.graph.model;
  8765. var result = [];
  8766. function addCell(cell)
  8767. {
  8768. if (!dict.get(cell))
  8769. {
  8770. dict.put(cell, true);
  8771. result.push(cell);
  8772. }
  8773. };
  8774. for (var i = 0; i < cells.length; i++)
  8775. {
  8776. var cell = cells[i];
  8777. if (this.graph.isTableCell(cell))
  8778. {
  8779. addCell(model.getParent(model.getParent(cell)));
  8780. }
  8781. else if (this.graph.isTableRow(cell))
  8782. {
  8783. addCell(model.getParent(cell));
  8784. }
  8785. addCell(cell);
  8786. }
  8787. return result;
  8788. };
  8789. /**
  8790. * Creates the shape used to draw the selection border.
  8791. */
  8792. var vertexHandlerCreateParentHighlightShape = mxVertexHandler.prototype.createParentHighlightShape;
  8793. mxVertexHandler.prototype.createParentHighlightShape = function(bounds)
  8794. {
  8795. var shape = vertexHandlerCreateParentHighlightShape.apply(this, arguments);
  8796. shape.stroke = '#C0C0C0';
  8797. shape.strokewidth = 1;
  8798. return shape;
  8799. };
  8800. /**
  8801. * Creates the shape used to draw the selection border.
  8802. */
  8803. var edgeHandlerCreateParentHighlightShape = mxEdgeHandler.prototype.createParentHighlightShape;
  8804. mxEdgeHandler.prototype.createParentHighlightShape = function(bounds)
  8805. {
  8806. var shape = edgeHandlerCreateParentHighlightShape.apply(this, arguments);
  8807. shape.stroke = '#C0C0C0';
  8808. shape.strokewidth = 1;
  8809. return shape;
  8810. };
  8811. /**
  8812. * Moves rotation handle to top, right corner.
  8813. */
  8814. mxVertexHandler.prototype.rotationHandleVSpacing = -12;
  8815. mxVertexHandler.prototype.getRotationHandlePosition = function()
  8816. {
  8817. var padding = this.getHandlePadding();
  8818. return new mxPoint(this.bounds.x + this.bounds.width - this.rotationHandleVSpacing + padding.x / 2,
  8819. this.bounds.y + this.rotationHandleVSpacing - padding.y / 2)
  8820. };
  8821. /**
  8822. * Enables recursive resize for groups.
  8823. */
  8824. mxVertexHandler.prototype.isRecursiveResize = function(state, me)
  8825. {
  8826. return this.graph.isRecursiveVertexResize(state) &&
  8827. !mxEvent.isControlDown(me.getEvent());
  8828. };
  8829. /**
  8830. * Enables centered resize events.
  8831. */
  8832. mxVertexHandler.prototype.isCenteredEvent = function(state, me)
  8833. {
  8834. return (!(!this.graph.isSwimlane(state.cell) && this.graph.model.getChildCount(state.cell) > 0 &&
  8835. !this.graph.isCellCollapsed(state.cell) &&
  8836. mxUtils.getValue(state.style, 'recursiveResize', '1') == '1' &&
  8837. mxUtils.getValue(state.style, 'childLayout', null) == null) &&
  8838. mxEvent.isControlDown(me.getEvent())) ||
  8839. mxEvent.isMetaDown(me.getEvent());
  8840. };
  8841. /**
  8842. * Hides rotation handle for table cells and rows.
  8843. */
  8844. var vertexHandlerIsRotationHandleVisible = mxVertexHandler.prototype.isRotationHandleVisible;
  8845. mxVertexHandler.prototype.isRotationHandleVisible = function()
  8846. {
  8847. return vertexHandlerIsRotationHandleVisible.apply(this, arguments) &&
  8848. !this.graph.isTableCell(this.state.cell) &&
  8849. !this.graph.isTableRow(this.state.cell) &&
  8850. !this.graph.isTable(this.state.cell);
  8851. };
  8852. /**
  8853. * Hides rotation handle for table cells and rows.
  8854. */
  8855. mxVertexHandler.prototype.getSizerBounds = function()
  8856. {
  8857. if (this.graph.isTableCell(this.state.cell))
  8858. {
  8859. return this.graph.view.getState(this.graph.model.getParent(this.graph.model.getParent(this.state.cell)));
  8860. }
  8861. else
  8862. {
  8863. return this.bounds;
  8864. }
  8865. };
  8866. /**
  8867. * Hides rotation handle for table cells and rows.
  8868. */
  8869. var vertexHandlerIsParentHighlightVisible = mxVertexHandler.prototype.isParentHighlightVisible;
  8870. mxVertexHandler.prototype.isParentHighlightVisible = function()
  8871. {
  8872. return vertexHandlerIsParentHighlightVisible.apply(this, arguments) &&
  8873. !this.graph.isTableCell(this.state.cell) &&
  8874. !this.graph.isTableRow(this.state.cell);
  8875. };
  8876. /**
  8877. * Hides rotation handle for table cells and rows.
  8878. */
  8879. var vertexHandlerIsCustomHandleVisible = mxVertexHandler.prototype.isCustomHandleVisible;
  8880. mxVertexHandler.prototype.isCustomHandleVisible = function(handle)
  8881. {
  8882. return handle.tableHandle ||
  8883. (vertexHandlerIsCustomHandleVisible.apply(this, arguments) &&
  8884. (!this.graph.isTable(this.state.cell) ||
  8885. this.graph.isCellSelected(this.state.cell)));
  8886. };
  8887. /**
  8888. * Adds selection border inset for table cells and rows.
  8889. */
  8890. mxVertexHandler.prototype.getSelectionBorderInset = function()
  8891. {
  8892. var result = 0;
  8893. if (this.graph.isTableRow(this.state.cell))
  8894. {
  8895. result = 1;
  8896. }
  8897. else if (this.graph.isTableCell(this.state.cell))
  8898. {
  8899. result = 2;
  8900. }
  8901. return result;
  8902. };
  8903. /**
  8904. * Adds custom handles for table cells.
  8905. */
  8906. var vertexHandlerGetSelectionBorderBounds = mxVertexHandler.prototype.getSelectionBorderBounds;
  8907. mxVertexHandler.prototype.getSelectionBorderBounds = function()
  8908. {
  8909. return vertexHandlerGetSelectionBorderBounds.apply(this, arguments).grow(
  8910. -this.getSelectionBorderInset());
  8911. };
  8912. /**
  8913. * Adds custom handles for table cells.
  8914. */
  8915. var vertexHandlerCreateCustomHandles = mxVertexHandler.prototype.createCustomHandles;
  8916. mxVertexHandler.prototype.createCustomHandles = function()
  8917. {
  8918. var handles = vertexHandlerCreateCustomHandles.apply(this, arguments);
  8919. if (this.graph.isTable(this.state.cell))
  8920. {
  8921. var graph = this.graph;
  8922. var model = graph.model;
  8923. var tableState = this.state;
  8924. var sel = this.selectionBorder;
  8925. var self = this;
  8926. if (handles == null)
  8927. {
  8928. handles = [];
  8929. }
  8930. // Adds handles for rows and columns
  8931. var rows = graph.view.getCellStates(model.getChildCells(this.state.cell, true));
  8932. if (rows.length > 0)
  8933. {
  8934. var cols = graph.view.getCellStates(model.getChildCells(rows[0].cell, true));
  8935. // Adds column width handles
  8936. for (var i = 0; i < cols.length; i++)
  8937. {
  8938. (mxUtils.bind(this, function(index)
  8939. {
  8940. var colState = cols[index];
  8941. var nextCol = (index < cols.length - 1) ? cols[index + 1] : null;
  8942. var shape = new mxLine(new mxRectangle(), mxConstants.NONE, 1, true);
  8943. shape.isDashed = sel.isDashed;
  8944. // Workaround for event handling on overlapping cells with tolerance
  8945. shape.svgStrokeTolerance++;
  8946. var handle = new mxHandle(colState, 'col-resize', null, shape);
  8947. handle.tableHandle = true;
  8948. var dx = 0;
  8949. handle.shape.node.parentNode.insertBefore(handle.shape.node,
  8950. handle.shape.node.parentNode.firstChild);
  8951. handle.redraw = function()
  8952. {
  8953. if (this.shape != null && this.state.shape != null)
  8954. {
  8955. var start = graph.getActualStartSize(tableState.cell);
  8956. this.shape.stroke = (dx == 0) ? mxConstants.NONE : sel.stroke;
  8957. this.shape.bounds.x = this.state.x + this.state.width +
  8958. dx * this.graph.view.scale;
  8959. this.shape.bounds.width = 1;
  8960. this.shape.bounds.y = tableState.y + ((index == cols.length - 1) ?
  8961. 0 : start.y * this.graph.view.scale);
  8962. this.shape.bounds.height = tableState.height -
  8963. ((index == cols.length - 1) ? 0 :
  8964. (start.height + start.y) * this.graph.view.scale);
  8965. this.shape.redraw();
  8966. }
  8967. };
  8968. var shiftPressed = false;
  8969. handle.setPosition = function(bounds, pt, me)
  8970. {
  8971. dx = Math.max(Graph.minTableColumnWidth - bounds.width,
  8972. pt.x - bounds.x - bounds.width);
  8973. shiftPressed = mxEvent.isShiftDown(me.getEvent());
  8974. if (nextCol != null && !shiftPressed)
  8975. {
  8976. dx = Math.min((nextCol.x + nextCol.width - colState.x -
  8977. colState.width) / graph.view.scale -
  8978. Graph.minTableColumnWidth, dx);
  8979. }
  8980. };
  8981. handle.execute = function(me)
  8982. {
  8983. if (dx != 0)
  8984. {
  8985. graph.setTableColumnWidth(this.state.cell,
  8986. dx, shiftPressed);
  8987. }
  8988. else if (!self.blockDelayedSelection)
  8989. {
  8990. var temp = graph.getCellAt(me.getGraphX(), me.getGraphY()) || tableState.cell;
  8991. graph.graphHandler.selectCellForEvent(temp, me);
  8992. }
  8993. dx = 0;
  8994. };
  8995. handle.reset = function()
  8996. {
  8997. dx = 0;
  8998. };
  8999. handles.push(handle);
  9000. }))(i);
  9001. }
  9002. // Adds row height handles
  9003. for (var i = 0; i < rows.length; i++)
  9004. {
  9005. (mxUtils.bind(this, function(index)
  9006. {
  9007. var rowState = rows[index];
  9008. var shape = new mxLine(new mxRectangle(), mxConstants.NONE, 1);
  9009. shape.isDashed = sel.isDashed;
  9010. shape.svgStrokeTolerance++;
  9011. var handle = new mxHandle(rowState, 'row-resize', null, shape);
  9012. handle.tableHandle = true;
  9013. var dy = 0;
  9014. handle.shape.node.parentNode.insertBefore(handle.shape.node,
  9015. handle.shape.node.parentNode.firstChild);
  9016. handle.redraw = function()
  9017. {
  9018. if (this.shape != null && this.state.shape != null)
  9019. {
  9020. this.shape.stroke = (dy == 0) ? mxConstants.NONE : sel.stroke;
  9021. this.shape.bounds.x = this.state.x;
  9022. this.shape.bounds.width = this.state.width;
  9023. this.shape.bounds.y = this.state.y + this.state.height +
  9024. dy * this.graph.view.scale;
  9025. this.shape.bounds.height = 1;
  9026. this.shape.redraw();
  9027. }
  9028. };
  9029. handle.setPosition = function(bounds, pt, me)
  9030. {
  9031. dy = Math.max(Graph.minTableRowHeight - bounds.height,
  9032. pt.y - bounds.y - bounds.height);
  9033. };
  9034. handle.execute = function(me)
  9035. {
  9036. if (dy != 0)
  9037. {
  9038. graph.setTableRowHeight(this.state.cell, dy,
  9039. !mxEvent.isShiftDown(me.getEvent()));
  9040. }
  9041. else if (!self.blockDelayedSelection)
  9042. {
  9043. var temp = graph.getCellAt(me.getGraphX(), me.getGraphY()) || tableState.cell;
  9044. graph.graphHandler.selectCellForEvent(temp, me);
  9045. }
  9046. dy = 0;
  9047. };
  9048. handle.reset = function()
  9049. {
  9050. dy = 0;
  9051. };
  9052. handles.push(handle);
  9053. }))(i);
  9054. }
  9055. }
  9056. }
  9057. // Reserve gives point handles precedence over line handles
  9058. return (handles != null) ? handles.reverse() : null;
  9059. };
  9060. var vertexHandlerSetHandlesVisible = mxVertexHandler.prototype.setHandlesVisible;
  9061. mxVertexHandler.prototype.setHandlesVisible = function(visible)
  9062. {
  9063. vertexHandlerSetHandlesVisible.apply(this, arguments);
  9064. if (this.moveHandles != null)
  9065. {
  9066. for (var i = 0; i < this.moveHandles.length; i++)
  9067. {
  9068. this.moveHandles[i].style.visibility = (visible) ? '' : 'hidden';
  9069. }
  9070. }
  9071. if (this.cornerHandles != null)
  9072. {
  9073. for (var i = 0; i < this.cornerHandles.length; i++)
  9074. {
  9075. this.cornerHandles[i].node.style.visibility = (visible) ? '' : 'hidden';
  9076. }
  9077. }
  9078. };
  9079. /**
  9080. * Creates or updates special handles for moving rows.
  9081. */
  9082. mxVertexHandler.prototype.refreshMoveHandles = function()
  9083. {
  9084. var graph = this.graph;
  9085. var model = graph.model;
  9086. // Destroys existing handles
  9087. if (this.moveHandles != null)
  9088. {
  9089. for (var i = 0; i < this.moveHandles.length; i++)
  9090. {
  9091. this.moveHandles[i].parentNode.removeChild(this.moveHandles[i]);
  9092. }
  9093. this.moveHandles = null;
  9094. }
  9095. // Creates new handles
  9096. this.moveHandles = [];
  9097. for (var i = 0; i < model.getChildCount(this.state.cell); i++)
  9098. {
  9099. (mxUtils.bind(this, function(rowState)
  9100. {
  9101. if (rowState != null && model.isVertex(rowState.cell))
  9102. {
  9103. // Adds handle to move row
  9104. // LATER: Move to overlay pane to hide during zoom but keep padding
  9105. var moveHandle = mxUtils.createImage(Editor.rowMoveImage);
  9106. moveHandle.style.position = 'absolute';
  9107. moveHandle.style.cursor = 'pointer';
  9108. moveHandle.style.width = '7px';
  9109. moveHandle.style.height = '4px';
  9110. moveHandle.style.padding = '4px 2px 4px 2px';
  9111. moveHandle.rowState = rowState;
  9112. mxEvent.addGestureListeners(moveHandle, mxUtils.bind(this, function(evt)
  9113. {
  9114. this.graph.popupMenuHandler.hideMenu();
  9115. this.graph.stopEditing(false);
  9116. if (this.graph.isToggleEvent(evt) ||
  9117. !this.graph.isCellSelected(rowState.cell))
  9118. {
  9119. this.graph.selectCellForEvent(rowState.cell, evt);
  9120. }
  9121. if (!mxEvent.isPopupTrigger(evt))
  9122. {
  9123. this.graph.graphHandler.start(this.state.cell,
  9124. mxEvent.getClientX(evt), mxEvent.getClientY(evt),
  9125. this.graph.getSelectionCells());
  9126. this.graph.graphHandler.cellWasClicked = true;
  9127. this.graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  9128. this.graph.isMouseDown = true;
  9129. }
  9130. mxEvent.consume(evt);
  9131. }), null, mxUtils.bind(this, function(evt)
  9132. {
  9133. if (mxEvent.isPopupTrigger(evt))
  9134. {
  9135. this.graph.popupMenuHandler.popup(mxEvent.getClientX(evt),
  9136. mxEvent.getClientY(evt), rowState.cell, evt);
  9137. mxEvent.consume(evt);
  9138. }
  9139. }));
  9140. this.moveHandles.push(moveHandle);
  9141. this.graph.container.appendChild(moveHandle);
  9142. }
  9143. }))(this.graph.view.getState(model.getChildAt(this.state.cell, i)));
  9144. }
  9145. };
  9146. /**
  9147. * Adds handle padding for editing cells and exceptions.
  9148. */
  9149. mxVertexHandler.prototype.refresh = function()
  9150. {
  9151. if (this.customHandles != null)
  9152. {
  9153. for (var i = 0; i < this.customHandles.length; i++)
  9154. {
  9155. this.customHandles[i].destroy();
  9156. }
  9157. this.customHandles = this.createCustomHandles();
  9158. }
  9159. if (this.graph.isTable(this.state.cell))
  9160. {
  9161. this.refreshMoveHandles();
  9162. }
  9163. };
  9164. /**
  9165. * Adds handle padding for editing cells and exceptions.
  9166. */
  9167. var vertexHandlerGetHandlePadding = mxVertexHandler.prototype.getHandlePadding;
  9168. mxVertexHandler.prototype.getHandlePadding = function()
  9169. {
  9170. var result = new mxPoint(0, 0);
  9171. var tol = this.tolerance;
  9172. var name = this.state.style['shape'];
  9173. if (mxCellRenderer.defaultShapes[name] == null &&
  9174. mxStencilRegistry.getStencil(name) == null)
  9175. {
  9176. name = mxConstants.SHAPE_RECTANGLE;
  9177. }
  9178. // Checks if custom handles are overlapping with the shape border
  9179. var handlePadding = this.graph.isTable(this.state.cell) ||
  9180. this.graph.cellEditor.getEditingCell() == this.state.cell;
  9181. if (!handlePadding)
  9182. {
  9183. if (this.customHandles != null)
  9184. {
  9185. for (var i = 0; i < this.customHandles.length; i++)
  9186. {
  9187. if (this.customHandles[i].shape != null &&
  9188. this.customHandles[i].shape.bounds != null)
  9189. {
  9190. var b = this.customHandles[i].shape.bounds;
  9191. var px = b.getCenterX();
  9192. var py = b.getCenterY();
  9193. if ((Math.abs(this.state.x - px) < b.width / 2) ||
  9194. (Math.abs(this.state.y - py) < b.height / 2) ||
  9195. (Math.abs(this.state.x + this.state.width - px) < b.width / 2) ||
  9196. (Math.abs(this.state.y + this.state.height - py) < b.height / 2))
  9197. {
  9198. handlePadding = true;
  9199. break;
  9200. }
  9201. }
  9202. }
  9203. }
  9204. }
  9205. if (handlePadding && this.sizers != null &&
  9206. this.sizers.length > 0 && this.sizers[0] != null)
  9207. {
  9208. tol /= 2;
  9209. // Makes room for row move handle
  9210. if (this.graph.isTable(this.state.cell))
  9211. {
  9212. tol += 7;
  9213. }
  9214. result.x = this.sizers[0].bounds.width + tol;
  9215. result.y = this.sizers[0].bounds.height + tol;
  9216. }
  9217. else
  9218. {
  9219. result = vertexHandlerGetHandlePadding.apply(this, arguments);
  9220. }
  9221. return result;
  9222. };
  9223. /**
  9224. * Updates the hint for the current operation.
  9225. */
  9226. mxVertexHandler.prototype.updateHint = function(me)
  9227. {
  9228. if (this.index != mxEvent.LABEL_HANDLE)
  9229. {
  9230. if (this.hint == null)
  9231. {
  9232. this.hint = createHint();
  9233. this.state.view.graph.container.appendChild(this.hint);
  9234. }
  9235. if (this.index == mxEvent.ROTATION_HANDLE)
  9236. {
  9237. this.hint.innerHTML = this.currentAlpha + '&deg;';
  9238. }
  9239. else
  9240. {
  9241. var s = this.state.view.scale;
  9242. var unit = this.state.view.unit;
  9243. this.hint.innerHTML = formatHintText(this.roundLength(this.bounds.width / s), unit) + ' x ' +
  9244. formatHintText(this.roundLength(this.bounds.height / s), unit);
  9245. }
  9246. var rot = (this.currentAlpha != null) ? this.currentAlpha : this.state.style[mxConstants.STYLE_ROTATION] || '0';
  9247. var bb = mxUtils.getBoundingBox(this.bounds, rot);
  9248. if (bb == null)
  9249. {
  9250. bb = this.bounds;
  9251. }
  9252. this.hint.style.left = bb.x + Math.round((bb.width - this.hint.clientWidth) / 2) + 'px';
  9253. this.hint.style.top = (bb.y + bb.height + Editor.hintOffset) + 'px';
  9254. if (this.linkHint != null)
  9255. {
  9256. this.linkHint.style.display = 'none';
  9257. }
  9258. }
  9259. };
  9260. /**
  9261. * Updates the hint for the current operation.
  9262. */
  9263. mxVertexHandler.prototype.removeHint = function()
  9264. {
  9265. mxGraphHandler.prototype.removeHint.apply(this, arguments);
  9266. if (this.linkHint != null)
  9267. {
  9268. this.linkHint.style.display = '';
  9269. }
  9270. };
  9271. /**
  9272. * Hides link hint while moving cells.
  9273. */
  9274. var edgeHandlerMouseMove = mxEdgeHandler.prototype.mouseMove;
  9275. mxEdgeHandler.prototype.mouseMove = function(sender, me)
  9276. {
  9277. edgeHandlerMouseMove.apply(this, arguments);
  9278. if (this.linkHint != null && this.linkHint.style.display != 'none' &&
  9279. this.graph.graphHandler != null && this.graph.graphHandler.first != null)
  9280. {
  9281. this.linkHint.style.display = 'none';
  9282. }
  9283. }
  9284. /**
  9285. * Hides link hint while moving cells.
  9286. */
  9287. var edgeHandlerMouseUp = mxEdgeHandler.prototype.mouseUp;
  9288. mxEdgeHandler.prototype.mouseUp = function(sender, me)
  9289. {
  9290. edgeHandlerMouseUp.apply(this, arguments);
  9291. if (this.linkHint != null && this.linkHint.style.display == 'none')
  9292. {
  9293. this.linkHint.style.display = '';
  9294. }
  9295. }
  9296. /**
  9297. * Updates the hint for the current operation.
  9298. */
  9299. mxEdgeHandler.prototype.updateHint = function(me, point)
  9300. {
  9301. if (this.hint == null)
  9302. {
  9303. this.hint = createHint();
  9304. this.state.view.graph.container.appendChild(this.hint);
  9305. }
  9306. var t = this.graph.view.translate;
  9307. var s = this.graph.view.scale;
  9308. var x = this.roundLength(point.x / s - t.x);
  9309. var y = this.roundLength(point.y / s - t.y);
  9310. var unit = this.graph.view.unit;
  9311. this.hint.innerHTML = formatHintText(x, unit) + ', ' + formatHintText(y, unit);
  9312. this.hint.style.visibility = 'visible';
  9313. if (this.isSource || this.isTarget)
  9314. {
  9315. if (this.constraintHandler.currentConstraint != null &&
  9316. this.constraintHandler.currentFocus != null)
  9317. {
  9318. var pt = this.constraintHandler.currentConstraint.point;
  9319. this.hint.innerHTML = '[' + Math.round(pt.x * 100) + '%, '+ Math.round(pt.y * 100) + '%]';
  9320. }
  9321. else if (this.marker.hasValidState())
  9322. {
  9323. this.hint.style.visibility = 'hidden';
  9324. }
  9325. }
  9326. this.hint.style.left = Math.round(me.getGraphX() - this.hint.clientWidth / 2) + 'px';
  9327. this.hint.style.top = (Math.max(me.getGraphY(), point.y) + Editor.hintOffset) + 'px';
  9328. if (this.linkHint != null)
  9329. {
  9330. this.linkHint.style.display = 'none';
  9331. }
  9332. };
  9333. /**
  9334. * Updates the hint for the current operation.
  9335. */
  9336. mxEdgeHandler.prototype.removeHint = mxVertexHandler.prototype.removeHint;
  9337. /**
  9338. * Defines the handles for the UI. Uses data-URIs to speed-up loading time where supported.
  9339. */
  9340. // TODO: Increase handle padding
  9341. HoverIcons.prototype.mainHandle = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/handle-main.png', 17, 17) :
  9342. Graph.createSvgImage(18, 18, '<circle cx="9" cy="9" r="5" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '" stroke-width="1"/>');
  9343. HoverIcons.prototype.secondaryHandle = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/handle-secondary.png', 17, 17) :
  9344. Graph.createSvgImage(16, 16, '<path d="m 8 3 L 13 8 L 8 13 L 3 8 z" stroke="#fff" fill="#fca000"/>');
  9345. HoverIcons.prototype.fixedHandle = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/handle-fixed.png', 17, 17) :
  9346. Graph.createSvgImage(18, 18, '<circle cx="9" cy="9" r="5" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '" stroke-width="1"/><path d="m 7 7 L 11 11 M 7 11 L 11 7" stroke="#fff"/>');
  9347. HoverIcons.prototype.terminalHandle = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/handle-terminal.png', 17, 17) :
  9348. Graph.createSvgImage(18, 18, '<circle cx="9" cy="9" r="5" stroke="#fff" fill="' + HoverIcons.prototype.arrowFill + '" stroke-width="1"/><circle cx="9" cy="9" r="2" stroke="#fff" fill="transparent"/>');
  9349. HoverIcons.prototype.rotationHandle = (!mxClient.IS_SVG) ? new mxImage(IMAGE_PATH + '/handle-rotate.png', 16, 16) :
  9350. Graph.createSvgImage(16, 16, '<path stroke="' + HoverIcons.prototype.arrowFill +
  9351. '" fill="' + HoverIcons.prototype.arrowFill +
  9352. '" 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"/>',
  9353. 24, 24);
  9354. if (mxClient.IS_SVG)
  9355. {
  9356. mxConstraintHandler.prototype.pointImage = Graph.createSvgImage(5, 5, '<path d="m 0 0 L 5 5 M 0 5 L 5 0" stroke="' + HoverIcons.prototype.arrowFill + '"/>');
  9357. }
  9358. mxVertexHandler.TABLE_HANDLE_COLOR = '#fca000';
  9359. mxVertexHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  9360. mxVertexHandler.prototype.secondaryHandleImage = HoverIcons.prototype.secondaryHandle;
  9361. mxEdgeHandler.prototype.handleImage = HoverIcons.prototype.mainHandle;
  9362. mxEdgeHandler.prototype.terminalHandleImage = HoverIcons.prototype.terminalHandle;
  9363. mxEdgeHandler.prototype.fixedHandleImage = HoverIcons.prototype.fixedHandle;
  9364. mxEdgeHandler.prototype.labelHandleImage = HoverIcons.prototype.secondaryHandle;
  9365. mxOutline.prototype.sizerImage = HoverIcons.prototype.mainHandle;
  9366. if (window.Sidebar != null)
  9367. {
  9368. Sidebar.prototype.triangleUp = HoverIcons.prototype.triangleUp;
  9369. Sidebar.prototype.triangleRight = HoverIcons.prototype.triangleRight;
  9370. Sidebar.prototype.triangleDown = HoverIcons.prototype.triangleDown;
  9371. Sidebar.prototype.triangleLeft = HoverIcons.prototype.triangleLeft;
  9372. Sidebar.prototype.refreshTarget = HoverIcons.prototype.refreshTarget;
  9373. Sidebar.prototype.roundDrop = HoverIcons.prototype.roundDrop;
  9374. }
  9375. // Pre-fetches images (only needed for non data-uris)
  9376. if (!mxClient.IS_SVG)
  9377. {
  9378. new Image().src = HoverIcons.prototype.mainHandle.src;
  9379. new Image().src = HoverIcons.prototype.fixedHandle.src;
  9380. new Image().src = HoverIcons.prototype.terminalHandle.src;
  9381. new Image().src = HoverIcons.prototype.secondaryHandle.src;
  9382. new Image().src = HoverIcons.prototype.rotationHandle.src;
  9383. new Image().src = HoverIcons.prototype.triangleUp.src;
  9384. new Image().src = HoverIcons.prototype.triangleRight.src;
  9385. new Image().src = HoverIcons.prototype.triangleDown.src;
  9386. new Image().src = HoverIcons.prototype.triangleLeft.src;
  9387. new Image().src = HoverIcons.prototype.refreshTarget.src;
  9388. new Image().src = HoverIcons.prototype.roundDrop.src;
  9389. }
  9390. // Adds rotation handle and live preview
  9391. mxVertexHandler.prototype.rotationEnabled = true;
  9392. mxVertexHandler.prototype.manageSizers = true;
  9393. mxVertexHandler.prototype.livePreview = true;
  9394. mxGraphHandler.prototype.maxLivePreview = 16;
  9395. // Increases default rubberband opacity (default is 20)
  9396. mxRubberband.prototype.defaultOpacity = 30;
  9397. // Enables connections along the outline, virtual waypoints, parent highlight etc
  9398. mxConnectionHandler.prototype.outlineConnect = true;
  9399. mxCellHighlight.prototype.keepOnTop = true;
  9400. mxVertexHandler.prototype.parentHighlightEnabled = true;
  9401. mxEdgeHandler.prototype.parentHighlightEnabled = true;
  9402. mxEdgeHandler.prototype.dblClickRemoveEnabled = true;
  9403. mxEdgeHandler.prototype.straightRemoveEnabled = true;
  9404. mxEdgeHandler.prototype.virtualBendsEnabled = true;
  9405. mxEdgeHandler.prototype.mergeRemoveEnabled = true;
  9406. mxEdgeHandler.prototype.manageLabelHandle = true;
  9407. mxEdgeHandler.prototype.outlineConnect = true;
  9408. // Disables adding waypoints if shift is pressed
  9409. mxEdgeHandler.prototype.isAddVirtualBendEvent = function(me)
  9410. {
  9411. return !mxEvent.isShiftDown(me.getEvent());
  9412. };
  9413. // Disables custom handles if shift is pressed
  9414. mxEdgeHandler.prototype.isCustomHandleEvent = function(me)
  9415. {
  9416. return !mxEvent.isShiftDown(me.getEvent());
  9417. };
  9418. /**
  9419. * Implements touch style
  9420. */
  9421. if (Graph.touchStyle)
  9422. {
  9423. // Larger tolerance for real touch devices
  9424. if (mxClient.IS_TOUCH || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0)
  9425. {
  9426. mxShape.prototype.svgStrokeTolerance = 18;
  9427. mxVertexHandler.prototype.tolerance = 12;
  9428. mxEdgeHandler.prototype.tolerance = 12;
  9429. Graph.prototype.tolerance = 12;
  9430. mxVertexHandler.prototype.rotationHandleVSpacing = -16;
  9431. // Implements a smaller tolerance for mouse events and a larger tolerance for touch
  9432. // events on touch devices. The default tolerance (4px) is used for mouse events.
  9433. mxConstraintHandler.prototype.getTolerance = function(me)
  9434. {
  9435. return (mxEvent.isMouseEvent(me.getEvent())) ? 4 : this.graph.getTolerance();
  9436. };
  9437. }
  9438. // One finger pans (no rubberband selection) must start regardless of mouse button
  9439. mxPanningHandler.prototype.isPanningTrigger = function(me)
  9440. {
  9441. var evt = me.getEvent();
  9442. return (me.getState() == null && !mxEvent.isMouseEvent(evt)) ||
  9443. (mxEvent.isPopupTrigger(evt) && (me.getState() == null ||
  9444. mxEvent.isControlDown(evt) || mxEvent.isShiftDown(evt)));
  9445. };
  9446. // Don't clear selection if multiple cells selected
  9447. var graphHandlerMouseDown = mxGraphHandler.prototype.mouseDown;
  9448. mxGraphHandler.prototype.mouseDown = function(sender, me)
  9449. {
  9450. graphHandlerMouseDown.apply(this, arguments);
  9451. if (mxEvent.isTouchEvent(me.getEvent()) && this.graph.isCellSelected(me.getCell()) &&
  9452. this.graph.getSelectionCount() > 1)
  9453. {
  9454. this.delayedSelection = false;
  9455. }
  9456. };
  9457. }
  9458. else
  9459. {
  9460. // Removes ctrl+shift as panning trigger for space splitting
  9461. mxPanningHandler.prototype.isPanningTrigger = function(me)
  9462. {
  9463. var evt = me.getEvent();
  9464. return (mxEvent.isLeftMouseButton(evt) && ((this.useLeftButtonForPanning &&
  9465. me.getState() == null) || (mxEvent.isControlDown(evt) &&
  9466. !mxEvent.isShiftDown(evt)))) || (this.usePopupTrigger &&
  9467. mxEvent.isPopupTrigger(evt));
  9468. };
  9469. }
  9470. // Overrides/extends rubberband for space handling with Ctrl+Shift(+Alt) drag ("scissors tool")
  9471. mxRubberband.prototype.isSpaceEvent = function(me)
  9472. {
  9473. return this.graph.isEnabled() && !this.graph.isCellLocked(this.graph.getDefaultParent()) &&
  9474. mxEvent.isControlDown(me.getEvent()) && mxEvent.isShiftDown(me.getEvent());
  9475. };
  9476. // Cancelled state
  9477. mxRubberband.prototype.cancelled = false;
  9478. // Cancels ongoing rubberband selection but consumed event to avoid reset of selection
  9479. mxRubberband.prototype.cancel = function()
  9480. {
  9481. if (this.isActive())
  9482. {
  9483. this.cancelled = true;
  9484. this.reset();
  9485. }
  9486. };
  9487. // Handles moving of cells in both half panes
  9488. mxRubberband.prototype.mouseUp = function(sender, me)
  9489. {
  9490. if (this.cancelled)
  9491. {
  9492. this.cancelled = false;
  9493. me.consume();
  9494. }
  9495. else
  9496. {
  9497. var execute = this.div != null && this.div.style.display != 'none';
  9498. var x0 = null;
  9499. var y0 = null;
  9500. var dx = null;
  9501. var dy = null;
  9502. if (this.first != null && this.currentX != null && this.currentY != null)
  9503. {
  9504. x0 = this.first.x;
  9505. y0 = this.first.y;
  9506. dx = (this.currentX - x0) / this.graph.view.scale;
  9507. dy = (this.currentY - y0) / this.graph.view.scale;
  9508. if (!mxEvent.isAltDown(me.getEvent()))
  9509. {
  9510. dx = this.graph.snap(dx);
  9511. dy = this.graph.snap(dy);
  9512. if (!this.graph.isGridEnabled())
  9513. {
  9514. if (Math.abs(dx) < this.graph.tolerance)
  9515. {
  9516. dx = 0;
  9517. }
  9518. if (Math.abs(dy) < this.graph.tolerance)
  9519. {
  9520. dy = 0;
  9521. }
  9522. }
  9523. }
  9524. }
  9525. this.reset();
  9526. if (execute)
  9527. {
  9528. if (mxEvent.isAltDown(me.getEvent()) && this.graph.isToggleEvent(me.getEvent()))
  9529. {
  9530. var rect = new mxRectangle(this.x, this.y, this.width, this.height);
  9531. var cells = this.graph.getCells(rect.x, rect.y, rect.width, rect.height);
  9532. this.graph.removeSelectionCells(cells);
  9533. }
  9534. else if (this.isSpaceEvent(me))
  9535. {
  9536. this.graph.model.beginUpdate();
  9537. try
  9538. {
  9539. var cells = this.graph.getCellsBeyond(x0, y0, this.graph.getDefaultParent(), true, true);
  9540. for (var i = 0; i < cells.length; i++)
  9541. {
  9542. if (this.graph.isCellMovable(cells[i]))
  9543. {
  9544. var tmp = this.graph.view.getState(cells[i]);
  9545. var geo = this.graph.getCellGeometry(cells[i]);
  9546. if (tmp != null && geo != null)
  9547. {
  9548. geo = geo.clone();
  9549. geo.translate(dx, dy);
  9550. this.graph.model.setGeometry(cells[i], geo);
  9551. }
  9552. }
  9553. }
  9554. }
  9555. finally
  9556. {
  9557. this.graph.model.endUpdate();
  9558. }
  9559. }
  9560. else
  9561. {
  9562. var rect = new mxRectangle(this.x, this.y, this.width, this.height);
  9563. this.graph.selectRegion(rect, me.getEvent());
  9564. }
  9565. me.consume();
  9566. }
  9567. }
  9568. };
  9569. // Handles preview for creating/removing space in diagram
  9570. mxRubberband.prototype.mouseMove = function(sender, me)
  9571. {
  9572. if (!me.isConsumed() && this.first != null)
  9573. {
  9574. var origin = mxUtils.getScrollOrigin(this.graph.container);
  9575. var offset = mxUtils.getOffset(this.graph.container);
  9576. origin.x -= offset.x;
  9577. origin.y -= offset.y;
  9578. var x = me.getX() + origin.x;
  9579. var y = me.getY() + origin.y;
  9580. var dx = this.first.x - x;
  9581. var dy = this.first.y - y;
  9582. var tol = this.graph.tolerance;
  9583. if (this.div != null || Math.abs(dx) > tol || Math.abs(dy) > tol)
  9584. {
  9585. if (this.div == null)
  9586. {
  9587. this.div = this.createShape();
  9588. }
  9589. // Clears selection while rubberbanding. This is required because
  9590. // the event is not consumed in mouseDown.
  9591. mxUtils.clearSelection();
  9592. this.update(x, y);
  9593. if (this.isSpaceEvent(me))
  9594. {
  9595. var right = this.x + this.width;
  9596. var bottom = this.y + this.height;
  9597. var scale = this.graph.view.scale;
  9598. if (!mxEvent.isAltDown(me.getEvent()))
  9599. {
  9600. this.width = this.graph.snap(this.width / scale) * scale;
  9601. this.height = this.graph.snap(this.height / scale) * scale;
  9602. if (!this.graph.isGridEnabled())
  9603. {
  9604. if (this.width < this.graph.tolerance)
  9605. {
  9606. this.width = 0;
  9607. }
  9608. if (this.height < this.graph.tolerance)
  9609. {
  9610. this.height = 0;
  9611. }
  9612. }
  9613. if (this.x < this.first.x)
  9614. {
  9615. this.x = right - this.width;
  9616. }
  9617. if (this.y < this.first.y)
  9618. {
  9619. this.y = bottom - this.height;
  9620. }
  9621. }
  9622. this.div.style.borderStyle = 'dashed';
  9623. this.div.style.backgroundColor = 'white';
  9624. this.div.style.left = this.x + 'px';
  9625. this.div.style.top = this.y + 'px';
  9626. this.div.style.width = Math.max(0, this.width) + 'px';
  9627. this.div.style.height = this.graph.container.clientHeight + 'px';
  9628. this.div.style.borderWidth = (this.width <= 0) ? '0px 1px 0px 0px' : '0px 1px 0px 1px';
  9629. if (this.secondDiv == null)
  9630. {
  9631. this.secondDiv = this.div.cloneNode(true);
  9632. this.div.parentNode.appendChild(this.secondDiv);
  9633. }
  9634. this.secondDiv.style.left = this.x + 'px';
  9635. this.secondDiv.style.top = this.y + 'px';
  9636. this.secondDiv.style.width = this.graph.container.clientWidth + 'px';
  9637. this.secondDiv.style.height = Math.max(0, this.height) + 'px';
  9638. this.secondDiv.style.borderWidth = (this.height <= 0) ? '1px 0px 0px 0px' : '1px 0px 1px 0px';
  9639. }
  9640. else
  9641. {
  9642. // Hides second div and restores style
  9643. this.div.style.backgroundColor = '';
  9644. this.div.style.borderWidth = '';
  9645. this.div.style.borderStyle = '';
  9646. if (this.secondDiv != null)
  9647. {
  9648. this.secondDiv.parentNode.removeChild(this.secondDiv);
  9649. this.secondDiv = null;
  9650. }
  9651. }
  9652. me.consume();
  9653. }
  9654. }
  9655. };
  9656. // Removes preview
  9657. var mxRubberbandReset = mxRubberband.prototype.reset;
  9658. mxRubberband.prototype.reset = function()
  9659. {
  9660. if (this.secondDiv != null)
  9661. {
  9662. this.secondDiv.parentNode.removeChild(this.secondDiv);
  9663. this.secondDiv = null;
  9664. }
  9665. mxRubberbandReset.apply(this, arguments);
  9666. };
  9667. // Timer-based activation of outline connect in connection handler
  9668. var startTime = new Date().getTime();
  9669. var timeOnTarget = 0;
  9670. var mxEdgeHandlerUpdatePreviewState = mxEdgeHandler.prototype.updatePreviewState;
  9671. mxEdgeHandler.prototype.updatePreviewState = function(edge, point, terminalState, me)
  9672. {
  9673. mxEdgeHandlerUpdatePreviewState.apply(this, arguments);
  9674. if (terminalState != this.currentTerminalState)
  9675. {
  9676. startTime = new Date().getTime();
  9677. timeOnTarget = 0;
  9678. }
  9679. else
  9680. {
  9681. timeOnTarget = new Date().getTime() - startTime;
  9682. }
  9683. this.currentTerminalState = terminalState;
  9684. };
  9685. // Timer-based outline connect
  9686. var mxEdgeHandlerIsOutlineConnectEvent = mxEdgeHandler.prototype.isOutlineConnectEvent;
  9687. mxEdgeHandler.prototype.isOutlineConnectEvent = function(me)
  9688. {
  9689. return (this.currentTerminalState != null && me.getState() == this.currentTerminalState && timeOnTarget > 2000) ||
  9690. ((this.currentTerminalState == null || mxUtils.getValue(this.currentTerminalState.style, 'outlineConnect', '1') != '0') &&
  9691. mxEdgeHandlerIsOutlineConnectEvent.apply(this, arguments));
  9692. };
  9693. // Shows secondary handle for fixed connection points
  9694. mxEdgeHandler.prototype.createHandleShape = function(index, virtual)
  9695. {
  9696. var source = index != null && index == 0;
  9697. var terminalState = this.state.getVisibleTerminalState(source);
  9698. var c = (index != null && (index == 0 || index >= this.state.absolutePoints.length - 1 ||
  9699. (this.constructor == mxElbowEdgeHandler && index == 2))) ?
  9700. this.graph.getConnectionConstraint(this.state, terminalState, source) : null;
  9701. var pt = (c != null) ? this.graph.getConnectionPoint(this.state.getVisibleTerminalState(source), c) : null;
  9702. var img = (pt != null) ? this.fixedHandleImage : ((c != null && terminalState != null) ?
  9703. this.terminalHandleImage : this.handleImage);
  9704. if (img != null)
  9705. {
  9706. var shape = new mxImageShape(new mxRectangle(0, 0, img.width, img.height), img.src);
  9707. // Allows HTML rendering of the images
  9708. shape.preserveImageAspect = false;
  9709. return shape;
  9710. }
  9711. else
  9712. {
  9713. var s = mxConstants.HANDLE_SIZE;
  9714. if (this.preferHtml)
  9715. {
  9716. s -= 1;
  9717. }
  9718. return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  9719. }
  9720. };
  9721. var vertexHandlerCreateSizerShape = mxVertexHandler.prototype.createSizerShape;
  9722. mxVertexHandler.prototype.createSizerShape = function(bounds, index, fillColor)
  9723. {
  9724. this.handleImage = (index == mxEvent.ROTATION_HANDLE) ? HoverIcons.prototype.rotationHandle : (index == mxEvent.LABEL_HANDLE) ? this.secondaryHandleImage : this.handleImage;
  9725. return vertexHandlerCreateSizerShape.apply(this, arguments);
  9726. };
  9727. // Special case for single edge label handle moving in which case the text bounding box is used
  9728. var mxGraphHandlerGetBoundingBox = mxGraphHandler.prototype.getBoundingBox;
  9729. mxGraphHandler.prototype.getBoundingBox = function(cells)
  9730. {
  9731. if (cells != null && cells.length == 1)
  9732. {
  9733. var model = this.graph.getModel();
  9734. var parent = model.getParent(cells[0]);
  9735. var geo = this.graph.getCellGeometry(cells[0]);
  9736. if (model.isEdge(parent) && geo != null && geo.relative)
  9737. {
  9738. var state = this.graph.view.getState(cells[0]);
  9739. if (state != null && state.width < 2 && state.height < 2 && state.text != null &&
  9740. state.text.boundingBox != null)
  9741. {
  9742. return mxRectangle.fromRectangle(state.text.boundingBox);
  9743. }
  9744. }
  9745. }
  9746. return mxGraphHandlerGetBoundingBox.apply(this, arguments);
  9747. };
  9748. // Ignores child cells with part style as guides
  9749. var mxGraphHandlerGetGuideStates = mxGraphHandler.prototype.getGuideStates;
  9750. mxGraphHandler.prototype.getGuideStates = function()
  9751. {
  9752. var states = mxGraphHandlerGetGuideStates.apply(this, arguments);
  9753. var result = [];
  9754. // NOTE: Could do via isStateIgnored hook
  9755. for (var i = 0; i < states.length; i++)
  9756. {
  9757. if (mxUtils.getValue(states[i].style, 'part', '0') != '1')
  9758. {
  9759. result.push(states[i]);
  9760. }
  9761. }
  9762. return result;
  9763. };
  9764. // Uses text bounding box for edge labels
  9765. var mxVertexHandlerGetSelectionBounds = mxVertexHandler.prototype.getSelectionBounds;
  9766. mxVertexHandler.prototype.getSelectionBounds = function(state)
  9767. {
  9768. var model = this.graph.getModel();
  9769. var parent = model.getParent(state.cell);
  9770. var geo = this.graph.getCellGeometry(state.cell);
  9771. if (model.isEdge(parent) && geo != null && geo.relative && state.width < 2 && state.height < 2 && state.text != null && state.text.boundingBox != null)
  9772. {
  9773. var bbox = state.text.unrotatedBoundingBox || state.text.boundingBox;
  9774. return new mxRectangle(Math.round(bbox.x), Math.round(bbox.y), Math.round(bbox.width), Math.round(bbox.height));
  9775. }
  9776. else
  9777. {
  9778. return mxVertexHandlerGetSelectionBounds.apply(this, arguments);
  9779. }
  9780. };
  9781. // Redirects moving of edge labels to mxGraphHandler by not starting here.
  9782. // This will use the move preview of mxGraphHandler (see above).
  9783. var mxVertexHandlerMouseDown = mxVertexHandler.prototype.mouseDown;
  9784. mxVertexHandler.prototype.mouseDown = function(sender, me)
  9785. {
  9786. var model = this.graph.getModel();
  9787. var parent = model.getParent(this.state.cell);
  9788. var geo = this.graph.getCellGeometry(this.state.cell);
  9789. // Lets rotation events through
  9790. var handle = this.getHandleForEvent(me);
  9791. if (handle == mxEvent.ROTATION_HANDLE || !model.isEdge(parent) || geo == null || !geo.relative ||
  9792. this.state == null || this.state.width >= 2 || this.state.height >= 2)
  9793. {
  9794. mxVertexHandlerMouseDown.apply(this, arguments);
  9795. }
  9796. };
  9797. // Invokes turn on single click on rotation handle
  9798. mxVertexHandler.prototype.rotateClick = function()
  9799. {
  9800. var stroke = mxUtils.getValue(this.state.style, mxConstants.STYLE_STROKECOLOR, mxConstants.NONE);
  9801. var fill = mxUtils.getValue(this.state.style, mxConstants.STYLE_FILLCOLOR, mxConstants.NONE);
  9802. if (this.state.view.graph.model.isVertex(this.state.cell) &&
  9803. stroke == mxConstants.NONE && fill == mxConstants.NONE)
  9804. {
  9805. var angle = mxUtils.mod(mxUtils.getValue(this.state.style, mxConstants.STYLE_ROTATION, 0) + 90, 360);
  9806. this.state.view.graph.setCellStyles(mxConstants.STYLE_ROTATION, angle, [this.state.cell]);
  9807. }
  9808. else
  9809. {
  9810. this.state.view.graph.turnShapes([this.state.cell]);
  9811. }
  9812. };
  9813. var vertexHandlerMouseMove = mxVertexHandler.prototype.mouseMove;
  9814. // Workaround for "isConsumed not defined" in MS Edge is to use arguments
  9815. mxVertexHandler.prototype.mouseMove = function(sender, me)
  9816. {
  9817. vertexHandlerMouseMove.apply(this, arguments);
  9818. if (this.graph.graphHandler.first != null)
  9819. {
  9820. if (this.rotationShape != null && this.rotationShape.node != null)
  9821. {
  9822. this.rotationShape.node.style.display = 'none';
  9823. }
  9824. if (this.linkHint != null && this.linkHint.style.display != 'none')
  9825. {
  9826. this.linkHint.style.display = 'none';
  9827. }
  9828. }
  9829. };
  9830. var vertexHandlerMouseUp = mxVertexHandler.prototype.mouseUp;
  9831. mxVertexHandler.prototype.mouseUp = function(sender, me)
  9832. {
  9833. vertexHandlerMouseUp.apply(this, arguments);
  9834. // Shows rotation handle only if one vertex is selected
  9835. if (this.rotationShape != null && this.rotationShape.node != null)
  9836. {
  9837. this.rotationShape.node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  9838. }
  9839. if (this.linkHint != null && this.linkHint.style.display == 'none')
  9840. {
  9841. this.linkHint.style.display = '';
  9842. }
  9843. // Resets state after gesture
  9844. this.blockDelayedSelection = null;
  9845. };
  9846. var vertexHandlerInit = mxVertexHandler.prototype.init;
  9847. mxVertexHandler.prototype.init = function()
  9848. {
  9849. vertexHandlerInit.apply(this, arguments);
  9850. var redraw = false;
  9851. if (this.rotationShape != null)
  9852. {
  9853. this.rotationShape.node.setAttribute('title', mxResources.get('rotateTooltip'));
  9854. }
  9855. if (this.graph.isTable(this.state.cell))
  9856. {
  9857. this.refreshMoveHandles();
  9858. }
  9859. // Draws corner rectangles for single selected table cells and rows
  9860. else if (this.graph.getSelectionCount() == 1 &&
  9861. (this.graph.isTableCell(this.state.cell) ||
  9862. this.graph.isTableRow(this.state.cell)))
  9863. {
  9864. this.cornerHandles = [];
  9865. for (var i = 0; i < 4; i++)
  9866. {
  9867. var shape = new mxRectangleShape(new mxRectangle(0, 0, 6, 6),
  9868. '#ffffff', mxConstants.HANDLE_STROKECOLOR);
  9869. shape.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  9870. mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  9871. shape.init(this.graph.view.getOverlayPane());
  9872. this.cornerHandles.push(shape);
  9873. }
  9874. }
  9875. var update = mxUtils.bind(this, function()
  9876. {
  9877. if (this.specialHandle != null)
  9878. {
  9879. this.specialHandle.node.style.display = (this.graph.isEnabled() &&
  9880. this.graph.getSelectionCount() < this.graph.graphHandler.maxCells) ?
  9881. '' : 'none';
  9882. }
  9883. this.redrawHandles();
  9884. });
  9885. this.changeHandler = mxUtils.bind(this, function(sender, evt)
  9886. {
  9887. this.updateLinkHint(this.graph.getLinkForCell(this.state.cell),
  9888. this.graph.getLinksForState(this.state));
  9889. update();
  9890. });
  9891. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.changeHandler);
  9892. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  9893. // Repaint needed when editing stops and no change event is fired
  9894. this.editingHandler = mxUtils.bind(this, function(sender, evt)
  9895. {
  9896. this.redrawHandles();
  9897. });
  9898. this.graph.addListener(mxEvent.EDITING_STOPPED, this.editingHandler);
  9899. var link = this.graph.getLinkForCell(this.state.cell);
  9900. var links = this.graph.getLinksForState(this.state);
  9901. this.updateLinkHint(link, links);
  9902. if (link != null || (links != null && links.length > 0))
  9903. {
  9904. redraw = true;
  9905. }
  9906. if (redraw)
  9907. {
  9908. this.redrawHandles();
  9909. }
  9910. };
  9911. mxVertexHandler.prototype.updateLinkHint = function(link, links)
  9912. {
  9913. try
  9914. {
  9915. if ((link == null && (links == null || links.length == 0)) ||
  9916. this.graph.getSelectionCount() > 1)
  9917. {
  9918. if (this.linkHint != null)
  9919. {
  9920. this.linkHint.parentNode.removeChild(this.linkHint);
  9921. this.linkHint = null;
  9922. }
  9923. }
  9924. else if (link != null || (links != null && links.length > 0))
  9925. {
  9926. if (this.linkHint == null)
  9927. {
  9928. this.linkHint = createHint();
  9929. this.linkHint.style.padding = '6px 8px 6px 8px';
  9930. this.linkHint.style.opacity = '1';
  9931. this.linkHint.style.filter = '';
  9932. this.graph.container.appendChild(this.linkHint);
  9933. }
  9934. this.linkHint.innerHTML = '';
  9935. if (link != null)
  9936. {
  9937. this.linkHint.appendChild(this.graph.createLinkForHint(link));
  9938. if (this.graph.isEnabled() && typeof this.graph.editLink === 'function')
  9939. {
  9940. var changeLink = document.createElement('img');
  9941. changeLink.setAttribute('src', Editor.editImage);
  9942. changeLink.setAttribute('title', mxResources.get('editLink'));
  9943. changeLink.setAttribute('width', '11');
  9944. changeLink.setAttribute('height', '11');
  9945. changeLink.style.marginLeft = '10px';
  9946. changeLink.style.marginBottom = '-1px';
  9947. changeLink.style.cursor = 'pointer';
  9948. this.linkHint.appendChild(changeLink);
  9949. mxEvent.addListener(changeLink, 'click', mxUtils.bind(this, function(evt)
  9950. {
  9951. this.graph.setSelectionCell(this.state.cell);
  9952. this.graph.editLink();
  9953. mxEvent.consume(evt);
  9954. }));
  9955. var removeLink = document.createElement('img');
  9956. removeLink.setAttribute('src', Dialog.prototype.clearImage);
  9957. removeLink.setAttribute('title', mxResources.get('removeIt', [mxResources.get('link')]));
  9958. removeLink.setAttribute('width', '13');
  9959. removeLink.setAttribute('height', '10');
  9960. removeLink.style.marginLeft = '4px';
  9961. removeLink.style.marginBottom = '-1px';
  9962. removeLink.style.cursor = 'pointer';
  9963. this.linkHint.appendChild(removeLink);
  9964. mxEvent.addListener(removeLink, 'click', mxUtils.bind(this, function(evt)
  9965. {
  9966. this.graph.setLinkForCell(this.state.cell, null);
  9967. mxEvent.consume(evt);
  9968. }));
  9969. }
  9970. }
  9971. if (links != null)
  9972. {
  9973. for (var i = 0; i < links.length; i++)
  9974. {
  9975. var div = document.createElement('div');
  9976. div.style.marginTop = (link != null || i > 0) ? '6px' : '0px';
  9977. div.appendChild(this.graph.createLinkForHint(
  9978. links[i].getAttribute('href'),
  9979. mxUtils.getTextContent(links[i])));
  9980. this.linkHint.appendChild(div);
  9981. }
  9982. }
  9983. }
  9984. }
  9985. catch (e)
  9986. {
  9987. // ignore
  9988. }
  9989. };
  9990. mxEdgeHandler.prototype.updateLinkHint = mxVertexHandler.prototype.updateLinkHint;
  9991. // Creates special handles
  9992. var edgeHandlerInit = mxEdgeHandler.prototype.init;
  9993. mxEdgeHandler.prototype.init = function()
  9994. {
  9995. edgeHandlerInit.apply(this, arguments);
  9996. // Disables connection points
  9997. this.constraintHandler.isEnabled = mxUtils.bind(this, function()
  9998. {
  9999. return this.state.view.graph.connectionHandler.isEnabled();
  10000. });
  10001. var update = mxUtils.bind(this, function()
  10002. {
  10003. if (this.linkHint != null)
  10004. {
  10005. this.linkHint.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  10006. }
  10007. if (this.labelShape != null)
  10008. {
  10009. this.labelShape.node.style.display = (this.graph.isEnabled() &&
  10010. this.graph.getSelectionCount() < this.graph.graphHandler.maxCells) ?
  10011. '' : 'none';
  10012. }
  10013. });
  10014. this.changeHandler = mxUtils.bind(this, function(sender, evt)
  10015. {
  10016. this.updateLinkHint(this.graph.getLinkForCell(this.state.cell),
  10017. this.graph.getLinksForState(this.state));
  10018. update();
  10019. this.redrawHandles();
  10020. });
  10021. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.changeHandler);
  10022. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  10023. var link = this.graph.getLinkForCell(this.state.cell);
  10024. var links = this.graph.getLinksForState(this.state);
  10025. if (link != null || (links != null && links.length > 0))
  10026. {
  10027. this.updateLinkHint(link, links);
  10028. this.redrawHandles();
  10029. }
  10030. };
  10031. // Disables connection points
  10032. var connectionHandlerInit = mxConnectionHandler.prototype.init;
  10033. mxConnectionHandler.prototype.init = function()
  10034. {
  10035. connectionHandlerInit.apply(this, arguments);
  10036. this.constraintHandler.isEnabled = mxUtils.bind(this, function()
  10037. {
  10038. return this.graph.connectionHandler.isEnabled();
  10039. });
  10040. };
  10041. // Updates special handles
  10042. var vertexHandlerRedrawHandles = mxVertexHandler.prototype.redrawHandles;
  10043. mxVertexHandler.prototype.redrawHandles = function()
  10044. {
  10045. if (this.moveHandles != null)
  10046. {
  10047. for (var i = 0; i < this.moveHandles.length; i++)
  10048. {
  10049. this.moveHandles[i].style.left = (this.moveHandles[i].rowState.x +
  10050. this.moveHandles[i].rowState.width - 5) + 'px';
  10051. this.moveHandles[i].style.top = (this.moveHandles[i].rowState.y +
  10052. this.moveHandles[i].rowState.height / 2 - 6) + 'px';
  10053. }
  10054. }
  10055. if (this.cornerHandles != null)
  10056. {
  10057. var inset = this.getSelectionBorderInset();
  10058. var ch = this.cornerHandles;
  10059. var w = ch[0].bounds.width / 2;
  10060. var h = ch[0].bounds.height / 2;
  10061. ch[0].bounds.x = this.state.x - w + inset;
  10062. ch[0].bounds.y = this.state.y - h + inset;
  10063. ch[0].redraw();
  10064. ch[1].bounds.x = ch[0].bounds.x + this.state.width - 2 * inset;
  10065. ch[1].bounds.y = ch[0].bounds.y;
  10066. ch[1].redraw();
  10067. ch[2].bounds.x = ch[0].bounds.x;
  10068. ch[2].bounds.y = this.state.y + this.state.height - 2 * inset;
  10069. ch[2].redraw();
  10070. ch[3].bounds.x = ch[1].bounds.x;
  10071. ch[3].bounds.y = ch[2].bounds.y;
  10072. ch[3].redraw();
  10073. for (var i = 0; i < this.cornerHandles.length; i++)
  10074. {
  10075. this.cornerHandles[i].node.style.display = (this.graph.getSelectionCount() == 1) ? '' : 'none';
  10076. }
  10077. }
  10078. // Shows rotation handle only if one vertex is selected
  10079. if (this.rotationShape != null && this.rotationShape.node != null)
  10080. {
  10081. this.rotationShape.node.style.display = (this.moveHandles == null &&
  10082. (this.graph.getSelectionCount() == 1 && (this.index == null ||
  10083. this.index == mxEvent.ROTATION_HANDLE))) ? '' : 'none';
  10084. }
  10085. vertexHandlerRedrawHandles.apply(this);
  10086. if (this.state != null && this.linkHint != null)
  10087. {
  10088. var c = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  10089. var tmp = new mxRectangle(this.state.x, this.state.y - 22, this.state.width + 24, this.state.height + 22);
  10090. var bb = mxUtils.getBoundingBox(tmp, this.state.style[mxConstants.STYLE_ROTATION] || '0', c);
  10091. var rs = (bb != null) ? mxUtils.getBoundingBox(this.state,
  10092. this.state.style[mxConstants.STYLE_ROTATION] || '0') : this.state;
  10093. var tb = (this.state.text != null) ? this.state.text.boundingBox : null;
  10094. if (bb == null)
  10095. {
  10096. bb = this.state;
  10097. }
  10098. var b = bb.y + bb.height;
  10099. if (tb != null)
  10100. {
  10101. b = Math.max(b, tb.y + tb.height);
  10102. }
  10103. this.linkHint.style.left = Math.max(0, Math.round(rs.x + (rs.width - this.linkHint.clientWidth) / 2)) + 'px';
  10104. this.linkHint.style.top = Math.round(b + this.verticalOffset / 2 + Editor.hintOffset) + 'px';
  10105. }
  10106. };
  10107. // Destroys special handles
  10108. var vertexHandlerDestroy = mxVertexHandler.prototype.destroy;
  10109. mxVertexHandler.prototype.destroy = function()
  10110. {
  10111. vertexHandlerDestroy.apply(this, arguments);
  10112. if (this.moveHandles != null)
  10113. {
  10114. for (var i = 0; i < this.moveHandles.length; i++)
  10115. {
  10116. if (this.moveHandles[i] != null && this.moveHandles[i].parentNode != null)
  10117. {
  10118. this.moveHandles[i].parentNode.removeChild(this.moveHandles[i]);
  10119. }
  10120. }
  10121. this.moveHandles = null;
  10122. }
  10123. if (this.cornerHandles != null)
  10124. {
  10125. for (var i = 0; i < this.cornerHandles.length; i++)
  10126. {
  10127. if (this.cornerHandles[i] != null && this.cornerHandles[i].node != null &&
  10128. this.cornerHandles[i].node.parentNode != null)
  10129. {
  10130. this.cornerHandles[i].node.parentNode.removeChild(this.cornerHandles[i].node);
  10131. }
  10132. }
  10133. this.cornerHandles = null;
  10134. }
  10135. if (this.linkHint != null)
  10136. {
  10137. if (this.linkHint.parentNode != null)
  10138. {
  10139. this.linkHint.parentNode.removeChild(this.linkHint);
  10140. }
  10141. this.linkHint = null;
  10142. }
  10143. if (this.changeHandler != null)
  10144. {
  10145. this.graph.getSelectionModel().removeListener(this.changeHandler);
  10146. this.graph.getModel().removeListener(this.changeHandler);
  10147. this.changeHandler = null;
  10148. }
  10149. if (this.editingHandler != null)
  10150. {
  10151. this.graph.removeListener(this.editingHandler);
  10152. this.editingHandler = null;
  10153. }
  10154. };
  10155. var edgeHandlerRedrawHandles = mxEdgeHandler.prototype.redrawHandles;
  10156. mxEdgeHandler.prototype.redrawHandles = function()
  10157. {
  10158. // Workaround for special case where handler
  10159. // is reset before this which leads to a NPE
  10160. if (this.marker != null)
  10161. {
  10162. edgeHandlerRedrawHandles.apply(this);
  10163. if (this.state != null && this.linkHint != null)
  10164. {
  10165. var b = this.state;
  10166. if (this.state.text != null && this.state.text.bounds != null)
  10167. {
  10168. b = new mxRectangle(b.x, b.y, b.width, b.height);
  10169. b.add(this.state.text.bounds);
  10170. }
  10171. this.linkHint.style.left = Math.max(0, Math.round(b.x + (b.width - this.linkHint.clientWidth) / 2)) + 'px';
  10172. this.linkHint.style.top = Math.round(b.y + b.height + Editor.hintOffset) + 'px';
  10173. }
  10174. }
  10175. };
  10176. var edgeHandlerReset = mxEdgeHandler.prototype.reset;
  10177. mxEdgeHandler.prototype.reset = function()
  10178. {
  10179. edgeHandlerReset.apply(this, arguments);
  10180. if (this.linkHint != null)
  10181. {
  10182. this.linkHint.style.visibility = '';
  10183. }
  10184. };
  10185. var edgeHandlerDestroy = mxEdgeHandler.prototype.destroy;
  10186. mxEdgeHandler.prototype.destroy = function()
  10187. {
  10188. edgeHandlerDestroy.apply(this, arguments);
  10189. if (this.linkHint != null)
  10190. {
  10191. this.linkHint.parentNode.removeChild(this.linkHint);
  10192. this.linkHint = null;
  10193. }
  10194. if (this.changeHandler != null)
  10195. {
  10196. this.graph.getModel().removeListener(this.changeHandler);
  10197. this.graph.getSelectionModel().removeListener(this.changeHandler);
  10198. this.changeHandler = null;
  10199. }
  10200. };
  10201. })();
  10202. }