mxClient.js 2.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. var mxClient =
  6. {
  7. /**
  8. * Class: mxClient
  9. *
  10. * Bootstrapping mechanism for the mxGraph thin client. The production version
  11. * of this file contains all code required to run the mxGraph thin client, as
  12. * well as global constants to identify the browser and operating system in
  13. * use. You may have to load chrome://global/content/contentAreaUtils.js in
  14. * your page to disable certain security restrictions in Mozilla.
  15. *
  16. * Variable: VERSION
  17. *
  18. * Contains the current version of the mxGraph library. The strings that
  19. * communicate versions of mxGraph use the following format.
  20. *
  21. * versionMajor.versionMinor.buildNumber.revisionNumber
  22. *
  23. * Current version is 4.2.0.
  24. */
  25. VERSION: '4.2.0',
  26. /**
  27. * Variable: IS_IE
  28. *
  29. * True if the current browser is Internet Explorer 10 or below. Use <mxClient.IS_IE11>
  30. * to detect IE 11.
  31. */
  32. IS_IE: navigator.userAgent != null && navigator.userAgent.indexOf('MSIE') >= 0,
  33. /**
  34. * Variable: IS_IE6
  35. *
  36. * True if the current browser is Internet Explorer 6.x.
  37. */
  38. IS_IE6: navigator.userAgent != null && navigator.userAgent.indexOf('MSIE 6') >= 0,
  39. /**
  40. * Variable: IS_IE11
  41. *
  42. * True if the current browser is Internet Explorer 11.x.
  43. */
  44. IS_IE11: navigator.userAgent != null && !!navigator.userAgent.match(/Trident\/7\./),
  45. /**
  46. * Variable: IS_EDGE
  47. *
  48. * True if the current browser is Microsoft Edge.
  49. */
  50. IS_EDGE: navigator.userAgent != null && !!navigator.userAgent.match(/Edge\//),
  51. /**
  52. * Variable: IS_QUIRKS
  53. *
  54. * True if the current browser is Internet Explorer and it is in quirks mode.
  55. */
  56. IS_QUIRKS: navigator.userAgent != null && navigator.userAgent.indexOf('MSIE') >= 0 &&
  57. (document.documentMode == null || document.documentMode == 5),
  58. /**
  59. * Variable: IS_EM
  60. *
  61. * True if the browser is IE11 in enterprise mode (IE8 standards mode).
  62. */
  63. IS_EM: 'spellcheck' in document.createElement('textarea') && document.documentMode == 8,
  64. /**
  65. * Variable: VML_PREFIX
  66. *
  67. * Prefix for VML namespace in node names. Default is 'v'.
  68. */
  69. VML_PREFIX: 'v',
  70. /**
  71. * Variable: OFFICE_PREFIX
  72. *
  73. * Prefix for VML office namespace in node names. Default is 'o'.
  74. */
  75. OFFICE_PREFIX: 'o',
  76. /**
  77. * Variable: IS_NS
  78. *
  79. * True if the current browser is Netscape (including Firefox).
  80. */
  81. IS_NS: navigator.userAgent != null &&
  82. navigator.userAgent.indexOf('Mozilla/') >= 0 &&
  83. navigator.userAgent.indexOf('MSIE') < 0 &&
  84. navigator.userAgent.indexOf('Edge/') < 0,
  85. /**
  86. * Variable: IS_OP
  87. *
  88. * True if the current browser is Opera.
  89. */
  90. IS_OP: navigator.userAgent != null &&
  91. (navigator.userAgent.indexOf('Opera/') >= 0 ||
  92. navigator.userAgent.indexOf('OPR/') >= 0),
  93. /**
  94. * Variable: IS_OT
  95. *
  96. * True if -o-transform is available as a CSS style, ie for Opera browsers
  97. * based on a Presto engine with version 2.5 or later.
  98. */
  99. IS_OT: navigator.userAgent != null &&
  100. navigator.userAgent.indexOf('Presto/') >= 0 &&
  101. navigator.userAgent.indexOf('Presto/2.4.') < 0 &&
  102. navigator.userAgent.indexOf('Presto/2.3.') < 0 &&
  103. navigator.userAgent.indexOf('Presto/2.2.') < 0 &&
  104. navigator.userAgent.indexOf('Presto/2.1.') < 0 &&
  105. navigator.userAgent.indexOf('Presto/2.0.') < 0 &&
  106. navigator.userAgent.indexOf('Presto/1.') < 0,
  107. /**
  108. * Variable: IS_SF
  109. *
  110. * True if the current browser is Safari.
  111. */
  112. IS_SF: /Apple Computer, Inc/.test(navigator.vendor),
  113. /**
  114. * Variable: IS_ANDROID
  115. *
  116. * Returns true if the user agent contains Android.
  117. */
  118. IS_ANDROID: navigator.appVersion.indexOf('Android') >= 0,
  119. /**
  120. * Variable: IS_IOS
  121. *
  122. * Returns true if the user agent is an iPad, iPhone or iPod.
  123. */
  124. IS_IOS: (/iP(hone|od|ad)/.test(navigator.platform)),
  125. /**
  126. * Variable: IS_GC
  127. *
  128. * True if the current browser is Google Chrome.
  129. */
  130. IS_GC: /Google Inc/.test(navigator.vendor),
  131. /**
  132. * Variable: IS_CHROMEAPP
  133. *
  134. * True if the this is running inside a Chrome App.
  135. */
  136. IS_CHROMEAPP: window.chrome != null && chrome.app != null && chrome.app.runtime != null,
  137. /**
  138. * Variable: IS_FF
  139. *
  140. * True if the current browser is Firefox.
  141. */
  142. IS_FF: typeof InstallTrigger !== 'undefined',
  143. /**
  144. * Variable: IS_MT
  145. *
  146. * True if -moz-transform is available as a CSS style. This is the case
  147. * for all Firefox-based browsers newer than or equal 3, such as Camino,
  148. * Iceweasel, Seamonkey and Iceape.
  149. */
  150. IS_MT: (navigator.userAgent.indexOf('Firefox/') >= 0 &&
  151. navigator.userAgent.indexOf('Firefox/1.') < 0 &&
  152. navigator.userAgent.indexOf('Firefox/2.') < 0) ||
  153. (navigator.userAgent.indexOf('Iceweasel/') >= 0 &&
  154. navigator.userAgent.indexOf('Iceweasel/1.') < 0 &&
  155. navigator.userAgent.indexOf('Iceweasel/2.') < 0) ||
  156. (navigator.userAgent.indexOf('SeaMonkey/') >= 0 &&
  157. navigator.userAgent.indexOf('SeaMonkey/1.') < 0) ||
  158. (navigator.userAgent.indexOf('Iceape/') >= 0 &&
  159. navigator.userAgent.indexOf('Iceape/1.') < 0),
  160. /**
  161. * Variable: IS_VML
  162. *
  163. * True if the browser supports VML.
  164. */
  165. IS_VML: navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER',
  166. /**
  167. * Variable: IS_SVG
  168. *
  169. * True if the browser supports SVG.
  170. */
  171. IS_SVG: navigator.appName.toUpperCase() != 'MICROSOFT INTERNET EXPLORER',
  172. /**
  173. * Variable: NO_FO
  174. *
  175. * True if foreignObject support is not available. This is the case for
  176. * Opera, older SVG-based browsers and all versions of IE.
  177. */
  178. NO_FO: !document.createElementNS || document.createElementNS('http://www.w3.org/2000/svg',
  179. 'foreignObject') != '[object SVGForeignObjectElement]' || navigator.userAgent.indexOf('Opera/') >= 0,
  180. /**
  181. * Variable: IS_WIN
  182. *
  183. * True if the client is a Windows.
  184. */
  185. IS_WIN: navigator.appVersion.indexOf('Win') > 0,
  186. /**
  187. * Variable: IS_MAC
  188. *
  189. * True if the client is a Mac.
  190. */
  191. IS_MAC: navigator.appVersion.indexOf('Mac') > 0,
  192. /**
  193. * Variable: IS_CHROMEOS
  194. *
  195. * True if the client is a Chrome OS.
  196. */
  197. IS_CHROMEOS: /\bCrOS\b/.test(navigator.appVersion),
  198. /**
  199. * Variable: IS_TOUCH
  200. *
  201. * True if this device supports touchstart/-move/-end events (Apple iOS,
  202. * Android, Chromebook and Chrome Browser on touch-enabled devices).
  203. */
  204. IS_TOUCH: 'ontouchstart' in document.documentElement,
  205. /**
  206. * Variable: IS_POINTER
  207. *
  208. * True if this device supports Microsoft pointer events (always false on Macs).
  209. */
  210. IS_POINTER: window.PointerEvent != null && !(navigator.appVersion.indexOf('Mac') > 0),
  211. /**
  212. * Variable: IS_LOCAL
  213. *
  214. * True if the documents location does not start with http:// or https://.
  215. */
  216. IS_LOCAL: document.location.href.indexOf('http://') < 0 &&
  217. document.location.href.indexOf('https://') < 0,
  218. /**
  219. * Variable: defaultBundles
  220. *
  221. * Contains the base names of the default bundles if mxLoadResources is false.
  222. */
  223. defaultBundles: [],
  224. /**
  225. * Function: isBrowserSupported
  226. *
  227. * Returns true if the current browser is supported, that is, if
  228. * <mxClient.IS_VML> or <mxClient.IS_SVG> is true.
  229. *
  230. * Example:
  231. *
  232. * (code)
  233. * if (!mxClient.isBrowserSupported())
  234. * {
  235. * mxUtils.error('Browser is not supported!', 200, false);
  236. * }
  237. * (end)
  238. */
  239. isBrowserSupported: function()
  240. {
  241. return mxClient.IS_VML || mxClient.IS_SVG;
  242. },
  243. /**
  244. * Function: link
  245. *
  246. * Adds a link node to the head of the document. Use this
  247. * to add a stylesheet to the page as follows:
  248. *
  249. * (code)
  250. * mxClient.link('stylesheet', filename);
  251. * (end)
  252. *
  253. * where filename is the (relative) URL of the stylesheet. The charset
  254. * is hardcoded to ISO-8859-1 and the type is text/css.
  255. *
  256. * Parameters:
  257. *
  258. * rel - String that represents the rel attribute of the link node.
  259. * href - String that represents the href attribute of the link node.
  260. * doc - Optional parent document of the link node.
  261. * id - unique id for the link element to check if it already exists
  262. */
  263. link: function(rel, href, doc, id)
  264. {
  265. doc = doc || document;
  266. // Workaround for Operation Aborted in IE6 if base tag is used in head
  267. if (mxClient.IS_IE6)
  268. {
  269. doc.write('<link rel="' + rel + '" href="' + href + '" charset="UTF-8" type="text/css"/>');
  270. }
  271. else
  272. {
  273. var link = doc.createElement('link');
  274. link.setAttribute('rel', rel);
  275. link.setAttribute('href', href);
  276. link.setAttribute('charset', 'UTF-8');
  277. link.setAttribute('type', 'text/css');
  278. if (id)
  279. {
  280. link.setAttribute('id', id);
  281. }
  282. var head = doc.getElementsByTagName('head')[0];
  283. head.appendChild(link);
  284. }
  285. },
  286. /**
  287. * Function: loadResources
  288. *
  289. * Helper method to load the default bundles if mxLoadResources is false.
  290. *
  291. * Parameters:
  292. *
  293. * fn - Function to call after all resources have been loaded.
  294. * lan - Optional string to pass to <mxResources.add>.
  295. */
  296. loadResources: function(fn, lan)
  297. {
  298. var pending = mxClient.defaultBundles.length;
  299. function callback()
  300. {
  301. if (--pending == 0)
  302. {
  303. fn();
  304. }
  305. }
  306. for (var i = 0; i < mxClient.defaultBundles.length; i++)
  307. {
  308. mxResources.add(mxClient.defaultBundles[i], lan, callback);
  309. }
  310. },
  311. /**
  312. * Function: include
  313. *
  314. * Dynamically adds a script node to the document header.
  315. *
  316. * In production environments, the includes are resolved in the mxClient.js
  317. * file to reduce the number of requests required for client startup. This
  318. * function should only be used in development environments, but not in
  319. * production systems.
  320. */
  321. include: function(src)
  322. {
  323. document.write('<script src="'+src+'"></script>');
  324. }
  325. };
  326. /**
  327. * Variable: mxLoadResources
  328. *
  329. * Optional global config variable to toggle loading of the two resource files
  330. * in <mxGraph> and <mxEditor>. Default is true. NOTE: This is a global variable,
  331. * not a variable of mxClient. If this is false, you can use <mxClient.loadResources>
  332. * with its callback to load the default bundles asynchronously.
  333. *
  334. * (code)
  335. * <script type="text/javascript">
  336. * var mxLoadResources = false;
  337. * </script>
  338. * <script type="text/javascript" src="/path/to/core/directory/js/mxClient.js"></script>
  339. * (end)
  340. */
  341. if (typeof(mxLoadResources) == 'undefined')
  342. {
  343. mxLoadResources = true;
  344. }
  345. /**
  346. * Variable: mxForceIncludes
  347. *
  348. * Optional global config variable to force loading the JavaScript files in
  349. * development mode. Default is undefined. NOTE: This is a global variable,
  350. * not a variable of mxClient.
  351. *
  352. * (code)
  353. * <script type="text/javascript">
  354. * var mxLoadResources = true;
  355. * </script>
  356. * <script type="text/javascript" src="/path/to/core/directory/js/mxClient.js"></script>
  357. * (end)
  358. */
  359. if (typeof(mxForceIncludes) == 'undefined')
  360. {
  361. mxForceIncludes = false;
  362. }
  363. /**
  364. * Variable: mxResourceExtension
  365. *
  366. * Optional global config variable to specify the extension of resource files.
  367. * Default is true. NOTE: This is a global variable, not a variable of mxClient.
  368. *
  369. * (code)
  370. * <script type="text/javascript">
  371. * var mxResourceExtension = '.txt';
  372. * </script>
  373. * <script type="text/javascript" src="/path/to/core/directory/js/mxClient.js"></script>
  374. * (end)
  375. */
  376. if (typeof(mxResourceExtension) == 'undefined')
  377. {
  378. mxResourceExtension = '.txt';
  379. }
  380. /**
  381. * Variable: mxLoadStylesheets
  382. *
  383. * Optional global config variable to toggle loading of the CSS files when
  384. * the library is initialized. Default is true. NOTE: This is a global variable,
  385. * not a variable of mxClient.
  386. *
  387. * (code)
  388. * <script type="text/javascript">
  389. * var mxLoadStylesheets = false;
  390. * </script>
  391. * <script type="text/javascript" src="/path/to/core/directory/js/mxClient.js"></script>
  392. * (end)
  393. */
  394. if (typeof(mxLoadStylesheets) == 'undefined')
  395. {
  396. mxLoadStylesheets = true;
  397. }
  398. /**
  399. * Variable: basePath
  400. *
  401. * Basepath for all URLs in the core without trailing slash. Default is '.'.
  402. * Set mxBasePath prior to loading the mxClient library as follows to override
  403. * this setting:
  404. *
  405. * (code)
  406. * <script type="text/javascript">
  407. * mxBasePath = '/path/to/core/directory';
  408. * </script>
  409. * <script type="text/javascript" src="/path/to/core/directory/js/mxClient.js"></script>
  410. * (end)
  411. *
  412. * When using a relative path, the path is relative to the URL of the page that
  413. * contains the assignment. Trailing slashes are automatically removed.
  414. */
  415. if (typeof(mxBasePath) != 'undefined' && mxBasePath.length > 0)
  416. {
  417. // Adds a trailing slash if required
  418. if (mxBasePath.substring(mxBasePath.length - 1) == '/')
  419. {
  420. mxBasePath = mxBasePath.substring(0, mxBasePath.length - 1);
  421. }
  422. mxClient.basePath = mxBasePath;
  423. }
  424. else
  425. {
  426. mxClient.basePath = '.';
  427. }
  428. /**
  429. * Variable: imageBasePath
  430. *
  431. * Basepath for all images URLs in the core without trailing slash. Default is
  432. * <mxClient.basePath> + '/images'. Set mxImageBasePath prior to loading the
  433. * mxClient library as follows to override this setting:
  434. *
  435. * (code)
  436. * <script type="text/javascript">
  437. * mxImageBasePath = '/path/to/image/directory';
  438. * </script>
  439. * <script type="text/javascript" src="/path/to/core/directory/js/mxClient.js"></script>
  440. * (end)
  441. *
  442. * When using a relative path, the path is relative to the URL of the page that
  443. * contains the assignment. Trailing slashes are automatically removed.
  444. */
  445. if (typeof(mxImageBasePath) != 'undefined' && mxImageBasePath.length > 0)
  446. {
  447. // Adds a trailing slash if required
  448. if (mxImageBasePath.substring(mxImageBasePath.length - 1) == '/')
  449. {
  450. mxImageBasePath = mxImageBasePath.substring(0, mxImageBasePath.length - 1);
  451. }
  452. mxClient.imageBasePath = mxImageBasePath;
  453. }
  454. else
  455. {
  456. mxClient.imageBasePath = mxClient.basePath + '/images';
  457. }
  458. /**
  459. * Variable: language
  460. *
  461. * Defines the language of the client, eg. en for english, de for german etc.
  462. * The special value 'none' will disable all built-in internationalization and
  463. * resource loading. See <mxResources.getSpecialBundle> for handling identifiers
  464. * with and without a dash.
  465. *
  466. * Set mxLanguage prior to loading the mxClient library as follows to override
  467. * this setting:
  468. *
  469. * (code)
  470. * <script type="text/javascript">
  471. * mxLanguage = 'en';
  472. * </script>
  473. * <script type="text/javascript" src="js/mxClient.js"></script>
  474. * (end)
  475. *
  476. * If internationalization is disabled, then the following variables should be
  477. * overridden to reflect the current language of the system. These variables are
  478. * cleared when i18n is disabled.
  479. * <mxEditor.askZoomResource>, <mxEditor.lastSavedResource>,
  480. * <mxEditor.currentFileResource>, <mxEditor.propertiesResource>,
  481. * <mxEditor.tasksResource>, <mxEditor.helpResource>, <mxEditor.outlineResource>,
  482. * <mxElbowEdgeHandler.doubleClickOrientationResource>, <mxUtils.errorResource>,
  483. * <mxUtils.closeResource>, <mxGraphSelectionModel.doneResource>,
  484. * <mxGraphSelectionModel.updatingSelectionResource>, <mxGraphView.doneResource>,
  485. * <mxGraphView.updatingDocumentResource>, <mxCellRenderer.collapseExpandResource>,
  486. * <mxGraph.containsValidationErrorsResource> and
  487. * <mxGraph.alreadyConnectedResource>.
  488. */
  489. if (typeof(mxLanguage) != 'undefined' && mxLanguage != null)
  490. {
  491. mxClient.language = mxLanguage;
  492. }
  493. else
  494. {
  495. mxClient.language = (mxClient.IS_IE) ? navigator.userLanguage : navigator.language;
  496. }
  497. /**
  498. * Variable: defaultLanguage
  499. *
  500. * Defines the default language which is used in the common resource files. Any
  501. * resources for this language will only load the common resource file, but not
  502. * the language-specific resource file. Default is 'en'.
  503. *
  504. * Set mxDefaultLanguage prior to loading the mxClient library as follows to override
  505. * this setting:
  506. *
  507. * (code)
  508. * <script type="text/javascript">
  509. * mxDefaultLanguage = 'de';
  510. * </script>
  511. * <script type="text/javascript" src="js/mxClient.js"></script>
  512. * (end)
  513. */
  514. if (typeof(mxDefaultLanguage) != 'undefined' && mxDefaultLanguage != null)
  515. {
  516. mxClient.defaultLanguage = mxDefaultLanguage;
  517. }
  518. else
  519. {
  520. mxClient.defaultLanguage = 'en';
  521. }
  522. // Adds all required stylesheets and namespaces
  523. if (mxLoadStylesheets)
  524. {
  525. mxClient.link('stylesheet', mxClient.basePath + '/css/common.css');
  526. }
  527. /**
  528. * Variable: languages
  529. *
  530. * Defines the optional array of all supported language extensions. The default
  531. * language does not have to be part of this list. See
  532. * <mxResources.isLanguageSupported>.
  533. *
  534. * (code)
  535. * <script type="text/javascript">
  536. * mxLanguages = ['de', 'it', 'fr'];
  537. * </script>
  538. * <script type="text/javascript" src="js/mxClient.js"></script>
  539. * (end)
  540. *
  541. * This is used to avoid unnecessary requests to language files, ie. if a 404
  542. * will be returned.
  543. */
  544. if (typeof(mxLanguages) != 'undefined' && mxLanguages != null)
  545. {
  546. mxClient.languages = mxLanguages;
  547. }
  548. // Adds required namespaces, stylesheets and memory handling for older IE browsers
  549. if (mxClient.IS_VML)
  550. {
  551. if (mxClient.IS_SVG)
  552. {
  553. mxClient.IS_VML = false;
  554. }
  555. else
  556. {
  557. // Enables support for IE8 standards mode. Note that this requires all attributes for VML
  558. // elements to be set using direct notation, ie. node.attr = value, not setAttribute.
  559. if (document.namespaces != null)
  560. {
  561. if (document.documentMode == 8)
  562. {
  563. document.namespaces.add(mxClient.VML_PREFIX, 'urn:schemas-microsoft-com:vml', '#default#VML');
  564. document.namespaces.add(mxClient.OFFICE_PREFIX, 'urn:schemas-microsoft-com:office:office', '#default#VML');
  565. }
  566. else
  567. {
  568. document.namespaces.add(mxClient.VML_PREFIX, 'urn:schemas-microsoft-com:vml');
  569. document.namespaces.add(mxClient.OFFICE_PREFIX, 'urn:schemas-microsoft-com:office:office');
  570. }
  571. }
  572. // Workaround for limited number of stylesheets in IE (does not work in standards mode)
  573. if (mxClient.IS_QUIRKS && document.styleSheets.length >= 30)
  574. {
  575. (function()
  576. {
  577. var node = document.createElement('style');
  578. node.type = 'text/css';
  579. node.styleSheet.cssText = mxClient.VML_PREFIX + '\\:*{behavior:url(#default#VML)}' +
  580. mxClient.OFFICE_PREFIX + '\\:*{behavior:url(#default#VML)}';
  581. document.getElementsByTagName('head')[0].appendChild(node);
  582. })();
  583. }
  584. else
  585. {
  586. document.createStyleSheet().cssText = mxClient.VML_PREFIX + '\\:*{behavior:url(#default#VML)}' +
  587. mxClient.OFFICE_PREFIX + '\\:*{behavior:url(#default#VML)}';
  588. }
  589. if (mxLoadStylesheets)
  590. {
  591. mxClient.link('stylesheet', mxClient.basePath + '/css/explorer.css');
  592. }
  593. }
  594. }
  595. /**
  596. * Copyright (c) 2006-2015, JGraph Ltd
  597. * Copyright (c) 2006-2015, Gaudenz Alder
  598. */
  599. var mxLog =
  600. {
  601. /**
  602. * Class: mxLog
  603. *
  604. * A singleton class that implements a simple console.
  605. *
  606. * Variable: consoleName
  607. *
  608. * Specifies the name of the console window. Default is 'Console'.
  609. */
  610. consoleName: 'Console',
  611. /**
  612. * Variable: TRACE
  613. *
  614. * Specified if the output for <enter> and <leave> should be visible in the
  615. * console. Default is false.
  616. */
  617. TRACE: false,
  618. /**
  619. * Variable: DEBUG
  620. *
  621. * Specifies if the output for <debug> should be visible in the console.
  622. * Default is true.
  623. */
  624. DEBUG: true,
  625. /**
  626. * Variable: WARN
  627. *
  628. * Specifies if the output for <warn> should be visible in the console.
  629. * Default is true.
  630. */
  631. WARN: true,
  632. /**
  633. * Variable: buffer
  634. *
  635. * Buffer for pre-initialized content.
  636. */
  637. buffer: '',
  638. /**
  639. * Function: init
  640. *
  641. * Initializes the DOM node for the console. This requires document.body to
  642. * point to a non-null value. This is called from within <setVisible> if the
  643. * log has not yet been initialized.
  644. */
  645. init: function()
  646. {
  647. if (mxLog.window == null && document.body != null)
  648. {
  649. var title = mxLog.consoleName + ' - mxGraph ' + mxClient.VERSION;
  650. // Creates a table that maintains the layout
  651. var table = document.createElement('table');
  652. table.setAttribute('width', '100%');
  653. table.setAttribute('height', '100%');
  654. var tbody = document.createElement('tbody');
  655. var tr = document.createElement('tr');
  656. var td = document.createElement('td');
  657. td.style.verticalAlign = 'top';
  658. // Adds the actual console as a textarea
  659. mxLog.textarea = document.createElement('textarea');
  660. mxLog.textarea.setAttribute('wrap', 'off');
  661. mxLog.textarea.setAttribute('readOnly', 'true');
  662. mxLog.textarea.style.height = '100%';
  663. mxLog.textarea.style.resize = 'none';
  664. mxLog.textarea.value = mxLog.buffer;
  665. // Workaround for wrong width in standards mode
  666. if (mxClient.IS_NS && document.compatMode != 'BackCompat')
  667. {
  668. mxLog.textarea.style.width = '99%';
  669. }
  670. else
  671. {
  672. mxLog.textarea.style.width = '100%';
  673. }
  674. td.appendChild(mxLog.textarea);
  675. tr.appendChild(td);
  676. tbody.appendChild(tr);
  677. // Creates the container div
  678. tr = document.createElement('tr');
  679. mxLog.td = document.createElement('td');
  680. mxLog.td.style.verticalAlign = 'top';
  681. mxLog.td.setAttribute('height', '30px');
  682. tr.appendChild(mxLog.td);
  683. tbody.appendChild(tr);
  684. table.appendChild(tbody);
  685. // Adds various debugging buttons
  686. mxLog.addButton('Info', function (evt)
  687. {
  688. mxLog.info();
  689. });
  690. mxLog.addButton('DOM', function (evt)
  691. {
  692. var content = mxUtils.getInnerHtml(document.body);
  693. mxLog.debug(content);
  694. });
  695. mxLog.addButton('Trace', function (evt)
  696. {
  697. mxLog.TRACE = !mxLog.TRACE;
  698. if (mxLog.TRACE)
  699. {
  700. mxLog.debug('Tracing enabled');
  701. }
  702. else
  703. {
  704. mxLog.debug('Tracing disabled');
  705. }
  706. });
  707. mxLog.addButton('Copy', function (evt)
  708. {
  709. try
  710. {
  711. mxUtils.copy(mxLog.textarea.value);
  712. }
  713. catch (err)
  714. {
  715. mxUtils.alert(err);
  716. }
  717. });
  718. mxLog.addButton('Show', function (evt)
  719. {
  720. try
  721. {
  722. mxUtils.popup(mxLog.textarea.value);
  723. }
  724. catch (err)
  725. {
  726. mxUtils.alert(err);
  727. }
  728. });
  729. mxLog.addButton('Clear', function (evt)
  730. {
  731. mxLog.textarea.value = '';
  732. });
  733. // Cross-browser code to get window size
  734. var h = 0;
  735. var w = 0;
  736. if (typeof(window.innerWidth) === 'number')
  737. {
  738. h = window.innerHeight;
  739. w = window.innerWidth;
  740. }
  741. else
  742. {
  743. h = (document.documentElement.clientHeight || document.body.clientHeight);
  744. w = document.body.clientWidth;
  745. }
  746. mxLog.window = new mxWindow(title, table, Math.max(0, w - 320), Math.max(0, h - 210), 300, 160);
  747. mxLog.window.setMaximizable(true);
  748. mxLog.window.setScrollable(false);
  749. mxLog.window.setResizable(true);
  750. mxLog.window.setClosable(true);
  751. mxLog.window.destroyOnClose = false;
  752. // Workaround for ignored textarea height in various setups
  753. if (((mxClient.IS_NS || mxClient.IS_IE) && !mxClient.IS_GC &&
  754. !mxClient.IS_SF && document.compatMode != 'BackCompat') ||
  755. document.documentMode == 11)
  756. {
  757. var elt = mxLog.window.getElement();
  758. var resizeHandler = function(sender, evt)
  759. {
  760. mxLog.textarea.style.height = Math.max(0, elt.offsetHeight - 70) + 'px';
  761. };
  762. mxLog.window.addListener(mxEvent.RESIZE_END, resizeHandler);
  763. mxLog.window.addListener(mxEvent.MAXIMIZE, resizeHandler);
  764. mxLog.window.addListener(mxEvent.NORMALIZE, resizeHandler);
  765. mxLog.textarea.style.height = '92px';
  766. }
  767. }
  768. },
  769. /**
  770. * Function: info
  771. *
  772. * Writes the current navigator information to the console.
  773. */
  774. info: function()
  775. {
  776. mxLog.writeln(mxUtils.toString(navigator));
  777. },
  778. /**
  779. * Function: addButton
  780. *
  781. * Adds a button to the console using the given label and function.
  782. */
  783. addButton: function(lab, funct)
  784. {
  785. var button = document.createElement('button');
  786. mxUtils.write(button, lab);
  787. mxEvent.addListener(button, 'click', funct);
  788. mxLog.td.appendChild(button);
  789. },
  790. /**
  791. * Function: isVisible
  792. *
  793. * Returns true if the console is visible.
  794. */
  795. isVisible: function()
  796. {
  797. if (mxLog.window != null)
  798. {
  799. return mxLog.window.isVisible();
  800. }
  801. return false;
  802. },
  803. /**
  804. * Function: show
  805. *
  806. * Shows the console.
  807. */
  808. show: function()
  809. {
  810. mxLog.setVisible(true);
  811. },
  812. /**
  813. * Function: setVisible
  814. *
  815. * Shows or hides the console.
  816. */
  817. setVisible: function(visible)
  818. {
  819. if (mxLog.window == null)
  820. {
  821. mxLog.init();
  822. }
  823. if (mxLog.window != null)
  824. {
  825. mxLog.window.setVisible(visible);
  826. }
  827. },
  828. /**
  829. * Function: enter
  830. *
  831. * Writes the specified string to the console
  832. * if <TRACE> is true and returns the current
  833. * time in milliseconds.
  834. *
  835. * Example:
  836. *
  837. * (code)
  838. * mxLog.show();
  839. * var t0 = mxLog.enter('Hello');
  840. * // Do something
  841. * mxLog.leave('World!', t0);
  842. * (end)
  843. */
  844. enter: function(string)
  845. {
  846. if (mxLog.TRACE)
  847. {
  848. mxLog.writeln('Entering '+string);
  849. return new Date().getTime();
  850. }
  851. },
  852. /**
  853. * Function: leave
  854. *
  855. * Writes the specified string to the console
  856. * if <TRACE> is true and computes the difference
  857. * between the current time and t0 in milliseconds.
  858. * See <enter> for an example.
  859. */
  860. leave: function(string, t0)
  861. {
  862. if (mxLog.TRACE)
  863. {
  864. var dt = (t0 != 0) ? ' ('+(new Date().getTime() - t0)+' ms)' : '';
  865. mxLog.writeln('Leaving '+string+dt);
  866. }
  867. },
  868. /**
  869. * Function: debug
  870. *
  871. * Adds all arguments to the console if <DEBUG> is enabled.
  872. *
  873. * Example:
  874. *
  875. * (code)
  876. * mxLog.show();
  877. * mxLog.debug('Hello, World!');
  878. * (end)
  879. */
  880. debug: function()
  881. {
  882. if (mxLog.DEBUG)
  883. {
  884. mxLog.writeln.apply(this, arguments);
  885. }
  886. },
  887. /**
  888. * Function: warn
  889. *
  890. * Adds all arguments to the console if <WARN> is enabled.
  891. *
  892. * Example:
  893. *
  894. * (code)
  895. * mxLog.show();
  896. * mxLog.warn('Hello, World!');
  897. * (end)
  898. */
  899. warn: function()
  900. {
  901. if (mxLog.WARN)
  902. {
  903. mxLog.writeln.apply(this, arguments);
  904. }
  905. },
  906. /**
  907. * Function: write
  908. *
  909. * Adds the specified strings to the console.
  910. */
  911. write: function()
  912. {
  913. var string = '';
  914. for (var i = 0; i < arguments.length; i++)
  915. {
  916. string += arguments[i];
  917. if (i < arguments.length - 1)
  918. {
  919. string += ' ';
  920. }
  921. }
  922. if (mxLog.textarea != null)
  923. {
  924. mxLog.textarea.value = mxLog.textarea.value + string;
  925. // Workaround for no update in Presto 2.5.22 (Opera 10.5)
  926. if (navigator.userAgent != null &&
  927. navigator.userAgent.indexOf('Presto/2.5') >= 0)
  928. {
  929. mxLog.textarea.style.visibility = 'hidden';
  930. mxLog.textarea.style.visibility = 'visible';
  931. }
  932. mxLog.textarea.scrollTop = mxLog.textarea.scrollHeight;
  933. }
  934. else
  935. {
  936. mxLog.buffer += string;
  937. }
  938. },
  939. /**
  940. * Function: writeln
  941. *
  942. * Adds the specified strings to the console, appending a linefeed at the
  943. * end of each string.
  944. */
  945. writeln: function()
  946. {
  947. var string = '';
  948. for (var i = 0; i < arguments.length; i++)
  949. {
  950. string += arguments[i];
  951. if (i < arguments.length - 1)
  952. {
  953. string += ' ';
  954. }
  955. }
  956. mxLog.write(string + '\n');
  957. }
  958. };
  959. /**
  960. * Copyright (c) 2006-2015, JGraph Ltd
  961. * Copyright (c) 2006-2015, Gaudenz Alder
  962. */
  963. var mxObjectIdentity =
  964. {
  965. /**
  966. * Class: mxObjectIdentity
  967. *
  968. * Identity for JavaScript objects and functions. This is implemented using
  969. * a simple incrementing counter which is stored in each object under
  970. * <FIELD_NAME>.
  971. *
  972. * The identity for an object does not change during its lifecycle.
  973. *
  974. * Variable: FIELD_NAME
  975. *
  976. * Name of the field to be used to store the object ID. Default is
  977. * <code>mxObjectId</code>.
  978. */
  979. FIELD_NAME: 'mxObjectId',
  980. /**
  981. * Variable: counter
  982. *
  983. * Current counter.
  984. */
  985. counter: 0,
  986. /**
  987. * Function: get
  988. *
  989. * Returns the ID for the given object or function or null if no object
  990. * is specified.
  991. */
  992. get: function(obj)
  993. {
  994. if (obj != null)
  995. {
  996. if (obj[mxObjectIdentity.FIELD_NAME] == null)
  997. {
  998. if (typeof obj === 'object')
  999. {
  1000. var ctor = mxUtils.getFunctionName(obj.constructor);
  1001. obj[mxObjectIdentity.FIELD_NAME] = ctor + '#' + mxObjectIdentity.counter++;
  1002. }
  1003. else if (typeof obj === 'function')
  1004. {
  1005. obj[mxObjectIdentity.FIELD_NAME] = 'Function#' + mxObjectIdentity.counter++;
  1006. }
  1007. }
  1008. return obj[mxObjectIdentity.FIELD_NAME];
  1009. }
  1010. return null;
  1011. },
  1012. /**
  1013. * Function: clear
  1014. *
  1015. * Deletes the ID from the given object or function.
  1016. */
  1017. clear: function(obj)
  1018. {
  1019. if (typeof(obj) === 'object' || typeof obj === 'function')
  1020. {
  1021. delete obj[mxObjectIdentity.FIELD_NAME];
  1022. }
  1023. }
  1024. };
  1025. /**
  1026. * Copyright (c) 2006-2015, JGraph Ltd
  1027. * Copyright (c) 2006-2015, Gaudenz Alder
  1028. */
  1029. /**
  1030. * Class: mxDictionary
  1031. *
  1032. * A wrapper class for an associative array with object keys. Note: This
  1033. * implementation uses <mxObjectIdentitiy> to turn object keys into strings.
  1034. *
  1035. * Constructor: mxEventSource
  1036. *
  1037. * Constructs a new dictionary which allows object to be used as keys.
  1038. */
  1039. function mxDictionary()
  1040. {
  1041. this.clear();
  1042. };
  1043. /**
  1044. * Function: map
  1045. *
  1046. * Stores the (key, value) pairs in this dictionary.
  1047. */
  1048. mxDictionary.prototype.map = null;
  1049. /**
  1050. * Function: clear
  1051. *
  1052. * Clears the dictionary.
  1053. */
  1054. mxDictionary.prototype.clear = function()
  1055. {
  1056. this.map = {};
  1057. };
  1058. /**
  1059. * Function: get
  1060. *
  1061. * Returns the value for the given key.
  1062. */
  1063. mxDictionary.prototype.get = function(key)
  1064. {
  1065. var id = mxObjectIdentity.get(key);
  1066. return this.map[id];
  1067. };
  1068. /**
  1069. * Function: put
  1070. *
  1071. * Stores the value under the given key and returns the previous
  1072. * value for that key.
  1073. */
  1074. mxDictionary.prototype.put = function(key, value)
  1075. {
  1076. var id = mxObjectIdentity.get(key);
  1077. var previous = this.map[id];
  1078. this.map[id] = value;
  1079. return previous;
  1080. };
  1081. /**
  1082. * Function: remove
  1083. *
  1084. * Removes the value for the given key and returns the value that
  1085. * has been removed.
  1086. */
  1087. mxDictionary.prototype.remove = function(key)
  1088. {
  1089. var id = mxObjectIdentity.get(key);
  1090. var previous = this.map[id];
  1091. delete this.map[id];
  1092. return previous;
  1093. };
  1094. /**
  1095. * Function: getKeys
  1096. *
  1097. * Returns all keys as an array.
  1098. */
  1099. mxDictionary.prototype.getKeys = function()
  1100. {
  1101. var result = [];
  1102. for (var key in this.map)
  1103. {
  1104. result.push(key);
  1105. }
  1106. return result;
  1107. };
  1108. /**
  1109. * Function: getValues
  1110. *
  1111. * Returns all values as an array.
  1112. */
  1113. mxDictionary.prototype.getValues = function()
  1114. {
  1115. var result = [];
  1116. for (var key in this.map)
  1117. {
  1118. result.push(this.map[key]);
  1119. }
  1120. return result;
  1121. };
  1122. /**
  1123. * Function: visit
  1124. *
  1125. * Visits all entries in the dictionary using the given function with the
  1126. * following signature: function(key, value) where key is a string and
  1127. * value is an object.
  1128. *
  1129. * Parameters:
  1130. *
  1131. * visitor - A function that takes the key and value as arguments.
  1132. */
  1133. mxDictionary.prototype.visit = function(visitor)
  1134. {
  1135. for (var key in this.map)
  1136. {
  1137. visitor(key, this.map[key]);
  1138. }
  1139. };
  1140. /**
  1141. * Copyright (c) 2006-2016, JGraph Ltd
  1142. * Copyright (c) 2006-2016, Gaudenz Alder
  1143. */
  1144. var mxResources =
  1145. {
  1146. /**
  1147. * Class: mxResources
  1148. *
  1149. * Implements internationalization. You can provide any number of
  1150. * resource files on the server using the following format for the
  1151. * filename: name[-en].properties. The en stands for any lowercase
  1152. * 2-character language shortcut (eg. de for german, fr for french).
  1153. *
  1154. * If the optional language extension is omitted, then the file is used as a
  1155. * default resource which is loaded in all cases. If a properties file for a
  1156. * specific language exists, then it is used to override the settings in the
  1157. * default resource. All entries in the file are of the form key=value. The
  1158. * values may then be accessed in code via <get>. Lines without
  1159. * equal signs in the properties files are ignored.
  1160. *
  1161. * Resource files may either be added programmatically using
  1162. * <add> or via a resource tag in the UI section of the
  1163. * editor configuration file, eg:
  1164. *
  1165. * (code)
  1166. * <mxEditor>
  1167. * <ui>
  1168. * <resource basename="examples/resources/mxWorkflow"/>
  1169. * (end)
  1170. *
  1171. * The above element will load examples/resources/mxWorkflow.properties as well
  1172. * as the language specific file for the current language, if it exists.
  1173. *
  1174. * Values may contain placeholders of the form {1}...{n} where each placeholder
  1175. * is replaced with the value of the corresponding array element in the params
  1176. * argument passed to <mxResources.get>. The placeholder {1} maps to the first
  1177. * element in the array (at index 0).
  1178. *
  1179. * See <mxClient.language> for more information on specifying the default
  1180. * language or disabling all loading of resources.
  1181. *
  1182. * Lines that start with a # sign will be ignored.
  1183. *
  1184. * Special characters
  1185. *
  1186. * To use unicode characters, use the standard notation (eg. \u8fd1) or %u as a
  1187. * prefix (eg. %u20AC will display a Euro sign). For normal hex encoded strings,
  1188. * use % as a prefix, eg. %F6 will display a "o umlaut" (&ouml;).
  1189. *
  1190. * See <resourcesEncoded> to disable this. If you disable this, make sure that
  1191. * your files are UTF-8 encoded.
  1192. *
  1193. * Asynchronous loading
  1194. *
  1195. * By default, the core adds two resource files synchronously at load time.
  1196. * To load these files asynchronously, set <mxLoadResources> to false
  1197. * before loading mxClient.js and use <mxResources.loadResources> instead.
  1198. *
  1199. * Variable: resources
  1200. *
  1201. * Object that maps from keys to values.
  1202. */
  1203. resources: {},
  1204. /**
  1205. * Variable: extension
  1206. *
  1207. * Specifies the extension used for language files. Default is <mxResourceExtension>.
  1208. */
  1209. extension: mxResourceExtension,
  1210. /**
  1211. * Variable: resourcesEncoded
  1212. *
  1213. * Specifies whether or not values in resource files are encoded with \u or
  1214. * percentage. Default is false.
  1215. */
  1216. resourcesEncoded: false,
  1217. /**
  1218. * Variable: loadDefaultBundle
  1219. *
  1220. * Specifies if the default file for a given basename should be loaded.
  1221. * Default is true.
  1222. */
  1223. loadDefaultBundle: true,
  1224. /**
  1225. * Variable: loadDefaultBundle
  1226. *
  1227. * Specifies if the specific language file file for a given basename should
  1228. * be loaded. Default is true.
  1229. */
  1230. loadSpecialBundle: true,
  1231. /**
  1232. * Function: isLanguageSupported
  1233. *
  1234. * Hook for subclassers to disable support for a given language. This
  1235. * implementation returns true if lan is in <mxClient.languages>.
  1236. *
  1237. * Parameters:
  1238. *
  1239. * lan - The current language.
  1240. */
  1241. isLanguageSupported: function(lan)
  1242. {
  1243. if (mxClient.languages != null)
  1244. {
  1245. return mxUtils.indexOf(mxClient.languages, lan) >= 0;
  1246. }
  1247. return true;
  1248. },
  1249. /**
  1250. * Function: getDefaultBundle
  1251. *
  1252. * Hook for subclassers to return the URL for the special bundle. This
  1253. * implementation returns basename + <extension> or null if
  1254. * <loadDefaultBundle> is false.
  1255. *
  1256. * Parameters:
  1257. *
  1258. * basename - The basename for which the file should be loaded.
  1259. * lan - The current language.
  1260. */
  1261. getDefaultBundle: function(basename, lan)
  1262. {
  1263. if (mxResources.loadDefaultBundle || !mxResources.isLanguageSupported(lan))
  1264. {
  1265. return basename + mxResources.extension;
  1266. }
  1267. else
  1268. {
  1269. return null;
  1270. }
  1271. },
  1272. /**
  1273. * Function: getSpecialBundle
  1274. *
  1275. * Hook for subclassers to return the URL for the special bundle. This
  1276. * implementation returns basename + '_' + lan + <extension> or null if
  1277. * <loadSpecialBundle> is false or lan equals <mxClient.defaultLanguage>.
  1278. *
  1279. * If <mxResources.languages> is not null and <mxClient.language> contains
  1280. * a dash, then this method checks if <isLanguageSupported> returns true
  1281. * for the full language (including the dash). If that returns false the
  1282. * first part of the language (up to the dash) will be tried as an extension.
  1283. *
  1284. * If <mxResources.language> is null then the first part of the language is
  1285. * used to maintain backwards compatibility.
  1286. *
  1287. * Parameters:
  1288. *
  1289. * basename - The basename for which the file should be loaded.
  1290. * lan - The language for which the file should be loaded.
  1291. */
  1292. getSpecialBundle: function(basename, lan)
  1293. {
  1294. if (mxClient.languages == null || !this.isLanguageSupported(lan))
  1295. {
  1296. var dash = lan.indexOf('-');
  1297. if (dash > 0)
  1298. {
  1299. lan = lan.substring(0, dash);
  1300. }
  1301. }
  1302. if (mxResources.loadSpecialBundle && mxResources.isLanguageSupported(lan) && lan != mxClient.defaultLanguage)
  1303. {
  1304. return basename + '_' + lan + mxResources.extension;
  1305. }
  1306. else
  1307. {
  1308. return null;
  1309. }
  1310. },
  1311. /**
  1312. * Function: add
  1313. *
  1314. * Adds the default and current language properties file for the specified
  1315. * basename. Existing keys are overridden as new files are added. If no
  1316. * callback is used then the request is synchronous.
  1317. *
  1318. * Example:
  1319. *
  1320. * At application startup, additional resources may be
  1321. * added using the following code:
  1322. *
  1323. * (code)
  1324. * mxResources.add('resources/editor');
  1325. * (end)
  1326. *
  1327. * Parameters:
  1328. *
  1329. * basename - The basename for which the file should be loaded.
  1330. * lan - The language for which the file should be loaded.
  1331. * callback - Optional callback for asynchronous loading.
  1332. */
  1333. add: function(basename, lan, callback)
  1334. {
  1335. lan = (lan != null) ? lan : ((mxClient.language != null) ?
  1336. mxClient.language.toLowerCase() : mxConstants.NONE);
  1337. if (lan != mxConstants.NONE)
  1338. {
  1339. var defaultBundle = mxResources.getDefaultBundle(basename, lan);
  1340. var specialBundle = mxResources.getSpecialBundle(basename, lan);
  1341. var loadSpecialBundle = function()
  1342. {
  1343. if (specialBundle != null)
  1344. {
  1345. if (callback)
  1346. {
  1347. mxUtils.get(specialBundle, function(req)
  1348. {
  1349. mxResources.parse(req.getText());
  1350. callback();
  1351. }, function()
  1352. {
  1353. callback();
  1354. });
  1355. }
  1356. else
  1357. {
  1358. try
  1359. {
  1360. var req = mxUtils.load(specialBundle);
  1361. if (req.isReady())
  1362. {
  1363. mxResources.parse(req.getText());
  1364. }
  1365. }
  1366. catch (e)
  1367. {
  1368. // ignore
  1369. }
  1370. }
  1371. }
  1372. else if (callback != null)
  1373. {
  1374. callback();
  1375. }
  1376. }
  1377. if (defaultBundle != null)
  1378. {
  1379. if (callback)
  1380. {
  1381. mxUtils.get(defaultBundle, function(req)
  1382. {
  1383. mxResources.parse(req.getText());
  1384. loadSpecialBundle();
  1385. }, function()
  1386. {
  1387. loadSpecialBundle();
  1388. });
  1389. }
  1390. else
  1391. {
  1392. try
  1393. {
  1394. var req = mxUtils.load(defaultBundle);
  1395. if (req.isReady())
  1396. {
  1397. mxResources.parse(req.getText());
  1398. }
  1399. loadSpecialBundle();
  1400. }
  1401. catch (e)
  1402. {
  1403. // ignore
  1404. }
  1405. }
  1406. }
  1407. else
  1408. {
  1409. // Overlays the language specific file (_lan-extension)
  1410. loadSpecialBundle();
  1411. }
  1412. }
  1413. },
  1414. /**
  1415. * Function: parse
  1416. *
  1417. * Parses the key, value pairs in the specified
  1418. * text and stores them as local resources.
  1419. */
  1420. parse: function(text)
  1421. {
  1422. if (text != null)
  1423. {
  1424. var lines = text.split('\n');
  1425. for (var i = 0; i < lines.length; i++)
  1426. {
  1427. if (lines[i].charAt(0) != '#')
  1428. {
  1429. var index = lines[i].indexOf('=');
  1430. if (index > 0)
  1431. {
  1432. var key = lines[i].substring(0, index);
  1433. var idx = lines[i].length;
  1434. if (lines[i].charCodeAt(idx - 1) == 13)
  1435. {
  1436. idx--;
  1437. }
  1438. var value = lines[i].substring(index + 1, idx);
  1439. if (this.resourcesEncoded)
  1440. {
  1441. value = value.replace(/\\(?=u[a-fA-F\d]{4})/g,"%");
  1442. mxResources.resources[key] = unescape(value);
  1443. }
  1444. else
  1445. {
  1446. mxResources.resources[key] = value;
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. },
  1453. /**
  1454. * Function: get
  1455. *
  1456. * Returns the value for the specified resource key.
  1457. *
  1458. * Example:
  1459. * To read the value for 'welomeMessage', use the following:
  1460. * (code)
  1461. * var result = mxResources.get('welcomeMessage') || '';
  1462. * (end)
  1463. *
  1464. * This would require an entry of the following form in
  1465. * one of the English language resource files:
  1466. * (code)
  1467. * welcomeMessage=Welcome to mxGraph!
  1468. * (end)
  1469. *
  1470. * The part behind the || is the string value to be used if the given
  1471. * resource is not available.
  1472. *
  1473. * Parameters:
  1474. *
  1475. * key - String that represents the key of the resource to be returned.
  1476. * params - Array of the values for the placeholders of the form {1}...{n}
  1477. * to be replaced with in the resulting string.
  1478. * defaultValue - Optional string that specifies the default return value.
  1479. */
  1480. get: function(key, params, defaultValue)
  1481. {
  1482. var value = mxResources.resources[key];
  1483. // Applies the default value if no resource was found
  1484. if (value == null)
  1485. {
  1486. value = defaultValue;
  1487. }
  1488. // Replaces the placeholders with the values in the array
  1489. if (value != null && params != null)
  1490. {
  1491. value = mxResources.replacePlaceholders(value, params);
  1492. }
  1493. return value;
  1494. },
  1495. /**
  1496. * Function: replacePlaceholders
  1497. *
  1498. * Replaces the given placeholders with the given parameters.
  1499. *
  1500. * Parameters:
  1501. *
  1502. * value - String that contains the placeholders.
  1503. * params - Array of the values for the placeholders of the form {1}...{n}
  1504. * to be replaced with in the resulting string.
  1505. */
  1506. replacePlaceholders: function(value, params)
  1507. {
  1508. var result = [];
  1509. var index = null;
  1510. for (var i = 0; i < value.length; i++)
  1511. {
  1512. var c = value.charAt(i);
  1513. if (c == '{')
  1514. {
  1515. index = '';
  1516. }
  1517. else if (index != null && c == '}')
  1518. {
  1519. index = parseInt(index)-1;
  1520. if (index >= 0 && index < params.length)
  1521. {
  1522. result.push(params[index]);
  1523. }
  1524. index = null;
  1525. }
  1526. else if (index != null)
  1527. {
  1528. index += c;
  1529. }
  1530. else
  1531. {
  1532. result.push(c);
  1533. }
  1534. }
  1535. return result.join('');
  1536. },
  1537. /**
  1538. * Function: loadResources
  1539. *
  1540. * Loads all required resources asynchronously. Use this to load the graph and
  1541. * editor resources if <mxLoadResources> is false.
  1542. *
  1543. * Parameters:
  1544. *
  1545. * callback - Callback function for asynchronous loading.
  1546. */
  1547. loadResources: function(callback)
  1548. {
  1549. mxResources.add(mxClient.basePath+'/resources/editor', null, function()
  1550. {
  1551. mxResources.add(mxClient.basePath+'/resources/graph', null, callback);
  1552. });
  1553. }
  1554. };
  1555. /**
  1556. * Copyright (c) 2006-2015, JGraph Ltd
  1557. * Copyright (c) 2006-2015, Gaudenz Alder
  1558. */
  1559. /**
  1560. * Class: mxPoint
  1561. *
  1562. * Implements a 2-dimensional vector with double precision coordinates.
  1563. *
  1564. * Constructor: mxPoint
  1565. *
  1566. * Constructs a new point for the optional x and y coordinates. If no
  1567. * coordinates are given, then the default values for <x> and <y> are used.
  1568. */
  1569. function mxPoint(x, y)
  1570. {
  1571. this.x = (x != null) ? x : 0;
  1572. this.y = (y != null) ? y : 0;
  1573. };
  1574. /**
  1575. * Variable: x
  1576. *
  1577. * Holds the x-coordinate of the point. Default is 0.
  1578. */
  1579. mxPoint.prototype.x = null;
  1580. /**
  1581. * Variable: y
  1582. *
  1583. * Holds the y-coordinate of the point. Default is 0.
  1584. */
  1585. mxPoint.prototype.y = null;
  1586. /**
  1587. * Function: equals
  1588. *
  1589. * Returns true if the given object equals this point.
  1590. */
  1591. mxPoint.prototype.equals = function(obj)
  1592. {
  1593. return obj != null && obj.x == this.x && obj.y == this.y;
  1594. };
  1595. /**
  1596. * Function: clone
  1597. *
  1598. * Returns a clone of this <mxPoint>.
  1599. */
  1600. mxPoint.prototype.clone = function()
  1601. {
  1602. // Handles subclasses as well
  1603. return mxUtils.clone(this);
  1604. };
  1605. /**
  1606. * Copyright (c) 2006-2015, JGraph Ltd
  1607. * Copyright (c) 2006-2015, Gaudenz Alder
  1608. */
  1609. /**
  1610. * Class: mxRectangle
  1611. *
  1612. * Extends <mxPoint> to implement a 2-dimensional rectangle with double
  1613. * precision coordinates.
  1614. *
  1615. * Constructor: mxRectangle
  1616. *
  1617. * Constructs a new rectangle for the optional parameters. If no parameters
  1618. * are given then the respective default values are used.
  1619. */
  1620. function mxRectangle(x, y, width, height)
  1621. {
  1622. mxPoint.call(this, x, y);
  1623. this.width = (width != null) ? width : 0;
  1624. this.height = (height != null) ? height : 0;
  1625. };
  1626. /**
  1627. * Extends mxPoint.
  1628. */
  1629. mxRectangle.prototype = new mxPoint();
  1630. mxRectangle.prototype.constructor = mxRectangle;
  1631. /**
  1632. * Variable: width
  1633. *
  1634. * Holds the width of the rectangle. Default is 0.
  1635. */
  1636. mxRectangle.prototype.width = null;
  1637. /**
  1638. * Variable: height
  1639. *
  1640. * Holds the height of the rectangle. Default is 0.
  1641. */
  1642. mxRectangle.prototype.height = null;
  1643. /**
  1644. * Function: setRect
  1645. *
  1646. * Sets this rectangle to the specified values
  1647. */
  1648. mxRectangle.prototype.setRect = function(x, y, w, h)
  1649. {
  1650. this.x = x;
  1651. this.y = y;
  1652. this.width = w;
  1653. this.height = h;
  1654. };
  1655. /**
  1656. * Function: getCenterX
  1657. *
  1658. * Returns the x-coordinate of the center point.
  1659. */
  1660. mxRectangle.prototype.getCenterX = function ()
  1661. {
  1662. return this.x + this.width/2;
  1663. };
  1664. /**
  1665. * Function: getCenterY
  1666. *
  1667. * Returns the y-coordinate of the center point.
  1668. */
  1669. mxRectangle.prototype.getCenterY = function ()
  1670. {
  1671. return this.y + this.height/2;
  1672. };
  1673. /**
  1674. * Function: add
  1675. *
  1676. * Adds the given rectangle to this rectangle.
  1677. */
  1678. mxRectangle.prototype.add = function(rect)
  1679. {
  1680. if (rect != null)
  1681. {
  1682. var minX = Math.min(this.x, rect.x);
  1683. var minY = Math.min(this.y, rect.y);
  1684. var maxX = Math.max(this.x + this.width, rect.x + rect.width);
  1685. var maxY = Math.max(this.y + this.height, rect.y + rect.height);
  1686. this.x = minX;
  1687. this.y = minY;
  1688. this.width = maxX - minX;
  1689. this.height = maxY - minY;
  1690. }
  1691. };
  1692. /**
  1693. * Function: intersect
  1694. *
  1695. * Changes this rectangle to where it overlaps with the given rectangle.
  1696. */
  1697. mxRectangle.prototype.intersect = function(rect)
  1698. {
  1699. if (rect != null)
  1700. {
  1701. var r1 = this.x + this.width;
  1702. var r2 = rect.x + rect.width;
  1703. var b1 = this.y + this.height;
  1704. var b2 = rect.y + rect.height;
  1705. this.x = Math.max(this.x, rect.x);
  1706. this.y = Math.max(this.y, rect.y);
  1707. this.width = Math.min(r1, r2) - this.x;
  1708. this.height = Math.min(b1, b2) - this.y;
  1709. }
  1710. };
  1711. /**
  1712. * Function: grow
  1713. *
  1714. * Grows the rectangle by the given amount, that is, this method subtracts
  1715. * the given amount from the x- and y-coordinates and adds twice the amount
  1716. * to the width and height.
  1717. */
  1718. mxRectangle.prototype.grow = function(amount)
  1719. {
  1720. this.x -= amount;
  1721. this.y -= amount;
  1722. this.width += 2 * amount;
  1723. this.height += 2 * amount;
  1724. return this;
  1725. };
  1726. /**
  1727. * Function: getPoint
  1728. *
  1729. * Returns the top, left corner as a new <mxPoint>.
  1730. */
  1731. mxRectangle.prototype.getPoint = function()
  1732. {
  1733. return new mxPoint(this.x, this.y);
  1734. };
  1735. /**
  1736. * Function: rotate90
  1737. *
  1738. * Rotates this rectangle by 90 degree around its center point.
  1739. */
  1740. mxRectangle.prototype.rotate90 = function()
  1741. {
  1742. var t = (this.width - this.height) / 2;
  1743. this.x += t;
  1744. this.y -= t;
  1745. var tmp = this.width;
  1746. this.width = this.height;
  1747. this.height = tmp;
  1748. };
  1749. /**
  1750. * Function: equals
  1751. *
  1752. * Returns true if the given object equals this rectangle.
  1753. */
  1754. mxRectangle.prototype.equals = function(obj)
  1755. {
  1756. return obj != null && obj.x == this.x && obj.y == this.y &&
  1757. obj.width == this.width && obj.height == this.height;
  1758. };
  1759. /**
  1760. * Function: fromRectangle
  1761. *
  1762. * Returns a new <mxRectangle> which is a copy of the given rectangle.
  1763. */
  1764. mxRectangle.fromRectangle = function(rect)
  1765. {
  1766. return new mxRectangle(rect.x, rect.y, rect.width, rect.height);
  1767. };
  1768. /**
  1769. * Copyright (c) 2006-2015, JGraph Ltd
  1770. * Copyright (c) 2006-2015, Gaudenz Alder
  1771. */
  1772. var mxEffects =
  1773. {
  1774. /**
  1775. * Class: mxEffects
  1776. *
  1777. * Provides animation effects.
  1778. */
  1779. /**
  1780. * Function: animateChanges
  1781. *
  1782. * Asynchronous animated move operation. See also: <mxMorphing>.
  1783. *
  1784. * Example:
  1785. *
  1786. * (code)
  1787. * graph.model.addListener(mxEvent.CHANGE, function(sender, evt)
  1788. * {
  1789. * var changes = evt.getProperty('edit').changes;
  1790. *
  1791. * if (changes.length < 10)
  1792. * {
  1793. * mxEffects.animateChanges(graph, changes);
  1794. * }
  1795. * });
  1796. * (end)
  1797. *
  1798. * Parameters:
  1799. *
  1800. * graph - <mxGraph> that received the changes.
  1801. * changes - Array of changes to be animated.
  1802. * done - Optional function argument that is invoked after the
  1803. * last step of the animation.
  1804. */
  1805. animateChanges: function(graph, changes, done)
  1806. {
  1807. var maxStep = 10;
  1808. var step = 0;
  1809. var animate = function()
  1810. {
  1811. var isRequired = false;
  1812. for (var i = 0; i < changes.length; i++)
  1813. {
  1814. var change = changes[i];
  1815. if (change instanceof mxGeometryChange ||
  1816. change instanceof mxTerminalChange ||
  1817. change instanceof mxValueChange ||
  1818. change instanceof mxChildChange ||
  1819. change instanceof mxStyleChange)
  1820. {
  1821. var state = graph.getView().getState(change.cell || change.child, false);
  1822. if (state != null)
  1823. {
  1824. isRequired = true;
  1825. if (change.constructor != mxGeometryChange || graph.model.isEdge(change.cell))
  1826. {
  1827. mxUtils.setOpacity(state.shape.node, 100 * step / maxStep);
  1828. }
  1829. else
  1830. {
  1831. var scale = graph.getView().scale;
  1832. var dx = (change.geometry.x - change.previous.x) * scale;
  1833. var dy = (change.geometry.y - change.previous.y) * scale;
  1834. var sx = (change.geometry.width - change.previous.width) * scale;
  1835. var sy = (change.geometry.height - change.previous.height) * scale;
  1836. if (step == 0)
  1837. {
  1838. state.x -= dx;
  1839. state.y -= dy;
  1840. state.width -= sx;
  1841. state.height -= sy;
  1842. }
  1843. else
  1844. {
  1845. state.x += dx / maxStep;
  1846. state.y += dy / maxStep;
  1847. state.width += sx / maxStep;
  1848. state.height += sy / maxStep;
  1849. }
  1850. graph.cellRenderer.redraw(state);
  1851. // Fades all connected edges and children
  1852. mxEffects.cascadeOpacity(graph, change.cell, 100 * step / maxStep);
  1853. }
  1854. }
  1855. }
  1856. }
  1857. if (step < maxStep && isRequired)
  1858. {
  1859. step++;
  1860. window.setTimeout(animate, delay);
  1861. }
  1862. else if (done != null)
  1863. {
  1864. done();
  1865. }
  1866. };
  1867. var delay = 30;
  1868. animate();
  1869. },
  1870. /**
  1871. * Function: cascadeOpacity
  1872. *
  1873. * Sets the opacity on the given cell and its descendants.
  1874. *
  1875. * Parameters:
  1876. *
  1877. * graph - <mxGraph> that contains the cells.
  1878. * cell - <mxCell> to set the opacity for.
  1879. * opacity - New value for the opacity in %.
  1880. */
  1881. cascadeOpacity: function(graph, cell, opacity)
  1882. {
  1883. // Fades all children
  1884. var childCount = graph.model.getChildCount(cell);
  1885. for (var i=0; i<childCount; i++)
  1886. {
  1887. var child = graph.model.getChildAt(cell, i);
  1888. var childState = graph.getView().getState(child);
  1889. if (childState != null)
  1890. {
  1891. mxUtils.setOpacity(childState.shape.node, opacity);
  1892. mxEffects.cascadeOpacity(graph, child, opacity);
  1893. }
  1894. }
  1895. // Fades all connected edges
  1896. var edges = graph.model.getEdges(cell);
  1897. if (edges != null)
  1898. {
  1899. for (var i=0; i<edges.length; i++)
  1900. {
  1901. var edgeState = graph.getView().getState(edges[i]);
  1902. if (edgeState != null)
  1903. {
  1904. mxUtils.setOpacity(edgeState.shape.node, opacity);
  1905. }
  1906. }
  1907. }
  1908. },
  1909. /**
  1910. * Function: fadeOut
  1911. *
  1912. * Asynchronous fade-out operation.
  1913. */
  1914. fadeOut: function(node, from, remove, step, delay, isEnabled)
  1915. {
  1916. step = step || 40;
  1917. delay = delay || 30;
  1918. var opacity = from || 100;
  1919. mxUtils.setOpacity(node, opacity);
  1920. if (isEnabled || isEnabled == null)
  1921. {
  1922. var f = function()
  1923. {
  1924. opacity = Math.max(opacity-step, 0);
  1925. mxUtils.setOpacity(node, opacity);
  1926. if (opacity > 0)
  1927. {
  1928. window.setTimeout(f, delay);
  1929. }
  1930. else
  1931. {
  1932. node.style.visibility = 'hidden';
  1933. if (remove && node.parentNode)
  1934. {
  1935. node.parentNode.removeChild(node);
  1936. }
  1937. }
  1938. };
  1939. window.setTimeout(f, delay);
  1940. }
  1941. else
  1942. {
  1943. node.style.visibility = 'hidden';
  1944. if (remove && node.parentNode)
  1945. {
  1946. node.parentNode.removeChild(node);
  1947. }
  1948. }
  1949. }
  1950. };
  1951. /**
  1952. * Copyright (c) 2006-2015, JGraph Ltd
  1953. * Copyright (c) 2006-2015, Gaudenz Alder
  1954. */
  1955. var mxUtils =
  1956. {
  1957. /**
  1958. * Class: mxUtils
  1959. *
  1960. * A singleton class that provides cross-browser helper methods.
  1961. * This is a global functionality. To access the functions in this
  1962. * class, use the global classname appended by the functionname.
  1963. * You may have to load chrome://global/content/contentAreaUtils.js
  1964. * to disable certain security restrictions in Mozilla for the <open>,
  1965. * <save>, <saveAs> and <copy> function.
  1966. *
  1967. * For example, the following code displays an error message:
  1968. *
  1969. * (code)
  1970. * mxUtils.error('Browser is not supported!', 200, false);
  1971. * (end)
  1972. *
  1973. * Variable: errorResource
  1974. *
  1975. * Specifies the resource key for the title of the error window. If the
  1976. * resource for this key does not exist then the value is used as
  1977. * the title. Default is 'error'.
  1978. */
  1979. errorResource: (mxClient.language != 'none') ? 'error' : '',
  1980. /**
  1981. * Variable: closeResource
  1982. *
  1983. * Specifies the resource key for the label of the close button. If the
  1984. * resource for this key does not exist then the value is used as
  1985. * the label. Default is 'close'.
  1986. */
  1987. closeResource: (mxClient.language != 'none') ? 'close' : '',
  1988. /**
  1989. * Variable: errorImage
  1990. *
  1991. * Defines the image used for error dialogs.
  1992. */
  1993. errorImage: mxClient.imageBasePath + '/error.gif',
  1994. /**
  1995. * Function: removeCursors
  1996. *
  1997. * Removes the cursors from the style of the given DOM node and its
  1998. * descendants.
  1999. *
  2000. * Parameters:
  2001. *
  2002. * element - DOM node to remove the cursor style from.
  2003. */
  2004. removeCursors: function(element)
  2005. {
  2006. if (element.style != null)
  2007. {
  2008. element.style.cursor = '';
  2009. }
  2010. var children = element.childNodes;
  2011. if (children != null)
  2012. {
  2013. var childCount = children.length;
  2014. for (var i = 0; i < childCount; i += 1)
  2015. {
  2016. mxUtils.removeCursors(children[i]);
  2017. }
  2018. }
  2019. },
  2020. /**
  2021. * Function: getCurrentStyle
  2022. *
  2023. * Returns the current style of the specified element.
  2024. *
  2025. * Parameters:
  2026. *
  2027. * element - DOM node whose current style should be returned.
  2028. */
  2029. getCurrentStyle: function()
  2030. {
  2031. if (mxClient.IS_IE && (document.documentMode == null || document.documentMode < 9))
  2032. {
  2033. return function(element)
  2034. {
  2035. return (element != null) ? element.currentStyle : null;
  2036. };
  2037. }
  2038. else
  2039. {
  2040. return function(element)
  2041. {
  2042. return (element != null) ?
  2043. window.getComputedStyle(element, '') :
  2044. null;
  2045. };
  2046. }
  2047. }(),
  2048. /**
  2049. * Function: parseCssNumber
  2050. *
  2051. * Parses the given CSS numeric value adding handling for the values thin,
  2052. * medium and thick (2, 4 and 6).
  2053. */
  2054. parseCssNumber: function(value)
  2055. {
  2056. if (value == 'thin')
  2057. {
  2058. value = '2';
  2059. }
  2060. else if (value == 'medium')
  2061. {
  2062. value = '4';
  2063. }
  2064. else if (value == 'thick')
  2065. {
  2066. value = '6';
  2067. }
  2068. value = parseFloat(value);
  2069. if (isNaN(value))
  2070. {
  2071. value = 0;
  2072. }
  2073. return value;
  2074. },
  2075. /**
  2076. * Function: setPrefixedStyle
  2077. *
  2078. * Adds the given style with the standard name and an optional vendor prefix for the current
  2079. * browser.
  2080. *
  2081. * (code)
  2082. * mxUtils.setPrefixedStyle(node.style, 'transformOrigin', '0% 0%');
  2083. * (end)
  2084. */
  2085. setPrefixedStyle: function()
  2086. {
  2087. var prefix = null;
  2088. if (mxClient.IS_OT)
  2089. {
  2090. prefix = 'O';
  2091. }
  2092. else if (mxClient.IS_SF || mxClient.IS_GC)
  2093. {
  2094. prefix = 'Webkit';
  2095. }
  2096. else if (mxClient.IS_MT)
  2097. {
  2098. prefix = 'Moz';
  2099. }
  2100. else if (mxClient.IS_IE && document.documentMode >= 9 && document.documentMode < 10)
  2101. {
  2102. prefix = 'ms';
  2103. }
  2104. return function(style, name, value)
  2105. {
  2106. style[name] = value;
  2107. if (prefix != null && name.length > 0)
  2108. {
  2109. name = prefix + name.substring(0, 1).toUpperCase() + name.substring(1);
  2110. style[name] = value;
  2111. }
  2112. };
  2113. }(),
  2114. /**
  2115. * Function: hasScrollbars
  2116. *
  2117. * Returns true if the overflow CSS property of the given node is either
  2118. * scroll or auto.
  2119. *
  2120. * Parameters:
  2121. *
  2122. * node - DOM node whose style should be checked for scrollbars.
  2123. */
  2124. hasScrollbars: function(node)
  2125. {
  2126. var style = mxUtils.getCurrentStyle(node);
  2127. return style != null && (style.overflow == 'scroll' || style.overflow == 'auto');
  2128. },
  2129. /**
  2130. * Function: bind
  2131. *
  2132. * Returns a wrapper function that locks the execution scope of the given
  2133. * function to the specified scope. Inside funct, the "this" keyword
  2134. * becomes a reference to that scope.
  2135. */
  2136. bind: function(scope, funct)
  2137. {
  2138. return function()
  2139. {
  2140. return funct.apply(scope, arguments);
  2141. };
  2142. },
  2143. /**
  2144. * Function: eval
  2145. *
  2146. * Evaluates the given expression using eval and returns the JavaScript
  2147. * object that represents the expression result. Supports evaluation of
  2148. * expressions that define functions and returns the function object for
  2149. * these expressions.
  2150. *
  2151. * Parameters:
  2152. *
  2153. * expr - A string that represents a JavaScript expression.
  2154. */
  2155. eval: function(expr)
  2156. {
  2157. var result = null;
  2158. if (expr.indexOf('function') >= 0)
  2159. {
  2160. try
  2161. {
  2162. eval('var _mxJavaScriptExpression='+expr);
  2163. result = _mxJavaScriptExpression;
  2164. // TODO: Use delete here?
  2165. _mxJavaScriptExpression = null;
  2166. }
  2167. catch (e)
  2168. {
  2169. mxLog.warn(e.message + ' while evaluating ' + expr);
  2170. }
  2171. }
  2172. else
  2173. {
  2174. try
  2175. {
  2176. result = eval(expr);
  2177. }
  2178. catch (e)
  2179. {
  2180. mxLog.warn(e.message + ' while evaluating ' + expr);
  2181. }
  2182. }
  2183. return result;
  2184. },
  2185. /**
  2186. * Function: findNode
  2187. *
  2188. * Returns the first node where attr equals value.
  2189. * This implementation does not use XPath.
  2190. */
  2191. findNode: function(node, attr, value)
  2192. {
  2193. if (node.nodeType == mxConstants.NODETYPE_ELEMENT)
  2194. {
  2195. var tmp = node.getAttribute(attr);
  2196. if (tmp != null && tmp == value)
  2197. {
  2198. return node;
  2199. }
  2200. }
  2201. node = node.firstChild;
  2202. while (node != null)
  2203. {
  2204. var result = mxUtils.findNode(node, attr, value);
  2205. if (result != null)
  2206. {
  2207. return result;
  2208. }
  2209. node = node.nextSibling;
  2210. }
  2211. return null;
  2212. },
  2213. /**
  2214. * Function: getFunctionName
  2215. *
  2216. * Returns the name for the given function.
  2217. *
  2218. * Parameters:
  2219. *
  2220. * f - JavaScript object that represents a function.
  2221. */
  2222. getFunctionName: function(f)
  2223. {
  2224. var str = null;
  2225. if (f != null)
  2226. {
  2227. if (f.name != null)
  2228. {
  2229. str = f.name;
  2230. }
  2231. else
  2232. {
  2233. str = mxUtils.trim(f.toString());
  2234. if (/^function\s/.test(str))
  2235. {
  2236. str = mxUtils.ltrim(str.substring(9));
  2237. var idx2 = str.indexOf('(');
  2238. if (idx2 > 0)
  2239. {
  2240. str = str.substring(0, idx2);
  2241. }
  2242. }
  2243. }
  2244. }
  2245. return str;
  2246. },
  2247. /**
  2248. * Function: indexOf
  2249. *
  2250. * Returns the index of obj in array or -1 if the array does not contain
  2251. * the given object.
  2252. *
  2253. * Parameters:
  2254. *
  2255. * array - Array to check for the given obj.
  2256. * obj - Object to find in the given array.
  2257. */
  2258. indexOf: function(array, obj)
  2259. {
  2260. if (array != null && obj != null)
  2261. {
  2262. for (var i = 0; i < array.length; i++)
  2263. {
  2264. if (array[i] == obj)
  2265. {
  2266. return i;
  2267. }
  2268. }
  2269. }
  2270. return -1;
  2271. },
  2272. /**
  2273. * Function: forEach
  2274. *
  2275. * Calls the given function for each element of the given array and returns
  2276. * the array.
  2277. *
  2278. * Parameters:
  2279. *
  2280. * array - Array that contains the elements.
  2281. * fn - Function to be called for each object.
  2282. */
  2283. forEach: function(array, fn)
  2284. {
  2285. if (array != null && fn != null)
  2286. {
  2287. for (var i = 0; i < array.length; i++)
  2288. {
  2289. fn(array[i]);
  2290. }
  2291. }
  2292. return array;
  2293. },
  2294. /**
  2295. * Function: remove
  2296. *
  2297. * Removes all occurrences of the given object in the given array or
  2298. * object. If there are multiple occurrences of the object, be they
  2299. * associative or as an array entry, all occurrences are removed from
  2300. * the array or deleted from the object. By removing the object from
  2301. * the array, all elements following the removed element are shifted
  2302. * by one step towards the beginning of the array.
  2303. *
  2304. * The length of arrays is not modified inside this function.
  2305. *
  2306. * Parameters:
  2307. *
  2308. * obj - Object to find in the given array.
  2309. * array - Array to check for the given obj.
  2310. */
  2311. remove: function(obj, array)
  2312. {
  2313. var result = null;
  2314. if (typeof(array) == 'object')
  2315. {
  2316. var index = mxUtils.indexOf(array, obj);
  2317. while (index >= 0)
  2318. {
  2319. array.splice(index, 1);
  2320. result = obj;
  2321. index = mxUtils.indexOf(array, obj);
  2322. }
  2323. }
  2324. for (var key in array)
  2325. {
  2326. if (array[key] == obj)
  2327. {
  2328. delete array[key];
  2329. result = obj;
  2330. }
  2331. }
  2332. return result;
  2333. },
  2334. /**
  2335. * Function: isNode
  2336. *
  2337. * Returns true if the given value is an XML node with the node name
  2338. * and if the optional attribute has the specified value.
  2339. *
  2340. * This implementation assumes that the given value is a DOM node if the
  2341. * nodeType property is numeric, that is, if isNaN returns false for
  2342. * value.nodeType.
  2343. *
  2344. * Parameters:
  2345. *
  2346. * value - Object that should be examined as a node.
  2347. * nodeName - String that specifies the node name.
  2348. * attributeName - Optional attribute name to check.
  2349. * attributeValue - Optional attribute value to check.
  2350. */
  2351. isNode: function(value, nodeName, attributeName, attributeValue)
  2352. {
  2353. if (value != null && !isNaN(value.nodeType) && (nodeName == null ||
  2354. value.nodeName.toLowerCase() == nodeName.toLowerCase()))
  2355. {
  2356. return attributeName == null ||
  2357. value.getAttribute(attributeName) == attributeValue;
  2358. }
  2359. return false;
  2360. },
  2361. /**
  2362. * Function: isAncestorNode
  2363. *
  2364. * Returns true if the given ancestor is an ancestor of the
  2365. * given DOM node in the DOM. This also returns true if the
  2366. * child is the ancestor.
  2367. *
  2368. * Parameters:
  2369. *
  2370. * ancestor - DOM node that represents the ancestor.
  2371. * child - DOM node that represents the child.
  2372. */
  2373. isAncestorNode: function(ancestor, child)
  2374. {
  2375. var parent = child;
  2376. while (parent != null)
  2377. {
  2378. if (parent == ancestor)
  2379. {
  2380. return true;
  2381. }
  2382. parent = parent.parentNode;
  2383. }
  2384. return false;
  2385. },
  2386. /**
  2387. * Function: getChildNodes
  2388. *
  2389. * Returns an array of child nodes that are of the given node type.
  2390. *
  2391. * Parameters:
  2392. *
  2393. * node - Parent DOM node to return the children from.
  2394. * nodeType - Optional node type to return. Default is
  2395. * <mxConstants.NODETYPE_ELEMENT>.
  2396. */
  2397. getChildNodes: function(node, nodeType)
  2398. {
  2399. nodeType = nodeType || mxConstants.NODETYPE_ELEMENT;
  2400. var children = [];
  2401. var tmp = node.firstChild;
  2402. while (tmp != null)
  2403. {
  2404. if (tmp.nodeType == nodeType)
  2405. {
  2406. children.push(tmp);
  2407. }
  2408. tmp = tmp.nextSibling;
  2409. }
  2410. return children;
  2411. },
  2412. /**
  2413. * Function: importNode
  2414. *
  2415. * Cross browser implementation for document.importNode. Uses document.importNode
  2416. * in all browsers but IE, where the node is cloned by creating a new node and
  2417. * copying all attributes and children into it using importNode, recursively.
  2418. *
  2419. * Parameters:
  2420. *
  2421. * doc - Document to import the node into.
  2422. * node - Node to be imported.
  2423. * allChildren - If all children should be imported.
  2424. */
  2425. importNode: function(doc, node, allChildren)
  2426. {
  2427. if (mxClient.IS_IE && (document.documentMode == null || document.documentMode < 10))
  2428. {
  2429. return mxUtils.importNodeImplementation(doc, node, allChildren);
  2430. }
  2431. else
  2432. {
  2433. return doc.importNode(node, allChildren);
  2434. }
  2435. },
  2436. /**
  2437. * Function: importNodeImplementation
  2438. *
  2439. * Full DOM API implementation for importNode without using importNode API call.
  2440. *
  2441. * Parameters:
  2442. *
  2443. * doc - Document to import the node into.
  2444. * node - Node to be imported.
  2445. * allChildren - If all children should be imported.
  2446. */
  2447. importNodeImplementation: function(doc, node, allChildren)
  2448. {
  2449. switch (node.nodeType)
  2450. {
  2451. case 1: /* element */
  2452. {
  2453. var newNode = doc.createElement(node.nodeName);
  2454. if (node.attributes && node.attributes.length > 0)
  2455. {
  2456. for (var i = 0; i < node.attributes.length; i++)
  2457. {
  2458. newNode.setAttribute(node.attributes[i].nodeName,
  2459. node.getAttribute(node.attributes[i].nodeName));
  2460. }
  2461. }
  2462. if (allChildren && node.childNodes && node.childNodes.length > 0)
  2463. {
  2464. for (var i = 0; i < node.childNodes.length; i++)
  2465. {
  2466. newNode.appendChild(mxUtils.importNodeImplementation(doc, node.childNodes[i], allChildren));
  2467. }
  2468. }
  2469. return newNode;
  2470. break;
  2471. }
  2472. case 3: /* text */
  2473. case 4: /* cdata-section */
  2474. case 8: /* comment */
  2475. {
  2476. return doc.createTextNode((node.nodeValue != null) ? node.nodeValue : node.value);
  2477. break;
  2478. }
  2479. };
  2480. },
  2481. /**
  2482. * Function: createXmlDocument
  2483. *
  2484. * Returns a new, empty XML document.
  2485. */
  2486. createXmlDocument: function()
  2487. {
  2488. var doc = null;
  2489. if (document.implementation && document.implementation.createDocument)
  2490. {
  2491. doc = document.implementation.createDocument('', '', null);
  2492. }
  2493. else if ("ActiveXObject" in window)
  2494. {
  2495. doc = mxUtils.createMsXmlDocument();
  2496. }
  2497. return doc;
  2498. },
  2499. /**
  2500. * Function: createMsXmlDocument
  2501. *
  2502. * Returns a new, empty Microsoft.XMLDOM document using ActiveXObject.
  2503. */
  2504. createMsXmlDocument: function()
  2505. {
  2506. var doc = new ActiveXObject('Microsoft.XMLDOM');
  2507. doc.async = false;
  2508. // Workaround for parsing errors with SVG DTD
  2509. doc.validateOnParse = false;
  2510. doc.resolveExternals = false;
  2511. return doc;
  2512. },
  2513. /**
  2514. * Function: parseXml
  2515. *
  2516. * Parses the specified XML string into a new XML document and returns the
  2517. * new document.
  2518. *
  2519. * Example:
  2520. *
  2521. * (code)
  2522. * var doc = mxUtils.parseXml(
  2523. * '<mxGraphModel><root><MyDiagram id="0"><mxCell/></MyDiagram>'+
  2524. * '<MyLayer id="1"><mxCell parent="0" /></MyLayer><MyObject id="2">'+
  2525. * '<mxCell style="strokeColor=blue;fillColor=red" parent="1" vertex="1">'+
  2526. * '<mxGeometry x="10" y="10" width="80" height="30" as="geometry"/>'+
  2527. * '</mxCell></MyObject></root></mxGraphModel>');
  2528. * (end)
  2529. *
  2530. * Parameters:
  2531. *
  2532. * xml - String that contains the XML data.
  2533. */
  2534. parseXml: function()
  2535. {
  2536. if (window.DOMParser)
  2537. {
  2538. return function(xml)
  2539. {
  2540. var parser = new DOMParser();
  2541. return parser.parseFromString(xml, 'text/xml');
  2542. };
  2543. }
  2544. else // IE<=9
  2545. {
  2546. return function(xml)
  2547. {
  2548. var doc = mxUtils.createMsXmlDocument();
  2549. doc.loadXML(xml);
  2550. return doc;
  2551. };
  2552. }
  2553. }(),
  2554. /**
  2555. * Function: clearSelection
  2556. *
  2557. * Clears the current selection in the page.
  2558. */
  2559. clearSelection: function()
  2560. {
  2561. if (document.selection)
  2562. {
  2563. return function()
  2564. {
  2565. document.selection.empty();
  2566. };
  2567. }
  2568. else if (window.getSelection)
  2569. {
  2570. return function()
  2571. {
  2572. if (window.getSelection().empty)
  2573. {
  2574. window.getSelection().empty();
  2575. }
  2576. else if (window.getSelection().removeAllRanges)
  2577. {
  2578. window.getSelection().removeAllRanges();
  2579. }
  2580. };
  2581. }
  2582. else
  2583. {
  2584. return function() { };
  2585. }
  2586. }(),
  2587. /**
  2588. * Function: removeWhitespace
  2589. *
  2590. * Removes the sibling text nodes for the given node that only consists
  2591. * of tabs, newlines and spaces.
  2592. *
  2593. * Parameters:
  2594. *
  2595. * node - DOM node whose siblings should be removed.
  2596. * before - Optional boolean that specifies the direction of the traversal.
  2597. */
  2598. removeWhitespace: function(node, before)
  2599. {
  2600. var tmp = (before) ? node.previousSibling : node.nextSibling;
  2601. while (tmp != null && tmp.nodeType == mxConstants.NODETYPE_TEXT)
  2602. {
  2603. var next = (before) ? tmp.previousSibling : tmp.nextSibling;
  2604. var text = mxUtils.getTextContent(tmp);
  2605. if (mxUtils.trim(text).length == 0)
  2606. {
  2607. tmp.parentNode.removeChild(tmp);
  2608. }
  2609. tmp = next;
  2610. }
  2611. },
  2612. /**
  2613. * Function: htmlEntities
  2614. *
  2615. * Replaces characters (less than, greater than, newlines and quotes) with
  2616. * their HTML entities in the given string and returns the result.
  2617. *
  2618. * Parameters:
  2619. *
  2620. * s - String that contains the characters to be converted.
  2621. * newline - If newlines should be replaced. Default is true.
  2622. */
  2623. htmlEntities: function(s, newline)
  2624. {
  2625. s = String(s || '');
  2626. s = s.replace(/&/g,'&amp;'); // 38 26
  2627. s = s.replace(/"/g,'&quot;'); // 34 22
  2628. s = s.replace(/\'/g,'&#39;'); // 39 27
  2629. s = s.replace(/</g,'&lt;'); // 60 3C
  2630. s = s.replace(/>/g,'&gt;'); // 62 3E
  2631. if (newline == null || newline)
  2632. {
  2633. s = s.replace(/\n/g, '&#xa;');
  2634. }
  2635. return s;
  2636. },
  2637. /**
  2638. * Function: isVml
  2639. *
  2640. * Returns true if the given node is in the VML namespace.
  2641. *
  2642. * Parameters:
  2643. *
  2644. * node - DOM node whose tag urn should be checked.
  2645. */
  2646. isVml: function(node)
  2647. {
  2648. return node != null && node.tagUrn == 'urn:schemas-microsoft-com:vml';
  2649. },
  2650. /**
  2651. * Function: getXml
  2652. *
  2653. * Returns the XML content of the specified node. For Internet Explorer,
  2654. * all \r\n\t[\t]* are removed from the XML string and the remaining \r\n
  2655. * are replaced by \n. All \n are then replaced with linefeed, or &#xa; if
  2656. * no linefeed is defined.
  2657. *
  2658. * Parameters:
  2659. *
  2660. * node - DOM node to return the XML for.
  2661. * linefeed - Optional string that linefeeds are converted into. Default is
  2662. * &#xa;
  2663. */
  2664. getXml: function(node, linefeed)
  2665. {
  2666. var xml = '';
  2667. if (mxClient.IS_IE || mxClient.IS_IE11)
  2668. {
  2669. xml = mxUtils.getPrettyXml(node, '', '', '');
  2670. }
  2671. else if (window.XMLSerializer != null)
  2672. {
  2673. var xmlSerializer = new XMLSerializer();
  2674. xml = xmlSerializer.serializeToString(node);
  2675. }
  2676. else if (node.xml != null)
  2677. {
  2678. xml = node.xml.replace(/\r\n\t[\t]*/g, '').
  2679. replace(/>\r\n/g, '>').
  2680. replace(/\r\n/g, '\n');
  2681. }
  2682. // Replaces linefeeds with HTML Entities.
  2683. linefeed = linefeed || '&#xa;';
  2684. xml = xml.replace(/\n/g, linefeed);
  2685. return xml;
  2686. },
  2687. /**
  2688. * Function: getPrettyXML
  2689. *
  2690. * Returns a pretty printed string that represents the XML tree for the
  2691. * given node. This method should only be used to print XML for reading,
  2692. * use <getXml> instead to obtain a string for processing.
  2693. *
  2694. * Parameters:
  2695. *
  2696. * node - DOM node to return the XML for.
  2697. * tab - Optional string that specifies the indentation for one level.
  2698. * Default is two spaces.
  2699. * indent - Optional string that represents the current indentation.
  2700. * Default is an empty string.
  2701. * newline - Option string that represents a linefeed. Default is '\n'.
  2702. */
  2703. getPrettyXml: function(node, tab, indent, newline, ns)
  2704. {
  2705. var result = [];
  2706. if (node != null)
  2707. {
  2708. tab = (tab != null) ? tab : ' ';
  2709. indent = (indent != null) ? indent : '';
  2710. newline = (newline != null) ? newline : '\n';
  2711. if (node.namespaceURI != null && node.namespaceURI != ns)
  2712. {
  2713. ns = node.namespaceURI;
  2714. if (node.getAttribute('xmlns') == null)
  2715. {
  2716. node.setAttribute('xmlns', node.namespaceURI);
  2717. }
  2718. }
  2719. if (node.nodeType == mxConstants.NODETYPE_DOCUMENT)
  2720. {
  2721. result.push(mxUtils.getPrettyXml(node.documentElement, tab, indent, newline, ns));
  2722. }
  2723. else if (node.nodeType == mxConstants.NODETYPE_DOCUMENT_FRAGMENT)
  2724. {
  2725. var tmp = node.firstChild;
  2726. if (tmp != null)
  2727. {
  2728. while (tmp != null)
  2729. {
  2730. result.push(mxUtils.getPrettyXml(tmp, tab, indent, newline, ns));
  2731. tmp = tmp.nextSibling;
  2732. }
  2733. }
  2734. }
  2735. else if (node.nodeType == mxConstants.NODETYPE_COMMENT)
  2736. {
  2737. var value = mxUtils.getTextContent(node);
  2738. if (value.length > 0)
  2739. {
  2740. result.push(indent + '<!--' + value + '-->' + newline);
  2741. }
  2742. }
  2743. else if (node.nodeType == mxConstants.NODETYPE_TEXT)
  2744. {
  2745. var value = mxUtils.getTextContent(node);
  2746. if (value.length > 0)
  2747. {
  2748. result.push(indent + mxUtils.htmlEntities(mxUtils.trim(value), false) + newline);
  2749. }
  2750. }
  2751. else if (node.nodeType == mxConstants.NODETYPE_CDATA)
  2752. {
  2753. var value = mxUtils.getTextContent(node);
  2754. if (value.length > 0)
  2755. {
  2756. result.push(indent + '<![CDATA[' + value + ']]' + newline);
  2757. }
  2758. }
  2759. else
  2760. {
  2761. result.push(indent + '<' + node.nodeName);
  2762. // Creates the string with the node attributes
  2763. // and converts all HTML entities in the values
  2764. var attrs = node.attributes;
  2765. if (attrs != null)
  2766. {
  2767. for (var i = 0; i < attrs.length; i++)
  2768. {
  2769. var val = mxUtils.htmlEntities(attrs[i].value);
  2770. result.push(' ' + attrs[i].nodeName + '="' + val + '"');
  2771. }
  2772. }
  2773. // Recursively creates the XML string for each child
  2774. // node and appends it here with an indentation
  2775. var tmp = node.firstChild;
  2776. if (tmp != null)
  2777. {
  2778. result.push('>' + newline);
  2779. while (tmp != null)
  2780. {
  2781. result.push(mxUtils.getPrettyXml(tmp, tab, indent + tab, newline, ns));
  2782. tmp = tmp.nextSibling;
  2783. }
  2784. result.push(indent + '</'+ node.nodeName + '>' + newline);
  2785. }
  2786. else
  2787. {
  2788. result.push(' />' + newline);
  2789. }
  2790. }
  2791. }
  2792. return result.join('');
  2793. },
  2794. /**
  2795. * Function: extractTextWithWhitespace
  2796. *
  2797. * Returns the text content of the specified node.
  2798. *
  2799. * Parameters:
  2800. *
  2801. * elems - DOM nodes to return the text for.
  2802. */
  2803. extractTextWithWhitespace: function(elems)
  2804. {
  2805. // Known block elements for handling linefeeds (list is not complete)
  2806. var blocks = ['BLOCKQUOTE', 'DIV', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'OL', 'P', 'PRE', 'TABLE', 'UL'];
  2807. var ret = [];
  2808. function doExtract(elts)
  2809. {
  2810. // Single break should be ignored
  2811. if (elts.length == 1 && (elts[0].nodeName == 'BR' ||
  2812. elts[0].innerHTML == '\n'))
  2813. {
  2814. return;
  2815. }
  2816. for (var i = 0; i < elts.length; i++)
  2817. {
  2818. var elem = elts[i];
  2819. // DIV with a br or linefeed forces a linefeed
  2820. if (elem.nodeName == 'BR' || elem.innerHTML == '\n' ||
  2821. ((elts.length == 1 || i == 0) && (elem.nodeName == 'DIV' &&
  2822. elem.innerHTML.toLowerCase() == '<br>')))
  2823. {
  2824. ret.push('\n');
  2825. }
  2826. else
  2827. {
  2828. if (elem.nodeType === 3 || elem.nodeType === 4)
  2829. {
  2830. if (elem.nodeValue.length > 0)
  2831. {
  2832. ret.push(elem.nodeValue);
  2833. }
  2834. }
  2835. else if (elem.nodeType !== 8 && elem.childNodes.length > 0)
  2836. {
  2837. doExtract(elem.childNodes);
  2838. }
  2839. if (i < elts.length - 1 && mxUtils.indexOf(blocks, elts[i + 1].nodeName) >= 0)
  2840. {
  2841. ret.push('\n');
  2842. }
  2843. }
  2844. }
  2845. };
  2846. doExtract(elems);
  2847. return ret.join('');
  2848. },
  2849. /**
  2850. * Function: replaceTrailingNewlines
  2851. *
  2852. * Replaces each trailing newline with the given pattern.
  2853. */
  2854. replaceTrailingNewlines: function(str, pattern)
  2855. {
  2856. // LATER: Check is this can be done with a regular expression
  2857. var postfix = '';
  2858. while (str.length > 0 && str.charAt(str.length - 1) == '\n')
  2859. {
  2860. str = str.substring(0, str.length - 1);
  2861. postfix += pattern;
  2862. }
  2863. return str + postfix;
  2864. },
  2865. /**
  2866. * Function: getTextContent
  2867. *
  2868. * Returns the text content of the specified node.
  2869. *
  2870. * Parameters:
  2871. *
  2872. * node - DOM node to return the text content for.
  2873. */
  2874. getTextContent: function(node)
  2875. {
  2876. // Only IE10-
  2877. if (mxClient.IS_IE && node.innerText !== undefined)
  2878. {
  2879. return node.innerText;
  2880. }
  2881. else
  2882. {
  2883. return (node != null) ? node[(node.textContent === undefined) ? 'text' : 'textContent'] : '';
  2884. }
  2885. },
  2886. /**
  2887. * Function: setTextContent
  2888. *
  2889. * Sets the text content of the specified node.
  2890. *
  2891. * Parameters:
  2892. *
  2893. * node - DOM node to set the text content for.
  2894. * text - String that represents the text content.
  2895. */
  2896. setTextContent: function(node, text)
  2897. {
  2898. if (node.innerText !== undefined)
  2899. {
  2900. node.innerText = text;
  2901. }
  2902. else
  2903. {
  2904. node[(node.textContent === undefined) ? 'text' : 'textContent'] = text;
  2905. }
  2906. },
  2907. /**
  2908. * Function: getInnerHtml
  2909. *
  2910. * Returns the inner HTML for the given node as a string or an empty string
  2911. * if no node was specified. The inner HTML is the text representing all
  2912. * children of the node, but not the node itself.
  2913. *
  2914. * Parameters:
  2915. *
  2916. * node - DOM node to return the inner HTML for.
  2917. */
  2918. getInnerHtml: function()
  2919. {
  2920. if (mxClient.IS_IE)
  2921. {
  2922. return function(node)
  2923. {
  2924. if (node != null)
  2925. {
  2926. return node.innerHTML;
  2927. }
  2928. return '';
  2929. };
  2930. }
  2931. else
  2932. {
  2933. return function(node)
  2934. {
  2935. if (node != null)
  2936. {
  2937. var serializer = new XMLSerializer();
  2938. return serializer.serializeToString(node);
  2939. }
  2940. return '';
  2941. };
  2942. }
  2943. }(),
  2944. /**
  2945. * Function: getOuterHtml
  2946. *
  2947. * Returns the outer HTML for the given node as a string or an empty
  2948. * string if no node was specified. The outer HTML is the text representing
  2949. * all children of the node including the node itself.
  2950. *
  2951. * Parameters:
  2952. *
  2953. * node - DOM node to return the outer HTML for.
  2954. */
  2955. getOuterHtml: function()
  2956. {
  2957. if (mxClient.IS_IE)
  2958. {
  2959. return function(node)
  2960. {
  2961. if (node != null)
  2962. {
  2963. if (node.outerHTML != null)
  2964. {
  2965. return node.outerHTML;
  2966. }
  2967. else
  2968. {
  2969. var tmp = [];
  2970. tmp.push('<'+node.nodeName);
  2971. var attrs = node.attributes;
  2972. if (attrs != null)
  2973. {
  2974. for (var i = 0; i < attrs.length; i++)
  2975. {
  2976. var value = attrs[i].value;
  2977. if (value != null && value.length > 0)
  2978. {
  2979. tmp.push(' ');
  2980. tmp.push(attrs[i].nodeName);
  2981. tmp.push('="');
  2982. tmp.push(value);
  2983. tmp.push('"');
  2984. }
  2985. }
  2986. }
  2987. if (node.innerHTML.length == 0)
  2988. {
  2989. tmp.push('/>');
  2990. }
  2991. else
  2992. {
  2993. tmp.push('>');
  2994. tmp.push(node.innerHTML);
  2995. tmp.push('</'+node.nodeName+'>');
  2996. }
  2997. return tmp.join('');
  2998. }
  2999. }
  3000. return '';
  3001. };
  3002. }
  3003. else
  3004. {
  3005. return function(node)
  3006. {
  3007. if (node != null)
  3008. {
  3009. var serializer = new XMLSerializer();
  3010. return serializer.serializeToString(node);
  3011. }
  3012. return '';
  3013. };
  3014. }
  3015. }(),
  3016. /**
  3017. * Function: write
  3018. *
  3019. * Creates a text node for the given string and appends it to the given
  3020. * parent. Returns the text node.
  3021. *
  3022. * Parameters:
  3023. *
  3024. * parent - DOM node to append the text node to.
  3025. * text - String representing the text to be added.
  3026. */
  3027. write: function(parent, text)
  3028. {
  3029. var doc = parent.ownerDocument;
  3030. var node = doc.createTextNode(text);
  3031. if (parent != null)
  3032. {
  3033. parent.appendChild(node);
  3034. }
  3035. return node;
  3036. },
  3037. /**
  3038. * Function: writeln
  3039. *
  3040. * Creates a text node for the given string and appends it to the given
  3041. * parent with an additional linefeed. Returns the text node.
  3042. *
  3043. * Parameters:
  3044. *
  3045. * parent - DOM node to append the text node to.
  3046. * text - String representing the text to be added.
  3047. */
  3048. writeln: function(parent, text)
  3049. {
  3050. var doc = parent.ownerDocument;
  3051. var node = doc.createTextNode(text);
  3052. if (parent != null)
  3053. {
  3054. parent.appendChild(node);
  3055. parent.appendChild(document.createElement('br'));
  3056. }
  3057. return node;
  3058. },
  3059. /**
  3060. * Function: br
  3061. *
  3062. * Appends a linebreak to the given parent and returns the linebreak.
  3063. *
  3064. * Parameters:
  3065. *
  3066. * parent - DOM node to append the linebreak to.
  3067. */
  3068. br: function(parent, count)
  3069. {
  3070. count = count || 1;
  3071. var br = null;
  3072. for (var i = 0; i < count; i++)
  3073. {
  3074. if (parent != null)
  3075. {
  3076. br = parent.ownerDocument.createElement('br');
  3077. parent.appendChild(br);
  3078. }
  3079. }
  3080. return br;
  3081. },
  3082. /**
  3083. * Function: button
  3084. *
  3085. * Returns a new button with the given level and function as an onclick
  3086. * event handler.
  3087. *
  3088. * (code)
  3089. * document.body.appendChild(mxUtils.button('Test', function(evt)
  3090. * {
  3091. * alert('Hello, World!');
  3092. * }));
  3093. * (end)
  3094. *
  3095. * Parameters:
  3096. *
  3097. * label - String that represents the label of the button.
  3098. * funct - Function to be called if the button is pressed.
  3099. * doc - Optional document to be used for creating the button. Default is the
  3100. * current document.
  3101. */
  3102. button: function(label, funct, doc)
  3103. {
  3104. doc = (doc != null) ? doc : document;
  3105. var button = doc.createElement('button');
  3106. mxUtils.write(button, label);
  3107. mxEvent.addListener(button, 'click', function(evt)
  3108. {
  3109. funct(evt);
  3110. });
  3111. return button;
  3112. },
  3113. /**
  3114. * Function: para
  3115. *
  3116. * Appends a new paragraph with the given text to the specified parent and
  3117. * returns the paragraph.
  3118. *
  3119. * Parameters:
  3120. *
  3121. * parent - DOM node to append the text node to.
  3122. * text - String representing the text for the new paragraph.
  3123. */
  3124. para: function(parent, text)
  3125. {
  3126. var p = document.createElement('p');
  3127. mxUtils.write(p, text);
  3128. if (parent != null)
  3129. {
  3130. parent.appendChild(p);
  3131. }
  3132. return p;
  3133. },
  3134. /**
  3135. * Function: addTransparentBackgroundFilter
  3136. *
  3137. * Adds a transparent background to the filter of the given node. This
  3138. * background can be used in IE8 standards mode (native IE8 only) to pass
  3139. * events through the node.
  3140. */
  3141. addTransparentBackgroundFilter: function(node)
  3142. {
  3143. node.style.filter += 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' +
  3144. mxClient.imageBasePath + '/transparent.gif\', sizingMethod=\'scale\')';
  3145. },
  3146. /**
  3147. * Function: linkAction
  3148. *
  3149. * Adds a hyperlink to the specified parent that invokes action on the
  3150. * specified editor.
  3151. *
  3152. * Parameters:
  3153. *
  3154. * parent - DOM node to contain the new link.
  3155. * text - String that is used as the link label.
  3156. * editor - <mxEditor> that will execute the action.
  3157. * action - String that defines the name of the action to be executed.
  3158. * pad - Optional left-padding for the link. Default is 0.
  3159. */
  3160. linkAction: function(parent, text, editor, action, pad)
  3161. {
  3162. return mxUtils.link(parent, text, function()
  3163. {
  3164. editor.execute(action);
  3165. }, pad);
  3166. },
  3167. /**
  3168. * Function: linkInvoke
  3169. *
  3170. * Adds a hyperlink to the specified parent that invokes the specified
  3171. * function on the editor passing along the specified argument. The
  3172. * function name is the name of a function of the editor instance,
  3173. * not an action name.
  3174. *
  3175. * Parameters:
  3176. *
  3177. * parent - DOM node to contain the new link.
  3178. * text - String that is used as the link label.
  3179. * editor - <mxEditor> instance to execute the function on.
  3180. * functName - String that represents the name of the function.
  3181. * arg - Object that represents the argument to the function.
  3182. * pad - Optional left-padding for the link. Default is 0.
  3183. */
  3184. linkInvoke: function(parent, text, editor, functName, arg, pad)
  3185. {
  3186. return mxUtils.link(parent, text, function()
  3187. {
  3188. editor[functName](arg);
  3189. }, pad);
  3190. },
  3191. /**
  3192. * Function: link
  3193. *
  3194. * Adds a hyperlink to the specified parent and invokes the given function
  3195. * when the link is clicked.
  3196. *
  3197. * Parameters:
  3198. *
  3199. * parent - DOM node to contain the new link.
  3200. * text - String that is used as the link label.
  3201. * funct - Function to execute when the link is clicked.
  3202. * pad - Optional left-padding for the link. Default is 0.
  3203. */
  3204. link: function(parent, text, funct, pad)
  3205. {
  3206. var a = document.createElement('span');
  3207. a.style.color = 'blue';
  3208. a.style.textDecoration = 'underline';
  3209. a.style.cursor = 'pointer';
  3210. if (pad != null)
  3211. {
  3212. a.style.paddingLeft = pad+'px';
  3213. }
  3214. mxEvent.addListener(a, 'click', funct);
  3215. mxUtils.write(a, text);
  3216. if (parent != null)
  3217. {
  3218. parent.appendChild(a);
  3219. }
  3220. return a;
  3221. },
  3222. /**
  3223. * Function: getDocumentSize
  3224. *
  3225. * Returns the client size for the current document as an <mxRectangle>.
  3226. */
  3227. getDocumentSize: function()
  3228. {
  3229. var b = document.body;
  3230. var d = document.documentElement;
  3231. try
  3232. {
  3233. return new mxRectangle(0, 0, b.clientWidth || d.clientWidth, Math.max(b.clientHeight || 0, d.clientHeight));
  3234. }
  3235. catch (e)
  3236. {
  3237. return new mxRectangle();
  3238. }
  3239. },
  3240. /**
  3241. * Function: fit
  3242. *
  3243. * Makes sure the given node is inside the visible area of the window. This
  3244. * is done by setting the left and top in the style.
  3245. */
  3246. fit: function(node)
  3247. {
  3248. var ds = mxUtils.getDocumentSize();
  3249. var left = parseInt(node.offsetLeft);
  3250. var width = parseInt(node.offsetWidth);
  3251. var offset = mxUtils.getDocumentScrollOrigin(node.ownerDocument);
  3252. var sl = offset.x;
  3253. var st = offset.y;
  3254. var b = document.body;
  3255. var d = document.documentElement;
  3256. var right = (sl) + ds.width;
  3257. if (left + width > right)
  3258. {
  3259. node.style.left = Math.max(sl, right - width) + 'px';
  3260. }
  3261. var top = parseInt(node.offsetTop);
  3262. var height = parseInt(node.offsetHeight);
  3263. var bottom = st + ds.height;
  3264. if (top + height > bottom)
  3265. {
  3266. node.style.top = Math.max(st, bottom - height) + 'px';
  3267. }
  3268. },
  3269. /**
  3270. * Function: load
  3271. *
  3272. * Loads the specified URL *synchronously* and returns the <mxXmlRequest>.
  3273. * Throws an exception if the file cannot be loaded. See <mxUtils.get> for
  3274. * an asynchronous implementation.
  3275. *
  3276. * Example:
  3277. *
  3278. * (code)
  3279. * try
  3280. * {
  3281. * var req = mxUtils.load(filename);
  3282. * var root = req.getDocumentElement();
  3283. * // Process XML DOM...
  3284. * }
  3285. * catch (ex)
  3286. * {
  3287. * mxUtils.alert('Cannot load '+filename+': '+ex);
  3288. * }
  3289. * (end)
  3290. *
  3291. * Parameters:
  3292. *
  3293. * url - URL to get the data from.
  3294. */
  3295. load: function(url)
  3296. {
  3297. var req = new mxXmlRequest(url, null, 'GET', false);
  3298. req.send();
  3299. return req;
  3300. },
  3301. /**
  3302. * Function: get
  3303. *
  3304. * Loads the specified URL *asynchronously* and invokes the given functions
  3305. * depending on the request status. Returns the <mxXmlRequest> in use. Both
  3306. * functions take the <mxXmlRequest> as the only parameter. See
  3307. * <mxUtils.load> for a synchronous implementation.
  3308. *
  3309. * Example:
  3310. *
  3311. * (code)
  3312. * mxUtils.get(url, function(req)
  3313. * {
  3314. * var node = req.getDocumentElement();
  3315. * // Process XML DOM...
  3316. * });
  3317. * (end)
  3318. *
  3319. * So for example, to load a diagram into an existing graph model, the
  3320. * following code is used.
  3321. *
  3322. * (code)
  3323. * mxUtils.get(url, function(req)
  3324. * {
  3325. * var node = req.getDocumentElement();
  3326. * var dec = new mxCodec(node.ownerDocument);
  3327. * dec.decode(node, graph.getModel());
  3328. * });
  3329. * (end)
  3330. *
  3331. * Parameters:
  3332. *
  3333. * url - URL to get the data from.
  3334. * onload - Optional function to execute for a successful response.
  3335. * onerror - Optional function to execute on error.
  3336. * binary - Optional boolean parameter that specifies if the request is
  3337. * binary.
  3338. * timeout - Optional timeout in ms before calling ontimeout.
  3339. * ontimeout - Optional function to execute on timeout.
  3340. * headers - Optional with headers, eg. {'Authorization': 'token xyz'}
  3341. */
  3342. get: function(url, onload, onerror, binary, timeout, ontimeout, headers)
  3343. {
  3344. var req = new mxXmlRequest(url, null, 'GET');
  3345. var setRequestHeaders = req.setRequestHeaders;
  3346. if (headers)
  3347. {
  3348. req.setRequestHeaders = function(request, params)
  3349. {
  3350. setRequestHeaders.apply(this, arguments);
  3351. for (var key in headers)
  3352. {
  3353. request.setRequestHeader(key, headers[key]);
  3354. }
  3355. };
  3356. }
  3357. if (binary != null)
  3358. {
  3359. req.setBinary(binary);
  3360. }
  3361. req.send(onload, onerror, timeout, ontimeout);
  3362. return req;
  3363. },
  3364. /**
  3365. * Function: getAll
  3366. *
  3367. * Loads the URLs in the given array *asynchronously* and invokes the given function
  3368. * if all requests returned with a valid 2xx status. The error handler is invoked
  3369. * once on the first error or invalid response.
  3370. *
  3371. * Parameters:
  3372. *
  3373. * urls - Array of URLs to be loaded.
  3374. * onload - Callback with array of <mxXmlRequests>.
  3375. * onerror - Optional function to execute on error.
  3376. */
  3377. getAll: function(urls, onload, onerror)
  3378. {
  3379. var remain = urls.length;
  3380. var result = [];
  3381. var errors = 0;
  3382. var err = function()
  3383. {
  3384. if (errors == 0 && onerror != null)
  3385. {
  3386. onerror();
  3387. }
  3388. errors++;
  3389. };
  3390. for (var i = 0; i < urls.length; i++)
  3391. {
  3392. (function(url, index)
  3393. {
  3394. mxUtils.get(url, function(req)
  3395. {
  3396. var status = req.getStatus();
  3397. if (status < 200 || status > 299)
  3398. {
  3399. err();
  3400. }
  3401. else
  3402. {
  3403. result[index] = req;
  3404. remain--;
  3405. if (remain == 0)
  3406. {
  3407. onload(result);
  3408. }
  3409. }
  3410. }, err);
  3411. })(urls[i], i);
  3412. }
  3413. if (remain == 0)
  3414. {
  3415. onload(result);
  3416. }
  3417. },
  3418. /**
  3419. * Function: post
  3420. *
  3421. * Posts the specified params to the given URL *asynchronously* and invokes
  3422. * the given functions depending on the request status. Returns the
  3423. * <mxXmlRequest> in use. Both functions take the <mxXmlRequest> as the
  3424. * only parameter. Make sure to use encodeURIComponent for the parameter
  3425. * values.
  3426. *
  3427. * Example:
  3428. *
  3429. * (code)
  3430. * mxUtils.post(url, 'key=value', function(req)
  3431. * {
  3432. * mxUtils.alert('Ready: '+req.isReady()+' Status: '+req.getStatus());
  3433. * // Process req.getDocumentElement() using DOM API if OK...
  3434. * });
  3435. * (end)
  3436. *
  3437. * Parameters:
  3438. *
  3439. * url - URL to get the data from.
  3440. * params - Parameters for the post request.
  3441. * onload - Optional function to execute for a successful response.
  3442. * onerror - Optional function to execute on error.
  3443. */
  3444. post: function(url, params, onload, onerror)
  3445. {
  3446. return new mxXmlRequest(url, params).send(onload, onerror);
  3447. },
  3448. /**
  3449. * Function: submit
  3450. *
  3451. * Submits the given parameters to the specified URL using
  3452. * <mxXmlRequest.simulate> and returns the <mxXmlRequest>.
  3453. * Make sure to use encodeURIComponent for the parameter
  3454. * values.
  3455. *
  3456. * Parameters:
  3457. *
  3458. * url - URL to get the data from.
  3459. * params - Parameters for the form.
  3460. * doc - Document to create the form in.
  3461. * target - Target to send the form result to.
  3462. */
  3463. submit: function(url, params, doc, target)
  3464. {
  3465. return new mxXmlRequest(url, params).simulate(doc, target);
  3466. },
  3467. /**
  3468. * Function: loadInto
  3469. *
  3470. * Loads the specified URL *asynchronously* into the specified document,
  3471. * invoking onload after the document has been loaded. This implementation
  3472. * does not use <mxXmlRequest>, but the document.load method.
  3473. *
  3474. * Parameters:
  3475. *
  3476. * url - URL to get the data from.
  3477. * doc - The document to load the URL into.
  3478. * onload - Function to execute when the URL has been loaded.
  3479. */
  3480. loadInto: function(url, doc, onload)
  3481. {
  3482. if (mxClient.IS_IE)
  3483. {
  3484. doc.onreadystatechange = function ()
  3485. {
  3486. if (doc.readyState == 4)
  3487. {
  3488. onload();
  3489. }
  3490. };
  3491. }
  3492. else
  3493. {
  3494. doc.addEventListener('load', onload, false);
  3495. }
  3496. doc.load(url);
  3497. },
  3498. /**
  3499. * Function: getValue
  3500. *
  3501. * Returns the value for the given key in the given associative array or
  3502. * the given default value if the value is null.
  3503. *
  3504. * Parameters:
  3505. *
  3506. * array - Associative array that contains the value for the key.
  3507. * key - Key whose value should be returned.
  3508. * defaultValue - Value to be returned if the value for the given
  3509. * key is null.
  3510. */
  3511. getValue: function(array, key, defaultValue)
  3512. {
  3513. var value = (array != null) ? array[key] : null;
  3514. if (value == null)
  3515. {
  3516. value = defaultValue;
  3517. }
  3518. return value;
  3519. },
  3520. /**
  3521. * Function: getNumber
  3522. *
  3523. * Returns the numeric value for the given key in the given associative
  3524. * array or the given default value (or 0) if the value is null. The value
  3525. * is converted to a numeric value using the Number function.
  3526. *
  3527. * Parameters:
  3528. *
  3529. * array - Associative array that contains the value for the key.
  3530. * key - Key whose value should be returned.
  3531. * defaultValue - Value to be returned if the value for the given
  3532. * key is null. Default is 0.
  3533. */
  3534. getNumber: function(array, key, defaultValue)
  3535. {
  3536. var value = (array != null) ? array[key] : null;
  3537. if (value == null)
  3538. {
  3539. value = defaultValue || 0;
  3540. }
  3541. return Number(value);
  3542. },
  3543. /**
  3544. * Function: getColor
  3545. *
  3546. * Returns the color value for the given key in the given associative
  3547. * array or the given default value if the value is null. If the value
  3548. * is <mxConstants.NONE> then null is returned.
  3549. *
  3550. * Parameters:
  3551. *
  3552. * array - Associative array that contains the value for the key.
  3553. * key - Key whose value should be returned.
  3554. * defaultValue - Value to be returned if the value for the given
  3555. * key is null. Default is null.
  3556. */
  3557. getColor: function(array, key, defaultValue)
  3558. {
  3559. var value = (array != null) ? array[key] : null;
  3560. if (value == null)
  3561. {
  3562. value = defaultValue;
  3563. }
  3564. else if (value == mxConstants.NONE)
  3565. {
  3566. value = null;
  3567. }
  3568. return value;
  3569. },
  3570. /**
  3571. * Function: clone
  3572. *
  3573. * Recursively clones the specified object ignoring all fieldnames in the
  3574. * given array of transient fields. <mxObjectIdentity.FIELD_NAME> is always
  3575. * ignored by this function.
  3576. *
  3577. * Parameters:
  3578. *
  3579. * obj - Object to be cloned.
  3580. * transients - Optional array of strings representing the fieldname to be
  3581. * ignored.
  3582. * shallow - Optional boolean argument to specify if a shallow clone should
  3583. * be created, that is, one where all object references are not cloned or,
  3584. * in other words, one where only atomic (strings, numbers) values are
  3585. * cloned. Default is false.
  3586. */
  3587. clone: function(obj, transients, shallow)
  3588. {
  3589. shallow = (shallow != null) ? shallow : false;
  3590. var clone = null;
  3591. if (obj != null && typeof(obj.constructor) == 'function')
  3592. {
  3593. clone = new obj.constructor();
  3594. for (var i in obj)
  3595. {
  3596. if (i != mxObjectIdentity.FIELD_NAME && (transients == null ||
  3597. mxUtils.indexOf(transients, i) < 0))
  3598. {
  3599. if (!shallow && typeof(obj[i]) == 'object')
  3600. {
  3601. clone[i] = mxUtils.clone(obj[i]);
  3602. }
  3603. else
  3604. {
  3605. clone[i] = obj[i];
  3606. }
  3607. }
  3608. }
  3609. }
  3610. return clone;
  3611. },
  3612. /**
  3613. * Function: equalPoints
  3614. *
  3615. * Compares all mxPoints in the given lists.
  3616. *
  3617. * Parameters:
  3618. *
  3619. * a - Array of <mxPoints> to be compared.
  3620. * b - Array of <mxPoints> to be compared.
  3621. */
  3622. equalPoints: function(a, b)
  3623. {
  3624. if ((a == null && b != null) || (a != null && b == null) ||
  3625. (a != null && b != null && a.length != b.length))
  3626. {
  3627. return false;
  3628. }
  3629. else if (a != null && b != null)
  3630. {
  3631. for (var i = 0; i < a.length; i++)
  3632. {
  3633. if ((a[i] != null && b[i] == null) ||
  3634. (a[i] == null && b[i] != null) ||
  3635. (a[i] != null && b[i] != null &&
  3636. (a[i].x != b[i].x || a[i].y != b[i].y)))
  3637. {
  3638. return false;
  3639. }
  3640. }
  3641. }
  3642. return true;
  3643. },
  3644. /**
  3645. * Function: equalEntries
  3646. *
  3647. * Returns true if all properties of the given objects are equal. Values
  3648. * with NaN are equal to NaN and unequal to any other value.
  3649. *
  3650. * Parameters:
  3651. *
  3652. * a - First object to be compared.
  3653. * b - Second object to be compared.
  3654. */
  3655. equalEntries: function(a, b)
  3656. {
  3657. // Counts keys in b to check if all values have been compared
  3658. var count = 0;
  3659. if ((a == null && b != null) || (a != null && b == null) ||
  3660. (a != null && b != null && a.length != b.length))
  3661. {
  3662. return false;
  3663. }
  3664. else if (a != null && b != null)
  3665. {
  3666. for (var key in b)
  3667. {
  3668. count++;
  3669. }
  3670. for (var key in a)
  3671. {
  3672. count--
  3673. if ((!mxUtils.isNaN(a[key]) || !mxUtils.isNaN(b[key])) && a[key] != b[key])
  3674. {
  3675. return false;
  3676. }
  3677. }
  3678. }
  3679. return count == 0;
  3680. },
  3681. /**
  3682. * Function: removeDuplicates
  3683. *
  3684. * Removes all duplicates from the given array.
  3685. */
  3686. removeDuplicates: function(arr)
  3687. {
  3688. var dict = new mxDictionary();
  3689. var result = [];
  3690. for (var i = 0; i < arr.length; i++)
  3691. {
  3692. if (!dict.get(arr[i]))
  3693. {
  3694. result.push(arr[i]);
  3695. dict.put(arr[i], true);
  3696. }
  3697. }
  3698. return result;
  3699. },
  3700. /**
  3701. * Function: isNaN
  3702. *
  3703. * Returns true if the given value is of type number and isNaN returns true.
  3704. */
  3705. isNaN: function(value)
  3706. {
  3707. return typeof(value) == 'number' && isNaN(value);
  3708. },
  3709. /**
  3710. * Function: extend
  3711. *
  3712. * Assigns a copy of the superclass prototype to the subclass prototype.
  3713. * Note that this does not call the constructor of the superclass at this
  3714. * point, the superclass constructor should be called explicitely in the
  3715. * subclass constructor. Below is an example.
  3716. *
  3717. * (code)
  3718. * MyGraph = function(container, model, renderHint, stylesheet)
  3719. * {
  3720. * mxGraph.call(this, container, model, renderHint, stylesheet);
  3721. * }
  3722. *
  3723. * mxUtils.extend(MyGraph, mxGraph);
  3724. * (end)
  3725. *
  3726. * Parameters:
  3727. *
  3728. * ctor - Constructor of the subclass.
  3729. * superCtor - Constructor of the superclass.
  3730. */
  3731. extend: function(ctor, superCtor)
  3732. {
  3733. var f = function() {};
  3734. f.prototype = superCtor.prototype;
  3735. ctor.prototype = new f();
  3736. ctor.prototype.constructor = ctor;
  3737. },
  3738. /**
  3739. * Function: toString
  3740. *
  3741. * Returns a textual representation of the specified object.
  3742. *
  3743. * Parameters:
  3744. *
  3745. * obj - Object to return the string representation for.
  3746. */
  3747. toString: function(obj)
  3748. {
  3749. var output = '';
  3750. for (var i in obj)
  3751. {
  3752. try
  3753. {
  3754. if (obj[i] == null)
  3755. {
  3756. output += i + ' = [null]\n';
  3757. }
  3758. else if (typeof(obj[i]) == 'function')
  3759. {
  3760. output += i + ' => [Function]\n';
  3761. }
  3762. else if (typeof(obj[i]) == 'object')
  3763. {
  3764. var ctor = mxUtils.getFunctionName(obj[i].constructor);
  3765. output += i + ' => [' + ctor + ']\n';
  3766. }
  3767. else
  3768. {
  3769. output += i + ' = ' + obj[i] + '\n';
  3770. }
  3771. }
  3772. catch (e)
  3773. {
  3774. output += i + '=' + e.message;
  3775. }
  3776. }
  3777. return output;
  3778. },
  3779. /**
  3780. * Function: toRadians
  3781. *
  3782. * Converts the given degree to radians.
  3783. */
  3784. toRadians: function(deg)
  3785. {
  3786. return Math.PI * deg / 180;
  3787. },
  3788. /**
  3789. * Function: toDegree
  3790. *
  3791. * Converts the given radians to degree.
  3792. */
  3793. toDegree: function(rad)
  3794. {
  3795. return rad * 180 / Math.PI;
  3796. },
  3797. /**
  3798. * Function: arcToCurves
  3799. *
  3800. * Converts the given arc to a series of curves.
  3801. */
  3802. arcToCurves: function(x0, y0, r1, r2, angle, largeArcFlag, sweepFlag, x, y)
  3803. {
  3804. x -= x0;
  3805. y -= y0;
  3806. if (r1 === 0 || r2 === 0)
  3807. {
  3808. return result;
  3809. }
  3810. var fS = sweepFlag;
  3811. var psai = angle;
  3812. r1 = Math.abs(r1);
  3813. r2 = Math.abs(r2);
  3814. var ctx = -x / 2;
  3815. var cty = -y / 2;
  3816. var cpsi = Math.cos(psai * Math.PI / 180);
  3817. var spsi = Math.sin(psai * Math.PI / 180);
  3818. var rxd = cpsi * ctx + spsi * cty;
  3819. var ryd = -1 * spsi * ctx + cpsi * cty;
  3820. var rxdd = rxd * rxd;
  3821. var rydd = ryd * ryd;
  3822. var r1x = r1 * r1;
  3823. var r2y = r2 * r2;
  3824. var lamda = rxdd / r1x + rydd / r2y;
  3825. var sds;
  3826. if (lamda > 1)
  3827. {
  3828. r1 = Math.sqrt(lamda) * r1;
  3829. r2 = Math.sqrt(lamda) * r2;
  3830. sds = 0;
  3831. }
  3832. else
  3833. {
  3834. var seif = 1;
  3835. if (largeArcFlag === fS)
  3836. {
  3837. seif = -1;
  3838. }
  3839. sds = seif * Math.sqrt((r1x * r2y - r1x * rydd - r2y * rxdd) / (r1x * rydd + r2y * rxdd));
  3840. }
  3841. var txd = sds * r1 * ryd / r2;
  3842. var tyd = -1 * sds * r2 * rxd / r1;
  3843. var tx = cpsi * txd - spsi * tyd + x / 2;
  3844. var ty = spsi * txd + cpsi * tyd + y / 2;
  3845. var rad = Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1) - Math.atan2(0, 1);
  3846. var s1 = (rad >= 0) ? rad : 2 * Math.PI + rad;
  3847. rad = Math.atan2((-ryd - tyd) / r2, (-rxd - txd) / r1) - Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1);
  3848. var dr = (rad >= 0) ? rad : 2 * Math.PI + rad;
  3849. if (fS == 0 && dr > 0)
  3850. {
  3851. dr -= 2 * Math.PI;
  3852. }
  3853. else if (fS != 0 && dr < 0)
  3854. {
  3855. dr += 2 * Math.PI;
  3856. }
  3857. var sse = dr * 2 / Math.PI;
  3858. var seg = Math.ceil(sse < 0 ? -1 * sse : sse);
  3859. var segr = dr / seg;
  3860. var t = 8/3 * Math.sin(segr / 4) * Math.sin(segr / 4) / Math.sin(segr / 2);
  3861. var cpsir1 = cpsi * r1;
  3862. var cpsir2 = cpsi * r2;
  3863. var spsir1 = spsi * r1;
  3864. var spsir2 = spsi * r2;
  3865. var mc = Math.cos(s1);
  3866. var ms = Math.sin(s1);
  3867. var x2 = -t * (cpsir1 * ms + spsir2 * mc);
  3868. var y2 = -t * (spsir1 * ms - cpsir2 * mc);
  3869. var x3 = 0;
  3870. var y3 = 0;
  3871. var result = [];
  3872. for (var n = 0; n < seg; ++n)
  3873. {
  3874. s1 += segr;
  3875. mc = Math.cos(s1);
  3876. ms = Math.sin(s1);
  3877. x3 = cpsir1 * mc - spsir2 * ms + tx;
  3878. y3 = spsir1 * mc + cpsir2 * ms + ty;
  3879. var dx = -t * (cpsir1 * ms + spsir2 * mc);
  3880. var dy = -t * (spsir1 * ms - cpsir2 * mc);
  3881. // CurveTo updates x0, y0 so need to restore it
  3882. var index = n * 6;
  3883. result[index] = Number(x2 + x0);
  3884. result[index + 1] = Number(y2 + y0);
  3885. result[index + 2] = Number(x3 - dx + x0);
  3886. result[index + 3] = Number(y3 - dy + y0);
  3887. result[index + 4] = Number(x3 + x0);
  3888. result[index + 5] = Number(y3 + y0);
  3889. x2 = x3 + dx;
  3890. y2 = y3 + dy;
  3891. }
  3892. return result;
  3893. },
  3894. /**
  3895. * Function: getBoundingBox
  3896. *
  3897. * Returns the bounding box for the rotated rectangle.
  3898. *
  3899. * Parameters:
  3900. *
  3901. * rect - <mxRectangle> to be rotated.
  3902. * angle - Number that represents the angle (in degrees).
  3903. * cx - Optional <mxPoint> that represents the rotation center. If no
  3904. * rotation center is given then the center of rect is used.
  3905. */
  3906. getBoundingBox: function(rect, rotation, cx)
  3907. {
  3908. var result = null;
  3909. if (rect != null && rotation != null && rotation != 0)
  3910. {
  3911. var rad = mxUtils.toRadians(rotation);
  3912. var cos = Math.cos(rad);
  3913. var sin = Math.sin(rad);
  3914. cx = (cx != null) ? cx : new mxPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
  3915. var p1 = new mxPoint(rect.x, rect.y);
  3916. var p2 = new mxPoint(rect.x + rect.width, rect.y);
  3917. var p3 = new mxPoint(p2.x, rect.y + rect.height);
  3918. var p4 = new mxPoint(rect.x, p3.y);
  3919. p1 = mxUtils.getRotatedPoint(p1, cos, sin, cx);
  3920. p2 = mxUtils.getRotatedPoint(p2, cos, sin, cx);
  3921. p3 = mxUtils.getRotatedPoint(p3, cos, sin, cx);
  3922. p4 = mxUtils.getRotatedPoint(p4, cos, sin, cx);
  3923. result = new mxRectangle(p1.x, p1.y, 0, 0);
  3924. result.add(new mxRectangle(p2.x, p2.y, 0, 0));
  3925. result.add(new mxRectangle(p3.x, p3.y, 0, 0));
  3926. result.add(new mxRectangle(p4.x, p4.y, 0, 0));
  3927. }
  3928. return result;
  3929. },
  3930. /**
  3931. * Function: getRotatedPoint
  3932. *
  3933. * Rotates the given point by the given cos and sin.
  3934. */
  3935. getRotatedPoint: function(pt, cos, sin, c)
  3936. {
  3937. c = (c != null) ? c : new mxPoint();
  3938. var x = pt.x - c.x;
  3939. var y = pt.y - c.y;
  3940. var x1 = x * cos - y * sin;
  3941. var y1 = y * cos + x * sin;
  3942. return new mxPoint(x1 + c.x, y1 + c.y);
  3943. },
  3944. /**
  3945. * Returns an integer mask of the port constraints of the given map
  3946. * @param dict the style map to determine the port constraints for
  3947. * @param defaultValue Default value to return if the key is undefined.
  3948. * @return the mask of port constraint directions
  3949. *
  3950. * Parameters:
  3951. *
  3952. * terminal - <mxCelState> that represents the terminal.
  3953. * edge - <mxCellState> that represents the edge.
  3954. * source - Boolean that specifies if the terminal is the source terminal.
  3955. * defaultValue - Default value to be returned.
  3956. */
  3957. getPortConstraints: function(terminal, edge, source, defaultValue)
  3958. {
  3959. var value = mxUtils.getValue(terminal.style, mxConstants.STYLE_PORT_CONSTRAINT,
  3960. mxUtils.getValue(edge.style, (source) ? mxConstants.STYLE_SOURCE_PORT_CONSTRAINT :
  3961. mxConstants.STYLE_TARGET_PORT_CONSTRAINT, null));
  3962. if (value == null)
  3963. {
  3964. return defaultValue;
  3965. }
  3966. else
  3967. {
  3968. var directions = value.toString();
  3969. var returnValue = mxConstants.DIRECTION_MASK_NONE;
  3970. var constraintRotationEnabled = mxUtils.getValue(terminal.style, mxConstants.STYLE_PORT_CONSTRAINT_ROTATION, 0);
  3971. var rotation = 0;
  3972. if (constraintRotationEnabled == 1)
  3973. {
  3974. rotation = mxUtils.getValue(terminal.style, mxConstants.STYLE_ROTATION, 0);
  3975. }
  3976. var quad = 0;
  3977. if (rotation > 45)
  3978. {
  3979. quad = 1;
  3980. if (rotation >= 135)
  3981. {
  3982. quad = 2;
  3983. }
  3984. }
  3985. else if (rotation < -45)
  3986. {
  3987. quad = 3;
  3988. if (rotation <= -135)
  3989. {
  3990. quad = 2;
  3991. }
  3992. }
  3993. if (directions.indexOf(mxConstants.DIRECTION_NORTH) >= 0)
  3994. {
  3995. switch (quad)
  3996. {
  3997. case 0:
  3998. returnValue |= mxConstants.DIRECTION_MASK_NORTH;
  3999. break;
  4000. case 1:
  4001. returnValue |= mxConstants.DIRECTION_MASK_EAST;
  4002. break;
  4003. case 2:
  4004. returnValue |= mxConstants.DIRECTION_MASK_SOUTH;
  4005. break;
  4006. case 3:
  4007. returnValue |= mxConstants.DIRECTION_MASK_WEST;
  4008. break;
  4009. }
  4010. }
  4011. if (directions.indexOf(mxConstants.DIRECTION_WEST) >= 0)
  4012. {
  4013. switch (quad)
  4014. {
  4015. case 0:
  4016. returnValue |= mxConstants.DIRECTION_MASK_WEST;
  4017. break;
  4018. case 1:
  4019. returnValue |= mxConstants.DIRECTION_MASK_NORTH;
  4020. break;
  4021. case 2:
  4022. returnValue |= mxConstants.DIRECTION_MASK_EAST;
  4023. break;
  4024. case 3:
  4025. returnValue |= mxConstants.DIRECTION_MASK_SOUTH;
  4026. break;
  4027. }
  4028. }
  4029. if (directions.indexOf(mxConstants.DIRECTION_SOUTH) >= 0)
  4030. {
  4031. switch (quad)
  4032. {
  4033. case 0:
  4034. returnValue |= mxConstants.DIRECTION_MASK_SOUTH;
  4035. break;
  4036. case 1:
  4037. returnValue |= mxConstants.DIRECTION_MASK_WEST;
  4038. break;
  4039. case 2:
  4040. returnValue |= mxConstants.DIRECTION_MASK_NORTH;
  4041. break;
  4042. case 3:
  4043. returnValue |= mxConstants.DIRECTION_MASK_EAST;
  4044. break;
  4045. }
  4046. }
  4047. if (directions.indexOf(mxConstants.DIRECTION_EAST) >= 0)
  4048. {
  4049. switch (quad)
  4050. {
  4051. case 0:
  4052. returnValue |= mxConstants.DIRECTION_MASK_EAST;
  4053. break;
  4054. case 1:
  4055. returnValue |= mxConstants.DIRECTION_MASK_SOUTH;
  4056. break;
  4057. case 2:
  4058. returnValue |= mxConstants.DIRECTION_MASK_WEST;
  4059. break;
  4060. case 3:
  4061. returnValue |= mxConstants.DIRECTION_MASK_NORTH;
  4062. break;
  4063. }
  4064. }
  4065. return returnValue;
  4066. }
  4067. },
  4068. /**
  4069. * Function: reversePortConstraints
  4070. *
  4071. * Reverse the port constraint bitmask. For example, north | east
  4072. * becomes south | west
  4073. */
  4074. reversePortConstraints: function(constraint)
  4075. {
  4076. var result = 0;
  4077. result = (constraint & mxConstants.DIRECTION_MASK_WEST) << 3;
  4078. result |= (constraint & mxConstants.DIRECTION_MASK_NORTH) << 1;
  4079. result |= (constraint & mxConstants.DIRECTION_MASK_SOUTH) >> 1;
  4080. result |= (constraint & mxConstants.DIRECTION_MASK_EAST) >> 3;
  4081. return result;
  4082. },
  4083. /**
  4084. * Function: findNearestSegment
  4085. *
  4086. * Finds the index of the nearest segment on the given cell state for
  4087. * the specified coordinate pair.
  4088. */
  4089. findNearestSegment: function(state, x, y)
  4090. {
  4091. var index = -1;
  4092. if (state.absolutePoints.length > 0)
  4093. {
  4094. var last = state.absolutePoints[0];
  4095. var min = null;
  4096. for (var i = 1; i < state.absolutePoints.length; i++)
  4097. {
  4098. var current = state.absolutePoints[i];
  4099. var dist = mxUtils.ptSegDistSq(last.x, last.y,
  4100. current.x, current.y, x, y);
  4101. if (min == null || dist < min)
  4102. {
  4103. min = dist;
  4104. index = i - 1;
  4105. }
  4106. last = current;
  4107. }
  4108. }
  4109. return index;
  4110. },
  4111. /**
  4112. * Function: getDirectedBounds
  4113. *
  4114. * Adds the given margins to the given rectangle and rotates and flips the
  4115. * rectangle according to the respective styles in style.
  4116. */
  4117. getDirectedBounds: function (rect, m, style, flipH, flipV)
  4118. {
  4119. var d = mxUtils.getValue(style, mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
  4120. flipH = (flipH != null) ? flipH : mxUtils.getValue(style, mxConstants.STYLE_FLIPH, false);
  4121. flipV = (flipV != null) ? flipV : mxUtils.getValue(style, mxConstants.STYLE_FLIPV, false);
  4122. m.x = Math.round(Math.max(0, Math.min(rect.width, m.x)));
  4123. m.y = Math.round(Math.max(0, Math.min(rect.height, m.y)));
  4124. m.width = Math.round(Math.max(0, Math.min(rect.width, m.width)));
  4125. m.height = Math.round(Math.max(0, Math.min(rect.height, m.height)));
  4126. if ((flipV && (d == mxConstants.DIRECTION_SOUTH || d == mxConstants.DIRECTION_NORTH)) ||
  4127. (flipH && (d == mxConstants.DIRECTION_EAST || d == mxConstants.DIRECTION_WEST)))
  4128. {
  4129. var tmp = m.x;
  4130. m.x = m.width;
  4131. m.width = tmp;
  4132. }
  4133. if ((flipH && (d == mxConstants.DIRECTION_SOUTH || d == mxConstants.DIRECTION_NORTH)) ||
  4134. (flipV && (d == mxConstants.DIRECTION_EAST || d == mxConstants.DIRECTION_WEST)))
  4135. {
  4136. var tmp = m.y;
  4137. m.y = m.height;
  4138. m.height = tmp;
  4139. }
  4140. var m2 = mxRectangle.fromRectangle(m);
  4141. if (d == mxConstants.DIRECTION_SOUTH)
  4142. {
  4143. m2.y = m.x;
  4144. m2.x = m.height;
  4145. m2.width = m.y;
  4146. m2.height = m.width;
  4147. }
  4148. else if (d == mxConstants.DIRECTION_WEST)
  4149. {
  4150. m2.y = m.height;
  4151. m2.x = m.width;
  4152. m2.width = m.x;
  4153. m2.height = m.y;
  4154. }
  4155. else if (d == mxConstants.DIRECTION_NORTH)
  4156. {
  4157. m2.y = m.width;
  4158. m2.x = m.y;
  4159. m2.width = m.height;
  4160. m2.height = m.x;
  4161. }
  4162. return new mxRectangle(rect.x + m2.x, rect.y + m2.y, rect.width - m2.width - m2.x, rect.height - m2.height - m2.y);
  4163. },
  4164. /**
  4165. * Function: getPerimeterPoint
  4166. *
  4167. * Returns the intersection between the polygon defined by the array of
  4168. * points and the line between center and point.
  4169. */
  4170. getPerimeterPoint: function (pts, center, point)
  4171. {
  4172. var min = null;
  4173. for (var i = 0; i < pts.length - 1; i++)
  4174. {
  4175. var pt = mxUtils.intersection(pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y,
  4176. center.x, center.y, point.x, point.y);
  4177. if (pt != null)
  4178. {
  4179. var dx = point.x - pt.x;
  4180. var dy = point.y - pt.y;
  4181. var ip = {p: pt, distSq: dy * dy + dx * dx};
  4182. if (ip != null && (min == null || min.distSq > ip.distSq))
  4183. {
  4184. min = ip;
  4185. }
  4186. }
  4187. }
  4188. return (min != null) ? min.p : null;
  4189. },
  4190. /**
  4191. * Function: rectangleIntersectsSegment
  4192. *
  4193. * Returns true if the given rectangle intersects the given segment.
  4194. *
  4195. * Parameters:
  4196. *
  4197. * bounds - <mxRectangle> that represents the rectangle.
  4198. * p1 - <mxPoint> that represents the first point of the segment.
  4199. * p2 - <mxPoint> that represents the second point of the segment.
  4200. */
  4201. rectangleIntersectsSegment: function(bounds, p1, p2)
  4202. {
  4203. var top = bounds.y;
  4204. var left = bounds.x;
  4205. var bottom = top + bounds.height;
  4206. var right = left + bounds.width;
  4207. // Find min and max X for the segment
  4208. var minX = p1.x;
  4209. var maxX = p2.x;
  4210. if (p1.x > p2.x)
  4211. {
  4212. minX = p2.x;
  4213. maxX = p1.x;
  4214. }
  4215. // Find the intersection of the segment's and rectangle's x-projections
  4216. if (maxX > right)
  4217. {
  4218. maxX = right;
  4219. }
  4220. if (minX < left)
  4221. {
  4222. minX = left;
  4223. }
  4224. if (minX > maxX) // If their projections do not intersect return false
  4225. {
  4226. return false;
  4227. }
  4228. // Find corresponding min and max Y for min and max X we found before
  4229. var minY = p1.y;
  4230. var maxY = p2.y;
  4231. var dx = p2.x - p1.x;
  4232. if (Math.abs(dx) > 0.0000001)
  4233. {
  4234. var a = (p2.y - p1.y) / dx;
  4235. var b = p1.y - a * p1.x;
  4236. minY = a * minX + b;
  4237. maxY = a * maxX + b;
  4238. }
  4239. if (minY > maxY)
  4240. {
  4241. var tmp = maxY;
  4242. maxY = minY;
  4243. minY = tmp;
  4244. }
  4245. // Find the intersection of the segment's and rectangle's y-projections
  4246. if (maxY > bottom)
  4247. {
  4248. maxY = bottom;
  4249. }
  4250. if (minY < top)
  4251. {
  4252. minY = top;
  4253. }
  4254. if (minY > maxY) // If Y-projections do not intersect return false
  4255. {
  4256. return false;
  4257. }
  4258. return true;
  4259. },
  4260. /**
  4261. * Function: contains
  4262. *
  4263. * Returns true if the specified point (x, y) is contained in the given rectangle.
  4264. *
  4265. * Parameters:
  4266. *
  4267. * bounds - <mxRectangle> that represents the area.
  4268. * x - X-coordinate of the point.
  4269. * y - Y-coordinate of the point.
  4270. */
  4271. contains: function(bounds, x, y)
  4272. {
  4273. return (bounds.x <= x && bounds.x + bounds.width >= x &&
  4274. bounds.y <= y && bounds.y + bounds.height >= y);
  4275. },
  4276. /**
  4277. * Function: intersects
  4278. *
  4279. * Returns true if the two rectangles intersect.
  4280. *
  4281. * Parameters:
  4282. *
  4283. * a - <mxRectangle> to be checked for intersection.
  4284. * b - <mxRectangle> to be checked for intersection.
  4285. */
  4286. intersects: function(a, b)
  4287. {
  4288. var tw = a.width;
  4289. var th = a.height;
  4290. var rw = b.width;
  4291. var rh = b.height;
  4292. if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0)
  4293. {
  4294. return false;
  4295. }
  4296. var tx = a.x;
  4297. var ty = a.y;
  4298. var rx = b.x;
  4299. var ry = b.y;
  4300. rw += rx;
  4301. rh += ry;
  4302. tw += tx;
  4303. th += ty;
  4304. return ((rw < rx || rw > tx) &&
  4305. (rh < ry || rh > ty) &&
  4306. (tw < tx || tw > rx) &&
  4307. (th < ty || th > ry));
  4308. },
  4309. /**
  4310. * Function: intersects
  4311. *
  4312. * Returns true if the two rectangles intersect.
  4313. *
  4314. * Parameters:
  4315. *
  4316. * a - <mxRectangle> to be checked for intersection.
  4317. * b - <mxRectangle> to be checked for intersection.
  4318. */
  4319. intersectsHotspot: function(state, x, y, hotspot, min, max)
  4320. {
  4321. hotspot = (hotspot != null) ? hotspot : 1;
  4322. min = (min != null) ? min : 0;
  4323. max = (max != null) ? max : 0;
  4324. if (hotspot > 0)
  4325. {
  4326. var cx = state.getCenterX();
  4327. var cy = state.getCenterY();
  4328. var w = state.width;
  4329. var h = state.height;
  4330. var start = mxUtils.getValue(state.style, mxConstants.STYLE_STARTSIZE) * state.view.scale;
  4331. if (start > 0)
  4332. {
  4333. if (mxUtils.getValue(state.style, mxConstants.STYLE_HORIZONTAL, true))
  4334. {
  4335. cy = state.y + start / 2;
  4336. h = start;
  4337. }
  4338. else
  4339. {
  4340. cx = state.x + start / 2;
  4341. w = start;
  4342. }
  4343. }
  4344. w = Math.max(min, w * hotspot);
  4345. h = Math.max(min, h * hotspot);
  4346. if (max > 0)
  4347. {
  4348. w = Math.min(w, max);
  4349. h = Math.min(h, max);
  4350. }
  4351. var rect = new mxRectangle(cx - w / 2, cy - h / 2, w, h);
  4352. var alpha = mxUtils.toRadians(mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION) || 0);
  4353. if (alpha != 0)
  4354. {
  4355. var cos = Math.cos(-alpha);
  4356. var sin = Math.sin(-alpha);
  4357. var cx = new mxPoint(state.getCenterX(), state.getCenterY());
  4358. var pt = mxUtils.getRotatedPoint(new mxPoint(x, y), cos, sin, cx);
  4359. x = pt.x;
  4360. y = pt.y;
  4361. }
  4362. return mxUtils.contains(rect, x, y);
  4363. }
  4364. return true;
  4365. },
  4366. /**
  4367. * Function: getOffset
  4368. *
  4369. * Returns the offset for the specified container as an <mxPoint>. The
  4370. * offset is the distance from the top left corner of the container to the
  4371. * top left corner of the document.
  4372. *
  4373. * Parameters:
  4374. *
  4375. * container - DOM node to return the offset for.
  4376. * scollOffset - Optional boolean to add the scroll offset of the document.
  4377. * Default is false.
  4378. */
  4379. getOffset: function(container, scrollOffset)
  4380. {
  4381. var offsetLeft = 0;
  4382. var offsetTop = 0;
  4383. // Ignores document scroll origin for fixed elements
  4384. var fixed = false;
  4385. var node = container;
  4386. var b = document.body;
  4387. var d = document.documentElement;
  4388. while (node != null && node != b && node != d && !fixed)
  4389. {
  4390. var style = mxUtils.getCurrentStyle(node);
  4391. if (style != null)
  4392. {
  4393. fixed = fixed || style.position == 'fixed';
  4394. }
  4395. node = node.parentNode;
  4396. }
  4397. if (!scrollOffset && !fixed)
  4398. {
  4399. var offset = mxUtils.getDocumentScrollOrigin(container.ownerDocument);
  4400. offsetLeft += offset.x;
  4401. offsetTop += offset.y;
  4402. }
  4403. var r = container.getBoundingClientRect();
  4404. if (r != null)
  4405. {
  4406. offsetLeft += r.left;
  4407. offsetTop += r.top;
  4408. }
  4409. return new mxPoint(offsetLeft, offsetTop);
  4410. },
  4411. /**
  4412. * Function: getDocumentScrollOrigin
  4413. *
  4414. * Returns the scroll origin of the given document or the current document
  4415. * if no document is given.
  4416. */
  4417. getDocumentScrollOrigin: function(doc)
  4418. {
  4419. if (mxClient.IS_QUIRKS)
  4420. {
  4421. return new mxPoint(doc.body.scrollLeft, doc.body.scrollTop);
  4422. }
  4423. else
  4424. {
  4425. var wnd = doc.defaultView || doc.parentWindow;
  4426. var x = (wnd != null && window.pageXOffset !== undefined) ? window.pageXOffset : (document.documentElement || document.body.parentNode || document.body).scrollLeft;
  4427. var y = (wnd != null && window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
  4428. return new mxPoint(x, y);
  4429. }
  4430. },
  4431. /**
  4432. * Function: getScrollOrigin
  4433. *
  4434. * Returns the top, left corner of the viewrect as an <mxPoint>.
  4435. *
  4436. * Parameters:
  4437. *
  4438. * node - DOM node whose scroll origin should be returned.
  4439. * includeAncestors - Whether the scroll origin of the ancestors should be
  4440. * included. Default is false.
  4441. * includeDocument - Whether the scroll origin of the document should be
  4442. * included. Default is true.
  4443. */
  4444. getScrollOrigin: function(node, includeAncestors, includeDocument)
  4445. {
  4446. includeAncestors = (includeAncestors != null) ? includeAncestors : false;
  4447. includeDocument = (includeDocument != null) ? includeDocument : true;
  4448. var doc = (node != null) ? node.ownerDocument : document;
  4449. var b = doc.body;
  4450. var d = doc.documentElement;
  4451. var result = new mxPoint();
  4452. var fixed = false;
  4453. while (node != null && node != b && node != d)
  4454. {
  4455. if (!isNaN(node.scrollLeft) && !isNaN(node.scrollTop))
  4456. {
  4457. result.x += node.scrollLeft;
  4458. result.y += node.scrollTop;
  4459. }
  4460. var style = mxUtils.getCurrentStyle(node);
  4461. if (style != null)
  4462. {
  4463. fixed = fixed || style.position == 'fixed';
  4464. }
  4465. node = (includeAncestors) ? node.parentNode : null;
  4466. }
  4467. if (!fixed && includeDocument)
  4468. {
  4469. var origin = mxUtils.getDocumentScrollOrigin(doc);
  4470. result.x += origin.x;
  4471. result.y += origin.y;
  4472. }
  4473. return result;
  4474. },
  4475. /**
  4476. * Function: convertPoint
  4477. *
  4478. * Converts the specified point (x, y) using the offset of the specified
  4479. * container and returns a new <mxPoint> with the result.
  4480. *
  4481. * (code)
  4482. * var pt = mxUtils.convertPoint(graph.container,
  4483. * mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  4484. * (end)
  4485. *
  4486. * Parameters:
  4487. *
  4488. * container - DOM node to use for the offset.
  4489. * x - X-coordinate of the point to be converted.
  4490. * y - Y-coordinate of the point to be converted.
  4491. */
  4492. convertPoint: function(container, x, y)
  4493. {
  4494. var origin = mxUtils.getScrollOrigin(container, false);
  4495. var offset = mxUtils.getOffset(container);
  4496. offset.x -= origin.x;
  4497. offset.y -= origin.y;
  4498. return new mxPoint(x - offset.x, y - offset.y);
  4499. },
  4500. /**
  4501. * Function: ltrim
  4502. *
  4503. * Strips all whitespaces from the beginning of the string. Without the
  4504. * second parameter, this will trim these characters:
  4505. *
  4506. * - " " (ASCII 32 (0x20)), an ordinary space
  4507. * - "\t" (ASCII 9 (0x09)), a tab
  4508. * - "\n" (ASCII 10 (0x0A)), a new line (line feed)
  4509. * - "\r" (ASCII 13 (0x0D)), a carriage return
  4510. * - "\0" (ASCII 0 (0x00)), the NUL-byte
  4511. * - "\x0B" (ASCII 11 (0x0B)), a vertical tab
  4512. */
  4513. ltrim: function(str, chars)
  4514. {
  4515. chars = chars || "\\s";
  4516. return (str != null) ? str.replace(new RegExp("^[" + chars + "]+", "g"), "") : null;
  4517. },
  4518. /**
  4519. * Function: rtrim
  4520. *
  4521. * Strips all whitespaces from the end of the string. Without the second
  4522. * parameter, this will trim these characters:
  4523. *
  4524. * - " " (ASCII 32 (0x20)), an ordinary space
  4525. * - "\t" (ASCII 9 (0x09)), a tab
  4526. * - "\n" (ASCII 10 (0x0A)), a new line (line feed)
  4527. * - "\r" (ASCII 13 (0x0D)), a carriage return
  4528. * - "\0" (ASCII 0 (0x00)), the NUL-byte
  4529. * - "\x0B" (ASCII 11 (0x0B)), a vertical tab
  4530. */
  4531. rtrim: function(str, chars)
  4532. {
  4533. chars = chars || "\\s";
  4534. return (str != null) ? str.replace(new RegExp("[" + chars + "]+$", "g"), "") : null;
  4535. },
  4536. /**
  4537. * Function: trim
  4538. *
  4539. * Strips all whitespaces from both end of the string.
  4540. * Without the second parameter, Javascript function will trim these
  4541. * characters:
  4542. *
  4543. * - " " (ASCII 32 (0x20)), an ordinary space
  4544. * - "\t" (ASCII 9 (0x09)), a tab
  4545. * - "\n" (ASCII 10 (0x0A)), a new line (line feed)
  4546. * - "\r" (ASCII 13 (0x0D)), a carriage return
  4547. * - "\0" (ASCII 0 (0x00)), the NUL-byte
  4548. * - "\x0B" (ASCII 11 (0x0B)), a vertical tab
  4549. */
  4550. trim: function(str, chars)
  4551. {
  4552. return mxUtils.ltrim(mxUtils.rtrim(str, chars), chars);
  4553. },
  4554. /**
  4555. * Function: isNumeric
  4556. *
  4557. * Returns true if the specified value is numeric, that is, if it is not
  4558. * null, not an empty string, not a HEX number and isNaN returns false.
  4559. *
  4560. * Parameters:
  4561. *
  4562. * n - String representing the possibly numeric value.
  4563. */
  4564. isNumeric: function(n)
  4565. {
  4566. return !isNaN(parseFloat(n)) && isFinite(n) && (typeof(n) != 'string' || n.toLowerCase().indexOf('0x') < 0);
  4567. },
  4568. /**
  4569. * Function: isInteger
  4570. *
  4571. * Returns true if the given value is an valid integer number.
  4572. *
  4573. * Parameters:
  4574. *
  4575. * n - String representing the possibly numeric value.
  4576. */
  4577. isInteger: function(n)
  4578. {
  4579. return String(parseInt(n)) === String(n);
  4580. },
  4581. /**
  4582. * Function: mod
  4583. *
  4584. * Returns the remainder of division of n by m. You should use this instead
  4585. * of the built-in operation as the built-in operation does not properly
  4586. * handle negative numbers.
  4587. */
  4588. mod: function(n, m)
  4589. {
  4590. return ((n % m) + m) % m;
  4591. },
  4592. /**
  4593. * Function: intersection
  4594. *
  4595. * Returns the intersection of two lines as an <mxPoint>.
  4596. *
  4597. * Parameters:
  4598. *
  4599. * x0 - X-coordinate of the first line's startpoint.
  4600. * y0 - X-coordinate of the first line's startpoint.
  4601. * x1 - X-coordinate of the first line's endpoint.
  4602. * y1 - Y-coordinate of the first line's endpoint.
  4603. * x2 - X-coordinate of the second line's startpoint.
  4604. * y2 - Y-coordinate of the second line's startpoint.
  4605. * x3 - X-coordinate of the second line's endpoint.
  4606. * y3 - Y-coordinate of the second line's endpoint.
  4607. */
  4608. intersection: function (x0, y0, x1, y1, x2, y2, x3, y3)
  4609. {
  4610. var denom = ((y3 - y2) * (x1 - x0)) - ((x3 - x2) * (y1 - y0));
  4611. var nume_a = ((x3 - x2) * (y0 - y2)) - ((y3 - y2) * (x0 - x2));
  4612. var nume_b = ((x1 - x0) * (y0 - y2)) - ((y1 - y0) * (x0 - x2));
  4613. var ua = nume_a / denom;
  4614. var ub = nume_b / denom;
  4615. if(ua >= 0.0 && ua <= 1.0 && ub >= 0.0 && ub <= 1.0)
  4616. {
  4617. // Get the intersection point
  4618. var x = x0 + ua * (x1 - x0);
  4619. var y = y0 + ua * (y1 - y0);
  4620. return new mxPoint(x, y);
  4621. }
  4622. // No intersection
  4623. return null;
  4624. },
  4625. /**
  4626. * Function: ptSegDistSq
  4627. *
  4628. * Returns the square distance between a segment and a point. To get the
  4629. * distance between a point and a line (with infinite length) use
  4630. * <mxUtils.ptLineDist>.
  4631. *
  4632. * Parameters:
  4633. *
  4634. * x1 - X-coordinate of the startpoint of the segment.
  4635. * y1 - Y-coordinate of the startpoint of the segment.
  4636. * x2 - X-coordinate of the endpoint of the segment.
  4637. * y2 - Y-coordinate of the endpoint of the segment.
  4638. * px - X-coordinate of the point.
  4639. * py - Y-coordinate of the point.
  4640. */
  4641. ptSegDistSq: function(x1, y1, x2, y2, px, py)
  4642. {
  4643. x2 -= x1;
  4644. y2 -= y1;
  4645. px -= x1;
  4646. py -= y1;
  4647. var dotprod = px * x2 + py * y2;
  4648. var projlenSq;
  4649. if (dotprod <= 0.0)
  4650. {
  4651. projlenSq = 0.0;
  4652. }
  4653. else
  4654. {
  4655. px = x2 - px;
  4656. py = y2 - py;
  4657. dotprod = px * x2 + py * y2;
  4658. if (dotprod <= 0.0)
  4659. {
  4660. projlenSq = 0.0;
  4661. }
  4662. else
  4663. {
  4664. projlenSq = dotprod * dotprod / (x2 * x2 + y2 * y2);
  4665. }
  4666. }
  4667. var lenSq = px * px + py * py - projlenSq;
  4668. if (lenSq < 0)
  4669. {
  4670. lenSq = 0;
  4671. }
  4672. return lenSq;
  4673. },
  4674. /**
  4675. * Function: ptLineDist
  4676. *
  4677. * Returns the distance between a line defined by two points and a point.
  4678. * To get the distance between a point and a segment (with a specific
  4679. * length) use <mxUtils.ptSeqDistSq>.
  4680. *
  4681. * Parameters:
  4682. *
  4683. * x1 - X-coordinate of point 1 of the line.
  4684. * y1 - Y-coordinate of point 1 of the line.
  4685. * x2 - X-coordinate of point 1 of the line.
  4686. * y2 - Y-coordinate of point 1 of the line.
  4687. * px - X-coordinate of the point.
  4688. * py - Y-coordinate of the point.
  4689. */
  4690. ptLineDist: function(x1, y1, x2, y2, px, py)
  4691. {
  4692. return Math.abs((y2 - y1) * px - (x2 - x1) * py + x2 * y1 - y2 * x1) /
  4693. Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
  4694. },
  4695. /**
  4696. * Function: relativeCcw
  4697. *
  4698. * Returns 1 if the given point on the right side of the segment, 0 if its
  4699. * on the segment, and -1 if the point is on the left side of the segment.
  4700. *
  4701. * Parameters:
  4702. *
  4703. * x1 - X-coordinate of the startpoint of the segment.
  4704. * y1 - Y-coordinate of the startpoint of the segment.
  4705. * x2 - X-coordinate of the endpoint of the segment.
  4706. * y2 - Y-coordinate of the endpoint of the segment.
  4707. * px - X-coordinate of the point.
  4708. * py - Y-coordinate of the point.
  4709. */
  4710. relativeCcw: function(x1, y1, x2, y2, px, py)
  4711. {
  4712. x2 -= x1;
  4713. y2 -= y1;
  4714. px -= x1;
  4715. py -= y1;
  4716. var ccw = px * y2 - py * x2;
  4717. if (ccw == 0.0)
  4718. {
  4719. ccw = px * x2 + py * y2;
  4720. if (ccw > 0.0)
  4721. {
  4722. px -= x2;
  4723. py -= y2;
  4724. ccw = px * x2 + py * y2;
  4725. if (ccw < 0.0)
  4726. {
  4727. ccw = 0.0;
  4728. }
  4729. }
  4730. }
  4731. return (ccw < 0.0) ? -1 : ((ccw > 0.0) ? 1 : 0);
  4732. },
  4733. /**
  4734. * Function: animateChanges
  4735. *
  4736. * See <mxEffects.animateChanges>. This is for backwards compatibility and
  4737. * will be removed later.
  4738. */
  4739. animateChanges: function(graph, changes)
  4740. {
  4741. // LATER: Deprecated, remove this function
  4742. mxEffects.animateChanges.apply(this, arguments);
  4743. },
  4744. /**
  4745. * Function: cascadeOpacity
  4746. *
  4747. * See <mxEffects.cascadeOpacity>. This is for backwards compatibility and
  4748. * will be removed later.
  4749. */
  4750. cascadeOpacity: function(graph, cell, opacity)
  4751. {
  4752. mxEffects.cascadeOpacity.apply(this, arguments);
  4753. },
  4754. /**
  4755. * Function: fadeOut
  4756. *
  4757. * See <mxEffects.fadeOut>. This is for backwards compatibility and
  4758. * will be removed later.
  4759. */
  4760. fadeOut: function(node, from, remove, step, delay, isEnabled)
  4761. {
  4762. mxEffects.fadeOut.apply(this, arguments);
  4763. },
  4764. /**
  4765. * Function: setOpacity
  4766. *
  4767. * Sets the opacity of the specified DOM node to the given value in %.
  4768. *
  4769. * Parameters:
  4770. *
  4771. * node - DOM node to set the opacity for.
  4772. * value - Opacity in %. Possible values are between 0 and 100.
  4773. */
  4774. setOpacity: function(node, value)
  4775. {
  4776. if (mxUtils.isVml(node))
  4777. {
  4778. if (value >= 100)
  4779. {
  4780. node.style.filter = '';
  4781. }
  4782. else
  4783. {
  4784. // TODO: Why is the division by 5 needed in VML?
  4785. node.style.filter = 'alpha(opacity=' + (value/5) + ')';
  4786. }
  4787. }
  4788. else if (mxClient.IS_IE && (typeof(document.documentMode) === 'undefined' || document.documentMode < 9))
  4789. {
  4790. if (value >= 100)
  4791. {
  4792. node.style.filter = '';
  4793. }
  4794. else
  4795. {
  4796. node.style.filter = 'alpha(opacity=' + value + ')';
  4797. }
  4798. }
  4799. else
  4800. {
  4801. node.style.opacity = (value / 100);
  4802. }
  4803. },
  4804. /**
  4805. * Function: createImage
  4806. *
  4807. * Creates and returns an image (IMG node) or VML image (v:image) in IE6 in
  4808. * quirks mode.
  4809. *
  4810. * Parameters:
  4811. *
  4812. * src - URL that points to the image to be displayed.
  4813. */
  4814. createImage: function(src)
  4815. {
  4816. var imageNode = null;
  4817. if (mxClient.IS_IE6 && document.compatMode != 'CSS1Compat')
  4818. {
  4819. imageNode = document.createElement(mxClient.VML_PREFIX + ':image');
  4820. imageNode.setAttribute('src', src);
  4821. imageNode.style.borderStyle = 'none';
  4822. }
  4823. else
  4824. {
  4825. imageNode = document.createElement('img');
  4826. imageNode.setAttribute('src', src);
  4827. imageNode.setAttribute('border', '0');
  4828. }
  4829. return imageNode;
  4830. },
  4831. /**
  4832. * Function: sortCells
  4833. *
  4834. * Sorts the given cells according to the order in the cell hierarchy.
  4835. * Ascending is optional and defaults to true.
  4836. */
  4837. sortCells: function(cells, ascending)
  4838. {
  4839. ascending = (ascending != null) ? ascending : true;
  4840. var lookup = new mxDictionary();
  4841. cells.sort(function(o1, o2)
  4842. {
  4843. var p1 = lookup.get(o1);
  4844. if (p1 == null)
  4845. {
  4846. p1 = mxCellPath.create(o1).split(mxCellPath.PATH_SEPARATOR);
  4847. lookup.put(o1, p1);
  4848. }
  4849. var p2 = lookup.get(o2);
  4850. if (p2 == null)
  4851. {
  4852. p2 = mxCellPath.create(o2).split(mxCellPath.PATH_SEPARATOR);
  4853. lookup.put(o2, p2);
  4854. }
  4855. var comp = mxCellPath.compare(p1, p2);
  4856. return (comp == 0) ? 0 : (((comp > 0) == ascending) ? 1 : -1);
  4857. });
  4858. return cells;
  4859. },
  4860. /**
  4861. * Function: getStylename
  4862. *
  4863. * Returns the stylename in a style of the form [(stylename|key=value);] or
  4864. * an empty string if the given style does not contain a stylename.
  4865. *
  4866. * Parameters:
  4867. *
  4868. * style - String of the form [(stylename|key=value);].
  4869. */
  4870. getStylename: function(style)
  4871. {
  4872. if (style != null)
  4873. {
  4874. var pairs = style.split(';');
  4875. var stylename = pairs[0];
  4876. if (stylename.indexOf('=') < 0)
  4877. {
  4878. return stylename;
  4879. }
  4880. }
  4881. return '';
  4882. },
  4883. /**
  4884. * Function: getStylenames
  4885. *
  4886. * Returns the stylenames in a style of the form [(stylename|key=value);]
  4887. * or an empty array if the given style does not contain any stylenames.
  4888. *
  4889. * Parameters:
  4890. *
  4891. * style - String of the form [(stylename|key=value);].
  4892. */
  4893. getStylenames: function(style)
  4894. {
  4895. var result = [];
  4896. if (style != null)
  4897. {
  4898. var pairs = style.split(';');
  4899. for (var i = 0; i < pairs.length; i++)
  4900. {
  4901. if (pairs[i].indexOf('=') < 0)
  4902. {
  4903. result.push(pairs[i]);
  4904. }
  4905. }
  4906. }
  4907. return result;
  4908. },
  4909. /**
  4910. * Function: indexOfStylename
  4911. *
  4912. * Returns the index of the given stylename in the given style. This
  4913. * returns -1 if the given stylename does not occur (as a stylename) in the
  4914. * given style, otherwise it returns the index of the first character.
  4915. */
  4916. indexOfStylename: function(style, stylename)
  4917. {
  4918. if (style != null && stylename != null)
  4919. {
  4920. var tokens = style.split(';');
  4921. var pos = 0;
  4922. for (var i = 0; i < tokens.length; i++)
  4923. {
  4924. if (tokens[i] == stylename)
  4925. {
  4926. return pos;
  4927. }
  4928. pos += tokens[i].length + 1;
  4929. }
  4930. }
  4931. return -1;
  4932. },
  4933. /**
  4934. * Function: addStylename
  4935. *
  4936. * Adds the specified stylename to the given style if it does not already
  4937. * contain the stylename.
  4938. */
  4939. addStylename: function(style, stylename)
  4940. {
  4941. if (mxUtils.indexOfStylename(style, stylename) < 0)
  4942. {
  4943. if (style == null)
  4944. {
  4945. style = '';
  4946. }
  4947. else if (style.length > 0 && style.charAt(style.length - 1) != ';')
  4948. {
  4949. style += ';';
  4950. }
  4951. style += stylename;
  4952. }
  4953. return style;
  4954. },
  4955. /**
  4956. * Function: removeStylename
  4957. *
  4958. * Removes all occurrences of the specified stylename in the given style
  4959. * and returns the updated style. Trailing semicolons are not preserved.
  4960. */
  4961. removeStylename: function(style, stylename)
  4962. {
  4963. var result = [];
  4964. if (style != null)
  4965. {
  4966. var tokens = style.split(';');
  4967. for (var i = 0; i < tokens.length; i++)
  4968. {
  4969. if (tokens[i] != stylename)
  4970. {
  4971. result.push(tokens[i]);
  4972. }
  4973. }
  4974. }
  4975. return result.join(';');
  4976. },
  4977. /**
  4978. * Function: removeAllStylenames
  4979. *
  4980. * Removes all stylenames from the given style and returns the updated
  4981. * style.
  4982. */
  4983. removeAllStylenames: function(style)
  4984. {
  4985. var result = [];
  4986. if (style != null)
  4987. {
  4988. var tokens = style.split(';');
  4989. for (var i = 0; i < tokens.length; i++)
  4990. {
  4991. // Keeps the key, value assignments
  4992. if (tokens[i].indexOf('=') >= 0)
  4993. {
  4994. result.push(tokens[i]);
  4995. }
  4996. }
  4997. }
  4998. return result.join(';');
  4999. },
  5000. /**
  5001. * Function: setCellStyles
  5002. *
  5003. * Assigns the value for the given key in the styles of the given cells, or
  5004. * removes the key from the styles if the value is null.
  5005. *
  5006. * Parameters:
  5007. *
  5008. * model - <mxGraphModel> to execute the transaction in.
  5009. * cells - Array of <mxCells> to be updated.
  5010. * key - Key of the style to be changed.
  5011. * value - New value for the given key.
  5012. */
  5013. setCellStyles: function(model, cells, key, value)
  5014. {
  5015. if (cells != null && cells.length > 0)
  5016. {
  5017. model.beginUpdate();
  5018. try
  5019. {
  5020. for (var i = 0; i < cells.length; i++)
  5021. {
  5022. if (cells[i] != null)
  5023. {
  5024. var style = mxUtils.setStyle(model.getStyle(cells[i]), key, value);
  5025. model.setStyle(cells[i], style);
  5026. }
  5027. }
  5028. }
  5029. finally
  5030. {
  5031. model.endUpdate();
  5032. }
  5033. }
  5034. },
  5035. /**
  5036. * Function: setStyle
  5037. *
  5038. * Adds or removes the given key, value pair to the style and returns the
  5039. * new style. If value is null or zero length then the key is removed from
  5040. * the style. This is for cell styles, not for CSS styles.
  5041. *
  5042. * Parameters:
  5043. *
  5044. * style - String of the form [(stylename|key=value);].
  5045. * key - Key of the style to be changed.
  5046. * value - New value for the given key.
  5047. */
  5048. setStyle: function(style, key, value)
  5049. {
  5050. var isValue = value != null && (typeof(value.length) == 'undefined' || value.length > 0);
  5051. if (style == null || style.length == 0)
  5052. {
  5053. if (isValue)
  5054. {
  5055. style = key + '=' + value + ';';
  5056. }
  5057. }
  5058. else
  5059. {
  5060. if (style.substring(0, key.length + 1) == key + '=')
  5061. {
  5062. var next = style.indexOf(';');
  5063. if (isValue)
  5064. {
  5065. style = key + '=' + value + ((next < 0) ? ';' : style.substring(next));
  5066. }
  5067. else
  5068. {
  5069. style = (next < 0 || next == style.length - 1) ? '' : style.substring(next + 1);
  5070. }
  5071. }
  5072. else
  5073. {
  5074. var index = style.indexOf(';' + key + '=');
  5075. if (index < 0)
  5076. {
  5077. if (isValue)
  5078. {
  5079. var sep = (style.charAt(style.length - 1) == ';') ? '' : ';';
  5080. style = style + sep + key + '=' + value + ';';
  5081. }
  5082. }
  5083. else
  5084. {
  5085. var next = style.indexOf(';', index + 1);
  5086. if (isValue)
  5087. {
  5088. style = style.substring(0, index + 1) + key + '=' + value + ((next < 0) ? ';' : style.substring(next));
  5089. }
  5090. else
  5091. {
  5092. style = style.substring(0, index) + ((next < 0) ? ';' : style.substring(next));
  5093. }
  5094. }
  5095. }
  5096. }
  5097. return style;
  5098. },
  5099. /**
  5100. * Function: setCellStyleFlags
  5101. *
  5102. * Sets or toggles the flag bit for the given key in the cell's styles.
  5103. * If value is null then the flag is toggled.
  5104. *
  5105. * Example:
  5106. *
  5107. * (code)
  5108. * var cells = graph.getSelectionCells();
  5109. * mxUtils.setCellStyleFlags(graph.model,
  5110. * cells,
  5111. * mxConstants.STYLE_FONTSTYLE,
  5112. * mxConstants.FONT_BOLD);
  5113. * (end)
  5114. *
  5115. * Toggles the bold font style.
  5116. *
  5117. * Parameters:
  5118. *
  5119. * model - <mxGraphModel> that contains the cells.
  5120. * cells - Array of <mxCells> to change the style for.
  5121. * key - Key of the style to be changed.
  5122. * flag - Integer for the bit to be changed.
  5123. * value - Optional boolean value for the flag.
  5124. */
  5125. setCellStyleFlags: function(model, cells, key, flag, value)
  5126. {
  5127. if (cells != null && cells.length > 0)
  5128. {
  5129. model.beginUpdate();
  5130. try
  5131. {
  5132. for (var i = 0; i < cells.length; i++)
  5133. {
  5134. if (cells[i] != null)
  5135. {
  5136. var style = mxUtils.setStyleFlag(
  5137. model.getStyle(cells[i]),
  5138. key, flag, value);
  5139. model.setStyle(cells[i], style);
  5140. }
  5141. }
  5142. }
  5143. finally
  5144. {
  5145. model.endUpdate();
  5146. }
  5147. }
  5148. },
  5149. /**
  5150. * Function: setStyleFlag
  5151. *
  5152. * Sets or removes the given key from the specified style and returns the
  5153. * new style. If value is null then the flag is toggled.
  5154. *
  5155. * Parameters:
  5156. *
  5157. * style - String of the form [(stylename|key=value);].
  5158. * key - Key of the style to be changed.
  5159. * flag - Integer for the bit to be changed.
  5160. * value - Optional boolean value for the given flag.
  5161. */
  5162. setStyleFlag: function(style, key, flag, value)
  5163. {
  5164. if (style == null || style.length == 0)
  5165. {
  5166. if (value || value == null)
  5167. {
  5168. style = key+'='+flag;
  5169. }
  5170. else
  5171. {
  5172. style = key+'=0';
  5173. }
  5174. }
  5175. else
  5176. {
  5177. var index = style.indexOf(key+'=');
  5178. if (index < 0)
  5179. {
  5180. var sep = (style.charAt(style.length-1) == ';') ? '' : ';';
  5181. if (value || value == null)
  5182. {
  5183. style = style + sep + key + '=' + flag;
  5184. }
  5185. else
  5186. {
  5187. style = style + sep + key + '=0';
  5188. }
  5189. }
  5190. else
  5191. {
  5192. var cont = style.indexOf(';', index);
  5193. var tmp = '';
  5194. if (cont < 0)
  5195. {
  5196. tmp = style.substring(index+key.length+1);
  5197. }
  5198. else
  5199. {
  5200. tmp = style.substring(index+key.length+1, cont);
  5201. }
  5202. if (value == null)
  5203. {
  5204. tmp = parseInt(tmp) ^ flag;
  5205. }
  5206. else if (value)
  5207. {
  5208. tmp = parseInt(tmp) | flag;
  5209. }
  5210. else
  5211. {
  5212. tmp = parseInt(tmp) & ~flag;
  5213. }
  5214. style = style.substring(0, index) + key + '=' + tmp +
  5215. ((cont >= 0) ? style.substring(cont) : '');
  5216. }
  5217. }
  5218. return style;
  5219. },
  5220. /**
  5221. * Function: getAlignmentAsPoint
  5222. *
  5223. * Returns an <mxPoint> that represents the horizontal and vertical alignment
  5224. * for numeric computations. X is -0.5 for center, -1 for right and 0 for
  5225. * left alignment. Y is -0.5 for middle, -1 for bottom and 0 for top
  5226. * alignment. Default values for missing arguments is top, left.
  5227. */
  5228. getAlignmentAsPoint: function(align, valign)
  5229. {
  5230. var dx = -0.5;
  5231. var dy = -0.5;
  5232. // Horizontal alignment
  5233. if (align == mxConstants.ALIGN_LEFT)
  5234. {
  5235. dx = 0;
  5236. }
  5237. else if (align == mxConstants.ALIGN_RIGHT)
  5238. {
  5239. dx = -1;
  5240. }
  5241. // Vertical alignment
  5242. if (valign == mxConstants.ALIGN_TOP)
  5243. {
  5244. dy = 0;
  5245. }
  5246. else if (valign == mxConstants.ALIGN_BOTTOM)
  5247. {
  5248. dy = -1;
  5249. }
  5250. return new mxPoint(dx, dy);
  5251. },
  5252. /**
  5253. * Function: getSizeForString
  5254. *
  5255. * Returns an <mxRectangle> with the size (width and height in pixels) of
  5256. * the given string. The string may contain HTML markup. Newlines should be
  5257. * converted to <br> before calling this method. The caller is responsible
  5258. * for sanitizing the HTML markup.
  5259. *
  5260. * Example:
  5261. *
  5262. * (code)
  5263. * var label = graph.getLabel(cell).replace(/\n/g, "<br>");
  5264. * var size = graph.getSizeForString(label);
  5265. * (end)
  5266. *
  5267. * Parameters:
  5268. *
  5269. * text - String whose size should be returned.
  5270. * fontSize - Integer that specifies the font size in pixels. Default is
  5271. * <mxConstants.DEFAULT_FONTSIZE>.
  5272. * fontFamily - String that specifies the name of the font family. Default
  5273. * is <mxConstants.DEFAULT_FONTFAMILY>.
  5274. * textWidth - Optional width for text wrapping.
  5275. * fontStyle - Optional font style.
  5276. */
  5277. getSizeForString: function(text, fontSize, fontFamily, textWidth, fontStyle)
  5278. {
  5279. fontSize = (fontSize != null) ? fontSize : mxConstants.DEFAULT_FONTSIZE;
  5280. fontFamily = (fontFamily != null) ? fontFamily : mxConstants.DEFAULT_FONTFAMILY;
  5281. var div = document.createElement('div');
  5282. // Sets the font size and family
  5283. div.style.fontFamily = fontFamily;
  5284. div.style.fontSize = Math.round(fontSize) + 'px';
  5285. div.style.lineHeight = Math.round(fontSize * mxConstants.LINE_HEIGHT) + 'px';
  5286. // Sets the font style
  5287. if (fontStyle != null)
  5288. {
  5289. if ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  5290. {
  5291. div.style.fontWeight = 'bold';
  5292. }
  5293. if ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  5294. {
  5295. div.style.fontStyle = 'italic';
  5296. }
  5297. var txtDecor = [];
  5298. if ((fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  5299. {
  5300. txtDecor.push('underline');
  5301. }
  5302. if ((fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  5303. {
  5304. txtDecor.push('line-through');
  5305. }
  5306. if (txtDecor.length > 0)
  5307. {
  5308. div.style.textDecoration = txtDecor.join(' ');
  5309. }
  5310. }
  5311. // Disables block layout and outside wrapping and hides the div
  5312. div.style.position = 'absolute';
  5313. div.style.visibility = 'hidden';
  5314. div.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  5315. div.style.zoom = '1';
  5316. if (textWidth != null)
  5317. {
  5318. div.style.width = textWidth + 'px';
  5319. div.style.whiteSpace = 'normal';
  5320. }
  5321. else
  5322. {
  5323. div.style.whiteSpace = 'nowrap';
  5324. }
  5325. // Adds the text and inserts into DOM for updating of size
  5326. div.innerHTML = text;
  5327. document.body.appendChild(div);
  5328. // Gets the size and removes from DOM
  5329. var size = new mxRectangle(0, 0, div.offsetWidth, div.offsetHeight);
  5330. document.body.removeChild(div);
  5331. return size;
  5332. },
  5333. /**
  5334. * Function: getViewXml
  5335. */
  5336. getViewXml: function(graph, scale, cells, x0, y0)
  5337. {
  5338. x0 = (x0 != null) ? x0 : 0;
  5339. y0 = (y0 != null) ? y0 : 0;
  5340. scale = (scale != null) ? scale : 1;
  5341. if (cells == null)
  5342. {
  5343. var model = graph.getModel();
  5344. cells = [model.getRoot()];
  5345. }
  5346. var view = graph.getView();
  5347. var result = null;
  5348. // Disables events on the view
  5349. var eventsEnabled = view.isEventsEnabled();
  5350. view.setEventsEnabled(false);
  5351. // Workaround for label bounds not taken into account for image export.
  5352. // Creates a temporary draw pane which is used for rendering the text.
  5353. // Text rendering is required for finding the bounds of the labels.
  5354. var drawPane = view.drawPane;
  5355. var overlayPane = view.overlayPane;
  5356. if (graph.dialect == mxConstants.DIALECT_SVG)
  5357. {
  5358. view.drawPane = document.createElementNS(mxConstants.NS_SVG, 'g');
  5359. view.canvas.appendChild(view.drawPane);
  5360. // Redirects cell overlays into temporary container
  5361. view.overlayPane = document.createElementNS(mxConstants.NS_SVG, 'g');
  5362. view.canvas.appendChild(view.overlayPane);
  5363. }
  5364. else
  5365. {
  5366. view.drawPane = view.drawPane.cloneNode(false);
  5367. view.canvas.appendChild(view.drawPane);
  5368. // Redirects cell overlays into temporary container
  5369. view.overlayPane = view.overlayPane.cloneNode(false);
  5370. view.canvas.appendChild(view.overlayPane);
  5371. }
  5372. // Resets the translation
  5373. var translate = view.getTranslate();
  5374. view.translate = new mxPoint(x0, y0);
  5375. // Creates the temporary cell states in the view
  5376. var temp = new mxTemporaryCellStates(graph.getView(), scale, cells);
  5377. try
  5378. {
  5379. var enc = new mxCodec();
  5380. result = enc.encode(graph.getView());
  5381. }
  5382. finally
  5383. {
  5384. temp.destroy();
  5385. view.translate = translate;
  5386. view.canvas.removeChild(view.drawPane);
  5387. view.canvas.removeChild(view.overlayPane);
  5388. view.drawPane = drawPane;
  5389. view.overlayPane = overlayPane;
  5390. view.setEventsEnabled(eventsEnabled);
  5391. }
  5392. return result;
  5393. },
  5394. /**
  5395. * Function: getScaleForPageCount
  5396. *
  5397. * Returns the scale to be used for printing the graph with the given
  5398. * bounds across the specifies number of pages with the given format. The
  5399. * scale is always computed such that it given the given amount or fewer
  5400. * pages in the print output. See <mxPrintPreview> for an example.
  5401. *
  5402. * Parameters:
  5403. *
  5404. * pageCount - Specifies the number of pages in the print output.
  5405. * graph - <mxGraph> that should be printed.
  5406. * pageFormat - Optional <mxRectangle> that specifies the page format.
  5407. * Default is <mxConstants.PAGE_FORMAT_A4_PORTRAIT>.
  5408. * border - The border along each side of every page.
  5409. */
  5410. getScaleForPageCount: function(pageCount, graph, pageFormat, border)
  5411. {
  5412. if (pageCount < 1)
  5413. {
  5414. // We can't work with less than 1 page, return no scale
  5415. // change
  5416. return 1;
  5417. }
  5418. pageFormat = (pageFormat != null) ? pageFormat : mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  5419. border = (border != null) ? border : 0;
  5420. var availablePageWidth = pageFormat.width - (border * 2);
  5421. var availablePageHeight = pageFormat.height - (border * 2);
  5422. // Work out the number of pages required if the
  5423. // graph is not scaled.
  5424. var graphBounds = graph.getGraphBounds().clone();
  5425. var sc = graph.getView().getScale();
  5426. graphBounds.width /= sc;
  5427. graphBounds.height /= sc;
  5428. var graphWidth = graphBounds.width;
  5429. var graphHeight = graphBounds.height;
  5430. var scale = 1;
  5431. // The ratio of the width/height for each printer page
  5432. var pageFormatAspectRatio = availablePageWidth / availablePageHeight;
  5433. // The ratio of the width/height for the graph to be printer
  5434. var graphAspectRatio = graphWidth / graphHeight;
  5435. // The ratio of horizontal pages / vertical pages for this
  5436. // graph to maintain its aspect ratio on this page format
  5437. var pagesAspectRatio = graphAspectRatio / pageFormatAspectRatio;
  5438. // Factor the square root of the page count up and down
  5439. // by the pages aspect ratio to obtain a horizontal and
  5440. // vertical page count that adds up to the page count
  5441. // and has the correct aspect ratio
  5442. var pageRoot = Math.sqrt(pageCount);
  5443. var pagesAspectRatioSqrt = Math.sqrt(pagesAspectRatio);
  5444. var numRowPages = pageRoot * pagesAspectRatioSqrt;
  5445. var numColumnPages = pageRoot / pagesAspectRatioSqrt;
  5446. // These value are rarely more than 2 rounding downs away from
  5447. // a total that meets the page count. In cases of one being less
  5448. // than 1 page, the other value can be too high and take more iterations
  5449. // In this case, just change that value to be the page count, since
  5450. // we know the other value is 1
  5451. if (numRowPages < 1 && numColumnPages > pageCount)
  5452. {
  5453. var scaleChange = numColumnPages / pageCount;
  5454. numColumnPages = pageCount;
  5455. numRowPages /= scaleChange;
  5456. }
  5457. if (numColumnPages < 1 && numRowPages > pageCount)
  5458. {
  5459. var scaleChange = numRowPages / pageCount;
  5460. numRowPages = pageCount;
  5461. numColumnPages /= scaleChange;
  5462. }
  5463. var currentTotalPages = Math.ceil(numRowPages) * Math.ceil(numColumnPages);
  5464. var numLoops = 0;
  5465. // Iterate through while the rounded up number of pages comes to
  5466. // a total greater than the required number
  5467. while (currentTotalPages > pageCount)
  5468. {
  5469. // Round down the page count (rows or columns) that is
  5470. // closest to its next integer down in percentage terms.
  5471. // i.e. Reduce the page total by reducing the total
  5472. // page area by the least possible amount
  5473. var roundRowDownProportion = Math.floor(numRowPages) / numRowPages;
  5474. var roundColumnDownProportion = Math.floor(numColumnPages) / numColumnPages;
  5475. // If the round down proportion is, work out the proportion to
  5476. // round down to 1 page less
  5477. if (roundRowDownProportion == 1)
  5478. {
  5479. roundRowDownProportion = Math.floor(numRowPages-1) / numRowPages;
  5480. }
  5481. if (roundColumnDownProportion == 1)
  5482. {
  5483. roundColumnDownProportion = Math.floor(numColumnPages-1) / numColumnPages;
  5484. }
  5485. // Check which rounding down is smaller, but in the case of very small roundings
  5486. // try the other dimension instead
  5487. var scaleChange = 1;
  5488. // Use the higher of the two values
  5489. if (roundRowDownProportion > roundColumnDownProportion)
  5490. {
  5491. scaleChange = roundRowDownProportion;
  5492. }
  5493. else
  5494. {
  5495. scaleChange = roundColumnDownProportion;
  5496. }
  5497. numRowPages = numRowPages * scaleChange;
  5498. numColumnPages = numColumnPages * scaleChange;
  5499. currentTotalPages = Math.ceil(numRowPages) * Math.ceil(numColumnPages);
  5500. numLoops++;
  5501. if (numLoops > 10)
  5502. {
  5503. break;
  5504. }
  5505. }
  5506. // Work out the scale from the number of row pages required
  5507. // The column pages will give the same value
  5508. var posterWidth = availablePageWidth * numRowPages;
  5509. scale = posterWidth / graphWidth;
  5510. // Allow for rounding errors
  5511. return scale * 0.99999;
  5512. },
  5513. /**
  5514. * Function: show
  5515. *
  5516. * Copies the styles and the markup from the graph's container into the
  5517. * given document and removes all cursor styles. The document is returned.
  5518. *
  5519. * This function should be called from within the document with the graph.
  5520. * If you experience problems with missing stylesheets in IE then try adding
  5521. * the domain to the trusted sites.
  5522. *
  5523. * Parameters:
  5524. *
  5525. * graph - <mxGraph> to be copied.
  5526. * doc - Document where the new graph is created.
  5527. * x0 - X-coordinate of the graph view origin. Default is 0.
  5528. * y0 - Y-coordinate of the graph view origin. Default is 0.
  5529. * w - Optional width of the graph view.
  5530. * h - Optional height of the graph view.
  5531. */
  5532. show: function(graph, doc, x0, y0, w, h)
  5533. {
  5534. x0 = (x0 != null) ? x0 : 0;
  5535. y0 = (y0 != null) ? y0 : 0;
  5536. if (doc == null)
  5537. {
  5538. var wnd = window.open();
  5539. doc = wnd.document;
  5540. }
  5541. else
  5542. {
  5543. doc.open();
  5544. }
  5545. // Workaround for missing print output in IE9 standards
  5546. if (document.documentMode == 9)
  5547. {
  5548. doc.writeln('<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=9"><![endif]-->');
  5549. }
  5550. var bounds = graph.getGraphBounds();
  5551. var dx = Math.ceil(x0 - bounds.x);
  5552. var dy = Math.ceil(y0 - bounds.y);
  5553. if (w == null)
  5554. {
  5555. w = Math.ceil(bounds.width + x0) + Math.ceil(Math.ceil(bounds.x) - bounds.x);
  5556. }
  5557. if (h == null)
  5558. {
  5559. h = Math.ceil(bounds.height + y0) + Math.ceil(Math.ceil(bounds.y) - bounds.y);
  5560. }
  5561. // Needs a special way of creating the page so that no click is required
  5562. // to refresh the contents after the external CSS styles have been loaded.
  5563. // To avoid a click or programmatic refresh, the styleSheets[].cssText
  5564. // property is copied over from the original document.
  5565. if (mxClient.IS_IE || document.documentMode == 11)
  5566. {
  5567. var html = '<html><head>';
  5568. var base = document.getElementsByTagName('base');
  5569. for (var i = 0; i < base.length; i++)
  5570. {
  5571. html += base[i].outerHTML;
  5572. }
  5573. html += '<style>';
  5574. // Copies the stylesheets without having to load them again
  5575. for (var i = 0; i < document.styleSheets.length; i++)
  5576. {
  5577. try
  5578. {
  5579. html += document.styleSheets[i].cssText;
  5580. }
  5581. catch (e)
  5582. {
  5583. // ignore security exception
  5584. }
  5585. }
  5586. html += '</style></head><body style="margin:0px;">';
  5587. // Copies the contents of the graph container
  5588. html += '<div style="position:absolute;overflow:hidden;width:' + w + 'px;height:' + h + 'px;"><div style="position:relative;left:' + dx + 'px;top:' + dy + 'px;">';
  5589. html += graph.container.innerHTML;
  5590. html += '</div></div></body><html>';
  5591. doc.writeln(html);
  5592. doc.close();
  5593. }
  5594. else
  5595. {
  5596. doc.writeln('<html><head>');
  5597. var base = document.getElementsByTagName('base');
  5598. for (var i = 0; i < base.length; i++)
  5599. {
  5600. doc.writeln(mxUtils.getOuterHtml(base[i]));
  5601. }
  5602. var links = document.getElementsByTagName('link');
  5603. for (var i = 0; i < links.length; i++)
  5604. {
  5605. doc.writeln(mxUtils.getOuterHtml(links[i]));
  5606. }
  5607. var styles = document.getElementsByTagName('style');
  5608. for (var i = 0; i < styles.length; i++)
  5609. {
  5610. doc.writeln(mxUtils.getOuterHtml(styles[i]));
  5611. }
  5612. doc.writeln('</head><body style="margin:0px;"></body></html>');
  5613. doc.close();
  5614. var outer = doc.createElement('div');
  5615. outer.position = 'absolute';
  5616. outer.overflow = 'hidden';
  5617. outer.style.width = w + 'px';
  5618. outer.style.height = h + 'px';
  5619. // Required for HTML labels if foreignObjects are disabled
  5620. var div = doc.createElement('div');
  5621. div.style.position = 'absolute';
  5622. div.style.left = dx + 'px';
  5623. div.style.top = dy + 'px';
  5624. var node = graph.container.firstChild;
  5625. var svg = null;
  5626. while (node != null)
  5627. {
  5628. var clone = node.cloneNode(true);
  5629. if (node == graph.view.drawPane.ownerSVGElement)
  5630. {
  5631. outer.appendChild(clone);
  5632. svg = clone;
  5633. }
  5634. else
  5635. {
  5636. div.appendChild(clone);
  5637. }
  5638. node = node.nextSibling;
  5639. }
  5640. doc.body.appendChild(outer);
  5641. if (div.firstChild != null)
  5642. {
  5643. doc.body.appendChild(div);
  5644. }
  5645. if (svg != null)
  5646. {
  5647. svg.style.minWidth = '';
  5648. svg.style.minHeight = '';
  5649. svg.firstChild.setAttribute('transform', 'translate(' + dx + ',' + dy + ')');
  5650. }
  5651. }
  5652. mxUtils.removeCursors(doc.body);
  5653. return doc;
  5654. },
  5655. /**
  5656. * Function: printScreen
  5657. *
  5658. * Prints the specified graph using a new window and the built-in print
  5659. * dialog.
  5660. *
  5661. * This function should be called from within the document with the graph.
  5662. *
  5663. * Parameters:
  5664. *
  5665. * graph - <mxGraph> to be printed.
  5666. */
  5667. printScreen: function(graph)
  5668. {
  5669. var wnd = window.open();
  5670. var bounds = graph.getGraphBounds();
  5671. mxUtils.show(graph, wnd.document);
  5672. var print = function()
  5673. {
  5674. wnd.focus();
  5675. wnd.print();
  5676. wnd.close();
  5677. };
  5678. // Workaround for Google Chrome which needs a bit of a
  5679. // delay in order to render the SVG contents
  5680. if (mxClient.IS_GC)
  5681. {
  5682. wnd.setTimeout(print, 500);
  5683. }
  5684. else
  5685. {
  5686. print();
  5687. }
  5688. },
  5689. /**
  5690. * Function: popup
  5691. *
  5692. * Shows the specified text content in a new <mxWindow> or a new browser
  5693. * window if isInternalWindow is false.
  5694. *
  5695. * Parameters:
  5696. *
  5697. * content - String that specifies the text to be displayed.
  5698. * isInternalWindow - Optional boolean indicating if an mxWindow should be
  5699. * used instead of a new browser window. Default is false.
  5700. */
  5701. popup: function(content, isInternalWindow)
  5702. {
  5703. if (isInternalWindow)
  5704. {
  5705. var div = document.createElement('div');
  5706. div.style.overflow = 'scroll';
  5707. div.style.width = '636px';
  5708. div.style.height = '460px';
  5709. var pre = document.createElement('pre');
  5710. pre.innerHTML = mxUtils.htmlEntities(content, false).
  5711. replace(/\n/g,'<br>').replace(/ /g, '&nbsp;');
  5712. div.appendChild(pre);
  5713. var w = document.body.clientWidth;
  5714. var h = Math.max(document.body.clientHeight || 0, document.documentElement.clientHeight)
  5715. var wnd = new mxWindow('Popup Window', div,
  5716. w/2-320, h/2-240, 640, 480, false, true);
  5717. wnd.setClosable(true);
  5718. wnd.setVisible(true);
  5719. }
  5720. else
  5721. {
  5722. // Wraps up the XML content in a textarea
  5723. if (mxClient.IS_NS)
  5724. {
  5725. var wnd = window.open();
  5726. wnd.document.writeln('<pre>'+mxUtils.htmlEntities(content)+'</pre');
  5727. wnd.document.close();
  5728. }
  5729. else
  5730. {
  5731. var wnd = window.open();
  5732. var pre = wnd.document.createElement('pre');
  5733. pre.innerHTML = mxUtils.htmlEntities(content, false).
  5734. replace(/\n/g,'<br>').replace(/ /g, '&nbsp;');
  5735. wnd.document.body.appendChild(pre);
  5736. }
  5737. }
  5738. },
  5739. /**
  5740. * Function: alert
  5741. *
  5742. * Displayss the given alert in a new dialog. This implementation uses the
  5743. * built-in alert function. This is used to display validation errors when
  5744. * connections cannot be changed or created.
  5745. *
  5746. * Parameters:
  5747. *
  5748. * message - String specifying the message to be displayed.
  5749. */
  5750. alert: function(message)
  5751. {
  5752. alert(message);
  5753. },
  5754. /**
  5755. * Function: prompt
  5756. *
  5757. * Displays the given message in a prompt dialog. This implementation uses
  5758. * the built-in prompt function.
  5759. *
  5760. * Parameters:
  5761. *
  5762. * message - String specifying the message to be displayed.
  5763. * defaultValue - Optional string specifying the default value.
  5764. */
  5765. prompt: function(message, defaultValue)
  5766. {
  5767. return prompt(message, (defaultValue != null) ? defaultValue : '');
  5768. },
  5769. /**
  5770. * Function: confirm
  5771. *
  5772. * Displays the given message in a confirm dialog. This implementation uses
  5773. * the built-in confirm function.
  5774. *
  5775. * Parameters:
  5776. *
  5777. * message - String specifying the message to be displayed.
  5778. */
  5779. confirm: function(message)
  5780. {
  5781. return confirm(message);
  5782. },
  5783. /**
  5784. * Function: error
  5785. *
  5786. * Displays the given error message in a new <mxWindow> of the given width.
  5787. * If close is true then an additional close button is added to the window.
  5788. * The optional icon specifies the icon to be used for the window. Default
  5789. * is <mxUtils.errorImage>.
  5790. *
  5791. * Parameters:
  5792. *
  5793. * message - String specifying the message to be displayed.
  5794. * width - Integer specifying the width of the window.
  5795. * close - Optional boolean indicating whether to add a close button.
  5796. * icon - Optional icon for the window decoration.
  5797. */
  5798. error: function(message, width, close, icon)
  5799. {
  5800. var div = document.createElement('div');
  5801. div.style.padding = '20px';
  5802. var img = document.createElement('img');
  5803. img.setAttribute('src', icon || mxUtils.errorImage);
  5804. img.setAttribute('valign', 'bottom');
  5805. img.style.verticalAlign = 'middle';
  5806. div.appendChild(img);
  5807. div.appendChild(document.createTextNode('\u00a0')); // &nbsp;
  5808. div.appendChild(document.createTextNode('\u00a0')); // &nbsp;
  5809. div.appendChild(document.createTextNode('\u00a0')); // &nbsp;
  5810. mxUtils.write(div, message);
  5811. var w = document.body.clientWidth;
  5812. var h = (document.body.clientHeight || document.documentElement.clientHeight);
  5813. var warn = new mxWindow(mxResources.get(mxUtils.errorResource) ||
  5814. mxUtils.errorResource, div, (w-width)/2, h/4, width, null,
  5815. false, true);
  5816. if (close)
  5817. {
  5818. mxUtils.br(div);
  5819. var tmp = document.createElement('p');
  5820. var button = document.createElement('button');
  5821. if (mxClient.IS_IE)
  5822. {
  5823. button.style.cssText = 'float:right';
  5824. }
  5825. else
  5826. {
  5827. button.setAttribute('style', 'float:right');
  5828. }
  5829. mxEvent.addListener(button, 'click', function(evt)
  5830. {
  5831. warn.destroy();
  5832. });
  5833. mxUtils.write(button, mxResources.get(mxUtils.closeResource) ||
  5834. mxUtils.closeResource);
  5835. tmp.appendChild(button);
  5836. div.appendChild(tmp);
  5837. mxUtils.br(div);
  5838. warn.setClosable(true);
  5839. }
  5840. warn.setVisible(true);
  5841. return warn;
  5842. },
  5843. /**
  5844. * Function: makeDraggable
  5845. *
  5846. * Configures the given DOM element to act as a drag source for the
  5847. * specified graph. Returns a a new <mxDragSource>. If
  5848. * <mxDragSource.guideEnabled> is enabled then the x and y arguments must
  5849. * be used in funct to match the preview location.
  5850. *
  5851. * Example:
  5852. *
  5853. * (code)
  5854. * var funct = function(graph, evt, cell, x, y)
  5855. * {
  5856. * if (graph.canImportCell(cell))
  5857. * {
  5858. * var parent = graph.getDefaultParent();
  5859. * var vertex = null;
  5860. *
  5861. * graph.getModel().beginUpdate();
  5862. * try
  5863. * {
  5864. * vertex = graph.insertVertex(parent, null, 'Hello', x, y, 80, 30);
  5865. * }
  5866. * finally
  5867. * {
  5868. * graph.getModel().endUpdate();
  5869. * }
  5870. *
  5871. * graph.setSelectionCell(vertex);
  5872. * }
  5873. * }
  5874. *
  5875. * var img = document.createElement('img');
  5876. * img.setAttribute('src', 'editors/images/rectangle.gif');
  5877. * img.style.position = 'absolute';
  5878. * img.style.left = '0px';
  5879. * img.style.top = '0px';
  5880. * img.style.width = '16px';
  5881. * img.style.height = '16px';
  5882. *
  5883. * var dragImage = img.cloneNode(true);
  5884. * dragImage.style.width = '32px';
  5885. * dragImage.style.height = '32px';
  5886. * mxUtils.makeDraggable(img, graph, funct, dragImage);
  5887. * document.body.appendChild(img);
  5888. * (end)
  5889. *
  5890. * Parameters:
  5891. *
  5892. * element - DOM element to make draggable.
  5893. * graphF - <mxGraph> that acts as the drop target or a function that takes a
  5894. * mouse event and returns the current <mxGraph>.
  5895. * funct - Function to execute on a successful drop.
  5896. * dragElement - Optional DOM node to be used for the drag preview.
  5897. * dx - Optional horizontal offset between the cursor and the drag
  5898. * preview.
  5899. * dy - Optional vertical offset between the cursor and the drag
  5900. * preview.
  5901. * autoscroll - Optional boolean that specifies if autoscroll should be
  5902. * used. Default is mxGraph.autoscroll.
  5903. * scalePreview - Optional boolean that specifies if the preview element
  5904. * should be scaled according to the graph scale. If this is true, then
  5905. * the offsets will also be scaled. Default is false.
  5906. * highlightDropTargets - Optional boolean that specifies if dropTargets
  5907. * should be highlighted. Default is true.
  5908. * getDropTarget - Optional function to return the drop target for a given
  5909. * location (x, y). Default is mxGraph.getCellAt.
  5910. */
  5911. makeDraggable: function(element, graphF, funct, dragElement, dx, dy, autoscroll,
  5912. scalePreview, highlightDropTargets, getDropTarget)
  5913. {
  5914. var dragSource = new mxDragSource(element, funct);
  5915. dragSource.dragOffset = new mxPoint((dx != null) ? dx : 0,
  5916. (dy != null) ? dy : mxConstants.TOOLTIP_VERTICAL_OFFSET);
  5917. dragSource.autoscroll = autoscroll;
  5918. // Cannot enable this by default. This needs to be enabled in the caller
  5919. // if the funct argument uses the new x- and y-arguments.
  5920. dragSource.setGuidesEnabled(false);
  5921. if (highlightDropTargets != null)
  5922. {
  5923. dragSource.highlightDropTargets = highlightDropTargets;
  5924. }
  5925. // Overrides function to find drop target cell
  5926. if (getDropTarget != null)
  5927. {
  5928. dragSource.getDropTarget = getDropTarget;
  5929. }
  5930. // Overrides function to get current graph
  5931. dragSource.getGraphForEvent = function(evt)
  5932. {
  5933. return (typeof(graphF) == 'function') ? graphF(evt) : graphF;
  5934. };
  5935. // Translates switches into dragSource customizations
  5936. if (dragElement != null)
  5937. {
  5938. dragSource.createDragElement = function()
  5939. {
  5940. return dragElement.cloneNode(true);
  5941. };
  5942. if (scalePreview)
  5943. {
  5944. dragSource.createPreviewElement = function(graph)
  5945. {
  5946. var elt = dragElement.cloneNode(true);
  5947. var w = parseInt(elt.style.width);
  5948. var h = parseInt(elt.style.height);
  5949. elt.style.width = Math.round(w * graph.view.scale) + 'px';
  5950. elt.style.height = Math.round(h * graph.view.scale) + 'px';
  5951. return elt;
  5952. };
  5953. }
  5954. }
  5955. return dragSource;
  5956. }
  5957. };
  5958. /**
  5959. * Copyright (c) 2006-2015, JGraph Ltd
  5960. * Copyright (c) 2006-2015, Gaudenz Alder
  5961. */
  5962. var mxConstants =
  5963. {
  5964. /**
  5965. * Class: mxConstants
  5966. *
  5967. * Defines various global constants.
  5968. *
  5969. * Variable: DEFAULT_HOTSPOT
  5970. *
  5971. * Defines the portion of the cell which is to be used as a connectable
  5972. * region. Default is 0.3. Possible values are 0 < x <= 1.
  5973. */
  5974. DEFAULT_HOTSPOT: 0.3,
  5975. /**
  5976. * Variable: MIN_HOTSPOT_SIZE
  5977. *
  5978. * Defines the minimum size in pixels of the portion of the cell which is
  5979. * to be used as a connectable region. Default is 8.
  5980. */
  5981. MIN_HOTSPOT_SIZE: 8,
  5982. /**
  5983. * Variable: MAX_HOTSPOT_SIZE
  5984. *
  5985. * Defines the maximum size in pixels of the portion of the cell which is
  5986. * to be used as a connectable region. Use 0 for no maximum. Default is 0.
  5987. */
  5988. MAX_HOTSPOT_SIZE: 0,
  5989. /**
  5990. * Variable: RENDERING_HINT_EXACT
  5991. *
  5992. * Defines the exact rendering hint.
  5993. */
  5994. RENDERING_HINT_EXACT: 'exact',
  5995. /**
  5996. * Variable: RENDERING_HINT_FASTER
  5997. *
  5998. * Defines the faster rendering hint.
  5999. */
  6000. RENDERING_HINT_FASTER: 'faster',
  6001. /**
  6002. * Variable: RENDERING_HINT_FASTEST
  6003. *
  6004. * Defines the fastest rendering hint.
  6005. */
  6006. RENDERING_HINT_FASTEST: 'fastest',
  6007. /**
  6008. * Variable: DIALECT_SVG
  6009. *
  6010. * Defines the SVG display dialect name.
  6011. */
  6012. DIALECT_SVG: 'svg',
  6013. /**
  6014. * Variable: DIALECT_VML
  6015. *
  6016. * Defines the VML display dialect name.
  6017. */
  6018. DIALECT_VML: 'vml',
  6019. /**
  6020. * Variable: DIALECT_MIXEDHTML
  6021. *
  6022. * Defines the mixed HTML display dialect name.
  6023. */
  6024. DIALECT_MIXEDHTML: 'mixedHtml',
  6025. /**
  6026. * Variable: DIALECT_PREFERHTML
  6027. *
  6028. * Defines the preferred HTML display dialect name.
  6029. */
  6030. DIALECT_PREFERHTML: 'preferHtml',
  6031. /**
  6032. * Variable: DIALECT_STRICTHTML
  6033. *
  6034. * Defines the strict HTML display dialect.
  6035. */
  6036. DIALECT_STRICTHTML: 'strictHtml',
  6037. /**
  6038. * Variable: NS_SVG
  6039. *
  6040. * Defines the SVG namespace.
  6041. */
  6042. NS_SVG: 'http://www.w3.org/2000/svg',
  6043. /**
  6044. * Variable: NS_XHTML
  6045. *
  6046. * Defines the XHTML namespace.
  6047. */
  6048. NS_XHTML: 'http://www.w3.org/1999/xhtml',
  6049. /**
  6050. * Variable: NS_XLINK
  6051. *
  6052. * Defines the XLink namespace.
  6053. */
  6054. NS_XLINK: 'http://www.w3.org/1999/xlink',
  6055. /**
  6056. * Variable: SHADOWCOLOR
  6057. *
  6058. * Defines the color to be used to draw shadows in shapes and windows.
  6059. * Default is gray.
  6060. */
  6061. SHADOWCOLOR: 'gray',
  6062. /**
  6063. * Variable: VML_SHADOWCOLOR
  6064. *
  6065. * Used for shadow color in filters where transparency is not supported
  6066. * (Microsoft Internet Explorer). Default is gray.
  6067. */
  6068. VML_SHADOWCOLOR: 'gray',
  6069. /**
  6070. * Variable: SHADOW_OFFSET_X
  6071. *
  6072. * Specifies the x-offset of the shadow. Default is 2.
  6073. */
  6074. SHADOW_OFFSET_X: 2,
  6075. /**
  6076. * Variable: SHADOW_OFFSET_Y
  6077. *
  6078. * Specifies the y-offset of the shadow. Default is 3.
  6079. */
  6080. SHADOW_OFFSET_Y: 3,
  6081. /**
  6082. * Variable: SHADOW_OPACITY
  6083. *
  6084. * Defines the opacity for shadows. Default is 1.
  6085. */
  6086. SHADOW_OPACITY: 1,
  6087. /**
  6088. * Variable: NODETYPE_ELEMENT
  6089. *
  6090. * DOM node of type ELEMENT.
  6091. */
  6092. NODETYPE_ELEMENT: 1,
  6093. /**
  6094. * Variable: NODETYPE_ATTRIBUTE
  6095. *
  6096. * DOM node of type ATTRIBUTE.
  6097. */
  6098. NODETYPE_ATTRIBUTE: 2,
  6099. /**
  6100. * Variable: NODETYPE_TEXT
  6101. *
  6102. * DOM node of type TEXT.
  6103. */
  6104. NODETYPE_TEXT: 3,
  6105. /**
  6106. * Variable: NODETYPE_CDATA
  6107. *
  6108. * DOM node of type CDATA.
  6109. */
  6110. NODETYPE_CDATA: 4,
  6111. /**
  6112. * Variable: NODETYPE_ENTITY_REFERENCE
  6113. *
  6114. * DOM node of type ENTITY_REFERENCE.
  6115. */
  6116. NODETYPE_ENTITY_REFERENCE: 5,
  6117. /**
  6118. * Variable: NODETYPE_ENTITY
  6119. *
  6120. * DOM node of type ENTITY.
  6121. */
  6122. NODETYPE_ENTITY: 6,
  6123. /**
  6124. * Variable: NODETYPE_PROCESSING_INSTRUCTION
  6125. *
  6126. * DOM node of type PROCESSING_INSTRUCTION.
  6127. */
  6128. NODETYPE_PROCESSING_INSTRUCTION: 7,
  6129. /**
  6130. * Variable: NODETYPE_COMMENT
  6131. *
  6132. * DOM node of type COMMENT.
  6133. */
  6134. NODETYPE_COMMENT: 8,
  6135. /**
  6136. * Variable: NODETYPE_DOCUMENT
  6137. *
  6138. * DOM node of type DOCUMENT.
  6139. */
  6140. NODETYPE_DOCUMENT: 9,
  6141. /**
  6142. * Variable: NODETYPE_DOCUMENTTYPE
  6143. *
  6144. * DOM node of type DOCUMENTTYPE.
  6145. */
  6146. NODETYPE_DOCUMENTTYPE: 10,
  6147. /**
  6148. * Variable: NODETYPE_DOCUMENT_FRAGMENT
  6149. *
  6150. * DOM node of type DOCUMENT_FRAGMENT.
  6151. */
  6152. NODETYPE_DOCUMENT_FRAGMENT: 11,
  6153. /**
  6154. * Variable: NODETYPE_NOTATION
  6155. *
  6156. * DOM node of type NOTATION.
  6157. */
  6158. NODETYPE_NOTATION: 12,
  6159. /**
  6160. * Variable: TOOLTIP_VERTICAL_OFFSET
  6161. *
  6162. * Defines the vertical offset for the tooltip.
  6163. * Default is 16.
  6164. */
  6165. TOOLTIP_VERTICAL_OFFSET: 16,
  6166. /**
  6167. * Variable: DEFAULT_VALID_COLOR
  6168. *
  6169. * Specifies the default valid color. Default is #0000FF.
  6170. */
  6171. DEFAULT_VALID_COLOR: '#00FF00',
  6172. /**
  6173. * Variable: DEFAULT_INVALID_COLOR
  6174. *
  6175. * Specifies the default invalid color. Default is #FF0000.
  6176. */
  6177. DEFAULT_INVALID_COLOR: '#FF0000',
  6178. /**
  6179. * Variable: OUTLINE_HIGHLIGHT_COLOR
  6180. *
  6181. * Specifies the default highlight color for shape outlines.
  6182. * Default is #0000FF. This is used in <mxEdgeHandler>.
  6183. */
  6184. OUTLINE_HIGHLIGHT_COLOR: '#00FF00',
  6185. /**
  6186. * Variable: OUTLINE_HIGHLIGHT_COLOR
  6187. *
  6188. * Defines the strokewidth to be used for shape outlines.
  6189. * Default is 5. This is used in <mxEdgeHandler>.
  6190. */
  6191. OUTLINE_HIGHLIGHT_STROKEWIDTH: 5,
  6192. /**
  6193. * Variable: HIGHLIGHT_STROKEWIDTH
  6194. *
  6195. * Defines the strokewidth to be used for the highlights.
  6196. * Default is 3.
  6197. */
  6198. HIGHLIGHT_STROKEWIDTH: 3,
  6199. /**
  6200. * Variable: CONSTRAINT_HIGHLIGHT_SIZE
  6201. *
  6202. * Size of the constraint highlight (in px). Default is 2.
  6203. */
  6204. HIGHLIGHT_SIZE: 2,
  6205. /**
  6206. * Variable: HIGHLIGHT_OPACITY
  6207. *
  6208. * Opacity (in %) used for the highlights (including outline).
  6209. * Default is 100.
  6210. */
  6211. HIGHLIGHT_OPACITY: 100,
  6212. /**
  6213. * Variable: CURSOR_MOVABLE_VERTEX
  6214. *
  6215. * Defines the cursor for a movable vertex. Default is 'move'.
  6216. */
  6217. CURSOR_MOVABLE_VERTEX: 'move',
  6218. /**
  6219. * Variable: CURSOR_MOVABLE_EDGE
  6220. *
  6221. * Defines the cursor for a movable edge. Default is 'move'.
  6222. */
  6223. CURSOR_MOVABLE_EDGE: 'move',
  6224. /**
  6225. * Variable: CURSOR_LABEL_HANDLE
  6226. *
  6227. * Defines the cursor for a movable label. Default is 'default'.
  6228. */
  6229. CURSOR_LABEL_HANDLE: 'default',
  6230. /**
  6231. * Variable: CURSOR_TERMINAL_HANDLE
  6232. *
  6233. * Defines the cursor for a terminal handle. Default is 'pointer'.
  6234. */
  6235. CURSOR_TERMINAL_HANDLE: 'pointer',
  6236. /**
  6237. * Variable: CURSOR_BEND_HANDLE
  6238. *
  6239. * Defines the cursor for a movable bend. Default is 'crosshair'.
  6240. */
  6241. CURSOR_BEND_HANDLE: 'crosshair',
  6242. /**
  6243. * Variable: CURSOR_VIRTUAL_BEND_HANDLE
  6244. *
  6245. * Defines the cursor for a movable bend. Default is 'crosshair'.
  6246. */
  6247. CURSOR_VIRTUAL_BEND_HANDLE: 'crosshair',
  6248. /**
  6249. * Variable: CURSOR_CONNECT
  6250. *
  6251. * Defines the cursor for a connectable state. Default is 'pointer'.
  6252. */
  6253. CURSOR_CONNECT: 'pointer',
  6254. /**
  6255. * Variable: HIGHLIGHT_COLOR
  6256. *
  6257. * Defines the color to be used for the cell highlighting.
  6258. * Use 'none' for no color. Default is #00FF00.
  6259. */
  6260. HIGHLIGHT_COLOR: '#00FF00',
  6261. /**
  6262. * Variable: TARGET_HIGHLIGHT_COLOR
  6263. *
  6264. * Defines the color to be used for highlighting a target cell for a new
  6265. * or changed connection. Note that this may be either a source or
  6266. * target terminal in the graph. Use 'none' for no color.
  6267. * Default is #0000FF.
  6268. */
  6269. CONNECT_TARGET_COLOR: '#0000FF',
  6270. /**
  6271. * Variable: INVALID_CONNECT_TARGET_COLOR
  6272. *
  6273. * Defines the color to be used for highlighting a invalid target cells
  6274. * for a new or changed connections. Note that this may be either a source
  6275. * or target terminal in the graph. Use 'none' for no color. Default is
  6276. * #FF0000.
  6277. */
  6278. INVALID_CONNECT_TARGET_COLOR: '#FF0000',
  6279. /**
  6280. * Variable: DROP_TARGET_COLOR
  6281. *
  6282. * Defines the color to be used for the highlighting target parent cells
  6283. * (for drag and drop). Use 'none' for no color. Default is #0000FF.
  6284. */
  6285. DROP_TARGET_COLOR: '#0000FF',
  6286. /**
  6287. * Variable: VALID_COLOR
  6288. *
  6289. * Defines the color to be used for the coloring valid connection
  6290. * previews. Use 'none' for no color. Default is #FF0000.
  6291. */
  6292. VALID_COLOR: '#00FF00',
  6293. /**
  6294. * Variable: INVALID_COLOR
  6295. *
  6296. * Defines the color to be used for the coloring invalid connection
  6297. * previews. Use 'none' for no color. Default is #FF0000.
  6298. */
  6299. INVALID_COLOR: '#FF0000',
  6300. /**
  6301. * Variable: EDGE_SELECTION_COLOR
  6302. *
  6303. * Defines the color to be used for the selection border of edges. Use
  6304. * 'none' for no color. Default is #00FF00.
  6305. */
  6306. EDGE_SELECTION_COLOR: '#00FF00',
  6307. /**
  6308. * Variable: VERTEX_SELECTION_COLOR
  6309. *
  6310. * Defines the color to be used for the selection border of vertices. Use
  6311. * 'none' for no color. Default is #00FF00.
  6312. */
  6313. VERTEX_SELECTION_COLOR: '#00FF00',
  6314. /**
  6315. * Variable: VERTEX_SELECTION_STROKEWIDTH
  6316. *
  6317. * Defines the strokewidth to be used for vertex selections.
  6318. * Default is 1.
  6319. */
  6320. VERTEX_SELECTION_STROKEWIDTH: 1,
  6321. /**
  6322. * Variable: EDGE_SELECTION_STROKEWIDTH
  6323. *
  6324. * Defines the strokewidth to be used for edge selections.
  6325. * Default is 1.
  6326. */
  6327. EDGE_SELECTION_STROKEWIDTH: 1,
  6328. /**
  6329. * Variable: SELECTION_DASHED
  6330. *
  6331. * Defines the dashed state to be used for the vertex selection
  6332. * border. Default is true.
  6333. */
  6334. VERTEX_SELECTION_DASHED: true,
  6335. /**
  6336. * Variable: SELECTION_DASHED
  6337. *
  6338. * Defines the dashed state to be used for the edge selection
  6339. * border. Default is true.
  6340. */
  6341. EDGE_SELECTION_DASHED: true,
  6342. /**
  6343. * Variable: GUIDE_COLOR
  6344. *
  6345. * Defines the color to be used for the guidelines in mxGraphHandler.
  6346. * Default is #FF0000.
  6347. */
  6348. GUIDE_COLOR: '#FF0000',
  6349. /**
  6350. * Variable: GUIDE_STROKEWIDTH
  6351. *
  6352. * Defines the strokewidth to be used for the guidelines in mxGraphHandler.
  6353. * Default is 1.
  6354. */
  6355. GUIDE_STROKEWIDTH: 1,
  6356. /**
  6357. * Variable: OUTLINE_COLOR
  6358. *
  6359. * Defines the color to be used for the outline rectangle
  6360. * border. Use 'none' for no color. Default is #0099FF.
  6361. */
  6362. OUTLINE_COLOR: '#0099FF',
  6363. /**
  6364. * Variable: OUTLINE_STROKEWIDTH
  6365. *
  6366. * Defines the strokewidth to be used for the outline rectangle
  6367. * stroke width. Default is 3.
  6368. */
  6369. OUTLINE_STROKEWIDTH: (mxClient.IS_IE) ? 2 : 3,
  6370. /**
  6371. * Variable: HANDLE_SIZE
  6372. *
  6373. * Defines the default size for handles. Default is 6.
  6374. */
  6375. HANDLE_SIZE: 6,
  6376. /**
  6377. * Variable: LABEL_HANDLE_SIZE
  6378. *
  6379. * Defines the default size for label handles. Default is 4.
  6380. */
  6381. LABEL_HANDLE_SIZE: 4,
  6382. /**
  6383. * Variable: HANDLE_FILLCOLOR
  6384. *
  6385. * Defines the color to be used for the handle fill color. Use 'none' for
  6386. * no color. Default is #00FF00 (green).
  6387. */
  6388. HANDLE_FILLCOLOR: '#00FF00',
  6389. /**
  6390. * Variable: HANDLE_STROKECOLOR
  6391. *
  6392. * Defines the color to be used for the handle stroke color. Use 'none' for
  6393. * no color. Default is black.
  6394. */
  6395. HANDLE_STROKECOLOR: 'black',
  6396. /**
  6397. * Variable: LABEL_HANDLE_FILLCOLOR
  6398. *
  6399. * Defines the color to be used for the label handle fill color. Use 'none'
  6400. * for no color. Default is yellow.
  6401. */
  6402. LABEL_HANDLE_FILLCOLOR: 'yellow',
  6403. /**
  6404. * Variable: CONNECT_HANDLE_FILLCOLOR
  6405. *
  6406. * Defines the color to be used for the connect handle fill color. Use
  6407. * 'none' for no color. Default is #0000FF (blue).
  6408. */
  6409. CONNECT_HANDLE_FILLCOLOR: '#0000FF',
  6410. /**
  6411. * Variable: LOCKED_HANDLE_FILLCOLOR
  6412. *
  6413. * Defines the color to be used for the locked handle fill color. Use
  6414. * 'none' for no color. Default is #FF0000 (red).
  6415. */
  6416. LOCKED_HANDLE_FILLCOLOR: '#FF0000',
  6417. /**
  6418. * Variable: OUTLINE_HANDLE_FILLCOLOR
  6419. *
  6420. * Defines the color to be used for the outline sizer fill color. Use
  6421. * 'none' for no color. Default is #00FFFF.
  6422. */
  6423. OUTLINE_HANDLE_FILLCOLOR: '#00FFFF',
  6424. /**
  6425. * Variable: OUTLINE_HANDLE_STROKECOLOR
  6426. *
  6427. * Defines the color to be used for the outline sizer stroke color. Use
  6428. * 'none' for no color. Default is #0033FF.
  6429. */
  6430. OUTLINE_HANDLE_STROKECOLOR: '#0033FF',
  6431. /**
  6432. * Variable: DEFAULT_FONTFAMILY
  6433. *
  6434. * Defines the default family for all fonts. Default is Arial,Helvetica.
  6435. */
  6436. DEFAULT_FONTFAMILY: 'Arial,Helvetica',
  6437. /**
  6438. * Variable: DEFAULT_FONTSIZE
  6439. *
  6440. * Defines the default size (in px). Default is 11.
  6441. */
  6442. DEFAULT_FONTSIZE: 11,
  6443. /**
  6444. * Variable: DEFAULT_TEXT_DIRECTION
  6445. *
  6446. * Defines the default value for the <STYLE_TEXT_DIRECTION> if no value is
  6447. * defined for it in the style. Default value is an empty string which means
  6448. * the default system setting is used and no direction is set.
  6449. */
  6450. DEFAULT_TEXT_DIRECTION: '',
  6451. /**
  6452. * Variable: LINE_HEIGHT
  6453. *
  6454. * Defines the default line height for text labels. Default is 1.2.
  6455. */
  6456. LINE_HEIGHT: 1.2,
  6457. /**
  6458. * Variable: WORD_WRAP
  6459. *
  6460. * Defines the CSS value for the word-wrap property. Default is "normal".
  6461. * Change this to "break-word" to allow long words to be able to be broken
  6462. * and wrap onto the next line.
  6463. */
  6464. WORD_WRAP: 'normal',
  6465. /**
  6466. * Variable: ABSOLUTE_LINE_HEIGHT
  6467. *
  6468. * Specifies if absolute line heights should be used (px) in CSS. Default
  6469. * is false. Set this to true for backwards compatibility.
  6470. */
  6471. ABSOLUTE_LINE_HEIGHT: false,
  6472. /**
  6473. * Variable: DEFAULT_FONTSTYLE
  6474. *
  6475. * Defines the default style for all fonts. Default is 0. This can be set
  6476. * to any combination of font styles as follows.
  6477. *
  6478. * (code)
  6479. * mxConstants.DEFAULT_FONTSTYLE = mxConstants.FONT_BOLD | mxConstants.FONT_ITALIC;
  6480. * (end)
  6481. */
  6482. DEFAULT_FONTSTYLE: 0,
  6483. /**
  6484. * Variable: DEFAULT_STARTSIZE
  6485. *
  6486. * Defines the default start size for swimlanes. Default is 40.
  6487. */
  6488. DEFAULT_STARTSIZE: 40,
  6489. /**
  6490. * Variable: DEFAULT_MARKERSIZE
  6491. *
  6492. * Defines the default size for all markers. Default is 6.
  6493. */
  6494. DEFAULT_MARKERSIZE: 6,
  6495. /**
  6496. * Variable: DEFAULT_IMAGESIZE
  6497. *
  6498. * Defines the default width and height for images used in the
  6499. * label shape. Default is 24.
  6500. */
  6501. DEFAULT_IMAGESIZE: 24,
  6502. /**
  6503. * Variable: ENTITY_SEGMENT
  6504. *
  6505. * Defines the length of the horizontal segment of an Entity Relation.
  6506. * This can be overridden using <mxConstants.STYLE_SEGMENT> style.
  6507. * Default is 30.
  6508. */
  6509. ENTITY_SEGMENT: 30,
  6510. /**
  6511. * Variable: RECTANGLE_ROUNDING_FACTOR
  6512. *
  6513. * Defines the rounding factor for rounded rectangles in percent between
  6514. * 0 and 1. Values should be smaller than 0.5. Default is 0.15.
  6515. */
  6516. RECTANGLE_ROUNDING_FACTOR: 0.15,
  6517. /**
  6518. * Variable: LINE_ARCSIZE
  6519. *
  6520. * Defines the size of the arcs for rounded edges. Default is 20.
  6521. */
  6522. LINE_ARCSIZE: 20,
  6523. /**
  6524. * Variable: ARROW_SPACING
  6525. *
  6526. * Defines the spacing between the arrow shape and its terminals. Default is 0.
  6527. */
  6528. ARROW_SPACING: 0,
  6529. /**
  6530. * Variable: ARROW_WIDTH
  6531. *
  6532. * Defines the width of the arrow shape. Default is 30.
  6533. */
  6534. ARROW_WIDTH: 30,
  6535. /**
  6536. * Variable: ARROW_SIZE
  6537. *
  6538. * Defines the size of the arrowhead in the arrow shape. Default is 30.
  6539. */
  6540. ARROW_SIZE: 30,
  6541. /**
  6542. * Variable: PAGE_FORMAT_A4_PORTRAIT
  6543. *
  6544. * Defines the rectangle for the A4 portrait page format. The dimensions
  6545. * of this page format are 826x1169 pixels.
  6546. */
  6547. PAGE_FORMAT_A4_PORTRAIT: new mxRectangle(0, 0, 827, 1169),
  6548. /**
  6549. * Variable: PAGE_FORMAT_A4_PORTRAIT
  6550. *
  6551. * Defines the rectangle for the A4 portrait page format. The dimensions
  6552. * of this page format are 826x1169 pixels.
  6553. */
  6554. PAGE_FORMAT_A4_LANDSCAPE: new mxRectangle(0, 0, 1169, 827),
  6555. /**
  6556. * Variable: PAGE_FORMAT_LETTER_PORTRAIT
  6557. *
  6558. * Defines the rectangle for the Letter portrait page format. The
  6559. * dimensions of this page format are 850x1100 pixels.
  6560. */
  6561. PAGE_FORMAT_LETTER_PORTRAIT: new mxRectangle(0, 0, 850, 1100),
  6562. /**
  6563. * Variable: PAGE_FORMAT_LETTER_PORTRAIT
  6564. *
  6565. * Defines the rectangle for the Letter portrait page format. The dimensions
  6566. * of this page format are 850x1100 pixels.
  6567. */
  6568. PAGE_FORMAT_LETTER_LANDSCAPE: new mxRectangle(0, 0, 1100, 850),
  6569. /**
  6570. * Variable: NONE
  6571. *
  6572. * Defines the value for none. Default is "none".
  6573. */
  6574. NONE: 'none',
  6575. /**
  6576. * Variable: STYLE_PERIMETER
  6577. *
  6578. * Defines the key for the perimeter style. This is a function that defines
  6579. * the perimeter around a particular shape. Possible values are the
  6580. * functions defined in <mxPerimeter>. Alternatively, the constants in this
  6581. * class that start with "PERIMETER_" may be used to access
  6582. * perimeter styles in <mxStyleRegistry>. Value is "perimeter".
  6583. */
  6584. STYLE_PERIMETER: 'perimeter',
  6585. /**
  6586. * Variable: STYLE_SOURCE_PORT
  6587. *
  6588. * Defines the ID of the cell that should be used for computing the
  6589. * perimeter point of the source for an edge. This allows for graphically
  6590. * connecting to a cell while keeping the actual terminal of the edge.
  6591. * Value is "sourcePort".
  6592. */
  6593. STYLE_SOURCE_PORT: 'sourcePort',
  6594. /**
  6595. * Variable: STYLE_TARGET_PORT
  6596. *
  6597. * Defines the ID of the cell that should be used for computing the
  6598. * perimeter point of the target for an edge. This allows for graphically
  6599. * connecting to a cell while keeping the actual terminal of the edge.
  6600. * Value is "targetPort".
  6601. */
  6602. STYLE_TARGET_PORT: 'targetPort',
  6603. /**
  6604. * Variable: STYLE_PORT_CONSTRAINT
  6605. *
  6606. * Defines the direction(s) that edges are allowed to connect to cells in.
  6607. * Possible values are "DIRECTION_NORTH, DIRECTION_SOUTH,
  6608. * DIRECTION_EAST" and "DIRECTION_WEST". Value is
  6609. * "portConstraint".
  6610. */
  6611. STYLE_PORT_CONSTRAINT: 'portConstraint',
  6612. /**
  6613. * Variable: STYLE_PORT_CONSTRAINT_ROTATION
  6614. *
  6615. * Define whether port constraint directions are rotated with vertex
  6616. * rotation. 0 (default) causes port constraints to remain absolute,
  6617. * relative to the graph, 1 causes the constraints to rotate with
  6618. * the vertex. Value is "portConstraintRotation".
  6619. */
  6620. STYLE_PORT_CONSTRAINT_ROTATION: 'portConstraintRotation',
  6621. /**
  6622. * Variable: STYLE_SOURCE_PORT_CONSTRAINT
  6623. *
  6624. * Defines the direction(s) that edges are allowed to connect to sources in.
  6625. * Possible values are "DIRECTION_NORTH, DIRECTION_SOUTH, DIRECTION_EAST"
  6626. * and "DIRECTION_WEST". Value is "sourcePortConstraint".
  6627. */
  6628. STYLE_SOURCE_PORT_CONSTRAINT: 'sourcePortConstraint',
  6629. /**
  6630. * Variable: STYLE_TARGET_PORT_CONSTRAINT
  6631. *
  6632. * Defines the direction(s) that edges are allowed to connect to targets in.
  6633. * Possible values are "DIRECTION_NORTH, DIRECTION_SOUTH, DIRECTION_EAST"
  6634. * and "DIRECTION_WEST". Value is "targetPortConstraint".
  6635. */
  6636. STYLE_TARGET_PORT_CONSTRAINT: 'targetPortConstraint',
  6637. /**
  6638. * Variable: STYLE_OPACITY
  6639. *
  6640. * Defines the key for the opacity style. The type of the value is
  6641. * numeric and the possible range is 0-100. Value is "opacity".
  6642. */
  6643. STYLE_OPACITY: 'opacity',
  6644. /**
  6645. * Variable: STYLE_FILL_OPACITY
  6646. *
  6647. * Defines the key for the fill opacity style. The type of the value is
  6648. * numeric and the possible range is 0-100. Value is "fillOpacity".
  6649. */
  6650. STYLE_FILL_OPACITY: 'fillOpacity',
  6651. /**
  6652. * Variable: STYLE_STROKE_OPACITY
  6653. *
  6654. * Defines the key for the stroke opacity style. The type of the value is
  6655. * numeric and the possible range is 0-100. Value is "strokeOpacity".
  6656. */
  6657. STYLE_STROKE_OPACITY: 'strokeOpacity',
  6658. /**
  6659. * Variable: STYLE_TEXT_OPACITY
  6660. *
  6661. * Defines the key for the text opacity style. The type of the value is
  6662. * numeric and the possible range is 0-100. Value is "textOpacity".
  6663. */
  6664. STYLE_TEXT_OPACITY: 'textOpacity',
  6665. /**
  6666. * Variable: STYLE_TEXT_DIRECTION
  6667. *
  6668. * Defines the key for the text direction style. Possible values are
  6669. * "TEXT_DIRECTION_DEFAULT, TEXT_DIRECTION_AUTO, TEXT_DIRECTION_LTR"
  6670. * and "TEXT_DIRECTION_RTL". Value is "textDirection".
  6671. * The default value for the style is defined in <DEFAULT_TEXT_DIRECTION>.
  6672. * It is used is no value is defined for this key in a given style. This is
  6673. * an experimental style that is currently ignored in the backends.
  6674. */
  6675. STYLE_TEXT_DIRECTION: 'textDirection',
  6676. /**
  6677. * Variable: STYLE_OVERFLOW
  6678. *
  6679. * Defines the key for the overflow style. Possible values are 'visible',
  6680. * 'hidden', 'fill' and 'width'. The default value is 'visible'. This value
  6681. * specifies how overlapping vertex labels are handled. A value of
  6682. * 'visible' will show the complete label. A value of 'hidden' will clip
  6683. * the label so that it does not overlap the vertex bounds. A value of
  6684. * 'fill' will use the vertex bounds and a value of 'width' will use the
  6685. * the vertex width for the label. See <mxGraph.isLabelClipped>. Note that
  6686. * the vertical alignment is ignored for overflow fill and for horizontal
  6687. * alignment, left should be used to avoid pixel offsets in Internet Explorer
  6688. * 11 and earlier or if foreignObjects are disabled. Value is "overflow".
  6689. */
  6690. STYLE_OVERFLOW: 'overflow',
  6691. /**
  6692. * Variable: STYLE_ORTHOGONAL
  6693. *
  6694. * Defines if the connection points on either end of the edge should be
  6695. * computed so that the edge is vertical or horizontal if possible and
  6696. * if the point is not at a fixed location. Default is false. This is
  6697. * used in <mxGraph.isOrthogonal>, which also returns true if the edgeStyle
  6698. * of the edge is an elbow or entity. Value is "orthogonal".
  6699. */
  6700. STYLE_ORTHOGONAL: 'orthogonal',
  6701. /**
  6702. * Variable: STYLE_EXIT_X
  6703. *
  6704. * Defines the key for the horizontal relative coordinate connection point
  6705. * of an edge with its source terminal. Value is "exitX".
  6706. */
  6707. STYLE_EXIT_X: 'exitX',
  6708. /**
  6709. * Variable: STYLE_EXIT_Y
  6710. *
  6711. * Defines the key for the vertical relative coordinate connection point
  6712. * of an edge with its source terminal. Value is "exitY".
  6713. */
  6714. STYLE_EXIT_Y: 'exitY',
  6715. /**
  6716. * Variable: STYLE_EXIT_DX
  6717. *
  6718. * Defines the key for the horizontal offset of the connection point
  6719. * of an edge with its source terminal. Value is "exitDx".
  6720. */
  6721. STYLE_EXIT_DX: 'exitDx',
  6722. /**
  6723. * Variable: STYLE_EXIT_DY
  6724. *
  6725. * Defines the key for the vertical offset of the connection point
  6726. * of an edge with its source terminal. Value is "exitDy".
  6727. */
  6728. STYLE_EXIT_DY: 'exitDy',
  6729. /**
  6730. * Variable: STYLE_EXIT_PERIMETER
  6731. *
  6732. * Defines if the perimeter should be used to find the exact entry point
  6733. * along the perimeter of the source. Possible values are 0 (false) and
  6734. * 1 (true). Default is 1 (true). Value is "exitPerimeter".
  6735. */
  6736. STYLE_EXIT_PERIMETER: 'exitPerimeter',
  6737. /**
  6738. * Variable: STYLE_ENTRY_X
  6739. *
  6740. * Defines the key for the horizontal relative coordinate connection point
  6741. * of an edge with its target terminal. Value is "entryX".
  6742. */
  6743. STYLE_ENTRY_X: 'entryX',
  6744. /**
  6745. * Variable: STYLE_ENTRY_Y
  6746. *
  6747. * Defines the key for the vertical relative coordinate connection point
  6748. * of an edge with its target terminal. Value is "entryY".
  6749. */
  6750. STYLE_ENTRY_Y: 'entryY',
  6751. /**
  6752. * Variable: STYLE_ENTRY_DX
  6753. *
  6754. * Defines the key for the horizontal offset of the connection point
  6755. * of an edge with its target terminal. Value is "entryDx".
  6756. */
  6757. STYLE_ENTRY_DX: 'entryDx',
  6758. /**
  6759. * Variable: STYLE_ENTRY_DY
  6760. *
  6761. * Defines the key for the vertical offset of the connection point
  6762. * of an edge with its target terminal. Value is "entryDy".
  6763. */
  6764. STYLE_ENTRY_DY: 'entryDy',
  6765. /**
  6766. * Variable: STYLE_ENTRY_PERIMETER
  6767. *
  6768. * Defines if the perimeter should be used to find the exact entry point
  6769. * along the perimeter of the target. Possible values are 0 (false) and
  6770. * 1 (true). Default is 1 (true). Value is "entryPerimeter".
  6771. */
  6772. STYLE_ENTRY_PERIMETER: 'entryPerimeter',
  6773. /**
  6774. * Variable: STYLE_WHITE_SPACE
  6775. *
  6776. * Defines the key for the white-space style. Possible values are 'nowrap'
  6777. * and 'wrap'. The default value is 'nowrap'. This value specifies how
  6778. * white-space inside a HTML vertex label should be handled. A value of
  6779. * 'nowrap' means the text will never wrap to the next line until a
  6780. * linefeed is encountered. A value of 'wrap' means text will wrap when
  6781. * necessary. This style is only used for HTML labels.
  6782. * See <mxGraph.isWrapping>. Value is "whiteSpace".
  6783. */
  6784. STYLE_WHITE_SPACE: 'whiteSpace',
  6785. /**
  6786. * Variable: STYLE_ROTATION
  6787. *
  6788. * Defines the key for the rotation style. The type of the value is
  6789. * numeric and the possible range is 0-360. Value is "rotation".
  6790. */
  6791. STYLE_ROTATION: 'rotation',
  6792. /**
  6793. * Variable: STYLE_FILLCOLOR
  6794. *
  6795. * Defines the key for the fill color. Possible values are all HTML color
  6796. * names or HEX codes, as well as special keywords such as 'swimlane,
  6797. * 'inherit' or 'indicated' to use the color code of a related cell or the
  6798. * indicator shape. Value is "fillColor".
  6799. */
  6800. STYLE_FILLCOLOR: 'fillColor',
  6801. /**
  6802. * Variable: STYLE_POINTER_EVENTS
  6803. *
  6804. * Specifies if pointer events should be fired on transparent backgrounds.
  6805. * This style is currently only supported in <mxRectangleShape>. Default
  6806. * is true. Value is "pointerEvents". This is typically set to
  6807. * false in groups where the transparent part should allow any underlying
  6808. * cells to be clickable.
  6809. */
  6810. STYLE_POINTER_EVENTS: 'pointerEvents',
  6811. /**
  6812. * Variable: STYLE_SWIMLANE_FILLCOLOR
  6813. *
  6814. * Defines the key for the fill color of the swimlane background. Possible
  6815. * values are all HTML color names or HEX codes. Default is no background.
  6816. * Value is "swimlaneFillColor".
  6817. */
  6818. STYLE_SWIMLANE_FILLCOLOR: 'swimlaneFillColor',
  6819. /**
  6820. * Variable: STYLE_MARGIN
  6821. *
  6822. * Defines the key for the margin between the ellipses in the double ellipse shape.
  6823. * Possible values are all positive numbers. Value is "margin".
  6824. */
  6825. STYLE_MARGIN: 'margin',
  6826. /**
  6827. * Variable: STYLE_GRADIENTCOLOR
  6828. *
  6829. * Defines the key for the gradient color. Possible values are all HTML color
  6830. * names or HEX codes, as well as special keywords such as 'swimlane,
  6831. * 'inherit' or 'indicated' to use the color code of a related cell or the
  6832. * indicator shape. This is ignored if no fill color is defined. Value is
  6833. * "gradientColor".
  6834. */
  6835. STYLE_GRADIENTCOLOR: 'gradientColor',
  6836. /**
  6837. * Variable: STYLE_GRADIENT_DIRECTION
  6838. *
  6839. * Defines the key for the gradient direction. Possible values are
  6840. * <DIRECTION_EAST>, <DIRECTION_WEST>, <DIRECTION_NORTH> and
  6841. * <DIRECTION_SOUTH>. Default is <DIRECTION_SOUTH>. Generally, and by
  6842. * default in mxGraph, gradient painting is done from the value of
  6843. * <STYLE_FILLCOLOR> to the value of <STYLE_GRADIENTCOLOR>. Taking the
  6844. * example of <DIRECTION_NORTH>, this means <STYLE_FILLCOLOR> color at the
  6845. * bottom of paint pattern and <STYLE_GRADIENTCOLOR> at top, with a
  6846. * gradient in-between. Value is "gradientDirection".
  6847. */
  6848. STYLE_GRADIENT_DIRECTION: 'gradientDirection',
  6849. /**
  6850. * Variable: STYLE_STROKECOLOR
  6851. *
  6852. * Defines the key for the strokeColor style. Possible values are all HTML
  6853. * color names or HEX codes, as well as special keywords such as 'swimlane,
  6854. * 'inherit', 'indicated' to use the color code of a related cell or the
  6855. * indicator shape or 'none' for no color. Value is "strokeColor".
  6856. */
  6857. STYLE_STROKECOLOR: 'strokeColor',
  6858. /**
  6859. * Variable: STYLE_SEPARATORCOLOR
  6860. *
  6861. * Defines the key for the separatorColor style. Possible values are all
  6862. * HTML color names or HEX codes. This style is only used for
  6863. * <SHAPE_SWIMLANE> shapes. Value is "separatorColor".
  6864. */
  6865. STYLE_SEPARATORCOLOR: 'separatorColor',
  6866. /**
  6867. * Variable: STYLE_STROKEWIDTH
  6868. *
  6869. * Defines the key for the strokeWidth style. The type of the value is
  6870. * numeric and the possible range is any non-negative value larger or equal
  6871. * to 1. The value defines the stroke width in pixels. Note: To hide a
  6872. * stroke use strokeColor none. Value is "strokeWidth".
  6873. */
  6874. STYLE_STROKEWIDTH: 'strokeWidth',
  6875. /**
  6876. * Variable: STYLE_ALIGN
  6877. *
  6878. * Defines the key for the align style. Possible values are <ALIGN_LEFT>,
  6879. * <ALIGN_CENTER> and <ALIGN_RIGHT>. This value defines how the lines of
  6880. * the label are horizontally aligned. <ALIGN_LEFT> mean label text lines
  6881. * are aligned to left of the label bounds, <ALIGN_RIGHT> to the right of
  6882. * the label bounds and <ALIGN_CENTER> means the center of the text lines
  6883. * are aligned in the center of the label bounds. Note this value doesn't
  6884. * affect the positioning of the overall label bounds relative to the
  6885. * vertex, to move the label bounds horizontally, use
  6886. * <STYLE_LABEL_POSITION>. Value is "align".
  6887. */
  6888. STYLE_ALIGN: 'align',
  6889. /**
  6890. * Variable: STYLE_VERTICAL_ALIGN
  6891. *
  6892. * Defines the key for the verticalAlign style. Possible values are
  6893. * <ALIGN_TOP>, <ALIGN_MIDDLE> and <ALIGN_BOTTOM>. This value defines how
  6894. * the lines of the label are vertically aligned. <ALIGN_TOP> means the
  6895. * topmost label text line is aligned against the top of the label bounds,
  6896. * <ALIGN_BOTTOM> means the bottom-most label text line is aligned against
  6897. * the bottom of the label bounds and <ALIGN_MIDDLE> means there is equal
  6898. * spacing between the topmost text label line and the top of the label
  6899. * bounds and the bottom-most text label line and the bottom of the label
  6900. * bounds. Note this value doesn't affect the positioning of the overall
  6901. * label bounds relative to the vertex, to move the label bounds
  6902. * vertically, use <STYLE_VERTICAL_LABEL_POSITION>. Value is "verticalAlign".
  6903. */
  6904. STYLE_VERTICAL_ALIGN: 'verticalAlign',
  6905. /**
  6906. * Variable: STYLE_LABEL_WIDTH
  6907. *
  6908. * Defines the key for the width of the label if the label position is not
  6909. * center. Value is "labelWidth".
  6910. */
  6911. STYLE_LABEL_WIDTH: 'labelWidth',
  6912. /**
  6913. * Variable: STYLE_LABEL_POSITION
  6914. *
  6915. * Defines the key for the horizontal label position of vertices. Possible
  6916. * values are <ALIGN_LEFT>, <ALIGN_CENTER> and <ALIGN_RIGHT>. Default is
  6917. * <ALIGN_CENTER>. The label align defines the position of the label
  6918. * relative to the cell. <ALIGN_LEFT> means the entire label bounds is
  6919. * placed completely just to the left of the vertex, <ALIGN_RIGHT> means
  6920. * adjust to the right and <ALIGN_CENTER> means the label bounds are
  6921. * vertically aligned with the bounds of the vertex. Note this value
  6922. * doesn't affect the positioning of label within the label bounds, to move
  6923. * the label horizontally within the label bounds, use <STYLE_ALIGN>.
  6924. * Value is "labelPosition".
  6925. */
  6926. STYLE_LABEL_POSITION: 'labelPosition',
  6927. /**
  6928. * Variable: STYLE_VERTICAL_LABEL_POSITION
  6929. *
  6930. * Defines the key for the vertical label position of vertices. Possible
  6931. * values are <ALIGN_TOP>, <ALIGN_BOTTOM> and <ALIGN_MIDDLE>. Default is
  6932. * <ALIGN_MIDDLE>. The label align defines the position of the label
  6933. * relative to the cell. <ALIGN_TOP> means the entire label bounds is
  6934. * placed completely just on the top of the vertex, <ALIGN_BOTTOM> means
  6935. * adjust on the bottom and <ALIGN_MIDDLE> means the label bounds are
  6936. * horizontally aligned with the bounds of the vertex. Note this value
  6937. * doesn't affect the positioning of label within the label bounds, to move
  6938. * the label vertically within the label bounds, use
  6939. * <STYLE_VERTICAL_ALIGN>. Value is "verticalLabelPosition".
  6940. */
  6941. STYLE_VERTICAL_LABEL_POSITION: 'verticalLabelPosition',
  6942. /**
  6943. * Variable: STYLE_IMAGE_ASPECT
  6944. *
  6945. * Defines the key for the image aspect style. Possible values are 0 (do
  6946. * not preserve aspect) or 1 (keep aspect). This is only used in
  6947. * <mxImageShape>. Default is 1. Value is "imageAspect".
  6948. */
  6949. STYLE_IMAGE_ASPECT: 'imageAspect',
  6950. /**
  6951. * Variable: STYLE_IMAGE_ALIGN
  6952. *
  6953. * Defines the key for the align style. Possible values are <ALIGN_LEFT>,
  6954. * <ALIGN_CENTER> and <ALIGN_RIGHT>. The value defines how any image in the
  6955. * vertex label is aligned horizontally within the label bounds of a
  6956. * <SHAPE_LABEL> shape. Value is "imageAlign".
  6957. */
  6958. STYLE_IMAGE_ALIGN: 'imageAlign',
  6959. /**
  6960. * Variable: STYLE_IMAGE_VERTICAL_ALIGN
  6961. *
  6962. * Defines the key for the verticalAlign style. Possible values are
  6963. * <ALIGN_TOP>, <ALIGN_MIDDLE> and <ALIGN_BOTTOM>. The value defines how
  6964. * any image in the vertex label is aligned vertically within the label
  6965. * bounds of a <SHAPE_LABEL> shape. Value is "imageVerticalAlign".
  6966. */
  6967. STYLE_IMAGE_VERTICAL_ALIGN: 'imageVerticalAlign',
  6968. /**
  6969. * Variable: STYLE_GLASS
  6970. *
  6971. * Defines the key for the glass style. Possible values are 0 (disabled) and
  6972. * 1(enabled). The default value is 0. This is used in <mxLabel>. Value is
  6973. * "glass".
  6974. */
  6975. STYLE_GLASS: 'glass',
  6976. /**
  6977. * Variable: STYLE_IMAGE
  6978. *
  6979. * Defines the key for the image style. Possible values are any image URL,
  6980. * the type of the value is String. This is the path to the image that is
  6981. * to be displayed within the label of a vertex. Data URLs should use the
  6982. * following format: data:image/png,xyz where xyz is the base64 encoded
  6983. * data (without the "base64"-prefix). Note that Data URLs are only
  6984. * supported in modern browsers. Value is "image".
  6985. */
  6986. STYLE_IMAGE: 'image',
  6987. /**
  6988. * Variable: STYLE_IMAGE_WIDTH
  6989. *
  6990. * Defines the key for the imageWidth style. The type of this value is
  6991. * int, the value is the image width in pixels and must be greater than 0.
  6992. * Value is "imageWidth".
  6993. */
  6994. STYLE_IMAGE_WIDTH: 'imageWidth',
  6995. /**
  6996. * Variable: STYLE_IMAGE_HEIGHT
  6997. *
  6998. * Defines the key for the imageHeight style. The type of this value is
  6999. * int, the value is the image height in pixels and must be greater than 0.
  7000. * Value is "imageHeight".
  7001. */
  7002. STYLE_IMAGE_HEIGHT: 'imageHeight',
  7003. /**
  7004. * Variable: STYLE_IMAGE_BACKGROUND
  7005. *
  7006. * Defines the key for the image background color. This style is only used
  7007. * in <mxImageShape>. Possible values are all HTML color names or HEX
  7008. * codes. Value is "imageBackground".
  7009. */
  7010. STYLE_IMAGE_BACKGROUND: 'imageBackground',
  7011. /**
  7012. * Variable: STYLE_IMAGE_BORDER
  7013. *
  7014. * Defines the key for the image border color. This style is only used in
  7015. * <mxImageShape>. Possible values are all HTML color names or HEX codes.
  7016. * Value is "imageBorder".
  7017. */
  7018. STYLE_IMAGE_BORDER: 'imageBorder',
  7019. /**
  7020. * Variable: STYLE_FLIPH
  7021. *
  7022. * Defines the key for the horizontal image flip. This style is only used
  7023. * in <mxImageShape>. Possible values are 0 and 1. Default is 0. Value is
  7024. * "flipH".
  7025. */
  7026. STYLE_FLIPH: 'flipH',
  7027. /**
  7028. * Variable: STYLE_FLIPV
  7029. *
  7030. * Defines the key for the vertical flip. Possible values are 0 and 1.
  7031. * Default is 0. Value is "flipV".
  7032. */
  7033. STYLE_FLIPV: 'flipV',
  7034. /**
  7035. * Variable: STYLE_NOLABEL
  7036. *
  7037. * Defines the key for the noLabel style. If this is true then no label is
  7038. * visible for a given cell. Possible values are true or false (1 or 0).
  7039. * Default is false. Value is "noLabel".
  7040. */
  7041. STYLE_NOLABEL: 'noLabel',
  7042. /**
  7043. * Variable: STYLE_NOEDGESTYLE
  7044. *
  7045. * Defines the key for the noEdgeStyle style. If this is true then no edge
  7046. * style is applied for a given edge. Possible values are true or false
  7047. * (1 or 0). Default is false. Value is "noEdgeStyle".
  7048. */
  7049. STYLE_NOEDGESTYLE: 'noEdgeStyle',
  7050. /**
  7051. * Variable: STYLE_LABEL_BACKGROUNDCOLOR
  7052. *
  7053. * Defines the key for the label background color. Possible values are all
  7054. * HTML color names or HEX codes. Value is "labelBackgroundColor".
  7055. */
  7056. STYLE_LABEL_BACKGROUNDCOLOR: 'labelBackgroundColor',
  7057. /**
  7058. * Variable: STYLE_LABEL_BORDERCOLOR
  7059. *
  7060. * Defines the key for the label border color. Possible values are all
  7061. * HTML color names or HEX codes. Value is "labelBorderColor".
  7062. */
  7063. STYLE_LABEL_BORDERCOLOR: 'labelBorderColor',
  7064. /**
  7065. * Variable: STYLE_LABEL_PADDING
  7066. *
  7067. * Defines the key for the label padding, ie. the space between the label
  7068. * border and the label. Value is "labelPadding".
  7069. */
  7070. STYLE_LABEL_PADDING: 'labelPadding',
  7071. /**
  7072. * Variable: STYLE_INDICATOR_SHAPE
  7073. *
  7074. * Defines the key for the indicator shape used within an <mxLabel>.
  7075. * Possible values are all SHAPE_* constants or the names of any new
  7076. * shapes. The indicatorShape has precedence over the indicatorImage.
  7077. * Value is "indicatorShape".
  7078. */
  7079. STYLE_INDICATOR_SHAPE: 'indicatorShape',
  7080. /**
  7081. * Variable: STYLE_INDICATOR_IMAGE
  7082. *
  7083. * Defines the key for the indicator image used within an <mxLabel>.
  7084. * Possible values are all image URLs. The indicatorShape has
  7085. * precedence over the indicatorImage. Value is "indicatorImage".
  7086. */
  7087. STYLE_INDICATOR_IMAGE: 'indicatorImage',
  7088. /**
  7089. * Variable: STYLE_INDICATOR_COLOR
  7090. *
  7091. * Defines the key for the indicatorColor style. Possible values are all
  7092. * HTML color names or HEX codes, as well as the special 'swimlane' keyword
  7093. * to refer to the color of the parent swimlane if one exists. Value is
  7094. * "indicatorColor".
  7095. */
  7096. STYLE_INDICATOR_COLOR: 'indicatorColor',
  7097. /**
  7098. * Variable: STYLE_INDICATOR_STROKECOLOR
  7099. *
  7100. * Defines the key for the indicator stroke color in <mxLabel>.
  7101. * Possible values are all color codes. Value is "indicatorStrokeColor".
  7102. */
  7103. STYLE_INDICATOR_STROKECOLOR: 'indicatorStrokeColor',
  7104. /**
  7105. * Variable: STYLE_INDICATOR_GRADIENTCOLOR
  7106. *
  7107. * Defines the key for the indicatorGradientColor style. Possible values
  7108. * are all HTML color names or HEX codes. This style is only supported in
  7109. * <SHAPE_LABEL> shapes. Value is "indicatorGradientColor".
  7110. */
  7111. STYLE_INDICATOR_GRADIENTCOLOR: 'indicatorGradientColor',
  7112. /**
  7113. * Variable: STYLE_INDICATOR_SPACING
  7114. *
  7115. * The defines the key for the spacing between the label and the
  7116. * indicator in <mxLabel>. Possible values are in pixels. Value is
  7117. * "indicatorSpacing".
  7118. */
  7119. STYLE_INDICATOR_SPACING: 'indicatorSpacing',
  7120. /**
  7121. * Variable: STYLE_INDICATOR_WIDTH
  7122. *
  7123. * Defines the key for the indicator width. Possible values start at 0 (in
  7124. * pixels). Value is "indicatorWidth".
  7125. */
  7126. STYLE_INDICATOR_WIDTH: 'indicatorWidth',
  7127. /**
  7128. * Variable: STYLE_INDICATOR_HEIGHT
  7129. *
  7130. * Defines the key for the indicator height. Possible values start at 0 (in
  7131. * pixels). Value is "indicatorHeight".
  7132. */
  7133. STYLE_INDICATOR_HEIGHT: 'indicatorHeight',
  7134. /**
  7135. * Variable: STYLE_INDICATOR_DIRECTION
  7136. *
  7137. * Defines the key for the indicatorDirection style. The direction style is
  7138. * used to specify the direction of certain shapes (eg. <mxTriangle>).
  7139. * Possible values are <DIRECTION_EAST> (default), <DIRECTION_WEST>,
  7140. * <DIRECTION_NORTH> and <DIRECTION_SOUTH>. Value is "indicatorDirection".
  7141. */
  7142. STYLE_INDICATOR_DIRECTION: 'indicatorDirection',
  7143. /**
  7144. * Variable: STYLE_SHADOW
  7145. *
  7146. * Defines the key for the shadow style. The type of the value is Boolean.
  7147. * Value is "shadow".
  7148. */
  7149. STYLE_SHADOW: 'shadow',
  7150. /**
  7151. * Variable: STYLE_SEGMENT
  7152. *
  7153. * Defines the key for the segment style. The type of this value is float
  7154. * and the value represents the size of the horizontal segment of the
  7155. * entity relation style. Default is ENTITY_SEGMENT. Value is "segment".
  7156. */
  7157. STYLE_SEGMENT: 'segment',
  7158. /**
  7159. * Variable: STYLE_ENDARROW
  7160. *
  7161. * Defines the key for the end arrow marker. Possible values are all
  7162. * constants with an ARROW-prefix. This is only used in <mxConnector>.
  7163. * Value is "endArrow".
  7164. *
  7165. * Example:
  7166. * (code)
  7167. * style[mxConstants.STYLE_ENDARROW] = mxConstants.ARROW_CLASSIC;
  7168. * (end)
  7169. */
  7170. STYLE_ENDARROW: 'endArrow',
  7171. /**
  7172. * Variable: STYLE_STARTARROW
  7173. *
  7174. * Defines the key for the start arrow marker. Possible values are all
  7175. * constants with an ARROW-prefix. This is only used in <mxConnector>.
  7176. * See <STYLE_ENDARROW>. Value is "startArrow".
  7177. */
  7178. STYLE_STARTARROW: 'startArrow',
  7179. /**
  7180. * Variable: STYLE_ENDSIZE
  7181. *
  7182. * Defines the key for the endSize style. The type of this value is numeric
  7183. * and the value represents the size of the end marker in pixels. Value is
  7184. * "endSize".
  7185. */
  7186. STYLE_ENDSIZE: 'endSize',
  7187. /**
  7188. * Variable: STYLE_STARTSIZE
  7189. *
  7190. * Defines the key for the startSize style. The type of this value is
  7191. * numeric and the value represents the size of the start marker or the
  7192. * size of the swimlane title region depending on the shape it is used for.
  7193. * Value is "startSize".
  7194. */
  7195. STYLE_STARTSIZE: 'startSize',
  7196. /**
  7197. * Variable: STYLE_SWIMLANE_LINE
  7198. *
  7199. * Defines the key for the swimlaneLine style. This style specifies whether
  7200. * the line between the title regio of a swimlane should be visible. Use 0
  7201. * for hidden or 1 (default) for visible. Value is "swimlaneLine".
  7202. */
  7203. STYLE_SWIMLANE_LINE: 'swimlaneLine',
  7204. /**
  7205. * Variable: STYLE_ENDFILL
  7206. *
  7207. * Defines the key for the endFill style. Use 0 for no fill or 1 (default)
  7208. * for fill. (This style is only exported via <mxImageExport>.) Value is
  7209. * "endFill".
  7210. */
  7211. STYLE_ENDFILL: 'endFill',
  7212. /**
  7213. * Variable: STYLE_STARTFILL
  7214. *
  7215. * Defines the key for the startFill style. Use 0 for no fill or 1 (default)
  7216. * for fill. (This style is only exported via <mxImageExport>.) Value is
  7217. * "startFill".
  7218. */
  7219. STYLE_STARTFILL: 'startFill',
  7220. /**
  7221. * Variable: STYLE_DASHED
  7222. *
  7223. * Defines the key for the dashed style. Use 0 (default) for non-dashed or 1
  7224. * for dashed. Value is "dashed".
  7225. */
  7226. STYLE_DASHED: 'dashed',
  7227. /**
  7228. * Defines the key for the dashed pattern style in SVG and image exports.
  7229. * The type of this value is a space separated list of numbers that specify
  7230. * a custom-defined dash pattern. Dash styles are defined in terms of the
  7231. * length of the dash (the drawn part of the stroke) and the length of the
  7232. * space between the dashes. The lengths are relative to the line width: a
  7233. * length of "1" is equal to the line width. VML ignores this style and
  7234. * uses dashStyle instead as defined in the VML specification. This style
  7235. * is only used in the <mxConnector> shape. Value is "dashPattern".
  7236. */
  7237. STYLE_DASH_PATTERN: 'dashPattern',
  7238. /**
  7239. * Variable: STYLE_FIX_DASH
  7240. *
  7241. * Defines the key for the fixDash style. Use 0 (default) for dash patterns
  7242. * that depend on the linewidth and 1 for dash patterns that ignore the
  7243. * line width. Value is "fixDash".
  7244. */
  7245. STYLE_FIX_DASH: 'fixDash',
  7246. /**
  7247. * Variable: STYLE_ROUNDED
  7248. *
  7249. * Defines the key for the rounded style. The type of this value is
  7250. * Boolean. For edges this determines whether or not joins between edges
  7251. * segments are smoothed to a rounded finish. For vertices that have the
  7252. * rectangle shape, this determines whether or not the rectangle is
  7253. * rounded. Use 0 (default) for non-rounded or 1 for rounded. Value is
  7254. * "rounded".
  7255. */
  7256. STYLE_ROUNDED: 'rounded',
  7257. /**
  7258. * Variable: STYLE_CURVED
  7259. *
  7260. * Defines the key for the curved style. The type of this value is
  7261. * Boolean. It is only applicable for connector shapes. Use 0 (default)
  7262. * for non-curved or 1 for curved. Value is "curved".
  7263. */
  7264. STYLE_CURVED: 'curved',
  7265. /**
  7266. * Variable: STYLE_ARCSIZE
  7267. *
  7268. * Defines the rounding factor for a rounded rectangle in percent (without
  7269. * the percent sign). Possible values are between 0 and 100. If this value
  7270. * is not specified then RECTANGLE_ROUNDING_FACTOR * 100 is used. For
  7271. * edges, this defines the absolute size of rounded corners in pixels. If
  7272. * this values is not specified then LINE_ARCSIZE is used.
  7273. * (This style is only exported via <mxImageExport>.) Value is "arcSize".
  7274. */
  7275. STYLE_ARCSIZE: 'arcSize',
  7276. /**
  7277. * Variable: STYLE_ABSOLUTE_ARCSIZE
  7278. *
  7279. * Defines the key for the absolute arc size style. This specifies if
  7280. * arcSize for rectangles is abolute or relative. Possible values are 1
  7281. * and 0 (default). Value is "absoluteArcSize".
  7282. */
  7283. STYLE_ABSOLUTE_ARCSIZE: 'absoluteArcSize',
  7284. /**
  7285. * Variable: STYLE_SOURCE_PERIMETER_SPACING
  7286. *
  7287. * Defines the key for the source perimeter spacing. The type of this value
  7288. * is numeric. This is the distance between the source connection point of
  7289. * an edge and the perimeter of the source vertex in pixels. This style
  7290. * only applies to edges. Value is "sourcePerimeterSpacing".
  7291. */
  7292. STYLE_SOURCE_PERIMETER_SPACING: 'sourcePerimeterSpacing',
  7293. /**
  7294. * Variable: STYLE_TARGET_PERIMETER_SPACING
  7295. *
  7296. * Defines the key for the target perimeter spacing. The type of this value
  7297. * is numeric. This is the distance between the target connection point of
  7298. * an edge and the perimeter of the target vertex in pixels. This style
  7299. * only applies to edges. Value is "targetPerimeterSpacing".
  7300. */
  7301. STYLE_TARGET_PERIMETER_SPACING: 'targetPerimeterSpacing',
  7302. /**
  7303. * Variable: STYLE_PERIMETER_SPACING
  7304. *
  7305. * Defines the key for the perimeter spacing. This is the distance between
  7306. * the connection point and the perimeter in pixels. When used in a vertex
  7307. * style, this applies to all incoming edges to floating ports (edges that
  7308. * terminate on the perimeter of the vertex). When used in an edge style,
  7309. * this spacing applies to the source and target separately, if they
  7310. * terminate in floating ports (on the perimeter of the vertex). Value is
  7311. * "perimeterSpacing".
  7312. */
  7313. STYLE_PERIMETER_SPACING: 'perimeterSpacing',
  7314. /**
  7315. * Variable: STYLE_SPACING
  7316. *
  7317. * Defines the key for the spacing. The value represents the spacing, in
  7318. * pixels, added to each side of a label in a vertex (style applies to
  7319. * vertices only). Value is "spacing".
  7320. */
  7321. STYLE_SPACING: 'spacing',
  7322. /**
  7323. * Variable: STYLE_SPACING_TOP
  7324. *
  7325. * Defines the key for the spacingTop style. The value represents the
  7326. * spacing, in pixels, added to the top side of a label in a vertex (style
  7327. * applies to vertices only). Value is "spacingTop".
  7328. */
  7329. STYLE_SPACING_TOP: 'spacingTop',
  7330. /**
  7331. * Variable: STYLE_SPACING_LEFT
  7332. *
  7333. * Defines the key for the spacingLeft style. The value represents the
  7334. * spacing, in pixels, added to the left side of a label in a vertex (style
  7335. * applies to vertices only). Value is "spacingLeft".
  7336. */
  7337. STYLE_SPACING_LEFT: 'spacingLeft',
  7338. /**
  7339. * Variable: STYLE_SPACING_BOTTOM
  7340. *
  7341. * Defines the key for the spacingBottom style The value represents the
  7342. * spacing, in pixels, added to the bottom side of a label in a vertex
  7343. * (style applies to vertices only). Value is "spacingBottom".
  7344. */
  7345. STYLE_SPACING_BOTTOM: 'spacingBottom',
  7346. /**
  7347. * Variable: STYLE_SPACING_RIGHT
  7348. *
  7349. * Defines the key for the spacingRight style The value represents the
  7350. * spacing, in pixels, added to the right side of a label in a vertex (style
  7351. * applies to vertices only). Value is "spacingRight".
  7352. */
  7353. STYLE_SPACING_RIGHT: 'spacingRight',
  7354. /**
  7355. * Variable: STYLE_HORIZONTAL
  7356. *
  7357. * Defines the key for the horizontal style. Possible values are
  7358. * true or false. This value only applies to vertices. If the <STYLE_SHAPE>
  7359. * is "SHAPE_SWIMLANE" a value of false indicates that the
  7360. * swimlane should be drawn vertically, true indicates to draw it
  7361. * horizontally. If the shape style does not indicate that this vertex is a
  7362. * swimlane, this value affects only whether the label is drawn
  7363. * horizontally or vertically. Value is "horizontal".
  7364. */
  7365. STYLE_HORIZONTAL: 'horizontal',
  7366. /**
  7367. * Variable: STYLE_DIRECTION
  7368. *
  7369. * Defines the key for the direction style. The direction style is used
  7370. * to specify the direction of certain shapes (eg. <mxTriangle>).
  7371. * Possible values are <DIRECTION_EAST> (default), <DIRECTION_WEST>,
  7372. * <DIRECTION_NORTH> and <DIRECTION_SOUTH>. Value is "direction".
  7373. */
  7374. STYLE_DIRECTION: 'direction',
  7375. /**
  7376. * Variable: STYLE_ANCHOR_POINT_DIRECTION
  7377. *
  7378. * Defines the key for the anchorPointDirection style. The defines if the
  7379. * direction style should be taken into account when computing the fixed
  7380. * point location for connected edges. Default is 1 (yes). Set this to 0
  7381. * to ignore the direction style for fixed connection points. Value is
  7382. * "anchorPointDirection".
  7383. */
  7384. STYLE_ANCHOR_POINT_DIRECTION: 'anchorPointDirection',
  7385. /**
  7386. * Variable: STYLE_ELBOW
  7387. *
  7388. * Defines the key for the elbow style. Possible values are
  7389. * <ELBOW_HORIZONTAL> and <ELBOW_VERTICAL>. Default is <ELBOW_HORIZONTAL>.
  7390. * This defines how the three segment orthogonal edge style leaves its
  7391. * terminal vertices. The vertical style leaves the terminal vertices at
  7392. * the top and bottom sides. Value is "elbow".
  7393. */
  7394. STYLE_ELBOW: 'elbow',
  7395. /**
  7396. * Variable: STYLE_FONTCOLOR
  7397. *
  7398. * Defines the key for the fontColor style. Possible values are all HTML
  7399. * color names or HEX codes. Value is "fontColor".
  7400. */
  7401. STYLE_FONTCOLOR: 'fontColor',
  7402. /**
  7403. * Variable: STYLE_FONTFAMILY
  7404. *
  7405. * Defines the key for the fontFamily style. Possible values are names such
  7406. * as Arial; Dialog; Verdana; Times New Roman. The value is of type String.
  7407. * Value is fontFamily.
  7408. */
  7409. STYLE_FONTFAMILY: 'fontFamily',
  7410. /**
  7411. * Variable: STYLE_FONTSIZE
  7412. *
  7413. * Defines the key for the fontSize style (in px). The type of the value
  7414. * is int. Value is "fontSize".
  7415. */
  7416. STYLE_FONTSIZE: 'fontSize',
  7417. /**
  7418. * Variable: STYLE_FONTSTYLE
  7419. *
  7420. * Defines the key for the fontStyle style. Values may be any logical AND
  7421. * (sum) of <FONT_BOLD>, <FONT_ITALIC> and <FONT_UNDERLINE>.
  7422. * The type of the value is int. Value is "fontStyle".
  7423. */
  7424. STYLE_FONTSTYLE: 'fontStyle',
  7425. /**
  7426. * Variable: STYLE_ASPECT
  7427. *
  7428. * Defines the key for the aspect style. Possible values are empty or fixed.
  7429. * If fixed is used then the aspect ratio of the cell will be maintained
  7430. * when resizing. Default is empty. Value is "aspect".
  7431. */
  7432. STYLE_ASPECT: 'aspect',
  7433. /**
  7434. * Variable: STYLE_AUTOSIZE
  7435. *
  7436. * Defines the key for the autosize style. This specifies if a cell should be
  7437. * resized automatically if the value has changed. Possible values are 0 or 1.
  7438. * Default is 0. See <mxGraph.isAutoSizeCell>. This is normally combined with
  7439. * <STYLE_RESIZABLE> to disable manual sizing. Value is "autosize".
  7440. */
  7441. STYLE_AUTOSIZE: 'autosize',
  7442. /**
  7443. * Variable: STYLE_FOLDABLE
  7444. *
  7445. * Defines the key for the foldable style. This specifies if a cell is foldable
  7446. * using a folding icon. Possible values are 0 or 1. Default is 1. See
  7447. * <mxGraph.isCellFoldable>. Value is "foldable".
  7448. */
  7449. STYLE_FOLDABLE: 'foldable',
  7450. /**
  7451. * Variable: STYLE_EDITABLE
  7452. *
  7453. * Defines the key for the editable style. This specifies if the value of
  7454. * a cell can be edited using the in-place editor. Possible values are 0 or
  7455. * 1. Default is 1. See <mxGraph.isCellEditable>. Value is "editable".
  7456. */
  7457. STYLE_EDITABLE: 'editable',
  7458. /**
  7459. * Variable: STYLE_BACKGROUND_OUTLINE
  7460. *
  7461. * Defines the key for the backgroundOutline style. This specifies if a
  7462. * only the background of a cell should be painted when it is highlighted.
  7463. * Possible values are 0 or 1. Default is 0. Value is "backgroundOutline".
  7464. */
  7465. STYLE_BACKGROUND_OUTLINE: 'backgroundOutline',
  7466. /**
  7467. * Variable: STYLE_BENDABLE
  7468. *
  7469. * Defines the key for the bendable style. This specifies if the control
  7470. * points of an edge can be moved. Possible values are 0 or 1. Default is
  7471. * 1. See <mxGraph.isCellBendable>. Value is "bendable".
  7472. */
  7473. STYLE_BENDABLE: 'bendable',
  7474. /**
  7475. * Variable: STYLE_MOVABLE
  7476. *
  7477. * Defines the key for the movable style. This specifies if a cell can
  7478. * be moved. Possible values are 0 or 1. Default is 1. See
  7479. * <mxGraph.isCellMovable>. Value is "movable".
  7480. */
  7481. STYLE_MOVABLE: 'movable',
  7482. /**
  7483. * Variable: STYLE_RESIZABLE
  7484. *
  7485. * Defines the key for the resizable style. This specifies if a cell can
  7486. * be resized. Possible values are 0 or 1. Default is 1. See
  7487. * <mxGraph.isCellResizable>. Value is "resizable".
  7488. */
  7489. STYLE_RESIZABLE: 'resizable',
  7490. /**
  7491. * Variable: STYLE_RESIZE_WIDTH
  7492. *
  7493. * Defines the key for the resizeWidth style. This specifies if a cell's
  7494. * width is resized if the parent is resized. If this is 1 then the width
  7495. * will be resized even if the cell's geometry is relative. If this is 0
  7496. * then the cell's width will not be resized. Default is not defined. Value
  7497. * is "resizeWidth".
  7498. */
  7499. STYLE_RESIZE_WIDTH: 'resizeWidth',
  7500. /**
  7501. * Variable: STYLE_RESIZE_WIDTH
  7502. *
  7503. * Defines the key for the resizeHeight style. This specifies if a cell's
  7504. * height if resize if the parent is resized. If this is 1 then the height
  7505. * will be resized even if the cell's geometry is relative. If this is 0
  7506. * then the cell's height will not be resized. Default is not defined. Value
  7507. * is "resizeHeight".
  7508. */
  7509. STYLE_RESIZE_HEIGHT: 'resizeHeight',
  7510. /**
  7511. * Variable: STYLE_ROTATABLE
  7512. *
  7513. * Defines the key for the rotatable style. This specifies if a cell can
  7514. * be rotated. Possible values are 0 or 1. Default is 1. See
  7515. * <mxGraph.isCellRotatable>. Value is "rotatable".
  7516. */
  7517. STYLE_ROTATABLE: 'rotatable',
  7518. /**
  7519. * Variable: STYLE_CLONEABLE
  7520. *
  7521. * Defines the key for the cloneable style. This specifies if a cell can
  7522. * be cloned. Possible values are 0 or 1. Default is 1. See
  7523. * <mxGraph.isCellCloneable>. Value is "cloneable".
  7524. */
  7525. STYLE_CLONEABLE: 'cloneable',
  7526. /**
  7527. * Variable: STYLE_DELETABLE
  7528. *
  7529. * Defines the key for the deletable style. This specifies if a cell can be
  7530. * deleted. Possible values are 0 or 1. Default is 1. See
  7531. * <mxGraph.isCellDeletable>. Value is "deletable".
  7532. */
  7533. STYLE_DELETABLE: 'deletable',
  7534. /**
  7535. * Variable: STYLE_SHAPE
  7536. *
  7537. * Defines the key for the shape. Possible values are all constants with
  7538. * a SHAPE-prefix or any newly defined shape names. Value is "shape".
  7539. */
  7540. STYLE_SHAPE: 'shape',
  7541. /**
  7542. * Variable: STYLE_EDGE
  7543. *
  7544. * Defines the key for the edge style. Possible values are the functions
  7545. * defined in <mxEdgeStyle>. Value is "edgeStyle".
  7546. */
  7547. STYLE_EDGE: 'edgeStyle',
  7548. /**
  7549. * Variable: STYLE_JETTY_SIZE
  7550. *
  7551. * Defines the key for the jetty size in <mxEdgeStyle.OrthConnector>.
  7552. * Default is 10. Possible values are all numeric values or "auto".
  7553. * Jetty size is the minimum length of the orthogonal segment before
  7554. * it attaches to a shape.
  7555. * Value is "jettySize".
  7556. */
  7557. STYLE_JETTY_SIZE: 'jettySize',
  7558. /**
  7559. * Variable: STYLE_SOURCE_JETTY_SIZE
  7560. *
  7561. * Defines the key for the jetty size in <mxEdgeStyle.OrthConnector>.
  7562. * Default is 10. Possible values are numeric values or "auto". This has
  7563. * precedence over <STYLE_JETTY_SIZE>. Value is "sourceJettySize".
  7564. */
  7565. STYLE_SOURCE_JETTY_SIZE: 'sourceJettySize',
  7566. /**
  7567. * Variable: targetJettySize
  7568. *
  7569. * Defines the key for the jetty size in <mxEdgeStyle.OrthConnector>.
  7570. * Default is 10. Possible values are numeric values or "auto". This has
  7571. * precedence over <STYLE_JETTY_SIZE>. Value is "targetJettySize".
  7572. */
  7573. STYLE_TARGET_JETTY_SIZE: 'targetJettySize',
  7574. /**
  7575. * Variable: STYLE_LOOP
  7576. *
  7577. * Defines the key for the loop style. Possible values are the functions
  7578. * defined in <mxEdgeStyle>. Value is "loopStyle". Default is
  7579. * <mxGraph.defaultLoopStylean>.
  7580. */
  7581. STYLE_LOOP: 'loopStyle',
  7582. /**
  7583. * Variable: STYLE_ORTHOGONAL_LOOP
  7584. *
  7585. * Defines the key for the orthogonal loop style. Possible values are 0 and
  7586. * 1. Default is 0. Value is "orthogonalLoop". Use this style to specify
  7587. * if loops with no waypoints and defined anchor points should be routed
  7588. * using <STYLE_LOOP> or not routed.
  7589. */
  7590. STYLE_ORTHOGONAL_LOOP: 'orthogonalLoop',
  7591. /**
  7592. * Variable: STYLE_ROUTING_CENTER_X
  7593. *
  7594. * Defines the key for the horizontal routing center. Possible values are
  7595. * between -0.5 and 0.5. This is the relative offset from the center used
  7596. * for connecting edges. The type of this value is numeric. Value is
  7597. * "routingCenterX".
  7598. */
  7599. STYLE_ROUTING_CENTER_X: 'routingCenterX',
  7600. /**
  7601. * Variable: STYLE_ROUTING_CENTER_Y
  7602. *
  7603. * Defines the key for the vertical routing center. Possible values are
  7604. * between -0.5 and 0.5. This is the relative offset from the center used
  7605. * for connecting edges. The type of this value is numeric. Value is
  7606. * "routingCenterY".
  7607. */
  7608. STYLE_ROUTING_CENTER_Y: 'routingCenterY',
  7609. /**
  7610. * Variable: FONT_BOLD
  7611. *
  7612. * Constant for bold fonts. Default is 1.
  7613. */
  7614. FONT_BOLD: 1,
  7615. /**
  7616. * Variable: FONT_ITALIC
  7617. *
  7618. * Constant for italic fonts. Default is 2.
  7619. */
  7620. FONT_ITALIC: 2,
  7621. /**
  7622. * Variable: FONT_UNDERLINE
  7623. *
  7624. * Constant for underlined fonts. Default is 4.
  7625. */
  7626. FONT_UNDERLINE: 4,
  7627. /**
  7628. * Variable: FONT_STRIKETHROUGH
  7629. *
  7630. * Constant for strikthrough fonts. Default is 8.
  7631. */
  7632. FONT_STRIKETHROUGH: 8,
  7633. /**
  7634. * Variable: SHAPE_RECTANGLE
  7635. *
  7636. * Name under which <mxRectangleShape> is registered in <mxCellRenderer>.
  7637. * Default is rectangle.
  7638. */
  7639. SHAPE_RECTANGLE: 'rectangle',
  7640. /**
  7641. * Variable: SHAPE_ELLIPSE
  7642. *
  7643. * Name under which <mxEllipse> is registered in <mxCellRenderer>.
  7644. * Default is ellipse.
  7645. */
  7646. SHAPE_ELLIPSE: 'ellipse',
  7647. /**
  7648. * Variable: SHAPE_DOUBLE_ELLIPSE
  7649. *
  7650. * Name under which <mxDoubleEllipse> is registered in <mxCellRenderer>.
  7651. * Default is doubleEllipse.
  7652. */
  7653. SHAPE_DOUBLE_ELLIPSE: 'doubleEllipse',
  7654. /**
  7655. * Variable: SHAPE_RHOMBUS
  7656. *
  7657. * Name under which <mxRhombus> is registered in <mxCellRenderer>.
  7658. * Default is rhombus.
  7659. */
  7660. SHAPE_RHOMBUS: 'rhombus',
  7661. /**
  7662. * Variable: SHAPE_LINE
  7663. *
  7664. * Name under which <mxLine> is registered in <mxCellRenderer>.
  7665. * Default is line.
  7666. */
  7667. SHAPE_LINE: 'line',
  7668. /**
  7669. * Variable: SHAPE_IMAGE
  7670. *
  7671. * Name under which <mxImageShape> is registered in <mxCellRenderer>.
  7672. * Default is image.
  7673. */
  7674. SHAPE_IMAGE: 'image',
  7675. /**
  7676. * Variable: SHAPE_ARROW
  7677. *
  7678. * Name under which <mxArrow> is registered in <mxCellRenderer>.
  7679. * Default is arrow.
  7680. */
  7681. SHAPE_ARROW: 'arrow',
  7682. /**
  7683. * Variable: SHAPE_ARROW_CONNECTOR
  7684. *
  7685. * Name under which <mxArrowConnector> is registered in <mxCellRenderer>.
  7686. * Default is arrowConnector.
  7687. */
  7688. SHAPE_ARROW_CONNECTOR: 'arrowConnector',
  7689. /**
  7690. * Variable: SHAPE_LABEL
  7691. *
  7692. * Name under which <mxLabel> is registered in <mxCellRenderer>.
  7693. * Default is label.
  7694. */
  7695. SHAPE_LABEL: 'label',
  7696. /**
  7697. * Variable: SHAPE_CYLINDER
  7698. *
  7699. * Name under which <mxCylinder> is registered in <mxCellRenderer>.
  7700. * Default is cylinder.
  7701. */
  7702. SHAPE_CYLINDER: 'cylinder',
  7703. /**
  7704. * Variable: SHAPE_SWIMLANE
  7705. *
  7706. * Name under which <mxSwimlane> is registered in <mxCellRenderer>.
  7707. * Default is swimlane.
  7708. */
  7709. SHAPE_SWIMLANE: 'swimlane',
  7710. /**
  7711. * Variable: SHAPE_CONNECTOR
  7712. *
  7713. * Name under which <mxConnector> is registered in <mxCellRenderer>.
  7714. * Default is connector.
  7715. */
  7716. SHAPE_CONNECTOR: 'connector',
  7717. /**
  7718. * Variable: SHAPE_ACTOR
  7719. *
  7720. * Name under which <mxActor> is registered in <mxCellRenderer>.
  7721. * Default is actor.
  7722. */
  7723. SHAPE_ACTOR: 'actor',
  7724. /**
  7725. * Variable: SHAPE_CLOUD
  7726. *
  7727. * Name under which <mxCloud> is registered in <mxCellRenderer>.
  7728. * Default is cloud.
  7729. */
  7730. SHAPE_CLOUD: 'cloud',
  7731. /**
  7732. * Variable: SHAPE_TRIANGLE
  7733. *
  7734. * Name under which <mxTriangle> is registered in <mxCellRenderer>.
  7735. * Default is triangle.
  7736. */
  7737. SHAPE_TRIANGLE: 'triangle',
  7738. /**
  7739. * Variable: SHAPE_HEXAGON
  7740. *
  7741. * Name under which <mxHexagon> is registered in <mxCellRenderer>.
  7742. * Default is hexagon.
  7743. */
  7744. SHAPE_HEXAGON: 'hexagon',
  7745. /**
  7746. * Variable: ARROW_CLASSIC
  7747. *
  7748. * Constant for classic arrow markers.
  7749. */
  7750. ARROW_CLASSIC: 'classic',
  7751. /**
  7752. * Variable: ARROW_CLASSIC_THIN
  7753. *
  7754. * Constant for thin classic arrow markers.
  7755. */
  7756. ARROW_CLASSIC_THIN: 'classicThin',
  7757. /**
  7758. * Variable: ARROW_BLOCK
  7759. *
  7760. * Constant for block arrow markers.
  7761. */
  7762. ARROW_BLOCK: 'block',
  7763. /**
  7764. * Variable: ARROW_BLOCK_THIN
  7765. *
  7766. * Constant for thin block arrow markers.
  7767. */
  7768. ARROW_BLOCK_THIN: 'blockThin',
  7769. /**
  7770. * Variable: ARROW_OPEN
  7771. *
  7772. * Constant for open arrow markers.
  7773. */
  7774. ARROW_OPEN: 'open',
  7775. /**
  7776. * Variable: ARROW_OPEN_THIN
  7777. *
  7778. * Constant for thin open arrow markers.
  7779. */
  7780. ARROW_OPEN_THIN: 'openThin',
  7781. /**
  7782. * Variable: ARROW_OVAL
  7783. *
  7784. * Constant for oval arrow markers.
  7785. */
  7786. ARROW_OVAL: 'oval',
  7787. /**
  7788. * Variable: ARROW_DIAMOND
  7789. *
  7790. * Constant for diamond arrow markers.
  7791. */
  7792. ARROW_DIAMOND: 'diamond',
  7793. /**
  7794. * Variable: ARROW_DIAMOND_THIN
  7795. *
  7796. * Constant for thin diamond arrow markers.
  7797. */
  7798. ARROW_DIAMOND_THIN: 'diamondThin',
  7799. /**
  7800. * Variable: ALIGN_LEFT
  7801. *
  7802. * Constant for left horizontal alignment. Default is left.
  7803. */
  7804. ALIGN_LEFT: 'left',
  7805. /**
  7806. * Variable: ALIGN_CENTER
  7807. *
  7808. * Constant for center horizontal alignment. Default is center.
  7809. */
  7810. ALIGN_CENTER: 'center',
  7811. /**
  7812. * Variable: ALIGN_RIGHT
  7813. *
  7814. * Constant for right horizontal alignment. Default is right.
  7815. */
  7816. ALIGN_RIGHT: 'right',
  7817. /**
  7818. * Variable: ALIGN_TOP
  7819. *
  7820. * Constant for top vertical alignment. Default is top.
  7821. */
  7822. ALIGN_TOP: 'top',
  7823. /**
  7824. * Variable: ALIGN_MIDDLE
  7825. *
  7826. * Constant for middle vertical alignment. Default is middle.
  7827. */
  7828. ALIGN_MIDDLE: 'middle',
  7829. /**
  7830. * Variable: ALIGN_BOTTOM
  7831. *
  7832. * Constant for bottom vertical alignment. Default is bottom.
  7833. */
  7834. ALIGN_BOTTOM: 'bottom',
  7835. /**
  7836. * Variable: DIRECTION_NORTH
  7837. *
  7838. * Constant for direction north. Default is north.
  7839. */
  7840. DIRECTION_NORTH: 'north',
  7841. /**
  7842. * Variable: DIRECTION_SOUTH
  7843. *
  7844. * Constant for direction south. Default is south.
  7845. */
  7846. DIRECTION_SOUTH: 'south',
  7847. /**
  7848. * Variable: DIRECTION_EAST
  7849. *
  7850. * Constant for direction east. Default is east.
  7851. */
  7852. DIRECTION_EAST: 'east',
  7853. /**
  7854. * Variable: DIRECTION_WEST
  7855. *
  7856. * Constant for direction west. Default is west.
  7857. */
  7858. DIRECTION_WEST: 'west',
  7859. /**
  7860. * Variable: TEXT_DIRECTION_DEFAULT
  7861. *
  7862. * Constant for text direction default. Default is an empty string. Use
  7863. * this value to use the default text direction of the operating system.
  7864. */
  7865. TEXT_DIRECTION_DEFAULT: '',
  7866. /**
  7867. * Variable: TEXT_DIRECTION_AUTO
  7868. *
  7869. * Constant for text direction automatic. Default is auto. Use this value
  7870. * to find the direction for a given text with <mxText.getAutoDirection>.
  7871. */
  7872. TEXT_DIRECTION_AUTO: 'auto',
  7873. /**
  7874. * Variable: TEXT_DIRECTION_LTR
  7875. *
  7876. * Constant for text direction left to right. Default is ltr. Use this
  7877. * value for left to right text direction.
  7878. */
  7879. TEXT_DIRECTION_LTR: 'ltr',
  7880. /**
  7881. * Variable: TEXT_DIRECTION_RTL
  7882. *
  7883. * Constant for text direction right to left. Default is rtl. Use this
  7884. * value for right to left text direction.
  7885. */
  7886. TEXT_DIRECTION_RTL: 'rtl',
  7887. /**
  7888. * Variable: DIRECTION_MASK_NONE
  7889. *
  7890. * Constant for no direction.
  7891. */
  7892. DIRECTION_MASK_NONE: 0,
  7893. /**
  7894. * Variable: DIRECTION_MASK_WEST
  7895. *
  7896. * Bitwise mask for west direction.
  7897. */
  7898. DIRECTION_MASK_WEST: 1,
  7899. /**
  7900. * Variable: DIRECTION_MASK_NORTH
  7901. *
  7902. * Bitwise mask for north direction.
  7903. */
  7904. DIRECTION_MASK_NORTH: 2,
  7905. /**
  7906. * Variable: DIRECTION_MASK_SOUTH
  7907. *
  7908. * Bitwise mask for south direction.
  7909. */
  7910. DIRECTION_MASK_SOUTH: 4,
  7911. /**
  7912. * Variable: DIRECTION_MASK_EAST
  7913. *
  7914. * Bitwise mask for east direction.
  7915. */
  7916. DIRECTION_MASK_EAST: 8,
  7917. /**
  7918. * Variable: DIRECTION_MASK_ALL
  7919. *
  7920. * Bitwise mask for all directions.
  7921. */
  7922. DIRECTION_MASK_ALL: 15,
  7923. /**
  7924. * Variable: ELBOW_VERTICAL
  7925. *
  7926. * Constant for elbow vertical. Default is horizontal.
  7927. */
  7928. ELBOW_VERTICAL: 'vertical',
  7929. /**
  7930. * Variable: ELBOW_HORIZONTAL
  7931. *
  7932. * Constant for elbow horizontal. Default is horizontal.
  7933. */
  7934. ELBOW_HORIZONTAL: 'horizontal',
  7935. /**
  7936. * Variable: EDGESTYLE_ELBOW
  7937. *
  7938. * Name of the elbow edge style. Can be used as a string value
  7939. * for the STYLE_EDGE style.
  7940. */
  7941. EDGESTYLE_ELBOW: 'elbowEdgeStyle',
  7942. /**
  7943. * Variable: EDGESTYLE_ENTITY_RELATION
  7944. *
  7945. * Name of the entity relation edge style. Can be used as a string value
  7946. * for the STYLE_EDGE style.
  7947. */
  7948. EDGESTYLE_ENTITY_RELATION: 'entityRelationEdgeStyle',
  7949. /**
  7950. * Variable: EDGESTYLE_LOOP
  7951. *
  7952. * Name of the loop edge style. Can be used as a string value
  7953. * for the STYLE_EDGE style.
  7954. */
  7955. EDGESTYLE_LOOP: 'loopEdgeStyle',
  7956. /**
  7957. * Variable: EDGESTYLE_SIDETOSIDE
  7958. *
  7959. * Name of the side to side edge style. Can be used as a string value
  7960. * for the STYLE_EDGE style.
  7961. */
  7962. EDGESTYLE_SIDETOSIDE: 'sideToSideEdgeStyle',
  7963. /**
  7964. * Variable: EDGESTYLE_TOPTOBOTTOM
  7965. *
  7966. * Name of the top to bottom edge style. Can be used as a string value
  7967. * for the STYLE_EDGE style.
  7968. */
  7969. EDGESTYLE_TOPTOBOTTOM: 'topToBottomEdgeStyle',
  7970. /**
  7971. * Variable: EDGESTYLE_ORTHOGONAL
  7972. *
  7973. * Name of the generic orthogonal edge style. Can be used as a string value
  7974. * for the STYLE_EDGE style.
  7975. */
  7976. EDGESTYLE_ORTHOGONAL: 'orthogonalEdgeStyle',
  7977. /**
  7978. * Variable: EDGESTYLE_SEGMENT
  7979. *
  7980. * Name of the generic segment edge style. Can be used as a string value
  7981. * for the STYLE_EDGE style.
  7982. */
  7983. EDGESTYLE_SEGMENT: 'segmentEdgeStyle',
  7984. /**
  7985. * Variable: PERIMETER_ELLIPSE
  7986. *
  7987. * Name of the ellipse perimeter. Can be used as a string value
  7988. * for the STYLE_PERIMETER style.
  7989. */
  7990. PERIMETER_ELLIPSE: 'ellipsePerimeter',
  7991. /**
  7992. * Variable: PERIMETER_RECTANGLE
  7993. *
  7994. * Name of the rectangle perimeter. Can be used as a string value
  7995. * for the STYLE_PERIMETER style.
  7996. */
  7997. PERIMETER_RECTANGLE: 'rectanglePerimeter',
  7998. /**
  7999. * Variable: PERIMETER_RHOMBUS
  8000. *
  8001. * Name of the rhombus perimeter. Can be used as a string value
  8002. * for the STYLE_PERIMETER style.
  8003. */
  8004. PERIMETER_RHOMBUS: 'rhombusPerimeter',
  8005. /**
  8006. * Variable: PERIMETER_HEXAGON
  8007. *
  8008. * Name of the hexagon perimeter. Can be used as a string value
  8009. * for the STYLE_PERIMETER style.
  8010. */
  8011. PERIMETER_HEXAGON: 'hexagonPerimeter',
  8012. /**
  8013. * Variable: PERIMETER_TRIANGLE
  8014. *
  8015. * Name of the triangle perimeter. Can be used as a string value
  8016. * for the STYLE_PERIMETER style.
  8017. */
  8018. PERIMETER_TRIANGLE: 'trianglePerimeter'
  8019. };
  8020. /**
  8021. * Copyright (c) 2006-2015, JGraph Ltd
  8022. * Copyright (c) 2006-2015, Gaudenz Alder
  8023. */
  8024. /**
  8025. * Class: mxEventObject
  8026. *
  8027. * The mxEventObject is a wrapper for all properties of a single event.
  8028. * Additionally, it also offers functions to consume the event and check if it
  8029. * was consumed as follows:
  8030. *
  8031. * (code)
  8032. * evt.consume();
  8033. * INV: evt.isConsumed() == true
  8034. * (end)
  8035. *
  8036. * Constructor: mxEventObject
  8037. *
  8038. * Constructs a new event object with the specified name. An optional
  8039. * sequence of key, value pairs can be appended to define properties.
  8040. *
  8041. * Example:
  8042. *
  8043. * (code)
  8044. * new mxEventObject("eventName", key1, val1, .., keyN, valN)
  8045. * (end)
  8046. */
  8047. function mxEventObject(name)
  8048. {
  8049. this.name = name;
  8050. this.properties = [];
  8051. for (var i = 1; i < arguments.length; i += 2)
  8052. {
  8053. if (arguments[i + 1] != null)
  8054. {
  8055. this.properties[arguments[i]] = arguments[i + 1];
  8056. }
  8057. }
  8058. };
  8059. /**
  8060. * Variable: name
  8061. *
  8062. * Holds the name.
  8063. */
  8064. mxEventObject.prototype.name = null;
  8065. /**
  8066. * Variable: properties
  8067. *
  8068. * Holds the properties as an associative array.
  8069. */
  8070. mxEventObject.prototype.properties = null;
  8071. /**
  8072. * Variable: consumed
  8073. *
  8074. * Holds the consumed state. Default is false.
  8075. */
  8076. mxEventObject.prototype.consumed = false;
  8077. /**
  8078. * Function: getName
  8079. *
  8080. * Returns <name>.
  8081. */
  8082. mxEventObject.prototype.getName = function()
  8083. {
  8084. return this.name;
  8085. };
  8086. /**
  8087. * Function: getProperties
  8088. *
  8089. * Returns <properties>.
  8090. */
  8091. mxEventObject.prototype.getProperties = function()
  8092. {
  8093. return this.properties;
  8094. };
  8095. /**
  8096. * Function: getProperty
  8097. *
  8098. * Returns the property for the given key.
  8099. */
  8100. mxEventObject.prototype.getProperty = function(key)
  8101. {
  8102. return this.properties[key];
  8103. };
  8104. /**
  8105. * Function: isConsumed
  8106. *
  8107. * Returns true if the event has been consumed.
  8108. */
  8109. mxEventObject.prototype.isConsumed = function()
  8110. {
  8111. return this.consumed;
  8112. };
  8113. /**
  8114. * Function: consume
  8115. *
  8116. * Consumes the event.
  8117. */
  8118. mxEventObject.prototype.consume = function()
  8119. {
  8120. this.consumed = true;
  8121. };
  8122. /**
  8123. * Copyright (c) 2006-2015, JGraph Ltd
  8124. * Copyright (c) 2006-2015, Gaudenz Alder
  8125. */
  8126. /**
  8127. * Class: mxMouseEvent
  8128. *
  8129. * Base class for all mouse events in mxGraph. A listener for this event should
  8130. * implement the following methods:
  8131. *
  8132. * (code)
  8133. * graph.addMouseListener(
  8134. * {
  8135. * mouseDown: function(sender, evt)
  8136. * {
  8137. * mxLog.debug('mouseDown');
  8138. * },
  8139. * mouseMove: function(sender, evt)
  8140. * {
  8141. * mxLog.debug('mouseMove');
  8142. * },
  8143. * mouseUp: function(sender, evt)
  8144. * {
  8145. * mxLog.debug('mouseUp');
  8146. * }
  8147. * });
  8148. * (end)
  8149. *
  8150. * Constructor: mxMouseEvent
  8151. *
  8152. * Constructs a new event object for the given arguments.
  8153. *
  8154. * Parameters:
  8155. *
  8156. * evt - Native mouse event.
  8157. * state - Optional <mxCellState> under the mouse.
  8158. *
  8159. */
  8160. function mxMouseEvent(evt, state)
  8161. {
  8162. this.evt = evt;
  8163. this.state = state;
  8164. this.sourceState = state;
  8165. };
  8166. /**
  8167. * Variable: consumed
  8168. *
  8169. * Holds the consumed state of this event.
  8170. */
  8171. mxMouseEvent.prototype.consumed = false;
  8172. /**
  8173. * Variable: evt
  8174. *
  8175. * Holds the inner event object.
  8176. */
  8177. mxMouseEvent.prototype.evt = null;
  8178. /**
  8179. * Variable: graphX
  8180. *
  8181. * Holds the x-coordinate of the event in the graph. This value is set in
  8182. * <mxGraph.fireMouseEvent>.
  8183. */
  8184. mxMouseEvent.prototype.graphX = null;
  8185. /**
  8186. * Variable: graphY
  8187. *
  8188. * Holds the y-coordinate of the event in the graph. This value is set in
  8189. * <mxGraph.fireMouseEvent>.
  8190. */
  8191. mxMouseEvent.prototype.graphY = null;
  8192. /**
  8193. * Variable: state
  8194. *
  8195. * Holds the optional <mxCellState> associated with this event.
  8196. */
  8197. mxMouseEvent.prototype.state = null;
  8198. /**
  8199. * Variable: sourceState
  8200. *
  8201. * Holds the <mxCellState> that was passed to the constructor. This can be
  8202. * different from <state> depending on the result of <mxGraph.getEventState>.
  8203. */
  8204. mxMouseEvent.prototype.sourceState = null;
  8205. /**
  8206. * Function: getEvent
  8207. *
  8208. * Returns <evt>.
  8209. */
  8210. mxMouseEvent.prototype.getEvent = function()
  8211. {
  8212. return this.evt;
  8213. };
  8214. /**
  8215. * Function: getSource
  8216. *
  8217. * Returns the target DOM element using <mxEvent.getSource> for <evt>.
  8218. */
  8219. mxMouseEvent.prototype.getSource = function()
  8220. {
  8221. return mxEvent.getSource(this.evt);
  8222. };
  8223. /**
  8224. * Function: isSource
  8225. *
  8226. * Returns true if the given <mxShape> is the source of <evt>.
  8227. */
  8228. mxMouseEvent.prototype.isSource = function(shape)
  8229. {
  8230. if (shape != null)
  8231. {
  8232. return mxUtils.isAncestorNode(shape.node, this.getSource());
  8233. }
  8234. return false;
  8235. };
  8236. /**
  8237. * Function: getX
  8238. *
  8239. * Returns <evt.clientX>.
  8240. */
  8241. mxMouseEvent.prototype.getX = function()
  8242. {
  8243. return mxEvent.getClientX(this.getEvent());
  8244. };
  8245. /**
  8246. * Function: getY
  8247. *
  8248. * Returns <evt.clientY>.
  8249. */
  8250. mxMouseEvent.prototype.getY = function()
  8251. {
  8252. return mxEvent.getClientY(this.getEvent());
  8253. };
  8254. /**
  8255. * Function: getGraphX
  8256. *
  8257. * Returns <graphX>.
  8258. */
  8259. mxMouseEvent.prototype.getGraphX = function()
  8260. {
  8261. return this.graphX;
  8262. };
  8263. /**
  8264. * Function: getGraphY
  8265. *
  8266. * Returns <graphY>.
  8267. */
  8268. mxMouseEvent.prototype.getGraphY = function()
  8269. {
  8270. return this.graphY;
  8271. };
  8272. /**
  8273. * Function: getState
  8274. *
  8275. * Returns <state>.
  8276. */
  8277. mxMouseEvent.prototype.getState = function()
  8278. {
  8279. return this.state;
  8280. };
  8281. /**
  8282. * Function: getCell
  8283. *
  8284. * Returns the <mxCell> in <state> is not null.
  8285. */
  8286. mxMouseEvent.prototype.getCell = function()
  8287. {
  8288. var state = this.getState();
  8289. if (state != null)
  8290. {
  8291. return state.cell;
  8292. }
  8293. return null;
  8294. };
  8295. /**
  8296. * Function: isPopupTrigger
  8297. *
  8298. * Returns true if the event is a popup trigger.
  8299. */
  8300. mxMouseEvent.prototype.isPopupTrigger = function()
  8301. {
  8302. return mxEvent.isPopupTrigger(this.getEvent());
  8303. };
  8304. /**
  8305. * Function: isConsumed
  8306. *
  8307. * Returns <consumed>.
  8308. */
  8309. mxMouseEvent.prototype.isConsumed = function()
  8310. {
  8311. return this.consumed;
  8312. };
  8313. /**
  8314. * Function: consume
  8315. *
  8316. * Sets <consumed> to true and invokes preventDefault on the native event
  8317. * if such a method is defined. This is used mainly to avoid the cursor from
  8318. * being changed to a text cursor in Webkit. You can use the preventDefault
  8319. * flag to disable this functionality.
  8320. *
  8321. * Parameters:
  8322. *
  8323. * preventDefault - Specifies if the native event should be canceled. Default
  8324. * is true.
  8325. */
  8326. mxMouseEvent.prototype.consume = function(preventDefault)
  8327. {
  8328. preventDefault = (preventDefault != null) ? preventDefault :
  8329. (this.evt.touches != null || mxEvent.isMouseEvent(this.evt));
  8330. if (preventDefault && this.evt.preventDefault)
  8331. {
  8332. this.evt.preventDefault();
  8333. }
  8334. // Workaround for images being dragged in IE
  8335. // Does not change returnValue in Opera
  8336. if (mxClient.IS_IE)
  8337. {
  8338. this.evt.returnValue = true;
  8339. }
  8340. // Sets local consumed state
  8341. this.consumed = true;
  8342. };
  8343. /**
  8344. * Copyright (c) 2006-2015, JGraph Ltd
  8345. * Copyright (c) 2006-2015, Gaudenz Alder
  8346. */
  8347. /**
  8348. * Class: mxEventSource
  8349. *
  8350. * Base class for objects that dispatch named events. To create a subclass that
  8351. * inherits from mxEventSource, the following code is used.
  8352. *
  8353. * (code)
  8354. * function MyClass() { };
  8355. *
  8356. * MyClass.prototype = new mxEventSource();
  8357. * MyClass.prototype.constructor = MyClass;
  8358. * (end)
  8359. *
  8360. * Known Subclasses:
  8361. *
  8362. * <mxGraphModel>, <mxGraph>, <mxGraphView>, <mxEditor>, <mxCellOverlay>,
  8363. * <mxToolbar>, <mxWindow>
  8364. *
  8365. * Constructor: mxEventSource
  8366. *
  8367. * Constructs a new event source.
  8368. */
  8369. function mxEventSource(eventSource)
  8370. {
  8371. this.setEventSource(eventSource);
  8372. };
  8373. /**
  8374. * Variable: eventListeners
  8375. *
  8376. * Holds the event names and associated listeners in an array. The array
  8377. * contains the event name followed by the respective listener for each
  8378. * registered listener.
  8379. */
  8380. mxEventSource.prototype.eventListeners = null;
  8381. /**
  8382. * Variable: eventsEnabled
  8383. *
  8384. * Specifies if events can be fired. Default is true.
  8385. */
  8386. mxEventSource.prototype.eventsEnabled = true;
  8387. /**
  8388. * Variable: eventSource
  8389. *
  8390. * Optional source for events. Default is null.
  8391. */
  8392. mxEventSource.prototype.eventSource = null;
  8393. /**
  8394. * Function: isEventsEnabled
  8395. *
  8396. * Returns <eventsEnabled>.
  8397. */
  8398. mxEventSource.prototype.isEventsEnabled = function()
  8399. {
  8400. return this.eventsEnabled;
  8401. };
  8402. /**
  8403. * Function: setEventsEnabled
  8404. *
  8405. * Sets <eventsEnabled>.
  8406. */
  8407. mxEventSource.prototype.setEventsEnabled = function(value)
  8408. {
  8409. this.eventsEnabled = value;
  8410. };
  8411. /**
  8412. * Function: getEventSource
  8413. *
  8414. * Returns <eventSource>.
  8415. */
  8416. mxEventSource.prototype.getEventSource = function()
  8417. {
  8418. return this.eventSource;
  8419. };
  8420. /**
  8421. * Function: setEventSource
  8422. *
  8423. * Sets <eventSource>.
  8424. */
  8425. mxEventSource.prototype.setEventSource = function(value)
  8426. {
  8427. this.eventSource = value;
  8428. };
  8429. /**
  8430. * Function: addListener
  8431. *
  8432. * Binds the specified function to the given event name. If no event name
  8433. * is given, then the listener is registered for all events.
  8434. *
  8435. * The parameters of the listener are the sender and an <mxEventObject>.
  8436. */
  8437. mxEventSource.prototype.addListener = function(name, funct)
  8438. {
  8439. if (this.eventListeners == null)
  8440. {
  8441. this.eventListeners = [];
  8442. }
  8443. this.eventListeners.push(name);
  8444. this.eventListeners.push(funct);
  8445. };
  8446. /**
  8447. * Function: removeListener
  8448. *
  8449. * Removes all occurrences of the given listener from <eventListeners>.
  8450. */
  8451. mxEventSource.prototype.removeListener = function(funct)
  8452. {
  8453. if (this.eventListeners != null)
  8454. {
  8455. var i = 0;
  8456. while (i < this.eventListeners.length)
  8457. {
  8458. if (this.eventListeners[i+1] == funct)
  8459. {
  8460. this.eventListeners.splice(i, 2);
  8461. }
  8462. else
  8463. {
  8464. i += 2;
  8465. }
  8466. }
  8467. }
  8468. };
  8469. /**
  8470. * Function: fireEvent
  8471. *
  8472. * Dispatches the given event to the listeners which are registered for
  8473. * the event. The sender argument is optional. The current execution scope
  8474. * ("this") is used for the listener invocation (see <mxUtils.bind>).
  8475. *
  8476. * Example:
  8477. *
  8478. * (code)
  8479. * fireEvent(new mxEventObject("eventName", key1, val1, .., keyN, valN))
  8480. * (end)
  8481. *
  8482. * Parameters:
  8483. *
  8484. * evt - <mxEventObject> that represents the event.
  8485. * sender - Optional sender to be passed to the listener. Default value is
  8486. * the return value of <getEventSource>.
  8487. */
  8488. mxEventSource.prototype.fireEvent = function(evt, sender)
  8489. {
  8490. if (this.eventListeners != null && this.isEventsEnabled())
  8491. {
  8492. if (evt == null)
  8493. {
  8494. evt = new mxEventObject();
  8495. }
  8496. if (sender == null)
  8497. {
  8498. sender = this.getEventSource();
  8499. }
  8500. if (sender == null)
  8501. {
  8502. sender = this;
  8503. }
  8504. var args = [sender, evt];
  8505. for (var i = 0; i < this.eventListeners.length; i += 2)
  8506. {
  8507. var listen = this.eventListeners[i];
  8508. if (listen == null || listen == evt.getName())
  8509. {
  8510. this.eventListeners[i+1].apply(this, args);
  8511. }
  8512. }
  8513. }
  8514. };
  8515. /**
  8516. * Copyright (c) 2006-2015, JGraph Ltd
  8517. * Copyright (c) 2006-2015, Gaudenz Alder
  8518. */
  8519. var mxEvent =
  8520. {
  8521. /**
  8522. * Class: mxEvent
  8523. *
  8524. * Cross-browser DOM event support. For internal event handling,
  8525. * <mxEventSource> and the graph event dispatch loop in <mxGraph> are used.
  8526. *
  8527. * Memory Leaks:
  8528. *
  8529. * Use this class for adding and removing listeners to/from DOM nodes. The
  8530. * <removeAllListeners> function is provided to remove all listeners that
  8531. * have been added using <addListener>. The function should be invoked when
  8532. * the last reference is removed in the JavaScript code, typically when the
  8533. * referenced DOM node is removed from the DOM.
  8534. *
  8535. * Function: addListener
  8536. *
  8537. * Binds the function to the specified event on the given element. Use
  8538. * <mxUtils.bind> in order to bind the "this" keyword inside the function
  8539. * to a given execution scope.
  8540. */
  8541. addListener: function()
  8542. {
  8543. var updateListenerList = function(element, eventName, funct)
  8544. {
  8545. if (element.mxListenerList == null)
  8546. {
  8547. element.mxListenerList = [];
  8548. }
  8549. var entry = {name: eventName, f: funct};
  8550. element.mxListenerList.push(entry);
  8551. };
  8552. if (window.addEventListener)
  8553. {
  8554. return function(element, eventName, funct)
  8555. {
  8556. element.addEventListener(eventName, funct, false);
  8557. updateListenerList(element, eventName, funct);
  8558. };
  8559. }
  8560. else
  8561. {
  8562. return function(element, eventName, funct)
  8563. {
  8564. element.attachEvent('on' + eventName, funct);
  8565. updateListenerList(element, eventName, funct);
  8566. };
  8567. }
  8568. }(),
  8569. /**
  8570. * Function: removeListener
  8571. *
  8572. * Removes the specified listener from the given element.
  8573. */
  8574. removeListener: function()
  8575. {
  8576. var updateListener = function(element, eventName, funct)
  8577. {
  8578. if (element.mxListenerList != null)
  8579. {
  8580. var listenerCount = element.mxListenerList.length;
  8581. for (var i = 0; i < listenerCount; i++)
  8582. {
  8583. var entry = element.mxListenerList[i];
  8584. if (entry.f == funct)
  8585. {
  8586. element.mxListenerList.splice(i, 1);
  8587. break;
  8588. }
  8589. }
  8590. if (element.mxListenerList.length == 0)
  8591. {
  8592. element.mxListenerList = null;
  8593. }
  8594. }
  8595. };
  8596. if (window.removeEventListener)
  8597. {
  8598. return function(element, eventName, funct)
  8599. {
  8600. element.removeEventListener(eventName, funct, false);
  8601. updateListener(element, eventName, funct);
  8602. };
  8603. }
  8604. else
  8605. {
  8606. return function(element, eventName, funct)
  8607. {
  8608. element.detachEvent('on' + eventName, funct);
  8609. updateListener(element, eventName, funct);
  8610. };
  8611. }
  8612. }(),
  8613. /**
  8614. * Function: removeAllListeners
  8615. *
  8616. * Removes all listeners from the given element.
  8617. */
  8618. removeAllListeners: function(element)
  8619. {
  8620. var list = element.mxListenerList;
  8621. if (list != null)
  8622. {
  8623. while (list.length > 0)
  8624. {
  8625. var entry = list[0];
  8626. mxEvent.removeListener(element, entry.name, entry.f);
  8627. }
  8628. }
  8629. },
  8630. /**
  8631. * Function: addGestureListeners
  8632. *
  8633. * Adds the given listeners for touch, mouse and/or pointer events. If
  8634. * <mxClient.IS_POINTER> is true then pointer events will be registered,
  8635. * else the respective mouse events will be registered. If <mxClient.IS_POINTER>
  8636. * is false and <mxClient.IS_TOUCH> is true then the respective touch events
  8637. * will be registered as well as the mouse events.
  8638. */
  8639. addGestureListeners: function(node, startListener, moveListener, endListener)
  8640. {
  8641. if (startListener != null)
  8642. {
  8643. mxEvent.addListener(node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', startListener);
  8644. }
  8645. if (moveListener != null)
  8646. {
  8647. mxEvent.addListener(node, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', moveListener);
  8648. }
  8649. if (endListener != null)
  8650. {
  8651. mxEvent.addListener(node, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', endListener);
  8652. }
  8653. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  8654. {
  8655. if (startListener != null)
  8656. {
  8657. mxEvent.addListener(node, 'touchstart', startListener);
  8658. }
  8659. if (moveListener != null)
  8660. {
  8661. mxEvent.addListener(node, 'touchmove', moveListener);
  8662. }
  8663. if (endListener != null)
  8664. {
  8665. mxEvent.addListener(node, 'touchend', endListener);
  8666. }
  8667. }
  8668. },
  8669. /**
  8670. * Function: removeGestureListeners
  8671. *
  8672. * Removes the given listeners from mousedown, mousemove, mouseup and the
  8673. * respective touch events if <mxClient.IS_TOUCH> is true.
  8674. */
  8675. removeGestureListeners: function(node, startListener, moveListener, endListener)
  8676. {
  8677. if (startListener != null)
  8678. {
  8679. mxEvent.removeListener(node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', startListener);
  8680. }
  8681. if (moveListener != null)
  8682. {
  8683. mxEvent.removeListener(node, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', moveListener);
  8684. }
  8685. if (endListener != null)
  8686. {
  8687. mxEvent.removeListener(node, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', endListener);
  8688. }
  8689. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  8690. {
  8691. if (startListener != null)
  8692. {
  8693. mxEvent.removeListener(node, 'touchstart', startListener);
  8694. }
  8695. if (moveListener != null)
  8696. {
  8697. mxEvent.removeListener(node, 'touchmove', moveListener);
  8698. }
  8699. if (endListener != null)
  8700. {
  8701. mxEvent.removeListener(node, 'touchend', endListener);
  8702. }
  8703. }
  8704. },
  8705. /**
  8706. * Function: redirectMouseEvents
  8707. *
  8708. * Redirects the mouse events from the given DOM node to the graph dispatch
  8709. * loop using the event and given state as event arguments. State can
  8710. * either be an instance of <mxCellState> or a function that returns an
  8711. * <mxCellState>. The down, move, up and dblClick arguments are optional
  8712. * functions that take the trigger event as arguments and replace the
  8713. * default behaviour.
  8714. */
  8715. redirectMouseEvents: function(node, graph, state, down, move, up, dblClick)
  8716. {
  8717. var getState = function(evt)
  8718. {
  8719. return (typeof(state) == 'function') ? state(evt) : state;
  8720. };
  8721. mxEvent.addGestureListeners(node, function (evt)
  8722. {
  8723. if (down != null)
  8724. {
  8725. down(evt);
  8726. }
  8727. else if (!mxEvent.isConsumed(evt))
  8728. {
  8729. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt, getState(evt)));
  8730. }
  8731. },
  8732. function (evt)
  8733. {
  8734. if (move != null)
  8735. {
  8736. move(evt);
  8737. }
  8738. else if (!mxEvent.isConsumed(evt))
  8739. {
  8740. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt, getState(evt)));
  8741. }
  8742. },
  8743. function (evt)
  8744. {
  8745. if (up != null)
  8746. {
  8747. up(evt);
  8748. }
  8749. else if (!mxEvent.isConsumed(evt))
  8750. {
  8751. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt, getState(evt)));
  8752. }
  8753. });
  8754. mxEvent.addListener(node, 'dblclick', function (evt)
  8755. {
  8756. if (dblClick != null)
  8757. {
  8758. dblClick(evt);
  8759. }
  8760. else if (!mxEvent.isConsumed(evt))
  8761. {
  8762. var tmp = getState(evt);
  8763. graph.dblClick(evt, (tmp != null) ? tmp.cell : null);
  8764. }
  8765. });
  8766. },
  8767. /**
  8768. * Function: release
  8769. *
  8770. * Removes the known listeners from the given DOM node and its descendants.
  8771. *
  8772. * Parameters:
  8773. *
  8774. * element - DOM node to remove the listeners from.
  8775. */
  8776. release: function(element)
  8777. {
  8778. try
  8779. {
  8780. if (element != null)
  8781. {
  8782. mxEvent.removeAllListeners(element);
  8783. var children = element.childNodes;
  8784. if (children != null)
  8785. {
  8786. var childCount = children.length;
  8787. for (var i = 0; i < childCount; i += 1)
  8788. {
  8789. mxEvent.release(children[i]);
  8790. }
  8791. }
  8792. }
  8793. }
  8794. catch (e)
  8795. {
  8796. // ignores errors as this is typically called in cleanup code
  8797. }
  8798. },
  8799. /**
  8800. * Function: addMouseWheelListener
  8801. *
  8802. * Installs the given function as a handler for mouse wheel events. The
  8803. * function has two arguments: the mouse event and a boolean that specifies
  8804. * if the wheel was moved up or down.
  8805. *
  8806. * This has been tested with IE 6 and 7, Firefox (all versions), Opera and
  8807. * Safari. It does currently not work on Safari for Mac.
  8808. *
  8809. * Example:
  8810. *
  8811. * (code)
  8812. * mxEvent.addMouseWheelListener(function (evt, up)
  8813. * {
  8814. * mxLog.show();
  8815. * mxLog.debug('mouseWheel: up='+up);
  8816. * });
  8817. *(end)
  8818. *
  8819. * Parameters:
  8820. *
  8821. * funct - Handler function that takes the event argument and a boolean up
  8822. * argument for the mousewheel direction.
  8823. * target - Target for installing the listener in Google Chrome. See
  8824. * https://www.chromestatus.com/features/6662647093133312.
  8825. */
  8826. addMouseWheelListener: function(funct, target)
  8827. {
  8828. if (funct != null)
  8829. {
  8830. var wheelHandler = function(evt)
  8831. {
  8832. // IE does not give an event object but the
  8833. // global event object is the mousewheel event
  8834. // at this point in time.
  8835. if (evt == null)
  8836. {
  8837. evt = window.event;
  8838. }
  8839. //To prevent window zoom on trackpad pinch
  8840. if (evt.ctrlKey)
  8841. {
  8842. evt.preventDefault();
  8843. }
  8844. var delta = -evt.deltaY;
  8845. // Handles the event using the given function
  8846. if (Math.abs(evt.deltaX) > 0.5 || Math.abs(evt.deltaY) > 0.5)
  8847. {
  8848. funct(evt, (evt.deltaY == 0) ? -evt.deltaX > 0 : -evt.deltaY > 0);
  8849. }
  8850. };
  8851. target = target != null ? target : window;
  8852. if (mxClient.IS_SF && !mxClient.IS_TOUCH)
  8853. {
  8854. var scale = 1;
  8855. mxEvent.addListener(target, 'gesturestart', function(evt)
  8856. {
  8857. mxEvent.consume(evt);
  8858. scale = 1;
  8859. });
  8860. mxEvent.addListener(target, 'gesturechange', function(evt)
  8861. {
  8862. mxEvent.consume(evt);
  8863. var diff = scale - evt.scale;
  8864. if (Math.abs(diff) > 0.2)
  8865. {
  8866. funct(evt, diff < 0, true);
  8867. scale = evt.scale;
  8868. }
  8869. });
  8870. mxEvent.addListener(target, 'gestureend', function(evt)
  8871. {
  8872. mxEvent.consume(evt);
  8873. });
  8874. }
  8875. mxEvent.addListener(target, 'wheel', wheelHandler);
  8876. }
  8877. },
  8878. /**
  8879. * Function: disableContextMenu
  8880. *
  8881. * Disables the context menu for the given element.
  8882. */
  8883. disableContextMenu: function(element)
  8884. {
  8885. mxEvent.addListener(element, 'contextmenu', function(evt)
  8886. {
  8887. if (evt.preventDefault)
  8888. {
  8889. evt.preventDefault();
  8890. }
  8891. return false;
  8892. });
  8893. },
  8894. /**
  8895. * Function: getSource
  8896. *
  8897. * Returns the event's target or srcElement depending on the browser.
  8898. */
  8899. getSource: function(evt)
  8900. {
  8901. return (evt.srcElement != null) ? evt.srcElement : evt.target;
  8902. },
  8903. /**
  8904. * Function: isConsumed
  8905. *
  8906. * Returns true if the event has been consumed using <consume>.
  8907. */
  8908. isConsumed: function(evt)
  8909. {
  8910. return evt.isConsumed != null && evt.isConsumed;
  8911. },
  8912. /**
  8913. * Function: isTouchEvent
  8914. *
  8915. * Returns true if the event was generated using a touch device (not a pen or mouse).
  8916. */
  8917. isTouchEvent: function(evt)
  8918. {
  8919. return (evt.pointerType != null) ? (evt.pointerType == 'touch' || evt.pointerType ===
  8920. evt.MSPOINTER_TYPE_TOUCH) : ((evt.mozInputSource != null) ?
  8921. evt.mozInputSource == 5 : evt.type.indexOf('touch') == 0);
  8922. },
  8923. /**
  8924. * Function: isPenEvent
  8925. *
  8926. * Returns true if the event was generated using a pen (not a touch device or mouse).
  8927. */
  8928. isPenEvent: function(evt)
  8929. {
  8930. return (evt.pointerType != null) ? (evt.pointerType == 'pen' || evt.pointerType ===
  8931. evt.MSPOINTER_TYPE_PEN) : ((evt.mozInputSource != null) ?
  8932. evt.mozInputSource == 2 : evt.type.indexOf('pen') == 0);
  8933. },
  8934. /**
  8935. * Function: isMultiTouchEvent
  8936. *
  8937. * Returns true if the event was generated using a touch device (not a pen or mouse).
  8938. */
  8939. isMultiTouchEvent: function(evt)
  8940. {
  8941. return (evt.type != null && evt.type.indexOf('touch') == 0 && evt.touches != null && evt.touches.length > 1);
  8942. },
  8943. /**
  8944. * Function: isMouseEvent
  8945. *
  8946. * Returns true if the event was generated using a mouse (not a pen or touch device).
  8947. */
  8948. isMouseEvent: function(evt)
  8949. {
  8950. return (evt.pointerType != null) ? (evt.pointerType == 'mouse' || evt.pointerType ===
  8951. evt.MSPOINTER_TYPE_MOUSE) : ((evt.mozInputSource != null) ?
  8952. evt.mozInputSource == 1 : evt.type.indexOf('mouse') == 0);
  8953. },
  8954. /**
  8955. * Function: isLeftMouseButton
  8956. *
  8957. * Returns true if the left mouse button is pressed for the given event.
  8958. * To check if a button is pressed during a mouseMove you should use the
  8959. * <mxGraph.isMouseDown> property. Note that this returns true in Firefox
  8960. * for control+left-click on the Mac.
  8961. */
  8962. isLeftMouseButton: function(evt)
  8963. {
  8964. // Special case for mousemove and mousedown we check the buttons
  8965. // if it exists because which is 0 even if no button is pressed
  8966. if ('buttons' in evt && (evt.type == 'mousedown' || evt.type == 'mousemove'))
  8967. {
  8968. return evt.buttons == 1;
  8969. }
  8970. else if ('which' in evt)
  8971. {
  8972. return evt.which === 1;
  8973. }
  8974. else
  8975. {
  8976. return evt.button === 1;
  8977. }
  8978. },
  8979. /**
  8980. * Function: isMiddleMouseButton
  8981. *
  8982. * Returns true if the middle mouse button is pressed for the given event.
  8983. * To check if a button is pressed during a mouseMove you should use the
  8984. * <mxGraph.isMouseDown> property.
  8985. */
  8986. isMiddleMouseButton: function(evt)
  8987. {
  8988. if ('which' in evt)
  8989. {
  8990. return evt.which === 2;
  8991. }
  8992. else
  8993. {
  8994. return evt.button === 4;
  8995. }
  8996. },
  8997. /**
  8998. * Function: isRightMouseButton
  8999. *
  9000. * Returns true if the right mouse button was pressed. Note that this
  9001. * button might not be available on some systems. For handling a popup
  9002. * trigger <isPopupTrigger> should be used.
  9003. */
  9004. isRightMouseButton: function(evt)
  9005. {
  9006. if ('which' in evt)
  9007. {
  9008. return evt.which === 3;
  9009. }
  9010. else
  9011. {
  9012. return evt.button === 2;
  9013. }
  9014. },
  9015. /**
  9016. * Function: isPopupTrigger
  9017. *
  9018. * Returns true if the event is a popup trigger. This implementation
  9019. * returns true if the right button or the left button and control was
  9020. * pressed on a Mac.
  9021. */
  9022. isPopupTrigger: function(evt)
  9023. {
  9024. return mxEvent.isRightMouseButton(evt) || (mxClient.IS_MAC && mxEvent.isControlDown(evt) &&
  9025. !mxEvent.isShiftDown(evt) && !mxEvent.isMetaDown(evt) && !mxEvent.isAltDown(evt));
  9026. },
  9027. /**
  9028. * Function: isShiftDown
  9029. *
  9030. * Returns true if the shift key is pressed for the given event.
  9031. */
  9032. isShiftDown: function(evt)
  9033. {
  9034. return (evt != null) ? evt.shiftKey : false;
  9035. },
  9036. /**
  9037. * Function: isAltDown
  9038. *
  9039. * Returns true if the alt key is pressed for the given event.
  9040. */
  9041. isAltDown: function(evt)
  9042. {
  9043. return (evt != null) ? evt.altKey : false;
  9044. },
  9045. /**
  9046. * Function: isControlDown
  9047. *
  9048. * Returns true if the control key is pressed for the given event.
  9049. */
  9050. isControlDown: function(evt)
  9051. {
  9052. return (evt != null) ? evt.ctrlKey : false;
  9053. },
  9054. /**
  9055. * Function: isMetaDown
  9056. *
  9057. * Returns true if the meta key is pressed for the given event.
  9058. */
  9059. isMetaDown: function(evt)
  9060. {
  9061. return (evt != null) ? evt.metaKey : false;
  9062. },
  9063. /**
  9064. * Function: getMainEvent
  9065. *
  9066. * Returns the touch or mouse event that contains the mouse coordinates.
  9067. */
  9068. getMainEvent: function(e)
  9069. {
  9070. if ((e.type == 'touchstart' || e.type == 'touchmove') && e.touches != null && e.touches[0] != null)
  9071. {
  9072. e = e.touches[0];
  9073. }
  9074. else if (e.type == 'touchend' && e.changedTouches != null && e.changedTouches[0] != null)
  9075. {
  9076. e = e.changedTouches[0];
  9077. }
  9078. return e;
  9079. },
  9080. /**
  9081. * Function: getClientX
  9082. *
  9083. * Returns true if the meta key is pressed for the given event.
  9084. */
  9085. getClientX: function(e)
  9086. {
  9087. return mxEvent.getMainEvent(e).clientX;
  9088. },
  9089. /**
  9090. * Function: getClientY
  9091. *
  9092. * Returns true if the meta key is pressed for the given event.
  9093. */
  9094. getClientY: function(e)
  9095. {
  9096. return mxEvent.getMainEvent(e).clientY;
  9097. },
  9098. /**
  9099. * Function: consume
  9100. *
  9101. * Consumes the given event.
  9102. *
  9103. * Parameters:
  9104. *
  9105. * evt - Native event to be consumed.
  9106. * preventDefault - Optional boolean to prevent the default for the event.
  9107. * Default is true.
  9108. * stopPropagation - Option boolean to stop event propagation. Default is
  9109. * true.
  9110. */
  9111. consume: function(evt, preventDefault, stopPropagation)
  9112. {
  9113. preventDefault = (preventDefault != null) ? preventDefault : true;
  9114. stopPropagation = (stopPropagation != null) ? stopPropagation : true;
  9115. if (preventDefault)
  9116. {
  9117. if (evt.preventDefault)
  9118. {
  9119. if (stopPropagation)
  9120. {
  9121. evt.stopPropagation();
  9122. }
  9123. evt.preventDefault();
  9124. }
  9125. else if (stopPropagation)
  9126. {
  9127. evt.cancelBubble = true;
  9128. }
  9129. }
  9130. // Opera
  9131. evt.isConsumed = true;
  9132. // Other browsers
  9133. if (!evt.preventDefault)
  9134. {
  9135. evt.returnValue = false;
  9136. }
  9137. },
  9138. //
  9139. // Special handles in mouse events
  9140. //
  9141. /**
  9142. * Variable: LABEL_HANDLE
  9143. *
  9144. * Index for the label handle in an mxMouseEvent. This should be a negative
  9145. * value that does not interfere with any possible handle indices. Default
  9146. * is -1.
  9147. */
  9148. LABEL_HANDLE: -1,
  9149. /**
  9150. * Variable: ROTATION_HANDLE
  9151. *
  9152. * Index for the rotation handle in an mxMouseEvent. This should be a
  9153. * negative value that does not interfere with any possible handle indices.
  9154. * Default is -2.
  9155. */
  9156. ROTATION_HANDLE: -2,
  9157. /**
  9158. * Variable: CUSTOM_HANDLE
  9159. *
  9160. * Start index for the custom handles in an mxMouseEvent. This should be a
  9161. * negative value and is the start index which is decremented for each
  9162. * custom handle. Default is -100.
  9163. */
  9164. CUSTOM_HANDLE: -100,
  9165. /**
  9166. * Variable: VIRTUAL_HANDLE
  9167. *
  9168. * Start index for the virtual handles in an mxMouseEvent. This should be a
  9169. * negative value and is the start index which is decremented for each
  9170. * virtual handle. Default is -100000. This assumes that there are no more
  9171. * than VIRTUAL_HANDLE - CUSTOM_HANDLE custom handles.
  9172. *
  9173. */
  9174. VIRTUAL_HANDLE: -100000,
  9175. //
  9176. // Event names
  9177. //
  9178. /**
  9179. * Variable: MOUSE_DOWN
  9180. *
  9181. * Specifies the event name for mouseDown.
  9182. */
  9183. MOUSE_DOWN: 'mouseDown',
  9184. /**
  9185. * Variable: MOUSE_MOVE
  9186. *
  9187. * Specifies the event name for mouseMove.
  9188. */
  9189. MOUSE_MOVE: 'mouseMove',
  9190. /**
  9191. * Variable: MOUSE_UP
  9192. *
  9193. * Specifies the event name for mouseUp.
  9194. */
  9195. MOUSE_UP: 'mouseUp',
  9196. /**
  9197. * Variable: ACTIVATE
  9198. *
  9199. * Specifies the event name for activate.
  9200. */
  9201. ACTIVATE: 'activate',
  9202. /**
  9203. * Variable: RESIZE_START
  9204. *
  9205. * Specifies the event name for resizeStart.
  9206. */
  9207. RESIZE_START: 'resizeStart',
  9208. /**
  9209. * Variable: RESIZE
  9210. *
  9211. * Specifies the event name for resize.
  9212. */
  9213. RESIZE: 'resize',
  9214. /**
  9215. * Variable: RESIZE_END
  9216. *
  9217. * Specifies the event name for resizeEnd.
  9218. */
  9219. RESIZE_END: 'resizeEnd',
  9220. /**
  9221. * Variable: MOVE_START
  9222. *
  9223. * Specifies the event name for moveStart.
  9224. */
  9225. MOVE_START: 'moveStart',
  9226. /**
  9227. * Variable: MOVE
  9228. *
  9229. * Specifies the event name for move.
  9230. */
  9231. MOVE: 'move',
  9232. /**
  9233. * Variable: MOVE_END
  9234. *
  9235. * Specifies the event name for moveEnd.
  9236. */
  9237. MOVE_END: 'moveEnd',
  9238. /**
  9239. * Variable: PAN_START
  9240. *
  9241. * Specifies the event name for panStart.
  9242. */
  9243. PAN_START: 'panStart',
  9244. /**
  9245. * Variable: PAN
  9246. *
  9247. * Specifies the event name for pan.
  9248. */
  9249. PAN: 'pan',
  9250. /**
  9251. * Variable: PAN_END
  9252. *
  9253. * Specifies the event name for panEnd.
  9254. */
  9255. PAN_END: 'panEnd',
  9256. /**
  9257. * Variable: MINIMIZE
  9258. *
  9259. * Specifies the event name for minimize.
  9260. */
  9261. MINIMIZE: 'minimize',
  9262. /**
  9263. * Variable: NORMALIZE
  9264. *
  9265. * Specifies the event name for normalize.
  9266. */
  9267. NORMALIZE: 'normalize',
  9268. /**
  9269. * Variable: MAXIMIZE
  9270. *
  9271. * Specifies the event name for maximize.
  9272. */
  9273. MAXIMIZE: 'maximize',
  9274. /**
  9275. * Variable: HIDE
  9276. *
  9277. * Specifies the event name for hide.
  9278. */
  9279. HIDE: 'hide',
  9280. /**
  9281. * Variable: SHOW
  9282. *
  9283. * Specifies the event name for show.
  9284. */
  9285. SHOW: 'show',
  9286. /**
  9287. * Variable: CLOSE
  9288. *
  9289. * Specifies the event name for close.
  9290. */
  9291. CLOSE: 'close',
  9292. /**
  9293. * Variable: DESTROY
  9294. *
  9295. * Specifies the event name for destroy.
  9296. */
  9297. DESTROY: 'destroy',
  9298. /**
  9299. * Variable: REFRESH
  9300. *
  9301. * Specifies the event name for refresh.
  9302. */
  9303. REFRESH: 'refresh',
  9304. /**
  9305. * Variable: SIZE
  9306. *
  9307. * Specifies the event name for size.
  9308. */
  9309. SIZE: 'size',
  9310. /**
  9311. * Variable: SELECT
  9312. *
  9313. * Specifies the event name for select.
  9314. */
  9315. SELECT: 'select',
  9316. /**
  9317. * Variable: FIRED
  9318. *
  9319. * Specifies the event name for fired.
  9320. */
  9321. FIRED: 'fired',
  9322. /**
  9323. * Variable: FIRE_MOUSE_EVENT
  9324. *
  9325. * Specifies the event name for fireMouseEvent.
  9326. */
  9327. FIRE_MOUSE_EVENT: 'fireMouseEvent',
  9328. /**
  9329. * Variable: GESTURE
  9330. *
  9331. * Specifies the event name for gesture.
  9332. */
  9333. GESTURE: 'gesture',
  9334. /**
  9335. * Variable: TAP_AND_HOLD
  9336. *
  9337. * Specifies the event name for tapAndHold.
  9338. */
  9339. TAP_AND_HOLD: 'tapAndHold',
  9340. /**
  9341. * Variable: GET
  9342. *
  9343. * Specifies the event name for get.
  9344. */
  9345. GET: 'get',
  9346. /**
  9347. * Variable: RECEIVE
  9348. *
  9349. * Specifies the event name for receive.
  9350. */
  9351. RECEIVE: 'receive',
  9352. /**
  9353. * Variable: CONNECT
  9354. *
  9355. * Specifies the event name for connect.
  9356. */
  9357. CONNECT: 'connect',
  9358. /**
  9359. * Variable: DISCONNECT
  9360. *
  9361. * Specifies the event name for disconnect.
  9362. */
  9363. DISCONNECT: 'disconnect',
  9364. /**
  9365. * Variable: SUSPEND
  9366. *
  9367. * Specifies the event name for suspend.
  9368. */
  9369. SUSPEND: 'suspend',
  9370. /**
  9371. * Variable: RESUME
  9372. *
  9373. * Specifies the event name for suspend.
  9374. */
  9375. RESUME: 'resume',
  9376. /**
  9377. * Variable: MARK
  9378. *
  9379. * Specifies the event name for mark.
  9380. */
  9381. MARK: 'mark',
  9382. /**
  9383. * Variable: ROOT
  9384. *
  9385. * Specifies the event name for root.
  9386. */
  9387. ROOT: 'root',
  9388. /**
  9389. * Variable: POST
  9390. *
  9391. * Specifies the event name for post.
  9392. */
  9393. POST: 'post',
  9394. /**
  9395. * Variable: OPEN
  9396. *
  9397. * Specifies the event name for open.
  9398. */
  9399. OPEN: 'open',
  9400. /**
  9401. * Variable: SAVE
  9402. *
  9403. * Specifies the event name for open.
  9404. */
  9405. SAVE: 'save',
  9406. /**
  9407. * Variable: BEFORE_ADD_VERTEX
  9408. *
  9409. * Specifies the event name for beforeAddVertex.
  9410. */
  9411. BEFORE_ADD_VERTEX: 'beforeAddVertex',
  9412. /**
  9413. * Variable: ADD_VERTEX
  9414. *
  9415. * Specifies the event name for addVertex.
  9416. */
  9417. ADD_VERTEX: 'addVertex',
  9418. /**
  9419. * Variable: AFTER_ADD_VERTEX
  9420. *
  9421. * Specifies the event name for afterAddVertex.
  9422. */
  9423. AFTER_ADD_VERTEX: 'afterAddVertex',
  9424. /**
  9425. * Variable: DONE
  9426. *
  9427. * Specifies the event name for done.
  9428. */
  9429. DONE: 'done',
  9430. /**
  9431. * Variable: EXECUTE
  9432. *
  9433. * Specifies the event name for execute.
  9434. */
  9435. EXECUTE: 'execute',
  9436. /**
  9437. * Variable: EXECUTED
  9438. *
  9439. * Specifies the event name for executed.
  9440. */
  9441. EXECUTED: 'executed',
  9442. /**
  9443. * Variable: BEGIN_UPDATE
  9444. *
  9445. * Specifies the event name for beginUpdate.
  9446. */
  9447. BEGIN_UPDATE: 'beginUpdate',
  9448. /**
  9449. * Variable: START_EDIT
  9450. *
  9451. * Specifies the event name for startEdit.
  9452. */
  9453. START_EDIT: 'startEdit',
  9454. /**
  9455. * Variable: END_UPDATE
  9456. *
  9457. * Specifies the event name for endUpdate.
  9458. */
  9459. END_UPDATE: 'endUpdate',
  9460. /**
  9461. * Variable: END_EDIT
  9462. *
  9463. * Specifies the event name for endEdit.
  9464. */
  9465. END_EDIT: 'endEdit',
  9466. /**
  9467. * Variable: BEFORE_UNDO
  9468. *
  9469. * Specifies the event name for beforeUndo.
  9470. */
  9471. BEFORE_UNDO: 'beforeUndo',
  9472. /**
  9473. * Variable: UNDO
  9474. *
  9475. * Specifies the event name for undo.
  9476. */
  9477. UNDO: 'undo',
  9478. /**
  9479. * Variable: REDO
  9480. *
  9481. * Specifies the event name for redo.
  9482. */
  9483. REDO: 'redo',
  9484. /**
  9485. * Variable: CHANGE
  9486. *
  9487. * Specifies the event name for change.
  9488. */
  9489. CHANGE: 'change',
  9490. /**
  9491. * Variable: NOTIFY
  9492. *
  9493. * Specifies the event name for notify.
  9494. */
  9495. NOTIFY: 'notify',
  9496. /**
  9497. * Variable: LAYOUT_CELLS
  9498. *
  9499. * Specifies the event name for layoutCells.
  9500. */
  9501. LAYOUT_CELLS: 'layoutCells',
  9502. /**
  9503. * Variable: CLICK
  9504. *
  9505. * Specifies the event name for click.
  9506. */
  9507. CLICK: 'click',
  9508. /**
  9509. * Variable: SCALE
  9510. *
  9511. * Specifies the event name for scale.
  9512. */
  9513. SCALE: 'scale',
  9514. /**
  9515. * Variable: TRANSLATE
  9516. *
  9517. * Specifies the event name for translate.
  9518. */
  9519. TRANSLATE: 'translate',
  9520. /**
  9521. * Variable: SCALE_AND_TRANSLATE
  9522. *
  9523. * Specifies the event name for scaleAndTranslate.
  9524. */
  9525. SCALE_AND_TRANSLATE: 'scaleAndTranslate',
  9526. /**
  9527. * Variable: UP
  9528. *
  9529. * Specifies the event name for up.
  9530. */
  9531. UP: 'up',
  9532. /**
  9533. * Variable: DOWN
  9534. *
  9535. * Specifies the event name for down.
  9536. */
  9537. DOWN: 'down',
  9538. /**
  9539. * Variable: ADD
  9540. *
  9541. * Specifies the event name for add.
  9542. */
  9543. ADD: 'add',
  9544. /**
  9545. * Variable: REMOVE
  9546. *
  9547. * Specifies the event name for remove.
  9548. */
  9549. REMOVE: 'remove',
  9550. /**
  9551. * Variable: CLEAR
  9552. *
  9553. * Specifies the event name for clear.
  9554. */
  9555. CLEAR: 'clear',
  9556. /**
  9557. * Variable: ADD_CELLS
  9558. *
  9559. * Specifies the event name for addCells.
  9560. */
  9561. ADD_CELLS: 'addCells',
  9562. /**
  9563. * Variable: CELLS_ADDED
  9564. *
  9565. * Specifies the event name for cellsAdded.
  9566. */
  9567. CELLS_ADDED: 'cellsAdded',
  9568. /**
  9569. * Variable: MOVE_CELLS
  9570. *
  9571. * Specifies the event name for moveCells.
  9572. */
  9573. MOVE_CELLS: 'moveCells',
  9574. /**
  9575. * Variable: CELLS_MOVED
  9576. *
  9577. * Specifies the event name for cellsMoved.
  9578. */
  9579. CELLS_MOVED: 'cellsMoved',
  9580. /**
  9581. * Variable: RESIZE_CELLS
  9582. *
  9583. * Specifies the event name for resizeCells.
  9584. */
  9585. RESIZE_CELLS: 'resizeCells',
  9586. /**
  9587. * Variable: CELLS_RESIZED
  9588. *
  9589. * Specifies the event name for cellsResized.
  9590. */
  9591. CELLS_RESIZED: 'cellsResized',
  9592. /**
  9593. * Variable: TOGGLE_CELLS
  9594. *
  9595. * Specifies the event name for toggleCells.
  9596. */
  9597. TOGGLE_CELLS: 'toggleCells',
  9598. /**
  9599. * Variable: CELLS_TOGGLED
  9600. *
  9601. * Specifies the event name for cellsToggled.
  9602. */
  9603. CELLS_TOGGLED: 'cellsToggled',
  9604. /**
  9605. * Variable: ORDER_CELLS
  9606. *
  9607. * Specifies the event name for orderCells.
  9608. */
  9609. ORDER_CELLS: 'orderCells',
  9610. /**
  9611. * Variable: CELLS_ORDERED
  9612. *
  9613. * Specifies the event name for cellsOrdered.
  9614. */
  9615. CELLS_ORDERED: 'cellsOrdered',
  9616. /**
  9617. * Variable: REMOVE_CELLS
  9618. *
  9619. * Specifies the event name for removeCells.
  9620. */
  9621. REMOVE_CELLS: 'removeCells',
  9622. /**
  9623. * Variable: CELLS_REMOVED
  9624. *
  9625. * Specifies the event name for cellsRemoved.
  9626. */
  9627. CELLS_REMOVED: 'cellsRemoved',
  9628. /**
  9629. * Variable: GROUP_CELLS
  9630. *
  9631. * Specifies the event name for groupCells.
  9632. */
  9633. GROUP_CELLS: 'groupCells',
  9634. /**
  9635. * Variable: UNGROUP_CELLS
  9636. *
  9637. * Specifies the event name for ungroupCells.
  9638. */
  9639. UNGROUP_CELLS: 'ungroupCells',
  9640. /**
  9641. * Variable: REMOVE_CELLS_FROM_PARENT
  9642. *
  9643. * Specifies the event name for removeCellsFromParent.
  9644. */
  9645. REMOVE_CELLS_FROM_PARENT: 'removeCellsFromParent',
  9646. /**
  9647. * Variable: FOLD_CELLS
  9648. *
  9649. * Specifies the event name for foldCells.
  9650. */
  9651. FOLD_CELLS: 'foldCells',
  9652. /**
  9653. * Variable: CELLS_FOLDED
  9654. *
  9655. * Specifies the event name for cellsFolded.
  9656. */
  9657. CELLS_FOLDED: 'cellsFolded',
  9658. /**
  9659. * Variable: ALIGN_CELLS
  9660. *
  9661. * Specifies the event name for alignCells.
  9662. */
  9663. ALIGN_CELLS: 'alignCells',
  9664. /**
  9665. * Variable: LABEL_CHANGED
  9666. *
  9667. * Specifies the event name for labelChanged.
  9668. */
  9669. LABEL_CHANGED: 'labelChanged',
  9670. /**
  9671. * Variable: CONNECT_CELL
  9672. *
  9673. * Specifies the event name for connectCell.
  9674. */
  9675. CONNECT_CELL: 'connectCell',
  9676. /**
  9677. * Variable: CELL_CONNECTED
  9678. *
  9679. * Specifies the event name for cellConnected.
  9680. */
  9681. CELL_CONNECTED: 'cellConnected',
  9682. /**
  9683. * Variable: SPLIT_EDGE
  9684. *
  9685. * Specifies the event name for splitEdge.
  9686. */
  9687. SPLIT_EDGE: 'splitEdge',
  9688. /**
  9689. * Variable: FLIP_EDGE
  9690. *
  9691. * Specifies the event name for flipEdge.
  9692. */
  9693. FLIP_EDGE: 'flipEdge',
  9694. /**
  9695. * Variable: START_EDITING
  9696. *
  9697. * Specifies the event name for startEditing.
  9698. */
  9699. START_EDITING: 'startEditing',
  9700. /**
  9701. * Variable: EDITING_STARTED
  9702. *
  9703. * Specifies the event name for editingStarted.
  9704. */
  9705. EDITING_STARTED: 'editingStarted',
  9706. /**
  9707. * Variable: EDITING_STOPPED
  9708. *
  9709. * Specifies the event name for editingStopped.
  9710. */
  9711. EDITING_STOPPED: 'editingStopped',
  9712. /**
  9713. * Variable: ADD_OVERLAY
  9714. *
  9715. * Specifies the event name for addOverlay.
  9716. */
  9717. ADD_OVERLAY: 'addOverlay',
  9718. /**
  9719. * Variable: REMOVE_OVERLAY
  9720. *
  9721. * Specifies the event name for removeOverlay.
  9722. */
  9723. REMOVE_OVERLAY: 'removeOverlay',
  9724. /**
  9725. * Variable: UPDATE_CELL_SIZE
  9726. *
  9727. * Specifies the event name for updateCellSize.
  9728. */
  9729. UPDATE_CELL_SIZE: 'updateCellSize',
  9730. /**
  9731. * Variable: ESCAPE
  9732. *
  9733. * Specifies the event name for escape.
  9734. */
  9735. ESCAPE: 'escape',
  9736. /**
  9737. * Variable: DOUBLE_CLICK
  9738. *
  9739. * Specifies the event name for doubleClick.
  9740. */
  9741. DOUBLE_CLICK: 'doubleClick',
  9742. /**
  9743. * Variable: START
  9744. *
  9745. * Specifies the event name for start.
  9746. */
  9747. START: 'start',
  9748. /**
  9749. * Variable: RESET
  9750. *
  9751. * Specifies the event name for reset.
  9752. */
  9753. RESET: 'reset'
  9754. };
  9755. /**
  9756. * Copyright (c) 2006-2020, JGraph Ltd
  9757. * Copyright (c) 2006-2020, draw.io AG
  9758. */
  9759. /**
  9760. * Class: mxXmlRequest
  9761. *
  9762. * XML HTTP request wrapper. See also: <mxUtils.get>, <mxUtils.post> and
  9763. * <mxUtils.load>. This class provides a cross-browser abstraction for Ajax
  9764. * requests.
  9765. *
  9766. * Encoding:
  9767. *
  9768. * For encoding parameter values, the built-in encodeURIComponent JavaScript
  9769. * method must be used. For automatic encoding of post data in <mxEditor> the
  9770. * <mxEditor.escapePostData> switch can be set to true (default). The encoding
  9771. * will be carried out using the conte type of the page. That is, the page
  9772. * containting the editor should contain a meta tag in the header, eg.
  9773. * <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9774. *
  9775. * Example:
  9776. *
  9777. * (code)
  9778. * var onload = function(req)
  9779. * {
  9780. * mxUtils.alert(req.getDocumentElement());
  9781. * }
  9782. *
  9783. * var onerror = function(req)
  9784. * {
  9785. * mxUtils.alert('Error');
  9786. * }
  9787. * new mxXmlRequest(url, 'key=value').send(onload, onerror);
  9788. * (end)
  9789. *
  9790. * Sends an asynchronous POST request to the specified URL.
  9791. *
  9792. * Example:
  9793. *
  9794. * (code)
  9795. * var req = new mxXmlRequest(url, 'key=value', 'POST', false);
  9796. * req.send();
  9797. * mxUtils.alert(req.getDocumentElement());
  9798. * (end)
  9799. *
  9800. * Sends a synchronous POST request to the specified URL.
  9801. *
  9802. * Example:
  9803. *
  9804. * (code)
  9805. * var encoder = new mxCodec();
  9806. * var result = encoder.encode(graph.getModel());
  9807. * var xml = encodeURIComponent(mxUtils.getXml(result));
  9808. * new mxXmlRequest(url, 'xml='+xml).send();
  9809. * (end)
  9810. *
  9811. * Sends an encoded graph model to the specified URL using xml as the
  9812. * parameter name. The parameter can then be retrieved in C# as follows:
  9813. *
  9814. * (code)
  9815. * string xml = HttpUtility.UrlDecode(context.Request.Params["xml"]);
  9816. * (end)
  9817. *
  9818. * Or in Java as follows:
  9819. *
  9820. * (code)
  9821. * String xml = URLDecoder.decode(request.getParameter("xml"), "UTF-8").replace("\n", "&#xa;");
  9822. * (end)
  9823. *
  9824. * Note that the linefeeds should only be replaced if the XML is
  9825. * processed in Java, for example when creating an image.
  9826. *
  9827. * Constructor: mxXmlRequest
  9828. *
  9829. * Constructs an XML HTTP request.
  9830. *
  9831. * Parameters:
  9832. *
  9833. * url - Target URL of the request.
  9834. * params - Form encoded parameters to send with a POST request.
  9835. * method - String that specifies the request method. Possible values are
  9836. * POST and GET. Default is POST.
  9837. * async - Boolean specifying if an asynchronous request should be used.
  9838. * Default is true.
  9839. * username - String specifying the username to be used for the request.
  9840. * password - String specifying the password to be used for the request.
  9841. */
  9842. function mxXmlRequest(url, params, method, async, username, password)
  9843. {
  9844. this.url = url;
  9845. this.params = params;
  9846. this.method = method || 'POST';
  9847. this.async = (async != null) ? async : true;
  9848. this.username = username;
  9849. this.password = password;
  9850. };
  9851. /**
  9852. * Variable: url
  9853. *
  9854. * Holds the target URL of the request.
  9855. */
  9856. mxXmlRequest.prototype.url = null;
  9857. /**
  9858. * Variable: params
  9859. *
  9860. * Holds the form encoded data for the POST request.
  9861. */
  9862. mxXmlRequest.prototype.params = null;
  9863. /**
  9864. * Variable: method
  9865. *
  9866. * Specifies the request method. Possible values are POST and GET. Default
  9867. * is POST.
  9868. */
  9869. mxXmlRequest.prototype.method = null;
  9870. /**
  9871. * Variable: async
  9872. *
  9873. * Boolean indicating if the request is asynchronous.
  9874. */
  9875. mxXmlRequest.prototype.async = null;
  9876. /**
  9877. * Variable: binary
  9878. *
  9879. * Boolean indicating if the request is binary. This option is ignored in IE.
  9880. * In all other browsers the requested mime type is set to
  9881. * text/plain; charset=x-user-defined. Default is false.
  9882. */
  9883. mxXmlRequest.prototype.binary = false;
  9884. /**
  9885. * Variable: withCredentials
  9886. *
  9887. * Specifies if withCredentials should be used in HTML5-compliant browsers. Default is
  9888. * false.
  9889. */
  9890. mxXmlRequest.prototype.withCredentials = false;
  9891. /**
  9892. * Variable: username
  9893. *
  9894. * Specifies the username to be used for authentication.
  9895. */
  9896. mxXmlRequest.prototype.username = null;
  9897. /**
  9898. * Variable: password
  9899. *
  9900. * Specifies the password to be used for authentication.
  9901. */
  9902. mxXmlRequest.prototype.password = null;
  9903. /**
  9904. * Variable: request
  9905. *
  9906. * Holds the inner, browser-specific request object.
  9907. */
  9908. mxXmlRequest.prototype.request = null;
  9909. /**
  9910. * Variable: decodeSimulateValues
  9911. *
  9912. * Specifies if request values should be decoded as URIs before setting the
  9913. * textarea value in <simulate>. Defaults to false for backwards compatibility,
  9914. * to avoid another decode on the server this should be set to true.
  9915. */
  9916. mxXmlRequest.prototype.decodeSimulateValues = false;
  9917. /**
  9918. * Function: isBinary
  9919. *
  9920. * Returns <binary>.
  9921. */
  9922. mxXmlRequest.prototype.isBinary = function()
  9923. {
  9924. return this.binary;
  9925. };
  9926. /**
  9927. * Function: setBinary
  9928. *
  9929. * Sets <binary>.
  9930. */
  9931. mxXmlRequest.prototype.setBinary = function(value)
  9932. {
  9933. this.binary = value;
  9934. };
  9935. /**
  9936. * Function: getText
  9937. *
  9938. * Returns the response as a string.
  9939. */
  9940. mxXmlRequest.prototype.getText = function()
  9941. {
  9942. return this.request.responseText;
  9943. };
  9944. /**
  9945. * Function: isReady
  9946. *
  9947. * Returns true if the response is ready.
  9948. */
  9949. mxXmlRequest.prototype.isReady = function()
  9950. {
  9951. return this.request.readyState == 4;
  9952. };
  9953. /**
  9954. * Function: getDocumentElement
  9955. *
  9956. * Returns the document element of the response XML document.
  9957. */
  9958. mxXmlRequest.prototype.getDocumentElement = function()
  9959. {
  9960. var doc = this.getXml();
  9961. if (doc != null)
  9962. {
  9963. return doc.documentElement;
  9964. }
  9965. return null;
  9966. };
  9967. /**
  9968. * Function: getXml
  9969. *
  9970. * Returns the response as an XML document. Use <getDocumentElement> to get
  9971. * the document element of the XML document.
  9972. */
  9973. mxXmlRequest.prototype.getXml = function()
  9974. {
  9975. var xml = this.request.responseXML;
  9976. // Handles missing response headers in IE, the first condition handles
  9977. // the case where responseXML is there, but using its nodes leads to
  9978. // type errors in the mxCellCodec when putting the nodes into a new
  9979. // document. This happens in IE9 standards mode and with XML user
  9980. // objects only, as they are used directly as values in cells.
  9981. if (document.documentMode >= 9 || xml == null || xml.documentElement == null)
  9982. {
  9983. xml = mxUtils.parseXml(this.request.responseText);
  9984. }
  9985. return xml;
  9986. };
  9987. /**
  9988. * Function: getText
  9989. *
  9990. * Returns the response as a string.
  9991. */
  9992. mxXmlRequest.prototype.getText = function()
  9993. {
  9994. return this.request.responseText;
  9995. };
  9996. /**
  9997. * Function: getStatus
  9998. *
  9999. * Returns the status as a number, eg. 404 for "Not found" or 200 for "OK".
  10000. * Note: The NS_ERROR_NOT_AVAILABLE for invalid responses cannot be cought.
  10001. */
  10002. mxXmlRequest.prototype.getStatus = function()
  10003. {
  10004. return (this.request != null) ? this.request.status : null;
  10005. };
  10006. /**
  10007. * Function: create
  10008. *
  10009. * Creates and returns the inner <request> object.
  10010. */
  10011. mxXmlRequest.prototype.create = function()
  10012. {
  10013. if (window.XMLHttpRequest)
  10014. {
  10015. return function()
  10016. {
  10017. var req = new XMLHttpRequest();
  10018. // TODO: Check for overrideMimeType required here?
  10019. if (this.isBinary() && req.overrideMimeType)
  10020. {
  10021. req.overrideMimeType('text/plain; charset=x-user-defined');
  10022. }
  10023. return req;
  10024. };
  10025. }
  10026. else if (typeof(ActiveXObject) != 'undefined')
  10027. {
  10028. return function()
  10029. {
  10030. // TODO: Implement binary option
  10031. return new ActiveXObject('Microsoft.XMLHTTP');
  10032. };
  10033. }
  10034. }();
  10035. /**
  10036. * Function: send
  10037. *
  10038. * Send the <request> to the target URL using the specified functions to
  10039. * process the response asychronously.
  10040. *
  10041. * Note: Due to technical limitations, onerror is currently ignored.
  10042. *
  10043. * Parameters:
  10044. *
  10045. * onload - Function to be invoked if a successful response was received.
  10046. * onerror - Function to be called on any error.
  10047. * timeout - Optional timeout in ms before calling ontimeout.
  10048. * ontimeout - Optional function to execute on timeout.
  10049. */
  10050. mxXmlRequest.prototype.send = function(onload, onerror, timeout, ontimeout)
  10051. {
  10052. this.request = this.create();
  10053. if (this.request != null)
  10054. {
  10055. if (onload != null)
  10056. {
  10057. this.request.onreadystatechange = mxUtils.bind(this, function()
  10058. {
  10059. if (this.isReady())
  10060. {
  10061. onload(this);
  10062. this.request.onreadystatechange = null;
  10063. }
  10064. });
  10065. }
  10066. this.request.open(this.method, this.url, this.async,
  10067. this.username, this.password);
  10068. this.setRequestHeaders(this.request, this.params);
  10069. if (window.XMLHttpRequest && this.withCredentials)
  10070. {
  10071. this.request.withCredentials = 'true';
  10072. }
  10073. if (!mxClient.IS_QUIRKS && (document.documentMode == null || document.documentMode > 9) &&
  10074. window.XMLHttpRequest && timeout != null && ontimeout != null)
  10075. {
  10076. this.request.timeout = timeout;
  10077. this.request.ontimeout = ontimeout;
  10078. }
  10079. this.request.send(this.params);
  10080. }
  10081. };
  10082. /**
  10083. * Function: setRequestHeaders
  10084. *
  10085. * Sets the headers for the given request and parameters. This sets the
  10086. * content-type to application/x-www-form-urlencoded if any params exist.
  10087. *
  10088. * Example:
  10089. *
  10090. * (code)
  10091. * request.setRequestHeaders = function(request, params)
  10092. * {
  10093. * if (params != null)
  10094. * {
  10095. * request.setRequestHeader('Content-Type',
  10096. * 'multipart/form-data');
  10097. * request.setRequestHeader('Content-Length',
  10098. * params.length);
  10099. * }
  10100. * };
  10101. * (end)
  10102. *
  10103. * Use the code above before calling <send> if you require a
  10104. * multipart/form-data request.
  10105. */
  10106. mxXmlRequest.prototype.setRequestHeaders = function(request, params)
  10107. {
  10108. if (params != null)
  10109. {
  10110. request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  10111. }
  10112. };
  10113. /**
  10114. * Function: simulate
  10115. *
  10116. * Creates and posts a request to the given target URL using a dynamically
  10117. * created form inside the given document.
  10118. *
  10119. * Parameters:
  10120. *
  10121. * docs - Document that contains the form element.
  10122. * target - Target to send the form result to.
  10123. */
  10124. mxXmlRequest.prototype.simulate = function(doc, target)
  10125. {
  10126. doc = doc || document;
  10127. var old = null;
  10128. if (doc == document)
  10129. {
  10130. old = window.onbeforeunload;
  10131. window.onbeforeunload = null;
  10132. }
  10133. var form = doc.createElement('form');
  10134. form.setAttribute('method', this.method);
  10135. form.setAttribute('action', this.url);
  10136. if (target != null)
  10137. {
  10138. form.setAttribute('target', target);
  10139. }
  10140. form.style.display = 'none';
  10141. form.style.visibility = 'hidden';
  10142. var pars = (this.params.indexOf('&') > 0) ?
  10143. this.params.split('&') :
  10144. this.params.split();
  10145. // Adds the parameters as textareas to the form
  10146. for (var i=0; i<pars.length; i++)
  10147. {
  10148. var pos = pars[i].indexOf('=');
  10149. if (pos > 0)
  10150. {
  10151. var name = pars[i].substring(0, pos);
  10152. var value = pars[i].substring(pos+1);
  10153. if (this.decodeSimulateValues)
  10154. {
  10155. value = decodeURIComponent(value);
  10156. }
  10157. var textarea = doc.createElement('textarea');
  10158. textarea.setAttribute('wrap', 'off');
  10159. textarea.setAttribute('name', name);
  10160. mxUtils.write(textarea, value);
  10161. form.appendChild(textarea);
  10162. }
  10163. }
  10164. doc.body.appendChild(form);
  10165. form.submit();
  10166. if (form.parentNode != null)
  10167. {
  10168. form.parentNode.removeChild(form);
  10169. }
  10170. if (old != null)
  10171. {
  10172. window.onbeforeunload = old;
  10173. }
  10174. };
  10175. /**
  10176. * Copyright (c) 2006-2015, JGraph Ltd
  10177. * Copyright (c) 2006-2015, Gaudenz Alder
  10178. */
  10179. var mxClipboard =
  10180. {
  10181. /**
  10182. * Class: mxClipboard
  10183. *
  10184. * Singleton that implements a clipboard for graph cells.
  10185. *
  10186. * Example:
  10187. *
  10188. * (code)
  10189. * mxClipboard.copy(graph);
  10190. * mxClipboard.paste(graph2);
  10191. * (end)
  10192. *
  10193. * This copies the selection cells from the graph to the clipboard and
  10194. * pastes them into graph2.
  10195. *
  10196. * For fine-grained control of the clipboard data the <mxGraph.canExportCell>
  10197. * and <mxGraph.canImportCell> functions can be overridden.
  10198. *
  10199. * To restore previous parents for pasted cells, the implementation for
  10200. * <copy> and <paste> can be changed as follows.
  10201. *
  10202. * (code)
  10203. * mxClipboard.copy = function(graph, cells)
  10204. * {
  10205. * cells = cells || graph.getSelectionCells();
  10206. * var result = graph.getExportableCells(cells);
  10207. *
  10208. * mxClipboard.parents = new Object();
  10209. *
  10210. * for (var i = 0; i < result.length; i++)
  10211. * {
  10212. * mxClipboard.parents[i] = graph.model.getParent(cells[i]);
  10213. * }
  10214. *
  10215. * mxClipboard.insertCount = 1;
  10216. * mxClipboard.setCells(graph.cloneCells(result));
  10217. *
  10218. * return result;
  10219. * };
  10220. *
  10221. * mxClipboard.paste = function(graph)
  10222. * {
  10223. * if (!mxClipboard.isEmpty())
  10224. * {
  10225. * var cells = graph.getImportableCells(mxClipboard.getCells());
  10226. * var delta = mxClipboard.insertCount * mxClipboard.STEPSIZE;
  10227. * var parent = graph.getDefaultParent();
  10228. *
  10229. * graph.model.beginUpdate();
  10230. * try
  10231. * {
  10232. * for (var i = 0; i < cells.length; i++)
  10233. * {
  10234. * var tmp = (mxClipboard.parents != null && graph.model.contains(mxClipboard.parents[i])) ?
  10235. * mxClipboard.parents[i] : parent;
  10236. * cells[i] = graph.importCells([cells[i]], delta, delta, tmp)[0];
  10237. * }
  10238. * }
  10239. * finally
  10240. * {
  10241. * graph.model.endUpdate();
  10242. * }
  10243. *
  10244. * // Increments the counter and selects the inserted cells
  10245. * mxClipboard.insertCount++;
  10246. * graph.setSelectionCells(cells);
  10247. * }
  10248. * };
  10249. * (end)
  10250. *
  10251. * Variable: STEPSIZE
  10252. *
  10253. * Defines the step size to offset the cells after each paste operation.
  10254. * Default is 10.
  10255. */
  10256. STEPSIZE: 10,
  10257. /**
  10258. * Variable: insertCount
  10259. *
  10260. * Counts the number of times the clipboard data has been inserted.
  10261. */
  10262. insertCount: 1,
  10263. /**
  10264. * Variable: cells
  10265. *
  10266. * Holds the array of <mxCells> currently in the clipboard.
  10267. */
  10268. cells: null,
  10269. /**
  10270. * Function: setCells
  10271. *
  10272. * Sets the cells in the clipboard. Fires a <mxEvent.CHANGE> event.
  10273. */
  10274. setCells: function(cells)
  10275. {
  10276. mxClipboard.cells = cells;
  10277. },
  10278. /**
  10279. * Function: getCells
  10280. *
  10281. * Returns the cells in the clipboard.
  10282. */
  10283. getCells: function()
  10284. {
  10285. return mxClipboard.cells;
  10286. },
  10287. /**
  10288. * Function: isEmpty
  10289. *
  10290. * Returns true if the clipboard currently has not data stored.
  10291. */
  10292. isEmpty: function()
  10293. {
  10294. return mxClipboard.getCells() == null;
  10295. },
  10296. /**
  10297. * Function: cut
  10298. *
  10299. * Cuts the given array of <mxCells> from the specified graph.
  10300. * If cells is null then the selection cells of the graph will
  10301. * be used. Returns the cells that have been cut from the graph.
  10302. *
  10303. * Parameters:
  10304. *
  10305. * graph - <mxGraph> that contains the cells to be cut.
  10306. * cells - Optional array of <mxCells> to be cut.
  10307. */
  10308. cut: function(graph, cells)
  10309. {
  10310. cells = mxClipboard.copy(graph, cells);
  10311. mxClipboard.insertCount = 0;
  10312. mxClipboard.removeCells(graph, cells);
  10313. return cells;
  10314. },
  10315. /**
  10316. * Function: removeCells
  10317. *
  10318. * Hook to remove the given cells from the given graph after
  10319. * a cut operation.
  10320. *
  10321. * Parameters:
  10322. *
  10323. * graph - <mxGraph> that contains the cells to be cut.
  10324. * cells - Array of <mxCells> to be cut.
  10325. */
  10326. removeCells: function(graph, cells)
  10327. {
  10328. graph.removeCells(cells);
  10329. },
  10330. /**
  10331. * Function: copy
  10332. *
  10333. * Copies the given array of <mxCells> from the specified
  10334. * graph to <cells>. Returns the original array of cells that has
  10335. * been cloned. Descendants of cells in the array are ignored.
  10336. *
  10337. * Parameters:
  10338. *
  10339. * graph - <mxGraph> that contains the cells to be copied.
  10340. * cells - Optional array of <mxCells> to be copied.
  10341. */
  10342. copy: function(graph, cells)
  10343. {
  10344. cells = cells || graph.getSelectionCells();
  10345. var result = graph.getExportableCells(graph.model.getTopmostCells(cells));
  10346. mxClipboard.insertCount = 1;
  10347. mxClipboard.setCells(graph.cloneCells(result));
  10348. return result;
  10349. },
  10350. /**
  10351. * Function: paste
  10352. *
  10353. * Pastes the <cells> into the specified graph restoring
  10354. * the relation to <parents>, if possible. If the parents
  10355. * are no longer in the graph or invisible then the
  10356. * cells are added to the graph's default or into the
  10357. * swimlane under the cell's new location if one exists.
  10358. * The cells are added to the graph using <mxGraph.importCells>
  10359. * and returned.
  10360. *
  10361. * Parameters:
  10362. *
  10363. * graph - <mxGraph> to paste the <cells> into.
  10364. */
  10365. paste: function(graph)
  10366. {
  10367. var cells = null;
  10368. if (!mxClipboard.isEmpty())
  10369. {
  10370. cells = graph.getImportableCells(mxClipboard.getCells());
  10371. var delta = mxClipboard.insertCount * mxClipboard.STEPSIZE;
  10372. var parent = graph.getDefaultParent();
  10373. cells = graph.importCells(cells, delta, delta, parent);
  10374. // Increments the counter and selects the inserted cells
  10375. mxClipboard.insertCount++;
  10376. graph.setSelectionCells(cells);
  10377. }
  10378. return cells;
  10379. }
  10380. };
  10381. /**
  10382. * Copyright (c) 2006-2015, JGraph Ltd
  10383. * Copyright (c) 2006-2015, Gaudenz Alder
  10384. */
  10385. /**
  10386. * Class: mxWindow
  10387. *
  10388. * Basic window inside a document.
  10389. *
  10390. * Examples:
  10391. *
  10392. * Creating a simple window.
  10393. *
  10394. * (code)
  10395. * var tb = document.createElement('div');
  10396. * var wnd = new mxWindow('Title', tb, 100, 100, 200, 200, true, true);
  10397. * wnd.setVisible(true);
  10398. * (end)
  10399. *
  10400. * Creating a window that contains an iframe.
  10401. *
  10402. * (code)
  10403. * var frame = document.createElement('iframe');
  10404. * frame.setAttribute('width', '192px');
  10405. * frame.setAttribute('height', '172px');
  10406. * frame.setAttribute('src', 'http://www.example.com/');
  10407. * frame.style.backgroundColor = 'white';
  10408. *
  10409. * var w = document.body.clientWidth;
  10410. * var h = (document.body.clientHeight || document.documentElement.clientHeight);
  10411. * var wnd = new mxWindow('Title', frame, (w-200)/2, (h-200)/3, 200, 200);
  10412. * wnd.setVisible(true);
  10413. * (end)
  10414. *
  10415. * To limit the movement of a window, eg. to keep it from being moved beyond
  10416. * the top, left corner the following method can be overridden (recommended):
  10417. *
  10418. * (code)
  10419. * wnd.setLocation = function(x, y)
  10420. * {
  10421. * x = Math.max(0, x);
  10422. * y = Math.max(0, y);
  10423. * mxWindow.prototype.setLocation.apply(this, arguments);
  10424. * };
  10425. * (end)
  10426. *
  10427. * Or the following event handler can be used:
  10428. *
  10429. * (code)
  10430. * wnd.addListener(mxEvent.MOVE, function(e)
  10431. * {
  10432. * wnd.setLocation(Math.max(0, wnd.getX()), Math.max(0, wnd.getY()));
  10433. * });
  10434. * (end)
  10435. *
  10436. * To keep a window inside the current window:
  10437. *
  10438. * (code)
  10439. * mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
  10440. * {
  10441. * var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  10442. * var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  10443. *
  10444. * var x = this.window.getX();
  10445. * var y = this.window.getY();
  10446. *
  10447. * if (x + this.window.table.clientWidth > iw)
  10448. * {
  10449. * x = Math.max(0, iw - this.window.table.clientWidth);
  10450. * }
  10451. *
  10452. * if (y + this.window.table.clientHeight > ih)
  10453. * {
  10454. * y = Math.max(0, ih - this.window.table.clientHeight);
  10455. * }
  10456. *
  10457. * if (this.window.getX() != x || this.window.getY() != y)
  10458. * {
  10459. * this.window.setLocation(x, y);
  10460. * }
  10461. * }));
  10462. * (end)
  10463. *
  10464. * Event: mxEvent.MOVE_START
  10465. *
  10466. * Fires before the window is moved. The <code>event</code> property contains
  10467. * the corresponding mouse event.
  10468. *
  10469. * Event: mxEvent.MOVE
  10470. *
  10471. * Fires while the window is being moved. The <code>event</code> property
  10472. * contains the corresponding mouse event.
  10473. *
  10474. * Event: mxEvent.MOVE_END
  10475. *
  10476. * Fires after the window is moved. The <code>event</code> property contains
  10477. * the corresponding mouse event.
  10478. *
  10479. * Event: mxEvent.RESIZE_START
  10480. *
  10481. * Fires before the window is resized. The <code>event</code> property contains
  10482. * the corresponding mouse event.
  10483. *
  10484. * Event: mxEvent.RESIZE
  10485. *
  10486. * Fires while the window is being resized. The <code>event</code> property
  10487. * contains the corresponding mouse event.
  10488. *
  10489. * Event: mxEvent.RESIZE_END
  10490. *
  10491. * Fires after the window is resized. The <code>event</code> property contains
  10492. * the corresponding mouse event.
  10493. *
  10494. * Event: mxEvent.MAXIMIZE
  10495. *
  10496. * Fires after the window is maximized. The <code>event</code> property
  10497. * contains the corresponding mouse event.
  10498. *
  10499. * Event: mxEvent.MINIMIZE
  10500. *
  10501. * Fires after the window is minimized. The <code>event</code> property
  10502. * contains the corresponding mouse event.
  10503. *
  10504. * Event: mxEvent.NORMALIZE
  10505. *
  10506. * Fires after the window is normalized, that is, it returned from
  10507. * maximized or minimized state. The <code>event</code> property contains the
  10508. * corresponding mouse event.
  10509. *
  10510. * Event: mxEvent.ACTIVATE
  10511. *
  10512. * Fires after a window is activated. The <code>previousWindow</code> property
  10513. * contains the previous window. The event sender is the active window.
  10514. *
  10515. * Event: mxEvent.SHOW
  10516. *
  10517. * Fires after the window is shown. This event has no properties.
  10518. *
  10519. * Event: mxEvent.HIDE
  10520. *
  10521. * Fires after the window is hidden. This event has no properties.
  10522. *
  10523. * Event: mxEvent.CLOSE
  10524. *
  10525. * Fires before the window is closed. The <code>event</code> property contains
  10526. * the corresponding mouse event.
  10527. *
  10528. * Event: mxEvent.DESTROY
  10529. *
  10530. * Fires before the window is destroyed. This event has no properties.
  10531. *
  10532. * Constructor: mxWindow
  10533. *
  10534. * Constructs a new window with the given dimension and title to display
  10535. * the specified content. The window elements use the given style as a
  10536. * prefix for the classnames of the respective window elements, namely,
  10537. * the window title and window pane. The respective postfixes are appended
  10538. * to the given stylename as follows:
  10539. *
  10540. * style - Base style for the window.
  10541. * style+Title - Style for the window title.
  10542. * style+Pane - Style for the window pane.
  10543. *
  10544. * The default value for style is mxWindow, resulting in the following
  10545. * classnames for the window elements: mxWindow, mxWindowTitle and
  10546. * mxWindowPane.
  10547. *
  10548. * If replaceNode is given then the window replaces the given DOM node in
  10549. * the document.
  10550. *
  10551. * Parameters:
  10552. *
  10553. * title - String that represents the title of the new window.
  10554. * content - DOM node that is used as the window content.
  10555. * x - X-coordinate of the window location.
  10556. * y - Y-coordinate of the window location.
  10557. * width - Width of the window.
  10558. * height - Optional height of the window. Default is to match the height
  10559. * of the content at the specified width.
  10560. * minimizable - Optional boolean indicating if the window is minimizable.
  10561. * Default is true.
  10562. * movable - Optional boolean indicating if the window is movable. Default
  10563. * is true.
  10564. * replaceNode - Optional DOM node that the window should replace.
  10565. * style - Optional base classname for the window elements. Default is
  10566. * mxWindow.
  10567. */
  10568. function mxWindow(title, content, x, y, width, height, minimizable, movable, replaceNode, style)
  10569. {
  10570. if (content != null)
  10571. {
  10572. minimizable = (minimizable != null) ? minimizable : true;
  10573. this.content = content;
  10574. this.init(x, y, width, height, style);
  10575. this.installMaximizeHandler();
  10576. this.installMinimizeHandler();
  10577. this.installCloseHandler();
  10578. this.setMinimizable(minimizable);
  10579. this.setTitle(title);
  10580. if (movable == null || movable)
  10581. {
  10582. this.installMoveHandler();
  10583. }
  10584. if (replaceNode != null && replaceNode.parentNode != null)
  10585. {
  10586. replaceNode.parentNode.replaceChild(this.div, replaceNode);
  10587. }
  10588. else
  10589. {
  10590. document.body.appendChild(this.div);
  10591. }
  10592. }
  10593. };
  10594. /**
  10595. * Extends mxEventSource.
  10596. */
  10597. mxWindow.prototype = new mxEventSource();
  10598. mxWindow.prototype.constructor = mxWindow;
  10599. /**
  10600. * Variable: closeImage
  10601. *
  10602. * URL of the image to be used for the close icon in the titlebar.
  10603. */
  10604. mxWindow.prototype.closeImage = mxClient.imageBasePath + '/close.gif';
  10605. /**
  10606. * Variable: minimizeImage
  10607. *
  10608. * URL of the image to be used for the minimize icon in the titlebar.
  10609. */
  10610. mxWindow.prototype.minimizeImage = mxClient.imageBasePath + '/minimize.gif';
  10611. /**
  10612. * Variable: normalizeImage
  10613. *
  10614. * URL of the image to be used for the normalize icon in the titlebar.
  10615. */
  10616. mxWindow.prototype.normalizeImage = mxClient.imageBasePath + '/normalize.gif';
  10617. /**
  10618. * Variable: maximizeImage
  10619. *
  10620. * URL of the image to be used for the maximize icon in the titlebar.
  10621. */
  10622. mxWindow.prototype.maximizeImage = mxClient.imageBasePath + '/maximize.gif';
  10623. /**
  10624. * Variable: normalizeImage
  10625. *
  10626. * URL of the image to be used for the resize icon.
  10627. */
  10628. mxWindow.prototype.resizeImage = mxClient.imageBasePath + '/resize.gif';
  10629. /**
  10630. * Variable: visible
  10631. *
  10632. * Boolean flag that represents the visible state of the window.
  10633. */
  10634. mxWindow.prototype.visible = false;
  10635. /**
  10636. * Variable: minimumSize
  10637. *
  10638. * <mxRectangle> that specifies the minimum width and height of the window.
  10639. * Default is (50, 40).
  10640. */
  10641. mxWindow.prototype.minimumSize = new mxRectangle(0, 0, 50, 40);
  10642. /**
  10643. * Variable: destroyOnClose
  10644. *
  10645. * Specifies if the window should be destroyed when it is closed. If this
  10646. * is false then the window is hidden using <setVisible>. Default is true.
  10647. */
  10648. mxWindow.prototype.destroyOnClose = true;
  10649. /**
  10650. * Variable: contentHeightCorrection
  10651. *
  10652. * Defines the correction factor for computing the height of the contentWrapper.
  10653. * Default is 6 for IE 7/8 standards mode and 2 for all other browsers and modes.
  10654. */
  10655. mxWindow.prototype.contentHeightCorrection = (document.documentMode == 8 || document.documentMode == 7) ? 6 : 2;
  10656. /**
  10657. * Variable: title
  10658. *
  10659. * Reference to the DOM node (TD) that contains the title.
  10660. */
  10661. mxWindow.prototype.title = null;
  10662. /**
  10663. * Variable: content
  10664. *
  10665. * Reference to the DOM node that represents the window content.
  10666. */
  10667. mxWindow.prototype.content = null;
  10668. /**
  10669. * Function: init
  10670. *
  10671. * Initializes the DOM tree that represents the window.
  10672. */
  10673. mxWindow.prototype.init = function(x, y, width, height, style)
  10674. {
  10675. style = (style != null) ? style : 'mxWindow';
  10676. this.div = document.createElement('div');
  10677. this.div.className = style;
  10678. this.div.style.left = x + 'px';
  10679. this.div.style.top = y + 'px';
  10680. this.table = document.createElement('table');
  10681. this.table.className = style;
  10682. // Disables built-in pan and zoom in IE10 and later
  10683. if (mxClient.IS_POINTER)
  10684. {
  10685. this.div.style.touchAction = 'none';
  10686. }
  10687. // Workaround for table size problems in FF
  10688. if (width != null)
  10689. {
  10690. if (!mxClient.IS_QUIRKS)
  10691. {
  10692. this.div.style.width = width + 'px';
  10693. }
  10694. this.table.style.width = width + 'px';
  10695. }
  10696. if (height != null)
  10697. {
  10698. if (!mxClient.IS_QUIRKS)
  10699. {
  10700. this.div.style.height = height + 'px';
  10701. }
  10702. this.table.style.height = height + 'px';
  10703. }
  10704. // Creates title row
  10705. var tbody = document.createElement('tbody');
  10706. var tr = document.createElement('tr');
  10707. this.title = document.createElement('td');
  10708. this.title.className = style + 'Title';
  10709. this.buttons = document.createElement('div');
  10710. this.buttons.style.position = 'absolute';
  10711. this.buttons.style.display = 'inline-block';
  10712. this.buttons.style.right = '4px';
  10713. this.buttons.style.top = '5px';
  10714. this.title.appendChild(this.buttons);
  10715. tr.appendChild(this.title);
  10716. tbody.appendChild(tr);
  10717. // Creates content row and table cell
  10718. tr = document.createElement('tr');
  10719. this.td = document.createElement('td');
  10720. this.td.className = style + 'Pane';
  10721. if (document.documentMode == 7)
  10722. {
  10723. this.td.style.height = '100%';
  10724. }
  10725. this.contentWrapper = document.createElement('div');
  10726. this.contentWrapper.className = style + 'Pane';
  10727. this.contentWrapper.style.width = '100%';
  10728. this.contentWrapper.appendChild(this.content);
  10729. // Workaround for div around div restricts height
  10730. // of inner div if outerdiv has hidden overflow
  10731. if (mxClient.IS_QUIRKS || this.content.nodeName.toUpperCase() != 'DIV')
  10732. {
  10733. this.contentWrapper.style.height = '100%';
  10734. }
  10735. // Puts all content into the DOM
  10736. this.td.appendChild(this.contentWrapper);
  10737. tr.appendChild(this.td);
  10738. tbody.appendChild(tr);
  10739. this.table.appendChild(tbody);
  10740. this.div.appendChild(this.table);
  10741. // Puts the window on top of other windows when clicked
  10742. var activator = mxUtils.bind(this, function(evt)
  10743. {
  10744. this.activate();
  10745. });
  10746. mxEvent.addGestureListeners(this.title, activator);
  10747. mxEvent.addGestureListeners(this.table, activator);
  10748. this.hide();
  10749. };
  10750. /**
  10751. * Function: setTitle
  10752. *
  10753. * Sets the window title to the given string. HTML markup inside the title
  10754. * will be escaped.
  10755. */
  10756. mxWindow.prototype.setTitle = function(title)
  10757. {
  10758. // Removes all text content nodes (normally just one)
  10759. var child = this.title.firstChild;
  10760. while (child != null)
  10761. {
  10762. var next = child.nextSibling;
  10763. if (child.nodeType == mxConstants.NODETYPE_TEXT)
  10764. {
  10765. child.parentNode.removeChild(child);
  10766. }
  10767. child = next;
  10768. }
  10769. mxUtils.write(this.title, title || '');
  10770. this.title.appendChild(this.buttons);
  10771. };
  10772. /**
  10773. * Function: setScrollable
  10774. *
  10775. * Sets if the window contents should be scrollable.
  10776. */
  10777. mxWindow.prototype.setScrollable = function(scrollable)
  10778. {
  10779. // Workaround for hang in Presto 2.5.22 (Opera 10.5)
  10780. if (navigator.userAgent == null ||
  10781. navigator.userAgent.indexOf('Presto/2.5') < 0)
  10782. {
  10783. if (scrollable)
  10784. {
  10785. this.contentWrapper.style.overflow = 'auto';
  10786. }
  10787. else
  10788. {
  10789. this.contentWrapper.style.overflow = 'hidden';
  10790. }
  10791. }
  10792. };
  10793. /**
  10794. * Function: activate
  10795. *
  10796. * Puts the window on top of all other windows.
  10797. */
  10798. mxWindow.prototype.activate = function()
  10799. {
  10800. if (mxWindow.activeWindow != this)
  10801. {
  10802. var style = mxUtils.getCurrentStyle(this.getElement());
  10803. var index = (style != null) ? style.zIndex : 3;
  10804. if (mxWindow.activeWindow)
  10805. {
  10806. var elt = mxWindow.activeWindow.getElement();
  10807. if (elt != null && elt.style != null)
  10808. {
  10809. elt.style.zIndex = index;
  10810. }
  10811. }
  10812. var previousWindow = mxWindow.activeWindow;
  10813. this.getElement().style.zIndex = parseInt(index) + 1;
  10814. mxWindow.activeWindow = this;
  10815. this.fireEvent(new mxEventObject(mxEvent.ACTIVATE, 'previousWindow', previousWindow));
  10816. }
  10817. };
  10818. /**
  10819. * Function: getElement
  10820. *
  10821. * Returuns the outermost DOM node that makes up the window.
  10822. */
  10823. mxWindow.prototype.getElement = function()
  10824. {
  10825. return this.div;
  10826. };
  10827. /**
  10828. * Function: fit
  10829. *
  10830. * Makes sure the window is inside the client area of the window.
  10831. */
  10832. mxWindow.prototype.fit = function()
  10833. {
  10834. mxUtils.fit(this.div);
  10835. };
  10836. /**
  10837. * Function: isResizable
  10838. *
  10839. * Returns true if the window is resizable.
  10840. */
  10841. mxWindow.prototype.isResizable = function()
  10842. {
  10843. if (this.resize != null)
  10844. {
  10845. return this.resize.style.display != 'none';
  10846. }
  10847. return false;
  10848. };
  10849. /**
  10850. * Function: setResizable
  10851. *
  10852. * Sets if the window should be resizable. To avoid interference with some
  10853. * built-in features of IE10 and later, the use of the following code is
  10854. * recommended if there are resizable <mxWindow>s in the page:
  10855. *
  10856. * (code)
  10857. * if (mxClient.IS_POINTER)
  10858. * {
  10859. * document.body.style.msTouchAction = 'none';
  10860. * }
  10861. * (end)
  10862. */
  10863. mxWindow.prototype.setResizable = function(resizable)
  10864. {
  10865. if (resizable)
  10866. {
  10867. if (this.resize == null)
  10868. {
  10869. this.resize = document.createElement('img');
  10870. this.resize.style.position = 'absolute';
  10871. this.resize.style.bottom = '2px';
  10872. this.resize.style.right = '2px';
  10873. this.resize.setAttribute('src', this.resizeImage);
  10874. this.resize.style.cursor = 'nw-resize';
  10875. var startX = null;
  10876. var startY = null;
  10877. var width = null;
  10878. var height = null;
  10879. var start = mxUtils.bind(this, function(evt)
  10880. {
  10881. // LATER: pointerdown starting on border of resize does start
  10882. // the drag operation but does not fire consecutive events via
  10883. // one of the listeners below (does pan instead).
  10884. // Workaround: document.body.style.msTouchAction = 'none'
  10885. this.activate();
  10886. startX = mxEvent.getClientX(evt);
  10887. startY = mxEvent.getClientY(evt);
  10888. width = this.div.offsetWidth;
  10889. height = this.div.offsetHeight;
  10890. mxEvent.addGestureListeners(document, null, dragHandler, dropHandler);
  10891. this.fireEvent(new mxEventObject(mxEvent.RESIZE_START, 'event', evt));
  10892. mxEvent.consume(evt);
  10893. });
  10894. // Adds a temporary pair of listeners to intercept
  10895. // the gesture event in the document
  10896. var dragHandler = mxUtils.bind(this, function(evt)
  10897. {
  10898. if (startX != null && startY != null)
  10899. {
  10900. var dx = mxEvent.getClientX(evt) - startX;
  10901. var dy = mxEvent.getClientY(evt) - startY;
  10902. this.setSize(width + dx, height + dy);
  10903. this.fireEvent(new mxEventObject(mxEvent.RESIZE, 'event', evt));
  10904. mxEvent.consume(evt);
  10905. }
  10906. });
  10907. var dropHandler = mxUtils.bind(this, function(evt)
  10908. {
  10909. if (startX != null && startY != null)
  10910. {
  10911. startX = null;
  10912. startY = null;
  10913. mxEvent.removeGestureListeners(document, null, dragHandler, dropHandler);
  10914. this.fireEvent(new mxEventObject(mxEvent.RESIZE_END, 'event', evt));
  10915. mxEvent.consume(evt);
  10916. }
  10917. });
  10918. mxEvent.addGestureListeners(this.resize, start, dragHandler, dropHandler);
  10919. this.div.appendChild(this.resize);
  10920. }
  10921. else
  10922. {
  10923. this.resize.style.display = 'inline';
  10924. }
  10925. }
  10926. else if (this.resize != null)
  10927. {
  10928. this.resize.style.display = 'none';
  10929. }
  10930. };
  10931. /**
  10932. * Function: setSize
  10933. *
  10934. * Sets the size of the window.
  10935. */
  10936. mxWindow.prototype.setSize = function(width, height)
  10937. {
  10938. width = Math.max(this.minimumSize.width, width);
  10939. height = Math.max(this.minimumSize.height, height);
  10940. // Workaround for table size problems in FF
  10941. if (!mxClient.IS_QUIRKS)
  10942. {
  10943. this.div.style.width = width + 'px';
  10944. this.div.style.height = height + 'px';
  10945. }
  10946. this.table.style.width = width + 'px';
  10947. this.table.style.height = height + 'px';
  10948. if (!mxClient.IS_QUIRKS)
  10949. {
  10950. this.contentWrapper.style.height = (this.div.offsetHeight -
  10951. this.title.offsetHeight - this.contentHeightCorrection) + 'px';
  10952. }
  10953. };
  10954. /**
  10955. * Function: setMinimizable
  10956. *
  10957. * Sets if the window is minimizable.
  10958. */
  10959. mxWindow.prototype.setMinimizable = function(minimizable)
  10960. {
  10961. this.minimize.style.display = (minimizable) ? '' : 'none';
  10962. };
  10963. /**
  10964. * Function: getMinimumSize
  10965. *
  10966. * Returns an <mxRectangle> that specifies the size for the minimized window.
  10967. * A width or height of 0 means keep the existing width or height. This
  10968. * implementation returns the height of the window title and keeps the width.
  10969. */
  10970. mxWindow.prototype.getMinimumSize = function()
  10971. {
  10972. return new mxRectangle(0, 0, 0, this.title.offsetHeight);
  10973. };
  10974. /**
  10975. * Function: installMinimizeHandler
  10976. *
  10977. * Installs the event listeners required for minimizing the window.
  10978. */
  10979. mxWindow.prototype.installMinimizeHandler = function()
  10980. {
  10981. this.minimize = document.createElement('img');
  10982. this.minimize.setAttribute('src', this.minimizeImage);
  10983. this.minimize.setAttribute('title', 'Minimize');
  10984. this.minimize.style.cursor = 'pointer';
  10985. this.minimize.style.marginLeft = '2px';
  10986. this.minimize.style.display = 'none';
  10987. this.buttons.appendChild(this.minimize);
  10988. var minimized = false;
  10989. var maxDisplay = null;
  10990. var height = null;
  10991. var funct = mxUtils.bind(this, function(evt)
  10992. {
  10993. this.activate();
  10994. if (!minimized)
  10995. {
  10996. minimized = true;
  10997. this.minimize.setAttribute('src', this.normalizeImage);
  10998. this.minimize.setAttribute('title', 'Normalize');
  10999. this.contentWrapper.style.display = 'none';
  11000. maxDisplay = this.maximize.style.display;
  11001. this.maximize.style.display = 'none';
  11002. height = this.table.style.height;
  11003. var minSize = this.getMinimumSize();
  11004. if (minSize.height > 0)
  11005. {
  11006. if (!mxClient.IS_QUIRKS)
  11007. {
  11008. this.div.style.height = minSize.height + 'px';
  11009. }
  11010. this.table.style.height = minSize.height + 'px';
  11011. }
  11012. if (minSize.width > 0)
  11013. {
  11014. if (!mxClient.IS_QUIRKS)
  11015. {
  11016. this.div.style.width = minSize.width + 'px';
  11017. }
  11018. this.table.style.width = minSize.width + 'px';
  11019. }
  11020. if (this.resize != null)
  11021. {
  11022. this.resize.style.visibility = 'hidden';
  11023. }
  11024. this.fireEvent(new mxEventObject(mxEvent.MINIMIZE, 'event', evt));
  11025. }
  11026. else
  11027. {
  11028. minimized = false;
  11029. this.minimize.setAttribute('src', this.minimizeImage);
  11030. this.minimize.setAttribute('title', 'Minimize');
  11031. this.contentWrapper.style.display = ''; // default
  11032. this.maximize.style.display = maxDisplay;
  11033. if (!mxClient.IS_QUIRKS)
  11034. {
  11035. this.div.style.height = height;
  11036. }
  11037. this.table.style.height = height;
  11038. if (this.resize != null)
  11039. {
  11040. this.resize.style.visibility = '';
  11041. }
  11042. this.fireEvent(new mxEventObject(mxEvent.NORMALIZE, 'event', evt));
  11043. }
  11044. mxEvent.consume(evt);
  11045. });
  11046. mxEvent.addGestureListeners(this.minimize, funct);
  11047. };
  11048. /**
  11049. * Function: setMaximizable
  11050. *
  11051. * Sets if the window is maximizable.
  11052. */
  11053. mxWindow.prototype.setMaximizable = function(maximizable)
  11054. {
  11055. this.maximize.style.display = (maximizable) ? '' : 'none';
  11056. };
  11057. /**
  11058. * Function: installMaximizeHandler
  11059. *
  11060. * Installs the event listeners required for maximizing the window.
  11061. */
  11062. mxWindow.prototype.installMaximizeHandler = function()
  11063. {
  11064. this.maximize = document.createElement('img');
  11065. this.maximize.setAttribute('src', this.maximizeImage);
  11066. this.maximize.setAttribute('title', 'Maximize');
  11067. this.maximize.style.cursor = 'default';
  11068. this.maximize.style.marginLeft = '2px';
  11069. this.maximize.style.cursor = 'pointer';
  11070. this.maximize.style.display = 'none';
  11071. this.buttons.appendChild(this.maximize);
  11072. var maximized = false;
  11073. var x = null;
  11074. var y = null;
  11075. var height = null;
  11076. var width = null;
  11077. var minDisplay = null;
  11078. var funct = mxUtils.bind(this, function(evt)
  11079. {
  11080. this.activate();
  11081. if (this.maximize.style.display != 'none')
  11082. {
  11083. if (!maximized)
  11084. {
  11085. maximized = true;
  11086. this.maximize.setAttribute('src', this.normalizeImage);
  11087. this.maximize.setAttribute('title', 'Normalize');
  11088. this.contentWrapper.style.display = '';
  11089. minDisplay = this.minimize.style.display;
  11090. this.minimize.style.display = 'none';
  11091. // Saves window state
  11092. x = parseInt(this.div.style.left);
  11093. y = parseInt(this.div.style.top);
  11094. height = this.table.style.height;
  11095. width = this.table.style.width;
  11096. this.div.style.left = '0px';
  11097. this.div.style.top = '0px';
  11098. var docHeight = Math.max(document.body.clientHeight || 0, document.documentElement.clientHeight || 0);
  11099. if (!mxClient.IS_QUIRKS)
  11100. {
  11101. this.div.style.width = (document.body.clientWidth - 2) + 'px';
  11102. this.div.style.height = (docHeight - 2) + 'px';
  11103. }
  11104. this.table.style.width = (document.body.clientWidth - 2) + 'px';
  11105. this.table.style.height = (docHeight - 2) + 'px';
  11106. if (this.resize != null)
  11107. {
  11108. this.resize.style.visibility = 'hidden';
  11109. }
  11110. if (!mxClient.IS_QUIRKS)
  11111. {
  11112. var style = mxUtils.getCurrentStyle(this.contentWrapper);
  11113. if (style.overflow == 'auto' || this.resize != null)
  11114. {
  11115. this.contentWrapper.style.height = (this.div.offsetHeight -
  11116. this.title.offsetHeight - this.contentHeightCorrection) + 'px';
  11117. }
  11118. }
  11119. this.fireEvent(new mxEventObject(mxEvent.MAXIMIZE, 'event', evt));
  11120. }
  11121. else
  11122. {
  11123. maximized = false;
  11124. this.maximize.setAttribute('src', this.maximizeImage);
  11125. this.maximize.setAttribute('title', 'Maximize');
  11126. this.contentWrapper.style.display = '';
  11127. this.minimize.style.display = minDisplay;
  11128. // Restores window state
  11129. this.div.style.left = x+'px';
  11130. this.div.style.top = y+'px';
  11131. if (!mxClient.IS_QUIRKS)
  11132. {
  11133. this.div.style.height = height;
  11134. this.div.style.width = width;
  11135. var style = mxUtils.getCurrentStyle(this.contentWrapper);
  11136. if (style.overflow == 'auto' || this.resize != null)
  11137. {
  11138. this.contentWrapper.style.height = (this.div.offsetHeight -
  11139. this.title.offsetHeight - this.contentHeightCorrection) + 'px';
  11140. }
  11141. }
  11142. this.table.style.height = height;
  11143. this.table.style.width = width;
  11144. if (this.resize != null)
  11145. {
  11146. this.resize.style.visibility = '';
  11147. }
  11148. this.fireEvent(new mxEventObject(mxEvent.NORMALIZE, 'event', evt));
  11149. }
  11150. mxEvent.consume(evt);
  11151. }
  11152. });
  11153. mxEvent.addGestureListeners(this.maximize, funct);
  11154. mxEvent.addListener(this.title, 'dblclick', funct);
  11155. };
  11156. /**
  11157. * Function: installMoveHandler
  11158. *
  11159. * Installs the event listeners required for moving the window.
  11160. */
  11161. mxWindow.prototype.installMoveHandler = function()
  11162. {
  11163. this.title.style.cursor = 'move';
  11164. mxEvent.addGestureListeners(this.title,
  11165. mxUtils.bind(this, function(evt)
  11166. {
  11167. var startX = mxEvent.getClientX(evt);
  11168. var startY = mxEvent.getClientY(evt);
  11169. var x = this.getX();
  11170. var y = this.getY();
  11171. // Adds a temporary pair of listeners to intercept
  11172. // the gesture event in the document
  11173. var dragHandler = mxUtils.bind(this, function(evt)
  11174. {
  11175. var dx = mxEvent.getClientX(evt) - startX;
  11176. var dy = mxEvent.getClientY(evt) - startY;
  11177. this.setLocation(x + dx, y + dy);
  11178. this.fireEvent(new mxEventObject(mxEvent.MOVE, 'event', evt));
  11179. mxEvent.consume(evt);
  11180. });
  11181. var dropHandler = mxUtils.bind(this, function(evt)
  11182. {
  11183. mxEvent.removeGestureListeners(document, null, dragHandler, dropHandler);
  11184. this.fireEvent(new mxEventObject(mxEvent.MOVE_END, 'event', evt));
  11185. mxEvent.consume(evt);
  11186. });
  11187. mxEvent.addGestureListeners(document, null, dragHandler, dropHandler);
  11188. this.fireEvent(new mxEventObject(mxEvent.MOVE_START, 'event', evt));
  11189. mxEvent.consume(evt);
  11190. }));
  11191. // Disables built-in pan and zoom in IE10 and later
  11192. if (mxClient.IS_POINTER)
  11193. {
  11194. this.title.style.touchAction = 'none';
  11195. }
  11196. };
  11197. /**
  11198. * Function: setLocation
  11199. *
  11200. * Sets the upper, left corner of the window.
  11201. */
  11202. mxWindow.prototype.setLocation = function(x, y)
  11203. {
  11204. this.div.style.left = x + 'px';
  11205. this.div.style.top = y + 'px';
  11206. };
  11207. /**
  11208. * Function: getX
  11209. *
  11210. * Returns the current position on the x-axis.
  11211. */
  11212. mxWindow.prototype.getX = function()
  11213. {
  11214. return parseInt(this.div.style.left);
  11215. };
  11216. /**
  11217. * Function: getY
  11218. *
  11219. * Returns the current position on the y-axis.
  11220. */
  11221. mxWindow.prototype.getY = function()
  11222. {
  11223. return parseInt(this.div.style.top);
  11224. };
  11225. /**
  11226. * Function: installCloseHandler
  11227. *
  11228. * Adds the <closeImage> as a new image node in <closeImg> and installs the
  11229. * <close> event.
  11230. */
  11231. mxWindow.prototype.installCloseHandler = function()
  11232. {
  11233. this.closeImg = document.createElement('img');
  11234. this.closeImg.setAttribute('src', this.closeImage);
  11235. this.closeImg.setAttribute('title', 'Close');
  11236. this.closeImg.style.marginLeft = '2px';
  11237. this.closeImg.style.cursor = 'pointer';
  11238. this.closeImg.style.display = 'none';
  11239. this.buttons.appendChild(this.closeImg);
  11240. mxEvent.addGestureListeners(this.closeImg,
  11241. mxUtils.bind(this, function(evt)
  11242. {
  11243. this.fireEvent(new mxEventObject(mxEvent.CLOSE, 'event', evt));
  11244. if (this.destroyOnClose)
  11245. {
  11246. this.destroy();
  11247. }
  11248. else
  11249. {
  11250. this.setVisible(false);
  11251. }
  11252. mxEvent.consume(evt);
  11253. }));
  11254. };
  11255. /**
  11256. * Function: setImage
  11257. *
  11258. * Sets the image associated with the window.
  11259. *
  11260. * Parameters:
  11261. *
  11262. * image - URL of the image to be used.
  11263. */
  11264. mxWindow.prototype.setImage = function(image)
  11265. {
  11266. this.image = document.createElement('img');
  11267. this.image.setAttribute('src', image);
  11268. this.image.setAttribute('align', 'left');
  11269. this.image.style.marginRight = '4px';
  11270. this.image.style.marginLeft = '0px';
  11271. this.image.style.marginTop = '-2px';
  11272. this.title.insertBefore(this.image, this.title.firstChild);
  11273. };
  11274. /**
  11275. * Function: setClosable
  11276. *
  11277. * Sets the image associated with the window.
  11278. *
  11279. * Parameters:
  11280. *
  11281. * closable - Boolean specifying if the window should be closable.
  11282. */
  11283. mxWindow.prototype.setClosable = function(closable)
  11284. {
  11285. this.closeImg.style.display = (closable) ? '' : 'none';
  11286. };
  11287. /**
  11288. * Function: isVisible
  11289. *
  11290. * Returns true if the window is visible.
  11291. */
  11292. mxWindow.prototype.isVisible = function()
  11293. {
  11294. if (this.div != null)
  11295. {
  11296. return this.div.style.display != 'none';
  11297. }
  11298. return false;
  11299. };
  11300. /**
  11301. * Function: setVisible
  11302. *
  11303. * Shows or hides the window depending on the given flag.
  11304. *
  11305. * Parameters:
  11306. *
  11307. * visible - Boolean indicating if the window should be made visible.
  11308. */
  11309. mxWindow.prototype.setVisible = function(visible)
  11310. {
  11311. if (this.div != null && this.isVisible() != visible)
  11312. {
  11313. if (visible)
  11314. {
  11315. this.show();
  11316. }
  11317. else
  11318. {
  11319. this.hide();
  11320. }
  11321. }
  11322. };
  11323. /**
  11324. * Function: show
  11325. *
  11326. * Shows the window.
  11327. */
  11328. mxWindow.prototype.show = function()
  11329. {
  11330. this.div.style.display = '';
  11331. this.activate();
  11332. var style = mxUtils.getCurrentStyle(this.contentWrapper);
  11333. if (!mxClient.IS_QUIRKS && (style.overflow == 'auto' || this.resize != null) &&
  11334. this.contentWrapper.style.display != 'none')
  11335. {
  11336. this.contentWrapper.style.height = (this.div.offsetHeight -
  11337. this.title.offsetHeight - this.contentHeightCorrection) + 'px';
  11338. }
  11339. this.fireEvent(new mxEventObject(mxEvent.SHOW));
  11340. };
  11341. /**
  11342. * Function: hide
  11343. *
  11344. * Hides the window.
  11345. */
  11346. mxWindow.prototype.hide = function()
  11347. {
  11348. this.div.style.display = 'none';
  11349. this.fireEvent(new mxEventObject(mxEvent.HIDE));
  11350. };
  11351. /**
  11352. * Function: destroy
  11353. *
  11354. * Destroys the window and removes all associated resources. Fires a
  11355. * <destroy> event prior to destroying the window.
  11356. */
  11357. mxWindow.prototype.destroy = function()
  11358. {
  11359. this.fireEvent(new mxEventObject(mxEvent.DESTROY));
  11360. if (this.div != null)
  11361. {
  11362. mxEvent.release(this.div);
  11363. this.div.parentNode.removeChild(this.div);
  11364. this.div = null;
  11365. }
  11366. this.title = null;
  11367. this.content = null;
  11368. this.contentWrapper = null;
  11369. };
  11370. /**
  11371. * Copyright (c) 2006-2015, JGraph Ltd
  11372. * Copyright (c) 2006-2015, Gaudenz Alder
  11373. */
  11374. /**
  11375. * Class: mxForm
  11376. *
  11377. * A simple class for creating HTML forms.
  11378. *
  11379. * Constructor: mxForm
  11380. *
  11381. * Creates a HTML table using the specified classname.
  11382. */
  11383. function mxForm(className)
  11384. {
  11385. this.table = document.createElement('table');
  11386. this.table.className = className;
  11387. this.body = document.createElement('tbody');
  11388. this.table.appendChild(this.body);
  11389. };
  11390. /**
  11391. * Variable: table
  11392. *
  11393. * Holds the DOM node that represents the table.
  11394. */
  11395. mxForm.prototype.table = null;
  11396. /**
  11397. * Variable: body
  11398. *
  11399. * Holds the DOM node that represents the tbody (table body). New rows
  11400. * can be added to this object using DOM API.
  11401. */
  11402. mxForm.prototype.body = false;
  11403. /**
  11404. * Function: getTable
  11405. *
  11406. * Returns the table that contains this form.
  11407. */
  11408. mxForm.prototype.getTable = function()
  11409. {
  11410. return this.table;
  11411. };
  11412. /**
  11413. * Function: addButtons
  11414. *
  11415. * Helper method to add an OK and Cancel button using the respective
  11416. * functions.
  11417. */
  11418. mxForm.prototype.addButtons = function(okFunct, cancelFunct)
  11419. {
  11420. var tr = document.createElement('tr');
  11421. var td = document.createElement('td');
  11422. tr.appendChild(td);
  11423. td = document.createElement('td');
  11424. // Adds the ok button
  11425. var button = document.createElement('button');
  11426. mxUtils.write(button, mxResources.get('ok') || 'OK');
  11427. td.appendChild(button);
  11428. mxEvent.addListener(button, 'click', function()
  11429. {
  11430. okFunct();
  11431. });
  11432. // Adds the cancel button
  11433. button = document.createElement('button');
  11434. mxUtils.write(button, mxResources.get('cancel') || 'Cancel');
  11435. td.appendChild(button);
  11436. mxEvent.addListener(button, 'click', function()
  11437. {
  11438. cancelFunct();
  11439. });
  11440. tr.appendChild(td);
  11441. this.body.appendChild(tr);
  11442. };
  11443. /**
  11444. * Function: addText
  11445. *
  11446. * Adds an input for the given name, type and value and returns it.
  11447. */
  11448. mxForm.prototype.addText = function(name, value, type)
  11449. {
  11450. var input = document.createElement('input');
  11451. input.setAttribute('type', type || 'text');
  11452. input.value = value;
  11453. return this.addField(name, input);
  11454. };
  11455. /**
  11456. * Function: addCheckbox
  11457. *
  11458. * Adds a checkbox for the given name and value and returns the textfield.
  11459. */
  11460. mxForm.prototype.addCheckbox = function(name, value)
  11461. {
  11462. var input = document.createElement('input');
  11463. input.setAttribute('type', 'checkbox');
  11464. this.addField(name, input);
  11465. // IE can only change the checked value if the input is inside the DOM
  11466. if (value)
  11467. {
  11468. input.checked = true;
  11469. }
  11470. return input;
  11471. };
  11472. /**
  11473. * Function: addTextarea
  11474. *
  11475. * Adds a textarea for the given name and value and returns the textarea.
  11476. */
  11477. mxForm.prototype.addTextarea = function(name, value, rows)
  11478. {
  11479. var input = document.createElement('textarea');
  11480. if (mxClient.IS_NS)
  11481. {
  11482. rows--;
  11483. }
  11484. input.setAttribute('rows', rows || 2);
  11485. input.value = value;
  11486. return this.addField(name, input);
  11487. };
  11488. /**
  11489. * Function: addCombo
  11490. *
  11491. * Adds a combo for the given name and returns the combo.
  11492. */
  11493. mxForm.prototype.addCombo = function(name, isMultiSelect, size)
  11494. {
  11495. var select = document.createElement('select');
  11496. if (size != null)
  11497. {
  11498. select.setAttribute('size', size);
  11499. }
  11500. if (isMultiSelect)
  11501. {
  11502. select.setAttribute('multiple', 'true');
  11503. }
  11504. return this.addField(name, select);
  11505. };
  11506. /**
  11507. * Function: addOption
  11508. *
  11509. * Adds an option for the given label to the specified combo.
  11510. */
  11511. mxForm.prototype.addOption = function(combo, label, value, isSelected)
  11512. {
  11513. var option = document.createElement('option');
  11514. mxUtils.writeln(option, label);
  11515. option.setAttribute('value', value);
  11516. if (isSelected)
  11517. {
  11518. option.setAttribute('selected', isSelected);
  11519. }
  11520. combo.appendChild(option);
  11521. };
  11522. /**
  11523. * Function: addField
  11524. *
  11525. * Adds a new row with the name and the input field in two columns and
  11526. * returns the given input.
  11527. */
  11528. mxForm.prototype.addField = function(name, input)
  11529. {
  11530. var tr = document.createElement('tr');
  11531. var td = document.createElement('td');
  11532. mxUtils.write(td, name);
  11533. tr.appendChild(td);
  11534. td = document.createElement('td');
  11535. td.appendChild(input);
  11536. tr.appendChild(td);
  11537. this.body.appendChild(tr);
  11538. return input;
  11539. };
  11540. /**
  11541. * Copyright (c) 2006-2015, JGraph Ltd
  11542. * Copyright (c) 2006-2015, Gaudenz Alder
  11543. */
  11544. /**
  11545. * Class: mxImage
  11546. *
  11547. * Encapsulates the URL, width and height of an image.
  11548. *
  11549. * Constructor: mxImage
  11550. *
  11551. * Constructs a new image.
  11552. */
  11553. function mxImage(src, width, height)
  11554. {
  11555. this.src = src;
  11556. this.width = width;
  11557. this.height = height;
  11558. };
  11559. /**
  11560. * Variable: src
  11561. *
  11562. * String that specifies the URL of the image.
  11563. */
  11564. mxImage.prototype.src = null;
  11565. /**
  11566. * Variable: width
  11567. *
  11568. * Integer that specifies the width of the image.
  11569. */
  11570. mxImage.prototype.width = null;
  11571. /**
  11572. * Variable: height
  11573. *
  11574. * Integer that specifies the height of the image.
  11575. */
  11576. mxImage.prototype.height = null;
  11577. /**
  11578. * Copyright (c) 2006-2015, JGraph Ltd
  11579. * Copyright (c) 2006-2015, Gaudenz Alder
  11580. */
  11581. /**
  11582. * Class: mxDivResizer
  11583. *
  11584. * Maintains the size of a div element in Internet Explorer. This is a
  11585. * workaround for the right and bottom style being ignored in IE.
  11586. *
  11587. * If you need a div to cover the scrollwidth and -height of a document,
  11588. * then you can use this class as follows:
  11589. *
  11590. * (code)
  11591. * var resizer = new mxDivResizer(background);
  11592. * resizer.getDocumentHeight = function()
  11593. * {
  11594. * return document.body.scrollHeight;
  11595. * }
  11596. * resizer.getDocumentWidth = function()
  11597. * {
  11598. * return document.body.scrollWidth;
  11599. * }
  11600. * resizer.resize();
  11601. * (end)
  11602. *
  11603. * Constructor: mxDivResizer
  11604. *
  11605. * Constructs an object that maintains the size of a div
  11606. * element when the window is being resized. This is only
  11607. * required for Internet Explorer as it ignores the respective
  11608. * stylesheet information for DIV elements.
  11609. *
  11610. * Parameters:
  11611. *
  11612. * div - Reference to the DOM node whose size should be maintained.
  11613. * container - Optional Container that contains the div. Default is the
  11614. * window.
  11615. */
  11616. function mxDivResizer(div, container)
  11617. {
  11618. if (div.nodeName.toLowerCase() == 'div')
  11619. {
  11620. if (container == null)
  11621. {
  11622. container = window;
  11623. }
  11624. this.div = div;
  11625. var style = mxUtils.getCurrentStyle(div);
  11626. if (style != null)
  11627. {
  11628. this.resizeWidth = style.width == 'auto';
  11629. this.resizeHeight = style.height == 'auto';
  11630. }
  11631. mxEvent.addListener(container, 'resize',
  11632. mxUtils.bind(this, function(evt)
  11633. {
  11634. if (!this.handlingResize)
  11635. {
  11636. this.handlingResize = true;
  11637. this.resize();
  11638. this.handlingResize = false;
  11639. }
  11640. })
  11641. );
  11642. this.resize();
  11643. }
  11644. };
  11645. /**
  11646. * Function: resizeWidth
  11647. *
  11648. * Boolean specifying if the width should be updated.
  11649. */
  11650. mxDivResizer.prototype.resizeWidth = true;
  11651. /**
  11652. * Function: resizeHeight
  11653. *
  11654. * Boolean specifying if the height should be updated.
  11655. */
  11656. mxDivResizer.prototype.resizeHeight = true;
  11657. /**
  11658. * Function: handlingResize
  11659. *
  11660. * Boolean specifying if the width should be updated.
  11661. */
  11662. mxDivResizer.prototype.handlingResize = false;
  11663. /**
  11664. * Function: resize
  11665. *
  11666. * Updates the style of the DIV after the window has been resized.
  11667. */
  11668. mxDivResizer.prototype.resize = function()
  11669. {
  11670. var w = this.getDocumentWidth();
  11671. var h = this.getDocumentHeight();
  11672. var l = parseInt(this.div.style.left);
  11673. var r = parseInt(this.div.style.right);
  11674. var t = parseInt(this.div.style.top);
  11675. var b = parseInt(this.div.style.bottom);
  11676. if (this.resizeWidth &&
  11677. !isNaN(l) &&
  11678. !isNaN(r) &&
  11679. l >= 0 &&
  11680. r >= 0 &&
  11681. w - r - l > 0)
  11682. {
  11683. this.div.style.width = (w - r - l)+'px';
  11684. }
  11685. if (this.resizeHeight &&
  11686. !isNaN(t) &&
  11687. !isNaN(b) &&
  11688. t >= 0 &&
  11689. b >= 0 &&
  11690. h - t - b > 0)
  11691. {
  11692. this.div.style.height = (h - t - b)+'px';
  11693. }
  11694. };
  11695. /**
  11696. * Function: getDocumentWidth
  11697. *
  11698. * Hook for subclassers to return the width of the document (without
  11699. * scrollbars).
  11700. */
  11701. mxDivResizer.prototype.getDocumentWidth = function()
  11702. {
  11703. return document.body.clientWidth;
  11704. };
  11705. /**
  11706. * Function: getDocumentHeight
  11707. *
  11708. * Hook for subclassers to return the height of the document (without
  11709. * scrollbars).
  11710. */
  11711. mxDivResizer.prototype.getDocumentHeight = function()
  11712. {
  11713. return document.body.clientHeight;
  11714. };
  11715. /**
  11716. * Copyright (c) 2006-2015, JGraph Ltd
  11717. * Copyright (c) 2006-2015, Gaudenz Alder
  11718. */
  11719. /**
  11720. * Class: mxDragSource
  11721. *
  11722. * Wrapper to create a drag source from a DOM element so that the element can
  11723. * be dragged over a graph and dropped into the graph as a new cell.
  11724. *
  11725. * Problem is that in the dropHandler the current preview location is not
  11726. * available, so the preview and the dropHandler must match.
  11727. *
  11728. * Constructor: mxDragSource
  11729. *
  11730. * Constructs a new drag source for the given element.
  11731. */
  11732. function mxDragSource(element, dropHandler)
  11733. {
  11734. this.element = element;
  11735. this.dropHandler = dropHandler;
  11736. // Handles a drag gesture on the element
  11737. mxEvent.addGestureListeners(element, mxUtils.bind(this, function(evt)
  11738. {
  11739. this.mouseDown(evt);
  11740. }));
  11741. // Prevents native drag and drop
  11742. mxEvent.addListener(element, 'dragstart', function(evt)
  11743. {
  11744. mxEvent.consume(evt);
  11745. });
  11746. this.eventConsumer = function(sender, evt)
  11747. {
  11748. var evtName = evt.getProperty('eventName');
  11749. var me = evt.getProperty('event');
  11750. if (evtName != mxEvent.MOUSE_DOWN)
  11751. {
  11752. me.consume();
  11753. }
  11754. };
  11755. };
  11756. /**
  11757. * Variable: element
  11758. *
  11759. * Reference to the DOM node which was made draggable.
  11760. */
  11761. mxDragSource.prototype.element = null;
  11762. /**
  11763. * Variable: dropHandler
  11764. *
  11765. * Holds the DOM node that is used to represent the drag preview. If this is
  11766. * null then the source element will be cloned and used for the drag preview.
  11767. */
  11768. mxDragSource.prototype.dropHandler = null;
  11769. /**
  11770. * Variable: dragOffset
  11771. *
  11772. * <mxPoint> that specifies the offset of the <dragElement>. Default is null.
  11773. */
  11774. mxDragSource.prototype.dragOffset = null;
  11775. /**
  11776. * Variable: dragElement
  11777. *
  11778. * Holds the DOM node that is used to represent the drag preview. If this is
  11779. * null then the source element will be cloned and used for the drag preview.
  11780. */
  11781. mxDragSource.prototype.dragElement = null;
  11782. /**
  11783. * Variable: previewElement
  11784. *
  11785. * Optional <mxRectangle> that specifies the unscaled size of the preview.
  11786. */
  11787. mxDragSource.prototype.previewElement = null;
  11788. /**
  11789. * Variable: enabled
  11790. *
  11791. * Specifies if this drag source is enabled. Default is true.
  11792. */
  11793. mxDragSource.prototype.enabled = true;
  11794. /**
  11795. * Variable: currentGraph
  11796. *
  11797. * Reference to the <mxGraph> that is the current drop target.
  11798. */
  11799. mxDragSource.prototype.currentGraph = null;
  11800. /**
  11801. * Variable: currentDropTarget
  11802. *
  11803. * Holds the current drop target under the mouse.
  11804. */
  11805. mxDragSource.prototype.currentDropTarget = null;
  11806. /**
  11807. * Variable: currentPoint
  11808. *
  11809. * Holds the current drop location.
  11810. */
  11811. mxDragSource.prototype.currentPoint = null;
  11812. /**
  11813. * Variable: currentGuide
  11814. *
  11815. * Holds an <mxGuide> for the <currentGraph> if <dragPreview> is not null.
  11816. */
  11817. mxDragSource.prototype.currentGuide = null;
  11818. /**
  11819. * Variable: currentGuide
  11820. *
  11821. * Holds an <mxGuide> for the <currentGraph> if <dragPreview> is not null.
  11822. */
  11823. mxDragSource.prototype.currentHighlight = null;
  11824. /**
  11825. * Variable: autoscroll
  11826. *
  11827. * Specifies if the graph should scroll automatically. Default is true.
  11828. */
  11829. mxDragSource.prototype.autoscroll = true;
  11830. /**
  11831. * Variable: guidesEnabled
  11832. *
  11833. * Specifies if <mxGuide> should be enabled. Default is true.
  11834. */
  11835. mxDragSource.prototype.guidesEnabled = true;
  11836. /**
  11837. * Variable: gridEnabled
  11838. *
  11839. * Specifies if the grid should be allowed. Default is true.
  11840. */
  11841. mxDragSource.prototype.gridEnabled = true;
  11842. /**
  11843. * Variable: highlightDropTargets
  11844. *
  11845. * Specifies if drop targets should be highlighted. Default is true.
  11846. */
  11847. mxDragSource.prototype.highlightDropTargets = true;
  11848. /**
  11849. * Variable: dragElementZIndex
  11850. *
  11851. * ZIndex for the drag element. Default is 100.
  11852. */
  11853. mxDragSource.prototype.dragElementZIndex = 100;
  11854. /**
  11855. * Variable: dragElementOpacity
  11856. *
  11857. * Opacity of the drag element in %. Default is 70.
  11858. */
  11859. mxDragSource.prototype.dragElementOpacity = 70;
  11860. /**
  11861. * Variable: checkEventSource
  11862. *
  11863. * Whether the event source should be checked in <graphContainerEvent>. Default
  11864. * is true.
  11865. */
  11866. mxDragSource.prototype.checkEventSource = true;
  11867. /**
  11868. * Function: isEnabled
  11869. *
  11870. * Returns <enabled>.
  11871. */
  11872. mxDragSource.prototype.isEnabled = function()
  11873. {
  11874. return this.enabled;
  11875. };
  11876. /**
  11877. * Function: setEnabled
  11878. *
  11879. * Sets <enabled>.
  11880. */
  11881. mxDragSource.prototype.setEnabled = function(value)
  11882. {
  11883. this.enabled = value;
  11884. };
  11885. /**
  11886. * Function: isGuidesEnabled
  11887. *
  11888. * Returns <guidesEnabled>.
  11889. */
  11890. mxDragSource.prototype.isGuidesEnabled = function()
  11891. {
  11892. return this.guidesEnabled;
  11893. };
  11894. /**
  11895. * Function: setGuidesEnabled
  11896. *
  11897. * Sets <guidesEnabled>.
  11898. */
  11899. mxDragSource.prototype.setGuidesEnabled = function(value)
  11900. {
  11901. this.guidesEnabled = value;
  11902. };
  11903. /**
  11904. * Function: isGridEnabled
  11905. *
  11906. * Returns <gridEnabled>.
  11907. */
  11908. mxDragSource.prototype.isGridEnabled = function()
  11909. {
  11910. return this.gridEnabled;
  11911. };
  11912. /**
  11913. * Function: setGridEnabled
  11914. *
  11915. * Sets <gridEnabled>.
  11916. */
  11917. mxDragSource.prototype.setGridEnabled = function(value)
  11918. {
  11919. this.gridEnabled = value;
  11920. };
  11921. /**
  11922. * Function: getGraphForEvent
  11923. *
  11924. * Returns the graph for the given mouse event. This implementation returns
  11925. * null.
  11926. */
  11927. mxDragSource.prototype.getGraphForEvent = function(evt)
  11928. {
  11929. return null;
  11930. };
  11931. /**
  11932. * Function: getDropTarget
  11933. *
  11934. * Returns the drop target for the given graph and coordinates. This
  11935. * implementation uses <mxGraph.getCellAt>.
  11936. */
  11937. mxDragSource.prototype.getDropTarget = function(graph, x, y, evt)
  11938. {
  11939. return graph.getCellAt(x, y);
  11940. };
  11941. /**
  11942. * Function: createDragElement
  11943. *
  11944. * Creates and returns a clone of the <dragElementPrototype> or the <element>
  11945. * if the former is not defined.
  11946. */
  11947. mxDragSource.prototype.createDragElement = function(evt)
  11948. {
  11949. return this.element.cloneNode(true);
  11950. };
  11951. /**
  11952. * Function: createPreviewElement
  11953. *
  11954. * Creates and returns an element which can be used as a preview in the given
  11955. * graph.
  11956. */
  11957. mxDragSource.prototype.createPreviewElement = function(graph)
  11958. {
  11959. return null;
  11960. };
  11961. /**
  11962. * Function: isActive
  11963. *
  11964. * Returns true if this drag source is active.
  11965. */
  11966. mxDragSource.prototype.isActive = function()
  11967. {
  11968. return this.mouseMoveHandler != null;
  11969. };
  11970. /**
  11971. * Function: reset
  11972. *
  11973. * Stops and removes everything and restores the state of the object.
  11974. */
  11975. mxDragSource.prototype.reset = function()
  11976. {
  11977. if (this.currentGraph != null)
  11978. {
  11979. this.dragExit(this.currentGraph);
  11980. this.currentGraph = null;
  11981. }
  11982. this.removeDragElement();
  11983. this.removeListeners();
  11984. this.stopDrag();
  11985. };
  11986. /**
  11987. * Function: mouseDown
  11988. *
  11989. * Returns the drop target for the given graph and coordinates. This
  11990. * implementation uses <mxGraph.getCellAt>.
  11991. *
  11992. * To ignore popup menu events for a drag source, this function can be
  11993. * overridden as follows.
  11994. *
  11995. * (code)
  11996. * var mouseDown = dragSource.mouseDown;
  11997. *
  11998. * dragSource.mouseDown = function(evt)
  11999. * {
  12000. * if (!mxEvent.isPopupTrigger(evt))
  12001. * {
  12002. * mouseDown.apply(this, arguments);
  12003. * }
  12004. * };
  12005. * (end)
  12006. */
  12007. mxDragSource.prototype.mouseDown = function(evt)
  12008. {
  12009. if (this.enabled && !mxEvent.isConsumed(evt) && this.mouseMoveHandler == null)
  12010. {
  12011. this.startDrag(evt);
  12012. this.mouseMoveHandler = mxUtils.bind(this, this.mouseMove);
  12013. this.mouseUpHandler = mxUtils.bind(this, this.mouseUp);
  12014. mxEvent.addGestureListeners(document, null, this.mouseMoveHandler, this.mouseUpHandler);
  12015. if (mxClient.IS_TOUCH && !mxEvent.isMouseEvent(evt))
  12016. {
  12017. this.eventSource = mxEvent.getSource(evt);
  12018. mxEvent.addGestureListeners(this.eventSource, null, this.mouseMoveHandler, this.mouseUpHandler);
  12019. }
  12020. }
  12021. };
  12022. /**
  12023. * Function: startDrag
  12024. *
  12025. * Creates the <dragElement> using <createDragElement>.
  12026. */
  12027. mxDragSource.prototype.startDrag = function(evt)
  12028. {
  12029. this.dragElement = this.createDragElement(evt);
  12030. this.dragElement.style.position = 'absolute';
  12031. this.dragElement.style.zIndex = this.dragElementZIndex;
  12032. mxUtils.setOpacity(this.dragElement, this.dragElementOpacity);
  12033. if (this.checkEventSource && mxClient.IS_SVG)
  12034. {
  12035. this.dragElement.style.pointerEvents = 'none';
  12036. }
  12037. };
  12038. /**
  12039. * Function: stopDrag
  12040. *
  12041. * Invokes <removeDragElement>.
  12042. */
  12043. mxDragSource.prototype.stopDrag = function()
  12044. {
  12045. // LATER: This used to have a mouse event. If that is still needed we need to add another
  12046. // final call to the DnD protocol to add a cleanup step in the case of escape press, which
  12047. // is not associated with a mouse event and which currently calles this method.
  12048. this.removeDragElement();
  12049. };
  12050. /**
  12051. * Function: removeDragElement
  12052. *
  12053. * Removes and destroys the <dragElement>.
  12054. */
  12055. mxDragSource.prototype.removeDragElement = function()
  12056. {
  12057. if (this.dragElement != null)
  12058. {
  12059. if (this.dragElement.parentNode != null)
  12060. {
  12061. this.dragElement.parentNode.removeChild(this.dragElement);
  12062. }
  12063. this.dragElement = null;
  12064. }
  12065. };
  12066. /**
  12067. * Function: getElementForEvent
  12068. *
  12069. * Returns the topmost element under the given event.
  12070. */
  12071. mxDragSource.prototype.getElementForEvent = function(evt)
  12072. {
  12073. return ((mxEvent.isTouchEvent(evt) || mxEvent.isPenEvent(evt)) ?
  12074. document.elementFromPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt)) :
  12075. mxEvent.getSource(evt));
  12076. };
  12077. /**
  12078. * Function: graphContainsEvent
  12079. *
  12080. * Returns true if the given graph contains the given event.
  12081. */
  12082. mxDragSource.prototype.graphContainsEvent = function(graph, evt)
  12083. {
  12084. var x = mxEvent.getClientX(evt);
  12085. var y = mxEvent.getClientY(evt);
  12086. var offset = mxUtils.getOffset(graph.container);
  12087. var origin = mxUtils.getScrollOrigin();
  12088. var elt = this.getElementForEvent(evt);
  12089. if (this.checkEventSource)
  12090. {
  12091. while (elt != null && elt != graph.container)
  12092. {
  12093. elt = elt.parentNode;
  12094. }
  12095. }
  12096. // Checks if event is inside the bounds of the graph container
  12097. return elt != null && x >= offset.x - origin.x && y >= offset.y - origin.y &&
  12098. x <= offset.x - origin.x + graph.container.offsetWidth &&
  12099. y <= offset.y - origin.y + graph.container.offsetHeight;
  12100. };
  12101. /**
  12102. * Function: mouseMove
  12103. *
  12104. * Gets the graph for the given event using <getGraphForEvent>, updates the
  12105. * <currentGraph>, calling <dragEnter> and <dragExit> on the new and old graph,
  12106. * respectively, and invokes <dragOver> if <currentGraph> is not null.
  12107. */
  12108. mxDragSource.prototype.mouseMove = function(evt)
  12109. {
  12110. var graph = this.getGraphForEvent(evt);
  12111. // Checks if event is inside the bounds of the graph container
  12112. if (graph != null && !this.graphContainsEvent(graph, evt))
  12113. {
  12114. graph = null;
  12115. }
  12116. if (graph != this.currentGraph)
  12117. {
  12118. if (this.currentGraph != null)
  12119. {
  12120. this.dragExit(this.currentGraph, evt);
  12121. }
  12122. this.currentGraph = graph;
  12123. if (this.currentGraph != null)
  12124. {
  12125. this.dragEnter(this.currentGraph, evt);
  12126. }
  12127. }
  12128. if (this.currentGraph != null)
  12129. {
  12130. this.dragOver(this.currentGraph, evt);
  12131. }
  12132. if (this.dragElement != null && (this.previewElement == null || this.previewElement.style.visibility != 'visible'))
  12133. {
  12134. var x = mxEvent.getClientX(evt);
  12135. var y = mxEvent.getClientY(evt);
  12136. if (this.dragElement.parentNode == null)
  12137. {
  12138. document.body.appendChild(this.dragElement);
  12139. }
  12140. this.dragElement.style.visibility = 'visible';
  12141. if (this.dragOffset != null)
  12142. {
  12143. x += this.dragOffset.x;
  12144. y += this.dragOffset.y;
  12145. }
  12146. var offset = mxUtils.getDocumentScrollOrigin(document);
  12147. this.dragElement.style.left = (x + offset.x) + 'px';
  12148. this.dragElement.style.top = (y + offset.y) + 'px';
  12149. }
  12150. else if (this.dragElement != null)
  12151. {
  12152. this.dragElement.style.visibility = 'hidden';
  12153. }
  12154. mxEvent.consume(evt);
  12155. };
  12156. /**
  12157. * Function: mouseUp
  12158. *
  12159. * Processes the mouse up event and invokes <drop>, <dragExit> and <stopDrag>
  12160. * as required.
  12161. */
  12162. mxDragSource.prototype.mouseUp = function(evt)
  12163. {
  12164. if (this.currentGraph != null)
  12165. {
  12166. if (this.currentPoint != null && (this.previewElement == null ||
  12167. this.previewElement.style.visibility != 'hidden'))
  12168. {
  12169. var scale = this.currentGraph.view.scale;
  12170. var tr = this.currentGraph.view.translate;
  12171. var x = this.currentPoint.x / scale - tr.x;
  12172. var y = this.currentPoint.y / scale - tr.y;
  12173. this.drop(this.currentGraph, evt, this.currentDropTarget, x, y);
  12174. }
  12175. this.dragExit(this.currentGraph);
  12176. this.currentGraph = null;
  12177. }
  12178. this.stopDrag();
  12179. this.removeListeners();
  12180. mxEvent.consume(evt);
  12181. };
  12182. /**
  12183. * Function: removeListeners
  12184. *
  12185. * Actives the given graph as a drop target.
  12186. */
  12187. mxDragSource.prototype.removeListeners = function()
  12188. {
  12189. if (this.eventSource != null)
  12190. {
  12191. mxEvent.removeGestureListeners(this.eventSource, null, this.mouseMoveHandler, this.mouseUpHandler);
  12192. this.eventSource = null;
  12193. }
  12194. mxEvent.removeGestureListeners(document, null, this.mouseMoveHandler, this.mouseUpHandler);
  12195. this.mouseMoveHandler = null;
  12196. this.mouseUpHandler = null;
  12197. };
  12198. /**
  12199. * Function: dragEnter
  12200. *
  12201. * Actives the given graph as a drop target.
  12202. */
  12203. mxDragSource.prototype.dragEnter = function(graph, evt)
  12204. {
  12205. graph.isMouseDown = true;
  12206. graph.isMouseTrigger = mxEvent.isMouseEvent(evt);
  12207. this.previewElement = this.createPreviewElement(graph);
  12208. if (this.previewElement != null && this.checkEventSource && mxClient.IS_SVG)
  12209. {
  12210. this.previewElement.style.pointerEvents = 'none';
  12211. }
  12212. // Guide is only needed if preview element is used
  12213. if (this.isGuidesEnabled() && this.previewElement != null)
  12214. {
  12215. this.currentGuide = new mxGuide(graph, graph.graphHandler.getGuideStates());
  12216. }
  12217. if (this.highlightDropTargets)
  12218. {
  12219. this.currentHighlight = new mxCellHighlight(graph, mxConstants.DROP_TARGET_COLOR);
  12220. }
  12221. // Consumes all events in the current graph before they are fired
  12222. graph.addListener(mxEvent.FIRE_MOUSE_EVENT, this.eventConsumer);
  12223. };
  12224. /**
  12225. * Function: dragExit
  12226. *
  12227. * Deactivates the given graph as a drop target.
  12228. */
  12229. mxDragSource.prototype.dragExit = function(graph, evt)
  12230. {
  12231. this.currentDropTarget = null;
  12232. this.currentPoint = null;
  12233. graph.isMouseDown = false;
  12234. // Consumes all events in the current graph before they are fired
  12235. graph.removeListener(this.eventConsumer);
  12236. if (this.previewElement != null)
  12237. {
  12238. if (this.previewElement.parentNode != null)
  12239. {
  12240. this.previewElement.parentNode.removeChild(this.previewElement);
  12241. }
  12242. this.previewElement = null;
  12243. }
  12244. if (this.currentGuide != null)
  12245. {
  12246. this.currentGuide.destroy();
  12247. this.currentGuide = null;
  12248. }
  12249. if (this.currentHighlight != null)
  12250. {
  12251. this.currentHighlight.destroy();
  12252. this.currentHighlight = null;
  12253. }
  12254. };
  12255. /**
  12256. * Function: dragOver
  12257. *
  12258. * Implements autoscroll, updates the <currentPoint>, highlights any drop
  12259. * targets and updates the preview.
  12260. */
  12261. mxDragSource.prototype.dragOver = function(graph, evt)
  12262. {
  12263. var offset = mxUtils.getOffset(graph.container);
  12264. var origin = mxUtils.getScrollOrigin(graph.container);
  12265. var x = mxEvent.getClientX(evt) - offset.x + origin.x - graph.panDx;
  12266. var y = mxEvent.getClientY(evt) - offset.y + origin.y - graph.panDy;
  12267. if (graph.autoScroll && (this.autoscroll == null || this.autoscroll))
  12268. {
  12269. graph.scrollPointToVisible(x, y, graph.autoExtend);
  12270. }
  12271. // Highlights the drop target under the mouse
  12272. if (this.currentHighlight != null && graph.isDropEnabled())
  12273. {
  12274. this.currentDropTarget = this.getDropTarget(graph, x, y, evt);
  12275. var state = graph.getView().getState(this.currentDropTarget);
  12276. this.currentHighlight.highlight(state);
  12277. }
  12278. // Updates the location of the preview
  12279. if (this.previewElement != null)
  12280. {
  12281. if (this.previewElement.parentNode == null)
  12282. {
  12283. graph.container.appendChild(this.previewElement);
  12284. this.previewElement.style.zIndex = '3';
  12285. this.previewElement.style.position = 'absolute';
  12286. }
  12287. var gridEnabled = this.isGridEnabled() && graph.isGridEnabledEvent(evt);
  12288. var hideGuide = true;
  12289. // Grid and guides
  12290. if (this.currentGuide != null && this.currentGuide.isEnabledForEvent(evt))
  12291. {
  12292. // LATER: HTML preview appears smaller than SVG preview
  12293. var w = parseInt(this.previewElement.style.width);
  12294. var h = parseInt(this.previewElement.style.height);
  12295. var bounds = new mxRectangle(0, 0, w, h);
  12296. var delta = new mxPoint(x, y);
  12297. delta = this.currentGuide.move(bounds, delta, gridEnabled, true);
  12298. hideGuide = false;
  12299. x = delta.x;
  12300. y = delta.y;
  12301. }
  12302. else if (gridEnabled)
  12303. {
  12304. var scale = graph.view.scale;
  12305. var tr = graph.view.translate;
  12306. var off = graph.gridSize / 2;
  12307. x = (graph.snap(x / scale - tr.x - off) + tr.x) * scale;
  12308. y = (graph.snap(y / scale - tr.y - off) + tr.y) * scale;
  12309. }
  12310. if (this.currentGuide != null && hideGuide)
  12311. {
  12312. this.currentGuide.hide();
  12313. }
  12314. if (this.previewOffset != null)
  12315. {
  12316. x += this.previewOffset.x;
  12317. y += this.previewOffset.y;
  12318. }
  12319. this.previewElement.style.left = Math.round(x) + 'px';
  12320. this.previewElement.style.top = Math.round(y) + 'px';
  12321. this.previewElement.style.visibility = 'visible';
  12322. }
  12323. this.currentPoint = new mxPoint(x, y);
  12324. };
  12325. /**
  12326. * Function: drop
  12327. *
  12328. * Returns the drop target for the given graph and coordinates. This
  12329. * implementation uses <mxGraph.getCellAt>.
  12330. */
  12331. mxDragSource.prototype.drop = function(graph, evt, dropTarget, x, y)
  12332. {
  12333. this.dropHandler.apply(this, arguments);
  12334. // Had to move this to after the insert because it will
  12335. // affect the scrollbars of the window in IE to try and
  12336. // make the complete container visible.
  12337. // LATER: Should be made optional.
  12338. if (graph.container.style.visibility != 'hidden')
  12339. {
  12340. graph.container.focus();
  12341. }
  12342. };
  12343. /**
  12344. * Copyright (c) 2006-2015, JGraph Ltd
  12345. * Copyright (c) 2006-2015, Gaudenz Alder
  12346. */
  12347. /**
  12348. * Class: mxToolbar
  12349. *
  12350. * Creates a toolbar inside a given DOM node. The toolbar may contain icons,
  12351. * buttons and combo boxes.
  12352. *
  12353. * Event: mxEvent.SELECT
  12354. *
  12355. * Fires when an item was selected in the toolbar. The <code>function</code>
  12356. * property contains the function that was selected in <selectMode>.
  12357. *
  12358. * Constructor: mxToolbar
  12359. *
  12360. * Constructs a toolbar in the specified container.
  12361. *
  12362. * Parameters:
  12363. *
  12364. * container - DOM node that contains the toolbar.
  12365. */
  12366. function mxToolbar(container)
  12367. {
  12368. this.container = container;
  12369. };
  12370. /**
  12371. * Extends mxEventSource.
  12372. */
  12373. mxToolbar.prototype = new mxEventSource();
  12374. mxToolbar.prototype.constructor = mxToolbar;
  12375. /**
  12376. * Variable: container
  12377. *
  12378. * Reference to the DOM nodes that contains the toolbar.
  12379. */
  12380. mxToolbar.prototype.container = null;
  12381. /**
  12382. * Variable: enabled
  12383. *
  12384. * Specifies if events are handled. Default is true.
  12385. */
  12386. mxToolbar.prototype.enabled = true;
  12387. /**
  12388. * Variable: noReset
  12389. *
  12390. * Specifies if <resetMode> requires a forced flag of true for resetting
  12391. * the current mode in the toolbar. Default is false. This is set to true
  12392. * if the toolbar item is double clicked to avoid a reset after a single
  12393. * use of the item.
  12394. */
  12395. mxToolbar.prototype.noReset = false;
  12396. /**
  12397. * Variable: updateDefaultMode
  12398. *
  12399. * Boolean indicating if the default mode should be the last selected
  12400. * switch mode or the first inserted switch mode. Default is true, that
  12401. * is the last selected switch mode is the default mode. The default mode
  12402. * is the mode to be selected after a reset of the toolbar. If this is
  12403. * false, then the default mode is the first inserted mode item regardless
  12404. * of what was last selected. Otherwise, the selected item after a reset is
  12405. * the previously selected item.
  12406. */
  12407. mxToolbar.prototype.updateDefaultMode = true;
  12408. /**
  12409. * Function: addItem
  12410. *
  12411. * Adds the given function as an image with the specified title and icon
  12412. * and returns the new image node.
  12413. *
  12414. * Parameters:
  12415. *
  12416. * title - Optional string that is used as the tooltip.
  12417. * icon - Optional URL of the image to be used. If no URL is given, then a
  12418. * button is created.
  12419. * funct - Function to execute on a mouse click.
  12420. * pressedIcon - Optional URL of the pressed image. Default is a gray
  12421. * background.
  12422. * style - Optional style classname. Default is mxToolbarItem.
  12423. * factoryMethod - Optional factory method for popup menu, eg.
  12424. * function(menu, evt, cell) { menu.addItem('Hello, World!'); }
  12425. */
  12426. mxToolbar.prototype.addItem = function(title, icon, funct, pressedIcon, style, factoryMethod)
  12427. {
  12428. var img = document.createElement((icon != null) ? 'img' : 'button');
  12429. var initialClassName = style || ((factoryMethod != null) ?
  12430. 'mxToolbarMode' : 'mxToolbarItem');
  12431. img.className = initialClassName;
  12432. img.setAttribute('src', icon);
  12433. if (title != null)
  12434. {
  12435. if (icon != null)
  12436. {
  12437. img.setAttribute('title', title);
  12438. }
  12439. else
  12440. {
  12441. mxUtils.write(img, title);
  12442. }
  12443. }
  12444. this.container.appendChild(img);
  12445. // Invokes the function on a click on the toolbar item
  12446. if (funct != null)
  12447. {
  12448. mxEvent.addListener(img, 'click', funct);
  12449. if (mxClient.IS_TOUCH)
  12450. {
  12451. mxEvent.addListener(img, 'touchend', funct);
  12452. }
  12453. }
  12454. var mouseHandler = mxUtils.bind(this, function(evt)
  12455. {
  12456. if (pressedIcon != null)
  12457. {
  12458. img.setAttribute('src', icon);
  12459. }
  12460. else
  12461. {
  12462. img.style.backgroundColor = '';
  12463. }
  12464. });
  12465. // Highlights the toolbar item with a gray background
  12466. // while it is being clicked with the mouse
  12467. mxEvent.addGestureListeners(img, mxUtils.bind(this, function(evt)
  12468. {
  12469. if (pressedIcon != null)
  12470. {
  12471. img.setAttribute('src', pressedIcon);
  12472. }
  12473. else
  12474. {
  12475. img.style.backgroundColor = 'gray';
  12476. }
  12477. // Popup Menu
  12478. if (factoryMethod != null)
  12479. {
  12480. if (this.menu == null)
  12481. {
  12482. this.menu = new mxPopupMenu();
  12483. this.menu.init();
  12484. }
  12485. var last = this.currentImg;
  12486. if (this.menu.isMenuShowing())
  12487. {
  12488. this.menu.hideMenu();
  12489. }
  12490. if (last != img)
  12491. {
  12492. // Redirects factory method to local factory method
  12493. this.currentImg = img;
  12494. this.menu.factoryMethod = factoryMethod;
  12495. var point = new mxPoint(
  12496. img.offsetLeft,
  12497. img.offsetTop + img.offsetHeight);
  12498. this.menu.popup(point.x, point.y, null, evt);
  12499. // Sets and overrides to restore classname
  12500. if (this.menu.isMenuShowing())
  12501. {
  12502. img.className = initialClassName + 'Selected';
  12503. this.menu.hideMenu = function()
  12504. {
  12505. mxPopupMenu.prototype.hideMenu.apply(this);
  12506. img.className = initialClassName;
  12507. this.currentImg = null;
  12508. };
  12509. }
  12510. }
  12511. }
  12512. }), null, mouseHandler);
  12513. mxEvent.addListener(img, 'mouseout', mouseHandler);
  12514. return img;
  12515. };
  12516. /**
  12517. * Function: addCombo
  12518. *
  12519. * Adds and returns a new SELECT element using the given style. The element
  12520. * is placed inside a DIV with the mxToolbarComboContainer style classname.
  12521. *
  12522. * Parameters:
  12523. *
  12524. * style - Optional style classname. Default is mxToolbarCombo.
  12525. */
  12526. mxToolbar.prototype.addCombo = function(style)
  12527. {
  12528. var div = document.createElement('div');
  12529. div.style.display = 'inline';
  12530. div.className = 'mxToolbarComboContainer';
  12531. var select = document.createElement('select');
  12532. select.className = style || 'mxToolbarCombo';
  12533. div.appendChild(select);
  12534. this.container.appendChild(div);
  12535. return select;
  12536. };
  12537. /**
  12538. * Function: addCombo
  12539. *
  12540. * Adds and returns a new SELECT element using the given title as the
  12541. * default element. The selection is reset to this element after each
  12542. * change.
  12543. *
  12544. * Parameters:
  12545. *
  12546. * title - String that specifies the title of the default element.
  12547. * style - Optional style classname. Default is mxToolbarCombo.
  12548. */
  12549. mxToolbar.prototype.addActionCombo = function(title, style)
  12550. {
  12551. var select = document.createElement('select');
  12552. select.className = style || 'mxToolbarCombo';
  12553. this.addOption(select, title, null);
  12554. mxEvent.addListener(select, 'change', function(evt)
  12555. {
  12556. var value = select.options[select.selectedIndex];
  12557. select.selectedIndex = 0;
  12558. if (value.funct != null)
  12559. {
  12560. value.funct(evt);
  12561. }
  12562. });
  12563. this.container.appendChild(select);
  12564. return select;
  12565. };
  12566. /**
  12567. * Function: addOption
  12568. *
  12569. * Adds and returns a new OPTION element inside the given SELECT element.
  12570. * If the given value is a function then it is stored in the option's funct
  12571. * field.
  12572. *
  12573. * Parameters:
  12574. *
  12575. * combo - SELECT element that will contain the new entry.
  12576. * title - String that specifies the title of the option.
  12577. * value - Specifies the value associated with this option.
  12578. */
  12579. mxToolbar.prototype.addOption = function(combo, title, value)
  12580. {
  12581. var option = document.createElement('option');
  12582. mxUtils.writeln(option, title);
  12583. if (typeof(value) == 'function')
  12584. {
  12585. option.funct = value;
  12586. }
  12587. else
  12588. {
  12589. option.setAttribute('value', value);
  12590. }
  12591. combo.appendChild(option);
  12592. return option;
  12593. };
  12594. /**
  12595. * Function: addSwitchMode
  12596. *
  12597. * Adds a new selectable item to the toolbar. Only one switch mode item may
  12598. * be selected at a time. The currently selected item is the default item
  12599. * after a reset of the toolbar.
  12600. */
  12601. mxToolbar.prototype.addSwitchMode = function(title, icon, funct, pressedIcon, style)
  12602. {
  12603. var img = document.createElement('img');
  12604. img.initialClassName = style || 'mxToolbarMode';
  12605. img.className = img.initialClassName;
  12606. img.setAttribute('src', icon);
  12607. img.altIcon = pressedIcon;
  12608. if (title != null)
  12609. {
  12610. img.setAttribute('title', title);
  12611. }
  12612. mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
  12613. {
  12614. var tmp = this.selectedMode.altIcon;
  12615. if (tmp != null)
  12616. {
  12617. this.selectedMode.altIcon = this.selectedMode.getAttribute('src');
  12618. this.selectedMode.setAttribute('src', tmp);
  12619. }
  12620. else
  12621. {
  12622. this.selectedMode.className = this.selectedMode.initialClassName;
  12623. }
  12624. if (this.updateDefaultMode)
  12625. {
  12626. this.defaultMode = img;
  12627. }
  12628. this.selectedMode = img;
  12629. var tmp = img.altIcon;
  12630. if (tmp != null)
  12631. {
  12632. img.altIcon = img.getAttribute('src');
  12633. img.setAttribute('src', tmp);
  12634. }
  12635. else
  12636. {
  12637. img.className = img.initialClassName+'Selected';
  12638. }
  12639. this.fireEvent(new mxEventObject(mxEvent.SELECT));
  12640. funct();
  12641. }));
  12642. this.container.appendChild(img);
  12643. if (this.defaultMode == null)
  12644. {
  12645. this.defaultMode = img;
  12646. // Function should fire only once so
  12647. // do not pass it with the select event
  12648. this.selectMode(img);
  12649. funct();
  12650. }
  12651. return img;
  12652. };
  12653. /**
  12654. * Function: addMode
  12655. *
  12656. * Adds a new item to the toolbar. The selection is typically reset after
  12657. * the item has been consumed, for example by adding a new vertex to the
  12658. * graph. The reset is not carried out if the item is double clicked.
  12659. *
  12660. * The function argument uses the following signature: funct(evt, cell) where
  12661. * evt is the native mouse event and cell is the cell under the mouse.
  12662. */
  12663. mxToolbar.prototype.addMode = function(title, icon, funct, pressedIcon, style, toggle)
  12664. {
  12665. toggle = (toggle != null) ? toggle : true;
  12666. var img = document.createElement((icon != null) ? 'img' : 'button');
  12667. img.initialClassName = style || 'mxToolbarMode';
  12668. img.className = img.initialClassName;
  12669. img.setAttribute('src', icon);
  12670. img.altIcon = pressedIcon;
  12671. if (title != null)
  12672. {
  12673. img.setAttribute('title', title);
  12674. }
  12675. if (this.enabled && toggle)
  12676. {
  12677. mxEvent.addListener(img, 'click', mxUtils.bind(this, function(evt)
  12678. {
  12679. this.selectMode(img, funct);
  12680. this.noReset = false;
  12681. }));
  12682. mxEvent.addListener(img, 'dblclick', mxUtils.bind(this, function(evt)
  12683. {
  12684. this.selectMode(img, funct);
  12685. this.noReset = true;
  12686. }));
  12687. if (this.defaultMode == null)
  12688. {
  12689. this.defaultMode = img;
  12690. this.defaultFunction = funct;
  12691. this.selectMode(img, funct);
  12692. }
  12693. }
  12694. this.container.appendChild(img);
  12695. return img;
  12696. };
  12697. /**
  12698. * Function: selectMode
  12699. *
  12700. * Resets the state of the previously selected mode and displays the given
  12701. * DOM node as selected. This function fires a select event with the given
  12702. * function as a parameter.
  12703. */
  12704. mxToolbar.prototype.selectMode = function(domNode, funct)
  12705. {
  12706. if (this.selectedMode != domNode)
  12707. {
  12708. if (this.selectedMode != null)
  12709. {
  12710. var tmp = this.selectedMode.altIcon;
  12711. if (tmp != null)
  12712. {
  12713. this.selectedMode.altIcon = this.selectedMode.getAttribute('src');
  12714. this.selectedMode.setAttribute('src', tmp);
  12715. }
  12716. else
  12717. {
  12718. this.selectedMode.className = this.selectedMode.initialClassName;
  12719. }
  12720. }
  12721. this.selectedMode = domNode;
  12722. var tmp = this.selectedMode.altIcon;
  12723. if (tmp != null)
  12724. {
  12725. this.selectedMode.altIcon = this.selectedMode.getAttribute('src');
  12726. this.selectedMode.setAttribute('src', tmp);
  12727. }
  12728. else
  12729. {
  12730. this.selectedMode.className = this.selectedMode.initialClassName+'Selected';
  12731. }
  12732. this.fireEvent(new mxEventObject(mxEvent.SELECT, "function", funct));
  12733. }
  12734. };
  12735. /**
  12736. * Function: resetMode
  12737. *
  12738. * Selects the default mode and resets the state of the previously selected
  12739. * mode.
  12740. */
  12741. mxToolbar.prototype.resetMode = function(forced)
  12742. {
  12743. if ((forced || !this.noReset) && this.selectedMode != this.defaultMode)
  12744. {
  12745. // The last selected switch mode will be activated
  12746. // so the function was already executed and is
  12747. // no longer required here
  12748. this.selectMode(this.defaultMode, this.defaultFunction);
  12749. }
  12750. };
  12751. /**
  12752. * Function: addSeparator
  12753. *
  12754. * Adds the specifies image as a separator.
  12755. *
  12756. * Parameters:
  12757. *
  12758. * icon - URL of the separator icon.
  12759. */
  12760. mxToolbar.prototype.addSeparator = function(icon)
  12761. {
  12762. return this.addItem(null, icon, null);
  12763. };
  12764. /**
  12765. * Function: addBreak
  12766. *
  12767. * Adds a break to the container.
  12768. */
  12769. mxToolbar.prototype.addBreak = function()
  12770. {
  12771. mxUtils.br(this.container);
  12772. };
  12773. /**
  12774. * Function: addLine
  12775. *
  12776. * Adds a horizontal line to the container.
  12777. */
  12778. mxToolbar.prototype.addLine = function()
  12779. {
  12780. var hr = document.createElement('hr');
  12781. hr.style.marginRight = '6px';
  12782. hr.setAttribute('size', '1');
  12783. this.container.appendChild(hr);
  12784. };
  12785. /**
  12786. * Function: destroy
  12787. *
  12788. * Removes the toolbar and all its associated resources.
  12789. */
  12790. mxToolbar.prototype.destroy = function ()
  12791. {
  12792. mxEvent.release(this.container);
  12793. this.container = null;
  12794. this.defaultMode = null;
  12795. this.defaultFunction = null;
  12796. this.selectedMode = null;
  12797. if (this.menu != null)
  12798. {
  12799. this.menu.destroy();
  12800. }
  12801. };
  12802. /**
  12803. * Copyright (c) 2006-2015, JGraph Ltd
  12804. * Copyright (c) 2006-2015, Gaudenz Alder
  12805. */
  12806. /**
  12807. * Class: mxUndoableEdit
  12808. *
  12809. * Implements a composite undoable edit. Here is an example for a custom change
  12810. * which gets executed via the model:
  12811. *
  12812. * (code)
  12813. * function CustomChange(model, name)
  12814. * {
  12815. * this.model = model;
  12816. * this.name = name;
  12817. * this.previous = name;
  12818. * };
  12819. *
  12820. * CustomChange.prototype.execute = function()
  12821. * {
  12822. * var tmp = this.model.name;
  12823. * this.model.name = this.previous;
  12824. * this.previous = tmp;
  12825. * };
  12826. *
  12827. * var name = prompt('Enter name');
  12828. * graph.model.execute(new CustomChange(graph.model, name));
  12829. * (end)
  12830. *
  12831. * Event: mxEvent.EXECUTED
  12832. *
  12833. * Fires between START_EDIT and END_EDIT after an atomic change was executed.
  12834. * The <code>change</code> property contains the change that was executed.
  12835. *
  12836. * Event: mxEvent.START_EDIT
  12837. *
  12838. * Fires before a set of changes will be executed in <undo> or <redo>.
  12839. * This event contains no properties.
  12840. *
  12841. * Event: mxEvent.END_EDIT
  12842. *
  12843. * Fires after a set of changeswas executed in <undo> or <redo>.
  12844. * This event contains no properties.
  12845. *
  12846. * Constructor: mxUndoableEdit
  12847. *
  12848. * Constructs a new undoable edit for the given source.
  12849. */
  12850. function mxUndoableEdit(source, significant)
  12851. {
  12852. this.source = source;
  12853. this.changes = [];
  12854. this.significant = (significant != null) ? significant : true;
  12855. };
  12856. /**
  12857. * Variable: source
  12858. *
  12859. * Specifies the source of the edit.
  12860. */
  12861. mxUndoableEdit.prototype.source = null;
  12862. /**
  12863. * Variable: changes
  12864. *
  12865. * Array that contains the changes that make up this edit. The changes are
  12866. * expected to either have an undo and redo function, or an execute
  12867. * function. Default is an empty array.
  12868. */
  12869. mxUndoableEdit.prototype.changes = null;
  12870. /**
  12871. * Variable: significant
  12872. *
  12873. * Specifies if the undoable change is significant.
  12874. * Default is true.
  12875. */
  12876. mxUndoableEdit.prototype.significant = null;
  12877. /**
  12878. * Variable: undone
  12879. *
  12880. * Specifies if this edit has been undone. Default is false.
  12881. */
  12882. mxUndoableEdit.prototype.undone = false;
  12883. /**
  12884. * Variable: redone
  12885. *
  12886. * Specifies if this edit has been redone. Default is false.
  12887. */
  12888. mxUndoableEdit.prototype.redone = false;
  12889. /**
  12890. * Function: isEmpty
  12891. *
  12892. * Returns true if the this edit contains no changes.
  12893. */
  12894. mxUndoableEdit.prototype.isEmpty = function()
  12895. {
  12896. return this.changes.length == 0;
  12897. };
  12898. /**
  12899. * Function: isSignificant
  12900. *
  12901. * Returns <significant>.
  12902. */
  12903. mxUndoableEdit.prototype.isSignificant = function()
  12904. {
  12905. return this.significant;
  12906. };
  12907. /**
  12908. * Function: add
  12909. *
  12910. * Adds the specified change to this edit. The change is an object that is
  12911. * expected to either have an undo and redo, or an execute function.
  12912. */
  12913. mxUndoableEdit.prototype.add = function(change)
  12914. {
  12915. this.changes.push(change);
  12916. };
  12917. /**
  12918. * Function: notify
  12919. *
  12920. * Hook to notify any listeners of the changes after an <undo> or <redo>
  12921. * has been carried out. This implementation is empty.
  12922. */
  12923. mxUndoableEdit.prototype.notify = function() { };
  12924. /**
  12925. * Function: die
  12926. *
  12927. * Hook to free resources after the edit has been removed from the command
  12928. * history. This implementation is empty.
  12929. */
  12930. mxUndoableEdit.prototype.die = function() { };
  12931. /**
  12932. * Function: undo
  12933. *
  12934. * Undoes all changes in this edit.
  12935. */
  12936. mxUndoableEdit.prototype.undo = function()
  12937. {
  12938. if (!this.undone)
  12939. {
  12940. this.source.fireEvent(new mxEventObject(mxEvent.START_EDIT));
  12941. var count = this.changes.length;
  12942. for (var i = count - 1; i >= 0; i--)
  12943. {
  12944. var change = this.changes[i];
  12945. if (change.execute != null)
  12946. {
  12947. change.execute();
  12948. }
  12949. else if (change.undo != null)
  12950. {
  12951. change.undo();
  12952. }
  12953. // New global executed event
  12954. this.source.fireEvent(new mxEventObject(mxEvent.EXECUTED, 'change', change));
  12955. }
  12956. this.undone = true;
  12957. this.redone = false;
  12958. this.source.fireEvent(new mxEventObject(mxEvent.END_EDIT));
  12959. }
  12960. this.notify();
  12961. };
  12962. /**
  12963. * Function: redo
  12964. *
  12965. * Redoes all changes in this edit.
  12966. */
  12967. mxUndoableEdit.prototype.redo = function()
  12968. {
  12969. if (!this.redone)
  12970. {
  12971. this.source.fireEvent(new mxEventObject(mxEvent.START_EDIT));
  12972. var count = this.changes.length;
  12973. for (var i = 0; i < count; i++)
  12974. {
  12975. var change = this.changes[i];
  12976. if (change.execute != null)
  12977. {
  12978. change.execute();
  12979. }
  12980. else if (change.redo != null)
  12981. {
  12982. change.redo();
  12983. }
  12984. // New global executed event
  12985. this.source.fireEvent(new mxEventObject(mxEvent.EXECUTED, 'change', change));
  12986. }
  12987. this.undone = false;
  12988. this.redone = true;
  12989. this.source.fireEvent(new mxEventObject(mxEvent.END_EDIT));
  12990. }
  12991. this.notify();
  12992. };
  12993. /**
  12994. * Copyright (c) 2006-2015, JGraph Ltd
  12995. * Copyright (c) 2006-2015, Gaudenz Alder
  12996. */
  12997. /**
  12998. * Class: mxUndoManager
  12999. *
  13000. * Implements a command history. When changing the graph model, an
  13001. * <mxUndoableChange> object is created at the start of the transaction (when
  13002. * model.beginUpdate is called). All atomic changes are then added to this
  13003. * object until the last model.endUpdate call, at which point the
  13004. * <mxUndoableEdit> is dispatched in an event, and added to the history inside
  13005. * <mxUndoManager>. This is done by an event listener in
  13006. * <mxEditor.installUndoHandler>.
  13007. *
  13008. * Each atomic change of the model is represented by an object (eg.
  13009. * <mxRootChange>, <mxChildChange>, <mxTerminalChange> etc) which contains the
  13010. * complete undo information. The <mxUndoManager> also listens to the
  13011. * <mxGraphView> and stores it's changes to the current root as insignificant
  13012. * undoable changes, so that drilling (step into, step up) is undone.
  13013. *
  13014. * This means when you execute an atomic change on the model, then change the
  13015. * current root on the view and click undo, the change of the root will be
  13016. * undone together with the change of the model so that the display represents
  13017. * the state at which the model was changed. However, these changes are not
  13018. * transmitted for sharing as they do not represent a state change.
  13019. *
  13020. * Example:
  13021. *
  13022. * When adding an undo manager to a graph, make sure to add it
  13023. * to the model and the view as well to maintain a consistent
  13024. * display across multiple undo/redo steps.
  13025. *
  13026. * (code)
  13027. * var undoManager = new mxUndoManager();
  13028. * var listener = function(sender, evt)
  13029. * {
  13030. * undoManager.undoableEditHappened(evt.getProperty('edit'));
  13031. * };
  13032. * graph.getModel().addListener(mxEvent.UNDO, listener);
  13033. * graph.getView().addListener(mxEvent.UNDO, listener);
  13034. * (end)
  13035. *
  13036. * The code creates a function that informs the undoManager
  13037. * of an undoable edit and binds it to the undo event of
  13038. * <mxGraphModel> and <mxGraphView> using
  13039. * <mxEventSource.addListener>.
  13040. *
  13041. * Event: mxEvent.CLEAR
  13042. *
  13043. * Fires after <clear> was invoked. This event has no properties.
  13044. *
  13045. * Event: mxEvent.UNDO
  13046. *
  13047. * Fires afer a significant edit was undone in <undo>. The <code>edit</code>
  13048. * property contains the <mxUndoableEdit> that was undone.
  13049. *
  13050. * Event: mxEvent.REDO
  13051. *
  13052. * Fires afer a significant edit was redone in <redo>. The <code>edit</code>
  13053. * property contains the <mxUndoableEdit> that was redone.
  13054. *
  13055. * Event: mxEvent.ADD
  13056. *
  13057. * Fires after an undoable edit was added to the history. The <code>edit</code>
  13058. * property contains the <mxUndoableEdit> that was added.
  13059. *
  13060. * Constructor: mxUndoManager
  13061. *
  13062. * Constructs a new undo manager with the given history size. If no history
  13063. * size is given, then a default size of 100 steps is used.
  13064. */
  13065. function mxUndoManager(size)
  13066. {
  13067. this.size = (size != null) ? size : 100;
  13068. this.clear();
  13069. };
  13070. /**
  13071. * Extends mxEventSource.
  13072. */
  13073. mxUndoManager.prototype = new mxEventSource();
  13074. mxUndoManager.prototype.constructor = mxUndoManager;
  13075. /**
  13076. * Variable: size
  13077. *
  13078. * Maximum command history size. 0 means unlimited history. Default is
  13079. * 100.
  13080. */
  13081. mxUndoManager.prototype.size = null;
  13082. /**
  13083. * Variable: history
  13084. *
  13085. * Array that contains the steps of the command history.
  13086. */
  13087. mxUndoManager.prototype.history = null;
  13088. /**
  13089. * Variable: indexOfNextAdd
  13090. *
  13091. * Index of the element to be added next.
  13092. */
  13093. mxUndoManager.prototype.indexOfNextAdd = 0;
  13094. /**
  13095. * Function: isEmpty
  13096. *
  13097. * Returns true if the history is empty.
  13098. */
  13099. mxUndoManager.prototype.isEmpty = function()
  13100. {
  13101. return this.history.length == 0;
  13102. };
  13103. /**
  13104. * Function: clear
  13105. *
  13106. * Clears the command history.
  13107. */
  13108. mxUndoManager.prototype.clear = function()
  13109. {
  13110. this.history = [];
  13111. this.indexOfNextAdd = 0;
  13112. this.fireEvent(new mxEventObject(mxEvent.CLEAR));
  13113. };
  13114. /**
  13115. * Function: canUndo
  13116. *
  13117. * Returns true if an undo is possible.
  13118. */
  13119. mxUndoManager.prototype.canUndo = function()
  13120. {
  13121. return this.indexOfNextAdd > 0;
  13122. };
  13123. /**
  13124. * Function: undo
  13125. *
  13126. * Undoes the last change.
  13127. */
  13128. mxUndoManager.prototype.undo = function()
  13129. {
  13130. while (this.indexOfNextAdd > 0)
  13131. {
  13132. var edit = this.history[--this.indexOfNextAdd];
  13133. edit.undo();
  13134. if (edit.isSignificant())
  13135. {
  13136. this.fireEvent(new mxEventObject(mxEvent.UNDO, 'edit', edit));
  13137. break;
  13138. }
  13139. }
  13140. };
  13141. /**
  13142. * Function: canRedo
  13143. *
  13144. * Returns true if a redo is possible.
  13145. */
  13146. mxUndoManager.prototype.canRedo = function()
  13147. {
  13148. return this.indexOfNextAdd < this.history.length;
  13149. };
  13150. /**
  13151. * Function: redo
  13152. *
  13153. * Redoes the last change.
  13154. */
  13155. mxUndoManager.prototype.redo = function()
  13156. {
  13157. var n = this.history.length;
  13158. while (this.indexOfNextAdd < n)
  13159. {
  13160. var edit = this.history[this.indexOfNextAdd++];
  13161. edit.redo();
  13162. if (edit.isSignificant())
  13163. {
  13164. this.fireEvent(new mxEventObject(mxEvent.REDO, 'edit', edit));
  13165. break;
  13166. }
  13167. }
  13168. };
  13169. /**
  13170. * Function: undoableEditHappened
  13171. *
  13172. * Method to be called to add new undoable edits to the <history>.
  13173. */
  13174. mxUndoManager.prototype.undoableEditHappened = function(undoableEdit)
  13175. {
  13176. this.trim();
  13177. if (this.size > 0 &&
  13178. this.size == this.history.length)
  13179. {
  13180. this.history.shift();
  13181. }
  13182. this.history.push(undoableEdit);
  13183. this.indexOfNextAdd = this.history.length;
  13184. this.fireEvent(new mxEventObject(mxEvent.ADD, 'edit', undoableEdit));
  13185. };
  13186. /**
  13187. * Function: trim
  13188. *
  13189. * Removes all pending steps after <indexOfNextAdd> from the history,
  13190. * invoking die on each edit. This is called from <undoableEditHappened>.
  13191. */
  13192. mxUndoManager.prototype.trim = function()
  13193. {
  13194. if (this.history.length > this.indexOfNextAdd)
  13195. {
  13196. var edits = this.history.splice(this.indexOfNextAdd,
  13197. this.history.length - this.indexOfNextAdd);
  13198. for (var i = 0; i < edits.length; i++)
  13199. {
  13200. edits[i].die();
  13201. }
  13202. }
  13203. };
  13204. /**
  13205. * Copyright (c) 2006-2015, JGraph Ltd
  13206. * Copyright (c) 2006-2015, Gaudenz Alder
  13207. */
  13208. /**
  13209. *
  13210. * Class: mxUrlConverter
  13211. *
  13212. * Converts relative and absolute URLs to absolute URLs with protocol and domain.
  13213. */
  13214. var mxUrlConverter = function()
  13215. {
  13216. // Empty constructor
  13217. };
  13218. /**
  13219. * Variable: enabled
  13220. *
  13221. * Specifies if the converter is enabled. Default is true.
  13222. */
  13223. mxUrlConverter.prototype.enabled = true;
  13224. /**
  13225. * Variable: baseUrl
  13226. *
  13227. * Specifies the base URL to be used as a prefix for relative URLs.
  13228. */
  13229. mxUrlConverter.prototype.baseUrl = null;
  13230. /**
  13231. * Variable: baseDomain
  13232. *
  13233. * Specifies the base domain to be used as a prefix for absolute URLs.
  13234. */
  13235. mxUrlConverter.prototype.baseDomain = null;
  13236. /**
  13237. * Function: updateBaseUrl
  13238. *
  13239. * Private helper function to update the base URL.
  13240. */
  13241. mxUrlConverter.prototype.updateBaseUrl = function()
  13242. {
  13243. this.baseDomain = location.protocol + '//' + location.host;
  13244. this.baseUrl = this.baseDomain + location.pathname;
  13245. var tmp = this.baseUrl.lastIndexOf('/');
  13246. // Strips filename etc
  13247. if (tmp > 0)
  13248. {
  13249. this.baseUrl = this.baseUrl.substring(0, tmp + 1);
  13250. }
  13251. };
  13252. /**
  13253. * Function: isEnabled
  13254. *
  13255. * Returns <enabled>.
  13256. */
  13257. mxUrlConverter.prototype.isEnabled = function()
  13258. {
  13259. return this.enabled;
  13260. };
  13261. /**
  13262. * Function: setEnabled
  13263. *
  13264. * Sets <enabled>.
  13265. */
  13266. mxUrlConverter.prototype.setEnabled = function(value)
  13267. {
  13268. this.enabled = value;
  13269. };
  13270. /**
  13271. * Function: getBaseUrl
  13272. *
  13273. * Returns <baseUrl>.
  13274. */
  13275. mxUrlConverter.prototype.getBaseUrl = function()
  13276. {
  13277. return this.baseUrl;
  13278. };
  13279. /**
  13280. * Function: setBaseUrl
  13281. *
  13282. * Sets <baseUrl>.
  13283. */
  13284. mxUrlConverter.prototype.setBaseUrl = function(value)
  13285. {
  13286. this.baseUrl = value;
  13287. };
  13288. /**
  13289. * Function: getBaseDomain
  13290. *
  13291. * Returns <baseDomain>.
  13292. */
  13293. mxUrlConverter.prototype.getBaseDomain = function()
  13294. {
  13295. return this.baseDomain;
  13296. };
  13297. /**
  13298. * Function: setBaseDomain
  13299. *
  13300. * Sets <baseDomain>.
  13301. */
  13302. mxUrlConverter.prototype.setBaseDomain = function(value)
  13303. {
  13304. this.baseDomain = value;
  13305. };
  13306. /**
  13307. * Function: isRelativeUrl
  13308. *
  13309. * Returns true if the given URL is relative.
  13310. */
  13311. mxUrlConverter.prototype.isRelativeUrl = function(url)
  13312. {
  13313. return url != null && url.substring(0, 2) != '//' && url.substring(0, 7) != 'http://' &&
  13314. url.substring(0, 8) != 'https://' && url.substring(0, 10) != 'data:image' &&
  13315. url.substring(0, 7) != 'file://';
  13316. };
  13317. /**
  13318. * Function: convert
  13319. *
  13320. * Converts the given URL to an absolute URL with protol and domain.
  13321. * Relative URLs are first converted to absolute URLs.
  13322. */
  13323. mxUrlConverter.prototype.convert = function(url)
  13324. {
  13325. if (this.isEnabled() && this.isRelativeUrl(url))
  13326. {
  13327. if (this.getBaseUrl() == null)
  13328. {
  13329. this.updateBaseUrl();
  13330. }
  13331. if (url.charAt(0) == '/')
  13332. {
  13333. url = this.getBaseDomain() + url;
  13334. }
  13335. else
  13336. {
  13337. url = this.getBaseUrl() + url;
  13338. }
  13339. }
  13340. return url;
  13341. };
  13342. /**
  13343. * Copyright (c) 2006-2015, JGraph Ltd
  13344. * Copyright (c) 2006-2015, Gaudenz Alder
  13345. */
  13346. /**
  13347. * Class: mxPanningManager
  13348. *
  13349. * Implements a handler for panning.
  13350. */
  13351. function mxPanningManager(graph)
  13352. {
  13353. this.thread = null;
  13354. this.active = false;
  13355. this.tdx = 0;
  13356. this.tdy = 0;
  13357. this.t0x = 0;
  13358. this.t0y = 0;
  13359. this.dx = 0;
  13360. this.dy = 0;
  13361. this.scrollbars = false;
  13362. this.scrollLeft = 0;
  13363. this.scrollTop = 0;
  13364. this.mouseListener =
  13365. {
  13366. mouseDown: function(sender, me) { },
  13367. mouseMove: function(sender, me) { },
  13368. mouseUp: mxUtils.bind(this, function(sender, me)
  13369. {
  13370. if (this.active)
  13371. {
  13372. this.stop();
  13373. }
  13374. })
  13375. };
  13376. graph.addMouseListener(this.mouseListener);
  13377. this.mouseUpListener = mxUtils.bind(this, function()
  13378. {
  13379. if (this.active)
  13380. {
  13381. this.stop();
  13382. }
  13383. });
  13384. // Stops scrolling on every mouseup anywhere in the document
  13385. mxEvent.addListener(document, 'mouseup', this.mouseUpListener);
  13386. var createThread = mxUtils.bind(this, function()
  13387. {
  13388. this.scrollbars = mxUtils.hasScrollbars(graph.container);
  13389. this.scrollLeft = graph.container.scrollLeft;
  13390. this.scrollTop = graph.container.scrollTop;
  13391. return window.setInterval(mxUtils.bind(this, function()
  13392. {
  13393. this.tdx -= this.dx;
  13394. this.tdy -= this.dy;
  13395. if (this.scrollbars)
  13396. {
  13397. var left = -graph.container.scrollLeft - Math.ceil(this.dx);
  13398. var top = -graph.container.scrollTop - Math.ceil(this.dy);
  13399. graph.panGraph(left, top);
  13400. graph.panDx = this.scrollLeft - graph.container.scrollLeft;
  13401. graph.panDy = this.scrollTop - graph.container.scrollTop;
  13402. graph.fireEvent(new mxEventObject(mxEvent.PAN));
  13403. // TODO: Implement graph.autoExtend
  13404. }
  13405. else
  13406. {
  13407. graph.panGraph(this.getDx(), this.getDy());
  13408. }
  13409. }), this.delay);
  13410. });
  13411. this.isActive = function()
  13412. {
  13413. return active;
  13414. };
  13415. this.getDx = function()
  13416. {
  13417. return Math.round(this.tdx);
  13418. };
  13419. this.getDy = function()
  13420. {
  13421. return Math.round(this.tdy);
  13422. };
  13423. this.start = function()
  13424. {
  13425. this.t0x = graph.view.translate.x;
  13426. this.t0y = graph.view.translate.y;
  13427. this.active = true;
  13428. };
  13429. this.panTo = function(x, y, w, h)
  13430. {
  13431. if (!this.active)
  13432. {
  13433. this.start();
  13434. }
  13435. this.scrollLeft = graph.container.scrollLeft;
  13436. this.scrollTop = graph.container.scrollTop;
  13437. w = (w != null) ? w : 0;
  13438. h = (h != null) ? h : 0;
  13439. var c = graph.container;
  13440. this.dx = x + w - c.scrollLeft - c.clientWidth;
  13441. if (this.dx < 0 && Math.abs(this.dx) < this.border)
  13442. {
  13443. this.dx = this.border + this.dx;
  13444. }
  13445. else if (this.handleMouseOut)
  13446. {
  13447. this.dx = Math.max(this.dx, 0);
  13448. }
  13449. else
  13450. {
  13451. this.dx = 0;
  13452. }
  13453. if (this.dx == 0)
  13454. {
  13455. this.dx = x - c.scrollLeft;
  13456. if (this.dx > 0 && this.dx < this.border)
  13457. {
  13458. this.dx = this.dx - this.border;
  13459. }
  13460. else if (this.handleMouseOut)
  13461. {
  13462. this.dx = Math.min(0, this.dx);
  13463. }
  13464. else
  13465. {
  13466. this.dx = 0;
  13467. }
  13468. }
  13469. this.dy = y + h - c.scrollTop - c.clientHeight;
  13470. if (this.dy < 0 && Math.abs(this.dy) < this.border)
  13471. {
  13472. this.dy = this.border + this.dy;
  13473. }
  13474. else if (this.handleMouseOut)
  13475. {
  13476. this.dy = Math.max(this.dy, 0);
  13477. }
  13478. else
  13479. {
  13480. this.dy = 0;
  13481. }
  13482. if (this.dy == 0)
  13483. {
  13484. this.dy = y - c.scrollTop;
  13485. if (this.dy > 0 && this.dy < this.border)
  13486. {
  13487. this.dy = this.dy - this.border;
  13488. }
  13489. else if (this.handleMouseOut)
  13490. {
  13491. this.dy = Math.min(0, this.dy);
  13492. }
  13493. else
  13494. {
  13495. this.dy = 0;
  13496. }
  13497. }
  13498. if (this.dx != 0 || this.dy != 0)
  13499. {
  13500. this.dx *= this.damper;
  13501. this.dy *= this.damper;
  13502. if (this.thread == null)
  13503. {
  13504. this.thread = createThread();
  13505. }
  13506. }
  13507. else if (this.thread != null)
  13508. {
  13509. window.clearInterval(this.thread);
  13510. this.thread = null;
  13511. }
  13512. };
  13513. this.stop = function()
  13514. {
  13515. if (this.active)
  13516. {
  13517. this.active = false;
  13518. if (this.thread != null)
  13519. {
  13520. window.clearInterval(this.thread);
  13521. this.thread = null;
  13522. }
  13523. this.tdx = 0;
  13524. this.tdy = 0;
  13525. if (!this.scrollbars)
  13526. {
  13527. var px = graph.panDx;
  13528. var py = graph.panDy;
  13529. if (px != 0 || py != 0)
  13530. {
  13531. graph.panGraph(0, 0);
  13532. graph.view.setTranslate(this.t0x + px / graph.view.scale, this.t0y + py / graph.view.scale);
  13533. }
  13534. }
  13535. else
  13536. {
  13537. graph.panDx = 0;
  13538. graph.panDy = 0;
  13539. graph.fireEvent(new mxEventObject(mxEvent.PAN));
  13540. }
  13541. }
  13542. };
  13543. this.destroy = function()
  13544. {
  13545. graph.removeMouseListener(this.mouseListener);
  13546. mxEvent.removeListener(document, 'mouseup', this.mouseUpListener);
  13547. };
  13548. };
  13549. /**
  13550. * Variable: damper
  13551. *
  13552. * Damper value for the panning. Default is 1/6.
  13553. */
  13554. mxPanningManager.prototype.damper = 1/6;
  13555. /**
  13556. * Variable: delay
  13557. *
  13558. * Delay in milliseconds for the panning. Default is 10.
  13559. */
  13560. mxPanningManager.prototype.delay = 10;
  13561. /**
  13562. * Variable: handleMouseOut
  13563. *
  13564. * Specifies if mouse events outside of the component should be handled. Default is true.
  13565. */
  13566. mxPanningManager.prototype.handleMouseOut = true;
  13567. /**
  13568. * Variable: border
  13569. *
  13570. * Border to handle automatic panning inside the component. Default is 0 (disabled).
  13571. */
  13572. mxPanningManager.prototype.border = 0;
  13573. /**
  13574. * Copyright (c) 2006-2015, JGraph Ltd
  13575. * Copyright (c) 2006-2015, Gaudenz Alder
  13576. */
  13577. /**
  13578. * Class: mxPopupMenu
  13579. *
  13580. * Basic popup menu. To add a vertical scrollbar to a given submenu, the
  13581. * following code can be used.
  13582. *
  13583. * (code)
  13584. * var mxPopupMenuShowMenu = mxPopupMenu.prototype.showMenu;
  13585. * mxPopupMenu.prototype.showMenu = function()
  13586. * {
  13587. * mxPopupMenuShowMenu.apply(this, arguments);
  13588. *
  13589. * this.div.style.overflowY = 'auto';
  13590. * this.div.style.overflowX = 'hidden';
  13591. * this.div.style.maxHeight = '160px';
  13592. * };
  13593. * (end)
  13594. *
  13595. * Constructor: mxPopupMenu
  13596. *
  13597. * Constructs a popupmenu.
  13598. *
  13599. * Event: mxEvent.SHOW
  13600. *
  13601. * Fires after the menu has been shown in <popup>.
  13602. */
  13603. function mxPopupMenu(factoryMethod)
  13604. {
  13605. this.factoryMethod = factoryMethod;
  13606. if (factoryMethod != null)
  13607. {
  13608. this.init();
  13609. }
  13610. };
  13611. /**
  13612. * Extends mxEventSource.
  13613. */
  13614. mxPopupMenu.prototype = new mxEventSource();
  13615. mxPopupMenu.prototype.constructor = mxPopupMenu;
  13616. /**
  13617. * Variable: submenuImage
  13618. *
  13619. * URL of the image to be used for the submenu icon.
  13620. */
  13621. mxPopupMenu.prototype.submenuImage = mxClient.imageBasePath + '/submenu.gif';
  13622. /**
  13623. * Variable: zIndex
  13624. *
  13625. * Specifies the zIndex for the popupmenu and its shadow. Default is 10006.
  13626. */
  13627. mxPopupMenu.prototype.zIndex = 10006;
  13628. /**
  13629. * Variable: factoryMethod
  13630. *
  13631. * Function that is used to create the popup menu. The function takes the
  13632. * current panning handler, the <mxCell> under the mouse and the mouse
  13633. * event that triggered the call as arguments.
  13634. */
  13635. mxPopupMenu.prototype.factoryMethod = null;
  13636. /**
  13637. * Variable: useLeftButtonForPopup
  13638. *
  13639. * Specifies if popupmenus should be activated by clicking the left mouse
  13640. * button. Default is false.
  13641. */
  13642. mxPopupMenu.prototype.useLeftButtonForPopup = false;
  13643. /**
  13644. * Variable: enabled
  13645. *
  13646. * Specifies if events are handled. Default is true.
  13647. */
  13648. mxPopupMenu.prototype.enabled = true;
  13649. /**
  13650. * Variable: itemCount
  13651. *
  13652. * Contains the number of times <addItem> has been called for a new menu.
  13653. */
  13654. mxPopupMenu.prototype.itemCount = 0;
  13655. /**
  13656. * Variable: autoExpand
  13657. *
  13658. * Specifies if submenus should be expanded on mouseover. Default is false.
  13659. */
  13660. mxPopupMenu.prototype.autoExpand = false;
  13661. /**
  13662. * Variable: smartSeparators
  13663. *
  13664. * Specifies if separators should only be added if a menu item follows them.
  13665. * Default is false.
  13666. */
  13667. mxPopupMenu.prototype.smartSeparators = false;
  13668. /**
  13669. * Variable: labels
  13670. *
  13671. * Specifies if any labels should be visible. Default is true.
  13672. */
  13673. mxPopupMenu.prototype.labels = true;
  13674. /**
  13675. * Function: init
  13676. *
  13677. * Initializes the shapes required for this vertex handler.
  13678. */
  13679. mxPopupMenu.prototype.init = function()
  13680. {
  13681. // Adds the inner table
  13682. this.table = document.createElement('table');
  13683. this.table.className = 'mxPopupMenu';
  13684. this.tbody = document.createElement('tbody');
  13685. this.table.appendChild(this.tbody);
  13686. // Adds the outer div
  13687. this.div = document.createElement('div');
  13688. this.div.className = 'mxPopupMenu';
  13689. this.div.style.display = 'inline';
  13690. this.div.style.zIndex = this.zIndex;
  13691. this.div.appendChild(this.table);
  13692. // Disables the context menu on the outer div
  13693. mxEvent.disableContextMenu(this.div);
  13694. };
  13695. /**
  13696. * Function: isEnabled
  13697. *
  13698. * Returns true if events are handled. This implementation
  13699. * returns <enabled>.
  13700. */
  13701. mxPopupMenu.prototype.isEnabled = function()
  13702. {
  13703. return this.enabled;
  13704. };
  13705. /**
  13706. * Function: setEnabled
  13707. *
  13708. * Enables or disables event handling. This implementation
  13709. * updates <enabled>.
  13710. */
  13711. mxPopupMenu.prototype.setEnabled = function(enabled)
  13712. {
  13713. this.enabled = enabled;
  13714. };
  13715. /**
  13716. * Function: isPopupTrigger
  13717. *
  13718. * Returns true if the given event is a popupmenu trigger for the optional
  13719. * given cell.
  13720. *
  13721. * Parameters:
  13722. *
  13723. * me - <mxMouseEvent> that represents the mouse event.
  13724. */
  13725. mxPopupMenu.prototype.isPopupTrigger = function(me)
  13726. {
  13727. return me.isPopupTrigger() || (this.useLeftButtonForPopup && mxEvent.isLeftMouseButton(me.getEvent()));
  13728. };
  13729. /**
  13730. * Function: addItem
  13731. *
  13732. * Adds the given item to the given parent item. If no parent item is specified
  13733. * then the item is added to the top-level menu. The return value may be used
  13734. * as the parent argument, ie. as a submenu item. The return value is the table
  13735. * row that represents the item.
  13736. *
  13737. * Paramters:
  13738. *
  13739. * title - String that represents the title of the menu item.
  13740. * image - Optional URL for the image icon.
  13741. * funct - Function associated that takes a mouseup or touchend event.
  13742. * parent - Optional item returned by <addItem>.
  13743. * iconCls - Optional string that represents the CSS class for the image icon.
  13744. * IconsCls is ignored if image is given.
  13745. * enabled - Optional boolean indicating if the item is enabled. Default is true.
  13746. * active - Optional boolean indicating if the menu should implement any event handling.
  13747. * Default is true.
  13748. * noHover - Optional boolean to disable hover state.
  13749. */
  13750. mxPopupMenu.prototype.addItem = function(title, image, funct, parent, iconCls, enabled, active, noHover)
  13751. {
  13752. parent = parent || this;
  13753. this.itemCount++;
  13754. // Smart separators only added if element contains items
  13755. if (parent.willAddSeparator)
  13756. {
  13757. if (parent.containsItems)
  13758. {
  13759. this.addSeparator(parent, true);
  13760. }
  13761. parent.willAddSeparator = false;
  13762. }
  13763. parent.containsItems = true;
  13764. var tr = document.createElement('tr');
  13765. tr.className = 'mxPopupMenuItem';
  13766. var col1 = document.createElement('td');
  13767. col1.className = 'mxPopupMenuIcon';
  13768. // Adds the given image into the first column
  13769. if (image != null)
  13770. {
  13771. var img = document.createElement('img');
  13772. img.src = image;
  13773. col1.appendChild(img);
  13774. }
  13775. else if (iconCls != null)
  13776. {
  13777. var div = document.createElement('div');
  13778. div.className = iconCls;
  13779. col1.appendChild(div);
  13780. }
  13781. tr.appendChild(col1);
  13782. if (this.labels)
  13783. {
  13784. var col2 = document.createElement('td');
  13785. col2.className = 'mxPopupMenuItem' +
  13786. ((enabled != null && !enabled) ? ' mxDisabled' : '');
  13787. mxUtils.write(col2, title);
  13788. col2.align = 'left';
  13789. tr.appendChild(col2);
  13790. var col3 = document.createElement('td');
  13791. col3.className = 'mxPopupMenuItem' +
  13792. ((enabled != null && !enabled) ? ' mxDisabled' : '');
  13793. col3.style.paddingRight = '6px';
  13794. col3.style.textAlign = 'right';
  13795. tr.appendChild(col3);
  13796. if (parent.div == null)
  13797. {
  13798. this.createSubmenu(parent);
  13799. }
  13800. }
  13801. parent.tbody.appendChild(tr);
  13802. if (active != false && enabled != false)
  13803. {
  13804. var currentSelection = null;
  13805. mxEvent.addGestureListeners(tr,
  13806. mxUtils.bind(this, function(evt)
  13807. {
  13808. this.eventReceiver = tr;
  13809. if (parent.activeRow != tr && parent.activeRow != parent)
  13810. {
  13811. if (parent.activeRow != null && parent.activeRow.div.parentNode != null)
  13812. {
  13813. this.hideSubmenu(parent);
  13814. }
  13815. if (tr.div != null)
  13816. {
  13817. this.showSubmenu(parent, tr);
  13818. parent.activeRow = tr;
  13819. }
  13820. }
  13821. // Workaround for lost current selection in page because of focus in IE
  13822. if (document.selection != null && (mxClient.IS_QUIRKS || document.documentMode == 8))
  13823. {
  13824. currentSelection = document.selection.createRange();
  13825. }
  13826. mxEvent.consume(evt);
  13827. }),
  13828. mxUtils.bind(this, function(evt)
  13829. {
  13830. if (parent.activeRow != tr && parent.activeRow != parent)
  13831. {
  13832. if (parent.activeRow != null && parent.activeRow.div.parentNode != null)
  13833. {
  13834. this.hideSubmenu(parent);
  13835. }
  13836. if (this.autoExpand && tr.div != null)
  13837. {
  13838. this.showSubmenu(parent, tr);
  13839. parent.activeRow = tr;
  13840. }
  13841. }
  13842. // Sets hover style because TR in IE doesn't have hover
  13843. if (!noHover)
  13844. {
  13845. tr.className = 'mxPopupMenuItemHover';
  13846. }
  13847. }),
  13848. mxUtils.bind(this, function(evt)
  13849. {
  13850. // EventReceiver avoids clicks on a submenu item
  13851. // which has just been shown in the mousedown
  13852. if (this.eventReceiver == tr)
  13853. {
  13854. if (parent.activeRow != tr)
  13855. {
  13856. this.hideMenu();
  13857. }
  13858. // Workaround for lost current selection in page because of focus in IE
  13859. if (currentSelection != null)
  13860. {
  13861. // Workaround for "unspecified error" in IE8 standards
  13862. try
  13863. {
  13864. currentSelection.select();
  13865. }
  13866. catch (e)
  13867. {
  13868. // ignore
  13869. }
  13870. currentSelection = null;
  13871. }
  13872. if (funct != null)
  13873. {
  13874. funct(evt);
  13875. }
  13876. }
  13877. this.eventReceiver = null;
  13878. mxEvent.consume(evt);
  13879. })
  13880. );
  13881. // Resets hover style because TR in IE doesn't have hover
  13882. if (!noHover)
  13883. {
  13884. mxEvent.addListener(tr, 'mouseout',
  13885. mxUtils.bind(this, function(evt)
  13886. {
  13887. tr.className = 'mxPopupMenuItem';
  13888. })
  13889. );
  13890. }
  13891. }
  13892. return tr;
  13893. };
  13894. /**
  13895. * Adds a checkmark to the given menuitem.
  13896. */
  13897. mxPopupMenu.prototype.addCheckmark = function(item, img)
  13898. {
  13899. var td = item.firstChild.nextSibling;
  13900. td.style.backgroundImage = 'url(\'' + img + '\')';
  13901. td.style.backgroundRepeat = 'no-repeat';
  13902. td.style.backgroundPosition = '2px 50%';
  13903. };
  13904. /**
  13905. * Function: createSubmenu
  13906. *
  13907. * Creates the nodes required to add submenu items inside the given parent
  13908. * item. This is called in <addItem> if a parent item is used for the first
  13909. * time. This adds various DOM nodes and a <submenuImage> to the parent.
  13910. *
  13911. * Parameters:
  13912. *
  13913. * parent - An item returned by <addItem>.
  13914. */
  13915. mxPopupMenu.prototype.createSubmenu = function(parent)
  13916. {
  13917. parent.table = document.createElement('table');
  13918. parent.table.className = 'mxPopupMenu';
  13919. parent.tbody = document.createElement('tbody');
  13920. parent.table.appendChild(parent.tbody);
  13921. parent.div = document.createElement('div');
  13922. parent.div.className = 'mxPopupMenu';
  13923. parent.div.style.position = 'absolute';
  13924. parent.div.style.display = 'inline';
  13925. parent.div.style.zIndex = this.zIndex;
  13926. parent.div.appendChild(parent.table);
  13927. var img = document.createElement('img');
  13928. img.setAttribute('src', this.submenuImage);
  13929. // Last column of the submenu item in the parent menu
  13930. td = parent.firstChild.nextSibling.nextSibling;
  13931. td.appendChild(img);
  13932. };
  13933. /**
  13934. * Function: showSubmenu
  13935. *
  13936. * Shows the submenu inside the given parent row.
  13937. */
  13938. mxPopupMenu.prototype.showSubmenu = function(parent, row)
  13939. {
  13940. if (row.div != null)
  13941. {
  13942. row.div.style.left = (parent.div.offsetLeft +
  13943. row.offsetLeft+row.offsetWidth - 1) + 'px';
  13944. row.div.style.top = (parent.div.offsetTop+row.offsetTop) + 'px';
  13945. document.body.appendChild(row.div);
  13946. // Moves the submenu to the left side if there is no space
  13947. var left = parseInt(row.div.offsetLeft);
  13948. var width = parseInt(row.div.offsetWidth);
  13949. var offset = mxUtils.getDocumentScrollOrigin(document);
  13950. var b = document.body;
  13951. var d = document.documentElement;
  13952. var right = offset.x + (b.clientWidth || d.clientWidth);
  13953. if (left + width > right)
  13954. {
  13955. row.div.style.left = Math.max(0, (parent.div.offsetLeft - width + ((mxClient.IS_IE) ? 6 : -6))) + 'px';
  13956. }
  13957. mxUtils.fit(row.div);
  13958. }
  13959. };
  13960. /**
  13961. * Function: addSeparator
  13962. *
  13963. * Adds a horizontal separator in the given parent item or the top-level menu
  13964. * if no parent is specified.
  13965. *
  13966. * Parameters:
  13967. *
  13968. * parent - Optional item returned by <addItem>.
  13969. * force - Optional boolean to ignore <smartSeparators>. Default is false.
  13970. */
  13971. mxPopupMenu.prototype.addSeparator = function(parent, force)
  13972. {
  13973. parent = parent || this;
  13974. if (this.smartSeparators && !force)
  13975. {
  13976. parent.willAddSeparator = true;
  13977. }
  13978. else if (parent.tbody != null)
  13979. {
  13980. parent.willAddSeparator = false;
  13981. var tr = document.createElement('tr');
  13982. var col1 = document.createElement('td');
  13983. col1.className = 'mxPopupMenuIcon';
  13984. col1.style.padding = '0 0 0 0px';
  13985. tr.appendChild(col1);
  13986. var col2 = document.createElement('td');
  13987. col2.style.padding = '0 0 0 0px';
  13988. col2.setAttribute('colSpan', '2');
  13989. var hr = document.createElement('hr');
  13990. hr.setAttribute('size', '1');
  13991. col2.appendChild(hr);
  13992. tr.appendChild(col2);
  13993. parent.tbody.appendChild(tr);
  13994. }
  13995. };
  13996. /**
  13997. * Function: popup
  13998. *
  13999. * Shows the popup menu for the given event and cell.
  14000. *
  14001. * Example:
  14002. *
  14003. * (code)
  14004. * graph.panningHandler.popup = function(x, y, cell, evt)
  14005. * {
  14006. * mxUtils.alert('Hello, World!');
  14007. * }
  14008. * (end)
  14009. */
  14010. mxPopupMenu.prototype.popup = function(x, y, cell, evt)
  14011. {
  14012. if (this.div != null && this.tbody != null && this.factoryMethod != null)
  14013. {
  14014. this.div.style.left = x + 'px';
  14015. this.div.style.top = y + 'px';
  14016. // Removes all child nodes from the existing menu
  14017. while (this.tbody.firstChild != null)
  14018. {
  14019. mxEvent.release(this.tbody.firstChild);
  14020. this.tbody.removeChild(this.tbody.firstChild);
  14021. }
  14022. this.itemCount = 0;
  14023. this.factoryMethod(this, cell, evt);
  14024. if (this.itemCount > 0)
  14025. {
  14026. this.showMenu();
  14027. this.fireEvent(new mxEventObject(mxEvent.SHOW));
  14028. }
  14029. }
  14030. };
  14031. /**
  14032. * Function: isMenuShowing
  14033. *
  14034. * Returns true if the menu is showing.
  14035. */
  14036. mxPopupMenu.prototype.isMenuShowing = function()
  14037. {
  14038. return this.div != null && this.div.parentNode == document.body;
  14039. };
  14040. /**
  14041. * Function: showMenu
  14042. *
  14043. * Shows the menu.
  14044. */
  14045. mxPopupMenu.prototype.showMenu = function()
  14046. {
  14047. // Disables filter-based shadow in IE9 standards mode
  14048. if (document.documentMode >= 9)
  14049. {
  14050. this.div.style.filter = 'none';
  14051. }
  14052. // Fits the div inside the viewport
  14053. document.body.appendChild(this.div);
  14054. mxUtils.fit(this.div);
  14055. };
  14056. /**
  14057. * Function: hideMenu
  14058. *
  14059. * Removes the menu and all submenus.
  14060. */
  14061. mxPopupMenu.prototype.hideMenu = function()
  14062. {
  14063. if (this.div != null)
  14064. {
  14065. if (this.div.parentNode != null)
  14066. {
  14067. this.div.parentNode.removeChild(this.div);
  14068. }
  14069. this.hideSubmenu(this);
  14070. this.containsItems = false;
  14071. this.fireEvent(new mxEventObject(mxEvent.HIDE));
  14072. }
  14073. };
  14074. /**
  14075. * Function: hideSubmenu
  14076. *
  14077. * Removes all submenus inside the given parent.
  14078. *
  14079. * Parameters:
  14080. *
  14081. * parent - An item returned by <addItem>.
  14082. */
  14083. mxPopupMenu.prototype.hideSubmenu = function(parent)
  14084. {
  14085. if (parent.activeRow != null)
  14086. {
  14087. this.hideSubmenu(parent.activeRow);
  14088. if (parent.activeRow.div.parentNode != null)
  14089. {
  14090. parent.activeRow.div.parentNode.removeChild(parent.activeRow.div);
  14091. }
  14092. parent.activeRow = null;
  14093. }
  14094. };
  14095. /**
  14096. * Function: destroy
  14097. *
  14098. * Destroys the handler and all its resources and DOM nodes.
  14099. */
  14100. mxPopupMenu.prototype.destroy = function()
  14101. {
  14102. if (this.div != null)
  14103. {
  14104. mxEvent.release(this.div);
  14105. if (this.div.parentNode != null)
  14106. {
  14107. this.div.parentNode.removeChild(this.div);
  14108. }
  14109. this.div = null;
  14110. }
  14111. };
  14112. /**
  14113. * Copyright (c) 2006-2015, JGraph Ltd
  14114. * Copyright (c) 2006-2015, Gaudenz Alder
  14115. */
  14116. /**
  14117. * Class: mxAutoSaveManager
  14118. *
  14119. * Manager for automatically saving diagrams. The <save> hook must be
  14120. * implemented.
  14121. *
  14122. * Example:
  14123. *
  14124. * (code)
  14125. * var mgr = new mxAutoSaveManager(editor.graph);
  14126. * mgr.save = function()
  14127. * {
  14128. * mxLog.show();
  14129. * mxLog.debug('save');
  14130. * };
  14131. * (end)
  14132. *
  14133. * Constructor: mxAutoSaveManager
  14134. *
  14135. * Constructs a new automatic layout for the given graph.
  14136. *
  14137. * Arguments:
  14138. *
  14139. * graph - Reference to the enclosing graph.
  14140. */
  14141. function mxAutoSaveManager(graph)
  14142. {
  14143. // Notifies the manager of a change
  14144. this.changeHandler = mxUtils.bind(this, function(sender, evt)
  14145. {
  14146. if (this.isEnabled())
  14147. {
  14148. this.graphModelChanged(evt.getProperty('edit').changes);
  14149. }
  14150. });
  14151. this.setGraph(graph);
  14152. };
  14153. /**
  14154. * Extends mxEventSource.
  14155. */
  14156. mxAutoSaveManager.prototype = new mxEventSource();
  14157. mxAutoSaveManager.prototype.constructor = mxAutoSaveManager;
  14158. /**
  14159. * Variable: graph
  14160. *
  14161. * Reference to the enclosing <mxGraph>.
  14162. */
  14163. mxAutoSaveManager.prototype.graph = null;
  14164. /**
  14165. * Variable: autoSaveDelay
  14166. *
  14167. * Minimum amount of seconds between two consecutive autosaves. Eg. a
  14168. * value of 1 (s) means the graph is not stored more than once per second.
  14169. * Default is 10.
  14170. */
  14171. mxAutoSaveManager.prototype.autoSaveDelay = 10;
  14172. /**
  14173. * Variable: autoSaveThrottle
  14174. *
  14175. * Minimum amount of seconds between two consecutive autosaves triggered by
  14176. * more than <autoSaveThreshhold> changes within a timespan of less than
  14177. * <autoSaveDelay> seconds. Eg. a value of 1 (s) means the graph is not
  14178. * stored more than once per second even if there are more than
  14179. * <autoSaveThreshold> changes within that timespan. Default is 2.
  14180. */
  14181. mxAutoSaveManager.prototype.autoSaveThrottle = 2;
  14182. /**
  14183. * Variable: autoSaveThreshold
  14184. *
  14185. * Minimum amount of ignored changes before an autosave. Eg. a value of 2
  14186. * means after 2 change of the graph model the autosave will trigger if the
  14187. * condition below is true. Default is 5.
  14188. */
  14189. mxAutoSaveManager.prototype.autoSaveThreshold = 5;
  14190. /**
  14191. * Variable: ignoredChanges
  14192. *
  14193. * Counter for ignored changes in autosave.
  14194. */
  14195. mxAutoSaveManager.prototype.ignoredChanges = 0;
  14196. /**
  14197. * Variable: lastSnapshot
  14198. *
  14199. * Used for autosaving. See <autosave>.
  14200. */
  14201. mxAutoSaveManager.prototype.lastSnapshot = 0;
  14202. /**
  14203. * Variable: enabled
  14204. *
  14205. * Specifies if event handling is enabled. Default is true.
  14206. */
  14207. mxAutoSaveManager.prototype.enabled = true;
  14208. /**
  14209. * Variable: changeHandler
  14210. *
  14211. * Holds the function that handles graph model changes.
  14212. */
  14213. mxAutoSaveManager.prototype.changeHandler = null;
  14214. /**
  14215. * Function: isEnabled
  14216. *
  14217. * Returns true if events are handled. This implementation
  14218. * returns <enabled>.
  14219. */
  14220. mxAutoSaveManager.prototype.isEnabled = function()
  14221. {
  14222. return this.enabled;
  14223. };
  14224. /**
  14225. * Function: setEnabled
  14226. *
  14227. * Enables or disables event handling. This implementation
  14228. * updates <enabled>.
  14229. *
  14230. * Parameters:
  14231. *
  14232. * enabled - Boolean that specifies the new enabled state.
  14233. */
  14234. mxAutoSaveManager.prototype.setEnabled = function(value)
  14235. {
  14236. this.enabled = value;
  14237. };
  14238. /**
  14239. * Function: setGraph
  14240. *
  14241. * Sets the graph that the layouts operate on.
  14242. */
  14243. mxAutoSaveManager.prototype.setGraph = function(graph)
  14244. {
  14245. if (this.graph != null)
  14246. {
  14247. this.graph.getModel().removeListener(this.changeHandler);
  14248. }
  14249. this.graph = graph;
  14250. if (this.graph != null)
  14251. {
  14252. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  14253. }
  14254. };
  14255. /**
  14256. * Function: save
  14257. *
  14258. * Empty hook that is called if the graph should be saved.
  14259. */
  14260. mxAutoSaveManager.prototype.save = function()
  14261. {
  14262. // empty
  14263. };
  14264. /**
  14265. * Function: graphModelChanged
  14266. *
  14267. * Invoked when the graph model has changed.
  14268. */
  14269. mxAutoSaveManager.prototype.graphModelChanged = function(changes)
  14270. {
  14271. var now = new Date().getTime();
  14272. var dt = (now - this.lastSnapshot) / 1000;
  14273. if (dt > this.autoSaveDelay ||
  14274. (this.ignoredChanges >= this.autoSaveThreshold &&
  14275. dt > this.autoSaveThrottle))
  14276. {
  14277. this.save();
  14278. this.reset();
  14279. }
  14280. else
  14281. {
  14282. // Increments the number of ignored changes
  14283. this.ignoredChanges++;
  14284. }
  14285. };
  14286. /**
  14287. * Function: reset
  14288. *
  14289. * Resets all counters.
  14290. */
  14291. mxAutoSaveManager.prototype.reset = function()
  14292. {
  14293. this.lastSnapshot = new Date().getTime();
  14294. this.ignoredChanges = 0;
  14295. };
  14296. /**
  14297. * Function: destroy
  14298. *
  14299. * Removes all handlers from the <graph> and deletes the reference to it.
  14300. */
  14301. mxAutoSaveManager.prototype.destroy = function()
  14302. {
  14303. this.setGraph(null);
  14304. };
  14305. /**
  14306. * Copyright (c) 2006-2015, JGraph Ltd
  14307. * Copyright (c) 2006-2015, Gaudenz Alder
  14308. */
  14309. /**
  14310. *
  14311. * Class: mxAnimation
  14312. *
  14313. * Implements a basic animation in JavaScript.
  14314. *
  14315. * Constructor: mxAnimation
  14316. *
  14317. * Constructs an animation.
  14318. *
  14319. * Parameters:
  14320. *
  14321. * graph - Reference to the enclosing <mxGraph>.
  14322. */
  14323. function mxAnimation(delay)
  14324. {
  14325. this.delay = (delay != null) ? delay : 20;
  14326. };
  14327. /**
  14328. * Extends mxEventSource.
  14329. */
  14330. mxAnimation.prototype = new mxEventSource();
  14331. mxAnimation.prototype.constructor = mxAnimation;
  14332. /**
  14333. * Variable: delay
  14334. *
  14335. * Specifies the delay between the animation steps. Defaul is 30ms.
  14336. */
  14337. mxAnimation.prototype.delay = null;
  14338. /**
  14339. * Variable: thread
  14340. *
  14341. * Reference to the thread while the animation is running.
  14342. */
  14343. mxAnimation.prototype.thread = null;
  14344. /**
  14345. * Function: isRunning
  14346. *
  14347. * Returns true if the animation is running.
  14348. */
  14349. mxAnimation.prototype.isRunning = function()
  14350. {
  14351. return this.thread != null;
  14352. };
  14353. /**
  14354. * Function: startAnimation
  14355. *
  14356. * Starts the animation by repeatedly invoking updateAnimation.
  14357. */
  14358. mxAnimation.prototype.startAnimation = function()
  14359. {
  14360. if (this.thread == null)
  14361. {
  14362. this.thread = window.setInterval(mxUtils.bind(this, this.updateAnimation), this.delay);
  14363. }
  14364. };
  14365. /**
  14366. * Function: updateAnimation
  14367. *
  14368. * Hook for subclassers to implement the animation. Invoke stopAnimation
  14369. * when finished, startAnimation to resume. This is called whenever the
  14370. * timer fires and fires an mxEvent.EXECUTE event with no properties.
  14371. */
  14372. mxAnimation.prototype.updateAnimation = function()
  14373. {
  14374. this.fireEvent(new mxEventObject(mxEvent.EXECUTE));
  14375. };
  14376. /**
  14377. * Function: stopAnimation
  14378. *
  14379. * Stops the animation by deleting the timer and fires an <mxEvent.DONE>.
  14380. */
  14381. mxAnimation.prototype.stopAnimation = function()
  14382. {
  14383. if (this.thread != null)
  14384. {
  14385. window.clearInterval(this.thread);
  14386. this.thread = null;
  14387. this.fireEvent(new mxEventObject(mxEvent.DONE));
  14388. }
  14389. };
  14390. /**
  14391. * Copyright (c) 2006-2015, JGraph Ltd
  14392. * Copyright (c) 2006-2015, Gaudenz Alder
  14393. */
  14394. /**
  14395. *
  14396. * Class: mxMorphing
  14397. *
  14398. * Implements animation for morphing cells. Here is an example of
  14399. * using this class for animating the result of a layout algorithm:
  14400. *
  14401. * (code)
  14402. * graph.getModel().beginUpdate();
  14403. * try
  14404. * {
  14405. * var circleLayout = new mxCircleLayout(graph);
  14406. * circleLayout.execute(graph.getDefaultParent());
  14407. * }
  14408. * finally
  14409. * {
  14410. * var morph = new mxMorphing(graph);
  14411. * morph.addListener(mxEvent.DONE, function()
  14412. * {
  14413. * graph.getModel().endUpdate();
  14414. * });
  14415. *
  14416. * morph.startAnimation();
  14417. * }
  14418. * (end)
  14419. *
  14420. * Constructor: mxMorphing
  14421. *
  14422. * Constructs an animation.
  14423. *
  14424. * Parameters:
  14425. *
  14426. * graph - Reference to the enclosing <mxGraph>.
  14427. * steps - Optional number of steps in the morphing animation. Default is 6.
  14428. * ease - Optional easing constant for the animation. Default is 1.5.
  14429. * delay - Optional delay between the animation steps. Passed to <mxAnimation>.
  14430. */
  14431. function mxMorphing(graph, steps, ease, delay)
  14432. {
  14433. mxAnimation.call(this, delay);
  14434. this.graph = graph;
  14435. this.steps = (steps != null) ? steps : 6;
  14436. this.ease = (ease != null) ? ease : 1.5;
  14437. };
  14438. /**
  14439. * Extends mxEventSource.
  14440. */
  14441. mxMorphing.prototype = new mxAnimation();
  14442. mxMorphing.prototype.constructor = mxMorphing;
  14443. /**
  14444. * Variable: graph
  14445. *
  14446. * Specifies the delay between the animation steps. Defaul is 30ms.
  14447. */
  14448. mxMorphing.prototype.graph = null;
  14449. /**
  14450. * Variable: steps
  14451. *
  14452. * Specifies the maximum number of steps for the morphing.
  14453. */
  14454. mxMorphing.prototype.steps = null;
  14455. /**
  14456. * Variable: step
  14457. *
  14458. * Contains the current step.
  14459. */
  14460. mxMorphing.prototype.step = 0;
  14461. /**
  14462. * Variable: ease
  14463. *
  14464. * Ease-off for movement towards the given vector. Larger values are
  14465. * slower and smoother. Default is 4.
  14466. */
  14467. mxMorphing.prototype.ease = null;
  14468. /**
  14469. * Variable: cells
  14470. *
  14471. * Optional array of cells to be animated. If this is not specified
  14472. * then all cells are checked and animated if they have been moved
  14473. * in the current transaction.
  14474. */
  14475. mxMorphing.prototype.cells = null;
  14476. /**
  14477. * Function: updateAnimation
  14478. *
  14479. * Animation step.
  14480. */
  14481. mxMorphing.prototype.updateAnimation = function()
  14482. {
  14483. mxAnimation.prototype.updateAnimation.apply(this, arguments);
  14484. var move = new mxCellStatePreview(this.graph);
  14485. if (this.cells != null)
  14486. {
  14487. // Animates the given cells individually without recursion
  14488. for (var i = 0; i < this.cells.length; i++)
  14489. {
  14490. this.animateCell(this.cells[i], move, false);
  14491. }
  14492. }
  14493. else
  14494. {
  14495. // Animates all changed cells by using recursion to find
  14496. // the changed cells but not for the animation itself
  14497. this.animateCell(this.graph.getModel().getRoot(), move, true);
  14498. }
  14499. this.show(move);
  14500. if (move.isEmpty() || this.step++ >= this.steps)
  14501. {
  14502. this.stopAnimation();
  14503. }
  14504. };
  14505. /**
  14506. * Function: show
  14507. *
  14508. * Shows the changes in the given <mxCellStatePreview>.
  14509. */
  14510. mxMorphing.prototype.show = function(move)
  14511. {
  14512. move.show();
  14513. };
  14514. /**
  14515. * Function: animateCell
  14516. *
  14517. * Animates the given cell state using <mxCellStatePreview.moveState>.
  14518. */
  14519. mxMorphing.prototype.animateCell = function(cell, move, recurse)
  14520. {
  14521. var state = this.graph.getView().getState(cell);
  14522. var delta = null;
  14523. if (state != null)
  14524. {
  14525. // Moves the animated state from where it will be after the model
  14526. // change by subtracting the given delta vector from that location
  14527. delta = this.getDelta(state);
  14528. if (this.graph.getModel().isVertex(cell) && (delta.x != 0 || delta.y != 0))
  14529. {
  14530. var translate = this.graph.view.getTranslate();
  14531. var scale = this.graph.view.getScale();
  14532. delta.x += translate.x * scale;
  14533. delta.y += translate.y * scale;
  14534. move.moveState(state, -delta.x / this.ease, -delta.y / this.ease);
  14535. }
  14536. }
  14537. if (recurse && !this.stopRecursion(state, delta))
  14538. {
  14539. var childCount = this.graph.getModel().getChildCount(cell);
  14540. for (var i = 0; i < childCount; i++)
  14541. {
  14542. this.animateCell(this.graph.getModel().getChildAt(cell, i), move, recurse);
  14543. }
  14544. }
  14545. };
  14546. /**
  14547. * Function: stopRecursion
  14548. *
  14549. * Returns true if the animation should not recursively find more
  14550. * deltas for children if the given parent state has been animated.
  14551. */
  14552. mxMorphing.prototype.stopRecursion = function(state, delta)
  14553. {
  14554. return delta != null && (delta.x != 0 || delta.y != 0);
  14555. };
  14556. /**
  14557. * Function: getDelta
  14558. *
  14559. * Returns the vector between the current rendered state and the future
  14560. * location of the state after the display will be updated.
  14561. */
  14562. mxMorphing.prototype.getDelta = function(state)
  14563. {
  14564. var origin = this.getOriginForCell(state.cell);
  14565. var translate = this.graph.getView().getTranslate();
  14566. var scale = this.graph.getView().getScale();
  14567. var x = state.x / scale - translate.x;
  14568. var y = state.y / scale - translate.y;
  14569. return new mxPoint((origin.x - x) * scale, (origin.y - y) * scale);
  14570. };
  14571. /**
  14572. * Function: getOriginForCell
  14573. *
  14574. * Returns the top, left corner of the given cell. TODO: Improve performance
  14575. * by using caching inside this method as the result per cell never changes
  14576. * during the lifecycle of this object.
  14577. */
  14578. mxMorphing.prototype.getOriginForCell = function(cell)
  14579. {
  14580. var result = null;
  14581. if (cell != null)
  14582. {
  14583. var parent = this.graph.getModel().getParent(cell);
  14584. var geo = this.graph.getCellGeometry(cell);
  14585. result = this.getOriginForCell(parent);
  14586. // TODO: Handle offsets
  14587. if (geo != null)
  14588. {
  14589. if (geo.relative)
  14590. {
  14591. var pgeo = this.graph.getCellGeometry(parent);
  14592. if (pgeo != null)
  14593. {
  14594. result.x += geo.x * pgeo.width;
  14595. result.y += geo.y * pgeo.height;
  14596. }
  14597. }
  14598. else
  14599. {
  14600. result.x += geo.x;
  14601. result.y += geo.y;
  14602. }
  14603. }
  14604. }
  14605. if (result == null)
  14606. {
  14607. var t = this.graph.view.getTranslate();
  14608. result = new mxPoint(-t.x, -t.y);
  14609. }
  14610. return result;
  14611. };
  14612. /**
  14613. * Copyright (c) 2006-2015, JGraph Ltd
  14614. * Copyright (c) 2006-2015, Gaudenz Alder
  14615. */
  14616. /**
  14617. * Class: mxImageBundle
  14618. *
  14619. * Maps from keys to base64 encoded images or file locations. All values must
  14620. * be URLs or use the format data:image/format followed by a comma and the base64
  14621. * encoded image data, eg. "data:image/gif,XYZ", where XYZ is the base64 encoded
  14622. * image data.
  14623. *
  14624. * To add a new image bundle to an existing graph, the following code is used:
  14625. *
  14626. * (code)
  14627. * var bundle = new mxImageBundle(alt);
  14628. * bundle.putImage('myImage', 'data:image/gif,R0lGODlhEAAQAMIGAAAAAICAAICAgP' +
  14629. * '//AOzp2O3r2////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgAHACwAAAAA' +
  14630. * 'EAAQAAADTXi63AowynnAMDfjPUDlnAAJhmeBFxAEloliKltWmiYCQvfVr6lBPB1ggxN1hi' +
  14631. * 'laSSASFQpIV5HJBDyHpqK2ejVRm2AAgZCdmCGO9CIBADs=', fallback);
  14632. * bundle.putImage('mySvgImage', 'data:image/svg+xml,' + encodeURIComponent(
  14633. * '<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">' +
  14634. * '<linearGradient id="gradient"><stop offset="10%" stop-color="#F00"/>' +
  14635. * '<stop offset="90%" stop-color="#fcc"/></linearGradient>' +
  14636. * '<rect fill="url(#gradient)" width="100%" height="100%"/></svg>'), fallback);
  14637. * graph.addImageBundle(bundle);
  14638. * (end);
  14639. *
  14640. * Alt is an optional boolean (default is false) that specifies if the value
  14641. * or the fallback should be returned in <getImage>.
  14642. *
  14643. * The image can then be referenced in any cell style using image=myImage.
  14644. * If you are using mxOutline, you should use the same image bundles in the
  14645. * graph that renders the outline.
  14646. *
  14647. * The keys for images are resolved in <mxGraph.postProcessCellStyle> and
  14648. * turned into a data URI if the returned value has a short data URI format
  14649. * as specified above.
  14650. *
  14651. * A typical value for the fallback is a MTHML link as defined in RFC 2557.
  14652. * Note that this format requires a file to be dynamically created on the
  14653. * server-side, or the page that contains the graph to be modified to contain
  14654. * the resources, this can be done by adding a comment that contains the
  14655. * resource in the HEAD section of the page after the title tag.
  14656. *
  14657. * This type of fallback mechanism should be used in IE6 and IE7. IE8 does
  14658. * support data URIs, but the maximum size is limited to 32 KB, which means
  14659. * all data URIs should be limited to 32 KB.
  14660. */
  14661. function mxImageBundle(alt)
  14662. {
  14663. this.images = [];
  14664. this.alt = (alt != null) ? alt : false;
  14665. };
  14666. /**
  14667. * Variable: images
  14668. *
  14669. * Maps from keys to images.
  14670. */
  14671. mxImageBundle.prototype.images = null;
  14672. /**
  14673. * Variable: alt
  14674. *
  14675. * Specifies if the fallback representation should be returned.
  14676. */
  14677. mxImageBundle.prototype.alt = null;
  14678. /**
  14679. * Function: putImage
  14680. *
  14681. * Adds the specified entry to the map. The entry is an object with a value and
  14682. * fallback property as specified in the arguments.
  14683. */
  14684. mxImageBundle.prototype.putImage = function(key, value, fallback)
  14685. {
  14686. this.images[key] = {value: value, fallback: fallback};
  14687. };
  14688. /**
  14689. * Function: getImage
  14690. *
  14691. * Returns the value for the given key. This returns the value
  14692. * or fallback, depending on <alt>. The fallback is returned if
  14693. * <alt> is true, the value is returned otherwise.
  14694. */
  14695. mxImageBundle.prototype.getImage = function(key)
  14696. {
  14697. var result = null;
  14698. if (key != null)
  14699. {
  14700. var img = this.images[key];
  14701. if (img != null)
  14702. {
  14703. result = (this.alt) ? img.fallback : img.value;
  14704. }
  14705. }
  14706. return result;
  14707. };
  14708. /**
  14709. * Copyright (c) 2006-2015, JGraph Ltd
  14710. * Copyright (c) 2006-2015, Gaudenz Alder
  14711. */
  14712. /**
  14713. * Class: mxImageExport
  14714. *
  14715. * Creates a new image export instance to be used with an export canvas. Here
  14716. * is an example that uses this class to create an image via a backend using
  14717. * <mxXmlExportCanvas>.
  14718. *
  14719. * (code)
  14720. * var xmlDoc = mxUtils.createXmlDocument();
  14721. * var root = xmlDoc.createElement('output');
  14722. * xmlDoc.appendChild(root);
  14723. *
  14724. * var xmlCanvas = new mxXmlCanvas2D(root);
  14725. * var imgExport = new mxImageExport();
  14726. * imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  14727. *
  14728. * var bounds = graph.getGraphBounds();
  14729. * var w = Math.ceil(bounds.x + bounds.width);
  14730. * var h = Math.ceil(bounds.y + bounds.height);
  14731. *
  14732. * var xml = mxUtils.getXml(root);
  14733. * new mxXmlRequest('export', 'format=png&w=' + w +
  14734. * '&h=' + h + '&bg=#F9F7ED&xml=' + encodeURIComponent(xml))
  14735. * .simulate(document, '_blank');
  14736. * (end)
  14737. *
  14738. * Constructor: mxImageExport
  14739. *
  14740. * Constructs a new image export.
  14741. */
  14742. function mxImageExport() { };
  14743. /**
  14744. * Variable: includeOverlays
  14745. *
  14746. * Specifies if overlays should be included in the export. Default is false.
  14747. */
  14748. mxImageExport.prototype.includeOverlays = false;
  14749. /**
  14750. * Function: drawState
  14751. *
  14752. * Draws the given state and all its descendants to the given canvas.
  14753. */
  14754. mxImageExport.prototype.drawState = function(state, canvas)
  14755. {
  14756. if (state != null)
  14757. {
  14758. this.visitStatesRecursive(state, canvas, mxUtils.bind(this, function()
  14759. {
  14760. this.drawCellState.apply(this, arguments);
  14761. }));
  14762. // Paints the overlays
  14763. if (this.includeOverlays)
  14764. {
  14765. this.visitStatesRecursive(state, canvas, mxUtils.bind(this, function()
  14766. {
  14767. this.drawOverlays.apply(this, arguments);
  14768. }));
  14769. }
  14770. }
  14771. };
  14772. /**
  14773. * Function: drawState
  14774. *
  14775. * Draws the given state and all its descendants to the given canvas.
  14776. */
  14777. mxImageExport.prototype.visitStatesRecursive = function(state, canvas, visitor)
  14778. {
  14779. if (state != null)
  14780. {
  14781. visitor(state, canvas);
  14782. var graph = state.view.graph;
  14783. var childCount = graph.model.getChildCount(state.cell);
  14784. for (var i = 0; i < childCount; i++)
  14785. {
  14786. var childState = graph.view.getState(graph.model.getChildAt(state.cell, i));
  14787. this.visitStatesRecursive(childState, canvas, visitor);
  14788. }
  14789. }
  14790. };
  14791. /**
  14792. * Function: getLinkForCellState
  14793. *
  14794. * Returns the link for the given cell state and canvas. This returns null.
  14795. */
  14796. mxImageExport.prototype.getLinkForCellState = function(state, canvas)
  14797. {
  14798. return null;
  14799. };
  14800. /**
  14801. * Function: drawCellState
  14802. *
  14803. * Draws the given state to the given canvas.
  14804. */
  14805. mxImageExport.prototype.drawCellState = function(state, canvas)
  14806. {
  14807. // Experimental feature
  14808. var link = this.getLinkForCellState(state, canvas);
  14809. if (link != null)
  14810. {
  14811. canvas.setLink(link);
  14812. }
  14813. // Paints the shape and text
  14814. this.drawShape(state, canvas);
  14815. this.drawText(state, canvas);
  14816. if (link != null)
  14817. {
  14818. canvas.setLink(null);
  14819. }
  14820. };
  14821. /**
  14822. * Function: drawShape
  14823. *
  14824. * Draws the shape of the given state.
  14825. */
  14826. mxImageExport.prototype.drawShape = function(state, canvas)
  14827. {
  14828. if (state.shape instanceof mxShape && state.shape.checkBounds())
  14829. {
  14830. canvas.save();
  14831. state.shape.paint(canvas);
  14832. canvas.restore();
  14833. }
  14834. };
  14835. /**
  14836. * Function: drawText
  14837. *
  14838. * Draws the text of the given state.
  14839. */
  14840. mxImageExport.prototype.drawText = function(state, canvas)
  14841. {
  14842. if (state.text != null && state.text.checkBounds())
  14843. {
  14844. canvas.save();
  14845. state.text.paint(canvas);
  14846. canvas.restore();
  14847. }
  14848. };
  14849. /**
  14850. * Function: drawOverlays
  14851. *
  14852. * Draws the overlays for the given state. This is called if <includeOverlays>
  14853. * is true.
  14854. */
  14855. mxImageExport.prototype.drawOverlays = function(state, canvas)
  14856. {
  14857. if (state.overlays != null)
  14858. {
  14859. state.overlays.visit(function(id, shape)
  14860. {
  14861. if (shape instanceof mxShape)
  14862. {
  14863. shape.paint(canvas);
  14864. }
  14865. });
  14866. }
  14867. };
  14868. /**
  14869. * Copyright (c) 2006-2015, JGraph Ltd
  14870. * Copyright (c) 2006-2015, Gaudenz Alder
  14871. */
  14872. /**
  14873. * Class: mxAbstractCanvas2D
  14874. *
  14875. * Base class for all canvases. A description of the public API is available in <mxXmlCanvas2D>.
  14876. * All color values of <mxConstants.NONE> will be converted to null in the state.
  14877. *
  14878. * Constructor: mxAbstractCanvas2D
  14879. *
  14880. * Constructs a new abstract canvas.
  14881. */
  14882. function mxAbstractCanvas2D()
  14883. {
  14884. /**
  14885. * Variable: converter
  14886. *
  14887. * Holds the <mxUrlConverter> to convert image URLs.
  14888. */
  14889. this.converter = this.createUrlConverter();
  14890. this.reset();
  14891. };
  14892. /**
  14893. * Variable: state
  14894. *
  14895. * Holds the current state.
  14896. */
  14897. mxAbstractCanvas2D.prototype.state = null;
  14898. /**
  14899. * Variable: states
  14900. *
  14901. * Stack of states.
  14902. */
  14903. mxAbstractCanvas2D.prototype.states = null;
  14904. /**
  14905. * Variable: path
  14906. *
  14907. * Holds the current path as an array.
  14908. */
  14909. mxAbstractCanvas2D.prototype.path = null;
  14910. /**
  14911. * Variable: rotateHtml
  14912. *
  14913. * Switch for rotation of HTML. Default is false.
  14914. */
  14915. mxAbstractCanvas2D.prototype.rotateHtml = true;
  14916. /**
  14917. * Variable: lastX
  14918. *
  14919. * Holds the last x coordinate.
  14920. */
  14921. mxAbstractCanvas2D.prototype.lastX = 0;
  14922. /**
  14923. * Variable: lastY
  14924. *
  14925. * Holds the last y coordinate.
  14926. */
  14927. mxAbstractCanvas2D.prototype.lastY = 0;
  14928. /**
  14929. * Variable: moveOp
  14930. *
  14931. * Contains the string used for moving in paths. Default is 'M'.
  14932. */
  14933. mxAbstractCanvas2D.prototype.moveOp = 'M';
  14934. /**
  14935. * Variable: lineOp
  14936. *
  14937. * Contains the string used for moving in paths. Default is 'L'.
  14938. */
  14939. mxAbstractCanvas2D.prototype.lineOp = 'L';
  14940. /**
  14941. * Variable: quadOp
  14942. *
  14943. * Contains the string used for quadratic paths. Default is 'Q'.
  14944. */
  14945. mxAbstractCanvas2D.prototype.quadOp = 'Q';
  14946. /**
  14947. * Variable: curveOp
  14948. *
  14949. * Contains the string used for bezier curves. Default is 'C'.
  14950. */
  14951. mxAbstractCanvas2D.prototype.curveOp = 'C';
  14952. /**
  14953. * Variable: closeOp
  14954. *
  14955. * Holds the operator for closing curves. Default is 'Z'.
  14956. */
  14957. mxAbstractCanvas2D.prototype.closeOp = 'Z';
  14958. /**
  14959. * Variable: pointerEvents
  14960. *
  14961. * Boolean value that specifies if events should be handled. Default is false.
  14962. */
  14963. mxAbstractCanvas2D.prototype.pointerEvents = false;
  14964. /**
  14965. * Function: createUrlConverter
  14966. *
  14967. * Create a new <mxUrlConverter> and returns it.
  14968. */
  14969. mxAbstractCanvas2D.prototype.createUrlConverter = function()
  14970. {
  14971. return new mxUrlConverter();
  14972. };
  14973. /**
  14974. * Function: reset
  14975. *
  14976. * Resets the state of this canvas.
  14977. */
  14978. mxAbstractCanvas2D.prototype.reset = function()
  14979. {
  14980. this.state = this.createState();
  14981. this.states = [];
  14982. };
  14983. /**
  14984. * Function: createState
  14985. *
  14986. * Creates the state of the this canvas.
  14987. */
  14988. mxAbstractCanvas2D.prototype.createState = function()
  14989. {
  14990. return {
  14991. dx: 0,
  14992. dy: 0,
  14993. scale: 1,
  14994. alpha: 1,
  14995. fillAlpha: 1,
  14996. strokeAlpha: 1,
  14997. fillColor: null,
  14998. gradientFillAlpha: 1,
  14999. gradientColor: null,
  15000. gradientAlpha: 1,
  15001. gradientDirection: null,
  15002. strokeColor: null,
  15003. strokeWidth: 1,
  15004. dashed: false,
  15005. dashPattern: '3 3',
  15006. fixDash: false,
  15007. lineCap: 'flat',
  15008. lineJoin: 'miter',
  15009. miterLimit: 10,
  15010. fontColor: '#000000',
  15011. fontBackgroundColor: null,
  15012. fontBorderColor: null,
  15013. fontSize: mxConstants.DEFAULT_FONTSIZE,
  15014. fontFamily: mxConstants.DEFAULT_FONTFAMILY,
  15015. fontStyle: 0,
  15016. shadow: false,
  15017. shadowColor: mxConstants.SHADOWCOLOR,
  15018. shadowAlpha: mxConstants.SHADOW_OPACITY,
  15019. shadowDx: mxConstants.SHADOW_OFFSET_X,
  15020. shadowDy: mxConstants.SHADOW_OFFSET_Y,
  15021. rotation: 0,
  15022. rotationCx: 0,
  15023. rotationCy: 0
  15024. };
  15025. };
  15026. /**
  15027. * Function: format
  15028. *
  15029. * Rounds all numbers to integers.
  15030. */
  15031. mxAbstractCanvas2D.prototype.format = function(value)
  15032. {
  15033. return Math.round(parseFloat(value));
  15034. };
  15035. /**
  15036. * Function: addOp
  15037. *
  15038. * Adds the given operation to the path.
  15039. */
  15040. mxAbstractCanvas2D.prototype.addOp = function()
  15041. {
  15042. if (this.path != null)
  15043. {
  15044. this.path.push(arguments[0]);
  15045. if (arguments.length > 2)
  15046. {
  15047. var s = this.state;
  15048. for (var i = 2; i < arguments.length; i += 2)
  15049. {
  15050. this.lastX = arguments[i - 1];
  15051. this.lastY = arguments[i];
  15052. this.path.push(this.format((this.lastX + s.dx) * s.scale));
  15053. this.path.push(this.format((this.lastY + s.dy) * s.scale));
  15054. }
  15055. }
  15056. }
  15057. };
  15058. /**
  15059. * Function: rotatePoint
  15060. *
  15061. * Rotates the given point and returns the result as an <mxPoint>.
  15062. */
  15063. mxAbstractCanvas2D.prototype.rotatePoint = function(x, y, theta, cx, cy)
  15064. {
  15065. var rad = theta * (Math.PI / 180);
  15066. return mxUtils.getRotatedPoint(new mxPoint(x, y), Math.cos(rad),
  15067. Math.sin(rad), new mxPoint(cx, cy));
  15068. };
  15069. /**
  15070. * Function: save
  15071. *
  15072. * Saves the current state.
  15073. */
  15074. mxAbstractCanvas2D.prototype.save = function()
  15075. {
  15076. this.states.push(this.state);
  15077. this.state = mxUtils.clone(this.state);
  15078. };
  15079. /**
  15080. * Function: restore
  15081. *
  15082. * Restores the current state.
  15083. */
  15084. mxAbstractCanvas2D.prototype.restore = function()
  15085. {
  15086. if (this.states.length > 0)
  15087. {
  15088. this.state = this.states.pop();
  15089. }
  15090. };
  15091. /**
  15092. * Function: setLink
  15093. *
  15094. * Sets the current link. Hook for subclassers.
  15095. */
  15096. mxAbstractCanvas2D.prototype.setLink = function(link)
  15097. {
  15098. // nop
  15099. };
  15100. /**
  15101. * Function: scale
  15102. *
  15103. * Scales the current state.
  15104. */
  15105. mxAbstractCanvas2D.prototype.scale = function(value)
  15106. {
  15107. this.state.scale *= value;
  15108. this.state.strokeWidth *= value;
  15109. };
  15110. /**
  15111. * Function: translate
  15112. *
  15113. * Translates the current state.
  15114. */
  15115. mxAbstractCanvas2D.prototype.translate = function(dx, dy)
  15116. {
  15117. this.state.dx += dx;
  15118. this.state.dy += dy;
  15119. };
  15120. /**
  15121. * Function: rotate
  15122. *
  15123. * Rotates the current state.
  15124. */
  15125. mxAbstractCanvas2D.prototype.rotate = function(theta, flipH, flipV, cx, cy)
  15126. {
  15127. // nop
  15128. };
  15129. /**
  15130. * Function: setAlpha
  15131. *
  15132. * Sets the current alpha.
  15133. */
  15134. mxAbstractCanvas2D.prototype.setAlpha = function(value)
  15135. {
  15136. this.state.alpha = value;
  15137. };
  15138. /**
  15139. * Function: setFillAlpha
  15140. *
  15141. * Sets the current solid fill alpha.
  15142. */
  15143. mxAbstractCanvas2D.prototype.setFillAlpha = function(value)
  15144. {
  15145. this.state.fillAlpha = value;
  15146. };
  15147. /**
  15148. * Function: setStrokeAlpha
  15149. *
  15150. * Sets the current stroke alpha.
  15151. */
  15152. mxAbstractCanvas2D.prototype.setStrokeAlpha = function(value)
  15153. {
  15154. this.state.strokeAlpha = value;
  15155. };
  15156. /**
  15157. * Function: setFillColor
  15158. *
  15159. * Sets the current fill color.
  15160. */
  15161. mxAbstractCanvas2D.prototype.setFillColor = function(value)
  15162. {
  15163. if (value == mxConstants.NONE)
  15164. {
  15165. value = null;
  15166. }
  15167. this.state.fillColor = value;
  15168. this.state.gradientColor = null;
  15169. };
  15170. /**
  15171. * Function: setGradient
  15172. *
  15173. * Sets the current gradient.
  15174. */
  15175. mxAbstractCanvas2D.prototype.setGradient = function(color1, color2, x, y, w, h, direction, alpha1, alpha2)
  15176. {
  15177. var s = this.state;
  15178. s.fillColor = color1;
  15179. s.gradientFillAlpha = (alpha1 != null) ? alpha1 : 1;
  15180. s.gradientColor = color2;
  15181. s.gradientAlpha = (alpha2 != null) ? alpha2 : 1;
  15182. s.gradientDirection = direction;
  15183. };
  15184. /**
  15185. * Function: setStrokeColor
  15186. *
  15187. * Sets the current stroke color.
  15188. */
  15189. mxAbstractCanvas2D.prototype.setStrokeColor = function(value)
  15190. {
  15191. if (value == mxConstants.NONE)
  15192. {
  15193. value = null;
  15194. }
  15195. this.state.strokeColor = value;
  15196. };
  15197. /**
  15198. * Function: setStrokeWidth
  15199. *
  15200. * Sets the current stroke width.
  15201. */
  15202. mxAbstractCanvas2D.prototype.setStrokeWidth = function(value)
  15203. {
  15204. this.state.strokeWidth = value;
  15205. };
  15206. /**
  15207. * Function: setDashed
  15208. *
  15209. * Enables or disables dashed lines.
  15210. */
  15211. mxAbstractCanvas2D.prototype.setDashed = function(value, fixDash)
  15212. {
  15213. this.state.dashed = value;
  15214. this.state.fixDash = fixDash;
  15215. };
  15216. /**
  15217. * Function: setDashPattern
  15218. *
  15219. * Sets the current dash pattern.
  15220. */
  15221. mxAbstractCanvas2D.prototype.setDashPattern = function(value)
  15222. {
  15223. this.state.dashPattern = value;
  15224. };
  15225. /**
  15226. * Function: setLineCap
  15227. *
  15228. * Sets the current line cap.
  15229. */
  15230. mxAbstractCanvas2D.prototype.setLineCap = function(value)
  15231. {
  15232. this.state.lineCap = value;
  15233. };
  15234. /**
  15235. * Function: setLineJoin
  15236. *
  15237. * Sets the current line join.
  15238. */
  15239. mxAbstractCanvas2D.prototype.setLineJoin = function(value)
  15240. {
  15241. this.state.lineJoin = value;
  15242. };
  15243. /**
  15244. * Function: setMiterLimit
  15245. *
  15246. * Sets the current miter limit.
  15247. */
  15248. mxAbstractCanvas2D.prototype.setMiterLimit = function(value)
  15249. {
  15250. this.state.miterLimit = value;
  15251. };
  15252. /**
  15253. * Function: setFontColor
  15254. *
  15255. * Sets the current font color.
  15256. */
  15257. mxAbstractCanvas2D.prototype.setFontColor = function(value)
  15258. {
  15259. if (value == mxConstants.NONE)
  15260. {
  15261. value = null;
  15262. }
  15263. this.state.fontColor = value;
  15264. };
  15265. /**
  15266. * Function: setFontColor
  15267. *
  15268. * Sets the current font color.
  15269. */
  15270. mxAbstractCanvas2D.prototype.setFontBackgroundColor = function(value)
  15271. {
  15272. if (value == mxConstants.NONE)
  15273. {
  15274. value = null;
  15275. }
  15276. this.state.fontBackgroundColor = value;
  15277. };
  15278. /**
  15279. * Function: setFontColor
  15280. *
  15281. * Sets the current font color.
  15282. */
  15283. mxAbstractCanvas2D.prototype.setFontBorderColor = function(value)
  15284. {
  15285. if (value == mxConstants.NONE)
  15286. {
  15287. value = null;
  15288. }
  15289. this.state.fontBorderColor = value;
  15290. };
  15291. /**
  15292. * Function: setFontSize
  15293. *
  15294. * Sets the current font size.
  15295. */
  15296. mxAbstractCanvas2D.prototype.setFontSize = function(value)
  15297. {
  15298. this.state.fontSize = parseFloat(value);
  15299. };
  15300. /**
  15301. * Function: setFontFamily
  15302. *
  15303. * Sets the current font family.
  15304. */
  15305. mxAbstractCanvas2D.prototype.setFontFamily = function(value)
  15306. {
  15307. this.state.fontFamily = value;
  15308. };
  15309. /**
  15310. * Function: setFontStyle
  15311. *
  15312. * Sets the current font style.
  15313. */
  15314. mxAbstractCanvas2D.prototype.setFontStyle = function(value)
  15315. {
  15316. if (value == null)
  15317. {
  15318. value = 0;
  15319. }
  15320. this.state.fontStyle = value;
  15321. };
  15322. /**
  15323. * Function: setShadow
  15324. *
  15325. * Enables or disables and configures the current shadow.
  15326. */
  15327. mxAbstractCanvas2D.prototype.setShadow = function(enabled)
  15328. {
  15329. this.state.shadow = enabled;
  15330. };
  15331. /**
  15332. * Function: setShadowColor
  15333. *
  15334. * Enables or disables and configures the current shadow.
  15335. */
  15336. mxAbstractCanvas2D.prototype.setShadowColor = function(value)
  15337. {
  15338. if (value == mxConstants.NONE)
  15339. {
  15340. value = null;
  15341. }
  15342. this.state.shadowColor = value;
  15343. };
  15344. /**
  15345. * Function: setShadowAlpha
  15346. *
  15347. * Enables or disables and configures the current shadow.
  15348. */
  15349. mxAbstractCanvas2D.prototype.setShadowAlpha = function(value)
  15350. {
  15351. this.state.shadowAlpha = value;
  15352. };
  15353. /**
  15354. * Function: setShadowOffset
  15355. *
  15356. * Enables or disables and configures the current shadow.
  15357. */
  15358. mxAbstractCanvas2D.prototype.setShadowOffset = function(dx, dy)
  15359. {
  15360. this.state.shadowDx = dx;
  15361. this.state.shadowDy = dy;
  15362. };
  15363. /**
  15364. * Function: begin
  15365. *
  15366. * Starts a new path.
  15367. */
  15368. mxAbstractCanvas2D.prototype.begin = function()
  15369. {
  15370. this.lastX = 0;
  15371. this.lastY = 0;
  15372. this.path = [];
  15373. };
  15374. /**
  15375. * Function: moveTo
  15376. *
  15377. * Moves the current path the given coordinates.
  15378. */
  15379. mxAbstractCanvas2D.prototype.moveTo = function(x, y)
  15380. {
  15381. this.addOp(this.moveOp, x, y);
  15382. };
  15383. /**
  15384. * Function: lineTo
  15385. *
  15386. * Draws a line to the given coordinates. Uses moveTo with the op argument.
  15387. */
  15388. mxAbstractCanvas2D.prototype.lineTo = function(x, y)
  15389. {
  15390. this.addOp(this.lineOp, x, y);
  15391. };
  15392. /**
  15393. * Function: quadTo
  15394. *
  15395. * Adds a quadratic curve to the current path.
  15396. */
  15397. mxAbstractCanvas2D.prototype.quadTo = function(x1, y1, x2, y2)
  15398. {
  15399. this.addOp(this.quadOp, x1, y1, x2, y2);
  15400. };
  15401. /**
  15402. * Function: curveTo
  15403. *
  15404. * Adds a bezier curve to the current path.
  15405. */
  15406. mxAbstractCanvas2D.prototype.curveTo = function(x1, y1, x2, y2, x3, y3)
  15407. {
  15408. this.addOp(this.curveOp, x1, y1, x2, y2, x3, y3);
  15409. };
  15410. /**
  15411. * Function: arcTo
  15412. *
  15413. * Adds the given arc to the current path. This is a synthetic operation that
  15414. * is broken down into curves.
  15415. */
  15416. mxAbstractCanvas2D.prototype.arcTo = function(rx, ry, angle, largeArcFlag, sweepFlag, x, y)
  15417. {
  15418. var curves = mxUtils.arcToCurves(this.lastX, this.lastY, rx, ry, angle, largeArcFlag, sweepFlag, x, y);
  15419. if (curves != null)
  15420. {
  15421. for (var i = 0; i < curves.length; i += 6)
  15422. {
  15423. this.curveTo(curves[i], curves[i + 1], curves[i + 2],
  15424. curves[i + 3], curves[i + 4], curves[i + 5]);
  15425. }
  15426. }
  15427. };
  15428. /**
  15429. * Function: close
  15430. *
  15431. * Closes the current path.
  15432. */
  15433. mxAbstractCanvas2D.prototype.close = function(x1, y1, x2, y2, x3, y3)
  15434. {
  15435. this.addOp(this.closeOp);
  15436. };
  15437. /**
  15438. * Function: end
  15439. *
  15440. * Empty implementation for backwards compatibility. This will be removed.
  15441. */
  15442. mxAbstractCanvas2D.prototype.end = function() { };
  15443. /**
  15444. * Copyright (c) 2006-2015, JGraph Ltd
  15445. * Copyright (c) 2006-2015, Gaudenz Alder
  15446. */
  15447. /**
  15448. * Class: mxXmlCanvas2D
  15449. *
  15450. * Base class for all canvases. The following methods make up the public
  15451. * interface of the canvas 2D for all painting in mxGraph:
  15452. *
  15453. * - <save>, <restore>
  15454. * - <scale>, <translate>, <rotate>
  15455. * - <setAlpha>, <setFillAlpha>, <setStrokeAlpha>, <setFillColor>, <setGradient>,
  15456. * <setStrokeColor>, <setStrokeWidth>, <setDashed>, <setDashPattern>, <setLineCap>,
  15457. * <setLineJoin>, <setMiterLimit>
  15458. * - <setFontColor>, <setFontBackgroundColor>, <setFontBorderColor>, <setFontSize>,
  15459. * <setFontFamily>, <setFontStyle>
  15460. * - <setShadow>, <setShadowColor>, <setShadowAlpha>, <setShadowOffset>
  15461. * - <rect>, <roundrect>, <ellipse>, <image>, <text>
  15462. * - <begin>, <moveTo>, <lineTo>, <quadTo>, <curveTo>
  15463. * - <stroke>, <fill>, <fillAndStroke>
  15464. *
  15465. * <mxAbstractCanvas2D.arcTo> is an additional method for drawing paths. This is
  15466. * a synthetic method, meaning that it is turned into a sequence of curves by
  15467. * default. Subclassers may add native support for arcs.
  15468. *
  15469. * Constructor: mxXmlCanvas2D
  15470. *
  15471. * Constructs a new abstract canvas.
  15472. */
  15473. function mxXmlCanvas2D(root)
  15474. {
  15475. mxAbstractCanvas2D.call(this);
  15476. /**
  15477. * Variable: root
  15478. *
  15479. * Reference to the container for the SVG content.
  15480. */
  15481. this.root = root;
  15482. // Writes default settings;
  15483. this.writeDefaults();
  15484. };
  15485. /**
  15486. * Extends mxAbstractCanvas2D
  15487. */
  15488. mxUtils.extend(mxXmlCanvas2D, mxAbstractCanvas2D);
  15489. /**
  15490. * Variable: textEnabled
  15491. *
  15492. * Specifies if text output should be enabled. Default is true.
  15493. */
  15494. mxXmlCanvas2D.prototype.textEnabled = true;
  15495. /**
  15496. * Variable: compressed
  15497. *
  15498. * Specifies if the output should be compressed by removing redundant calls.
  15499. * Default is true.
  15500. */
  15501. mxXmlCanvas2D.prototype.compressed = true;
  15502. /**
  15503. * Function: writeDefaults
  15504. *
  15505. * Writes the rendering defaults to <root>:
  15506. */
  15507. mxXmlCanvas2D.prototype.writeDefaults = function()
  15508. {
  15509. var elem;
  15510. // Writes font defaults
  15511. elem = this.createElement('fontfamily');
  15512. elem.setAttribute('family', mxConstants.DEFAULT_FONTFAMILY);
  15513. this.root.appendChild(elem);
  15514. elem = this.createElement('fontsize');
  15515. elem.setAttribute('size', mxConstants.DEFAULT_FONTSIZE);
  15516. this.root.appendChild(elem);
  15517. // Writes shadow defaults
  15518. elem = this.createElement('shadowcolor');
  15519. elem.setAttribute('color', mxConstants.SHADOWCOLOR);
  15520. this.root.appendChild(elem);
  15521. elem = this.createElement('shadowalpha');
  15522. elem.setAttribute('alpha', mxConstants.SHADOW_OPACITY);
  15523. this.root.appendChild(elem);
  15524. elem = this.createElement('shadowoffset');
  15525. elem.setAttribute('dx', mxConstants.SHADOW_OFFSET_X);
  15526. elem.setAttribute('dy', mxConstants.SHADOW_OFFSET_Y);
  15527. this.root.appendChild(elem);
  15528. };
  15529. /**
  15530. * Function: format
  15531. *
  15532. * Returns a formatted number with 2 decimal places.
  15533. */
  15534. mxXmlCanvas2D.prototype.format = function(value)
  15535. {
  15536. return parseFloat(parseFloat(value).toFixed(2));
  15537. };
  15538. /**
  15539. * Function: createElement
  15540. *
  15541. * Creates the given element using the owner document of <root>.
  15542. */
  15543. mxXmlCanvas2D.prototype.createElement = function(name)
  15544. {
  15545. return this.root.ownerDocument.createElement(name);
  15546. };
  15547. /**
  15548. * Function: save
  15549. *
  15550. * Saves the drawing state.
  15551. */
  15552. mxXmlCanvas2D.prototype.save = function()
  15553. {
  15554. if (this.compressed)
  15555. {
  15556. mxAbstractCanvas2D.prototype.save.apply(this, arguments);
  15557. }
  15558. this.root.appendChild(this.createElement('save'));
  15559. };
  15560. /**
  15561. * Function: restore
  15562. *
  15563. * Restores the drawing state.
  15564. */
  15565. mxXmlCanvas2D.prototype.restore = function()
  15566. {
  15567. if (this.compressed)
  15568. {
  15569. mxAbstractCanvas2D.prototype.restore.apply(this, arguments);
  15570. }
  15571. this.root.appendChild(this.createElement('restore'));
  15572. };
  15573. /**
  15574. * Function: scale
  15575. *
  15576. * Scales the output.
  15577. *
  15578. * Parameters:
  15579. *
  15580. * scale - Number that represents the scale where 1 is equal to 100%.
  15581. */
  15582. mxXmlCanvas2D.prototype.scale = function(value)
  15583. {
  15584. var elem = this.createElement('scale');
  15585. elem.setAttribute('scale', value);
  15586. this.root.appendChild(elem);
  15587. };
  15588. /**
  15589. * Function: translate
  15590. *
  15591. * Translates the output.
  15592. *
  15593. * Parameters:
  15594. *
  15595. * dx - Number that specifies the horizontal translation.
  15596. * dy - Number that specifies the vertical translation.
  15597. */
  15598. mxXmlCanvas2D.prototype.translate = function(dx, dy)
  15599. {
  15600. var elem = this.createElement('translate');
  15601. elem.setAttribute('dx', this.format(dx));
  15602. elem.setAttribute('dy', this.format(dy));
  15603. this.root.appendChild(elem);
  15604. };
  15605. /**
  15606. * Function: rotate
  15607. *
  15608. * Rotates and/or flips the output around a given center. (Note: Due to
  15609. * limitations in VML, the rotation cannot be concatenated.)
  15610. *
  15611. * Parameters:
  15612. *
  15613. * theta - Number that represents the angle of the rotation (in degrees).
  15614. * flipH - Boolean indicating if the output should be flipped horizontally.
  15615. * flipV - Boolean indicating if the output should be flipped vertically.
  15616. * cx - Number that represents the x-coordinate of the rotation center.
  15617. * cy - Number that represents the y-coordinate of the rotation center.
  15618. */
  15619. mxXmlCanvas2D.prototype.rotate = function(theta, flipH, flipV, cx, cy)
  15620. {
  15621. var elem = this.createElement('rotate');
  15622. if (theta != 0 || flipH || flipV)
  15623. {
  15624. elem.setAttribute('theta', this.format(theta));
  15625. elem.setAttribute('flipH', (flipH) ? '1' : '0');
  15626. elem.setAttribute('flipV', (flipV) ? '1' : '0');
  15627. elem.setAttribute('cx', this.format(cx));
  15628. elem.setAttribute('cy', this.format(cy));
  15629. this.root.appendChild(elem);
  15630. }
  15631. };
  15632. /**
  15633. * Function: setAlpha
  15634. *
  15635. * Sets the current alpha.
  15636. *
  15637. * Parameters:
  15638. *
  15639. * value - Number that represents the new alpha. Possible values are between
  15640. * 1 (opaque) and 0 (transparent).
  15641. */
  15642. mxXmlCanvas2D.prototype.setAlpha = function(value)
  15643. {
  15644. if (this.compressed)
  15645. {
  15646. if (this.state.alpha == value)
  15647. {
  15648. return;
  15649. }
  15650. mxAbstractCanvas2D.prototype.setAlpha.apply(this, arguments);
  15651. }
  15652. var elem = this.createElement('alpha');
  15653. elem.setAttribute('alpha', this.format(value));
  15654. this.root.appendChild(elem);
  15655. };
  15656. /**
  15657. * Function: setFillAlpha
  15658. *
  15659. * Sets the current fill alpha.
  15660. *
  15661. * Parameters:
  15662. *
  15663. * value - Number that represents the new fill alpha. Possible values are between
  15664. * 1 (opaque) and 0 (transparent).
  15665. */
  15666. mxXmlCanvas2D.prototype.setFillAlpha = function(value)
  15667. {
  15668. if (this.compressed)
  15669. {
  15670. if (this.state.fillAlpha == value)
  15671. {
  15672. return;
  15673. }
  15674. mxAbstractCanvas2D.prototype.setFillAlpha.apply(this, arguments);
  15675. }
  15676. var elem = this.createElement('fillalpha');
  15677. elem.setAttribute('alpha', this.format(value));
  15678. this.root.appendChild(elem);
  15679. };
  15680. /**
  15681. * Function: setStrokeAlpha
  15682. *
  15683. * Sets the current stroke alpha.
  15684. *
  15685. * Parameters:
  15686. *
  15687. * value - Number that represents the new stroke alpha. Possible values are between
  15688. * 1 (opaque) and 0 (transparent).
  15689. */
  15690. mxXmlCanvas2D.prototype.setStrokeAlpha = function(value)
  15691. {
  15692. if (this.compressed)
  15693. {
  15694. if (this.state.strokeAlpha == value)
  15695. {
  15696. return;
  15697. }
  15698. mxAbstractCanvas2D.prototype.setStrokeAlpha.apply(this, arguments);
  15699. }
  15700. var elem = this.createElement('strokealpha');
  15701. elem.setAttribute('alpha', this.format(value));
  15702. this.root.appendChild(elem);
  15703. };
  15704. /**
  15705. * Function: setFillColor
  15706. *
  15707. * Sets the current fill color.
  15708. *
  15709. * Parameters:
  15710. *
  15711. * value - Hexadecimal representation of the color or 'none'.
  15712. */
  15713. mxXmlCanvas2D.prototype.setFillColor = function(value)
  15714. {
  15715. if (value == mxConstants.NONE)
  15716. {
  15717. value = null;
  15718. }
  15719. if (this.compressed)
  15720. {
  15721. if (this.state.fillColor == value)
  15722. {
  15723. return;
  15724. }
  15725. mxAbstractCanvas2D.prototype.setFillColor.apply(this, arguments);
  15726. }
  15727. var elem = this.createElement('fillcolor');
  15728. elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
  15729. this.root.appendChild(elem);
  15730. };
  15731. /**
  15732. * Function: setGradient
  15733. *
  15734. * Sets the gradient. Note that the coordinates may be ignored by some implementations.
  15735. *
  15736. * Parameters:
  15737. *
  15738. * color1 - Hexadecimal representation of the start color.
  15739. * color2 - Hexadecimal representation of the end color.
  15740. * x - X-coordinate of the gradient region.
  15741. * y - y-coordinate of the gradient region.
  15742. * w - Width of the gradient region.
  15743. * h - Height of the gradient region.
  15744. * direction - One of <mxConstants.DIRECTION_NORTH>, <mxConstants.DIRECTION_EAST>,
  15745. * <mxConstants.DIRECTION_SOUTH> or <mxConstants.DIRECTION_WEST>.
  15746. * alpha1 - Optional alpha of the start color. Default is 1. Possible values
  15747. * are between 1 (opaque) and 0 (transparent).
  15748. * alpha2 - Optional alpha of the end color. Default is 1. Possible values
  15749. * are between 1 (opaque) and 0 (transparent).
  15750. */
  15751. mxXmlCanvas2D.prototype.setGradient = function(color1, color2, x, y, w, h, direction, alpha1, alpha2)
  15752. {
  15753. if (color1 != null && color2 != null)
  15754. {
  15755. mxAbstractCanvas2D.prototype.setGradient.apply(this, arguments);
  15756. var elem = this.createElement('gradient');
  15757. elem.setAttribute('c1', color1);
  15758. elem.setAttribute('c2', color2);
  15759. elem.setAttribute('x', this.format(x));
  15760. elem.setAttribute('y', this.format(y));
  15761. elem.setAttribute('w', this.format(w));
  15762. elem.setAttribute('h', this.format(h));
  15763. // Default direction is south
  15764. if (direction != null)
  15765. {
  15766. elem.setAttribute('direction', direction);
  15767. }
  15768. if (alpha1 != null)
  15769. {
  15770. elem.setAttribute('alpha1', alpha1);
  15771. }
  15772. if (alpha2 != null)
  15773. {
  15774. elem.setAttribute('alpha2', alpha2);
  15775. }
  15776. this.root.appendChild(elem);
  15777. }
  15778. };
  15779. /**
  15780. * Function: setStrokeColor
  15781. *
  15782. * Sets the current stroke color.
  15783. *
  15784. * Parameters:
  15785. *
  15786. * value - Hexadecimal representation of the color or 'none'.
  15787. */
  15788. mxXmlCanvas2D.prototype.setStrokeColor = function(value)
  15789. {
  15790. if (value == mxConstants.NONE)
  15791. {
  15792. value = null;
  15793. }
  15794. if (this.compressed)
  15795. {
  15796. if (this.state.strokeColor == value)
  15797. {
  15798. return;
  15799. }
  15800. mxAbstractCanvas2D.prototype.setStrokeColor.apply(this, arguments);
  15801. }
  15802. var elem = this.createElement('strokecolor');
  15803. elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
  15804. this.root.appendChild(elem);
  15805. };
  15806. /**
  15807. * Function: setStrokeWidth
  15808. *
  15809. * Sets the current stroke width.
  15810. *
  15811. * Parameters:
  15812. *
  15813. * value - Numeric representation of the stroke width.
  15814. */
  15815. mxXmlCanvas2D.prototype.setStrokeWidth = function(value)
  15816. {
  15817. if (this.compressed)
  15818. {
  15819. if (this.state.strokeWidth == value)
  15820. {
  15821. return;
  15822. }
  15823. mxAbstractCanvas2D.prototype.setStrokeWidth.apply(this, arguments);
  15824. }
  15825. var elem = this.createElement('strokewidth');
  15826. elem.setAttribute('width', this.format(value));
  15827. this.root.appendChild(elem);
  15828. };
  15829. /**
  15830. * Function: setDashed
  15831. *
  15832. * Enables or disables dashed lines.
  15833. *
  15834. * Parameters:
  15835. *
  15836. * value - Boolean that specifies if dashed lines should be enabled.
  15837. * value - Boolean that specifies if the stroke width should be ignored
  15838. * for the dash pattern. Default is false.
  15839. */
  15840. mxXmlCanvas2D.prototype.setDashed = function(value, fixDash)
  15841. {
  15842. if (this.compressed)
  15843. {
  15844. if (this.state.dashed == value)
  15845. {
  15846. return;
  15847. }
  15848. mxAbstractCanvas2D.prototype.setDashed.apply(this, arguments);
  15849. }
  15850. var elem = this.createElement('dashed');
  15851. elem.setAttribute('dashed', (value) ? '1' : '0');
  15852. if (fixDash != null)
  15853. {
  15854. elem.setAttribute('fixDash', (fixDash) ? '1' : '0');
  15855. }
  15856. this.root.appendChild(elem);
  15857. };
  15858. /**
  15859. * Function: setDashPattern
  15860. *
  15861. * Sets the current dash pattern. Default is '3 3'.
  15862. *
  15863. * Parameters:
  15864. *
  15865. * value - String that represents the dash pattern, which is a sequence of
  15866. * numbers defining the length of the dashes and the length of the spaces
  15867. * between the dashes. The lengths are relative to the line width - a length
  15868. * of 1 is equals to the line width.
  15869. */
  15870. mxXmlCanvas2D.prototype.setDashPattern = function(value)
  15871. {
  15872. if (this.compressed)
  15873. {
  15874. if (this.state.dashPattern == value)
  15875. {
  15876. return;
  15877. }
  15878. mxAbstractCanvas2D.prototype.setDashPattern.apply(this, arguments);
  15879. }
  15880. var elem = this.createElement('dashpattern');
  15881. elem.setAttribute('pattern', value);
  15882. this.root.appendChild(elem);
  15883. };
  15884. /**
  15885. * Function: setLineCap
  15886. *
  15887. * Sets the line cap. Default is 'flat' which corresponds to 'butt' in SVG.
  15888. *
  15889. * Parameters:
  15890. *
  15891. * value - String that represents the line cap. Possible values are flat, round
  15892. * and square.
  15893. */
  15894. mxXmlCanvas2D.prototype.setLineCap = function(value)
  15895. {
  15896. if (this.compressed)
  15897. {
  15898. if (this.state.lineCap == value)
  15899. {
  15900. return;
  15901. }
  15902. mxAbstractCanvas2D.prototype.setLineCap.apply(this, arguments);
  15903. }
  15904. var elem = this.createElement('linecap');
  15905. elem.setAttribute('cap', value);
  15906. this.root.appendChild(elem);
  15907. };
  15908. /**
  15909. * Function: setLineJoin
  15910. *
  15911. * Sets the line join. Default is 'miter'.
  15912. *
  15913. * Parameters:
  15914. *
  15915. * value - String that represents the line join. Possible values are miter,
  15916. * round and bevel.
  15917. */
  15918. mxXmlCanvas2D.prototype.setLineJoin = function(value)
  15919. {
  15920. if (this.compressed)
  15921. {
  15922. if (this.state.lineJoin == value)
  15923. {
  15924. return;
  15925. }
  15926. mxAbstractCanvas2D.prototype.setLineJoin.apply(this, arguments);
  15927. }
  15928. var elem = this.createElement('linejoin');
  15929. elem.setAttribute('join', value);
  15930. this.root.appendChild(elem);
  15931. };
  15932. /**
  15933. * Function: setMiterLimit
  15934. *
  15935. * Sets the miter limit. Default is 10.
  15936. *
  15937. * Parameters:
  15938. *
  15939. * value - Number that represents the miter limit.
  15940. */
  15941. mxXmlCanvas2D.prototype.setMiterLimit = function(value)
  15942. {
  15943. if (this.compressed)
  15944. {
  15945. if (this.state.miterLimit == value)
  15946. {
  15947. return;
  15948. }
  15949. mxAbstractCanvas2D.prototype.setMiterLimit.apply(this, arguments);
  15950. }
  15951. var elem = this.createElement('miterlimit');
  15952. elem.setAttribute('limit', value);
  15953. this.root.appendChild(elem);
  15954. };
  15955. /**
  15956. * Function: setFontColor
  15957. *
  15958. * Sets the current font color. Default is '#000000'.
  15959. *
  15960. * Parameters:
  15961. *
  15962. * value - Hexadecimal representation of the color or 'none'.
  15963. */
  15964. mxXmlCanvas2D.prototype.setFontColor = function(value)
  15965. {
  15966. if (this.textEnabled)
  15967. {
  15968. if (value == mxConstants.NONE)
  15969. {
  15970. value = null;
  15971. }
  15972. if (this.compressed)
  15973. {
  15974. if (this.state.fontColor == value)
  15975. {
  15976. return;
  15977. }
  15978. mxAbstractCanvas2D.prototype.setFontColor.apply(this, arguments);
  15979. }
  15980. var elem = this.createElement('fontcolor');
  15981. elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
  15982. this.root.appendChild(elem);
  15983. }
  15984. };
  15985. /**
  15986. * Function: setFontBackgroundColor
  15987. *
  15988. * Sets the current font background color.
  15989. *
  15990. * Parameters:
  15991. *
  15992. * value - Hexadecimal representation of the color or 'none'.
  15993. */
  15994. mxXmlCanvas2D.prototype.setFontBackgroundColor = function(value)
  15995. {
  15996. if (this.textEnabled)
  15997. {
  15998. if (value == mxConstants.NONE)
  15999. {
  16000. value = null;
  16001. }
  16002. if (this.compressed)
  16003. {
  16004. if (this.state.fontBackgroundColor == value)
  16005. {
  16006. return;
  16007. }
  16008. mxAbstractCanvas2D.prototype.setFontBackgroundColor.apply(this, arguments);
  16009. }
  16010. var elem = this.createElement('fontbackgroundcolor');
  16011. elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
  16012. this.root.appendChild(elem);
  16013. }
  16014. };
  16015. /**
  16016. * Function: setFontBorderColor
  16017. *
  16018. * Sets the current font border color.
  16019. *
  16020. * Parameters:
  16021. *
  16022. * value - Hexadecimal representation of the color or 'none'.
  16023. */
  16024. mxXmlCanvas2D.prototype.setFontBorderColor = function(value)
  16025. {
  16026. if (this.textEnabled)
  16027. {
  16028. if (value == mxConstants.NONE)
  16029. {
  16030. value = null;
  16031. }
  16032. if (this.compressed)
  16033. {
  16034. if (this.state.fontBorderColor == value)
  16035. {
  16036. return;
  16037. }
  16038. mxAbstractCanvas2D.prototype.setFontBorderColor.apply(this, arguments);
  16039. }
  16040. var elem = this.createElement('fontbordercolor');
  16041. elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
  16042. this.root.appendChild(elem);
  16043. }
  16044. };
  16045. /**
  16046. * Function: setFontSize
  16047. *
  16048. * Sets the current font size. Default is <mxConstants.DEFAULT_FONTSIZE>.
  16049. *
  16050. * Parameters:
  16051. *
  16052. * value - Numeric representation of the font size.
  16053. */
  16054. mxXmlCanvas2D.prototype.setFontSize = function(value)
  16055. {
  16056. if (this.textEnabled)
  16057. {
  16058. if (this.compressed)
  16059. {
  16060. if (this.state.fontSize == value)
  16061. {
  16062. return;
  16063. }
  16064. mxAbstractCanvas2D.prototype.setFontSize.apply(this, arguments);
  16065. }
  16066. var elem = this.createElement('fontsize');
  16067. elem.setAttribute('size', value);
  16068. this.root.appendChild(elem);
  16069. }
  16070. };
  16071. /**
  16072. * Function: setFontFamily
  16073. *
  16074. * Sets the current font family. Default is <mxConstants.DEFAULT_FONTFAMILY>.
  16075. *
  16076. * Parameters:
  16077. *
  16078. * value - String representation of the font family. This handles the same
  16079. * values as the CSS font-family property.
  16080. */
  16081. mxXmlCanvas2D.prototype.setFontFamily = function(value)
  16082. {
  16083. if (this.textEnabled)
  16084. {
  16085. if (this.compressed)
  16086. {
  16087. if (this.state.fontFamily == value)
  16088. {
  16089. return;
  16090. }
  16091. mxAbstractCanvas2D.prototype.setFontFamily.apply(this, arguments);
  16092. }
  16093. var elem = this.createElement('fontfamily');
  16094. elem.setAttribute('family', value);
  16095. this.root.appendChild(elem);
  16096. }
  16097. };
  16098. /**
  16099. * Function: setFontStyle
  16100. *
  16101. * Sets the current font style.
  16102. *
  16103. * Parameters:
  16104. *
  16105. * value - Numeric representation of the font family. This is the sum of the
  16106. * font styles from <mxConstants>.
  16107. */
  16108. mxXmlCanvas2D.prototype.setFontStyle = function(value)
  16109. {
  16110. if (this.textEnabled)
  16111. {
  16112. if (value == null)
  16113. {
  16114. value = 0;
  16115. }
  16116. if (this.compressed)
  16117. {
  16118. if (this.state.fontStyle == value)
  16119. {
  16120. return;
  16121. }
  16122. mxAbstractCanvas2D.prototype.setFontStyle.apply(this, arguments);
  16123. }
  16124. var elem = this.createElement('fontstyle');
  16125. elem.setAttribute('style', value);
  16126. this.root.appendChild(elem);
  16127. }
  16128. };
  16129. /**
  16130. * Function: setShadow
  16131. *
  16132. * Enables or disables shadows.
  16133. *
  16134. * Parameters:
  16135. *
  16136. * value - Boolean that specifies if shadows should be enabled.
  16137. */
  16138. mxXmlCanvas2D.prototype.setShadow = function(value)
  16139. {
  16140. if (this.compressed)
  16141. {
  16142. if (this.state.shadow == value)
  16143. {
  16144. return;
  16145. }
  16146. mxAbstractCanvas2D.prototype.setShadow.apply(this, arguments);
  16147. }
  16148. var elem = this.createElement('shadow');
  16149. elem.setAttribute('enabled', (value) ? '1' : '0');
  16150. this.root.appendChild(elem);
  16151. };
  16152. /**
  16153. * Function: setShadowColor
  16154. *
  16155. * Sets the current shadow color. Default is <mxConstants.SHADOWCOLOR>.
  16156. *
  16157. * Parameters:
  16158. *
  16159. * value - Hexadecimal representation of the color or 'none'.
  16160. */
  16161. mxXmlCanvas2D.prototype.setShadowColor = function(value)
  16162. {
  16163. if (this.compressed)
  16164. {
  16165. if (value == mxConstants.NONE)
  16166. {
  16167. value = null;
  16168. }
  16169. if (this.state.shadowColor == value)
  16170. {
  16171. return;
  16172. }
  16173. mxAbstractCanvas2D.prototype.setShadowColor.apply(this, arguments);
  16174. }
  16175. var elem = this.createElement('shadowcolor');
  16176. elem.setAttribute('color', (value != null) ? value : mxConstants.NONE);
  16177. this.root.appendChild(elem);
  16178. };
  16179. /**
  16180. * Function: setShadowAlpha
  16181. *
  16182. * Sets the current shadows alpha. Default is <mxConstants.SHADOW_OPACITY>.
  16183. *
  16184. * Parameters:
  16185. *
  16186. * value - Number that represents the new alpha. Possible values are between
  16187. * 1 (opaque) and 0 (transparent).
  16188. */
  16189. mxXmlCanvas2D.prototype.setShadowAlpha = function(value)
  16190. {
  16191. if (this.compressed)
  16192. {
  16193. if (this.state.shadowAlpha == value)
  16194. {
  16195. return;
  16196. }
  16197. mxAbstractCanvas2D.prototype.setShadowAlpha.apply(this, arguments);
  16198. }
  16199. var elem = this.createElement('shadowalpha');
  16200. elem.setAttribute('alpha', value);
  16201. this.root.appendChild(elem);
  16202. };
  16203. /**
  16204. * Function: setShadowOffset
  16205. *
  16206. * Sets the current shadow offset.
  16207. *
  16208. * Parameters:
  16209. *
  16210. * dx - Number that represents the horizontal offset of the shadow.
  16211. * dy - Number that represents the vertical offset of the shadow.
  16212. */
  16213. mxXmlCanvas2D.prototype.setShadowOffset = function(dx, dy)
  16214. {
  16215. if (this.compressed)
  16216. {
  16217. if (this.state.shadowDx == dx && this.state.shadowDy == dy)
  16218. {
  16219. return;
  16220. }
  16221. mxAbstractCanvas2D.prototype.setShadowOffset.apply(this, arguments);
  16222. }
  16223. var elem = this.createElement('shadowoffset');
  16224. elem.setAttribute('dx', dx);
  16225. elem.setAttribute('dy', dy);
  16226. this.root.appendChild(elem);
  16227. };
  16228. /**
  16229. * Function: rect
  16230. *
  16231. * Puts a rectangle into the drawing buffer.
  16232. *
  16233. * Parameters:
  16234. *
  16235. * x - Number that represents the x-coordinate of the rectangle.
  16236. * y - Number that represents the y-coordinate of the rectangle.
  16237. * w - Number that represents the width of the rectangle.
  16238. * h - Number that represents the height of the rectangle.
  16239. */
  16240. mxXmlCanvas2D.prototype.rect = function(x, y, w, h)
  16241. {
  16242. var elem = this.createElement('rect');
  16243. elem.setAttribute('x', this.format(x));
  16244. elem.setAttribute('y', this.format(y));
  16245. elem.setAttribute('w', this.format(w));
  16246. elem.setAttribute('h', this.format(h));
  16247. this.root.appendChild(elem);
  16248. };
  16249. /**
  16250. * Function: roundrect
  16251. *
  16252. * Puts a rounded rectangle into the drawing buffer.
  16253. *
  16254. * Parameters:
  16255. *
  16256. * x - Number that represents the x-coordinate of the rectangle.
  16257. * y - Number that represents the y-coordinate of the rectangle.
  16258. * w - Number that represents the width of the rectangle.
  16259. * h - Number that represents the height of the rectangle.
  16260. * dx - Number that represents the horizontal rounding.
  16261. * dy - Number that represents the vertical rounding.
  16262. */
  16263. mxXmlCanvas2D.prototype.roundrect = function(x, y, w, h, dx, dy)
  16264. {
  16265. var elem = this.createElement('roundrect');
  16266. elem.setAttribute('x', this.format(x));
  16267. elem.setAttribute('y', this.format(y));
  16268. elem.setAttribute('w', this.format(w));
  16269. elem.setAttribute('h', this.format(h));
  16270. elem.setAttribute('dx', this.format(dx));
  16271. elem.setAttribute('dy', this.format(dy));
  16272. this.root.appendChild(elem);
  16273. };
  16274. /**
  16275. * Function: ellipse
  16276. *
  16277. * Puts an ellipse into the drawing buffer.
  16278. *
  16279. * Parameters:
  16280. *
  16281. * x - Number that represents the x-coordinate of the ellipse.
  16282. * y - Number that represents the y-coordinate of the ellipse.
  16283. * w - Number that represents the width of the ellipse.
  16284. * h - Number that represents the height of the ellipse.
  16285. */
  16286. mxXmlCanvas2D.prototype.ellipse = function(x, y, w, h)
  16287. {
  16288. var elem = this.createElement('ellipse');
  16289. elem.setAttribute('x', this.format(x));
  16290. elem.setAttribute('y', this.format(y));
  16291. elem.setAttribute('w', this.format(w));
  16292. elem.setAttribute('h', this.format(h));
  16293. this.root.appendChild(elem);
  16294. };
  16295. /**
  16296. * Function: image
  16297. *
  16298. * Paints an image.
  16299. *
  16300. * Parameters:
  16301. *
  16302. * x - Number that represents the x-coordinate of the image.
  16303. * y - Number that represents the y-coordinate of the image.
  16304. * w - Number that represents the width of the image.
  16305. * h - Number that represents the height of the image.
  16306. * src - String that specifies the URL of the image.
  16307. * aspect - Boolean indicating if the aspect of the image should be preserved.
  16308. * flipH - Boolean indicating if the image should be flipped horizontally.
  16309. * flipV - Boolean indicating if the image should be flipped vertically.
  16310. */
  16311. mxXmlCanvas2D.prototype.image = function(x, y, w, h, src, aspect, flipH, flipV)
  16312. {
  16313. src = this.converter.convert(src);
  16314. // LATER: Add option for embedding images as base64.
  16315. var elem = this.createElement('image');
  16316. elem.setAttribute('x', this.format(x));
  16317. elem.setAttribute('y', this.format(y));
  16318. elem.setAttribute('w', this.format(w));
  16319. elem.setAttribute('h', this.format(h));
  16320. elem.setAttribute('src', src);
  16321. elem.setAttribute('aspect', (aspect) ? '1' : '0');
  16322. elem.setAttribute('flipH', (flipH) ? '1' : '0');
  16323. elem.setAttribute('flipV', (flipV) ? '1' : '0');
  16324. this.root.appendChild(elem);
  16325. };
  16326. /**
  16327. * Function: begin
  16328. *
  16329. * Starts a new path and puts it into the drawing buffer.
  16330. */
  16331. mxXmlCanvas2D.prototype.begin = function()
  16332. {
  16333. this.root.appendChild(this.createElement('begin'));
  16334. this.lastX = 0;
  16335. this.lastY = 0;
  16336. };
  16337. /**
  16338. * Function: moveTo
  16339. *
  16340. * Moves the current path the given point.
  16341. *
  16342. * Parameters:
  16343. *
  16344. * x - Number that represents the x-coordinate of the point.
  16345. * y - Number that represents the y-coordinate of the point.
  16346. */
  16347. mxXmlCanvas2D.prototype.moveTo = function(x, y)
  16348. {
  16349. var elem = this.createElement('move');
  16350. elem.setAttribute('x', this.format(x));
  16351. elem.setAttribute('y', this.format(y));
  16352. this.root.appendChild(elem);
  16353. this.lastX = x;
  16354. this.lastY = y;
  16355. };
  16356. /**
  16357. * Function: lineTo
  16358. *
  16359. * Draws a line to the given coordinates.
  16360. *
  16361. * Parameters:
  16362. *
  16363. * x - Number that represents the x-coordinate of the endpoint.
  16364. * y - Number that represents the y-coordinate of the endpoint.
  16365. */
  16366. mxXmlCanvas2D.prototype.lineTo = function(x, y)
  16367. {
  16368. var elem = this.createElement('line');
  16369. elem.setAttribute('x', this.format(x));
  16370. elem.setAttribute('y', this.format(y));
  16371. this.root.appendChild(elem);
  16372. this.lastX = x;
  16373. this.lastY = y;
  16374. };
  16375. /**
  16376. * Function: quadTo
  16377. *
  16378. * Adds a quadratic curve to the current path.
  16379. *
  16380. * Parameters:
  16381. *
  16382. * x1 - Number that represents the x-coordinate of the control point.
  16383. * y1 - Number that represents the y-coordinate of the control point.
  16384. * x2 - Number that represents the x-coordinate of the endpoint.
  16385. * y2 - Number that represents the y-coordinate of the endpoint.
  16386. */
  16387. mxXmlCanvas2D.prototype.quadTo = function(x1, y1, x2, y2)
  16388. {
  16389. var elem = this.createElement('quad');
  16390. elem.setAttribute('x1', this.format(x1));
  16391. elem.setAttribute('y1', this.format(y1));
  16392. elem.setAttribute('x2', this.format(x2));
  16393. elem.setAttribute('y2', this.format(y2));
  16394. this.root.appendChild(elem);
  16395. this.lastX = x2;
  16396. this.lastY = y2;
  16397. };
  16398. /**
  16399. * Function: curveTo
  16400. *
  16401. * Adds a bezier curve to the current path.
  16402. *
  16403. * Parameters:
  16404. *
  16405. * x1 - Number that represents the x-coordinate of the first control point.
  16406. * y1 - Number that represents the y-coordinate of the first control point.
  16407. * x2 - Number that represents the x-coordinate of the second control point.
  16408. * y2 - Number that represents the y-coordinate of the second control point.
  16409. * x3 - Number that represents the x-coordinate of the endpoint.
  16410. * y3 - Number that represents the y-coordinate of the endpoint.
  16411. */
  16412. mxXmlCanvas2D.prototype.curveTo = function(x1, y1, x2, y2, x3, y3)
  16413. {
  16414. var elem = this.createElement('curve');
  16415. elem.setAttribute('x1', this.format(x1));
  16416. elem.setAttribute('y1', this.format(y1));
  16417. elem.setAttribute('x2', this.format(x2));
  16418. elem.setAttribute('y2', this.format(y2));
  16419. elem.setAttribute('x3', this.format(x3));
  16420. elem.setAttribute('y3', this.format(y3));
  16421. this.root.appendChild(elem);
  16422. this.lastX = x3;
  16423. this.lastY = y3;
  16424. };
  16425. /**
  16426. * Function: close
  16427. *
  16428. * Closes the current path.
  16429. */
  16430. mxXmlCanvas2D.prototype.close = function()
  16431. {
  16432. this.root.appendChild(this.createElement('close'));
  16433. };
  16434. /**
  16435. * Function: text
  16436. *
  16437. * Paints the given text. Possible values for format are empty string for
  16438. * plain text and html for HTML markup. Background and border color as well
  16439. * as clipping is not available in plain text labels for VML. HTML labels
  16440. * are not available as part of shapes with no foreignObject support in SVG
  16441. * (eg. IE9, IE10).
  16442. *
  16443. * Parameters:
  16444. *
  16445. * x - Number that represents the x-coordinate of the text.
  16446. * y - Number that represents the y-coordinate of the text.
  16447. * w - Number that represents the available width for the text or 0 for automatic width.
  16448. * h - Number that represents the available height for the text or 0 for automatic height.
  16449. * str - String that specifies the text to be painted.
  16450. * align - String that represents the horizontal alignment.
  16451. * valign - String that represents the vertical alignment.
  16452. * wrap - Boolean that specifies if word-wrapping is enabled. Requires w > 0.
  16453. * format - Empty string for plain text or 'html' for HTML markup.
  16454. * overflow - Specifies the overflow behaviour of the label. Requires w > 0 and/or h > 0.
  16455. * clip - Boolean that specifies if the label should be clipped. Requires w > 0 and/or h > 0.
  16456. * rotation - Number that specifies the angle of the rotation around the anchor point of the text.
  16457. * dir - Optional string that specifies the text direction. Possible values are rtl and lrt.
  16458. */
  16459. mxXmlCanvas2D.prototype.text = function(x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation, dir)
  16460. {
  16461. if (this.textEnabled && str != null)
  16462. {
  16463. if (mxUtils.isNode(str))
  16464. {
  16465. str = mxUtils.getOuterHtml(str);
  16466. }
  16467. var elem = this.createElement('text');
  16468. elem.setAttribute('x', this.format(x));
  16469. elem.setAttribute('y', this.format(y));
  16470. elem.setAttribute('w', this.format(w));
  16471. elem.setAttribute('h', this.format(h));
  16472. elem.setAttribute('str', str);
  16473. if (align != null)
  16474. {
  16475. elem.setAttribute('align', align);
  16476. }
  16477. if (valign != null)
  16478. {
  16479. elem.setAttribute('valign', valign);
  16480. }
  16481. elem.setAttribute('wrap', (wrap) ? '1' : '0');
  16482. if (format == null)
  16483. {
  16484. format = '';
  16485. }
  16486. elem.setAttribute('format', format);
  16487. if (overflow != null)
  16488. {
  16489. elem.setAttribute('overflow', overflow);
  16490. }
  16491. if (clip != null)
  16492. {
  16493. elem.setAttribute('clip', (clip) ? '1' : '0');
  16494. }
  16495. if (rotation != null)
  16496. {
  16497. elem.setAttribute('rotation', rotation);
  16498. }
  16499. if (dir != null)
  16500. {
  16501. elem.setAttribute('dir', dir);
  16502. }
  16503. this.root.appendChild(elem);
  16504. }
  16505. };
  16506. /**
  16507. * Function: stroke
  16508. *
  16509. * Paints the outline of the current drawing buffer.
  16510. */
  16511. mxXmlCanvas2D.prototype.stroke = function()
  16512. {
  16513. this.root.appendChild(this.createElement('stroke'));
  16514. };
  16515. /**
  16516. * Function: fill
  16517. *
  16518. * Fills the current drawing buffer.
  16519. */
  16520. mxXmlCanvas2D.prototype.fill = function()
  16521. {
  16522. this.root.appendChild(this.createElement('fill'));
  16523. };
  16524. /**
  16525. * Function: fillAndStroke
  16526. *
  16527. * Fills the current drawing buffer and its outline.
  16528. */
  16529. mxXmlCanvas2D.prototype.fillAndStroke = function()
  16530. {
  16531. this.root.appendChild(this.createElement('fillstroke'));
  16532. };
  16533. /**
  16534. * Copyright (c) 2006-2015, JGraph Ltd
  16535. * Copyright (c) 2006-2015, Gaudenz Alder
  16536. */
  16537. /**
  16538. * Class: mxSvgCanvas2D
  16539. *
  16540. * Extends <mxAbstractCanvas2D> to implement a canvas for SVG. This canvas writes all
  16541. * calls as SVG output to the given SVG root node.
  16542. *
  16543. * (code)
  16544. * var svgDoc = mxUtils.createXmlDocument();
  16545. * var root = (svgDoc.createElementNS != null) ?
  16546. * svgDoc.createElementNS(mxConstants.NS_SVG, 'svg') : svgDoc.createElement('svg');
  16547. *
  16548. * if (svgDoc.createElementNS == null)
  16549. * {
  16550. * root.setAttribute('xmlns', mxConstants.NS_SVG);
  16551. * root.setAttribute('xmlns:xlink', mxConstants.NS_XLINK);
  16552. * }
  16553. * else
  16554. * {
  16555. * root.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', mxConstants.NS_XLINK);
  16556. * }
  16557. *
  16558. * var bounds = graph.getGraphBounds();
  16559. * root.setAttribute('width', (bounds.x + bounds.width + 4) + 'px');
  16560. * root.setAttribute('height', (bounds.y + bounds.height + 4) + 'px');
  16561. * root.setAttribute('version', '1.1');
  16562. *
  16563. * svgDoc.appendChild(root);
  16564. *
  16565. * var svgCanvas = new mxSvgCanvas2D(root);
  16566. * (end)
  16567. *
  16568. * A description of the public API is available in <mxXmlCanvas2D>.
  16569. *
  16570. * To disable anti-aliasing in the output, use the following code.
  16571. *
  16572. * (code)
  16573. * graph.view.canvas.ownerSVGElement.setAttribute('shape-rendering', 'crispEdges');
  16574. * (end)
  16575. *
  16576. * Or set the respective attribute in the SVG element directly.
  16577. *
  16578. * Constructor: mxSvgCanvas2D
  16579. *
  16580. * Constructs a new SVG canvas.
  16581. *
  16582. * Parameters:
  16583. *
  16584. * root - SVG container for the output.
  16585. * styleEnabled - Optional boolean that specifies if a style section should be
  16586. * added. The style section sets the default font-size, font-family and
  16587. * stroke-miterlimit globally. Default is false.
  16588. */
  16589. function mxSvgCanvas2D(root, styleEnabled)
  16590. {
  16591. mxAbstractCanvas2D.call(this);
  16592. /**
  16593. * Variable: root
  16594. *
  16595. * Reference to the container for the SVG content.
  16596. */
  16597. this.root = root;
  16598. /**
  16599. * Variable: gradients
  16600. *
  16601. * Local cache of gradients for quick lookups.
  16602. */
  16603. this.gradients = [];
  16604. /**
  16605. * Variable: defs
  16606. *
  16607. * Reference to the defs section of the SVG document. Only for export.
  16608. */
  16609. this.defs = null;
  16610. /**
  16611. * Variable: styleEnabled
  16612. *
  16613. * Stores the value of styleEnabled passed to the constructor.
  16614. */
  16615. this.styleEnabled = (styleEnabled != null) ? styleEnabled : false;
  16616. var svg = null;
  16617. // Adds optional defs section for export
  16618. if (root.ownerDocument != document)
  16619. {
  16620. var node = root;
  16621. // Finds owner SVG element in XML DOM
  16622. while (node != null && node.nodeName != 'svg')
  16623. {
  16624. node = node.parentNode;
  16625. }
  16626. svg = node;
  16627. }
  16628. if (svg != null)
  16629. {
  16630. // Tries to get existing defs section
  16631. var tmp = svg.getElementsByTagName('defs');
  16632. if (tmp.length > 0)
  16633. {
  16634. this.defs = svg.getElementsByTagName('defs')[0];
  16635. }
  16636. // Adds defs section if none exists
  16637. if (this.defs == null)
  16638. {
  16639. this.defs = this.createElement('defs');
  16640. if (svg.firstChild != null)
  16641. {
  16642. svg.insertBefore(this.defs, svg.firstChild);
  16643. }
  16644. else
  16645. {
  16646. svg.appendChild(this.defs);
  16647. }
  16648. }
  16649. // Adds stylesheet
  16650. if (this.styleEnabled)
  16651. {
  16652. this.defs.appendChild(this.createStyle());
  16653. }
  16654. }
  16655. };
  16656. /**
  16657. * Extends mxAbstractCanvas2D
  16658. */
  16659. mxUtils.extend(mxSvgCanvas2D, mxAbstractCanvas2D);
  16660. /**
  16661. * Capability check for DOM parser.
  16662. */
  16663. (function()
  16664. {
  16665. mxSvgCanvas2D.prototype.useDomParser = !mxClient.IS_IE && typeof DOMParser === 'function' && typeof XMLSerializer === 'function';
  16666. if (mxSvgCanvas2D.prototype.useDomParser)
  16667. {
  16668. // Checks using a generic test text if the parsing actually works. This is a workaround
  16669. // for older browsers where the capability check returns true but the parsing fails.
  16670. try
  16671. {
  16672. var doc = new DOMParser().parseFromString('test text', 'text/html');
  16673. mxSvgCanvas2D.prototype.useDomParser = doc != null;
  16674. }
  16675. catch (e)
  16676. {
  16677. mxSvgCanvas2D.prototype.useDomParser = false;
  16678. }
  16679. }
  16680. })();
  16681. /**
  16682. * Variable: path
  16683. *
  16684. * Holds the current DOM node.
  16685. */
  16686. mxSvgCanvas2D.prototype.node = null;
  16687. /**
  16688. * Variable: matchHtmlAlignment
  16689. *
  16690. * Specifies if plain text output should match the vertical HTML alignment.
  16691. * Defaul is true.
  16692. */
  16693. mxSvgCanvas2D.prototype.matchHtmlAlignment = true;
  16694. /**
  16695. * Variable: textEnabled
  16696. *
  16697. * Specifies if text output should be enabled. Default is true.
  16698. */
  16699. mxSvgCanvas2D.prototype.textEnabled = true;
  16700. /**
  16701. * Variable: foEnabled
  16702. *
  16703. * Specifies if use of foreignObject for HTML markup is allowed. Default is true.
  16704. */
  16705. mxSvgCanvas2D.prototype.foEnabled = true;
  16706. /**
  16707. * Variable: foAltText
  16708. *
  16709. * Specifies the fallback text for unsupported foreignObjects in exported
  16710. * documents. Default is '[Object]'. If this is set to null then no fallback
  16711. * text is added to the exported document.
  16712. */
  16713. mxSvgCanvas2D.prototype.foAltText = '[Object]';
  16714. /**
  16715. * Variable: foOffset
  16716. *
  16717. * Offset to be used for foreignObjects.
  16718. */
  16719. mxSvgCanvas2D.prototype.foOffset = 0;
  16720. /**
  16721. * Variable: textOffset
  16722. *
  16723. * Offset to be used for text elements.
  16724. */
  16725. mxSvgCanvas2D.prototype.textOffset = 0;
  16726. /**
  16727. * Variable: imageOffset
  16728. *
  16729. * Offset to be used for image elements.
  16730. */
  16731. mxSvgCanvas2D.prototype.imageOffset = 0;
  16732. /**
  16733. * Variable: strokeTolerance
  16734. *
  16735. * Adds transparent paths for strokes.
  16736. */
  16737. mxSvgCanvas2D.prototype.strokeTolerance = 0;
  16738. /**
  16739. * Variable: minStrokeWidth
  16740. *
  16741. * Minimum stroke width for output.
  16742. */
  16743. mxSvgCanvas2D.prototype.minStrokeWidth = 1;
  16744. /**
  16745. * Variable: refCount
  16746. *
  16747. * Local counter for references in SVG export.
  16748. */
  16749. mxSvgCanvas2D.prototype.refCount = 0;
  16750. /**
  16751. * Variable: lineHeightCorrection
  16752. *
  16753. * Correction factor for <mxConstants.LINE_HEIGHT> in HTML output. Default is 1.
  16754. */
  16755. mxSvgCanvas2D.prototype.lineHeightCorrection = 1;
  16756. /**
  16757. * Variable: pointerEventsValue
  16758. *
  16759. * Default value for active pointer events. Default is all.
  16760. */
  16761. mxSvgCanvas2D.prototype.pointerEventsValue = 'all';
  16762. /**
  16763. * Variable: fontMetricsPadding
  16764. *
  16765. * Padding to be added for text that is not wrapped to account for differences
  16766. * in font metrics on different platforms in pixels. Default is 10.
  16767. */
  16768. mxSvgCanvas2D.prototype.fontMetricsPadding = 10;
  16769. /**
  16770. * Variable: cacheOffsetSize
  16771. *
  16772. * Specifies if offsetWidth and offsetHeight should be cached. Default is true.
  16773. * This is used to speed up repaint of text in <updateText>.
  16774. */
  16775. mxSvgCanvas2D.prototype.cacheOffsetSize = true;
  16776. /**
  16777. * Function: format
  16778. *
  16779. * Rounds all numbers to 2 decimal points.
  16780. */
  16781. mxSvgCanvas2D.prototype.format = function(value)
  16782. {
  16783. return parseFloat(parseFloat(value).toFixed(2));
  16784. };
  16785. /**
  16786. * Function: getBaseUrl
  16787. *
  16788. * Returns the URL of the page without the hash part. This needs to use href to
  16789. * include any search part with no params (ie question mark alone). This is a
  16790. * workaround for the fact that window.location.search is empty if there is
  16791. * no search string behind the question mark.
  16792. */
  16793. mxSvgCanvas2D.prototype.getBaseUrl = function()
  16794. {
  16795. var href = window.location.href;
  16796. var hash = href.lastIndexOf('#');
  16797. if (hash > 0)
  16798. {
  16799. href = href.substring(0, hash);
  16800. }
  16801. return href;
  16802. };
  16803. /**
  16804. * Function: reset
  16805. *
  16806. * Returns any offsets for rendering pixels.
  16807. */
  16808. mxSvgCanvas2D.prototype.reset = function()
  16809. {
  16810. mxAbstractCanvas2D.prototype.reset.apply(this, arguments);
  16811. this.gradients = [];
  16812. };
  16813. /**
  16814. * Function: createStyle
  16815. *
  16816. * Creates the optional style section.
  16817. */
  16818. mxSvgCanvas2D.prototype.createStyle = function(x)
  16819. {
  16820. var style = this.createElement('style');
  16821. style.setAttribute('type', 'text/css');
  16822. mxUtils.write(style, 'svg{font-family:' + mxConstants.DEFAULT_FONTFAMILY +
  16823. ';font-size:' + mxConstants.DEFAULT_FONTSIZE +
  16824. ';fill:none;stroke-miterlimit:10}');
  16825. return style;
  16826. };
  16827. /**
  16828. * Function: createElement
  16829. *
  16830. * Private helper function to create SVG elements
  16831. */
  16832. mxSvgCanvas2D.prototype.createElement = function(tagName, namespace)
  16833. {
  16834. if (this.root.ownerDocument.createElementNS != null)
  16835. {
  16836. return this.root.ownerDocument.createElementNS(namespace || mxConstants.NS_SVG, tagName);
  16837. }
  16838. else
  16839. {
  16840. var elt = this.root.ownerDocument.createElement(tagName);
  16841. if (namespace != null)
  16842. {
  16843. elt.setAttribute('xmlns', namespace);
  16844. }
  16845. return elt;
  16846. }
  16847. };
  16848. /**
  16849. * Function: getAlternateText
  16850. *
  16851. * Returns the alternate text string for the given foreignObject.
  16852. */
  16853. mxSvgCanvas2D.prototype.getAlternateText = function(fo, x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation)
  16854. {
  16855. return (str != null) ? this.foAltText : null;
  16856. };
  16857. /**
  16858. * Function: getAlternateContent
  16859. *
  16860. * Returns the alternate content for the given foreignObject.
  16861. */
  16862. mxSvgCanvas2D.prototype.createAlternateContent = function(fo, x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation)
  16863. {
  16864. var text = this.getAlternateText(fo, x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation);
  16865. var s = this.state;
  16866. if (text != null && s.fontSize > 0)
  16867. {
  16868. var dy = (valign == mxConstants.ALIGN_TOP) ? 1 :
  16869. (valign == mxConstants.ALIGN_BOTTOM) ? 0 : 0.3;
  16870. var anchor = (align == mxConstants.ALIGN_RIGHT) ? 'end' :
  16871. (align == mxConstants.ALIGN_LEFT) ? 'start' :
  16872. 'middle';
  16873. var alt = this.createElement('text');
  16874. alt.setAttribute('x', Math.round(x + s.dx));
  16875. alt.setAttribute('y', Math.round(y + s.dy + dy * s.fontSize));
  16876. alt.setAttribute('fill', s.fontColor || 'black');
  16877. alt.setAttribute('font-family', s.fontFamily);
  16878. alt.setAttribute('font-size', Math.round(s.fontSize) + 'px');
  16879. // Text-anchor start is default in SVG
  16880. if (anchor != 'start')
  16881. {
  16882. alt.setAttribute('text-anchor', anchor);
  16883. }
  16884. if ((s.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  16885. {
  16886. alt.setAttribute('font-weight', 'bold');
  16887. }
  16888. if ((s.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  16889. {
  16890. alt.setAttribute('font-style', 'italic');
  16891. }
  16892. var txtDecor = [];
  16893. if ((s.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  16894. {
  16895. txtDecor.push('underline');
  16896. }
  16897. if ((s.fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  16898. {
  16899. txtDecor.push('line-through');
  16900. }
  16901. if (txtDecor.length > 0)
  16902. {
  16903. alt.setAttribute('text-decoration', txtDecor.join(' '));
  16904. }
  16905. mxUtils.write(alt, text);
  16906. return alt;
  16907. }
  16908. else
  16909. {
  16910. return null;
  16911. }
  16912. };
  16913. /**
  16914. * Function: createGradientId
  16915. *
  16916. * Private helper function to create SVG elements
  16917. */
  16918. mxSvgCanvas2D.prototype.createGradientId = function(start, end, alpha1, alpha2, direction)
  16919. {
  16920. // Removes illegal characters from gradient ID
  16921. if (start.charAt(0) == '#')
  16922. {
  16923. start = start.substring(1);
  16924. }
  16925. if (end.charAt(0) == '#')
  16926. {
  16927. end = end.substring(1);
  16928. }
  16929. // Workaround for gradient IDs not working in Safari 5 / Chrome 6
  16930. // if they contain uppercase characters
  16931. start = start.toLowerCase() + '-' + alpha1;
  16932. end = end.toLowerCase() + '-' + alpha2;
  16933. // Wrong gradient directions possible?
  16934. var dir = null;
  16935. if (direction == null || direction == mxConstants.DIRECTION_SOUTH)
  16936. {
  16937. dir = 's';
  16938. }
  16939. else if (direction == mxConstants.DIRECTION_EAST)
  16940. {
  16941. dir = 'e';
  16942. }
  16943. else
  16944. {
  16945. var tmp = start;
  16946. start = end;
  16947. end = tmp;
  16948. if (direction == mxConstants.DIRECTION_NORTH)
  16949. {
  16950. dir = 's';
  16951. }
  16952. else if (direction == mxConstants.DIRECTION_WEST)
  16953. {
  16954. dir = 'e';
  16955. }
  16956. }
  16957. return 'mx-gradient-' + start + '-' + end + '-' + dir;
  16958. };
  16959. /**
  16960. * Function: getSvgGradient
  16961. *
  16962. * Private helper function to create SVG elements
  16963. */
  16964. mxSvgCanvas2D.prototype.getSvgGradient = function(start, end, alpha1, alpha2, direction)
  16965. {
  16966. var id = this.createGradientId(start, end, alpha1, alpha2, direction);
  16967. var gradient = this.gradients[id];
  16968. if (gradient == null)
  16969. {
  16970. var svg = this.root.ownerSVGElement;
  16971. var counter = 0;
  16972. var tmpId = id + '-' + counter;
  16973. if (svg != null)
  16974. {
  16975. gradient = svg.ownerDocument.getElementById(tmpId);
  16976. while (gradient != null && gradient.ownerSVGElement != svg)
  16977. {
  16978. tmpId = id + '-' + counter++;
  16979. gradient = svg.ownerDocument.getElementById(tmpId);
  16980. }
  16981. }
  16982. else
  16983. {
  16984. // Uses shorter IDs for export
  16985. tmpId = 'id' + (++this.refCount);
  16986. }
  16987. if (gradient == null)
  16988. {
  16989. gradient = this.createSvgGradient(start, end, alpha1, alpha2, direction);
  16990. gradient.setAttribute('id', tmpId);
  16991. if (this.defs != null)
  16992. {
  16993. this.defs.appendChild(gradient);
  16994. }
  16995. else
  16996. {
  16997. svg.appendChild(gradient);
  16998. }
  16999. }
  17000. this.gradients[id] = gradient;
  17001. }
  17002. return gradient.getAttribute('id');
  17003. };
  17004. /**
  17005. * Function: createSvgGradient
  17006. *
  17007. * Creates the given SVG gradient.
  17008. */
  17009. mxSvgCanvas2D.prototype.createSvgGradient = function(start, end, alpha1, alpha2, direction)
  17010. {
  17011. var gradient = this.createElement('linearGradient');
  17012. gradient.setAttribute('x1', '0%');
  17013. gradient.setAttribute('y1', '0%');
  17014. gradient.setAttribute('x2', '0%');
  17015. gradient.setAttribute('y2', '0%');
  17016. if (direction == null || direction == mxConstants.DIRECTION_SOUTH)
  17017. {
  17018. gradient.setAttribute('y2', '100%');
  17019. }
  17020. else if (direction == mxConstants.DIRECTION_EAST)
  17021. {
  17022. gradient.setAttribute('x2', '100%');
  17023. }
  17024. else if (direction == mxConstants.DIRECTION_NORTH)
  17025. {
  17026. gradient.setAttribute('y1', '100%');
  17027. }
  17028. else if (direction == mxConstants.DIRECTION_WEST)
  17029. {
  17030. gradient.setAttribute('x1', '100%');
  17031. }
  17032. var op = (alpha1 < 1) ? ';stop-opacity:' + alpha1 : '';
  17033. var stop = this.createElement('stop');
  17034. stop.setAttribute('offset', '0%');
  17035. stop.setAttribute('style', 'stop-color:' + start + op);
  17036. gradient.appendChild(stop);
  17037. op = (alpha2 < 1) ? ';stop-opacity:' + alpha2 : '';
  17038. stop = this.createElement('stop');
  17039. stop.setAttribute('offset', '100%');
  17040. stop.setAttribute('style', 'stop-color:' + end + op);
  17041. gradient.appendChild(stop);
  17042. return gradient;
  17043. };
  17044. /**
  17045. * Function: addNode
  17046. *
  17047. * Private helper function to create SVG elements
  17048. */
  17049. mxSvgCanvas2D.prototype.addNode = function(filled, stroked)
  17050. {
  17051. var node = this.node;
  17052. var s = this.state;
  17053. if (node != null)
  17054. {
  17055. if (node.nodeName == 'path')
  17056. {
  17057. // Checks if the path is not empty
  17058. if (this.path != null && this.path.length > 0)
  17059. {
  17060. node.setAttribute('d', this.path.join(' '));
  17061. }
  17062. else
  17063. {
  17064. return;
  17065. }
  17066. }
  17067. if (filled && s.fillColor != null)
  17068. {
  17069. this.updateFill();
  17070. }
  17071. else if (!this.styleEnabled)
  17072. {
  17073. // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=814952
  17074. if (node.nodeName == 'ellipse' && mxClient.IS_FF)
  17075. {
  17076. node.setAttribute('fill', 'transparent');
  17077. }
  17078. else
  17079. {
  17080. node.setAttribute('fill', 'none');
  17081. }
  17082. // Sets the actual filled state for stroke tolerance
  17083. filled = false;
  17084. }
  17085. if (stroked && s.strokeColor != null)
  17086. {
  17087. this.updateStroke();
  17088. }
  17089. else if (!this.styleEnabled)
  17090. {
  17091. node.setAttribute('stroke', 'none');
  17092. }
  17093. if (s.transform != null && s.transform.length > 0)
  17094. {
  17095. node.setAttribute('transform', s.transform);
  17096. }
  17097. if (s.shadow)
  17098. {
  17099. this.root.appendChild(this.createShadow(node));
  17100. }
  17101. // Adds stroke tolerance
  17102. if (this.strokeTolerance > 0 && !filled)
  17103. {
  17104. this.root.appendChild(this.createTolerance(node));
  17105. }
  17106. // Adds pointer events
  17107. if (this.pointerEvents)
  17108. {
  17109. node.setAttribute('pointer-events', this.pointerEventsValue);
  17110. }
  17111. // Enables clicks for nodes inside a link element
  17112. else if (!this.pointerEvents && this.originalRoot == null)
  17113. {
  17114. node.setAttribute('pointer-events', 'none');
  17115. }
  17116. // Removes invisible nodes from output if they don't handle events
  17117. if ((node.nodeName != 'rect' && node.nodeName != 'path' && node.nodeName != 'ellipse') ||
  17118. (node.getAttribute('fill') != 'none' && node.getAttribute('fill') != 'transparent') ||
  17119. node.getAttribute('stroke') != 'none' || node.getAttribute('pointer-events') != 'none')
  17120. {
  17121. // LATER: Update existing DOM for performance
  17122. this.root.appendChild(node);
  17123. }
  17124. this.node = null;
  17125. }
  17126. };
  17127. /**
  17128. * Function: updateFill
  17129. *
  17130. * Transfers the stroke attributes from <state> to <node>.
  17131. */
  17132. mxSvgCanvas2D.prototype.updateFill = function()
  17133. {
  17134. var s = this.state;
  17135. if (s.alpha < 1 || s.fillAlpha < 1)
  17136. {
  17137. this.node.setAttribute('fill-opacity', s.alpha * s.fillAlpha);
  17138. }
  17139. if (s.fillColor != null)
  17140. {
  17141. if (s.gradientColor != null)
  17142. {
  17143. var id = this.getSvgGradient(String(s.fillColor), String(s.gradientColor),
  17144. s.gradientFillAlpha, s.gradientAlpha, s.gradientDirection);
  17145. if (!mxClient.IS_CHROMEAPP && !mxClient.IS_IE && !mxClient.IS_IE11 &&
  17146. !mxClient.IS_EDGE && this.root.ownerDocument == document)
  17147. {
  17148. // Workaround for potential base tag and brackets must be escaped
  17149. var base = this.getBaseUrl().replace(/([\(\)])/g, '\\$1');
  17150. this.node.setAttribute('fill', 'url(' + base + '#' + id + ')');
  17151. }
  17152. else
  17153. {
  17154. this.node.setAttribute('fill', 'url(#' + id + ')');
  17155. }
  17156. }
  17157. else
  17158. {
  17159. this.node.setAttribute('fill', String(s.fillColor).toLowerCase());
  17160. }
  17161. }
  17162. };
  17163. /**
  17164. * Function: getCurrentStrokeWidth
  17165. *
  17166. * Returns the current stroke width (>= 1), ie. max(1, this.format(this.state.strokeWidth * this.state.scale)).
  17167. */
  17168. mxSvgCanvas2D.prototype.getCurrentStrokeWidth = function()
  17169. {
  17170. return Math.max(this.minStrokeWidth, Math.max(0.01, this.format(this.state.strokeWidth * this.state.scale)));
  17171. };
  17172. /**
  17173. * Function: updateStroke
  17174. *
  17175. * Transfers the stroke attributes from <state> to <node>.
  17176. */
  17177. mxSvgCanvas2D.prototype.updateStroke = function()
  17178. {
  17179. var s = this.state;
  17180. this.node.setAttribute('stroke', String(s.strokeColor).toLowerCase());
  17181. if (s.alpha < 1 || s.strokeAlpha < 1)
  17182. {
  17183. this.node.setAttribute('stroke-opacity', s.alpha * s.strokeAlpha);
  17184. }
  17185. var sw = this.getCurrentStrokeWidth();
  17186. if (sw != 1)
  17187. {
  17188. this.node.setAttribute('stroke-width', sw);
  17189. }
  17190. if (this.node.nodeName == 'path')
  17191. {
  17192. this.updateStrokeAttributes();
  17193. }
  17194. if (s.dashed)
  17195. {
  17196. this.node.setAttribute('stroke-dasharray', this.createDashPattern(
  17197. ((s.fixDash) ? 1 : s.strokeWidth) * s.scale));
  17198. }
  17199. };
  17200. /**
  17201. * Function: updateStrokeAttributes
  17202. *
  17203. * Transfers the stroke attributes from <state> to <node>.
  17204. */
  17205. mxSvgCanvas2D.prototype.updateStrokeAttributes = function()
  17206. {
  17207. var s = this.state;
  17208. // Linejoin miter is default in SVG
  17209. if (s.lineJoin != null && s.lineJoin != 'miter')
  17210. {
  17211. this.node.setAttribute('stroke-linejoin', s.lineJoin);
  17212. }
  17213. if (s.lineCap != null)
  17214. {
  17215. // flat is called butt in SVG
  17216. var value = s.lineCap;
  17217. if (value == 'flat')
  17218. {
  17219. value = 'butt';
  17220. }
  17221. // Linecap butt is default in SVG
  17222. if (value != 'butt')
  17223. {
  17224. this.node.setAttribute('stroke-linecap', value);
  17225. }
  17226. }
  17227. // Miterlimit 10 is default in our document
  17228. if (s.miterLimit != null && (!this.styleEnabled || s.miterLimit != 10))
  17229. {
  17230. this.node.setAttribute('stroke-miterlimit', s.miterLimit);
  17231. }
  17232. };
  17233. /**
  17234. * Function: createDashPattern
  17235. *
  17236. * Creates the SVG dash pattern for the given state.
  17237. */
  17238. mxSvgCanvas2D.prototype.createDashPattern = function(scale)
  17239. {
  17240. var pat = [];
  17241. if (typeof(this.state.dashPattern) === 'string')
  17242. {
  17243. var dash = this.state.dashPattern.split(' ');
  17244. if (dash.length > 0)
  17245. {
  17246. for (var i = 0; i < dash.length; i++)
  17247. {
  17248. pat[i] = Number(dash[i]) * scale;
  17249. }
  17250. }
  17251. }
  17252. return pat.join(' ');
  17253. };
  17254. /**
  17255. * Function: createTolerance
  17256. *
  17257. * Creates a hit detection tolerance shape for the given node.
  17258. */
  17259. mxSvgCanvas2D.prototype.createTolerance = function(node)
  17260. {
  17261. var tol = node.cloneNode(true);
  17262. var sw = parseFloat(tol.getAttribute('stroke-width') || 1) + this.strokeTolerance;
  17263. tol.setAttribute('pointer-events', 'stroke');
  17264. tol.setAttribute('visibility', 'hidden');
  17265. tol.removeAttribute('stroke-dasharray');
  17266. tol.setAttribute('stroke-width', sw);
  17267. tol.setAttribute('fill', 'none');
  17268. // Workaround for Opera ignoring the visiblity attribute above while
  17269. // other browsers need a stroke color to perform the hit-detection but
  17270. // do not ignore the visibility attribute. Side-effect is that Opera's
  17271. // hit detection for horizontal/vertical edges seems to ignore the tol.
  17272. tol.setAttribute('stroke', (mxClient.IS_OT) ? 'none' : 'white');
  17273. return tol;
  17274. };
  17275. /**
  17276. * Function: createShadow
  17277. *
  17278. * Creates a shadow for the given node.
  17279. */
  17280. mxSvgCanvas2D.prototype.createShadow = function(node)
  17281. {
  17282. var shadow = node.cloneNode(true);
  17283. var s = this.state;
  17284. // Firefox uses transparent for no fill in ellipses
  17285. if (shadow.getAttribute('fill') != 'none' && (!mxClient.IS_FF || shadow.getAttribute('fill') != 'transparent'))
  17286. {
  17287. shadow.setAttribute('fill', s.shadowColor);
  17288. }
  17289. if (shadow.getAttribute('stroke') != 'none')
  17290. {
  17291. shadow.setAttribute('stroke', s.shadowColor);
  17292. }
  17293. shadow.setAttribute('transform', 'translate(' + this.format(s.shadowDx * s.scale) +
  17294. ',' + this.format(s.shadowDy * s.scale) + ')' + (s.transform || ''));
  17295. shadow.setAttribute('opacity', s.shadowAlpha);
  17296. return shadow;
  17297. };
  17298. /**
  17299. * Function: setLink
  17300. *
  17301. * Experimental implementation for hyperlinks.
  17302. */
  17303. mxSvgCanvas2D.prototype.setLink = function(link)
  17304. {
  17305. if (link == null)
  17306. {
  17307. this.root = this.originalRoot;
  17308. }
  17309. else
  17310. {
  17311. this.originalRoot = this.root;
  17312. var node = this.createElement('a');
  17313. // Workaround for implicit namespace handling in HTML5 export, IE adds NS1 namespace so use code below
  17314. // in all IE versions except quirks mode. KNOWN: Adds xlink namespace to each image tag in output.
  17315. if (node.setAttributeNS == null || (this.root.ownerDocument != document && document.documentMode == null))
  17316. {
  17317. node.setAttribute('xlink:href', link);
  17318. }
  17319. else
  17320. {
  17321. node.setAttributeNS(mxConstants.NS_XLINK, 'xlink:href', link);
  17322. }
  17323. this.root.appendChild(node);
  17324. this.root = node;
  17325. }
  17326. };
  17327. /**
  17328. * Function: rotate
  17329. *
  17330. * Sets the rotation of the canvas. Note that rotation cannot be concatenated.
  17331. */
  17332. mxSvgCanvas2D.prototype.rotate = function(theta, flipH, flipV, cx, cy)
  17333. {
  17334. if (theta != 0 || flipH || flipV)
  17335. {
  17336. var s = this.state;
  17337. cx += s.dx;
  17338. cy += s.dy;
  17339. cx *= s.scale;
  17340. cy *= s.scale;
  17341. s.transform = s.transform || '';
  17342. // This implementation uses custom scale/translate and built-in rotation
  17343. // Rotation state is part of the AffineTransform in state.transform
  17344. if (flipH && flipV)
  17345. {
  17346. theta += 180;
  17347. }
  17348. else if (flipH != flipV)
  17349. {
  17350. var tx = (flipH) ? cx : 0;
  17351. var sx = (flipH) ? -1 : 1;
  17352. var ty = (flipV) ? cy : 0;
  17353. var sy = (flipV) ? -1 : 1;
  17354. s.transform += 'translate(' + this.format(tx) + ',' + this.format(ty) + ')' +
  17355. 'scale(' + this.format(sx) + ',' + this.format(sy) + ')' +
  17356. 'translate(' + this.format(-tx) + ',' + this.format(-ty) + ')';
  17357. }
  17358. if (flipH ? !flipV : flipV)
  17359. {
  17360. theta *= -1;
  17361. }
  17362. if (theta != 0)
  17363. {
  17364. s.transform += 'rotate(' + this.format(theta) + ',' + this.format(cx) + ',' + this.format(cy) + ')';
  17365. }
  17366. s.rotation = s.rotation + theta;
  17367. s.rotationCx = cx;
  17368. s.rotationCy = cy;
  17369. }
  17370. };
  17371. /**
  17372. * Function: begin
  17373. *
  17374. * Extends superclass to create path.
  17375. */
  17376. mxSvgCanvas2D.prototype.begin = function()
  17377. {
  17378. mxAbstractCanvas2D.prototype.begin.apply(this, arguments);
  17379. this.node = this.createElement('path');
  17380. };
  17381. /**
  17382. * Function: rect
  17383. *
  17384. * Private helper function to create SVG elements
  17385. */
  17386. mxSvgCanvas2D.prototype.rect = function(x, y, w, h)
  17387. {
  17388. var s = this.state;
  17389. var n = this.createElement('rect');
  17390. n.setAttribute('x', this.format((x + s.dx) * s.scale));
  17391. n.setAttribute('y', this.format((y + s.dy) * s.scale));
  17392. n.setAttribute('width', this.format(w * s.scale));
  17393. n.setAttribute('height', this.format(h * s.scale));
  17394. this.node = n;
  17395. };
  17396. /**
  17397. * Function: roundrect
  17398. *
  17399. * Private helper function to create SVG elements
  17400. */
  17401. mxSvgCanvas2D.prototype.roundrect = function(x, y, w, h, dx, dy)
  17402. {
  17403. this.rect(x, y, w, h);
  17404. if (dx > 0)
  17405. {
  17406. this.node.setAttribute('rx', this.format(dx * this.state.scale));
  17407. }
  17408. if (dy > 0)
  17409. {
  17410. this.node.setAttribute('ry', this.format(dy * this.state.scale));
  17411. }
  17412. };
  17413. /**
  17414. * Function: ellipse
  17415. *
  17416. * Private helper function to create SVG elements
  17417. */
  17418. mxSvgCanvas2D.prototype.ellipse = function(x, y, w, h)
  17419. {
  17420. var s = this.state;
  17421. var n = this.createElement('ellipse');
  17422. // No rounding for consistent output with 1.x
  17423. n.setAttribute('cx', this.format((x + w / 2 + s.dx) * s.scale));
  17424. n.setAttribute('cy', this.format((y + h / 2 + s.dy) * s.scale));
  17425. n.setAttribute('rx', w / 2 * s.scale);
  17426. n.setAttribute('ry', h / 2 * s.scale);
  17427. this.node = n;
  17428. };
  17429. /**
  17430. * Function: image
  17431. *
  17432. * Private helper function to create SVG elements
  17433. */
  17434. mxSvgCanvas2D.prototype.image = function(x, y, w, h, src, aspect, flipH, flipV)
  17435. {
  17436. src = this.converter.convert(src);
  17437. // LATER: Add option for embedding images as base64.
  17438. aspect = (aspect != null) ? aspect : true;
  17439. flipH = (flipH != null) ? flipH : false;
  17440. flipV = (flipV != null) ? flipV : false;
  17441. var s = this.state;
  17442. x += s.dx;
  17443. y += s.dy;
  17444. var node = this.createElement('image');
  17445. node.setAttribute('x', this.format(x * s.scale) + this.imageOffset);
  17446. node.setAttribute('y', this.format(y * s.scale) + this.imageOffset);
  17447. node.setAttribute('width', this.format(w * s.scale));
  17448. node.setAttribute('height', this.format(h * s.scale));
  17449. // Workaround for missing namespace support
  17450. if (node.setAttributeNS == null)
  17451. {
  17452. node.setAttribute('xlink:href', src);
  17453. }
  17454. else
  17455. {
  17456. node.setAttributeNS(mxConstants.NS_XLINK, 'xlink:href', src);
  17457. }
  17458. if (!aspect)
  17459. {
  17460. node.setAttribute('preserveAspectRatio', 'none');
  17461. }
  17462. if (s.alpha < 1 || s.fillAlpha < 1)
  17463. {
  17464. node.setAttribute('opacity', s.alpha * s.fillAlpha);
  17465. }
  17466. var tr = this.state.transform || '';
  17467. if (flipH || flipV)
  17468. {
  17469. var sx = 1;
  17470. var sy = 1;
  17471. var dx = 0;
  17472. var dy = 0;
  17473. if (flipH)
  17474. {
  17475. sx = -1;
  17476. dx = -w - 2 * x;
  17477. }
  17478. if (flipV)
  17479. {
  17480. sy = -1;
  17481. dy = -h - 2 * y;
  17482. }
  17483. // Adds image tansformation to existing transform
  17484. tr += 'scale(' + sx + ',' + sy + ')translate(' + (dx * s.scale) + ',' + (dy * s.scale) + ')';
  17485. }
  17486. if (tr.length > 0)
  17487. {
  17488. node.setAttribute('transform', tr);
  17489. }
  17490. if (!this.pointerEvents)
  17491. {
  17492. node.setAttribute('pointer-events', 'none');
  17493. }
  17494. this.root.appendChild(node);
  17495. };
  17496. /**
  17497. * Function: convertHtml
  17498. *
  17499. * Converts the given HTML string to XHTML.
  17500. */
  17501. mxSvgCanvas2D.prototype.convertHtml = function(val)
  17502. {
  17503. if (this.useDomParser)
  17504. {
  17505. var doc = new DOMParser().parseFromString(val, 'text/html');
  17506. if (doc != null)
  17507. {
  17508. val = new XMLSerializer().serializeToString(doc.body);
  17509. // Extracts body content from DOM
  17510. if (val.substring(0, 5) == '<body')
  17511. {
  17512. val = val.substring(val.indexOf('>', 5) + 1);
  17513. }
  17514. if (val.substring(val.length - 7, val.length) == '</body>')
  17515. {
  17516. val = val.substring(0, val.length - 7);
  17517. }
  17518. }
  17519. }
  17520. else if (document.implementation != null && document.implementation.createDocument != null)
  17521. {
  17522. var xd = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
  17523. var xb = xd.createElement('body');
  17524. xd.documentElement.appendChild(xb);
  17525. var div = document.createElement('div');
  17526. div.innerHTML = val;
  17527. var child = div.firstChild;
  17528. while (child != null)
  17529. {
  17530. var next = child.nextSibling;
  17531. xb.appendChild(xd.adoptNode(child));
  17532. child = next;
  17533. }
  17534. return xb.innerHTML;
  17535. }
  17536. else
  17537. {
  17538. var ta = document.createElement('textarea');
  17539. // Handles special HTML entities < and > and double escaping
  17540. // and converts unclosed br, hr and img tags to XHTML
  17541. // LATER: Convert all unclosed tags
  17542. ta.innerHTML = val.replace(/&amp;/g, '&amp;amp;').
  17543. replace(/&#60;/g, '&amp;lt;').replace(/&#62;/g, '&amp;gt;').
  17544. replace(/&lt;/g, '&amp;lt;').replace(/&gt;/g, '&amp;gt;').
  17545. replace(/</g, '&lt;').replace(/>/g, '&gt;');
  17546. val = ta.value.replace(/&/g, '&amp;').replace(/&amp;lt;/g, '&lt;').
  17547. replace(/&amp;gt;/g, '&gt;').replace(/&amp;amp;/g, '&amp;').
  17548. replace(/<br>/g, '<br />').replace(/<hr>/g, '<hr />').
  17549. replace(/(<img[^>]+)>/gm, "$1 />");
  17550. }
  17551. return val;
  17552. };
  17553. /**
  17554. * Function: createDiv
  17555. *
  17556. * Private helper function to create SVG elements
  17557. */
  17558. mxSvgCanvas2D.prototype.createDiv = function(str)
  17559. {
  17560. var val = str;
  17561. if (!mxUtils.isNode(val))
  17562. {
  17563. val = '<div><div>' + this.convertHtml(val) + '</div></div>';
  17564. }
  17565. // IE uses this code for export as it cannot render foreignObjects
  17566. if (!mxClient.IS_IE && !mxClient.IS_IE11 && document.createElementNS)
  17567. {
  17568. var div = document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
  17569. if (mxUtils.isNode(val))
  17570. {
  17571. var div2 = document.createElement('div');
  17572. var div3 = div2.cloneNode(false);
  17573. // Creates a copy for export
  17574. if (this.root.ownerDocument != document)
  17575. {
  17576. div2.appendChild(val.cloneNode(true));
  17577. }
  17578. else
  17579. {
  17580. div2.appendChild(val);
  17581. }
  17582. div3.appendChild(div2);
  17583. div.appendChild(div3);
  17584. }
  17585. else
  17586. {
  17587. div.innerHTML = val;
  17588. }
  17589. return div;
  17590. }
  17591. else
  17592. {
  17593. if (mxUtils.isNode(val))
  17594. {
  17595. val = '<div><div>' + mxUtils.getXml(val) + '</div></div>';
  17596. }
  17597. val = '<div xmlns="http://www.w3.org/1999/xhtml">' + val + '</div>';
  17598. // NOTE: FF 3.6 crashes if content CSS contains "height:100%"
  17599. return mxUtils.parseXml(val).documentElement;
  17600. }
  17601. };
  17602. /**
  17603. * Updates existing DOM nodes for text rendering. LATER: Merge common parts with text function below.
  17604. */
  17605. mxSvgCanvas2D.prototype.updateText = function(x, y, w, h, align, valign, wrap, overflow, clip, rotation, node)
  17606. {
  17607. if (node != null && node.firstChild != null && node.firstChild.firstChild != null)
  17608. {
  17609. this.updateTextNodes(x, y, w, h, align, valign, wrap, overflow, clip, rotation, node.firstChild);
  17610. }
  17611. };
  17612. /**
  17613. * Function: addForeignObject
  17614. *
  17615. * Creates a foreignObject for the given string and adds it to the given root.
  17616. */
  17617. mxSvgCanvas2D.prototype.addForeignObject = function(x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation, dir, div, root)
  17618. {
  17619. var group = this.createElement('g');
  17620. var fo = this.createElement('foreignObject');
  17621. // Workarounds for print clipping and static position in Safari
  17622. fo.setAttribute('style', 'overflow: visible; text-align: left;');
  17623. fo.setAttribute('pointer-events', 'none');
  17624. // Import needed for older versions of IE
  17625. if (div.ownerDocument != document)
  17626. {
  17627. div = mxUtils.importNodeImplementation(fo.ownerDocument, div, true);
  17628. }
  17629. fo.appendChild(div);
  17630. group.appendChild(fo);
  17631. this.updateTextNodes(x, y, w, h, align, valign, wrap, overflow, clip, rotation, group);
  17632. // Alternate content if foreignObject not supported
  17633. if (this.root.ownerDocument != document)
  17634. {
  17635. var alt = this.createAlternateContent(fo, x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation);
  17636. if (alt != null)
  17637. {
  17638. fo.setAttribute('requiredFeatures', 'http://www.w3.org/TR/SVG11/feature#Extensibility');
  17639. var sw = this.createElement('switch');
  17640. sw.appendChild(fo);
  17641. sw.appendChild(alt);
  17642. group.appendChild(sw);
  17643. }
  17644. }
  17645. root.appendChild(group);
  17646. };
  17647. /**
  17648. * Updates existing DOM nodes for text rendering.
  17649. */
  17650. mxSvgCanvas2D.prototype.updateTextNodes = function(x, y, w, h, align, valign, wrap, overflow, clip, rotation, g)
  17651. {
  17652. var s = this.state.scale;
  17653. mxSvgCanvas2D.createCss(w + 2, h, align, valign, wrap, overflow, clip,
  17654. (this.state.fontBackgroundColor != null) ? this.state.fontBackgroundColor : null,
  17655. (this.state.fontBorderColor != null) ? this.state.fontBorderColor : null,
  17656. 'display: flex; align-items: unsafe ' +
  17657. ((valign == mxConstants.ALIGN_TOP) ? 'flex-start' :
  17658. ((valign == mxConstants.ALIGN_BOTTOM) ? 'flex-end' : 'center')) + '; ' +
  17659. 'justify-content: unsafe ' + ((align == mxConstants.ALIGN_LEFT) ? 'flex-start' :
  17660. ((align == mxConstants.ALIGN_RIGHT) ? 'flex-end' : 'center')) + '; ',
  17661. this.getTextCss(), s, mxUtils.bind(this, function(dx, dy, flex, item, block)
  17662. {
  17663. x += this.state.dx;
  17664. y += this.state.dy;
  17665. var fo = g.firstChild;
  17666. var div = fo.firstChild;
  17667. var box = div.firstChild;
  17668. var text = box.firstChild;
  17669. var r = ((this.rotateHtml) ? this.state.rotation : 0) + ((rotation != null) ? rotation : 0);
  17670. var t = ((this.foOffset != 0) ? 'translate(' + this.foOffset + ' ' + this.foOffset + ')' : '') +
  17671. ((s != 1) ? 'scale(' + s + ')' : '');
  17672. text.setAttribute('style', block);
  17673. box.setAttribute('style', item);
  17674. // Workaround for clipping in Webkit with scrolling and zoom
  17675. fo.setAttribute('width', Math.ceil(1 / Math.min(1, s) * 100) + '%');
  17676. fo.setAttribute('height', Math.ceil(1 / Math.min(1, s) * 100) + '%');
  17677. var yp = Math.round(y + dy);
  17678. // Allows for negative values which are causing problems with
  17679. // transformed content where the top edge of the foreignObject
  17680. // limits the text box being moved further up in the diagram.
  17681. // KNOWN: Possible clipping problems with zoom and scrolling
  17682. // but this is normally not used with scrollbars as the
  17683. // coordinates are always positive with scrollbars.
  17684. // Margin-top is ignored in Safari and no negative values allowed
  17685. // for padding.
  17686. if (yp < 0)
  17687. {
  17688. fo.setAttribute('y', yp);
  17689. }
  17690. else
  17691. {
  17692. fo.removeAttribute('y');
  17693. flex += 'padding-top: ' + yp + 'px; ';
  17694. }
  17695. div.setAttribute('style', flex + 'margin-left: ' + Math.round(x + dx) + 'px;');
  17696. t += ((r != 0) ? ('rotate(' + r + ' ' + x + ' ' + y + ')') : '');
  17697. // Output allows for reflow but Safari cannot use absolute position,
  17698. // transforms or opacity. https://bugs.webkit.org/show_bug.cgi?id=23113
  17699. if (t != '')
  17700. {
  17701. g.setAttribute('transform', t);
  17702. }
  17703. else
  17704. {
  17705. g.removeAttribute('transform');
  17706. }
  17707. if (this.state.alpha != 1)
  17708. {
  17709. g.setAttribute('opacity', this.state.alpha);
  17710. }
  17711. else
  17712. {
  17713. g.removeAttribute('opacity');
  17714. }
  17715. }));
  17716. };
  17717. /**
  17718. * Updates existing DOM nodes for text rendering.
  17719. */
  17720. mxSvgCanvas2D.createCss = function(w, h, align, valign, wrap, overflow, clip, bg, border, flex, block, s, callback)
  17721. {
  17722. var item = 'box-sizing: border-box; font-size: 0; text-align: ' + ((align == mxConstants.ALIGN_LEFT) ? 'left' :
  17723. ((align == mxConstants.ALIGN_RIGHT) ? 'right' : 'center')) + '; ';
  17724. var pt = mxUtils.getAlignmentAsPoint(align, valign);
  17725. var ofl = 'overflow: hidden; ';
  17726. var fw = 'width: 1px; ';
  17727. var fh = 'height: 1px; ';
  17728. var dx = pt.x * w;
  17729. var dy = pt.y * h;
  17730. if (clip)
  17731. {
  17732. fw = 'width: ' + Math.round(w) + 'px; ';
  17733. item += 'max-height: ' + Math.round(h) + 'px; ';
  17734. dy = 0;
  17735. }
  17736. else if (overflow == 'fill')
  17737. {
  17738. fw = 'width: ' + Math.round(w) + 'px; ';
  17739. fh = 'height: ' + Math.round(h) + 'px; ';
  17740. block += 'width: 100%; height: 100%; ';
  17741. item += fw + fh;
  17742. }
  17743. else if (overflow == 'width')
  17744. {
  17745. fw = 'width: ' + Math.round(w) + 'px; ';
  17746. block += 'width: 100%; ';
  17747. item += fw;
  17748. dy = 0;
  17749. if (h > 0)
  17750. {
  17751. item += 'max-height: ' + Math.round(h) + 'px; ';
  17752. }
  17753. }
  17754. else
  17755. {
  17756. ofl = '';
  17757. dy = 0;
  17758. }
  17759. var bgc = '';
  17760. if (bg != null)
  17761. {
  17762. bgc += 'background-color: ' + bg + '; ';
  17763. }
  17764. if (border != null)
  17765. {
  17766. bgc += 'border: 1px solid ' + border + '; ';
  17767. }
  17768. if (ofl == '' || clip)
  17769. {
  17770. block += bgc;
  17771. }
  17772. else
  17773. {
  17774. item += bgc;
  17775. }
  17776. if (wrap && w > 0)
  17777. {
  17778. block += 'white-space: normal; word-wrap: ' + mxConstants.WORD_WRAP + '; ';
  17779. fw = 'width: ' + Math.round(w) + 'px; ';
  17780. if (ofl != '' && overflow != 'fill')
  17781. {
  17782. dy = 0;
  17783. }
  17784. }
  17785. else
  17786. {
  17787. block += 'white-space: nowrap; ';
  17788. if (ofl == '')
  17789. {
  17790. dx = 0;
  17791. }
  17792. }
  17793. callback(dx, dy, flex + fw + fh, item + ofl, block, ofl);
  17794. };
  17795. /**
  17796. * Function: getTextCss
  17797. *
  17798. * Private helper function to create SVG elements
  17799. */
  17800. mxSvgCanvas2D.prototype.getTextCss = function()
  17801. {
  17802. var s = this.state;
  17803. var lh = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? (s.fontSize * mxConstants.LINE_HEIGHT) + 'px' :
  17804. (mxConstants.LINE_HEIGHT * this.lineHeightCorrection);
  17805. var css = 'display: inline-block; font-size: ' + s.fontSize + 'px; ' +
  17806. 'font-family: ' + s.fontFamily + '; color: ' + s.fontColor + '; line-height: ' + lh +
  17807. '; pointer-events: ' + ((this.pointerEvents) ? this.pointerEventsValue : 'none') + '; ';
  17808. if ((s.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  17809. {
  17810. css += 'font-weight: bold; ';
  17811. }
  17812. if ((s.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  17813. {
  17814. css += 'font-style: italic; ';
  17815. }
  17816. var deco = [];
  17817. if ((s.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  17818. {
  17819. deco.push('underline');
  17820. }
  17821. if ((s.fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  17822. {
  17823. deco.push('line-through');
  17824. }
  17825. if (deco.length > 0)
  17826. {
  17827. css += 'text-decoration: ' + deco.join(' ') + '; ';
  17828. }
  17829. return css;
  17830. };
  17831. /**
  17832. * Function: text
  17833. *
  17834. * Paints the given text. Possible values for format are empty string for plain
  17835. * text and html for HTML markup. Note that HTML markup is only supported if
  17836. * foreignObject is supported and <foEnabled> is true. (This means IE9 and later
  17837. * does currently not support HTML text as part of shapes.)
  17838. */
  17839. mxSvgCanvas2D.prototype.text = function(x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation, dir)
  17840. {
  17841. if (this.textEnabled && str != null)
  17842. {
  17843. rotation = (rotation != null) ? rotation : 0;
  17844. if (this.foEnabled && format == 'html')
  17845. {
  17846. var div = this.createDiv(str);
  17847. // Ignores invalid XHTML labels
  17848. if (div != null)
  17849. {
  17850. if (dir != null)
  17851. {
  17852. div.setAttribute('dir', dir);
  17853. }
  17854. this.addForeignObject(x, y, w, h, str, align, valign, wrap,
  17855. format, overflow, clip, rotation, dir, div, this.root);
  17856. }
  17857. }
  17858. else
  17859. {
  17860. this.plainText(x + this.state.dx, y + this.state.dy, w, h, str,
  17861. align, valign, wrap, overflow, clip, rotation, dir);
  17862. }
  17863. }
  17864. };
  17865. /**
  17866. * Function: createClip
  17867. *
  17868. * Creates a clip for the given coordinates.
  17869. */
  17870. mxSvgCanvas2D.prototype.createClip = function(x, y, w, h)
  17871. {
  17872. x = Math.round(x);
  17873. y = Math.round(y);
  17874. w = Math.round(w);
  17875. h = Math.round(h);
  17876. var id = 'mx-clip-' + x + '-' + y + '-' + w + '-' + h;
  17877. var counter = 0;
  17878. var tmp = id + '-' + counter;
  17879. // Resolves ID conflicts
  17880. while (document.getElementById(tmp) != null)
  17881. {
  17882. tmp = id + '-' + (++counter);
  17883. }
  17884. clip = this.createElement('clipPath');
  17885. clip.setAttribute('id', tmp);
  17886. var rect = this.createElement('rect');
  17887. rect.setAttribute('x', x);
  17888. rect.setAttribute('y', y);
  17889. rect.setAttribute('width', w);
  17890. rect.setAttribute('height', h);
  17891. clip.appendChild(rect);
  17892. return clip;
  17893. };
  17894. /**
  17895. * Function: text
  17896. *
  17897. * Paints the given text. Possible values for format are empty string for
  17898. * plain text and html for HTML markup.
  17899. */
  17900. mxSvgCanvas2D.prototype.plainText = function(x, y, w, h, str, align, valign, wrap, overflow, clip, rotation, dir)
  17901. {
  17902. rotation = (rotation != null) ? rotation : 0;
  17903. var s = this.state;
  17904. var size = s.fontSize;
  17905. var node = this.createElement('g');
  17906. var tr = s.transform || '';
  17907. this.updateFont(node);
  17908. // Non-rotated text
  17909. if (rotation != 0)
  17910. {
  17911. tr += 'rotate(' + rotation + ',' + this.format(x * s.scale) + ',' + this.format(y * s.scale) + ')';
  17912. }
  17913. if (dir != null)
  17914. {
  17915. node.setAttribute('direction', dir);
  17916. }
  17917. if (clip && w > 0 && h > 0)
  17918. {
  17919. var cx = x;
  17920. var cy = y;
  17921. if (align == mxConstants.ALIGN_CENTER)
  17922. {
  17923. cx -= w / 2;
  17924. }
  17925. else if (align == mxConstants.ALIGN_RIGHT)
  17926. {
  17927. cx -= w;
  17928. }
  17929. if (overflow != 'fill')
  17930. {
  17931. if (valign == mxConstants.ALIGN_MIDDLE)
  17932. {
  17933. cy -= h / 2;
  17934. }
  17935. else if (valign == mxConstants.ALIGN_BOTTOM)
  17936. {
  17937. cy -= h;
  17938. }
  17939. }
  17940. // LATER: Remove spacing from clip rectangle
  17941. var c = this.createClip(cx * s.scale - 2, cy * s.scale - 2, w * s.scale + 4, h * s.scale + 4);
  17942. if (this.defs != null)
  17943. {
  17944. this.defs.appendChild(c);
  17945. }
  17946. else
  17947. {
  17948. // Makes sure clip is removed with referencing node
  17949. this.root.appendChild(c);
  17950. }
  17951. if (!mxClient.IS_CHROMEAPP && !mxClient.IS_IE && !mxClient.IS_IE11 &&
  17952. !mxClient.IS_EDGE && this.root.ownerDocument == document)
  17953. {
  17954. // Workaround for potential base tag
  17955. var base = this.getBaseUrl().replace(/([\(\)])/g, '\\$1');
  17956. node.setAttribute('clip-path', 'url(' + base + '#' + c.getAttribute('id') + ')');
  17957. }
  17958. else
  17959. {
  17960. node.setAttribute('clip-path', 'url(#' + c.getAttribute('id') + ')');
  17961. }
  17962. }
  17963. // Default is left
  17964. var anchor = (align == mxConstants.ALIGN_RIGHT) ? 'end' :
  17965. (align == mxConstants.ALIGN_CENTER) ? 'middle' :
  17966. 'start';
  17967. // Text-anchor start is default in SVG
  17968. if (anchor != 'start')
  17969. {
  17970. node.setAttribute('text-anchor', anchor);
  17971. }
  17972. if (!this.styleEnabled || size != mxConstants.DEFAULT_FONTSIZE)
  17973. {
  17974. node.setAttribute('font-size', (size * s.scale) + 'px');
  17975. }
  17976. if (tr.length > 0)
  17977. {
  17978. node.setAttribute('transform', tr);
  17979. }
  17980. if (s.alpha < 1)
  17981. {
  17982. node.setAttribute('opacity', s.alpha);
  17983. }
  17984. var lines = str.split('\n');
  17985. var lh = Math.round(size * mxConstants.LINE_HEIGHT);
  17986. var textHeight = size + (lines.length - 1) * lh;
  17987. var cy = y + size - 1;
  17988. if (valign == mxConstants.ALIGN_MIDDLE)
  17989. {
  17990. if (overflow == 'fill')
  17991. {
  17992. cy -= h / 2;
  17993. }
  17994. else
  17995. {
  17996. var dy = ((this.matchHtmlAlignment && clip && h > 0) ? Math.min(textHeight, h) : textHeight) / 2;
  17997. cy -= dy;
  17998. }
  17999. }
  18000. else if (valign == mxConstants.ALIGN_BOTTOM)
  18001. {
  18002. if (overflow == 'fill')
  18003. {
  18004. cy -= h;
  18005. }
  18006. else
  18007. {
  18008. var dy = (this.matchHtmlAlignment && clip && h > 0) ? Math.min(textHeight, h) : textHeight;
  18009. cy -= dy + 1;
  18010. }
  18011. }
  18012. for (var i = 0; i < lines.length; i++)
  18013. {
  18014. // Workaround for bounding box of empty lines and spaces
  18015. if (lines[i].length > 0 && mxUtils.trim(lines[i]).length > 0)
  18016. {
  18017. var text = this.createElement('text');
  18018. // LATER: Match horizontal HTML alignment
  18019. text.setAttribute('x', this.format(x * s.scale) + this.textOffset);
  18020. text.setAttribute('y', this.format(cy * s.scale) + this.textOffset);
  18021. mxUtils.write(text, lines[i]);
  18022. node.appendChild(text);
  18023. }
  18024. cy += lh;
  18025. }
  18026. this.root.appendChild(node);
  18027. this.addTextBackground(node, str, x, y, w, (overflow == 'fill') ? h : textHeight, align, valign, overflow);
  18028. };
  18029. /**
  18030. * Function: updateFont
  18031. *
  18032. * Updates the text properties for the given node. (NOTE: For this to work in
  18033. * IE, the given node must be a text or tspan element.)
  18034. */
  18035. mxSvgCanvas2D.prototype.updateFont = function(node)
  18036. {
  18037. var s = this.state;
  18038. node.setAttribute('fill', s.fontColor);
  18039. if (!this.styleEnabled || s.fontFamily != mxConstants.DEFAULT_FONTFAMILY)
  18040. {
  18041. node.setAttribute('font-family', s.fontFamily);
  18042. }
  18043. if ((s.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  18044. {
  18045. node.setAttribute('font-weight', 'bold');
  18046. }
  18047. if ((s.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  18048. {
  18049. node.setAttribute('font-style', 'italic');
  18050. }
  18051. var txtDecor = [];
  18052. if ((s.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  18053. {
  18054. txtDecor.push('underline');
  18055. }
  18056. if ((s.fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  18057. {
  18058. txtDecor.push('line-through');
  18059. }
  18060. if (txtDecor.length > 0)
  18061. {
  18062. node.setAttribute('text-decoration', txtDecor.join(' '));
  18063. }
  18064. };
  18065. /**
  18066. * Function: addTextBackground
  18067. *
  18068. * Background color and border
  18069. */
  18070. mxSvgCanvas2D.prototype.addTextBackground = function(node, str, x, y, w, h, align, valign, overflow)
  18071. {
  18072. var s = this.state;
  18073. if (s.fontBackgroundColor != null || s.fontBorderColor != null)
  18074. {
  18075. var bbox = null;
  18076. if (overflow == 'fill' || overflow == 'width')
  18077. {
  18078. if (align == mxConstants.ALIGN_CENTER)
  18079. {
  18080. x -= w / 2;
  18081. }
  18082. else if (align == mxConstants.ALIGN_RIGHT)
  18083. {
  18084. x -= w;
  18085. }
  18086. if (valign == mxConstants.ALIGN_MIDDLE)
  18087. {
  18088. y -= h / 2;
  18089. }
  18090. else if (valign == mxConstants.ALIGN_BOTTOM)
  18091. {
  18092. y -= h;
  18093. }
  18094. bbox = new mxRectangle((x + 1) * s.scale, y * s.scale, (w - 2) * s.scale, (h + 2) * s.scale);
  18095. }
  18096. else if (node.getBBox != null && this.root.ownerDocument == document)
  18097. {
  18098. // Uses getBBox only if inside document for correct size
  18099. try
  18100. {
  18101. bbox = node.getBBox();
  18102. var ie = mxClient.IS_IE && mxClient.IS_SVG;
  18103. bbox = new mxRectangle(bbox.x, bbox.y + ((ie) ? 0 : 1), bbox.width, bbox.height + ((ie) ? 1 : 0));
  18104. }
  18105. catch (e)
  18106. {
  18107. // Ignores NS_ERROR_FAILURE in FF if container display is none.
  18108. }
  18109. }
  18110. else
  18111. {
  18112. // Computes size if not in document or no getBBox available
  18113. var div = document.createElement('div');
  18114. // Wrapping and clipping can be ignored here
  18115. div.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? (s.fontSize * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  18116. div.style.fontSize = s.fontSize + 'px';
  18117. div.style.fontFamily = s.fontFamily;
  18118. div.style.whiteSpace = 'nowrap';
  18119. div.style.position = 'absolute';
  18120. div.style.visibility = 'hidden';
  18121. div.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  18122. div.style.zoom = '1';
  18123. if ((s.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  18124. {
  18125. div.style.fontWeight = 'bold';
  18126. }
  18127. if ((s.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  18128. {
  18129. div.style.fontStyle = 'italic';
  18130. }
  18131. str = mxUtils.htmlEntities(str, false);
  18132. div.innerHTML = str.replace(/\n/g, '<br/>');
  18133. document.body.appendChild(div);
  18134. var w = div.offsetWidth;
  18135. var h = div.offsetHeight;
  18136. div.parentNode.removeChild(div);
  18137. if (align == mxConstants.ALIGN_CENTER)
  18138. {
  18139. x -= w / 2;
  18140. }
  18141. else if (align == mxConstants.ALIGN_RIGHT)
  18142. {
  18143. x -= w;
  18144. }
  18145. if (valign == mxConstants.ALIGN_MIDDLE)
  18146. {
  18147. y -= h / 2;
  18148. }
  18149. else if (valign == mxConstants.ALIGN_BOTTOM)
  18150. {
  18151. y -= h;
  18152. }
  18153. bbox = new mxRectangle((x + 1) * s.scale, (y + 2) * s.scale, w * s.scale, (h + 1) * s.scale);
  18154. }
  18155. if (bbox != null)
  18156. {
  18157. var n = this.createElement('rect');
  18158. n.setAttribute('fill', s.fontBackgroundColor || 'none');
  18159. n.setAttribute('stroke', s.fontBorderColor || 'none');
  18160. n.setAttribute('x', Math.floor(bbox.x - 1));
  18161. n.setAttribute('y', Math.floor(bbox.y - 1));
  18162. n.setAttribute('width', Math.ceil(bbox.width + 2));
  18163. n.setAttribute('height', Math.ceil(bbox.height));
  18164. var sw = (s.fontBorderColor != null) ? Math.max(1, this.format(s.scale)) : 0;
  18165. n.setAttribute('stroke-width', sw);
  18166. // Workaround for crisp rendering - only required if not exporting
  18167. if (this.root.ownerDocument == document && mxUtils.mod(sw, 2) == 1)
  18168. {
  18169. n.setAttribute('transform', 'translate(0.5, 0.5)');
  18170. }
  18171. node.insertBefore(n, node.firstChild);
  18172. }
  18173. }
  18174. };
  18175. /**
  18176. * Function: stroke
  18177. *
  18178. * Paints the outline of the current path.
  18179. */
  18180. mxSvgCanvas2D.prototype.stroke = function()
  18181. {
  18182. this.addNode(false, true);
  18183. };
  18184. /**
  18185. * Function: fill
  18186. *
  18187. * Fills the current path.
  18188. */
  18189. mxSvgCanvas2D.prototype.fill = function()
  18190. {
  18191. this.addNode(true, false);
  18192. };
  18193. /**
  18194. * Function: fillAndStroke
  18195. *
  18196. * Fills and paints the outline of the current path.
  18197. */
  18198. mxSvgCanvas2D.prototype.fillAndStroke = function()
  18199. {
  18200. this.addNode(true, true);
  18201. };
  18202. /**
  18203. * Copyright (c) 2006-2015, JGraph Ltd
  18204. * Copyright (c) 2006-2015, Gaudenz Alder
  18205. */
  18206. /**
  18207. *
  18208. * Class: mxVmlCanvas2D
  18209. *
  18210. * Implements a canvas to be used for rendering VML. Here is an example of implementing a
  18211. * fallback for SVG images which are not supported in VML-based browsers.
  18212. *
  18213. * (code)
  18214. * var mxVmlCanvas2DImage = mxVmlCanvas2D.prototype.image;
  18215. * mxVmlCanvas2D.prototype.image = function(x, y, w, h, src, aspect, flipH, flipV)
  18216. * {
  18217. * if (src.substring(src.length - 4, src.length) == '.svg')
  18218. * {
  18219. * src = 'http://www.jgraph.com/images/mxgraph.gif';
  18220. * }
  18221. *
  18222. * mxVmlCanvas2DImage.apply(this, arguments);
  18223. * };
  18224. * (end)
  18225. *
  18226. * To disable anti-aliasing in the output, use the following code.
  18227. *
  18228. * (code)
  18229. * document.createStyleSheet().cssText = mxClient.VML_PREFIX + '\\:*{antialias:false;)}';
  18230. * (end)
  18231. *
  18232. * A description of the public API is available in <mxXmlCanvas2D>. Note that
  18233. * there is a known issue in VML where gradients are painted using the outer
  18234. * bounding box of rotated shapes, not the actual bounds of the shape. See
  18235. * also <text> for plain text label restrictions in shapes for VML.
  18236. */
  18237. var mxVmlCanvas2D = function(root)
  18238. {
  18239. mxAbstractCanvas2D.call(this);
  18240. /**
  18241. * Variable: root
  18242. *
  18243. * Reference to the container for the SVG content.
  18244. */
  18245. this.root = root;
  18246. };
  18247. /**
  18248. * Extends mxAbstractCanvas2D
  18249. */
  18250. mxUtils.extend(mxVmlCanvas2D, mxAbstractCanvas2D);
  18251. /**
  18252. * Variable: path
  18253. *
  18254. * Holds the current DOM node.
  18255. */
  18256. mxVmlCanvas2D.prototype.node = null;
  18257. /**
  18258. * Variable: textEnabled
  18259. *
  18260. * Specifies if text output should be enabledetB. Default is true.
  18261. */
  18262. mxVmlCanvas2D.prototype.textEnabled = true;
  18263. /**
  18264. * Variable: moveOp
  18265. *
  18266. * Contains the string used for moving in paths. Default is 'm'.
  18267. */
  18268. mxVmlCanvas2D.prototype.moveOp = 'm';
  18269. /**
  18270. * Variable: lineOp
  18271. *
  18272. * Contains the string used for moving in paths. Default is 'l'.
  18273. */
  18274. mxVmlCanvas2D.prototype.lineOp = 'l';
  18275. /**
  18276. * Variable: curveOp
  18277. *
  18278. * Contains the string used for bezier curves. Default is 'c'.
  18279. */
  18280. mxVmlCanvas2D.prototype.curveOp = 'c';
  18281. /**
  18282. * Variable: closeOp
  18283. *
  18284. * Holds the operator for closing curves. Default is 'x e'.
  18285. */
  18286. mxVmlCanvas2D.prototype.closeOp = 'x';
  18287. /**
  18288. * Variable: rotatedHtmlBackground
  18289. *
  18290. * Background color for rotated HTML. Default is ''. This can be set to eg.
  18291. * white to improve rendering of rotated text in VML for IE9.
  18292. */
  18293. mxVmlCanvas2D.prototype.rotatedHtmlBackground = '';
  18294. /**
  18295. * Variable: vmlScale
  18296. *
  18297. * Specifies the scale used to draw VML shapes.
  18298. */
  18299. mxVmlCanvas2D.prototype.vmlScale = 1;
  18300. /**
  18301. * Function: createElement
  18302. *
  18303. * Creates the given element using the document.
  18304. */
  18305. mxVmlCanvas2D.prototype.createElement = function(name)
  18306. {
  18307. return document.createElement(name);
  18308. };
  18309. /**
  18310. * Function: createVmlElement
  18311. *
  18312. * Creates a new element using <createElement> and prefixes the given name with
  18313. * <mxClient.VML_PREFIX>.
  18314. */
  18315. mxVmlCanvas2D.prototype.createVmlElement = function(name)
  18316. {
  18317. return this.createElement(mxClient.VML_PREFIX + ':' + name);
  18318. };
  18319. /**
  18320. * Function: addNode
  18321. *
  18322. * Adds the current node to the <root>.
  18323. */
  18324. mxVmlCanvas2D.prototype.addNode = function(filled, stroked)
  18325. {
  18326. var node = this.node;
  18327. var s = this.state;
  18328. if (node != null)
  18329. {
  18330. if (node.nodeName == 'shape')
  18331. {
  18332. // Checks if the path is not empty
  18333. if (this.path != null && this.path.length > 0)
  18334. {
  18335. node.path = this.path.join(' ') + ' e';
  18336. node.style.width = this.root.style.width;
  18337. node.style.height = this.root.style.height;
  18338. node.coordsize = parseInt(node.style.width) + ' ' + parseInt(node.style.height);
  18339. }
  18340. else
  18341. {
  18342. return;
  18343. }
  18344. }
  18345. node.strokeweight = this.format(Math.max(1, s.strokeWidth * s.scale / this.vmlScale)) + 'px';
  18346. if (s.shadow)
  18347. {
  18348. this.root.appendChild(this.createShadow(node,
  18349. filled && s.fillColor != null,
  18350. stroked && s.strokeColor != null));
  18351. }
  18352. if (stroked && s.strokeColor != null)
  18353. {
  18354. node.stroked = 'true';
  18355. node.strokecolor = s.strokeColor;
  18356. }
  18357. else
  18358. {
  18359. node.stroked = 'false';
  18360. }
  18361. node.appendChild(this.createStroke());
  18362. if (filled && s.fillColor != null)
  18363. {
  18364. node.appendChild(this.createFill());
  18365. }
  18366. else if (this.pointerEvents && (node.nodeName != 'shape' ||
  18367. this.path[this.path.length - 1] == this.closeOp))
  18368. {
  18369. node.appendChild(this.createTransparentFill());
  18370. }
  18371. else
  18372. {
  18373. node.filled = 'false';
  18374. }
  18375. // LATER: Update existing DOM for performance
  18376. this.root.appendChild(node);
  18377. }
  18378. };
  18379. /**
  18380. * Function: createTransparentFill
  18381. *
  18382. * Creates a transparent fill.
  18383. */
  18384. mxVmlCanvas2D.prototype.createTransparentFill = function()
  18385. {
  18386. var fill = this.createVmlElement('fill');
  18387. fill.src = mxClient.imageBasePath + '/transparent.gif';
  18388. fill.type = 'tile';
  18389. return fill;
  18390. };
  18391. /**
  18392. * Function: createFill
  18393. *
  18394. * Creates a fill for the current state.
  18395. */
  18396. mxVmlCanvas2D.prototype.createFill = function()
  18397. {
  18398. var s = this.state;
  18399. // Gradients in foregrounds not supported because special gradients
  18400. // with bounds must be created for each element in graphics-canvases
  18401. var fill = this.createVmlElement('fill');
  18402. fill.color = s.fillColor;
  18403. if (s.gradientColor != null)
  18404. {
  18405. fill.type = 'gradient';
  18406. fill.method = 'none';
  18407. fill.color2 = s.gradientColor;
  18408. var angle = 180 - s.rotation;
  18409. if (s.gradientDirection == mxConstants.DIRECTION_WEST)
  18410. {
  18411. angle -= 90 + ((this.root.style.flip == 'x') ? 180 : 0);
  18412. }
  18413. else if (s.gradientDirection == mxConstants.DIRECTION_EAST)
  18414. {
  18415. angle += 90 + ((this.root.style.flip == 'x') ? 180 : 0);
  18416. }
  18417. else if (s.gradientDirection == mxConstants.DIRECTION_NORTH)
  18418. {
  18419. angle -= 180 + ((this.root.style.flip == 'y') ? -180 : 0);
  18420. }
  18421. else
  18422. {
  18423. angle += ((this.root.style.flip == 'y') ? -180 : 0);
  18424. }
  18425. if (this.root.style.flip == 'x' || this.root.style.flip == 'y')
  18426. {
  18427. angle *= -1;
  18428. }
  18429. // LATER: Fix outer bounding box for rotated shapes used in VML.
  18430. fill.angle = mxUtils.mod(angle, 360);
  18431. fill.opacity = (s.alpha * s.gradientFillAlpha * 100) + '%';
  18432. fill.setAttribute(mxClient.OFFICE_PREFIX + ':opacity2', (s.alpha * s.gradientAlpha * 100) + '%');
  18433. }
  18434. else if (s.alpha < 1 || s.fillAlpha < 1)
  18435. {
  18436. fill.opacity = (s.alpha * s.fillAlpha * 100) + '%';
  18437. }
  18438. return fill;
  18439. };
  18440. /**
  18441. * Function: createStroke
  18442. *
  18443. * Creates a fill for the current state.
  18444. */
  18445. mxVmlCanvas2D.prototype.createStroke = function()
  18446. {
  18447. var s = this.state;
  18448. var stroke = this.createVmlElement('stroke');
  18449. stroke.endcap = s.lineCap || 'flat';
  18450. stroke.joinstyle = s.lineJoin || 'miter';
  18451. stroke.miterlimit = s.miterLimit || '10';
  18452. if (s.alpha < 1 || s.strokeAlpha < 1)
  18453. {
  18454. stroke.opacity = (s.alpha * s.strokeAlpha * 100) + '%';
  18455. }
  18456. if (s.dashed)
  18457. {
  18458. stroke.dashstyle = this.getVmlDashStyle();
  18459. }
  18460. return stroke;
  18461. };
  18462. /**
  18463. * Function: getVmlDashPattern
  18464. *
  18465. * Returns a VML dash pattern for the current dashPattern.
  18466. * See http://msdn.microsoft.com/en-us/library/bb264085(v=vs.85).aspx
  18467. */
  18468. mxVmlCanvas2D.prototype.getVmlDashStyle = function()
  18469. {
  18470. var result = 'dash';
  18471. if (typeof(this.state.dashPattern) === 'string')
  18472. {
  18473. var tok = this.state.dashPattern.split(' ');
  18474. if (tok.length > 0 && tok[0] == 1)
  18475. {
  18476. result = '0 2';
  18477. }
  18478. }
  18479. return result;
  18480. };
  18481. /**
  18482. * Function: createShadow
  18483. *
  18484. * Creates a shadow for the given node.
  18485. */
  18486. mxVmlCanvas2D.prototype.createShadow = function(node, filled, stroked)
  18487. {
  18488. var s = this.state;
  18489. var rad = -s.rotation * (Math.PI / 180);
  18490. var cos = Math.cos(rad);
  18491. var sin = Math.sin(rad);
  18492. var dx = s.shadowDx * s.scale;
  18493. var dy = s.shadowDy * s.scale;
  18494. if (this.root.style.flip == 'x')
  18495. {
  18496. dx *= -1;
  18497. }
  18498. else if (this.root.style.flip == 'y')
  18499. {
  18500. dy *= -1;
  18501. }
  18502. var shadow = node.cloneNode(true);
  18503. shadow.style.marginLeft = Math.round(dx * cos - dy * sin) + 'px';
  18504. shadow.style.marginTop = Math.round(dx * sin + dy * cos) + 'px';
  18505. // Workaround for wrong cloning in IE8 standards mode
  18506. if (document.documentMode == 8)
  18507. {
  18508. shadow.strokeweight = node.strokeweight;
  18509. if (node.nodeName == 'shape')
  18510. {
  18511. shadow.path = this.path.join(' ') + ' e';
  18512. shadow.style.width = this.root.style.width;
  18513. shadow.style.height = this.root.style.height;
  18514. shadow.coordsize = parseInt(node.style.width) + ' ' + parseInt(node.style.height);
  18515. }
  18516. }
  18517. if (stroked)
  18518. {
  18519. shadow.strokecolor = s.shadowColor;
  18520. shadow.appendChild(this.createShadowStroke());
  18521. }
  18522. else
  18523. {
  18524. shadow.stroked = 'false';
  18525. }
  18526. if (filled)
  18527. {
  18528. shadow.appendChild(this.createShadowFill());
  18529. }
  18530. else
  18531. {
  18532. shadow.filled = 'false';
  18533. }
  18534. return shadow;
  18535. };
  18536. /**
  18537. * Function: createShadowFill
  18538. *
  18539. * Creates the fill for the shadow.
  18540. */
  18541. mxVmlCanvas2D.prototype.createShadowFill = function()
  18542. {
  18543. var fill = this.createVmlElement('fill');
  18544. fill.color = this.state.shadowColor;
  18545. fill.opacity = (this.state.alpha * this.state.shadowAlpha * 100) + '%';
  18546. return fill;
  18547. };
  18548. /**
  18549. * Function: createShadowStroke
  18550. *
  18551. * Creates the stroke for the shadow.
  18552. */
  18553. mxVmlCanvas2D.prototype.createShadowStroke = function()
  18554. {
  18555. var stroke = this.createStroke();
  18556. stroke.opacity = (this.state.alpha * this.state.shadowAlpha * 100) + '%';
  18557. return stroke;
  18558. };
  18559. /**
  18560. * Function: rotate
  18561. *
  18562. * Sets the rotation of the canvas. Note that rotation cannot be concatenated.
  18563. */
  18564. mxVmlCanvas2D.prototype.rotate = function(theta, flipH, flipV, cx, cy)
  18565. {
  18566. if (flipH && flipV)
  18567. {
  18568. theta += 180;
  18569. }
  18570. else if (flipH)
  18571. {
  18572. this.root.style.flip = 'x';
  18573. }
  18574. else if (flipV)
  18575. {
  18576. this.root.style.flip = 'y';
  18577. }
  18578. if (flipH ? !flipV : flipV)
  18579. {
  18580. theta *= -1;
  18581. }
  18582. this.root.style.rotation = theta;
  18583. this.state.rotation = this.state.rotation + theta;
  18584. this.state.rotationCx = cx;
  18585. this.state.rotationCy = cy;
  18586. };
  18587. /**
  18588. * Function: begin
  18589. *
  18590. * Extends superclass to create path.
  18591. */
  18592. mxVmlCanvas2D.prototype.begin = function()
  18593. {
  18594. mxAbstractCanvas2D.prototype.begin.apply(this, arguments);
  18595. this.node = this.createVmlElement('shape');
  18596. this.node.style.position = 'absolute';
  18597. };
  18598. /**
  18599. * Function: quadTo
  18600. *
  18601. * Replaces quadratic curve with bezier curve in VML.
  18602. */
  18603. mxVmlCanvas2D.prototype.quadTo = function(x1, y1, x2, y2)
  18604. {
  18605. var s = this.state;
  18606. var cpx0 = (this.lastX + s.dx) * s.scale;
  18607. var cpy0 = (this.lastY + s.dy) * s.scale;
  18608. var qpx1 = (x1 + s.dx) * s.scale;
  18609. var qpy1 = (y1 + s.dy) * s.scale;
  18610. var cpx3 = (x2 + s.dx) * s.scale;
  18611. var cpy3 = (y2 + s.dy) * s.scale;
  18612. var cpx1 = cpx0 + 2/3 * (qpx1 - cpx0);
  18613. var cpy1 = cpy0 + 2/3 * (qpy1 - cpy0);
  18614. var cpx2 = cpx3 + 2/3 * (qpx1 - cpx3);
  18615. var cpy2 = cpy3 + 2/3 * (qpy1 - cpy3);
  18616. this.path.push('c ' + this.format(cpx1) + ' ' + this.format(cpy1) +
  18617. ' ' + this.format(cpx2) + ' ' + this.format(cpy2) +
  18618. ' ' + this.format(cpx3) + ' ' + this.format(cpy3));
  18619. this.lastX = (cpx3 / s.scale) - s.dx;
  18620. this.lastY = (cpy3 / s.scale) - s.dy;
  18621. };
  18622. /**
  18623. * Function: createRect
  18624. *
  18625. * Sets the glass gradient.
  18626. */
  18627. mxVmlCanvas2D.prototype.createRect = function(nodeName, x, y, w, h)
  18628. {
  18629. var s = this.state;
  18630. var n = this.createVmlElement(nodeName);
  18631. n.style.position = 'absolute';
  18632. n.style.left = this.format((x + s.dx) * s.scale) + 'px';
  18633. n.style.top = this.format((y + s.dy) * s.scale) + 'px';
  18634. n.style.width = this.format(w * s.scale) + 'px';
  18635. n.style.height = this.format(h * s.scale) + 'px';
  18636. return n;
  18637. };
  18638. /**
  18639. * Function: rect
  18640. *
  18641. * Sets the current path to a rectangle.
  18642. */
  18643. mxVmlCanvas2D.prototype.rect = function(x, y, w, h)
  18644. {
  18645. this.node = this.createRect('rect', x, y, w, h);
  18646. };
  18647. /**
  18648. * Function: roundrect
  18649. *
  18650. * Sets the current path to a rounded rectangle.
  18651. */
  18652. mxVmlCanvas2D.prototype.roundrect = function(x, y, w, h, dx, dy)
  18653. {
  18654. this.node = this.createRect('roundrect', x, y, w, h);
  18655. // SetAttribute needed here for IE8
  18656. this.node.setAttribute('arcsize', Math.max(dx * 100 / w, dy * 100 / h) + '%');
  18657. };
  18658. /**
  18659. * Function: ellipse
  18660. *
  18661. * Sets the current path to an ellipse.
  18662. */
  18663. mxVmlCanvas2D.prototype.ellipse = function(x, y, w, h)
  18664. {
  18665. this.node = this.createRect('oval', x, y, w, h);
  18666. };
  18667. /**
  18668. * Function: image
  18669. *
  18670. * Paints an image.
  18671. */
  18672. mxVmlCanvas2D.prototype.image = function(x, y, w, h, src, aspect, flipH, flipV)
  18673. {
  18674. var node = null;
  18675. if (!aspect)
  18676. {
  18677. node = this.createRect('image', x, y, w, h);
  18678. node.src = src;
  18679. }
  18680. else
  18681. {
  18682. // Uses fill with aspect to avoid asynchronous update of size
  18683. node = this.createRect('rect', x, y, w, h);
  18684. node.stroked = 'false';
  18685. // Handles image aspect via fill
  18686. var fill = this.createVmlElement('fill');
  18687. fill.aspect = (aspect) ? 'atmost' : 'ignore';
  18688. fill.rotate = 'true';
  18689. fill.type = 'frame';
  18690. fill.src = src;
  18691. node.appendChild(fill);
  18692. }
  18693. if (flipH && flipV)
  18694. {
  18695. node.style.rotation = '180';
  18696. }
  18697. else if (flipH)
  18698. {
  18699. node.style.flip = 'x';
  18700. }
  18701. else if (flipV)
  18702. {
  18703. node.style.flip = 'y';
  18704. }
  18705. if (this.state.alpha < 1 || this.state.fillAlpha < 1)
  18706. {
  18707. // KNOWN: Borders around transparent images in IE<9. Using fill.opacity
  18708. // fixes this problem by adding a white background in all IE versions.
  18709. node.style.filter += 'alpha(opacity=' + (this.state.alpha * this.state.fillAlpha * 100) + ')';
  18710. }
  18711. this.root.appendChild(node);
  18712. };
  18713. /**
  18714. * Function: createText
  18715. *
  18716. * Creates the innermost element that contains the HTML text.
  18717. */
  18718. mxVmlCanvas2D.prototype.createDiv = function(str, align, valign, overflow)
  18719. {
  18720. var div = this.createElement('div');
  18721. var state = this.state;
  18722. var css = '';
  18723. if (state.fontBackgroundColor != null)
  18724. {
  18725. css += 'background-color:' + mxUtils.htmlEntities(state.fontBackgroundColor) + ';';
  18726. }
  18727. if (state.fontBorderColor != null)
  18728. {
  18729. css += 'border:1px solid ' + mxUtils.htmlEntities(state.fontBorderColor) + ';';
  18730. }
  18731. if (mxUtils.isNode(str))
  18732. {
  18733. div.appendChild(str);
  18734. }
  18735. else
  18736. {
  18737. if (overflow != 'fill' && overflow != 'width')
  18738. {
  18739. var div2 = this.createElement('div');
  18740. div2.style.cssText = css;
  18741. div2.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  18742. div2.style.zoom = '1';
  18743. div2.style.textDecoration = 'inherit';
  18744. div2.innerHTML = str;
  18745. div.appendChild(div2);
  18746. }
  18747. else
  18748. {
  18749. div.style.cssText = css;
  18750. div.innerHTML = str;
  18751. }
  18752. }
  18753. var style = div.style;
  18754. style.fontSize = (state.fontSize / this.vmlScale) + 'px';
  18755. style.fontFamily = state.fontFamily;
  18756. style.color = state.fontColor;
  18757. style.verticalAlign = 'top';
  18758. style.textAlign = align || 'left';
  18759. style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? (state.fontSize * mxConstants.LINE_HEIGHT / this.vmlScale) + 'px' : mxConstants.LINE_HEIGHT;
  18760. if ((state.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  18761. {
  18762. style.fontWeight = 'bold';
  18763. }
  18764. if ((state.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  18765. {
  18766. style.fontStyle = 'italic';
  18767. }
  18768. if ((state.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  18769. {
  18770. style.textDecoration = 'underline';
  18771. }
  18772. return div;
  18773. };
  18774. /**
  18775. * Function: text
  18776. *
  18777. * Paints the given text. Possible values for format are empty string for plain
  18778. * text and html for HTML markup. Clipping, text background and border are not
  18779. * supported for plain text in VML.
  18780. */
  18781. mxVmlCanvas2D.prototype.text = function(x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation, dir)
  18782. {
  18783. if (this.textEnabled && str != null)
  18784. {
  18785. var s = this.state;
  18786. if (format == 'html')
  18787. {
  18788. if (s.rotation != null)
  18789. {
  18790. var pt = this.rotatePoint(x, y, s.rotation, s.rotationCx, s.rotationCy);
  18791. x = pt.x;
  18792. y = pt.y;
  18793. }
  18794. if (document.documentMode == 8 && !mxClient.IS_EM)
  18795. {
  18796. x += s.dx;
  18797. y += s.dy;
  18798. // Workaround for rendering offsets
  18799. if (overflow != 'fill' && valign == mxConstants.ALIGN_TOP)
  18800. {
  18801. y -= 1;
  18802. }
  18803. }
  18804. else
  18805. {
  18806. x *= s.scale;
  18807. y *= s.scale;
  18808. }
  18809. // Adds event transparency in IE8 standards without the transparent background
  18810. // filter which cannot be used due to bugs in the zoomed bounding box (too slow)
  18811. // FIXME: No event transparency if inside v:rect (ie part of shape)
  18812. // KNOWN: Offset wrong for rotated text with word that are longer than the wrapping
  18813. // width in IE8 because real width of text cannot be determined here.
  18814. // This should be fixed in mxText.updateBoundingBox by calling before this and
  18815. // passing the real width to this method if not clipped and wrapped.
  18816. var abs = (document.documentMode == 8 && !mxClient.IS_EM) ? this.createVmlElement('group') : this.createElement('div');
  18817. abs.style.position = 'absolute';
  18818. abs.style.display = 'inline';
  18819. abs.style.left = this.format(x) + 'px';
  18820. abs.style.top = this.format(y) + 'px';
  18821. abs.style.zoom = s.scale;
  18822. var box = this.createElement('div');
  18823. box.style.position = 'relative';
  18824. box.style.display = 'inline';
  18825. var margin = mxUtils.getAlignmentAsPoint(align, valign);
  18826. var dx = margin.x;
  18827. var dy = margin.y;
  18828. var div = this.createDiv(str, align, valign, overflow);
  18829. var inner = this.createElement('div');
  18830. if (dir != null)
  18831. {
  18832. div.setAttribute('dir', dir);
  18833. }
  18834. if (wrap && w > 0)
  18835. {
  18836. if (!clip)
  18837. {
  18838. div.style.width = Math.round(w) + 'px';
  18839. }
  18840. div.style.wordWrap = mxConstants.WORD_WRAP;
  18841. div.style.whiteSpace = 'normal';
  18842. // LATER: Check if other cases need to be handled
  18843. if (div.style.wordWrap == 'break-word')
  18844. {
  18845. var tmp = div;
  18846. if (tmp.firstChild != null && tmp.firstChild.nodeName == 'DIV')
  18847. {
  18848. tmp.firstChild.style.width = '100%';
  18849. }
  18850. }
  18851. }
  18852. else
  18853. {
  18854. div.style.whiteSpace = 'nowrap';
  18855. }
  18856. var rot = s.rotation + (rotation || 0);
  18857. if (this.rotateHtml && rot != 0)
  18858. {
  18859. inner.style.display = 'inline';
  18860. inner.style.zoom = '1';
  18861. inner.appendChild(div);
  18862. // Box not needed for rendering in IE8 standards
  18863. if (document.documentMode == 8 && !mxClient.IS_EM && this.root.nodeName != 'DIV')
  18864. {
  18865. box.appendChild(inner);
  18866. abs.appendChild(box);
  18867. }
  18868. else
  18869. {
  18870. abs.appendChild(inner);
  18871. }
  18872. }
  18873. else if (document.documentMode == 8 && !mxClient.IS_EM)
  18874. {
  18875. box.appendChild(div);
  18876. abs.appendChild(box);
  18877. }
  18878. else
  18879. {
  18880. div.style.display = 'inline';
  18881. abs.appendChild(div);
  18882. }
  18883. // Inserts the node into the DOM
  18884. if (this.root.nodeName != 'DIV')
  18885. {
  18886. // Rectangle to fix position in group
  18887. var rect = this.createVmlElement('rect');
  18888. rect.stroked = 'false';
  18889. rect.filled = 'false';
  18890. rect.appendChild(abs);
  18891. this.root.appendChild(rect);
  18892. }
  18893. else
  18894. {
  18895. this.root.appendChild(abs);
  18896. }
  18897. if (clip)
  18898. {
  18899. div.style.overflow = 'hidden';
  18900. div.style.width = Math.round(w) + 'px';
  18901. if (!mxClient.IS_QUIRKS)
  18902. {
  18903. div.style.maxHeight = Math.round(h) + 'px';
  18904. }
  18905. }
  18906. else if (overflow == 'fill')
  18907. {
  18908. // KNOWN: Affects horizontal alignment in quirks
  18909. // but fill should only be used with align=left
  18910. div.style.overflow = 'hidden';
  18911. div.style.width = (Math.max(0, w) + 1) + 'px';
  18912. div.style.height = (Math.max(0, h) + 1) + 'px';
  18913. }
  18914. else if (overflow == 'width')
  18915. {
  18916. // KNOWN: Affects horizontal alignment in quirks
  18917. // but fill should only be used with align=left
  18918. div.style.overflow = 'hidden';
  18919. div.style.width = (Math.max(0, w) + 1) + 'px';
  18920. div.style.maxHeight = (Math.max(0, h) + 1) + 'px';
  18921. }
  18922. if (this.rotateHtml && rot != 0)
  18923. {
  18924. var rad = rot * (Math.PI / 180);
  18925. // Precalculate cos and sin for the rotation
  18926. var real_cos = parseFloat(parseFloat(Math.cos(rad)).toFixed(8));
  18927. var real_sin = parseFloat(parseFloat(Math.sin(-rad)).toFixed(8));
  18928. rad %= 2 * Math.PI;
  18929. if (rad < 0) rad += 2 * Math.PI;
  18930. rad %= Math.PI;
  18931. if (rad > Math.PI / 2) rad = Math.PI - rad;
  18932. var cos = Math.cos(rad);
  18933. var sin = Math.sin(rad);
  18934. // Adds div to document to measure size
  18935. if (document.documentMode == 8 && !mxClient.IS_EM)
  18936. {
  18937. div.style.display = 'inline-block';
  18938. inner.style.display = 'inline-block';
  18939. box.style.display = 'inline-block';
  18940. }
  18941. div.style.visibility = 'hidden';
  18942. div.style.position = 'absolute';
  18943. document.body.appendChild(div);
  18944. var sizeDiv = div;
  18945. if (sizeDiv.firstChild != null && sizeDiv.firstChild.nodeName == 'DIV')
  18946. {
  18947. sizeDiv = sizeDiv.firstChild;
  18948. }
  18949. var tmp = sizeDiv.offsetWidth + 3;
  18950. var oh = sizeDiv.offsetHeight;
  18951. if (clip)
  18952. {
  18953. w = Math.min(w, tmp);
  18954. oh = Math.min(oh, h);
  18955. }
  18956. else
  18957. {
  18958. w = tmp;
  18959. }
  18960. // Handles words that are longer than the given wrapping width
  18961. if (wrap)
  18962. {
  18963. div.style.width = w + 'px';
  18964. }
  18965. // Simulates max-height in quirks
  18966. if (mxClient.IS_QUIRKS && (clip || overflow == 'width') && oh > h)
  18967. {
  18968. oh = h;
  18969. // Quirks does not support maxHeight
  18970. div.style.height = oh + 'px';
  18971. }
  18972. h = oh;
  18973. var top_fix = (h - h * cos + w * -sin) / 2 - real_sin * w * (dx + 0.5) + real_cos * h * (dy + 0.5);
  18974. var left_fix = (w - w * cos + h * -sin) / 2 + real_cos * w * (dx + 0.5) + real_sin * h * (dy + 0.5);
  18975. if (abs.nodeName == 'group' && this.root.nodeName == 'DIV')
  18976. {
  18977. // Workaround for bug where group gets moved away if left and top are non-zero in IE8 standards
  18978. var pos = this.createElement('div');
  18979. pos.style.display = 'inline-block';
  18980. pos.style.position = 'absolute';
  18981. pos.style.left = this.format(x + (left_fix - w / 2) * s.scale) + 'px';
  18982. pos.style.top = this.format(y + (top_fix - h / 2) * s.scale) + 'px';
  18983. abs.parentNode.appendChild(pos);
  18984. pos.appendChild(abs);
  18985. }
  18986. else
  18987. {
  18988. var sc = (document.documentMode == 8 && !mxClient.IS_EM) ? 1 : s.scale;
  18989. abs.style.left = this.format(x + (left_fix - w / 2) * sc) + 'px';
  18990. abs.style.top = this.format(y + (top_fix - h / 2) * sc) + 'px';
  18991. }
  18992. // KNOWN: Rotated text rendering quality is bad for IE9 quirks
  18993. inner.style.filter = "progid:DXImageTransform.Microsoft.Matrix(M11="+real_cos+", M12="+
  18994. real_sin+", M21="+(-real_sin)+", M22="+real_cos+", sizingMethod='auto expand')";
  18995. inner.style.backgroundColor = this.rotatedHtmlBackground;
  18996. if (this.state.alpha < 1)
  18997. {
  18998. inner.style.filter += 'alpha(opacity=' + (this.state.alpha * 100) + ')';
  18999. }
  19000. // Restore parent node for DIV
  19001. inner.appendChild(div);
  19002. div.style.position = '';
  19003. div.style.visibility = '';
  19004. }
  19005. else if (document.documentMode != 8 || mxClient.IS_EM)
  19006. {
  19007. div.style.verticalAlign = 'top';
  19008. if (this.state.alpha < 1)
  19009. {
  19010. abs.style.filter = 'alpha(opacity=' + (this.state.alpha * 100) + ')';
  19011. }
  19012. // Adds div to document to measure size
  19013. var divParent = div.parentNode;
  19014. div.style.visibility = 'hidden';
  19015. document.body.appendChild(div);
  19016. w = div.offsetWidth;
  19017. var oh = div.offsetHeight;
  19018. // Simulates max-height in quirks
  19019. if (mxClient.IS_QUIRKS && clip && oh > h)
  19020. {
  19021. oh = h;
  19022. // Quirks does not support maxHeight
  19023. div.style.height = oh + 'px';
  19024. }
  19025. h = oh;
  19026. div.style.visibility = '';
  19027. divParent.appendChild(div);
  19028. abs.style.left = this.format(x + w * dx * this.state.scale) + 'px';
  19029. abs.style.top = this.format(y + h * dy * this.state.scale) + 'px';
  19030. }
  19031. else
  19032. {
  19033. if (this.state.alpha < 1)
  19034. {
  19035. div.style.filter = 'alpha(opacity=' + (this.state.alpha * 100) + ')';
  19036. }
  19037. // Faster rendering in IE8 without offsetWidth/Height
  19038. box.style.left = (dx * 100) + '%';
  19039. box.style.top = (dy * 100) + '%';
  19040. }
  19041. }
  19042. else
  19043. {
  19044. this.plainText(x, y, w, h, mxUtils.htmlEntities(str, false), align, valign, wrap, format, overflow, clip, rotation, dir);
  19045. }
  19046. }
  19047. };
  19048. /**
  19049. * Function: plainText
  19050. *
  19051. * Paints the outline of the current path.
  19052. */
  19053. mxVmlCanvas2D.prototype.plainText = function(x, y, w, h, str, align, valign, wrap, format, overflow, clip, rotation, dir)
  19054. {
  19055. // TextDirection is ignored since this code is not used (format is always HTML in the text function)
  19056. var s = this.state;
  19057. x = (x + s.dx) * s.scale;
  19058. y = (y + s.dy) * s.scale;
  19059. var node = this.createVmlElement('shape');
  19060. node.style.width = '1px';
  19061. node.style.height = '1px';
  19062. node.stroked = 'false';
  19063. var fill = this.createVmlElement('fill');
  19064. fill.color = s.fontColor;
  19065. fill.opacity = (s.alpha * 100) + '%';
  19066. node.appendChild(fill);
  19067. var path = this.createVmlElement('path');
  19068. path.textpathok = 'true';
  19069. path.v = 'm ' + this.format(0) + ' ' + this.format(0) + ' l ' + this.format(1) + ' ' + this.format(0);
  19070. node.appendChild(path);
  19071. // KNOWN: Font family and text decoration ignored
  19072. var tp = this.createVmlElement('textpath');
  19073. tp.style.cssText = 'v-text-align:' + align;
  19074. tp.style.align = align;
  19075. tp.style.fontFamily = s.fontFamily;
  19076. tp.string = str;
  19077. tp.on = 'true';
  19078. // Scale via fontsize instead of node.style.zoom for correct offsets in IE8
  19079. var size = s.fontSize * s.scale / this.vmlScale;
  19080. tp.style.fontSize = size + 'px';
  19081. // Bold
  19082. if ((s.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  19083. {
  19084. tp.style.fontWeight = 'bold';
  19085. }
  19086. // Italic
  19087. if ((s.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  19088. {
  19089. tp.style.fontStyle = 'italic';
  19090. }
  19091. // Underline
  19092. if ((s.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  19093. {
  19094. tp.style.textDecoration = 'underline';
  19095. }
  19096. var lines = str.split('\n');
  19097. var textHeight = size + (lines.length - 1) * size * mxConstants.LINE_HEIGHT;
  19098. var dx = 0;
  19099. var dy = 0;
  19100. if (valign == mxConstants.ALIGN_BOTTOM)
  19101. {
  19102. dy = - textHeight / 2;
  19103. }
  19104. else if (valign != mxConstants.ALIGN_MIDDLE) // top
  19105. {
  19106. dy = textHeight / 2;
  19107. }
  19108. if (rotation != null)
  19109. {
  19110. node.style.rotation = rotation;
  19111. var rad = rotation * (Math.PI / 180);
  19112. dx = Math.sin(rad) * dy;
  19113. dy = Math.cos(rad) * dy;
  19114. }
  19115. // FIXME: Clipping is relative to bounding box
  19116. /*if (clip)
  19117. {
  19118. node.style.clip = 'rect(0px ' + this.format(w) + 'px ' + this.format(h) + 'px 0px)';
  19119. }*/
  19120. node.appendChild(tp);
  19121. node.style.left = this.format(x - dx) + 'px';
  19122. node.style.top = this.format(y + dy) + 'px';
  19123. this.root.appendChild(node);
  19124. };
  19125. /**
  19126. * Function: stroke
  19127. *
  19128. * Paints the outline of the current path.
  19129. */
  19130. mxVmlCanvas2D.prototype.stroke = function()
  19131. {
  19132. this.addNode(false, true);
  19133. };
  19134. /**
  19135. * Function: fill
  19136. *
  19137. * Fills the current path.
  19138. */
  19139. mxVmlCanvas2D.prototype.fill = function()
  19140. {
  19141. this.addNode(true, false);
  19142. };
  19143. /**
  19144. * Function: fillAndStroke
  19145. *
  19146. * Fills and paints the outline of the current path.
  19147. */
  19148. mxVmlCanvas2D.prototype.fillAndStroke = function()
  19149. {
  19150. this.addNode(true, true);
  19151. };
  19152. /**
  19153. * Copyright (c) 2006-2015, JGraph Ltd
  19154. * Copyright (c) 2006-2015, Gaudenz Alder
  19155. */
  19156. /**
  19157. * Class: mxGuide
  19158. *
  19159. * Implements the alignment of selection cells to other cells in the graph.
  19160. *
  19161. * Constructor: mxGuide
  19162. *
  19163. * Constructs a new guide object.
  19164. */
  19165. function mxGuide(graph, states)
  19166. {
  19167. this.graph = graph;
  19168. this.setStates(states);
  19169. };
  19170. /**
  19171. * Variable: graph
  19172. *
  19173. * Reference to the enclosing <mxGraph> instance.
  19174. */
  19175. mxGuide.prototype.graph = null;
  19176. /**
  19177. * Variable: states
  19178. *
  19179. * Contains the <mxCellStates> that are used for alignment.
  19180. */
  19181. mxGuide.prototype.states = null;
  19182. /**
  19183. * Variable: horizontal
  19184. *
  19185. * Specifies if horizontal guides are enabled. Default is true.
  19186. */
  19187. mxGuide.prototype.horizontal = true;
  19188. /**
  19189. * Variable: vertical
  19190. *
  19191. * Specifies if vertical guides are enabled. Default is true.
  19192. */
  19193. mxGuide.prototype.vertical = true;
  19194. /**
  19195. * Variable: vertical
  19196. *
  19197. * Holds the <mxShape> for the horizontal guide.
  19198. */
  19199. mxGuide.prototype.guideX = null;
  19200. /**
  19201. * Variable: vertical
  19202. *
  19203. * Holds the <mxShape> for the vertical guide.
  19204. */
  19205. mxGuide.prototype.guideY = null;
  19206. /**
  19207. * Variable: rounded
  19208. *
  19209. * Specifies if rounded coordinates should be used. Default is false.
  19210. */
  19211. mxGuide.prototype.rounded = false;
  19212. /**
  19213. * Variable: tolerance
  19214. *
  19215. * Default tolerance in px if grid is disabled. Default is 2.
  19216. */
  19217. mxGuide.prototype.tolerance = 2;
  19218. /**
  19219. * Function: setStates
  19220. *
  19221. * Sets the <mxCellStates> that should be used for alignment.
  19222. */
  19223. mxGuide.prototype.setStates = function(states)
  19224. {
  19225. this.states = states;
  19226. };
  19227. /**
  19228. * Function: isEnabledForEvent
  19229. *
  19230. * Returns true if the guide should be enabled for the given native event. This
  19231. * implementation always returns true.
  19232. */
  19233. mxGuide.prototype.isEnabledForEvent = function(evt)
  19234. {
  19235. return true;
  19236. };
  19237. /**
  19238. * Function: getGuideTolerance
  19239. *
  19240. * Returns the tolerance for the guides. Default value is gridSize / 2.
  19241. */
  19242. mxGuide.prototype.getGuideTolerance = function(gridEnabled)
  19243. {
  19244. return (gridEnabled && this.graph.gridEnabled) ? this.graph.gridSize / 2 : this.tolerance;
  19245. };
  19246. /**
  19247. * Function: createGuideShape
  19248. *
  19249. * Returns the mxShape to be used for painting the respective guide. This
  19250. * implementation returns a new, dashed and crisp <mxPolyline> using
  19251. * <mxConstants.GUIDE_COLOR> and <mxConstants.GUIDE_STROKEWIDTH> as the format.
  19252. *
  19253. * Parameters:
  19254. *
  19255. * horizontal - Boolean that specifies which guide should be created.
  19256. */
  19257. mxGuide.prototype.createGuideShape = function(horizontal)
  19258. {
  19259. var guide = new mxPolyline([], mxConstants.GUIDE_COLOR, mxConstants.GUIDE_STROKEWIDTH);
  19260. guide.isDashed = true;
  19261. return guide;
  19262. };
  19263. /**
  19264. * Function: isStateIgnored
  19265. *
  19266. * Returns true if the given state should be ignored.
  19267. */
  19268. mxGuide.prototype.isStateIgnored = function(state)
  19269. {
  19270. return false;
  19271. };
  19272. /**
  19273. * Function: move
  19274. *
  19275. * Moves the <bounds> by the given <mxPoint> and returnt the snapped point.
  19276. */
  19277. mxGuide.prototype.move = function(bounds, delta, gridEnabled, clone)
  19278. {
  19279. if (this.states != null && (this.horizontal || this.vertical) && bounds != null && delta != null)
  19280. {
  19281. var scale = this.graph.getView().scale;
  19282. var tt = this.getGuideTolerance(gridEnabled) * scale;
  19283. var b = bounds.clone();
  19284. b.x += delta.x;
  19285. b.y += delta.y;
  19286. var overrideX = false;
  19287. var stateX = null;
  19288. var valueX = null;
  19289. var overrideY = false;
  19290. var stateY = null;
  19291. var valueY = null;
  19292. var ttX = tt;
  19293. var ttY = tt;
  19294. var left = b.x;
  19295. var right = b.x + b.width;
  19296. var center = b.getCenterX();
  19297. var top = b.y;
  19298. var bottom = b.y + b.height;
  19299. var middle = b.getCenterY();
  19300. // Snaps the left, center and right to the given x-coordinate
  19301. function snapX(x, state, centerAlign)
  19302. {
  19303. var override = false;
  19304. if (centerAlign && Math.abs(x - center) < ttX)
  19305. {
  19306. delta.x = x - bounds.getCenterX();
  19307. ttX = Math.abs(x - center);
  19308. override = true;
  19309. }
  19310. else if (!centerAlign)
  19311. {
  19312. if (Math.abs(x - left) < ttX)
  19313. {
  19314. delta.x = x - bounds.x;
  19315. ttX = Math.abs(x - left);
  19316. override = true;
  19317. }
  19318. else if (Math.abs(x - right) < ttX)
  19319. {
  19320. delta.x = x - bounds.x - bounds.width;
  19321. ttX = Math.abs(x - right);
  19322. override = true;
  19323. }
  19324. }
  19325. if (override)
  19326. {
  19327. stateX = state;
  19328. valueX = x;
  19329. if (this.guideX == null)
  19330. {
  19331. this.guideX = this.createGuideShape(true);
  19332. // Makes sure to use either VML or SVG shapes in order to implement
  19333. // event-transparency on the background area of the rectangle since
  19334. // HTML shapes do not let mouseevents through even when transparent
  19335. this.guideX.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  19336. mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  19337. this.guideX.pointerEvents = false;
  19338. this.guideX.init(this.graph.getView().getOverlayPane());
  19339. }
  19340. }
  19341. overrideX = overrideX || override;
  19342. };
  19343. // Snaps the top, middle or bottom to the given y-coordinate
  19344. function snapY(y, state, centerAlign)
  19345. {
  19346. var override = false;
  19347. if (centerAlign && Math.abs(y - middle) < ttY)
  19348. {
  19349. delta.y = y - bounds.getCenterY();
  19350. ttY = Math.abs(y - middle);
  19351. override = true;
  19352. }
  19353. else if (!centerAlign)
  19354. {
  19355. if (Math.abs(y - top) < ttY)
  19356. {
  19357. delta.y = y - bounds.y;
  19358. ttY = Math.abs(y - top);
  19359. override = true;
  19360. }
  19361. else if (Math.abs(y - bottom) < ttY)
  19362. {
  19363. delta.y = y - bounds.y - bounds.height;
  19364. ttY = Math.abs(y - bottom);
  19365. override = true;
  19366. }
  19367. }
  19368. if (override)
  19369. {
  19370. stateY = state;
  19371. valueY = y;
  19372. if (this.guideY == null)
  19373. {
  19374. this.guideY = this.createGuideShape(false);
  19375. // Makes sure to use either VML or SVG shapes in order to implement
  19376. // event-transparency on the background area of the rectangle since
  19377. // HTML shapes do not let mouseevents through even when transparent
  19378. this.guideY.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  19379. mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  19380. this.guideY.pointerEvents = false;
  19381. this.guideY.init(this.graph.getView().getOverlayPane());
  19382. }
  19383. }
  19384. overrideY = overrideY || override;
  19385. };
  19386. for (var i = 0; i < this.states.length; i++)
  19387. {
  19388. var state = this.states[i];
  19389. if (state != null && !this.isStateIgnored(state))
  19390. {
  19391. // Align x
  19392. if (this.horizontal)
  19393. {
  19394. snapX.call(this, state.getCenterX(), state, true);
  19395. snapX.call(this, state.x, state, false);
  19396. snapX.call(this, state.x + state.width, state, false);
  19397. // Aligns left and right of shape to center of page
  19398. if (state.cell == null)
  19399. {
  19400. snapX.call(this, state.getCenterX(), state, false);
  19401. }
  19402. }
  19403. // Align y
  19404. if (this.vertical)
  19405. {
  19406. snapY.call(this, state.getCenterY(), state, true);
  19407. snapY.call(this, state.y, state, false);
  19408. snapY.call(this, state.y + state.height, state, false);
  19409. // Aligns left and right of shape to center of page
  19410. if (state.cell == null)
  19411. {
  19412. snapY.call(this, state.getCenterY(), state, false);
  19413. }
  19414. }
  19415. }
  19416. }
  19417. // Moves cells to the raster if not aligned
  19418. this.graph.snapDelta(delta, bounds, !gridEnabled, overrideX, overrideY);
  19419. delta = this.getDelta(bounds, stateX, delta.x, stateY, delta.y)
  19420. // Redraws the guides
  19421. var c = this.graph.container;
  19422. if (!overrideX && this.guideX != null)
  19423. {
  19424. this.guideX.node.style.visibility = 'hidden';
  19425. }
  19426. else if (this.guideX != null)
  19427. {
  19428. var minY = null;
  19429. var maxY = null;
  19430. if (stateX != null && bounds != null)
  19431. {
  19432. minY = Math.min(bounds.y + delta.y - this.graph.panDy, stateX.y);
  19433. maxY = Math.max(bounds.y + bounds.height + delta.y - this.graph.panDy, stateX.y + stateX.height);
  19434. }
  19435. if (minY != null && maxY != null)
  19436. {
  19437. this.guideX.points = [new mxPoint(valueX, minY), new mxPoint(valueX, maxY)];
  19438. }
  19439. else
  19440. {
  19441. this.guideX.points = [new mxPoint(valueX, -this.graph.panDy),
  19442. new mxPoint(valueX, c.scrollHeight - 3 - this.graph.panDy)];
  19443. }
  19444. this.guideX.stroke = this.getGuideColor(stateX, true);
  19445. this.guideX.node.style.visibility = 'visible';
  19446. this.guideX.redraw();
  19447. }
  19448. if (!overrideY && this.guideY != null)
  19449. {
  19450. this.guideY.node.style.visibility = 'hidden';
  19451. }
  19452. else if (this.guideY != null)
  19453. {
  19454. var minX = null;
  19455. var maxX = null;
  19456. if (stateY != null && bounds != null)
  19457. {
  19458. minX = Math.min(bounds.x + delta.x - this.graph.panDx, stateY.x);
  19459. maxX = Math.max(bounds.x + bounds.width + delta.x - this.graph.panDx, stateY.x + stateY.width);
  19460. }
  19461. if (minX != null && maxX != null)
  19462. {
  19463. this.guideY.points = [new mxPoint(minX, valueY), new mxPoint(maxX, valueY)];
  19464. }
  19465. else
  19466. {
  19467. this.guideY.points = [new mxPoint(-this.graph.panDx, valueY),
  19468. new mxPoint(c.scrollWidth - 3 - this.graph.panDx, valueY)];
  19469. }
  19470. this.guideY.stroke = this.getGuideColor(stateY, false);
  19471. this.guideY.node.style.visibility = 'visible';
  19472. this.guideY.redraw();
  19473. }
  19474. }
  19475. return delta;
  19476. };
  19477. /**
  19478. * Function: getDelta
  19479. *
  19480. * Rounds to pixels for virtual states (eg. page guides)
  19481. */
  19482. mxGuide.prototype.getDelta = function(bounds, stateX, dx, stateY, dy)
  19483. {
  19484. var s = this.graph.view.scale;
  19485. if (this.rounded || (stateX != null && stateX.cell == null))
  19486. {
  19487. dx = Math.round((bounds.x + dx) / s) * s - bounds.x;
  19488. }
  19489. if (this.rounded || (stateY != null && stateY.cell == null))
  19490. {
  19491. dy = Math.round((bounds.y + dy) / s) * s - bounds.y;
  19492. }
  19493. return new mxPoint(dx, dy);
  19494. };
  19495. /**
  19496. * Function: getGuideColor
  19497. *
  19498. * Returns the color for the given state.
  19499. */
  19500. mxGuide.prototype.getGuideColor = function(state, horizontal)
  19501. {
  19502. return mxConstants.GUIDE_COLOR;
  19503. };
  19504. /**
  19505. * Function: hide
  19506. *
  19507. * Hides all current guides.
  19508. */
  19509. mxGuide.prototype.hide = function()
  19510. {
  19511. this.setVisible(false);
  19512. };
  19513. /**
  19514. * Function: setVisible
  19515. *
  19516. * Shows or hides the current guides.
  19517. */
  19518. mxGuide.prototype.setVisible = function(visible)
  19519. {
  19520. if (this.guideX != null)
  19521. {
  19522. this.guideX.node.style.visibility = (visible) ? 'visible' : 'hidden';
  19523. }
  19524. if (this.guideY != null)
  19525. {
  19526. this.guideY.node.style.visibility = (visible) ? 'visible' : 'hidden';
  19527. }
  19528. };
  19529. /**
  19530. * Function: destroy
  19531. *
  19532. * Destroys all resources that this object uses.
  19533. */
  19534. mxGuide.prototype.destroy = function()
  19535. {
  19536. if (this.guideX != null)
  19537. {
  19538. this.guideX.destroy();
  19539. this.guideX = null;
  19540. }
  19541. if (this.guideY != null)
  19542. {
  19543. this.guideY.destroy();
  19544. this.guideY = null;
  19545. }
  19546. };
  19547. /**
  19548. * Copyright (c) 2006-2015, JGraph Ltd
  19549. * Copyright (c) 2006-2015, Gaudenz Alder
  19550. */
  19551. /**
  19552. * Class: mxShape
  19553. *
  19554. * Base class for all shapes. A shape in mxGraph is a
  19555. * separate implementation for SVG, VML and HTML. Which
  19556. * implementation to use is controlled by the <dialect>
  19557. * property which is assigned from within the <mxCellRenderer>
  19558. * when the shape is created. The dialect must be assigned
  19559. * for a shape, and it does normally depend on the browser and
  19560. * the confiuration of the graph (see <mxGraph> rendering hint).
  19561. *
  19562. * For each supported shape in SVG and VML, a corresponding
  19563. * shape exists in mxGraph, namely for text, image, rectangle,
  19564. * rhombus, ellipse and polyline. The other shapes are a
  19565. * combination of these shapes (eg. label and swimlane)
  19566. * or they consist of one or more (filled) path objects
  19567. * (eg. actor and cylinder). The HTML implementation is
  19568. * optional but may be required for a HTML-only view of
  19569. * the graph.
  19570. *
  19571. * Custom Shapes:
  19572. *
  19573. * To extend from this class, the basic code looks as follows.
  19574. * In the special case where the custom shape consists only of
  19575. * one filled region or one filled region and an additional stroke
  19576. * the <mxActor> and <mxCylinder> should be subclassed,
  19577. * respectively.
  19578. *
  19579. * (code)
  19580. * function CustomShape() { }
  19581. *
  19582. * CustomShape.prototype = new mxShape();
  19583. * CustomShape.prototype.constructor = CustomShape;
  19584. * (end)
  19585. *
  19586. * To register a custom shape in an existing graph instance,
  19587. * one must register the shape under a new name in the graph's
  19588. * cell renderer as follows:
  19589. *
  19590. * (code)
  19591. * mxCellRenderer.registerShape('customShape', CustomShape);
  19592. * (end)
  19593. *
  19594. * The second argument is the name of the constructor.
  19595. *
  19596. * In order to use the shape you can refer to the given name above
  19597. * in a stylesheet. For example, to change the shape for the default
  19598. * vertex style, the following code is used:
  19599. *
  19600. * (code)
  19601. * var style = graph.getStylesheet().getDefaultVertexStyle();
  19602. * style[mxConstants.STYLE_SHAPE] = 'customShape';
  19603. * (end)
  19604. *
  19605. * Constructor: mxShape
  19606. *
  19607. * Constructs a new shape.
  19608. */
  19609. function mxShape(stencil)
  19610. {
  19611. this.stencil = stencil;
  19612. this.initStyles();
  19613. };
  19614. /**
  19615. * Variable: dialect
  19616. *
  19617. * Holds the dialect in which the shape is to be painted.
  19618. * This can be one of the DIALECT constants in <mxConstants>.
  19619. */
  19620. mxShape.prototype.dialect = null;
  19621. /**
  19622. * Variable: scale
  19623. *
  19624. * Holds the scale in which the shape is being painted.
  19625. */
  19626. mxShape.prototype.scale = 1;
  19627. /**
  19628. * Variable: antiAlias
  19629. *
  19630. * Rendering hint for configuring the canvas.
  19631. */
  19632. mxShape.prototype.antiAlias = true;
  19633. /**
  19634. * Variable: minSvgStrokeWidth
  19635. *
  19636. * Minimum stroke width for SVG output.
  19637. */
  19638. mxShape.prototype.minSvgStrokeWidth = 1;
  19639. /**
  19640. * Variable: bounds
  19641. *
  19642. * Holds the <mxRectangle> that specifies the bounds of this shape.
  19643. */
  19644. mxShape.prototype.bounds = null;
  19645. /**
  19646. * Variable: points
  19647. *
  19648. * Holds the array of <mxPoints> that specify the points of this shape.
  19649. */
  19650. mxShape.prototype.points = null;
  19651. /**
  19652. * Variable: node
  19653. *
  19654. * Holds the outermost DOM node that represents this shape.
  19655. */
  19656. mxShape.prototype.node = null;
  19657. /**
  19658. * Variable: state
  19659. *
  19660. * Optional reference to the corresponding <mxCellState>.
  19661. */
  19662. mxShape.prototype.state = null;
  19663. /**
  19664. * Variable: style
  19665. *
  19666. * Optional reference to the style of the corresponding <mxCellState>.
  19667. */
  19668. mxShape.prototype.style = null;
  19669. /**
  19670. * Variable: boundingBox
  19671. *
  19672. * Contains the bounding box of the shape, that is, the smallest rectangle
  19673. * that includes all pixels of the shape.
  19674. */
  19675. mxShape.prototype.boundingBox = null;
  19676. /**
  19677. * Variable: stencil
  19678. *
  19679. * Holds the <mxStencil> that defines the shape.
  19680. */
  19681. mxShape.prototype.stencil = null;
  19682. /**
  19683. * Variable: svgStrokeTolerance
  19684. *
  19685. * Event-tolerance for SVG strokes (in px). Default is 8. This is only passed
  19686. * to the canvas in <createSvgCanvas> if <pointerEvents> is true.
  19687. */
  19688. mxShape.prototype.svgStrokeTolerance = 8;
  19689. /**
  19690. * Variable: pointerEvents
  19691. *
  19692. * Specifies if pointer events should be handled. Default is true.
  19693. */
  19694. mxShape.prototype.pointerEvents = true;
  19695. /**
  19696. * Variable: svgPointerEvents
  19697. *
  19698. * Specifies if pointer events should be handled. Default is true.
  19699. */
  19700. mxShape.prototype.svgPointerEvents = 'all';
  19701. /**
  19702. * Variable: shapePointerEvents
  19703. *
  19704. * Specifies if pointer events outside of shape should be handled. Default
  19705. * is false.
  19706. */
  19707. mxShape.prototype.shapePointerEvents = false;
  19708. /**
  19709. * Variable: stencilPointerEvents
  19710. *
  19711. * Specifies if pointer events outside of stencils should be handled. Default
  19712. * is false. Set this to true for backwards compatibility with the 1.x branch.
  19713. */
  19714. mxShape.prototype.stencilPointerEvents = false;
  19715. /**
  19716. * Variable: vmlScale
  19717. *
  19718. * Scale for improving the precision of VML rendering. Default is 1.
  19719. */
  19720. mxShape.prototype.vmlScale = 1;
  19721. /**
  19722. * Variable: outline
  19723. *
  19724. * Specifies if the shape should be drawn as an outline. This disables all
  19725. * fill colors and can be used to disable other drawing states that should
  19726. * not be painted for outlines. Default is false. This should be set before
  19727. * calling <apply>.
  19728. */
  19729. mxShape.prototype.outline = false;
  19730. /**
  19731. * Variable: visible
  19732. *
  19733. * Specifies if the shape is visible. Default is true.
  19734. */
  19735. mxShape.prototype.visible = true;
  19736. /**
  19737. * Variable: useSvgBoundingBox
  19738. *
  19739. * Allows to use the SVG bounding box in SVG. Default is false for performance
  19740. * reasons.
  19741. */
  19742. mxShape.prototype.useSvgBoundingBox = false;
  19743. /**
  19744. * Function: init
  19745. *
  19746. * Initializes the shape by creaing the DOM node using <create>
  19747. * and adding it into the given container.
  19748. *
  19749. * Parameters:
  19750. *
  19751. * container - DOM node that will contain the shape.
  19752. */
  19753. mxShape.prototype.init = function(container)
  19754. {
  19755. if (this.node == null)
  19756. {
  19757. this.node = this.create(container);
  19758. if (container != null)
  19759. {
  19760. container.appendChild(this.node);
  19761. }
  19762. }
  19763. };
  19764. /**
  19765. * Function: initStyles
  19766. *
  19767. * Sets the styles to their default values.
  19768. */
  19769. mxShape.prototype.initStyles = function(container)
  19770. {
  19771. this.strokewidth = 1;
  19772. this.rotation = 0;
  19773. this.opacity = 100;
  19774. this.fillOpacity = 100;
  19775. this.strokeOpacity = 100;
  19776. this.flipH = false;
  19777. this.flipV = false;
  19778. };
  19779. /**
  19780. * Function: isParseVml
  19781. *
  19782. * Specifies if any VML should be added via insertAdjacentHtml to the DOM. This
  19783. * is only needed in IE8 and only if the shape contains VML markup. This method
  19784. * returns true.
  19785. */
  19786. mxShape.prototype.isParseVml = function()
  19787. {
  19788. return true;
  19789. };
  19790. /**
  19791. * Function: isHtmlAllowed
  19792. *
  19793. * Returns true if HTML is allowed for this shape. This implementation always
  19794. * returns false.
  19795. */
  19796. mxShape.prototype.isHtmlAllowed = function()
  19797. {
  19798. return false;
  19799. };
  19800. /**
  19801. * Function: getSvgScreenOffset
  19802. *
  19803. * Returns 0, or 0.5 if <strokewidth> % 2 == 1.
  19804. */
  19805. mxShape.prototype.getSvgScreenOffset = function()
  19806. {
  19807. var sw = this.stencil && this.stencil.strokewidth != 'inherit' ? Number(this.stencil.strokewidth) : this.strokewidth;
  19808. return (mxUtils.mod(Math.max(1, Math.round(sw * this.scale)), 2) == 1) ? 0.5 : 0;
  19809. };
  19810. /**
  19811. * Function: create
  19812. *
  19813. * Creates and returns the DOM node(s) for the shape in
  19814. * the given container. This implementation invokes
  19815. * <createSvg>, <createHtml> or <createVml> depending
  19816. * on the <dialect> and style settings.
  19817. *
  19818. * Parameters:
  19819. *
  19820. * container - DOM node that will contain the shape.
  19821. */
  19822. mxShape.prototype.create = function(container)
  19823. {
  19824. var node = null;
  19825. if (container != null && container.ownerSVGElement != null)
  19826. {
  19827. node = this.createSvg(container);
  19828. }
  19829. else if (document.documentMode == 8 || !mxClient.IS_VML ||
  19830. (this.dialect != mxConstants.DIALECT_VML && this.isHtmlAllowed()))
  19831. {
  19832. node = this.createHtml(container);
  19833. }
  19834. else
  19835. {
  19836. node = this.createVml(container);
  19837. }
  19838. return node;
  19839. };
  19840. /**
  19841. * Function: createSvg
  19842. *
  19843. * Creates and returns the SVG node(s) to represent this shape.
  19844. */
  19845. mxShape.prototype.createSvg = function()
  19846. {
  19847. return document.createElementNS(mxConstants.NS_SVG, 'g');
  19848. };
  19849. /**
  19850. * Function: createVml
  19851. *
  19852. * Creates and returns the VML node to represent this shape.
  19853. */
  19854. mxShape.prototype.createVml = function()
  19855. {
  19856. var node = document.createElement(mxClient.VML_PREFIX + ':group');
  19857. node.style.position = 'absolute';
  19858. return node;
  19859. };
  19860. /**
  19861. * Function: createHtml
  19862. *
  19863. * Creates and returns the HTML DOM node(s) to represent
  19864. * this shape. This implementation falls back to <createVml>
  19865. * so that the HTML creation is optional.
  19866. */
  19867. mxShape.prototype.createHtml = function()
  19868. {
  19869. var node = document.createElement('div');
  19870. node.style.position = 'absolute';
  19871. return node;
  19872. };
  19873. /**
  19874. * Function: reconfigure
  19875. *
  19876. * Reconfigures this shape. This will update the colors etc in
  19877. * addition to the bounds or points.
  19878. */
  19879. mxShape.prototype.reconfigure = function()
  19880. {
  19881. this.redraw();
  19882. };
  19883. /**
  19884. * Function: redraw
  19885. *
  19886. * Creates and returns the SVG node(s) to represent this shape.
  19887. */
  19888. mxShape.prototype.redraw = function()
  19889. {
  19890. this.updateBoundsFromPoints();
  19891. if (this.visible && this.checkBounds())
  19892. {
  19893. this.node.style.visibility = 'visible';
  19894. this.clear();
  19895. if (this.node.nodeName == 'DIV' && (this.isHtmlAllowed() || !mxClient.IS_VML))
  19896. {
  19897. this.redrawHtmlShape();
  19898. }
  19899. else
  19900. {
  19901. this.redrawShape();
  19902. }
  19903. this.updateBoundingBox();
  19904. }
  19905. else
  19906. {
  19907. this.node.style.visibility = 'hidden';
  19908. this.boundingBox = null;
  19909. }
  19910. };
  19911. /**
  19912. * Function: clear
  19913. *
  19914. * Removes all child nodes and resets all CSS.
  19915. */
  19916. mxShape.prototype.clear = function()
  19917. {
  19918. if (this.node.ownerSVGElement != null)
  19919. {
  19920. while (this.node.lastChild != null)
  19921. {
  19922. this.node.removeChild(this.node.lastChild);
  19923. }
  19924. }
  19925. else
  19926. {
  19927. this.node.style.cssText = 'position:absolute;' + ((this.cursor != null) ?
  19928. ('cursor:' + this.cursor + ';') : '');
  19929. this.node.innerHTML = '';
  19930. }
  19931. };
  19932. /**
  19933. * Function: updateBoundsFromPoints
  19934. *
  19935. * Updates the bounds based on the points.
  19936. */
  19937. mxShape.prototype.updateBoundsFromPoints = function()
  19938. {
  19939. var pts = this.points;
  19940. if (pts != null && pts.length > 0 && pts[0] != null)
  19941. {
  19942. this.bounds = new mxRectangle(Number(pts[0].x), Number(pts[0].y), 1, 1);
  19943. for (var i = 1; i < this.points.length; i++)
  19944. {
  19945. if (pts[i] != null)
  19946. {
  19947. this.bounds.add(new mxRectangle(Number(pts[i].x), Number(pts[i].y), 1, 1));
  19948. }
  19949. }
  19950. }
  19951. };
  19952. /**
  19953. * Function: getLabelBounds
  19954. *
  19955. * Returns the <mxRectangle> for the label bounds of this shape, based on the
  19956. * given scaled and translated bounds of the shape. This method should not
  19957. * change the rectangle in-place. This implementation returns the given rect.
  19958. */
  19959. mxShape.prototype.getLabelBounds = function(rect)
  19960. {
  19961. var d = mxUtils.getValue(this.style, mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
  19962. var bounds = rect;
  19963. // Normalizes argument for getLabelMargins hook
  19964. if (d != mxConstants.DIRECTION_SOUTH && d != mxConstants.DIRECTION_NORTH &&
  19965. this.state != null && this.state.text != null &&
  19966. this.state.text.isPaintBoundsInverted())
  19967. {
  19968. bounds = bounds.clone();
  19969. var tmp = bounds.width;
  19970. bounds.width = bounds.height;
  19971. bounds.height = tmp;
  19972. }
  19973. var m = this.getLabelMargins(bounds);
  19974. if (m != null)
  19975. {
  19976. var flipH = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPH, false) == '1';
  19977. var flipV = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPV, false) == '1';
  19978. // Handles special case for vertical labels
  19979. if (this.state != null && this.state.text != null &&
  19980. this.state.text.isPaintBoundsInverted())
  19981. {
  19982. var tmp = m.x;
  19983. m.x = m.height;
  19984. m.height = m.width;
  19985. m.width = m.y;
  19986. m.y = tmp;
  19987. tmp = flipH;
  19988. flipH = flipV;
  19989. flipV = tmp;
  19990. }
  19991. return mxUtils.getDirectedBounds(rect, m, this.style, flipH, flipV);
  19992. }
  19993. return rect;
  19994. };
  19995. /**
  19996. * Function: getLabelMargins
  19997. *
  19998. * Returns the scaled top, left, bottom and right margin to be used for
  19999. * computing the label bounds as an <mxRectangle>, where the bottom and right
  20000. * margin are defined in the width and height of the rectangle, respectively.
  20001. */
  20002. mxShape.prototype.getLabelMargins= function(rect)
  20003. {
  20004. return null;
  20005. };
  20006. /**
  20007. * Function: checkBounds
  20008. *
  20009. * Returns true if the bounds are not null and all of its variables are numeric.
  20010. */
  20011. mxShape.prototype.checkBounds = function()
  20012. {
  20013. return (!isNaN(this.scale) && isFinite(this.scale) && this.scale > 0 &&
  20014. this.bounds != null && !isNaN(this.bounds.x) && !isNaN(this.bounds.y) &&
  20015. !isNaN(this.bounds.width) && !isNaN(this.bounds.height) &&
  20016. this.bounds.width > 0 && this.bounds.height > 0);
  20017. };
  20018. /**
  20019. * Function: createVmlGroup
  20020. *
  20021. * Returns the temporary element used for rendering in IE8 standards mode.
  20022. */
  20023. mxShape.prototype.createVmlGroup = function()
  20024. {
  20025. var node = document.createElement(mxClient.VML_PREFIX + ':group');
  20026. node.style.position = 'absolute';
  20027. node.style.width = this.node.style.width;
  20028. node.style.height = this.node.style.height;
  20029. return node;
  20030. };
  20031. /**
  20032. * Function: redrawShape
  20033. *
  20034. * Updates the SVG or VML shape.
  20035. */
  20036. mxShape.prototype.redrawShape = function()
  20037. {
  20038. var canvas = this.createCanvas();
  20039. if (canvas != null)
  20040. {
  20041. // Specifies if events should be handled
  20042. canvas.pointerEvents = this.pointerEvents;
  20043. this.paint(canvas);
  20044. if (this.node != canvas.root)
  20045. {
  20046. // Forces parsing in IE8 standards mode - slow! avoid
  20047. this.node.insertAdjacentHTML('beforeend', canvas.root.outerHTML);
  20048. }
  20049. if (this.node.nodeName == 'DIV' && document.documentMode == 8)
  20050. {
  20051. // Makes DIV transparent to events for IE8 in IE8 standards
  20052. // mode (Note: Does not work for IE9 in IE8 standards mode
  20053. // and not for IE11 in enterprise mode)
  20054. this.node.style.filter = '';
  20055. // Adds event transparency in IE8 standards
  20056. mxUtils.addTransparentBackgroundFilter(this.node);
  20057. }
  20058. this.destroyCanvas(canvas);
  20059. }
  20060. };
  20061. /**
  20062. * Function: createCanvas
  20063. *
  20064. * Creates a new canvas for drawing this shape. May return null.
  20065. */
  20066. mxShape.prototype.createCanvas = function()
  20067. {
  20068. var canvas = null;
  20069. // LATER: Check if reusing existing DOM nodes improves performance
  20070. if (this.node.ownerSVGElement != null)
  20071. {
  20072. canvas = this.createSvgCanvas();
  20073. }
  20074. else if (mxClient.IS_VML)
  20075. {
  20076. this.updateVmlContainer();
  20077. canvas = this.createVmlCanvas();
  20078. }
  20079. if (canvas != null && this.outline)
  20080. {
  20081. canvas.setStrokeWidth(this.strokewidth);
  20082. canvas.setStrokeColor(this.stroke);
  20083. if (this.isDashed != null)
  20084. {
  20085. canvas.setDashed(this.isDashed);
  20086. }
  20087. canvas.setStrokeWidth = function() {};
  20088. canvas.setStrokeColor = function() {};
  20089. canvas.setFillColor = function() {};
  20090. canvas.setGradient = function() {};
  20091. canvas.setDashed = function() {};
  20092. canvas.text = function() {};
  20093. }
  20094. return canvas;
  20095. };
  20096. /**
  20097. * Function: createSvgCanvas
  20098. *
  20099. * Creates and returns an <mxSvgCanvas2D> for rendering this shape.
  20100. */
  20101. mxShape.prototype.createSvgCanvas = function()
  20102. {
  20103. var canvas = new mxSvgCanvas2D(this.node, false);
  20104. canvas.strokeTolerance = (this.pointerEvents) ? this.svgStrokeTolerance : 0;
  20105. canvas.pointerEventsValue = this.svgPointerEvents;
  20106. var off = this.getSvgScreenOffset();
  20107. if (off != 0)
  20108. {
  20109. this.node.setAttribute('transform', 'translate(' + off + ',' + off + ')');
  20110. }
  20111. else
  20112. {
  20113. this.node.removeAttribute('transform');
  20114. }
  20115. canvas.minStrokeWidth = this.minSvgStrokeWidth;
  20116. if (!this.antiAlias)
  20117. {
  20118. // Rounds all numbers in the SVG output to integers
  20119. canvas.format = function(value)
  20120. {
  20121. return Math.round(parseFloat(value));
  20122. };
  20123. }
  20124. return canvas;
  20125. };
  20126. /**
  20127. * Function: createVmlCanvas
  20128. *
  20129. * Creates and returns an <mxVmlCanvas2D> for rendering this shape.
  20130. */
  20131. mxShape.prototype.createVmlCanvas = function()
  20132. {
  20133. // Workaround for VML rendering bug in IE8 standards mode
  20134. var node = (document.documentMode == 8 && this.isParseVml()) ? this.createVmlGroup() : this.node;
  20135. var canvas = new mxVmlCanvas2D(node, false);
  20136. if (node.tagUrn != '')
  20137. {
  20138. var w = Math.max(1, Math.round(this.bounds.width));
  20139. var h = Math.max(1, Math.round(this.bounds.height));
  20140. node.coordsize = (w * this.vmlScale) + ',' + (h * this.vmlScale);
  20141. canvas.scale(this.vmlScale);
  20142. canvas.vmlScale = this.vmlScale;
  20143. }
  20144. // Painting relative to top, left shape corner
  20145. var s = this.scale;
  20146. canvas.translate(-Math.round(this.bounds.x / s), -Math.round(this.bounds.y / s));
  20147. return canvas;
  20148. };
  20149. /**
  20150. * Function: updateVmlContainer
  20151. *
  20152. * Updates the bounds of the VML container.
  20153. */
  20154. mxShape.prototype.updateVmlContainer = function()
  20155. {
  20156. this.node.style.left = Math.round(this.bounds.x) + 'px';
  20157. this.node.style.top = Math.round(this.bounds.y) + 'px';
  20158. var w = Math.max(1, Math.round(this.bounds.width));
  20159. var h = Math.max(1, Math.round(this.bounds.height));
  20160. this.node.style.width = w + 'px';
  20161. this.node.style.height = h + 'px';
  20162. this.node.style.overflow = 'visible';
  20163. };
  20164. /**
  20165. * Function: redrawHtml
  20166. *
  20167. * Allow optimization by replacing VML with HTML.
  20168. */
  20169. mxShape.prototype.redrawHtmlShape = function()
  20170. {
  20171. // LATER: Refactor methods
  20172. this.updateHtmlBounds(this.node);
  20173. this.updateHtmlFilters(this.node);
  20174. this.updateHtmlColors(this.node);
  20175. };
  20176. /**
  20177. * Function: updateHtmlFilters
  20178. *
  20179. * Allow optimization by replacing VML with HTML.
  20180. */
  20181. mxShape.prototype.updateHtmlFilters = function(node)
  20182. {
  20183. var f = '';
  20184. if (this.opacity < 100)
  20185. {
  20186. f += 'alpha(opacity=' + (this.opacity) + ')';
  20187. }
  20188. if (this.isShadow)
  20189. {
  20190. // FIXME: Cannot implement shadow transparency with filter
  20191. f += 'progid:DXImageTransform.Microsoft.dropShadow (' +
  20192. 'OffX=\'' + Math.round(mxConstants.SHADOW_OFFSET_X * this.scale) + '\', ' +
  20193. 'OffY=\'' + Math.round(mxConstants.SHADOW_OFFSET_Y * this.scale) + '\', ' +
  20194. 'Color=\'' + mxConstants.VML_SHADOWCOLOR + '\')';
  20195. }
  20196. if (this.fill != null && this.fill != mxConstants.NONE && this.gradient && this.gradient != mxConstants.NONE)
  20197. {
  20198. var start = this.fill;
  20199. var end = this.gradient;
  20200. var type = '0';
  20201. var lookup = {east:0,south:1,west:2,north:3};
  20202. var dir = (this.direction != null) ? lookup[this.direction] : 0;
  20203. if (this.gradientDirection != null)
  20204. {
  20205. dir = mxUtils.mod(dir + lookup[this.gradientDirection] - 1, 4);
  20206. }
  20207. if (dir == 1)
  20208. {
  20209. type = '1';
  20210. var tmp = start;
  20211. start = end;
  20212. end = tmp;
  20213. }
  20214. else if (dir == 2)
  20215. {
  20216. var tmp = start;
  20217. start = end;
  20218. end = tmp;
  20219. }
  20220. else if (dir == 3)
  20221. {
  20222. type = '1';
  20223. }
  20224. f += 'progid:DXImageTransform.Microsoft.gradient(' +
  20225. 'startColorStr=\'' + start + '\', endColorStr=\'' + end +
  20226. '\', gradientType=\'' + type + '\')';
  20227. }
  20228. node.style.filter = f;
  20229. };
  20230. /**
  20231. * Function: mixedModeHtml
  20232. *
  20233. * Allow optimization by replacing VML with HTML.
  20234. */
  20235. mxShape.prototype.updateHtmlColors = function(node)
  20236. {
  20237. var color = this.stroke;
  20238. if (color != null && color != mxConstants.NONE)
  20239. {
  20240. node.style.borderColor = color;
  20241. if (this.isDashed)
  20242. {
  20243. node.style.borderStyle = 'dashed';
  20244. }
  20245. else if (this.strokewidth > 0)
  20246. {
  20247. node.style.borderStyle = 'solid';
  20248. }
  20249. node.style.borderWidth = Math.max(1, Math.ceil(this.strokewidth * this.scale)) + 'px';
  20250. }
  20251. else
  20252. {
  20253. node.style.borderWidth = '0px';
  20254. }
  20255. color = (this.outline) ? null : this.fill;
  20256. if (color != null && color != mxConstants.NONE)
  20257. {
  20258. node.style.backgroundColor = color;
  20259. node.style.backgroundImage = 'none';
  20260. }
  20261. else if (this.pointerEvents)
  20262. {
  20263. node.style.backgroundColor = 'transparent';
  20264. }
  20265. else if (document.documentMode == 8)
  20266. {
  20267. mxUtils.addTransparentBackgroundFilter(node);
  20268. }
  20269. else
  20270. {
  20271. this.setTransparentBackgroundImage(node);
  20272. }
  20273. };
  20274. /**
  20275. * Function: mixedModeHtml
  20276. *
  20277. * Allow optimization by replacing VML with HTML.
  20278. */
  20279. mxShape.prototype.updateHtmlBounds = function(node)
  20280. {
  20281. var sw = (document.documentMode >= 9) ? 0 : Math.ceil(this.strokewidth * this.scale);
  20282. node.style.borderWidth = Math.max(1, sw) + 'px';
  20283. node.style.overflow = 'hidden';
  20284. node.style.left = Math.round(this.bounds.x - sw / 2) + 'px';
  20285. node.style.top = Math.round(this.bounds.y - sw / 2) + 'px';
  20286. if (document.compatMode == 'CSS1Compat')
  20287. {
  20288. sw = -sw;
  20289. }
  20290. node.style.width = Math.round(Math.max(0, this.bounds.width + sw)) + 'px';
  20291. node.style.height = Math.round(Math.max(0, this.bounds.height + sw)) + 'px';
  20292. };
  20293. /**
  20294. * Function: destroyCanvas
  20295. *
  20296. * Destroys the given canvas which was used for drawing. This implementation
  20297. * increments the reference counts on all shared gradients used in the canvas.
  20298. */
  20299. mxShape.prototype.destroyCanvas = function(canvas)
  20300. {
  20301. // Manages reference counts
  20302. if (canvas instanceof mxSvgCanvas2D)
  20303. {
  20304. // Increments ref counts
  20305. for (var key in canvas.gradients)
  20306. {
  20307. var gradient = canvas.gradients[key];
  20308. if (gradient != null)
  20309. {
  20310. gradient.mxRefCount = (gradient.mxRefCount || 0) + 1;
  20311. }
  20312. }
  20313. this.releaseSvgGradients(this.oldGradients);
  20314. this.oldGradients = canvas.gradients;
  20315. }
  20316. };
  20317. /**
  20318. * Function: paint
  20319. *
  20320. * Generic rendering code.
  20321. */
  20322. mxShape.prototype.paint = function(c)
  20323. {
  20324. var strokeDrawn = false;
  20325. if (c != null && this.outline)
  20326. {
  20327. var stroke = c.stroke;
  20328. c.stroke = function()
  20329. {
  20330. strokeDrawn = true;
  20331. stroke.apply(this, arguments);
  20332. };
  20333. var fillAndStroke = c.fillAndStroke;
  20334. c.fillAndStroke = function()
  20335. {
  20336. strokeDrawn = true;
  20337. fillAndStroke.apply(this, arguments);
  20338. };
  20339. }
  20340. // Scale is passed-through to canvas
  20341. var s = this.scale;
  20342. var x = this.bounds.x / s;
  20343. var y = this.bounds.y / s;
  20344. var w = this.bounds.width / s;
  20345. var h = this.bounds.height / s;
  20346. if (this.isPaintBoundsInverted())
  20347. {
  20348. var t = (w - h) / 2;
  20349. x += t;
  20350. y -= t;
  20351. var tmp = w;
  20352. w = h;
  20353. h = tmp;
  20354. }
  20355. this.updateTransform(c, x, y, w, h);
  20356. this.configureCanvas(c, x, y, w, h);
  20357. // Adds background rectangle to capture events
  20358. var bg = null;
  20359. if ((this.stencil == null && this.points == null && this.shapePointerEvents) ||
  20360. (this.stencil != null && this.stencilPointerEvents))
  20361. {
  20362. var bb = this.createBoundingBox();
  20363. if (this.dialect == mxConstants.DIALECT_SVG)
  20364. {
  20365. bg = this.createTransparentSvgRectangle(bb.x, bb.y, bb.width, bb.height);
  20366. this.node.appendChild(bg);
  20367. }
  20368. else
  20369. {
  20370. var rect = c.createRect('rect', bb.x / s, bb.y / s, bb.width / s, bb.height / s);
  20371. rect.appendChild(c.createTransparentFill());
  20372. rect.stroked = 'false';
  20373. c.root.appendChild(rect);
  20374. }
  20375. }
  20376. if (this.stencil != null)
  20377. {
  20378. this.stencil.drawShape(c, this, x, y, w, h);
  20379. }
  20380. else
  20381. {
  20382. // Stencils have separate strokewidth
  20383. c.setStrokeWidth(this.strokewidth);
  20384. if (this.points != null)
  20385. {
  20386. // Paints edge shape
  20387. var pts = [];
  20388. for (var i = 0; i < this.points.length; i++)
  20389. {
  20390. if (this.points[i] != null)
  20391. {
  20392. pts.push(new mxPoint(this.points[i].x / s, this.points[i].y / s));
  20393. }
  20394. }
  20395. this.paintEdgeShape(c, pts);
  20396. }
  20397. else
  20398. {
  20399. // Paints vertex shape
  20400. this.paintVertexShape(c, x, y, w, h);
  20401. }
  20402. }
  20403. if (bg != null && c.state != null && c.state.transform != null)
  20404. {
  20405. bg.setAttribute('transform', c.state.transform);
  20406. }
  20407. // Draws highlight rectangle if no stroke was used
  20408. if (c != null && this.outline && !strokeDrawn)
  20409. {
  20410. c.rect(x, y, w, h);
  20411. c.stroke();
  20412. }
  20413. };
  20414. /**
  20415. * Function: configureCanvas
  20416. *
  20417. * Sets the state of the canvas for drawing the shape.
  20418. */
  20419. mxShape.prototype.configureCanvas = function(c, x, y, w, h)
  20420. {
  20421. var dash = null;
  20422. if (this.style != null)
  20423. {
  20424. dash = this.style['dashPattern'];
  20425. }
  20426. c.setAlpha(this.opacity / 100);
  20427. c.setFillAlpha(this.fillOpacity / 100);
  20428. c.setStrokeAlpha(this.strokeOpacity / 100);
  20429. // Sets alpha, colors and gradients
  20430. if (this.isShadow != null)
  20431. {
  20432. c.setShadow(this.isShadow);
  20433. }
  20434. // Dash pattern
  20435. if (this.isDashed != null)
  20436. {
  20437. c.setDashed(this.isDashed, (this.style != null) ?
  20438. mxUtils.getValue(this.style, mxConstants.STYLE_FIX_DASH, false) == 1 : false);
  20439. }
  20440. if (dash != null)
  20441. {
  20442. c.setDashPattern(dash);
  20443. }
  20444. if (this.fill != null && this.fill != mxConstants.NONE && this.gradient && this.gradient != mxConstants.NONE)
  20445. {
  20446. var b = this.getGradientBounds(c, x, y, w, h);
  20447. c.setGradient(this.fill, this.gradient, b.x, b.y, b.width, b.height, this.gradientDirection);
  20448. }
  20449. else
  20450. {
  20451. c.setFillColor(this.fill);
  20452. }
  20453. c.setStrokeColor(this.stroke);
  20454. };
  20455. /**
  20456. * Function: getGradientBounds
  20457. *
  20458. * Returns the bounding box for the gradient box for this shape.
  20459. */
  20460. mxShape.prototype.getGradientBounds = function(c, x, y, w, h)
  20461. {
  20462. return new mxRectangle(x, y, w, h);
  20463. };
  20464. /**
  20465. * Function: updateTransform
  20466. *
  20467. * Sets the scale and rotation on the given canvas.
  20468. */
  20469. mxShape.prototype.updateTransform = function(c, x, y, w, h)
  20470. {
  20471. // NOTE: Currently, scale is implemented in state and canvas. This will
  20472. // move to canvas in a later version, so that the states are unscaled
  20473. // and untranslated and do not need an update after zooming or panning.
  20474. c.scale(this.scale);
  20475. c.rotate(this.getShapeRotation(), this.flipH, this.flipV, x + w / 2, y + h / 2);
  20476. };
  20477. /**
  20478. * Function: paintVertexShape
  20479. *
  20480. * Paints the vertex shape.
  20481. */
  20482. mxShape.prototype.paintVertexShape = function(c, x, y, w, h)
  20483. {
  20484. this.paintBackground(c, x, y, w, h);
  20485. if (!this.outline || this.style == null || mxUtils.getValue(
  20486. this.style, mxConstants.STYLE_BACKGROUND_OUTLINE, 0) == 0)
  20487. {
  20488. c.setShadow(false);
  20489. this.paintForeground(c, x, y, w, h);
  20490. }
  20491. };
  20492. /**
  20493. * Function: paintBackground
  20494. *
  20495. * Hook for subclassers. This implementation is empty.
  20496. */
  20497. mxShape.prototype.paintBackground = function(c, x, y, w, h) { };
  20498. /**
  20499. * Function: paintForeground
  20500. *
  20501. * Hook for subclassers. This implementation is empty.
  20502. */
  20503. mxShape.prototype.paintForeground = function(c, x, y, w, h) { };
  20504. /**
  20505. * Function: paintEdgeShape
  20506. *
  20507. * Hook for subclassers. This implementation is empty.
  20508. */
  20509. mxShape.prototype.paintEdgeShape = function(c, pts) { };
  20510. /**
  20511. * Function: getArcSize
  20512. *
  20513. * Returns the arc size for the given dimension.
  20514. */
  20515. mxShape.prototype.getArcSize = function(w, h)
  20516. {
  20517. var r = 0;
  20518. if (mxUtils.getValue(this.style, mxConstants.STYLE_ABSOLUTE_ARCSIZE, 0) == '1')
  20519. {
  20520. r = Math.min(w / 2, Math.min(h / 2, mxUtils.getValue(this.style,
  20521. mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2));
  20522. }
  20523. else
  20524. {
  20525. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  20526. mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  20527. r = Math.min(w * f, h * f);
  20528. }
  20529. return r;
  20530. };
  20531. /**
  20532. * Function: paintGlassEffect
  20533. *
  20534. * Paints the glass gradient effect.
  20535. */
  20536. mxShape.prototype.paintGlassEffect = function(c, x, y, w, h, arc)
  20537. {
  20538. var sw = Math.ceil(this.strokewidth / 2);
  20539. var size = 0.4;
  20540. c.setGradient('#ffffff', '#ffffff', x, y, w, h * 0.6, 'south', 0.9, 0.1);
  20541. c.begin();
  20542. arc += 2 * sw;
  20543. if (this.isRounded)
  20544. {
  20545. c.moveTo(x - sw + arc, y - sw);
  20546. c.quadTo(x - sw, y - sw, x - sw, y - sw + arc);
  20547. c.lineTo(x - sw, y + h * size);
  20548. c.quadTo(x + w * 0.5, y + h * 0.7, x + w + sw, y + h * size);
  20549. c.lineTo(x + w + sw, y - sw + arc);
  20550. c.quadTo(x + w + sw, y - sw, x + w + sw - arc, y - sw);
  20551. }
  20552. else
  20553. {
  20554. c.moveTo(x - sw, y - sw);
  20555. c.lineTo(x - sw, y + h * size);
  20556. c.quadTo(x + w * 0.5, y + h * 0.7, x + w + sw, y + h * size);
  20557. c.lineTo(x + w + sw, y - sw);
  20558. }
  20559. c.close();
  20560. c.fill();
  20561. };
  20562. /**
  20563. * Function: addPoints
  20564. *
  20565. * Paints the given points with rounded corners.
  20566. */
  20567. mxShape.prototype.addPoints = function(c, pts, rounded, arcSize, close, exclude, initialMove)
  20568. {
  20569. if (pts != null && pts.length > 0)
  20570. {
  20571. initialMove = (initialMove != null) ? initialMove : true;
  20572. var pe = pts[pts.length - 1];
  20573. // Adds virtual waypoint in the center between start and end point
  20574. if (close && rounded)
  20575. {
  20576. pts = pts.slice();
  20577. var p0 = pts[0];
  20578. var wp = new mxPoint(pe.x + (p0.x - pe.x) / 2, pe.y + (p0.y - pe.y) / 2);
  20579. pts.splice(0, 0, wp);
  20580. }
  20581. var pt = pts[0];
  20582. var i = 1;
  20583. // Draws the line segments
  20584. if (initialMove)
  20585. {
  20586. c.moveTo(pt.x, pt.y);
  20587. }
  20588. else
  20589. {
  20590. c.lineTo(pt.x, pt.y);
  20591. }
  20592. while (i < ((close) ? pts.length : pts.length - 1))
  20593. {
  20594. var tmp = pts[mxUtils.mod(i, pts.length)];
  20595. var dx = pt.x - tmp.x;
  20596. var dy = pt.y - tmp.y;
  20597. if (rounded && (dx != 0 || dy != 0) && (exclude == null || mxUtils.indexOf(exclude, i - 1) < 0))
  20598. {
  20599. // Draws a line from the last point to the current
  20600. // point with a spacing of size off the current point
  20601. // into direction of the last point
  20602. var dist = Math.sqrt(dx * dx + dy * dy);
  20603. var nx1 = dx * Math.min(arcSize, dist / 2) / dist;
  20604. var ny1 = dy * Math.min(arcSize, dist / 2) / dist;
  20605. var x1 = tmp.x + nx1;
  20606. var y1 = tmp.y + ny1;
  20607. c.lineTo(x1, y1);
  20608. // Draws a curve from the last point to the current
  20609. // point with a spacing of size off the current point
  20610. // into direction of the next point
  20611. var next = pts[mxUtils.mod(i + 1, pts.length)];
  20612. // Uses next non-overlapping point
  20613. while (i < pts.length - 2 && Math.round(next.x - tmp.x) == 0 && Math.round(next.y - tmp.y) == 0)
  20614. {
  20615. next = pts[mxUtils.mod(i + 2, pts.length)];
  20616. i++;
  20617. }
  20618. dx = next.x - tmp.x;
  20619. dy = next.y - tmp.y;
  20620. dist = Math.max(1, Math.sqrt(dx * dx + dy * dy));
  20621. var nx2 = dx * Math.min(arcSize, dist / 2) / dist;
  20622. var ny2 = dy * Math.min(arcSize, dist / 2) / dist;
  20623. var x2 = tmp.x + nx2;
  20624. var y2 = tmp.y + ny2;
  20625. c.quadTo(tmp.x, tmp.y, x2, y2);
  20626. tmp = new mxPoint(x2, y2);
  20627. }
  20628. else
  20629. {
  20630. c.lineTo(tmp.x, tmp.y);
  20631. }
  20632. pt = tmp;
  20633. i++;
  20634. }
  20635. if (close)
  20636. {
  20637. c.close();
  20638. }
  20639. else
  20640. {
  20641. c.lineTo(pe.x, pe.y);
  20642. }
  20643. }
  20644. };
  20645. /**
  20646. * Function: resetStyles
  20647. *
  20648. * Resets all styles.
  20649. */
  20650. mxShape.prototype.resetStyles = function()
  20651. {
  20652. this.initStyles();
  20653. this.spacing = 0;
  20654. delete this.fill;
  20655. delete this.gradient;
  20656. delete this.gradientDirection;
  20657. delete this.stroke;
  20658. delete this.startSize;
  20659. delete this.endSize;
  20660. delete this.startArrow;
  20661. delete this.endArrow;
  20662. delete this.direction;
  20663. delete this.isShadow;
  20664. delete this.isDashed;
  20665. delete this.isRounded;
  20666. delete this.glass;
  20667. };
  20668. /**
  20669. * Function: apply
  20670. *
  20671. * Applies the style of the given <mxCellState> to the shape. This
  20672. * implementation assigns the following styles to local fields:
  20673. *
  20674. * - <mxConstants.STYLE_FILLCOLOR> => fill
  20675. * - <mxConstants.STYLE_GRADIENTCOLOR> => gradient
  20676. * - <mxConstants.STYLE_GRADIENT_DIRECTION> => gradientDirection
  20677. * - <mxConstants.STYLE_OPACITY> => opacity
  20678. * - <mxConstants.STYLE_FILL_OPACITY> => fillOpacity
  20679. * - <mxConstants.STYLE_STROKE_OPACITY> => strokeOpacity
  20680. * - <mxConstants.STYLE_STROKECOLOR> => stroke
  20681. * - <mxConstants.STYLE_STROKEWIDTH> => strokewidth
  20682. * - <mxConstants.STYLE_SHADOW> => isShadow
  20683. * - <mxConstants.STYLE_DASHED> => isDashed
  20684. * - <mxConstants.STYLE_SPACING> => spacing
  20685. * - <mxConstants.STYLE_STARTSIZE> => startSize
  20686. * - <mxConstants.STYLE_ENDSIZE> => endSize
  20687. * - <mxConstants.STYLE_ROUNDED> => isRounded
  20688. * - <mxConstants.STYLE_STARTARROW> => startArrow
  20689. * - <mxConstants.STYLE_ENDARROW> => endArrow
  20690. * - <mxConstants.STYLE_ROTATION> => rotation
  20691. * - <mxConstants.STYLE_DIRECTION> => direction
  20692. * - <mxConstants.STYLE_GLASS> => glass
  20693. *
  20694. * This keeps a reference to the <style>. If you need to keep a reference to
  20695. * the cell, you can override this method and store a local reference to
  20696. * state.cell or the <mxCellState> itself. If <outline> should be true, make
  20697. * sure to set it before calling this method.
  20698. *
  20699. * Parameters:
  20700. *
  20701. * state - <mxCellState> of the corresponding cell.
  20702. */
  20703. mxShape.prototype.apply = function(state)
  20704. {
  20705. this.state = state;
  20706. this.style = state.style;
  20707. if (this.style != null)
  20708. {
  20709. this.fill = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, this.fill);
  20710. this.gradient = mxUtils.getValue(this.style, mxConstants.STYLE_GRADIENTCOLOR, this.gradient);
  20711. this.gradientDirection = mxUtils.getValue(this.style, mxConstants.STYLE_GRADIENT_DIRECTION, this.gradientDirection);
  20712. this.opacity = mxUtils.getValue(this.style, mxConstants.STYLE_OPACITY, this.opacity);
  20713. this.fillOpacity = mxUtils.getValue(this.style, mxConstants.STYLE_FILL_OPACITY, this.fillOpacity);
  20714. this.strokeOpacity = mxUtils.getValue(this.style, mxConstants.STYLE_STROKE_OPACITY, this.strokeOpacity);
  20715. this.stroke = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, this.stroke);
  20716. this.strokewidth = mxUtils.getNumber(this.style, mxConstants.STYLE_STROKEWIDTH, this.strokewidth);
  20717. this.spacing = mxUtils.getValue(this.style, mxConstants.STYLE_SPACING, this.spacing);
  20718. this.startSize = mxUtils.getNumber(this.style, mxConstants.STYLE_STARTSIZE, this.startSize);
  20719. this.endSize = mxUtils.getNumber(this.style, mxConstants.STYLE_ENDSIZE, this.endSize);
  20720. this.startArrow = mxUtils.getValue(this.style, mxConstants.STYLE_STARTARROW, this.startArrow);
  20721. this.endArrow = mxUtils.getValue(this.style, mxConstants.STYLE_ENDARROW, this.endArrow);
  20722. this.rotation = mxUtils.getValue(this.style, mxConstants.STYLE_ROTATION, this.rotation);
  20723. this.direction = mxUtils.getValue(this.style, mxConstants.STYLE_DIRECTION, this.direction);
  20724. this.flipH = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPH, 0) == 1;
  20725. this.flipV = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPV, 0) == 1;
  20726. // Legacy support for stencilFlipH/V
  20727. if (this.stencil != null)
  20728. {
  20729. this.flipH = mxUtils.getValue(this.style, 'stencilFlipH', 0) == 1 || this.flipH;
  20730. this.flipV = mxUtils.getValue(this.style, 'stencilFlipV', 0) == 1 || this.flipV;
  20731. }
  20732. if (this.direction == mxConstants.DIRECTION_NORTH || this.direction == mxConstants.DIRECTION_SOUTH)
  20733. {
  20734. var tmp = this.flipH;
  20735. this.flipH = this.flipV;
  20736. this.flipV = tmp;
  20737. }
  20738. this.isShadow = mxUtils.getValue(this.style, mxConstants.STYLE_SHADOW, this.isShadow) == 1;
  20739. this.isDashed = mxUtils.getValue(this.style, mxConstants.STYLE_DASHED, this.isDashed) == 1;
  20740. this.isRounded = mxUtils.getValue(this.style, mxConstants.STYLE_ROUNDED, this.isRounded) == 1;
  20741. this.glass = mxUtils.getValue(this.style, mxConstants.STYLE_GLASS, this.glass) == 1;
  20742. if (this.fill == mxConstants.NONE)
  20743. {
  20744. this.fill = null;
  20745. }
  20746. if (this.gradient == mxConstants.NONE)
  20747. {
  20748. this.gradient = null;
  20749. }
  20750. if (this.stroke == mxConstants.NONE)
  20751. {
  20752. this.stroke = null;
  20753. }
  20754. }
  20755. };
  20756. /**
  20757. * Function: setCursor
  20758. *
  20759. * Sets the cursor on the given shape.
  20760. *
  20761. * Parameters:
  20762. *
  20763. * cursor - The cursor to be used.
  20764. */
  20765. mxShape.prototype.setCursor = function(cursor)
  20766. {
  20767. if (cursor == null)
  20768. {
  20769. cursor = '';
  20770. }
  20771. this.cursor = cursor;
  20772. if (this.node != null)
  20773. {
  20774. this.node.style.cursor = cursor;
  20775. }
  20776. };
  20777. /**
  20778. * Function: getCursor
  20779. *
  20780. * Returns the current cursor.
  20781. */
  20782. mxShape.prototype.getCursor = function()
  20783. {
  20784. return this.cursor;
  20785. };
  20786. /**
  20787. * Function: isRoundable
  20788. *
  20789. * Hook for subclassers.
  20790. */
  20791. mxShape.prototype.isRoundable = function()
  20792. {
  20793. return false;
  20794. };
  20795. /**
  20796. * Function: updateBoundingBox
  20797. *
  20798. * Updates the <boundingBox> for this shape using <createBoundingBox> and
  20799. * <augmentBoundingBox> and stores the result in <boundingBox>.
  20800. */
  20801. mxShape.prototype.updateBoundingBox = function()
  20802. {
  20803. // Tries to get bounding box from SVG subsystem
  20804. // LATER: Use getBoundingClientRect for fallback in VML
  20805. if (this.useSvgBoundingBox && this.node != null && this.node.ownerSVGElement != null)
  20806. {
  20807. try
  20808. {
  20809. var b = this.node.getBBox();
  20810. if (b.width > 0 && b.height > 0)
  20811. {
  20812. this.boundingBox = new mxRectangle(b.x, b.y, b.width, b.height);
  20813. // Adds strokeWidth
  20814. this.boundingBox.grow(this.strokewidth * this.scale / 2);
  20815. return;
  20816. }
  20817. }
  20818. catch(e)
  20819. {
  20820. // fallback to code below
  20821. }
  20822. }
  20823. if (this.bounds != null)
  20824. {
  20825. var bbox = this.createBoundingBox();
  20826. if (bbox != null)
  20827. {
  20828. this.augmentBoundingBox(bbox);
  20829. var rot = this.getShapeRotation();
  20830. if (rot != 0)
  20831. {
  20832. bbox = mxUtils.getBoundingBox(bbox, rot);
  20833. }
  20834. }
  20835. this.boundingBox = bbox;
  20836. }
  20837. };
  20838. /**
  20839. * Function: createBoundingBox
  20840. *
  20841. * Returns a new rectangle that represents the bounding box of the bare shape
  20842. * with no shadows or strokewidths.
  20843. */
  20844. mxShape.prototype.createBoundingBox = function()
  20845. {
  20846. var bb = this.bounds.clone();
  20847. if ((this.stencil != null && (this.direction == mxConstants.DIRECTION_NORTH ||
  20848. this.direction == mxConstants.DIRECTION_SOUTH)) || this.isPaintBoundsInverted())
  20849. {
  20850. bb.rotate90();
  20851. }
  20852. return bb;
  20853. };
  20854. /**
  20855. * Function: augmentBoundingBox
  20856. *
  20857. * Augments the bounding box with the strokewidth and shadow offsets.
  20858. */
  20859. mxShape.prototype.augmentBoundingBox = function(bbox)
  20860. {
  20861. if (this.isShadow)
  20862. {
  20863. bbox.width += Math.ceil(mxConstants.SHADOW_OFFSET_X * this.scale);
  20864. bbox.height += Math.ceil(mxConstants.SHADOW_OFFSET_Y * this.scale);
  20865. }
  20866. // Adds strokeWidth
  20867. bbox.grow(this.strokewidth * this.scale / 2);
  20868. };
  20869. /**
  20870. * Function: isPaintBoundsInverted
  20871. *
  20872. * Returns true if the bounds should be inverted.
  20873. */
  20874. mxShape.prototype.isPaintBoundsInverted = function()
  20875. {
  20876. // Stencil implements inversion via aspect
  20877. return this.stencil == null && (this.direction == mxConstants.DIRECTION_NORTH ||
  20878. this.direction == mxConstants.DIRECTION_SOUTH);
  20879. };
  20880. /**
  20881. * Function: getRotation
  20882. *
  20883. * Returns the rotation from the style.
  20884. */
  20885. mxShape.prototype.getRotation = function()
  20886. {
  20887. return (this.rotation != null) ? this.rotation : 0;
  20888. };
  20889. /**
  20890. * Function: getTextRotation
  20891. *
  20892. * Returns the rotation for the text label.
  20893. */
  20894. mxShape.prototype.getTextRotation = function()
  20895. {
  20896. var rot = this.getRotation();
  20897. if (mxUtils.getValue(this.style, mxConstants.STYLE_HORIZONTAL, 1) != 1)
  20898. {
  20899. rot += mxText.prototype.verticalTextRotation;
  20900. }
  20901. return rot;
  20902. };
  20903. /**
  20904. * Function: getShapeRotation
  20905. *
  20906. * Returns the actual rotation of the shape.
  20907. */
  20908. mxShape.prototype.getShapeRotation = function()
  20909. {
  20910. var rot = this.getRotation();
  20911. if (this.direction != null)
  20912. {
  20913. if (this.direction == mxConstants.DIRECTION_NORTH)
  20914. {
  20915. rot += 270;
  20916. }
  20917. else if (this.direction == mxConstants.DIRECTION_WEST)
  20918. {
  20919. rot += 180;
  20920. }
  20921. else if (this.direction == mxConstants.DIRECTION_SOUTH)
  20922. {
  20923. rot += 90;
  20924. }
  20925. }
  20926. return rot;
  20927. };
  20928. /**
  20929. * Function: createTransparentSvgRectangle
  20930. *
  20931. * Adds a transparent rectangle that catches all events.
  20932. */
  20933. mxShape.prototype.createTransparentSvgRectangle = function(x, y, w, h)
  20934. {
  20935. var rect = document.createElementNS(mxConstants.NS_SVG, 'rect');
  20936. rect.setAttribute('x', x);
  20937. rect.setAttribute('y', y);
  20938. rect.setAttribute('width', w);
  20939. rect.setAttribute('height', h);
  20940. rect.setAttribute('fill', 'none');
  20941. rect.setAttribute('stroke', 'none');
  20942. rect.setAttribute('pointer-events', 'all');
  20943. return rect;
  20944. };
  20945. /**
  20946. * Function: setTransparentBackgroundImage
  20947. *
  20948. * Sets a transparent background CSS style to catch all events.
  20949. *
  20950. * Paints the line shape.
  20951. */
  20952. mxShape.prototype.setTransparentBackgroundImage = function(node)
  20953. {
  20954. node.style.backgroundImage = 'url(\'' + mxClient.imageBasePath + '/transparent.gif\')';
  20955. };
  20956. /**
  20957. * Function: releaseSvgGradients
  20958. *
  20959. * Paints the line shape.
  20960. */
  20961. mxShape.prototype.releaseSvgGradients = function(grads)
  20962. {
  20963. if (grads != null)
  20964. {
  20965. for (var key in grads)
  20966. {
  20967. var gradient = grads[key];
  20968. if (gradient != null)
  20969. {
  20970. gradient.mxRefCount = (gradient.mxRefCount || 0) - 1;
  20971. if (gradient.mxRefCount == 0 && gradient.parentNode != null)
  20972. {
  20973. gradient.parentNode.removeChild(gradient);
  20974. }
  20975. }
  20976. }
  20977. }
  20978. };
  20979. /**
  20980. * Function: destroy
  20981. *
  20982. * Destroys the shape by removing it from the DOM and releasing the DOM
  20983. * node associated with the shape using <mxEvent.release>.
  20984. */
  20985. mxShape.prototype.destroy = function()
  20986. {
  20987. if (this.node != null)
  20988. {
  20989. mxEvent.release(this.node);
  20990. if (this.node.parentNode != null)
  20991. {
  20992. this.node.parentNode.removeChild(this.node);
  20993. }
  20994. this.node = null;
  20995. }
  20996. // Decrements refCount and removes unused
  20997. this.releaseSvgGradients(this.oldGradients);
  20998. this.oldGradients = null;
  20999. };
  21000. /**
  21001. * Copyright (c) 2006-2015, JGraph Ltd
  21002. * Copyright (c) 2006-2015, Gaudenz Alder
  21003. */
  21004. /**
  21005. * Class: mxStencil
  21006. *
  21007. * Implements a generic shape which is based on a XML node as a description.
  21008. *
  21009. * shape:
  21010. *
  21011. * The outer element is *shape*, that has attributes:
  21012. *
  21013. * - "name", string, required. The stencil name that uniquely identifies the shape.
  21014. * - "w" and "h" are optional decimal view bounds. This defines your co-ordinate
  21015. * system for the graphics operations in the shape. The default is 100,100.
  21016. * - "aspect", optional string. Either "variable", the default, or "fixed". Fixed
  21017. * means always render the shape with the aspect ratio defined by the ratio w/h.
  21018. * Variable causes the ratio to match that of the geometry of the current vertex.
  21019. * - "strokewidth", optional string. Either an integer or the string "inherit".
  21020. * "inherit" indicates that the strokeWidth of the cell is only changed on scaling,
  21021. * not on resizing. Default is "1".
  21022. * If numeric values are used, the strokeWidth of the cell is changed on both
  21023. * scaling and resizing and the value defines the multiple that is applied to
  21024. * the width.
  21025. *
  21026. * connections:
  21027. *
  21028. * If you want to define specific fixed connection points on the shape use the
  21029. * *connections* element. Each *constraint* element within connections defines
  21030. * a fixed connection point on the shape. Constraints have attributes:
  21031. *
  21032. * - "perimeter", required. 1 or 0. 0 sets the connection point where specified
  21033. * by x,y. 1 Causes the position of the connection point to be extrapolated from
  21034. * the center of the shape, through x,y to the point of intersection with the
  21035. * perimeter of the shape.
  21036. * - "x" and "y" are the position of the fixed point relative to the bounds of
  21037. * the shape. They can be automatically adjusted if perimeter=1. So, (0,0) is top
  21038. * left, (0.5,0.5) the center, (1,0.5) the center of the right hand edge of the
  21039. * bounds, etc. Values may be less than 0 or greater than 1 to be positioned
  21040. * outside of the shape.
  21041. * - "name", optional string. A unique identifier for the port on the shape.
  21042. *
  21043. * background and foreground:
  21044. *
  21045. * The path of the graphics drawing is split into two elements, *foreground* and
  21046. * *background*. The split is to define which part any shadow applied to the shape
  21047. * is derived from (the background). This, generally, means the background is the
  21048. * line tracing of the outside of the shape, but not always.
  21049. *
  21050. * Any stroke, fill or fillstroke of a background must be the first element of the
  21051. * foreground element, they must not be used within *background*. If the background
  21052. * is empty, this is not required.
  21053. *
  21054. * Because the background cannot have any fill or stroke, it can contain only one
  21055. * *path*, *rect*, *roundrect* or *ellipse* element (or none). It can also not
  21056. * include *image*, *text* or *include-shape*.
  21057. *
  21058. * Note that the state, styling and drawing in mxGraph stencils is very close in
  21059. * design to that of HTML 5 canvas. Tutorials on this subject, if you're not
  21060. * familiar with the topic, will give a good high-level introduction to the
  21061. * concepts used.
  21062. *
  21063. * State:
  21064. *
  21065. * Rendering within the foreground and background elements has the concept of
  21066. * state. There are two types of operations other than state save/load, styling
  21067. * and drawing. The styling operations change the current state, so you can save
  21068. * the current state with <save/> and pull the last saved state from the state
  21069. * stack using <restore/>.
  21070. *
  21071. * Styling:
  21072. *
  21073. * The elements that change colors within the current state all take a hash
  21074. * prefixed hex color code ("#FFEA80").
  21075. *
  21076. * - *strokecolor*, this sets the color that drawing paths will be rendered in
  21077. * when a stroke or fillstroke command is issued.
  21078. * - *fillcolor*, this sets the color that the inside of closed paths will be
  21079. * rendered in when a fill or fillstroke command is issued.
  21080. * - *fontcolor*, this sets the color that fonts are rendered in when text is drawn.
  21081. *
  21082. * *alpha* defines the degree of transparency used between 1.0 for fully opaque
  21083. * and 0.0 for fully transparent.
  21084. *
  21085. * *fillalpha* defines the degree of fill transparency used between 1.0 for fully
  21086. * opaque and 0.0 for fully transparent.
  21087. *
  21088. * *strokealpha* defines the degree of stroke transparency used between 1.0 for
  21089. * fully opaque and 0.0 for fully transparent.
  21090. *
  21091. * *strokewidth* defines the integer thickness of drawing elements rendered by
  21092. * stroking. Use fixed="1" to apply the value as-is, without scaling.
  21093. *
  21094. * *dashed* is "1" for dashing enabled and "0" for disabled.
  21095. *
  21096. * When *dashed* is enabled the current dash pattern, defined by *dashpattern*,
  21097. * is used on strokes. dashpattern is a sequence of space separated "on, off"
  21098. * lengths that define what distance to paint the stroke for, then what distance
  21099. * to paint nothing for, repeat... The default is "3 3". You could define a more
  21100. * complex pattern with "5 3 2 6", for example. Generally, it makes sense to have
  21101. * an even number of elements in the dashpattern, but that's not required.
  21102. *
  21103. * *linejoin*, *linecap* and *miterlimit* are best explained by the Mozilla page
  21104. * on Canvas styling (about halfway down). The values are all the same except we
  21105. * use "flat" for linecap, instead of Canvas' "butt".
  21106. *
  21107. * For font styling there are.
  21108. *
  21109. * - *fontsize*, an integer,
  21110. * - *fontstyle*, an ORed bit pattern of bold (1), italic (2) and underline (4),
  21111. * i.e bold underline is "5".
  21112. * - *fontfamily*, is a string defining the typeface to be used.
  21113. *
  21114. * Drawing:
  21115. *
  21116. * Most drawing is contained within a *path* element. Again, the graphic
  21117. * primitives are very similar to that of HTML 5 canvas.
  21118. *
  21119. * - *move* to attributes required decimals (x,y).
  21120. * - *line* to attributes required decimals (x,y).
  21121. * - *quad* to required decimals (x2,y2) via control point required decimals
  21122. * (x1,y1).
  21123. * - *curve* to required decimals (x3,y3), via control points required decimals
  21124. * (x1,y1) and (x2,y2).
  21125. * - *arc*, this doesn't follow the HTML Canvas signatures, instead it's a copy
  21126. * of the SVG arc command. The SVG specification documentation gives the best
  21127. * description of its behaviors. The attributes are named identically, they are
  21128. * decimals and all required.
  21129. * - *close* ends the current subpath and causes an automatic straight line to
  21130. * be drawn from the current point to the initial point of the current subpath.
  21131. *
  21132. * Complex drawing:
  21133. *
  21134. * In addition to the graphics primitive operations there are non-primitive
  21135. * operations. These provide an easy method to draw some basic shapes.
  21136. *
  21137. * - *rect*, attributes "x", "y", "w", "h", all required decimals
  21138. * - *roundrect*, attributes "x", "y", "w", "h", all required decimals. Also
  21139. * "arcsize" an optional decimal attribute defining how large, the corner curves
  21140. * are.
  21141. * - *ellipse*, attributes "x", "y", "w", "h", all required decimals.
  21142. *
  21143. * Note that these 3 shapes and all paths must be followed by either a fill,
  21144. * stroke, or fillstroke.
  21145. *
  21146. * Text:
  21147. *
  21148. * *text* elements have the following attributes.
  21149. *
  21150. * - "str", the text string to display, required.
  21151. * - "x" and "y", the decimal location (x,y) of the text element, required.
  21152. * - "align", the horizontal alignment of the text element, either "left",
  21153. * "center" or "right". Optional, default is "left".
  21154. * - "valign", the vertical alignment of the text element, either "top", "middle"
  21155. * or "bottom". Optional, default is "top".
  21156. * - "localized", 0 or 1, if 1 then the "str" actually contains a key to use to
  21157. * fetch the value out of mxResources. Optional, default is
  21158. * <mxStencil.defaultLocalized>.
  21159. * - "vertical", 0 or 1, if 1 the label is rendered vertically (rotated by 90
  21160. * degrees). Optional, default is 0.
  21161. * - "rotation", angle in degrees (0 to 360). The angle to rotate the text by.
  21162. * Optional, default is 0.
  21163. * - "align-shape", 0 or 1, if 0 ignore the rotation of the shape when setting
  21164. * the text rotation. Optional, default is 1.
  21165. *
  21166. * If <allowEval> is true, then the text content of the this element can define
  21167. * a function which is invoked with the shape as the only argument and returns
  21168. * the value for the text element (ignored if the str attribute is not null).
  21169. *
  21170. * Images:
  21171. *
  21172. * *image* elements can either be external URLs, or data URIs, where supported
  21173. * (not in IE 7-). Attributes are:
  21174. *
  21175. * - "src", required string. Either a data URI or URL.
  21176. * - "x", "y", required decimals. The (x,y) position of the image.
  21177. * - "w", "h", required decimals. The width and height of the image.
  21178. * - "flipH" and "flipV", optional 0 or 1. Whether to flip the image along the
  21179. * horizontal/vertical axis. Default is 0 for both.
  21180. *
  21181. * If <allowEval> is true, then the text content of the this element can define
  21182. * a function which is invoked with the shape as the only argument and returns
  21183. * the value for the image source (ignored if the src attribute is not null).
  21184. *
  21185. * Sub-shapes:
  21186. *
  21187. * *include-shape* allow stencils to be rendered within the current stencil by
  21188. * referencing the sub-stencil by name. Attributes are:
  21189. *
  21190. * - "name", required string. The unique shape name of the stencil.
  21191. * - "x", "y", "w", "h", required decimals. The (x,y) position of the sub-shape
  21192. * and its width and height.
  21193. *
  21194. * Constructor: mxStencil
  21195. *
  21196. * Constructs a new generic shape by setting <desc> to the given XML node and
  21197. * invoking <parseDescription> and <parseConstraints>.
  21198. *
  21199. * Parameters:
  21200. *
  21201. * desc - XML node that contains the stencil description.
  21202. */
  21203. function mxStencil(desc)
  21204. {
  21205. this.desc = desc;
  21206. this.parseDescription();
  21207. this.parseConstraints();
  21208. };
  21209. /**
  21210. * Extends mxShape.
  21211. */
  21212. mxUtils.extend(mxStencil, mxShape);
  21213. /**
  21214. * Variable: defaultLocalized
  21215. *
  21216. * Static global variable that specifies the default value for the localized
  21217. * attribute of the text element. Default is false.
  21218. */
  21219. mxStencil.defaultLocalized = false;
  21220. /**
  21221. * Function: allowEval
  21222. *
  21223. * Static global switch that specifies if the use of eval is allowed for
  21224. * evaluating text content and images. Default is false. Set this to true
  21225. * if stencils can not contain user input.
  21226. */
  21227. mxStencil.allowEval = false;
  21228. /**
  21229. * Variable: desc
  21230. *
  21231. * Holds the XML node with the stencil description.
  21232. */
  21233. mxStencil.prototype.desc = null;
  21234. /**
  21235. * Variable: constraints
  21236. *
  21237. * Holds an array of <mxConnectionConstraints> as defined in the shape.
  21238. */
  21239. mxStencil.prototype.constraints = null;
  21240. /**
  21241. * Variable: aspect
  21242. *
  21243. * Holds the aspect of the shape. Default is 'auto'.
  21244. */
  21245. mxStencil.prototype.aspect = null;
  21246. /**
  21247. * Variable: w0
  21248. *
  21249. * Holds the width of the shape. Default is 100.
  21250. */
  21251. mxStencil.prototype.w0 = null;
  21252. /**
  21253. * Variable: h0
  21254. *
  21255. * Holds the height of the shape. Default is 100.
  21256. */
  21257. mxStencil.prototype.h0 = null;
  21258. /**
  21259. * Variable: bgNodes
  21260. *
  21261. * Holds the XML node with the stencil description.
  21262. */
  21263. mxStencil.prototype.bgNode = null;
  21264. /**
  21265. * Variable: fgNodes
  21266. *
  21267. * Holds the XML node with the stencil description.
  21268. */
  21269. mxStencil.prototype.fgNode = null;
  21270. /**
  21271. * Variable: strokewidth
  21272. *
  21273. * Holds the strokewidth direction from the description.
  21274. */
  21275. mxStencil.prototype.strokewidth = null;
  21276. /**
  21277. * Function: parseDescription
  21278. *
  21279. * Reads <w0>, <h0>, <aspect>, <bgNodes> and <fgNodes> from <desc>.
  21280. */
  21281. mxStencil.prototype.parseDescription = function()
  21282. {
  21283. // LATER: Preprocess nodes for faster painting
  21284. this.fgNode = this.desc.getElementsByTagName('foreground')[0];
  21285. this.bgNode = this.desc.getElementsByTagName('background')[0];
  21286. this.w0 = Number(this.desc.getAttribute('w') || 100);
  21287. this.h0 = Number(this.desc.getAttribute('h') || 100);
  21288. // Possible values for aspect are: variable and fixed where
  21289. // variable means fill the available space and fixed means
  21290. // use w0 and h0 to compute the aspect.
  21291. var aspect = this.desc.getAttribute('aspect');
  21292. this.aspect = (aspect != null) ? aspect : 'variable';
  21293. // Possible values for strokewidth are all numbers and "inherit"
  21294. // where the inherit means take the value from the style (ie. the
  21295. // user-defined stroke-width). Note that the strokewidth is scaled
  21296. // by the minimum scaling that is used to draw the shape (sx, sy).
  21297. var sw = this.desc.getAttribute('strokewidth');
  21298. this.strokewidth = (sw != null) ? sw : '1';
  21299. };
  21300. /**
  21301. * Function: parseConstraints
  21302. *
  21303. * Reads the constraints from <desc> into <constraints> using
  21304. * <parseConstraint>.
  21305. */
  21306. mxStencil.prototype.parseConstraints = function()
  21307. {
  21308. var conns = this.desc.getElementsByTagName('connections')[0];
  21309. if (conns != null)
  21310. {
  21311. var tmp = mxUtils.getChildNodes(conns);
  21312. if (tmp != null && tmp.length > 0)
  21313. {
  21314. this.constraints = [];
  21315. for (var i = 0; i < tmp.length; i++)
  21316. {
  21317. this.constraints.push(this.parseConstraint(tmp[i]));
  21318. }
  21319. }
  21320. }
  21321. };
  21322. /**
  21323. * Function: parseConstraint
  21324. *
  21325. * Parses the given XML node and returns its <mxConnectionConstraint>.
  21326. */
  21327. mxStencil.prototype.parseConstraint = function(node)
  21328. {
  21329. var x = Number(node.getAttribute('x'));
  21330. var y = Number(node.getAttribute('y'));
  21331. var perimeter = node.getAttribute('perimeter') == '1';
  21332. var name = node.getAttribute('name');
  21333. return new mxConnectionConstraint(new mxPoint(x, y), perimeter, name);
  21334. };
  21335. /**
  21336. * Function: evaluateTextAttribute
  21337. *
  21338. * Gets the given attribute as a text. The return value from <evaluateAttribute>
  21339. * is used as a key to <mxResources.get> if the localized attribute in the text
  21340. * node is 1 or if <defaultLocalized> is true.
  21341. */
  21342. mxStencil.prototype.evaluateTextAttribute = function(node, attribute, shape)
  21343. {
  21344. var result = this.evaluateAttribute(node, attribute, shape);
  21345. var loc = node.getAttribute('localized');
  21346. if ((mxStencil.defaultLocalized && loc == null) || loc == '1')
  21347. {
  21348. result = mxResources.get(result);
  21349. }
  21350. return result;
  21351. };
  21352. /**
  21353. * Function: evaluateAttribute
  21354. *
  21355. * Gets the attribute for the given name from the given node. If the attribute
  21356. * does not exist then the text content of the node is evaluated and if it is
  21357. * a function it is invoked with <shape> as the only argument and the return
  21358. * value is used as the attribute value to be returned.
  21359. */
  21360. mxStencil.prototype.evaluateAttribute = function(node, attribute, shape)
  21361. {
  21362. var result = node.getAttribute(attribute);
  21363. if (result == null)
  21364. {
  21365. var text = mxUtils.getTextContent(node);
  21366. if (text != null && mxStencil.allowEval)
  21367. {
  21368. var funct = mxUtils.eval(text);
  21369. if (typeof(funct) == 'function')
  21370. {
  21371. result = funct(shape);
  21372. }
  21373. }
  21374. }
  21375. return result;
  21376. };
  21377. /**
  21378. * Function: drawShape
  21379. *
  21380. * Draws this stencil inside the given bounds.
  21381. */
  21382. mxStencil.prototype.drawShape = function(canvas, shape, x, y, w, h)
  21383. {
  21384. var stack = canvas.states.slice();
  21385. // TODO: Internal structure (array of special structs?), relative and absolute
  21386. // coordinates (eg. note shape, process vs star, actor etc.), text rendering
  21387. // and non-proportional scaling, how to implement pluggable edge shapes
  21388. // (start, segment, end blocks), pluggable markers, how to implement
  21389. // swimlanes (title area) with this API, add icon, horizontal/vertical
  21390. // label, indicator for all shapes, rotation
  21391. var direction = mxUtils.getValue(shape.style, mxConstants.STYLE_DIRECTION, null);
  21392. var aspect = this.computeAspect(shape.style, x, y, w, h, direction);
  21393. var minScale = Math.min(aspect.width, aspect.height);
  21394. var sw = (this.strokewidth == 'inherit') ?
  21395. Number(mxUtils.getNumber(shape.style, mxConstants.STYLE_STROKEWIDTH, 1)) :
  21396. Number(this.strokewidth) * minScale;
  21397. canvas.setStrokeWidth(sw);
  21398. // Draws a transparent rectangle for catching events
  21399. if (shape.style != null && mxUtils.getValue(shape.style, mxConstants.STYLE_POINTER_EVENTS, '0') == '1')
  21400. {
  21401. canvas.setStrokeColor(mxConstants.NONE);
  21402. canvas.rect(x, y, w, h);
  21403. canvas.stroke();
  21404. canvas.setStrokeColor(shape.stroke);
  21405. }
  21406. this.drawChildren(canvas, shape, x, y, w, h, this.bgNode, aspect, false, true);
  21407. this.drawChildren(canvas, shape, x, y, w, h, this.fgNode, aspect, true,
  21408. !shape.outline || shape.style == null || mxUtils.getValue(
  21409. shape.style, mxConstants.STYLE_BACKGROUND_OUTLINE, 0) == 0);
  21410. // Restores stack for unequal count of save/restore calls
  21411. if (canvas.states.length != stack.length)
  21412. {
  21413. canvas.states = stack;
  21414. }
  21415. };
  21416. /**
  21417. * Function: drawChildren
  21418. *
  21419. * Draws this stencil inside the given bounds.
  21420. */
  21421. mxStencil.prototype.drawChildren = function(canvas, shape, x, y, w, h, node, aspect, disableShadow, paint)
  21422. {
  21423. if (node != null && w > 0 && h > 0)
  21424. {
  21425. var tmp = node.firstChild;
  21426. while (tmp != null)
  21427. {
  21428. if (tmp.nodeType == mxConstants.NODETYPE_ELEMENT)
  21429. {
  21430. this.drawNode(canvas, shape, tmp, aspect, disableShadow, paint);
  21431. }
  21432. tmp = tmp.nextSibling;
  21433. }
  21434. }
  21435. };
  21436. /**
  21437. * Function: computeAspect
  21438. *
  21439. * Returns a rectangle that contains the offset in x and y and the horizontal
  21440. * and vertical scale in width and height used to draw this shape inside the
  21441. * given <mxRectangle>.
  21442. *
  21443. * Parameters:
  21444. *
  21445. * shape - <mxShape> to be drawn.
  21446. * bounds - <mxRectangle> that should contain the stencil.
  21447. * direction - Optional direction of the shape to be darwn.
  21448. */
  21449. mxStencil.prototype.computeAspect = function(shape, x, y, w, h, direction)
  21450. {
  21451. var x0 = x;
  21452. var y0 = y;
  21453. var sx = w / this.w0;
  21454. var sy = h / this.h0;
  21455. var inverse = (direction == mxConstants.DIRECTION_NORTH || direction == mxConstants.DIRECTION_SOUTH);
  21456. if (inverse)
  21457. {
  21458. sy = w / this.h0;
  21459. sx = h / this.w0;
  21460. var delta = (w - h) / 2;
  21461. x0 += delta;
  21462. y0 -= delta;
  21463. }
  21464. if (this.aspect == 'fixed')
  21465. {
  21466. sy = Math.min(sx, sy);
  21467. sx = sy;
  21468. // Centers the shape inside the available space
  21469. if (inverse)
  21470. {
  21471. x0 += (h - this.w0 * sx) / 2;
  21472. y0 += (w - this.h0 * sy) / 2;
  21473. }
  21474. else
  21475. {
  21476. x0 += (w - this.w0 * sx) / 2;
  21477. y0 += (h - this.h0 * sy) / 2;
  21478. }
  21479. }
  21480. return new mxRectangle(x0, y0, sx, sy);
  21481. };
  21482. /**
  21483. * Function: drawNode
  21484. *
  21485. * Draws this stencil inside the given bounds.
  21486. */
  21487. mxStencil.prototype.drawNode = function(canvas, shape, node, aspect, disableShadow, paint)
  21488. {
  21489. var name = node.nodeName;
  21490. var x0 = aspect.x;
  21491. var y0 = aspect.y;
  21492. var sx = aspect.width;
  21493. var sy = aspect.height;
  21494. var minScale = Math.min(sx, sy);
  21495. if (name == 'save')
  21496. {
  21497. canvas.save();
  21498. }
  21499. else if (name == 'restore')
  21500. {
  21501. canvas.restore();
  21502. }
  21503. else if (paint)
  21504. {
  21505. if (name == 'path')
  21506. {
  21507. canvas.begin();
  21508. var parseRegularly = true;
  21509. if (node.getAttribute('rounded') == '1')
  21510. {
  21511. parseRegularly = false;
  21512. var arcSize = Number(node.getAttribute('arcSize'));
  21513. var pointCount = 0;
  21514. var segs = [];
  21515. // Renders the elements inside the given path
  21516. var childNode = node.firstChild;
  21517. while (childNode != null)
  21518. {
  21519. if (childNode.nodeType == mxConstants.NODETYPE_ELEMENT)
  21520. {
  21521. var childName = childNode.nodeName;
  21522. if (childName == 'move' || childName == 'line')
  21523. {
  21524. if (childName == 'move' || segs.length == 0)
  21525. {
  21526. segs.push([]);
  21527. }
  21528. segs[segs.length - 1].push(new mxPoint(x0 + Number(childNode.getAttribute('x')) * sx,
  21529. y0 + Number(childNode.getAttribute('y')) * sy));
  21530. pointCount++;
  21531. }
  21532. else
  21533. {
  21534. //We only support move and line for rounded corners
  21535. parseRegularly = true;
  21536. break;
  21537. }
  21538. }
  21539. childNode = childNode.nextSibling;
  21540. }
  21541. if (!parseRegularly && pointCount > 0)
  21542. {
  21543. for (var i = 0; i < segs.length; i++)
  21544. {
  21545. var close = false, ps = segs[i][0], pe = segs[i][segs[i].length - 1];
  21546. if (ps.x == pe.x && ps.y == pe.y)
  21547. {
  21548. segs[i].pop();
  21549. close = true;
  21550. }
  21551. this.addPoints(canvas, segs[i], true, arcSize, close);
  21552. }
  21553. }
  21554. else
  21555. {
  21556. parseRegularly = true;
  21557. }
  21558. }
  21559. if (parseRegularly)
  21560. {
  21561. // Renders the elements inside the given path
  21562. var childNode = node.firstChild;
  21563. while (childNode != null)
  21564. {
  21565. if (childNode.nodeType == mxConstants.NODETYPE_ELEMENT)
  21566. {
  21567. this.drawNode(canvas, shape, childNode, aspect, disableShadow, paint);
  21568. }
  21569. childNode = childNode.nextSibling;
  21570. }
  21571. }
  21572. }
  21573. else if (name == 'close')
  21574. {
  21575. canvas.close();
  21576. }
  21577. else if (name == 'move')
  21578. {
  21579. canvas.moveTo(x0 + Number(node.getAttribute('x')) * sx, y0 + Number(node.getAttribute('y')) * sy);
  21580. }
  21581. else if (name == 'line')
  21582. {
  21583. canvas.lineTo(x0 + Number(node.getAttribute('x')) * sx, y0 + Number(node.getAttribute('y')) * sy);
  21584. }
  21585. else if (name == 'quad')
  21586. {
  21587. canvas.quadTo(x0 + Number(node.getAttribute('x1')) * sx,
  21588. y0 + Number(node.getAttribute('y1')) * sy,
  21589. x0 + Number(node.getAttribute('x2')) * sx,
  21590. y0 + Number(node.getAttribute('y2')) * sy);
  21591. }
  21592. else if (name == 'curve')
  21593. {
  21594. canvas.curveTo(x0 + Number(node.getAttribute('x1')) * sx,
  21595. y0 + Number(node.getAttribute('y1')) * sy,
  21596. x0 + Number(node.getAttribute('x2')) * sx,
  21597. y0 + Number(node.getAttribute('y2')) * sy,
  21598. x0 + Number(node.getAttribute('x3')) * sx,
  21599. y0 + Number(node.getAttribute('y3')) * sy);
  21600. }
  21601. else if (name == 'arc')
  21602. {
  21603. canvas.arcTo(Number(node.getAttribute('rx')) * sx,
  21604. Number(node.getAttribute('ry')) * sy,
  21605. Number(node.getAttribute('x-axis-rotation')),
  21606. Number(node.getAttribute('large-arc-flag')),
  21607. Number(node.getAttribute('sweep-flag')),
  21608. x0 + Number(node.getAttribute('x')) * sx,
  21609. y0 + Number(node.getAttribute('y')) * sy);
  21610. }
  21611. else if (name == 'rect')
  21612. {
  21613. canvas.rect(x0 + Number(node.getAttribute('x')) * sx,
  21614. y0 + Number(node.getAttribute('y')) * sy,
  21615. Number(node.getAttribute('w')) * sx,
  21616. Number(node.getAttribute('h')) * sy);
  21617. }
  21618. else if (name == 'roundrect')
  21619. {
  21620. var arcsize = Number(node.getAttribute('arcsize'));
  21621. if (arcsize == 0)
  21622. {
  21623. arcsize = mxConstants.RECTANGLE_ROUNDING_FACTOR * 100;
  21624. }
  21625. var w = Number(node.getAttribute('w')) * sx;
  21626. var h = Number(node.getAttribute('h')) * sy;
  21627. var factor = Number(arcsize) / 100;
  21628. var r = Math.min(w * factor, h * factor);
  21629. canvas.roundrect(x0 + Number(node.getAttribute('x')) * sx,
  21630. y0 + Number(node.getAttribute('y')) * sy,
  21631. w, h, r, r);
  21632. }
  21633. else if (name == 'ellipse')
  21634. {
  21635. canvas.ellipse(x0 + Number(node.getAttribute('x')) * sx,
  21636. y0 + Number(node.getAttribute('y')) * sy,
  21637. Number(node.getAttribute('w')) * sx,
  21638. Number(node.getAttribute('h')) * sy);
  21639. }
  21640. else if (name == 'image')
  21641. {
  21642. if (!shape.outline)
  21643. {
  21644. var src = this.evaluateAttribute(node, 'src', shape);
  21645. canvas.image(x0 + Number(node.getAttribute('x')) * sx,
  21646. y0 + Number(node.getAttribute('y')) * sy,
  21647. Number(node.getAttribute('w')) * sx,
  21648. Number(node.getAttribute('h')) * sy,
  21649. src, false, node.getAttribute('flipH') == '1',
  21650. node.getAttribute('flipV') == '1');
  21651. }
  21652. }
  21653. else if (name == 'text')
  21654. {
  21655. if (!shape.outline)
  21656. {
  21657. var str = this.evaluateTextAttribute(node, 'str', shape);
  21658. var rotation = node.getAttribute('vertical') == '1' ? -90 : 0;
  21659. if (node.getAttribute('align-shape') == '0')
  21660. {
  21661. var dr = shape.rotation;
  21662. // Depends on flipping
  21663. var flipH = mxUtils.getValue(shape.style, mxConstants.STYLE_FLIPH, 0) == 1;
  21664. var flipV = mxUtils.getValue(shape.style, mxConstants.STYLE_FLIPV, 0) == 1;
  21665. if (flipH && flipV)
  21666. {
  21667. rotation -= dr;
  21668. }
  21669. else if (flipH || flipV)
  21670. {
  21671. rotation += dr;
  21672. }
  21673. else
  21674. {
  21675. rotation -= dr;
  21676. }
  21677. }
  21678. rotation -= node.getAttribute('rotation');
  21679. canvas.text(x0 + Number(node.getAttribute('x')) * sx,
  21680. y0 + Number(node.getAttribute('y')) * sy,
  21681. 0, 0, str, node.getAttribute('align') || 'left',
  21682. node.getAttribute('valign') || 'top', false, '',
  21683. null, false, rotation);
  21684. }
  21685. }
  21686. else if (name == 'include-shape')
  21687. {
  21688. var stencil = mxStencilRegistry.getStencil(node.getAttribute('name'));
  21689. if (stencil != null)
  21690. {
  21691. var x = x0 + Number(node.getAttribute('x')) * sx;
  21692. var y = y0 + Number(node.getAttribute('y')) * sy;
  21693. var w = Number(node.getAttribute('w')) * sx;
  21694. var h = Number(node.getAttribute('h')) * sy;
  21695. stencil.drawShape(canvas, shape, x, y, w, h);
  21696. }
  21697. }
  21698. else if (name == 'fillstroke')
  21699. {
  21700. canvas.fillAndStroke();
  21701. }
  21702. else if (name == 'fill')
  21703. {
  21704. canvas.fill();
  21705. }
  21706. else if (name == 'stroke')
  21707. {
  21708. canvas.stroke();
  21709. }
  21710. else if (name == 'strokewidth')
  21711. {
  21712. var s = (node.getAttribute('fixed') == '1') ? 1 : minScale;
  21713. canvas.setStrokeWidth(Number(node.getAttribute('width')) * s);
  21714. }
  21715. else if (name == 'dashed')
  21716. {
  21717. canvas.setDashed(node.getAttribute('dashed') == '1');
  21718. }
  21719. else if (name == 'dashpattern')
  21720. {
  21721. var value = node.getAttribute('pattern');
  21722. if (value != null)
  21723. {
  21724. var tmp = value.split(' ');
  21725. var pat = [];
  21726. for (var i = 0; i < tmp.length; i++)
  21727. {
  21728. if (tmp[i].length > 0)
  21729. {
  21730. pat.push(Number(tmp[i]) * minScale);
  21731. }
  21732. }
  21733. value = pat.join(' ');
  21734. canvas.setDashPattern(value);
  21735. }
  21736. }
  21737. else if (name == 'strokecolor')
  21738. {
  21739. canvas.setStrokeColor(node.getAttribute('color'));
  21740. }
  21741. else if (name == 'linecap')
  21742. {
  21743. canvas.setLineCap(node.getAttribute('cap'));
  21744. }
  21745. else if (name == 'linejoin')
  21746. {
  21747. canvas.setLineJoin(node.getAttribute('join'));
  21748. }
  21749. else if (name == 'miterlimit')
  21750. {
  21751. canvas.setMiterLimit(Number(node.getAttribute('limit')));
  21752. }
  21753. else if (name == 'fillcolor')
  21754. {
  21755. canvas.setFillColor(node.getAttribute('color'));
  21756. }
  21757. else if (name == 'alpha')
  21758. {
  21759. canvas.setAlpha(node.getAttribute('alpha'));
  21760. }
  21761. else if (name == 'fillalpha')
  21762. {
  21763. canvas.setAlpha(node.getAttribute('alpha'));
  21764. }
  21765. else if (name == 'strokealpha')
  21766. {
  21767. canvas.setAlpha(node.getAttribute('alpha'));
  21768. }
  21769. else if (name == 'fontcolor')
  21770. {
  21771. canvas.setFontColor(node.getAttribute('color'));
  21772. }
  21773. else if (name == 'fontstyle')
  21774. {
  21775. canvas.setFontStyle(node.getAttribute('style'));
  21776. }
  21777. else if (name == 'fontfamily')
  21778. {
  21779. canvas.setFontFamily(node.getAttribute('family'));
  21780. }
  21781. else if (name == 'fontsize')
  21782. {
  21783. canvas.setFontSize(Number(node.getAttribute('size')) * minScale);
  21784. }
  21785. if (disableShadow && (name == 'fillstroke' || name == 'fill' || name == 'stroke'))
  21786. {
  21787. disableShadow = false;
  21788. canvas.setShadow(false);
  21789. }
  21790. }
  21791. };
  21792. /**
  21793. * Copyright (c) 2006-2015, JGraph Ltd
  21794. * Copyright (c) 2006-2015, Gaudenz Alder
  21795. *
  21796. * Code to add stencils.
  21797. *
  21798. * (code)
  21799. * var req = mxUtils.load('test/stencils.xml');
  21800. * var root = req.getDocumentElement();
  21801. * var shape = root.firstChild;
  21802. *
  21803. * while (shape != null)
  21804. * {
  21805. * if (shape.nodeType == mxConstants.NODETYPE_ELEMENT)
  21806. * {
  21807. * mxStencilRegistry.addStencil(shape.getAttribute('name'), new mxStencil(shape));
  21808. * }
  21809. *
  21810. * shape = shape.nextSibling;
  21811. * }
  21812. * (end)
  21813. */
  21814. var mxStencilRegistry =
  21815. {
  21816. /**
  21817. * Class: mxStencilRegistry
  21818. *
  21819. * A singleton class that provides a registry for stencils and the methods
  21820. * for painting those stencils onto a canvas or into a DOM.
  21821. */
  21822. stencils: {},
  21823. /**
  21824. * Function: addStencil
  21825. *
  21826. * Adds the given <mxStencil>.
  21827. */
  21828. addStencil: function(name, stencil)
  21829. {
  21830. mxStencilRegistry.stencils[name] = stencil;
  21831. },
  21832. /**
  21833. * Function: getStencil
  21834. *
  21835. * Returns the <mxStencil> for the given name.
  21836. */
  21837. getStencil: function(name)
  21838. {
  21839. return mxStencilRegistry.stencils[name];
  21840. }
  21841. };
  21842. /**
  21843. * Copyright (c) 2006-2015, JGraph Ltd
  21844. * Copyright (c) 2006-2015, Gaudenz Alder
  21845. */
  21846. var mxMarker =
  21847. {
  21848. /**
  21849. * Class: mxMarker
  21850. *
  21851. * A static class that implements all markers for VML and SVG using a
  21852. * registry. NOTE: The signatures in this class will change.
  21853. *
  21854. * Variable: markers
  21855. *
  21856. * Maps from markers names to functions to paint the markers.
  21857. */
  21858. markers: [],
  21859. /**
  21860. * Function: addMarker
  21861. *
  21862. * Adds a factory method that updates a given endpoint and returns a
  21863. * function to paint the marker onto the given canvas.
  21864. */
  21865. addMarker: function(type, funct)
  21866. {
  21867. mxMarker.markers[type] = funct;
  21868. },
  21869. /**
  21870. * Function: createMarker
  21871. *
  21872. * Returns a function to paint the given marker.
  21873. */
  21874. createMarker: function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  21875. {
  21876. var funct = mxMarker.markers[type];
  21877. return (funct != null) ? funct(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled) : null;
  21878. }
  21879. };
  21880. /**
  21881. * Adds the classic and block marker factory method.
  21882. */
  21883. (function()
  21884. {
  21885. function createArrow(widthFactor)
  21886. {
  21887. widthFactor = (widthFactor != null) ? widthFactor : 2;
  21888. return function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  21889. {
  21890. // The angle of the forward facing arrow sides against the x axis is
  21891. // 26.565 degrees, 1/sin(26.565) = 2.236 / 2 = 1.118 ( / 2 allows for
  21892. // only half the strokewidth is processed ).
  21893. var endOffsetX = unitX * sw * 1.118;
  21894. var endOffsetY = unitY * sw * 1.118;
  21895. unitX = unitX * (size + sw);
  21896. unitY = unitY * (size + sw);
  21897. var pt = pe.clone();
  21898. pt.x -= endOffsetX;
  21899. pt.y -= endOffsetY;
  21900. var f = (type != mxConstants.ARROW_CLASSIC && type != mxConstants.ARROW_CLASSIC_THIN) ? 1 : 3 / 4;
  21901. pe.x += -unitX * f - endOffsetX;
  21902. pe.y += -unitY * f - endOffsetY;
  21903. return function()
  21904. {
  21905. canvas.begin();
  21906. canvas.moveTo(pt.x, pt.y);
  21907. canvas.lineTo(pt.x - unitX - unitY / widthFactor, pt.y - unitY + unitX / widthFactor);
  21908. if (type == mxConstants.ARROW_CLASSIC || type == mxConstants.ARROW_CLASSIC_THIN)
  21909. {
  21910. canvas.lineTo(pt.x - unitX * 3 / 4, pt.y - unitY * 3 / 4);
  21911. }
  21912. canvas.lineTo(pt.x + unitY / widthFactor - unitX, pt.y - unitY - unitX / widthFactor);
  21913. canvas.close();
  21914. if (filled)
  21915. {
  21916. canvas.fillAndStroke();
  21917. }
  21918. else
  21919. {
  21920. canvas.stroke();
  21921. }
  21922. };
  21923. }
  21924. };
  21925. mxMarker.addMarker('classic', createArrow(2));
  21926. mxMarker.addMarker('classicThin', createArrow(3));
  21927. mxMarker.addMarker('block', createArrow(2));
  21928. mxMarker.addMarker('blockThin', createArrow(3));
  21929. function createOpenArrow(widthFactor)
  21930. {
  21931. widthFactor = (widthFactor != null) ? widthFactor : 2;
  21932. return function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  21933. {
  21934. // The angle of the forward facing arrow sides against the x axis is
  21935. // 26.565 degrees, 1/sin(26.565) = 2.236 / 2 = 1.118 ( / 2 allows for
  21936. // only half the strokewidth is processed ).
  21937. var endOffsetX = unitX * sw * 1.118;
  21938. var endOffsetY = unitY * sw * 1.118;
  21939. unitX = unitX * (size + sw);
  21940. unitY = unitY * (size + sw);
  21941. var pt = pe.clone();
  21942. pt.x -= endOffsetX;
  21943. pt.y -= endOffsetY;
  21944. pe.x += -endOffsetX * 2;
  21945. pe.y += -endOffsetY * 2;
  21946. return function()
  21947. {
  21948. canvas.begin();
  21949. canvas.moveTo(pt.x - unitX - unitY / widthFactor, pt.y - unitY + unitX / widthFactor);
  21950. canvas.lineTo(pt.x, pt.y);
  21951. canvas.lineTo(pt.x + unitY / widthFactor - unitX, pt.y - unitY - unitX / widthFactor);
  21952. canvas.stroke();
  21953. };
  21954. }
  21955. };
  21956. mxMarker.addMarker('open', createOpenArrow(2));
  21957. mxMarker.addMarker('openThin', createOpenArrow(3));
  21958. mxMarker.addMarker('oval', function(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  21959. {
  21960. var a = size / 2;
  21961. var pt = pe.clone();
  21962. pe.x -= unitX * a;
  21963. pe.y -= unitY * a;
  21964. return function()
  21965. {
  21966. canvas.ellipse(pt.x - a, pt.y - a, size, size);
  21967. if (filled)
  21968. {
  21969. canvas.fillAndStroke();
  21970. }
  21971. else
  21972. {
  21973. canvas.stroke();
  21974. }
  21975. };
  21976. });
  21977. function diamond(canvas, shape, type, pe, unitX, unitY, size, source, sw, filled)
  21978. {
  21979. // The angle of the forward facing arrow sides against the x axis is
  21980. // 45 degrees, 1/sin(45) = 1.4142 / 2 = 0.7071 ( / 2 allows for
  21981. // only half the strokewidth is processed ). Or 0.9862 for thin diamond.
  21982. // Note these values and the tk variable below are dependent, update
  21983. // both together (saves trig hard coding it).
  21984. var swFactor = (type == mxConstants.ARROW_DIAMOND) ? 0.7071 : 0.9862;
  21985. var endOffsetX = unitX * sw * swFactor;
  21986. var endOffsetY = unitY * sw * swFactor;
  21987. unitX = unitX * (size + sw);
  21988. unitY = unitY * (size + sw);
  21989. var pt = pe.clone();
  21990. pt.x -= endOffsetX;
  21991. pt.y -= endOffsetY;
  21992. pe.x += -unitX - endOffsetX;
  21993. pe.y += -unitY - endOffsetY;
  21994. // thickness factor for diamond
  21995. var tk = ((type == mxConstants.ARROW_DIAMOND) ? 2 : 3.4);
  21996. return function()
  21997. {
  21998. canvas.begin();
  21999. canvas.moveTo(pt.x, pt.y);
  22000. canvas.lineTo(pt.x - unitX / 2 - unitY / tk, pt.y + unitX / tk - unitY / 2);
  22001. canvas.lineTo(pt.x - unitX, pt.y - unitY);
  22002. canvas.lineTo(pt.x - unitX / 2 + unitY / tk, pt.y - unitY / 2 - unitX / tk);
  22003. canvas.close();
  22004. if (filled)
  22005. {
  22006. canvas.fillAndStroke();
  22007. }
  22008. else
  22009. {
  22010. canvas.stroke();
  22011. }
  22012. };
  22013. };
  22014. mxMarker.addMarker('diamond', diamond);
  22015. mxMarker.addMarker('diamondThin', diamond);
  22016. })();
  22017. /**
  22018. * Copyright (c) 2006-2015, JGraph Ltd
  22019. * Copyright (c) 2006-2015, Gaudenz Alder
  22020. */
  22021. /**
  22022. * Class: mxActor
  22023. *
  22024. * Extends <mxShape> to implement an actor shape. If a custom shape with one
  22025. * filled area is needed, then this shape's <redrawPath> should be overridden.
  22026. *
  22027. * Example:
  22028. *
  22029. * (code)
  22030. * function SampleShape() { }
  22031. *
  22032. * SampleShape.prototype = new mxActor();
  22033. * SampleShape.prototype.constructor = vsAseShape;
  22034. *
  22035. * mxCellRenderer.registerShape('sample', SampleShape);
  22036. * SampleShape.prototype.redrawPath = function(path, x, y, w, h)
  22037. * {
  22038. * path.moveTo(0, 0);
  22039. * path.lineTo(w, h);
  22040. * // ...
  22041. * path.close();
  22042. * }
  22043. * (end)
  22044. *
  22045. * This shape is registered under <mxConstants.SHAPE_ACTOR> in
  22046. * <mxCellRenderer>.
  22047. *
  22048. * Constructor: mxActor
  22049. *
  22050. * Constructs a new actor shape.
  22051. *
  22052. * Parameters:
  22053. *
  22054. * bounds - <mxRectangle> that defines the bounds. This is stored in
  22055. * <mxShape.bounds>.
  22056. * fill - String that defines the fill color. This is stored in <fill>.
  22057. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22058. * strokewidth - Optional integer that defines the stroke width. Default is
  22059. * 1. This is stored in <strokewidth>.
  22060. */
  22061. function mxActor(bounds, fill, stroke, strokewidth)
  22062. {
  22063. mxShape.call(this);
  22064. this.bounds = bounds;
  22065. this.fill = fill;
  22066. this.stroke = stroke;
  22067. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22068. };
  22069. /**
  22070. * Extends mxShape.
  22071. */
  22072. mxUtils.extend(mxActor, mxShape);
  22073. /**
  22074. * Function: paintVertexShape
  22075. *
  22076. * Redirects to redrawPath for subclasses to work.
  22077. */
  22078. mxActor.prototype.paintVertexShape = function(c, x, y, w, h)
  22079. {
  22080. c.translate(x, y);
  22081. c.begin();
  22082. this.redrawPath(c, x, y, w, h);
  22083. c.fillAndStroke();
  22084. };
  22085. /**
  22086. * Function: redrawPath
  22087. *
  22088. * Draws the path for this shape.
  22089. */
  22090. mxActor.prototype.redrawPath = function(c, x, y, w, h)
  22091. {
  22092. var width = w/3;
  22093. c.moveTo(0, h);
  22094. c.curveTo(0, 3 * h / 5, 0, 2 * h / 5, w / 2, 2 * h / 5);
  22095. c.curveTo(w / 2 - width, 2 * h / 5, w / 2 - width, 0, w / 2, 0);
  22096. c.curveTo(w / 2 + width, 0, w / 2 + width, 2 * h / 5, w / 2, 2 * h / 5);
  22097. c.curveTo(w, 2 * h / 5, w, 3 * h / 5, w, h);
  22098. c.close();
  22099. };
  22100. /**
  22101. * Copyright (c) 2006-2015, JGraph Ltd
  22102. * Copyright (c) 2006-2015, Gaudenz Alder
  22103. */
  22104. /**
  22105. * Class: mxCloud
  22106. *
  22107. * Extends <mxActor> to implement a cloud shape.
  22108. *
  22109. * This shape is registered under <mxConstants.SHAPE_CLOUD> in
  22110. * <mxCellRenderer>.
  22111. *
  22112. * Constructor: mxCloud
  22113. *
  22114. * Constructs a new cloud shape.
  22115. *
  22116. * Parameters:
  22117. *
  22118. * bounds - <mxRectangle> that defines the bounds. This is stored in
  22119. * <mxShape.bounds>.
  22120. * fill - String that defines the fill color. This is stored in <fill>.
  22121. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22122. * strokewidth - Optional integer that defines the stroke width. Default is
  22123. * 1. This is stored in <strokewidth>.
  22124. */
  22125. function mxCloud(bounds, fill, stroke, strokewidth)
  22126. {
  22127. mxActor.call(this);
  22128. this.bounds = bounds;
  22129. this.fill = fill;
  22130. this.stroke = stroke;
  22131. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22132. };
  22133. /**
  22134. * Extends mxActor.
  22135. */
  22136. mxUtils.extend(mxCloud, mxActor);
  22137. /**
  22138. * Function: redrawPath
  22139. *
  22140. * Draws the path for this shape.
  22141. */
  22142. mxCloud.prototype.redrawPath = function(c, x, y, w, h)
  22143. {
  22144. c.moveTo(0.25 * w, 0.25 * h);
  22145. c.curveTo(0.05 * w, 0.25 * h, 0, 0.5 * h, 0.16 * w, 0.55 * h);
  22146. c.curveTo(0, 0.66 * h, 0.18 * w, 0.9 * h, 0.31 * w, 0.8 * h);
  22147. c.curveTo(0.4 * w, h, 0.7 * w, h, 0.8 * w, 0.8 * h);
  22148. c.curveTo(w, 0.8 * h, w, 0.6 * h, 0.875 * w, 0.5 * h);
  22149. c.curveTo(w, 0.3 * h, 0.8 * w, 0.1 * h, 0.625 * w, 0.2 * h);
  22150. c.curveTo(0.5 * w, 0.05 * h, 0.3 * w, 0.05 * h, 0.25 * w, 0.25 * h);
  22151. c.close();
  22152. };
  22153. /**
  22154. * Copyright (c) 2006-2015, JGraph Ltd
  22155. * Copyright (c) 2006-2015, Gaudenz Alder
  22156. */
  22157. /**
  22158. * Class: mxRectangleShape
  22159. *
  22160. * Extends <mxShape> to implement a rectangle shape.
  22161. * This shape is registered under <mxConstants.SHAPE_RECTANGLE>
  22162. * in <mxCellRenderer>.
  22163. *
  22164. * Constructor: mxRectangleShape
  22165. *
  22166. * Constructs a new rectangle shape.
  22167. *
  22168. * Parameters:
  22169. *
  22170. * bounds - <mxRectangle> that defines the bounds. This is stored in
  22171. * <mxShape.bounds>.
  22172. * fill - String that defines the fill color. This is stored in <fill>.
  22173. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22174. * strokewidth - Optional integer that defines the stroke width. Default is
  22175. * 1. This is stored in <strokewidth>.
  22176. */
  22177. function mxRectangleShape(bounds, fill, stroke, strokewidth)
  22178. {
  22179. mxShape.call(this);
  22180. this.bounds = bounds;
  22181. this.fill = fill;
  22182. this.stroke = stroke;
  22183. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22184. };
  22185. /**
  22186. * Extends mxShape.
  22187. */
  22188. mxUtils.extend(mxRectangleShape, mxShape);
  22189. /**
  22190. * Function: isHtmlAllowed
  22191. *
  22192. * Returns true for non-rounded, non-rotated shapes with no glass gradient.
  22193. */
  22194. mxRectangleShape.prototype.isHtmlAllowed = function()
  22195. {
  22196. var events = true;
  22197. if (this.style != null)
  22198. {
  22199. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  22200. }
  22201. return !this.isRounded && !this.glass && this.rotation == 0 && (events ||
  22202. (this.fill != null && this.fill != mxConstants.NONE));
  22203. };
  22204. /**
  22205. * Function: paintBackground
  22206. *
  22207. * Generic background painting implementation.
  22208. */
  22209. mxRectangleShape.prototype.paintBackground = function(c, x, y, w, h)
  22210. {
  22211. var events = true;
  22212. if (this.style != null)
  22213. {
  22214. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  22215. }
  22216. if (events || (this.fill != null && this.fill != mxConstants.NONE) ||
  22217. (this.stroke != null && this.stroke != mxConstants.NONE))
  22218. {
  22219. if (!events && (this.fill == null || this.fill == mxConstants.NONE))
  22220. {
  22221. c.pointerEvents = false;
  22222. }
  22223. if (this.isRounded)
  22224. {
  22225. var r = 0;
  22226. if (mxUtils.getValue(this.style, mxConstants.STYLE_ABSOLUTE_ARCSIZE, 0) == '1')
  22227. {
  22228. r = Math.min(w / 2, Math.min(h / 2, mxUtils.getValue(this.style,
  22229. mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2));
  22230. }
  22231. else
  22232. {
  22233. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE,
  22234. mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  22235. r = Math.min(w * f, h * f);
  22236. }
  22237. c.roundrect(x, y, w, h, r, r);
  22238. }
  22239. else
  22240. {
  22241. c.rect(x, y, w, h);
  22242. }
  22243. c.fillAndStroke();
  22244. }
  22245. };
  22246. /**
  22247. * Function: isRoundable
  22248. *
  22249. * Adds roundable support.
  22250. */
  22251. mxRectangleShape.prototype.isRoundable = function(c, x, y, w, h)
  22252. {
  22253. return true;
  22254. };
  22255. /**
  22256. * Function: paintForeground
  22257. *
  22258. * Generic background painting implementation.
  22259. */
  22260. mxRectangleShape.prototype.paintForeground = function(c, x, y, w, h)
  22261. {
  22262. if (this.glass && !this.outline && this.fill != null && this.fill != mxConstants.NONE)
  22263. {
  22264. this.paintGlassEffect(c, x, y, w, h, this.getArcSize(w + this.strokewidth, h + this.strokewidth));
  22265. }
  22266. };
  22267. /**
  22268. * Copyright (c) 2006-2015, JGraph Ltd
  22269. * Copyright (c) 2006-2015, Gaudenz Alder
  22270. */
  22271. /**
  22272. * Class: mxEllipse
  22273. *
  22274. * Extends <mxShape> to implement an ellipse shape.
  22275. * This shape is registered under <mxConstants.SHAPE_ELLIPSE>
  22276. * in <mxCellRenderer>.
  22277. *
  22278. * Constructor: mxEllipse
  22279. *
  22280. * Constructs a new ellipse shape.
  22281. *
  22282. * Parameters:
  22283. *
  22284. * bounds - <mxRectangle> that defines the bounds. This is stored in
  22285. * <mxShape.bounds>.
  22286. * fill - String that defines the fill color. This is stored in <fill>.
  22287. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22288. * strokewidth - Optional integer that defines the stroke width. Default is
  22289. * 1. This is stored in <strokewidth>.
  22290. */
  22291. function mxEllipse(bounds, fill, stroke, strokewidth)
  22292. {
  22293. mxShape.call(this);
  22294. this.bounds = bounds;
  22295. this.fill = fill;
  22296. this.stroke = stroke;
  22297. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22298. };
  22299. /**
  22300. * Extends mxShape.
  22301. */
  22302. mxUtils.extend(mxEllipse, mxShape);
  22303. /**
  22304. * Function: paintVertexShape
  22305. *
  22306. * Paints the ellipse shape.
  22307. */
  22308. mxEllipse.prototype.paintVertexShape = function(c, x, y, w, h)
  22309. {
  22310. c.ellipse(x, y, w, h);
  22311. c.fillAndStroke();
  22312. };
  22313. /**
  22314. * Copyright (c) 2006-2015, JGraph Ltd
  22315. * Copyright (c) 2006-2015, Gaudenz Alder
  22316. */
  22317. /**
  22318. * Class: mxDoubleEllipse
  22319. *
  22320. * Extends <mxShape> to implement a double ellipse shape. This shape is
  22321. * registered under <mxConstants.SHAPE_DOUBLE_ELLIPSE> in <mxCellRenderer>.
  22322. * Use the following override to only fill the inner ellipse in this shape:
  22323. *
  22324. * (code)
  22325. * mxDoubleEllipse.prototype.paintVertexShape = function(c, x, y, w, h)
  22326. * {
  22327. * c.ellipse(x, y, w, h);
  22328. * c.stroke();
  22329. *
  22330. * var inset = mxUtils.getValue(this.style, mxConstants.STYLE_MARGIN, Math.min(3 + this.strokewidth, Math.min(w / 5, h / 5)));
  22331. * x += inset;
  22332. * y += inset;
  22333. * w -= 2 * inset;
  22334. * h -= 2 * inset;
  22335. *
  22336. * if (w > 0 && h > 0)
  22337. * {
  22338. * c.ellipse(x, y, w, h);
  22339. * }
  22340. *
  22341. * c.fillAndStroke();
  22342. * };
  22343. * (end)
  22344. *
  22345. * Constructor: mxDoubleEllipse
  22346. *
  22347. * Constructs a new ellipse shape.
  22348. *
  22349. * Parameters:
  22350. *
  22351. * bounds - <mxRectangle> that defines the bounds. This is stored in
  22352. * <mxShape.bounds>.
  22353. * fill - String that defines the fill color. This is stored in <fill>.
  22354. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22355. * strokewidth - Optional integer that defines the stroke width. Default is
  22356. * 1. This is stored in <strokewidth>.
  22357. */
  22358. function mxDoubleEllipse(bounds, fill, stroke, strokewidth)
  22359. {
  22360. mxShape.call(this);
  22361. this.bounds = bounds;
  22362. this.fill = fill;
  22363. this.stroke = stroke;
  22364. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22365. };
  22366. /**
  22367. * Extends mxShape.
  22368. */
  22369. mxUtils.extend(mxDoubleEllipse, mxShape);
  22370. /**
  22371. * Variable: vmlScale
  22372. *
  22373. * Scale for improving the precision of VML rendering. Default is 10.
  22374. */
  22375. mxDoubleEllipse.prototype.vmlScale = 10;
  22376. /**
  22377. * Function: paintBackground
  22378. *
  22379. * Paints the background.
  22380. */
  22381. mxDoubleEllipse.prototype.paintBackground = function(c, x, y, w, h)
  22382. {
  22383. c.ellipse(x, y, w, h);
  22384. c.fillAndStroke();
  22385. };
  22386. /**
  22387. * Function: paintForeground
  22388. *
  22389. * Paints the foreground.
  22390. */
  22391. mxDoubleEllipse.prototype.paintForeground = function(c, x, y, w, h)
  22392. {
  22393. if (!this.outline)
  22394. {
  22395. var margin = mxUtils.getValue(this.style, mxConstants.STYLE_MARGIN, Math.min(3 + this.strokewidth, Math.min(w / 5, h / 5)));
  22396. x += margin;
  22397. y += margin;
  22398. w -= 2 * margin;
  22399. h -= 2 * margin;
  22400. // FIXME: Rounding issues in IE8 standards mode (not in 1.x)
  22401. if (w > 0 && h > 0)
  22402. {
  22403. c.ellipse(x, y, w, h);
  22404. }
  22405. c.stroke();
  22406. }
  22407. };
  22408. /**
  22409. * Function: getLabelBounds
  22410. *
  22411. * Returns the bounds for the label.
  22412. */
  22413. mxDoubleEllipse.prototype.getLabelBounds = function(rect)
  22414. {
  22415. var margin = (mxUtils.getValue(this.style, mxConstants.STYLE_MARGIN, Math.min(3 + this.strokewidth,
  22416. Math.min(rect.width / 5 / this.scale, rect.height / 5 / this.scale)))) * this.scale;
  22417. return new mxRectangle(rect.x + margin, rect.y + margin, rect.width - 2 * margin, rect.height - 2 * margin);
  22418. };
  22419. /**
  22420. * Copyright (c) 2006-2015, JGraph Ltd
  22421. * Copyright (c) 2006-2015, Gaudenz Alder
  22422. */
  22423. /**
  22424. * Class: mxRhombus
  22425. *
  22426. * Extends <mxShape> to implement a rhombus (aka diamond) shape.
  22427. * This shape is registered under <mxConstants.SHAPE_RHOMBUS>
  22428. * in <mxCellRenderer>.
  22429. *
  22430. * Constructor: mxRhombus
  22431. *
  22432. * Constructs a new rhombus shape.
  22433. *
  22434. * Parameters:
  22435. *
  22436. * bounds - <mxRectangle> that defines the bounds. This is stored in
  22437. * <mxShape.bounds>.
  22438. * fill - String that defines the fill color. This is stored in <fill>.
  22439. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22440. * strokewidth - Optional integer that defines the stroke width. Default is
  22441. * 1. This is stored in <strokewidth>.
  22442. */
  22443. function mxRhombus(bounds, fill, stroke, strokewidth)
  22444. {
  22445. mxShape.call(this);
  22446. this.bounds = bounds;
  22447. this.fill = fill;
  22448. this.stroke = stroke;
  22449. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22450. };
  22451. /**
  22452. * Extends mxShape.
  22453. */
  22454. mxUtils.extend(mxRhombus, mxShape);
  22455. /**
  22456. * Function: isRoundable
  22457. *
  22458. * Adds roundable support.
  22459. */
  22460. mxRhombus.prototype.isRoundable = function()
  22461. {
  22462. return true;
  22463. };
  22464. /**
  22465. * Function: paintVertexShape
  22466. *
  22467. * Generic painting implementation.
  22468. */
  22469. mxRhombus.prototype.paintVertexShape = function(c, x, y, w, h)
  22470. {
  22471. var hw = w / 2;
  22472. var hh = h / 2;
  22473. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  22474. c.begin();
  22475. this.addPoints(c, [new mxPoint(x + hw, y), new mxPoint(x + w, y + hh), new mxPoint(x + hw, y + h),
  22476. new mxPoint(x, y + hh)], this.isRounded, arcSize, true);
  22477. c.fillAndStroke();
  22478. };
  22479. /**
  22480. * Copyright (c) 2006-2015, JGraph Ltd
  22481. * Copyright (c) 2006-2015, Gaudenz Alder
  22482. */
  22483. /**
  22484. * Class: mxPolyline
  22485. *
  22486. * Extends <mxShape> to implement a polyline (a line with multiple points).
  22487. * This shape is registered under <mxConstants.SHAPE_POLYLINE> in
  22488. * <mxCellRenderer>.
  22489. *
  22490. * Constructor: mxPolyline
  22491. *
  22492. * Constructs a new polyline shape.
  22493. *
  22494. * Parameters:
  22495. *
  22496. * points - Array of <mxPoints> that define the points. This is stored in
  22497. * <mxShape.points>.
  22498. * stroke - String that defines the stroke color. Default is 'black'. This is
  22499. * stored in <stroke>.
  22500. * strokewidth - Optional integer that defines the stroke width. Default is
  22501. * 1. This is stored in <strokewidth>.
  22502. */
  22503. function mxPolyline(points, stroke, strokewidth)
  22504. {
  22505. mxShape.call(this);
  22506. this.points = points;
  22507. this.stroke = stroke;
  22508. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22509. };
  22510. /**
  22511. * Extends mxShape.
  22512. */
  22513. mxUtils.extend(mxPolyline, mxShape);
  22514. /**
  22515. * Function: getRotation
  22516. *
  22517. * Returns 0.
  22518. */
  22519. mxPolyline.prototype.getRotation = function()
  22520. {
  22521. return 0;
  22522. };
  22523. /**
  22524. * Function: getShapeRotation
  22525. *
  22526. * Returns 0.
  22527. */
  22528. mxPolyline.prototype.getShapeRotation = function()
  22529. {
  22530. return 0;
  22531. };
  22532. /**
  22533. * Function: isPaintBoundsInverted
  22534. *
  22535. * Returns false.
  22536. */
  22537. mxPolyline.prototype.isPaintBoundsInverted = function()
  22538. {
  22539. return false;
  22540. };
  22541. /**
  22542. * Function: paintEdgeShape
  22543. *
  22544. * Paints the line shape.
  22545. */
  22546. mxPolyline.prototype.paintEdgeShape = function(c, pts)
  22547. {
  22548. var prev = c.pointerEventsValue;
  22549. c.pointerEventsValue = 'stroke';
  22550. if (this.style == null || this.style[mxConstants.STYLE_CURVED] != 1)
  22551. {
  22552. this.paintLine(c, pts, this.isRounded);
  22553. }
  22554. else
  22555. {
  22556. this.paintCurvedLine(c, pts);
  22557. }
  22558. c.pointerEventsValue = prev;
  22559. };
  22560. /**
  22561. * Function: paintLine
  22562. *
  22563. * Paints the line shape.
  22564. */
  22565. mxPolyline.prototype.paintLine = function(c, pts, rounded)
  22566. {
  22567. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  22568. c.begin();
  22569. this.addPoints(c, pts, rounded, arcSize, false);
  22570. c.stroke();
  22571. };
  22572. /**
  22573. * Function: paintLine
  22574. *
  22575. * Paints the line shape.
  22576. */
  22577. mxPolyline.prototype.paintCurvedLine = function(c, pts)
  22578. {
  22579. c.begin();
  22580. var pt = pts[0];
  22581. var n = pts.length;
  22582. c.moveTo(pt.x, pt.y);
  22583. for (var i = 1; i < n - 2; i++)
  22584. {
  22585. var p0 = pts[i];
  22586. var p1 = pts[i + 1];
  22587. var ix = (p0.x + p1.x) / 2;
  22588. var iy = (p0.y + p1.y) / 2;
  22589. c.quadTo(p0.x, p0.y, ix, iy);
  22590. }
  22591. var p0 = pts[n - 2];
  22592. var p1 = pts[n - 1];
  22593. c.quadTo(p0.x, p0.y, p1.x, p1.y);
  22594. c.stroke();
  22595. };
  22596. /**
  22597. * Copyright (c) 2006-2015, JGraph Ltd
  22598. * Copyright (c) 2006-2015, Gaudenz Alder
  22599. */
  22600. /**
  22601. * Class: mxArrow
  22602. *
  22603. * Extends <mxShape> to implement an arrow shape. (The shape
  22604. * is used to represent edges, not vertices.)
  22605. * This shape is registered under <mxConstants.SHAPE_ARROW>
  22606. * in <mxCellRenderer>.
  22607. *
  22608. * Constructor: mxArrow
  22609. *
  22610. * Constructs a new arrow shape.
  22611. *
  22612. * Parameters:
  22613. *
  22614. * points - Array of <mxPoints> that define the points. This is stored in
  22615. * <mxShape.points>.
  22616. * fill - String that defines the fill color. This is stored in <fill>.
  22617. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22618. * strokewidth - Optional integer that defines the stroke width. Default is
  22619. * 1. This is stored in <strokewidth>.
  22620. * arrowWidth - Optional integer that defines the arrow width. Default is
  22621. * <mxConstants.ARROW_WIDTH>. This is stored in <arrowWidth>.
  22622. * spacing - Optional integer that defines the spacing between the arrow shape
  22623. * and its endpoints. Default is <mxConstants.ARROW_SPACING>. This is stored in
  22624. * <spacing>.
  22625. * endSize - Optional integer that defines the size of the arrowhead. Default
  22626. * is <mxConstants.ARROW_SIZE>. This is stored in <endSize>.
  22627. */
  22628. function mxArrow(points, fill, stroke, strokewidth, arrowWidth, spacing, endSize)
  22629. {
  22630. mxShape.call(this);
  22631. this.points = points;
  22632. this.fill = fill;
  22633. this.stroke = stroke;
  22634. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22635. this.arrowWidth = (arrowWidth != null) ? arrowWidth : mxConstants.ARROW_WIDTH;
  22636. this.spacing = (spacing != null) ? spacing : mxConstants.ARROW_SPACING;
  22637. this.endSize = (endSize != null) ? endSize : mxConstants.ARROW_SIZE;
  22638. };
  22639. /**
  22640. * Extends mxShape.
  22641. */
  22642. mxUtils.extend(mxArrow, mxShape);
  22643. /**
  22644. * Function: augmentBoundingBox
  22645. *
  22646. * Augments the bounding box with the edge width and markers.
  22647. */
  22648. mxArrow.prototype.augmentBoundingBox = function(bbox)
  22649. {
  22650. mxShape.prototype.augmentBoundingBox.apply(this, arguments);
  22651. var w = Math.max(this.arrowWidth, this.endSize);
  22652. bbox.grow((w / 2 + this.strokewidth) * this.scale);
  22653. };
  22654. /**
  22655. * Function: paintEdgeShape
  22656. *
  22657. * Paints the line shape.
  22658. */
  22659. mxArrow.prototype.paintEdgeShape = function(c, pts)
  22660. {
  22661. // Geometry of arrow
  22662. var spacing = mxConstants.ARROW_SPACING;
  22663. var width = mxConstants.ARROW_WIDTH;
  22664. var arrow = mxConstants.ARROW_SIZE;
  22665. // Base vector (between end points)
  22666. var p0 = pts[0];
  22667. var pe = pts[pts.length - 1];
  22668. var dx = pe.x - p0.x;
  22669. var dy = pe.y - p0.y;
  22670. var dist = Math.sqrt(dx * dx + dy * dy);
  22671. var length = dist - 2 * spacing - arrow;
  22672. // Computes the norm and the inverse norm
  22673. var nx = dx / dist;
  22674. var ny = dy / dist;
  22675. var basex = length * nx;
  22676. var basey = length * ny;
  22677. var floorx = width * ny/3;
  22678. var floory = -width * nx/3;
  22679. // Computes points
  22680. var p0x = p0.x - floorx / 2 + spacing * nx;
  22681. var p0y = p0.y - floory / 2 + spacing * ny;
  22682. var p1x = p0x + floorx;
  22683. var p1y = p0y + floory;
  22684. var p2x = p1x + basex;
  22685. var p2y = p1y + basey;
  22686. var p3x = p2x + floorx;
  22687. var p3y = p2y + floory;
  22688. // p4 not necessary
  22689. var p5x = p3x - 3 * floorx;
  22690. var p5y = p3y - 3 * floory;
  22691. c.begin();
  22692. c.moveTo(p0x, p0y);
  22693. c.lineTo(p1x, p1y);
  22694. c.lineTo(p2x, p2y);
  22695. c.lineTo(p3x, p3y);
  22696. c.lineTo(pe.x - spacing * nx, pe.y - spacing * ny);
  22697. c.lineTo(p5x, p5y);
  22698. c.lineTo(p5x + floorx, p5y + floory);
  22699. c.close();
  22700. c.fillAndStroke();
  22701. };
  22702. /**
  22703. * Copyright (c) 2006-2015, JGraph Ltd
  22704. * Copyright (c) 2006-2015, Gaudenz Alder
  22705. */
  22706. /**
  22707. * Class: mxArrowConnector
  22708. *
  22709. * Extends <mxShape> to implement an new rounded arrow shape with support for
  22710. * waypoints and double arrows. (The shape is used to represent edges, not
  22711. * vertices.) This shape is registered under <mxConstants.SHAPE_ARROW_CONNECTOR>
  22712. * in <mxCellRenderer>.
  22713. *
  22714. * Constructor: mxArrowConnector
  22715. *
  22716. * Constructs a new arrow shape.
  22717. *
  22718. * Parameters:
  22719. *
  22720. * points - Array of <mxPoints> that define the points. This is stored in
  22721. * <mxShape.points>.
  22722. * fill - String that defines the fill color. This is stored in <fill>.
  22723. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22724. * strokewidth - Optional integer that defines the stroke width. Default is
  22725. * 1. This is stored in <strokewidth>.
  22726. * arrowWidth - Optional integer that defines the arrow width. Default is
  22727. * <mxConstants.ARROW_WIDTH>. This is stored in <arrowWidth>.
  22728. * spacing - Optional integer that defines the spacing between the arrow shape
  22729. * and its endpoints. Default is <mxConstants.ARROW_SPACING>. This is stored in
  22730. * <spacing>.
  22731. * endSize - Optional integer that defines the size of the arrowhead. Default
  22732. * is <mxConstants.ARROW_SIZE>. This is stored in <endSize>.
  22733. */
  22734. function mxArrowConnector(points, fill, stroke, strokewidth, arrowWidth, spacing, endSize)
  22735. {
  22736. mxShape.call(this);
  22737. this.points = points;
  22738. this.fill = fill;
  22739. this.stroke = stroke;
  22740. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  22741. this.arrowWidth = (arrowWidth != null) ? arrowWidth : mxConstants.ARROW_WIDTH;
  22742. this.arrowSpacing = (spacing != null) ? spacing : mxConstants.ARROW_SPACING;
  22743. this.startSize = mxConstants.ARROW_SIZE / 5;
  22744. this.endSize = mxConstants.ARROW_SIZE / 5;
  22745. };
  22746. /**
  22747. * Extends mxShape.
  22748. */
  22749. mxUtils.extend(mxArrowConnector, mxShape);
  22750. /**
  22751. * Variable: useSvgBoundingBox
  22752. *
  22753. * Allows to use the SVG bounding box in SVG. Default is false for performance
  22754. * reasons.
  22755. */
  22756. mxArrowConnector.prototype.useSvgBoundingBox = true;
  22757. /**
  22758. * Variable: resetStyles
  22759. *
  22760. * Overrides mxShape to reset spacing.
  22761. */
  22762. mxArrowConnector.prototype.resetStyles = function()
  22763. {
  22764. mxShape.prototype.resetStyles.apply(this, arguments);
  22765. this.arrowSpacing = mxConstants.ARROW_SPACING;
  22766. };
  22767. /**
  22768. * Overrides apply to get smooth transition from default start- and endsize.
  22769. */
  22770. mxArrowConnector.prototype.apply = function(state)
  22771. {
  22772. mxShape.prototype.apply.apply(this, arguments);
  22773. if (this.style != null)
  22774. {
  22775. this.startSize = mxUtils.getNumber(this.style, mxConstants.STYLE_STARTSIZE, mxConstants.ARROW_SIZE / 5) * 3;
  22776. this.endSize = mxUtils.getNumber(this.style, mxConstants.STYLE_ENDSIZE, mxConstants.ARROW_SIZE / 5) * 3;
  22777. }
  22778. };
  22779. /**
  22780. * Function: augmentBoundingBox
  22781. *
  22782. * Augments the bounding box with the edge width and markers.
  22783. */
  22784. mxArrowConnector.prototype.augmentBoundingBox = function(bbox)
  22785. {
  22786. mxShape.prototype.augmentBoundingBox.apply(this, arguments);
  22787. var w = this.getEdgeWidth();
  22788. if (this.isMarkerStart())
  22789. {
  22790. w = Math.max(w, this.getStartArrowWidth());
  22791. }
  22792. if (this.isMarkerEnd())
  22793. {
  22794. w = Math.max(w, this.getEndArrowWidth());
  22795. }
  22796. bbox.grow((w / 2 + this.strokewidth) * this.scale);
  22797. };
  22798. /**
  22799. * Function: paintEdgeShape
  22800. *
  22801. * Paints the line shape.
  22802. */
  22803. mxArrowConnector.prototype.paintEdgeShape = function(c, pts)
  22804. {
  22805. // Geometry of arrow
  22806. var strokeWidth = this.strokewidth;
  22807. if (this.outline)
  22808. {
  22809. strokeWidth = Math.max(1, mxUtils.getNumber(this.style, mxConstants.STYLE_STROKEWIDTH, this.strokewidth));
  22810. }
  22811. var startWidth = this.getStartArrowWidth() + strokeWidth;
  22812. var endWidth = this.getEndArrowWidth() + strokeWidth;
  22813. var edgeWidth = this.outline ? this.getEdgeWidth() + strokeWidth : this.getEdgeWidth();
  22814. var openEnded = this.isOpenEnded();
  22815. var markerStart = this.isMarkerStart();
  22816. var markerEnd = this.isMarkerEnd();
  22817. var spacing = (openEnded) ? 0 : this.arrowSpacing + strokeWidth / 2;
  22818. var startSize = this.startSize + strokeWidth;
  22819. var endSize = this.endSize + strokeWidth;
  22820. var isRounded = this.isArrowRounded();
  22821. // Base vector (between first points)
  22822. var pe = pts[pts.length - 1];
  22823. // Finds first non-overlapping point
  22824. var i0 = 1;
  22825. while (i0 < pts.length - 1 && pts[i0].x == pts[0].x && pts[i0].y == pts[0].y)
  22826. {
  22827. i0++;
  22828. }
  22829. var dx = pts[i0].x - pts[0].x;
  22830. var dy = pts[i0].y - pts[0].y;
  22831. var dist = Math.sqrt(dx * dx + dy * dy);
  22832. if (dist == 0)
  22833. {
  22834. return;
  22835. }
  22836. // Computes the norm and the inverse norm
  22837. var nx = dx / dist;
  22838. var nx2, nx1 = nx;
  22839. var ny = dy / dist;
  22840. var ny2, ny1 = ny;
  22841. var orthx = edgeWidth * ny;
  22842. var orthy = -edgeWidth * nx;
  22843. // Stores the inbound function calls in reverse order in fns
  22844. var fns = [];
  22845. if (isRounded)
  22846. {
  22847. c.setLineJoin('round');
  22848. }
  22849. else if (pts.length > 2)
  22850. {
  22851. // Only mitre if there are waypoints
  22852. c.setMiterLimit(1.42);
  22853. }
  22854. c.begin();
  22855. var startNx = nx;
  22856. var startNy = ny;
  22857. if (markerStart && !openEnded)
  22858. {
  22859. this.paintMarker(c, pts[0].x, pts[0].y, nx, ny, startSize, startWidth, edgeWidth, spacing, true);
  22860. }
  22861. else
  22862. {
  22863. var outStartX = pts[0].x + orthx / 2 + spacing * nx;
  22864. var outStartY = pts[0].y + orthy / 2 + spacing * ny;
  22865. var inEndX = pts[0].x - orthx / 2 + spacing * nx;
  22866. var inEndY = pts[0].y - orthy / 2 + spacing * ny;
  22867. if (openEnded)
  22868. {
  22869. c.moveTo(outStartX, outStartY);
  22870. fns.push(function()
  22871. {
  22872. c.lineTo(inEndX, inEndY);
  22873. });
  22874. }
  22875. else
  22876. {
  22877. c.moveTo(inEndX, inEndY);
  22878. c.lineTo(outStartX, outStartY);
  22879. }
  22880. }
  22881. var dx1 = 0;
  22882. var dy1 = 0;
  22883. var dist1 = 0;
  22884. for (var i = 0; i < pts.length - 2; i++)
  22885. {
  22886. // Work out in which direction the line is bending
  22887. var pos = mxUtils.relativeCcw(pts[i].x, pts[i].y, pts[i+1].x, pts[i+1].y, pts[i+2].x, pts[i+2].y);
  22888. dx1 = pts[i+2].x - pts[i+1].x;
  22889. dy1 = pts[i+2].y - pts[i+1].y;
  22890. dist1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
  22891. if (dist1 != 0)
  22892. {
  22893. nx1 = dx1 / dist1;
  22894. ny1 = dy1 / dist1;
  22895. var tmp1 = nx * nx1 + ny * ny1;
  22896. var tmp = Math.max(Math.sqrt((tmp1 + 1) / 2), 0.04);
  22897. // Work out the normal orthogonal to the line through the control point and the edge sides intersection
  22898. nx2 = (nx + nx1);
  22899. ny2 = (ny + ny1);
  22900. var dist2 = Math.sqrt(nx2 * nx2 + ny2 * ny2);
  22901. if (dist2 != 0)
  22902. {
  22903. nx2 = nx2 / dist2;
  22904. ny2 = ny2 / dist2;
  22905. // Higher strokewidths require a larger minimum bend, 0.35 covers all but the most extreme cases
  22906. var strokeWidthFactor = Math.max(tmp, Math.min(this.strokewidth / 200 + 0.04, 0.35));
  22907. var angleFactor = (pos != 0 && isRounded) ? Math.max(0.1, strokeWidthFactor) : Math.max(tmp, 0.06);
  22908. var outX = pts[i+1].x + ny2 * edgeWidth / 2 / angleFactor;
  22909. var outY = pts[i+1].y - nx2 * edgeWidth / 2 / angleFactor;
  22910. var inX = pts[i+1].x - ny2 * edgeWidth / 2 / angleFactor;
  22911. var inY = pts[i+1].y + nx2 * edgeWidth / 2 / angleFactor;
  22912. if (pos == 0 || !isRounded)
  22913. {
  22914. // If the two segments are aligned, or if we're not drawing curved sections between segments
  22915. // just draw straight to the intersection point
  22916. c.lineTo(outX, outY);
  22917. (function(x, y)
  22918. {
  22919. fns.push(function()
  22920. {
  22921. c.lineTo(x, y);
  22922. });
  22923. })(inX, inY);
  22924. }
  22925. else if (pos == -1)
  22926. {
  22927. var c1x = inX + ny * edgeWidth;
  22928. var c1y = inY - nx * edgeWidth;
  22929. var c2x = inX + ny1 * edgeWidth;
  22930. var c2y = inY - nx1 * edgeWidth;
  22931. c.lineTo(c1x, c1y);
  22932. c.quadTo(outX, outY, c2x, c2y);
  22933. (function(x, y)
  22934. {
  22935. fns.push(function()
  22936. {
  22937. c.lineTo(x, y);
  22938. });
  22939. })(inX, inY);
  22940. }
  22941. else
  22942. {
  22943. c.lineTo(outX, outY);
  22944. (function(x, y)
  22945. {
  22946. var c1x = outX - ny * edgeWidth;
  22947. var c1y = outY + nx * edgeWidth;
  22948. var c2x = outX - ny1 * edgeWidth;
  22949. var c2y = outY + nx1 * edgeWidth;
  22950. fns.push(function()
  22951. {
  22952. c.quadTo(x, y, c1x, c1y);
  22953. });
  22954. fns.push(function()
  22955. {
  22956. c.lineTo(c2x, c2y);
  22957. });
  22958. })(inX, inY);
  22959. }
  22960. nx = nx1;
  22961. ny = ny1;
  22962. }
  22963. }
  22964. }
  22965. orthx = edgeWidth * ny1;
  22966. orthy = - edgeWidth * nx1;
  22967. if (markerEnd && !openEnded)
  22968. {
  22969. this.paintMarker(c, pe.x, pe.y, -nx, -ny, endSize, endWidth, edgeWidth, spacing, false);
  22970. }
  22971. else
  22972. {
  22973. c.lineTo(pe.x - spacing * nx1 + orthx / 2, pe.y - spacing * ny1 + orthy / 2);
  22974. var inStartX = pe.x - spacing * nx1 - orthx / 2;
  22975. var inStartY = pe.y - spacing * ny1 - orthy / 2;
  22976. if (!openEnded)
  22977. {
  22978. c.lineTo(inStartX, inStartY);
  22979. }
  22980. else
  22981. {
  22982. c.moveTo(inStartX, inStartY);
  22983. fns.splice(0, 0, function()
  22984. {
  22985. c.moveTo(inStartX, inStartY);
  22986. });
  22987. }
  22988. }
  22989. for (var i = fns.length - 1; i >= 0; i--)
  22990. {
  22991. fns[i]();
  22992. }
  22993. if (openEnded)
  22994. {
  22995. c.end();
  22996. c.stroke();
  22997. }
  22998. else
  22999. {
  23000. c.close();
  23001. c.fillAndStroke();
  23002. }
  23003. // Workaround for shadow on top of base arrow
  23004. c.setShadow(false);
  23005. // Need to redraw the markers without the low miter limit
  23006. c.setMiterLimit(4);
  23007. if (isRounded)
  23008. {
  23009. c.setLineJoin('flat');
  23010. }
  23011. if (pts.length > 2)
  23012. {
  23013. // Only to repaint markers if no waypoints
  23014. // Need to redraw the markers without the low miter limit
  23015. c.setMiterLimit(4);
  23016. if (markerStart && !openEnded)
  23017. {
  23018. c.begin();
  23019. this.paintMarker(c, pts[0].x, pts[0].y, startNx, startNy, startSize, startWidth, edgeWidth, spacing, true);
  23020. c.stroke();
  23021. c.end();
  23022. }
  23023. if (markerEnd && !openEnded)
  23024. {
  23025. c.begin();
  23026. this.paintMarker(c, pe.x, pe.y, -nx, -ny, endSize, endWidth, edgeWidth, spacing, true);
  23027. c.stroke();
  23028. c.end();
  23029. }
  23030. }
  23031. };
  23032. /**
  23033. * Function: paintEdgeShape
  23034. *
  23035. * Paints the line shape.
  23036. */
  23037. mxArrowConnector.prototype.paintMarker = function(c, ptX, ptY, nx, ny, size, arrowWidth, edgeWidth, spacing, initialMove)
  23038. {
  23039. var widthArrowRatio = edgeWidth / arrowWidth;
  23040. var orthx = edgeWidth * ny / 2;
  23041. var orthy = -edgeWidth * nx / 2;
  23042. var spaceX = (spacing + size) * nx;
  23043. var spaceY = (spacing + size) * ny;
  23044. if (initialMove)
  23045. {
  23046. c.moveTo(ptX - orthx + spaceX, ptY - orthy + spaceY);
  23047. }
  23048. else
  23049. {
  23050. c.lineTo(ptX - orthx + spaceX, ptY - orthy + spaceY);
  23051. }
  23052. c.lineTo(ptX - orthx / widthArrowRatio + spaceX, ptY - orthy / widthArrowRatio + spaceY);
  23053. c.lineTo(ptX + spacing * nx, ptY + spacing * ny);
  23054. c.lineTo(ptX + orthx / widthArrowRatio + spaceX, ptY + orthy / widthArrowRatio + spaceY);
  23055. c.lineTo(ptX + orthx + spaceX, ptY + orthy + spaceY);
  23056. }
  23057. /**
  23058. * Function: isArrowRounded
  23059. *
  23060. * Returns wether the arrow is rounded
  23061. */
  23062. mxArrowConnector.prototype.isArrowRounded = function()
  23063. {
  23064. return this.isRounded;
  23065. };
  23066. /**
  23067. * Function: getStartArrowWidth
  23068. *
  23069. * Returns the width of the start arrow
  23070. */
  23071. mxArrowConnector.prototype.getStartArrowWidth = function()
  23072. {
  23073. return mxConstants.ARROW_WIDTH;
  23074. };
  23075. /**
  23076. * Function: getEndArrowWidth
  23077. *
  23078. * Returns the width of the end arrow
  23079. */
  23080. mxArrowConnector.prototype.getEndArrowWidth = function()
  23081. {
  23082. return mxConstants.ARROW_WIDTH;
  23083. };
  23084. /**
  23085. * Function: getEdgeWidth
  23086. *
  23087. * Returns the width of the body of the edge
  23088. */
  23089. mxArrowConnector.prototype.getEdgeWidth = function()
  23090. {
  23091. return mxConstants.ARROW_WIDTH / 3;
  23092. };
  23093. /**
  23094. * Function: isOpenEnded
  23095. *
  23096. * Returns whether the ends of the shape are drawn
  23097. */
  23098. mxArrowConnector.prototype.isOpenEnded = function()
  23099. {
  23100. return false;
  23101. };
  23102. /**
  23103. * Function: isMarkerStart
  23104. *
  23105. * Returns whether the start marker is drawn
  23106. */
  23107. mxArrowConnector.prototype.isMarkerStart = function()
  23108. {
  23109. return (mxUtils.getValue(this.style, mxConstants.STYLE_STARTARROW, mxConstants.NONE) != mxConstants.NONE);
  23110. };
  23111. /**
  23112. * Function: isMarkerEnd
  23113. *
  23114. * Returns whether the end marker is drawn
  23115. */
  23116. mxArrowConnector.prototype.isMarkerEnd = function()
  23117. {
  23118. return (mxUtils.getValue(this.style, mxConstants.STYLE_ENDARROW, mxConstants.NONE) != mxConstants.NONE);
  23119. };
  23120. /**
  23121. * Copyright (c) 2006-2015, JGraph Ltd
  23122. * Copyright (c) 2006-2015, Gaudenz Alder
  23123. */
  23124. /**
  23125. * Class: mxText
  23126. *
  23127. * Extends <mxShape> to implement a text shape. To change vertical text from
  23128. * bottom to top to top to bottom, the following code can be used:
  23129. *
  23130. * (code)
  23131. * mxText.prototype.verticalTextRotation = 90;
  23132. * (end)
  23133. *
  23134. * Constructor: mxText
  23135. *
  23136. * Constructs a new text shape.
  23137. *
  23138. * Parameters:
  23139. *
  23140. * value - String that represents the text to be displayed. This is stored in
  23141. * <value>.
  23142. * bounds - <mxRectangle> that defines the bounds. This is stored in
  23143. * <mxShape.bounds>.
  23144. * align - Specifies the horizontal alignment. Default is ''. This is stored in
  23145. * <align>.
  23146. * valign - Specifies the vertical alignment. Default is ''. This is stored in
  23147. * <valign>.
  23148. * color - String that specifies the text color. Default is 'black'. This is
  23149. * stored in <color>.
  23150. * family - String that specifies the font family. Default is
  23151. * <mxConstants.DEFAULT_FONTFAMILY>. This is stored in <family>.
  23152. * size - Integer that specifies the font size. Default is
  23153. * <mxConstants.DEFAULT_FONTSIZE>. This is stored in <size>.
  23154. * fontStyle - Specifies the font style. Default is 0. This is stored in
  23155. * <fontStyle>.
  23156. * spacing - Integer that specifies the global spacing. Default is 2. This is
  23157. * stored in <spacing>.
  23158. * spacingTop - Integer that specifies the top spacing. Default is 0. The
  23159. * sum of the spacing and this is stored in <spacingTop>.
  23160. * spacingRight - Integer that specifies the right spacing. Default is 0. The
  23161. * sum of the spacing and this is stored in <spacingRight>.
  23162. * spacingBottom - Integer that specifies the bottom spacing. Default is 0.The
  23163. * sum of the spacing and this is stored in <spacingBottom>.
  23164. * spacingLeft - Integer that specifies the left spacing. Default is 0. The
  23165. * sum of the spacing and this is stored in <spacingLeft>.
  23166. * horizontal - Boolean that specifies if the label is horizontal. Default is
  23167. * true. This is stored in <horizontal>.
  23168. * background - String that specifies the background color. Default is null.
  23169. * This is stored in <background>.
  23170. * border - String that specifies the label border color. Default is null.
  23171. * This is stored in <border>.
  23172. * wrap - Specifies if word-wrapping should be enabled. Default is false.
  23173. * This is stored in <wrap>.
  23174. * clipped - Specifies if the label should be clipped. Default is false.
  23175. * This is stored in <clipped>.
  23176. * overflow - Value of the overflow style. Default is 'visible'.
  23177. */
  23178. function mxText(value, bounds, align, valign, color,
  23179. family, size, fontStyle, spacing, spacingTop, spacingRight,
  23180. spacingBottom, spacingLeft, horizontal, background, border,
  23181. wrap, clipped, overflow, labelPadding, textDirection)
  23182. {
  23183. mxShape.call(this);
  23184. this.value = value;
  23185. this.bounds = bounds;
  23186. this.color = (color != null) ? color : 'black';
  23187. this.align = (align != null) ? align : mxConstants.ALIGN_CENTER;
  23188. this.valign = (valign != null) ? valign : mxConstants.ALIGN_MIDDLE;
  23189. this.family = (family != null) ? family : mxConstants.DEFAULT_FONTFAMILY;
  23190. this.size = (size != null) ? size : mxConstants.DEFAULT_FONTSIZE;
  23191. this.fontStyle = (fontStyle != null) ? fontStyle : mxConstants.DEFAULT_FONTSTYLE;
  23192. this.spacing = parseInt(spacing || 2);
  23193. this.spacingTop = this.spacing + parseInt(spacingTop || 0);
  23194. this.spacingRight = this.spacing + parseInt(spacingRight || 0);
  23195. this.spacingBottom = this.spacing + parseInt(spacingBottom || 0);
  23196. this.spacingLeft = this.spacing + parseInt(spacingLeft || 0);
  23197. this.horizontal = (horizontal != null) ? horizontal : true;
  23198. this.background = background;
  23199. this.border = border;
  23200. this.wrap = (wrap != null) ? wrap : false;
  23201. this.clipped = (clipped != null) ? clipped : false;
  23202. this.overflow = (overflow != null) ? overflow : 'visible';
  23203. this.labelPadding = (labelPadding != null) ? labelPadding : 0;
  23204. this.textDirection = textDirection;
  23205. this.rotation = 0;
  23206. this.updateMargin();
  23207. };
  23208. /**
  23209. * Extends mxShape.
  23210. */
  23211. mxUtils.extend(mxText, mxShape);
  23212. /**
  23213. * Variable: baseSpacingTop
  23214. *
  23215. * Specifies the spacing to be added to the top spacing. Default is 0. Use the
  23216. * value 5 here to get the same label positions as in mxGraph 1.x.
  23217. */
  23218. mxText.prototype.baseSpacingTop = 0;
  23219. /**
  23220. * Variable: baseSpacingBottom
  23221. *
  23222. * Specifies the spacing to be added to the bottom spacing. Default is 0. Use the
  23223. * value 1 here to get the same label positions as in mxGraph 1.x.
  23224. */
  23225. mxText.prototype.baseSpacingBottom = 0;
  23226. /**
  23227. * Variable: baseSpacingLeft
  23228. *
  23229. * Specifies the spacing to be added to the left spacing. Default is 0.
  23230. */
  23231. mxText.prototype.baseSpacingLeft = 0;
  23232. /**
  23233. * Variable: baseSpacingRight
  23234. *
  23235. * Specifies the spacing to be added to the right spacing. Default is 0.
  23236. */
  23237. mxText.prototype.baseSpacingRight = 0;
  23238. /**
  23239. * Variable: replaceLinefeeds
  23240. *
  23241. * Specifies if linefeeds in HTML labels should be replaced with BR tags.
  23242. * Default is true.
  23243. */
  23244. mxText.prototype.replaceLinefeeds = true;
  23245. /**
  23246. * Variable: verticalTextRotation
  23247. *
  23248. * Rotation for vertical text. Default is -90 (bottom to top).
  23249. */
  23250. mxText.prototype.verticalTextRotation = -90;
  23251. /**
  23252. * Variable: ignoreClippedStringSize
  23253. *
  23254. * Specifies if the string size should be measured in <updateBoundingBox> if
  23255. * the label is clipped and the label position is center and middle. If this is
  23256. * true, then the bounding box will be set to <bounds>. Default is true.
  23257. * <ignoreStringSize> has precedence over this switch.
  23258. */
  23259. mxText.prototype.ignoreClippedStringSize = true;
  23260. /**
  23261. * Variable: ignoreStringSize
  23262. *
  23263. * Specifies if the actual string size should be measured. If disabled the
  23264. * boundingBox will not ignore the actual size of the string, otherwise
  23265. * <bounds> will be used instead. Default is false.
  23266. */
  23267. mxText.prototype.ignoreStringSize = false;
  23268. /**
  23269. * Variable: textWidthPadding
  23270. *
  23271. * Specifies the padding to be added to the text width for the bounding box.
  23272. * This is needed to make sure no clipping is applied to borders. Default is 4
  23273. * for IE 8 standards mode and 3 for all others.
  23274. */
  23275. mxText.prototype.textWidthPadding = (document.documentMode == 8 && !mxClient.IS_EM) ? 4 : 3;
  23276. /**
  23277. * Variable: lastValue
  23278. *
  23279. * Contains the last rendered text value. Used for caching.
  23280. */
  23281. mxText.prototype.lastValue = null;
  23282. /**
  23283. * Variable: cacheEnabled
  23284. *
  23285. * Specifies if caching for HTML labels should be enabled. Default is true.
  23286. */
  23287. mxText.prototype.cacheEnabled = true;
  23288. /**
  23289. * Function: isParseVml
  23290. *
  23291. * Text shapes do not contain VML markup and do not need to be parsed. This
  23292. * method returns false to speed up rendering in IE8.
  23293. */
  23294. mxText.prototype.isParseVml = function()
  23295. {
  23296. return false;
  23297. };
  23298. /**
  23299. * Function: isHtmlAllowed
  23300. *
  23301. * Returns true if HTML is allowed for this shape. This implementation returns
  23302. * true if the browser is not in IE8 standards mode.
  23303. */
  23304. mxText.prototype.isHtmlAllowed = function()
  23305. {
  23306. return document.documentMode != 8 || mxClient.IS_EM;
  23307. };
  23308. /**
  23309. * Function: getSvgScreenOffset
  23310. *
  23311. * Disables offset in IE9 for crisper image output.
  23312. */
  23313. mxText.prototype.getSvgScreenOffset = function()
  23314. {
  23315. return 0;
  23316. };
  23317. /**
  23318. * Function: checkBounds
  23319. *
  23320. * Returns true if the bounds are not null and all of its variables are numeric.
  23321. */
  23322. mxText.prototype.checkBounds = function()
  23323. {
  23324. return (!isNaN(this.scale) && isFinite(this.scale) && this.scale > 0 &&
  23325. this.bounds != null && !isNaN(this.bounds.x) && !isNaN(this.bounds.y) &&
  23326. !isNaN(this.bounds.width) && !isNaN(this.bounds.height));
  23327. };
  23328. /**
  23329. * Function: paint
  23330. *
  23331. * Generic rendering code.
  23332. */
  23333. mxText.prototype.paint = function(c, update)
  23334. {
  23335. // Scale is passed-through to canvas
  23336. var s = this.scale;
  23337. var x = this.bounds.x / s;
  23338. var y = this.bounds.y / s;
  23339. var w = this.bounds.width / s;
  23340. var h = this.bounds.height / s;
  23341. this.updateTransform(c, x, y, w, h);
  23342. this.configureCanvas(c, x, y, w, h);
  23343. if (update)
  23344. {
  23345. c.updateText(x, y, w, h, this.align, this.valign, this.wrap, this.overflow,
  23346. this.clipped, this.getTextRotation(), this.node);
  23347. }
  23348. else
  23349. {
  23350. // Checks if text contains HTML markup
  23351. var realHtml = mxUtils.isNode(this.value) || this.dialect == mxConstants.DIALECT_STRICTHTML;
  23352. // Always renders labels as HTML in VML
  23353. var fmt = (realHtml || c instanceof mxVmlCanvas2D) ? 'html' : '';
  23354. var val = this.value;
  23355. if (!realHtml && fmt == 'html')
  23356. {
  23357. val = mxUtils.htmlEntities(val, false);
  23358. }
  23359. if (fmt == 'html' && !mxUtils.isNode(this.value))
  23360. {
  23361. val = mxUtils.replaceTrailingNewlines(val, '<div><br></div>');
  23362. }
  23363. // Handles trailing newlines to make sure they are visible in rendering output
  23364. val = (!mxUtils.isNode(this.value) && this.replaceLinefeeds && fmt == 'html') ?
  23365. val.replace(/\n/g, '<br/>') : val;
  23366. var dir = this.textDirection;
  23367. if (dir == mxConstants.TEXT_DIRECTION_AUTO && !realHtml)
  23368. {
  23369. dir = this.getAutoDirection();
  23370. }
  23371. if (dir != mxConstants.TEXT_DIRECTION_LTR && dir != mxConstants.TEXT_DIRECTION_RTL)
  23372. {
  23373. dir = null;
  23374. }
  23375. c.text(x, y, w, h, val, this.align, this.valign, this.wrap, fmt,
  23376. this.overflow, this.clipped, this.getTextRotation(), dir);
  23377. }
  23378. };
  23379. /**
  23380. * Function: redraw
  23381. *
  23382. * Renders the text using the given DOM nodes.
  23383. */
  23384. mxText.prototype.redraw = function()
  23385. {
  23386. if (this.visible && this.checkBounds() && this.cacheEnabled && this.lastValue == this.value &&
  23387. (mxUtils.isNode(this.value) || this.dialect == mxConstants.DIALECT_STRICTHTML))
  23388. {
  23389. if (this.node.nodeName == 'DIV' && (this.isHtmlAllowed() || !mxClient.IS_VML))
  23390. {
  23391. if (mxClient.IS_SVG)
  23392. {
  23393. this.redrawHtmlShapeWithCss3();
  23394. }
  23395. else
  23396. {
  23397. this.updateSize(this.node, (this.state == null || this.state.view.textDiv == null));
  23398. if (mxClient.IS_IE && (document.documentMode == null || document.documentMode <= 8))
  23399. {
  23400. this.updateHtmlFilter();
  23401. }
  23402. else
  23403. {
  23404. this.updateHtmlTransform();
  23405. }
  23406. }
  23407. this.updateBoundingBox();
  23408. }
  23409. else
  23410. {
  23411. var canvas = this.createCanvas();
  23412. if (canvas != null && canvas.updateText != null)
  23413. {
  23414. // Specifies if events should be handled
  23415. canvas.pointerEvents = this.pointerEvents;
  23416. this.paint(canvas, true);
  23417. this.destroyCanvas(canvas);
  23418. this.updateBoundingBox();
  23419. }
  23420. else
  23421. {
  23422. // Fallback if canvas does not support updateText (VML)
  23423. mxShape.prototype.redraw.apply(this, arguments);
  23424. }
  23425. }
  23426. }
  23427. else
  23428. {
  23429. mxShape.prototype.redraw.apply(this, arguments);
  23430. if (mxUtils.isNode(this.value) || this.dialect == mxConstants.DIALECT_STRICTHTML)
  23431. {
  23432. this.lastValue = this.value;
  23433. }
  23434. else
  23435. {
  23436. this.lastValue = null;
  23437. }
  23438. }
  23439. };
  23440. /**
  23441. * Function: resetStyles
  23442. *
  23443. * Resets all styles.
  23444. */
  23445. mxText.prototype.resetStyles = function()
  23446. {
  23447. mxShape.prototype.resetStyles.apply(this, arguments);
  23448. this.color = 'black';
  23449. this.align = mxConstants.ALIGN_CENTER;
  23450. this.valign = mxConstants.ALIGN_MIDDLE;
  23451. this.family = mxConstants.DEFAULT_FONTFAMILY;
  23452. this.size = mxConstants.DEFAULT_FONTSIZE;
  23453. this.fontStyle = mxConstants.DEFAULT_FONTSTYLE;
  23454. this.spacing = 2;
  23455. this.spacingTop = 2;
  23456. this.spacingRight = 2;
  23457. this.spacingBottom = 2;
  23458. this.spacingLeft = 2;
  23459. this.horizontal = true;
  23460. delete this.background;
  23461. delete this.border;
  23462. this.textDirection = mxConstants.DEFAULT_TEXT_DIRECTION;
  23463. delete this.margin;
  23464. };
  23465. /**
  23466. * Function: apply
  23467. *
  23468. * Extends mxShape to update the text styles.
  23469. *
  23470. * Parameters:
  23471. *
  23472. * state - <mxCellState> of the corresponding cell.
  23473. */
  23474. mxText.prototype.apply = function(state)
  23475. {
  23476. var old = this.spacing;
  23477. mxShape.prototype.apply.apply(this, arguments);
  23478. if (this.style != null)
  23479. {
  23480. this.fontStyle = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSTYLE, this.fontStyle);
  23481. this.family = mxUtils.getValue(this.style, mxConstants.STYLE_FONTFAMILY, this.family);
  23482. this.size = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, this.size);
  23483. this.color = mxUtils.getValue(this.style, mxConstants.STYLE_FONTCOLOR, this.color);
  23484. this.align = mxUtils.getValue(this.style, mxConstants.STYLE_ALIGN, this.align);
  23485. this.valign = mxUtils.getValue(this.style, mxConstants.STYLE_VERTICAL_ALIGN, this.valign);
  23486. this.spacing = parseInt(mxUtils.getValue(this.style, mxConstants.STYLE_SPACING, this.spacing));
  23487. this.spacingTop = parseInt(mxUtils.getValue(this.style, mxConstants.STYLE_SPACING_TOP, this.spacingTop - old)) + this.spacing;
  23488. this.spacingRight = parseInt(mxUtils.getValue(this.style, mxConstants.STYLE_SPACING_RIGHT, this.spacingRight - old)) + this.spacing;
  23489. this.spacingBottom = parseInt(mxUtils.getValue(this.style, mxConstants.STYLE_SPACING_BOTTOM, this.spacingBottom - old)) + this.spacing;
  23490. this.spacingLeft = parseInt(mxUtils.getValue(this.style, mxConstants.STYLE_SPACING_LEFT, this.spacingLeft - old)) + this.spacing;
  23491. this.horizontal = mxUtils.getValue(this.style, mxConstants.STYLE_HORIZONTAL, this.horizontal);
  23492. this.background = mxUtils.getValue(this.style, mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, this.background);
  23493. this.border = mxUtils.getValue(this.style, mxConstants.STYLE_LABEL_BORDERCOLOR, this.border);
  23494. this.textDirection = mxUtils.getValue(this.style, mxConstants.STYLE_TEXT_DIRECTION, mxConstants.DEFAULT_TEXT_DIRECTION);
  23495. this.opacity = mxUtils.getValue(this.style, mxConstants.STYLE_TEXT_OPACITY, 100);
  23496. this.updateMargin();
  23497. }
  23498. this.flipV = null;
  23499. this.flipH = null;
  23500. };
  23501. /**
  23502. * Function: getAutoDirection
  23503. *
  23504. * Used to determine the automatic text direction. Returns
  23505. * <mxConstants.TEXT_DIRECTION_LTR> or <mxConstants.TEXT_DIRECTION_RTL>
  23506. * depending on the contents of <value>. This is not invoked for HTML, wrapped
  23507. * content or if <value> is a DOM node.
  23508. */
  23509. mxText.prototype.getAutoDirection = function()
  23510. {
  23511. // Looks for strong (directional) characters
  23512. var tmp = /[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(this.value);
  23513. // Returns the direction defined by the character
  23514. return (tmp != null && tmp.length > 0 && tmp[0] > 'z') ?
  23515. mxConstants.TEXT_DIRECTION_RTL : mxConstants.TEXT_DIRECTION_LTR;
  23516. };
  23517. /**
  23518. * Function: getContentNode
  23519. *
  23520. * Returns the node that contains the rendered input.
  23521. */
  23522. mxText.prototype.getContentNode = function()
  23523. {
  23524. var result = this.node;
  23525. if (result != null)
  23526. {
  23527. // Rendered with no foreignObject
  23528. if (result.ownerSVGElement == null)
  23529. {
  23530. result = this.node.firstChild.firstChild;
  23531. }
  23532. else
  23533. {
  23534. // Innermost DIV that contains the actual content
  23535. result = result.firstChild.firstChild.firstChild.firstChild.firstChild;
  23536. }
  23537. }
  23538. return result;
  23539. };
  23540. /**
  23541. * Function: updateBoundingBox
  23542. *
  23543. * Updates the <boundingBox> for this shape using the given node and position.
  23544. */
  23545. mxText.prototype.updateBoundingBox = function()
  23546. {
  23547. var node = this.node;
  23548. this.boundingBox = this.bounds.clone();
  23549. var rot = this.getTextRotation();
  23550. var h = (this.style != null) ? mxUtils.getValue(this.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER) : null;
  23551. var v = (this.style != null) ? mxUtils.getValue(this.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE) : null;
  23552. if (!this.ignoreStringSize && node != null && this.overflow != 'fill' && (!this.clipped ||
  23553. !this.ignoreClippedStringSize || h != mxConstants.ALIGN_CENTER || v != mxConstants.ALIGN_MIDDLE))
  23554. {
  23555. var ow = null;
  23556. var oh = null;
  23557. if (node.ownerSVGElement != null)
  23558. {
  23559. if (node.firstChild != null && node.firstChild.firstChild != null &&
  23560. node.firstChild.firstChild.nodeName == 'foreignObject')
  23561. {
  23562. // Uses second inner DIV for font metrics
  23563. node = node.firstChild.firstChild.firstChild.firstChild;
  23564. oh = node.offsetHeight * this.scale;
  23565. if (this.overflow == 'width')
  23566. {
  23567. ow = this.boundingBox.width;
  23568. }
  23569. else
  23570. {
  23571. ow = node.offsetWidth * this.scale;
  23572. }
  23573. }
  23574. else
  23575. {
  23576. try
  23577. {
  23578. var b = node.getBBox();
  23579. // Workaround for bounding box of empty string
  23580. if (typeof(this.value) == 'string' && mxUtils.trim(this.value) == 0)
  23581. {
  23582. this.boundingBox = null;
  23583. }
  23584. else if (b.width == 0 && b.height == 0)
  23585. {
  23586. this.boundingBox = null;
  23587. }
  23588. else
  23589. {
  23590. this.boundingBox = new mxRectangle(b.x, b.y, b.width, b.height);
  23591. }
  23592. return;
  23593. }
  23594. catch (e)
  23595. {
  23596. // Ignores NS_ERROR_FAILURE in FF if container display is none.
  23597. }
  23598. }
  23599. }
  23600. else
  23601. {
  23602. var td = (this.state != null) ? this.state.view.textDiv : null;
  23603. // Use cached offset size
  23604. if (this.offsetWidth != null && this.offsetHeight != null)
  23605. {
  23606. ow = this.offsetWidth * this.scale;
  23607. oh = this.offsetHeight * this.scale;
  23608. }
  23609. else
  23610. {
  23611. // Cannot get node size while container hidden so a
  23612. // shared temporary DIV is used for text measuring
  23613. if (td != null)
  23614. {
  23615. this.updateFont(td);
  23616. this.updateSize(td, false);
  23617. this.updateInnerHtml(td);
  23618. node = td;
  23619. }
  23620. var sizeDiv = node;
  23621. if (document.documentMode == 8 && !mxClient.IS_EM)
  23622. {
  23623. var w = Math.round(this.bounds.width / this.scale);
  23624. if (this.wrap && w > 0)
  23625. {
  23626. node.style.wordWrap = mxConstants.WORD_WRAP;
  23627. node.style.whiteSpace = 'normal';
  23628. if (node.style.wordWrap != 'break-word')
  23629. {
  23630. // Innermost DIV is used for measuring text
  23631. var divs = sizeDiv.getElementsByTagName('div');
  23632. if (divs.length > 0)
  23633. {
  23634. sizeDiv = divs[divs.length - 1];
  23635. }
  23636. ow = sizeDiv.offsetWidth + 2;
  23637. divs = this.node.getElementsByTagName('div');
  23638. if (this.clipped)
  23639. {
  23640. ow = Math.min(w, ow);
  23641. }
  23642. // Second last DIV width must be updated in DOM tree
  23643. if (divs.length > 1)
  23644. {
  23645. divs[divs.length - 2].style.width = ow + 'px';
  23646. }
  23647. }
  23648. }
  23649. else
  23650. {
  23651. node.style.whiteSpace = 'nowrap';
  23652. }
  23653. }
  23654. else if (sizeDiv.firstChild != null && sizeDiv.firstChild.nodeName == 'DIV')
  23655. {
  23656. sizeDiv = sizeDiv.firstChild;
  23657. }
  23658. this.offsetWidth = sizeDiv.offsetWidth + this.textWidthPadding;
  23659. this.offsetHeight = sizeDiv.offsetHeight;
  23660. ow = this.offsetWidth * this.scale;
  23661. oh = this.offsetHeight * this.scale;
  23662. }
  23663. }
  23664. if (ow != null && oh != null)
  23665. {
  23666. this.boundingBox = new mxRectangle(this.bounds.x,
  23667. this.bounds.y, ow, oh);
  23668. }
  23669. }
  23670. if (this.boundingBox != null)
  23671. {
  23672. if (rot != 0)
  23673. {
  23674. // Accounts for pre-rotated x and y
  23675. var bbox = mxUtils.getBoundingBox(new mxRectangle(
  23676. this.margin.x * this.boundingBox.width,
  23677. this.margin.y * this.boundingBox.height,
  23678. this.boundingBox.width, this.boundingBox.height),
  23679. rot, new mxPoint(0, 0));
  23680. this.unrotatedBoundingBox = mxRectangle.fromRectangle(this.boundingBox);
  23681. this.unrotatedBoundingBox.x += this.margin.x * this.unrotatedBoundingBox.width;
  23682. this.unrotatedBoundingBox.y += this.margin.y * this.unrotatedBoundingBox.height;
  23683. this.boundingBox.x += bbox.x;
  23684. this.boundingBox.y += bbox.y;
  23685. this.boundingBox.width = bbox.width;
  23686. this.boundingBox.height = bbox.height;
  23687. }
  23688. else
  23689. {
  23690. this.boundingBox.x += this.margin.x * this.boundingBox.width;
  23691. this.boundingBox.y += this.margin.y * this.boundingBox.height;
  23692. this.unrotatedBoundingBox = null;
  23693. }
  23694. }
  23695. };
  23696. /**
  23697. * Function: getShapeRotation
  23698. *
  23699. * Returns 0 to avoid using rotation in the canvas via updateTransform.
  23700. */
  23701. mxText.prototype.getShapeRotation = function()
  23702. {
  23703. return 0;
  23704. };
  23705. /**
  23706. * Function: getTextRotation
  23707. *
  23708. * Returns the rotation for the text label of the corresponding shape.
  23709. */
  23710. mxText.prototype.getTextRotation = function()
  23711. {
  23712. return (this.state != null && this.state.shape != null) ? this.state.shape.getTextRotation() : 0;
  23713. };
  23714. /**
  23715. * Function: isPaintBoundsInverted
  23716. *
  23717. * Inverts the bounds if <mxShape.isBoundsInverted> returns true or if the
  23718. * horizontal style is false.
  23719. */
  23720. mxText.prototype.isPaintBoundsInverted = function()
  23721. {
  23722. return !this.horizontal && this.state != null && this.state.view.graph.model.isVertex(this.state.cell);
  23723. };
  23724. /**
  23725. * Function: configureCanvas
  23726. *
  23727. * Sets the state of the canvas for drawing the shape.
  23728. */
  23729. mxText.prototype.configureCanvas = function(c, x, y, w, h)
  23730. {
  23731. mxShape.prototype.configureCanvas.apply(this, arguments);
  23732. c.setFontColor(this.color);
  23733. c.setFontBackgroundColor(this.background);
  23734. c.setFontBorderColor(this.border);
  23735. c.setFontFamily(this.family);
  23736. c.setFontSize(this.size);
  23737. c.setFontStyle(this.fontStyle);
  23738. };
  23739. /**
  23740. * Function: updateVmlContainer
  23741. *
  23742. * Sets the width and height of the container to 1px.
  23743. */
  23744. mxText.prototype.updateVmlContainer = function()
  23745. {
  23746. this.node.style.left = Math.round(this.bounds.x) + 'px';
  23747. this.node.style.top = Math.round(this.bounds.y) + 'px';
  23748. this.node.style.width = '1px';
  23749. this.node.style.height = '1px';
  23750. this.node.style.overflow = 'visible';
  23751. };
  23752. /**
  23753. * Function: getHtmlValue
  23754. *
  23755. * Private helper function to create SVG elements
  23756. */
  23757. mxText.prototype.getHtmlValue = function()
  23758. {
  23759. var val = this.value;
  23760. if (this.dialect != mxConstants.DIALECT_STRICTHTML)
  23761. {
  23762. val = mxUtils.htmlEntities(val, false);
  23763. }
  23764. // Handles trailing newlines to make sure they are visible in rendering output
  23765. val = mxUtils.replaceTrailingNewlines(val, '<div><br></div>');
  23766. val = (this.replaceLinefeeds) ? val.replace(/\n/g, '<br/>') : val;
  23767. return val;
  23768. };
  23769. /**
  23770. * Function: getTextCss
  23771. *
  23772. * Private helper function to create SVG elements
  23773. */
  23774. mxText.prototype.getTextCss = function()
  23775. {
  23776. var lh = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? (this.size * mxConstants.LINE_HEIGHT) + 'px' :
  23777. mxConstants.LINE_HEIGHT;
  23778. var css = 'display: inline-block; font-size: ' + this.size + 'px; ' +
  23779. 'font-family: ' + this.family + '; color: ' + this.color + '; line-height: ' + lh +
  23780. '; pointer-events: ' + ((this.pointerEvents) ? 'all' : 'none') + '; ';
  23781. if ((this.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  23782. {
  23783. css += 'font-weight: bold; ';
  23784. }
  23785. if ((this.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  23786. {
  23787. css += 'font-style: italic; ';
  23788. }
  23789. var deco = [];
  23790. if ((this.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  23791. {
  23792. deco.push('underline');
  23793. }
  23794. if ((this.fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  23795. {
  23796. deco.push('line-through');
  23797. }
  23798. if (deco.length > 0)
  23799. {
  23800. css += 'text-decoration: ' + deco.join(' ') + '; ';
  23801. }
  23802. return css;
  23803. };
  23804. /**
  23805. * Function: redrawHtmlShape
  23806. *
  23807. * Updates the HTML node(s) to reflect the latest bounds and scale.
  23808. */
  23809. mxText.prototype.redrawHtmlShape = function()
  23810. {
  23811. if (mxClient.IS_SVG)
  23812. {
  23813. this.redrawHtmlShapeWithCss3();
  23814. }
  23815. else
  23816. {
  23817. var style = this.node.style;
  23818. // Resets CSS styles
  23819. style.whiteSpace = 'normal';
  23820. style.overflow = '';
  23821. style.width = '';
  23822. style.height = '';
  23823. this.updateValue();
  23824. this.updateFont(this.node);
  23825. this.updateSize(this.node, (this.state == null || this.state.view.textDiv == null));
  23826. this.offsetWidth = null;
  23827. this.offsetHeight = null;
  23828. if (mxClient.IS_IE && (document.documentMode == null || document.documentMode <= 8))
  23829. {
  23830. this.updateHtmlFilter();
  23831. }
  23832. else
  23833. {
  23834. this.updateHtmlTransform();
  23835. }
  23836. }
  23837. };
  23838. /**
  23839. * Function: redrawHtmlShapeWithCss3
  23840. *
  23841. * Updates the HTML node(s) to reflect the latest bounds and scale.
  23842. */
  23843. mxText.prototype.redrawHtmlShapeWithCss3 = function()
  23844. {
  23845. var w = Math.max(0, Math.round(this.bounds.width / this.scale));
  23846. var h = Math.max(0, Math.round(this.bounds.height / this.scale));
  23847. var flex = 'position: absolute; left: ' + Math.round(this.bounds.x) + 'px; ' +
  23848. 'top: ' + Math.round(this.bounds.y) + 'px; pointer-events: none; ';
  23849. var block = this.getTextCss();
  23850. mxSvgCanvas2D.createCss(w + 2, h, this.align, this.valign, this.wrap, this.overflow, this.clipped,
  23851. (this.background != null) ? mxUtils.htmlEntities(this.background) : null,
  23852. (this.border != null) ? mxUtils.htmlEntities(this.border) : null,
  23853. flex, block, this.scale, mxUtils.bind(this, function(dx, dy, flex, item, block, ofl)
  23854. {
  23855. var r = this.getTextRotation();
  23856. var tr = ((this.scale != 1) ? 'scale(' + this.scale + ') ' : '') +
  23857. ((r != 0) ? 'rotate(' + r + 'deg) ' : '') +
  23858. ((this.margin.x != 0 || this.margin.y != 0) ?
  23859. 'translate(' + (this.margin.x * 100) + '%,' +
  23860. (this.margin.y * 100) + '%)' : '');
  23861. if (tr != '')
  23862. {
  23863. tr = 'transform-origin: 0 0; transform: ' + tr + '; ';
  23864. }
  23865. if (ofl == '')
  23866. {
  23867. flex += item;
  23868. item = 'display:inline-block; min-width: 100%; ' + tr;
  23869. }
  23870. else
  23871. {
  23872. item += tr;
  23873. }
  23874. if (this.opacity < 100)
  23875. {
  23876. block += 'opacity: ' + (this.opacity / 100) + '; ';
  23877. }
  23878. this.node.setAttribute('style', flex);
  23879. var html = (mxUtils.isNode(this.value)) ? this.value.outerHTML : this.getHtmlValue();
  23880. if (this.node.firstChild == null)
  23881. {
  23882. this.node.innerHTML = '<div><div>' + html +'</div></div>';
  23883. }
  23884. this.node.firstChild.firstChild.setAttribute('style', block);
  23885. this.node.firstChild.setAttribute('style', item);
  23886. }));
  23887. };
  23888. /**
  23889. * Function: updateHtmlTransform
  23890. *
  23891. * Returns the spacing as an <mxPoint>.
  23892. */
  23893. mxText.prototype.updateHtmlTransform = function()
  23894. {
  23895. var theta = this.getTextRotation();
  23896. var style = this.node.style;
  23897. var dx = this.margin.x;
  23898. var dy = this.margin.y;
  23899. if (theta != 0)
  23900. {
  23901. mxUtils.setPrefixedStyle(style, 'transformOrigin', (-dx * 100) + '%' + ' ' + (-dy * 100) + '%');
  23902. mxUtils.setPrefixedStyle(style, 'transform', 'translate(' + (dx * 100) + '%' + ',' + (dy * 100) + '%) ' +
  23903. 'scale(' + this.scale + ') rotate(' + theta + 'deg)');
  23904. }
  23905. else
  23906. {
  23907. mxUtils.setPrefixedStyle(style, 'transformOrigin', '0% 0%');
  23908. mxUtils.setPrefixedStyle(style, 'transform', 'scale(' + this.scale + ') ' +
  23909. 'translate(' + (dx * 100) + '%' + ',' + (dy * 100) + '%)');
  23910. }
  23911. style.left = Math.round(this.bounds.x - Math.ceil(dx * ((this.overflow != 'fill' &&
  23912. this.overflow != 'width') ? 3 : 1))) + 'px';
  23913. style.top = Math.round(this.bounds.y - dy * ((this.overflow != 'fill') ? 3 : 1)) + 'px';
  23914. if (this.opacity < 100)
  23915. {
  23916. style.opacity = this.opacity / 100;
  23917. }
  23918. else
  23919. {
  23920. style.opacity = '';
  23921. }
  23922. };
  23923. /**
  23924. * Function: updateInnerHtml
  23925. *
  23926. * Sets the inner HTML of the given element to the <value>.
  23927. */
  23928. mxText.prototype.updateInnerHtml = function(elt)
  23929. {
  23930. if (mxUtils.isNode(this.value))
  23931. {
  23932. elt.innerHTML = this.value.outerHTML;
  23933. }
  23934. else
  23935. {
  23936. var val = this.value;
  23937. if (this.dialect != mxConstants.DIALECT_STRICTHTML)
  23938. {
  23939. // LATER: Can be cached in updateValue
  23940. val = mxUtils.htmlEntities(val, false);
  23941. }
  23942. // Handles trailing newlines to make sure they are visible in rendering output
  23943. val = mxUtils.replaceTrailingNewlines(val, '<div>&nbsp;</div>');
  23944. val = (this.replaceLinefeeds) ? val.replace(/\n/g, '<br/>') : val;
  23945. val = '<div style="display:inline-block;_display:inline;">' + val + '</div>';
  23946. elt.innerHTML = val;
  23947. }
  23948. };
  23949. /**
  23950. * Function: updateHtmlFilter
  23951. *
  23952. * Rotated text rendering quality is bad for IE9 quirks/IE8 standards
  23953. */
  23954. mxText.prototype.updateHtmlFilter = function()
  23955. {
  23956. var style = this.node.style;
  23957. var dx = this.margin.x;
  23958. var dy = this.margin.y;
  23959. var s = this.scale;
  23960. // Resets filter before getting offsetWidth
  23961. mxUtils.setOpacity(this.node, this.opacity);
  23962. // Adds 1 to match table height in 1.x
  23963. var ow = 0;
  23964. var oh = 0;
  23965. var td = (this.state != null) ? this.state.view.textDiv : null;
  23966. var sizeDiv = this.node;
  23967. // Fallback for hidden text rendering in IE quirks mode
  23968. if (td != null)
  23969. {
  23970. td.style.overflow = '';
  23971. td.style.height = '';
  23972. td.style.width = '';
  23973. this.updateFont(td);
  23974. this.updateSize(td, false);
  23975. this.updateInnerHtml(td);
  23976. var w = Math.round(this.bounds.width / this.scale);
  23977. if (this.wrap && w > 0)
  23978. {
  23979. td.style.whiteSpace = 'normal';
  23980. td.style.wordWrap = mxConstants.WORD_WRAP;
  23981. ow = w;
  23982. if (this.clipped)
  23983. {
  23984. ow = Math.min(ow, this.bounds.width);
  23985. }
  23986. td.style.width = ow + 'px';
  23987. }
  23988. else
  23989. {
  23990. td.style.whiteSpace = 'nowrap';
  23991. }
  23992. sizeDiv = td;
  23993. if (sizeDiv.firstChild != null && sizeDiv.firstChild.nodeName == 'DIV')
  23994. {
  23995. sizeDiv = sizeDiv.firstChild;
  23996. if (this.wrap && td.style.wordWrap == 'break-word')
  23997. {
  23998. sizeDiv.style.width = '100%';
  23999. }
  24000. }
  24001. // Required to update the height of the text box after wrapping width is known
  24002. if (!this.clipped && this.wrap && w > 0)
  24003. {
  24004. ow = sizeDiv.offsetWidth + this.textWidthPadding;
  24005. td.style.width = ow + 'px';
  24006. }
  24007. oh = sizeDiv.offsetHeight + 2;
  24008. if (mxClient.IS_QUIRKS && this.border != null && this.border != mxConstants.NONE)
  24009. {
  24010. oh += 3;
  24011. }
  24012. }
  24013. else if (sizeDiv.firstChild != null && sizeDiv.firstChild.nodeName == 'DIV')
  24014. {
  24015. sizeDiv = sizeDiv.firstChild;
  24016. oh = sizeDiv.offsetHeight;
  24017. }
  24018. ow = sizeDiv.offsetWidth + this.textWidthPadding;
  24019. if (this.clipped)
  24020. {
  24021. oh = Math.min(oh, this.bounds.height);
  24022. }
  24023. var w = this.bounds.width / s;
  24024. var h = this.bounds.height / s;
  24025. // Handles special case for live preview with no wrapper DIV and no textDiv
  24026. if (this.overflow == 'fill')
  24027. {
  24028. oh = h;
  24029. ow = w;
  24030. }
  24031. else if (this.overflow == 'width')
  24032. {
  24033. oh = sizeDiv.scrollHeight;
  24034. ow = w;
  24035. }
  24036. // Stores for later use
  24037. this.offsetWidth = ow;
  24038. this.offsetHeight = oh;
  24039. // Simulates max-height CSS in quirks mode
  24040. if (mxClient.IS_QUIRKS && (this.clipped || (this.overflow == 'width' && h > 0)))
  24041. {
  24042. h = Math.min(h, oh);
  24043. style.height = Math.round(h) + 'px';
  24044. }
  24045. else
  24046. {
  24047. h = oh;
  24048. }
  24049. if (this.overflow != 'fill' && this.overflow != 'width')
  24050. {
  24051. if (this.clipped)
  24052. {
  24053. ow = Math.min(w, ow);
  24054. }
  24055. w = ow;
  24056. // Simulates max-width CSS in quirks mode
  24057. if ((mxClient.IS_QUIRKS && this.clipped) || this.wrap)
  24058. {
  24059. style.width = Math.round(w) + 'px';
  24060. }
  24061. }
  24062. h *= s;
  24063. w *= s;
  24064. // Rotation case is handled via VML canvas
  24065. var rad = this.getTextRotation() * (Math.PI / 180);
  24066. // Precalculate cos and sin for the rotation
  24067. var real_cos = parseFloat(parseFloat(Math.cos(rad)).toFixed(8));
  24068. var real_sin = parseFloat(parseFloat(Math.sin(-rad)).toFixed(8));
  24069. rad %= 2 * Math.PI;
  24070. if (rad < 0)
  24071. {
  24072. rad += 2 * Math.PI;
  24073. }
  24074. rad %= Math.PI;
  24075. if (rad > Math.PI / 2)
  24076. {
  24077. rad = Math.PI - rad;
  24078. }
  24079. var cos = Math.cos(rad);
  24080. var sin = Math.sin(-rad);
  24081. var tx = w * -(dx + 0.5);
  24082. var ty = h * -(dy + 0.5);
  24083. var top_fix = (h - h * cos + w * sin) / 2 + real_sin * tx - real_cos * ty;
  24084. var left_fix = (w - w * cos + h * sin) / 2 - real_cos * tx - real_sin * ty;
  24085. if (rad != 0)
  24086. {
  24087. var f = 'progid:DXImageTransform.Microsoft.Matrix(M11=' + real_cos + ', M12='+
  24088. real_sin + ', M21=' + (-real_sin) + ', M22=' + real_cos + ', sizingMethod=\'auto expand\')';
  24089. if (style.filter != null && style.filter.length > 0)
  24090. {
  24091. style.filter += ' ' + f;
  24092. }
  24093. else
  24094. {
  24095. style.filter = f;
  24096. }
  24097. }
  24098. // Workaround for rendering offsets
  24099. var dy = 0;
  24100. if (this.overflow != 'fill' && mxClient.IS_QUIRKS)
  24101. {
  24102. if (this.valign == mxConstants.ALIGN_TOP)
  24103. {
  24104. dy -= 1;
  24105. }
  24106. else if (this.valign == mxConstants.ALIGN_BOTTOM)
  24107. {
  24108. dy += 2;
  24109. }
  24110. else
  24111. {
  24112. dy += 1;
  24113. }
  24114. }
  24115. style.zoom = s;
  24116. style.left = Math.round(this.bounds.x + left_fix - w / 2) + 'px';
  24117. style.top = Math.round(this.bounds.y + top_fix - h / 2 + dy) + 'px';
  24118. };
  24119. /**
  24120. * Function: updateValue
  24121. *
  24122. * Updates the HTML node(s) to reflect the latest bounds and scale.
  24123. */
  24124. mxText.prototype.updateValue = function()
  24125. {
  24126. if (mxUtils.isNode(this.value))
  24127. {
  24128. this.node.innerHTML = '';
  24129. this.node.appendChild(this.value);
  24130. }
  24131. else
  24132. {
  24133. var val = this.value;
  24134. if (this.dialect != mxConstants.DIALECT_STRICTHTML)
  24135. {
  24136. val = mxUtils.htmlEntities(val, false);
  24137. }
  24138. // Handles trailing newlines to make sure they are visible in rendering output
  24139. val = mxUtils.replaceTrailingNewlines(val, '<div><br></div>');
  24140. val = (this.replaceLinefeeds) ? val.replace(/\n/g, '<br/>') : val;
  24141. var bg = (this.background != null && this.background != mxConstants.NONE) ? this.background : null;
  24142. var bd = (this.border != null && this.border != mxConstants.NONE) ? this.border : null;
  24143. if (this.overflow == 'fill' || this.overflow == 'width')
  24144. {
  24145. if (bg != null)
  24146. {
  24147. this.node.style.backgroundColor = bg;
  24148. }
  24149. if (bd != null)
  24150. {
  24151. this.node.style.border = '1px solid ' + bd;
  24152. }
  24153. }
  24154. else
  24155. {
  24156. var css = '';
  24157. if (bg != null)
  24158. {
  24159. css += 'background-color:' + mxUtils.htmlEntities(bg) + ';';
  24160. }
  24161. if (bd != null)
  24162. {
  24163. css += 'border:1px solid ' + mxUtils.htmlEntities(bd) + ';';
  24164. }
  24165. // Wrapper DIV for background, zoom needed for inline in quirks
  24166. // and to measure wrapped font sizes in all browsers
  24167. // FIXME: Background size in quirks mode for wrapped text
  24168. var lh = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? (this.size * mxConstants.LINE_HEIGHT) + 'px' :
  24169. mxConstants.LINE_HEIGHT;
  24170. val = '<div style="zoom:1;' + css + 'display:inline-block;_display:inline;text-decoration:inherit;' +
  24171. 'padding-bottom:1px;padding-right:1px;line-height:' + lh + '">' + val + '</div>';
  24172. }
  24173. this.node.innerHTML = val;
  24174. // Sets text direction
  24175. var divs = this.node.getElementsByTagName('div');
  24176. if (divs.length > 0)
  24177. {
  24178. var dir = this.textDirection;
  24179. if (dir == mxConstants.TEXT_DIRECTION_AUTO && this.dialect != mxConstants.DIALECT_STRICTHTML)
  24180. {
  24181. dir = this.getAutoDirection();
  24182. }
  24183. if (dir == mxConstants.TEXT_DIRECTION_LTR || dir == mxConstants.TEXT_DIRECTION_RTL)
  24184. {
  24185. divs[divs.length - 1].setAttribute('dir', dir);
  24186. }
  24187. else
  24188. {
  24189. divs[divs.length - 1].removeAttribute('dir');
  24190. }
  24191. }
  24192. }
  24193. };
  24194. /**
  24195. * Function: updateFont
  24196. *
  24197. * Updates the HTML node(s) to reflect the latest bounds and scale.
  24198. */
  24199. mxText.prototype.updateFont = function(node)
  24200. {
  24201. var style = node.style;
  24202. style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? (this.size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  24203. style.fontSize = this.size + 'px';
  24204. style.fontFamily = this.family;
  24205. style.verticalAlign = 'top';
  24206. style.color = this.color;
  24207. if ((this.fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  24208. {
  24209. style.fontWeight = 'bold';
  24210. }
  24211. else
  24212. {
  24213. style.fontWeight = '';
  24214. }
  24215. if ((this.fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  24216. {
  24217. style.fontStyle = 'italic';
  24218. }
  24219. else
  24220. {
  24221. style.fontStyle = '';
  24222. }
  24223. var txtDecor = [];
  24224. if ((this.fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  24225. {
  24226. txtDecor.push('underline');
  24227. }
  24228. if ((this.fontStyle & mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  24229. {
  24230. txtDecor.push('line-through');
  24231. }
  24232. style.textDecoration = txtDecor.join(' ');
  24233. if (this.align == mxConstants.ALIGN_CENTER)
  24234. {
  24235. style.textAlign = 'center';
  24236. }
  24237. else if (this.align == mxConstants.ALIGN_RIGHT)
  24238. {
  24239. style.textAlign = 'right';
  24240. }
  24241. else
  24242. {
  24243. style.textAlign = 'left';
  24244. }
  24245. };
  24246. /**
  24247. * Function: updateSize
  24248. *
  24249. * Updates the HTML node(s) to reflect the latest bounds and scale.
  24250. */
  24251. mxText.prototype.updateSize = function(node, enableWrap)
  24252. {
  24253. var w = Math.max(0, Math.round(this.bounds.width / this.scale));
  24254. var h = Math.max(0, Math.round(this.bounds.height / this.scale));
  24255. var style = node.style;
  24256. // NOTE: Do not use maxWidth here because wrapping will
  24257. // go wrong if the cell is outside of the viewable area
  24258. if (this.clipped)
  24259. {
  24260. style.overflow = 'hidden';
  24261. if (!mxClient.IS_QUIRKS)
  24262. {
  24263. style.maxHeight = h + 'px';
  24264. style.maxWidth = w + 'px';
  24265. }
  24266. else
  24267. {
  24268. style.width = w + 'px';
  24269. }
  24270. }
  24271. else if (this.overflow == 'fill')
  24272. {
  24273. style.width = (w + 1) + 'px';
  24274. style.height = (h + 1) + 'px';
  24275. style.overflow = 'hidden';
  24276. }
  24277. else if (this.overflow == 'width')
  24278. {
  24279. style.width = (w + 1) + 'px';
  24280. style.maxHeight = (h + 1) + 'px';
  24281. style.overflow = 'hidden';
  24282. }
  24283. if (this.wrap && w > 0)
  24284. {
  24285. style.wordWrap = mxConstants.WORD_WRAP;
  24286. style.whiteSpace = 'normal';
  24287. style.width = w + 'px';
  24288. if (enableWrap && this.overflow != 'fill' && this.overflow != 'width')
  24289. {
  24290. var sizeDiv = node;
  24291. if (sizeDiv.firstChild != null && sizeDiv.firstChild.nodeName == 'DIV')
  24292. {
  24293. sizeDiv = sizeDiv.firstChild;
  24294. if (node.style.wordWrap == 'break-word')
  24295. {
  24296. sizeDiv.style.width = '100%';
  24297. }
  24298. }
  24299. var tmp = sizeDiv.offsetWidth;
  24300. // Workaround for text measuring in hidden containers
  24301. if (tmp == 0)
  24302. {
  24303. var prev = node.parentNode;
  24304. node.style.visibility = 'hidden';
  24305. document.body.appendChild(node);
  24306. tmp = sizeDiv.offsetWidth;
  24307. node.style.visibility = '';
  24308. prev.appendChild(node);
  24309. }
  24310. tmp += 3;
  24311. if (this.clipped)
  24312. {
  24313. tmp = Math.min(tmp, w);
  24314. }
  24315. style.width = tmp + 'px';
  24316. }
  24317. }
  24318. else
  24319. {
  24320. style.whiteSpace = 'nowrap';
  24321. }
  24322. };
  24323. /**
  24324. * Function: getMargin
  24325. *
  24326. * Returns the spacing as an <mxPoint>.
  24327. */
  24328. mxText.prototype.updateMargin = function()
  24329. {
  24330. this.margin = mxUtils.getAlignmentAsPoint(this.align, this.valign);
  24331. };
  24332. /**
  24333. * Function: getSpacing
  24334. *
  24335. * Returns the spacing as an <mxPoint>.
  24336. */
  24337. mxText.prototype.getSpacing = function()
  24338. {
  24339. var dx = 0;
  24340. var dy = 0;
  24341. if (this.align == mxConstants.ALIGN_CENTER)
  24342. {
  24343. dx = (this.spacingLeft - this.spacingRight) / 2;
  24344. }
  24345. else if (this.align == mxConstants.ALIGN_RIGHT)
  24346. {
  24347. dx = -this.spacingRight - this.baseSpacingRight;
  24348. }
  24349. else
  24350. {
  24351. dx = this.spacingLeft + this.baseSpacingLeft;
  24352. }
  24353. if (this.valign == mxConstants.ALIGN_MIDDLE)
  24354. {
  24355. dy = (this.spacingTop - this.spacingBottom) / 2;
  24356. }
  24357. else if (this.valign == mxConstants.ALIGN_BOTTOM)
  24358. {
  24359. dy = -this.spacingBottom - this.baseSpacingBottom;;
  24360. }
  24361. else
  24362. {
  24363. dy = this.spacingTop + this.baseSpacingTop;
  24364. }
  24365. return new mxPoint(dx, dy);
  24366. };
  24367. /**
  24368. * Copyright (c) 2006-2015, JGraph Ltd
  24369. * Copyright (c) 2006-2015, Gaudenz Alder
  24370. */
  24371. /**
  24372. * Class: mxTriangle
  24373. *
  24374. * Implementation of the triangle shape.
  24375. *
  24376. * Constructor: mxTriangle
  24377. *
  24378. * Constructs a new triangle shape.
  24379. */
  24380. function mxTriangle()
  24381. {
  24382. mxActor.call(this);
  24383. };
  24384. /**
  24385. * Extends mxActor.
  24386. */
  24387. mxUtils.extend(mxTriangle, mxActor);
  24388. /**
  24389. * Function: isRoundable
  24390. *
  24391. * Adds roundable support.
  24392. */
  24393. mxTriangle.prototype.isRoundable = function()
  24394. {
  24395. return true;
  24396. };
  24397. /**
  24398. * Function: redrawPath
  24399. *
  24400. * Draws the path for this shape.
  24401. */
  24402. mxTriangle.prototype.redrawPath = function(c, x, y, w, h)
  24403. {
  24404. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  24405. this.addPoints(c, [new mxPoint(0, 0), new mxPoint(w, 0.5 * h), new mxPoint(0, h)], this.isRounded, arcSize, true);
  24406. };
  24407. /**
  24408. * Copyright (c) 2006-2015, JGraph Ltd
  24409. * Copyright (c) 2006-2015, Gaudenz Alder
  24410. */
  24411. /**
  24412. * Class: mxHexagon
  24413. *
  24414. * Implementation of the hexagon shape.
  24415. *
  24416. * Constructor: mxHexagon
  24417. *
  24418. * Constructs a new hexagon shape.
  24419. */
  24420. function mxHexagon()
  24421. {
  24422. mxActor.call(this);
  24423. };
  24424. /**
  24425. * Extends mxActor.
  24426. */
  24427. mxUtils.extend(mxHexagon, mxActor);
  24428. /**
  24429. * Function: redrawPath
  24430. *
  24431. * Draws the path for this shape.
  24432. */
  24433. mxHexagon.prototype.redrawPath = function(c, x, y, w, h)
  24434. {
  24435. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  24436. this.addPoints(c, [new mxPoint(0.25 * w, 0), new mxPoint(0.75 * w, 0), new mxPoint(w, 0.5 * h), new mxPoint(0.75 * w, h),
  24437. new mxPoint(0.25 * w, h), new mxPoint(0, 0.5 * h)], this.isRounded, arcSize, true);
  24438. };
  24439. /**
  24440. * Copyright (c) 2006-2015, JGraph Ltd
  24441. * Copyright (c) 2006-2015, Gaudenz Alder
  24442. */
  24443. /**
  24444. * Class: mxLine
  24445. *
  24446. * Extends <mxShape> to implement a horizontal line shape.
  24447. * This shape is registered under <mxConstants.SHAPE_LINE> in
  24448. * <mxCellRenderer>.
  24449. *
  24450. * Constructor: mxLine
  24451. *
  24452. * Constructs a new line shape.
  24453. *
  24454. * Parameters:
  24455. *
  24456. * bounds - <mxRectangle> that defines the bounds. This is stored in
  24457. * <mxShape.bounds>.
  24458. * stroke - String that defines the stroke color. Default is 'black'. This is
  24459. * stored in <stroke>.
  24460. * strokewidth - Optional integer that defines the stroke width. Default is
  24461. * 1. This is stored in <strokewidth>.
  24462. */
  24463. function mxLine(bounds, stroke, strokewidth, vertical)
  24464. {
  24465. mxShape.call(this);
  24466. this.bounds = bounds;
  24467. this.stroke = stroke;
  24468. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  24469. this.vertical = (vertical != null) ? vertical : this.vertical;
  24470. };
  24471. /**
  24472. * Extends mxShape.
  24473. */
  24474. mxUtils.extend(mxLine, mxShape);
  24475. /**
  24476. * Function: vertical
  24477. *
  24478. * Whether to paint a vertical line.
  24479. */
  24480. mxLine.prototype.vertical = false;
  24481. /**
  24482. * Function: paintVertexShape
  24483. *
  24484. * Redirects to redrawPath for subclasses to work.
  24485. */
  24486. mxLine.prototype.paintVertexShape = function(c, x, y, w, h)
  24487. {
  24488. c.begin();
  24489. if (this.vertical)
  24490. {
  24491. var mid = x + w / 2;
  24492. c.moveTo(mid, y);
  24493. c.lineTo(mid, y + h);
  24494. }
  24495. else
  24496. {
  24497. var mid = y + h / 2;
  24498. c.moveTo(x, mid);
  24499. c.lineTo(x + w, mid);
  24500. }
  24501. c.stroke();
  24502. };
  24503. /**
  24504. * Copyright (c) 2006-2015, JGraph Ltd
  24505. * Copyright (c) 2006-2015, Gaudenz Alder
  24506. */
  24507. /**
  24508. * Class: mxImageShape
  24509. *
  24510. * Extends <mxShape> to implement an image shape. This shape is registered
  24511. * under <mxConstants.SHAPE_IMAGE> in <mxCellRenderer>.
  24512. *
  24513. * Constructor: mxImageShape
  24514. *
  24515. * Constructs a new image shape.
  24516. *
  24517. * Parameters:
  24518. *
  24519. * bounds - <mxRectangle> that defines the bounds. This is stored in
  24520. * <mxShape.bounds>.
  24521. * image - String that specifies the URL of the image. This is stored in
  24522. * <image>.
  24523. * fill - String that defines the fill color. This is stored in <fill>.
  24524. * stroke - String that defines the stroke color. This is stored in <stroke>.
  24525. * strokewidth - Optional integer that defines the stroke width. Default is
  24526. * 0. This is stored in <strokewidth>.
  24527. */
  24528. function mxImageShape(bounds, image, fill, stroke, strokewidth)
  24529. {
  24530. mxShape.call(this);
  24531. this.bounds = bounds;
  24532. this.image = image;
  24533. this.fill = fill;
  24534. this.stroke = stroke;
  24535. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  24536. this.shadow = false;
  24537. };
  24538. /**
  24539. * Extends mxShape.
  24540. */
  24541. mxUtils.extend(mxImageShape, mxRectangleShape);
  24542. /**
  24543. * Variable: preserveImageAspect
  24544. *
  24545. * Switch to preserve image aspect. Default is true.
  24546. */
  24547. mxImageShape.prototype.preserveImageAspect = true;
  24548. /**
  24549. * Function: getSvgScreenOffset
  24550. *
  24551. * Disables offset in IE9 for crisper image output.
  24552. */
  24553. mxImageShape.prototype.getSvgScreenOffset = function()
  24554. {
  24555. return 0;
  24556. };
  24557. /**
  24558. * Function: apply
  24559. *
  24560. * Overrides <mxShape.apply> to replace the fill and stroke colors with the
  24561. * respective values from <mxConstants.STYLE_IMAGE_BACKGROUND> and
  24562. * <mxConstants.STYLE_IMAGE_BORDER>.
  24563. *
  24564. * Applies the style of the given <mxCellState> to the shape. This
  24565. * implementation assigns the following styles to local fields:
  24566. *
  24567. * - <mxConstants.STYLE_IMAGE_BACKGROUND> => fill
  24568. * - <mxConstants.STYLE_IMAGE_BORDER> => stroke
  24569. *
  24570. * Parameters:
  24571. *
  24572. * state - <mxCellState> of the corresponding cell.
  24573. */
  24574. mxImageShape.prototype.apply = function(state)
  24575. {
  24576. mxShape.prototype.apply.apply(this, arguments);
  24577. this.fill = null;
  24578. this.stroke = null;
  24579. this.gradient = null;
  24580. if (this.style != null)
  24581. {
  24582. this.preserveImageAspect = mxUtils.getNumber(this.style, mxConstants.STYLE_IMAGE_ASPECT, 1) == 1;
  24583. // Legacy support for imageFlipH/V
  24584. this.flipH = this.flipH || mxUtils.getValue(this.style, 'imageFlipH', 0) == 1;
  24585. this.flipV = this.flipV || mxUtils.getValue(this.style, 'imageFlipV', 0) == 1;
  24586. }
  24587. };
  24588. /**
  24589. * Function: isHtmlAllowed
  24590. *
  24591. * Returns true if HTML is allowed for this shape. This implementation always
  24592. * returns false.
  24593. */
  24594. mxImageShape.prototype.isHtmlAllowed = function()
  24595. {
  24596. return !this.preserveImageAspect;
  24597. };
  24598. /**
  24599. * Function: createHtml
  24600. *
  24601. * Creates and returns the HTML DOM node(s) to represent
  24602. * this shape. This implementation falls back to <createVml>
  24603. * so that the HTML creation is optional.
  24604. */
  24605. mxImageShape.prototype.createHtml = function()
  24606. {
  24607. var node = document.createElement('div');
  24608. node.style.position = 'absolute';
  24609. return node;
  24610. };
  24611. /**
  24612. * Function: isRoundable
  24613. *
  24614. * Disables inherited roundable support.
  24615. */
  24616. mxImageShape.prototype.isRoundable = function(c, x, y, w, h)
  24617. {
  24618. return false;
  24619. };
  24620. /**
  24621. * Function: paintVertexShape
  24622. *
  24623. * Generic background painting implementation.
  24624. */
  24625. mxImageShape.prototype.paintVertexShape = function(c, x, y, w, h)
  24626. {
  24627. if (this.image != null)
  24628. {
  24629. var fill = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_BACKGROUND, null);
  24630. var stroke = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_BORDER, null);
  24631. if (fill != null)
  24632. {
  24633. // Stroke rendering required for shadow
  24634. c.setFillColor(fill);
  24635. c.setStrokeColor(stroke);
  24636. c.rect(x, y, w, h);
  24637. c.fillAndStroke();
  24638. }
  24639. // FlipH/V are implicit via mxShape.updateTransform
  24640. c.image(x, y, w, h, this.image, this.preserveImageAspect, false, false);
  24641. var stroke = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_BORDER, null);
  24642. if (stroke != null)
  24643. {
  24644. c.setShadow(false);
  24645. c.setStrokeColor(stroke);
  24646. c.rect(x, y, w, h);
  24647. c.stroke();
  24648. }
  24649. }
  24650. else
  24651. {
  24652. mxRectangleShape.prototype.paintBackground.apply(this, arguments);
  24653. }
  24654. };
  24655. /**
  24656. * Function: redraw
  24657. *
  24658. * Overrides <mxShape.redraw> to preserve the aspect ratio of images.
  24659. */
  24660. mxImageShape.prototype.redrawHtmlShape = function()
  24661. {
  24662. this.node.style.left = Math.round(this.bounds.x) + 'px';
  24663. this.node.style.top = Math.round(this.bounds.y) + 'px';
  24664. this.node.style.width = Math.max(0, Math.round(this.bounds.width)) + 'px';
  24665. this.node.style.height = Math.max(0, Math.round(this.bounds.height)) + 'px';
  24666. this.node.innerHTML = '';
  24667. if (this.image != null)
  24668. {
  24669. var fill = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_BACKGROUND, '');
  24670. var stroke = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_BORDER, '');
  24671. this.node.style.backgroundColor = fill;
  24672. this.node.style.borderColor = stroke;
  24673. // VML image supports PNG in IE6
  24674. var useVml = mxClient.IS_IE6 || ((document.documentMode == null || document.documentMode <= 8) && this.rotation != 0);
  24675. var img = document.createElement((useVml) ? mxClient.VML_PREFIX + ':image' : 'img');
  24676. img.setAttribute('border', '0');
  24677. img.style.position = 'absolute';
  24678. img.src = this.image;
  24679. var filter = (this.opacity < 100) ? 'alpha(opacity=' + this.opacity + ')' : '';
  24680. this.node.style.filter = filter;
  24681. if (this.flipH && this.flipV)
  24682. {
  24683. filter += 'progid:DXImageTransform.Microsoft.BasicImage(rotation=2)';
  24684. }
  24685. else if (this.flipH)
  24686. {
  24687. filter += 'progid:DXImageTransform.Microsoft.BasicImage(mirror=1)';
  24688. }
  24689. else if (this.flipV)
  24690. {
  24691. filter += 'progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)';
  24692. }
  24693. if (img.style.filter != filter)
  24694. {
  24695. img.style.filter = filter;
  24696. }
  24697. if (img.nodeName == 'image')
  24698. {
  24699. img.style.rotation = this.rotation;
  24700. }
  24701. else if (this.rotation != 0)
  24702. {
  24703. // LATER: Add flipV/H support
  24704. mxUtils.setPrefixedStyle(img.style, 'transform', 'rotate(' + this.rotation + 'deg)');
  24705. }
  24706. else
  24707. {
  24708. mxUtils.setPrefixedStyle(img.style, 'transform', '');
  24709. }
  24710. // Known problem: IE clips top line of image for certain angles
  24711. img.style.width = this.node.style.width;
  24712. img.style.height = this.node.style.height;
  24713. this.node.style.backgroundImage = '';
  24714. this.node.appendChild(img);
  24715. }
  24716. else
  24717. {
  24718. this.setTransparentBackgroundImage(this.node);
  24719. }
  24720. };
  24721. /**
  24722. * Copyright (c) 2006-2015, JGraph Ltd
  24723. * Copyright (c) 2006-2015, Gaudenz Alder
  24724. */
  24725. /**
  24726. * Class: mxLabel
  24727. *
  24728. * Extends <mxShape> to implement an image shape with a label.
  24729. * This shape is registered under <mxConstants.SHAPE_LABEL> in
  24730. * <mxCellRenderer>.
  24731. *
  24732. * Constructor: mxLabel
  24733. *
  24734. * Constructs a new label shape.
  24735. *
  24736. * Parameters:
  24737. *
  24738. * bounds - <mxRectangle> that defines the bounds. This is stored in
  24739. * <mxShape.bounds>.
  24740. * fill - String that defines the fill color. This is stored in <fill>.
  24741. * stroke - String that defines the stroke color. This is stored in <stroke>.
  24742. * strokewidth - Optional integer that defines the stroke width. Default is
  24743. * 1. This is stored in <strokewidth>.
  24744. */
  24745. function mxLabel(bounds, fill, stroke, strokewidth)
  24746. {
  24747. mxRectangleShape.call(this, bounds, fill, stroke, strokewidth);
  24748. };
  24749. /**
  24750. * Extends mxShape.
  24751. */
  24752. mxUtils.extend(mxLabel, mxRectangleShape);
  24753. /**
  24754. * Variable: imageSize
  24755. *
  24756. * Default width and height for the image. Default is
  24757. * <mxConstants.DEFAULT_IMAGESIZE>.
  24758. */
  24759. mxLabel.prototype.imageSize = mxConstants.DEFAULT_IMAGESIZE;
  24760. /**
  24761. * Variable: spacing
  24762. *
  24763. * Default value for image spacing. Default is 2.
  24764. */
  24765. mxLabel.prototype.spacing = 2;
  24766. /**
  24767. * Variable: indicatorSize
  24768. *
  24769. * Default width and height for the indicicator. Default is 10.
  24770. */
  24771. mxLabel.prototype.indicatorSize = 10;
  24772. /**
  24773. * Variable: indicatorSpacing
  24774. *
  24775. * Default spacing between image and indicator. Default is 2.
  24776. */
  24777. mxLabel.prototype.indicatorSpacing = 2;
  24778. /**
  24779. * Function: init
  24780. *
  24781. * Initializes the shape and the <indicator>.
  24782. */
  24783. mxLabel.prototype.init = function(container)
  24784. {
  24785. mxShape.prototype.init.apply(this, arguments);
  24786. if (this.indicatorShape != null)
  24787. {
  24788. this.indicator = new this.indicatorShape();
  24789. this.indicator.dialect = this.dialect;
  24790. this.indicator.init(this.node);
  24791. }
  24792. };
  24793. /**
  24794. * Function: redraw
  24795. *
  24796. * Reconfigures this shape. This will update the colors of the indicator
  24797. * and reconfigure it if required.
  24798. */
  24799. mxLabel.prototype.redraw = function()
  24800. {
  24801. if (this.indicator != null)
  24802. {
  24803. this.indicator.fill = this.indicatorColor;
  24804. this.indicator.stroke = this.indicatorStrokeColor;
  24805. this.indicator.gradient = this.indicatorGradientColor;
  24806. this.indicator.direction = this.indicatorDirection;
  24807. this.indicator.redraw();
  24808. }
  24809. mxShape.prototype.redraw.apply(this, arguments);
  24810. };
  24811. /**
  24812. * Function: isHtmlAllowed
  24813. *
  24814. * Returns true for non-rounded, non-rotated shapes with no glass gradient and
  24815. * no indicator shape.
  24816. */
  24817. mxLabel.prototype.isHtmlAllowed = function()
  24818. {
  24819. return mxRectangleShape.prototype.isHtmlAllowed.apply(this, arguments) &&
  24820. this.indicatorColor == null && this.indicatorShape == null;
  24821. };
  24822. /**
  24823. * Function: paintForeground
  24824. *
  24825. * Generic background painting implementation.
  24826. */
  24827. mxLabel.prototype.paintForeground = function(c, x, y, w, h)
  24828. {
  24829. this.paintImage(c, x, y, w, h);
  24830. this.paintIndicator(c, x, y, w, h);
  24831. mxRectangleShape.prototype.paintForeground.apply(this, arguments);
  24832. };
  24833. /**
  24834. * Function: paintImage
  24835. *
  24836. * Generic background painting implementation.
  24837. */
  24838. mxLabel.prototype.paintImage = function(c, x, y, w, h)
  24839. {
  24840. if (this.image != null)
  24841. {
  24842. var bounds = this.getImageBounds(x, y, w, h);
  24843. c.image(bounds.x, bounds.y, bounds.width, bounds.height, this.image, false, false, false);
  24844. }
  24845. };
  24846. /**
  24847. * Function: getImageBounds
  24848. *
  24849. * Generic background painting implementation.
  24850. */
  24851. mxLabel.prototype.getImageBounds = function(x, y, w, h)
  24852. {
  24853. var align = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_ALIGN, mxConstants.ALIGN_LEFT);
  24854. var valign = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
  24855. var width = mxUtils.getNumber(this.style, mxConstants.STYLE_IMAGE_WIDTH, mxConstants.DEFAULT_IMAGESIZE);
  24856. var height = mxUtils.getNumber(this.style, mxConstants.STYLE_IMAGE_HEIGHT, mxConstants.DEFAULT_IMAGESIZE);
  24857. var spacing = mxUtils.getNumber(this.style, mxConstants.STYLE_SPACING, this.spacing) + 5;
  24858. if (align == mxConstants.ALIGN_CENTER)
  24859. {
  24860. x += (w - width) / 2;
  24861. }
  24862. else if (align == mxConstants.ALIGN_RIGHT)
  24863. {
  24864. x += w - width - spacing;
  24865. }
  24866. else // default is left
  24867. {
  24868. x += spacing;
  24869. }
  24870. if (valign == mxConstants.ALIGN_TOP)
  24871. {
  24872. y += spacing;
  24873. }
  24874. else if (valign == mxConstants.ALIGN_BOTTOM)
  24875. {
  24876. y += h - height - spacing;
  24877. }
  24878. else // default is middle
  24879. {
  24880. y += (h - height) / 2;
  24881. }
  24882. return new mxRectangle(x, y, width, height);
  24883. };
  24884. /**
  24885. * Function: paintIndicator
  24886. *
  24887. * Generic background painting implementation.
  24888. */
  24889. mxLabel.prototype.paintIndicator = function(c, x, y, w, h)
  24890. {
  24891. if (this.indicator != null)
  24892. {
  24893. this.indicator.bounds = this.getIndicatorBounds(x, y, w, h);
  24894. this.indicator.paint(c);
  24895. }
  24896. else if (this.indicatorImage != null)
  24897. {
  24898. var bounds = this.getIndicatorBounds(x, y, w, h);
  24899. c.image(bounds.x, bounds.y, bounds.width, bounds.height, this.indicatorImage, false, false, false);
  24900. }
  24901. };
  24902. /**
  24903. * Function: getIndicatorBounds
  24904. *
  24905. * Generic background painting implementation.
  24906. */
  24907. mxLabel.prototype.getIndicatorBounds = function(x, y, w, h)
  24908. {
  24909. var align = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_ALIGN, mxConstants.ALIGN_LEFT);
  24910. var valign = mxUtils.getValue(this.style, mxConstants.STYLE_IMAGE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
  24911. var width = mxUtils.getNumber(this.style, mxConstants.STYLE_INDICATOR_WIDTH, this.indicatorSize);
  24912. var height = mxUtils.getNumber(this.style, mxConstants.STYLE_INDICATOR_HEIGHT, this.indicatorSize);
  24913. var spacing = this.spacing + 5;
  24914. if (align == mxConstants.ALIGN_RIGHT)
  24915. {
  24916. x += w - width - spacing;
  24917. }
  24918. else if (align == mxConstants.ALIGN_CENTER)
  24919. {
  24920. x += (w - width) / 2;
  24921. }
  24922. else // default is left
  24923. {
  24924. x += spacing;
  24925. }
  24926. if (valign == mxConstants.ALIGN_BOTTOM)
  24927. {
  24928. y += h - height - spacing;
  24929. }
  24930. else if (valign == mxConstants.ALIGN_TOP)
  24931. {
  24932. y += spacing;
  24933. }
  24934. else // default is middle
  24935. {
  24936. y += (h - height) / 2;
  24937. }
  24938. return new mxRectangle(x, y, width, height);
  24939. };
  24940. /**
  24941. * Function: redrawHtmlShape
  24942. *
  24943. * Generic background painting implementation.
  24944. */
  24945. mxLabel.prototype.redrawHtmlShape = function()
  24946. {
  24947. mxRectangleShape.prototype.redrawHtmlShape.apply(this, arguments);
  24948. // Removes all children
  24949. while(this.node.hasChildNodes())
  24950. {
  24951. this.node.removeChild(this.node.lastChild);
  24952. }
  24953. if (this.image != null)
  24954. {
  24955. var node = document.createElement('img');
  24956. node.style.position = 'relative';
  24957. node.setAttribute('border', '0');
  24958. var bounds = this.getImageBounds(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
  24959. bounds.x -= this.bounds.x;
  24960. bounds.y -= this.bounds.y;
  24961. node.style.left = Math.round(bounds.x) + 'px';
  24962. node.style.top = Math.round(bounds.y) + 'px';
  24963. node.style.width = Math.round(bounds.width) + 'px';
  24964. node.style.height = Math.round(bounds.height) + 'px';
  24965. node.src = this.image;
  24966. this.node.appendChild(node);
  24967. }
  24968. };
  24969. /**
  24970. * Copyright (c) 2006-2015, JGraph Ltd
  24971. * Copyright (c) 2006-2015, Gaudenz Alder
  24972. */
  24973. /**
  24974. * Class: mxCylinder
  24975. *
  24976. * Extends <mxShape> to implement an cylinder shape. If a
  24977. * custom shape with one filled area and an overlay path is
  24978. * needed, then this shape's <redrawPath> should be overridden.
  24979. * This shape is registered under <mxConstants.SHAPE_CYLINDER>
  24980. * in <mxCellRenderer>.
  24981. *
  24982. * Constructor: mxCylinder
  24983. *
  24984. * Constructs a new cylinder shape.
  24985. *
  24986. * Parameters:
  24987. *
  24988. * bounds - <mxRectangle> that defines the bounds. This is stored in
  24989. * <mxShape.bounds>.
  24990. * fill - String that defines the fill color. This is stored in <fill>.
  24991. * stroke - String that defines the stroke color. This is stored in <stroke>.
  24992. * strokewidth - Optional integer that defines the stroke width. Default is
  24993. * 1. This is stored in <strokewidth>.
  24994. */
  24995. function mxCylinder(bounds, fill, stroke, strokewidth)
  24996. {
  24997. mxShape.call(this);
  24998. this.bounds = bounds;
  24999. this.fill = fill;
  25000. this.stroke = stroke;
  25001. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  25002. };
  25003. /**
  25004. * Extends mxShape.
  25005. */
  25006. mxUtils.extend(mxCylinder, mxShape);
  25007. /**
  25008. * Variable: maxHeight
  25009. *
  25010. * Defines the maximum height of the top and bottom part
  25011. * of the cylinder shape.
  25012. */
  25013. mxCylinder.prototype.maxHeight = 40;
  25014. /**
  25015. * Variable: svgStrokeTolerance
  25016. *
  25017. * Sets stroke tolerance to 0 for SVG.
  25018. */
  25019. mxCylinder.prototype.svgStrokeTolerance = 0;
  25020. /**
  25021. * Function: paintVertexShape
  25022. *
  25023. * Redirects to redrawPath for subclasses to work.
  25024. */
  25025. mxCylinder.prototype.paintVertexShape = function(c, x, y, w, h)
  25026. {
  25027. c.translate(x, y);
  25028. c.begin();
  25029. this.redrawPath(c, x, y, w, h, false);
  25030. c.fillAndStroke();
  25031. if (!this.outline || this.style == null || mxUtils.getValue(
  25032. this.style, mxConstants.STYLE_BACKGROUND_OUTLINE, 0) == 0)
  25033. {
  25034. c.setShadow(false);
  25035. c.begin();
  25036. this.redrawPath(c, x, y, w, h, true);
  25037. c.stroke();
  25038. }
  25039. };
  25040. /**
  25041. * Function: redrawPath
  25042. *
  25043. * Draws the path for this shape.
  25044. */
  25045. mxCylinder.prototype.getCylinderSize = function(x, y, w, h)
  25046. {
  25047. return Math.min(this.maxHeight, Math.round(h / 5));
  25048. };
  25049. /**
  25050. * Function: redrawPath
  25051. *
  25052. * Draws the path for this shape.
  25053. */
  25054. mxCylinder.prototype.redrawPath = function(c, x, y, w, h, isForeground)
  25055. {
  25056. var dy = this.getCylinderSize(x, y, w, h);
  25057. if ((isForeground && this.fill != null) || (!isForeground && this.fill == null))
  25058. {
  25059. c.moveTo(0, dy);
  25060. c.curveTo(0, 2 * dy, w, 2 * dy, w, dy);
  25061. // Needs separate shapes for correct hit-detection
  25062. if (!isForeground)
  25063. {
  25064. c.stroke();
  25065. c.begin();
  25066. }
  25067. }
  25068. if (!isForeground)
  25069. {
  25070. c.moveTo(0, dy);
  25071. c.curveTo(0, -dy / 3, w, -dy / 3, w, dy);
  25072. c.lineTo(w, h - dy);
  25073. c.curveTo(w, h + dy / 3, 0, h + dy / 3, 0, h - dy);
  25074. c.close();
  25075. }
  25076. };
  25077. /**
  25078. * Copyright (c) 2006-2015, JGraph Ltd
  25079. * Copyright (c) 2006-2015, Gaudenz Alder
  25080. */
  25081. /**
  25082. * Class: mxConnector
  25083. *
  25084. * Extends <mxShape> to implement a connector shape. The connector
  25085. * shape allows for arrow heads on either side.
  25086. *
  25087. * This shape is registered under <mxConstants.SHAPE_CONNECTOR> in
  25088. * <mxCellRenderer>.
  25089. *
  25090. * Constructor: mxConnector
  25091. *
  25092. * Constructs a new connector shape.
  25093. *
  25094. * Parameters:
  25095. *
  25096. * points - Array of <mxPoints> that define the points. This is stored in
  25097. * <mxShape.points>.
  25098. * stroke - String that defines the stroke color. This is stored in <stroke>.
  25099. * Default is 'black'.
  25100. * strokewidth - Optional integer that defines the stroke width. Default is
  25101. * 1. This is stored in <strokewidth>.
  25102. */
  25103. function mxConnector(points, stroke, strokewidth)
  25104. {
  25105. mxPolyline.call(this, points, stroke, strokewidth);
  25106. };
  25107. /**
  25108. * Extends mxPolyline.
  25109. */
  25110. mxUtils.extend(mxConnector, mxPolyline);
  25111. /**
  25112. * Function: updateBoundingBox
  25113. *
  25114. * Updates the <boundingBox> for this shape using <createBoundingBox> and
  25115. * <augmentBoundingBox> and stores the result in <boundingBox>.
  25116. */
  25117. mxConnector.prototype.updateBoundingBox = function()
  25118. {
  25119. this.useSvgBoundingBox = this.style != null && this.style[mxConstants.STYLE_CURVED] == 1;
  25120. mxShape.prototype.updateBoundingBox.apply(this, arguments);
  25121. };
  25122. /**
  25123. * Function: paintEdgeShape
  25124. *
  25125. * Paints the line shape.
  25126. */
  25127. mxConnector.prototype.paintEdgeShape = function(c, pts)
  25128. {
  25129. // The indirection via functions for markers is needed in
  25130. // order to apply the offsets before painting the line and
  25131. // paint the markers after painting the line.
  25132. var sourceMarker = this.createMarker(c, pts, true);
  25133. var targetMarker = this.createMarker(c, pts, false);
  25134. mxPolyline.prototype.paintEdgeShape.apply(this, arguments);
  25135. // Disables shadows, dashed styles and fixes fill color for markers
  25136. c.setFillColor(this.stroke);
  25137. c.setShadow(false);
  25138. c.setDashed(false);
  25139. if (sourceMarker != null)
  25140. {
  25141. sourceMarker();
  25142. }
  25143. if (targetMarker != null)
  25144. {
  25145. targetMarker();
  25146. }
  25147. };
  25148. /**
  25149. * Function: createMarker
  25150. *
  25151. * Prepares the marker by adding offsets in pts and returning a function to
  25152. * paint the marker.
  25153. */
  25154. mxConnector.prototype.createMarker = function(c, pts, source)
  25155. {
  25156. var result = null;
  25157. var n = pts.length;
  25158. var type = mxUtils.getValue(this.style, (source) ? mxConstants.STYLE_STARTARROW : mxConstants.STYLE_ENDARROW);
  25159. var p0 = (source) ? pts[1] : pts[n - 2];
  25160. var pe = (source) ? pts[0] : pts[n - 1];
  25161. if (type != null && p0 != null && pe != null)
  25162. {
  25163. var count = 1;
  25164. // Uses next non-overlapping point
  25165. while (count < n - 1 && Math.round(p0.x - pe.x) == 0 && Math.round(p0.y - pe.y) == 0)
  25166. {
  25167. p0 = (source) ? pts[1 + count] : pts[n - 2 - count];
  25168. count++;
  25169. }
  25170. // Computes the norm and the inverse norm
  25171. var dx = pe.x - p0.x;
  25172. var dy = pe.y - p0.y;
  25173. var dist = Math.max(1, Math.sqrt(dx * dx + dy * dy));
  25174. var unitX = dx / dist;
  25175. var unitY = dy / dist;
  25176. var size = mxUtils.getNumber(this.style, (source) ? mxConstants.STYLE_STARTSIZE : mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE);
  25177. // Allow for stroke width in the end point used and the
  25178. // orthogonal vectors describing the direction of the marker
  25179. var filled = this.style[(source) ? mxConstants.STYLE_STARTFILL : mxConstants.STYLE_ENDFILL] != 0;
  25180. result = mxMarker.createMarker(c, this, type, pe, unitX, unitY, size, source, this.strokewidth, filled);
  25181. }
  25182. return result;
  25183. };
  25184. /**
  25185. * Function: augmentBoundingBox
  25186. *
  25187. * Augments the bounding box with the strokewidth and shadow offsets.
  25188. */
  25189. mxConnector.prototype.augmentBoundingBox = function(bbox)
  25190. {
  25191. mxShape.prototype.augmentBoundingBox.apply(this, arguments);
  25192. // Adds marker sizes
  25193. var size = 0;
  25194. if (mxUtils.getValue(this.style, mxConstants.STYLE_STARTARROW, mxConstants.NONE) != mxConstants.NONE)
  25195. {
  25196. size = mxUtils.getNumber(this.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_MARKERSIZE) + 1;
  25197. }
  25198. if (mxUtils.getValue(this.style, mxConstants.STYLE_ENDARROW, mxConstants.NONE) != mxConstants.NONE)
  25199. {
  25200. size = Math.max(size, mxUtils.getNumber(this.style, mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE)) + 1;
  25201. }
  25202. bbox.grow(size * this.scale);
  25203. };
  25204. /**
  25205. * Copyright (c) 2006-2015, JGraph Ltd
  25206. * Copyright (c) 2006-2015, Gaudenz Alder
  25207. */
  25208. /**
  25209. * Class: mxSwimlane
  25210. *
  25211. * Extends <mxShape> to implement a swimlane shape. This shape is registered
  25212. * under <mxConstants.SHAPE_SWIMLANE> in <mxCellRenderer>. Use the
  25213. * <mxConstants.STYLE_STYLE_STARTSIZE> to define the size of the title
  25214. * region, <mxConstants.STYLE_SWIMLANE_FILLCOLOR> for the content area fill,
  25215. * <mxConstants.STYLE_SEPARATORCOLOR> to draw an additional vertical separator
  25216. * and <mxConstants.STYLE_SWIMLANE_LINE> to hide the line between the title
  25217. * region and the content area. The <mxConstants.STYLE_HORIZONTAL> affects
  25218. * the orientation of this shape, not only its label.
  25219. *
  25220. * Constructor: mxSwimlane
  25221. *
  25222. * Constructs a new swimlane shape.
  25223. *
  25224. * Parameters:
  25225. *
  25226. * bounds - <mxRectangle> that defines the bounds. This is stored in
  25227. * <mxShape.bounds>.
  25228. * fill - String that defines the fill color. This is stored in <fill>.
  25229. * stroke - String that defines the stroke color. This is stored in <stroke>.
  25230. * strokewidth - Optional integer that defines the stroke width. Default is
  25231. * 1. This is stored in <strokewidth>.
  25232. */
  25233. function mxSwimlane(bounds, fill, stroke, strokewidth)
  25234. {
  25235. mxShape.call(this);
  25236. this.bounds = bounds;
  25237. this.fill = fill;
  25238. this.stroke = stroke;
  25239. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  25240. };
  25241. /**
  25242. * Extends mxShape.
  25243. */
  25244. mxUtils.extend(mxSwimlane, mxShape);
  25245. /**
  25246. * Variable: imageSize
  25247. *
  25248. * Default imagewidth and imageheight if an image but no imagewidth
  25249. * and imageheight are defined in the style. Value is 16.
  25250. */
  25251. mxSwimlane.prototype.imageSize = 16;
  25252. /**
  25253. * Function: isRoundable
  25254. *
  25255. * Adds roundable support.
  25256. */
  25257. mxSwimlane.prototype.isRoundable = function(c, x, y, w, h)
  25258. {
  25259. return true;
  25260. };
  25261. /**
  25262. * Function: getGradientBounds
  25263. *
  25264. * Returns the bounding box for the gradient box for this shape.
  25265. */
  25266. mxSwimlane.prototype.getTitleSize = function()
  25267. {
  25268. return Math.max(0, mxUtils.getValue(this.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE));
  25269. };
  25270. /**
  25271. * Function: getGradientBounds
  25272. *
  25273. * Returns the bounding box for the gradient box for this shape.
  25274. */
  25275. mxSwimlane.prototype.getLabelBounds = function(rect)
  25276. {
  25277. var start = this.getTitleSize();
  25278. var bounds = new mxRectangle(rect.x, rect.y, rect.width, rect.height);
  25279. var horizontal = this.isHorizontal();
  25280. var flipH = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPH, 0) == 1;
  25281. var flipV = mxUtils.getValue(this.style, mxConstants.STYLE_FLIPV, 0) == 1;
  25282. // East is default
  25283. var shapeVertical = (this.direction == mxConstants.DIRECTION_NORTH ||
  25284. this.direction == mxConstants.DIRECTION_SOUTH);
  25285. var realHorizontal = horizontal == !shapeVertical;
  25286. var realFlipH = !realHorizontal && flipH != (this.direction == mxConstants.DIRECTION_SOUTH ||
  25287. this.direction == mxConstants.DIRECTION_WEST);
  25288. var realFlipV = realHorizontal && flipV != (this.direction == mxConstants.DIRECTION_SOUTH ||
  25289. this.direction == mxConstants.DIRECTION_WEST);
  25290. // Shape is horizontal
  25291. if (!shapeVertical)
  25292. {
  25293. var tmp = Math.min(bounds.height, start * this.scale);
  25294. if (realFlipH || realFlipV)
  25295. {
  25296. bounds.y += bounds.height - tmp;
  25297. }
  25298. bounds.height = tmp;
  25299. }
  25300. else
  25301. {
  25302. var tmp = Math.min(bounds.width, start * this.scale);
  25303. if (realFlipH || realFlipV)
  25304. {
  25305. bounds.x += bounds.width - tmp;
  25306. }
  25307. bounds.width = tmp;
  25308. }
  25309. return bounds;
  25310. };
  25311. /**
  25312. * Function: getGradientBounds
  25313. *
  25314. * Returns the bounding box for the gradient box for this shape.
  25315. */
  25316. mxSwimlane.prototype.getGradientBounds = function(c, x, y, w, h)
  25317. {
  25318. var start = this.getTitleSize();
  25319. if (this.isHorizontal())
  25320. {
  25321. start = Math.min(start, h);
  25322. return new mxRectangle(x, y, w, start);
  25323. }
  25324. else
  25325. {
  25326. start = Math.min(start, w);
  25327. return new mxRectangle(x, y, start, h);
  25328. }
  25329. };
  25330. /**
  25331. * Function: getSwimlaneArcSize
  25332. *
  25333. * Returns the arcsize for the swimlane.
  25334. */
  25335. mxSwimlane.prototype.getSwimlaneArcSize = function(w, h, start)
  25336. {
  25337. if (mxUtils.getValue(this.style, mxConstants.STYLE_ABSOLUTE_ARCSIZE, 0) == '1')
  25338. {
  25339. return Math.min(w / 2, Math.min(h / 2, mxUtils.getValue(this.style,
  25340. mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2));
  25341. }
  25342. else
  25343. {
  25344. var f = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.RECTANGLE_ROUNDING_FACTOR * 100) / 100;
  25345. return start * f * 3;
  25346. }
  25347. };
  25348. /**
  25349. * Function: isHorizontal
  25350. *
  25351. * Paints the swimlane vertex shape.
  25352. */
  25353. mxSwimlane.prototype.isHorizontal = function()
  25354. {
  25355. return mxUtils.getValue(this.style, mxConstants.STYLE_HORIZONTAL, 1) == 1;
  25356. };
  25357. /**
  25358. * Function: paintVertexShape
  25359. *
  25360. * Paints the swimlane vertex shape.
  25361. */
  25362. mxSwimlane.prototype.paintVertexShape = function(c, x, y, w, h)
  25363. {
  25364. var start = this.getTitleSize();
  25365. var fill = mxUtils.getValue(this.style, mxConstants.STYLE_SWIMLANE_FILLCOLOR, mxConstants.NONE);
  25366. var swimlaneLine = mxUtils.getValue(this.style, mxConstants.STYLE_SWIMLANE_LINE, 1) == 1;
  25367. var r = 0;
  25368. if (this.isHorizontal())
  25369. {
  25370. start = Math.min(start, h);
  25371. }
  25372. else
  25373. {
  25374. start = Math.min(start, w);
  25375. }
  25376. c.translate(x, y);
  25377. if (!this.isRounded)
  25378. {
  25379. this.paintSwimlane(c, x, y, w, h, start, fill, swimlaneLine);
  25380. }
  25381. else
  25382. {
  25383. r = this.getSwimlaneArcSize(w, h, start);
  25384. r = Math.min(((this.isHorizontal()) ? h : w) - start, Math.min(start, r));
  25385. this.paintRoundedSwimlane(c, x, y, w, h, start, r, fill, swimlaneLine);
  25386. }
  25387. var sep = mxUtils.getValue(this.style, mxConstants.STYLE_SEPARATORCOLOR, mxConstants.NONE);
  25388. this.paintSeparator(c, x, y, w, h, start, sep);
  25389. if (this.image != null)
  25390. {
  25391. var bounds = this.getImageBounds(x, y, w, h);
  25392. c.image(bounds.x - x, bounds.y - y, bounds.width, bounds.height,
  25393. this.image, false, false, false);
  25394. }
  25395. if (this.glass)
  25396. {
  25397. c.setShadow(false);
  25398. this.paintGlassEffect(c, 0, 0, w, start, r);
  25399. }
  25400. };
  25401. /**
  25402. * Function: paintSwimlane
  25403. *
  25404. * Paints the swimlane vertex shape.
  25405. */
  25406. mxSwimlane.prototype.paintSwimlane = function(c, x, y, w, h, start, fill, swimlaneLine)
  25407. {
  25408. c.begin();
  25409. var events = true;
  25410. if (this.style != null)
  25411. {
  25412. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  25413. }
  25414. if (!events && (this.fill == null || this.fill == mxConstants.NONE))
  25415. {
  25416. c.pointerEvents = false;
  25417. }
  25418. if (this.isHorizontal())
  25419. {
  25420. c.moveTo(0, start);
  25421. c.lineTo(0, 0);
  25422. c.lineTo(w, 0);
  25423. c.lineTo(w, start);
  25424. c.fillAndStroke();
  25425. if (start < h)
  25426. {
  25427. if (fill == mxConstants.NONE || !events)
  25428. {
  25429. c.pointerEvents = false;
  25430. }
  25431. if (fill != mxConstants.NONE)
  25432. {
  25433. c.setFillColor(fill);
  25434. }
  25435. c.begin();
  25436. c.moveTo(0, start);
  25437. c.lineTo(0, h);
  25438. c.lineTo(w, h);
  25439. c.lineTo(w, start);
  25440. if (fill == mxConstants.NONE)
  25441. {
  25442. c.stroke();
  25443. }
  25444. else
  25445. {
  25446. c.fillAndStroke();
  25447. }
  25448. }
  25449. }
  25450. else
  25451. {
  25452. c.moveTo(start, 0);
  25453. c.lineTo(0, 0);
  25454. c.lineTo(0, h);
  25455. c.lineTo(start, h);
  25456. c.fillAndStroke();
  25457. if (start < w)
  25458. {
  25459. if (fill == mxConstants.NONE || !events)
  25460. {
  25461. c.pointerEvents = false;
  25462. }
  25463. if (fill != mxConstants.NONE)
  25464. {
  25465. c.setFillColor(fill);
  25466. }
  25467. c.begin();
  25468. c.moveTo(start, 0);
  25469. c.lineTo(w, 0);
  25470. c.lineTo(w, h);
  25471. c.lineTo(start, h);
  25472. if (fill == mxConstants.NONE)
  25473. {
  25474. c.stroke();
  25475. }
  25476. else
  25477. {
  25478. c.fillAndStroke();
  25479. }
  25480. }
  25481. }
  25482. if (swimlaneLine)
  25483. {
  25484. this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE);
  25485. }
  25486. };
  25487. /**
  25488. * Function: paintRoundedSwimlane
  25489. *
  25490. * Paints the swimlane vertex shape.
  25491. */
  25492. mxSwimlane.prototype.paintRoundedSwimlane = function(c, x, y, w, h, start, r, fill, swimlaneLine)
  25493. {
  25494. c.begin();
  25495. var events = true;
  25496. if (this.style != null)
  25497. {
  25498. events = mxUtils.getValue(this.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1';
  25499. }
  25500. if (!events && (this.fill == null || this.fill == mxConstants.NONE))
  25501. {
  25502. c.pointerEvents = false;
  25503. }
  25504. if (this.isHorizontal())
  25505. {
  25506. c.moveTo(w, start);
  25507. c.lineTo(w, r);
  25508. c.quadTo(w, 0, w - Math.min(w / 2, r), 0);
  25509. c.lineTo(Math.min(w / 2, r), 0);
  25510. c.quadTo(0, 0, 0, r);
  25511. c.lineTo(0, start);
  25512. c.fillAndStroke();
  25513. if (start < h)
  25514. {
  25515. if (fill == mxConstants.NONE || !events)
  25516. {
  25517. c.pointerEvents = false;
  25518. }
  25519. if (fill != mxConstants.NONE)
  25520. {
  25521. c.setFillColor(fill);
  25522. }
  25523. c.begin();
  25524. c.moveTo(0, start);
  25525. c.lineTo(0, h - r);
  25526. c.quadTo(0, h, Math.min(w / 2, r), h);
  25527. c.lineTo(w - Math.min(w / 2, r), h);
  25528. c.quadTo(w, h, w, h - r);
  25529. c.lineTo(w, start);
  25530. if (fill == mxConstants.NONE)
  25531. {
  25532. c.stroke();
  25533. }
  25534. else
  25535. {
  25536. c.fillAndStroke();
  25537. }
  25538. }
  25539. }
  25540. else
  25541. {
  25542. c.moveTo(start, 0);
  25543. c.lineTo(r, 0);
  25544. c.quadTo(0, 0, 0, Math.min(h / 2, r));
  25545. c.lineTo(0, h - Math.min(h / 2, r));
  25546. c.quadTo(0, h, r, h);
  25547. c.lineTo(start, h);
  25548. c.fillAndStroke();
  25549. if (start < w)
  25550. {
  25551. if (fill == mxConstants.NONE || !events)
  25552. {
  25553. c.pointerEvents = false;
  25554. }
  25555. if (fill != mxConstants.NONE)
  25556. {
  25557. c.setFillColor(fill);
  25558. }
  25559. c.begin();
  25560. c.moveTo(start, h);
  25561. c.lineTo(w - r, h);
  25562. c.quadTo(w, h, w, h - Math.min(h / 2, r));
  25563. c.lineTo(w, Math.min(h / 2, r));
  25564. c.quadTo(w, 0, w - r, 0);
  25565. c.lineTo(start, 0);
  25566. if (fill == mxConstants.NONE)
  25567. {
  25568. c.stroke();
  25569. }
  25570. else
  25571. {
  25572. c.fillAndStroke();
  25573. }
  25574. }
  25575. }
  25576. if (swimlaneLine)
  25577. {
  25578. this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE);
  25579. }
  25580. };
  25581. /**
  25582. * Function: paintDivider
  25583. *
  25584. * Paints the divider between swimlane title and content area.
  25585. */
  25586. mxSwimlane.prototype.paintDivider = function(c, x, y, w, h, start, shadow)
  25587. {
  25588. if (!shadow)
  25589. {
  25590. c.setShadow(false);
  25591. }
  25592. c.begin();
  25593. if (this.isHorizontal())
  25594. {
  25595. c.moveTo(0, start);
  25596. c.lineTo(w, start);
  25597. }
  25598. else
  25599. {
  25600. c.moveTo(start, 0);
  25601. c.lineTo(start, h);
  25602. }
  25603. c.stroke();
  25604. };
  25605. /**
  25606. * Function: paintSeparator
  25607. *
  25608. * Paints the vertical or horizontal separator line between swimlanes.
  25609. */
  25610. mxSwimlane.prototype.paintSeparator = function(c, x, y, w, h, start, color)
  25611. {
  25612. if (color != mxConstants.NONE)
  25613. {
  25614. c.setStrokeColor(color);
  25615. c.setDashed(true);
  25616. c.begin();
  25617. if (this.isHorizontal())
  25618. {
  25619. c.moveTo(w, start);
  25620. c.lineTo(w, h);
  25621. }
  25622. else
  25623. {
  25624. c.moveTo(start, 0);
  25625. c.lineTo(w, 0);
  25626. }
  25627. c.stroke();
  25628. c.setDashed(false);
  25629. }
  25630. };
  25631. /**
  25632. * Function: getImageBounds
  25633. *
  25634. * Paints the swimlane vertex shape.
  25635. */
  25636. mxSwimlane.prototype.getImageBounds = function(x, y, w, h)
  25637. {
  25638. if (this.isHorizontal())
  25639. {
  25640. return new mxRectangle(x + w - this.imageSize, y, this.imageSize, this.imageSize);
  25641. }
  25642. else
  25643. {
  25644. return new mxRectangle(x, y, this.imageSize, this.imageSize);
  25645. }
  25646. };
  25647. /**
  25648. * Copyright (c) 2006-2018, JGraph Ltd
  25649. * Copyright (c) 2006-2018, Gaudenz Alder
  25650. */
  25651. /**
  25652. * Class: mxGraphLayout
  25653. *
  25654. * Base class for all layout algorithms in mxGraph. Main public functions are
  25655. * <moveCell> for handling a moved cell within a layouted parent, and <execute> for
  25656. * running the layout on a given parent cell.
  25657. *
  25658. * Known Subclasses:
  25659. *
  25660. * <mxCircleLayout>, <mxCompactTreeLayout>, <mxCompositeLayout>,
  25661. * <mxFastOrganicLayout>, <mxParallelEdgeLayout>, <mxPartitionLayout>,
  25662. * <mxStackLayout>
  25663. *
  25664. * Constructor: mxGraphLayout
  25665. *
  25666. * Constructs a new layout using the given layouts.
  25667. *
  25668. * Arguments:
  25669. *
  25670. * graph - Enclosing
  25671. */
  25672. function mxGraphLayout(graph)
  25673. {
  25674. this.graph = graph;
  25675. };
  25676. /**
  25677. * Variable: graph
  25678. *
  25679. * Reference to the enclosing <mxGraph>.
  25680. */
  25681. mxGraphLayout.prototype.graph = null;
  25682. /**
  25683. * Variable: useBoundingBox
  25684. *
  25685. * Boolean indicating if the bounding box of the label should be used if
  25686. * its available. Default is true.
  25687. */
  25688. mxGraphLayout.prototype.useBoundingBox = true;
  25689. /**
  25690. * Variable: parent
  25691. *
  25692. * The parent cell of the layout, if any
  25693. */
  25694. mxGraphLayout.prototype.parent = null;
  25695. /**
  25696. * Function: moveCell
  25697. *
  25698. * Notified when a cell is being moved in a parent that has automatic
  25699. * layout to update the cell state (eg. index) so that the outcome of the
  25700. * layout will position the vertex as close to the point (x, y) as
  25701. * possible.
  25702. *
  25703. * Empty implementation.
  25704. *
  25705. * Parameters:
  25706. *
  25707. * cell - <mxCell> which has been moved.
  25708. * x - X-coordinate of the new cell location.
  25709. * y - Y-coordinate of the new cell location.
  25710. */
  25711. mxGraphLayout.prototype.moveCell = function(cell, x, y) { };
  25712. /**
  25713. * Function: resizeCell
  25714. *
  25715. * Notified when a cell is being resized in a parent that has automatic
  25716. * layout to update the other cells in the layout.
  25717. *
  25718. * Empty implementation.
  25719. *
  25720. * Parameters:
  25721. *
  25722. * cell - <mxCell> which has been moved.
  25723. * bounds - <mxRectangle> that represents the new cell bounds.
  25724. */
  25725. mxGraphLayout.prototype.resizeCell = function(cell, bounds) { };
  25726. /**
  25727. * Function: execute
  25728. *
  25729. * Executes the layout algorithm for the children of the given parent.
  25730. *
  25731. * Parameters:
  25732. *
  25733. * parent - <mxCell> whose children should be layed out.
  25734. */
  25735. mxGraphLayout.prototype.execute = function(parent) { };
  25736. /**
  25737. * Function: getGraph
  25738. *
  25739. * Returns the graph that this layout operates on.
  25740. */
  25741. mxGraphLayout.prototype.getGraph = function()
  25742. {
  25743. return this.graph;
  25744. };
  25745. /**
  25746. * Function: getConstraint
  25747. *
  25748. * Returns the constraint for the given key and cell. The optional edge and
  25749. * source arguments are used to return inbound and outgoing routing-
  25750. * constraints for the given edge and vertex. This implementation always
  25751. * returns the value for the given key in the style of the given cell.
  25752. *
  25753. * Parameters:
  25754. *
  25755. * key - Key of the constraint to be returned.
  25756. * cell - <mxCell> whose constraint should be returned.
  25757. * edge - Optional <mxCell> that represents the connection whose constraint
  25758. * should be returned. Default is null.
  25759. * source - Optional boolean that specifies if the connection is incoming
  25760. * or outgoing. Default is null.
  25761. */
  25762. mxGraphLayout.prototype.getConstraint = function(key, cell, edge, source)
  25763. {
  25764. return this.graph.getCurrentCellStyle(cell)[key]
  25765. };
  25766. /**
  25767. * Function: traverse
  25768. *
  25769. * Traverses the (directed) graph invoking the given function for each
  25770. * visited vertex and edge. The function is invoked with the current vertex
  25771. * and the incoming edge as a parameter. This implementation makes sure
  25772. * each vertex is only visited once. The function may return false if the
  25773. * traversal should stop at the given vertex.
  25774. *
  25775. * Example:
  25776. *
  25777. * (code)
  25778. * mxLog.show();
  25779. * var cell = graph.getSelectionCell();
  25780. * graph.traverse(cell, false, function(vertex, edge)
  25781. * {
  25782. * mxLog.debug(graph.getLabel(vertex));
  25783. * });
  25784. * (end)
  25785. *
  25786. * Parameters:
  25787. *
  25788. * vertex - <mxCell> that represents the vertex where the traversal starts.
  25789. * directed - Optional boolean indicating if edges should only be traversed
  25790. * from source to target. Default is true.
  25791. * func - Visitor function that takes the current vertex and the incoming
  25792. * edge as arguments. The traversal stops if the function returns false.
  25793. * edge - Optional <mxCell> that represents the incoming edge. This is
  25794. * null for the first step of the traversal.
  25795. * visited - Optional <mxDictionary> of cell paths for the visited cells.
  25796. */
  25797. mxGraphLayout.traverse = function(vertex, directed, func, edge, visited)
  25798. {
  25799. if (func != null && vertex != null)
  25800. {
  25801. directed = (directed != null) ? directed : true;
  25802. visited = visited || new mxDictionary();
  25803. if (!visited.get(vertex))
  25804. {
  25805. visited.put(vertex, true);
  25806. var result = func(vertex, edge);
  25807. if (result == null || result)
  25808. {
  25809. var edgeCount = this.graph.model.getEdgeCount(vertex);
  25810. if (edgeCount > 0)
  25811. {
  25812. for (var i = 0; i < edgeCount; i++)
  25813. {
  25814. var e = this.graph.model.getEdgeAt(vertex, i);
  25815. var isSource = this.graph.model.getTerminal(e, true) == vertex;
  25816. if (!directed || isSource)
  25817. {
  25818. var next = this.graph.view.getVisibleTerminal(e, !isSource);
  25819. this.traverse(next, directed, func, e, visited);
  25820. }
  25821. }
  25822. }
  25823. }
  25824. }
  25825. }
  25826. };
  25827. /**
  25828. * Function: isAncestor
  25829. *
  25830. * Returns true if the given parent is an ancestor of the given child.
  25831. *
  25832. * Parameters:
  25833. *
  25834. * parent - <mxCell> that specifies the parent.
  25835. * child - <mxCell> that specifies the child.
  25836. * traverseAncestors - boolean whether to
  25837. */
  25838. mxGraphLayout.prototype.isAncestor = function(parent, child, traverseAncestors)
  25839. {
  25840. if (!traverseAncestors)
  25841. {
  25842. return (this.graph.model.getParent(child) == parent);
  25843. }
  25844. if (child == parent)
  25845. {
  25846. return false;
  25847. }
  25848. while (child != null && child != parent)
  25849. {
  25850. child = this.graph.model.getParent(child);
  25851. }
  25852. return child == parent;
  25853. };
  25854. /**
  25855. * Function: isVertexMovable
  25856. *
  25857. * Returns a boolean indicating if the given <mxCell> is movable or
  25858. * bendable by the algorithm. This implementation returns true if the given
  25859. * cell is movable in the graph.
  25860. *
  25861. * Parameters:
  25862. *
  25863. * cell - <mxCell> whose movable state should be returned.
  25864. */
  25865. mxGraphLayout.prototype.isVertexMovable = function(cell)
  25866. {
  25867. return this.graph.isCellMovable(cell);
  25868. };
  25869. /**
  25870. * Function: isVertexIgnored
  25871. *
  25872. * Returns a boolean indicating if the given <mxCell> should be ignored by
  25873. * the algorithm. This implementation returns false for all vertices.
  25874. *
  25875. * Parameters:
  25876. *
  25877. * vertex - <mxCell> whose ignored state should be returned.
  25878. */
  25879. mxGraphLayout.prototype.isVertexIgnored = function(vertex)
  25880. {
  25881. return !this.graph.getModel().isVertex(vertex) ||
  25882. !this.graph.isCellVisible(vertex);
  25883. };
  25884. /**
  25885. * Function: isEdgeIgnored
  25886. *
  25887. * Returns a boolean indicating if the given <mxCell> should be ignored by
  25888. * the algorithm. This implementation returns false for all vertices.
  25889. *
  25890. * Parameters:
  25891. *
  25892. * cell - <mxCell> whose ignored state should be returned.
  25893. */
  25894. mxGraphLayout.prototype.isEdgeIgnored = function(edge)
  25895. {
  25896. var model = this.graph.getModel();
  25897. return !model.isEdge(edge) ||
  25898. !this.graph.isCellVisible(edge) ||
  25899. model.getTerminal(edge, true) == null ||
  25900. model.getTerminal(edge, false) == null;
  25901. };
  25902. /**
  25903. * Function: setEdgeStyleEnabled
  25904. *
  25905. * Disables or enables the edge style of the given edge.
  25906. */
  25907. mxGraphLayout.prototype.setEdgeStyleEnabled = function(edge, value)
  25908. {
  25909. this.graph.setCellStyles(mxConstants.STYLE_NOEDGESTYLE,
  25910. (value) ? '0' : '1', [edge]);
  25911. };
  25912. /**
  25913. * Function: setOrthogonalEdge
  25914. *
  25915. * Disables or enables orthogonal end segments of the given edge.
  25916. */
  25917. mxGraphLayout.prototype.setOrthogonalEdge = function(edge, value)
  25918. {
  25919. this.graph.setCellStyles(mxConstants.STYLE_ORTHOGONAL,
  25920. (value) ? '1' : '0', [edge]);
  25921. };
  25922. /**
  25923. * Function: getParentOffset
  25924. *
  25925. * Determines the offset of the given parent to the parent
  25926. * of the layout
  25927. */
  25928. mxGraphLayout.prototype.getParentOffset = function(parent)
  25929. {
  25930. var result = new mxPoint();
  25931. if (parent != null && parent != this.parent)
  25932. {
  25933. var model = this.graph.getModel();
  25934. if (model.isAncestor(this.parent, parent))
  25935. {
  25936. var parentGeo = model.getGeometry(parent);
  25937. while (parent != this.parent)
  25938. {
  25939. result.x = result.x + parentGeo.x;
  25940. result.y = result.y + parentGeo.y;
  25941. parent = model.getParent(parent);;
  25942. parentGeo = model.getGeometry(parent);
  25943. }
  25944. }
  25945. }
  25946. return result;
  25947. };
  25948. /**
  25949. * Function: setEdgePoints
  25950. *
  25951. * Replaces the array of mxPoints in the geometry of the given edge
  25952. * with the given array of mxPoints.
  25953. */
  25954. mxGraphLayout.prototype.setEdgePoints = function(edge, points)
  25955. {
  25956. if (edge != null)
  25957. {
  25958. var model = this.graph.model;
  25959. var geometry = model.getGeometry(edge);
  25960. if (geometry == null)
  25961. {
  25962. geometry = new mxGeometry();
  25963. geometry.setRelative(true);
  25964. }
  25965. else
  25966. {
  25967. geometry = geometry.clone();
  25968. }
  25969. if (this.parent != null && points != null)
  25970. {
  25971. var parent = model.getParent(edge);
  25972. var parentOffset = this.getParentOffset(parent);
  25973. for (var i = 0; i < points.length; i++)
  25974. {
  25975. points[i].x = points[i].x - parentOffset.x;
  25976. points[i].y = points[i].y - parentOffset.y;
  25977. }
  25978. }
  25979. geometry.points = points;
  25980. model.setGeometry(edge, geometry);
  25981. }
  25982. };
  25983. /**
  25984. * Function: setVertexLocation
  25985. *
  25986. * Sets the new position of the given cell taking into account the size of
  25987. * the bounding box if <useBoundingBox> is true. The change is only carried
  25988. * out if the new location is not equal to the existing location, otherwise
  25989. * the geometry is not replaced with an updated instance. The new or old
  25990. * bounds are returned (including overlapping labels).
  25991. *
  25992. * Parameters:
  25993. *
  25994. * cell - <mxCell> whose geometry is to be set.
  25995. * x - Integer that defines the x-coordinate of the new location.
  25996. * y - Integer that defines the y-coordinate of the new location.
  25997. */
  25998. mxGraphLayout.prototype.setVertexLocation = function(cell, x, y)
  25999. {
  26000. var model = this.graph.getModel();
  26001. var geometry = model.getGeometry(cell);
  26002. var result = null;
  26003. if (geometry != null)
  26004. {
  26005. result = new mxRectangle(x, y, geometry.width, geometry.height);
  26006. // Checks for oversize labels and shifts the result
  26007. // TODO: Use mxUtils.getStringSize for label bounds
  26008. if (this.useBoundingBox)
  26009. {
  26010. var state = this.graph.getView().getState(cell);
  26011. if (state != null && state.text != null && state.text.boundingBox != null)
  26012. {
  26013. var scale = this.graph.getView().scale;
  26014. var box = state.text.boundingBox;
  26015. if (state.text.boundingBox.x < state.x)
  26016. {
  26017. x += (state.x - box.x) / scale;
  26018. result.width = box.width;
  26019. }
  26020. if (state.text.boundingBox.y < state.y)
  26021. {
  26022. y += (state.y - box.y) / scale;
  26023. result.height = box.height;
  26024. }
  26025. }
  26026. }
  26027. if (this.parent != null)
  26028. {
  26029. var parent = model.getParent(cell);
  26030. if (parent != null && parent != this.parent)
  26031. {
  26032. var parentOffset = this.getParentOffset(parent);
  26033. x = x - parentOffset.x;
  26034. y = y - parentOffset.y;
  26035. }
  26036. }
  26037. if (geometry.x != x || geometry.y != y)
  26038. {
  26039. geometry = geometry.clone();
  26040. geometry.x = x;
  26041. geometry.y = y;
  26042. model.setGeometry(cell, geometry);
  26043. }
  26044. }
  26045. return result;
  26046. };
  26047. /**
  26048. * Function: getVertexBounds
  26049. *
  26050. * Returns an <mxRectangle> that defines the bounds of the given cell or
  26051. * the bounding box if <useBoundingBox> is true.
  26052. */
  26053. mxGraphLayout.prototype.getVertexBounds = function(cell)
  26054. {
  26055. var geo = this.graph.getModel().getGeometry(cell);
  26056. // Checks for oversize label bounding box and corrects
  26057. // the return value accordingly
  26058. // TODO: Use mxUtils.getStringSize for label bounds
  26059. if (this.useBoundingBox)
  26060. {
  26061. var state = this.graph.getView().getState(cell);
  26062. if (state != null && state.text != null && state.text.boundingBox != null)
  26063. {
  26064. var scale = this.graph.getView().scale;
  26065. var tmp = state.text.boundingBox;
  26066. var dx0 = Math.max(state.x - tmp.x, 0) / scale;
  26067. var dy0 = Math.max(state.y - tmp.y, 0) / scale;
  26068. var dx1 = Math.max((tmp.x + tmp.width) - (state.x + state.width), 0) / scale;
  26069. var dy1 = Math.max((tmp.y + tmp.height) - (state.y + state.height), 0) / scale;
  26070. geo = new mxRectangle(geo.x - dx0, geo.y - dy0, geo.width + dx0 + dx1, geo.height + dy0 + dy1);
  26071. }
  26072. }
  26073. if (this.parent != null)
  26074. {
  26075. var parent = this.graph.getModel().getParent(cell);
  26076. geo = geo.clone();
  26077. if (parent != null && parent != this.parent)
  26078. {
  26079. var parentOffset = this.getParentOffset(parent);
  26080. geo.x = geo.x + parentOffset.x;
  26081. geo.y = geo.y + parentOffset.y;
  26082. }
  26083. }
  26084. return new mxRectangle(geo.x, geo.y, geo.width, geo.height);
  26085. };
  26086. /**
  26087. * Function: arrangeGroups
  26088. *
  26089. * Shortcut to <mxGraph.updateGroupBounds> with moveGroup set to true.
  26090. */
  26091. mxGraphLayout.prototype.arrangeGroups = function(cells, border, topBorder, rightBorder, bottomBorder, leftBorder)
  26092. {
  26093. return this.graph.updateGroupBounds(cells, border, true, topBorder, rightBorder, bottomBorder, leftBorder);
  26094. };
  26095. /**
  26096. * Class: WeightedCellSorter
  26097. *
  26098. * A utility class used to track cells whilst sorting occurs on the weighted
  26099. * sum of their connected edges. Does not violate (x.compareTo(y)==0) ==
  26100. * (x.equals(y))
  26101. *
  26102. * Constructor: WeightedCellSorter
  26103. *
  26104. * Constructs a new weighted cell sorted for the given cell and weight.
  26105. */
  26106. function WeightedCellSorter(cell, weightedValue)
  26107. {
  26108. this.cell = cell;
  26109. this.weightedValue = weightedValue;
  26110. };
  26111. /**
  26112. * Variable: weightedValue
  26113. *
  26114. * The weighted value of the cell stored.
  26115. */
  26116. WeightedCellSorter.prototype.weightedValue = 0;
  26117. /**
  26118. * Variable: nudge
  26119. *
  26120. * Whether or not to flip equal weight values.
  26121. */
  26122. WeightedCellSorter.prototype.nudge = false;
  26123. /**
  26124. * Variable: visited
  26125. *
  26126. * Whether or not this cell has been visited in the current assignment.
  26127. */
  26128. WeightedCellSorter.prototype.visited = false;
  26129. /**
  26130. * Variable: rankIndex
  26131. *
  26132. * The index this cell is in the model rank.
  26133. */
  26134. WeightedCellSorter.prototype.rankIndex = null;
  26135. /**
  26136. * Variable: cell
  26137. *
  26138. * The cell whose median value is being calculated.
  26139. */
  26140. WeightedCellSorter.prototype.cell = null;
  26141. /**
  26142. * Function: compare
  26143. *
  26144. * Compares two WeightedCellSorters.
  26145. */
  26146. WeightedCellSorter.prototype.compare = function(a, b)
  26147. {
  26148. if (a != null && b != null)
  26149. {
  26150. if (b.weightedValue > a.weightedValue)
  26151. {
  26152. return -1;
  26153. }
  26154. else if (b.weightedValue < a.weightedValue)
  26155. {
  26156. return 1;
  26157. }
  26158. else
  26159. {
  26160. if (b.nudge)
  26161. {
  26162. return -1;
  26163. }
  26164. else
  26165. {
  26166. return 1;
  26167. }
  26168. }
  26169. }
  26170. else
  26171. {
  26172. return 0;
  26173. }
  26174. };
  26175. /**
  26176. * Copyright (c) 2006-2015, JGraph Ltd
  26177. * Copyright (c) 2006-2015, Gaudenz Alder
  26178. */
  26179. /**
  26180. * Class: mxStackLayout
  26181. *
  26182. * Extends <mxGraphLayout> to create a horizontal or vertical stack of the
  26183. * child vertices. The children do not need to be connected for this layout
  26184. * to work.
  26185. *
  26186. * Example:
  26187. *
  26188. * (code)
  26189. * var layout = new mxStackLayout(graph, true);
  26190. * layout.execute(graph.getDefaultParent());
  26191. * (end)
  26192. *
  26193. * Constructor: mxStackLayout
  26194. *
  26195. * Constructs a new stack layout layout for the specified graph,
  26196. * spacing, orientation and offset.
  26197. */
  26198. function mxStackLayout(graph, horizontal, spacing, x0, y0, border)
  26199. {
  26200. mxGraphLayout.call(this, graph);
  26201. this.horizontal = (horizontal != null) ? horizontal : true;
  26202. this.spacing = (spacing != null) ? spacing : 0;
  26203. this.x0 = (x0 != null) ? x0 : 0;
  26204. this.y0 = (y0 != null) ? y0 : 0;
  26205. this.border = (border != null) ? border : 0;
  26206. };
  26207. /**
  26208. * Extends mxGraphLayout.
  26209. */
  26210. mxStackLayout.prototype = new mxGraphLayout();
  26211. mxStackLayout.prototype.constructor = mxStackLayout;
  26212. /**
  26213. * Variable: horizontal
  26214. *
  26215. * Specifies the orientation of the layout. Default is true.
  26216. */
  26217. mxStackLayout.prototype.horizontal = null;
  26218. /**
  26219. * Variable: spacing
  26220. *
  26221. * Specifies the spacing between the cells. Default is 0.
  26222. */
  26223. mxStackLayout.prototype.spacing = null;
  26224. /**
  26225. * Variable: x0
  26226. *
  26227. * Specifies the horizontal origin of the layout. Default is 0.
  26228. */
  26229. mxStackLayout.prototype.x0 = null;
  26230. /**
  26231. * Variable: y0
  26232. *
  26233. * Specifies the vertical origin of the layout. Default is 0.
  26234. */
  26235. mxStackLayout.prototype.y0 = null;
  26236. /**
  26237. * Variable: border
  26238. *
  26239. * Border to be added if fill is true. Default is 0.
  26240. */
  26241. mxStackLayout.prototype.border = 0;
  26242. /**
  26243. * Variable: marginTop
  26244. *
  26245. * Top margin for the child area. Default is 0.
  26246. */
  26247. mxStackLayout.prototype.marginTop = 0;
  26248. /**
  26249. * Variable: marginLeft
  26250. *
  26251. * Top margin for the child area. Default is 0.
  26252. */
  26253. mxStackLayout.prototype.marginLeft = 0;
  26254. /**
  26255. * Variable: marginRight
  26256. *
  26257. * Top margin for the child area. Default is 0.
  26258. */
  26259. mxStackLayout.prototype.marginRight = 0;
  26260. /**
  26261. * Variable: marginBottom
  26262. *
  26263. * Top margin for the child area. Default is 0.
  26264. */
  26265. mxStackLayout.prototype.marginBottom = 0;
  26266. /**
  26267. * Variable: keepFirstLocation
  26268. *
  26269. * Boolean indicating if the location of the first cell should be
  26270. * kept, that is, it will not be moved to x0 or y0. Default is false.
  26271. */
  26272. mxStackLayout.prototype.keepFirstLocation = false;
  26273. /**
  26274. * Variable: fill
  26275. *
  26276. * Boolean indicating if dimension should be changed to fill out the parent
  26277. * cell. Default is false.
  26278. */
  26279. mxStackLayout.prototype.fill = false;
  26280. /**
  26281. * Variable: resizeParent
  26282. *
  26283. * If the parent should be resized to match the width/height of the
  26284. * stack. Default is false.
  26285. */
  26286. mxStackLayout.prototype.resizeParent = false;
  26287. /**
  26288. * Variable: resizeParentMax
  26289. *
  26290. * Use maximum of existing value and new value for resize of parent.
  26291. * Default is false.
  26292. */
  26293. mxStackLayout.prototype.resizeParentMax = false;
  26294. /**
  26295. * Variable: resizeLast
  26296. *
  26297. * If the last element should be resized to fill out the parent. Default is
  26298. * false. If <resizeParent> is true then this is ignored.
  26299. */
  26300. mxStackLayout.prototype.resizeLast = false;
  26301. /**
  26302. * Variable: wrap
  26303. *
  26304. * Value at which a new column or row should be created. Default is null.
  26305. */
  26306. mxStackLayout.prototype.wrap = null;
  26307. /**
  26308. * Variable: borderCollapse
  26309. *
  26310. * If the strokeWidth should be ignored. Default is true.
  26311. */
  26312. mxStackLayout.prototype.borderCollapse = true;
  26313. /**
  26314. * Variable: allowGaps
  26315. *
  26316. * If gaps should be allowed in the stack. Default is false.
  26317. */
  26318. mxStackLayout.prototype.allowGaps = false;
  26319. /**
  26320. * Variable: gridSize
  26321. *
  26322. * Grid size for alignment of position and size. Default is 0.
  26323. */
  26324. mxStackLayout.prototype.gridSize = 0;
  26325. /**
  26326. * Function: isHorizontal
  26327. *
  26328. * Returns <horizontal>.
  26329. */
  26330. mxStackLayout.prototype.isHorizontal = function()
  26331. {
  26332. return this.horizontal;
  26333. };
  26334. /**
  26335. * Function: moveCell
  26336. *
  26337. * Implements <mxGraphLayout.moveCell>.
  26338. */
  26339. mxStackLayout.prototype.moveCell = function(cell, x, y)
  26340. {
  26341. var model = this.graph.getModel();
  26342. var parent = model.getParent(cell);
  26343. var horizontal = this.isHorizontal();
  26344. if (cell != null && parent != null)
  26345. {
  26346. var i = 0;
  26347. var last = 0;
  26348. var childCount = model.getChildCount(parent);
  26349. var value = (horizontal) ? x : y;
  26350. var pstate = this.graph.getView().getState(parent);
  26351. if (pstate != null)
  26352. {
  26353. value -= (horizontal) ? pstate.x : pstate.y;
  26354. }
  26355. value /= this.graph.view.scale;
  26356. for (i = 0; i < childCount; i++)
  26357. {
  26358. var child = model.getChildAt(parent, i);
  26359. if (child != cell)
  26360. {
  26361. var bounds = model.getGeometry(child);
  26362. if (bounds != null)
  26363. {
  26364. var tmp = (horizontal) ?
  26365. bounds.x + bounds.width / 2 :
  26366. bounds.y + bounds.height / 2;
  26367. if (last <= value && tmp > value)
  26368. {
  26369. break;
  26370. }
  26371. last = tmp;
  26372. }
  26373. }
  26374. }
  26375. // Changes child order in parent
  26376. var idx = parent.getIndex(cell);
  26377. idx = Math.max(0, i - ((i > idx) ? 1 : 0));
  26378. model.add(parent, cell, idx);
  26379. }
  26380. };
  26381. /**
  26382. * Function: getParentSize
  26383. *
  26384. * Returns the size for the parent container or the size of the graph
  26385. * container if the parent is a layer or the root of the model.
  26386. */
  26387. mxStackLayout.prototype.getParentSize = function(parent)
  26388. {
  26389. var model = this.graph.getModel();
  26390. var pgeo = model.getGeometry(parent);
  26391. // Handles special case where the parent is either a layer with no
  26392. // geometry or the current root of the view in which case the size
  26393. // of the graph's container will be used.
  26394. if (this.graph.container != null && ((pgeo == null &&
  26395. model.isLayer(parent)) || parent == this.graph.getView().currentRoot))
  26396. {
  26397. var width = this.graph.container.offsetWidth - 1;
  26398. var height = this.graph.container.offsetHeight - 1;
  26399. pgeo = new mxRectangle(0, 0, width, height);
  26400. }
  26401. return pgeo;
  26402. };
  26403. /**
  26404. * Function: getLayoutCells
  26405. *
  26406. * Returns the cells to be layouted.
  26407. */
  26408. mxStackLayout.prototype.getLayoutCells = function(parent)
  26409. {
  26410. var model = this.graph.getModel();
  26411. var childCount = model.getChildCount(parent);
  26412. var cells = [];
  26413. for (var i = 0; i < childCount; i++)
  26414. {
  26415. var child = model.getChildAt(parent, i);
  26416. if (!this.isVertexIgnored(child) && this.isVertexMovable(child))
  26417. {
  26418. cells.push(child);
  26419. }
  26420. }
  26421. if (this.allowGaps)
  26422. {
  26423. cells.sort(mxUtils.bind(this, function(c1, c2)
  26424. {
  26425. var geo1 = this.graph.getCellGeometry(c1);
  26426. var geo2 = this.graph.getCellGeometry(c2);
  26427. return (geo1.y == geo2.y) ? 0 : ((geo1.y > geo2.y > 0) ? 1 : -1);
  26428. }));
  26429. }
  26430. return cells;
  26431. };
  26432. /**
  26433. * Function: snap
  26434. *
  26435. * Snaps the given value to the grid size.
  26436. */
  26437. mxStackLayout.prototype.snap = function(value)
  26438. {
  26439. if (this.gridSize != null && this.gridSize > 0)
  26440. {
  26441. value = Math.max(value, this.gridSize);
  26442. if (value / this.gridSize > 1)
  26443. {
  26444. var mod = value % this.gridSize;
  26445. value += mod > this.gridSize / 2 ? (this.gridSize - mod) : -mod;
  26446. }
  26447. }
  26448. return value;
  26449. };
  26450. /**
  26451. * Function: execute
  26452. *
  26453. * Implements <mxGraphLayout.execute>.
  26454. *
  26455. * Only children where <isVertexIgnored> returns false are taken into
  26456. * account.
  26457. */
  26458. mxStackLayout.prototype.execute = function(parent)
  26459. {
  26460. if (parent != null)
  26461. {
  26462. var pgeo = this.getParentSize(parent);
  26463. var horizontal = this.isHorizontal();
  26464. var model = this.graph.getModel();
  26465. var fillValue = null;
  26466. if (pgeo != null)
  26467. {
  26468. fillValue = (horizontal) ? pgeo.height - this.marginTop - this.marginBottom :
  26469. pgeo.width - this.marginLeft - this.marginRight;
  26470. }
  26471. fillValue -= 2 * this.border;
  26472. var x0 = this.x0 + this.border + this.marginLeft;
  26473. var y0 = this.y0 + this.border + this.marginTop;
  26474. // Handles swimlane start size
  26475. if (this.graph.isSwimlane(parent))
  26476. {
  26477. // Uses computed style to get latest
  26478. var style = this.graph.getCellStyle(parent);
  26479. var start = mxUtils.getNumber(style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE);
  26480. var horz = mxUtils.getValue(style, mxConstants.STYLE_HORIZONTAL, true) == 1;
  26481. if (pgeo != null)
  26482. {
  26483. if (horz)
  26484. {
  26485. start = Math.min(start, pgeo.height);
  26486. }
  26487. else
  26488. {
  26489. start = Math.min(start, pgeo.width);
  26490. }
  26491. }
  26492. if (horizontal == horz)
  26493. {
  26494. fillValue -= start;
  26495. }
  26496. if (horz)
  26497. {
  26498. y0 += start;
  26499. }
  26500. else
  26501. {
  26502. x0 += start;
  26503. }
  26504. }
  26505. model.beginUpdate();
  26506. try
  26507. {
  26508. var tmp = 0;
  26509. var last = null;
  26510. var lastValue = 0;
  26511. var lastChild = null;
  26512. var cells = this.getLayoutCells(parent);
  26513. for (var i = 0; i < cells.length; i++)
  26514. {
  26515. var child = cells[i];
  26516. var geo = model.getGeometry(child);
  26517. if (geo != null)
  26518. {
  26519. geo = geo.clone();
  26520. if (this.wrap != null && last != null)
  26521. {
  26522. if ((horizontal && last.x + last.width +
  26523. geo.width + 2 * this.spacing > this.wrap) ||
  26524. (!horizontal && last.y + last.height +
  26525. geo.height + 2 * this.spacing > this.wrap))
  26526. {
  26527. last = null;
  26528. if (horizontal)
  26529. {
  26530. y0 += tmp + this.spacing;
  26531. }
  26532. else
  26533. {
  26534. x0 += tmp + this.spacing;
  26535. }
  26536. tmp = 0;
  26537. }
  26538. }
  26539. tmp = Math.max(tmp, (horizontal) ? geo.height : geo.width);
  26540. var sw = 0;
  26541. if (!this.borderCollapse)
  26542. {
  26543. var childStyle = this.graph.getCellStyle(child);
  26544. sw = mxUtils.getNumber(childStyle, mxConstants.STYLE_STROKEWIDTH, 1);
  26545. }
  26546. if (last != null)
  26547. {
  26548. var temp = lastValue + this.spacing + Math.floor(sw / 2);
  26549. if (horizontal)
  26550. {
  26551. geo.x = this.snap(((this.allowGaps) ? Math.max(temp, geo.x) :
  26552. temp) - this.marginLeft) + this.marginLeft;
  26553. }
  26554. else
  26555. {
  26556. geo.y = this.snap(((this.allowGaps) ? Math.max(temp, geo.y) :
  26557. temp) - this.marginTop) + this.marginTop;
  26558. }
  26559. }
  26560. else if (!this.keepFirstLocation)
  26561. {
  26562. if (horizontal)
  26563. {
  26564. geo.x = (this.allowGaps && geo.x > x0) ? Math.max(this.snap(geo.x -
  26565. this.marginLeft) + this.marginLeft, x0) : x0;
  26566. }
  26567. else
  26568. {
  26569. geo.y = (this.allowGaps && geo.y > y0) ? Math.max(this.snap(geo.y -
  26570. this.marginTop) + this.marginTop, y0) : y0;
  26571. }
  26572. }
  26573. if (horizontal)
  26574. {
  26575. geo.y = y0;
  26576. }
  26577. else
  26578. {
  26579. geo.x = x0;
  26580. }
  26581. if (this.fill && fillValue != null)
  26582. {
  26583. if (horizontal)
  26584. {
  26585. geo.height = fillValue;
  26586. }
  26587. else
  26588. {
  26589. geo.width = fillValue;
  26590. }
  26591. }
  26592. if (horizontal)
  26593. {
  26594. geo.width = this.snap(geo.width);
  26595. }
  26596. else
  26597. {
  26598. geo.height = this.snap(geo.height);
  26599. }
  26600. this.setChildGeometry(child, geo);
  26601. lastChild = child;
  26602. last = geo;
  26603. if (horizontal)
  26604. {
  26605. lastValue = last.x + last.width + Math.floor(sw / 2);
  26606. }
  26607. else
  26608. {
  26609. lastValue = last.y + last.height + Math.floor(sw / 2);
  26610. }
  26611. }
  26612. }
  26613. if (this.resizeParent && pgeo != null && last != null && !this.graph.isCellCollapsed(parent))
  26614. {
  26615. this.updateParentGeometry(parent, pgeo, last);
  26616. }
  26617. else if (this.resizeLast && pgeo != null && last != null && lastChild != null)
  26618. {
  26619. if (horizontal)
  26620. {
  26621. last.width = pgeo.width - last.x - this.spacing - this.marginRight - this.marginLeft;
  26622. }
  26623. else
  26624. {
  26625. last.height = pgeo.height - last.y - this.spacing - this.marginBottom;
  26626. }
  26627. this.setChildGeometry(lastChild, last);
  26628. }
  26629. }
  26630. finally
  26631. {
  26632. model.endUpdate();
  26633. }
  26634. }
  26635. };
  26636. /**
  26637. * Function: execute
  26638. *
  26639. * Implements <mxGraphLayout.execute>.
  26640. *
  26641. * Only children where <isVertexIgnored> returns false are taken into
  26642. * account.
  26643. */
  26644. mxStackLayout.prototype.setChildGeometry = function(child, geo)
  26645. {
  26646. var geo2 = this.graph.getCellGeometry(child);
  26647. if (geo2 == null || geo.x != geo2.x || geo.y != geo2.y ||
  26648. geo.width != geo2.width || geo.height != geo2.height)
  26649. {
  26650. this.graph.getModel().setGeometry(child, geo);
  26651. }
  26652. };
  26653. /**
  26654. * Function: execute
  26655. *
  26656. * Implements <mxGraphLayout.execute>.
  26657. *
  26658. * Only children where <isVertexIgnored> returns false are taken into
  26659. * account.
  26660. */
  26661. mxStackLayout.prototype.updateParentGeometry = function(parent, pgeo, last)
  26662. {
  26663. var horizontal = this.isHorizontal();
  26664. var model = this.graph.getModel();
  26665. var pgeo2 = pgeo.clone();
  26666. if (horizontal)
  26667. {
  26668. var tmp = last.x + last.width + this.marginRight + this.border;
  26669. if (this.resizeParentMax)
  26670. {
  26671. pgeo2.width = Math.max(pgeo2.width, tmp);
  26672. }
  26673. else
  26674. {
  26675. pgeo2.width = tmp;
  26676. }
  26677. }
  26678. else
  26679. {
  26680. var tmp = last.y + last.height + this.marginBottom + this.border;
  26681. if (this.resizeParentMax)
  26682. {
  26683. pgeo2.height = Math.max(pgeo2.height, tmp);
  26684. }
  26685. else
  26686. {
  26687. pgeo2.height = tmp;
  26688. }
  26689. }
  26690. if (pgeo.x != pgeo2.x || pgeo.y != pgeo2.y ||
  26691. pgeo.width != pgeo2.width || pgeo.height != pgeo2.height)
  26692. {
  26693. model.setGeometry(parent, pgeo2);
  26694. }
  26695. };
  26696. /**
  26697. * Copyright (c) 2006-2015, JGraph Ltd
  26698. * Copyright (c) 2006-2015, Gaudenz Alder
  26699. */
  26700. /**
  26701. * Class: mxPartitionLayout
  26702. *
  26703. * Extends <mxGraphLayout> for partitioning the parent cell vertically or
  26704. * horizontally by filling the complete area with the child cells. A horizontal
  26705. * layout partitions the height of the given parent whereas a a non-horizontal
  26706. * layout partitions the width. If the parent is a layer (that is, a child of
  26707. * the root node), then the current graph size is partitioned. The children do
  26708. * not need to be connected for this layout to work.
  26709. *
  26710. * Example:
  26711. *
  26712. * (code)
  26713. * var layout = new mxPartitionLayout(graph, true, 10, 20);
  26714. * layout.execute(graph.getDefaultParent());
  26715. * (end)
  26716. *
  26717. * Constructor: mxPartitionLayout
  26718. *
  26719. * Constructs a new stack layout layout for the specified graph,
  26720. * spacing, orientation and offset.
  26721. */
  26722. function mxPartitionLayout(graph, horizontal, spacing, border)
  26723. {
  26724. mxGraphLayout.call(this, graph);
  26725. this.horizontal = (horizontal != null) ? horizontal : true;
  26726. this.spacing = spacing || 0;
  26727. this.border = border || 0;
  26728. };
  26729. /**
  26730. * Extends mxGraphLayout.
  26731. */
  26732. mxPartitionLayout.prototype = new mxGraphLayout();
  26733. mxPartitionLayout.prototype.constructor = mxPartitionLayout;
  26734. /**
  26735. * Variable: horizontal
  26736. *
  26737. * Boolean indicating the direction in which the space is partitioned.
  26738. * Default is true.
  26739. */
  26740. mxPartitionLayout.prototype.horizontal = null;
  26741. /**
  26742. * Variable: spacing
  26743. *
  26744. * Integer that specifies the absolute spacing in pixels between the
  26745. * children. Default is 0.
  26746. */
  26747. mxPartitionLayout.prototype.spacing = null;
  26748. /**
  26749. * Variable: border
  26750. *
  26751. * Integer that specifies the absolute inset in pixels for the parent that
  26752. * contains the children. Default is 0.
  26753. */
  26754. mxPartitionLayout.prototype.border = null;
  26755. /**
  26756. * Variable: resizeVertices
  26757. *
  26758. * Boolean that specifies if vertices should be resized. Default is true.
  26759. */
  26760. mxPartitionLayout.prototype.resizeVertices = true;
  26761. /**
  26762. * Function: isHorizontal
  26763. *
  26764. * Returns <horizontal>.
  26765. */
  26766. mxPartitionLayout.prototype.isHorizontal = function()
  26767. {
  26768. return this.horizontal;
  26769. };
  26770. /**
  26771. * Function: moveCell
  26772. *
  26773. * Implements <mxGraphLayout.moveCell>.
  26774. */
  26775. mxPartitionLayout.prototype.moveCell = function(cell, x, y)
  26776. {
  26777. var model = this.graph.getModel();
  26778. var parent = model.getParent(cell);
  26779. if (cell != null &&
  26780. parent != null)
  26781. {
  26782. var i = 0;
  26783. var last = 0;
  26784. var childCount = model.getChildCount(parent);
  26785. // Finds index of the closest swimlane
  26786. // TODO: Take into account the orientation
  26787. for (i = 0; i < childCount; i++)
  26788. {
  26789. var child = model.getChildAt(parent, i);
  26790. var bounds = this.getVertexBounds(child);
  26791. if (bounds != null)
  26792. {
  26793. var tmp = bounds.x + bounds.width / 2;
  26794. if (last < x && tmp > x)
  26795. {
  26796. break;
  26797. }
  26798. last = tmp;
  26799. }
  26800. }
  26801. // Changes child order in parent
  26802. var idx = parent.getIndex(cell);
  26803. idx = Math.max(0, i - ((i > idx) ? 1 : 0));
  26804. model.add(parent, cell, idx);
  26805. }
  26806. };
  26807. /**
  26808. * Function: execute
  26809. *
  26810. * Implements <mxGraphLayout.execute>. All children where <isVertexIgnored>
  26811. * returns false and <isVertexMovable> returns true are modified.
  26812. */
  26813. mxPartitionLayout.prototype.execute = function(parent)
  26814. {
  26815. var horizontal = this.isHorizontal();
  26816. var model = this.graph.getModel();
  26817. var pgeo = model.getGeometry(parent);
  26818. // Handles special case where the parent is either a layer with no
  26819. // geometry or the current root of the view in which case the size
  26820. // of the graph's container will be used.
  26821. if (this.graph.container != null &&
  26822. ((pgeo == null &&
  26823. model.isLayer(parent)) ||
  26824. parent == this.graph.getView().currentRoot))
  26825. {
  26826. var width = this.graph.container.offsetWidth - 1;
  26827. var height = this.graph.container.offsetHeight - 1;
  26828. pgeo = new mxRectangle(0, 0, width, height);
  26829. }
  26830. if (pgeo != null)
  26831. {
  26832. var children = [];
  26833. var childCount = model.getChildCount(parent);
  26834. for (var i = 0; i < childCount; i++)
  26835. {
  26836. var child = model.getChildAt(parent, i);
  26837. if (!this.isVertexIgnored(child) &&
  26838. this.isVertexMovable(child))
  26839. {
  26840. children.push(child);
  26841. }
  26842. }
  26843. var n = children.length;
  26844. if (n > 0)
  26845. {
  26846. var x0 = this.border;
  26847. var y0 = this.border;
  26848. var other = (horizontal) ? pgeo.height : pgeo.width;
  26849. other -= 2 * this.border;
  26850. var size = (this.graph.isSwimlane(parent)) ?
  26851. this.graph.getStartSize(parent) :
  26852. new mxRectangle();
  26853. other -= (horizontal) ? size.height : size.width;
  26854. x0 = x0 + size.width;
  26855. y0 = y0 + size.height;
  26856. var tmp = this.border + (n - 1) * this.spacing;
  26857. var value = (horizontal) ?
  26858. ((pgeo.width - x0 - tmp) / n) :
  26859. ((pgeo.height - y0 - tmp) / n);
  26860. // Avoids negative values, that is values where the sum of the
  26861. // spacing plus the border is larger then the available space
  26862. if (value > 0)
  26863. {
  26864. model.beginUpdate();
  26865. try
  26866. {
  26867. for (var i = 0; i < n; i++)
  26868. {
  26869. var child = children[i];
  26870. var geo = model.getGeometry(child);
  26871. if (geo != null)
  26872. {
  26873. geo = geo.clone();
  26874. geo.x = x0;
  26875. geo.y = y0;
  26876. if (horizontal)
  26877. {
  26878. if (this.resizeVertices)
  26879. {
  26880. geo.width = value;
  26881. geo.height = other;
  26882. }
  26883. x0 += value + this.spacing;
  26884. }
  26885. else
  26886. {
  26887. if (this.resizeVertices)
  26888. {
  26889. geo.height = value;
  26890. geo.width = other;
  26891. }
  26892. y0 += value + this.spacing;
  26893. }
  26894. model.setGeometry(child, geo);
  26895. }
  26896. }
  26897. }
  26898. finally
  26899. {
  26900. model.endUpdate();
  26901. }
  26902. }
  26903. }
  26904. }
  26905. };
  26906. /**
  26907. * Copyright (c) 2006-2018, JGraph Ltd
  26908. * Copyright (c) 2006-2018, Gaudenz Alder
  26909. */
  26910. /**
  26911. * Class: mxCompactTreeLayout
  26912. *
  26913. * Extends <mxGraphLayout> to implement a compact tree (Moen) algorithm. This
  26914. * layout is suitable for graphs that have no cycles (trees). Vertices that are
  26915. * not connected to the tree will be ignored by this layout.
  26916. *
  26917. * Example:
  26918. *
  26919. * (code)
  26920. * var layout = new mxCompactTreeLayout(graph);
  26921. * layout.execute(graph.getDefaultParent());
  26922. * (end)
  26923. *
  26924. * Constructor: mxCompactTreeLayout
  26925. *
  26926. * Constructs a new compact tree layout for the specified graph
  26927. * and orientation.
  26928. */
  26929. function mxCompactTreeLayout(graph, horizontal, invert)
  26930. {
  26931. mxGraphLayout.call(this, graph);
  26932. this.horizontal = (horizontal != null) ? horizontal : true;
  26933. this.invert = (invert != null) ? invert : false;
  26934. };
  26935. /**
  26936. * Extends mxGraphLayout.
  26937. */
  26938. mxCompactTreeLayout.prototype = new mxGraphLayout();
  26939. mxCompactTreeLayout.prototype.constructor = mxCompactTreeLayout;
  26940. /**
  26941. * Variable: horizontal
  26942. *
  26943. * Specifies the orientation of the layout. Default is true.
  26944. */
  26945. mxCompactTreeLayout.prototype.horizontal = null;
  26946. /**
  26947. * Variable: invert
  26948. *
  26949. * Specifies if edge directions should be inverted. Default is false.
  26950. */
  26951. mxCompactTreeLayout.prototype.invert = null;
  26952. /**
  26953. * Variable: resizeParent
  26954. *
  26955. * If the parents should be resized to match the width/height of the
  26956. * children. Default is true.
  26957. */
  26958. mxCompactTreeLayout.prototype.resizeParent = true;
  26959. /**
  26960. * Variable: maintainParentLocation
  26961. *
  26962. * Specifies if the parent location should be maintained, so that the
  26963. * top, left corner stays the same before and after execution of
  26964. * the layout. Default is false for backwards compatibility.
  26965. */
  26966. mxCompactTreeLayout.prototype.maintainParentLocation = false;
  26967. /**
  26968. * Variable: groupPadding
  26969. *
  26970. * Padding added to resized parents. Default is 10.
  26971. */
  26972. mxCompactTreeLayout.prototype.groupPadding = 10;
  26973. /**
  26974. * Variable: groupPaddingTop
  26975. *
  26976. * Top padding added to resized parents. Default is 0.
  26977. */
  26978. mxCompactTreeLayout.prototype.groupPaddingTop = 0;
  26979. /**
  26980. * Variable: groupPaddingRight
  26981. *
  26982. * Right padding added to resized parents. Default is 0.
  26983. */
  26984. mxCompactTreeLayout.prototype.groupPaddingRight = 0;
  26985. /**
  26986. * Variable: groupPaddingBottom
  26987. *
  26988. * Bottom padding added to resized parents. Default is 0.
  26989. */
  26990. mxCompactTreeLayout.prototype.groupPaddingBottom = 0;
  26991. /**
  26992. * Variable: groupPaddingLeft
  26993. *
  26994. * Left padding added to resized parents. Default is 0.
  26995. */
  26996. mxCompactTreeLayout.prototype.groupPaddingLeft = 0;
  26997. /**
  26998. * Variable: parentsChanged
  26999. *
  27000. * A set of the parents that need updating based on children
  27001. * process as part of the layout.
  27002. */
  27003. mxCompactTreeLayout.prototype.parentsChanged = null;
  27004. /**
  27005. * Variable: moveTree
  27006. *
  27007. * Specifies if the tree should be moved to the top, left corner
  27008. * if it is inside a top-level layer. Default is false.
  27009. */
  27010. mxCompactTreeLayout.prototype.moveTree = false;
  27011. /**
  27012. * Variable: visited
  27013. *
  27014. * Specifies if the tree should be moved to the top, left corner
  27015. * if it is inside a top-level layer. Default is false.
  27016. */
  27017. mxCompactTreeLayout.prototype.visited = null;
  27018. /**
  27019. * Variable: levelDistance
  27020. *
  27021. * Holds the levelDistance. Default is 10.
  27022. */
  27023. mxCompactTreeLayout.prototype.levelDistance = 10;
  27024. /**
  27025. * Variable: nodeDistance
  27026. *
  27027. * Holds the nodeDistance. Default is 20.
  27028. */
  27029. mxCompactTreeLayout.prototype.nodeDistance = 20;
  27030. /**
  27031. * Variable: resetEdges
  27032. *
  27033. * Specifies if all edge points of traversed edges should be removed.
  27034. * Default is true.
  27035. */
  27036. mxCompactTreeLayout.prototype.resetEdges = true;
  27037. /**
  27038. * Variable: prefHozEdgeSep
  27039. *
  27040. * The preferred horizontal distance between edges exiting a vertex.
  27041. */
  27042. mxCompactTreeLayout.prototype.prefHozEdgeSep = 5;
  27043. /**
  27044. * Variable: prefVertEdgeOff
  27045. *
  27046. * The preferred vertical offset between edges exiting a vertex.
  27047. */
  27048. mxCompactTreeLayout.prototype.prefVertEdgeOff = 4;
  27049. /**
  27050. * Variable: minEdgeJetty
  27051. *
  27052. * The minimum distance for an edge jetty from a vertex.
  27053. */
  27054. mxCompactTreeLayout.prototype.minEdgeJetty = 8;
  27055. /**
  27056. * Variable: channelBuffer
  27057. *
  27058. * The size of the vertical buffer in the center of inter-rank channels
  27059. * where edge control points should not be placed.
  27060. */
  27061. mxCompactTreeLayout.prototype.channelBuffer = 4;
  27062. /**
  27063. * Variable: edgeRouting
  27064. *
  27065. * Whether or not to apply the internal tree edge routing.
  27066. */
  27067. mxCompactTreeLayout.prototype.edgeRouting = true;
  27068. /**
  27069. * Variable: sortEdges
  27070. *
  27071. * Specifies if edges should be sorted according to the order of their
  27072. * opposite terminal cell in the model.
  27073. */
  27074. mxCompactTreeLayout.prototype.sortEdges = false;
  27075. /**
  27076. * Variable: alignRanks
  27077. *
  27078. * Whether or not the tops of cells in each rank should be aligned
  27079. * across the rank
  27080. */
  27081. mxCompactTreeLayout.prototype.alignRanks = false;
  27082. /**
  27083. * Variable: maxRankHeight
  27084. *
  27085. * An array of the maximum height of cells (relative to the layout direction)
  27086. * per rank
  27087. */
  27088. mxCompactTreeLayout.prototype.maxRankHeight = null;
  27089. /**
  27090. * Variable: root
  27091. *
  27092. * The cell to use as the root of the tree
  27093. */
  27094. mxCompactTreeLayout.prototype.root = null;
  27095. /**
  27096. * Variable: node
  27097. *
  27098. * The internal node representation of the root cell. Do not set directly
  27099. * , this value is only exposed to assist with post-processing functionality
  27100. */
  27101. mxCompactTreeLayout.prototype.node = null;
  27102. /**
  27103. * Function: isVertexIgnored
  27104. *
  27105. * Returns a boolean indicating if the given <mxCell> should be ignored as a
  27106. * vertex. This returns true if the cell has no connections.
  27107. *
  27108. * Parameters:
  27109. *
  27110. * vertex - <mxCell> whose ignored state should be returned.
  27111. */
  27112. mxCompactTreeLayout.prototype.isVertexIgnored = function(vertex)
  27113. {
  27114. return mxGraphLayout.prototype.isVertexIgnored.apply(this, arguments) ||
  27115. this.graph.getConnections(vertex).length == 0;
  27116. };
  27117. /**
  27118. * Function: isHorizontal
  27119. *
  27120. * Returns <horizontal>.
  27121. */
  27122. mxCompactTreeLayout.prototype.isHorizontal = function()
  27123. {
  27124. return this.horizontal;
  27125. };
  27126. /**
  27127. * Function: execute
  27128. *
  27129. * Implements <mxGraphLayout.execute>.
  27130. *
  27131. * If the parent has any connected edges, then it is used as the root of
  27132. * the tree. Else, <mxGraph.findTreeRoots> will be used to find a suitable
  27133. * root node within the set of children of the given parent.
  27134. *
  27135. * Parameters:
  27136. *
  27137. * parent - <mxCell> whose children should be laid out.
  27138. * root - Optional <mxCell> that will be used as the root of the tree.
  27139. * Overrides <root> if specified.
  27140. */
  27141. mxCompactTreeLayout.prototype.execute = function(parent, root)
  27142. {
  27143. this.parent = parent;
  27144. var model = this.graph.getModel();
  27145. if (root == null)
  27146. {
  27147. // Takes the parent as the root if it has outgoing edges
  27148. if (this.graph.getEdges(parent, model.getParent(parent),
  27149. this.invert, !this.invert, false).length > 0)
  27150. {
  27151. this.root = parent;
  27152. }
  27153. // Tries to find a suitable root in the parent's
  27154. // children
  27155. else
  27156. {
  27157. var roots = this.graph.findTreeRoots(parent, true, this.invert);
  27158. if (roots.length > 0)
  27159. {
  27160. for (var i = 0; i < roots.length; i++)
  27161. {
  27162. if (!this.isVertexIgnored(roots[i]) &&
  27163. this.graph.getEdges(roots[i], null,
  27164. this.invert, !this.invert, false).length > 0)
  27165. {
  27166. this.root = roots[i];
  27167. break;
  27168. }
  27169. }
  27170. }
  27171. }
  27172. }
  27173. else
  27174. {
  27175. this.root = root;
  27176. }
  27177. if (this.root != null)
  27178. {
  27179. if (this.resizeParent)
  27180. {
  27181. this.parentsChanged = new Object();
  27182. }
  27183. else
  27184. {
  27185. this.parentsChanged = null;
  27186. }
  27187. // Maintaining parent location
  27188. this.parentX = null;
  27189. this.parentY = null;
  27190. if (parent != this.root && model.isVertex(parent) != null && this.maintainParentLocation)
  27191. {
  27192. var geo = this.graph.getCellGeometry(parent);
  27193. if (geo != null)
  27194. {
  27195. this.parentX = geo.x;
  27196. this.parentY = geo.y;
  27197. }
  27198. }
  27199. model.beginUpdate();
  27200. try
  27201. {
  27202. this.visited = new Object();
  27203. this.node = this.dfs(this.root, parent);
  27204. if (this.alignRanks)
  27205. {
  27206. this.maxRankHeight = [];
  27207. this.findRankHeights(this.node, 0);
  27208. this.setCellHeights(this.node, 0);
  27209. }
  27210. if (this.node != null)
  27211. {
  27212. this.layout(this.node);
  27213. var x0 = this.graph.gridSize;
  27214. var y0 = x0;
  27215. if (!this.moveTree)
  27216. {
  27217. var g = this.getVertexBounds(this.root);
  27218. if (g != null)
  27219. {
  27220. x0 = g.x;
  27221. y0 = g.y;
  27222. }
  27223. }
  27224. var bounds = null;
  27225. if (this.isHorizontal())
  27226. {
  27227. bounds = this.horizontalLayout(this.node, x0, y0);
  27228. }
  27229. else
  27230. {
  27231. bounds = this.verticalLayout(this.node, null, x0, y0);
  27232. }
  27233. if (bounds != null)
  27234. {
  27235. var dx = 0;
  27236. var dy = 0;
  27237. if (bounds.x < 0)
  27238. {
  27239. dx = Math.abs(x0 - bounds.x);
  27240. }
  27241. if (bounds.y < 0)
  27242. {
  27243. dy = Math.abs(y0 - bounds.y);
  27244. }
  27245. if (dx != 0 || dy != 0)
  27246. {
  27247. this.moveNode(this.node, dx, dy);
  27248. }
  27249. if (this.resizeParent)
  27250. {
  27251. this.adjustParents();
  27252. }
  27253. if (this.edgeRouting)
  27254. {
  27255. // Iterate through all edges setting their positions
  27256. this.localEdgeProcessing(this.node);
  27257. }
  27258. }
  27259. // Maintaining parent location
  27260. if (this.parentX != null && this.parentY != null)
  27261. {
  27262. var geo = this.graph.getCellGeometry(parent);
  27263. if (geo != null)
  27264. {
  27265. geo = geo.clone();
  27266. geo.x = this.parentX;
  27267. geo.y = this.parentY;
  27268. model.setGeometry(parent, geo);
  27269. }
  27270. }
  27271. }
  27272. }
  27273. finally
  27274. {
  27275. model.endUpdate();
  27276. }
  27277. }
  27278. };
  27279. /**
  27280. * Function: moveNode
  27281. *
  27282. * Moves the specified node and all of its children by the given amount.
  27283. */
  27284. mxCompactTreeLayout.prototype.moveNode = function(node, dx, dy)
  27285. {
  27286. node.x += dx;
  27287. node.y += dy;
  27288. this.apply(node);
  27289. var child = node.child;
  27290. while (child != null)
  27291. {
  27292. this.moveNode(child, dx, dy);
  27293. child = child.next;
  27294. }
  27295. };
  27296. /**
  27297. * Function: sortOutgoingEdges
  27298. *
  27299. * Called if <sortEdges> is true to sort the array of outgoing edges in place.
  27300. */
  27301. mxCompactTreeLayout.prototype.sortOutgoingEdges = function(source, edges)
  27302. {
  27303. var lookup = new mxDictionary();
  27304. edges.sort(function(e1, e2)
  27305. {
  27306. var end1 = e1.getTerminal(e1.getTerminal(false) == source);
  27307. var p1 = lookup.get(end1);
  27308. if (p1 == null)
  27309. {
  27310. p1 = mxCellPath.create(end1).split(mxCellPath.PATH_SEPARATOR);
  27311. lookup.put(end1, p1);
  27312. }
  27313. var end2 = e2.getTerminal(e2.getTerminal(false) == source);
  27314. var p2 = lookup.get(end2);
  27315. if (p2 == null)
  27316. {
  27317. p2 = mxCellPath.create(end2).split(mxCellPath.PATH_SEPARATOR);
  27318. lookup.put(end2, p2);
  27319. }
  27320. return mxCellPath.compare(p1, p2);
  27321. });
  27322. };
  27323. /**
  27324. * Function: findRankHeights
  27325. *
  27326. * Stores the maximum height (relative to the layout
  27327. * direction) of cells in each rank
  27328. */
  27329. mxCompactTreeLayout.prototype.findRankHeights = function(node, rank)
  27330. {
  27331. if (this.maxRankHeight[rank] == null || this.maxRankHeight[rank] < node.height)
  27332. {
  27333. this.maxRankHeight[rank] = node.height;
  27334. }
  27335. var child = node.child;
  27336. while (child != null)
  27337. {
  27338. this.findRankHeights(child, rank + 1);
  27339. child = child.next;
  27340. }
  27341. };
  27342. /**
  27343. * Function: setCellHeights
  27344. *
  27345. * Set the cells heights (relative to the layout
  27346. * direction) when the tops of each rank are to be aligned
  27347. */
  27348. mxCompactTreeLayout.prototype.setCellHeights = function(node, rank)
  27349. {
  27350. if (this.maxRankHeight[rank] != null && this.maxRankHeight[rank] > node.height)
  27351. {
  27352. node.height = this.maxRankHeight[rank];
  27353. }
  27354. var child = node.child;
  27355. while (child != null)
  27356. {
  27357. this.setCellHeights(child, rank + 1);
  27358. child = child.next;
  27359. }
  27360. };
  27361. /**
  27362. * Function: dfs
  27363. *
  27364. * Does a depth first search starting at the specified cell.
  27365. * Makes sure the specified parent is never left by the
  27366. * algorithm.
  27367. */
  27368. mxCompactTreeLayout.prototype.dfs = function(cell, parent)
  27369. {
  27370. var id = mxCellPath.create(cell);
  27371. var node = null;
  27372. if (cell != null && this.visited[id] == null && !this.isVertexIgnored(cell))
  27373. {
  27374. this.visited[id] = cell;
  27375. node = this.createNode(cell);
  27376. var model = this.graph.getModel();
  27377. var prev = null;
  27378. var out = this.graph.getEdges(cell, parent, this.invert, !this.invert, false, true);
  27379. var view = this.graph.getView();
  27380. if (this.sortEdges)
  27381. {
  27382. this.sortOutgoingEdges(cell, out);
  27383. }
  27384. for (var i = 0; i < out.length; i++)
  27385. {
  27386. var edge = out[i];
  27387. if (!this.isEdgeIgnored(edge))
  27388. {
  27389. // Resets the points on the traversed edge
  27390. if (this.resetEdges)
  27391. {
  27392. this.setEdgePoints(edge, null);
  27393. }
  27394. if (this.edgeRouting)
  27395. {
  27396. this.setEdgeStyleEnabled(edge, false);
  27397. this.setEdgePoints(edge, null);
  27398. }
  27399. // Checks if terminal in same swimlane
  27400. var state = view.getState(edge);
  27401. var target = (state != null) ? state.getVisibleTerminal(this.invert) : view.getVisibleTerminal(edge, this.invert);
  27402. var tmp = this.dfs(target, parent);
  27403. if (tmp != null && model.getGeometry(target) != null)
  27404. {
  27405. if (prev == null)
  27406. {
  27407. node.child = tmp;
  27408. }
  27409. else
  27410. {
  27411. prev.next = tmp;
  27412. }
  27413. prev = tmp;
  27414. }
  27415. }
  27416. }
  27417. }
  27418. return node;
  27419. };
  27420. /**
  27421. * Function: layout
  27422. *
  27423. * Starts the actual compact tree layout algorithm
  27424. * at the given node.
  27425. */
  27426. mxCompactTreeLayout.prototype.layout = function(node)
  27427. {
  27428. if (node != null)
  27429. {
  27430. var child = node.child;
  27431. while (child != null)
  27432. {
  27433. this.layout(child);
  27434. child = child.next;
  27435. }
  27436. if (node.child != null)
  27437. {
  27438. this.attachParent(node, this.join(node));
  27439. }
  27440. else
  27441. {
  27442. this.layoutLeaf(node);
  27443. }
  27444. }
  27445. };
  27446. /**
  27447. * Function: horizontalLayout
  27448. */
  27449. mxCompactTreeLayout.prototype.horizontalLayout = function(node, x0, y0, bounds)
  27450. {
  27451. node.x += x0 + node.offsetX;
  27452. node.y += y0 + node.offsetY;
  27453. bounds = this.apply(node, bounds);
  27454. var child = node.child;
  27455. if (child != null)
  27456. {
  27457. bounds = this.horizontalLayout(child, node.x, node.y, bounds);
  27458. var siblingOffset = node.y + child.offsetY;
  27459. var s = child.next;
  27460. while (s != null)
  27461. {
  27462. bounds = this.horizontalLayout(s, node.x + child.offsetX, siblingOffset, bounds);
  27463. siblingOffset += s.offsetY;
  27464. s = s.next;
  27465. }
  27466. }
  27467. return bounds;
  27468. };
  27469. /**
  27470. * Function: verticalLayout
  27471. */
  27472. mxCompactTreeLayout.prototype.verticalLayout = function(node, parent, x0, y0, bounds)
  27473. {
  27474. node.x += x0 + node.offsetY;
  27475. node.y += y0 + node.offsetX;
  27476. bounds = this.apply(node, bounds);
  27477. var child = node.child;
  27478. if (child != null)
  27479. {
  27480. bounds = this.verticalLayout(child, node, node.x, node.y, bounds);
  27481. var siblingOffset = node.x + child.offsetY;
  27482. var s = child.next;
  27483. while (s != null)
  27484. {
  27485. bounds = this.verticalLayout(s, node, siblingOffset, node.y + child.offsetX, bounds);
  27486. siblingOffset += s.offsetY;
  27487. s = s.next;
  27488. }
  27489. }
  27490. return bounds;
  27491. };
  27492. /**
  27493. * Function: attachParent
  27494. */
  27495. mxCompactTreeLayout.prototype.attachParent = function(node, height)
  27496. {
  27497. var x = this.nodeDistance + this.levelDistance;
  27498. var y2 = (height - node.width) / 2 - this.nodeDistance;
  27499. var y1 = y2 + node.width + 2 * this.nodeDistance - height;
  27500. node.child.offsetX = x + node.height;
  27501. node.child.offsetY = y1;
  27502. node.contour.upperHead = this.createLine(node.height, 0,
  27503. this.createLine(x, y1, node.contour.upperHead));
  27504. node.contour.lowerHead = this.createLine(node.height, 0,
  27505. this.createLine(x, y2, node.contour.lowerHead));
  27506. };
  27507. /**
  27508. * Function: layoutLeaf
  27509. */
  27510. mxCompactTreeLayout.prototype.layoutLeaf = function(node)
  27511. {
  27512. var dist = 2 * this.nodeDistance;
  27513. node.contour.upperTail = this.createLine(
  27514. node.height + dist, 0);
  27515. node.contour.upperHead = node.contour.upperTail;
  27516. node.contour.lowerTail = this.createLine(
  27517. 0, -node.width - dist);
  27518. node.contour.lowerHead = this.createLine(
  27519. node.height + dist, 0, node.contour.lowerTail);
  27520. };
  27521. /**
  27522. * Function: join
  27523. */
  27524. mxCompactTreeLayout.prototype.join = function(node)
  27525. {
  27526. var dist = 2 * this.nodeDistance;
  27527. var child = node.child;
  27528. node.contour = child.contour;
  27529. var h = child.width + dist;
  27530. var sum = h;
  27531. child = child.next;
  27532. while (child != null)
  27533. {
  27534. var d = this.merge(node.contour, child.contour);
  27535. child.offsetY = d + h;
  27536. child.offsetX = 0;
  27537. h = child.width + dist;
  27538. sum += d + h;
  27539. child = child.next;
  27540. }
  27541. return sum;
  27542. };
  27543. /**
  27544. * Function: merge
  27545. */
  27546. mxCompactTreeLayout.prototype.merge = function(p1, p2)
  27547. {
  27548. var x = 0;
  27549. var y = 0;
  27550. var total = 0;
  27551. var upper = p1.lowerHead;
  27552. var lower = p2.upperHead;
  27553. while (lower != null && upper != null)
  27554. {
  27555. var d = this.offset(x, y, lower.dx, lower.dy,
  27556. upper.dx, upper.dy);
  27557. y += d;
  27558. total += d;
  27559. if (x + lower.dx <= upper.dx)
  27560. {
  27561. x += lower.dx;
  27562. y += lower.dy;
  27563. lower = lower.next;
  27564. }
  27565. else
  27566. {
  27567. x -= upper.dx;
  27568. y -= upper.dy;
  27569. upper = upper.next;
  27570. }
  27571. }
  27572. if (lower != null)
  27573. {
  27574. var b = this.bridge(p1.upperTail, 0, 0, lower, x, y);
  27575. p1.upperTail = (b.next != null) ? p2.upperTail : b;
  27576. p1.lowerTail = p2.lowerTail;
  27577. }
  27578. else
  27579. {
  27580. var b = this.bridge(p2.lowerTail, x, y, upper, 0, 0);
  27581. if (b.next == null)
  27582. {
  27583. p1.lowerTail = b;
  27584. }
  27585. }
  27586. p1.lowerHead = p2.lowerHead;
  27587. return total;
  27588. };
  27589. /**
  27590. * Function: offset
  27591. */
  27592. mxCompactTreeLayout.prototype.offset = function(p1, p2, a1, a2, b1, b2)
  27593. {
  27594. var d = 0;
  27595. if (b1 <= p1 || p1 + a1 <= 0)
  27596. {
  27597. return 0;
  27598. }
  27599. var t = b1 * a2 - a1 * b2;
  27600. if (t > 0)
  27601. {
  27602. if (p1 < 0)
  27603. {
  27604. var s = p1 * a2;
  27605. d = s / a1 - p2;
  27606. }
  27607. else if (p1 > 0)
  27608. {
  27609. var s = p1 * b2;
  27610. d = s / b1 - p2;
  27611. }
  27612. else
  27613. {
  27614. d = -p2;
  27615. }
  27616. }
  27617. else if (b1 < p1 + a1)
  27618. {
  27619. var s = (b1 - p1) * a2;
  27620. d = b2 - (p2 + s / a1);
  27621. }
  27622. else if (b1 > p1 + a1)
  27623. {
  27624. var s = (a1 + p1) * b2;
  27625. d = s / b1 - (p2 + a2);
  27626. }
  27627. else
  27628. {
  27629. d = b2 - (p2 + a2);
  27630. }
  27631. if (d > 0)
  27632. {
  27633. return d;
  27634. }
  27635. else
  27636. {
  27637. return 0;
  27638. }
  27639. };
  27640. /**
  27641. * Function: bridge
  27642. */
  27643. mxCompactTreeLayout.prototype.bridge = function(line1, x1, y1, line2, x2, y2)
  27644. {
  27645. var dx = x2 + line2.dx - x1;
  27646. var dy = 0;
  27647. var s = 0;
  27648. if (line2.dx == 0)
  27649. {
  27650. dy = line2.dy;
  27651. }
  27652. else
  27653. {
  27654. s = dx * line2.dy;
  27655. dy = s / line2.dx;
  27656. }
  27657. var r = this.createLine(dx, dy, line2.next);
  27658. line1.next = this.createLine(0, y2 + line2.dy - dy - y1, r);
  27659. return r;
  27660. };
  27661. /**
  27662. * Function: createNode
  27663. */
  27664. mxCompactTreeLayout.prototype.createNode = function(cell)
  27665. {
  27666. var node = new Object();
  27667. node.cell = cell;
  27668. node.x = 0;
  27669. node.y = 0;
  27670. node.width = 0;
  27671. node.height = 0;
  27672. var geo = this.getVertexBounds(cell);
  27673. if (geo != null)
  27674. {
  27675. if (this.isHorizontal())
  27676. {
  27677. node.width = geo.height;
  27678. node.height = geo.width;
  27679. }
  27680. else
  27681. {
  27682. node.width = geo.width;
  27683. node.height = geo.height;
  27684. }
  27685. }
  27686. node.offsetX = 0;
  27687. node.offsetY = 0;
  27688. node.contour = new Object();
  27689. return node;
  27690. };
  27691. /**
  27692. * Function: apply
  27693. */
  27694. mxCompactTreeLayout.prototype.apply = function(node, bounds)
  27695. {
  27696. var model = this.graph.getModel();
  27697. var cell = node.cell;
  27698. var g = model.getGeometry(cell);
  27699. if (cell != null && g != null)
  27700. {
  27701. if (this.isVertexMovable(cell))
  27702. {
  27703. g = this.setVertexLocation(cell, node.x, node.y);
  27704. if (this.resizeParent)
  27705. {
  27706. var parent = model.getParent(cell);
  27707. var id = mxCellPath.create(parent);
  27708. // Implements set semantic
  27709. if (this.parentsChanged[id] == null)
  27710. {
  27711. this.parentsChanged[id] = parent;
  27712. }
  27713. }
  27714. }
  27715. if (bounds == null)
  27716. {
  27717. bounds = new mxRectangle(g.x, g.y, g.width, g.height);
  27718. }
  27719. else
  27720. {
  27721. bounds = new mxRectangle(Math.min(bounds.x, g.x),
  27722. Math.min(bounds.y, g.y),
  27723. Math.max(bounds.x + bounds.width, g.x + g.width),
  27724. Math.max(bounds.y + bounds.height, g.y + g.height));
  27725. }
  27726. }
  27727. return bounds;
  27728. };
  27729. /**
  27730. * Function: createLine
  27731. */
  27732. mxCompactTreeLayout.prototype.createLine = function(dx, dy, next)
  27733. {
  27734. var line = new Object();
  27735. line.dx = dx;
  27736. line.dy = dy;
  27737. line.next = next;
  27738. return line;
  27739. };
  27740. /**
  27741. * Function: adjustParents
  27742. *
  27743. * Adjust parent cells whose child geometries have changed. The default
  27744. * implementation adjusts the group to just fit around the children with
  27745. * a padding.
  27746. */
  27747. mxCompactTreeLayout.prototype.adjustParents = function()
  27748. {
  27749. var tmp = [];
  27750. for (var id in this.parentsChanged)
  27751. {
  27752. tmp.push(this.parentsChanged[id]);
  27753. }
  27754. this.arrangeGroups(mxUtils.sortCells(tmp, true), this.groupPadding, this.groupPaddingTop,
  27755. this.groupPaddingRight, this.groupPaddingBottom, this.groupPaddingLeft);
  27756. };
  27757. /**
  27758. * Function: localEdgeProcessing
  27759. *
  27760. * Moves the specified node and all of its children by the given amount.
  27761. */
  27762. mxCompactTreeLayout.prototype.localEdgeProcessing = function(node)
  27763. {
  27764. this.processNodeOutgoing(node);
  27765. var child = node.child;
  27766. while (child != null)
  27767. {
  27768. this.localEdgeProcessing(child);
  27769. child = child.next;
  27770. }
  27771. };
  27772. /**
  27773. * Function: localEdgeProcessing
  27774. *
  27775. * Separates the x position of edges as they connect to vertices
  27776. */
  27777. mxCompactTreeLayout.prototype.processNodeOutgoing = function(node)
  27778. {
  27779. var child = node.child;
  27780. var parentCell = node.cell;
  27781. var childCount = 0;
  27782. var sortedCells = [];
  27783. while (child != null)
  27784. {
  27785. childCount++;
  27786. var sortingCriterion = child.x;
  27787. if (this.horizontal)
  27788. {
  27789. sortingCriterion = child.y;
  27790. }
  27791. sortedCells.push(new WeightedCellSorter(child, sortingCriterion));
  27792. child = child.next;
  27793. }
  27794. sortedCells.sort(WeightedCellSorter.prototype.compare);
  27795. var availableWidth = node.width;
  27796. var requiredWidth = (childCount + 1) * this.prefHozEdgeSep;
  27797. // Add a buffer on the edges of the vertex if the edge count allows
  27798. if (availableWidth > requiredWidth + (2 * this.prefHozEdgeSep))
  27799. {
  27800. availableWidth -= 2 * this.prefHozEdgeSep;
  27801. }
  27802. var edgeSpacing = availableWidth / childCount;
  27803. var currentXOffset = edgeSpacing / 2.0;
  27804. if (availableWidth > requiredWidth + (2 * this.prefHozEdgeSep))
  27805. {
  27806. currentXOffset += this.prefHozEdgeSep;
  27807. }
  27808. var currentYOffset = this.minEdgeJetty - this.prefVertEdgeOff;
  27809. var maxYOffset = 0;
  27810. var parentBounds = this.getVertexBounds(parentCell);
  27811. child = node.child;
  27812. for (var j = 0; j < sortedCells.length; j++)
  27813. {
  27814. var childCell = sortedCells[j].cell.cell;
  27815. var childBounds = this.getVertexBounds(childCell);
  27816. var edges = this.graph.getEdgesBetween(parentCell,
  27817. childCell, false);
  27818. var newPoints = [];
  27819. var x = 0;
  27820. var y = 0;
  27821. for (var i = 0; i < edges.length; i++)
  27822. {
  27823. if (this.horizontal)
  27824. {
  27825. // Use opposite co-ords, calculation was done for
  27826. //
  27827. x = parentBounds.x + parentBounds.width;
  27828. y = parentBounds.y + currentXOffset;
  27829. newPoints.push(new mxPoint(x, y));
  27830. x = parentBounds.x + parentBounds.width
  27831. + currentYOffset;
  27832. newPoints.push(new mxPoint(x, y));
  27833. y = childBounds.y + childBounds.height / 2.0;
  27834. newPoints.push(new mxPoint(x, y));
  27835. this.setEdgePoints(edges[i], newPoints);
  27836. }
  27837. else
  27838. {
  27839. x = parentBounds.x + currentXOffset;
  27840. y = parentBounds.y + parentBounds.height;
  27841. newPoints.push(new mxPoint(x, y));
  27842. y = parentBounds.y + parentBounds.height
  27843. + currentYOffset;
  27844. newPoints.push(new mxPoint(x, y));
  27845. x = childBounds.x + childBounds.width / 2.0;
  27846. newPoints.push(new mxPoint(x, y));
  27847. this.setEdgePoints(edges[i], newPoints);
  27848. }
  27849. }
  27850. if (j < childCount / 2)
  27851. {
  27852. currentYOffset += this.prefVertEdgeOff;
  27853. }
  27854. else if (j > childCount / 2)
  27855. {
  27856. currentYOffset -= this.prefVertEdgeOff;
  27857. }
  27858. // Ignore the case if equals, this means the second of 2
  27859. // jettys with the same y (even number of edges)
  27860. // pos[k * 2] = currentX;
  27861. currentXOffset += edgeSpacing;
  27862. // pos[k * 2 + 1] = currentYOffset;
  27863. maxYOffset = Math.max(maxYOffset, currentYOffset);
  27864. }
  27865. };
  27866. /**
  27867. * Copyright (c) 2006-2015, JGraph Ltd
  27868. * Copyright (c) 2006-2015, Gaudenz Alder
  27869. */
  27870. /**
  27871. * Class: mxRadialTreeLayout
  27872. *
  27873. * Extends <mxGraphLayout> to implement a radial tree algorithm. This
  27874. * layout is suitable for graphs that have no cycles (trees). Vertices that are
  27875. * not connected to the tree will be ignored by this layout.
  27876. *
  27877. * Example:
  27878. *
  27879. * (code)
  27880. * var layout = new mxRadialTreeLayout(graph);
  27881. * layout.execute(graph.getDefaultParent());
  27882. * (end)
  27883. *
  27884. * Constructor: mxRadialTreeLayout
  27885. *
  27886. * Constructs a new radial tree layout for the specified graph
  27887. */
  27888. function mxRadialTreeLayout(graph)
  27889. {
  27890. mxCompactTreeLayout.call(this, graph , false);
  27891. };
  27892. /**
  27893. * Extends mxGraphLayout.
  27894. */
  27895. mxUtils.extend(mxRadialTreeLayout, mxCompactTreeLayout);
  27896. /**
  27897. * Variable: angleOffset
  27898. *
  27899. * The initial offset to compute the angle position.
  27900. */
  27901. mxRadialTreeLayout.prototype.angleOffset = 0.5;
  27902. /**
  27903. * Variable: rootx
  27904. *
  27905. * The X co-ordinate of the root cell
  27906. */
  27907. mxRadialTreeLayout.prototype.rootx = 0;
  27908. /**
  27909. * Variable: rooty
  27910. *
  27911. * The Y co-ordinate of the root cell
  27912. */
  27913. mxRadialTreeLayout.prototype.rooty = 0;
  27914. /**
  27915. * Variable: levelDistance
  27916. *
  27917. * Holds the levelDistance. Default is 120.
  27918. */
  27919. mxRadialTreeLayout.prototype.levelDistance = 120;
  27920. /**
  27921. * Variable: nodeDistance
  27922. *
  27923. * Holds the nodeDistance. Default is 10.
  27924. */
  27925. mxRadialTreeLayout.prototype.nodeDistance = 10;
  27926. /**
  27927. * Variable: autoRadius
  27928. *
  27929. * Specifies if the radios should be computed automatically
  27930. */
  27931. mxRadialTreeLayout.prototype.autoRadius = false;
  27932. /**
  27933. * Variable: sortEdges
  27934. *
  27935. * Specifies if edges should be sorted according to the order of their
  27936. * opposite terminal cell in the model.
  27937. */
  27938. mxRadialTreeLayout.prototype.sortEdges = false;
  27939. /**
  27940. * Variable: rowMinX
  27941. *
  27942. * Array of leftmost x coordinate of each row
  27943. */
  27944. mxRadialTreeLayout.prototype.rowMinX = [];
  27945. /**
  27946. * Variable: rowMaxX
  27947. *
  27948. * Array of rightmost x coordinate of each row
  27949. */
  27950. mxRadialTreeLayout.prototype.rowMaxX = [];
  27951. /**
  27952. * Variable: rowMinCenX
  27953. *
  27954. * Array of x coordinate of leftmost vertex of each row
  27955. */
  27956. mxRadialTreeLayout.prototype.rowMinCenX = [];
  27957. /**
  27958. * Variable: rowMaxCenX
  27959. *
  27960. * Array of x coordinate of rightmost vertex of each row
  27961. */
  27962. mxRadialTreeLayout.prototype.rowMaxCenX = [];
  27963. /**
  27964. * Variable: rowRadi
  27965. *
  27966. * Array of y deltas of each row behind root vertex, also the radius in the tree
  27967. */
  27968. mxRadialTreeLayout.prototype.rowRadi = [];
  27969. /**
  27970. * Variable: row
  27971. *
  27972. * Array of vertices on each row
  27973. */
  27974. mxRadialTreeLayout.prototype.row = [];
  27975. /**
  27976. * Function: isVertexIgnored
  27977. *
  27978. * Returns a boolean indicating if the given <mxCell> should be ignored as a
  27979. * vertex. This returns true if the cell has no connections.
  27980. *
  27981. * Parameters:
  27982. *
  27983. * vertex - <mxCell> whose ignored state should be returned.
  27984. */
  27985. mxRadialTreeLayout.prototype.isVertexIgnored = function(vertex)
  27986. {
  27987. return mxGraphLayout.prototype.isVertexIgnored.apply(this, arguments) ||
  27988. this.graph.getConnections(vertex).length == 0;
  27989. };
  27990. /**
  27991. * Function: execute
  27992. *
  27993. * Implements <mxGraphLayout.execute>.
  27994. *
  27995. * If the parent has any connected edges, then it is used as the root of
  27996. * the tree. Else, <mxGraph.findTreeRoots> will be used to find a suitable
  27997. * root node within the set of children of the given parent.
  27998. *
  27999. * Parameters:
  28000. *
  28001. * parent - <mxCell> whose children should be laid out.
  28002. * root - Optional <mxCell> that will be used as the root of the tree.
  28003. */
  28004. mxRadialTreeLayout.prototype.execute = function(parent, root)
  28005. {
  28006. this.parent = parent;
  28007. this.useBoundingBox = false;
  28008. this.edgeRouting = false;
  28009. //this.horizontal = false;
  28010. mxCompactTreeLayout.prototype.execute.apply(this, arguments);
  28011. var bounds = null;
  28012. var rootBounds = this.getVertexBounds(this.root);
  28013. this.centerX = rootBounds.x + rootBounds.width / 2;
  28014. this.centerY = rootBounds.y + rootBounds.height / 2;
  28015. // Calculate the bounds of the involved vertices directly from the values set in the compact tree
  28016. for (var vertex in this.visited)
  28017. {
  28018. var vertexBounds = this.getVertexBounds(this.visited[vertex]);
  28019. bounds = (bounds != null) ? bounds : vertexBounds.clone();
  28020. bounds.add(vertexBounds);
  28021. }
  28022. this.calcRowDims([this.node], 0);
  28023. var maxLeftGrad = 0;
  28024. var maxRightGrad = 0;
  28025. // Find the steepest left and right gradients
  28026. for (var i = 0; i < this.row.length; i++)
  28027. {
  28028. var leftGrad = (this.centerX - this.rowMinX[i] - this.nodeDistance) / this.rowRadi[i];
  28029. var rightGrad = (this.rowMaxX[i] - this.centerX - this.nodeDistance) / this.rowRadi[i];
  28030. maxLeftGrad = Math.max (maxLeftGrad, leftGrad);
  28031. maxRightGrad = Math.max (maxRightGrad, rightGrad);
  28032. }
  28033. // Extend out row so they meet the maximum gradient and convert to polar co-ords
  28034. for (var i = 0; i < this.row.length; i++)
  28035. {
  28036. var xLeftLimit = this.centerX - this.nodeDistance - maxLeftGrad * this.rowRadi[i];
  28037. var xRightLimit = this.centerX + this.nodeDistance + maxRightGrad * this.rowRadi[i];
  28038. var fullWidth = xRightLimit - xLeftLimit;
  28039. for (var j = 0; j < this.row[i].length; j ++)
  28040. {
  28041. var row = this.row[i];
  28042. var node = row[j];
  28043. var vertexBounds = this.getVertexBounds(node.cell);
  28044. var xProportion = (vertexBounds.x + vertexBounds.width / 2 - xLeftLimit) / (fullWidth);
  28045. var theta = 2 * Math.PI * xProportion;
  28046. node.theta = theta;
  28047. }
  28048. }
  28049. // Post-process from outside inwards to try to align parents with children
  28050. for (var i = this.row.length - 2; i >= 0; i--)
  28051. {
  28052. var row = this.row[i];
  28053. for (var j = 0; j < row.length; j++)
  28054. {
  28055. var node = row[j];
  28056. var child = node.child;
  28057. var counter = 0;
  28058. var totalTheta = 0;
  28059. while (child != null)
  28060. {
  28061. totalTheta += child.theta;
  28062. counter++;
  28063. child = child.next;
  28064. }
  28065. if (counter > 0)
  28066. {
  28067. var averTheta = totalTheta / counter;
  28068. if (averTheta > node.theta && j < row.length - 1)
  28069. {
  28070. var nextTheta = row[j+1].theta;
  28071. node.theta = Math.min (averTheta, nextTheta - Math.PI/10);
  28072. }
  28073. else if (averTheta < node.theta && j > 0 )
  28074. {
  28075. var lastTheta = row[j-1].theta;
  28076. node.theta = Math.max (averTheta, lastTheta + Math.PI/10);
  28077. }
  28078. }
  28079. }
  28080. }
  28081. // Set locations
  28082. for (var i = 0; i < this.row.length; i++)
  28083. {
  28084. for (var j = 0; j < this.row[i].length; j ++)
  28085. {
  28086. var row = this.row[i];
  28087. var node = row[j];
  28088. var vertexBounds = this.getVertexBounds(node.cell);
  28089. this.setVertexLocation(node.cell,
  28090. this.centerX - vertexBounds.width / 2 + this.rowRadi[i] * Math.cos(node.theta),
  28091. this.centerY - vertexBounds.height / 2 + this.rowRadi[i] * Math.sin(node.theta));
  28092. }
  28093. }
  28094. };
  28095. /**
  28096. * Function: calcRowDims
  28097. *
  28098. * Recursive function to calculate the dimensions of each row
  28099. *
  28100. * Parameters:
  28101. *
  28102. * row - Array of internal nodes, the children of which are to be processed.
  28103. * rowNum - Integer indicating which row is being processed.
  28104. */
  28105. mxRadialTreeLayout.prototype.calcRowDims = function(row, rowNum)
  28106. {
  28107. if (row == null || row.length == 0)
  28108. {
  28109. return;
  28110. }
  28111. // Place root's children proportionally around the first level
  28112. this.rowMinX[rowNum] = this.centerX;
  28113. this.rowMaxX[rowNum] = this.centerX;
  28114. this.rowMinCenX[rowNum] = this.centerX;
  28115. this.rowMaxCenX[rowNum] = this.centerX;
  28116. this.row[rowNum] = [];
  28117. var rowHasChildren = false;
  28118. for (var i = 0; i < row.length; i++)
  28119. {
  28120. var child = row[i] != null ? row[i].child : null;
  28121. while (child != null)
  28122. {
  28123. var cell = child.cell;
  28124. var vertexBounds = this.getVertexBounds(cell);
  28125. this.rowMinX[rowNum] = Math.min(vertexBounds.x, this.rowMinX[rowNum]);
  28126. this.rowMaxX[rowNum] = Math.max(vertexBounds.x + vertexBounds.width, this.rowMaxX[rowNum]);
  28127. this.rowMinCenX[rowNum] = Math.min(vertexBounds.x + vertexBounds.width / 2, this.rowMinCenX[rowNum]);
  28128. this.rowMaxCenX[rowNum] = Math.max(vertexBounds.x + vertexBounds.width / 2, this.rowMaxCenX[rowNum]);
  28129. this.rowRadi[rowNum] = vertexBounds.y - this.getVertexBounds(this.root).y;
  28130. if (child.child != null)
  28131. {
  28132. rowHasChildren = true;
  28133. }
  28134. this.row[rowNum].push(child);
  28135. child = child.next;
  28136. }
  28137. }
  28138. if (rowHasChildren)
  28139. {
  28140. this.calcRowDims(this.row[rowNum], rowNum + 1);
  28141. }
  28142. };
  28143. /**
  28144. * Copyright (c) 2006-2015, JGraph Ltd
  28145. * Copyright (c) 2006-2015, Gaudenz Alder
  28146. */
  28147. /**
  28148. * Class: mxFastOrganicLayout
  28149. *
  28150. * Extends <mxGraphLayout> to implement a fast organic layout algorithm.
  28151. * The vertices need to be connected for this layout to work, vertices
  28152. * with no connections are ignored.
  28153. *
  28154. * Example:
  28155. *
  28156. * (code)
  28157. * var layout = new mxFastOrganicLayout(graph);
  28158. * layout.execute(graph.getDefaultParent());
  28159. * (end)
  28160. *
  28161. * Constructor: mxCompactTreeLayout
  28162. *
  28163. * Constructs a new fast organic layout for the specified graph.
  28164. */
  28165. function mxFastOrganicLayout(graph)
  28166. {
  28167. mxGraphLayout.call(this, graph);
  28168. };
  28169. /**
  28170. * Extends mxGraphLayout.
  28171. */
  28172. mxFastOrganicLayout.prototype = new mxGraphLayout();
  28173. mxFastOrganicLayout.prototype.constructor = mxFastOrganicLayout;
  28174. /**
  28175. * Variable: useInputOrigin
  28176. *
  28177. * Specifies if the top left corner of the input cells should be the origin
  28178. * of the layout result. Default is true.
  28179. */
  28180. mxFastOrganicLayout.prototype.useInputOrigin = true;
  28181. /**
  28182. * Variable: resetEdges
  28183. *
  28184. * Specifies if all edge points of traversed edges should be removed.
  28185. * Default is true.
  28186. */
  28187. mxFastOrganicLayout.prototype.resetEdges = true;
  28188. /**
  28189. * Variable: disableEdgeStyle
  28190. *
  28191. * Specifies if the STYLE_NOEDGESTYLE flag should be set on edges that are
  28192. * modified by the result. Default is true.
  28193. */
  28194. mxFastOrganicLayout.prototype.disableEdgeStyle = true;
  28195. /**
  28196. * Variable: forceConstant
  28197. *
  28198. * The force constant by which the attractive forces are divided and the
  28199. * replusive forces are multiple by the square of. The value equates to the
  28200. * average radius there is of free space around each node. Default is 50.
  28201. */
  28202. mxFastOrganicLayout.prototype.forceConstant = 50;
  28203. /**
  28204. * Variable: forceConstantSquared
  28205. *
  28206. * Cache of <forceConstant>^2 for performance.
  28207. */
  28208. mxFastOrganicLayout.prototype.forceConstantSquared = 0;
  28209. /**
  28210. * Variable: minDistanceLimit
  28211. *
  28212. * Minimal distance limit. Default is 2. Prevents of
  28213. * dividing by zero.
  28214. */
  28215. mxFastOrganicLayout.prototype.minDistanceLimit = 2;
  28216. /**
  28217. * Variable: minDistanceLimit
  28218. *
  28219. * Minimal distance limit. Default is 2. Prevents of
  28220. * dividing by zero.
  28221. */
  28222. mxFastOrganicLayout.prototype.maxDistanceLimit = 500;
  28223. /**
  28224. * Variable: minDistanceLimitSquared
  28225. *
  28226. * Cached version of <minDistanceLimit> squared.
  28227. */
  28228. mxFastOrganicLayout.prototype.minDistanceLimitSquared = 4;
  28229. /**
  28230. * Variable: initialTemp
  28231. *
  28232. * Start value of temperature. Default is 200.
  28233. */
  28234. mxFastOrganicLayout.prototype.initialTemp = 200;
  28235. /**
  28236. * Variable: temperature
  28237. *
  28238. * Temperature to limit displacement at later stages of layout.
  28239. */
  28240. mxFastOrganicLayout.prototype.temperature = 0;
  28241. /**
  28242. * Variable: maxIterations
  28243. *
  28244. * Total number of iterations to run the layout though.
  28245. */
  28246. mxFastOrganicLayout.prototype.maxIterations = 0;
  28247. /**
  28248. * Variable: iteration
  28249. *
  28250. * Current iteration count.
  28251. */
  28252. mxFastOrganicLayout.prototype.iteration = 0;
  28253. /**
  28254. * Variable: vertexArray
  28255. *
  28256. * An array of all vertices to be laid out.
  28257. */
  28258. mxFastOrganicLayout.prototype.vertexArray;
  28259. /**
  28260. * Variable: dispX
  28261. *
  28262. * An array of locally stored X co-ordinate displacements for the vertices.
  28263. */
  28264. mxFastOrganicLayout.prototype.dispX;
  28265. /**
  28266. * Variable: dispY
  28267. *
  28268. * An array of locally stored Y co-ordinate displacements for the vertices.
  28269. */
  28270. mxFastOrganicLayout.prototype.dispY;
  28271. /**
  28272. * Variable: cellLocation
  28273. *
  28274. * An array of locally stored co-ordinate positions for the vertices.
  28275. */
  28276. mxFastOrganicLayout.prototype.cellLocation;
  28277. /**
  28278. * Variable: radius
  28279. *
  28280. * The approximate radius of each cell, nodes only.
  28281. */
  28282. mxFastOrganicLayout.prototype.radius;
  28283. /**
  28284. * Variable: radiusSquared
  28285. *
  28286. * The approximate radius squared of each cell, nodes only.
  28287. */
  28288. mxFastOrganicLayout.prototype.radiusSquared;
  28289. /**
  28290. * Variable: isMoveable
  28291. *
  28292. * Array of booleans representing the movable states of the vertices.
  28293. */
  28294. mxFastOrganicLayout.prototype.isMoveable;
  28295. /**
  28296. * Variable: neighbours
  28297. *
  28298. * Local copy of cell neighbours.
  28299. */
  28300. mxFastOrganicLayout.prototype.neighbours;
  28301. /**
  28302. * Variable: indices
  28303. *
  28304. * Hashtable from cells to local indices.
  28305. */
  28306. mxFastOrganicLayout.prototype.indices;
  28307. /**
  28308. * Variable: allowedToRun
  28309. *
  28310. * Boolean flag that specifies if the layout is allowed to run. If this is
  28311. * set to false, then the layout exits in the following iteration.
  28312. */
  28313. mxFastOrganicLayout.prototype.allowedToRun = true;
  28314. /**
  28315. * Function: isVertexIgnored
  28316. *
  28317. * Returns a boolean indicating if the given <mxCell> should be ignored as a
  28318. * vertex. This returns true if the cell has no connections.
  28319. *
  28320. * Parameters:
  28321. *
  28322. * vertex - <mxCell> whose ignored state should be returned.
  28323. */
  28324. mxFastOrganicLayout.prototype.isVertexIgnored = function(vertex)
  28325. {
  28326. return mxGraphLayout.prototype.isVertexIgnored.apply(this, arguments) ||
  28327. this.graph.getConnections(vertex).length == 0;
  28328. };
  28329. /**
  28330. * Function: execute
  28331. *
  28332. * Implements <mxGraphLayout.execute>. This operates on all children of the
  28333. * given parent where <isVertexIgnored> returns false.
  28334. */
  28335. mxFastOrganicLayout.prototype.execute = function(parent)
  28336. {
  28337. var model = this.graph.getModel();
  28338. this.vertexArray = [];
  28339. var cells = this.graph.getChildVertices(parent);
  28340. for (var i = 0; i < cells.length; i++)
  28341. {
  28342. if (!this.isVertexIgnored(cells[i]))
  28343. {
  28344. this.vertexArray.push(cells[i]);
  28345. }
  28346. }
  28347. var initialBounds = (this.useInputOrigin) ?
  28348. this.graph.getBoundingBoxFromGeometry(this.vertexArray) :
  28349. null;
  28350. var n = this.vertexArray.length;
  28351. this.indices = [];
  28352. this.dispX = [];
  28353. this.dispY = [];
  28354. this.cellLocation = [];
  28355. this.isMoveable = [];
  28356. this.neighbours = [];
  28357. this.radius = [];
  28358. this.radiusSquared = [];
  28359. if (this.forceConstant < 0.001)
  28360. {
  28361. this.forceConstant = 0.001;
  28362. }
  28363. this.forceConstantSquared = this.forceConstant * this.forceConstant;
  28364. // Create a map of vertices first. This is required for the array of
  28365. // arrays called neighbours which holds, for each vertex, a list of
  28366. // ints which represents the neighbours cells to that vertex as
  28367. // the indices into vertexArray
  28368. for (var i = 0; i < this.vertexArray.length; i++)
  28369. {
  28370. var vertex = this.vertexArray[i];
  28371. this.cellLocation[i] = [];
  28372. // Set up the mapping from array indices to cells
  28373. var id = mxObjectIdentity.get(vertex);
  28374. this.indices[id] = i;
  28375. var bounds = this.getVertexBounds(vertex);
  28376. // Set the X,Y value of the internal version of the cell to
  28377. // the center point of the vertex for better positioning
  28378. var width = bounds.width;
  28379. var height = bounds.height;
  28380. // Randomize (0, 0) locations
  28381. var x = bounds.x;
  28382. var y = bounds.y;
  28383. this.cellLocation[i][0] = x + width / 2.0;
  28384. this.cellLocation[i][1] = y + height / 2.0;
  28385. this.radius[i] = Math.min(width, height);
  28386. this.radiusSquared[i] = this.radius[i] * this.radius[i];
  28387. }
  28388. // Moves cell location back to top-left from center locations used in
  28389. // algorithm, resetting the edge points is part of the transaction
  28390. model.beginUpdate();
  28391. try
  28392. {
  28393. for (var i = 0; i < n; i++)
  28394. {
  28395. this.dispX[i] = 0;
  28396. this.dispY[i] = 0;
  28397. this.isMoveable[i] = this.isVertexMovable(this.vertexArray[i]);
  28398. // Get lists of neighbours to all vertices, translate the cells
  28399. // obtained in indices into vertexArray and store as an array
  28400. // against the orginial cell index
  28401. var edges = this.graph.getConnections(this.vertexArray[i], parent);
  28402. var cells = this.graph.getOpposites(edges, this.vertexArray[i]);
  28403. this.neighbours[i] = [];
  28404. for (var j = 0; j < cells.length; j++)
  28405. {
  28406. // Resets the points on the traversed edge
  28407. if (this.resetEdges)
  28408. {
  28409. this.graph.resetEdge(edges[j]);
  28410. }
  28411. if (this.disableEdgeStyle)
  28412. {
  28413. this.setEdgeStyleEnabled(edges[j], false);
  28414. }
  28415. // Looks the cell up in the indices dictionary
  28416. var id = mxObjectIdentity.get(cells[j]);
  28417. var index = this.indices[id];
  28418. // Check the connected cell in part of the vertex list to be
  28419. // acted on by this layout
  28420. if (index != null)
  28421. {
  28422. this.neighbours[i][j] = index;
  28423. }
  28424. // Else if index of the other cell doesn't correspond to
  28425. // any cell listed to be acted upon in this layout. Set
  28426. // the index to the value of this vertex (a dummy self-loop)
  28427. // so the attraction force of the edge is not calculated
  28428. else
  28429. {
  28430. this.neighbours[i][j] = i;
  28431. }
  28432. }
  28433. }
  28434. this.temperature = this.initialTemp;
  28435. // If max number of iterations has not been set, guess it
  28436. if (this.maxIterations == 0)
  28437. {
  28438. this.maxIterations = 20 * Math.sqrt(n);
  28439. }
  28440. // Main iteration loop
  28441. for (this.iteration = 0; this.iteration < this.maxIterations; this.iteration++)
  28442. {
  28443. if (!this.allowedToRun)
  28444. {
  28445. return;
  28446. }
  28447. // Calculate repulsive forces on all vertices
  28448. this.calcRepulsion();
  28449. // Calculate attractive forces through edges
  28450. this.calcAttraction();
  28451. this.calcPositions();
  28452. this.reduceTemperature();
  28453. }
  28454. var minx = null;
  28455. var miny = null;
  28456. for (var i = 0; i < this.vertexArray.length; i++)
  28457. {
  28458. var vertex = this.vertexArray[i];
  28459. if (this.isVertexMovable(vertex))
  28460. {
  28461. var bounds = this.getVertexBounds(vertex);
  28462. if (bounds != null)
  28463. {
  28464. this.cellLocation[i][0] -= bounds.width / 2.0;
  28465. this.cellLocation[i][1] -= bounds.height / 2.0;
  28466. var x = this.graph.snap(Math.round(this.cellLocation[i][0]));
  28467. var y = this.graph.snap(Math.round(this.cellLocation[i][1]));
  28468. this.setVertexLocation(vertex, x, y);
  28469. if (minx == null)
  28470. {
  28471. minx = x;
  28472. }
  28473. else
  28474. {
  28475. minx = Math.min(minx, x);
  28476. }
  28477. if (miny == null)
  28478. {
  28479. miny = y;
  28480. }
  28481. else
  28482. {
  28483. miny = Math.min(miny, y);
  28484. }
  28485. }
  28486. }
  28487. }
  28488. // Modifies the cloned geometries in-place. Not needed
  28489. // to clone the geometries again as we're in the same
  28490. // undoable change.
  28491. var dx = -(minx || 0) + 1;
  28492. var dy = -(miny || 0) + 1;
  28493. if (initialBounds != null)
  28494. {
  28495. dx += initialBounds.x;
  28496. dy += initialBounds.y;
  28497. }
  28498. this.graph.moveCells(this.vertexArray, dx, dy);
  28499. }
  28500. finally
  28501. {
  28502. model.endUpdate();
  28503. }
  28504. };
  28505. /**
  28506. * Function: calcPositions
  28507. *
  28508. * Takes the displacements calculated for each cell and applies them to the
  28509. * local cache of cell positions. Limits the displacement to the current
  28510. * temperature.
  28511. */
  28512. mxFastOrganicLayout.prototype.calcPositions = function()
  28513. {
  28514. for (var index = 0; index < this.vertexArray.length; index++)
  28515. {
  28516. if (this.isMoveable[index])
  28517. {
  28518. // Get the distance of displacement for this node for this
  28519. // iteration
  28520. var deltaLength = Math.sqrt(this.dispX[index] * this.dispX[index] +
  28521. this.dispY[index] * this.dispY[index]);
  28522. if (deltaLength < 0.001)
  28523. {
  28524. deltaLength = 0.001;
  28525. }
  28526. // Scale down by the current temperature if less than the
  28527. // displacement distance
  28528. var newXDisp = this.dispX[index] / deltaLength
  28529. * Math.min(deltaLength, this.temperature);
  28530. var newYDisp = this.dispY[index] / deltaLength
  28531. * Math.min(deltaLength, this.temperature);
  28532. // reset displacements
  28533. this.dispX[index] = 0;
  28534. this.dispY[index] = 0;
  28535. // Update the cached cell locations
  28536. this.cellLocation[index][0] += newXDisp;
  28537. this.cellLocation[index][1] += newYDisp;
  28538. }
  28539. }
  28540. };
  28541. /**
  28542. * Function: calcAttraction
  28543. *
  28544. * Calculates the attractive forces between all laid out nodes linked by
  28545. * edges
  28546. */
  28547. mxFastOrganicLayout.prototype.calcAttraction = function()
  28548. {
  28549. // Check the neighbours of each vertex and calculate the attractive
  28550. // force of the edge connecting them
  28551. for (var i = 0; i < this.vertexArray.length; i++)
  28552. {
  28553. for (var k = 0; k < this.neighbours[i].length; k++)
  28554. {
  28555. // Get the index of the othe cell in the vertex array
  28556. var j = this.neighbours[i][k];
  28557. // Do not proceed self-loops
  28558. if (i != j &&
  28559. this.isMoveable[i] &&
  28560. this.isMoveable[j])
  28561. {
  28562. var xDelta = this.cellLocation[i][0] - this.cellLocation[j][0];
  28563. var yDelta = this.cellLocation[i][1] - this.cellLocation[j][1];
  28564. // The distance between the nodes
  28565. var deltaLengthSquared = xDelta * xDelta + yDelta
  28566. * yDelta - this.radiusSquared[i] - this.radiusSquared[j];
  28567. if (deltaLengthSquared < this.minDistanceLimitSquared)
  28568. {
  28569. deltaLengthSquared = this.minDistanceLimitSquared;
  28570. }
  28571. var deltaLength = Math.sqrt(deltaLengthSquared);
  28572. var force = (deltaLengthSquared) / this.forceConstant;
  28573. var displacementX = (xDelta / deltaLength) * force;
  28574. var displacementY = (yDelta / deltaLength) * force;
  28575. this.dispX[i] -= displacementX;
  28576. this.dispY[i] -= displacementY;
  28577. this.dispX[j] += displacementX;
  28578. this.dispY[j] += displacementY;
  28579. }
  28580. }
  28581. }
  28582. };
  28583. /**
  28584. * Function: calcRepulsion
  28585. *
  28586. * Calculates the repulsive forces between all laid out nodes
  28587. */
  28588. mxFastOrganicLayout.prototype.calcRepulsion = function()
  28589. {
  28590. var vertexCount = this.vertexArray.length;
  28591. for (var i = 0; i < vertexCount; i++)
  28592. {
  28593. for (var j = i; j < vertexCount; j++)
  28594. {
  28595. // Exits if the layout is no longer allowed to run
  28596. if (!this.allowedToRun)
  28597. {
  28598. return;
  28599. }
  28600. if (j != i &&
  28601. this.isMoveable[i] &&
  28602. this.isMoveable[j])
  28603. {
  28604. var xDelta = this.cellLocation[i][0] - this.cellLocation[j][0];
  28605. var yDelta = this.cellLocation[i][1] - this.cellLocation[j][1];
  28606. if (xDelta == 0)
  28607. {
  28608. xDelta = 0.01 + Math.random();
  28609. }
  28610. if (yDelta == 0)
  28611. {
  28612. yDelta = 0.01 + Math.random();
  28613. }
  28614. // Distance between nodes
  28615. var deltaLength = Math.sqrt((xDelta * xDelta)
  28616. + (yDelta * yDelta));
  28617. var deltaLengthWithRadius = deltaLength - this.radius[i]
  28618. - this.radius[j];
  28619. if (deltaLengthWithRadius > this.maxDistanceLimit)
  28620. {
  28621. // Ignore vertices too far apart
  28622. continue;
  28623. }
  28624. if (deltaLengthWithRadius < this.minDistanceLimit)
  28625. {
  28626. deltaLengthWithRadius = this.minDistanceLimit;
  28627. }
  28628. var force = this.forceConstantSquared / deltaLengthWithRadius;
  28629. var displacementX = (xDelta / deltaLength) * force;
  28630. var displacementY = (yDelta / deltaLength) * force;
  28631. this.dispX[i] += displacementX;
  28632. this.dispY[i] += displacementY;
  28633. this.dispX[j] -= displacementX;
  28634. this.dispY[j] -= displacementY;
  28635. }
  28636. }
  28637. }
  28638. };
  28639. /**
  28640. * Function: reduceTemperature
  28641. *
  28642. * Reduces the temperature of the layout from an initial setting in a linear
  28643. * fashion to zero.
  28644. */
  28645. mxFastOrganicLayout.prototype.reduceTemperature = function()
  28646. {
  28647. this.temperature = this.initialTemp * (1.0 - this.iteration / this.maxIterations);
  28648. };
  28649. /**
  28650. * Copyright (c) 2006-2015, JGraph Ltd
  28651. * Copyright (c) 2006-2015, Gaudenz Alder
  28652. */
  28653. /**
  28654. * Class: mxCircleLayout
  28655. *
  28656. * Extends <mxGraphLayout> to implement a circluar layout for a given radius.
  28657. * The vertices do not need to be connected for this layout to work and all
  28658. * connections between vertices are not taken into account.
  28659. *
  28660. * Example:
  28661. *
  28662. * (code)
  28663. * var layout = new mxCircleLayout(graph);
  28664. * layout.execute(graph.getDefaultParent());
  28665. * (end)
  28666. *
  28667. * Constructor: mxCircleLayout
  28668. *
  28669. * Constructs a new circular layout for the specified radius.
  28670. *
  28671. * Arguments:
  28672. *
  28673. * graph - <mxGraph> that contains the cells.
  28674. * radius - Optional radius as an int. Default is 100.
  28675. */
  28676. function mxCircleLayout(graph, radius)
  28677. {
  28678. mxGraphLayout.call(this, graph);
  28679. this.radius = (radius != null) ? radius : 100;
  28680. };
  28681. /**
  28682. * Extends mxGraphLayout.
  28683. */
  28684. mxCircleLayout.prototype = new mxGraphLayout();
  28685. mxCircleLayout.prototype.constructor = mxCircleLayout;
  28686. /**
  28687. * Variable: radius
  28688. *
  28689. * Integer specifying the size of the radius. Default is 100.
  28690. */
  28691. mxCircleLayout.prototype.radius = null;
  28692. /**
  28693. * Variable: moveCircle
  28694. *
  28695. * Boolean specifying if the circle should be moved to the top,
  28696. * left corner specified by <x0> and <y0>. Default is false.
  28697. */
  28698. mxCircleLayout.prototype.moveCircle = false;
  28699. /**
  28700. * Variable: x0
  28701. *
  28702. * Integer specifying the left coordinate of the circle.
  28703. * Default is 0.
  28704. */
  28705. mxCircleLayout.prototype.x0 = 0;
  28706. /**
  28707. * Variable: y0
  28708. *
  28709. * Integer specifying the top coordinate of the circle.
  28710. * Default is 0.
  28711. */
  28712. mxCircleLayout.prototype.y0 = 0;
  28713. /**
  28714. * Variable: resetEdges
  28715. *
  28716. * Specifies if all edge points of traversed edges should be removed.
  28717. * Default is true.
  28718. */
  28719. mxCircleLayout.prototype.resetEdges = true;
  28720. /**
  28721. * Variable: disableEdgeStyle
  28722. *
  28723. * Specifies if the STYLE_NOEDGESTYLE flag should be set on edges that are
  28724. * modified by the result. Default is true.
  28725. */
  28726. mxCircleLayout.prototype.disableEdgeStyle = true;
  28727. /**
  28728. * Function: execute
  28729. *
  28730. * Implements <mxGraphLayout.execute>.
  28731. */
  28732. mxCircleLayout.prototype.execute = function(parent)
  28733. {
  28734. var model = this.graph.getModel();
  28735. // Moves the vertices to build a circle. Makes sure the
  28736. // radius is large enough for the vertices to not
  28737. // overlap
  28738. model.beginUpdate();
  28739. try
  28740. {
  28741. // Gets all vertices inside the parent and finds
  28742. // the maximum dimension of the largest vertex
  28743. var max = 0;
  28744. var top = null;
  28745. var left = null;
  28746. var vertices = [];
  28747. var childCount = model.getChildCount(parent);
  28748. for (var i = 0; i < childCount; i++)
  28749. {
  28750. var cell = model.getChildAt(parent, i);
  28751. if (!this.isVertexIgnored(cell))
  28752. {
  28753. vertices.push(cell);
  28754. var bounds = this.getVertexBounds(cell);
  28755. if (top == null)
  28756. {
  28757. top = bounds.y;
  28758. }
  28759. else
  28760. {
  28761. top = Math.min(top, bounds.y);
  28762. }
  28763. if (left == null)
  28764. {
  28765. left = bounds.x;
  28766. }
  28767. else
  28768. {
  28769. left = Math.min(left, bounds.x);
  28770. }
  28771. max = Math.max(max, Math.max(bounds.width, bounds.height));
  28772. }
  28773. else if (!this.isEdgeIgnored(cell))
  28774. {
  28775. // Resets the points on the traversed edge
  28776. if (this.resetEdges)
  28777. {
  28778. this.graph.resetEdge(cell);
  28779. }
  28780. if (this.disableEdgeStyle)
  28781. {
  28782. this.setEdgeStyleEnabled(cell, false);
  28783. }
  28784. }
  28785. }
  28786. var r = this.getRadius(vertices.length, max);
  28787. // Moves the circle to the specified origin
  28788. if (this.moveCircle)
  28789. {
  28790. left = this.x0;
  28791. top = this.y0;
  28792. }
  28793. this.circle(vertices, r, left, top);
  28794. }
  28795. finally
  28796. {
  28797. model.endUpdate();
  28798. }
  28799. };
  28800. /**
  28801. * Function: getRadius
  28802. *
  28803. * Returns the radius to be used for the given vertex count. Max is the maximum
  28804. * width or height of all vertices in the layout.
  28805. */
  28806. mxCircleLayout.prototype.getRadius = function(count, max)
  28807. {
  28808. return Math.max(count * max / Math.PI, this.radius);
  28809. };
  28810. /**
  28811. * Function: circle
  28812. *
  28813. * Executes the circular layout for the specified array
  28814. * of vertices and the given radius. This is called from
  28815. * <execute>.
  28816. */
  28817. mxCircleLayout.prototype.circle = function(vertices, r, left, top)
  28818. {
  28819. var vertexCount = vertices.length;
  28820. var phi = 2 * Math.PI / vertexCount;
  28821. for (var i = 0; i < vertexCount; i++)
  28822. {
  28823. if (this.isVertexMovable(vertices[i]))
  28824. {
  28825. this.setVertexLocation(vertices[i],
  28826. Math.round(left + r + r * Math.sin(i * phi)),
  28827. Math.round(top + r + r * Math.cos(i * phi)));
  28828. }
  28829. }
  28830. };
  28831. /**
  28832. * Copyright (c) 2006-2015, JGraph Ltd
  28833. * Copyright (c) 2006-2015, Gaudenz Alder
  28834. */
  28835. /**
  28836. * Class: mxParallelEdgeLayout
  28837. *
  28838. * Extends <mxGraphLayout> for arranging parallel edges. This layout works
  28839. * on edges for all pairs of vertices where there is more than one edge
  28840. * connecting the latter.
  28841. *
  28842. * Example:
  28843. *
  28844. * (code)
  28845. * var layout = new mxParallelEdgeLayout(graph);
  28846. * layout.execute(graph.getDefaultParent());
  28847. * (end)
  28848. *
  28849. * To run the layout for the parallel edges of a changed edge only, the
  28850. * following code can be used.
  28851. *
  28852. * (code)
  28853. * var layout = new mxParallelEdgeLayout(graph);
  28854. *
  28855. * graph.addListener(mxEvent.CELL_CONNECTED, function(sender, evt)
  28856. * {
  28857. * var model = graph.getModel();
  28858. * var edge = evt.getProperty('edge');
  28859. * var src = model.getTerminal(edge, true);
  28860. * var trg = model.getTerminal(edge, false);
  28861. *
  28862. * layout.isEdgeIgnored = function(edge2)
  28863. * {
  28864. * var src2 = model.getTerminal(edge2, true);
  28865. * var trg2 = model.getTerminal(edge2, false);
  28866. *
  28867. * return !(model.isEdge(edge2) && ((src == src2 && trg == trg2) || (src == trg2 && trg == src2)));
  28868. * };
  28869. *
  28870. * layout.execute(graph.getDefaultParent());
  28871. * });
  28872. * (end)
  28873. *
  28874. * Constructor: mxParallelEdgeLayout
  28875. *
  28876. * Constructs a new parallel edge layout for the specified graph.
  28877. */
  28878. function mxParallelEdgeLayout(graph)
  28879. {
  28880. mxGraphLayout.call(this, graph);
  28881. };
  28882. /**
  28883. * Extends mxGraphLayout.
  28884. */
  28885. mxParallelEdgeLayout.prototype = new mxGraphLayout();
  28886. mxParallelEdgeLayout.prototype.constructor = mxParallelEdgeLayout;
  28887. /**
  28888. * Variable: spacing
  28889. *
  28890. * Defines the spacing between the parallels. Default is 20.
  28891. */
  28892. mxParallelEdgeLayout.prototype.spacing = 20;
  28893. /**
  28894. * Function: execute
  28895. *
  28896. * Implements <mxGraphLayout.execute>.
  28897. */
  28898. mxParallelEdgeLayout.prototype.execute = function(parent)
  28899. {
  28900. var lookup = this.findParallels(parent);
  28901. this.graph.model.beginUpdate();
  28902. try
  28903. {
  28904. for (var i in lookup)
  28905. {
  28906. var parallels = lookup[i];
  28907. if (parallels.length > 1)
  28908. {
  28909. this.layout(parallels);
  28910. }
  28911. }
  28912. }
  28913. finally
  28914. {
  28915. this.graph.model.endUpdate();
  28916. }
  28917. };
  28918. /**
  28919. * Function: findParallels
  28920. *
  28921. * Finds the parallel edges in the given parent.
  28922. */
  28923. mxParallelEdgeLayout.prototype.findParallels = function(parent)
  28924. {
  28925. var model = this.graph.getModel();
  28926. var lookup = [];
  28927. var childCount = model.getChildCount(parent);
  28928. for (var i = 0; i < childCount; i++)
  28929. {
  28930. var child = model.getChildAt(parent, i);
  28931. if (!this.isEdgeIgnored(child))
  28932. {
  28933. var id = this.getEdgeId(child);
  28934. if (id != null)
  28935. {
  28936. if (lookup[id] == null)
  28937. {
  28938. lookup[id] = [];
  28939. }
  28940. lookup[id].push(child);
  28941. }
  28942. }
  28943. }
  28944. return lookup;
  28945. };
  28946. /**
  28947. * Function: getEdgeId
  28948. *
  28949. * Returns a unique ID for the given edge. The id is independent of the
  28950. * edge direction and is built using the visible terminal of the given
  28951. * edge.
  28952. */
  28953. mxParallelEdgeLayout.prototype.getEdgeId = function(edge)
  28954. {
  28955. var view = this.graph.getView();
  28956. // Cannot used cached visible terminal because this could be triggered in BEFORE_UNDO
  28957. var src = view.getVisibleTerminal(edge, true);
  28958. var trg = view.getVisibleTerminal(edge, false);
  28959. if (src != null && trg != null)
  28960. {
  28961. src = mxObjectIdentity.get(src);
  28962. trg = mxObjectIdentity.get(trg);
  28963. return (src > trg) ? trg + '-' + src : src + '-' + trg;
  28964. }
  28965. return null;
  28966. };
  28967. /**
  28968. * Function: layout
  28969. *
  28970. * Lays out the parallel edges in the given array.
  28971. */
  28972. mxParallelEdgeLayout.prototype.layout = function(parallels)
  28973. {
  28974. var edge = parallels[0];
  28975. var view = this.graph.getView();
  28976. var model = this.graph.getModel();
  28977. var src = model.getGeometry(view.getVisibleTerminal(edge, true));
  28978. var trg = model.getGeometry(view.getVisibleTerminal(edge, false));
  28979. // Routes multiple loops
  28980. if (src == trg)
  28981. {
  28982. var x0 = src.x + src.width + this.spacing;
  28983. var y0 = src.y + src.height / 2;
  28984. for (var i = 0; i < parallels.length; i++)
  28985. {
  28986. this.route(parallels[i], x0, y0);
  28987. x0 += this.spacing;
  28988. }
  28989. }
  28990. else if (src != null && trg != null)
  28991. {
  28992. // Routes parallel edges
  28993. var scx = src.x + src.width / 2;
  28994. var scy = src.y + src.height / 2;
  28995. var tcx = trg.x + trg.width / 2;
  28996. var tcy = trg.y + trg.height / 2;
  28997. var dx = tcx - scx;
  28998. var dy = tcy - scy;
  28999. var len = Math.sqrt(dx * dx + dy * dy);
  29000. if (len > 0)
  29001. {
  29002. var x0 = scx + dx / 2;
  29003. var y0 = scy + dy / 2;
  29004. var nx = dy * this.spacing / len;
  29005. var ny = dx * this.spacing / len;
  29006. x0 += nx * (parallels.length - 1) / 2;
  29007. y0 -= ny * (parallels.length - 1) / 2;
  29008. for (var i = 0; i < parallels.length; i++)
  29009. {
  29010. this.route(parallels[i], x0, y0);
  29011. x0 -= nx;
  29012. y0 += ny;
  29013. }
  29014. }
  29015. }
  29016. };
  29017. /**
  29018. * Function: route
  29019. *
  29020. * Routes the given edge via the given point.
  29021. */
  29022. mxParallelEdgeLayout.prototype.route = function(edge, x, y)
  29023. {
  29024. if (this.graph.isCellMovable(edge))
  29025. {
  29026. this.setEdgePoints(edge, [new mxPoint(x, y)]);
  29027. }
  29028. };
  29029. /**
  29030. * Copyright (c) 2006-2015, JGraph Ltd
  29031. * Copyright (c) 2006-2015, Gaudenz Alder
  29032. */
  29033. /**
  29034. * Class: mxCompositeLayout
  29035. *
  29036. * Allows to compose multiple layouts into a single layout. The master layout
  29037. * is the layout that handles move operations if another layout than the first
  29038. * element in <layouts> should be used. The <master> layout is not executed as
  29039. * the code assumes that it is part of <layouts>.
  29040. *
  29041. * Example:
  29042. * (code)
  29043. * var first = new mxFastOrganicLayout(graph);
  29044. * var second = new mxParallelEdgeLayout(graph);
  29045. * var layout = new mxCompositeLayout(graph, [first, second], first);
  29046. * layout.execute(graph.getDefaultParent());
  29047. * (end)
  29048. *
  29049. * Constructor: mxCompositeLayout
  29050. *
  29051. * Constructs a new layout using the given layouts. The graph instance is
  29052. * required for creating the transaction that contains all layouts.
  29053. *
  29054. * Arguments:
  29055. *
  29056. * graph - Reference to the enclosing <mxGraph>.
  29057. * layouts - Array of <mxGraphLayouts>.
  29058. * master - Optional layout that handles moves. If no layout is given then
  29059. * the first layout of the above array is used to handle moves.
  29060. */
  29061. function mxCompositeLayout(graph, layouts, master)
  29062. {
  29063. mxGraphLayout.call(this, graph);
  29064. this.layouts = layouts;
  29065. this.master = master;
  29066. };
  29067. /**
  29068. * Extends mxGraphLayout.
  29069. */
  29070. mxCompositeLayout.prototype = new mxGraphLayout();
  29071. mxCompositeLayout.prototype.constructor = mxCompositeLayout;
  29072. /**
  29073. * Variable: layouts
  29074. *
  29075. * Holds the array of <mxGraphLayouts> that this layout contains.
  29076. */
  29077. mxCompositeLayout.prototype.layouts = null;
  29078. /**
  29079. * Variable: layouts
  29080. *
  29081. * Reference to the <mxGraphLayouts> that handles moves. If this is null
  29082. * then the first layout in <layouts> is used.
  29083. */
  29084. mxCompositeLayout.prototype.master = null;
  29085. /**
  29086. * Function: moveCell
  29087. *
  29088. * Implements <mxGraphLayout.moveCell> by calling move on <master> or the first
  29089. * layout in <layouts>.
  29090. */
  29091. mxCompositeLayout.prototype.moveCell = function(cell, x, y)
  29092. {
  29093. if (this.master != null)
  29094. {
  29095. this.master.moveCell.apply(this.master, arguments);
  29096. }
  29097. else
  29098. {
  29099. this.layouts[0].moveCell.apply(this.layouts[0], arguments);
  29100. }
  29101. };
  29102. /**
  29103. * Function: execute
  29104. *
  29105. * Implements <mxGraphLayout.execute> by executing all <layouts> in a
  29106. * single transaction.
  29107. */
  29108. mxCompositeLayout.prototype.execute = function(parent)
  29109. {
  29110. var model = this.graph.getModel();
  29111. model.beginUpdate();
  29112. try
  29113. {
  29114. for (var i = 0; i < this.layouts.length; i++)
  29115. {
  29116. this.layouts[i].execute.apply(this.layouts[i], arguments);
  29117. }
  29118. }
  29119. finally
  29120. {
  29121. model.endUpdate();
  29122. }
  29123. };
  29124. /**
  29125. * Copyright (c) 2006-2015, JGraph Ltd
  29126. * Copyright (c) 2006-2015, Gaudenz Alder
  29127. */
  29128. /**
  29129. * Class: mxEdgeLabelLayout
  29130. *
  29131. * Extends <mxGraphLayout> to implement an edge label layout. This layout
  29132. * makes use of cell states, which means the graph must be validated in
  29133. * a graph view (so that the label bounds are available) before this layout
  29134. * can be executed.
  29135. *
  29136. * Example:
  29137. *
  29138. * (code)
  29139. * var layout = new mxEdgeLabelLayout(graph);
  29140. * layout.execute(graph.getDefaultParent());
  29141. * (end)
  29142. *
  29143. * Constructor: mxEdgeLabelLayout
  29144. *
  29145. * Constructs a new edge label layout.
  29146. *
  29147. * Arguments:
  29148. *
  29149. * graph - <mxGraph> that contains the cells.
  29150. */
  29151. function mxEdgeLabelLayout(graph, radius)
  29152. {
  29153. mxGraphLayout.call(this, graph);
  29154. };
  29155. /**
  29156. * Extends mxGraphLayout.
  29157. */
  29158. mxEdgeLabelLayout.prototype = new mxGraphLayout();
  29159. mxEdgeLabelLayout.prototype.constructor = mxEdgeLabelLayout;
  29160. /**
  29161. * Function: execute
  29162. *
  29163. * Implements <mxGraphLayout.execute>.
  29164. */
  29165. mxEdgeLabelLayout.prototype.execute = function(parent)
  29166. {
  29167. var view = this.graph.view;
  29168. var model = this.graph.getModel();
  29169. // Gets all vertices and edges inside the parent
  29170. var edges = [];
  29171. var vertices = [];
  29172. var childCount = model.getChildCount(parent);
  29173. for (var i = 0; i < childCount; i++)
  29174. {
  29175. var cell = model.getChildAt(parent, i);
  29176. var state = view.getState(cell);
  29177. if (state != null)
  29178. {
  29179. if (!this.isVertexIgnored(cell))
  29180. {
  29181. vertices.push(state);
  29182. }
  29183. else if (!this.isEdgeIgnored(cell))
  29184. {
  29185. edges.push(state);
  29186. }
  29187. }
  29188. }
  29189. this.placeLabels(vertices, edges);
  29190. };
  29191. /**
  29192. * Function: placeLabels
  29193. *
  29194. * Places the labels of the given edges.
  29195. */
  29196. mxEdgeLabelLayout.prototype.placeLabels = function(v, e)
  29197. {
  29198. var model = this.graph.getModel();
  29199. // Moves the vertices to build a circle. Makes sure the
  29200. // radius is large enough for the vertices to not
  29201. // overlap
  29202. model.beginUpdate();
  29203. try
  29204. {
  29205. for (var i = 0; i < e.length; i++)
  29206. {
  29207. var edge = e[i];
  29208. if (edge != null && edge.text != null &&
  29209. edge.text.boundingBox != null)
  29210. {
  29211. for (var j = 0; j < v.length; j++)
  29212. {
  29213. var vertex = v[j];
  29214. if (vertex != null)
  29215. {
  29216. this.avoid(edge, vertex);
  29217. }
  29218. }
  29219. }
  29220. }
  29221. }
  29222. finally
  29223. {
  29224. model.endUpdate();
  29225. }
  29226. };
  29227. /**
  29228. * Function: avoid
  29229. *
  29230. * Places the labels of the given edges.
  29231. */
  29232. mxEdgeLabelLayout.prototype.avoid = function(edge, vertex)
  29233. {
  29234. var model = this.graph.getModel();
  29235. var labRect = edge.text.boundingBox;
  29236. if (mxUtils.intersects(labRect, vertex))
  29237. {
  29238. var dy1 = -labRect.y - labRect.height + vertex.y;
  29239. var dy2 = -labRect.y + vertex.y + vertex.height;
  29240. var dy = (Math.abs(dy1) < Math.abs(dy2)) ? dy1 : dy2;
  29241. var dx1 = -labRect.x - labRect.width + vertex.x;
  29242. var dx2 = -labRect.x + vertex.x + vertex.width;
  29243. var dx = (Math.abs(dx1) < Math.abs(dx2)) ? dx1 : dx2;
  29244. if (Math.abs(dx) < Math.abs(dy))
  29245. {
  29246. dy = 0;
  29247. }
  29248. else
  29249. {
  29250. dx = 0;
  29251. }
  29252. var g = model.getGeometry(edge.cell);
  29253. if (g != null)
  29254. {
  29255. g = g.clone();
  29256. if (g.offset != null)
  29257. {
  29258. g.offset.x += dx;
  29259. g.offset.y += dy;
  29260. }
  29261. else
  29262. {
  29263. g.offset = new mxPoint(dx, dy);
  29264. }
  29265. model.setGeometry(edge.cell, g);
  29266. }
  29267. }
  29268. };
  29269. /**
  29270. * Copyright (c) 2006-2015, JGraph Ltd
  29271. * Copyright (c) 2006-2015, Gaudenz Alder
  29272. */
  29273. /**
  29274. * Class: mxGraphAbstractHierarchyCell
  29275. *
  29276. * An abstraction of an internal hierarchy node or edge
  29277. *
  29278. * Constructor: mxGraphAbstractHierarchyCell
  29279. *
  29280. * Constructs a new hierarchical layout algorithm.
  29281. */
  29282. function mxGraphAbstractHierarchyCell()
  29283. {
  29284. this.x = [];
  29285. this.y = [];
  29286. this.temp = [];
  29287. };
  29288. /**
  29289. * Variable: maxRank
  29290. *
  29291. * The maximum rank this cell occupies. Default is -1.
  29292. */
  29293. mxGraphAbstractHierarchyCell.prototype.maxRank = -1;
  29294. /**
  29295. * Variable: minRank
  29296. *
  29297. * The minimum rank this cell occupies. Default is -1.
  29298. */
  29299. mxGraphAbstractHierarchyCell.prototype.minRank = -1;
  29300. /**
  29301. * Variable: x
  29302. *
  29303. * The x position of this cell for each layer it occupies
  29304. */
  29305. mxGraphAbstractHierarchyCell.prototype.x = null;
  29306. /**
  29307. * Variable: y
  29308. *
  29309. * The y position of this cell for each layer it occupies
  29310. */
  29311. mxGraphAbstractHierarchyCell.prototype.y = null;
  29312. /**
  29313. * Variable: width
  29314. *
  29315. * The width of this cell. Default is 0.
  29316. */
  29317. mxGraphAbstractHierarchyCell.prototype.width = 0;
  29318. /**
  29319. * Variable: height
  29320. *
  29321. * The height of this cell. Default is 0.
  29322. */
  29323. mxGraphAbstractHierarchyCell.prototype.height = 0;
  29324. /**
  29325. * Variable: nextLayerConnectedCells
  29326. *
  29327. * A cached version of the cells this cell connects to on the next layer up
  29328. */
  29329. mxGraphAbstractHierarchyCell.prototype.nextLayerConnectedCells = null;
  29330. /**
  29331. * Variable: previousLayerConnectedCells
  29332. *
  29333. * A cached version of the cells this cell connects to on the next layer down
  29334. */
  29335. mxGraphAbstractHierarchyCell.prototype.previousLayerConnectedCells = null;
  29336. /**
  29337. * Variable: temp
  29338. *
  29339. * Temporary variable for general use. Generally, try to avoid
  29340. * carrying information between stages. Currently, the longest
  29341. * path layering sets temp to the rank position in fixRanks()
  29342. * and the crossing reduction uses this. This meant temp couldn't
  29343. * be used for hashing the nodes in the model dfs and so hashCode
  29344. * was created
  29345. */
  29346. mxGraphAbstractHierarchyCell.prototype.temp = null;
  29347. /**
  29348. * Function: getNextLayerConnectedCells
  29349. *
  29350. * Returns the cells this cell connects to on the next layer up
  29351. */
  29352. mxGraphAbstractHierarchyCell.prototype.getNextLayerConnectedCells = function(layer)
  29353. {
  29354. return null;
  29355. };
  29356. /**
  29357. * Function: getPreviousLayerConnectedCells
  29358. *
  29359. * Returns the cells this cell connects to on the next layer down
  29360. */
  29361. mxGraphAbstractHierarchyCell.prototype.getPreviousLayerConnectedCells = function(layer)
  29362. {
  29363. return null;
  29364. };
  29365. /**
  29366. * Function: isEdge
  29367. *
  29368. * Returns whether or not this cell is an edge
  29369. */
  29370. mxGraphAbstractHierarchyCell.prototype.isEdge = function()
  29371. {
  29372. return false;
  29373. };
  29374. /**
  29375. * Function: isVertex
  29376. *
  29377. * Returns whether or not this cell is a node
  29378. */
  29379. mxGraphAbstractHierarchyCell.prototype.isVertex = function()
  29380. {
  29381. return false;
  29382. };
  29383. /**
  29384. * Function: getGeneralPurposeVariable
  29385. *
  29386. * Gets the value of temp for the specified layer
  29387. */
  29388. mxGraphAbstractHierarchyCell.prototype.getGeneralPurposeVariable = function(layer)
  29389. {
  29390. return null;
  29391. };
  29392. /**
  29393. * Function: setGeneralPurposeVariable
  29394. *
  29395. * Set the value of temp for the specified layer
  29396. */
  29397. mxGraphAbstractHierarchyCell.prototype.setGeneralPurposeVariable = function(layer, value)
  29398. {
  29399. return null;
  29400. };
  29401. /**
  29402. * Function: setX
  29403. *
  29404. * Set the value of x for the specified layer
  29405. */
  29406. mxGraphAbstractHierarchyCell.prototype.setX = function(layer, value)
  29407. {
  29408. if (this.isVertex())
  29409. {
  29410. this.x[0] = value;
  29411. }
  29412. else if (this.isEdge())
  29413. {
  29414. this.x[layer - this.minRank - 1] = value;
  29415. }
  29416. };
  29417. /**
  29418. * Function: getX
  29419. *
  29420. * Gets the value of x on the specified layer
  29421. */
  29422. mxGraphAbstractHierarchyCell.prototype.getX = function(layer)
  29423. {
  29424. if (this.isVertex())
  29425. {
  29426. return this.x[0];
  29427. }
  29428. else if (this.isEdge())
  29429. {
  29430. return this.x[layer - this.minRank - 1];
  29431. }
  29432. return 0.0;
  29433. };
  29434. /**
  29435. * Function: setY
  29436. *
  29437. * Set the value of y for the specified layer
  29438. */
  29439. mxGraphAbstractHierarchyCell.prototype.setY = function(layer, value)
  29440. {
  29441. if (this.isVertex())
  29442. {
  29443. this.y[0] = value;
  29444. }
  29445. else if (this.isEdge())
  29446. {
  29447. this.y[layer -this. minRank - 1] = value;
  29448. }
  29449. };
  29450. /**
  29451. * Copyright (c) 2006-2015, JGraph Ltd
  29452. * Copyright (c) 2006-2015, Gaudenz Alder
  29453. */
  29454. /**
  29455. * Class: mxGraphHierarchyNode
  29456. *
  29457. * An abstraction of a hierarchical edge for the hierarchy layout
  29458. *
  29459. * Constructor: mxGraphHierarchyNode
  29460. *
  29461. * Constructs an internal node to represent the specified real graph cell
  29462. *
  29463. * Arguments:
  29464. *
  29465. * cell - the real graph cell this node represents
  29466. */
  29467. function mxGraphHierarchyNode(cell)
  29468. {
  29469. mxGraphAbstractHierarchyCell.apply(this, arguments);
  29470. this.cell = cell;
  29471. this.id = mxObjectIdentity.get(cell);
  29472. this.connectsAsTarget = [];
  29473. this.connectsAsSource = [];
  29474. };
  29475. /**
  29476. * Extends mxGraphAbstractHierarchyCell.
  29477. */
  29478. mxGraphHierarchyNode.prototype = new mxGraphAbstractHierarchyCell();
  29479. mxGraphHierarchyNode.prototype.constructor = mxGraphHierarchyNode;
  29480. /**
  29481. * Variable: cell
  29482. *
  29483. * The graph cell this object represents.
  29484. */
  29485. mxGraphHierarchyNode.prototype.cell = null;
  29486. /**
  29487. * Variable: id
  29488. *
  29489. * The object identity of the wrapped cell
  29490. */
  29491. mxGraphHierarchyNode.prototype.id = null;
  29492. /**
  29493. * Variable: connectsAsTarget
  29494. *
  29495. * Collection of hierarchy edges that have this node as a target
  29496. */
  29497. mxGraphHierarchyNode.prototype.connectsAsTarget = null;
  29498. /**
  29499. * Variable: connectsAsSource
  29500. *
  29501. * Collection of hierarchy edges that have this node as a source
  29502. */
  29503. mxGraphHierarchyNode.prototype.connectsAsSource = null;
  29504. /**
  29505. * Variable: hashCode
  29506. *
  29507. * Assigns a unique hashcode for each node. Used by the model dfs instead
  29508. * of copying HashSets
  29509. */
  29510. mxGraphHierarchyNode.prototype.hashCode = false;
  29511. /**
  29512. * Function: getRankValue
  29513. *
  29514. * Returns the integer value of the layer that this node resides in
  29515. */
  29516. mxGraphHierarchyNode.prototype.getRankValue = function(layer)
  29517. {
  29518. return this.maxRank;
  29519. };
  29520. /**
  29521. * Function: getNextLayerConnectedCells
  29522. *
  29523. * Returns the cells this cell connects to on the next layer up
  29524. */
  29525. mxGraphHierarchyNode.prototype.getNextLayerConnectedCells = function(layer)
  29526. {
  29527. if (this.nextLayerConnectedCells == null)
  29528. {
  29529. this.nextLayerConnectedCells = [];
  29530. this.nextLayerConnectedCells[0] = [];
  29531. for (var i = 0; i < this.connectsAsTarget.length; i++)
  29532. {
  29533. var edge = this.connectsAsTarget[i];
  29534. if (edge.maxRank == -1 || edge.maxRank == layer + 1)
  29535. {
  29536. // Either edge is not in any rank or
  29537. // no dummy nodes in edge, add node of other side of edge
  29538. this.nextLayerConnectedCells[0].push(edge.source);
  29539. }
  29540. else
  29541. {
  29542. // Edge spans at least two layers, add edge
  29543. this.nextLayerConnectedCells[0].push(edge);
  29544. }
  29545. }
  29546. }
  29547. return this.nextLayerConnectedCells[0];
  29548. };
  29549. /**
  29550. * Function: getPreviousLayerConnectedCells
  29551. *
  29552. * Returns the cells this cell connects to on the next layer down
  29553. */
  29554. mxGraphHierarchyNode.prototype.getPreviousLayerConnectedCells = function(layer)
  29555. {
  29556. if (this.previousLayerConnectedCells == null)
  29557. {
  29558. this.previousLayerConnectedCells = [];
  29559. this.previousLayerConnectedCells[0] = [];
  29560. for (var i = 0; i < this.connectsAsSource.length; i++)
  29561. {
  29562. var edge = this.connectsAsSource[i];
  29563. if (edge.minRank == -1 || edge.minRank == layer - 1)
  29564. {
  29565. // No dummy nodes in edge, add node of other side of edge
  29566. this.previousLayerConnectedCells[0].push(edge.target);
  29567. }
  29568. else
  29569. {
  29570. // Edge spans at least two layers, add edge
  29571. this.previousLayerConnectedCells[0].push(edge);
  29572. }
  29573. }
  29574. }
  29575. return this.previousLayerConnectedCells[0];
  29576. };
  29577. /**
  29578. * Function: isVertex
  29579. *
  29580. * Returns true.
  29581. */
  29582. mxGraphHierarchyNode.prototype.isVertex = function()
  29583. {
  29584. return true;
  29585. };
  29586. /**
  29587. * Function: getGeneralPurposeVariable
  29588. *
  29589. * Gets the value of temp for the specified layer
  29590. */
  29591. mxGraphHierarchyNode.prototype.getGeneralPurposeVariable = function(layer)
  29592. {
  29593. return this.temp[0];
  29594. };
  29595. /**
  29596. * Function: setGeneralPurposeVariable
  29597. *
  29598. * Set the value of temp for the specified layer
  29599. */
  29600. mxGraphHierarchyNode.prototype.setGeneralPurposeVariable = function(layer, value)
  29601. {
  29602. this.temp[0] = value;
  29603. };
  29604. /**
  29605. * Function: isAncestor
  29606. */
  29607. mxGraphHierarchyNode.prototype.isAncestor = function(otherNode)
  29608. {
  29609. // Firstly, the hash code of this node needs to be shorter than the
  29610. // other node
  29611. if (otherNode != null && this.hashCode != null && otherNode.hashCode != null
  29612. && this.hashCode.length < otherNode.hashCode.length)
  29613. {
  29614. if (this.hashCode == otherNode.hashCode)
  29615. {
  29616. return true;
  29617. }
  29618. if (this.hashCode == null || this.hashCode == null)
  29619. {
  29620. return false;
  29621. }
  29622. // Secondly, this hash code must match the start of the other
  29623. // node's hash code. Arrays.equals cannot be used here since
  29624. // the arrays are different length, and we do not want to
  29625. // perform another array copy.
  29626. for (var i = 0; i < this.hashCode.length; i++)
  29627. {
  29628. if (this.hashCode[i] != otherNode.hashCode[i])
  29629. {
  29630. return false;
  29631. }
  29632. }
  29633. return true;
  29634. }
  29635. return false;
  29636. };
  29637. /**
  29638. * Function: getCoreCell
  29639. *
  29640. * Gets the core vertex associated with this wrapper
  29641. */
  29642. mxGraphHierarchyNode.prototype.getCoreCell = function()
  29643. {
  29644. return this.cell;
  29645. };
  29646. /**
  29647. * Copyright (c) 2006-2015, JGraph Ltd
  29648. * Copyright (c) 2006-2015, Gaudenz Alder
  29649. */
  29650. /**
  29651. * Class: mxGraphHierarchyEdge
  29652. *
  29653. * An abstraction of a hierarchical edge for the hierarchy layout
  29654. *
  29655. * Constructor: mxGraphHierarchyEdge
  29656. *
  29657. * Constructs a hierarchy edge
  29658. *
  29659. * Arguments:
  29660. *
  29661. * edges - a list of real graph edges this abstraction represents
  29662. */
  29663. function mxGraphHierarchyEdge(edges)
  29664. {
  29665. mxGraphAbstractHierarchyCell.apply(this, arguments);
  29666. this.edges = edges;
  29667. this.ids = [];
  29668. for (var i = 0; i < edges.length; i++)
  29669. {
  29670. this.ids.push(mxObjectIdentity.get(edges[i]));
  29671. }
  29672. };
  29673. /**
  29674. * Extends mxGraphAbstractHierarchyCell.
  29675. */
  29676. mxGraphHierarchyEdge.prototype = new mxGraphAbstractHierarchyCell();
  29677. mxGraphHierarchyEdge.prototype.constructor = mxGraphHierarchyEdge;
  29678. /**
  29679. * Variable: edges
  29680. *
  29681. * The graph edge(s) this object represents. Parallel edges are all grouped
  29682. * together within one hierarchy edge.
  29683. */
  29684. mxGraphHierarchyEdge.prototype.edges = null;
  29685. /**
  29686. * Variable: ids
  29687. *
  29688. * The object identities of the wrapped cells
  29689. */
  29690. mxGraphHierarchyEdge.prototype.ids = null;
  29691. /**
  29692. * Variable: source
  29693. *
  29694. * The node this edge is sourced at
  29695. */
  29696. mxGraphHierarchyEdge.prototype.source = null;
  29697. /**
  29698. * Variable: target
  29699. *
  29700. * The node this edge targets
  29701. */
  29702. mxGraphHierarchyEdge.prototype.target = null;
  29703. /**
  29704. * Variable: isReversed
  29705. *
  29706. * Whether or not the direction of this edge has been reversed
  29707. * internally to create a DAG for the hierarchical layout
  29708. */
  29709. mxGraphHierarchyEdge.prototype.isReversed = false;
  29710. /**
  29711. * Function: invert
  29712. *
  29713. * Inverts the direction of this internal edge(s)
  29714. */
  29715. mxGraphHierarchyEdge.prototype.invert = function(layer)
  29716. {
  29717. var temp = this.source;
  29718. this.source = this.target;
  29719. this.target = temp;
  29720. this.isReversed = !this.isReversed;
  29721. };
  29722. /**
  29723. * Function: getNextLayerConnectedCells
  29724. *
  29725. * Returns the cells this cell connects to on the next layer up
  29726. */
  29727. mxGraphHierarchyEdge.prototype.getNextLayerConnectedCells = function(layer)
  29728. {
  29729. if (this.nextLayerConnectedCells == null)
  29730. {
  29731. this.nextLayerConnectedCells = [];
  29732. for (var i = 0; i < this.temp.length; i++)
  29733. {
  29734. this.nextLayerConnectedCells[i] = [];
  29735. if (i == this.temp.length - 1)
  29736. {
  29737. this.nextLayerConnectedCells[i].push(this.source);
  29738. }
  29739. else
  29740. {
  29741. this.nextLayerConnectedCells[i].push(this);
  29742. }
  29743. }
  29744. }
  29745. return this.nextLayerConnectedCells[layer - this.minRank - 1];
  29746. };
  29747. /**
  29748. * Function: getPreviousLayerConnectedCells
  29749. *
  29750. * Returns the cells this cell connects to on the next layer down
  29751. */
  29752. mxGraphHierarchyEdge.prototype.getPreviousLayerConnectedCells = function(layer)
  29753. {
  29754. if (this.previousLayerConnectedCells == null)
  29755. {
  29756. this.previousLayerConnectedCells = [];
  29757. for (var i = 0; i < this.temp.length; i++)
  29758. {
  29759. this.previousLayerConnectedCells[i] = [];
  29760. if (i == 0)
  29761. {
  29762. this.previousLayerConnectedCells[i].push(this.target);
  29763. }
  29764. else
  29765. {
  29766. this.previousLayerConnectedCells[i].push(this);
  29767. }
  29768. }
  29769. }
  29770. return this.previousLayerConnectedCells[layer - this.minRank - 1];
  29771. };
  29772. /**
  29773. * Function: isEdge
  29774. *
  29775. * Returns true.
  29776. */
  29777. mxGraphHierarchyEdge.prototype.isEdge = function()
  29778. {
  29779. return true;
  29780. };
  29781. /**
  29782. * Function: getGeneralPurposeVariable
  29783. *
  29784. * Gets the value of temp for the specified layer
  29785. */
  29786. mxGraphHierarchyEdge.prototype.getGeneralPurposeVariable = function(layer)
  29787. {
  29788. return this.temp[layer - this.minRank - 1];
  29789. };
  29790. /**
  29791. * Function: setGeneralPurposeVariable
  29792. *
  29793. * Set the value of temp for the specified layer
  29794. */
  29795. mxGraphHierarchyEdge.prototype.setGeneralPurposeVariable = function(layer, value)
  29796. {
  29797. this.temp[layer - this.minRank - 1] = value;
  29798. };
  29799. /**
  29800. * Function: getCoreCell
  29801. *
  29802. * Gets the first core edge associated with this wrapper
  29803. */
  29804. mxGraphHierarchyEdge.prototype.getCoreCell = function()
  29805. {
  29806. if (this.edges != null && this.edges.length > 0)
  29807. {
  29808. return this.edges[0];
  29809. }
  29810. return null;
  29811. };
  29812. /**
  29813. * Copyright (c) 2006-2015, JGraph Ltd
  29814. * Copyright (c) 2006-2015, Gaudenz Alder
  29815. */
  29816. /**
  29817. * Class: mxGraphHierarchyModel
  29818. *
  29819. * Internal model of a hierarchical graph. This model stores nodes and edges
  29820. * equivalent to the real graph nodes and edges, but also stores the rank of the
  29821. * cells, the order within the ranks and the new candidate locations of cells.
  29822. * The internal model also reverses edge direction were appropriate , ignores
  29823. * self-loop and groups parallels together under one edge object.
  29824. *
  29825. * Constructor: mxGraphHierarchyModel
  29826. *
  29827. * Creates an internal ordered graph model using the vertices passed in. If
  29828. * there are any, leftward edge need to be inverted in the internal model
  29829. *
  29830. * Arguments:
  29831. *
  29832. * graph - the facade describing the graph to be operated on
  29833. * vertices - the vertices for this hierarchy
  29834. * ordered - whether or not the vertices are already ordered
  29835. * deterministic - whether or not this layout should be deterministic on each
  29836. * tightenToSource - whether or not to tighten vertices towards the sources
  29837. * scanRanksFromSinks - Whether rank assignment is from the sinks or sources.
  29838. * usage
  29839. */
  29840. function mxGraphHierarchyModel(layout, vertices, roots, parent, tightenToSource)
  29841. {
  29842. var graph = layout.getGraph();
  29843. this.tightenToSource = tightenToSource;
  29844. this.roots = roots;
  29845. this.parent = parent;
  29846. // map of cells to internal cell needed for second run through
  29847. // to setup the sink of edges correctly
  29848. this.vertexMapper = new mxDictionary();
  29849. this.edgeMapper = new mxDictionary();
  29850. this.maxRank = 0;
  29851. var internalVertices = [];
  29852. if (vertices == null)
  29853. {
  29854. vertices = this.graph.getChildVertices(parent);
  29855. }
  29856. this.maxRank = this.SOURCESCANSTARTRANK;
  29857. // map of cells to internal cell needed for second run through
  29858. // to setup the sink of edges correctly. Guess size by number
  29859. // of edges is roughly same as number of vertices.
  29860. this.createInternalCells(layout, vertices, internalVertices);
  29861. // Go through edges set their sink values. Also check the
  29862. // ordering if and invert edges if necessary
  29863. for (var i = 0; i < vertices.length; i++)
  29864. {
  29865. var edges = internalVertices[i].connectsAsSource;
  29866. for (var j = 0; j < edges.length; j++)
  29867. {
  29868. var internalEdge = edges[j];
  29869. var realEdges = internalEdge.edges;
  29870. // Only need to process the first real edge, since
  29871. // all the edges connect to the same other vertex
  29872. if (realEdges != null && realEdges.length > 0)
  29873. {
  29874. var realEdge = realEdges[0];
  29875. var targetCell = layout.getVisibleTerminal(
  29876. realEdge, false);
  29877. var internalTargetCell = this.vertexMapper.get(targetCell);
  29878. if (internalVertices[i] == internalTargetCell)
  29879. {
  29880. // If there are parallel edges going between two vertices and not all are in the same direction
  29881. // you can have navigated across one direction when doing the cycle reversal that isn't the same
  29882. // direction as the first real edge in the array above. When that happens the if above catches
  29883. // that and we correct the target cell before continuing.
  29884. // This branch only detects this single case
  29885. targetCell = layout.getVisibleTerminal(
  29886. realEdge, true);
  29887. internalTargetCell = this.vertexMapper.get(targetCell);
  29888. }
  29889. if (internalTargetCell != null
  29890. && internalVertices[i] != internalTargetCell)
  29891. {
  29892. internalEdge.target = internalTargetCell;
  29893. if (internalTargetCell.connectsAsTarget.length == 0)
  29894. {
  29895. internalTargetCell.connectsAsTarget = [];
  29896. }
  29897. if (mxUtils.indexOf(internalTargetCell.connectsAsTarget, internalEdge) < 0)
  29898. {
  29899. internalTargetCell.connectsAsTarget.push(internalEdge);
  29900. }
  29901. }
  29902. }
  29903. }
  29904. // Use the temp variable in the internal nodes to mark this
  29905. // internal vertex as having been visited.
  29906. internalVertices[i].temp[0] = 1;
  29907. }
  29908. };
  29909. /**
  29910. * Variable: maxRank
  29911. *
  29912. * Stores the largest rank number allocated
  29913. */
  29914. mxGraphHierarchyModel.prototype.maxRank = null;
  29915. /**
  29916. * Variable: vertexMapper
  29917. *
  29918. * Map from graph vertices to internal model nodes.
  29919. */
  29920. mxGraphHierarchyModel.prototype.vertexMapper = null;
  29921. /**
  29922. * Variable: edgeMapper
  29923. *
  29924. * Map from graph edges to internal model edges
  29925. */
  29926. mxGraphHierarchyModel.prototype.edgeMapper = null;
  29927. /**
  29928. * Variable: ranks
  29929. *
  29930. * Mapping from rank number to actual rank
  29931. */
  29932. mxGraphHierarchyModel.prototype.ranks = null;
  29933. /**
  29934. * Variable: roots
  29935. *
  29936. * Store of roots of this hierarchy model, these are real graph cells, not
  29937. * internal cells
  29938. */
  29939. mxGraphHierarchyModel.prototype.roots = null;
  29940. /**
  29941. * Variable: parent
  29942. *
  29943. * The parent cell whose children are being laid out
  29944. */
  29945. mxGraphHierarchyModel.prototype.parent = null;
  29946. /**
  29947. * Variable: dfsCount
  29948. *
  29949. * Count of the number of times the ancestor dfs has been used.
  29950. */
  29951. mxGraphHierarchyModel.prototype.dfsCount = 0;
  29952. /**
  29953. * Variable: SOURCESCANSTARTRANK
  29954. *
  29955. * High value to start source layering scan rank value from.
  29956. */
  29957. mxGraphHierarchyModel.prototype.SOURCESCANSTARTRANK = 100000000;
  29958. /**
  29959. * Variable: tightenToSource
  29960. *
  29961. * Whether or not to tighten the assigned ranks of vertices up towards
  29962. * the source cells.
  29963. */
  29964. mxGraphHierarchyModel.prototype.tightenToSource = false;
  29965. /**
  29966. * Function: createInternalCells
  29967. *
  29968. * Creates all edges in the internal model
  29969. *
  29970. * Parameters:
  29971. *
  29972. * layout - Reference to the <mxHierarchicalLayout> algorithm.
  29973. * vertices - Array of <mxCells> that represent the vertices whom are to
  29974. * have an internal representation created.
  29975. * internalVertices - The array of <mxGraphHierarchyNodes> to have their
  29976. * information filled in using the real vertices.
  29977. */
  29978. mxGraphHierarchyModel.prototype.createInternalCells = function(layout, vertices, internalVertices)
  29979. {
  29980. var graph = layout.getGraph();
  29981. // Create internal edges
  29982. for (var i = 0; i < vertices.length; i++)
  29983. {
  29984. internalVertices[i] = new mxGraphHierarchyNode(vertices[i]);
  29985. this.vertexMapper.put(vertices[i], internalVertices[i]);
  29986. // If the layout is deterministic, order the cells
  29987. //List outgoingCells = graph.getNeighbours(vertices[i], deterministic);
  29988. var conns = layout.getEdges(vertices[i]);
  29989. internalVertices[i].connectsAsSource = [];
  29990. // Create internal edges, but don't do any rank assignment yet
  29991. // First use the information from the greedy cycle remover to
  29992. // invert the leftward edges internally
  29993. for (var j = 0; j < conns.length; j++)
  29994. {
  29995. var cell = layout.getVisibleTerminal(conns[j], false);
  29996. // Looking for outgoing edges only
  29997. if (cell != vertices[i] && layout.graph.model.isVertex(cell) &&
  29998. !layout.isVertexIgnored(cell))
  29999. {
  30000. // We process all edge between this source and its targets
  30001. // If there are edges going both ways, we need to collect
  30002. // them all into one internal edges to avoid looping problems
  30003. // later. We assume this direction (source -> target) is the
  30004. // natural direction if at least half the edges are going in
  30005. // that direction.
  30006. // The check below for edges[0] being in the vertex mapper is
  30007. // in case we've processed this the other way around
  30008. // (target -> source) and the number of edges in each direction
  30009. // are the same. All the graph edges will have been assigned to
  30010. // an internal edge going the other way, so we don't want to
  30011. // process them again
  30012. var undirectedEdges = layout.getEdgesBetween(vertices[i],
  30013. cell, false);
  30014. var directedEdges = layout.getEdgesBetween(vertices[i],
  30015. cell, true);
  30016. if (undirectedEdges != null &&
  30017. undirectedEdges.length > 0 &&
  30018. this.edgeMapper.get(undirectedEdges[0]) == null &&
  30019. directedEdges.length * 2 >= undirectedEdges.length)
  30020. {
  30021. var internalEdge = new mxGraphHierarchyEdge(undirectedEdges);
  30022. for (var k = 0; k < undirectedEdges.length; k++)
  30023. {
  30024. var edge = undirectedEdges[k];
  30025. this.edgeMapper.put(edge, internalEdge);
  30026. // Resets all point on the edge and disables the edge style
  30027. // without deleting it from the cell style
  30028. graph.resetEdge(edge);
  30029. if (layout.disableEdgeStyle)
  30030. {
  30031. layout.setEdgeStyleEnabled(edge, false);
  30032. layout.setOrthogonalEdge(edge,true);
  30033. }
  30034. }
  30035. internalEdge.source = internalVertices[i];
  30036. if (mxUtils.indexOf(internalVertices[i].connectsAsSource, internalEdge) < 0)
  30037. {
  30038. internalVertices[i].connectsAsSource.push(internalEdge);
  30039. }
  30040. }
  30041. }
  30042. }
  30043. // Ensure temp variable is cleared from any previous use
  30044. internalVertices[i].temp[0] = 0;
  30045. }
  30046. };
  30047. /**
  30048. * Function: initialRank
  30049. *
  30050. * Basic determination of minimum layer ranking by working from from sources
  30051. * or sinks and working through each node in the relevant edge direction.
  30052. * Starting at the sinks is basically a longest path layering algorithm.
  30053. */
  30054. mxGraphHierarchyModel.prototype.initialRank = function()
  30055. {
  30056. var startNodes = [];
  30057. if (this.roots != null)
  30058. {
  30059. for (var i = 0; i < this.roots.length; i++)
  30060. {
  30061. var internalNode = this.vertexMapper.get(this.roots[i]);
  30062. if (internalNode != null)
  30063. {
  30064. startNodes.push(internalNode);
  30065. }
  30066. }
  30067. }
  30068. var internalNodes = this.vertexMapper.getValues();
  30069. for (var i=0; i < internalNodes.length; i++)
  30070. {
  30071. // Mark the node as not having had a layer assigned
  30072. internalNodes[i].temp[0] = -1;
  30073. }
  30074. var startNodesCopy = startNodes.slice();
  30075. while (startNodes.length > 0)
  30076. {
  30077. var internalNode = startNodes[0];
  30078. var layerDeterminingEdges;
  30079. var edgesToBeMarked;
  30080. layerDeterminingEdges = internalNode.connectsAsTarget;
  30081. edgesToBeMarked = internalNode.connectsAsSource;
  30082. // flag to keep track of whether or not all layer determining
  30083. // edges have been scanned
  30084. var allEdgesScanned = true;
  30085. // Work out the layer of this node from the layer determining
  30086. // edges. The minimum layer number of any node connected by one of
  30087. // the layer determining edges variable
  30088. var minimumLayer = this.SOURCESCANSTARTRANK;
  30089. for (var i = 0; i < layerDeterminingEdges.length; i++)
  30090. {
  30091. var internalEdge = layerDeterminingEdges[i];
  30092. if (internalEdge.temp[0] == 5270620)
  30093. {
  30094. // This edge has been scanned, get the layer of the
  30095. // node on the other end
  30096. var otherNode = internalEdge.source;
  30097. minimumLayer = Math.min(minimumLayer, otherNode.temp[0] - 1);
  30098. }
  30099. else
  30100. {
  30101. allEdgesScanned = false;
  30102. break;
  30103. }
  30104. }
  30105. // If all edge have been scanned, assign the layer, mark all
  30106. // edges in the other direction and remove from the nodes list
  30107. if (allEdgesScanned)
  30108. {
  30109. internalNode.temp[0] = minimumLayer;
  30110. this.maxRank = Math.min(this.maxRank, minimumLayer);
  30111. if (edgesToBeMarked != null)
  30112. {
  30113. for (var i = 0; i < edgesToBeMarked.length; i++)
  30114. {
  30115. var internalEdge = edgesToBeMarked[i];
  30116. // Assign unique stamp ( y/m/d/h )
  30117. internalEdge.temp[0] = 5270620;
  30118. // Add node on other end of edge to LinkedList of
  30119. // nodes to be analysed
  30120. var otherNode = internalEdge.target;
  30121. // Only add node if it hasn't been assigned a layer
  30122. if (otherNode.temp[0] == -1)
  30123. {
  30124. startNodes.push(otherNode);
  30125. // Mark this other node as neither being
  30126. // unassigned nor assigned so it isn't
  30127. // added to this list again, but it's
  30128. // layer isn't used in any calculation.
  30129. otherNode.temp[0] = -2;
  30130. }
  30131. }
  30132. }
  30133. startNodes.shift();
  30134. }
  30135. else
  30136. {
  30137. // Not all the edges have been scanned, get to the back of
  30138. // the class and put the dunces cap on
  30139. var removedCell = startNodes.shift();
  30140. startNodes.push(internalNode);
  30141. if (removedCell == internalNode && startNodes.length == 1)
  30142. {
  30143. // This is an error condition, we can't get out of
  30144. // this loop. It could happen for more than one node
  30145. // but that's a lot harder to detect. Log the error
  30146. // TODO make log comment
  30147. break;
  30148. }
  30149. }
  30150. }
  30151. // Normalize the ranks down from their large starting value to place
  30152. // at least 1 sink on layer 0
  30153. for (var i=0; i < internalNodes.length; i++)
  30154. {
  30155. // Mark the node as not having had a layer assigned
  30156. internalNodes[i].temp[0] -= this.maxRank;
  30157. }
  30158. // Tighten the rank 0 nodes as far as possible
  30159. for ( var i = 0; i < startNodesCopy.length; i++)
  30160. {
  30161. var internalNode = startNodesCopy[i];
  30162. var currentMaxLayer = 0;
  30163. var layerDeterminingEdges = internalNode.connectsAsSource;
  30164. for ( var j = 0; j < layerDeterminingEdges.length; j++)
  30165. {
  30166. var internalEdge = layerDeterminingEdges[j];
  30167. var otherNode = internalEdge.target;
  30168. internalNode.temp[0] = Math.max(currentMaxLayer,
  30169. otherNode.temp[0] + 1);
  30170. currentMaxLayer = internalNode.temp[0];
  30171. }
  30172. }
  30173. // Reset the maxRank to that which would be expected for a from-sink
  30174. // scan
  30175. this.maxRank = this.SOURCESCANSTARTRANK - this.maxRank;
  30176. };
  30177. /**
  30178. * Function: fixRanks
  30179. *
  30180. * Fixes the layer assignments to the values stored in the nodes. Also needs
  30181. * to create dummy nodes for edges that cross layers.
  30182. */
  30183. mxGraphHierarchyModel.prototype.fixRanks = function()
  30184. {
  30185. var rankList = [];
  30186. this.ranks = [];
  30187. for (var i = 0; i < this.maxRank + 1; i++)
  30188. {
  30189. rankList[i] = [];
  30190. this.ranks[i] = rankList[i];
  30191. }
  30192. // Perform a DFS to obtain an initial ordering for each rank.
  30193. // Without doing this you would end up having to process
  30194. // crossings for a standard tree.
  30195. var rootsArray = null;
  30196. if (this.roots != null)
  30197. {
  30198. var oldRootsArray = this.roots;
  30199. rootsArray = [];
  30200. for (var i = 0; i < oldRootsArray.length; i++)
  30201. {
  30202. var cell = oldRootsArray[i];
  30203. var internalNode = this.vertexMapper.get(cell);
  30204. rootsArray[i] = internalNode;
  30205. }
  30206. }
  30207. this.visit(function(parent, node, edge, layer, seen)
  30208. {
  30209. if (seen == 0 && node.maxRank < 0 && node.minRank < 0)
  30210. {
  30211. rankList[node.temp[0]].push(node);
  30212. node.maxRank = node.temp[0];
  30213. node.minRank = node.temp[0];
  30214. // Set temp[0] to the nodes position in the rank
  30215. node.temp[0] = rankList[node.maxRank].length - 1;
  30216. }
  30217. if (parent != null && edge != null)
  30218. {
  30219. var parentToCellRankDifference = parent.maxRank - node.maxRank;
  30220. if (parentToCellRankDifference > 1)
  30221. {
  30222. // There are ranks in between the parent and current cell
  30223. edge.maxRank = parent.maxRank;
  30224. edge.minRank = node.maxRank;
  30225. edge.temp = [];
  30226. edge.x = [];
  30227. edge.y = [];
  30228. for (var i = edge.minRank + 1; i < edge.maxRank; i++)
  30229. {
  30230. // The connecting edge must be added to the
  30231. // appropriate ranks
  30232. rankList[i].push(edge);
  30233. edge.setGeneralPurposeVariable(i, rankList[i]
  30234. .length - 1);
  30235. }
  30236. }
  30237. }
  30238. }, rootsArray, false, null);
  30239. };
  30240. /**
  30241. * Function: visit
  30242. *
  30243. * A depth first search through the internal heirarchy model.
  30244. *
  30245. * Parameters:
  30246. *
  30247. * visitor - The visitor function pattern to be called for each node.
  30248. * trackAncestors - Whether or not the search is to keep track all nodes
  30249. * directly above this one in the search path.
  30250. */
  30251. mxGraphHierarchyModel.prototype.visit = function(visitor, dfsRoots, trackAncestors, seenNodes)
  30252. {
  30253. // Run dfs through on all roots
  30254. if (dfsRoots != null)
  30255. {
  30256. for (var i = 0; i < dfsRoots.length; i++)
  30257. {
  30258. var internalNode = dfsRoots[i];
  30259. if (internalNode != null)
  30260. {
  30261. if (seenNodes == null)
  30262. {
  30263. seenNodes = new Object();
  30264. }
  30265. if (trackAncestors)
  30266. {
  30267. // Set up hash code for root
  30268. internalNode.hashCode = [];
  30269. internalNode.hashCode[0] = this.dfsCount;
  30270. internalNode.hashCode[1] = i;
  30271. this.extendedDfs(null, internalNode, null, visitor, seenNodes,
  30272. internalNode.hashCode, i, 0);
  30273. }
  30274. else
  30275. {
  30276. this.dfs(null, internalNode, null, visitor, seenNodes, 0);
  30277. }
  30278. }
  30279. }
  30280. this.dfsCount++;
  30281. }
  30282. };
  30283. /**
  30284. * Function: dfs
  30285. *
  30286. * Performs a depth first search on the internal hierarchy model
  30287. *
  30288. * Parameters:
  30289. *
  30290. * parent - the parent internal node of the current internal node
  30291. * root - the current internal node
  30292. * connectingEdge - the internal edge connecting the internal node and the parent
  30293. * internal node, if any
  30294. * visitor - the visitor pattern to be called for each node
  30295. * seen - a set of all nodes seen by this dfs a set of all of the
  30296. * ancestor node of the current node
  30297. * layer - the layer on the dfs tree ( not the same as the model ranks )
  30298. */
  30299. mxGraphHierarchyModel.prototype.dfs = function(parent, root, connectingEdge, visitor, seen, layer)
  30300. {
  30301. if (root != null)
  30302. {
  30303. var rootId = root.id;
  30304. if (seen[rootId] == null)
  30305. {
  30306. seen[rootId] = root;
  30307. visitor(parent, root, connectingEdge, layer, 0);
  30308. // Copy the connects as source list so that visitors
  30309. // can change the original for edge direction inversions
  30310. var outgoingEdges = root.connectsAsSource.slice();
  30311. for (var i = 0; i< outgoingEdges.length; i++)
  30312. {
  30313. var internalEdge = outgoingEdges[i];
  30314. var targetNode = internalEdge.target;
  30315. // Root check is O(|roots|)
  30316. this.dfs(root, targetNode, internalEdge, visitor, seen,
  30317. layer + 1);
  30318. }
  30319. }
  30320. else
  30321. {
  30322. // Use the int field to indicate this node has been seen
  30323. visitor(parent, root, connectingEdge, layer, 1);
  30324. }
  30325. }
  30326. };
  30327. /**
  30328. * Function: extendedDfs
  30329. *
  30330. * Performs a depth first search on the internal hierarchy model. This dfs
  30331. * extends the default version by keeping track of cells ancestors, but it
  30332. * should be only used when necessary because of it can be computationally
  30333. * intensive for deep searches.
  30334. *
  30335. * Parameters:
  30336. *
  30337. * parent - the parent internal node of the current internal node
  30338. * root - the current internal node
  30339. * connectingEdge - the internal edge connecting the internal node and the parent
  30340. * internal node, if any
  30341. * visitor - the visitor pattern to be called for each node
  30342. * seen - a set of all nodes seen by this dfs
  30343. * ancestors - the parent hash code
  30344. * childHash - the new hash code for this node
  30345. * layer - the layer on the dfs tree ( not the same as the model ranks )
  30346. */
  30347. mxGraphHierarchyModel.prototype.extendedDfs = function(parent, root, connectingEdge, visitor, seen, ancestors, childHash, layer)
  30348. {
  30349. // Explanation of custom hash set. Previously, the ancestors variable
  30350. // was passed through the dfs as a HashSet. The ancestors were copied
  30351. // into a new HashSet and when the new child was processed it was also
  30352. // added to the set. If the current node was in its ancestor list it
  30353. // meant there is a cycle in the graph and this information is passed
  30354. // to the visitor.visit() in the seen parameter. The HashSet clone was
  30355. // very expensive on CPU so a custom hash was developed using primitive
  30356. // types. temp[] couldn't be used so hashCode[] was added to each node.
  30357. // Each new child adds another int to the array, copying the prefix
  30358. // from its parent. Child of the same parent add different ints (the
  30359. // limit is therefore 2^32 children per parent...). If a node has a
  30360. // child with the hashCode already set then the child code is compared
  30361. // to the same portion of the current nodes array. If they match there
  30362. // is a loop.
  30363. // Note that the basic mechanism would only allow for 1 use of this
  30364. // functionality, so the root nodes have two ints. The second int is
  30365. // incremented through each node root and the first is incremented
  30366. // through each run of the dfs algorithm (therefore the dfs is not
  30367. // thread safe). The hash code of each node is set if not already set,
  30368. // or if the first int does not match that of the current run.
  30369. if (root != null)
  30370. {
  30371. if (parent != null)
  30372. {
  30373. // Form this nodes hash code if necessary, that is, if the
  30374. // hashCode variable has not been initialized or if the
  30375. // start of the parent hash code does not equal the start of
  30376. // this nodes hash code, indicating the code was set on a
  30377. // previous run of this dfs.
  30378. if (root.hashCode == null ||
  30379. root.hashCode[0] != parent.hashCode[0])
  30380. {
  30381. var hashCodeLength = parent.hashCode.length + 1;
  30382. root.hashCode = parent.hashCode.slice();
  30383. root.hashCode[hashCodeLength - 1] = childHash;
  30384. }
  30385. }
  30386. var rootId = root.id;
  30387. if (seen[rootId] == null)
  30388. {
  30389. seen[rootId] = root;
  30390. visitor(parent, root, connectingEdge, layer, 0);
  30391. // Copy the connects as source list so that visitors
  30392. // can change the original for edge direction inversions
  30393. var outgoingEdges = root.connectsAsSource.slice();
  30394. for (var i = 0; i < outgoingEdges.length; i++)
  30395. {
  30396. var internalEdge = outgoingEdges[i];
  30397. var targetNode = internalEdge.target;
  30398. // Root check is O(|roots|)
  30399. this.extendedDfs(root, targetNode, internalEdge, visitor, seen,
  30400. root.hashCode, i, layer + 1);
  30401. }
  30402. }
  30403. else
  30404. {
  30405. // Use the int field to indicate this node has been seen
  30406. visitor(parent, root, connectingEdge, layer, 1);
  30407. }
  30408. }
  30409. };
  30410. /**
  30411. * Copyright (c) 2006-2018, JGraph Ltd
  30412. * Copyright (c) 2006-2018, Gaudenz Alder
  30413. */
  30414. /**
  30415. * Class: mxSwimlaneModel
  30416. *
  30417. * Internal model of a hierarchical graph. This model stores nodes and edges
  30418. * equivalent to the real graph nodes and edges, but also stores the rank of the
  30419. * cells, the order within the ranks and the new candidate locations of cells.
  30420. * The internal model also reverses edge direction were appropriate , ignores
  30421. * self-loop and groups parallels together under one edge object.
  30422. *
  30423. * Constructor: mxSwimlaneModel
  30424. *
  30425. * Creates an internal ordered graph model using the vertices passed in. If
  30426. * there are any, leftward edge need to be inverted in the internal model
  30427. *
  30428. * Arguments:
  30429. *
  30430. * graph - the facade describing the graph to be operated on
  30431. * vertices - the vertices for this hierarchy
  30432. * ordered - whether or not the vertices are already ordered
  30433. * deterministic - whether or not this layout should be deterministic on each
  30434. * tightenToSource - whether or not to tighten vertices towards the sources
  30435. * scanRanksFromSinks - Whether rank assignment is from the sinks or sources.
  30436. * usage
  30437. */
  30438. function mxSwimlaneModel(layout, vertices, roots, parent, tightenToSource)
  30439. {
  30440. var graph = layout.getGraph();
  30441. this.tightenToSource = tightenToSource;
  30442. this.roots = roots;
  30443. this.parent = parent;
  30444. // map of cells to internal cell needed for second run through
  30445. // to setup the sink of edges correctly
  30446. this.vertexMapper = new mxDictionary();
  30447. this.edgeMapper = new mxDictionary();
  30448. this.maxRank = 0;
  30449. var internalVertices = [];
  30450. if (vertices == null)
  30451. {
  30452. vertices = this.graph.getChildVertices(parent);
  30453. }
  30454. this.maxRank = this.SOURCESCANSTARTRANK;
  30455. // map of cells to internal cell needed for second run through
  30456. // to setup the sink of edges correctly. Guess size by number
  30457. // of edges is roughly same as number of vertices.
  30458. this.createInternalCells(layout, vertices, internalVertices);
  30459. // Go through edges set their sink values. Also check the
  30460. // ordering if and invert edges if necessary
  30461. for (var i = 0; i < vertices.length; i++)
  30462. {
  30463. var edges = internalVertices[i].connectsAsSource;
  30464. for (var j = 0; j < edges.length; j++)
  30465. {
  30466. var internalEdge = edges[j];
  30467. var realEdges = internalEdge.edges;
  30468. // Only need to process the first real edge, since
  30469. // all the edges connect to the same other vertex
  30470. if (realEdges != null && realEdges.length > 0)
  30471. {
  30472. var realEdge = realEdges[0];
  30473. var targetCell = layout.getVisibleTerminal(
  30474. realEdge, false);
  30475. var internalTargetCell = this.vertexMapper.get(targetCell);
  30476. if (internalVertices[i] == internalTargetCell)
  30477. {
  30478. // If there are parallel edges going between two vertices and not all are in the same direction
  30479. // you can have navigated across one direction when doing the cycle reversal that isn't the same
  30480. // direction as the first real edge in the array above. When that happens the if above catches
  30481. // that and we correct the target cell before continuing.
  30482. // This branch only detects this single case
  30483. targetCell = layout.getVisibleTerminal(
  30484. realEdge, true);
  30485. internalTargetCell = this.vertexMapper.get(targetCell);
  30486. }
  30487. if (internalTargetCell != null
  30488. && internalVertices[i] != internalTargetCell)
  30489. {
  30490. internalEdge.target = internalTargetCell;
  30491. if (internalTargetCell.connectsAsTarget.length == 0)
  30492. {
  30493. internalTargetCell.connectsAsTarget = [];
  30494. }
  30495. if (mxUtils.indexOf(internalTargetCell.connectsAsTarget, internalEdge) < 0)
  30496. {
  30497. internalTargetCell.connectsAsTarget.push(internalEdge);
  30498. }
  30499. }
  30500. }
  30501. }
  30502. // Use the temp variable in the internal nodes to mark this
  30503. // internal vertex as having been visited.
  30504. internalVertices[i].temp[0] = 1;
  30505. }
  30506. };
  30507. /**
  30508. * Variable: maxRank
  30509. *
  30510. * Stores the largest rank number allocated
  30511. */
  30512. mxSwimlaneModel.prototype.maxRank = null;
  30513. /**
  30514. * Variable: vertexMapper
  30515. *
  30516. * Map from graph vertices to internal model nodes.
  30517. */
  30518. mxSwimlaneModel.prototype.vertexMapper = null;
  30519. /**
  30520. * Variable: edgeMapper
  30521. *
  30522. * Map from graph edges to internal model edges
  30523. */
  30524. mxSwimlaneModel.prototype.edgeMapper = null;
  30525. /**
  30526. * Variable: ranks
  30527. *
  30528. * Mapping from rank number to actual rank
  30529. */
  30530. mxSwimlaneModel.prototype.ranks = null;
  30531. /**
  30532. * Variable: roots
  30533. *
  30534. * Store of roots of this hierarchy model, these are real graph cells, not
  30535. * internal cells
  30536. */
  30537. mxSwimlaneModel.prototype.roots = null;
  30538. /**
  30539. * Variable: parent
  30540. *
  30541. * The parent cell whose children are being laid out
  30542. */
  30543. mxSwimlaneModel.prototype.parent = null;
  30544. /**
  30545. * Variable: dfsCount
  30546. *
  30547. * Count of the number of times the ancestor dfs has been used.
  30548. */
  30549. mxSwimlaneModel.prototype.dfsCount = 0;
  30550. /**
  30551. * Variable: SOURCESCANSTARTRANK
  30552. *
  30553. * High value to start source layering scan rank value from.
  30554. */
  30555. mxSwimlaneModel.prototype.SOURCESCANSTARTRANK = 100000000;
  30556. /**
  30557. * Variable: tightenToSource
  30558. *
  30559. * Whether or not to tighten the assigned ranks of vertices up towards
  30560. * the source cells.
  30561. */
  30562. mxSwimlaneModel.prototype.tightenToSource = false;
  30563. /**
  30564. * Variable: ranksPerGroup
  30565. *
  30566. * An array of the number of ranks within each swimlane
  30567. */
  30568. mxSwimlaneModel.prototype.ranksPerGroup = null;
  30569. /**
  30570. * Function: createInternalCells
  30571. *
  30572. * Creates all edges in the internal model
  30573. *
  30574. * Parameters:
  30575. *
  30576. * layout - Reference to the <mxHierarchicalLayout> algorithm.
  30577. * vertices - Array of <mxCells> that represent the vertices whom are to
  30578. * have an internal representation created.
  30579. * internalVertices - The array of <mxGraphHierarchyNodes> to have their
  30580. * information filled in using the real vertices.
  30581. */
  30582. mxSwimlaneModel.prototype.createInternalCells = function(layout, vertices, internalVertices)
  30583. {
  30584. var graph = layout.getGraph();
  30585. var swimlanes = layout.swimlanes;
  30586. // Create internal edges
  30587. for (var i = 0; i < vertices.length; i++)
  30588. {
  30589. internalVertices[i] = new mxGraphHierarchyNode(vertices[i]);
  30590. this.vertexMapper.put(vertices[i], internalVertices[i]);
  30591. internalVertices[i].swimlaneIndex = -1;
  30592. for (var ii = 0; ii < swimlanes.length; ii++)
  30593. {
  30594. if (graph.model.getParent(vertices[i]) == swimlanes[ii])
  30595. {
  30596. internalVertices[i].swimlaneIndex = ii;
  30597. break;
  30598. }
  30599. }
  30600. // If the layout is deterministic, order the cells
  30601. //List outgoingCells = graph.getNeighbours(vertices[i], deterministic);
  30602. var conns = layout.getEdges(vertices[i]);
  30603. internalVertices[i].connectsAsSource = [];
  30604. // Create internal edges, but don't do any rank assignment yet
  30605. // First use the information from the greedy cycle remover to
  30606. // invert the leftward edges internally
  30607. for (var j = 0; j < conns.length; j++)
  30608. {
  30609. var cell = layout.getVisibleTerminal(conns[j], false);
  30610. // Looking for outgoing edges only
  30611. if (cell != vertices[i] && layout.graph.model.isVertex(cell) &&
  30612. !layout.isVertexIgnored(cell))
  30613. {
  30614. // We process all edge between this source and its targets
  30615. // If there are edges going both ways, we need to collect
  30616. // them all into one internal edges to avoid looping problems
  30617. // later. We assume this direction (source -> target) is the
  30618. // natural direction if at least half the edges are going in
  30619. // that direction.
  30620. // The check below for edges[0] being in the vertex mapper is
  30621. // in case we've processed this the other way around
  30622. // (target -> source) and the number of edges in each direction
  30623. // are the same. All the graph edges will have been assigned to
  30624. // an internal edge going the other way, so we don't want to
  30625. // process them again
  30626. var undirectedEdges = layout.getEdgesBetween(vertices[i],
  30627. cell, false);
  30628. var directedEdges = layout.getEdgesBetween(vertices[i],
  30629. cell, true);
  30630. if (undirectedEdges != null &&
  30631. undirectedEdges.length > 0 &&
  30632. this.edgeMapper.get(undirectedEdges[0]) == null &&
  30633. directedEdges.length * 2 >= undirectedEdges.length)
  30634. {
  30635. var internalEdge = new mxGraphHierarchyEdge(undirectedEdges);
  30636. for (var k = 0; k < undirectedEdges.length; k++)
  30637. {
  30638. var edge = undirectedEdges[k];
  30639. this.edgeMapper.put(edge, internalEdge);
  30640. // Resets all point on the edge and disables the edge style
  30641. // without deleting it from the cell style
  30642. graph.resetEdge(edge);
  30643. if (layout.disableEdgeStyle)
  30644. {
  30645. layout.setEdgeStyleEnabled(edge, false);
  30646. layout.setOrthogonalEdge(edge,true);
  30647. }
  30648. }
  30649. internalEdge.source = internalVertices[i];
  30650. if (mxUtils.indexOf(internalVertices[i].connectsAsSource, internalEdge) < 0)
  30651. {
  30652. internalVertices[i].connectsAsSource.push(internalEdge);
  30653. }
  30654. }
  30655. }
  30656. }
  30657. // Ensure temp variable is cleared from any previous use
  30658. internalVertices[i].temp[0] = 0;
  30659. }
  30660. };
  30661. /**
  30662. * Function: initialRank
  30663. *
  30664. * Basic determination of minimum layer ranking by working from from sources
  30665. * or sinks and working through each node in the relevant edge direction.
  30666. * Starting at the sinks is basically a longest path layering algorithm.
  30667. */
  30668. mxSwimlaneModel.prototype.initialRank = function()
  30669. {
  30670. this.ranksPerGroup = [];
  30671. var startNodes = [];
  30672. var seen = new Object();
  30673. if (this.roots != null)
  30674. {
  30675. for (var i = 0; i < this.roots.length; i++)
  30676. {
  30677. var internalNode = this.vertexMapper.get(this.roots[i]);
  30678. this.maxChainDfs(null, internalNode, null, seen, 0);
  30679. if (internalNode != null)
  30680. {
  30681. startNodes.push(internalNode);
  30682. }
  30683. }
  30684. }
  30685. // Calculate the lower and upper rank bounds of each swimlane
  30686. var lowerRank = [];
  30687. var upperRank = [];
  30688. for (var i = this.ranksPerGroup.length - 1; i >= 0; i--)
  30689. {
  30690. if (i == this.ranksPerGroup.length - 1)
  30691. {
  30692. lowerRank[i] = 0;
  30693. }
  30694. else
  30695. {
  30696. lowerRank[i] = upperRank[i+1] + 1;
  30697. }
  30698. upperRank[i] = lowerRank[i] + this.ranksPerGroup[i];
  30699. }
  30700. this.maxRank = upperRank[0];
  30701. var internalNodes = this.vertexMapper.getValues();
  30702. for (var i=0; i < internalNodes.length; i++)
  30703. {
  30704. // Mark the node as not having had a layer assigned
  30705. internalNodes[i].temp[0] = -1;
  30706. }
  30707. var startNodesCopy = startNodes.slice();
  30708. while (startNodes.length > 0)
  30709. {
  30710. var internalNode = startNodes[0];
  30711. var layerDeterminingEdges;
  30712. var edgesToBeMarked;
  30713. layerDeterminingEdges = internalNode.connectsAsTarget;
  30714. edgesToBeMarked = internalNode.connectsAsSource;
  30715. // flag to keep track of whether or not all layer determining
  30716. // edges have been scanned
  30717. var allEdgesScanned = true;
  30718. // Work out the layer of this node from the layer determining
  30719. // edges. The minimum layer number of any node connected by one of
  30720. // the layer determining edges variable
  30721. var minimumLayer = upperRank[0];
  30722. for (var i = 0; i < layerDeterminingEdges.length; i++)
  30723. {
  30724. var internalEdge = layerDeterminingEdges[i];
  30725. if (internalEdge.temp[0] == 5270620)
  30726. {
  30727. // This edge has been scanned, get the layer of the
  30728. // node on the other end
  30729. var otherNode = internalEdge.source;
  30730. minimumLayer = Math.min(minimumLayer, otherNode.temp[0] - 1);
  30731. }
  30732. else
  30733. {
  30734. allEdgesScanned = false;
  30735. break;
  30736. }
  30737. }
  30738. // If all edge have been scanned, assign the layer, mark all
  30739. // edges in the other direction and remove from the nodes list
  30740. if (allEdgesScanned)
  30741. {
  30742. if (minimumLayer > upperRank[internalNode.swimlaneIndex])
  30743. {
  30744. minimumLayer = upperRank[internalNode.swimlaneIndex];
  30745. }
  30746. internalNode.temp[0] = minimumLayer;
  30747. if (edgesToBeMarked != null)
  30748. {
  30749. for (var i = 0; i < edgesToBeMarked.length; i++)
  30750. {
  30751. var internalEdge = edgesToBeMarked[i];
  30752. // Assign unique stamp ( y/m/d/h )
  30753. internalEdge.temp[0] = 5270620;
  30754. // Add node on other end of edge to LinkedList of
  30755. // nodes to be analysed
  30756. var otherNode = internalEdge.target;
  30757. // Only add node if it hasn't been assigned a layer
  30758. if (otherNode.temp[0] == -1)
  30759. {
  30760. startNodes.push(otherNode);
  30761. // Mark this other node as neither being
  30762. // unassigned nor assigned so it isn't
  30763. // added to this list again, but it's
  30764. // layer isn't used in any calculation.
  30765. otherNode.temp[0] = -2;
  30766. }
  30767. }
  30768. }
  30769. startNodes.shift();
  30770. }
  30771. else
  30772. {
  30773. // Not all the edges have been scanned, get to the back of
  30774. // the class and put the dunces cap on
  30775. var removedCell = startNodes.shift();
  30776. startNodes.push(internalNode);
  30777. if (removedCell == internalNode && startNodes.length == 1)
  30778. {
  30779. // This is an error condition, we can't get out of
  30780. // this loop. It could happen for more than one node
  30781. // but that's a lot harder to detect. Log the error
  30782. // TODO make log comment
  30783. break;
  30784. }
  30785. }
  30786. }
  30787. // Normalize the ranks down from their large starting value to place
  30788. // at least 1 sink on layer 0
  30789. // for (var key in this.vertexMapper)
  30790. // {
  30791. // var internalNode = this.vertexMapper[key];
  30792. // // Mark the node as not having had a layer assigned
  30793. // internalNode.temp[0] -= this.maxRank;
  30794. // }
  30795. // Tighten the rank 0 nodes as far as possible
  30796. // for ( var i = 0; i < startNodesCopy.length; i++)
  30797. // {
  30798. // var internalNode = startNodesCopy[i];
  30799. // var currentMaxLayer = 0;
  30800. // var layerDeterminingEdges = internalNode.connectsAsSource;
  30801. //
  30802. // for ( var j = 0; j < layerDeterminingEdges.length; j++)
  30803. // {
  30804. // var internalEdge = layerDeterminingEdges[j];
  30805. // var otherNode = internalEdge.target;
  30806. // internalNode.temp[0] = Math.max(currentMaxLayer,
  30807. // otherNode.temp[0] + 1);
  30808. // currentMaxLayer = internalNode.temp[0];
  30809. // }
  30810. // }
  30811. };
  30812. /**
  30813. * Function: maxChainDfs
  30814. *
  30815. * Performs a depth first search on the internal hierarchy model. This dfs
  30816. * extends the default version by keeping track of chains within groups.
  30817. * Any cycles should be removed prior to running, but previously seen cells
  30818. * are ignored.
  30819. *
  30820. * Parameters:
  30821. *
  30822. * parent - the parent internal node of the current internal node
  30823. * root - the current internal node
  30824. * connectingEdge - the internal edge connecting the internal node and the parent
  30825. * internal node, if any
  30826. * seen - a set of all nodes seen by this dfs
  30827. * chainCount - the number of edges in the chain of vertices going through
  30828. * the current swimlane
  30829. */
  30830. mxSwimlaneModel.prototype.maxChainDfs = function(parent, root, connectingEdge, seen, chainCount)
  30831. {
  30832. if (root != null)
  30833. {
  30834. var rootId = mxCellPath.create(root.cell);
  30835. if (seen[rootId] == null)
  30836. {
  30837. seen[rootId] = root;
  30838. var slIndex = root.swimlaneIndex;
  30839. if (this.ranksPerGroup[slIndex] == null || this.ranksPerGroup[slIndex] < chainCount)
  30840. {
  30841. this.ranksPerGroup[slIndex] = chainCount;
  30842. }
  30843. // Copy the connects as source list so that visitors
  30844. // can change the original for edge direction inversions
  30845. var outgoingEdges = root.connectsAsSource.slice();
  30846. for (var i = 0; i < outgoingEdges.length; i++)
  30847. {
  30848. var internalEdge = outgoingEdges[i];
  30849. var targetNode = internalEdge.target;
  30850. // Only navigate in source->target direction within the same
  30851. // swimlane, or from a lower index swimlane to a higher one
  30852. if (root.swimlaneIndex < targetNode.swimlaneIndex)
  30853. {
  30854. this.maxChainDfs(root, targetNode, internalEdge, mxUtils.clone(seen, null , true), 0);
  30855. }
  30856. else if (root.swimlaneIndex == targetNode.swimlaneIndex)
  30857. {
  30858. this.maxChainDfs(root, targetNode, internalEdge, mxUtils.clone(seen, null , true), chainCount + 1);
  30859. }
  30860. }
  30861. }
  30862. }
  30863. };
  30864. /**
  30865. * Function: fixRanks
  30866. *
  30867. * Fixes the layer assignments to the values stored in the nodes. Also needs
  30868. * to create dummy nodes for edges that cross layers.
  30869. */
  30870. mxSwimlaneModel.prototype.fixRanks = function()
  30871. {
  30872. var rankList = [];
  30873. this.ranks = [];
  30874. for (var i = 0; i < this.maxRank + 1; i++)
  30875. {
  30876. rankList[i] = [];
  30877. this.ranks[i] = rankList[i];
  30878. }
  30879. // Perform a DFS to obtain an initial ordering for each rank.
  30880. // Without doing this you would end up having to process
  30881. // crossings for a standard tree.
  30882. var rootsArray = null;
  30883. if (this.roots != null)
  30884. {
  30885. var oldRootsArray = this.roots;
  30886. rootsArray = [];
  30887. for (var i = 0; i < oldRootsArray.length; i++)
  30888. {
  30889. var cell = oldRootsArray[i];
  30890. var internalNode = this.vertexMapper.get(cell);
  30891. rootsArray[i] = internalNode;
  30892. }
  30893. }
  30894. this.visit(function(parent, node, edge, layer, seen)
  30895. {
  30896. if (seen == 0 && node.maxRank < 0 && node.minRank < 0)
  30897. {
  30898. rankList[node.temp[0]].push(node);
  30899. node.maxRank = node.temp[0];
  30900. node.minRank = node.temp[0];
  30901. // Set temp[0] to the nodes position in the rank
  30902. node.temp[0] = rankList[node.maxRank].length - 1;
  30903. }
  30904. if (parent != null && edge != null)
  30905. {
  30906. var parentToCellRankDifference = parent.maxRank - node.maxRank;
  30907. if (parentToCellRankDifference > 1)
  30908. {
  30909. // There are ranks in between the parent and current cell
  30910. edge.maxRank = parent.maxRank;
  30911. edge.minRank = node.maxRank;
  30912. edge.temp = [];
  30913. edge.x = [];
  30914. edge.y = [];
  30915. for (var i = edge.minRank + 1; i < edge.maxRank; i++)
  30916. {
  30917. // The connecting edge must be added to the
  30918. // appropriate ranks
  30919. rankList[i].push(edge);
  30920. edge.setGeneralPurposeVariable(i, rankList[i]
  30921. .length - 1);
  30922. }
  30923. }
  30924. }
  30925. }, rootsArray, false, null);
  30926. };
  30927. /**
  30928. * Function: visit
  30929. *
  30930. * A depth first search through the internal heirarchy model.
  30931. *
  30932. * Parameters:
  30933. *
  30934. * visitor - The visitor function pattern to be called for each node.
  30935. * trackAncestors - Whether or not the search is to keep track all nodes
  30936. * directly above this one in the search path.
  30937. */
  30938. mxSwimlaneModel.prototype.visit = function(visitor, dfsRoots, trackAncestors, seenNodes)
  30939. {
  30940. // Run dfs through on all roots
  30941. if (dfsRoots != null)
  30942. {
  30943. for (var i = 0; i < dfsRoots.length; i++)
  30944. {
  30945. var internalNode = dfsRoots[i];
  30946. if (internalNode != null)
  30947. {
  30948. if (seenNodes == null)
  30949. {
  30950. seenNodes = new Object();
  30951. }
  30952. if (trackAncestors)
  30953. {
  30954. // Set up hash code for root
  30955. internalNode.hashCode = [];
  30956. internalNode.hashCode[0] = this.dfsCount;
  30957. internalNode.hashCode[1] = i;
  30958. this.extendedDfs(null, internalNode, null, visitor, seenNodes,
  30959. internalNode.hashCode, i, 0);
  30960. }
  30961. else
  30962. {
  30963. this.dfs(null, internalNode, null, visitor, seenNodes, 0);
  30964. }
  30965. }
  30966. }
  30967. this.dfsCount++;
  30968. }
  30969. };
  30970. /**
  30971. * Function: dfs
  30972. *
  30973. * Performs a depth first search on the internal hierarchy model
  30974. *
  30975. * Parameters:
  30976. *
  30977. * parent - the parent internal node of the current internal node
  30978. * root - the current internal node
  30979. * connectingEdge - the internal edge connecting the internal node and the parent
  30980. * internal node, if any
  30981. * visitor - the visitor pattern to be called for each node
  30982. * seen - a set of all nodes seen by this dfs a set of all of the
  30983. * ancestor node of the current node
  30984. * layer - the layer on the dfs tree ( not the same as the model ranks )
  30985. */
  30986. mxSwimlaneModel.prototype.dfs = function(parent, root, connectingEdge, visitor, seen, layer)
  30987. {
  30988. if (root != null)
  30989. {
  30990. var rootId = root.id;
  30991. if (seen[rootId] == null)
  30992. {
  30993. seen[rootId] = root;
  30994. visitor(parent, root, connectingEdge, layer, 0);
  30995. // Copy the connects as source list so that visitors
  30996. // can change the original for edge direction inversions
  30997. var outgoingEdges = root.connectsAsSource.slice();
  30998. for (var i = 0; i< outgoingEdges.length; i++)
  30999. {
  31000. var internalEdge = outgoingEdges[i];
  31001. var targetNode = internalEdge.target;
  31002. // Root check is O(|roots|)
  31003. this.dfs(root, targetNode, internalEdge, visitor, seen,
  31004. layer + 1);
  31005. }
  31006. }
  31007. else
  31008. {
  31009. // Use the int field to indicate this node has been seen
  31010. visitor(parent, root, connectingEdge, layer, 1);
  31011. }
  31012. }
  31013. };
  31014. /**
  31015. * Function: extendedDfs
  31016. *
  31017. * Performs a depth first search on the internal hierarchy model. This dfs
  31018. * extends the default version by keeping track of cells ancestors, but it
  31019. * should be only used when necessary because of it can be computationally
  31020. * intensive for deep searches.
  31021. *
  31022. * Parameters:
  31023. *
  31024. * parent - the parent internal node of the current internal node
  31025. * root - the current internal node
  31026. * connectingEdge - the internal edge connecting the internal node and the parent
  31027. * internal node, if any
  31028. * visitor - the visitor pattern to be called for each node
  31029. * seen - a set of all nodes seen by this dfs
  31030. * ancestors - the parent hash code
  31031. * childHash - the new hash code for this node
  31032. * layer - the layer on the dfs tree ( not the same as the model ranks )
  31033. */
  31034. mxSwimlaneModel.prototype.extendedDfs = function(parent, root, connectingEdge, visitor, seen, ancestors, childHash, layer)
  31035. {
  31036. // Explanation of custom hash set. Previously, the ancestors variable
  31037. // was passed through the dfs as a HashSet. The ancestors were copied
  31038. // into a new HashSet and when the new child was processed it was also
  31039. // added to the set. If the current node was in its ancestor list it
  31040. // meant there is a cycle in the graph and this information is passed
  31041. // to the visitor.visit() in the seen parameter. The HashSet clone was
  31042. // very expensive on CPU so a custom hash was developed using primitive
  31043. // types. temp[] couldn't be used so hashCode[] was added to each node.
  31044. // Each new child adds another int to the array, copying the prefix
  31045. // from its parent. Child of the same parent add different ints (the
  31046. // limit is therefore 2^32 children per parent...). If a node has a
  31047. // child with the hashCode already set then the child code is compared
  31048. // to the same portion of the current nodes array. If they match there
  31049. // is a loop.
  31050. // Note that the basic mechanism would only allow for 1 use of this
  31051. // functionality, so the root nodes have two ints. The second int is
  31052. // incremented through each node root and the first is incremented
  31053. // through each run of the dfs algorithm (therefore the dfs is not
  31054. // thread safe). The hash code of each node is set if not already set,
  31055. // or if the first int does not match that of the current run.
  31056. if (root != null)
  31057. {
  31058. if (parent != null)
  31059. {
  31060. // Form this nodes hash code if necessary, that is, if the
  31061. // hashCode variable has not been initialized or if the
  31062. // start of the parent hash code does not equal the start of
  31063. // this nodes hash code, indicating the code was set on a
  31064. // previous run of this dfs.
  31065. if (root.hashCode == null ||
  31066. root.hashCode[0] != parent.hashCode[0])
  31067. {
  31068. var hashCodeLength = parent.hashCode.length + 1;
  31069. root.hashCode = parent.hashCode.slice();
  31070. root.hashCode[hashCodeLength - 1] = childHash;
  31071. }
  31072. }
  31073. var rootId = root.id;
  31074. if (seen[rootId] == null)
  31075. {
  31076. seen[rootId] = root;
  31077. visitor(parent, root, connectingEdge, layer, 0);
  31078. // Copy the connects as source list so that visitors
  31079. // can change the original for edge direction inversions
  31080. var outgoingEdges = root.connectsAsSource.slice();
  31081. var incomingEdges = root.connectsAsTarget.slice();
  31082. for (var i = 0; i < outgoingEdges.length; i++)
  31083. {
  31084. var internalEdge = outgoingEdges[i];
  31085. var targetNode = internalEdge.target;
  31086. // Only navigate in source->target direction within the same
  31087. // swimlane, or from a lower index swimlane to a higher one
  31088. if (root.swimlaneIndex <= targetNode.swimlaneIndex)
  31089. {
  31090. this.extendedDfs(root, targetNode, internalEdge, visitor, seen,
  31091. root.hashCode, i, layer + 1);
  31092. }
  31093. }
  31094. for (var i = 0; i < incomingEdges.length; i++)
  31095. {
  31096. var internalEdge = incomingEdges[i];
  31097. var targetNode = internalEdge.source;
  31098. // Only navigate in target->source direction from a lower index
  31099. // swimlane to a higher one
  31100. if (root.swimlaneIndex < targetNode.swimlaneIndex)
  31101. {
  31102. this.extendedDfs(root, targetNode, internalEdge, visitor, seen,
  31103. root.hashCode, i, layer + 1);
  31104. }
  31105. }
  31106. }
  31107. else
  31108. {
  31109. // Use the int field to indicate this node has been seen
  31110. visitor(parent, root, connectingEdge, layer, 1);
  31111. }
  31112. }
  31113. };
  31114. /**
  31115. * Copyright (c) 2006-2015, JGraph Ltd
  31116. * Copyright (c) 2006-2015, Gaudenz Alder
  31117. */
  31118. /**
  31119. * Class: mxHierarchicalLayoutStage
  31120. *
  31121. * The specific layout interface for hierarchical layouts. It adds a
  31122. * <code>run</code> method with a parameter for the hierarchical layout model
  31123. * that is shared between the layout stages.
  31124. *
  31125. * Constructor: mxHierarchicalLayoutStage
  31126. *
  31127. * Constructs a new hierarchical layout stage.
  31128. */
  31129. function mxHierarchicalLayoutStage() { };
  31130. /**
  31131. * Function: execute
  31132. *
  31133. * Takes the graph detail and configuration information within the facade
  31134. * and creates the resulting laid out graph within that facade for further
  31135. * use.
  31136. */
  31137. mxHierarchicalLayoutStage.prototype.execute = function(parent) { };
  31138. /**
  31139. * Copyright (c) 2006-2015, JGraph Ltd
  31140. * Copyright (c) 2006-2015, Gaudenz Alder
  31141. */
  31142. /**
  31143. * Class: mxMedianHybridCrossingReduction
  31144. *
  31145. * Sets the horizontal locations of node and edge dummy nodes on each layer.
  31146. * Uses median down and up weighings as well heuristic to straighten edges as
  31147. * far as possible.
  31148. *
  31149. * Constructor: mxMedianHybridCrossingReduction
  31150. *
  31151. * Creates a coordinate assignment.
  31152. *
  31153. * Arguments:
  31154. *
  31155. * intraCellSpacing - the minimum buffer between cells on the same rank
  31156. * interRankCellSpacing - the minimum distance between cells on adjacent ranks
  31157. * orientation - the position of the root node(s) relative to the graph
  31158. * initialX - the leftmost coordinate node placement starts at
  31159. */
  31160. function mxMedianHybridCrossingReduction(layout)
  31161. {
  31162. this.layout = layout;
  31163. };
  31164. /**
  31165. * Extends mxMedianHybridCrossingReduction.
  31166. */
  31167. mxMedianHybridCrossingReduction.prototype = new mxHierarchicalLayoutStage();
  31168. mxMedianHybridCrossingReduction.prototype.constructor = mxMedianHybridCrossingReduction;
  31169. /**
  31170. * Variable: layout
  31171. *
  31172. * Reference to the enclosing <mxHierarchicalLayout>.
  31173. */
  31174. mxMedianHybridCrossingReduction.prototype.layout = null;
  31175. /**
  31176. * Variable: maxIterations
  31177. *
  31178. * The maximum number of iterations to perform whilst reducing edge
  31179. * crossings. Default is 24.
  31180. */
  31181. mxMedianHybridCrossingReduction.prototype.maxIterations = 24;
  31182. /**
  31183. * Variable: nestedBestRanks
  31184. *
  31185. * Stores each rank as a collection of cells in the best order found for
  31186. * each layer so far
  31187. */
  31188. mxMedianHybridCrossingReduction.prototype.nestedBestRanks = null;
  31189. /**
  31190. * Variable: currentBestCrossings
  31191. *
  31192. * The total number of crossings found in the best configuration so far
  31193. */
  31194. mxMedianHybridCrossingReduction.prototype.currentBestCrossings = 0;
  31195. /**
  31196. * Variable: iterationsWithoutImprovement
  31197. *
  31198. * The total number of crossings found in the best configuration so far
  31199. */
  31200. mxMedianHybridCrossingReduction.prototype.iterationsWithoutImprovement = 0;
  31201. /**
  31202. * Variable: maxNoImprovementIterations
  31203. *
  31204. * The total number of crossings found in the best configuration so far
  31205. */
  31206. mxMedianHybridCrossingReduction.prototype.maxNoImprovementIterations = 2;
  31207. /**
  31208. * Function: execute
  31209. *
  31210. * Performs a vertex ordering within ranks as described by Gansner et al
  31211. * 1993
  31212. */
  31213. mxMedianHybridCrossingReduction.prototype.execute = function(parent)
  31214. {
  31215. var model = this.layout.getModel();
  31216. // Stores initial ordering as being the best one found so far
  31217. this.nestedBestRanks = [];
  31218. for (var i = 0; i < model.ranks.length; i++)
  31219. {
  31220. this.nestedBestRanks[i] = model.ranks[i].slice();
  31221. }
  31222. var iterationsWithoutImprovement = 0;
  31223. var currentBestCrossings = this.calculateCrossings(model);
  31224. for (var i = 0; i < this.maxIterations &&
  31225. iterationsWithoutImprovement < this.maxNoImprovementIterations; i++)
  31226. {
  31227. this.weightedMedian(i, model);
  31228. this.transpose(i, model);
  31229. var candidateCrossings = this.calculateCrossings(model);
  31230. if (candidateCrossings < currentBestCrossings)
  31231. {
  31232. currentBestCrossings = candidateCrossings;
  31233. iterationsWithoutImprovement = 0;
  31234. // Store the current rankings as the best ones
  31235. for (var j = 0; j < this.nestedBestRanks.length; j++)
  31236. {
  31237. var rank = model.ranks[j];
  31238. for (var k = 0; k < rank.length; k++)
  31239. {
  31240. var cell = rank[k];
  31241. this.nestedBestRanks[j][cell.getGeneralPurposeVariable(j)] = cell;
  31242. }
  31243. }
  31244. }
  31245. else
  31246. {
  31247. // Increase count of iterations where we haven't improved the
  31248. // layout
  31249. iterationsWithoutImprovement++;
  31250. // Restore the best values to the cells
  31251. for (var j = 0; j < this.nestedBestRanks.length; j++)
  31252. {
  31253. var rank = model.ranks[j];
  31254. for (var k = 0; k < rank.length; k++)
  31255. {
  31256. var cell = rank[k];
  31257. cell.setGeneralPurposeVariable(j, k);
  31258. }
  31259. }
  31260. }
  31261. if (currentBestCrossings == 0)
  31262. {
  31263. // Do nothing further
  31264. break;
  31265. }
  31266. }
  31267. // Store the best rankings but in the model
  31268. var ranks = [];
  31269. var rankList = [];
  31270. for (var i = 0; i < model.maxRank + 1; i++)
  31271. {
  31272. rankList[i] = [];
  31273. ranks[i] = rankList[i];
  31274. }
  31275. for (var i = 0; i < this.nestedBestRanks.length; i++)
  31276. {
  31277. for (var j = 0; j < this.nestedBestRanks[i].length; j++)
  31278. {
  31279. rankList[i].push(this.nestedBestRanks[i][j]);
  31280. }
  31281. }
  31282. model.ranks = ranks;
  31283. };
  31284. /**
  31285. * Function: calculateCrossings
  31286. *
  31287. * Calculates the total number of edge crossing in the current graph.
  31288. * Returns the current number of edge crossings in the hierarchy graph
  31289. * model in the current candidate layout
  31290. *
  31291. * Parameters:
  31292. *
  31293. * model - the internal model describing the hierarchy
  31294. */
  31295. mxMedianHybridCrossingReduction.prototype.calculateCrossings = function(model)
  31296. {
  31297. var numRanks = model.ranks.length;
  31298. var totalCrossings = 0;
  31299. for (var i = 1; i < numRanks; i++)
  31300. {
  31301. totalCrossings += this.calculateRankCrossing(i, model);
  31302. }
  31303. return totalCrossings;
  31304. };
  31305. /**
  31306. * Function: calculateRankCrossing
  31307. *
  31308. * Calculates the number of edges crossings between the specified rank and
  31309. * the rank below it. Returns the number of edges crossings with the rank
  31310. * beneath
  31311. *
  31312. * Parameters:
  31313. *
  31314. * i - the topmost rank of the pair ( higher rank value )
  31315. * model - the internal model describing the hierarchy
  31316. */
  31317. mxMedianHybridCrossingReduction.prototype.calculateRankCrossing = function(i, model)
  31318. {
  31319. var totalCrossings = 0;
  31320. var rank = model.ranks[i];
  31321. var previousRank = model.ranks[i - 1];
  31322. var tmpIndices = [];
  31323. // Iterate over the top rank and fill in the connection information
  31324. for (var j = 0; j < rank.length; j++)
  31325. {
  31326. var node = rank[j];
  31327. var rankPosition = node.getGeneralPurposeVariable(i);
  31328. var connectedCells = node.getPreviousLayerConnectedCells(i);
  31329. var nodeIndices = [];
  31330. for (var k = 0; k < connectedCells.length; k++)
  31331. {
  31332. var connectedNode = connectedCells[k];
  31333. var otherCellRankPosition = connectedNode.getGeneralPurposeVariable(i - 1);
  31334. nodeIndices.push(otherCellRankPosition);
  31335. }
  31336. nodeIndices.sort(function(x, y) { return x - y; });
  31337. tmpIndices[rankPosition] = nodeIndices;
  31338. }
  31339. var indices = [];
  31340. for (var j = 0; j < tmpIndices.length; j++)
  31341. {
  31342. indices = indices.concat(tmpIndices[j]);
  31343. }
  31344. var firstIndex = 1;
  31345. while (firstIndex < previousRank.length)
  31346. {
  31347. firstIndex <<= 1;
  31348. }
  31349. var treeSize = 2 * firstIndex - 1;
  31350. firstIndex -= 1;
  31351. var tree = [];
  31352. for (var j = 0; j < treeSize; ++j)
  31353. {
  31354. tree[j] = 0;
  31355. }
  31356. for (var j = 0; j < indices.length; j++)
  31357. {
  31358. var index = indices[j];
  31359. var treeIndex = index + firstIndex;
  31360. ++tree[treeIndex];
  31361. while (treeIndex > 0)
  31362. {
  31363. if (treeIndex % 2)
  31364. {
  31365. totalCrossings += tree[treeIndex + 1];
  31366. }
  31367. treeIndex = (treeIndex - 1) >> 1;
  31368. ++tree[treeIndex];
  31369. }
  31370. }
  31371. return totalCrossings;
  31372. };
  31373. /**
  31374. * Function: transpose
  31375. *
  31376. * Takes each possible adjacent cell pair on each rank and checks if
  31377. * swapping them around reduces the number of crossing
  31378. *
  31379. * Parameters:
  31380. *
  31381. * mainLoopIteration - the iteration number of the main loop
  31382. * model - the internal model describing the hierarchy
  31383. */
  31384. mxMedianHybridCrossingReduction.prototype.transpose = function(mainLoopIteration, model)
  31385. {
  31386. var improved = true;
  31387. // Track the number of iterations in case of looping
  31388. var count = 0;
  31389. var maxCount = 10;
  31390. while (improved && count++ < maxCount)
  31391. {
  31392. // On certain iterations allow allow swapping of cell pairs with
  31393. // equal edge crossings switched or not switched. This help to
  31394. // nudge a stuck layout into a lower crossing total.
  31395. var nudge = mainLoopIteration % 2 == 1 && count % 2 == 1;
  31396. improved = false;
  31397. for (var i = 0; i < model.ranks.length; i++)
  31398. {
  31399. var rank = model.ranks[i];
  31400. var orderedCells = [];
  31401. for (var j = 0; j < rank.length; j++)
  31402. {
  31403. var cell = rank[j];
  31404. var tempRank = cell.getGeneralPurposeVariable(i);
  31405. // FIXME: Workaround to avoid negative tempRanks
  31406. if (tempRank < 0)
  31407. {
  31408. tempRank = j;
  31409. }
  31410. orderedCells[tempRank] = cell;
  31411. }
  31412. var leftCellAboveConnections = null;
  31413. var leftCellBelowConnections = null;
  31414. var rightCellAboveConnections = null;
  31415. var rightCellBelowConnections = null;
  31416. var leftAbovePositions = null;
  31417. var leftBelowPositions = null;
  31418. var rightAbovePositions = null;
  31419. var rightBelowPositions = null;
  31420. var leftCell = null;
  31421. var rightCell = null;
  31422. for (var j = 0; j < (rank.length - 1); j++)
  31423. {
  31424. // For each intra-rank adjacent pair of cells
  31425. // see if swapping them around would reduce the
  31426. // number of edges crossing they cause in total
  31427. // On every cell pair except the first on each rank, we
  31428. // can save processing using the previous values for the
  31429. // right cell on the new left cell
  31430. if (j == 0)
  31431. {
  31432. leftCell = orderedCells[j];
  31433. leftCellAboveConnections = leftCell
  31434. .getNextLayerConnectedCells(i);
  31435. leftCellBelowConnections = leftCell
  31436. .getPreviousLayerConnectedCells(i);
  31437. leftAbovePositions = [];
  31438. leftBelowPositions = [];
  31439. for (var k = 0; k < leftCellAboveConnections.length; k++)
  31440. {
  31441. leftAbovePositions[k] = leftCellAboveConnections[k].getGeneralPurposeVariable(i + 1);
  31442. }
  31443. for (var k = 0; k < leftCellBelowConnections.length; k++)
  31444. {
  31445. leftBelowPositions[k] = leftCellBelowConnections[k].getGeneralPurposeVariable(i - 1);
  31446. }
  31447. }
  31448. else
  31449. {
  31450. leftCellAboveConnections = rightCellAboveConnections;
  31451. leftCellBelowConnections = rightCellBelowConnections;
  31452. leftAbovePositions = rightAbovePositions;
  31453. leftBelowPositions = rightBelowPositions;
  31454. leftCell = rightCell;
  31455. }
  31456. rightCell = orderedCells[j + 1];
  31457. rightCellAboveConnections = rightCell
  31458. .getNextLayerConnectedCells(i);
  31459. rightCellBelowConnections = rightCell
  31460. .getPreviousLayerConnectedCells(i);
  31461. rightAbovePositions = [];
  31462. rightBelowPositions = [];
  31463. for (var k = 0; k < rightCellAboveConnections.length; k++)
  31464. {
  31465. rightAbovePositions[k] = rightCellAboveConnections[k].getGeneralPurposeVariable(i + 1);
  31466. }
  31467. for (var k = 0; k < rightCellBelowConnections.length; k++)
  31468. {
  31469. rightBelowPositions[k] = rightCellBelowConnections[k].getGeneralPurposeVariable(i - 1);
  31470. }
  31471. var totalCurrentCrossings = 0;
  31472. var totalSwitchedCrossings = 0;
  31473. for (var k = 0; k < leftAbovePositions.length; k++)
  31474. {
  31475. for (var ik = 0; ik < rightAbovePositions.length; ik++)
  31476. {
  31477. if (leftAbovePositions[k] > rightAbovePositions[ik])
  31478. {
  31479. totalCurrentCrossings++;
  31480. }
  31481. if (leftAbovePositions[k] < rightAbovePositions[ik])
  31482. {
  31483. totalSwitchedCrossings++;
  31484. }
  31485. }
  31486. }
  31487. for (var k = 0; k < leftBelowPositions.length; k++)
  31488. {
  31489. for (var ik = 0; ik < rightBelowPositions.length; ik++)
  31490. {
  31491. if (leftBelowPositions[k] > rightBelowPositions[ik])
  31492. {
  31493. totalCurrentCrossings++;
  31494. }
  31495. if (leftBelowPositions[k] < rightBelowPositions[ik])
  31496. {
  31497. totalSwitchedCrossings++;
  31498. }
  31499. }
  31500. }
  31501. if ((totalSwitchedCrossings < totalCurrentCrossings) ||
  31502. (totalSwitchedCrossings == totalCurrentCrossings &&
  31503. nudge))
  31504. {
  31505. var temp = leftCell.getGeneralPurposeVariable(i);
  31506. leftCell.setGeneralPurposeVariable(i, rightCell
  31507. .getGeneralPurposeVariable(i));
  31508. rightCell.setGeneralPurposeVariable(i, temp);
  31509. // With this pair exchanged we have to switch all of
  31510. // values for the left cell to the right cell so the
  31511. // next iteration for this rank uses it as the left
  31512. // cell again
  31513. rightCellAboveConnections = leftCellAboveConnections;
  31514. rightCellBelowConnections = leftCellBelowConnections;
  31515. rightAbovePositions = leftAbovePositions;
  31516. rightBelowPositions = leftBelowPositions;
  31517. rightCell = leftCell;
  31518. if (!nudge)
  31519. {
  31520. // Don't count nudges as improvement or we'll end
  31521. // up stuck in two combinations and not finishing
  31522. // as early as we should
  31523. improved = true;
  31524. }
  31525. }
  31526. }
  31527. }
  31528. }
  31529. };
  31530. /**
  31531. * Function: weightedMedian
  31532. *
  31533. * Sweeps up or down the layout attempting to minimise the median placement
  31534. * of connected cells on adjacent ranks
  31535. *
  31536. * Parameters:
  31537. *
  31538. * iteration - the iteration number of the main loop
  31539. * model - the internal model describing the hierarchy
  31540. */
  31541. mxMedianHybridCrossingReduction.prototype.weightedMedian = function(iteration, model)
  31542. {
  31543. // Reverse sweep direction each time through this method
  31544. var downwardSweep = (iteration % 2 == 0);
  31545. if (downwardSweep)
  31546. {
  31547. for (var j = model.maxRank - 1; j >= 0; j--)
  31548. {
  31549. this.medianRank(j, downwardSweep);
  31550. }
  31551. }
  31552. else
  31553. {
  31554. for (var j = 1; j < model.maxRank; j++)
  31555. {
  31556. this.medianRank(j, downwardSweep);
  31557. }
  31558. }
  31559. };
  31560. /**
  31561. * Function: medianRank
  31562. *
  31563. * Attempts to minimise the median placement of connected cells on this rank
  31564. * and one of the adjacent ranks
  31565. *
  31566. * Parameters:
  31567. *
  31568. * rankValue - the layer number of this rank
  31569. * downwardSweep - whether or not this is a downward sweep through the graph
  31570. */
  31571. mxMedianHybridCrossingReduction.prototype.medianRank = function(rankValue, downwardSweep)
  31572. {
  31573. var numCellsForRank = this.nestedBestRanks[rankValue].length;
  31574. var medianValues = [];
  31575. var reservedPositions = [];
  31576. for (var i = 0; i < numCellsForRank; i++)
  31577. {
  31578. var cell = this.nestedBestRanks[rankValue][i];
  31579. var sorterEntry = new MedianCellSorter();
  31580. sorterEntry.cell = cell;
  31581. // Flip whether or not equal medians are flipped on up and down
  31582. // sweeps
  31583. // TODO re-implement some kind of nudge
  31584. // medianValues[i].nudge = !downwardSweep;
  31585. var nextLevelConnectedCells;
  31586. if (downwardSweep)
  31587. {
  31588. nextLevelConnectedCells = cell
  31589. .getNextLayerConnectedCells(rankValue);
  31590. }
  31591. else
  31592. {
  31593. nextLevelConnectedCells = cell
  31594. .getPreviousLayerConnectedCells(rankValue);
  31595. }
  31596. var nextRankValue;
  31597. if (downwardSweep)
  31598. {
  31599. nextRankValue = rankValue + 1;
  31600. }
  31601. else
  31602. {
  31603. nextRankValue = rankValue - 1;
  31604. }
  31605. if (nextLevelConnectedCells != null
  31606. && nextLevelConnectedCells.length != 0)
  31607. {
  31608. sorterEntry.medianValue = this.medianValue(
  31609. nextLevelConnectedCells, nextRankValue);
  31610. medianValues.push(sorterEntry);
  31611. }
  31612. else
  31613. {
  31614. // Nodes with no adjacent vertices are flagged in the reserved array
  31615. // to indicate they should be left in their current position.
  31616. reservedPositions[cell.getGeneralPurposeVariable(rankValue)] = true;
  31617. }
  31618. }
  31619. medianValues.sort(MedianCellSorter.prototype.compare);
  31620. // Set the new position of each node within the rank using
  31621. // its temp variable
  31622. for (var i = 0; i < numCellsForRank; i++)
  31623. {
  31624. if (reservedPositions[i] == null)
  31625. {
  31626. var cell = medianValues.shift().cell;
  31627. cell.setGeneralPurposeVariable(rankValue, i);
  31628. }
  31629. }
  31630. };
  31631. /**
  31632. * Function: medianValue
  31633. *
  31634. * Calculates the median rank order positioning for the specified cell using
  31635. * the connected cells on the specified rank. Returns the median rank
  31636. * ordering value of the connected cells
  31637. *
  31638. * Parameters:
  31639. *
  31640. * connectedCells - the cells on the specified rank connected to the
  31641. * specified cell
  31642. * rankValue - the rank that the connected cell lie upon
  31643. */
  31644. mxMedianHybridCrossingReduction.prototype.medianValue = function(connectedCells, rankValue)
  31645. {
  31646. var medianValues = [];
  31647. var arrayCount = 0;
  31648. for (var i = 0; i < connectedCells.length; i++)
  31649. {
  31650. var cell = connectedCells[i];
  31651. medianValues[arrayCount++] = cell.getGeneralPurposeVariable(rankValue);
  31652. }
  31653. // Sort() sorts lexicographically by default (i.e. 11 before 9) so force
  31654. // numerical order sort
  31655. medianValues.sort(function(a,b){return a - b;});
  31656. if (arrayCount % 2 == 1)
  31657. {
  31658. // For odd numbers of adjacent vertices return the median
  31659. return medianValues[Math.floor(arrayCount / 2)];
  31660. }
  31661. else if (arrayCount == 2)
  31662. {
  31663. return ((medianValues[0] + medianValues[1]) / 2.0);
  31664. }
  31665. else
  31666. {
  31667. var medianPoint = arrayCount / 2;
  31668. var leftMedian = medianValues[medianPoint - 1] - medianValues[0];
  31669. var rightMedian = medianValues[arrayCount - 1]
  31670. - medianValues[medianPoint];
  31671. return (medianValues[medianPoint - 1] * rightMedian + medianValues[medianPoint]
  31672. * leftMedian)
  31673. / (leftMedian + rightMedian);
  31674. }
  31675. };
  31676. /**
  31677. * Class: MedianCellSorter
  31678. *
  31679. * A utility class used to track cells whilst sorting occurs on the median
  31680. * values. Does not violate (x.compareTo(y)==0) == (x.equals(y))
  31681. *
  31682. * Constructor: MedianCellSorter
  31683. *
  31684. * Constructs a new median cell sorter.
  31685. */
  31686. function MedianCellSorter()
  31687. {
  31688. // empty
  31689. };
  31690. /**
  31691. * Variable: medianValue
  31692. *
  31693. * The weighted value of the cell stored.
  31694. */
  31695. MedianCellSorter.prototype.medianValue = 0;
  31696. /**
  31697. * Variable: cell
  31698. *
  31699. * The cell whose median value is being calculated
  31700. */
  31701. MedianCellSorter.prototype.cell = false;
  31702. /**
  31703. * Function: compare
  31704. *
  31705. * Compares two MedianCellSorters.
  31706. */
  31707. MedianCellSorter.prototype.compare = function(a, b)
  31708. {
  31709. if (a != null && b != null)
  31710. {
  31711. if (b.medianValue > a.medianValue)
  31712. {
  31713. return -1;
  31714. }
  31715. else if (b.medianValue < a.medianValue)
  31716. {
  31717. return 1;
  31718. }
  31719. else
  31720. {
  31721. return 0;
  31722. }
  31723. }
  31724. else
  31725. {
  31726. return 0;
  31727. }
  31728. };
  31729. /**
  31730. * Copyright (c) 2006-2015, JGraph Ltd
  31731. * Copyright (c) 2006-2015, Gaudenz Alder
  31732. */
  31733. /**
  31734. * Class: mxMinimumCycleRemover
  31735. *
  31736. * An implementation of the first stage of the Sugiyama layout. Straightforward
  31737. * longest path calculation of layer assignment
  31738. *
  31739. * Constructor: mxMinimumCycleRemover
  31740. *
  31741. * Creates a cycle remover for the given internal model.
  31742. */
  31743. function mxMinimumCycleRemover(layout)
  31744. {
  31745. this.layout = layout;
  31746. };
  31747. /**
  31748. * Extends mxHierarchicalLayoutStage.
  31749. */
  31750. mxMinimumCycleRemover.prototype = new mxHierarchicalLayoutStage();
  31751. mxMinimumCycleRemover.prototype.constructor = mxMinimumCycleRemover;
  31752. /**
  31753. * Variable: layout
  31754. *
  31755. * Reference to the enclosing <mxHierarchicalLayout>.
  31756. */
  31757. mxMinimumCycleRemover.prototype.layout = null;
  31758. /**
  31759. * Function: execute
  31760. *
  31761. * Takes the graph detail and configuration information within the facade
  31762. * and creates the resulting laid out graph within that facade for further
  31763. * use.
  31764. */
  31765. mxMinimumCycleRemover.prototype.execute = function(parent)
  31766. {
  31767. var model = this.layout.getModel();
  31768. var seenNodes = new Object();
  31769. var unseenNodesArray = model.vertexMapper.getValues();
  31770. var unseenNodes = new Object();
  31771. for (var i = 0; i < unseenNodesArray.length; i++)
  31772. {
  31773. unseenNodes[unseenNodesArray[i].id] = unseenNodesArray[i];
  31774. }
  31775. // Perform a dfs through the internal model. If a cycle is found,
  31776. // reverse it.
  31777. var rootsArray = null;
  31778. if (model.roots != null)
  31779. {
  31780. var modelRoots = model.roots;
  31781. rootsArray = [];
  31782. for (var i = 0; i < modelRoots.length; i++)
  31783. {
  31784. rootsArray[i] = model.vertexMapper.get(modelRoots[i]);
  31785. }
  31786. }
  31787. model.visit(function(parent, node, connectingEdge, layer, seen)
  31788. {
  31789. // Check if the cell is in it's own ancestor list, if so
  31790. // invert the connecting edge and reverse the target/source
  31791. // relationship to that edge in the parent and the cell
  31792. if (node.isAncestor(parent))
  31793. {
  31794. connectingEdge.invert();
  31795. mxUtils.remove(connectingEdge, parent.connectsAsSource);
  31796. parent.connectsAsTarget.push(connectingEdge);
  31797. mxUtils.remove(connectingEdge, node.connectsAsTarget);
  31798. node.connectsAsSource.push(connectingEdge);
  31799. }
  31800. seenNodes[node.id] = node;
  31801. delete unseenNodes[node.id];
  31802. }, rootsArray, true, null);
  31803. // If there are any nodes that should be nodes that the dfs can miss
  31804. // these need to be processed with the dfs and the roots assigned
  31805. // correctly to form a correct internal model
  31806. var seenNodesCopy = mxUtils.clone(seenNodes, null, true);
  31807. // Pick a random cell and dfs from it
  31808. model.visit(function(parent, node, connectingEdge, layer, seen)
  31809. {
  31810. // Check if the cell is in it's own ancestor list, if so
  31811. // invert the connecting edge and reverse the target/source
  31812. // relationship to that edge in the parent and the cell
  31813. if (node.isAncestor(parent))
  31814. {
  31815. connectingEdge.invert();
  31816. mxUtils.remove(connectingEdge, parent.connectsAsSource);
  31817. node.connectsAsSource.push(connectingEdge);
  31818. parent.connectsAsTarget.push(connectingEdge);
  31819. mxUtils.remove(connectingEdge, node.connectsAsTarget);
  31820. }
  31821. seenNodes[node.id] = node;
  31822. delete unseenNodes[node.id];
  31823. }, unseenNodes, true, seenNodesCopy);
  31824. };
  31825. /**
  31826. * Copyright (c) 2006-2018, JGraph Ltd
  31827. * Copyright (c) 2006-2018, Gaudenz Alder
  31828. */
  31829. /**
  31830. * Class: mxCoordinateAssignment
  31831. *
  31832. * Sets the horizontal locations of node and edge dummy nodes on each layer.
  31833. * Uses median down and up weighings as well as heuristics to straighten edges as
  31834. * far as possible.
  31835. *
  31836. * Constructor: mxCoordinateAssignment
  31837. *
  31838. * Creates a coordinate assignment.
  31839. *
  31840. * Arguments:
  31841. *
  31842. * intraCellSpacing - the minimum buffer between cells on the same rank
  31843. * interRankCellSpacing - the minimum distance between cells on adjacent ranks
  31844. * orientation - the position of the root node(s) relative to the graph
  31845. * initialX - the leftmost coordinate node placement starts at
  31846. */
  31847. function mxCoordinateAssignment(layout, intraCellSpacing, interRankCellSpacing,
  31848. orientation, initialX, parallelEdgeSpacing)
  31849. {
  31850. this.layout = layout;
  31851. this.intraCellSpacing = intraCellSpacing;
  31852. this.interRankCellSpacing = interRankCellSpacing;
  31853. this.orientation = orientation;
  31854. this.initialX = initialX;
  31855. this.parallelEdgeSpacing = parallelEdgeSpacing;
  31856. };
  31857. /**
  31858. * Extends mxHierarchicalLayoutStage.
  31859. */
  31860. mxCoordinateAssignment.prototype = new mxHierarchicalLayoutStage();
  31861. mxCoordinateAssignment.prototype.constructor = mxCoordinateAssignment;
  31862. /**
  31863. * Variable: layout
  31864. *
  31865. * Reference to the enclosing <mxHierarchicalLayout>.
  31866. */
  31867. mxCoordinateAssignment.prototype.layout = null;
  31868. /**
  31869. * Variable: intraCellSpacing
  31870. *
  31871. * The minimum buffer between cells on the same rank. Default is 30.
  31872. */
  31873. mxCoordinateAssignment.prototype.intraCellSpacing = 30;
  31874. /**
  31875. * Variable: interRankCellSpacing
  31876. *
  31877. * The minimum distance between cells on adjacent ranks. Default is 100.
  31878. */
  31879. mxCoordinateAssignment.prototype.interRankCellSpacing = 100;
  31880. /**
  31881. * Variable: parallelEdgeSpacing
  31882. *
  31883. * The distance between each parallel edge on each ranks for long edges.
  31884. * Default is 10.
  31885. */
  31886. mxCoordinateAssignment.prototype.parallelEdgeSpacing = 10;
  31887. /**
  31888. * Variable: maxIterations
  31889. *
  31890. * The number of heuristic iterations to run. Default is 8.
  31891. */
  31892. mxCoordinateAssignment.prototype.maxIterations = 8;
  31893. /**
  31894. * Variable: prefHozEdgeSep
  31895. *
  31896. * The preferred horizontal distance between edges exiting a vertex Default is 5.
  31897. */
  31898. mxCoordinateAssignment.prototype.prefHozEdgeSep = 5;
  31899. /**
  31900. * Variable: prefVertEdgeOff
  31901. *
  31902. * The preferred vertical offset between edges exiting a vertex Default is 2.
  31903. */
  31904. mxCoordinateAssignment.prototype.prefVertEdgeOff = 2;
  31905. /**
  31906. * Variable: minEdgeJetty
  31907. *
  31908. * The minimum distance for an edge jetty from a vertex Default is 12.
  31909. */
  31910. mxCoordinateAssignment.prototype.minEdgeJetty = 12;
  31911. /**
  31912. * Variable: channelBuffer
  31913. *
  31914. * The size of the vertical buffer in the center of inter-rank channels
  31915. * where edge control points should not be placed Default is 4.
  31916. */
  31917. mxCoordinateAssignment.prototype.channelBuffer = 4;
  31918. /**
  31919. * Variable: jettyPositions
  31920. *
  31921. * Map of internal edges and (x,y) pair of positions of the start and end jetty
  31922. * for that edge where it connects to the source and target vertices.
  31923. * Note this should technically be a WeakHashMap, but since JS does not
  31924. * have an equivalent, housekeeping must be performed before using.
  31925. * i.e. check all edges are still in the model and clear the values.
  31926. * Note that the y co-ord is the offset of the jetty, not the
  31927. * absolute point
  31928. */
  31929. mxCoordinateAssignment.prototype.jettyPositions = null;
  31930. /**
  31931. * Variable: orientation
  31932. *
  31933. * The position of the root ( start ) node(s) relative to the rest of the
  31934. * laid out graph. Default is <mxConstants.DIRECTION_NORTH>.
  31935. */
  31936. mxCoordinateAssignment.prototype.orientation = mxConstants.DIRECTION_NORTH;
  31937. /**
  31938. * Variable: initialX
  31939. *
  31940. * The minimum x position node placement starts at
  31941. */
  31942. mxCoordinateAssignment.prototype.initialX = null;
  31943. /**
  31944. * Variable: limitX
  31945. *
  31946. * The maximum x value this positioning lays up to
  31947. */
  31948. mxCoordinateAssignment.prototype.limitX = null;
  31949. /**
  31950. * Variable: currentXDelta
  31951. *
  31952. * The sum of x-displacements for the current iteration
  31953. */
  31954. mxCoordinateAssignment.prototype.currentXDelta = null;
  31955. /**
  31956. * Variable: widestRank
  31957. *
  31958. * The rank that has the widest x position
  31959. */
  31960. mxCoordinateAssignment.prototype.widestRank = null;
  31961. /**
  31962. * Variable: rankTopY
  31963. *
  31964. * Internal cache of top-most values of Y for each rank
  31965. */
  31966. mxCoordinateAssignment.prototype.rankTopY = null;
  31967. /**
  31968. * Variable: rankBottomY
  31969. *
  31970. * Internal cache of bottom-most value of Y for each rank
  31971. */
  31972. mxCoordinateAssignment.prototype.rankBottomY = null;
  31973. /**
  31974. * Variable: widestRankValue
  31975. *
  31976. * The X-coordinate of the edge of the widest rank
  31977. */
  31978. mxCoordinateAssignment.prototype.widestRankValue = null;
  31979. /**
  31980. * Variable: rankWidths
  31981. *
  31982. * The width of all the ranks
  31983. */
  31984. mxCoordinateAssignment.prototype.rankWidths = null;
  31985. /**
  31986. * Variable: rankY
  31987. *
  31988. * The Y-coordinate of all the ranks
  31989. */
  31990. mxCoordinateAssignment.prototype.rankY = null;
  31991. /**
  31992. * Variable: fineTuning
  31993. *
  31994. * Whether or not to perform local optimisations and iterate multiple times
  31995. * through the algorithm. Default is true.
  31996. */
  31997. mxCoordinateAssignment.prototype.fineTuning = true;
  31998. /**
  31999. * Variable: nextLayerConnectedCache
  32000. *
  32001. * A store of connections to the layer above for speed
  32002. */
  32003. mxCoordinateAssignment.prototype.nextLayerConnectedCache = null;
  32004. /**
  32005. * Variable: previousLayerConnectedCache
  32006. *
  32007. * A store of connections to the layer below for speed
  32008. */
  32009. mxCoordinateAssignment.prototype.previousLayerConnectedCache = null;
  32010. /**
  32011. * Variable: groupPadding
  32012. *
  32013. * Padding added to resized parents Default is 10.
  32014. */
  32015. mxCoordinateAssignment.prototype.groupPadding = 10;
  32016. /**
  32017. * Utility method to display current positions
  32018. */
  32019. mxCoordinateAssignment.prototype.printStatus = function()
  32020. {
  32021. var model = this.layout.getModel();
  32022. mxLog.show();
  32023. mxLog.writeln('======Coord assignment debug=======');
  32024. for (var j = 0; j < model.ranks.length; j++)
  32025. {
  32026. mxLog.write('Rank ', j, ' : ' );
  32027. var rank = model.ranks[j];
  32028. for (var k = 0; k < rank.length; k++)
  32029. {
  32030. var cell = rank[k];
  32031. mxLog.write(cell.getGeneralPurposeVariable(j), ' ');
  32032. }
  32033. mxLog.writeln();
  32034. }
  32035. mxLog.writeln('====================================');
  32036. };
  32037. /**
  32038. * Function: execute
  32039. *
  32040. * A basic horizontal coordinate assignment algorithm
  32041. */
  32042. mxCoordinateAssignment.prototype.execute = function(parent)
  32043. {
  32044. this.jettyPositions = Object();
  32045. var model = this.layout.getModel();
  32046. this.currentXDelta = 0.0;
  32047. this.initialCoords(this.layout.getGraph(), model);
  32048. // this.printStatus();
  32049. if (this.fineTuning)
  32050. {
  32051. this.minNode(model);
  32052. }
  32053. var bestXDelta = 100000000.0;
  32054. if (this.fineTuning)
  32055. {
  32056. for (var i = 0; i < this.maxIterations; i++)
  32057. {
  32058. // this.printStatus();
  32059. // Median Heuristic
  32060. if (i != 0)
  32061. {
  32062. this.medianPos(i, model);
  32063. this.minNode(model);
  32064. }
  32065. // if the total offset is less for the current positioning,
  32066. // there are less heavily angled edges and so the current
  32067. // positioning is used
  32068. if (this.currentXDelta < bestXDelta)
  32069. {
  32070. for (var j = 0; j < model.ranks.length; j++)
  32071. {
  32072. var rank = model.ranks[j];
  32073. for (var k = 0; k < rank.length; k++)
  32074. {
  32075. var cell = rank[k];
  32076. cell.setX(j, cell.getGeneralPurposeVariable(j));
  32077. }
  32078. }
  32079. bestXDelta = this.currentXDelta;
  32080. }
  32081. else
  32082. {
  32083. // Restore the best positions
  32084. for (var j = 0; j < model.ranks.length; j++)
  32085. {
  32086. var rank = model.ranks[j];
  32087. for (var k = 0; k < rank.length; k++)
  32088. {
  32089. var cell = rank[k];
  32090. cell.setGeneralPurposeVariable(j, cell.getX(j));
  32091. }
  32092. }
  32093. }
  32094. this.minPath(this.layout.getGraph(), model);
  32095. this.currentXDelta = 0;
  32096. }
  32097. }
  32098. this.setCellLocations(this.layout.getGraph(), model);
  32099. };
  32100. /**
  32101. * Function: minNode
  32102. *
  32103. * Performs one median positioning sweep in both directions
  32104. */
  32105. mxCoordinateAssignment.prototype.minNode = function(model)
  32106. {
  32107. // Queue all nodes
  32108. var nodeList = [];
  32109. // Need to be able to map from cell to cellWrapper
  32110. var map = new mxDictionary();
  32111. var rank = [];
  32112. for (var i = 0; i <= model.maxRank; i++)
  32113. {
  32114. rank[i] = model.ranks[i];
  32115. for (var j = 0; j < rank[i].length; j++)
  32116. {
  32117. // Use the weight to store the rank and visited to store whether
  32118. // or not the cell is in the list
  32119. var node = rank[i][j];
  32120. var nodeWrapper = new WeightedCellSorter(node, i);
  32121. nodeWrapper.rankIndex = j;
  32122. nodeWrapper.visited = true;
  32123. nodeList.push(nodeWrapper);
  32124. map.put(node, nodeWrapper);
  32125. }
  32126. }
  32127. // Set a limit of the maximum number of times we will access the queue
  32128. // in case a loop appears
  32129. var maxTries = nodeList.length * 10;
  32130. var count = 0;
  32131. // Don't move cell within this value of their median
  32132. var tolerance = 1;
  32133. while (nodeList.length > 0 && count <= maxTries)
  32134. {
  32135. var cellWrapper = nodeList.shift();
  32136. var cell = cellWrapper.cell;
  32137. var rankValue = cellWrapper.weightedValue;
  32138. var rankIndex = parseInt(cellWrapper.rankIndex);
  32139. var nextLayerConnectedCells = cell.getNextLayerConnectedCells(rankValue);
  32140. var previousLayerConnectedCells = cell.getPreviousLayerConnectedCells(rankValue);
  32141. var numNextLayerConnected = nextLayerConnectedCells.length;
  32142. var numPreviousLayerConnected = previousLayerConnectedCells.length;
  32143. var medianNextLevel = this.medianXValue(nextLayerConnectedCells,
  32144. rankValue + 1);
  32145. var medianPreviousLevel = this.medianXValue(previousLayerConnectedCells,
  32146. rankValue - 1);
  32147. var numConnectedNeighbours = numNextLayerConnected
  32148. + numPreviousLayerConnected;
  32149. var currentPosition = cell.getGeneralPurposeVariable(rankValue);
  32150. var cellMedian = currentPosition;
  32151. if (numConnectedNeighbours > 0)
  32152. {
  32153. cellMedian = (medianNextLevel * numNextLayerConnected + medianPreviousLevel
  32154. * numPreviousLayerConnected)
  32155. / numConnectedNeighbours;
  32156. }
  32157. // Flag storing whether or not position has changed
  32158. var positionChanged = false;
  32159. if (cellMedian < currentPosition - tolerance)
  32160. {
  32161. if (rankIndex == 0)
  32162. {
  32163. cell.setGeneralPurposeVariable(rankValue, cellMedian);
  32164. positionChanged = true;
  32165. }
  32166. else
  32167. {
  32168. var leftCell = rank[rankValue][rankIndex - 1];
  32169. var leftLimit = leftCell
  32170. .getGeneralPurposeVariable(rankValue);
  32171. leftLimit = leftLimit + leftCell.width / 2
  32172. + this.intraCellSpacing + cell.width / 2;
  32173. if (leftLimit < cellMedian)
  32174. {
  32175. cell.setGeneralPurposeVariable(rankValue, cellMedian);
  32176. positionChanged = true;
  32177. }
  32178. else if (leftLimit < cell
  32179. .getGeneralPurposeVariable(rankValue)
  32180. - tolerance)
  32181. {
  32182. cell.setGeneralPurposeVariable(rankValue, leftLimit);
  32183. positionChanged = true;
  32184. }
  32185. }
  32186. }
  32187. else if (cellMedian > currentPosition + tolerance)
  32188. {
  32189. var rankSize = rank[rankValue].length;
  32190. if (rankIndex == rankSize - 1)
  32191. {
  32192. cell.setGeneralPurposeVariable(rankValue, cellMedian);
  32193. positionChanged = true;
  32194. }
  32195. else
  32196. {
  32197. var rightCell = rank[rankValue][rankIndex + 1];
  32198. var rightLimit = rightCell
  32199. .getGeneralPurposeVariable(rankValue);
  32200. rightLimit = rightLimit - rightCell.width / 2
  32201. - this.intraCellSpacing - cell.width / 2;
  32202. if (rightLimit > cellMedian)
  32203. {
  32204. cell.setGeneralPurposeVariable(rankValue, cellMedian);
  32205. positionChanged = true;
  32206. }
  32207. else if (rightLimit > cell
  32208. .getGeneralPurposeVariable(rankValue)
  32209. + tolerance)
  32210. {
  32211. cell.setGeneralPurposeVariable(rankValue, rightLimit);
  32212. positionChanged = true;
  32213. }
  32214. }
  32215. }
  32216. if (positionChanged)
  32217. {
  32218. // Add connected nodes to map and list
  32219. for (var i = 0; i < nextLayerConnectedCells.length; i++)
  32220. {
  32221. var connectedCell = nextLayerConnectedCells[i];
  32222. var connectedCellWrapper = map.get(connectedCell);
  32223. if (connectedCellWrapper != null)
  32224. {
  32225. if (connectedCellWrapper.visited == false)
  32226. {
  32227. connectedCellWrapper.visited = true;
  32228. nodeList.push(connectedCellWrapper);
  32229. }
  32230. }
  32231. }
  32232. // Add connected nodes to map and list
  32233. for (var i = 0; i < previousLayerConnectedCells.length; i++)
  32234. {
  32235. var connectedCell = previousLayerConnectedCells[i];
  32236. var connectedCellWrapper = map.get(connectedCell);
  32237. if (connectedCellWrapper != null)
  32238. {
  32239. if (connectedCellWrapper.visited == false)
  32240. {
  32241. connectedCellWrapper.visited = true;
  32242. nodeList.push(connectedCellWrapper);
  32243. }
  32244. }
  32245. }
  32246. }
  32247. cellWrapper.visited = false;
  32248. count++;
  32249. }
  32250. };
  32251. /**
  32252. * Function: medianPos
  32253. *
  32254. * Performs one median positioning sweep in one direction
  32255. *
  32256. * Parameters:
  32257. *
  32258. * i - the iteration of the whole process
  32259. * model - an internal model of the hierarchical layout
  32260. */
  32261. mxCoordinateAssignment.prototype.medianPos = function(i, model)
  32262. {
  32263. // Reverse sweep direction each time through this method
  32264. var downwardSweep = (i % 2 == 0);
  32265. if (downwardSweep)
  32266. {
  32267. for (var j = model.maxRank; j > 0; j--)
  32268. {
  32269. this.rankMedianPosition(j - 1, model, j);
  32270. }
  32271. }
  32272. else
  32273. {
  32274. for (var j = 0; j < model.maxRank - 1; j++)
  32275. {
  32276. this.rankMedianPosition(j + 1, model, j);
  32277. }
  32278. }
  32279. };
  32280. /**
  32281. * Function: rankMedianPosition
  32282. *
  32283. * Performs median minimisation over one rank.
  32284. *
  32285. * Parameters:
  32286. *
  32287. * rankValue - the layer number of this rank
  32288. * model - an internal model of the hierarchical layout
  32289. * nextRankValue - the layer number whose connected cels are to be laid out
  32290. * relative to
  32291. */
  32292. mxCoordinateAssignment.prototype.rankMedianPosition = function(rankValue, model, nextRankValue)
  32293. {
  32294. var rank = model.ranks[rankValue];
  32295. // Form an array of the order in which the cell are to be processed
  32296. // , the order is given by the weighted sum of the in or out edges,
  32297. // depending on whether we're traveling up or down the hierarchy.
  32298. var weightedValues = [];
  32299. var cellMap = new Object();
  32300. for (var i = 0; i < rank.length; i++)
  32301. {
  32302. var currentCell = rank[i];
  32303. weightedValues[i] = new WeightedCellSorter();
  32304. weightedValues[i].cell = currentCell;
  32305. weightedValues[i].rankIndex = i;
  32306. cellMap[currentCell.id] = weightedValues[i];
  32307. var nextLayerConnectedCells = null;
  32308. if (nextRankValue < rankValue)
  32309. {
  32310. nextLayerConnectedCells = currentCell
  32311. .getPreviousLayerConnectedCells(rankValue);
  32312. }
  32313. else
  32314. {
  32315. nextLayerConnectedCells = currentCell
  32316. .getNextLayerConnectedCells(rankValue);
  32317. }
  32318. // Calculate the weighing based on this node type and those this
  32319. // node is connected to on the next layer
  32320. weightedValues[i].weightedValue = this.calculatedWeightedValue(
  32321. currentCell, nextLayerConnectedCells);
  32322. }
  32323. weightedValues.sort(WeightedCellSorter.prototype.compare);
  32324. // Set the new position of each node within the rank using
  32325. // its temp variable
  32326. for (var i = 0; i < weightedValues.length; i++)
  32327. {
  32328. var numConnectionsNextLevel = 0;
  32329. var cell = weightedValues[i].cell;
  32330. var nextLayerConnectedCells = null;
  32331. var medianNextLevel = 0;
  32332. if (nextRankValue < rankValue)
  32333. {
  32334. nextLayerConnectedCells = cell.getPreviousLayerConnectedCells(
  32335. rankValue).slice();
  32336. }
  32337. else
  32338. {
  32339. nextLayerConnectedCells = cell.getNextLayerConnectedCells(
  32340. rankValue).slice();
  32341. }
  32342. if (nextLayerConnectedCells != null)
  32343. {
  32344. numConnectionsNextLevel = nextLayerConnectedCells.length;
  32345. if (numConnectionsNextLevel > 0)
  32346. {
  32347. medianNextLevel = this.medianXValue(nextLayerConnectedCells,
  32348. nextRankValue);
  32349. }
  32350. else
  32351. {
  32352. // For case of no connections on the next level set the
  32353. // median to be the current position and try to be
  32354. // positioned there
  32355. medianNextLevel = cell.getGeneralPurposeVariable(rankValue);
  32356. }
  32357. }
  32358. var leftBuffer = 0.0;
  32359. var leftLimit = -100000000.0;
  32360. for (var j = weightedValues[i].rankIndex - 1; j >= 0;)
  32361. {
  32362. var weightedValue = cellMap[rank[j].id];
  32363. if (weightedValue != null)
  32364. {
  32365. var leftCell = weightedValue.cell;
  32366. if (weightedValue.visited)
  32367. {
  32368. // The left limit is the right hand limit of that
  32369. // cell plus any allowance for unallocated cells
  32370. // in-between
  32371. leftLimit = leftCell
  32372. .getGeneralPurposeVariable(rankValue)
  32373. + leftCell.width
  32374. / 2.0
  32375. + this.intraCellSpacing
  32376. + leftBuffer + cell.width / 2.0;
  32377. j = -1;
  32378. }
  32379. else
  32380. {
  32381. leftBuffer += leftCell.width + this.intraCellSpacing;
  32382. j--;
  32383. }
  32384. }
  32385. }
  32386. var rightBuffer = 0.0;
  32387. var rightLimit = 100000000.0;
  32388. for (var j = weightedValues[i].rankIndex + 1; j < weightedValues.length;)
  32389. {
  32390. var weightedValue = cellMap[rank[j].id];
  32391. if (weightedValue != null)
  32392. {
  32393. var rightCell = weightedValue.cell;
  32394. if (weightedValue.visited)
  32395. {
  32396. // The left limit is the right hand limit of that
  32397. // cell plus any allowance for unallocated cells
  32398. // in-between
  32399. rightLimit = rightCell
  32400. .getGeneralPurposeVariable(rankValue)
  32401. - rightCell.width
  32402. / 2.0
  32403. - this.intraCellSpacing
  32404. - rightBuffer - cell.width / 2.0;
  32405. j = weightedValues.length;
  32406. }
  32407. else
  32408. {
  32409. rightBuffer += rightCell.width + this.intraCellSpacing;
  32410. j++;
  32411. }
  32412. }
  32413. }
  32414. if (medianNextLevel >= leftLimit && medianNextLevel <= rightLimit)
  32415. {
  32416. cell.setGeneralPurposeVariable(rankValue, medianNextLevel);
  32417. }
  32418. else if (medianNextLevel < leftLimit)
  32419. {
  32420. // Couldn't place at median value, place as close to that
  32421. // value as possible
  32422. cell.setGeneralPurposeVariable(rankValue, leftLimit);
  32423. this.currentXDelta += leftLimit - medianNextLevel;
  32424. }
  32425. else if (medianNextLevel > rightLimit)
  32426. {
  32427. // Couldn't place at median value, place as close to that
  32428. // value as possible
  32429. cell.setGeneralPurposeVariable(rankValue, rightLimit);
  32430. this.currentXDelta += medianNextLevel - rightLimit;
  32431. }
  32432. weightedValues[i].visited = true;
  32433. }
  32434. };
  32435. /**
  32436. * Function: calculatedWeightedValue
  32437. *
  32438. * Calculates the priority the specified cell has based on the type of its
  32439. * cell and the cells it is connected to on the next layer
  32440. *
  32441. * Parameters:
  32442. *
  32443. * currentCell - the cell whose weight is to be calculated
  32444. * collection - the cells the specified cell is connected to
  32445. */
  32446. mxCoordinateAssignment.prototype.calculatedWeightedValue = function(currentCell, collection)
  32447. {
  32448. var totalWeight = 0;
  32449. for (var i = 0; i < collection.length; i++)
  32450. {
  32451. var cell = collection[i];
  32452. if (currentCell.isVertex() && cell.isVertex())
  32453. {
  32454. totalWeight++;
  32455. }
  32456. else if (currentCell.isEdge() && cell.isEdge())
  32457. {
  32458. totalWeight += 8;
  32459. }
  32460. else
  32461. {
  32462. totalWeight += 2;
  32463. }
  32464. }
  32465. return totalWeight;
  32466. };
  32467. /**
  32468. * Function: medianXValue
  32469. *
  32470. * Calculates the median position of the connected cell on the specified
  32471. * rank
  32472. *
  32473. * Parameters:
  32474. *
  32475. * connectedCells - the cells the candidate connects to on this level
  32476. * rankValue - the layer number of this rank
  32477. */
  32478. mxCoordinateAssignment.prototype.medianXValue = function(connectedCells, rankValue)
  32479. {
  32480. if (connectedCells.length == 0)
  32481. {
  32482. return 0;
  32483. }
  32484. var medianValues = [];
  32485. for (var i = 0; i < connectedCells.length; i++)
  32486. {
  32487. medianValues[i] = connectedCells[i].getGeneralPurposeVariable(rankValue);
  32488. }
  32489. medianValues.sort(function(a,b){return a - b;});
  32490. if (connectedCells.length % 2 == 1)
  32491. {
  32492. // For odd numbers of adjacent vertices return the median
  32493. return medianValues[Math.floor(connectedCells.length / 2)];
  32494. }
  32495. else
  32496. {
  32497. var medianPoint = connectedCells.length / 2;
  32498. var leftMedian = medianValues[medianPoint - 1];
  32499. var rightMedian = medianValues[medianPoint];
  32500. return ((leftMedian + rightMedian) / 2);
  32501. }
  32502. };
  32503. /**
  32504. * Function: initialCoords
  32505. *
  32506. * Sets up the layout in an initial positioning. The ranks are all centered
  32507. * as much as possible along the middle vertex in each rank. The other cells
  32508. * are then placed as close as possible on either side.
  32509. *
  32510. * Parameters:
  32511. *
  32512. * facade - the facade describing the input graph
  32513. * model - an internal model of the hierarchical layout
  32514. */
  32515. mxCoordinateAssignment.prototype.initialCoords = function(facade, model)
  32516. {
  32517. this.calculateWidestRank(facade, model);
  32518. // Sweep up and down from the widest rank
  32519. for (var i = this.widestRank; i >= 0; i--)
  32520. {
  32521. if (i < model.maxRank)
  32522. {
  32523. this.rankCoordinates(i, facade, model);
  32524. }
  32525. }
  32526. for (var i = this.widestRank+1; i <= model.maxRank; i++)
  32527. {
  32528. if (i > 0)
  32529. {
  32530. this.rankCoordinates(i, facade, model);
  32531. }
  32532. }
  32533. };
  32534. /**
  32535. * Function: rankCoordinates
  32536. *
  32537. * Sets up the layout in an initial positioning. All the first cells in each
  32538. * rank are moved to the left and the rest of the rank inserted as close
  32539. * together as their size and buffering permits. This method works on just
  32540. * the specified rank.
  32541. *
  32542. * Parameters:
  32543. *
  32544. * rankValue - the current rank being processed
  32545. * graph - the facade describing the input graph
  32546. * model - an internal model of the hierarchical layout
  32547. */
  32548. mxCoordinateAssignment.prototype.rankCoordinates = function(rankValue, graph, model)
  32549. {
  32550. var rank = model.ranks[rankValue];
  32551. var maxY = 0.0;
  32552. var localX = this.initialX + (this.widestRankValue - this.rankWidths[rankValue])
  32553. / 2;
  32554. // Store whether or not any of the cells' bounds were unavailable so
  32555. // to only issue the warning once for all cells
  32556. var boundsWarning = false;
  32557. for (var i = 0; i < rank.length; i++)
  32558. {
  32559. var node = rank[i];
  32560. if (node.isVertex())
  32561. {
  32562. var bounds = this.layout.getVertexBounds(node.cell);
  32563. if (bounds != null)
  32564. {
  32565. if (this.orientation == mxConstants.DIRECTION_NORTH ||
  32566. this.orientation == mxConstants.DIRECTION_SOUTH)
  32567. {
  32568. node.width = bounds.width;
  32569. node.height = bounds.height;
  32570. }
  32571. else
  32572. {
  32573. node.width = bounds.height;
  32574. node.height = bounds.width;
  32575. }
  32576. }
  32577. else
  32578. {
  32579. boundsWarning = true;
  32580. }
  32581. maxY = Math.max(maxY, node.height);
  32582. }
  32583. else if (node.isEdge())
  32584. {
  32585. // The width is the number of additional parallel edges
  32586. // time the parallel edge spacing
  32587. var numEdges = 1;
  32588. if (node.edges != null)
  32589. {
  32590. numEdges = node.edges.length;
  32591. }
  32592. else
  32593. {
  32594. mxLog.warn('edge.edges is null');
  32595. }
  32596. node.width = (numEdges - 1) * this.parallelEdgeSpacing;
  32597. }
  32598. // Set the initial x-value as being the best result so far
  32599. localX += node.width / 2.0;
  32600. node.setX(rankValue, localX);
  32601. node.setGeneralPurposeVariable(rankValue, localX);
  32602. localX += node.width / 2.0;
  32603. localX += this.intraCellSpacing;
  32604. }
  32605. if (boundsWarning == true)
  32606. {
  32607. mxLog.warn('At least one cell has no bounds');
  32608. }
  32609. };
  32610. /**
  32611. * Function: calculateWidestRank
  32612. *
  32613. * Calculates the width rank in the hierarchy. Also set the y value of each
  32614. * rank whilst performing the calculation
  32615. *
  32616. * Parameters:
  32617. *
  32618. * graph - the facade describing the input graph
  32619. * model - an internal model of the hierarchical layout
  32620. */
  32621. mxCoordinateAssignment.prototype.calculateWidestRank = function(graph, model)
  32622. {
  32623. // Starting y co-ordinate
  32624. var y = -this.interRankCellSpacing;
  32625. // Track the widest cell on the last rank since the y
  32626. // difference depends on it
  32627. var lastRankMaxCellHeight = 0.0;
  32628. this.rankWidths = [];
  32629. this.rankY = [];
  32630. for (var rankValue = model.maxRank; rankValue >= 0; rankValue--)
  32631. {
  32632. // Keep track of the widest cell on this rank
  32633. var maxCellHeight = 0.0;
  32634. var rank = model.ranks[rankValue];
  32635. var localX = this.initialX;
  32636. // Store whether or not any of the cells' bounds were unavailable so
  32637. // to only issue the warning once for all cells
  32638. var boundsWarning = false;
  32639. for (var i = 0; i < rank.length; i++)
  32640. {
  32641. var node = rank[i];
  32642. if (node.isVertex())
  32643. {
  32644. var bounds = this.layout.getVertexBounds(node.cell);
  32645. if (bounds != null)
  32646. {
  32647. if (this.orientation == mxConstants.DIRECTION_NORTH ||
  32648. this.orientation == mxConstants.DIRECTION_SOUTH)
  32649. {
  32650. node.width = bounds.width;
  32651. node.height = bounds.height;
  32652. }
  32653. else
  32654. {
  32655. node.width = bounds.height;
  32656. node.height = bounds.width;
  32657. }
  32658. }
  32659. else
  32660. {
  32661. boundsWarning = true;
  32662. }
  32663. maxCellHeight = Math.max(maxCellHeight, node.height);
  32664. }
  32665. else if (node.isEdge())
  32666. {
  32667. // The width is the number of additional parallel edges
  32668. // time the parallel edge spacing
  32669. var numEdges = 1;
  32670. if (node.edges != null)
  32671. {
  32672. numEdges = node.edges.length;
  32673. }
  32674. else
  32675. {
  32676. mxLog.warn('edge.edges is null');
  32677. }
  32678. node.width = (numEdges - 1) * this.parallelEdgeSpacing;
  32679. }
  32680. // Set the initial x-value as being the best result so far
  32681. localX += node.width / 2.0;
  32682. node.setX(rankValue, localX);
  32683. node.setGeneralPurposeVariable(rankValue, localX);
  32684. localX += node.width / 2.0;
  32685. localX += this.intraCellSpacing;
  32686. if (localX > this.widestRankValue)
  32687. {
  32688. this.widestRankValue = localX;
  32689. this.widestRank = rankValue;
  32690. }
  32691. this.rankWidths[rankValue] = localX;
  32692. }
  32693. if (boundsWarning == true)
  32694. {
  32695. mxLog.warn('At least one cell has no bounds');
  32696. }
  32697. this.rankY[rankValue] = y;
  32698. var distanceToNextRank = maxCellHeight / 2.0
  32699. + lastRankMaxCellHeight / 2.0 + this.interRankCellSpacing;
  32700. lastRankMaxCellHeight = maxCellHeight;
  32701. if (this.orientation == mxConstants.DIRECTION_NORTH ||
  32702. this.orientation == mxConstants.DIRECTION_WEST)
  32703. {
  32704. y += distanceToNextRank;
  32705. }
  32706. else
  32707. {
  32708. y -= distanceToNextRank;
  32709. }
  32710. for (var i = 0; i < rank.length; i++)
  32711. {
  32712. var cell = rank[i];
  32713. cell.setY(rankValue, y);
  32714. }
  32715. }
  32716. };
  32717. /**
  32718. * Function: minPath
  32719. *
  32720. * Straightens out chains of virtual nodes where possibleacade to those stored after this layout
  32721. * processing step has completed.
  32722. *
  32723. * Parameters:
  32724. *
  32725. * graph - the facade describing the input graph
  32726. * model - an internal model of the hierarchical layout
  32727. */
  32728. mxCoordinateAssignment.prototype.minPath = function(graph, model)
  32729. {
  32730. // Work down and up each edge with at least 2 control points
  32731. // trying to straighten each one out. If the same number of
  32732. // straight segments are formed in both directions, the
  32733. // preferred direction used is the one where the final
  32734. // control points have the least offset from the connectable
  32735. // region of the terminating vertices
  32736. var edges = model.edgeMapper.getValues();
  32737. for (var j = 0; j < edges.length; j++)
  32738. {
  32739. var cell = edges[j];
  32740. if (cell.maxRank - cell.minRank - 1 < 1)
  32741. {
  32742. continue;
  32743. }
  32744. // At least two virtual nodes in the edge
  32745. // Check first whether the edge is already straight
  32746. var referenceX = cell
  32747. .getGeneralPurposeVariable(cell.minRank + 1);
  32748. var edgeStraight = true;
  32749. var refSegCount = 0;
  32750. for (var i = cell.minRank + 2; i < cell.maxRank; i++)
  32751. {
  32752. var x = cell.getGeneralPurposeVariable(i);
  32753. if (referenceX != x)
  32754. {
  32755. edgeStraight = false;
  32756. referenceX = x;
  32757. }
  32758. else
  32759. {
  32760. refSegCount++;
  32761. }
  32762. }
  32763. if (!edgeStraight)
  32764. {
  32765. var upSegCount = 0;
  32766. var downSegCount = 0;
  32767. var upXPositions = [];
  32768. var downXPositions = [];
  32769. var currentX = cell.getGeneralPurposeVariable(cell.minRank + 1);
  32770. for (var i = cell.minRank + 1; i < cell.maxRank - 1; i++)
  32771. {
  32772. // Attempt to straight out the control point on the
  32773. // next segment up with the current control point.
  32774. var nextX = cell.getX(i + 1);
  32775. if (currentX == nextX)
  32776. {
  32777. upXPositions[i - cell.minRank - 1] = currentX;
  32778. upSegCount++;
  32779. }
  32780. else if (this.repositionValid(model, cell, i + 1, currentX))
  32781. {
  32782. upXPositions[i - cell.minRank - 1] = currentX;
  32783. upSegCount++;
  32784. // Leave currentX at same value
  32785. }
  32786. else
  32787. {
  32788. upXPositions[i - cell.minRank - 1] = nextX;
  32789. currentX = nextX;
  32790. }
  32791. }
  32792. currentX = cell.getX(i);
  32793. for (var i = cell.maxRank - 1; i > cell.minRank + 1; i--)
  32794. {
  32795. // Attempt to straight out the control point on the
  32796. // next segment down with the current control point.
  32797. var nextX = cell.getX(i - 1);
  32798. if (currentX == nextX)
  32799. {
  32800. downXPositions[i - cell.minRank - 2] = currentX;
  32801. downSegCount++;
  32802. }
  32803. else if (this.repositionValid(model, cell, i - 1, currentX))
  32804. {
  32805. downXPositions[i - cell.minRank - 2] = currentX;
  32806. downSegCount++;
  32807. // Leave currentX at same value
  32808. }
  32809. else
  32810. {
  32811. downXPositions[i - cell.minRank - 2] = cell.getX(i-1);
  32812. currentX = nextX;
  32813. }
  32814. }
  32815. if (downSegCount > refSegCount || upSegCount > refSegCount)
  32816. {
  32817. if (downSegCount >= upSegCount)
  32818. {
  32819. // Apply down calculation values
  32820. for (var i = cell.maxRank - 2; i > cell.minRank; i--)
  32821. {
  32822. cell.setX(i, downXPositions[i - cell.minRank - 1]);
  32823. }
  32824. }
  32825. else if (upSegCount > downSegCount)
  32826. {
  32827. // Apply up calculation values
  32828. for (var i = cell.minRank + 2; i < cell.maxRank; i++)
  32829. {
  32830. cell.setX(i, upXPositions[i - cell.minRank - 2]);
  32831. }
  32832. }
  32833. else
  32834. {
  32835. // Neither direction provided a favourable result
  32836. // But both calculations are better than the
  32837. // existing solution, so apply the one with minimal
  32838. // offset to attached vertices at either end.
  32839. }
  32840. }
  32841. }
  32842. }
  32843. };
  32844. /**
  32845. * Function: repositionValid
  32846. *
  32847. * Determines whether or not a node may be moved to the specified x
  32848. * position on the specified rank
  32849. *
  32850. * Parameters:
  32851. *
  32852. * model - the layout model
  32853. * cell - the cell being analysed
  32854. * rank - the layer of the cell
  32855. * position - the x position being sought
  32856. */
  32857. mxCoordinateAssignment.prototype.repositionValid = function(model, cell, rank, position)
  32858. {
  32859. var rankArray = model.ranks[rank];
  32860. var rankIndex = -1;
  32861. for (var i = 0; i < rankArray.length; i++)
  32862. {
  32863. if (cell == rankArray[i])
  32864. {
  32865. rankIndex = i;
  32866. break;
  32867. }
  32868. }
  32869. if (rankIndex < 0)
  32870. {
  32871. return false;
  32872. }
  32873. var currentX = cell.getGeneralPurposeVariable(rank);
  32874. if (position < currentX)
  32875. {
  32876. // Trying to move node to the left.
  32877. if (rankIndex == 0)
  32878. {
  32879. // Left-most node, can move anywhere
  32880. return true;
  32881. }
  32882. var leftCell = rankArray[rankIndex - 1];
  32883. var leftLimit = leftCell.getGeneralPurposeVariable(rank);
  32884. leftLimit = leftLimit + leftCell.width / 2
  32885. + this.intraCellSpacing + cell.width / 2;
  32886. if (leftLimit <= position)
  32887. {
  32888. return true;
  32889. }
  32890. else
  32891. {
  32892. return false;
  32893. }
  32894. }
  32895. else if (position > currentX)
  32896. {
  32897. // Trying to move node to the right.
  32898. if (rankIndex == rankArray.length - 1)
  32899. {
  32900. // Right-most node, can move anywhere
  32901. return true;
  32902. }
  32903. var rightCell = rankArray[rankIndex + 1];
  32904. var rightLimit = rightCell.getGeneralPurposeVariable(rank);
  32905. rightLimit = rightLimit - rightCell.width / 2
  32906. - this.intraCellSpacing - cell.width / 2;
  32907. if (rightLimit >= position)
  32908. {
  32909. return true;
  32910. }
  32911. else
  32912. {
  32913. return false;
  32914. }
  32915. }
  32916. return true;
  32917. };
  32918. /**
  32919. * Function: setCellLocations
  32920. *
  32921. * Sets the cell locations in the facade to those stored after this layout
  32922. * processing step has completed.
  32923. *
  32924. * Parameters:
  32925. *
  32926. * graph - the input graph
  32927. * model - the layout model
  32928. */
  32929. mxCoordinateAssignment.prototype.setCellLocations = function(graph, model)
  32930. {
  32931. this.rankTopY = [];
  32932. this.rankBottomY = [];
  32933. for (var i = 0; i < model.ranks.length; i++)
  32934. {
  32935. this.rankTopY[i] = Number.MAX_VALUE;
  32936. this.rankBottomY[i] = -Number.MAX_VALUE;
  32937. }
  32938. var vertices = model.vertexMapper.getValues();
  32939. // Process vertices all first, since they define the lower and
  32940. // limits of each rank. Between these limits lie the channels
  32941. // where the edges can be routed across the graph
  32942. for (var i = 0; i < vertices.length; i++)
  32943. {
  32944. this.setVertexLocation(vertices[i]);
  32945. }
  32946. // Post process edge styles. Needs the vertex locations set for initial
  32947. // values of the top and bottoms of each rank
  32948. if (this.layout.edgeStyle == mxHierarchicalEdgeStyle.ORTHOGONAL
  32949. || this.layout.edgeStyle == mxHierarchicalEdgeStyle.POLYLINE
  32950. || this.layout.edgeStyle == mxHierarchicalEdgeStyle.CURVE)
  32951. {
  32952. this.localEdgeProcessing(model);
  32953. }
  32954. var edges = model.edgeMapper.getValues();
  32955. for (var i = 0; i < edges.length; i++)
  32956. {
  32957. this.setEdgePosition(edges[i]);
  32958. }
  32959. };
  32960. /**
  32961. * Function: localEdgeProcessing
  32962. *
  32963. * Separates the x position of edges as they connect to vertices
  32964. *
  32965. * Parameters:
  32966. *
  32967. * model - the layout model
  32968. */
  32969. mxCoordinateAssignment.prototype.localEdgeProcessing = function(model)
  32970. {
  32971. // Iterate through each vertex, look at the edges connected in
  32972. // both directions.
  32973. for (var rankIndex = 0; rankIndex < model.ranks.length; rankIndex++)
  32974. {
  32975. var rank = model.ranks[rankIndex];
  32976. for (var cellIndex = 0; cellIndex < rank.length; cellIndex++)
  32977. {
  32978. var cell = rank[cellIndex];
  32979. if (cell.isVertex())
  32980. {
  32981. var currentCells = cell.getPreviousLayerConnectedCells(rankIndex);
  32982. var currentRank = rankIndex - 1;
  32983. // Two loops, last connected cells, and next
  32984. for (var k = 0; k < 2; k++)
  32985. {
  32986. if (currentRank > -1
  32987. && currentRank < model.ranks.length
  32988. && currentCells != null
  32989. && currentCells.length > 0)
  32990. {
  32991. var sortedCells = [];
  32992. for (var j = 0; j < currentCells.length; j++)
  32993. {
  32994. var sorter = new WeightedCellSorter(
  32995. currentCells[j], currentCells[j].getX(currentRank));
  32996. sortedCells.push(sorter);
  32997. }
  32998. sortedCells.sort(WeightedCellSorter.prototype.compare);
  32999. var leftLimit = cell.x[0] - cell.width / 2;
  33000. var rightLimit = leftLimit + cell.width;
  33001. // Connected edge count starts at 1 to allow for buffer
  33002. // with edge of vertex
  33003. var connectedEdgeCount = 0;
  33004. var connectedEdgeGroupCount = 0;
  33005. var connectedEdges = [];
  33006. // Calculate width requirements for all connected edges
  33007. for (var j = 0; j < sortedCells.length; j++)
  33008. {
  33009. var innerCell = sortedCells[j].cell;
  33010. var connections;
  33011. if (innerCell.isVertex())
  33012. {
  33013. // Get the connecting edge
  33014. if (k == 0)
  33015. {
  33016. connections = cell.connectsAsSource;
  33017. }
  33018. else
  33019. {
  33020. connections = cell.connectsAsTarget;
  33021. }
  33022. for (var connIndex = 0; connIndex < connections.length; connIndex++)
  33023. {
  33024. if (connections[connIndex].source == innerCell
  33025. || connections[connIndex].target == innerCell)
  33026. {
  33027. connectedEdgeCount += connections[connIndex].edges
  33028. .length;
  33029. connectedEdgeGroupCount++;
  33030. connectedEdges.push(connections[connIndex]);
  33031. }
  33032. }
  33033. }
  33034. else
  33035. {
  33036. connectedEdgeCount += innerCell.edges.length;
  33037. connectedEdgeGroupCount++;
  33038. connectedEdges.push(innerCell);
  33039. }
  33040. }
  33041. var requiredWidth = (connectedEdgeCount + 1)
  33042. * this.prefHozEdgeSep;
  33043. // Add a buffer on the edges of the vertex if the edge count allows
  33044. if (cell.width > requiredWidth
  33045. + (2 * this.prefHozEdgeSep))
  33046. {
  33047. leftLimit += this.prefHozEdgeSep;
  33048. rightLimit -= this.prefHozEdgeSep;
  33049. }
  33050. var availableWidth = rightLimit - leftLimit;
  33051. var edgeSpacing = availableWidth / connectedEdgeCount;
  33052. var currentX = leftLimit + edgeSpacing / 2.0;
  33053. var currentYOffset = this.minEdgeJetty - this.prefVertEdgeOff;
  33054. var maxYOffset = 0;
  33055. for (var j = 0; j < connectedEdges.length; j++)
  33056. {
  33057. var numActualEdges = connectedEdges[j].edges
  33058. .length;
  33059. var pos = this.jettyPositions[connectedEdges[j].ids[0]];
  33060. if (pos == null)
  33061. {
  33062. pos = [];
  33063. this.jettyPositions[connectedEdges[j].ids[0]] = pos;
  33064. }
  33065. if (j < connectedEdgeCount / 2)
  33066. {
  33067. currentYOffset += this.prefVertEdgeOff;
  33068. }
  33069. else if (j > connectedEdgeCount / 2)
  33070. {
  33071. currentYOffset -= this.prefVertEdgeOff;
  33072. }
  33073. // Ignore the case if equals, this means the second of 2
  33074. // jettys with the same y (even number of edges)
  33075. for (var m = 0; m < numActualEdges; m++)
  33076. {
  33077. pos[m * 4 + k * 2] = currentX;
  33078. currentX += edgeSpacing;
  33079. pos[m * 4 + k * 2 + 1] = currentYOffset;
  33080. }
  33081. maxYOffset = Math.max(maxYOffset,
  33082. currentYOffset);
  33083. }
  33084. }
  33085. currentCells = cell.getNextLayerConnectedCells(rankIndex);
  33086. currentRank = rankIndex + 1;
  33087. }
  33088. }
  33089. }
  33090. }
  33091. };
  33092. /**
  33093. * Function: setEdgePosition
  33094. *
  33095. * Fixes the control points
  33096. */
  33097. mxCoordinateAssignment.prototype.setEdgePosition = function(cell)
  33098. {
  33099. // For parallel edges we need to seperate out the points a
  33100. // little
  33101. var offsetX = 0;
  33102. // Only set the edge control points once
  33103. if (cell.temp[0] != 101207)
  33104. {
  33105. var maxRank = cell.maxRank;
  33106. var minRank = cell.minRank;
  33107. if (maxRank == minRank)
  33108. {
  33109. maxRank = cell.source.maxRank;
  33110. minRank = cell.target.minRank;
  33111. }
  33112. var parallelEdgeCount = 0;
  33113. var jettys = this.jettyPositions[cell.ids[0]];
  33114. var source = cell.isReversed ? cell.target.cell : cell.source.cell;
  33115. var graph = this.layout.graph;
  33116. var layoutReversed = this.orientation == mxConstants.DIRECTION_EAST
  33117. || this.orientation == mxConstants.DIRECTION_SOUTH;
  33118. for (var i = 0; i < cell.edges.length; i++)
  33119. {
  33120. var realEdge = cell.edges[i];
  33121. var realSource = this.layout.getVisibleTerminal(realEdge, true);
  33122. //List oldPoints = graph.getPoints(realEdge);
  33123. var newPoints = [];
  33124. // Single length reversed edges end up with the jettys in the wrong
  33125. // places. Since single length edges only have jettys, not segment
  33126. // control points, we just say the edge isn't reversed in this section
  33127. var reversed = cell.isReversed;
  33128. if (realSource != source)
  33129. {
  33130. // The real edges include all core model edges and these can go
  33131. // in both directions. If the source of the hierarchical model edge
  33132. // isn't the source of the specific real edge in this iteration
  33133. // treat if as reversed
  33134. reversed = !reversed;
  33135. }
  33136. // First jetty of edge
  33137. if (jettys != null)
  33138. {
  33139. var arrayOffset = reversed ? 2 : 0;
  33140. var y = reversed ?
  33141. (layoutReversed ? this.rankBottomY[minRank] : this.rankTopY[minRank]) :
  33142. (layoutReversed ? this.rankTopY[maxRank] : this.rankBottomY[maxRank]);
  33143. var jetty = jettys[parallelEdgeCount * 4 + 1 + arrayOffset];
  33144. if (reversed != layoutReversed)
  33145. {
  33146. jetty = -jetty;
  33147. }
  33148. y += jetty;
  33149. var x = jettys[parallelEdgeCount * 4 + arrayOffset];
  33150. var modelSource = graph.model.getTerminal(realEdge, true);
  33151. if (this.layout.isPort(modelSource) && graph.model.getParent(modelSource) == realSource)
  33152. {
  33153. var state = graph.view.getState(modelSource);
  33154. if (state != null)
  33155. {
  33156. x = state.x;
  33157. }
  33158. else
  33159. {
  33160. x = realSource.geometry.x + cell.source.width * modelSource.geometry.x;
  33161. }
  33162. }
  33163. if (this.orientation == mxConstants.DIRECTION_NORTH
  33164. || this.orientation == mxConstants.DIRECTION_SOUTH)
  33165. {
  33166. newPoints.push(new mxPoint(x, y));
  33167. if (this.layout.edgeStyle == mxHierarchicalEdgeStyle.CURVE)
  33168. {
  33169. newPoints.push(new mxPoint(x, y + jetty));
  33170. }
  33171. }
  33172. else
  33173. {
  33174. newPoints.push(new mxPoint(y, x));
  33175. if (this.layout.edgeStyle == mxHierarchicalEdgeStyle.CURVE)
  33176. {
  33177. newPoints.push(new mxPoint(y + jetty, x));
  33178. }
  33179. }
  33180. }
  33181. // Declare variables to define loop through edge points and
  33182. // change direction if edge is reversed
  33183. var loopStart = cell.x.length - 1;
  33184. var loopLimit = -1;
  33185. var loopDelta = -1;
  33186. var currentRank = cell.maxRank - 1;
  33187. if (reversed)
  33188. {
  33189. loopStart = 0;
  33190. loopLimit = cell.x.length;
  33191. loopDelta = 1;
  33192. currentRank = cell.minRank + 1;
  33193. }
  33194. // Reversed edges need the points inserted in
  33195. // reverse order
  33196. for (var j = loopStart; (cell.maxRank != cell.minRank) && j != loopLimit; j += loopDelta)
  33197. {
  33198. // The horizontal position in a vertical layout
  33199. var positionX = cell.x[j] + offsetX;
  33200. // Work out the vertical positions in a vertical layout
  33201. // in the edge buffer channels above and below this rank
  33202. var topChannelY = (this.rankTopY[currentRank] + this.rankBottomY[currentRank + 1]) / 2.0;
  33203. var bottomChannelY = (this.rankTopY[currentRank - 1] + this.rankBottomY[currentRank]) / 2.0;
  33204. if (reversed)
  33205. {
  33206. var tmp = topChannelY;
  33207. topChannelY = bottomChannelY;
  33208. bottomChannelY = tmp;
  33209. }
  33210. if (this.orientation == mxConstants.DIRECTION_NORTH ||
  33211. this.orientation == mxConstants.DIRECTION_SOUTH)
  33212. {
  33213. newPoints.push(new mxPoint(positionX, topChannelY));
  33214. newPoints.push(new mxPoint(positionX, bottomChannelY));
  33215. }
  33216. else
  33217. {
  33218. newPoints.push(new mxPoint(topChannelY, positionX));
  33219. newPoints.push(new mxPoint(bottomChannelY, positionX));
  33220. }
  33221. this.limitX = Math.max(this.limitX, positionX);
  33222. currentRank += loopDelta;
  33223. }
  33224. // Second jetty of edge
  33225. if (jettys != null)
  33226. {
  33227. var arrayOffset = reversed ? 2 : 0;
  33228. var rankY = reversed ?
  33229. (layoutReversed ? this.rankTopY[maxRank] : this.rankBottomY[maxRank]) :
  33230. (layoutReversed ? this.rankBottomY[minRank] : this.rankTopY[minRank]);
  33231. var jetty = jettys[parallelEdgeCount * 4 + 3 - arrayOffset];
  33232. if (reversed != layoutReversed)
  33233. {
  33234. jetty = -jetty;
  33235. }
  33236. var y = rankY - jetty;
  33237. var x = jettys[parallelEdgeCount * 4 + 2 - arrayOffset];
  33238. var modelTarget = graph.model.getTerminal(realEdge, false);
  33239. var realTarget = this.layout.getVisibleTerminal(realEdge, false);
  33240. if (this.layout.isPort(modelTarget) && graph.model.getParent(modelTarget) == realTarget)
  33241. {
  33242. var state = graph.view.getState(modelTarget);
  33243. if (state != null)
  33244. {
  33245. x = state.x;
  33246. }
  33247. else
  33248. {
  33249. x = realTarget.geometry.x + cell.target.width * modelTarget.geometry.x;
  33250. }
  33251. }
  33252. if (this.orientation == mxConstants.DIRECTION_NORTH ||
  33253. this.orientation == mxConstants.DIRECTION_SOUTH)
  33254. {
  33255. if (this.layout.edgeStyle == mxHierarchicalEdgeStyle.CURVE)
  33256. {
  33257. newPoints.push(new mxPoint(x, y - jetty));
  33258. }
  33259. newPoints.push(new mxPoint(x, y));
  33260. }
  33261. else
  33262. {
  33263. if (this.layout.edgeStyle == mxHierarchicalEdgeStyle.CURVE)
  33264. {
  33265. newPoints.push(new mxPoint(y - jetty, x));
  33266. }
  33267. newPoints.push(new mxPoint(y, x));
  33268. }
  33269. }
  33270. if (cell.isReversed)
  33271. {
  33272. this.processReversedEdge(cell, realEdge);
  33273. }
  33274. this.layout.setEdgePoints(realEdge, newPoints);
  33275. // Increase offset so next edge is drawn next to
  33276. // this one
  33277. if (offsetX == 0.0)
  33278. {
  33279. offsetX = this.parallelEdgeSpacing;
  33280. }
  33281. else if (offsetX > 0)
  33282. {
  33283. offsetX = -offsetX;
  33284. }
  33285. else
  33286. {
  33287. offsetX = -offsetX + this.parallelEdgeSpacing;
  33288. }
  33289. parallelEdgeCount++;
  33290. }
  33291. cell.temp[0] = 101207;
  33292. }
  33293. };
  33294. /**
  33295. * Function: setVertexLocation
  33296. *
  33297. * Fixes the position of the specified vertex.
  33298. *
  33299. * Parameters:
  33300. *
  33301. * cell - the vertex to position
  33302. */
  33303. mxCoordinateAssignment.prototype.setVertexLocation = function(cell)
  33304. {
  33305. var realCell = cell.cell;
  33306. var positionX = cell.x[0] - cell.width / 2;
  33307. var positionY = cell.y[0] - cell.height / 2;
  33308. this.rankTopY[cell.minRank] = Math.min(this.rankTopY[cell.minRank], positionY);
  33309. this.rankBottomY[cell.minRank] = Math.max(this.rankBottomY[cell.minRank],
  33310. positionY + cell.height);
  33311. if (this.orientation == mxConstants.DIRECTION_NORTH ||
  33312. this.orientation == mxConstants.DIRECTION_SOUTH)
  33313. {
  33314. this.layout.setVertexLocation(realCell, positionX, positionY);
  33315. }
  33316. else
  33317. {
  33318. this.layout.setVertexLocation(realCell, positionY, positionX);
  33319. }
  33320. this.limitX = Math.max(this.limitX, positionX + cell.width);
  33321. };
  33322. /**
  33323. * Function: processReversedEdge
  33324. *
  33325. * Hook to add additional processing
  33326. *
  33327. * Parameters:
  33328. *
  33329. * edge - the hierarchical model edge
  33330. * realEdge - the real edge in the graph
  33331. */
  33332. mxCoordinateAssignment.prototype.processReversedEdge = function(graph, model)
  33333. {
  33334. // hook for subclassers
  33335. };
  33336. /**
  33337. * Copyright (c) 2006-2015, JGraph Ltd
  33338. * Copyright (c) 2006-2015, Gaudenz Alder
  33339. */
  33340. /**
  33341. * Class: mxSwimlaneOrdering
  33342. *
  33343. * An implementation of the first stage of the Sugiyama layout. Straightforward
  33344. * longest path calculation of layer assignment
  33345. *
  33346. * Constructor: mxSwimlaneOrdering
  33347. *
  33348. * Creates a cycle remover for the given internal model.
  33349. */
  33350. function mxSwimlaneOrdering(layout)
  33351. {
  33352. this.layout = layout;
  33353. };
  33354. /**
  33355. * Extends mxHierarchicalLayoutStage.
  33356. */
  33357. mxSwimlaneOrdering.prototype = new mxHierarchicalLayoutStage();
  33358. mxSwimlaneOrdering.prototype.constructor = mxSwimlaneOrdering;
  33359. /**
  33360. * Variable: layout
  33361. *
  33362. * Reference to the enclosing <mxHierarchicalLayout>.
  33363. */
  33364. mxSwimlaneOrdering.prototype.layout = null;
  33365. /**
  33366. * Function: execute
  33367. *
  33368. * Takes the graph detail and configuration information within the facade
  33369. * and creates the resulting laid out graph within that facade for further
  33370. * use.
  33371. */
  33372. mxSwimlaneOrdering.prototype.execute = function(parent)
  33373. {
  33374. var model = this.layout.getModel();
  33375. var seenNodes = new Object();
  33376. var unseenNodes = mxUtils.clone(model.vertexMapper, null, true);
  33377. // Perform a dfs through the internal model. If a cycle is found,
  33378. // reverse it.
  33379. var rootsArray = null;
  33380. if (model.roots != null)
  33381. {
  33382. var modelRoots = model.roots;
  33383. rootsArray = [];
  33384. for (var i = 0; i < modelRoots.length; i++)
  33385. {
  33386. rootsArray[i] = model.vertexMapper.get(modelRoots[i]);
  33387. }
  33388. }
  33389. model.visit(function(parent, node, connectingEdge, layer, seen)
  33390. {
  33391. // Check if the cell is in it's own ancestor list, if so
  33392. // invert the connecting edge and reverse the target/source
  33393. // relationship to that edge in the parent and the cell
  33394. // Ancestor hashes only line up within a swimlane
  33395. var isAncestor = parent != null && parent.swimlaneIndex == node.swimlaneIndex && node.isAncestor(parent);
  33396. // If the source->target swimlane indices go from higher to
  33397. // lower, the edge is reverse
  33398. var reversedOverSwimlane = parent != null && connectingEdge != null &&
  33399. parent.swimlaneIndex < node.swimlaneIndex && connectingEdge.source == node;
  33400. if (isAncestor)
  33401. {
  33402. connectingEdge.invert();
  33403. mxUtils.remove(connectingEdge, parent.connectsAsSource);
  33404. node.connectsAsSource.push(connectingEdge);
  33405. parent.connectsAsTarget.push(connectingEdge);
  33406. mxUtils.remove(connectingEdge, node.connectsAsTarget);
  33407. }
  33408. else if (reversedOverSwimlane)
  33409. {
  33410. connectingEdge.invert();
  33411. mxUtils.remove(connectingEdge, parent.connectsAsTarget);
  33412. node.connectsAsTarget.push(connectingEdge);
  33413. parent.connectsAsSource.push(connectingEdge);
  33414. mxUtils.remove(connectingEdge, node.connectsAsSource);
  33415. }
  33416. var cellId = mxCellPath.create(node.cell);
  33417. seenNodes[cellId] = node;
  33418. delete unseenNodes[cellId];
  33419. }, rootsArray, true, null);
  33420. };
  33421. /**
  33422. * Copyright (c) 2006-2018, JGraph Ltd
  33423. * Copyright (c) 2006-2018, Gaudenz Alder
  33424. */
  33425. /**
  33426. * Class: mxHierarchicalLayout
  33427. *
  33428. * A hierarchical layout algorithm.
  33429. *
  33430. * Constructor: mxHierarchicalLayout
  33431. *
  33432. * Constructs a new hierarchical layout algorithm.
  33433. *
  33434. * Arguments:
  33435. *
  33436. * graph - Reference to the enclosing <mxGraph>.
  33437. * orientation - Optional constant that defines the orientation of this
  33438. * layout.
  33439. * deterministic - Optional boolean that specifies if this layout should be
  33440. * deterministic. Default is true.
  33441. */
  33442. function mxHierarchicalLayout(graph, orientation, deterministic)
  33443. {
  33444. mxGraphLayout.call(this, graph);
  33445. this.orientation = (orientation != null) ? orientation : mxConstants.DIRECTION_NORTH;
  33446. this.deterministic = (deterministic != null) ? deterministic : true;
  33447. };
  33448. var mxHierarchicalEdgeStyle =
  33449. {
  33450. ORTHOGONAL: 1,
  33451. POLYLINE: 2,
  33452. STRAIGHT: 3,
  33453. CURVE: 4
  33454. };
  33455. /**
  33456. * Extends mxGraphLayout.
  33457. */
  33458. mxHierarchicalLayout.prototype = new mxGraphLayout();
  33459. mxHierarchicalLayout.prototype.constructor = mxHierarchicalLayout;
  33460. /**
  33461. * Variable: roots
  33462. *
  33463. * Holds the array of <mxCell> that this layout contains.
  33464. */
  33465. mxHierarchicalLayout.prototype.roots = null;
  33466. /**
  33467. * Variable: resizeParent
  33468. *
  33469. * Specifies if the parent should be resized after the layout so that it
  33470. * contains all the child cells. Default is false. See also <parentBorder>.
  33471. */
  33472. mxHierarchicalLayout.prototype.resizeParent = false;
  33473. /**
  33474. * Variable: maintainParentLocation
  33475. *
  33476. * Specifies if the parent location should be maintained, so that the
  33477. * top, left corner stays the same before and after execution of
  33478. * the layout. Default is false for backwards compatibility.
  33479. */
  33480. mxHierarchicalLayout.prototype.maintainParentLocation = false;
  33481. /**
  33482. * Variable: moveParent
  33483. *
  33484. * Specifies if the parent should be moved if <resizeParent> is enabled.
  33485. * Default is false.
  33486. */
  33487. mxHierarchicalLayout.prototype.moveParent = false;
  33488. /**
  33489. * Variable: parentBorder
  33490. *
  33491. * The border to be added around the children if the parent is to be
  33492. * resized using <resizeParent>. Default is 0.
  33493. */
  33494. mxHierarchicalLayout.prototype.parentBorder = 0;
  33495. /**
  33496. * Variable: intraCellSpacing
  33497. *
  33498. * The spacing buffer added between cells on the same layer. Default is 30.
  33499. */
  33500. mxHierarchicalLayout.prototype.intraCellSpacing = 30;
  33501. /**
  33502. * Variable: interRankCellSpacing
  33503. *
  33504. * The spacing buffer added between cell on adjacent layers. Default is 100.
  33505. */
  33506. mxHierarchicalLayout.prototype.interRankCellSpacing = 100;
  33507. /**
  33508. * Variable: interHierarchySpacing
  33509. *
  33510. * The spacing buffer between unconnected hierarchies. Default is 60.
  33511. */
  33512. mxHierarchicalLayout.prototype.interHierarchySpacing = 60;
  33513. /**
  33514. * Variable: parallelEdgeSpacing
  33515. *
  33516. * The distance between each parallel edge on each ranks for long edges.
  33517. * Default is 10.
  33518. */
  33519. mxHierarchicalLayout.prototype.parallelEdgeSpacing = 10;
  33520. /**
  33521. * Variable: orientation
  33522. *
  33523. * The position of the root node(s) relative to the laid out graph in.
  33524. * Default is <mxConstants.DIRECTION_NORTH>.
  33525. */
  33526. mxHierarchicalLayout.prototype.orientation = mxConstants.DIRECTION_NORTH;
  33527. /**
  33528. * Variable: fineTuning
  33529. *
  33530. * Whether or not to perform local optimisations and iterate multiple times
  33531. * through the algorithm. Default is true.
  33532. */
  33533. mxHierarchicalLayout.prototype.fineTuning = true;
  33534. /**
  33535. *
  33536. * Variable: tightenToSource
  33537. *
  33538. * Whether or not to tighten the assigned ranks of vertices up towards
  33539. * the source cells. Default is true.
  33540. */
  33541. mxHierarchicalLayout.prototype.tightenToSource = true;
  33542. /**
  33543. * Variable: disableEdgeStyle
  33544. *
  33545. * Specifies if the STYLE_NOEDGESTYLE flag should be set on edges that are
  33546. * modified by the result. Default is true.
  33547. */
  33548. mxHierarchicalLayout.prototype.disableEdgeStyle = true;
  33549. /**
  33550. * Variable: traverseAncestors
  33551. *
  33552. * Whether or not to drill into child cells and layout in reverse
  33553. * group order. This also cause the layout to navigate edges whose
  33554. * terminal vertices have different parents but are in the same
  33555. * ancestry chain. Default is true.
  33556. */
  33557. mxHierarchicalLayout.prototype.traverseAncestors = true;
  33558. /**
  33559. * Variable: model
  33560. *
  33561. * The internal <mxGraphHierarchyModel> formed of the layout.
  33562. */
  33563. mxHierarchicalLayout.prototype.model = null;
  33564. /**
  33565. * Variable: edgesSet
  33566. *
  33567. * A cache of edges whose source terminal is the key
  33568. */
  33569. mxHierarchicalLayout.prototype.edgesCache = null;
  33570. /**
  33571. * Variable: edgesSet
  33572. *
  33573. * A cache of edges whose source terminal is the key
  33574. */
  33575. mxHierarchicalLayout.prototype.edgeSourceTermCache = null;
  33576. /**
  33577. * Variable: edgesSet
  33578. *
  33579. * A cache of edges whose source terminal is the key
  33580. */
  33581. mxHierarchicalLayout.prototype.edgesTargetTermCache = null;
  33582. /**
  33583. * Variable: edgeStyle
  33584. *
  33585. * The style to apply between cell layers to edge segments.
  33586. * Default is <mxHierarchicalEdgeStyle.POLYLINE>.
  33587. */
  33588. mxHierarchicalLayout.prototype.edgeStyle = mxHierarchicalEdgeStyle.POLYLINE;
  33589. /**
  33590. * Function: getModel
  33591. *
  33592. * Returns the internal <mxGraphHierarchyModel> for this layout algorithm.
  33593. */
  33594. mxHierarchicalLayout.prototype.getModel = function()
  33595. {
  33596. return this.model;
  33597. };
  33598. /**
  33599. * Function: execute
  33600. *
  33601. * Executes the layout for the children of the specified parent.
  33602. *
  33603. * Parameters:
  33604. *
  33605. * parent - Parent <mxCell> that contains the children to be laid out.
  33606. * roots - Optional starting roots of the layout.
  33607. */
  33608. mxHierarchicalLayout.prototype.execute = function(parent, roots)
  33609. {
  33610. this.parent = parent;
  33611. var model = this.graph.model;
  33612. this.edgesCache = new mxDictionary();
  33613. this.edgeSourceTermCache = new mxDictionary();
  33614. this.edgesTargetTermCache = new mxDictionary();
  33615. if (roots != null && !(roots instanceof Array))
  33616. {
  33617. roots = [roots];
  33618. }
  33619. // If the roots are set and the parent is set, only
  33620. // use the roots that are some dependent of the that
  33621. // parent.
  33622. // If just the root are set, use them as-is
  33623. // If just the parent is set use it's immediate
  33624. // children as the initial set
  33625. if (roots == null && parent == null)
  33626. {
  33627. // TODO indicate the problem
  33628. return;
  33629. }
  33630. // Maintaining parent location
  33631. this.parentX = null;
  33632. this.parentY = null;
  33633. if (parent != this.root && model.isVertex(parent) != null && this.maintainParentLocation)
  33634. {
  33635. var geo = this.graph.getCellGeometry(parent);
  33636. if (geo != null)
  33637. {
  33638. this.parentX = geo.x;
  33639. this.parentY = geo.y;
  33640. }
  33641. }
  33642. if (roots != null)
  33643. {
  33644. var rootsCopy = [];
  33645. for (var i = 0; i < roots.length; i++)
  33646. {
  33647. var ancestor = parent != null ? model.isAncestor(parent, roots[i]) : true;
  33648. if (ancestor && model.isVertex(roots[i]))
  33649. {
  33650. rootsCopy.push(roots[i]);
  33651. }
  33652. }
  33653. this.roots = rootsCopy;
  33654. }
  33655. model.beginUpdate();
  33656. try
  33657. {
  33658. this.run(parent);
  33659. if (this.resizeParent && !this.graph.isCellCollapsed(parent))
  33660. {
  33661. this.graph.updateGroupBounds([parent], this.parentBorder, this.moveParent);
  33662. }
  33663. // Maintaining parent location
  33664. if (this.parentX != null && this.parentY != null)
  33665. {
  33666. var geo = this.graph.getCellGeometry(parent);
  33667. if (geo != null)
  33668. {
  33669. geo = geo.clone();
  33670. geo.x = this.parentX;
  33671. geo.y = this.parentY;
  33672. model.setGeometry(parent, geo);
  33673. }
  33674. }
  33675. }
  33676. finally
  33677. {
  33678. model.endUpdate();
  33679. }
  33680. };
  33681. /**
  33682. * Function: findRoots
  33683. *
  33684. * Returns all visible children in the given parent which do not have
  33685. * incoming edges. If the result is empty then the children with the
  33686. * maximum difference between incoming and outgoing edges are returned.
  33687. * This takes into account edges that are being promoted to the given
  33688. * root due to invisible children or collapsed cells.
  33689. *
  33690. * Parameters:
  33691. *
  33692. * parent - <mxCell> whose children should be checked.
  33693. * vertices - array of vertices to limit search to
  33694. */
  33695. mxHierarchicalLayout.prototype.findRoots = function(parent, vertices)
  33696. {
  33697. var roots = [];
  33698. if (parent != null && vertices != null)
  33699. {
  33700. var model = this.graph.model;
  33701. var best = null;
  33702. var maxDiff = -100000;
  33703. for (var i in vertices)
  33704. {
  33705. var cell = vertices[i];
  33706. if (model.isVertex(cell) && this.graph.isCellVisible(cell))
  33707. {
  33708. var conns = this.getEdges(cell);
  33709. var fanOut = 0;
  33710. var fanIn = 0;
  33711. for (var k = 0; k < conns.length; k++)
  33712. {
  33713. var src = this.getVisibleTerminal(conns[k], true);
  33714. if (src == cell)
  33715. {
  33716. fanOut++;
  33717. }
  33718. else
  33719. {
  33720. fanIn++;
  33721. }
  33722. }
  33723. if (fanIn == 0 && fanOut > 0)
  33724. {
  33725. roots.push(cell);
  33726. }
  33727. var diff = fanOut - fanIn;
  33728. if (diff > maxDiff)
  33729. {
  33730. maxDiff = diff;
  33731. best = cell;
  33732. }
  33733. }
  33734. }
  33735. if (roots.length == 0 && best != null)
  33736. {
  33737. roots.push(best);
  33738. }
  33739. }
  33740. return roots;
  33741. };
  33742. /**
  33743. * Function: getEdges
  33744. *
  33745. * Returns the connected edges for the given cell.
  33746. *
  33747. * Parameters:
  33748. *
  33749. * cell - <mxCell> whose edges should be returned.
  33750. */
  33751. mxHierarchicalLayout.prototype.getEdges = function(cell)
  33752. {
  33753. var cachedEdges = this.edgesCache.get(cell);
  33754. if (cachedEdges != null)
  33755. {
  33756. return cachedEdges;
  33757. }
  33758. var model = this.graph.model;
  33759. var edges = [];
  33760. var isCollapsed = this.graph.isCellCollapsed(cell);
  33761. var childCount = model.getChildCount(cell);
  33762. for (var i = 0; i < childCount; i++)
  33763. {
  33764. var child = model.getChildAt(cell, i);
  33765. if (this.isPort(child))
  33766. {
  33767. edges = edges.concat(model.getEdges(child, true, true));
  33768. }
  33769. else if (isCollapsed || !this.graph.isCellVisible(child))
  33770. {
  33771. edges = edges.concat(model.getEdges(child, true, true));
  33772. }
  33773. }
  33774. edges = edges.concat(model.getEdges(cell, true, true));
  33775. var result = [];
  33776. for (var i = 0; i < edges.length; i++)
  33777. {
  33778. var source = this.getVisibleTerminal(edges[i], true);
  33779. var target = this.getVisibleTerminal(edges[i], false);
  33780. if ((source == target) ||
  33781. ((source != target) &&
  33782. ((target == cell && (this.parent == null || this.isAncestor(this.parent, source, this.traverseAncestors))) ||
  33783. (source == cell && (this.parent == null || this.isAncestor(this.parent, target, this.traverseAncestors))))))
  33784. {
  33785. result.push(edges[i]);
  33786. }
  33787. }
  33788. this.edgesCache.put(cell, result);
  33789. return result;
  33790. };
  33791. /**
  33792. * Function: getVisibleTerminal
  33793. *
  33794. * Helper function to return visible terminal for edge allowing for ports
  33795. *
  33796. * Parameters:
  33797. *
  33798. * edge - <mxCell> whose edges should be returned.
  33799. * source - Boolean that specifies whether the source or target terminal is to be returned
  33800. */
  33801. mxHierarchicalLayout.prototype.getVisibleTerminal = function(edge, source)
  33802. {
  33803. var terminalCache = this.edgesTargetTermCache;
  33804. if (source)
  33805. {
  33806. terminalCache = this.edgeSourceTermCache;
  33807. }
  33808. var term = terminalCache.get(edge);
  33809. if (term != null)
  33810. {
  33811. return term;
  33812. }
  33813. var state = this.graph.view.getState(edge);
  33814. var terminal = (state != null) ? state.getVisibleTerminal(source) : this.graph.view.getVisibleTerminal(edge, source);
  33815. if (terminal == null)
  33816. {
  33817. terminal = (state != null) ? state.getVisibleTerminal(source) : this.graph.view.getVisibleTerminal(edge, source);
  33818. }
  33819. if (terminal != null)
  33820. {
  33821. if (this.isPort(terminal))
  33822. {
  33823. terminal = this.graph.model.getParent(terminal);
  33824. }
  33825. terminalCache.put(edge, terminal);
  33826. }
  33827. return terminal;
  33828. };
  33829. /**
  33830. * Function: run
  33831. *
  33832. * The API method used to exercise the layout upon the graph description
  33833. * and produce a separate description of the vertex position and edge
  33834. * routing changes made. It runs each stage of the layout that has been
  33835. * created.
  33836. */
  33837. mxHierarchicalLayout.prototype.run = function(parent)
  33838. {
  33839. // Separate out unconnected hierarchies
  33840. var hierarchyVertices = [];
  33841. var allVertexSet = [];
  33842. if (this.roots == null && parent != null)
  33843. {
  33844. var filledVertexSet = Object();
  33845. this.filterDescendants(parent, filledVertexSet);
  33846. this.roots = [];
  33847. var filledVertexSetEmpty = true;
  33848. // Poor man's isSetEmpty
  33849. for (var key in filledVertexSet)
  33850. {
  33851. if (filledVertexSet[key] != null)
  33852. {
  33853. filledVertexSetEmpty = false;
  33854. break;
  33855. }
  33856. }
  33857. while (!filledVertexSetEmpty)
  33858. {
  33859. var candidateRoots = this.findRoots(parent, filledVertexSet);
  33860. // If the candidate root is an unconnected group cell, remove it from
  33861. // the layout. We may need a custom set that holds such groups and forces
  33862. // them to be processed for resizing and/or moving.
  33863. for (var i = 0; i < candidateRoots.length; i++)
  33864. {
  33865. var vertexSet = Object();
  33866. hierarchyVertices.push(vertexSet);
  33867. this.traverse(candidateRoots[i], true, null, allVertexSet, vertexSet,
  33868. hierarchyVertices, filledVertexSet);
  33869. }
  33870. for (var i = 0; i < candidateRoots.length; i++)
  33871. {
  33872. this.roots.push(candidateRoots[i]);
  33873. }
  33874. filledVertexSetEmpty = true;
  33875. // Poor man's isSetEmpty
  33876. for (var key in filledVertexSet)
  33877. {
  33878. if (filledVertexSet[key] != null)
  33879. {
  33880. filledVertexSetEmpty = false;
  33881. break;
  33882. }
  33883. }
  33884. }
  33885. }
  33886. else
  33887. {
  33888. // Find vertex set as directed traversal from roots
  33889. for (var i = 0; i < this.roots.length; i++)
  33890. {
  33891. var vertexSet = Object();
  33892. hierarchyVertices.push(vertexSet);
  33893. this.traverse(this.roots[i], true, null, allVertexSet, vertexSet,
  33894. hierarchyVertices, null);
  33895. }
  33896. }
  33897. // Iterate through the result removing parents who have children in this layout
  33898. // Perform a layout for each seperate hierarchy
  33899. // Track initial coordinate x-positioning
  33900. var initialX = 0;
  33901. for (var i = 0; i < hierarchyVertices.length; i++)
  33902. {
  33903. var vertexSet = hierarchyVertices[i];
  33904. var tmp = [];
  33905. for (var key in vertexSet)
  33906. {
  33907. tmp.push(vertexSet[key]);
  33908. }
  33909. this.model = new mxGraphHierarchyModel(this, tmp, this.roots,
  33910. parent, this.tightenToSource);
  33911. this.cycleStage(parent);
  33912. this.layeringStage();
  33913. this.crossingStage(parent);
  33914. initialX = this.placementStage(initialX, parent);
  33915. }
  33916. };
  33917. /**
  33918. * Function: filterDescendants
  33919. *
  33920. * Creates an array of descendant cells
  33921. */
  33922. mxHierarchicalLayout.prototype.filterDescendants = function(cell, result)
  33923. {
  33924. var model = this.graph.model;
  33925. if (model.isVertex(cell) && cell != this.parent && this.graph.isCellVisible(cell))
  33926. {
  33927. result[mxObjectIdentity.get(cell)] = cell;
  33928. }
  33929. if (this.traverseAncestors || cell == this.parent
  33930. && this.graph.isCellVisible(cell))
  33931. {
  33932. var childCount = model.getChildCount(cell);
  33933. for (var i = 0; i < childCount; i++)
  33934. {
  33935. var child = model.getChildAt(cell, i);
  33936. // Ignore ports in the layout vertex list, they are dealt with
  33937. // in the traversal mechanisms
  33938. if (!this.isPort(child))
  33939. {
  33940. this.filterDescendants(child, result);
  33941. }
  33942. }
  33943. }
  33944. };
  33945. /**
  33946. * Function: isPort
  33947. *
  33948. * Returns true if the given cell is a "port", that is, when connecting to
  33949. * it, its parent is the connecting vertex in terms of graph traversal
  33950. *
  33951. * Parameters:
  33952. *
  33953. * cell - <mxCell> that represents the port.
  33954. */
  33955. mxHierarchicalLayout.prototype.isPort = function(cell)
  33956. {
  33957. if (cell != null && cell.geometry != null)
  33958. {
  33959. return cell.geometry.relative;
  33960. }
  33961. else
  33962. {
  33963. return false;
  33964. }
  33965. };
  33966. /**
  33967. * Function: getEdgesBetween
  33968. *
  33969. * Returns the edges between the given source and target. This takes into
  33970. * account collapsed and invisible cells and ports.
  33971. *
  33972. * Parameters:
  33973. *
  33974. * source -
  33975. * target -
  33976. * directed -
  33977. */
  33978. mxHierarchicalLayout.prototype.getEdgesBetween = function(source, target, directed)
  33979. {
  33980. directed = (directed != null) ? directed : false;
  33981. var edges = this.getEdges(source);
  33982. var result = [];
  33983. // Checks if the edge is connected to the correct
  33984. // cell and returns the first match
  33985. for (var i = 0; i < edges.length; i++)
  33986. {
  33987. var src = this.getVisibleTerminal(edges[i], true);
  33988. var trg = this.getVisibleTerminal(edges[i], false);
  33989. if ((src == source && trg == target) || (!directed && src == target && trg == source))
  33990. {
  33991. result.push(edges[i]);
  33992. }
  33993. }
  33994. return result;
  33995. };
  33996. /**
  33997. * Traverses the (directed) graph invoking the given function for each
  33998. * visited vertex and edge. The function is invoked with the current vertex
  33999. * and the incoming edge as a parameter. This implementation makes sure
  34000. * each vertex is only visited once. The function may return false if the
  34001. * traversal should stop at the given vertex.
  34002. *
  34003. * Parameters:
  34004. *
  34005. * vertex - <mxCell> that represents the vertex where the traversal starts.
  34006. * directed - boolean indicating if edges should only be traversed
  34007. * from source to target. Default is true.
  34008. * edge - Optional <mxCell> that represents the incoming edge. This is
  34009. * null for the first step of the traversal.
  34010. * allVertices - Array of cell paths for the visited cells.
  34011. */
  34012. mxHierarchicalLayout.prototype.traverse = function(vertex, directed, edge, allVertices, currentComp,
  34013. hierarchyVertices, filledVertexSet)
  34014. {
  34015. if (vertex != null && allVertices != null)
  34016. {
  34017. // Has this vertex been seen before in any traversal
  34018. // And if the filled vertex set is populated, only
  34019. // process vertices in that it contains
  34020. var vertexID = mxObjectIdentity.get(vertex);
  34021. if ((allVertices[vertexID] == null)
  34022. && (filledVertexSet == null ? true : filledVertexSet[vertexID] != null))
  34023. {
  34024. if (currentComp[vertexID] == null)
  34025. {
  34026. currentComp[vertexID] = vertex;
  34027. }
  34028. if (allVertices[vertexID] == null)
  34029. {
  34030. allVertices[vertexID] = vertex;
  34031. }
  34032. if (filledVertexSet !== null)
  34033. {
  34034. delete filledVertexSet[vertexID];
  34035. }
  34036. var edges = this.getEdges(vertex);
  34037. var edgeIsSource = [];
  34038. for (var i = 0; i < edges.length; i++)
  34039. {
  34040. edgeIsSource[i] = (this.getVisibleTerminal(edges[i], true) == vertex);
  34041. }
  34042. for (var i = 0; i < edges.length; i++)
  34043. {
  34044. if (!directed || edgeIsSource[i])
  34045. {
  34046. var next = this.getVisibleTerminal(edges[i], !edgeIsSource[i]);
  34047. // Check whether there are more edges incoming from the target vertex than outgoing
  34048. // The hierarchical model treats bi-directional parallel edges as being sourced
  34049. // from the more "sourced" terminal. If the directions are equal in number, the direction
  34050. // is that of the natural direction from the roots of the layout.
  34051. // The checks below are slightly more verbose than need be for performance reasons
  34052. var netCount = 1;
  34053. for (var j = 0; j < edges.length; j++)
  34054. {
  34055. if (j == i)
  34056. {
  34057. continue;
  34058. }
  34059. else
  34060. {
  34061. var isSource2 = edgeIsSource[j];
  34062. var otherTerm = this.getVisibleTerminal(edges[j], !isSource2);
  34063. if (otherTerm == next)
  34064. {
  34065. if (isSource2)
  34066. {
  34067. netCount++;
  34068. }
  34069. else
  34070. {
  34071. netCount--;
  34072. }
  34073. }
  34074. }
  34075. }
  34076. if (netCount >= 0)
  34077. {
  34078. currentComp = this.traverse(next, directed, edges[i], allVertices,
  34079. currentComp, hierarchyVertices,
  34080. filledVertexSet);
  34081. }
  34082. }
  34083. }
  34084. }
  34085. else
  34086. {
  34087. if (currentComp[vertexID] == null)
  34088. {
  34089. // We've seen this vertex before, but not in the current component
  34090. // This component and the one it's in need to be merged
  34091. for (var i = 0; i < hierarchyVertices.length; i++)
  34092. {
  34093. var comp = hierarchyVertices[i];
  34094. if (comp[vertexID] != null)
  34095. {
  34096. for (var key in comp)
  34097. {
  34098. currentComp[key] = comp[key];
  34099. }
  34100. // Remove the current component from the hierarchy set
  34101. hierarchyVertices.splice(i, 1);
  34102. return currentComp;
  34103. }
  34104. }
  34105. }
  34106. }
  34107. }
  34108. return currentComp;
  34109. };
  34110. /**
  34111. * Function: cycleStage
  34112. *
  34113. * Executes the cycle stage using mxMinimumCycleRemover.
  34114. */
  34115. mxHierarchicalLayout.prototype.cycleStage = function(parent)
  34116. {
  34117. var cycleStage = new mxMinimumCycleRemover(this);
  34118. cycleStage.execute(parent);
  34119. };
  34120. /**
  34121. * Function: layeringStage
  34122. *
  34123. * Implements first stage of a Sugiyama layout.
  34124. */
  34125. mxHierarchicalLayout.prototype.layeringStage = function()
  34126. {
  34127. this.model.initialRank();
  34128. this.model.fixRanks();
  34129. };
  34130. /**
  34131. * Function: crossingStage
  34132. *
  34133. * Executes the crossing stage using mxMedianHybridCrossingReduction.
  34134. */
  34135. mxHierarchicalLayout.prototype.crossingStage = function(parent)
  34136. {
  34137. var crossingStage = new mxMedianHybridCrossingReduction(this);
  34138. crossingStage.execute(parent);
  34139. };
  34140. /**
  34141. * Function: placementStage
  34142. *
  34143. * Executes the placement stage using mxCoordinateAssignment.
  34144. */
  34145. mxHierarchicalLayout.prototype.placementStage = function(initialX, parent)
  34146. {
  34147. var placementStage = new mxCoordinateAssignment(this, this.intraCellSpacing,
  34148. this.interRankCellSpacing, this.orientation, initialX,
  34149. this.parallelEdgeSpacing);
  34150. placementStage.fineTuning = this.fineTuning;
  34151. placementStage.execute(parent);
  34152. return placementStage.limitX + this.interHierarchySpacing;
  34153. };
  34154. /**
  34155. * Copyright (c) 2006-2015, JGraph Ltd
  34156. * Copyright (c) 2006-2015, Gaudenz Alder
  34157. */
  34158. /**
  34159. * Class: mxSwimlaneLayout
  34160. *
  34161. * A hierarchical layout algorithm.
  34162. *
  34163. * Constructor: mxSwimlaneLayout
  34164. *
  34165. * Constructs a new hierarchical layout algorithm.
  34166. *
  34167. * Arguments:
  34168. *
  34169. * graph - Reference to the enclosing <mxGraph>.
  34170. * orientation - Optional constant that defines the orientation of this
  34171. * layout.
  34172. * deterministic - Optional boolean that specifies if this layout should be
  34173. * deterministic. Default is true.
  34174. */
  34175. function mxSwimlaneLayout(graph, orientation, deterministic)
  34176. {
  34177. mxGraphLayout.call(this, graph);
  34178. this.orientation = (orientation != null) ? orientation : mxConstants.DIRECTION_NORTH;
  34179. this.deterministic = (deterministic != null) ? deterministic : true;
  34180. };
  34181. /**
  34182. * Extends mxGraphLayout.
  34183. */
  34184. mxSwimlaneLayout.prototype = new mxGraphLayout();
  34185. mxSwimlaneLayout.prototype.constructor = mxSwimlaneLayout;
  34186. /**
  34187. * Variable: roots
  34188. *
  34189. * Holds the array of <mxCell> that this layout contains.
  34190. */
  34191. mxSwimlaneLayout.prototype.roots = null;
  34192. /**
  34193. * Variable: swimlanes
  34194. *
  34195. * Holds the array of <mxCell> of the ordered swimlanes to lay out
  34196. */
  34197. mxSwimlaneLayout.prototype.swimlanes = null;
  34198. /**
  34199. * Variable: dummyVertexWidth
  34200. *
  34201. * The cell width of any dummy vertices inserted
  34202. */
  34203. mxSwimlaneLayout.prototype.dummyVertexWidth = 50;
  34204. /**
  34205. * Variable: resizeParent
  34206. *
  34207. * Specifies if the parent should be resized after the layout so that it
  34208. * contains all the child cells. Default is false. See also <parentBorder>.
  34209. */
  34210. mxSwimlaneLayout.prototype.resizeParent = false;
  34211. /**
  34212. * Variable: maintainParentLocation
  34213. *
  34214. * Specifies if the parent location should be maintained, so that the
  34215. * top, left corner stays the same before and after execution of
  34216. * the layout. Default is false for backwards compatibility.
  34217. */
  34218. mxSwimlaneLayout.prototype.maintainParentLocation = false;
  34219. /**
  34220. * Variable: moveParent
  34221. *
  34222. * Specifies if the parent should be moved if <resizeParent> is enabled.
  34223. * Default is false.
  34224. */
  34225. mxSwimlaneLayout.prototype.moveParent = false;
  34226. /**
  34227. * Variable: parentBorder
  34228. *
  34229. * The border to be added around the children if the parent is to be
  34230. * resized using <resizeParent>. Default is 30.
  34231. */
  34232. mxSwimlaneLayout.prototype.parentBorder = 30;
  34233. /**
  34234. * Variable: intraCellSpacing
  34235. *
  34236. * The spacing buffer added between cells on the same layer. Default is 30.
  34237. */
  34238. mxSwimlaneLayout.prototype.intraCellSpacing = 30;
  34239. /**
  34240. * Variable: interRankCellSpacing
  34241. *
  34242. * The spacing buffer added between cell on adjacent layers. Default is 100.
  34243. */
  34244. mxSwimlaneLayout.prototype.interRankCellSpacing = 100;
  34245. /**
  34246. * Variable: interHierarchySpacing
  34247. *
  34248. * The spacing buffer between unconnected hierarchies. Default is 60.
  34249. */
  34250. mxSwimlaneLayout.prototype.interHierarchySpacing = 60;
  34251. /**
  34252. * Variable: parallelEdgeSpacing
  34253. *
  34254. * The distance between each parallel edge on each ranks for long edges.
  34255. * Default is 10.
  34256. */
  34257. mxSwimlaneLayout.prototype.parallelEdgeSpacing = 10;
  34258. /**
  34259. * Variable: orientation
  34260. *
  34261. * The position of the root node(s) relative to the laid out graph in.
  34262. * Default is <mxConstants.DIRECTION_NORTH>.
  34263. */
  34264. mxSwimlaneLayout.prototype.orientation = mxConstants.DIRECTION_NORTH;
  34265. /**
  34266. * Variable: fineTuning
  34267. *
  34268. * Whether or not to perform local optimisations and iterate multiple times
  34269. * through the algorithm. Default is true.
  34270. */
  34271. mxSwimlaneLayout.prototype.fineTuning = true;
  34272. /**
  34273. * Variable: tightenToSource
  34274. *
  34275. * Whether or not to tighten the assigned ranks of vertices up towards
  34276. * the source cells. Default is true.
  34277. */
  34278. mxSwimlaneLayout.prototype.tightenToSource = true;
  34279. /**
  34280. * Variable: disableEdgeStyle
  34281. *
  34282. * Specifies if the STYLE_NOEDGESTYLE flag should be set on edges that are
  34283. * modified by the result. Default is true.
  34284. */
  34285. mxSwimlaneLayout.prototype.disableEdgeStyle = true;
  34286. /**
  34287. * Variable: traverseAncestors
  34288. *
  34289. * Whether or not to drill into child cells and layout in reverse
  34290. * group order. This also cause the layout to navigate edges whose
  34291. * terminal vertices have different parents but are in the same
  34292. * ancestry chain. Default is true.
  34293. */
  34294. mxSwimlaneLayout.prototype.traverseAncestors = true;
  34295. /**
  34296. * Variable: model
  34297. *
  34298. * The internal <mxSwimlaneModel> formed of the layout.
  34299. */
  34300. mxSwimlaneLayout.prototype.model = null;
  34301. /**
  34302. * Variable: edgesSet
  34303. *
  34304. * A cache of edges whose source terminal is the key
  34305. */
  34306. mxSwimlaneLayout.prototype.edgesCache = null;
  34307. /**
  34308. * Variable: edgesSet
  34309. *
  34310. * A cache of edges whose source terminal is the key
  34311. */
  34312. mxHierarchicalLayout.prototype.edgeSourceTermCache = null;
  34313. /**
  34314. * Variable: edgesSet
  34315. *
  34316. * A cache of edges whose source terminal is the key
  34317. */
  34318. mxHierarchicalLayout.prototype.edgesTargetTermCache = null;
  34319. /**
  34320. * Variable: edgeStyle
  34321. *
  34322. * The style to apply between cell layers to edge segments.
  34323. * Default is <mxHierarchicalEdgeStyle.POLYLINE>.
  34324. */
  34325. mxHierarchicalLayout.prototype.edgeStyle = mxHierarchicalEdgeStyle.POLYLINE;
  34326. /**
  34327. * Function: getModel
  34328. *
  34329. * Returns the internal <mxSwimlaneModel> for this layout algorithm.
  34330. */
  34331. mxSwimlaneLayout.prototype.getModel = function()
  34332. {
  34333. return this.model;
  34334. };
  34335. /**
  34336. * Function: execute
  34337. *
  34338. * Executes the layout for the children of the specified parent.
  34339. *
  34340. * Parameters:
  34341. *
  34342. * parent - Parent <mxCell> that contains the children to be laid out.
  34343. * swimlanes - Ordered array of swimlanes to be laid out
  34344. */
  34345. mxSwimlaneLayout.prototype.execute = function(parent, swimlanes)
  34346. {
  34347. this.parent = parent;
  34348. var model = this.graph.model;
  34349. this.edgesCache = new mxDictionary();
  34350. this.edgeSourceTermCache = new mxDictionary();
  34351. this.edgesTargetTermCache = new mxDictionary();
  34352. // If the roots are set and the parent is set, only
  34353. // use the roots that are some dependent of the that
  34354. // parent.
  34355. // If just the root are set, use them as-is
  34356. // If just the parent is set use it's immediate
  34357. // children as the initial set
  34358. if (swimlanes == null || swimlanes.length < 1)
  34359. {
  34360. // TODO indicate the problem
  34361. return;
  34362. }
  34363. if (parent == null)
  34364. {
  34365. parent = model.getParent(swimlanes[0]);
  34366. }
  34367. // Maintaining parent location
  34368. this.parentX = null;
  34369. this.parentY = null;
  34370. if (parent != this.root && model.isVertex(parent) != null && this.maintainParentLocation)
  34371. {
  34372. var geo = this.graph.getCellGeometry(parent);
  34373. if (geo != null)
  34374. {
  34375. this.parentX = geo.x;
  34376. this.parentY = geo.y;
  34377. }
  34378. }
  34379. this.swimlanes = swimlanes;
  34380. var dummyVertices = [];
  34381. // Check the swimlanes all have vertices
  34382. // in them
  34383. for (var i = 0; i < swimlanes.length; i++)
  34384. {
  34385. var children = this.graph.getChildCells(swimlanes[i]);
  34386. if (children == null || children.length == 0)
  34387. {
  34388. var vertex = this.graph.insertVertex(swimlanes[i], null, null, 0, 0, this.dummyVertexWidth, 0);
  34389. dummyVertices.push(vertex);
  34390. }
  34391. }
  34392. model.beginUpdate();
  34393. try
  34394. {
  34395. this.run(parent);
  34396. if (this.resizeParent && !this.graph.isCellCollapsed(parent))
  34397. {
  34398. this.graph.updateGroupBounds([parent], this.parentBorder, this.moveParent);
  34399. }
  34400. // Maintaining parent location
  34401. if (this.parentX != null && this.parentY != null)
  34402. {
  34403. var geo = this.graph.getCellGeometry(parent);
  34404. if (geo != null)
  34405. {
  34406. geo = geo.clone();
  34407. geo.x = this.parentX;
  34408. geo.y = this.parentY;
  34409. model.setGeometry(parent, geo);
  34410. }
  34411. }
  34412. this.graph.removeCells(dummyVertices);
  34413. }
  34414. finally
  34415. {
  34416. model.endUpdate();
  34417. }
  34418. };
  34419. /**
  34420. * Function: updateGroupBounds
  34421. *
  34422. * Updates the bounds of the given array of groups so that it includes
  34423. * all child vertices.
  34424. *
  34425. */
  34426. mxSwimlaneLayout.prototype.updateGroupBounds = function()
  34427. {
  34428. // Get all vertices and edge in the layout
  34429. var cells = [];
  34430. var model = this.model;
  34431. for (var key in model.edgeMapper)
  34432. {
  34433. var edge = model.edgeMapper[key];
  34434. for (var i = 0; i < edge.edges.length; i++)
  34435. {
  34436. cells.push(edge.edges[i]);
  34437. }
  34438. }
  34439. var layoutBounds = this.graph.getBoundingBoxFromGeometry(cells, true);
  34440. var childBounds = [];
  34441. for (var i = 0; i < this.swimlanes.length; i++)
  34442. {
  34443. var lane = this.swimlanes[i];
  34444. var geo = this.graph.getCellGeometry(lane);
  34445. if (geo != null)
  34446. {
  34447. var children = this.graph.getChildCells(lane);
  34448. var size = (this.graph.isSwimlane(lane)) ?
  34449. this.graph.getStartSize(lane) : new mxRectangle();
  34450. var bounds = this.graph.getBoundingBoxFromGeometry(children);
  34451. childBounds[i] = bounds;
  34452. var childrenY = bounds.y + geo.y - size.height - this.parentBorder;
  34453. var maxChildrenY = bounds.y + geo.y + bounds.height;
  34454. if (layoutBounds == null)
  34455. {
  34456. layoutBounds = new mxRectangle(0, childrenY, 0, maxChildrenY - childrenY);
  34457. }
  34458. else
  34459. {
  34460. layoutBounds.y = Math.min(layoutBounds.y, childrenY);
  34461. var maxY = Math.max(layoutBounds.y + layoutBounds.height, maxChildrenY);
  34462. layoutBounds.height = maxY - layoutBounds.y;
  34463. }
  34464. }
  34465. }
  34466. for (var i = 0; i < this.swimlanes.length; i++)
  34467. {
  34468. var lane = this.swimlanes[i];
  34469. var geo = this.graph.getCellGeometry(lane);
  34470. if (geo != null)
  34471. {
  34472. var children = this.graph.getChildCells(lane);
  34473. var size = (this.graph.isSwimlane(lane)) ?
  34474. this.graph.getStartSize(lane) : new mxRectangle();
  34475. var newGeo = geo.clone();
  34476. var leftGroupBorder = (i == 0) ? this.parentBorder : this.interRankCellSpacing/2;
  34477. var w = size.width + leftGroupBorder;
  34478. var x = childBounds[i].x - w;
  34479. var y = layoutBounds.y - this.parentBorder;
  34480. newGeo.x += x;
  34481. newGeo.y = y;
  34482. newGeo.width = childBounds[i].width + w + this.interRankCellSpacing/2;
  34483. newGeo.height = layoutBounds.height + size.height + 2 * this.parentBorder;
  34484. this.graph.model.setGeometry(lane, newGeo);
  34485. this.graph.moveCells(children, -x, geo.y - y);
  34486. }
  34487. }
  34488. };
  34489. /**
  34490. * Function: findRoots
  34491. *
  34492. * Returns all visible children in the given parent which do not have
  34493. * incoming edges. If the result is empty then the children with the
  34494. * maximum difference between incoming and outgoing edges are returned.
  34495. * This takes into account edges that are being promoted to the given
  34496. * root due to invisible children or collapsed cells.
  34497. *
  34498. * Parameters:
  34499. *
  34500. * parent - <mxCell> whose children should be checked.
  34501. * vertices - array of vertices to limit search to
  34502. */
  34503. mxSwimlaneLayout.prototype.findRoots = function(parent, vertices)
  34504. {
  34505. var roots = [];
  34506. if (parent != null && vertices != null)
  34507. {
  34508. var model = this.graph.model;
  34509. var best = null;
  34510. var maxDiff = -100000;
  34511. for (var i in vertices)
  34512. {
  34513. var cell = vertices[i];
  34514. if (cell != null && model.isVertex(cell) && this.graph.isCellVisible(cell) && model.isAncestor(parent, cell))
  34515. {
  34516. var conns = this.getEdges(cell);
  34517. var fanOut = 0;
  34518. var fanIn = 0;
  34519. for (var k = 0; k < conns.length; k++)
  34520. {
  34521. var src = this.getVisibleTerminal(conns[k], true);
  34522. if (src == cell)
  34523. {
  34524. // Only count connection within this swimlane
  34525. var other = this.getVisibleTerminal(conns[k], false);
  34526. if (model.isAncestor(parent, other))
  34527. {
  34528. fanOut++;
  34529. }
  34530. }
  34531. else if (model.isAncestor(parent, src))
  34532. {
  34533. fanIn++;
  34534. }
  34535. }
  34536. if (fanIn == 0 && fanOut > 0)
  34537. {
  34538. roots.push(cell);
  34539. }
  34540. var diff = fanOut - fanIn;
  34541. if (diff > maxDiff)
  34542. {
  34543. maxDiff = diff;
  34544. best = cell;
  34545. }
  34546. }
  34547. }
  34548. if (roots.length == 0 && best != null)
  34549. {
  34550. roots.push(best);
  34551. }
  34552. }
  34553. return roots;
  34554. };
  34555. /**
  34556. * Function: getEdges
  34557. *
  34558. * Returns the connected edges for the given cell.
  34559. *
  34560. * Parameters:
  34561. *
  34562. * cell - <mxCell> whose edges should be returned.
  34563. */
  34564. mxSwimlaneLayout.prototype.getEdges = function(cell)
  34565. {
  34566. var cachedEdges = this.edgesCache.get(cell);
  34567. if (cachedEdges != null)
  34568. {
  34569. return cachedEdges;
  34570. }
  34571. var model = this.graph.model;
  34572. var edges = [];
  34573. var isCollapsed = this.graph.isCellCollapsed(cell);
  34574. var childCount = model.getChildCount(cell);
  34575. for (var i = 0; i < childCount; i++)
  34576. {
  34577. var child = model.getChildAt(cell, i);
  34578. if (this.isPort(child))
  34579. {
  34580. edges = edges.concat(model.getEdges(child, true, true));
  34581. }
  34582. else if (isCollapsed || !this.graph.isCellVisible(child))
  34583. {
  34584. edges = edges.concat(model.getEdges(child, true, true));
  34585. }
  34586. }
  34587. edges = edges.concat(model.getEdges(cell, true, true));
  34588. var result = [];
  34589. for (var i = 0; i < edges.length; i++)
  34590. {
  34591. var source = this.getVisibleTerminal(edges[i], true);
  34592. var target = this.getVisibleTerminal(edges[i], false);
  34593. if ((source == target) || ((source != target) && ((target == cell && (this.parent == null || this.graph.isValidAncestor(source, this.parent, this.traverseAncestors))) ||
  34594. (source == cell && (this.parent == null ||
  34595. this.graph.isValidAncestor(target, this.parent, this.traverseAncestors))))))
  34596. {
  34597. result.push(edges[i]);
  34598. }
  34599. }
  34600. this.edgesCache.put(cell, result);
  34601. return result;
  34602. };
  34603. /**
  34604. * Function: getVisibleTerminal
  34605. *
  34606. * Helper function to return visible terminal for edge allowing for ports
  34607. *
  34608. * Parameters:
  34609. *
  34610. * edge - <mxCell> whose edges should be returned.
  34611. * source - Boolean that specifies whether the source or target terminal is to be returned
  34612. */
  34613. mxSwimlaneLayout.prototype.getVisibleTerminal = function(edge, source)
  34614. {
  34615. var terminalCache = this.edgesTargetTermCache;
  34616. if (source)
  34617. {
  34618. terminalCache = this.edgeSourceTermCache;
  34619. }
  34620. var term = terminalCache.get(edge);
  34621. if (term != null)
  34622. {
  34623. return term;
  34624. }
  34625. var state = this.graph.view.getState(edge);
  34626. var terminal = (state != null) ? state.getVisibleTerminal(source) : this.graph.view.getVisibleTerminal(edge, source);
  34627. if (terminal == null)
  34628. {
  34629. terminal = (state != null) ? state.getVisibleTerminal(source) : this.graph.view.getVisibleTerminal(edge, source);
  34630. }
  34631. if (terminal != null)
  34632. {
  34633. if (this.isPort(terminal))
  34634. {
  34635. terminal = this.graph.model.getParent(terminal);
  34636. }
  34637. terminalCache.put(edge, terminal);
  34638. }
  34639. return terminal;
  34640. };
  34641. /**
  34642. * Function: run
  34643. *
  34644. * The API method used to exercise the layout upon the graph description
  34645. * and produce a separate description of the vertex position and edge
  34646. * routing changes made. It runs each stage of the layout that has been
  34647. * created.
  34648. */
  34649. mxSwimlaneLayout.prototype.run = function(parent)
  34650. {
  34651. // Separate out unconnected hierarchies
  34652. var hierarchyVertices = [];
  34653. var allVertexSet = Object();
  34654. if (this.swimlanes != null && this.swimlanes.length > 0 && parent != null)
  34655. {
  34656. var filledVertexSet = Object();
  34657. for (var i = 0; i < this.swimlanes.length; i++)
  34658. {
  34659. this.filterDescendants(this.swimlanes[i], filledVertexSet);
  34660. }
  34661. this.roots = [];
  34662. var filledVertexSetEmpty = true;
  34663. // Poor man's isSetEmpty
  34664. for (var key in filledVertexSet)
  34665. {
  34666. if (filledVertexSet[key] != null)
  34667. {
  34668. filledVertexSetEmpty = false;
  34669. break;
  34670. }
  34671. }
  34672. // Only test for candidates in each swimlane in order
  34673. var laneCounter = 0;
  34674. while (!filledVertexSetEmpty && laneCounter < this.swimlanes.length)
  34675. {
  34676. var candidateRoots = this.findRoots(this.swimlanes[laneCounter], filledVertexSet);
  34677. if (candidateRoots.length == 0)
  34678. {
  34679. laneCounter++;
  34680. continue;
  34681. }
  34682. // If the candidate root is an unconnected group cell, remove it from
  34683. // the layout. We may need a custom set that holds such groups and forces
  34684. // them to be processed for resizing and/or moving.
  34685. for (var i = 0; i < candidateRoots.length; i++)
  34686. {
  34687. var vertexSet = Object();
  34688. hierarchyVertices.push(vertexSet);
  34689. this.traverse(candidateRoots[i], true, null, allVertexSet, vertexSet,
  34690. hierarchyVertices, filledVertexSet, laneCounter);
  34691. }
  34692. for (var i = 0; i < candidateRoots.length; i++)
  34693. {
  34694. this.roots.push(candidateRoots[i]);
  34695. }
  34696. filledVertexSetEmpty = true;
  34697. // Poor man's isSetEmpty
  34698. for (var key in filledVertexSet)
  34699. {
  34700. if (filledVertexSet[key] != null)
  34701. {
  34702. filledVertexSetEmpty = false;
  34703. break;
  34704. }
  34705. }
  34706. }
  34707. }
  34708. else
  34709. {
  34710. // Find vertex set as directed traversal from roots
  34711. for (var i = 0; i < this.roots.length; i++)
  34712. {
  34713. var vertexSet = Object();
  34714. hierarchyVertices.push(vertexSet);
  34715. this.traverse(this.roots[i], true, null, allVertexSet, vertexSet,
  34716. hierarchyVertices, null);
  34717. }
  34718. }
  34719. var tmp = [];
  34720. for (var key in allVertexSet)
  34721. {
  34722. tmp.push(allVertexSet[key]);
  34723. }
  34724. this.model = new mxSwimlaneModel(this, tmp, this.roots,
  34725. parent, this.tightenToSource);
  34726. this.cycleStage(parent);
  34727. this.layeringStage();
  34728. this.crossingStage(parent);
  34729. this.placementStage(0, parent);
  34730. };
  34731. /**
  34732. * Function: filterDescendants
  34733. *
  34734. * Creates an array of descendant cells
  34735. */
  34736. mxSwimlaneLayout.prototype.filterDescendants = function(cell, result)
  34737. {
  34738. var model = this.graph.model;
  34739. if (model.isVertex(cell) && cell != this.parent && model.getParent(cell) != this.parent && this.graph.isCellVisible(cell))
  34740. {
  34741. result[mxObjectIdentity.get(cell)] = cell;
  34742. }
  34743. if (this.traverseAncestors || cell == this.parent
  34744. && this.graph.isCellVisible(cell))
  34745. {
  34746. var childCount = model.getChildCount(cell);
  34747. for (var i = 0; i < childCount; i++)
  34748. {
  34749. var child = model.getChildAt(cell, i);
  34750. // Ignore ports in the layout vertex list, they are dealt with
  34751. // in the traversal mechanisms
  34752. if (!this.isPort(child))
  34753. {
  34754. this.filterDescendants(child, result);
  34755. }
  34756. }
  34757. }
  34758. };
  34759. /**
  34760. * Function: isPort
  34761. *
  34762. * Returns true if the given cell is a "port", that is, when connecting to
  34763. * it, its parent is the connecting vertex in terms of graph traversal
  34764. *
  34765. * Parameters:
  34766. *
  34767. * cell - <mxCell> that represents the port.
  34768. */
  34769. mxSwimlaneLayout.prototype.isPort = function(cell)
  34770. {
  34771. if (cell.geometry.relative)
  34772. {
  34773. return true;
  34774. }
  34775. return false;
  34776. };
  34777. /**
  34778. * Function: getEdgesBetween
  34779. *
  34780. * Returns the edges between the given source and target. This takes into
  34781. * account collapsed and invisible cells and ports.
  34782. *
  34783. * Parameters:
  34784. *
  34785. * source -
  34786. * target -
  34787. * directed -
  34788. */
  34789. mxSwimlaneLayout.prototype.getEdgesBetween = function(source, target, directed)
  34790. {
  34791. directed = (directed != null) ? directed : false;
  34792. var edges = this.getEdges(source);
  34793. var result = [];
  34794. // Checks if the edge is connected to the correct
  34795. // cell and returns the first match
  34796. for (var i = 0; i < edges.length; i++)
  34797. {
  34798. var src = this.getVisibleTerminal(edges[i], true);
  34799. var trg = this.getVisibleTerminal(edges[i], false);
  34800. if ((src == source && trg == target) || (!directed && src == target && trg == source))
  34801. {
  34802. result.push(edges[i]);
  34803. }
  34804. }
  34805. return result;
  34806. };
  34807. /**
  34808. * Traverses the (directed) graph invoking the given function for each
  34809. * visited vertex and edge. The function is invoked with the current vertex
  34810. * and the incoming edge as a parameter. This implementation makes sure
  34811. * each vertex is only visited once. The function may return false if the
  34812. * traversal should stop at the given vertex.
  34813. *
  34814. * Parameters:
  34815. *
  34816. * vertex - <mxCell> that represents the vertex where the traversal starts.
  34817. * directed - boolean indicating if edges should only be traversed
  34818. * from source to target. Default is true.
  34819. * edge - Optional <mxCell> that represents the incoming edge. This is
  34820. * null for the first step of the traversal.
  34821. * allVertices - Array of cell paths for the visited cells.
  34822. * swimlaneIndex - the laid out order index of the swimlane vertex is contained in
  34823. */
  34824. mxSwimlaneLayout.prototype.traverse = function(vertex, directed, edge, allVertices, currentComp,
  34825. hierarchyVertices, filledVertexSet, swimlaneIndex)
  34826. {
  34827. if (vertex != null && allVertices != null)
  34828. {
  34829. // Has this vertex been seen before in any traversal
  34830. // And if the filled vertex set is populated, only
  34831. // process vertices in that it contains
  34832. var vertexID = mxObjectIdentity.get(vertex);
  34833. if ((allVertices[vertexID] == null)
  34834. && (filledVertexSet == null ? true : filledVertexSet[vertexID] != null))
  34835. {
  34836. if (currentComp[vertexID] == null)
  34837. {
  34838. currentComp[vertexID] = vertex;
  34839. }
  34840. if (allVertices[vertexID] == null)
  34841. {
  34842. allVertices[vertexID] = vertex;
  34843. }
  34844. if (filledVertexSet !== null)
  34845. {
  34846. delete filledVertexSet[vertexID];
  34847. }
  34848. var edges = this.getEdges(vertex);
  34849. var model = this.graph.model;
  34850. for (var i = 0; i < edges.length; i++)
  34851. {
  34852. var otherVertex = this.getVisibleTerminal(edges[i], true);
  34853. var isSource = otherVertex == vertex;
  34854. if (isSource)
  34855. {
  34856. otherVertex = this.getVisibleTerminal(edges[i], false);
  34857. }
  34858. var otherIndex = 0;
  34859. // Get the swimlane index of the other terminal
  34860. for (otherIndex = 0; otherIndex < this.swimlanes.length; otherIndex++)
  34861. {
  34862. if (model.isAncestor(this.swimlanes[otherIndex], otherVertex))
  34863. {
  34864. break;
  34865. }
  34866. }
  34867. if (otherIndex >= this.swimlanes.length)
  34868. {
  34869. continue;
  34870. }
  34871. // Traverse if the other vertex is within the same swimlane as
  34872. // as the current vertex, or if the swimlane index of the other
  34873. // vertex is greater than that of this vertex
  34874. if ((otherIndex > swimlaneIndex) ||
  34875. ((!directed || isSource) && otherIndex == swimlaneIndex))
  34876. {
  34877. currentComp = this.traverse(otherVertex, directed, edges[i], allVertices,
  34878. currentComp, hierarchyVertices,
  34879. filledVertexSet, otherIndex);
  34880. }
  34881. }
  34882. }
  34883. else
  34884. {
  34885. if (currentComp[vertexID] == null)
  34886. {
  34887. // We've seen this vertex before, but not in the current component
  34888. // This component and the one it's in need to be merged
  34889. for (var i = 0; i < hierarchyVertices.length; i++)
  34890. {
  34891. var comp = hierarchyVertices[i];
  34892. if (comp[vertexID] != null)
  34893. {
  34894. for (var key in comp)
  34895. {
  34896. currentComp[key] = comp[key];
  34897. }
  34898. // Remove the current component from the hierarchy set
  34899. hierarchyVertices.splice(i, 1);
  34900. return currentComp;
  34901. }
  34902. }
  34903. }
  34904. }
  34905. }
  34906. return currentComp;
  34907. };
  34908. /**
  34909. * Function: cycleStage
  34910. *
  34911. * Executes the cycle stage using mxMinimumCycleRemover.
  34912. */
  34913. mxSwimlaneLayout.prototype.cycleStage = function(parent)
  34914. {
  34915. var cycleStage = new mxSwimlaneOrdering(this);
  34916. cycleStage.execute(parent);
  34917. };
  34918. /**
  34919. * Function: layeringStage
  34920. *
  34921. * Implements first stage of a Sugiyama layout.
  34922. */
  34923. mxSwimlaneLayout.prototype.layeringStage = function()
  34924. {
  34925. this.model.initialRank();
  34926. this.model.fixRanks();
  34927. };
  34928. /**
  34929. * Function: crossingStage
  34930. *
  34931. * Executes the crossing stage using mxMedianHybridCrossingReduction.
  34932. */
  34933. mxSwimlaneLayout.prototype.crossingStage = function(parent)
  34934. {
  34935. var crossingStage = new mxMedianHybridCrossingReduction(this);
  34936. crossingStage.execute(parent);
  34937. };
  34938. /**
  34939. * Function: placementStage
  34940. *
  34941. * Executes the placement stage using mxCoordinateAssignment.
  34942. */
  34943. mxSwimlaneLayout.prototype.placementStage = function(initialX, parent)
  34944. {
  34945. var placementStage = new mxCoordinateAssignment(this, this.intraCellSpacing,
  34946. this.interRankCellSpacing, this.orientation, initialX,
  34947. this.parallelEdgeSpacing);
  34948. placementStage.fineTuning = this.fineTuning;
  34949. placementStage.execute(parent);
  34950. return placementStage.limitX + this.interHierarchySpacing;
  34951. };
  34952. /**
  34953. * Copyright (c) 2006-2018, JGraph Ltd
  34954. * Copyright (c) 2006-2018, Gaudenz Alder
  34955. */
  34956. /**
  34957. * Class: mxGraphModel
  34958. *
  34959. * Extends <mxEventSource> to implement a graph model. The graph model acts as
  34960. * a wrapper around the cells which are in charge of storing the actual graph
  34961. * datastructure. The model acts as a transactional wrapper with event
  34962. * notification for all changes, whereas the cells contain the atomic
  34963. * operations for updating the actual datastructure.
  34964. *
  34965. * Layers:
  34966. *
  34967. * The cell hierarchy in the model must have a top-level root cell which
  34968. * contains the layers (typically one default layer), which in turn contain the
  34969. * top-level cells of the layers. This means each cell is contained in a layer.
  34970. * If no layers are required, then all new cells should be added to the default
  34971. * layer.
  34972. *
  34973. * Layers are useful for hiding and showing groups of cells, or for placing
  34974. * groups of cells on top of other cells in the display. To identify a layer,
  34975. * the <isLayer> function is used. It returns true if the parent of the given
  34976. * cell is the root of the model.
  34977. *
  34978. * Events:
  34979. *
  34980. * See events section for more details. There is a new set of events for
  34981. * tracking transactional changes as they happen. The events are called
  34982. * startEdit for the initial beginUpdate, executed for each executed change
  34983. * and endEdit for the terminal endUpdate. The executed event contains a
  34984. * property called change which represents the change after execution.
  34985. *
  34986. * Encoding the model:
  34987. *
  34988. * To encode a graph model, use the following code:
  34989. *
  34990. * (code)
  34991. * var enc = new mxCodec();
  34992. * var node = enc.encode(graph.getModel());
  34993. * (end)
  34994. *
  34995. * This will create an XML node that contains all the model information.
  34996. *
  34997. * Encoding and decoding changes:
  34998. *
  34999. * For the encoding of changes, a graph model listener is required that encodes
  35000. * each change from the given array of changes.
  35001. *
  35002. * (code)
  35003. * model.addListener(mxEvent.CHANGE, function(sender, evt)
  35004. * {
  35005. * var changes = evt.getProperty('edit').changes;
  35006. * var nodes = [];
  35007. * var codec = new mxCodec();
  35008. *
  35009. * for (var i = 0; i < changes.length; i++)
  35010. * {
  35011. * nodes.push(codec.encode(changes[i]));
  35012. * }
  35013. * // do something with the nodes
  35014. * });
  35015. * (end)
  35016. *
  35017. * For the decoding and execution of changes, the codec needs a lookup function
  35018. * that allows it to resolve cell IDs as follows:
  35019. *
  35020. * (code)
  35021. * var codec = new mxCodec();
  35022. * codec.lookup = function(id)
  35023. * {
  35024. * return model.getCell(id);
  35025. * }
  35026. * (end)
  35027. *
  35028. * For each encoded change (represented by a node), the following code can be
  35029. * used to carry out the decoding and create a change object.
  35030. *
  35031. * (code)
  35032. * var changes = [];
  35033. * var change = codec.decode(node);
  35034. * change.model = model;
  35035. * change.execute();
  35036. * changes.push(change);
  35037. * (end)
  35038. *
  35039. * The changes can then be dispatched using the model as follows.
  35040. *
  35041. * (code)
  35042. * var edit = new mxUndoableEdit(model, false);
  35043. * edit.changes = changes;
  35044. *
  35045. * edit.notify = function()
  35046. * {
  35047. * edit.source.fireEvent(new mxEventObject(mxEvent.CHANGE,
  35048. * 'edit', edit, 'changes', edit.changes));
  35049. * edit.source.fireEvent(new mxEventObject(mxEvent.NOTIFY,
  35050. * 'edit', edit, 'changes', edit.changes));
  35051. * }
  35052. *
  35053. * model.fireEvent(new mxEventObject(mxEvent.UNDO, 'edit', edit));
  35054. * model.fireEvent(new mxEventObject(mxEvent.CHANGE,
  35055. * 'edit', edit, 'changes', changes));
  35056. * (end)
  35057. *
  35058. * Event: mxEvent.CHANGE
  35059. *
  35060. * Fires when an undoable edit is dispatched. The <code>edit</code> property
  35061. * contains the <mxUndoableEdit>. The <code>changes</code> property contains
  35062. * the array of atomic changes inside the undoable edit. The changes property
  35063. * is <strong>deprecated</strong>, please use edit.changes instead.
  35064. *
  35065. * Example:
  35066. *
  35067. * For finding newly inserted cells, the following code can be used:
  35068. *
  35069. * (code)
  35070. * graph.model.addListener(mxEvent.CHANGE, function(sender, evt)
  35071. * {
  35072. * var changes = evt.getProperty('edit').changes;
  35073. *
  35074. * for (var i = 0; i < changes.length; i++)
  35075. * {
  35076. * var change = changes[i];
  35077. *
  35078. * if (change instanceof mxChildChange &&
  35079. * change.change.previous == null)
  35080. * {
  35081. * graph.startEditingAtCell(change.child);
  35082. * break;
  35083. * }
  35084. * }
  35085. * });
  35086. * (end)
  35087. *
  35088. *
  35089. * Event: mxEvent.NOTIFY
  35090. *
  35091. * Same as <mxEvent.CHANGE>, this event can be used for classes that need to
  35092. * implement a sync mechanism between this model and, say, a remote model. In
  35093. * such a setup, only local changes should trigger a notify event and all
  35094. * changes should trigger a change event.
  35095. *
  35096. * Event: mxEvent.EXECUTE
  35097. *
  35098. * Fires between begin- and endUpdate and after an atomic change was executed
  35099. * in the model. The <code>change</code> property contains the atomic change
  35100. * that was executed.
  35101. *
  35102. * Event: mxEvent.EXECUTED
  35103. *
  35104. * Fires between START_EDIT and END_EDIT after an atomic change was executed.
  35105. * The <code>change</code> property contains the change that was executed.
  35106. *
  35107. * Event: mxEvent.BEGIN_UPDATE
  35108. *
  35109. * Fires after the <updateLevel> was incremented in <beginUpdate>. This event
  35110. * contains no properties.
  35111. *
  35112. * Event: mxEvent.START_EDIT
  35113. *
  35114. * Fires after the <updateLevel> was changed from 0 to 1. This event
  35115. * contains no properties.
  35116. *
  35117. * Event: mxEvent.END_UPDATE
  35118. *
  35119. * Fires after the <updateLevel> was decreased in <endUpdate> but before any
  35120. * notification or change dispatching. The <code>edit</code> property contains
  35121. * the <currentEdit>.
  35122. *
  35123. * Event: mxEvent.END_EDIT
  35124. *
  35125. * Fires after the <updateLevel> was changed from 1 to 0. This event
  35126. * contains no properties.
  35127. *
  35128. * Event: mxEvent.BEFORE_UNDO
  35129. *
  35130. * Fires before the change is dispatched after the update level has reached 0
  35131. * in <endUpdate>. The <code>edit</code> property contains the <curreneEdit>.
  35132. *
  35133. * Event: mxEvent.UNDO
  35134. *
  35135. * Fires after the change was dispatched in <endUpdate>. The <code>edit</code>
  35136. * property contains the <currentEdit>.
  35137. *
  35138. * Constructor: mxGraphModel
  35139. *
  35140. * Constructs a new graph model. If no root is specified then a new root
  35141. * <mxCell> with a default layer is created.
  35142. *
  35143. * Parameters:
  35144. *
  35145. * root - <mxCell> that represents the root cell.
  35146. */
  35147. function mxGraphModel(root)
  35148. {
  35149. this.currentEdit = this.createUndoableEdit();
  35150. if (root != null)
  35151. {
  35152. this.setRoot(root);
  35153. }
  35154. else
  35155. {
  35156. this.clear();
  35157. }
  35158. };
  35159. /**
  35160. * Extends mxEventSource.
  35161. */
  35162. mxGraphModel.prototype = new mxEventSource();
  35163. mxGraphModel.prototype.constructor = mxGraphModel;
  35164. /**
  35165. * Variable: root
  35166. *
  35167. * Holds the root cell, which in turn contains the cells that represent the
  35168. * layers of the diagram as child cells. That is, the actual elements of the
  35169. * diagram are supposed to live in the third generation of cells and below.
  35170. */
  35171. mxGraphModel.prototype.root = null;
  35172. /**
  35173. * Variable: cells
  35174. *
  35175. * Maps from Ids to cells.
  35176. */
  35177. mxGraphModel.prototype.cells = null;
  35178. /**
  35179. * Variable: maintainEdgeParent
  35180. *
  35181. * Specifies if edges should automatically be moved into the nearest common
  35182. * ancestor of their terminals. Default is true.
  35183. */
  35184. mxGraphModel.prototype.maintainEdgeParent = true;
  35185. /**
  35186. * Variable: ignoreRelativeEdgeParent
  35187. *
  35188. * Specifies if relative edge parents should be ignored for finding the nearest
  35189. * common ancestors of an edge's terminals. Default is true.
  35190. */
  35191. mxGraphModel.prototype.ignoreRelativeEdgeParent = true;
  35192. /**
  35193. * Variable: createIds
  35194. *
  35195. * Specifies if the model should automatically create Ids for new cells.
  35196. * Default is true.
  35197. */
  35198. mxGraphModel.prototype.createIds = true;
  35199. /**
  35200. * Variable: prefix
  35201. *
  35202. * Defines the prefix of new Ids. Default is an empty string.
  35203. */
  35204. mxGraphModel.prototype.prefix = '';
  35205. /**
  35206. * Variable: postfix
  35207. *
  35208. * Defines the postfix of new Ids. Default is an empty string.
  35209. */
  35210. mxGraphModel.prototype.postfix = '';
  35211. /**
  35212. * Variable: nextId
  35213. *
  35214. * Specifies the next Id to be created. Initial value is 0.
  35215. */
  35216. mxGraphModel.prototype.nextId = 0;
  35217. /**
  35218. * Variable: currentEdit
  35219. *
  35220. * Holds the changes for the current transaction. If the transaction is
  35221. * closed then a new object is created for this variable using
  35222. * <createUndoableEdit>.
  35223. */
  35224. mxGraphModel.prototype.currentEdit = null;
  35225. /**
  35226. * Variable: updateLevel
  35227. *
  35228. * Counter for the depth of nested transactions. Each call to <beginUpdate>
  35229. * will increment this number and each call to <endUpdate> will decrement
  35230. * it. When the counter reaches 0, the transaction is closed and the
  35231. * respective events are fired. Initial value is 0.
  35232. */
  35233. mxGraphModel.prototype.updateLevel = 0;
  35234. /**
  35235. * Variable: endingUpdate
  35236. *
  35237. * True if the program flow is currently inside endUpdate.
  35238. */
  35239. mxGraphModel.prototype.endingUpdate = false;
  35240. /**
  35241. * Function: clear
  35242. *
  35243. * Sets a new root using <createRoot>.
  35244. */
  35245. mxGraphModel.prototype.clear = function()
  35246. {
  35247. this.setRoot(this.createRoot());
  35248. };
  35249. /**
  35250. * Function: isCreateIds
  35251. *
  35252. * Returns <createIds>.
  35253. */
  35254. mxGraphModel.prototype.isCreateIds = function()
  35255. {
  35256. return this.createIds;
  35257. };
  35258. /**
  35259. * Function: setCreateIds
  35260. *
  35261. * Sets <createIds>.
  35262. */
  35263. mxGraphModel.prototype.setCreateIds = function(value)
  35264. {
  35265. this.createIds = value;
  35266. };
  35267. /**
  35268. * Function: createRoot
  35269. *
  35270. * Creates a new root cell with a default layer (child 0).
  35271. */
  35272. mxGraphModel.prototype.createRoot = function()
  35273. {
  35274. var cell = new mxCell();
  35275. cell.insert(new mxCell());
  35276. return cell;
  35277. };
  35278. /**
  35279. * Function: getCell
  35280. *
  35281. * Returns the <mxCell> for the specified Id or null if no cell can be
  35282. * found for the given Id.
  35283. *
  35284. * Parameters:
  35285. *
  35286. * id - A string representing the Id of the cell.
  35287. */
  35288. mxGraphModel.prototype.getCell = function(id)
  35289. {
  35290. return (this.cells != null) ? this.cells[id] : null;
  35291. };
  35292. /**
  35293. * Function: filterCells
  35294. *
  35295. * Returns the cells from the given array where the given filter function
  35296. * returns true.
  35297. */
  35298. mxGraphModel.prototype.filterCells = function(cells, filter)
  35299. {
  35300. var result = null;
  35301. if (cells != null)
  35302. {
  35303. result = [];
  35304. for (var i = 0; i < cells.length; i++)
  35305. {
  35306. if (filter(cells[i]))
  35307. {
  35308. result.push(cells[i]);
  35309. }
  35310. }
  35311. }
  35312. return result;
  35313. };
  35314. /**
  35315. * Function: getDescendants
  35316. *
  35317. * Returns all descendants of the given cell and the cell itself in an array.
  35318. *
  35319. * Parameters:
  35320. *
  35321. * parent - <mxCell> whose descendants should be returned.
  35322. */
  35323. mxGraphModel.prototype.getDescendants = function(parent)
  35324. {
  35325. return this.filterDescendants(null, parent);
  35326. };
  35327. /**
  35328. * Function: filterDescendants
  35329. *
  35330. * Visits all cells recursively and applies the specified filter function
  35331. * to each cell. If the function returns true then the cell is added
  35332. * to the resulting array. The parent and result paramters are optional.
  35333. * If parent is not specified then the recursion starts at <root>.
  35334. *
  35335. * Example:
  35336. * The following example extracts all vertices from a given model:
  35337. * (code)
  35338. * var filter = function(cell)
  35339. * {
  35340. * return model.isVertex(cell);
  35341. * }
  35342. * var vertices = model.filterDescendants(filter);
  35343. * (end)
  35344. *
  35345. * Parameters:
  35346. *
  35347. * filter - JavaScript function that takes an <mxCell> as an argument
  35348. * and returns a boolean.
  35349. * parent - Optional <mxCell> that is used as the root of the recursion.
  35350. */
  35351. mxGraphModel.prototype.filterDescendants = function(filter, parent)
  35352. {
  35353. // Creates a new array for storing the result
  35354. var result = [];
  35355. // Recursion starts at the root of the model
  35356. parent = parent || this.getRoot();
  35357. // Checks if the filter returns true for the cell
  35358. // and adds it to the result array
  35359. if (filter == null || filter(parent))
  35360. {
  35361. result.push(parent);
  35362. }
  35363. // Visits the children of the cell
  35364. var childCount = this.getChildCount(parent);
  35365. for (var i = 0; i < childCount; i++)
  35366. {
  35367. var child = this.getChildAt(parent, i);
  35368. result = result.concat(this.filterDescendants(filter, child));
  35369. }
  35370. return result;
  35371. };
  35372. /**
  35373. * Function: getRoot
  35374. *
  35375. * Returns the root of the model or the topmost parent of the given cell.
  35376. *
  35377. * Parameters:
  35378. *
  35379. * cell - Optional <mxCell> that specifies the child.
  35380. */
  35381. mxGraphModel.prototype.getRoot = function(cell)
  35382. {
  35383. var root = cell || this.root;
  35384. if (cell != null)
  35385. {
  35386. while (cell != null)
  35387. {
  35388. root = cell;
  35389. cell = this.getParent(cell);
  35390. }
  35391. }
  35392. return root;
  35393. };
  35394. /**
  35395. * Function: setRoot
  35396. *
  35397. * Sets the <root> of the model using <mxRootChange> and adds the change to
  35398. * the current transaction. This resets all datastructures in the model and
  35399. * is the preferred way of clearing an existing model. Returns the new
  35400. * root.
  35401. *
  35402. * Example:
  35403. *
  35404. * (code)
  35405. * var root = new mxCell();
  35406. * root.insert(new mxCell());
  35407. * model.setRoot(root);
  35408. * (end)
  35409. *
  35410. * Parameters:
  35411. *
  35412. * root - <mxCell> that specifies the new root.
  35413. */
  35414. mxGraphModel.prototype.setRoot = function(root)
  35415. {
  35416. this.execute(new mxRootChange(this, root));
  35417. return root;
  35418. };
  35419. /**
  35420. * Function: rootChanged
  35421. *
  35422. * Inner callback to change the root of the model and update the internal
  35423. * datastructures, such as <cells> and <nextId>. Returns the previous root.
  35424. *
  35425. * Parameters:
  35426. *
  35427. * root - <mxCell> that specifies the new root.
  35428. */
  35429. mxGraphModel.prototype.rootChanged = function(root)
  35430. {
  35431. var oldRoot = this.root;
  35432. this.root = root;
  35433. // Resets counters and datastructures
  35434. this.nextId = 0;
  35435. this.cells = null;
  35436. this.cellAdded(root);
  35437. return oldRoot;
  35438. };
  35439. /**
  35440. * Function: isRoot
  35441. *
  35442. * Returns true if the given cell is the root of the model and a non-null
  35443. * value.
  35444. *
  35445. * Parameters:
  35446. *
  35447. * cell - <mxCell> that represents the possible root.
  35448. */
  35449. mxGraphModel.prototype.isRoot = function(cell)
  35450. {
  35451. return cell != null && this.root == cell;
  35452. };
  35453. /**
  35454. * Function: isLayer
  35455. *
  35456. * Returns true if <isRoot> returns true for the parent of the given cell.
  35457. *
  35458. * Parameters:
  35459. *
  35460. * cell - <mxCell> that represents the possible layer.
  35461. */
  35462. mxGraphModel.prototype.isLayer = function(cell)
  35463. {
  35464. return this.isRoot(this.getParent(cell));
  35465. };
  35466. /**
  35467. * Function: isAncestor
  35468. *
  35469. * Returns true if the given parent is an ancestor of the given child. Note
  35470. * returns true if child == parent.
  35471. *
  35472. * Parameters:
  35473. *
  35474. * parent - <mxCell> that specifies the parent.
  35475. * child - <mxCell> that specifies the child.
  35476. */
  35477. mxGraphModel.prototype.isAncestor = function(parent, child)
  35478. {
  35479. while (child != null && child != parent)
  35480. {
  35481. child = this.getParent(child);
  35482. }
  35483. return child == parent;
  35484. };
  35485. /**
  35486. * Function: contains
  35487. *
  35488. * Returns true if the model contains the given <mxCell>.
  35489. *
  35490. * Parameters:
  35491. *
  35492. * cell - <mxCell> that specifies the cell.
  35493. */
  35494. mxGraphModel.prototype.contains = function(cell)
  35495. {
  35496. return this.isAncestor(this.root, cell);
  35497. };
  35498. /**
  35499. * Function: getParent
  35500. *
  35501. * Returns the parent of the given cell.
  35502. *
  35503. * Parameters:
  35504. *
  35505. * cell - <mxCell> whose parent should be returned.
  35506. */
  35507. mxGraphModel.prototype.getParent = function(cell)
  35508. {
  35509. return (cell != null) ? cell.getParent() : null;
  35510. };
  35511. /**
  35512. * Function: add
  35513. *
  35514. * Adds the specified child to the parent at the given index using
  35515. * <mxChildChange> and adds the change to the current transaction. If no
  35516. * index is specified then the child is appended to the parent's array of
  35517. * children. Returns the inserted child.
  35518. *
  35519. * Parameters:
  35520. *
  35521. * parent - <mxCell> that specifies the parent to contain the child.
  35522. * child - <mxCell> that specifies the child to be inserted.
  35523. * index - Optional integer that specifies the index of the child.
  35524. */
  35525. mxGraphModel.prototype.add = function(parent, child, index)
  35526. {
  35527. if (child != parent && parent != null && child != null)
  35528. {
  35529. // Appends the child if no index was specified
  35530. if (index == null)
  35531. {
  35532. index = this.getChildCount(parent);
  35533. }
  35534. var parentChanged = parent != this.getParent(child);
  35535. this.execute(new mxChildChange(this, parent, child, index));
  35536. // Maintains the edges parents by moving the edges
  35537. // into the nearest common ancestor of its terminals
  35538. if (this.maintainEdgeParent && parentChanged)
  35539. {
  35540. this.updateEdgeParents(child);
  35541. }
  35542. }
  35543. return child;
  35544. };
  35545. /**
  35546. * Function: cellAdded
  35547. *
  35548. * Inner callback to update <cells> when a cell has been added. This
  35549. * implementation resolves collisions by creating new Ids. To change the
  35550. * ID of a cell after it was inserted into the model, use the following
  35551. * code:
  35552. *
  35553. * (code
  35554. * delete model.cells[cell.getId()];
  35555. * cell.setId(newId);
  35556. * model.cells[cell.getId()] = cell;
  35557. * (end)
  35558. *
  35559. * If the change of the ID should be part of the command history, then the
  35560. * cell should be removed from the model and a clone with the new ID should
  35561. * be reinserted into the model instead.
  35562. *
  35563. * Parameters:
  35564. *
  35565. * cell - <mxCell> that specifies the cell that has been added.
  35566. */
  35567. mxGraphModel.prototype.cellAdded = function(cell)
  35568. {
  35569. if (cell != null)
  35570. {
  35571. // Creates an Id for the cell if not Id exists
  35572. if (cell.getId() == null && this.createIds)
  35573. {
  35574. cell.setId(this.createId(cell));
  35575. }
  35576. if (cell.getId() != null)
  35577. {
  35578. var collision = this.getCell(cell.getId());
  35579. if (collision != cell)
  35580. {
  35581. // Creates new Id for the cell
  35582. // as long as there is a collision
  35583. while (collision != null)
  35584. {
  35585. cell.setId(this.createId(cell));
  35586. collision = this.getCell(cell.getId());
  35587. }
  35588. // Lazily creates the cells dictionary
  35589. if (this.cells == null)
  35590. {
  35591. this.cells = new Object();
  35592. }
  35593. this.cells[cell.getId()] = cell;
  35594. }
  35595. }
  35596. // Makes sure IDs of deleted cells are not reused
  35597. if (mxUtils.isNumeric(cell.getId()))
  35598. {
  35599. this.nextId = Math.max(this.nextId, cell.getId());
  35600. }
  35601. // Recursively processes child cells
  35602. var childCount = this.getChildCount(cell);
  35603. for (var i=0; i<childCount; i++)
  35604. {
  35605. this.cellAdded(this.getChildAt(cell, i));
  35606. }
  35607. }
  35608. };
  35609. /**
  35610. * Function: createId
  35611. *
  35612. * Hook method to create an Id for the specified cell. This implementation
  35613. * concatenates <prefix>, id and <postfix> to create the Id and increments
  35614. * <nextId>. The cell is ignored by this implementation, but can be used in
  35615. * overridden methods to prefix the Ids with eg. the cell type.
  35616. *
  35617. * Parameters:
  35618. *
  35619. * cell - <mxCell> to create the Id for.
  35620. */
  35621. mxGraphModel.prototype.createId = function(cell)
  35622. {
  35623. var id = this.nextId;
  35624. this.nextId++;
  35625. return this.prefix + id + this.postfix;
  35626. };
  35627. /**
  35628. * Function: updateEdgeParents
  35629. *
  35630. * Updates the parent for all edges that are connected to cell or one of
  35631. * its descendants using <updateEdgeParent>.
  35632. */
  35633. mxGraphModel.prototype.updateEdgeParents = function(cell, root)
  35634. {
  35635. // Gets the topmost node of the hierarchy
  35636. root = root || this.getRoot(cell);
  35637. // Updates edges on children first
  35638. var childCount = this.getChildCount(cell);
  35639. for (var i = 0; i < childCount; i++)
  35640. {
  35641. var child = this.getChildAt(cell, i);
  35642. this.updateEdgeParents(child, root);
  35643. }
  35644. // Updates the parents of all connected edges
  35645. var edgeCount = this.getEdgeCount(cell);
  35646. var edges = [];
  35647. for (var i = 0; i < edgeCount; i++)
  35648. {
  35649. edges.push(this.getEdgeAt(cell, i));
  35650. }
  35651. for (var i = 0; i < edges.length; i++)
  35652. {
  35653. var edge = edges[i];
  35654. // Updates edge parent if edge and child have
  35655. // a common root node (does not need to be the
  35656. // model root node)
  35657. if (this.isAncestor(root, edge))
  35658. {
  35659. this.updateEdgeParent(edge, root);
  35660. }
  35661. }
  35662. };
  35663. /**
  35664. * Function: updateEdgeParent
  35665. *
  35666. * Inner callback to update the parent of the specified <mxCell> to the
  35667. * nearest-common-ancestor of its two terminals.
  35668. *
  35669. * Parameters:
  35670. *
  35671. * edge - <mxCell> that specifies the edge.
  35672. * root - <mxCell> that represents the current root of the model.
  35673. */
  35674. mxGraphModel.prototype.updateEdgeParent = function(edge, root)
  35675. {
  35676. var source = this.getTerminal(edge, true);
  35677. var target = this.getTerminal(edge, false);
  35678. var cell = null;
  35679. // Uses the first non-relative descendants of the source terminal
  35680. while (source != null && !this.isEdge(source) &&
  35681. source.geometry != null && source.geometry.relative)
  35682. {
  35683. source = this.getParent(source);
  35684. }
  35685. // Uses the first non-relative descendants of the target terminal
  35686. while (target != null && this.ignoreRelativeEdgeParent &&
  35687. !this.isEdge(target) && target.geometry != null &&
  35688. target.geometry.relative)
  35689. {
  35690. target = this.getParent(target);
  35691. }
  35692. if (this.isAncestor(root, source) && this.isAncestor(root, target))
  35693. {
  35694. if (source == target)
  35695. {
  35696. cell = this.getParent(source);
  35697. }
  35698. else
  35699. {
  35700. cell = this.getNearestCommonAncestor(source, target);
  35701. }
  35702. if (cell != null && (this.getParent(cell) != this.root ||
  35703. this.isAncestor(cell, edge)) && this.getParent(edge) != cell)
  35704. {
  35705. var geo = this.getGeometry(edge);
  35706. if (geo != null)
  35707. {
  35708. var origin1 = this.getOrigin(this.getParent(edge));
  35709. var origin2 = this.getOrigin(cell);
  35710. var dx = origin2.x - origin1.x;
  35711. var dy = origin2.y - origin1.y;
  35712. geo = geo.clone();
  35713. geo.translate(-dx, -dy);
  35714. this.setGeometry(edge, geo);
  35715. }
  35716. this.add(cell, edge, this.getChildCount(cell));
  35717. }
  35718. }
  35719. };
  35720. /**
  35721. * Function: getOrigin
  35722. *
  35723. * Returns the absolute, accumulated origin for the children inside the
  35724. * given parent as an <mxPoint>.
  35725. */
  35726. mxGraphModel.prototype.getOrigin = function(cell)
  35727. {
  35728. var result = null;
  35729. if (cell != null)
  35730. {
  35731. result = this.getOrigin(this.getParent(cell));
  35732. if (!this.isEdge(cell))
  35733. {
  35734. var geo = this.getGeometry(cell);
  35735. if (geo != null)
  35736. {
  35737. result.x += geo.x;
  35738. result.y += geo.y;
  35739. }
  35740. }
  35741. }
  35742. else
  35743. {
  35744. result = new mxPoint();
  35745. }
  35746. return result;
  35747. };
  35748. /**
  35749. * Function: getNearestCommonAncestor
  35750. *
  35751. * Returns the nearest common ancestor for the specified cells.
  35752. *
  35753. * Parameters:
  35754. *
  35755. * cell1 - <mxCell> that specifies the first cell in the tree.
  35756. * cell2 - <mxCell> that specifies the second cell in the tree.
  35757. */
  35758. mxGraphModel.prototype.getNearestCommonAncestor = function(cell1, cell2)
  35759. {
  35760. if (cell1 != null && cell2 != null)
  35761. {
  35762. // Creates the cell path for the second cell
  35763. var path = mxCellPath.create(cell2);
  35764. if (path != null && path.length > 0)
  35765. {
  35766. // Bubbles through the ancestors of the first
  35767. // cell to find the nearest common ancestor.
  35768. var cell = cell1;
  35769. var current = mxCellPath.create(cell);
  35770. // Inverts arguments
  35771. if (path.length < current.length)
  35772. {
  35773. cell = cell2;
  35774. var tmp = current;
  35775. current = path;
  35776. path = tmp;
  35777. }
  35778. while (cell != null)
  35779. {
  35780. var parent = this.getParent(cell);
  35781. // Checks if the cell path is equal to the beginning of the given cell path
  35782. if (path.indexOf(current + mxCellPath.PATH_SEPARATOR) == 0 && parent != null)
  35783. {
  35784. return cell;
  35785. }
  35786. current = mxCellPath.getParentPath(current);
  35787. cell = parent;
  35788. }
  35789. }
  35790. }
  35791. return null;
  35792. };
  35793. /**
  35794. * Function: remove
  35795. *
  35796. * Removes the specified cell from the model using <mxChildChange> and adds
  35797. * the change to the current transaction. This operation will remove the
  35798. * cell and all of its children from the model. Returns the removed cell.
  35799. *
  35800. * Parameters:
  35801. *
  35802. * cell - <mxCell> that should be removed.
  35803. */
  35804. mxGraphModel.prototype.remove = function(cell)
  35805. {
  35806. if (cell == this.root)
  35807. {
  35808. this.setRoot(null);
  35809. }
  35810. else if (this.getParent(cell) != null)
  35811. {
  35812. this.execute(new mxChildChange(this, null, cell));
  35813. }
  35814. return cell;
  35815. };
  35816. /**
  35817. * Function: cellRemoved
  35818. *
  35819. * Inner callback to update <cells> when a cell has been removed.
  35820. *
  35821. * Parameters:
  35822. *
  35823. * cell - <mxCell> that specifies the cell that has been removed.
  35824. */
  35825. mxGraphModel.prototype.cellRemoved = function(cell)
  35826. {
  35827. if (cell != null && this.cells != null)
  35828. {
  35829. // Recursively processes child cells
  35830. var childCount = this.getChildCount(cell);
  35831. for (var i = childCount - 1; i >= 0; i--)
  35832. {
  35833. this.cellRemoved(this.getChildAt(cell, i));
  35834. }
  35835. // Removes the dictionary entry for the cell
  35836. if (this.cells != null && cell.getId() != null)
  35837. {
  35838. delete this.cells[cell.getId()];
  35839. }
  35840. }
  35841. };
  35842. /**
  35843. * Function: parentForCellChanged
  35844. *
  35845. * Inner callback to update the parent of a cell using <mxCell.insert>
  35846. * on the parent and return the previous parent.
  35847. *
  35848. * Parameters:
  35849. *
  35850. * cell - <mxCell> to update the parent for.
  35851. * parent - <mxCell> that specifies the new parent of the cell.
  35852. * index - Optional integer that defines the index of the child
  35853. * in the parent's child array.
  35854. */
  35855. mxGraphModel.prototype.parentForCellChanged = function(cell, parent, index)
  35856. {
  35857. var previous = this.getParent(cell);
  35858. if (parent != null)
  35859. {
  35860. if (parent != previous || previous.getIndex(cell) != index)
  35861. {
  35862. parent.insert(cell, index);
  35863. }
  35864. }
  35865. else if (previous != null)
  35866. {
  35867. var oldIndex = previous.getIndex(cell);
  35868. previous.remove(oldIndex);
  35869. }
  35870. // Adds or removes the cell from the model
  35871. var par = this.contains(parent);
  35872. var pre = this.contains(previous);
  35873. if (par && !pre)
  35874. {
  35875. this.cellAdded(cell);
  35876. }
  35877. else if (pre && !par)
  35878. {
  35879. this.cellRemoved(cell);
  35880. }
  35881. return previous;
  35882. };
  35883. /**
  35884. * Function: getChildCount
  35885. *
  35886. * Returns the number of children in the given cell.
  35887. *
  35888. * Parameters:
  35889. *
  35890. * cell - <mxCell> whose number of children should be returned.
  35891. */
  35892. mxGraphModel.prototype.getChildCount = function(cell)
  35893. {
  35894. return (cell != null) ? cell.getChildCount() : 0;
  35895. };
  35896. /**
  35897. * Function: getChildAt
  35898. *
  35899. * Returns the child of the given <mxCell> at the given index.
  35900. *
  35901. * Parameters:
  35902. *
  35903. * cell - <mxCell> that represents the parent.
  35904. * index - Integer that specifies the index of the child to be returned.
  35905. */
  35906. mxGraphModel.prototype.getChildAt = function(cell, index)
  35907. {
  35908. return (cell != null) ? cell.getChildAt(index) : null;
  35909. };
  35910. /**
  35911. * Function: getChildren
  35912. *
  35913. * Returns all children of the given <mxCell> as an array of <mxCells>. The
  35914. * return value should be only be read.
  35915. *
  35916. * Parameters:
  35917. *
  35918. * cell - <mxCell> the represents the parent.
  35919. */
  35920. mxGraphModel.prototype.getChildren = function(cell)
  35921. {
  35922. return (cell != null) ? cell.children : null;
  35923. };
  35924. /**
  35925. * Function: getChildVertices
  35926. *
  35927. * Returns the child vertices of the given parent.
  35928. *
  35929. * Parameters:
  35930. *
  35931. * cell - <mxCell> whose child vertices should be returned.
  35932. */
  35933. mxGraphModel.prototype.getChildVertices = function(parent)
  35934. {
  35935. return this.getChildCells(parent, true, false);
  35936. };
  35937. /**
  35938. * Function: getChildEdges
  35939. *
  35940. * Returns the child edges of the given parent.
  35941. *
  35942. * Parameters:
  35943. *
  35944. * cell - <mxCell> whose child edges should be returned.
  35945. */
  35946. mxGraphModel.prototype.getChildEdges = function(parent)
  35947. {
  35948. return this.getChildCells(parent, false, true);
  35949. };
  35950. /**
  35951. * Function: getChildCells
  35952. *
  35953. * Returns the children of the given cell that are vertices and/or edges
  35954. * depending on the arguments.
  35955. *
  35956. * Parameters:
  35957. *
  35958. * cell - <mxCell> the represents the parent.
  35959. * vertices - Boolean indicating if child vertices should be returned.
  35960. * Default is false.
  35961. * edges - Boolean indicating if child edges should be returned.
  35962. * Default is false.
  35963. */
  35964. mxGraphModel.prototype.getChildCells = function(parent, vertices, edges)
  35965. {
  35966. vertices = (vertices != null) ? vertices : false;
  35967. edges = (edges != null) ? edges : false;
  35968. var childCount = this.getChildCount(parent);
  35969. var result = [];
  35970. for (var i = 0; i < childCount; i++)
  35971. {
  35972. var child = this.getChildAt(parent, i);
  35973. if ((!edges && !vertices) || (edges && this.isEdge(child)) ||
  35974. (vertices && this.isVertex(child)))
  35975. {
  35976. result.push(child);
  35977. }
  35978. }
  35979. return result;
  35980. };
  35981. /**
  35982. * Function: getTerminal
  35983. *
  35984. * Returns the source or target <mxCell> of the given edge depending on the
  35985. * value of the boolean parameter.
  35986. *
  35987. * Parameters:
  35988. *
  35989. * edge - <mxCell> that specifies the edge.
  35990. * isSource - Boolean indicating which end of the edge should be returned.
  35991. */
  35992. mxGraphModel.prototype.getTerminal = function(edge, isSource)
  35993. {
  35994. return (edge != null) ? edge.getTerminal(isSource) : null;
  35995. };
  35996. /**
  35997. * Function: setTerminal
  35998. *
  35999. * Sets the source or target terminal of the given <mxCell> using
  36000. * <mxTerminalChange> and adds the change to the current transaction.
  36001. * This implementation updates the parent of the edge using <updateEdgeParent>
  36002. * if required.
  36003. *
  36004. * Parameters:
  36005. *
  36006. * edge - <mxCell> that specifies the edge.
  36007. * terminal - <mxCell> that specifies the new terminal.
  36008. * isSource - Boolean indicating if the terminal is the new source or
  36009. * target terminal of the edge.
  36010. */
  36011. mxGraphModel.prototype.setTerminal = function(edge, terminal, isSource)
  36012. {
  36013. var terminalChanged = terminal != this.getTerminal(edge, isSource);
  36014. this.execute(new mxTerminalChange(this, edge, terminal, isSource));
  36015. if (this.maintainEdgeParent && terminalChanged)
  36016. {
  36017. this.updateEdgeParent(edge, this.getRoot());
  36018. }
  36019. return terminal;
  36020. };
  36021. /**
  36022. * Function: setTerminals
  36023. *
  36024. * Sets the source and target <mxCell> of the given <mxCell> in a single
  36025. * transaction using <setTerminal> for each end of the edge.
  36026. *
  36027. * Parameters:
  36028. *
  36029. * edge - <mxCell> that specifies the edge.
  36030. * source - <mxCell> that specifies the new source terminal.
  36031. * target - <mxCell> that specifies the new target terminal.
  36032. */
  36033. mxGraphModel.prototype.setTerminals = function(edge, source, target)
  36034. {
  36035. this.beginUpdate();
  36036. try
  36037. {
  36038. this.setTerminal(edge, source, true);
  36039. this.setTerminal(edge, target, false);
  36040. }
  36041. finally
  36042. {
  36043. this.endUpdate();
  36044. }
  36045. };
  36046. /**
  36047. * Function: terminalForCellChanged
  36048. *
  36049. * Inner helper function to update the terminal of the edge using
  36050. * <mxCell.insertEdge> and return the previous terminal.
  36051. *
  36052. * Parameters:
  36053. *
  36054. * edge - <mxCell> that specifies the edge to be updated.
  36055. * terminal - <mxCell> that specifies the new terminal.
  36056. * isSource - Boolean indicating if the terminal is the new source or
  36057. * target terminal of the edge.
  36058. */
  36059. mxGraphModel.prototype.terminalForCellChanged = function(edge, terminal, isSource)
  36060. {
  36061. var previous = this.getTerminal(edge, isSource);
  36062. if (terminal != null)
  36063. {
  36064. terminal.insertEdge(edge, isSource);
  36065. }
  36066. else if (previous != null)
  36067. {
  36068. previous.removeEdge(edge, isSource);
  36069. }
  36070. return previous;
  36071. };
  36072. /**
  36073. * Function: getEdgeCount
  36074. *
  36075. * Returns the number of distinct edges connected to the given cell.
  36076. *
  36077. * Parameters:
  36078. *
  36079. * cell - <mxCell> that represents the vertex.
  36080. */
  36081. mxGraphModel.prototype.getEdgeCount = function(cell)
  36082. {
  36083. return (cell != null) ? cell.getEdgeCount() : 0;
  36084. };
  36085. /**
  36086. * Function: getEdgeAt
  36087. *
  36088. * Returns the edge of cell at the given index.
  36089. *
  36090. * Parameters:
  36091. *
  36092. * cell - <mxCell> that specifies the vertex.
  36093. * index - Integer that specifies the index of the edge
  36094. * to return.
  36095. */
  36096. mxGraphModel.prototype.getEdgeAt = function(cell, index)
  36097. {
  36098. return (cell != null) ? cell.getEdgeAt(index) : null;
  36099. };
  36100. /**
  36101. * Function: getDirectedEdgeCount
  36102. *
  36103. * Returns the number of incoming or outgoing edges, ignoring the given
  36104. * edge.
  36105. *
  36106. * Parameters:
  36107. *
  36108. * cell - <mxCell> whose edge count should be returned.
  36109. * outgoing - Boolean that specifies if the number of outgoing or
  36110. * incoming edges should be returned.
  36111. * ignoredEdge - <mxCell> that represents an edge to be ignored.
  36112. */
  36113. mxGraphModel.prototype.getDirectedEdgeCount = function(cell, outgoing, ignoredEdge)
  36114. {
  36115. var count = 0;
  36116. var edgeCount = this.getEdgeCount(cell);
  36117. for (var i = 0; i < edgeCount; i++)
  36118. {
  36119. var edge = this.getEdgeAt(cell, i);
  36120. if (edge != ignoredEdge && this.getTerminal(edge, outgoing) == cell)
  36121. {
  36122. count++;
  36123. }
  36124. }
  36125. return count;
  36126. };
  36127. /**
  36128. * Function: getConnections
  36129. *
  36130. * Returns all edges of the given cell without loops.
  36131. *
  36132. * Parameters:
  36133. *
  36134. * cell - <mxCell> whose edges should be returned.
  36135. *
  36136. */
  36137. mxGraphModel.prototype.getConnections = function(cell)
  36138. {
  36139. return this.getEdges(cell, true, true, false);
  36140. };
  36141. /**
  36142. * Function: getIncomingEdges
  36143. *
  36144. * Returns the incoming edges of the given cell without loops.
  36145. *
  36146. * Parameters:
  36147. *
  36148. * cell - <mxCell> whose incoming edges should be returned.
  36149. *
  36150. */
  36151. mxGraphModel.prototype.getIncomingEdges = function(cell)
  36152. {
  36153. return this.getEdges(cell, true, false, false);
  36154. };
  36155. /**
  36156. * Function: getOutgoingEdges
  36157. *
  36158. * Returns the outgoing edges of the given cell without loops.
  36159. *
  36160. * Parameters:
  36161. *
  36162. * cell - <mxCell> whose outgoing edges should be returned.
  36163. *
  36164. */
  36165. mxGraphModel.prototype.getOutgoingEdges = function(cell)
  36166. {
  36167. return this.getEdges(cell, false, true, false);
  36168. };
  36169. /**
  36170. * Function: getEdges
  36171. *
  36172. * Returns all distinct edges connected to this cell as a new array of
  36173. * <mxCells>. If at least one of incoming or outgoing is true, then loops
  36174. * are ignored, otherwise if both are false, then all edges connected to
  36175. * the given cell are returned including loops.
  36176. *
  36177. * Parameters:
  36178. *
  36179. * cell - <mxCell> that specifies the cell.
  36180. * incoming - Optional boolean that specifies if incoming edges should be
  36181. * returned. Default is true.
  36182. * outgoing - Optional boolean that specifies if outgoing edges should be
  36183. * returned. Default is true.
  36184. * includeLoops - Optional boolean that specifies if loops should be returned.
  36185. * Default is true.
  36186. */
  36187. mxGraphModel.prototype.getEdges = function(cell, incoming, outgoing, includeLoops)
  36188. {
  36189. incoming = (incoming != null) ? incoming : true;
  36190. outgoing = (outgoing != null) ? outgoing : true;
  36191. includeLoops = (includeLoops != null) ? includeLoops : true;
  36192. var edgeCount = this.getEdgeCount(cell);
  36193. var result = [];
  36194. for (var i = 0; i < edgeCount; i++)
  36195. {
  36196. var edge = this.getEdgeAt(cell, i);
  36197. var source = this.getTerminal(edge, true);
  36198. var target = this.getTerminal(edge, false);
  36199. if ((includeLoops && source == target) || ((source != target) && ((incoming && target == cell) ||
  36200. (outgoing && source == cell))))
  36201. {
  36202. result.push(edge);
  36203. }
  36204. }
  36205. return result;
  36206. };
  36207. /**
  36208. * Function: getEdgesBetween
  36209. *
  36210. * Returns all edges between the given source and target pair. If directed
  36211. * is true, then only edges from the source to the target are returned,
  36212. * otherwise, all edges between the two cells are returned.
  36213. *
  36214. * Parameters:
  36215. *
  36216. * source - <mxCell> that defines the source terminal of the edge to be
  36217. * returned.
  36218. * target - <mxCell> that defines the target terminal of the edge to be
  36219. * returned.
  36220. * directed - Optional boolean that specifies if the direction of the
  36221. * edge should be taken into account. Default is false.
  36222. */
  36223. mxGraphModel.prototype.getEdgesBetween = function(source, target, directed)
  36224. {
  36225. directed = (directed != null) ? directed : false;
  36226. var tmp1 = this.getEdgeCount(source);
  36227. var tmp2 = this.getEdgeCount(target);
  36228. // Assumes the source has less connected edges
  36229. var terminal = source;
  36230. var edgeCount = tmp1;
  36231. // Uses the smaller array of connected edges
  36232. // for searching the edge
  36233. if (tmp2 < tmp1)
  36234. {
  36235. edgeCount = tmp2;
  36236. terminal = target;
  36237. }
  36238. var result = [];
  36239. // Checks if the edge is connected to the correct
  36240. // cell and returns the first match
  36241. for (var i = 0; i < edgeCount; i++)
  36242. {
  36243. var edge = this.getEdgeAt(terminal, i);
  36244. var src = this.getTerminal(edge, true);
  36245. var trg = this.getTerminal(edge, false);
  36246. var directedMatch = (src == source) && (trg == target);
  36247. var oppositeMatch = (trg == source) && (src == target);
  36248. if (directedMatch || (!directed && oppositeMatch))
  36249. {
  36250. result.push(edge);
  36251. }
  36252. }
  36253. return result;
  36254. };
  36255. /**
  36256. * Function: getOpposites
  36257. *
  36258. * Returns all opposite vertices wrt terminal for the given edges, only
  36259. * returning sources and/or targets as specified. The result is returned
  36260. * as an array of <mxCells>.
  36261. *
  36262. * Parameters:
  36263. *
  36264. * edges - Array of <mxCells> that contain the edges to be examined.
  36265. * terminal - <mxCell> that specifies the known end of the edges.
  36266. * sources - Boolean that specifies if source terminals should be contained
  36267. * in the result. Default is true.
  36268. * targets - Boolean that specifies if target terminals should be contained
  36269. * in the result. Default is true.
  36270. */
  36271. mxGraphModel.prototype.getOpposites = function(edges, terminal, sources, targets)
  36272. {
  36273. sources = (sources != null) ? sources : true;
  36274. targets = (targets != null) ? targets : true;
  36275. var terminals = [];
  36276. if (edges != null)
  36277. {
  36278. for (var i = 0; i < edges.length; i++)
  36279. {
  36280. var source = this.getTerminal(edges[i], true);
  36281. var target = this.getTerminal(edges[i], false);
  36282. // Checks if the terminal is the source of
  36283. // the edge and if the target should be
  36284. // stored in the result
  36285. if (source == terminal && target != null && target != terminal && targets)
  36286. {
  36287. terminals.push(target);
  36288. }
  36289. // Checks if the terminal is the taget of
  36290. // the edge and if the source should be
  36291. // stored in the result
  36292. else if (target == terminal && source != null && source != terminal && sources)
  36293. {
  36294. terminals.push(source);
  36295. }
  36296. }
  36297. }
  36298. return terminals;
  36299. };
  36300. /**
  36301. * Function: getTopmostCells
  36302. *
  36303. * Returns the topmost cells of the hierarchy in an array that contains no
  36304. * descendants for each <mxCell> that it contains. Duplicates should be
  36305. * removed in the cells array to improve performance.
  36306. *
  36307. * Parameters:
  36308. *
  36309. * cells - Array of <mxCells> whose topmost ancestors should be returned.
  36310. */
  36311. mxGraphModel.prototype.getTopmostCells = function(cells)
  36312. {
  36313. var dict = new mxDictionary();
  36314. var tmp = [];
  36315. for (var i = 0; i < cells.length; i++)
  36316. {
  36317. dict.put(cells[i], true);
  36318. }
  36319. for (var i = 0; i < cells.length; i++)
  36320. {
  36321. var cell = cells[i];
  36322. var topmost = true;
  36323. var parent = this.getParent(cell);
  36324. while (parent != null)
  36325. {
  36326. if (dict.get(parent))
  36327. {
  36328. topmost = false;
  36329. break;
  36330. }
  36331. parent = this.getParent(parent);
  36332. }
  36333. if (topmost)
  36334. {
  36335. tmp.push(cell);
  36336. }
  36337. }
  36338. return tmp;
  36339. };
  36340. /**
  36341. * Function: isVertex
  36342. *
  36343. * Returns true if the given cell is a vertex.
  36344. *
  36345. * Parameters:
  36346. *
  36347. * cell - <mxCell> that represents the possible vertex.
  36348. */
  36349. mxGraphModel.prototype.isVertex = function(cell)
  36350. {
  36351. return (cell != null) ? cell.isVertex() : false;
  36352. };
  36353. /**
  36354. * Function: isEdge
  36355. *
  36356. * Returns true if the given cell is an edge.
  36357. *
  36358. * Parameters:
  36359. *
  36360. * cell - <mxCell> that represents the possible edge.
  36361. */
  36362. mxGraphModel.prototype.isEdge = function(cell)
  36363. {
  36364. return (cell != null) ? cell.isEdge() : false;
  36365. };
  36366. /**
  36367. * Function: isConnectable
  36368. *
  36369. * Returns true if the given <mxCell> is connectable. If <edgesConnectable>
  36370. * is false, then this function returns false for all edges else it returns
  36371. * the return value of <mxCell.isConnectable>.
  36372. *
  36373. * Parameters:
  36374. *
  36375. * cell - <mxCell> whose connectable state should be returned.
  36376. */
  36377. mxGraphModel.prototype.isConnectable = function(cell)
  36378. {
  36379. return (cell != null) ? cell.isConnectable() : false;
  36380. };
  36381. /**
  36382. * Function: getValue
  36383. *
  36384. * Returns the user object of the given <mxCell> using <mxCell.getValue>.
  36385. *
  36386. * Parameters:
  36387. *
  36388. * cell - <mxCell> whose user object should be returned.
  36389. */
  36390. mxGraphModel.prototype.getValue = function(cell)
  36391. {
  36392. return (cell != null) ? cell.getValue() : null;
  36393. };
  36394. /**
  36395. * Function: setValue
  36396. *
  36397. * Sets the user object of then given <mxCell> using <mxValueChange>
  36398. * and adds the change to the current transaction.
  36399. *
  36400. * Parameters:
  36401. *
  36402. * cell - <mxCell> whose user object should be changed.
  36403. * value - Object that defines the new user object.
  36404. */
  36405. mxGraphModel.prototype.setValue = function(cell, value)
  36406. {
  36407. this.execute(new mxValueChange(this, cell, value));
  36408. return value;
  36409. };
  36410. /**
  36411. * Function: valueForCellChanged
  36412. *
  36413. * Inner callback to update the user object of the given <mxCell>
  36414. * using <mxCell.valueChanged> and return the previous value,
  36415. * that is, the return value of <mxCell.valueChanged>.
  36416. *
  36417. * To change a specific attribute in an XML node, the following code can be
  36418. * used.
  36419. *
  36420. * (code)
  36421. * graph.getModel().valueForCellChanged = function(cell, value)
  36422. * {
  36423. * var previous = cell.value.getAttribute('label');
  36424. * cell.value.setAttribute('label', value);
  36425. *
  36426. * return previous;
  36427. * };
  36428. * (end)
  36429. */
  36430. mxGraphModel.prototype.valueForCellChanged = function(cell, value)
  36431. {
  36432. return cell.valueChanged(value);
  36433. };
  36434. /**
  36435. * Function: getGeometry
  36436. *
  36437. * Returns the <mxGeometry> of the given <mxCell>.
  36438. *
  36439. * Parameters:
  36440. *
  36441. * cell - <mxCell> whose geometry should be returned.
  36442. */
  36443. mxGraphModel.prototype.getGeometry = function(cell)
  36444. {
  36445. return (cell != null) ? cell.getGeometry() : null;
  36446. };
  36447. /**
  36448. * Function: setGeometry
  36449. *
  36450. * Sets the <mxGeometry> of the given <mxCell>. The actual update
  36451. * of the cell is carried out in <geometryForCellChanged>. The
  36452. * <mxGeometryChange> action is used to encapsulate the change.
  36453. *
  36454. * Parameters:
  36455. *
  36456. * cell - <mxCell> whose geometry should be changed.
  36457. * geometry - <mxGeometry> that defines the new geometry.
  36458. */
  36459. mxGraphModel.prototype.setGeometry = function(cell, geometry)
  36460. {
  36461. if (geometry != this.getGeometry(cell))
  36462. {
  36463. this.execute(new mxGeometryChange(this, cell, geometry));
  36464. }
  36465. return geometry;
  36466. };
  36467. /**
  36468. * Function: geometryForCellChanged
  36469. *
  36470. * Inner callback to update the <mxGeometry> of the given <mxCell> using
  36471. * <mxCell.setGeometry> and return the previous <mxGeometry>.
  36472. */
  36473. mxGraphModel.prototype.geometryForCellChanged = function(cell, geometry)
  36474. {
  36475. var previous = this.getGeometry(cell);
  36476. cell.setGeometry(geometry);
  36477. return previous;
  36478. };
  36479. /**
  36480. * Function: getStyle
  36481. *
  36482. * Returns the style of the given <mxCell>.
  36483. *
  36484. * Parameters:
  36485. *
  36486. * cell - <mxCell> whose style should be returned.
  36487. */
  36488. mxGraphModel.prototype.getStyle = function(cell)
  36489. {
  36490. return (cell != null) ? cell.getStyle() : null;
  36491. };
  36492. /**
  36493. * Function: setStyle
  36494. *
  36495. * Sets the style of the given <mxCell> using <mxStyleChange> and
  36496. * adds the change to the current transaction.
  36497. *
  36498. * Parameters:
  36499. *
  36500. * cell - <mxCell> whose style should be changed.
  36501. * style - String of the form [stylename;|key=value;] to specify
  36502. * the new cell style.
  36503. */
  36504. mxGraphModel.prototype.setStyle = function(cell, style)
  36505. {
  36506. if (style != this.getStyle(cell))
  36507. {
  36508. this.execute(new mxStyleChange(this, cell, style));
  36509. }
  36510. return style;
  36511. };
  36512. /**
  36513. * Function: styleForCellChanged
  36514. *
  36515. * Inner callback to update the style of the given <mxCell>
  36516. * using <mxCell.setStyle> and return the previous style.
  36517. *
  36518. * Parameters:
  36519. *
  36520. * cell - <mxCell> that specifies the cell to be updated.
  36521. * style - String of the form [stylename;|key=value;] to specify
  36522. * the new cell style.
  36523. */
  36524. mxGraphModel.prototype.styleForCellChanged = function(cell, style)
  36525. {
  36526. var previous = this.getStyle(cell);
  36527. cell.setStyle(style);
  36528. return previous;
  36529. };
  36530. /**
  36531. * Function: isCollapsed
  36532. *
  36533. * Returns true if the given <mxCell> is collapsed.
  36534. *
  36535. * Parameters:
  36536. *
  36537. * cell - <mxCell> whose collapsed state should be returned.
  36538. */
  36539. mxGraphModel.prototype.isCollapsed = function(cell)
  36540. {
  36541. return (cell != null) ? cell.isCollapsed() : false;
  36542. };
  36543. /**
  36544. * Function: setCollapsed
  36545. *
  36546. * Sets the collapsed state of the given <mxCell> using <mxCollapseChange>
  36547. * and adds the change to the current transaction.
  36548. *
  36549. * Parameters:
  36550. *
  36551. * cell - <mxCell> whose collapsed state should be changed.
  36552. * collapsed - Boolean that specifies the new collpased state.
  36553. */
  36554. mxGraphModel.prototype.setCollapsed = function(cell, collapsed)
  36555. {
  36556. if (collapsed != this.isCollapsed(cell))
  36557. {
  36558. this.execute(new mxCollapseChange(this, cell, collapsed));
  36559. }
  36560. return collapsed;
  36561. };
  36562. /**
  36563. * Function: collapsedStateForCellChanged
  36564. *
  36565. * Inner callback to update the collapsed state of the
  36566. * given <mxCell> using <mxCell.setCollapsed> and return
  36567. * the previous collapsed state.
  36568. *
  36569. * Parameters:
  36570. *
  36571. * cell - <mxCell> that specifies the cell to be updated.
  36572. * collapsed - Boolean that specifies the new collpased state.
  36573. */
  36574. mxGraphModel.prototype.collapsedStateForCellChanged = function(cell, collapsed)
  36575. {
  36576. var previous = this.isCollapsed(cell);
  36577. cell.setCollapsed(collapsed);
  36578. return previous;
  36579. };
  36580. /**
  36581. * Function: isVisible
  36582. *
  36583. * Returns true if the given <mxCell> is visible.
  36584. *
  36585. * Parameters:
  36586. *
  36587. * cell - <mxCell> whose visible state should be returned.
  36588. */
  36589. mxGraphModel.prototype.isVisible = function(cell)
  36590. {
  36591. return (cell != null) ? cell.isVisible() : false;
  36592. };
  36593. /**
  36594. * Function: setVisible
  36595. *
  36596. * Sets the visible state of the given <mxCell> using <mxVisibleChange> and
  36597. * adds the change to the current transaction.
  36598. *
  36599. * Parameters:
  36600. *
  36601. * cell - <mxCell> whose visible state should be changed.
  36602. * visible - Boolean that specifies the new visible state.
  36603. */
  36604. mxGraphModel.prototype.setVisible = function(cell, visible)
  36605. {
  36606. if (visible != this.isVisible(cell))
  36607. {
  36608. this.execute(new mxVisibleChange(this, cell, visible));
  36609. }
  36610. return visible;
  36611. };
  36612. /**
  36613. * Function: visibleStateForCellChanged
  36614. *
  36615. * Inner callback to update the visible state of the
  36616. * given <mxCell> using <mxCell.setCollapsed> and return
  36617. * the previous visible state.
  36618. *
  36619. * Parameters:
  36620. *
  36621. * cell - <mxCell> that specifies the cell to be updated.
  36622. * visible - Boolean that specifies the new visible state.
  36623. */
  36624. mxGraphModel.prototype.visibleStateForCellChanged = function(cell, visible)
  36625. {
  36626. var previous = this.isVisible(cell);
  36627. cell.setVisible(visible);
  36628. return previous;
  36629. };
  36630. /**
  36631. * Function: execute
  36632. *
  36633. * Executes the given edit and fires events if required. The edit object
  36634. * requires an execute function which is invoked. The edit is added to the
  36635. * <currentEdit> between <beginUpdate> and <endUpdate> calls, so that
  36636. * events will be fired if this execute is an individual transaction, that
  36637. * is, if no previous <beginUpdate> calls have been made without calling
  36638. * <endUpdate>. This implementation fires an <execute> event before
  36639. * executing the given change.
  36640. *
  36641. * Parameters:
  36642. *
  36643. * change - Object that described the change.
  36644. */
  36645. mxGraphModel.prototype.execute = function(change)
  36646. {
  36647. change.execute();
  36648. this.beginUpdate();
  36649. this.currentEdit.add(change);
  36650. this.fireEvent(new mxEventObject(mxEvent.EXECUTE, 'change', change));
  36651. // New global executed event
  36652. this.fireEvent(new mxEventObject(mxEvent.EXECUTED, 'change', change));
  36653. this.endUpdate();
  36654. };
  36655. /**
  36656. * Function: beginUpdate
  36657. *
  36658. * Increments the <updateLevel> by one. The event notification
  36659. * is queued until <updateLevel> reaches 0 by use of
  36660. * <endUpdate>.
  36661. *
  36662. * All changes on <mxGraphModel> are transactional,
  36663. * that is, they are executed in a single undoable change
  36664. * on the model (without transaction isolation).
  36665. * Therefore, if you want to combine any
  36666. * number of changes into a single undoable change,
  36667. * you should group any two or more API calls that
  36668. * modify the graph model between <beginUpdate>
  36669. * and <endUpdate> calls as shown here:
  36670. *
  36671. * (code)
  36672. * var model = graph.getModel();
  36673. * var parent = graph.getDefaultParent();
  36674. * var index = model.getChildCount(parent);
  36675. * model.beginUpdate();
  36676. * try
  36677. * {
  36678. * model.add(parent, v1, index);
  36679. * model.add(parent, v2, index+1);
  36680. * }
  36681. * finally
  36682. * {
  36683. * model.endUpdate();
  36684. * }
  36685. * (end)
  36686. *
  36687. * Of course there is a shortcut for appending a
  36688. * sequence of cells into the default parent:
  36689. *
  36690. * (code)
  36691. * graph.addCells([v1, v2]).
  36692. * (end)
  36693. */
  36694. mxGraphModel.prototype.beginUpdate = function()
  36695. {
  36696. this.updateLevel++;
  36697. this.fireEvent(new mxEventObject(mxEvent.BEGIN_UPDATE));
  36698. if (this.updateLevel == 1)
  36699. {
  36700. this.fireEvent(new mxEventObject(mxEvent.START_EDIT));
  36701. }
  36702. };
  36703. /**
  36704. * Function: endUpdate
  36705. *
  36706. * Decrements the <updateLevel> by one and fires an <undo>
  36707. * event if the <updateLevel> reaches 0. This function
  36708. * indirectly fires a <change> event by invoking the notify
  36709. * function on the <currentEdit> und then creates a new
  36710. * <currentEdit> using <createUndoableEdit>.
  36711. *
  36712. * The <undo> event is fired only once per edit, whereas
  36713. * the <change> event is fired whenever the notify
  36714. * function is invoked, that is, on undo and redo of
  36715. * the edit.
  36716. */
  36717. mxGraphModel.prototype.endUpdate = function()
  36718. {
  36719. this.updateLevel--;
  36720. if (this.updateLevel == 0)
  36721. {
  36722. this.fireEvent(new mxEventObject(mxEvent.END_EDIT));
  36723. }
  36724. if (!this.endingUpdate)
  36725. {
  36726. this.endingUpdate = this.updateLevel == 0;
  36727. this.fireEvent(new mxEventObject(mxEvent.END_UPDATE, 'edit', this.currentEdit));
  36728. try
  36729. {
  36730. if (this.endingUpdate && !this.currentEdit.isEmpty())
  36731. {
  36732. this.fireEvent(new mxEventObject(mxEvent.BEFORE_UNDO, 'edit', this.currentEdit));
  36733. var tmp = this.currentEdit;
  36734. this.currentEdit = this.createUndoableEdit();
  36735. tmp.notify();
  36736. this.fireEvent(new mxEventObject(mxEvent.UNDO, 'edit', tmp));
  36737. }
  36738. }
  36739. finally
  36740. {
  36741. this.endingUpdate = false;
  36742. }
  36743. }
  36744. };
  36745. /**
  36746. * Function: createUndoableEdit
  36747. *
  36748. * Creates a new <mxUndoableEdit> that implements the
  36749. * notify function to fire a <change> and <notify> event
  36750. * through the <mxUndoableEdit>'s source.
  36751. *
  36752. * Parameters:
  36753. *
  36754. * significant - Optional boolean that specifies if the edit to be created is
  36755. * significant. Default is true.
  36756. */
  36757. mxGraphModel.prototype.createUndoableEdit = function(significant)
  36758. {
  36759. var edit = new mxUndoableEdit(this, (significant != null) ? significant : true);
  36760. edit.notify = function()
  36761. {
  36762. // LATER: Remove changes property (deprecated)
  36763. edit.source.fireEvent(new mxEventObject(mxEvent.CHANGE,
  36764. 'edit', edit, 'changes', edit.changes));
  36765. edit.source.fireEvent(new mxEventObject(mxEvent.NOTIFY,
  36766. 'edit', edit, 'changes', edit.changes));
  36767. };
  36768. return edit;
  36769. };
  36770. /**
  36771. * Function: mergeChildren
  36772. *
  36773. * Merges the children of the given cell into the given target cell inside
  36774. * this model. All cells are cloned unless there is a corresponding cell in
  36775. * the model with the same id, in which case the source cell is ignored and
  36776. * all edges are connected to the corresponding cell in this model. Edges
  36777. * are considered to have no identity and are always cloned unless the
  36778. * cloneAllEdges flag is set to false, in which case edges with the same
  36779. * id in the target model are reconnected to reflect the terminals of the
  36780. * source edges.
  36781. */
  36782. mxGraphModel.prototype.mergeChildren = function(from, to, cloneAllEdges)
  36783. {
  36784. cloneAllEdges = (cloneAllEdges != null) ? cloneAllEdges : true;
  36785. this.beginUpdate();
  36786. try
  36787. {
  36788. var mapping = new Object();
  36789. this.mergeChildrenImpl(from, to, cloneAllEdges, mapping);
  36790. // Post-processes all edges in the mapping and
  36791. // reconnects the terminals to the corresponding
  36792. // cells in the target model
  36793. for (var key in mapping)
  36794. {
  36795. var cell = mapping[key];
  36796. var terminal = this.getTerminal(cell, true);
  36797. if (terminal != null)
  36798. {
  36799. terminal = mapping[mxCellPath.create(terminal)];
  36800. this.setTerminal(cell, terminal, true);
  36801. }
  36802. terminal = this.getTerminal(cell, false);
  36803. if (terminal != null)
  36804. {
  36805. terminal = mapping[mxCellPath.create(terminal)];
  36806. this.setTerminal(cell, terminal, false);
  36807. }
  36808. }
  36809. }
  36810. finally
  36811. {
  36812. this.endUpdate();
  36813. }
  36814. };
  36815. /**
  36816. * Function: mergeChildren
  36817. *
  36818. * Clones the children of the source cell into the given target cell in
  36819. * this model and adds an entry to the mapping that maps from the source
  36820. * cell to the target cell with the same id or the clone of the source cell
  36821. * that was inserted into this model.
  36822. */
  36823. mxGraphModel.prototype.mergeChildrenImpl = function(from, to, cloneAllEdges, mapping)
  36824. {
  36825. this.beginUpdate();
  36826. try
  36827. {
  36828. var childCount = from.getChildCount();
  36829. for (var i = 0; i < childCount; i++)
  36830. {
  36831. var cell = from.getChildAt(i);
  36832. if (typeof(cell.getId) == 'function')
  36833. {
  36834. var id = cell.getId();
  36835. var target = (id != null && (!this.isEdge(cell) || !cloneAllEdges)) ?
  36836. this.getCell(id) : null;
  36837. // Clones and adds the child if no cell exists for the id
  36838. if (target == null)
  36839. {
  36840. var clone = cell.clone();
  36841. clone.setId(id);
  36842. // Sets the terminals from the original cell to the clone
  36843. // because the lookup uses strings not cells in JS
  36844. clone.setTerminal(cell.getTerminal(true), true);
  36845. clone.setTerminal(cell.getTerminal(false), false);
  36846. // Do *NOT* use model.add as this will move the edge away
  36847. // from the parent in updateEdgeParent if maintainEdgeParent
  36848. // is enabled in the target model
  36849. target = to.insert(clone);
  36850. this.cellAdded(target);
  36851. }
  36852. // Stores the mapping for later reconnecting edges
  36853. mapping[mxCellPath.create(cell)] = target;
  36854. // Recurses
  36855. this.mergeChildrenImpl(cell, target, cloneAllEdges, mapping);
  36856. }
  36857. }
  36858. }
  36859. finally
  36860. {
  36861. this.endUpdate();
  36862. }
  36863. };
  36864. /**
  36865. * Function: getParents
  36866. *
  36867. * Returns an array that represents the set (no duplicates) of all parents
  36868. * for the given array of cells.
  36869. *
  36870. * Parameters:
  36871. *
  36872. * cells - Array of cells whose parents should be returned.
  36873. */
  36874. mxGraphModel.prototype.getParents = function(cells)
  36875. {
  36876. var parents = [];
  36877. if (cells != null)
  36878. {
  36879. var dict = new mxDictionary();
  36880. for (var i = 0; i < cells.length; i++)
  36881. {
  36882. var parent = this.getParent(cells[i]);
  36883. if (parent != null && !dict.get(parent))
  36884. {
  36885. dict.put(parent, true);
  36886. parents.push(parent);
  36887. }
  36888. }
  36889. }
  36890. return parents;
  36891. };
  36892. //
  36893. // Cell Cloning
  36894. //
  36895. /**
  36896. * Function: cloneCell
  36897. *
  36898. * Returns a deep clone of the given <mxCell> (including
  36899. * the children) which is created using <cloneCells>.
  36900. *
  36901. * Parameters:
  36902. *
  36903. * cell - <mxCell> to be cloned.
  36904. * includeChildren - Optional boolean indicating if the cells should be cloned
  36905. * with all descendants. Default is true.
  36906. */
  36907. mxGraphModel.prototype.cloneCell = function(cell, includeChildren)
  36908. {
  36909. if (cell != null)
  36910. {
  36911. return this.cloneCells([cell], includeChildren)[0];
  36912. }
  36913. return null;
  36914. };
  36915. /**
  36916. * Function: cloneCells
  36917. *
  36918. * Returns an array of clones for the given array of <mxCells>.
  36919. * Depending on the value of includeChildren, a deep clone is created for
  36920. * each cell. Connections are restored based if the corresponding
  36921. * cell is contained in the passed in array.
  36922. *
  36923. * Parameters:
  36924. *
  36925. * cells - Array of <mxCell> to be cloned.
  36926. * includeChildren - Optional boolean indicating if the cells should be cloned
  36927. * with all descendants. Default is true.
  36928. * mapping - Optional mapping for existing clones.
  36929. */
  36930. mxGraphModel.prototype.cloneCells = function(cells, includeChildren, mapping)
  36931. {
  36932. includeChildren = (includeChildren != null) ? includeChildren : true;
  36933. mapping = (mapping != null) ? mapping : new Object();
  36934. var clones = [];
  36935. for (var i = 0; i < cells.length; i++)
  36936. {
  36937. if (cells[i] != null)
  36938. {
  36939. clones.push(this.cloneCellImpl(cells[i], mapping, includeChildren));
  36940. }
  36941. else
  36942. {
  36943. clones.push(null);
  36944. }
  36945. }
  36946. for (var i = 0; i < clones.length; i++)
  36947. {
  36948. if (clones[i] != null)
  36949. {
  36950. this.restoreClone(clones[i], cells[i], mapping);
  36951. }
  36952. }
  36953. return clones;
  36954. };
  36955. /**
  36956. * Function: cloneCellImpl
  36957. *
  36958. * Inner helper method for cloning cells recursively.
  36959. */
  36960. mxGraphModel.prototype.cloneCellImpl = function(cell, mapping, includeChildren)
  36961. {
  36962. var ident = mxObjectIdentity.get(cell);
  36963. var clone = mapping[ident];
  36964. if (clone == null)
  36965. {
  36966. clone = this.cellCloned(cell);
  36967. mapping[ident] = clone;
  36968. if (includeChildren)
  36969. {
  36970. var childCount = this.getChildCount(cell);
  36971. for (var i = 0; i < childCount; i++)
  36972. {
  36973. var cloneChild = this.cloneCellImpl(
  36974. this.getChildAt(cell, i), mapping, true);
  36975. clone.insert(cloneChild);
  36976. }
  36977. }
  36978. }
  36979. return clone;
  36980. };
  36981. /**
  36982. * Function: cellCloned
  36983. *
  36984. * Hook for cloning the cell. This returns cell.clone() or
  36985. * any possible exceptions.
  36986. */
  36987. mxGraphModel.prototype.cellCloned = function(cell)
  36988. {
  36989. return cell.clone();
  36990. };
  36991. /**
  36992. * Function: restoreClone
  36993. *
  36994. * Inner helper method for restoring the connections in
  36995. * a network of cloned cells.
  36996. */
  36997. mxGraphModel.prototype.restoreClone = function(clone, cell, mapping)
  36998. {
  36999. var source = this.getTerminal(cell, true);
  37000. if (source != null)
  37001. {
  37002. var tmp = mapping[mxObjectIdentity.get(source)];
  37003. if (tmp != null)
  37004. {
  37005. tmp.insertEdge(clone, true);
  37006. }
  37007. }
  37008. var target = this.getTerminal(cell, false);
  37009. if (target != null)
  37010. {
  37011. var tmp = mapping[mxObjectIdentity.get(target)];
  37012. if (tmp != null)
  37013. {
  37014. tmp.insertEdge(clone, false);
  37015. }
  37016. }
  37017. var childCount = this.getChildCount(clone);
  37018. for (var i = 0; i < childCount; i++)
  37019. {
  37020. this.restoreClone(this.getChildAt(clone, i),
  37021. this.getChildAt(cell, i), mapping);
  37022. }
  37023. };
  37024. //
  37025. // Atomic changes
  37026. //
  37027. /**
  37028. * Class: mxRootChange
  37029. *
  37030. * Action to change the root in a model.
  37031. *
  37032. * Constructor: mxRootChange
  37033. *
  37034. * Constructs a change of the root in the
  37035. * specified model.
  37036. */
  37037. function mxRootChange(model, root)
  37038. {
  37039. this.model = model;
  37040. this.root = root;
  37041. this.previous = root;
  37042. };
  37043. /**
  37044. * Function: execute
  37045. *
  37046. * Carries out a change of the root using
  37047. * <mxGraphModel.rootChanged>.
  37048. */
  37049. mxRootChange.prototype.execute = function()
  37050. {
  37051. this.root = this.previous;
  37052. this.previous = this.model.rootChanged(this.previous);
  37053. };
  37054. /**
  37055. * Class: mxChildChange
  37056. *
  37057. * Action to add or remove a child in a model.
  37058. *
  37059. * Constructor: mxChildChange
  37060. *
  37061. * Constructs a change of a child in the
  37062. * specified model.
  37063. */
  37064. function mxChildChange(model, parent, child, index)
  37065. {
  37066. this.model = model;
  37067. this.parent = parent;
  37068. this.previous = parent;
  37069. this.child = child;
  37070. this.index = index;
  37071. this.previousIndex = index;
  37072. };
  37073. /**
  37074. * Function: execute
  37075. *
  37076. * Changes the parent of <child> using
  37077. * <mxGraphModel.parentForCellChanged> and
  37078. * removes or restores the cell's
  37079. * connections.
  37080. */
  37081. mxChildChange.prototype.execute = function()
  37082. {
  37083. if (this.child != null)
  37084. {
  37085. var tmp = this.model.getParent(this.child);
  37086. var tmp2 = (tmp != null) ? tmp.getIndex(this.child) : 0;
  37087. if (this.previous == null)
  37088. {
  37089. this.connect(this.child, false);
  37090. }
  37091. tmp = this.model.parentForCellChanged(
  37092. this.child, this.previous, this.previousIndex);
  37093. if (this.previous != null)
  37094. {
  37095. this.connect(this.child, true);
  37096. }
  37097. this.parent = this.previous;
  37098. this.previous = tmp;
  37099. this.index = this.previousIndex;
  37100. this.previousIndex = tmp2;
  37101. }
  37102. };
  37103. /**
  37104. * Function: disconnect
  37105. *
  37106. * Disconnects the given cell recursively from its
  37107. * terminals and stores the previous terminal in the
  37108. * cell's terminals.
  37109. */
  37110. mxChildChange.prototype.connect = function(cell, isConnect)
  37111. {
  37112. isConnect = (isConnect != null) ? isConnect : true;
  37113. var source = cell.getTerminal(true);
  37114. var target = cell.getTerminal(false);
  37115. if (source != null)
  37116. {
  37117. if (isConnect)
  37118. {
  37119. this.model.terminalForCellChanged(cell, source, true);
  37120. }
  37121. else
  37122. {
  37123. this.model.terminalForCellChanged(cell, null, true);
  37124. }
  37125. }
  37126. if (target != null)
  37127. {
  37128. if (isConnect)
  37129. {
  37130. this.model.terminalForCellChanged(cell, target, false);
  37131. }
  37132. else
  37133. {
  37134. this.model.terminalForCellChanged(cell, null, false);
  37135. }
  37136. }
  37137. cell.setTerminal(source, true);
  37138. cell.setTerminal(target, false);
  37139. var childCount = this.model.getChildCount(cell);
  37140. for (var i=0; i<childCount; i++)
  37141. {
  37142. this.connect(this.model.getChildAt(cell, i), isConnect);
  37143. }
  37144. };
  37145. /**
  37146. * Class: mxTerminalChange
  37147. *
  37148. * Action to change a terminal in a model.
  37149. *
  37150. * Constructor: mxTerminalChange
  37151. *
  37152. * Constructs a change of a terminal in the
  37153. * specified model.
  37154. */
  37155. function mxTerminalChange(model, cell, terminal, source)
  37156. {
  37157. this.model = model;
  37158. this.cell = cell;
  37159. this.terminal = terminal;
  37160. this.previous = terminal;
  37161. this.source = source;
  37162. };
  37163. /**
  37164. * Function: execute
  37165. *
  37166. * Changes the terminal of <cell> to <previous> using
  37167. * <mxGraphModel.terminalForCellChanged>.
  37168. */
  37169. mxTerminalChange.prototype.execute = function()
  37170. {
  37171. if (this.cell != null)
  37172. {
  37173. this.terminal = this.previous;
  37174. this.previous = this.model.terminalForCellChanged(
  37175. this.cell, this.previous, this.source);
  37176. }
  37177. };
  37178. /**
  37179. * Class: mxValueChange
  37180. *
  37181. * Action to change a user object in a model.
  37182. *
  37183. * Constructor: mxValueChange
  37184. *
  37185. * Constructs a change of a user object in the
  37186. * specified model.
  37187. */
  37188. function mxValueChange(model, cell, value)
  37189. {
  37190. this.model = model;
  37191. this.cell = cell;
  37192. this.value = value;
  37193. this.previous = value;
  37194. };
  37195. /**
  37196. * Function: execute
  37197. *
  37198. * Changes the value of <cell> to <previous> using
  37199. * <mxGraphModel.valueForCellChanged>.
  37200. */
  37201. mxValueChange.prototype.execute = function()
  37202. {
  37203. if (this.cell != null)
  37204. {
  37205. this.value = this.previous;
  37206. this.previous = this.model.valueForCellChanged(
  37207. this.cell, this.previous);
  37208. }
  37209. };
  37210. /**
  37211. * Class: mxStyleChange
  37212. *
  37213. * Action to change a cell's style in a model.
  37214. *
  37215. * Constructor: mxStyleChange
  37216. *
  37217. * Constructs a change of a style in the
  37218. * specified model.
  37219. */
  37220. function mxStyleChange(model, cell, style)
  37221. {
  37222. this.model = model;
  37223. this.cell = cell;
  37224. this.style = style;
  37225. this.previous = style;
  37226. };
  37227. /**
  37228. * Function: execute
  37229. *
  37230. * Changes the style of <cell> to <previous> using
  37231. * <mxGraphModel.styleForCellChanged>.
  37232. */
  37233. mxStyleChange.prototype.execute = function()
  37234. {
  37235. if (this.cell != null)
  37236. {
  37237. this.style = this.previous;
  37238. this.previous = this.model.styleForCellChanged(
  37239. this.cell, this.previous);
  37240. }
  37241. };
  37242. /**
  37243. * Class: mxGeometryChange
  37244. *
  37245. * Action to change a cell's geometry in a model.
  37246. *
  37247. * Constructor: mxGeometryChange
  37248. *
  37249. * Constructs a change of a geometry in the
  37250. * specified model.
  37251. */
  37252. function mxGeometryChange(model, cell, geometry)
  37253. {
  37254. this.model = model;
  37255. this.cell = cell;
  37256. this.geometry = geometry;
  37257. this.previous = geometry;
  37258. };
  37259. /**
  37260. * Function: execute
  37261. *
  37262. * Changes the geometry of <cell> ro <previous> using
  37263. * <mxGraphModel.geometryForCellChanged>.
  37264. */
  37265. mxGeometryChange.prototype.execute = function()
  37266. {
  37267. if (this.cell != null)
  37268. {
  37269. this.geometry = this.previous;
  37270. this.previous = this.model.geometryForCellChanged(
  37271. this.cell, this.previous);
  37272. }
  37273. };
  37274. /**
  37275. * Class: mxCollapseChange
  37276. *
  37277. * Action to change a cell's collapsed state in a model.
  37278. *
  37279. * Constructor: mxCollapseChange
  37280. *
  37281. * Constructs a change of a collapsed state in the
  37282. * specified model.
  37283. */
  37284. function mxCollapseChange(model, cell, collapsed)
  37285. {
  37286. this.model = model;
  37287. this.cell = cell;
  37288. this.collapsed = collapsed;
  37289. this.previous = collapsed;
  37290. };
  37291. /**
  37292. * Function: execute
  37293. *
  37294. * Changes the collapsed state of <cell> to <previous> using
  37295. * <mxGraphModel.collapsedStateForCellChanged>.
  37296. */
  37297. mxCollapseChange.prototype.execute = function()
  37298. {
  37299. if (this.cell != null)
  37300. {
  37301. this.collapsed = this.previous;
  37302. this.previous = this.model.collapsedStateForCellChanged(
  37303. this.cell, this.previous);
  37304. }
  37305. };
  37306. /**
  37307. * Class: mxVisibleChange
  37308. *
  37309. * Action to change a cell's visible state in a model.
  37310. *
  37311. * Constructor: mxVisibleChange
  37312. *
  37313. * Constructs a change of a visible state in the
  37314. * specified model.
  37315. */
  37316. function mxVisibleChange(model, cell, visible)
  37317. {
  37318. this.model = model;
  37319. this.cell = cell;
  37320. this.visible = visible;
  37321. this.previous = visible;
  37322. };
  37323. /**
  37324. * Function: execute
  37325. *
  37326. * Changes the visible state of <cell> to <previous> using
  37327. * <mxGraphModel.visibleStateForCellChanged>.
  37328. */
  37329. mxVisibleChange.prototype.execute = function()
  37330. {
  37331. if (this.cell != null)
  37332. {
  37333. this.visible = this.previous;
  37334. this.previous = this.model.visibleStateForCellChanged(
  37335. this.cell, this.previous);
  37336. }
  37337. };
  37338. /**
  37339. * Class: mxCellAttributeChange
  37340. *
  37341. * Action to change the attribute of a cell's user object.
  37342. * There is no method on the graph model that uses this
  37343. * action. To use the action, you can use the code shown
  37344. * in the example below.
  37345. *
  37346. * Example:
  37347. *
  37348. * To change the attributeName in the cell's user object
  37349. * to attributeValue, use the following code:
  37350. *
  37351. * (code)
  37352. * model.beginUpdate();
  37353. * try
  37354. * {
  37355. * var edit = new mxCellAttributeChange(
  37356. * cell, attributeName, attributeValue);
  37357. * model.execute(edit);
  37358. * }
  37359. * finally
  37360. * {
  37361. * model.endUpdate();
  37362. * }
  37363. * (end)
  37364. *
  37365. * Constructor: mxCellAttributeChange
  37366. *
  37367. * Constructs a change of a attribute of the DOM node
  37368. * stored as the value of the given <mxCell>.
  37369. */
  37370. function mxCellAttributeChange(cell, attribute, value)
  37371. {
  37372. this.cell = cell;
  37373. this.attribute = attribute;
  37374. this.value = value;
  37375. this.previous = value;
  37376. };
  37377. /**
  37378. * Function: execute
  37379. *
  37380. * Changes the attribute of the cell's user object by
  37381. * using <mxCell.setAttribute>.
  37382. */
  37383. mxCellAttributeChange.prototype.execute = function()
  37384. {
  37385. if (this.cell != null)
  37386. {
  37387. var tmp = this.cell.getAttribute(this.attribute);
  37388. if (this.previous == null)
  37389. {
  37390. this.cell.value.removeAttribute(this.attribute);
  37391. }
  37392. else
  37393. {
  37394. this.cell.setAttribute(this.attribute, this.previous);
  37395. }
  37396. this.previous = tmp;
  37397. }
  37398. };
  37399. /**
  37400. * Copyright (c) 2006-2015, JGraph Ltd
  37401. * Copyright (c) 2006-2015, Gaudenz Alder
  37402. */
  37403. /**
  37404. * Class: mxCell
  37405. *
  37406. * Cells are the elements of the graph model. They represent the state
  37407. * of the groups, vertices and edges in a graph.
  37408. *
  37409. * Custom attributes:
  37410. *
  37411. * For custom attributes we recommend using an XML node as the value of a cell.
  37412. * The following code can be used to create a cell with an XML node as the
  37413. * value:
  37414. *
  37415. * (code)
  37416. * var doc = mxUtils.createXmlDocument();
  37417. * var node = doc.createElement('MyNode')
  37418. * node.setAttribute('label', 'MyLabel');
  37419. * node.setAttribute('attribute1', 'value1');
  37420. * graph.insertVertex(graph.getDefaultParent(), null, node, 40, 40, 80, 30);
  37421. * (end)
  37422. *
  37423. * For the label to work, <mxGraph.convertValueToString> and
  37424. * <mxGraph.cellLabelChanged> should be overridden as follows:
  37425. *
  37426. * (code)
  37427. * graph.convertValueToString = function(cell)
  37428. * {
  37429. * if (mxUtils.isNode(cell.value))
  37430. * {
  37431. * return cell.getAttribute('label', '')
  37432. * }
  37433. * };
  37434. *
  37435. * var cellLabelChanged = graph.cellLabelChanged;
  37436. * graph.cellLabelChanged = function(cell, newValue, autoSize)
  37437. * {
  37438. * if (mxUtils.isNode(cell.value))
  37439. * {
  37440. * // Clones the value for correct undo/redo
  37441. * var elt = cell.value.cloneNode(true);
  37442. * elt.setAttribute('label', newValue);
  37443. * newValue = elt;
  37444. * }
  37445. *
  37446. * cellLabelChanged.apply(this, arguments);
  37447. * };
  37448. * (end)
  37449. *
  37450. * Callback: onInit
  37451. *
  37452. * Called from within the constructor.
  37453. *
  37454. * Constructor: mxCell
  37455. *
  37456. * Constructs a new cell to be used in a graph model.
  37457. * This method invokes <onInit> upon completion.
  37458. *
  37459. * Parameters:
  37460. *
  37461. * value - Optional object that represents the cell value.
  37462. * geometry - Optional <mxGeometry> that specifies the geometry.
  37463. * style - Optional formatted string that defines the style.
  37464. */
  37465. function mxCell(value, geometry, style)
  37466. {
  37467. this.value = value;
  37468. this.setGeometry(geometry);
  37469. this.setStyle(style);
  37470. if (this.onInit != null)
  37471. {
  37472. this.onInit();
  37473. }
  37474. };
  37475. /**
  37476. * Variable: id
  37477. *
  37478. * Holds the Id. Default is null.
  37479. */
  37480. mxCell.prototype.id = null;
  37481. /**
  37482. * Variable: value
  37483. *
  37484. * Holds the user object. Default is null.
  37485. */
  37486. mxCell.prototype.value = null;
  37487. /**
  37488. * Variable: geometry
  37489. *
  37490. * Holds the <mxGeometry>. Default is null.
  37491. */
  37492. mxCell.prototype.geometry = null;
  37493. /**
  37494. * Variable: style
  37495. *
  37496. * Holds the style as a string of the form [(stylename|key=value);]. Default is
  37497. * null.
  37498. */
  37499. mxCell.prototype.style = null;
  37500. /**
  37501. * Variable: vertex
  37502. *
  37503. * Specifies whether the cell is a vertex. Default is false.
  37504. */
  37505. mxCell.prototype.vertex = false;
  37506. /**
  37507. * Variable: edge
  37508. *
  37509. * Specifies whether the cell is an edge. Default is false.
  37510. */
  37511. mxCell.prototype.edge = false;
  37512. /**
  37513. * Variable: connectable
  37514. *
  37515. * Specifies whether the cell is connectable. Default is true.
  37516. */
  37517. mxCell.prototype.connectable = true;
  37518. /**
  37519. * Variable: visible
  37520. *
  37521. * Specifies whether the cell is visible. Default is true.
  37522. */
  37523. mxCell.prototype.visible = true;
  37524. /**
  37525. * Variable: collapsed
  37526. *
  37527. * Specifies whether the cell is collapsed. Default is false.
  37528. */
  37529. mxCell.prototype.collapsed = false;
  37530. /**
  37531. * Variable: parent
  37532. *
  37533. * Reference to the parent cell.
  37534. */
  37535. mxCell.prototype.parent = null;
  37536. /**
  37537. * Variable: source
  37538. *
  37539. * Reference to the source terminal.
  37540. */
  37541. mxCell.prototype.source = null;
  37542. /**
  37543. * Variable: target
  37544. *
  37545. * Reference to the target terminal.
  37546. */
  37547. mxCell.prototype.target = null;
  37548. /**
  37549. * Variable: children
  37550. *
  37551. * Holds the child cells.
  37552. */
  37553. mxCell.prototype.children = null;
  37554. /**
  37555. * Variable: edges
  37556. *
  37557. * Holds the edges.
  37558. */
  37559. mxCell.prototype.edges = null;
  37560. /**
  37561. * Variable: mxTransient
  37562. *
  37563. * List of members that should not be cloned inside <clone>. This field is
  37564. * passed to <mxUtils.clone> and is not made persistent in <mxCellCodec>.
  37565. * This is not a convention for all classes, it is only used in this class
  37566. * to mark transient fields since transient modifiers are not supported by
  37567. * the language.
  37568. */
  37569. mxCell.prototype.mxTransient = ['id', 'value', 'parent', 'source',
  37570. 'target', 'children', 'edges'];
  37571. /**
  37572. * Function: getId
  37573. *
  37574. * Returns the Id of the cell as a string.
  37575. */
  37576. mxCell.prototype.getId = function()
  37577. {
  37578. return this.id;
  37579. };
  37580. /**
  37581. * Function: setId
  37582. *
  37583. * Sets the Id of the cell to the given string.
  37584. */
  37585. mxCell.prototype.setId = function(id)
  37586. {
  37587. this.id = id;
  37588. };
  37589. /**
  37590. * Function: getValue
  37591. *
  37592. * Returns the user object of the cell. The user
  37593. * object is stored in <value>.
  37594. */
  37595. mxCell.prototype.getValue = function()
  37596. {
  37597. return this.value;
  37598. };
  37599. /**
  37600. * Function: setValue
  37601. *
  37602. * Sets the user object of the cell. The user object
  37603. * is stored in <value>.
  37604. */
  37605. mxCell.prototype.setValue = function(value)
  37606. {
  37607. this.value = value;
  37608. };
  37609. /**
  37610. * Function: valueChanged
  37611. *
  37612. * Changes the user object after an in-place edit
  37613. * and returns the previous value. This implementation
  37614. * replaces the user object with the given value and
  37615. * returns the old user object.
  37616. */
  37617. mxCell.prototype.valueChanged = function(newValue)
  37618. {
  37619. var previous = this.getValue();
  37620. this.setValue(newValue);
  37621. return previous;
  37622. };
  37623. /**
  37624. * Function: getGeometry
  37625. *
  37626. * Returns the <mxGeometry> that describes the <geometry>.
  37627. */
  37628. mxCell.prototype.getGeometry = function()
  37629. {
  37630. return this.geometry;
  37631. };
  37632. /**
  37633. * Function: setGeometry
  37634. *
  37635. * Sets the <mxGeometry> to be used as the <geometry>.
  37636. */
  37637. mxCell.prototype.setGeometry = function(geometry)
  37638. {
  37639. this.geometry = geometry;
  37640. };
  37641. /**
  37642. * Function: getStyle
  37643. *
  37644. * Returns a string that describes the <style>.
  37645. */
  37646. mxCell.prototype.getStyle = function()
  37647. {
  37648. return this.style;
  37649. };
  37650. /**
  37651. * Function: setStyle
  37652. *
  37653. * Sets the string to be used as the <style>.
  37654. */
  37655. mxCell.prototype.setStyle = function(style)
  37656. {
  37657. this.style = style;
  37658. };
  37659. /**
  37660. * Function: isVertex
  37661. *
  37662. * Returns true if the cell is a vertex.
  37663. */
  37664. mxCell.prototype.isVertex = function()
  37665. {
  37666. return this.vertex != 0;
  37667. };
  37668. /**
  37669. * Function: setVertex
  37670. *
  37671. * Specifies if the cell is a vertex. This should only be assigned at
  37672. * construction of the cell and not be changed during its lifecycle.
  37673. *
  37674. * Parameters:
  37675. *
  37676. * vertex - Boolean that specifies if the cell is a vertex.
  37677. */
  37678. mxCell.prototype.setVertex = function(vertex)
  37679. {
  37680. this.vertex = vertex;
  37681. };
  37682. /**
  37683. * Function: isEdge
  37684. *
  37685. * Returns true if the cell is an edge.
  37686. */
  37687. mxCell.prototype.isEdge = function()
  37688. {
  37689. return this.edge != 0;
  37690. };
  37691. /**
  37692. * Function: setEdge
  37693. *
  37694. * Specifies if the cell is an edge. This should only be assigned at
  37695. * construction of the cell and not be changed during its lifecycle.
  37696. *
  37697. * Parameters:
  37698. *
  37699. * edge - Boolean that specifies if the cell is an edge.
  37700. */
  37701. mxCell.prototype.setEdge = function(edge)
  37702. {
  37703. this.edge = edge;
  37704. };
  37705. /**
  37706. * Function: isConnectable
  37707. *
  37708. * Returns true if the cell is connectable.
  37709. */
  37710. mxCell.prototype.isConnectable = function()
  37711. {
  37712. return this.connectable != 0;
  37713. };
  37714. /**
  37715. * Function: setConnectable
  37716. *
  37717. * Sets the connectable state.
  37718. *
  37719. * Parameters:
  37720. *
  37721. * connectable - Boolean that specifies the new connectable state.
  37722. */
  37723. mxCell.prototype.setConnectable = function(connectable)
  37724. {
  37725. this.connectable = connectable;
  37726. };
  37727. /**
  37728. * Function: isVisible
  37729. *
  37730. * Returns true if the cell is visibile.
  37731. */
  37732. mxCell.prototype.isVisible = function()
  37733. {
  37734. return this.visible != 0;
  37735. };
  37736. /**
  37737. * Function: setVisible
  37738. *
  37739. * Specifies if the cell is visible.
  37740. *
  37741. * Parameters:
  37742. *
  37743. * visible - Boolean that specifies the new visible state.
  37744. */
  37745. mxCell.prototype.setVisible = function(visible)
  37746. {
  37747. this.visible = visible;
  37748. };
  37749. /**
  37750. * Function: isCollapsed
  37751. *
  37752. * Returns true if the cell is collapsed.
  37753. */
  37754. mxCell.prototype.isCollapsed = function()
  37755. {
  37756. return this.collapsed != 0;
  37757. };
  37758. /**
  37759. * Function: setCollapsed
  37760. *
  37761. * Sets the collapsed state.
  37762. *
  37763. * Parameters:
  37764. *
  37765. * collapsed - Boolean that specifies the new collapsed state.
  37766. */
  37767. mxCell.prototype.setCollapsed = function(collapsed)
  37768. {
  37769. this.collapsed = collapsed;
  37770. };
  37771. /**
  37772. * Function: getParent
  37773. *
  37774. * Returns the cell's parent.
  37775. */
  37776. mxCell.prototype.getParent = function()
  37777. {
  37778. return this.parent;
  37779. };
  37780. /**
  37781. * Function: setParent
  37782. *
  37783. * Sets the parent cell.
  37784. *
  37785. * Parameters:
  37786. *
  37787. * parent - <mxCell> that represents the new parent.
  37788. */
  37789. mxCell.prototype.setParent = function(parent)
  37790. {
  37791. this.parent = parent;
  37792. };
  37793. /**
  37794. * Function: getTerminal
  37795. *
  37796. * Returns the source or target terminal.
  37797. *
  37798. * Parameters:
  37799. *
  37800. * source - Boolean that specifies if the source terminal should be
  37801. * returned.
  37802. */
  37803. mxCell.prototype.getTerminal = function(source)
  37804. {
  37805. return (source) ? this.source : this.target;
  37806. };
  37807. /**
  37808. * Function: setTerminal
  37809. *
  37810. * Sets the source or target terminal and returns the new terminal.
  37811. *
  37812. * Parameters:
  37813. *
  37814. * terminal - <mxCell> that represents the new source or target terminal.
  37815. * isSource - Boolean that specifies if the source or target terminal
  37816. * should be set.
  37817. */
  37818. mxCell.prototype.setTerminal = function(terminal, isSource)
  37819. {
  37820. if (isSource)
  37821. {
  37822. this.source = terminal;
  37823. }
  37824. else
  37825. {
  37826. this.target = terminal;
  37827. }
  37828. return terminal;
  37829. };
  37830. /**
  37831. * Function: getChildCount
  37832. *
  37833. * Returns the number of child cells.
  37834. */
  37835. mxCell.prototype.getChildCount = function()
  37836. {
  37837. return (this.children == null) ? 0 : this.children.length;
  37838. };
  37839. /**
  37840. * Function: getIndex
  37841. *
  37842. * Returns the index of the specified child in the child array.
  37843. *
  37844. * Parameters:
  37845. *
  37846. * child - Child whose index should be returned.
  37847. */
  37848. mxCell.prototype.getIndex = function(child)
  37849. {
  37850. return mxUtils.indexOf(this.children, child);
  37851. };
  37852. /**
  37853. * Function: getChildAt
  37854. *
  37855. * Returns the child at the specified index.
  37856. *
  37857. * Parameters:
  37858. *
  37859. * index - Integer that specifies the child to be returned.
  37860. */
  37861. mxCell.prototype.getChildAt = function(index)
  37862. {
  37863. return (this.children == null) ? null : this.children[index];
  37864. };
  37865. /**
  37866. * Function: insert
  37867. *
  37868. * Inserts the specified child into the child array at the specified index
  37869. * and updates the parent reference of the child. If not childIndex is
  37870. * specified then the child is appended to the child array. Returns the
  37871. * inserted child.
  37872. *
  37873. * Parameters:
  37874. *
  37875. * child - <mxCell> to be inserted or appended to the child array.
  37876. * index - Optional integer that specifies the index at which the child
  37877. * should be inserted into the child array.
  37878. */
  37879. mxCell.prototype.insert = function(child, index)
  37880. {
  37881. if (child != null)
  37882. {
  37883. if (index == null)
  37884. {
  37885. index = this.getChildCount();
  37886. if (child.getParent() == this)
  37887. {
  37888. index--;
  37889. }
  37890. }
  37891. child.removeFromParent();
  37892. child.setParent(this);
  37893. if (this.children == null)
  37894. {
  37895. this.children = [];
  37896. this.children.push(child);
  37897. }
  37898. else
  37899. {
  37900. this.children.splice(index, 0, child);
  37901. }
  37902. }
  37903. return child;
  37904. };
  37905. /**
  37906. * Function: remove
  37907. *
  37908. * Removes the child at the specified index from the child array and
  37909. * returns the child that was removed. Will remove the parent reference of
  37910. * the child.
  37911. *
  37912. * Parameters:
  37913. *
  37914. * index - Integer that specifies the index of the child to be
  37915. * removed.
  37916. */
  37917. mxCell.prototype.remove = function(index)
  37918. {
  37919. var child = null;
  37920. if (this.children != null && index >= 0)
  37921. {
  37922. child = this.getChildAt(index);
  37923. if (child != null)
  37924. {
  37925. this.children.splice(index, 1);
  37926. child.setParent(null);
  37927. }
  37928. }
  37929. return child;
  37930. };
  37931. /**
  37932. * Function: removeFromParent
  37933. *
  37934. * Removes the cell from its parent.
  37935. */
  37936. mxCell.prototype.removeFromParent = function()
  37937. {
  37938. if (this.parent != null)
  37939. {
  37940. var index = this.parent.getIndex(this);
  37941. this.parent.remove(index);
  37942. }
  37943. };
  37944. /**
  37945. * Function: getEdgeCount
  37946. *
  37947. * Returns the number of edges in the edge array.
  37948. */
  37949. mxCell.prototype.getEdgeCount = function()
  37950. {
  37951. return (this.edges == null) ? 0 : this.edges.length;
  37952. };
  37953. /**
  37954. * Function: getEdgeIndex
  37955. *
  37956. * Returns the index of the specified edge in <edges>.
  37957. *
  37958. * Parameters:
  37959. *
  37960. * edge - <mxCell> whose index in <edges> should be returned.
  37961. */
  37962. mxCell.prototype.getEdgeIndex = function(edge)
  37963. {
  37964. return mxUtils.indexOf(this.edges, edge);
  37965. };
  37966. /**
  37967. * Function: getEdgeAt
  37968. *
  37969. * Returns the edge at the specified index in <edges>.
  37970. *
  37971. * Parameters:
  37972. *
  37973. * index - Integer that specifies the index of the edge to be returned.
  37974. */
  37975. mxCell.prototype.getEdgeAt = function(index)
  37976. {
  37977. return (this.edges == null) ? null : this.edges[index];
  37978. };
  37979. /**
  37980. * Function: insertEdge
  37981. *
  37982. * Inserts the specified edge into the edge array and returns the edge.
  37983. * Will update the respective terminal reference of the edge.
  37984. *
  37985. * Parameters:
  37986. *
  37987. * edge - <mxCell> to be inserted into the edge array.
  37988. * isOutgoing - Boolean that specifies if the edge is outgoing.
  37989. */
  37990. mxCell.prototype.insertEdge = function(edge, isOutgoing)
  37991. {
  37992. if (edge != null)
  37993. {
  37994. edge.removeFromTerminal(isOutgoing);
  37995. edge.setTerminal(this, isOutgoing);
  37996. if (this.edges == null ||
  37997. edge.getTerminal(!isOutgoing) != this ||
  37998. mxUtils.indexOf(this.edges, edge) < 0)
  37999. {
  38000. if (this.edges == null)
  38001. {
  38002. this.edges = [];
  38003. }
  38004. this.edges.push(edge);
  38005. }
  38006. }
  38007. return edge;
  38008. };
  38009. /**
  38010. * Function: removeEdge
  38011. *
  38012. * Removes the specified edge from the edge array and returns the edge.
  38013. * Will remove the respective terminal reference from the edge.
  38014. *
  38015. * Parameters:
  38016. *
  38017. * edge - <mxCell> to be removed from the edge array.
  38018. * isOutgoing - Boolean that specifies if the edge is outgoing.
  38019. */
  38020. mxCell.prototype.removeEdge = function(edge, isOutgoing)
  38021. {
  38022. if (edge != null)
  38023. {
  38024. if (edge.getTerminal(!isOutgoing) != this &&
  38025. this.edges != null)
  38026. {
  38027. var index = this.getEdgeIndex(edge);
  38028. if (index >= 0)
  38029. {
  38030. this.edges.splice(index, 1);
  38031. }
  38032. }
  38033. edge.setTerminal(null, isOutgoing);
  38034. }
  38035. return edge;
  38036. };
  38037. /**
  38038. * Function: removeFromTerminal
  38039. *
  38040. * Removes the edge from its source or target terminal.
  38041. *
  38042. * Parameters:
  38043. *
  38044. * isSource - Boolean that specifies if the edge should be removed from its
  38045. * source or target terminal.
  38046. */
  38047. mxCell.prototype.removeFromTerminal = function(isSource)
  38048. {
  38049. var terminal = this.getTerminal(isSource);
  38050. if (terminal != null)
  38051. {
  38052. terminal.removeEdge(this, isSource);
  38053. }
  38054. };
  38055. /**
  38056. * Function: hasAttribute
  38057. *
  38058. * Returns true if the user object is an XML node that contains the given
  38059. * attribute.
  38060. *
  38061. * Parameters:
  38062. *
  38063. * name - Name of the attribute.
  38064. */
  38065. mxCell.prototype.hasAttribute = function(name)
  38066. {
  38067. var userObject = this.getValue();
  38068. return (userObject != null &&
  38069. userObject.nodeType == mxConstants.NODETYPE_ELEMENT && userObject.hasAttribute) ?
  38070. userObject.hasAttribute(name) : userObject.getAttribute(name) != null;
  38071. };
  38072. /**
  38073. * Function: getAttribute
  38074. *
  38075. * Returns the specified attribute from the user object if it is an XML
  38076. * node.
  38077. *
  38078. * Parameters:
  38079. *
  38080. * name - Name of the attribute whose value should be returned.
  38081. * defaultValue - Optional default value to use if the attribute has no
  38082. * value.
  38083. */
  38084. mxCell.prototype.getAttribute = function(name, defaultValue)
  38085. {
  38086. var userObject = this.getValue();
  38087. var val = (userObject != null &&
  38088. userObject.nodeType == mxConstants.NODETYPE_ELEMENT) ?
  38089. userObject.getAttribute(name) : null;
  38090. return (val != null) ? val : defaultValue;
  38091. };
  38092. /**
  38093. * Function: setAttribute
  38094. *
  38095. * Sets the specified attribute on the user object if it is an XML node.
  38096. *
  38097. * Parameters:
  38098. *
  38099. * name - Name of the attribute whose value should be set.
  38100. * value - New value of the attribute.
  38101. */
  38102. mxCell.prototype.setAttribute = function(name, value)
  38103. {
  38104. var userObject = this.getValue();
  38105. if (userObject != null &&
  38106. userObject.nodeType == mxConstants.NODETYPE_ELEMENT)
  38107. {
  38108. userObject.setAttribute(name, value);
  38109. }
  38110. };
  38111. /**
  38112. * Function: clone
  38113. *
  38114. * Returns a clone of the cell. Uses <cloneValue> to clone
  38115. * the user object. All fields in <mxTransient> are ignored
  38116. * during the cloning.
  38117. */
  38118. mxCell.prototype.clone = function()
  38119. {
  38120. var clone = mxUtils.clone(this, this.mxTransient);
  38121. clone.setValue(this.cloneValue());
  38122. return clone;
  38123. };
  38124. /**
  38125. * Function: cloneValue
  38126. *
  38127. * Returns a clone of the cell's user object.
  38128. */
  38129. mxCell.prototype.cloneValue = function()
  38130. {
  38131. var value = this.getValue();
  38132. if (value != null)
  38133. {
  38134. if (typeof(value.clone) == 'function')
  38135. {
  38136. value = value.clone();
  38137. }
  38138. else if (!isNaN(value.nodeType))
  38139. {
  38140. value = value.cloneNode(true);
  38141. }
  38142. }
  38143. return value;
  38144. };
  38145. /**
  38146. * Copyright (c) 2006-2015, JGraph Ltd
  38147. * Copyright (c) 2006-2015, Gaudenz Alder
  38148. */
  38149. /**
  38150. * Class: mxGeometry
  38151. *
  38152. * Extends <mxRectangle> to represent the geometry of a cell.
  38153. *
  38154. * For vertices, the geometry consists of the x- and y-location, and the width
  38155. * and height. For edges, the geometry consists of the optional terminal- and
  38156. * control points. The terminal points are only required if an edge is
  38157. * unconnected, and are stored in the <sourcePoint> and <targetPoint>
  38158. * variables, respectively.
  38159. *
  38160. * Example:
  38161. *
  38162. * If an edge is unconnected, that is, it has no source or target terminal,
  38163. * then a geometry with terminal points for a new edge can be defined as
  38164. * follows.
  38165. *
  38166. * (code)
  38167. * geometry.setTerminalPoint(new mxPoint(x1, y1), true);
  38168. * geometry.points = [new mxPoint(x2, y2)];
  38169. * geometry.setTerminalPoint(new mxPoint(x3, y3), false);
  38170. * (end)
  38171. *
  38172. * Control points are used regardless of the connected state of an edge and may
  38173. * be ignored or interpreted differently depending on the edge's <mxEdgeStyle>.
  38174. *
  38175. * To disable automatic reset of control points after a cell has been moved or
  38176. * resized, the the <mxGraph.resizeEdgesOnMove> and
  38177. * <mxGraph.resetEdgesOnResize> may be used.
  38178. *
  38179. * Edge Labels:
  38180. *
  38181. * Using the x- and y-coordinates of a cell's geometry, it is possible to
  38182. * position the label on edges on a specific location on the actual edge shape
  38183. * as it appears on the screen. The x-coordinate of an edge's geometry is used
  38184. * to describe the distance from the center of the edge from -1 to 1 with 0
  38185. * being the center of the edge and the default value. The y-coordinate of an
  38186. * edge's geometry is used to describe the absolute, orthogonal distance in
  38187. * pixels from that point. In addition, the <mxGeometry.offset> is used as an
  38188. * absolute offset vector from the resulting point.
  38189. *
  38190. * This coordinate system is applied if <relative> is true, otherwise the
  38191. * offset defines the absolute vector from the edge's center point to the
  38192. * label and the values for <x> and <y> are ignored.
  38193. *
  38194. * The width and height parameter for edge geometries can be used to set the
  38195. * label width and height (eg. for word wrapping).
  38196. *
  38197. * Ports:
  38198. *
  38199. * The term "port" refers to a relatively positioned, connectable child cell,
  38200. * which is used to specify the connection between the parent and another cell
  38201. * in the graph. Ports are typically modeled as vertices with relative
  38202. * geometries.
  38203. *
  38204. * Offsets:
  38205. *
  38206. * The <offset> field is interpreted in 3 different ways, depending on the cell
  38207. * and the geometry. For edges, the offset defines the absolute offset for the
  38208. * edge label. For relative geometries, the offset defines the absolute offset
  38209. * for the origin (top, left corner) of the vertex, otherwise the offset
  38210. * defines the absolute offset for the label inside the vertex or group.
  38211. *
  38212. * Constructor: mxGeometry
  38213. *
  38214. * Constructs a new object to describe the size and location of a vertex or
  38215. * the control points of an edge.
  38216. */
  38217. function mxGeometry(x, y, width, height)
  38218. {
  38219. mxRectangle.call(this, x, y, width, height);
  38220. };
  38221. /**
  38222. * Extends mxRectangle.
  38223. */
  38224. mxGeometry.prototype = new mxRectangle();
  38225. mxGeometry.prototype.constructor = mxGeometry;
  38226. /**
  38227. * Variable: TRANSLATE_CONTROL_POINTS
  38228. *
  38229. * Global switch to translate the points in translate. Default is true.
  38230. */
  38231. mxGeometry.prototype.TRANSLATE_CONTROL_POINTS = true;
  38232. /**
  38233. * Variable: alternateBounds
  38234. *
  38235. * Stores alternate values for x, y, width and height in a rectangle. See
  38236. * <swap> to exchange the values. Default is null.
  38237. */
  38238. mxGeometry.prototype.alternateBounds = null;
  38239. /**
  38240. * Variable: sourcePoint
  38241. *
  38242. * Defines the source <mxPoint> of the edge. This is used if the
  38243. * corresponding edge does not have a source vertex. Otherwise it is
  38244. * ignored. Default is null.
  38245. */
  38246. mxGeometry.prototype.sourcePoint = null;
  38247. /**
  38248. * Variable: targetPoint
  38249. *
  38250. * Defines the target <mxPoint> of the edge. This is used if the
  38251. * corresponding edge does not have a target vertex. Otherwise it is
  38252. * ignored. Default is null.
  38253. */
  38254. mxGeometry.prototype.targetPoint = null;
  38255. /**
  38256. * Variable: points
  38257. *
  38258. * Array of <mxPoints> which specifies the control points along the edge.
  38259. * These points are the intermediate points on the edge, for the endpoints
  38260. * use <targetPoint> and <sourcePoint> or set the terminals of the edge to
  38261. * a non-null value. Default is null.
  38262. */
  38263. mxGeometry.prototype.points = null;
  38264. /**
  38265. * Variable: offset
  38266. *
  38267. * For edges, this holds the offset (in pixels) from the position defined
  38268. * by <x> and <y> on the edge. For relative geometries (for vertices), this
  38269. * defines the absolute offset from the point defined by the relative
  38270. * coordinates. For absolute geometries (for vertices), this defines the
  38271. * offset for the label. Default is null.
  38272. */
  38273. mxGeometry.prototype.offset = null;
  38274. /**
  38275. * Variable: relative
  38276. *
  38277. * Specifies if the coordinates in the geometry are to be interpreted as
  38278. * relative coordinates. For edges, this is used to define the location of
  38279. * the edge label relative to the edge as rendered on the display. For
  38280. * vertices, this specifies the relative location inside the bounds of the
  38281. * parent cell.
  38282. *
  38283. * If this is false, then the coordinates are relative to the origin of the
  38284. * parent cell or, for edges, the edge label position is relative to the
  38285. * center of the edge as rendered on screen.
  38286. *
  38287. * Default is false.
  38288. */
  38289. mxGeometry.prototype.relative = false;
  38290. /**
  38291. * Function: swap
  38292. *
  38293. * Swaps the x, y, width and height with the values stored in
  38294. * <alternateBounds> and puts the previous values into <alternateBounds> as
  38295. * a rectangle. This operation is carried-out in-place, that is, using the
  38296. * existing geometry instance. If this operation is called during a graph
  38297. * model transactional change, then the geometry should be cloned before
  38298. * calling this method and setting the geometry of the cell using
  38299. * <mxGraphModel.setGeometry>.
  38300. */
  38301. mxGeometry.prototype.swap = function()
  38302. {
  38303. if (this.alternateBounds != null)
  38304. {
  38305. var old = new mxRectangle(
  38306. this.x, this.y, this.width, this.height);
  38307. this.x = this.alternateBounds.x;
  38308. this.y = this.alternateBounds.y;
  38309. this.width = this.alternateBounds.width;
  38310. this.height = this.alternateBounds.height;
  38311. this.alternateBounds = old;
  38312. }
  38313. };
  38314. /**
  38315. * Function: getTerminalPoint
  38316. *
  38317. * Returns the <mxPoint> representing the source or target point of this
  38318. * edge. This is only used if the edge has no source or target vertex.
  38319. *
  38320. * Parameters:
  38321. *
  38322. * isSource - Boolean that specifies if the source or target point
  38323. * should be returned.
  38324. */
  38325. mxGeometry.prototype.getTerminalPoint = function(isSource)
  38326. {
  38327. return (isSource) ? this.sourcePoint : this.targetPoint;
  38328. };
  38329. /**
  38330. * Function: setTerminalPoint
  38331. *
  38332. * Sets the <sourcePoint> or <targetPoint> to the given <mxPoint> and
  38333. * returns the new point.
  38334. *
  38335. * Parameters:
  38336. *
  38337. * point - Point to be used as the new source or target point.
  38338. * isSource - Boolean that specifies if the source or target point
  38339. * should be set.
  38340. */
  38341. mxGeometry.prototype.setTerminalPoint = function(point, isSource)
  38342. {
  38343. if (isSource)
  38344. {
  38345. this.sourcePoint = point;
  38346. }
  38347. else
  38348. {
  38349. this.targetPoint = point;
  38350. }
  38351. return point;
  38352. };
  38353. /**
  38354. * Function: rotate
  38355. *
  38356. * Rotates the geometry by the given angle around the given center. That is,
  38357. * <x> and <y> of the geometry, the <sourcePoint>, <targetPoint> and all
  38358. * <points> are translated by the given amount. <x> and <y> are only
  38359. * translated if <relative> is false.
  38360. *
  38361. * Parameters:
  38362. *
  38363. * angle - Number that specifies the rotation angle in degrees.
  38364. * cx - <mxPoint> that specifies the center of the rotation.
  38365. */
  38366. mxGeometry.prototype.rotate = function(angle, cx)
  38367. {
  38368. var rad = mxUtils.toRadians(angle);
  38369. var cos = Math.cos(rad);
  38370. var sin = Math.sin(rad);
  38371. // Rotates the geometry
  38372. if (!this.relative)
  38373. {
  38374. var ct = new mxPoint(this.getCenterX(), this.getCenterY());
  38375. var pt = mxUtils.getRotatedPoint(ct, cos, sin, cx);
  38376. this.x = Math.round(pt.x - this.width / 2);
  38377. this.y = Math.round(pt.y - this.height / 2);
  38378. }
  38379. // Rotates the source point
  38380. if (this.sourcePoint != null)
  38381. {
  38382. var pt = mxUtils.getRotatedPoint(this.sourcePoint, cos, sin, cx);
  38383. this.sourcePoint.x = Math.round(pt.x);
  38384. this.sourcePoint.y = Math.round(pt.y);
  38385. }
  38386. // Translates the target point
  38387. if (this.targetPoint != null)
  38388. {
  38389. var pt = mxUtils.getRotatedPoint(this.targetPoint, cos, sin, cx);
  38390. this.targetPoint.x = Math.round(pt.x);
  38391. this.targetPoint.y = Math.round(pt.y);
  38392. }
  38393. // Translate the control points
  38394. if (this.points != null)
  38395. {
  38396. for (var i = 0; i < this.points.length; i++)
  38397. {
  38398. if (this.points[i] != null)
  38399. {
  38400. var pt = mxUtils.getRotatedPoint(this.points[i], cos, sin, cx);
  38401. this.points[i].x = Math.round(pt.x);
  38402. this.points[i].y = Math.round(pt.y);
  38403. }
  38404. }
  38405. }
  38406. };
  38407. /**
  38408. * Function: translate
  38409. *
  38410. * Translates the geometry by the specified amount. That is, <x> and <y> of the
  38411. * geometry, the <sourcePoint>, <targetPoint> and all <points> are translated
  38412. * by the given amount. <x> and <y> are only translated if <relative> is false.
  38413. * If <TRANSLATE_CONTROL_POINTS> is false, then <points> are not modified by
  38414. * this function.
  38415. *
  38416. * Parameters:
  38417. *
  38418. * dx - Number that specifies the x-coordinate of the translation.
  38419. * dy - Number that specifies the y-coordinate of the translation.
  38420. */
  38421. mxGeometry.prototype.translate = function(dx, dy)
  38422. {
  38423. dx = parseFloat(dx);
  38424. dy = parseFloat(dy);
  38425. // Translates the geometry
  38426. if (!this.relative)
  38427. {
  38428. this.x = parseFloat(this.x) + dx;
  38429. this.y = parseFloat(this.y) + dy;
  38430. }
  38431. // Translates the source point
  38432. if (this.sourcePoint != null)
  38433. {
  38434. this.sourcePoint.x = parseFloat(this.sourcePoint.x) + dx;
  38435. this.sourcePoint.y = parseFloat(this.sourcePoint.y) + dy;
  38436. }
  38437. // Translates the target point
  38438. if (this.targetPoint != null)
  38439. {
  38440. this.targetPoint.x = parseFloat(this.targetPoint.x) + dx;
  38441. this.targetPoint.y = parseFloat(this.targetPoint.y) + dy;
  38442. }
  38443. // Translate the control points
  38444. if (this.TRANSLATE_CONTROL_POINTS && this.points != null)
  38445. {
  38446. for (var i = 0; i < this.points.length; i++)
  38447. {
  38448. if (this.points[i] != null)
  38449. {
  38450. this.points[i].x = parseFloat(this.points[i].x) + dx;
  38451. this.points[i].y = parseFloat(this.points[i].y) + dy;
  38452. }
  38453. }
  38454. }
  38455. };
  38456. /**
  38457. * Function: scale
  38458. *
  38459. * Scales the geometry by the given amount. That is, <x> and <y> of the
  38460. * geometry, the <sourcePoint>, <targetPoint> and all <points> are scaled
  38461. * by the given amount. <x>, <y>, <width> and <height> are only scaled if
  38462. * <relative> is false. If <fixedAspect> is true, then the smaller value
  38463. * is used to scale the width and the height.
  38464. *
  38465. * Parameters:
  38466. *
  38467. * sx - Number that specifies the horizontal scale factor.
  38468. * sy - Number that specifies the vertical scale factor.
  38469. * fixedAspect - Optional boolean to keep the aspect ratio fixed.
  38470. */
  38471. mxGeometry.prototype.scale = function(sx, sy, fixedAspect)
  38472. {
  38473. sx = parseFloat(sx);
  38474. sy = parseFloat(sy);
  38475. // Translates the source point
  38476. if (this.sourcePoint != null)
  38477. {
  38478. this.sourcePoint.x = parseFloat(this.sourcePoint.x) * sx;
  38479. this.sourcePoint.y = parseFloat(this.sourcePoint.y) * sy;
  38480. }
  38481. // Translates the target point
  38482. if (this.targetPoint != null)
  38483. {
  38484. this.targetPoint.x = parseFloat(this.targetPoint.x) * sx;
  38485. this.targetPoint.y = parseFloat(this.targetPoint.y) * sy;
  38486. }
  38487. // Translate the control points
  38488. if (this.points != null)
  38489. {
  38490. for (var i = 0; i < this.points.length; i++)
  38491. {
  38492. if (this.points[i] != null)
  38493. {
  38494. this.points[i].x = parseFloat(this.points[i].x) * sx;
  38495. this.points[i].y = parseFloat(this.points[i].y) * sy;
  38496. }
  38497. }
  38498. }
  38499. // Translates the geometry
  38500. if (!this.relative)
  38501. {
  38502. this.x = parseFloat(this.x) * sx;
  38503. this.y = parseFloat(this.y) * sy;
  38504. if (fixedAspect)
  38505. {
  38506. sy = sx = Math.min(sx, sy);
  38507. }
  38508. this.width = parseFloat(this.width) * sx;
  38509. this.height = parseFloat(this.height) * sy;
  38510. }
  38511. };
  38512. /**
  38513. * Function: equals
  38514. *
  38515. * Returns true if the given object equals this geometry.
  38516. */
  38517. mxGeometry.prototype.equals = function(obj)
  38518. {
  38519. return mxRectangle.prototype.equals.apply(this, arguments) &&
  38520. this.relative == obj.relative &&
  38521. ((this.sourcePoint == null && obj.sourcePoint == null) || (this.sourcePoint != null && this.sourcePoint.equals(obj.sourcePoint))) &&
  38522. ((this.targetPoint == null && obj.targetPoint == null) || (this.targetPoint != null && this.targetPoint.equals(obj.targetPoint))) &&
  38523. ((this.points == null && obj.points == null) || (this.points != null && mxUtils.equalPoints(this.points, obj.points))) &&
  38524. ((this.alternateBounds == null && obj.alternateBounds == null) || (this.alternateBounds != null && this.alternateBounds.equals(obj.alternateBounds))) &&
  38525. ((this.offset == null && obj.offset == null) || (this.offset != null && this.offset.equals(obj.offset)));
  38526. };
  38527. /**
  38528. * Copyright (c) 2006-2015, JGraph Ltd
  38529. * Copyright (c) 2006-2015, Gaudenz Alder
  38530. */
  38531. var mxCellPath =
  38532. {
  38533. /**
  38534. * Class: mxCellPath
  38535. *
  38536. * Implements a mechanism for temporary cell Ids.
  38537. *
  38538. * Variable: PATH_SEPARATOR
  38539. *
  38540. * Defines the separator between the path components. Default is ".".
  38541. */
  38542. PATH_SEPARATOR: '.',
  38543. /**
  38544. * Function: create
  38545. *
  38546. * Creates the cell path for the given cell. The cell path is a
  38547. * concatenation of the indices of all ancestors on the (finite) path to
  38548. * the root, eg. "0.0.0.1".
  38549. *
  38550. * Parameters:
  38551. *
  38552. * cell - Cell whose path should be returned.
  38553. */
  38554. create: function(cell)
  38555. {
  38556. var result = '';
  38557. if (cell != null)
  38558. {
  38559. var parent = cell.getParent();
  38560. while (parent != null)
  38561. {
  38562. var index = parent.getIndex(cell);
  38563. result = index + mxCellPath.PATH_SEPARATOR + result;
  38564. cell = parent;
  38565. parent = cell.getParent();
  38566. }
  38567. }
  38568. // Removes trailing separator
  38569. var n = result.length;
  38570. if (n > 1)
  38571. {
  38572. result = result.substring(0, n - 1);
  38573. }
  38574. return result;
  38575. },
  38576. /**
  38577. * Function: getParentPath
  38578. *
  38579. * Returns the path for the parent of the cell represented by the given
  38580. * path. Returns null if the given path has no parent.
  38581. *
  38582. * Parameters:
  38583. *
  38584. * path - Path whose parent path should be returned.
  38585. */
  38586. getParentPath: function(path)
  38587. {
  38588. if (path != null)
  38589. {
  38590. var index = path.lastIndexOf(mxCellPath.PATH_SEPARATOR);
  38591. if (index >= 0)
  38592. {
  38593. return path.substring(0, index);
  38594. }
  38595. else if (path.length > 0)
  38596. {
  38597. return '';
  38598. }
  38599. }
  38600. return null;
  38601. },
  38602. /**
  38603. * Function: resolve
  38604. *
  38605. * Returns the cell for the specified cell path using the given root as the
  38606. * root of the path.
  38607. *
  38608. * Parameters:
  38609. *
  38610. * root - Root cell of the path to be resolved.
  38611. * path - String that defines the path.
  38612. */
  38613. resolve: function(root, path)
  38614. {
  38615. var parent = root;
  38616. if (path != null)
  38617. {
  38618. var tokens = path.split(mxCellPath.PATH_SEPARATOR);
  38619. for (var i=0; i<tokens.length; i++)
  38620. {
  38621. parent = parent.getChildAt(parseInt(tokens[i]));
  38622. }
  38623. }
  38624. return parent;
  38625. },
  38626. /**
  38627. * Function: compare
  38628. *
  38629. * Compares the given cell paths and returns -1 if p1 is smaller, 0 if
  38630. * p1 is equal and 1 if p1 is greater than p2.
  38631. */
  38632. compare: function(p1, p2)
  38633. {
  38634. var min = Math.min(p1.length, p2.length);
  38635. var comp = 0;
  38636. for (var i = 0; i < min; i++)
  38637. {
  38638. if (p1[i] != p2[i])
  38639. {
  38640. if (p1[i].length == 0 ||
  38641. p2[i].length == 0)
  38642. {
  38643. comp = (p1[i] == p2[i]) ? 0 : ((p1[i] > p2[i]) ? 1 : -1);
  38644. }
  38645. else
  38646. {
  38647. var t1 = parseInt(p1[i]);
  38648. var t2 = parseInt(p2[i]);
  38649. comp = (t1 == t2) ? 0 : ((t1 > t2) ? 1 : -1);
  38650. }
  38651. break;
  38652. }
  38653. }
  38654. // Compares path length if both paths are equal to this point
  38655. if (comp == 0)
  38656. {
  38657. var t1 = p1.length;
  38658. var t2 = p2.length;
  38659. if (t1 != t2)
  38660. {
  38661. comp = (t1 > t2) ? 1 : -1;
  38662. }
  38663. }
  38664. return comp;
  38665. }
  38666. };
  38667. /**
  38668. * Copyright (c) 2006-2015, JGraph Ltd
  38669. * Copyright (c) 2006-2015, Gaudenz Alder
  38670. */
  38671. var mxPerimeter =
  38672. {
  38673. /**
  38674. * Class: mxPerimeter
  38675. *
  38676. * Provides various perimeter functions to be used in a style
  38677. * as the value of <mxConstants.STYLE_PERIMETER>. Perimeters for
  38678. * rectangle, circle, rhombus and triangle are available.
  38679. *
  38680. * Example:
  38681. *
  38682. * (code)
  38683. * <add as="perimeter">mxPerimeter.RectanglePerimeter</add>
  38684. * (end)
  38685. *
  38686. * Or programmatically:
  38687. *
  38688. * (code)
  38689. * style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RectanglePerimeter;
  38690. * (end)
  38691. *
  38692. * When adding new perimeter functions, it is recommended to use the
  38693. * mxPerimeter-namespace as follows:
  38694. *
  38695. * (code)
  38696. * mxPerimeter.CustomPerimeter = function (bounds, vertex, next, orthogonal)
  38697. * {
  38698. * var x = 0; // Calculate x-coordinate
  38699. * var y = 0; // Calculate y-coordainte
  38700. *
  38701. * return new mxPoint(x, y);
  38702. * }
  38703. * (end)
  38704. *
  38705. * The new perimeter should then be registered in the <mxStyleRegistry> as follows:
  38706. * (code)
  38707. * mxStyleRegistry.putValue('customPerimeter', mxPerimeter.CustomPerimeter);
  38708. * (end)
  38709. *
  38710. * The custom perimeter above can now be used in a specific vertex as follows:
  38711. *
  38712. * (code)
  38713. * model.setStyle(vertex, 'perimeter=customPerimeter');
  38714. * (end)
  38715. *
  38716. * Note that the key of the <mxStyleRegistry> entry for the function should
  38717. * be used in string values, unless <mxGraphView.allowEval> is true, in
  38718. * which case you can also use mxPerimeter.CustomPerimeter for the value in
  38719. * the cell style above.
  38720. *
  38721. * Or it can be used for all vertices in the graph as follows:
  38722. *
  38723. * (code)
  38724. * var style = graph.getStylesheet().getDefaultVertexStyle();
  38725. * style[mxConstants.STYLE_PERIMETER] = mxPerimeter.CustomPerimeter;
  38726. * (end)
  38727. *
  38728. * Note that the object can be used directly when programmatically setting
  38729. * the value, but the key in the <mxStyleRegistry> should be used when
  38730. * setting the value via a key, value pair in a cell style.
  38731. *
  38732. * The parameters are explained in <RectanglePerimeter>.
  38733. *
  38734. * Function: RectanglePerimeter
  38735. *
  38736. * Describes a rectangular perimeter for the given bounds.
  38737. *
  38738. * Parameters:
  38739. *
  38740. * bounds - <mxRectangle> that represents the absolute bounds of the
  38741. * vertex.
  38742. * vertex - <mxCellState> that represents the vertex.
  38743. * next - <mxPoint> that represents the nearest neighbour point on the
  38744. * given edge.
  38745. * orthogonal - Boolean that specifies if the orthogonal projection onto
  38746. * the perimeter should be returned. If this is false then the intersection
  38747. * of the perimeter and the line between the next and the center point is
  38748. * returned.
  38749. */
  38750. RectanglePerimeter: function (bounds, vertex, next, orthogonal)
  38751. {
  38752. var cx = bounds.getCenterX();
  38753. var cy = bounds.getCenterY();
  38754. var dx = next.x - cx;
  38755. var dy = next.y - cy;
  38756. var alpha = Math.atan2(dy, dx);
  38757. var p = new mxPoint(0, 0);
  38758. var pi = Math.PI;
  38759. var pi2 = Math.PI/2;
  38760. var beta = pi2 - alpha;
  38761. var t = Math.atan2(bounds.height, bounds.width);
  38762. if (alpha < -pi + t || alpha > pi - t)
  38763. {
  38764. // Left edge
  38765. p.x = bounds.x;
  38766. p.y = cy - bounds.width * Math.tan(alpha) / 2;
  38767. }
  38768. else if (alpha < -t)
  38769. {
  38770. // Top Edge
  38771. p.y = bounds.y;
  38772. p.x = cx - bounds.height * Math.tan(beta) / 2;
  38773. }
  38774. else if (alpha < t)
  38775. {
  38776. // Right Edge
  38777. p.x = bounds.x + bounds.width;
  38778. p.y = cy + bounds.width * Math.tan(alpha) / 2;
  38779. }
  38780. else
  38781. {
  38782. // Bottom Edge
  38783. p.y = bounds.y + bounds.height;
  38784. p.x = cx + bounds.height * Math.tan(beta) / 2;
  38785. }
  38786. if (orthogonal)
  38787. {
  38788. if (next.x >= bounds.x &&
  38789. next.x <= bounds.x + bounds.width)
  38790. {
  38791. p.x = next.x;
  38792. }
  38793. else if (next.y >= bounds.y &&
  38794. next.y <= bounds.y + bounds.height)
  38795. {
  38796. p.y = next.y;
  38797. }
  38798. if (next.x < bounds.x)
  38799. {
  38800. p.x = bounds.x;
  38801. }
  38802. else if (next.x > bounds.x + bounds.width)
  38803. {
  38804. p.x = bounds.x + bounds.width;
  38805. }
  38806. if (next.y < bounds.y)
  38807. {
  38808. p.y = bounds.y;
  38809. }
  38810. else if (next.y > bounds.y + bounds.height)
  38811. {
  38812. p.y = bounds.y + bounds.height;
  38813. }
  38814. }
  38815. return p;
  38816. },
  38817. /**
  38818. * Function: EllipsePerimeter
  38819. *
  38820. * Describes an elliptic perimeter. See <RectanglePerimeter>
  38821. * for a description of the parameters.
  38822. */
  38823. EllipsePerimeter: function (bounds, vertex, next, orthogonal)
  38824. {
  38825. var x = bounds.x;
  38826. var y = bounds.y;
  38827. var a = bounds.width / 2;
  38828. var b = bounds.height / 2;
  38829. var cx = x + a;
  38830. var cy = y + b;
  38831. var px = next.x;
  38832. var py = next.y;
  38833. // Calculates straight line equation through
  38834. // point and ellipse center y = d * x + h
  38835. var dx = parseInt(px - cx);
  38836. var dy = parseInt(py - cy);
  38837. if (dx == 0 && dy != 0)
  38838. {
  38839. return new mxPoint(cx, cy + b * dy / Math.abs(dy));
  38840. }
  38841. else if (dx == 0 && dy == 0)
  38842. {
  38843. return new mxPoint(px, py);
  38844. }
  38845. if (orthogonal)
  38846. {
  38847. if (py >= y && py <= y + bounds.height)
  38848. {
  38849. var ty = py - cy;
  38850. var tx = Math.sqrt(a*a*(1-(ty*ty)/(b*b))) || 0;
  38851. if (px <= x)
  38852. {
  38853. tx = -tx;
  38854. }
  38855. return new mxPoint(cx+tx, py);
  38856. }
  38857. if (px >= x && px <= x + bounds.width)
  38858. {
  38859. var tx = px - cx;
  38860. var ty = Math.sqrt(b*b*(1-(tx*tx)/(a*a))) || 0;
  38861. if (py <= y)
  38862. {
  38863. ty = -ty;
  38864. }
  38865. return new mxPoint(px, cy+ty);
  38866. }
  38867. }
  38868. // Calculates intersection
  38869. var d = dy / dx;
  38870. var h = cy - d * cx;
  38871. var e = a * a * d * d + b * b;
  38872. var f = -2 * cx * e;
  38873. var g = a * a * d * d * cx * cx +
  38874. b * b * cx * cx -
  38875. a * a * b * b;
  38876. var det = Math.sqrt(f * f - 4 * e * g);
  38877. // Two solutions (perimeter points)
  38878. var xout1 = (-f + det) / (2 * e);
  38879. var xout2 = (-f - det) / (2 * e);
  38880. var yout1 = d * xout1 + h;
  38881. var yout2 = d * xout2 + h;
  38882. var dist1 = Math.sqrt(Math.pow((xout1 - px), 2)
  38883. + Math.pow((yout1 - py), 2));
  38884. var dist2 = Math.sqrt(Math.pow((xout2 - px), 2)
  38885. + Math.pow((yout2 - py), 2));
  38886. // Correct solution
  38887. var xout = 0;
  38888. var yout = 0;
  38889. if (dist1 < dist2)
  38890. {
  38891. xout = xout1;
  38892. yout = yout1;
  38893. }
  38894. else
  38895. {
  38896. xout = xout2;
  38897. yout = yout2;
  38898. }
  38899. return new mxPoint(xout, yout);
  38900. },
  38901. /**
  38902. * Function: RhombusPerimeter
  38903. *
  38904. * Describes a rhombus (aka diamond) perimeter. See <RectanglePerimeter>
  38905. * for a description of the parameters.
  38906. */
  38907. RhombusPerimeter: function (bounds, vertex, next, orthogonal)
  38908. {
  38909. var x = bounds.x;
  38910. var y = bounds.y;
  38911. var w = bounds.width;
  38912. var h = bounds.height;
  38913. var cx = x + w / 2;
  38914. var cy = y + h / 2;
  38915. var px = next.x;
  38916. var py = next.y;
  38917. // Special case for intersecting the diamond's corners
  38918. if (cx == px)
  38919. {
  38920. if (cy > py)
  38921. {
  38922. return new mxPoint(cx, y); // top
  38923. }
  38924. else
  38925. {
  38926. return new mxPoint(cx, y + h); // bottom
  38927. }
  38928. }
  38929. else if (cy == py)
  38930. {
  38931. if (cx > px)
  38932. {
  38933. return new mxPoint(x, cy); // left
  38934. }
  38935. else
  38936. {
  38937. return new mxPoint(x + w, cy); // right
  38938. }
  38939. }
  38940. var tx = cx;
  38941. var ty = cy;
  38942. if (orthogonal)
  38943. {
  38944. if (px >= x && px <= x + w)
  38945. {
  38946. tx = px;
  38947. }
  38948. else if (py >= y && py <= y + h)
  38949. {
  38950. ty = py;
  38951. }
  38952. }
  38953. // In which quadrant will the intersection be?
  38954. // set the slope and offset of the border line accordingly
  38955. if (px < cx)
  38956. {
  38957. if (py < cy)
  38958. {
  38959. return mxUtils.intersection(px, py, tx, ty, cx, y, x, cy);
  38960. }
  38961. else
  38962. {
  38963. return mxUtils.intersection(px, py, tx, ty, cx, y + h, x, cy);
  38964. }
  38965. }
  38966. else if (py < cy)
  38967. {
  38968. return mxUtils.intersection(px, py, tx, ty, cx, y, x + w, cy);
  38969. }
  38970. else
  38971. {
  38972. return mxUtils.intersection(px, py, tx, ty, cx, y + h, x + w, cy);
  38973. }
  38974. },
  38975. /**
  38976. * Function: TrianglePerimeter
  38977. *
  38978. * Describes a triangle perimeter. See <RectanglePerimeter>
  38979. * for a description of the parameters.
  38980. */
  38981. TrianglePerimeter: function (bounds, vertex, next, orthogonal)
  38982. {
  38983. var direction = (vertex != null) ?
  38984. vertex.style[mxConstants.STYLE_DIRECTION] : null;
  38985. var vertical = direction == mxConstants.DIRECTION_NORTH ||
  38986. direction == mxConstants.DIRECTION_SOUTH;
  38987. var x = bounds.x;
  38988. var y = bounds.y;
  38989. var w = bounds.width;
  38990. var h = bounds.height;
  38991. var cx = x + w / 2;
  38992. var cy = y + h / 2;
  38993. var start = new mxPoint(x, y);
  38994. var corner = new mxPoint(x + w, cy);
  38995. var end = new mxPoint(x, y + h);
  38996. if (direction == mxConstants.DIRECTION_NORTH)
  38997. {
  38998. start = end;
  38999. corner = new mxPoint(cx, y);
  39000. end = new mxPoint(x + w, y + h);
  39001. }
  39002. else if (direction == mxConstants.DIRECTION_SOUTH)
  39003. {
  39004. corner = new mxPoint(cx, y + h);
  39005. end = new mxPoint(x + w, y);
  39006. }
  39007. else if (direction == mxConstants.DIRECTION_WEST)
  39008. {
  39009. start = new mxPoint(x + w, y);
  39010. corner = new mxPoint(x, cy);
  39011. end = new mxPoint(x + w, y + h);
  39012. }
  39013. var dx = next.x - cx;
  39014. var dy = next.y - cy;
  39015. var alpha = (vertical) ? Math.atan2(dx, dy) : Math.atan2(dy, dx);
  39016. var t = (vertical) ? Math.atan2(w, h) : Math.atan2(h, w);
  39017. var base = false;
  39018. if (direction == mxConstants.DIRECTION_NORTH ||
  39019. direction == mxConstants.DIRECTION_WEST)
  39020. {
  39021. base = alpha > -t && alpha < t;
  39022. }
  39023. else
  39024. {
  39025. base = alpha < -Math.PI + t || alpha > Math.PI - t;
  39026. }
  39027. var result = null;
  39028. if (base)
  39029. {
  39030. if (orthogonal && ((vertical && next.x >= start.x && next.x <= end.x) ||
  39031. (!vertical && next.y >= start.y && next.y <= end.y)))
  39032. {
  39033. if (vertical)
  39034. {
  39035. result = new mxPoint(next.x, start.y);
  39036. }
  39037. else
  39038. {
  39039. result = new mxPoint(start.x, next.y);
  39040. }
  39041. }
  39042. else
  39043. {
  39044. if (direction == mxConstants.DIRECTION_NORTH)
  39045. {
  39046. result = new mxPoint(x + w / 2 + h * Math.tan(alpha) / 2,
  39047. y + h);
  39048. }
  39049. else if (direction == mxConstants.DIRECTION_SOUTH)
  39050. {
  39051. result = new mxPoint(x + w / 2 - h * Math.tan(alpha) / 2,
  39052. y);
  39053. }
  39054. else if (direction == mxConstants.DIRECTION_WEST)
  39055. {
  39056. result = new mxPoint(x + w, y + h / 2 +
  39057. w * Math.tan(alpha) / 2);
  39058. }
  39059. else
  39060. {
  39061. result = new mxPoint(x, y + h / 2 -
  39062. w * Math.tan(alpha) / 2);
  39063. }
  39064. }
  39065. }
  39066. else
  39067. {
  39068. if (orthogonal)
  39069. {
  39070. var pt = new mxPoint(cx, cy);
  39071. if (next.y >= y && next.y <= y + h)
  39072. {
  39073. pt.x = (vertical) ? cx : (
  39074. (direction == mxConstants.DIRECTION_WEST) ?
  39075. x + w : x);
  39076. pt.y = next.y;
  39077. }
  39078. else if (next.x >= x && next.x <= x + w)
  39079. {
  39080. pt.x = next.x;
  39081. pt.y = (!vertical) ? cy : (
  39082. (direction == mxConstants.DIRECTION_NORTH) ?
  39083. y + h : y);
  39084. }
  39085. // Compute angle
  39086. dx = next.x - pt.x;
  39087. dy = next.y - pt.y;
  39088. cx = pt.x;
  39089. cy = pt.y;
  39090. }
  39091. if ((vertical && next.x <= x + w / 2) ||
  39092. (!vertical && next.y <= y + h / 2))
  39093. {
  39094. result = mxUtils.intersection(next.x, next.y, cx, cy,
  39095. start.x, start.y, corner.x, corner.y);
  39096. }
  39097. else
  39098. {
  39099. result = mxUtils.intersection(next.x, next.y, cx, cy,
  39100. corner.x, corner.y, end.x, end.y);
  39101. }
  39102. }
  39103. if (result == null)
  39104. {
  39105. result = new mxPoint(cx, cy);
  39106. }
  39107. return result;
  39108. },
  39109. /**
  39110. * Function: HexagonPerimeter
  39111. *
  39112. * Describes a hexagon perimeter. See <RectanglePerimeter>
  39113. * for a description of the parameters.
  39114. */
  39115. HexagonPerimeter: function (bounds, vertex, next, orthogonal)
  39116. {
  39117. var x = bounds.x;
  39118. var y = bounds.y;
  39119. var w = bounds.width;
  39120. var h = bounds.height;
  39121. var cx = bounds.getCenterX();
  39122. var cy = bounds.getCenterY();
  39123. var px = next.x;
  39124. var py = next.y;
  39125. var dx = px - cx;
  39126. var dy = py - cy;
  39127. var alpha = -Math.atan2(dy, dx);
  39128. var pi = Math.PI;
  39129. var pi2 = Math.PI / 2;
  39130. var result = new mxPoint(cx, cy);
  39131. var direction = (vertex != null) ? mxUtils.getValue(
  39132. vertex.style, mxConstants.STYLE_DIRECTION,
  39133. mxConstants.DIRECTION_EAST) : mxConstants.DIRECTION_EAST;
  39134. var vertical = direction == mxConstants.DIRECTION_NORTH
  39135. || direction == mxConstants.DIRECTION_SOUTH;
  39136. var a = new mxPoint();
  39137. var b = new mxPoint();
  39138. //Only consider corrects quadrants for the orthogonal case.
  39139. if ((px < x) && (py < y) || (px < x) && (py > y + h)
  39140. || (px > x + w) && (py < y) || (px > x + w) && (py > y + h))
  39141. {
  39142. orthogonal = false;
  39143. }
  39144. if (orthogonal)
  39145. {
  39146. if (vertical)
  39147. {
  39148. //Special cases where intersects with hexagon corners
  39149. if (px == cx)
  39150. {
  39151. if (py <= y)
  39152. {
  39153. return new mxPoint(cx, y);
  39154. }
  39155. else if (py >= y + h)
  39156. {
  39157. return new mxPoint(cx, y + h);
  39158. }
  39159. }
  39160. else if (px < x)
  39161. {
  39162. if (py == y + h / 4)
  39163. {
  39164. return new mxPoint(x, y + h / 4);
  39165. }
  39166. else if (py == y + 3 * h / 4)
  39167. {
  39168. return new mxPoint(x, y + 3 * h / 4);
  39169. }
  39170. }
  39171. else if (px > x + w)
  39172. {
  39173. if (py == y + h / 4)
  39174. {
  39175. return new mxPoint(x + w, y + h / 4);
  39176. }
  39177. else if (py == y + 3 * h / 4)
  39178. {
  39179. return new mxPoint(x + w, y + 3 * h / 4);
  39180. }
  39181. }
  39182. else if (px == x)
  39183. {
  39184. if (py < cy)
  39185. {
  39186. return new mxPoint(x, y + h / 4);
  39187. }
  39188. else if (py > cy)
  39189. {
  39190. return new mxPoint(x, y + 3 * h / 4);
  39191. }
  39192. }
  39193. else if (px == x + w)
  39194. {
  39195. if (py < cy)
  39196. {
  39197. return new mxPoint(x + w, y + h / 4);
  39198. }
  39199. else if (py > cy)
  39200. {
  39201. return new mxPoint(x + w, y + 3 * h / 4);
  39202. }
  39203. }
  39204. if (py == y)
  39205. {
  39206. return new mxPoint(cx, y);
  39207. }
  39208. else if (py == y + h)
  39209. {
  39210. return new mxPoint(cx, y + h);
  39211. }
  39212. if (px < cx)
  39213. {
  39214. if ((py > y + h / 4) && (py < y + 3 * h / 4))
  39215. {
  39216. a = new mxPoint(x, y);
  39217. b = new mxPoint(x, y + h);
  39218. }
  39219. else if (py < y + h / 4)
  39220. {
  39221. a = new mxPoint(x - Math.floor(0.5 * w), y
  39222. + Math.floor(0.5 * h));
  39223. b = new mxPoint(x + w, y - Math.floor(0.25 * h));
  39224. }
  39225. else if (py > y + 3 * h / 4)
  39226. {
  39227. a = new mxPoint(x - Math.floor(0.5 * w), y
  39228. + Math.floor(0.5 * h));
  39229. b = new mxPoint(x + w, y + Math.floor(1.25 * h));
  39230. }
  39231. }
  39232. else if (px > cx)
  39233. {
  39234. if ((py > y + h / 4) && (py < y + 3 * h / 4))
  39235. {
  39236. a = new mxPoint(x + w, y);
  39237. b = new mxPoint(x + w, y + h);
  39238. }
  39239. else if (py < y + h / 4)
  39240. {
  39241. a = new mxPoint(x, y - Math.floor(0.25 * h));
  39242. b = new mxPoint(x + Math.floor(1.5 * w), y
  39243. + Math.floor(0.5 * h));
  39244. }
  39245. else if (py > y + 3 * h / 4)
  39246. {
  39247. a = new mxPoint(x + Math.floor(1.5 * w), y
  39248. + Math.floor(0.5 * h));
  39249. b = new mxPoint(x, y + Math.floor(1.25 * h));
  39250. }
  39251. }
  39252. }
  39253. else
  39254. {
  39255. //Special cases where intersects with hexagon corners
  39256. if (py == cy)
  39257. {
  39258. if (px <= x)
  39259. {
  39260. return new mxPoint(x, y + h / 2);
  39261. }
  39262. else if (px >= x + w)
  39263. {
  39264. return new mxPoint(x + w, y + h / 2);
  39265. }
  39266. }
  39267. else if (py < y)
  39268. {
  39269. if (px == x + w / 4)
  39270. {
  39271. return new mxPoint(x + w / 4, y);
  39272. }
  39273. else if (px == x + 3 * w / 4)
  39274. {
  39275. return new mxPoint(x + 3 * w / 4, y);
  39276. }
  39277. }
  39278. else if (py > y + h)
  39279. {
  39280. if (px == x + w / 4)
  39281. {
  39282. return new mxPoint(x + w / 4, y + h);
  39283. }
  39284. else if (px == x + 3 * w / 4)
  39285. {
  39286. return new mxPoint(x + 3 * w / 4, y + h);
  39287. }
  39288. }
  39289. else if (py == y)
  39290. {
  39291. if (px < cx)
  39292. {
  39293. return new mxPoint(x + w / 4, y);
  39294. }
  39295. else if (px > cx)
  39296. {
  39297. return new mxPoint(x + 3 * w / 4, y);
  39298. }
  39299. }
  39300. else if (py == y + h)
  39301. {
  39302. if (px < cx)
  39303. {
  39304. return new mxPoint(x + w / 4, y + h);
  39305. }
  39306. else if (py > cy)
  39307. {
  39308. return new mxPoint(x + 3 * w / 4, y + h);
  39309. }
  39310. }
  39311. if (px == x)
  39312. {
  39313. return new mxPoint(x, cy);
  39314. }
  39315. else if (px == x + w)
  39316. {
  39317. return new mxPoint(x + w, cy);
  39318. }
  39319. if (py < cy)
  39320. {
  39321. if ((px > x + w / 4) && (px < x + 3 * w / 4))
  39322. {
  39323. a = new mxPoint(x, y);
  39324. b = new mxPoint(x + w, y);
  39325. }
  39326. else if (px < x + w / 4)
  39327. {
  39328. a = new mxPoint(x - Math.floor(0.25 * w), y + h);
  39329. b = new mxPoint(x + Math.floor(0.5 * w), y
  39330. - Math.floor(0.5 * h));
  39331. }
  39332. else if (px > x + 3 * w / 4)
  39333. {
  39334. a = new mxPoint(x + Math.floor(0.5 * w), y
  39335. - Math.floor(0.5 * h));
  39336. b = new mxPoint(x + Math.floor(1.25 * w), y + h);
  39337. }
  39338. }
  39339. else if (py > cy)
  39340. {
  39341. if ((px > x + w / 4) && (px < x + 3 * w / 4))
  39342. {
  39343. a = new mxPoint(x, y + h);
  39344. b = new mxPoint(x + w, y + h);
  39345. }
  39346. else if (px < x + w / 4)
  39347. {
  39348. a = new mxPoint(x - Math.floor(0.25 * w), y);
  39349. b = new mxPoint(x + Math.floor(0.5 * w), y
  39350. + Math.floor(1.5 * h));
  39351. }
  39352. else if (px > x + 3 * w / 4)
  39353. {
  39354. a = new mxPoint(x + Math.floor(0.5 * w), y
  39355. + Math.floor(1.5 * h));
  39356. b = new mxPoint(x + Math.floor(1.25 * w), y);
  39357. }
  39358. }
  39359. }
  39360. var tx = cx;
  39361. var ty = cy;
  39362. if (px >= x && px <= x + w)
  39363. {
  39364. tx = px;
  39365. if (py < cy)
  39366. {
  39367. ty = y + h;
  39368. }
  39369. else
  39370. {
  39371. ty = y;
  39372. }
  39373. }
  39374. else if (py >= y && py <= y + h)
  39375. {
  39376. ty = py;
  39377. if (px < cx)
  39378. {
  39379. tx = x + w;
  39380. }
  39381. else
  39382. {
  39383. tx = x;
  39384. }
  39385. }
  39386. result = mxUtils.intersection(tx, ty, next.x, next.y, a.x, a.y, b.x, b.y);
  39387. }
  39388. else
  39389. {
  39390. if (vertical)
  39391. {
  39392. var beta = Math.atan2(h / 4, w / 2);
  39393. //Special cases where intersects with hexagon corners
  39394. if (alpha == beta)
  39395. {
  39396. return new mxPoint(x + w, y + Math.floor(0.25 * h));
  39397. }
  39398. else if (alpha == pi2)
  39399. {
  39400. return new mxPoint(x + Math.floor(0.5 * w), y);
  39401. }
  39402. else if (alpha == (pi - beta))
  39403. {
  39404. return new mxPoint(x, y + Math.floor(0.25 * h));
  39405. }
  39406. else if (alpha == -beta)
  39407. {
  39408. return new mxPoint(x + w, y + Math.floor(0.75 * h));
  39409. }
  39410. else if (alpha == (-pi2))
  39411. {
  39412. return new mxPoint(x + Math.floor(0.5 * w), y + h);
  39413. }
  39414. else if (alpha == (-pi + beta))
  39415. {
  39416. return new mxPoint(x, y + Math.floor(0.75 * h));
  39417. }
  39418. if ((alpha < beta) && (alpha > -beta))
  39419. {
  39420. a = new mxPoint(x + w, y);
  39421. b = new mxPoint(x + w, y + h);
  39422. }
  39423. else if ((alpha > beta) && (alpha < pi2))
  39424. {
  39425. a = new mxPoint(x, y - Math.floor(0.25 * h));
  39426. b = new mxPoint(x + Math.floor(1.5 * w), y
  39427. + Math.floor(0.5 * h));
  39428. }
  39429. else if ((alpha > pi2) && (alpha < (pi - beta)))
  39430. {
  39431. a = new mxPoint(x - Math.floor(0.5 * w), y
  39432. + Math.floor(0.5 * h));
  39433. b = new mxPoint(x + w, y - Math.floor(0.25 * h));
  39434. }
  39435. else if (((alpha > (pi - beta)) && (alpha <= pi))
  39436. || ((alpha < (-pi + beta)) && (alpha >= -pi)))
  39437. {
  39438. a = new mxPoint(x, y);
  39439. b = new mxPoint(x, y + h);
  39440. }
  39441. else if ((alpha < -beta) && (alpha > -pi2))
  39442. {
  39443. a = new mxPoint(x + Math.floor(1.5 * w), y
  39444. + Math.floor(0.5 * h));
  39445. b = new mxPoint(x, y + Math.floor(1.25 * h));
  39446. }
  39447. else if ((alpha < -pi2) && (alpha > (-pi + beta)))
  39448. {
  39449. a = new mxPoint(x - Math.floor(0.5 * w), y
  39450. + Math.floor(0.5 * h));
  39451. b = new mxPoint(x + w, y + Math.floor(1.25 * h));
  39452. }
  39453. }
  39454. else
  39455. {
  39456. var beta = Math.atan2(h / 2, w / 4);
  39457. //Special cases where intersects with hexagon corners
  39458. if (alpha == beta)
  39459. {
  39460. return new mxPoint(x + Math.floor(0.75 * w), y);
  39461. }
  39462. else if (alpha == (pi - beta))
  39463. {
  39464. return new mxPoint(x + Math.floor(0.25 * w), y);
  39465. }
  39466. else if ((alpha == pi) || (alpha == -pi))
  39467. {
  39468. return new mxPoint(x, y + Math.floor(0.5 * h));
  39469. }
  39470. else if (alpha == 0)
  39471. {
  39472. return new mxPoint(x + w, y + Math.floor(0.5 * h));
  39473. }
  39474. else if (alpha == -beta)
  39475. {
  39476. return new mxPoint(x + Math.floor(0.75 * w), y + h);
  39477. }
  39478. else if (alpha == (-pi + beta))
  39479. {
  39480. return new mxPoint(x + Math.floor(0.25 * w), y + h);
  39481. }
  39482. if ((alpha > 0) && (alpha < beta))
  39483. {
  39484. a = new mxPoint(x + Math.floor(0.5 * w), y
  39485. - Math.floor(0.5 * h));
  39486. b = new mxPoint(x + Math.floor(1.25 * w), y + h);
  39487. }
  39488. else if ((alpha > beta) && (alpha < (pi - beta)))
  39489. {
  39490. a = new mxPoint(x, y);
  39491. b = new mxPoint(x + w, y);
  39492. }
  39493. else if ((alpha > (pi - beta)) && (alpha < pi))
  39494. {
  39495. a = new mxPoint(x - Math.floor(0.25 * w), y + h);
  39496. b = new mxPoint(x + Math.floor(0.5 * w), y
  39497. - Math.floor(0.5 * h));
  39498. }
  39499. else if ((alpha < 0) && (alpha > -beta))
  39500. {
  39501. a = new mxPoint(x + Math.floor(0.5 * w), y
  39502. + Math.floor(1.5 * h));
  39503. b = new mxPoint(x + Math.floor(1.25 * w), y);
  39504. }
  39505. else if ((alpha < -beta) && (alpha > (-pi + beta)))
  39506. {
  39507. a = new mxPoint(x, y + h);
  39508. b = new mxPoint(x + w, y + h);
  39509. }
  39510. else if ((alpha < (-pi + beta)) && (alpha > -pi))
  39511. {
  39512. a = new mxPoint(x - Math.floor(0.25 * w), y);
  39513. b = new mxPoint(x + Math.floor(0.5 * w), y
  39514. + Math.floor(1.5 * h));
  39515. }
  39516. }
  39517. result = mxUtils.intersection(cx, cy, next.x, next.y, a.x, a.y, b.x, b.y);
  39518. }
  39519. if (result == null)
  39520. {
  39521. return new mxPoint(cx, cy);
  39522. }
  39523. return result;
  39524. }
  39525. };
  39526. /**
  39527. * Copyright (c) 2006-2019, JGraph Ltd
  39528. * Copyright (c) 2006-2017, draw.io AG
  39529. */
  39530. /**
  39531. * Class: mxPrintPreview
  39532. *
  39533. * Implements printing of a diagram across multiple pages. The following opens
  39534. * a print preview for an existing graph:
  39535. *
  39536. * (code)
  39537. * var preview = new mxPrintPreview(graph);
  39538. * preview.open();
  39539. * (end)
  39540. *
  39541. * Use <mxUtils.getScaleForPageCount> as follows in order to print the graph
  39542. * across a given number of pages:
  39543. *
  39544. * (code)
  39545. * var pageCount = mxUtils.prompt('Enter page count', '1');
  39546. *
  39547. * if (pageCount != null)
  39548. * {
  39549. * var scale = mxUtils.getScaleForPageCount(pageCount, graph);
  39550. * var preview = new mxPrintPreview(graph, scale);
  39551. * preview.open();
  39552. * }
  39553. * (end)
  39554. *
  39555. * Additional pages:
  39556. *
  39557. * To add additional pages before and after the output, <getCoverPages> and
  39558. * <getAppendices> can be used, respectively.
  39559. *
  39560. * (code)
  39561. * var preview = new mxPrintPreview(graph, 1);
  39562. *
  39563. * preview.getCoverPages = function(w, h)
  39564. * {
  39565. * return [this.renderPage(w, h, 0, 0, mxUtils.bind(this, function(div)
  39566. * {
  39567. * div.innerHTML = '<div style="position:relative;margin:4px;">Cover Page</p>'
  39568. * }))];
  39569. * };
  39570. *
  39571. * preview.getAppendices = function(w, h)
  39572. * {
  39573. * return [this.renderPage(w, h, 0, 0, mxUtils.bind(this, function(div)
  39574. * {
  39575. * div.innerHTML = '<div style="position:relative;margin:4px;">Appendix</p>'
  39576. * }))];
  39577. * };
  39578. *
  39579. * preview.open();
  39580. * (end)
  39581. *
  39582. * CSS:
  39583. *
  39584. * The CSS from the original page is not carried over to the print preview.
  39585. * To add CSS to the page, use the css argument in the <open> function or
  39586. * override <writeHead> to add the respective link tags as follows:
  39587. *
  39588. * (code)
  39589. * var writeHead = preview.writeHead;
  39590. * preview.writeHead = function(doc, css)
  39591. * {
  39592. * writeHead.apply(this, arguments);
  39593. * doc.writeln('<link rel="stylesheet" type="text/css" href="style.css">');
  39594. * };
  39595. * (end)
  39596. *
  39597. * Padding:
  39598. *
  39599. * To add a padding to the page in the preview (but not the print output), use
  39600. * the following code:
  39601. *
  39602. * (code)
  39603. * preview.writeHead = function(doc)
  39604. * {
  39605. * writeHead.apply(this, arguments);
  39606. *
  39607. * doc.writeln('<style type="text/css">');
  39608. * doc.writeln('@media screen {');
  39609. * doc.writeln(' body > div { padding-top:30px;padding-left:40px;box-sizing:content-box; }');
  39610. * doc.writeln('}');
  39611. * doc.writeln('</style>');
  39612. * };
  39613. * (end)
  39614. *
  39615. * Headers:
  39616. *
  39617. * Apart from setting the title argument in the mxPrintPreview constructor you
  39618. * can override <renderPage> as follows to add a header to any page:
  39619. *
  39620. * (code)
  39621. * var oldRenderPage = mxPrintPreview.prototype.renderPage;
  39622. * mxPrintPreview.prototype.renderPage = function(w, h, x, y, content, pageNumber)
  39623. * {
  39624. * var div = oldRenderPage.apply(this, arguments);
  39625. *
  39626. * var header = document.createElement('div');
  39627. * header.style.position = 'absolute';
  39628. * header.style.top = '0px';
  39629. * header.style.width = '100%';
  39630. * header.style.textAlign = 'right';
  39631. * mxUtils.write(header, 'Your header here');
  39632. * div.firstChild.appendChild(header);
  39633. *
  39634. * return div;
  39635. * };
  39636. * (end)
  39637. *
  39638. * The pageNumber argument contains the number of the current page, starting at
  39639. * 1. To display a header on the first page only, check pageNumber and add a
  39640. * vertical offset in the constructor call for the height of the header.
  39641. *
  39642. * Page Format:
  39643. *
  39644. * For landscape printing, use <mxConstants.PAGE_FORMAT_A4_LANDSCAPE> as
  39645. * the pageFormat in <mxUtils.getScaleForPageCount> and <mxPrintPreview>.
  39646. * Keep in mind that one can not set the defaults for the print dialog
  39647. * of the operating system from JavaScript so the user must manually choose
  39648. * a page format that matches this setting.
  39649. *
  39650. * You can try passing the following CSS directive to <open> to set the
  39651. * page format in the print dialog to landscape. However, this CSS
  39652. * directive seems to be ignored in most major browsers, including IE.
  39653. *
  39654. * (code)
  39655. * @page {
  39656. * size: landscape;
  39657. * }
  39658. * (end)
  39659. *
  39660. * Note that the print preview behaves differently in IE when used from the
  39661. * filesystem or via HTTP so printing should always be tested via HTTP.
  39662. *
  39663. * If you are using a DOCTYPE in the source page you can override <getDoctype>
  39664. * and provide the same DOCTYPE for the print preview if required. Here is
  39665. * an example for IE8 standards mode.
  39666. *
  39667. * (code)
  39668. * var preview = new mxPrintPreview(graph);
  39669. * preview.getDoctype = function()
  39670. * {
  39671. * return '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=8" ><![endif]-->';
  39672. * };
  39673. * preview.open();
  39674. * (end)
  39675. *
  39676. * Constructor: mxPrintPreview
  39677. *
  39678. * Constructs a new print preview for the given parameters.
  39679. *
  39680. * Parameters:
  39681. *
  39682. * graph - <mxGraph> to be previewed.
  39683. * scale - Optional scale of the output. Default is 1 / <mxGraph.pageScale>.
  39684. * pageFormat - <mxRectangle> that specifies the page format (in pixels).
  39685. * border - Border in pixels along each side of every page. Note that the
  39686. * actual print function in the browser will add another border for
  39687. * printing.
  39688. * This should match the page format of the printer. Default uses the
  39689. * <mxGraph.pageFormat> of the given graph.
  39690. * x0 - Optional left offset of the output. Default is 0.
  39691. * y0 - Optional top offset of the output. Default is 0.
  39692. * borderColor - Optional color of the page border. Default is no border.
  39693. * Note that a border is sometimes useful to highlight the printed page
  39694. * border in the print preview of the browser.
  39695. * title - Optional string that is used for the window title. Default
  39696. * is 'Printer-friendly version'.
  39697. * pageSelector - Optional boolean that specifies if the page selector
  39698. * should appear in the window with the print preview. Default is true.
  39699. */
  39700. function mxPrintPreview(graph, scale, pageFormat, border, x0, y0, borderColor, title, pageSelector)
  39701. {
  39702. this.graph = graph;
  39703. this.scale = (scale != null) ? scale : 1 / graph.pageScale;
  39704. this.border = (border != null) ? border : 0;
  39705. this.pageFormat = mxRectangle.fromRectangle((pageFormat != null) ? pageFormat : graph.pageFormat);
  39706. this.title = (title != null) ? title : 'Printer-friendly version';
  39707. this.x0 = (x0 != null) ? x0 : 0;
  39708. this.y0 = (y0 != null) ? y0 : 0;
  39709. this.borderColor = borderColor;
  39710. this.pageSelector = (pageSelector != null) ? pageSelector : true;
  39711. };
  39712. /**
  39713. * Variable: graph
  39714. *
  39715. * Reference to the <mxGraph> that should be previewed.
  39716. */
  39717. mxPrintPreview.prototype.graph = null;
  39718. /**
  39719. * Variable: pageFormat
  39720. *
  39721. * Holds the <mxRectangle> that defines the page format.
  39722. */
  39723. mxPrintPreview.prototype.pageFormat = null;
  39724. /**
  39725. * Variable: scale
  39726. *
  39727. * Holds the scale of the print preview.
  39728. */
  39729. mxPrintPreview.prototype.scale = null;
  39730. /**
  39731. * Variable: border
  39732. *
  39733. * The border inset around each side of every page in the preview. This is set
  39734. * to 0 if autoOrigin is false.
  39735. */
  39736. mxPrintPreview.prototype.border = 0;
  39737. /**
  39738. * Variable: marginTop
  39739. *
  39740. * The margin at the top of the page (number). Default is 0.
  39741. */
  39742. mxPrintPreview.prototype.marginTop = 0;
  39743. /**
  39744. * Variable: marginBottom
  39745. *
  39746. * The margin at the bottom of the page (number). Default is 0.
  39747. */
  39748. mxPrintPreview.prototype.marginBottom = 0;
  39749. /**
  39750. * Variable: x0
  39751. *
  39752. * Holds the horizontal offset of the output.
  39753. */
  39754. mxPrintPreview.prototype.x0 = 0;
  39755. /**
  39756. * Variable: y0
  39757. *
  39758. * Holds the vertical offset of the output.
  39759. */
  39760. mxPrintPreview.prototype.y0 = 0;
  39761. /**
  39762. * Variable: autoOrigin
  39763. *
  39764. * Specifies if the origin should be automatically computed based on the top,
  39765. * left corner of the actual diagram contents. The required offset will be added
  39766. * to <x0> and <y0> in <open>. Default is true.
  39767. */
  39768. mxPrintPreview.prototype.autoOrigin = true;
  39769. /**
  39770. * Variable: printOverlays
  39771. *
  39772. * Specifies if overlays should be printed. Default is false.
  39773. */
  39774. mxPrintPreview.prototype.printOverlays = false;
  39775. /**
  39776. * Variable: printControls
  39777. *
  39778. * Specifies if controls (such as folding icons) should be printed. Default is
  39779. * false.
  39780. */
  39781. mxPrintPreview.prototype.printControls = false;
  39782. /**
  39783. * Variable: printBackgroundImage
  39784. *
  39785. * Specifies if the background image should be printed. Default is false.
  39786. */
  39787. mxPrintPreview.prototype.printBackgroundImage = false;
  39788. /**
  39789. * Variable: backgroundColor
  39790. *
  39791. * Holds the color value for the page background color. Default is #ffffff.
  39792. */
  39793. mxPrintPreview.prototype.backgroundColor = '#ffffff';
  39794. /**
  39795. * Variable: borderColor
  39796. *
  39797. * Holds the color value for the page border.
  39798. */
  39799. mxPrintPreview.prototype.borderColor = null;
  39800. /**
  39801. * Variable: title
  39802. *
  39803. * Holds the title of the preview window.
  39804. */
  39805. mxPrintPreview.prototype.title = null;
  39806. /**
  39807. * Variable: pageSelector
  39808. *
  39809. * Boolean that specifies if the page selector should be
  39810. * displayed. Default is true.
  39811. */
  39812. mxPrintPreview.prototype.pageSelector = null;
  39813. /**
  39814. * Variable: wnd
  39815. *
  39816. * Reference to the preview window.
  39817. */
  39818. mxPrintPreview.prototype.wnd = null;
  39819. /**
  39820. * Variable: targetWindow
  39821. *
  39822. * Assign any window here to redirect the rendering in <open>.
  39823. */
  39824. mxPrintPreview.prototype.targetWindow = null;
  39825. /**
  39826. * Variable: pageCount
  39827. *
  39828. * Holds the actual number of pages in the preview.
  39829. */
  39830. mxPrintPreview.prototype.pageCount = 0;
  39831. /**
  39832. * Variable: clipping
  39833. *
  39834. * Specifies is clipping should be used to avoid creating too many cell states
  39835. * in large diagrams. The bounding box of the cells in the original diagram is
  39836. * used if this is enabled. Default is true.
  39837. */
  39838. mxPrintPreview.prototype.clipping = true;
  39839. /**
  39840. * Function: getWindow
  39841. *
  39842. * Returns <wnd>.
  39843. */
  39844. mxPrintPreview.prototype.getWindow = function()
  39845. {
  39846. return this.wnd;
  39847. };
  39848. /**
  39849. * Function: getDocType
  39850. *
  39851. * Returns the string that should go before the HTML tag in the print preview
  39852. * page. This implementation returns an X-UA meta tag for IE5 in quirks mode,
  39853. * IE8 in IE8 standards mode and edge in IE9 standards mode.
  39854. */
  39855. mxPrintPreview.prototype.getDoctype = function()
  39856. {
  39857. var dt = '';
  39858. if (document.documentMode == 5)
  39859. {
  39860. dt = '<meta http-equiv="X-UA-Compatible" content="IE=5">';
  39861. }
  39862. else if (document.documentMode == 8)
  39863. {
  39864. dt = '<meta http-equiv="X-UA-Compatible" content="IE=8">';
  39865. }
  39866. else if (document.documentMode > 8)
  39867. {
  39868. // Comment needed to make standards doctype apply in IE
  39869. dt = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->';
  39870. }
  39871. return dt;
  39872. };
  39873. /**
  39874. * Function: appendGraph
  39875. *
  39876. * Adds the given graph to the existing print preview.
  39877. *
  39878. * Parameters:
  39879. *
  39880. * css - Optional CSS string to be used in the head section.
  39881. * targetWindow - Optional window that should be used for rendering. If
  39882. * this is specified then no HEAD tag, CSS and BODY tag will be written.
  39883. */
  39884. mxPrintPreview.prototype.appendGraph = function(graph, scale, x0, y0, forcePageBreaks, keepOpen)
  39885. {
  39886. this.graph = graph;
  39887. this.scale = (scale != null) ? scale : 1 / graph.pageScale;
  39888. this.x0 = x0;
  39889. this.y0 = y0;
  39890. this.open(null, null, forcePageBreaks, keepOpen);
  39891. };
  39892. /**
  39893. * Function: open
  39894. *
  39895. * Shows the print preview window. The window is created here if it does
  39896. * not exist.
  39897. *
  39898. * Parameters:
  39899. *
  39900. * css - Optional CSS string to be used in the head section.
  39901. * targetWindow - Optional window that should be used for rendering. If
  39902. * this is specified then no HEAD tag, CSS and BODY tag will be written.
  39903. */
  39904. mxPrintPreview.prototype.open = function(css, targetWindow, forcePageBreaks, keepOpen)
  39905. {
  39906. // Closing the window while the page is being rendered may cause an
  39907. // exception in IE. This and any other exceptions are simply ignored.
  39908. var previousInitializeOverlay = this.graph.cellRenderer.initializeOverlay;
  39909. var div = null;
  39910. try
  39911. {
  39912. // Temporarily overrides the method to redirect rendering of overlays
  39913. // to the draw pane so that they are visible in the printout
  39914. if (this.printOverlays)
  39915. {
  39916. this.graph.cellRenderer.initializeOverlay = function(state, overlay)
  39917. {
  39918. overlay.init(state.view.getDrawPane());
  39919. };
  39920. }
  39921. if (this.printControls)
  39922. {
  39923. this.graph.cellRenderer.initControl = function(state, control, handleEvents, clickHandler)
  39924. {
  39925. control.dialect = state.view.graph.dialect;
  39926. control.init(state.view.getDrawPane());
  39927. };
  39928. }
  39929. this.wnd = (targetWindow != null) ? targetWindow : this.wnd;
  39930. var isNewWindow = false;
  39931. if (this.wnd == null)
  39932. {
  39933. isNewWindow = true;
  39934. this.wnd = window.open();
  39935. }
  39936. var doc = this.wnd.document;
  39937. if (isNewWindow)
  39938. {
  39939. var dt = this.getDoctype();
  39940. if (dt != null && dt.length > 0)
  39941. {
  39942. doc.writeln(dt);
  39943. }
  39944. if (mxClient.IS_VML)
  39945. {
  39946. doc.writeln('<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">');
  39947. }
  39948. else
  39949. {
  39950. if (document.compatMode === 'CSS1Compat')
  39951. {
  39952. doc.writeln('<!DOCTYPE html>');
  39953. }
  39954. doc.writeln('<html>');
  39955. }
  39956. doc.writeln('<head>');
  39957. this.writeHead(doc, css);
  39958. doc.writeln('</head>');
  39959. doc.writeln('<body class="mxPage">');
  39960. }
  39961. // Computes the horizontal and vertical page count
  39962. var bounds = this.graph.getGraphBounds().clone();
  39963. var currentScale = this.graph.getView().getScale();
  39964. var sc = currentScale / this.scale;
  39965. var tr = this.graph.getView().getTranslate();
  39966. // Uses the absolute origin with no offset for all printing
  39967. if (!this.autoOrigin)
  39968. {
  39969. this.x0 -= tr.x * this.scale;
  39970. this.y0 -= tr.y * this.scale;
  39971. bounds.width += bounds.x;
  39972. bounds.height += bounds.y;
  39973. bounds.x = 0;
  39974. bounds.y = 0;
  39975. this.border = 0;
  39976. }
  39977. // Store the available page area
  39978. var availableWidth = this.pageFormat.width - (this.border * 2);
  39979. var availableHeight = this.pageFormat.height - (this.border * 2);
  39980. // Adds margins to page format
  39981. this.pageFormat.height += this.marginTop + this.marginBottom;
  39982. // Compute the unscaled, untranslated bounds to find
  39983. // the number of vertical and horizontal pages
  39984. bounds.width /= sc;
  39985. bounds.height /= sc;
  39986. var hpages = Math.max(1, Math.ceil((bounds.width + this.x0) / availableWidth));
  39987. var vpages = Math.max(1, Math.ceil((bounds.height + this.y0) / availableHeight));
  39988. this.pageCount = hpages * vpages;
  39989. var writePageSelector = mxUtils.bind(this, function()
  39990. {
  39991. if (this.pageSelector && (vpages > 1 || hpages > 1))
  39992. {
  39993. var table = this.createPageSelector(vpages, hpages);
  39994. doc.body.appendChild(table);
  39995. // Implements position: fixed in IE quirks mode
  39996. if (mxClient.IS_IE && doc.documentMode == null || doc.documentMode == 5 || doc.documentMode == 8 || doc.documentMode == 7)
  39997. {
  39998. table.style.position = 'absolute';
  39999. var update = function()
  40000. {
  40001. table.style.top = ((doc.body.scrollTop || doc.documentElement.scrollTop) + 10) + 'px';
  40002. };
  40003. mxEvent.addListener(this.wnd, 'scroll', function(evt)
  40004. {
  40005. update();
  40006. });
  40007. mxEvent.addListener(this.wnd, 'resize', function(evt)
  40008. {
  40009. update();
  40010. });
  40011. }
  40012. }
  40013. });
  40014. var addPage = mxUtils.bind(this, function(div, addBreak)
  40015. {
  40016. // Border of the DIV (aka page) inside the document
  40017. if (this.borderColor != null)
  40018. {
  40019. div.style.borderColor = this.borderColor;
  40020. div.style.borderStyle = 'solid';
  40021. div.style.borderWidth = '1px';
  40022. }
  40023. // Needs to be assigned directly because IE doesn't support
  40024. // child selectors, eg. body > div { background: white; }
  40025. div.style.background = this.backgroundColor;
  40026. if (forcePageBreaks || addBreak)
  40027. {
  40028. div.style.pageBreakAfter = 'always';
  40029. }
  40030. // NOTE: We are dealing with cross-window DOM here, which
  40031. // is a problem in IE, so we copy the HTML markup instead.
  40032. // The underlying problem is that the graph display markup
  40033. // creation (in mxShape, mxGraphView) is hardwired to using
  40034. // document.createElement and hence we must use this document
  40035. // to create the complete page and then copy it over to the
  40036. // new window.document. This can be fixed later by using the
  40037. // ownerDocument of the container in mxShape and mxGraphView.
  40038. if (isNewWindow && (mxClient.IS_IE || document.documentMode >= 11 || mxClient.IS_EDGE))
  40039. {
  40040. // For some obscure reason, removing the DIV from the
  40041. // parent before fetching its outerHTML has missing
  40042. // fillcolor properties and fill children, so the div
  40043. // must be removed afterwards to keep the fillcolors.
  40044. doc.writeln(div.outerHTML);
  40045. div.parentNode.removeChild(div);
  40046. }
  40047. else if (mxClient.IS_IE || document.documentMode >= 11 || mxClient.IS_EDGE)
  40048. {
  40049. var clone = doc.createElement('div');
  40050. clone.innerHTML = div.outerHTML;
  40051. clone = clone.getElementsByTagName('div')[0];
  40052. doc.body.appendChild(clone);
  40053. div.parentNode.removeChild(div);
  40054. }
  40055. else
  40056. {
  40057. div.parentNode.removeChild(div);
  40058. doc.body.appendChild(div);
  40059. }
  40060. if (forcePageBreaks || addBreak)
  40061. {
  40062. this.addPageBreak(doc);
  40063. }
  40064. });
  40065. var cov = this.getCoverPages(this.pageFormat.width, this.pageFormat.height);
  40066. if (cov != null)
  40067. {
  40068. for (var i = 0; i < cov.length; i++)
  40069. {
  40070. addPage(cov[i], true);
  40071. }
  40072. }
  40073. var apx = this.getAppendices(this.pageFormat.width, this.pageFormat.height);
  40074. // Appends each page to the page output for printing, making
  40075. // sure there will be a page break after each page (ie. div)
  40076. for (var i = 0; i < vpages; i++)
  40077. {
  40078. var dy = i * availableHeight / this.scale - this.y0 / this.scale +
  40079. (bounds.y - tr.y * currentScale) / currentScale;
  40080. for (var j = 0; j < hpages; j++)
  40081. {
  40082. if (this.wnd == null)
  40083. {
  40084. return null;
  40085. }
  40086. var dx = j * availableWidth / this.scale - this.x0 / this.scale +
  40087. (bounds.x - tr.x * currentScale) / currentScale;
  40088. var pageNum = i * hpages + j + 1;
  40089. var clip = new mxRectangle(dx, dy, availableWidth, availableHeight);
  40090. div = this.renderPage(this.pageFormat.width, this.pageFormat.height, 0, 0, mxUtils.bind(this, function(div)
  40091. {
  40092. this.addGraphFragment(-dx, -dy, this.scale, pageNum, div, clip);
  40093. if (this.printBackgroundImage)
  40094. {
  40095. this.insertBackgroundImage(div, -dx, -dy);
  40096. }
  40097. }), pageNum);
  40098. // Gives the page a unique ID for later accessing the page
  40099. div.setAttribute('id', 'mxPage-'+pageNum);
  40100. addPage(div, apx != null || i < vpages - 1 || j < hpages - 1);
  40101. }
  40102. }
  40103. if (apx != null)
  40104. {
  40105. for (var i = 0; i < apx.length; i++)
  40106. {
  40107. addPage(apx[i], i < apx.length - 1);
  40108. }
  40109. }
  40110. if (isNewWindow && !keepOpen)
  40111. {
  40112. this.closeDocument();
  40113. writePageSelector();
  40114. }
  40115. this.wnd.focus();
  40116. }
  40117. catch (e)
  40118. {
  40119. // Removes the DIV from the document in case of an error
  40120. if (div != null && div.parentNode != null)
  40121. {
  40122. div.parentNode.removeChild(div);
  40123. }
  40124. }
  40125. finally
  40126. {
  40127. this.graph.cellRenderer.initializeOverlay = previousInitializeOverlay;
  40128. }
  40129. return this.wnd;
  40130. };
  40131. /**
  40132. * Function: addPageBreak
  40133. *
  40134. * Adds a page break to the given document.
  40135. */
  40136. mxPrintPreview.prototype.addPageBreak = function(doc)
  40137. {
  40138. var hr = doc.createElement('hr');
  40139. hr.className = 'mxPageBreak';
  40140. doc.body.appendChild(hr);
  40141. };
  40142. /**
  40143. * Function: closeDocument
  40144. *
  40145. * Writes the closing tags for body and page after calling <writePostfix>.
  40146. */
  40147. mxPrintPreview.prototype.closeDocument = function()
  40148. {
  40149. try
  40150. {
  40151. if (this.wnd != null && this.wnd.document != null)
  40152. {
  40153. var doc = this.wnd.document;
  40154. this.writePostfix(doc);
  40155. doc.writeln('</body>');
  40156. doc.writeln('</html>');
  40157. doc.close();
  40158. // Removes all event handlers in the print output
  40159. mxEvent.release(doc.body);
  40160. }
  40161. }
  40162. catch (e)
  40163. {
  40164. // ignore any errors resulting from wnd no longer being available
  40165. }
  40166. };
  40167. /**
  40168. * Function: writeHead
  40169. *
  40170. * Writes the HEAD section into the given document, without the opening
  40171. * and closing HEAD tags.
  40172. */
  40173. mxPrintPreview.prototype.writeHead = function(doc, css)
  40174. {
  40175. if (this.title != null)
  40176. {
  40177. doc.writeln('<title>' + this.title + '</title>');
  40178. }
  40179. // Adds required namespaces
  40180. if (mxClient.IS_VML)
  40181. {
  40182. doc.writeln('<style type="text/css">v\\:*{behavior:url(#default#VML)}o\\:*{behavior:url(#default#VML)}</style>');
  40183. }
  40184. // Adds all required stylesheets
  40185. mxClient.link('stylesheet', mxClient.basePath + '/css/common.css', doc);
  40186. // Removes horizontal rules and page selector from print output
  40187. doc.writeln('<style type="text/css">');
  40188. doc.writeln('@media print {');
  40189. doc.writeln(' * { -webkit-print-color-adjust: exact; }');
  40190. doc.writeln(' table.mxPageSelector { display: none; }');
  40191. doc.writeln(' hr.mxPageBreak { display: none; }');
  40192. doc.writeln('}');
  40193. doc.writeln('@media screen {');
  40194. // NOTE: position: fixed is not supported in IE, so the page selector
  40195. // position (absolute) needs to be updated in IE (see below)
  40196. doc.writeln(' table.mxPageSelector { position: fixed; right: 10px; top: 10px;' +
  40197. 'font-family: Arial; font-size:10pt; border: solid 1px darkgray;' +
  40198. 'background: white; border-collapse:collapse; }');
  40199. doc.writeln(' table.mxPageSelector td { border: solid 1px gray; padding:4px; }');
  40200. doc.writeln(' body.mxPage { background: gray; }');
  40201. doc.writeln('}');
  40202. if (css != null)
  40203. {
  40204. doc.writeln(css);
  40205. }
  40206. doc.writeln('</style>');
  40207. };
  40208. /**
  40209. * Function: writePostfix
  40210. *
  40211. * Called before closing the body of the page. This implementation is empty.
  40212. */
  40213. mxPrintPreview.prototype.writePostfix = function(doc)
  40214. {
  40215. // empty
  40216. };
  40217. /**
  40218. * Function: createPageSelector
  40219. *
  40220. * Creates the page selector table.
  40221. */
  40222. mxPrintPreview.prototype.createPageSelector = function(vpages, hpages)
  40223. {
  40224. var doc = this.wnd.document;
  40225. var table = doc.createElement('table');
  40226. table.className = 'mxPageSelector';
  40227. table.setAttribute('border', '0');
  40228. var tbody = doc.createElement('tbody');
  40229. for (var i = 0; i < vpages; i++)
  40230. {
  40231. var row = doc.createElement('tr');
  40232. for (var j = 0; j < hpages; j++)
  40233. {
  40234. var pageNum = i * hpages + j + 1;
  40235. var cell = doc.createElement('td');
  40236. var a = doc.createElement('a');
  40237. a.setAttribute('href', '#mxPage-' + pageNum);
  40238. // Workaround for FF where the anchor is appended to the URL of the original document
  40239. if (mxClient.IS_NS && !mxClient.IS_SF && !mxClient.IS_GC)
  40240. {
  40241. var js = 'var page = document.getElementById(\'mxPage-' + pageNum + '\');page.scrollIntoView(true);event.preventDefault();';
  40242. a.setAttribute('onclick', js);
  40243. }
  40244. mxUtils.write(a, pageNum, doc);
  40245. cell.appendChild(a);
  40246. row.appendChild(cell);
  40247. }
  40248. tbody.appendChild(row);
  40249. }
  40250. table.appendChild(tbody);
  40251. return table;
  40252. };
  40253. /**
  40254. * Function: renderPage
  40255. *
  40256. * Creates a DIV that prints a single page of the given
  40257. * graph using the given scale and returns the DIV that
  40258. * represents the page.
  40259. *
  40260. * Parameters:
  40261. *
  40262. * w - Width of the page in pixels.
  40263. * h - Height of the page in pixels.
  40264. * dx - Optional horizontal page offset in pixels (used internally).
  40265. * dy - Optional vertical page offset in pixels (used internally).
  40266. * content - Callback that adds the HTML content to the inner div of a page.
  40267. * Takes the inner div as the argument.
  40268. * pageNumber - Integer representing the page number.
  40269. */
  40270. mxPrintPreview.prototype.renderPage = function(w, h, dx, dy, content, pageNumber)
  40271. {
  40272. var doc = this.wnd.document;
  40273. var div = document.createElement('div');
  40274. var arg = null;
  40275. try
  40276. {
  40277. // Workaround for ignored clipping in IE 9 standards
  40278. // when printing with page breaks and HTML labels.
  40279. if (dx != 0 || dy != 0)
  40280. {
  40281. div.style.position = 'relative';
  40282. div.style.width = w + 'px';
  40283. div.style.height = h + 'px';
  40284. div.style.pageBreakInside = 'avoid';
  40285. var innerDiv = document.createElement('div');
  40286. innerDiv.style.position = 'relative';
  40287. innerDiv.style.top = this.border + 'px';
  40288. innerDiv.style.left = this.border + 'px';
  40289. innerDiv.style.width = (w - 2 * this.border) + 'px';
  40290. innerDiv.style.height = (h - 2 * this.border) + 'px';
  40291. innerDiv.style.overflow = 'hidden';
  40292. var viewport = document.createElement('div');
  40293. viewport.style.position = 'relative';
  40294. viewport.style.marginLeft = dx + 'px';
  40295. viewport.style.marginTop = dy + 'px';
  40296. // FIXME: IE8 standards output problems
  40297. if (doc.documentMode == 8)
  40298. {
  40299. innerDiv.style.position = 'absolute';
  40300. viewport.style.position = 'absolute';
  40301. }
  40302. if (doc.documentMode == 10)
  40303. {
  40304. viewport.style.width = '100%';
  40305. viewport.style.height = '100%';
  40306. }
  40307. innerDiv.appendChild(viewport);
  40308. div.appendChild(innerDiv);
  40309. document.body.appendChild(div);
  40310. arg = viewport;
  40311. }
  40312. // FIXME: IE10/11 too many pages
  40313. else
  40314. {
  40315. div.style.width = w + 'px';
  40316. div.style.height = h + 'px';
  40317. div.style.overflow = 'hidden';
  40318. div.style.pageBreakInside = 'avoid';
  40319. // IE8 uses above branch currently
  40320. if (doc.documentMode == 8)
  40321. {
  40322. div.style.position = 'relative';
  40323. }
  40324. var innerDiv = document.createElement('div');
  40325. innerDiv.style.width = (w - 2 * this.border) + 'px';
  40326. innerDiv.style.height = (h - 2 * this.border) + 'px';
  40327. innerDiv.style.overflow = 'hidden';
  40328. if (mxClient.IS_IE && (doc.documentMode == null || doc.documentMode == 5 ||
  40329. doc.documentMode == 8 || doc.documentMode == 7))
  40330. {
  40331. innerDiv.style.marginTop = this.border + 'px';
  40332. innerDiv.style.marginLeft = this.border + 'px';
  40333. }
  40334. else
  40335. {
  40336. innerDiv.style.top = this.border + 'px';
  40337. innerDiv.style.left = this.border + 'px';
  40338. }
  40339. if (this.graph.dialect == mxConstants.DIALECT_VML)
  40340. {
  40341. innerDiv.style.position = 'absolute';
  40342. }
  40343. div.appendChild(innerDiv);
  40344. document.body.appendChild(div);
  40345. arg = innerDiv;
  40346. }
  40347. }
  40348. catch (e)
  40349. {
  40350. div.parentNode.removeChild(div);
  40351. div = null;
  40352. throw e;
  40353. }
  40354. content(arg);
  40355. return div;
  40356. };
  40357. /**
  40358. * Function: getRoot
  40359. *
  40360. * Returns the root cell for painting the graph.
  40361. */
  40362. mxPrintPreview.prototype.getRoot = function()
  40363. {
  40364. var root = this.graph.view.currentRoot;
  40365. if (root == null)
  40366. {
  40367. root = this.graph.getModel().getRoot();
  40368. }
  40369. return root;
  40370. };
  40371. /**
  40372. * Function: addGraphFragment
  40373. *
  40374. * Adds a graph fragment to the given div.
  40375. *
  40376. * Parameters:
  40377. *
  40378. * dx - Horizontal translation for the diagram.
  40379. * dy - Vertical translation for the diagram.
  40380. * scale - Scale for the diagram.
  40381. * pageNumber - Number of the page to be rendered.
  40382. * div - Div that contains the output.
  40383. * clip - Contains the clipping rectangle as an <mxRectangle>.
  40384. */
  40385. mxPrintPreview.prototype.addGraphFragment = function(dx, dy, scale, pageNumber, div, clip)
  40386. {
  40387. var view = this.graph.getView();
  40388. var previousContainer = this.graph.container;
  40389. this.graph.container = div;
  40390. var canvas = view.getCanvas();
  40391. var backgroundPane = view.getBackgroundPane();
  40392. var drawPane = view.getDrawPane();
  40393. var overlayPane = view.getOverlayPane();
  40394. var realScale = scale;
  40395. if (this.graph.dialect == mxConstants.DIALECT_SVG)
  40396. {
  40397. view.createSvg();
  40398. // Uses CSS transform for scaling
  40399. if (!mxClient.NO_FO)
  40400. {
  40401. var g = view.getDrawPane().parentNode;
  40402. var prev = g.getAttribute('transform');
  40403. g.setAttribute('transformOrigin', '0 0');
  40404. g.setAttribute('transform', 'scale(' + scale + ',' + scale + ')' +
  40405. 'translate(' + dx + ',' + dy + ')');
  40406. scale = 1;
  40407. dx = 0;
  40408. dy = 0;
  40409. }
  40410. }
  40411. else if (this.graph.dialect == mxConstants.DIALECT_VML)
  40412. {
  40413. view.createVml();
  40414. }
  40415. else
  40416. {
  40417. view.createHtml();
  40418. }
  40419. // Disables events on the view
  40420. var eventsEnabled = view.isEventsEnabled();
  40421. view.setEventsEnabled(false);
  40422. // Disables the graph to avoid cursors
  40423. var graphEnabled = this.graph.isEnabled();
  40424. this.graph.setEnabled(false);
  40425. // Resets the translation
  40426. var translate = view.getTranslate();
  40427. view.translate = new mxPoint(dx, dy);
  40428. // Redraws only states that intersect the clip
  40429. var redraw = this.graph.cellRenderer.redraw;
  40430. var states = view.states;
  40431. var s = view.scale;
  40432. // Gets the transformed clip for intersection check below
  40433. if (this.clipping)
  40434. {
  40435. var tempClip = new mxRectangle((clip.x + translate.x) * s, (clip.y + translate.y) * s,
  40436. clip.width * s / realScale, clip.height * s / realScale);
  40437. // Checks clipping rectangle for speedup
  40438. // Must create terminal states for edge clipping even if terminal outside of clip
  40439. this.graph.cellRenderer.redraw = function(state, force, rendering)
  40440. {
  40441. if (state != null)
  40442. {
  40443. // Gets original state from graph to find bounding box
  40444. var orig = states.get(state.cell);
  40445. if (orig != null)
  40446. {
  40447. var bbox = view.getBoundingBox(orig, false);
  40448. // Stops rendering if outside clip for speedup but ignores
  40449. // edge labels where width and height is set to 0
  40450. if (bbox != null && bbox.width > 0 && bbox.height > 0 &&
  40451. !mxUtils.intersects(tempClip, bbox))
  40452. {
  40453. return;
  40454. }
  40455. }
  40456. }
  40457. redraw.apply(this, arguments);
  40458. };
  40459. }
  40460. var temp = null;
  40461. try
  40462. {
  40463. // Creates the temporary cell states in the view and
  40464. // draws them onto the temporary DOM nodes in the view
  40465. var cells = [this.getRoot()];
  40466. temp = new mxTemporaryCellStates(view, scale, cells, null, mxUtils.bind(this, function(state)
  40467. {
  40468. return this.getLinkForCellState(state);
  40469. }));
  40470. }
  40471. finally
  40472. {
  40473. // Removes overlay pane with selection handles
  40474. // controls and icons from the print output
  40475. if (mxClient.IS_IE)
  40476. {
  40477. view.overlayPane.innerHTML = '';
  40478. view.canvas.style.overflow = 'hidden';
  40479. view.canvas.style.position = 'relative';
  40480. view.canvas.style.top = this.marginTop + 'px';
  40481. view.canvas.style.width = clip.width + 'px';
  40482. view.canvas.style.height = clip.height + 'px';
  40483. }
  40484. else
  40485. {
  40486. // Removes everything but the SVG node
  40487. var tmp = div.firstChild;
  40488. while (tmp != null)
  40489. {
  40490. var next = tmp.nextSibling;
  40491. var name = tmp.nodeName.toLowerCase();
  40492. // Note: Width and height are required in FF 11
  40493. if (name == 'svg')
  40494. {
  40495. tmp.style.overflow = 'hidden';
  40496. tmp.style.position = 'relative';
  40497. tmp.style.top = this.marginTop + 'px';
  40498. tmp.setAttribute('width', clip.width);
  40499. tmp.setAttribute('height', clip.height);
  40500. tmp.style.width = '';
  40501. tmp.style.height = '';
  40502. }
  40503. // Tries to fetch all text labels and only text labels
  40504. else if (tmp.style.cursor != 'default' && name != 'div')
  40505. {
  40506. tmp.parentNode.removeChild(tmp);
  40507. }
  40508. tmp = next;
  40509. }
  40510. }
  40511. // Puts background image behind SVG output
  40512. if (this.printBackgroundImage)
  40513. {
  40514. var svgs = div.getElementsByTagName('svg');
  40515. if (svgs.length > 0)
  40516. {
  40517. svgs[0].style.position = 'absolute';
  40518. }
  40519. }
  40520. // Completely removes the overlay pane to remove more handles
  40521. view.overlayPane.parentNode.removeChild(view.overlayPane);
  40522. // Restores the state of the view
  40523. this.graph.setEnabled(graphEnabled);
  40524. this.graph.container = previousContainer;
  40525. this.graph.cellRenderer.redraw = redraw;
  40526. view.canvas = canvas;
  40527. view.backgroundPane = backgroundPane;
  40528. view.drawPane = drawPane;
  40529. view.overlayPane = overlayPane;
  40530. view.translate = translate;
  40531. temp.destroy();
  40532. view.setEventsEnabled(eventsEnabled);
  40533. }
  40534. };
  40535. /**
  40536. * Function: getLinkForCellState
  40537. *
  40538. * Returns the link for the given cell state. This returns null.
  40539. */
  40540. mxPrintPreview.prototype.getLinkForCellState = function(state)
  40541. {
  40542. return this.graph.getLinkForCell(state.cell);
  40543. };
  40544. /**
  40545. * Function: insertBackgroundImage
  40546. *
  40547. * Inserts the background image into the given div.
  40548. */
  40549. mxPrintPreview.prototype.insertBackgroundImage = function(div, dx, dy)
  40550. {
  40551. var bg = this.graph.backgroundImage;
  40552. if (bg != null)
  40553. {
  40554. var img = document.createElement('img');
  40555. img.style.position = 'absolute';
  40556. img.style.marginLeft = Math.round(dx * this.scale) + 'px';
  40557. img.style.marginTop = Math.round(dy * this.scale) + 'px';
  40558. img.setAttribute('width', Math.round(this.scale * bg.width));
  40559. img.setAttribute('height', Math.round(this.scale * bg.height));
  40560. img.src = bg.src;
  40561. div.insertBefore(img, div.firstChild);
  40562. }
  40563. };
  40564. /**
  40565. * Function: getCoverPages
  40566. *
  40567. * Returns the pages to be added before the print output. This returns null.
  40568. */
  40569. mxPrintPreview.prototype.getCoverPages = function()
  40570. {
  40571. return null;
  40572. };
  40573. /**
  40574. * Function: getAppendices
  40575. *
  40576. * Returns the pages to be added after the print output. This returns null.
  40577. */
  40578. mxPrintPreview.prototype.getAppendices = function()
  40579. {
  40580. return null;
  40581. };
  40582. /**
  40583. * Function: print
  40584. *
  40585. * Opens the print preview and shows the print dialog.
  40586. *
  40587. * Parameters:
  40588. *
  40589. * css - Optional CSS string to be used in the head section.
  40590. */
  40591. mxPrintPreview.prototype.print = function(css)
  40592. {
  40593. var wnd = this.open(css);
  40594. if (wnd != null)
  40595. {
  40596. wnd.print();
  40597. }
  40598. };
  40599. /**
  40600. * Function: close
  40601. *
  40602. * Closes the print preview window.
  40603. */
  40604. mxPrintPreview.prototype.close = function()
  40605. {
  40606. if (this.wnd != null)
  40607. {
  40608. this.wnd.close();
  40609. this.wnd = null;
  40610. }
  40611. };
  40612. /**
  40613. * Copyright (c) 2006-2015, JGraph Ltd
  40614. * Copyright (c) 2006-2015, Gaudenz Alder
  40615. */
  40616. /**
  40617. * Class: mxStylesheet
  40618. *
  40619. * Defines the appearance of the cells in a graph. See <putCellStyle> for an
  40620. * example of creating a new cell style. It is recommended to use objects, not
  40621. * arrays for holding cell styles. Existing styles can be cloned using
  40622. * <mxUtils.clone> and turned into a string for debugging using
  40623. * <mxUtils.toString>.
  40624. *
  40625. * Default Styles:
  40626. *
  40627. * The stylesheet contains two built-in styles, which are used if no style is
  40628. * defined for a cell:
  40629. *
  40630. * defaultVertex - Default style for vertices
  40631. * defaultEdge - Default style for edges
  40632. *
  40633. * Example:
  40634. *
  40635. * (code)
  40636. * var vertexStyle = stylesheet.getDefaultVertexStyle();
  40637. * vertexStyle[mxConstants.STYLE_ROUNDED] = true;
  40638. * var edgeStyle = stylesheet.getDefaultEdgeStyle();
  40639. * edgeStyle[mxConstants.STYLE_EDGE] = mxEdgeStyle.EntityRelation;
  40640. * (end)
  40641. *
  40642. * Modifies the built-in default styles.
  40643. *
  40644. * To avoid the default style for a cell, add a leading semicolon
  40645. * to the style definition, eg.
  40646. *
  40647. * (code)
  40648. * ;shadow=1
  40649. * (end)
  40650. *
  40651. * Removing keys:
  40652. *
  40653. * For removing a key in a cell style of the form [stylename;|key=value;] the
  40654. * special value none can be used, eg. highlight;fillColor=none
  40655. *
  40656. * See also the helper methods in mxUtils to modify strings of this format,
  40657. * namely <mxUtils.setStyle>, <mxUtils.indexOfStylename>,
  40658. * <mxUtils.addStylename>, <mxUtils.removeStylename>,
  40659. * <mxUtils.removeAllStylenames> and <mxUtils.setStyleFlag>.
  40660. *
  40661. * Constructor: mxStylesheet
  40662. *
  40663. * Constructs a new stylesheet and assigns default styles.
  40664. */
  40665. function mxStylesheet()
  40666. {
  40667. this.styles = new Object();
  40668. this.putDefaultVertexStyle(this.createDefaultVertexStyle());
  40669. this.putDefaultEdgeStyle(this.createDefaultEdgeStyle());
  40670. };
  40671. /**
  40672. * Function: styles
  40673. *
  40674. * Maps from names to cell styles. Each cell style is a map of key,
  40675. * value pairs.
  40676. */
  40677. mxStylesheet.prototype.styles;
  40678. /**
  40679. * Function: createDefaultVertexStyle
  40680. *
  40681. * Creates and returns the default vertex style.
  40682. */
  40683. mxStylesheet.prototype.createDefaultVertexStyle = function()
  40684. {
  40685. var style = new Object();
  40686. style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_RECTANGLE;
  40687. style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RectanglePerimeter;
  40688. style[mxConstants.STYLE_VERTICAL_ALIGN] = mxConstants.ALIGN_MIDDLE;
  40689. style[mxConstants.STYLE_ALIGN] = mxConstants.ALIGN_CENTER;
  40690. style[mxConstants.STYLE_FILLCOLOR] = '#C3D9FF';
  40691. style[mxConstants.STYLE_STROKECOLOR] = '#6482B9';
  40692. style[mxConstants.STYLE_FONTCOLOR] = '#774400';
  40693. return style;
  40694. };
  40695. /**
  40696. * Function: createDefaultEdgeStyle
  40697. *
  40698. * Creates and returns the default edge style.
  40699. */
  40700. mxStylesheet.prototype.createDefaultEdgeStyle = function()
  40701. {
  40702. var style = new Object();
  40703. style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_CONNECTOR;
  40704. style[mxConstants.STYLE_ENDARROW] = mxConstants.ARROW_CLASSIC;
  40705. style[mxConstants.STYLE_VERTICAL_ALIGN] = mxConstants.ALIGN_MIDDLE;
  40706. style[mxConstants.STYLE_ALIGN] = mxConstants.ALIGN_CENTER;
  40707. style[mxConstants.STYLE_STROKECOLOR] = '#6482B9';
  40708. style[mxConstants.STYLE_FONTCOLOR] = '#446299';
  40709. return style;
  40710. };
  40711. /**
  40712. * Function: putDefaultVertexStyle
  40713. *
  40714. * Sets the default style for vertices using defaultVertex as the
  40715. * stylename.
  40716. *
  40717. * Parameters:
  40718. * style - Key, value pairs that define the style.
  40719. */
  40720. mxStylesheet.prototype.putDefaultVertexStyle = function(style)
  40721. {
  40722. this.putCellStyle('defaultVertex', style);
  40723. };
  40724. /**
  40725. * Function: putDefaultEdgeStyle
  40726. *
  40727. * Sets the default style for edges using defaultEdge as the stylename.
  40728. */
  40729. mxStylesheet.prototype.putDefaultEdgeStyle = function(style)
  40730. {
  40731. this.putCellStyle('defaultEdge', style);
  40732. };
  40733. /**
  40734. * Function: getDefaultVertexStyle
  40735. *
  40736. * Returns the default style for vertices.
  40737. */
  40738. mxStylesheet.prototype.getDefaultVertexStyle = function()
  40739. {
  40740. return this.styles['defaultVertex'];
  40741. };
  40742. /**
  40743. * Function: getDefaultEdgeStyle
  40744. *
  40745. * Sets the default style for edges.
  40746. */
  40747. mxStylesheet.prototype.getDefaultEdgeStyle = function()
  40748. {
  40749. return this.styles['defaultEdge'];
  40750. };
  40751. /**
  40752. * Function: putCellStyle
  40753. *
  40754. * Stores the given map of key, value pairs under the given name in
  40755. * <styles>.
  40756. *
  40757. * Example:
  40758. *
  40759. * The following example adds a new style called 'rounded' into an
  40760. * existing stylesheet:
  40761. *
  40762. * (code)
  40763. * var style = new Object();
  40764. * style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_RECTANGLE;
  40765. * style[mxConstants.STYLE_PERIMETER] = mxPerimeter.RectanglePerimeter;
  40766. * style[mxConstants.STYLE_ROUNDED] = true;
  40767. * graph.getStylesheet().putCellStyle('rounded', style);
  40768. * (end)
  40769. *
  40770. * In the above example, the new style is an object. The possible keys of
  40771. * the object are all the constants in <mxConstants> that start with STYLE
  40772. * and the values are either JavaScript objects, such as
  40773. * <mxPerimeter.RightAngleRectanglePerimeter> (which is in fact a function)
  40774. * or expressions, such as true. Note that not all keys will be
  40775. * interpreted by all shapes (eg. the line shape ignores the fill color).
  40776. * The final call to this method associates the style with a name in the
  40777. * stylesheet. The style is used in a cell with the following code:
  40778. *
  40779. * (code)
  40780. * model.setStyle(cell, 'rounded');
  40781. * (end)
  40782. *
  40783. * Parameters:
  40784. *
  40785. * name - Name for the style to be stored.
  40786. * style - Key, value pairs that define the style.
  40787. */
  40788. mxStylesheet.prototype.putCellStyle = function(name, style)
  40789. {
  40790. this.styles[name] = style;
  40791. };
  40792. /**
  40793. * Function: getCellStyle
  40794. *
  40795. * Returns the cell style for the specified stylename or the given
  40796. * defaultStyle if no style can be found for the given stylename.
  40797. *
  40798. * Parameters:
  40799. *
  40800. * name - String of the form [(stylename|key=value);] that represents the
  40801. * style.
  40802. * defaultStyle - Default style to be returned if no style can be found.
  40803. */
  40804. mxStylesheet.prototype.getCellStyle = function(name, defaultStyle)
  40805. {
  40806. var style = defaultStyle;
  40807. if (name != null && name.length > 0)
  40808. {
  40809. var pairs = name.split(';');
  40810. if (style != null &&
  40811. name.charAt(0) != ';')
  40812. {
  40813. style = mxUtils.clone(style);
  40814. }
  40815. else
  40816. {
  40817. style = new Object();
  40818. }
  40819. // Parses each key, value pair into the existing style
  40820. for (var i = 0; i < pairs.length; i++)
  40821. {
  40822. var tmp = pairs[i];
  40823. var pos = tmp.indexOf('=');
  40824. if (pos >= 0)
  40825. {
  40826. var key = tmp.substring(0, pos);
  40827. var value = tmp.substring(pos + 1);
  40828. if (value == mxConstants.NONE)
  40829. {
  40830. delete style[key];
  40831. }
  40832. else if (mxUtils.isNumeric(value))
  40833. {
  40834. style[key] = parseFloat(value);
  40835. }
  40836. else
  40837. {
  40838. style[key] = value;
  40839. }
  40840. }
  40841. else
  40842. {
  40843. // Merges the entries from a named style
  40844. var tmpStyle = this.styles[tmp];
  40845. if (tmpStyle != null)
  40846. {
  40847. for (var key in tmpStyle)
  40848. {
  40849. style[key] = tmpStyle[key];
  40850. }
  40851. }
  40852. }
  40853. }
  40854. }
  40855. return style;
  40856. };
  40857. /**
  40858. * Copyright (c) 2006-2015, JGraph Ltd
  40859. * Copyright (c) 2006-2015, Gaudenz Alder
  40860. */
  40861. /**
  40862. * Class: mxCellState
  40863. *
  40864. * Represents the current state of a cell in a given <mxGraphView>.
  40865. *
  40866. * For edges, the edge label position is stored in <absoluteOffset>.
  40867. *
  40868. * The size for oversize labels can be retrieved using the boundingBox property
  40869. * of the <text> field as shown below.
  40870. *
  40871. * (code)
  40872. * var bbox = (state.text != null) ? state.text.boundingBox : null;
  40873. * (end)
  40874. *
  40875. * Constructor: mxCellState
  40876. *
  40877. * Constructs a new object that represents the current state of the given
  40878. * cell in the specified view.
  40879. *
  40880. * Parameters:
  40881. *
  40882. * view - <mxGraphView> that contains the state.
  40883. * cell - <mxCell> that this state represents.
  40884. * style - Array of key, value pairs that constitute the style.
  40885. */
  40886. function mxCellState(view, cell, style)
  40887. {
  40888. this.view = view;
  40889. this.cell = cell;
  40890. this.style = (style != null) ? style : {};
  40891. this.origin = new mxPoint();
  40892. this.absoluteOffset = new mxPoint();
  40893. };
  40894. /**
  40895. * Extends mxRectangle.
  40896. */
  40897. mxCellState.prototype = new mxRectangle();
  40898. mxCellState.prototype.constructor = mxCellState;
  40899. /**
  40900. * Variable: view
  40901. *
  40902. * Reference to the enclosing <mxGraphView>.
  40903. */
  40904. mxCellState.prototype.view = null;
  40905. /**
  40906. * Variable: cell
  40907. *
  40908. * Reference to the <mxCell> that is represented by this state.
  40909. */
  40910. mxCellState.prototype.cell = null;
  40911. /**
  40912. * Variable: style
  40913. *
  40914. * Contains an array of key, value pairs that represent the style of the
  40915. * cell.
  40916. */
  40917. mxCellState.prototype.style = null;
  40918. /**
  40919. * Variable: invalidStyle
  40920. *
  40921. * Specifies if the style is invalid. Default is false.
  40922. */
  40923. mxCellState.prototype.invalidStyle = false;
  40924. /**
  40925. * Variable: invalid
  40926. *
  40927. * Specifies if the state is invalid. Default is true.
  40928. */
  40929. mxCellState.prototype.invalid = true;
  40930. /**
  40931. * Variable: origin
  40932. *
  40933. * <mxPoint> that holds the origin for all child cells. Default is a new
  40934. * empty <mxPoint>.
  40935. */
  40936. mxCellState.prototype.origin = null;
  40937. /**
  40938. * Variable: absolutePoints
  40939. *
  40940. * Holds an array of <mxPoints> that represent the absolute points of an
  40941. * edge.
  40942. */
  40943. mxCellState.prototype.absolutePoints = null;
  40944. /**
  40945. * Variable: absoluteOffset
  40946. *
  40947. * <mxPoint> that holds the absolute offset. For edges, this is the
  40948. * absolute coordinates of the label position. For vertices, this is the
  40949. * offset of the label relative to the top, left corner of the vertex.
  40950. */
  40951. mxCellState.prototype.absoluteOffset = null;
  40952. /**
  40953. * Variable: visibleSourceState
  40954. *
  40955. * Caches the visible source terminal state.
  40956. */
  40957. mxCellState.prototype.visibleSourceState = null;
  40958. /**
  40959. * Variable: visibleTargetState
  40960. *
  40961. * Caches the visible target terminal state.
  40962. */
  40963. mxCellState.prototype.visibleTargetState = null;
  40964. /**
  40965. * Variable: terminalDistance
  40966. *
  40967. * Caches the distance between the end points for an edge.
  40968. */
  40969. mxCellState.prototype.terminalDistance = 0;
  40970. /**
  40971. * Variable: length
  40972. *
  40973. * Caches the length of an edge.
  40974. */
  40975. mxCellState.prototype.length = 0;
  40976. /**
  40977. * Variable: segments
  40978. *
  40979. * Array of numbers that represent the cached length of each segment of the
  40980. * edge.
  40981. */
  40982. mxCellState.prototype.segments = null;
  40983. /**
  40984. * Variable: shape
  40985. *
  40986. * Holds the <mxShape> that represents the cell graphically.
  40987. */
  40988. mxCellState.prototype.shape = null;
  40989. /**
  40990. * Variable: text
  40991. *
  40992. * Holds the <mxText> that represents the label of the cell. Thi smay be
  40993. * null if the cell has no label.
  40994. */
  40995. mxCellState.prototype.text = null;
  40996. /**
  40997. * Variable: unscaledWidth
  40998. *
  40999. * Holds the unscaled width of the state.
  41000. */
  41001. mxCellState.prototype.unscaledWidth = null;
  41002. /**
  41003. * Variable: unscaledHeight
  41004. *
  41005. * Holds the unscaled height of the state.
  41006. */
  41007. mxCellState.prototype.unscaledHeight = null;
  41008. /**
  41009. * Function: getPerimeterBounds
  41010. *
  41011. * Returns the <mxRectangle> that should be used as the perimeter of the
  41012. * cell.
  41013. *
  41014. * Parameters:
  41015. *
  41016. * border - Optional border to be added around the perimeter bounds.
  41017. * bounds - Optional <mxRectangle> to be used as the initial bounds.
  41018. */
  41019. mxCellState.prototype.getPerimeterBounds = function(border, bounds)
  41020. {
  41021. border = border || 0;
  41022. bounds = (bounds != null) ? bounds : new mxRectangle(this.x, this.y, this.width, this.height);
  41023. if (this.shape != null && this.shape.stencil != null && this.shape.stencil.aspect == 'fixed')
  41024. {
  41025. var aspect = this.shape.stencil.computeAspect(this.style, bounds.x, bounds.y, bounds.width, bounds.height);
  41026. bounds.x = aspect.x;
  41027. bounds.y = aspect.y;
  41028. bounds.width = this.shape.stencil.w0 * aspect.width;
  41029. bounds.height = this.shape.stencil.h0 * aspect.height;
  41030. }
  41031. if (border != 0)
  41032. {
  41033. bounds.grow(border);
  41034. }
  41035. return bounds;
  41036. };
  41037. /**
  41038. * Function: setAbsoluteTerminalPoint
  41039. *
  41040. * Sets the first or last point in <absolutePoints> depending on isSource.
  41041. *
  41042. * Parameters:
  41043. *
  41044. * point - <mxPoint> that represents the terminal point.
  41045. * isSource - Boolean that specifies if the first or last point should
  41046. * be assigned.
  41047. */
  41048. mxCellState.prototype.setAbsoluteTerminalPoint = function(point, isSource)
  41049. {
  41050. if (isSource)
  41051. {
  41052. if (this.absolutePoints == null)
  41053. {
  41054. this.absolutePoints = [];
  41055. }
  41056. if (this.absolutePoints.length == 0)
  41057. {
  41058. this.absolutePoints.push(point);
  41059. }
  41060. else
  41061. {
  41062. this.absolutePoints[0] = point;
  41063. }
  41064. }
  41065. else
  41066. {
  41067. if (this.absolutePoints == null)
  41068. {
  41069. this.absolutePoints = [];
  41070. this.absolutePoints.push(null);
  41071. this.absolutePoints.push(point);
  41072. }
  41073. else if (this.absolutePoints.length == 1)
  41074. {
  41075. this.absolutePoints.push(point);
  41076. }
  41077. else
  41078. {
  41079. this.absolutePoints[this.absolutePoints.length - 1] = point;
  41080. }
  41081. }
  41082. };
  41083. /**
  41084. * Function: setCursor
  41085. *
  41086. * Sets the given cursor on the shape and text shape.
  41087. */
  41088. mxCellState.prototype.setCursor = function(cursor)
  41089. {
  41090. if (this.shape != null)
  41091. {
  41092. this.shape.setCursor(cursor);
  41093. }
  41094. if (this.text != null)
  41095. {
  41096. this.text.setCursor(cursor);
  41097. }
  41098. };
  41099. /**
  41100. * Function: getVisibleTerminal
  41101. *
  41102. * Returns the visible source or target terminal cell.
  41103. *
  41104. * Parameters:
  41105. *
  41106. * source - Boolean that specifies if the source or target cell should be
  41107. * returned.
  41108. */
  41109. mxCellState.prototype.getVisibleTerminal = function(source)
  41110. {
  41111. var tmp = this.getVisibleTerminalState(source);
  41112. return (tmp != null) ? tmp.cell : null;
  41113. };
  41114. /**
  41115. * Function: getVisibleTerminalState
  41116. *
  41117. * Returns the visible source or target terminal state.
  41118. *
  41119. * Parameters:
  41120. *
  41121. * source - Boolean that specifies if the source or target state should be
  41122. * returned.
  41123. */
  41124. mxCellState.prototype.getVisibleTerminalState = function(source)
  41125. {
  41126. return (source) ? this.visibleSourceState : this.visibleTargetState;
  41127. };
  41128. /**
  41129. * Function: setVisibleTerminalState
  41130. *
  41131. * Sets the visible source or target terminal state.
  41132. *
  41133. * Parameters:
  41134. *
  41135. * terminalState - <mxCellState> that represents the terminal.
  41136. * source - Boolean that specifies if the source or target state should be set.
  41137. */
  41138. mxCellState.prototype.setVisibleTerminalState = function(terminalState, source)
  41139. {
  41140. if (source)
  41141. {
  41142. this.visibleSourceState = terminalState;
  41143. }
  41144. else
  41145. {
  41146. this.visibleTargetState = terminalState;
  41147. }
  41148. };
  41149. /**
  41150. * Function: getCellBounds
  41151. *
  41152. * Returns the unscaled, untranslated bounds.
  41153. */
  41154. mxCellState.prototype.getCellBounds = function()
  41155. {
  41156. return this.cellBounds;
  41157. };
  41158. /**
  41159. * Function: getPaintBounds
  41160. *
  41161. * Returns the unscaled, untranslated paint bounds. This is the same as
  41162. * <getCellBounds> but with a 90 degree rotation if the shape's
  41163. * isPaintBoundsInverted returns true.
  41164. */
  41165. mxCellState.prototype.getPaintBounds = function()
  41166. {
  41167. return this.paintBounds;
  41168. };
  41169. /**
  41170. * Function: updateCachedBounds
  41171. *
  41172. * Updates the cellBounds and paintBounds.
  41173. */
  41174. mxCellState.prototype.updateCachedBounds = function()
  41175. {
  41176. var tr = this.view.translate;
  41177. var s = this.view.scale;
  41178. this.cellBounds = new mxRectangle(this.x / s - tr.x, this.y / s - tr.y, this.width / s, this.height / s);
  41179. this.paintBounds = mxRectangle.fromRectangle(this.cellBounds);
  41180. if (this.shape != null && this.shape.isPaintBoundsInverted())
  41181. {
  41182. this.paintBounds.rotate90();
  41183. }
  41184. };
  41185. /**
  41186. * Destructor: setState
  41187. *
  41188. * Copies all fields from the given state to this state.
  41189. */
  41190. mxCellState.prototype.setState = function(state)
  41191. {
  41192. this.view = state.view;
  41193. this.cell = state.cell;
  41194. this.style = state.style;
  41195. this.absolutePoints = state.absolutePoints;
  41196. this.origin = state.origin;
  41197. this.absoluteOffset = state.absoluteOffset;
  41198. this.boundingBox = state.boundingBox;
  41199. this.terminalDistance = state.terminalDistance;
  41200. this.segments = state.segments;
  41201. this.length = state.length;
  41202. this.x = state.x;
  41203. this.y = state.y;
  41204. this.width = state.width;
  41205. this.height = state.height;
  41206. this.unscaledWidth = state.unscaledWidth;
  41207. this.unscaledHeight = state.unscaledHeight;
  41208. };
  41209. /**
  41210. * Function: clone
  41211. *
  41212. * Returns a clone of this <mxPoint>.
  41213. */
  41214. mxCellState.prototype.clone = function()
  41215. {
  41216. var clone = new mxCellState(this.view, this.cell, this.style);
  41217. // Clones the absolute points
  41218. if (this.absolutePoints != null)
  41219. {
  41220. clone.absolutePoints = [];
  41221. for (var i = 0; i < this.absolutePoints.length; i++)
  41222. {
  41223. clone.absolutePoints[i] = this.absolutePoints[i].clone();
  41224. }
  41225. }
  41226. if (this.origin != null)
  41227. {
  41228. clone.origin = this.origin.clone();
  41229. }
  41230. if (this.absoluteOffset != null)
  41231. {
  41232. clone.absoluteOffset = this.absoluteOffset.clone();
  41233. }
  41234. if (this.boundingBox != null)
  41235. {
  41236. clone.boundingBox = this.boundingBox.clone();
  41237. }
  41238. clone.terminalDistance = this.terminalDistance;
  41239. clone.segments = this.segments;
  41240. clone.length = this.length;
  41241. clone.x = this.x;
  41242. clone.y = this.y;
  41243. clone.width = this.width;
  41244. clone.height = this.height;
  41245. clone.unscaledWidth = this.unscaledWidth;
  41246. clone.unscaledHeight = this.unscaledHeight;
  41247. return clone;
  41248. };
  41249. /**
  41250. * Destructor: destroy
  41251. *
  41252. * Destroys the state and all associated resources.
  41253. */
  41254. mxCellState.prototype.destroy = function()
  41255. {
  41256. this.view.graph.cellRenderer.destroy(this);
  41257. };
  41258. /**
  41259. * Copyright (c) 2006-2015, JGraph Ltd
  41260. * Copyright (c) 2006-2015, Gaudenz Alder
  41261. */
  41262. /**
  41263. * Class: mxGraphSelectionModel
  41264. *
  41265. * Implements the selection model for a graph. Here is a listener that handles
  41266. * all removed selection cells.
  41267. *
  41268. * (code)
  41269. * graph.getSelectionModel().addListener(mxEvent.CHANGE, function(sender, evt)
  41270. * {
  41271. * var cells = evt.getProperty('added');
  41272. *
  41273. * for (var i = 0; i < cells.length; i++)
  41274. * {
  41275. * // Handle cells[i]...
  41276. * }
  41277. * });
  41278. * (end)
  41279. *
  41280. * Event: mxEvent.UNDO
  41281. *
  41282. * Fires after the selection was changed in <changeSelection>. The
  41283. * <code>edit</code> property contains the <mxUndoableEdit> which contains the
  41284. * <mxSelectionChange>.
  41285. *
  41286. * Event: mxEvent.CHANGE
  41287. *
  41288. * Fires after the selection changes by executing an <mxSelectionChange>. The
  41289. * <code>added</code> and <code>removed</code> properties contain arrays of
  41290. * cells that have been added to or removed from the selection, respectively.
  41291. * The names are inverted due to historic reasons. This cannot be changed.
  41292. *
  41293. * Constructor: mxGraphSelectionModel
  41294. *
  41295. * Constructs a new graph selection model for the given <mxGraph>.
  41296. *
  41297. * Parameters:
  41298. *
  41299. * graph - Reference to the enclosing <mxGraph>.
  41300. */
  41301. function mxGraphSelectionModel(graph)
  41302. {
  41303. this.graph = graph;
  41304. this.cells = [];
  41305. };
  41306. /**
  41307. * Extends mxEventSource.
  41308. */
  41309. mxGraphSelectionModel.prototype = new mxEventSource();
  41310. mxGraphSelectionModel.prototype.constructor = mxGraphSelectionModel;
  41311. /**
  41312. * Variable: doneResource
  41313. *
  41314. * Specifies the resource key for the status message after a long operation.
  41315. * If the resource for this key does not exist then the value is used as
  41316. * the status message. Default is 'done'.
  41317. */
  41318. mxGraphSelectionModel.prototype.doneResource = (mxClient.language != 'none') ? 'done' : '';
  41319. /**
  41320. * Variable: updatingSelectionResource
  41321. *
  41322. * Specifies the resource key for the status message while the selection is
  41323. * being updated. If the resource for this key does not exist then the
  41324. * value is used as the status message. Default is 'updatingSelection'.
  41325. */
  41326. mxGraphSelectionModel.prototype.updatingSelectionResource = (mxClient.language != 'none') ? 'updatingSelection' : '';
  41327. /**
  41328. * Variable: graph
  41329. *
  41330. * Reference to the enclosing <mxGraph>.
  41331. */
  41332. mxGraphSelectionModel.prototype.graph = null;
  41333. /**
  41334. * Variable: singleSelection
  41335. *
  41336. * Specifies if only one selected item at a time is allowed.
  41337. * Default is false.
  41338. */
  41339. mxGraphSelectionModel.prototype.singleSelection = false;
  41340. /**
  41341. * Function: isSingleSelection
  41342. *
  41343. * Returns <singleSelection> as a boolean.
  41344. */
  41345. mxGraphSelectionModel.prototype.isSingleSelection = function()
  41346. {
  41347. return this.singleSelection;
  41348. };
  41349. /**
  41350. * Function: setSingleSelection
  41351. *
  41352. * Sets the <singleSelection> flag.
  41353. *
  41354. * Parameters:
  41355. *
  41356. * singleSelection - Boolean that specifies the new value for
  41357. * <singleSelection>.
  41358. */
  41359. mxGraphSelectionModel.prototype.setSingleSelection = function(singleSelection)
  41360. {
  41361. this.singleSelection = singleSelection;
  41362. };
  41363. /**
  41364. * Function: isSelected
  41365. *
  41366. * Returns true if the given <mxCell> is selected.
  41367. */
  41368. mxGraphSelectionModel.prototype.isSelected = function(cell)
  41369. {
  41370. if (cell != null)
  41371. {
  41372. return mxUtils.indexOf(this.cells, cell) >= 0;
  41373. }
  41374. return false;
  41375. };
  41376. /**
  41377. * Function: isEmpty
  41378. *
  41379. * Returns true if no cells are currently selected.
  41380. */
  41381. mxGraphSelectionModel.prototype.isEmpty = function()
  41382. {
  41383. return this.cells.length == 0;
  41384. };
  41385. /**
  41386. * Function: clear
  41387. *
  41388. * Clears the selection and fires a <change> event if the selection was not
  41389. * empty.
  41390. */
  41391. mxGraphSelectionModel.prototype.clear = function()
  41392. {
  41393. this.changeSelection(null, this.cells);
  41394. };
  41395. /**
  41396. * Function: setCell
  41397. *
  41398. * Selects the specified <mxCell> using <setCells>.
  41399. *
  41400. * Parameters:
  41401. *
  41402. * cell - <mxCell> to be selected.
  41403. */
  41404. mxGraphSelectionModel.prototype.setCell = function(cell)
  41405. {
  41406. if (cell != null)
  41407. {
  41408. this.setCells([cell]);
  41409. }
  41410. };
  41411. /**
  41412. * Function: setCells
  41413. *
  41414. * Selects the given array of <mxCells> and fires a <change> event.
  41415. *
  41416. * Parameters:
  41417. *
  41418. * cells - Array of <mxCells> to be selected.
  41419. */
  41420. mxGraphSelectionModel.prototype.setCells = function(cells)
  41421. {
  41422. if (cells != null)
  41423. {
  41424. if (this.singleSelection)
  41425. {
  41426. cells = [this.getFirstSelectableCell(cells)];
  41427. }
  41428. var tmp = [];
  41429. for (var i = 0; i < cells.length; i++)
  41430. {
  41431. if (this.graph.isCellSelectable(cells[i]))
  41432. {
  41433. tmp.push(cells[i]);
  41434. }
  41435. }
  41436. this.changeSelection(tmp, this.cells);
  41437. }
  41438. };
  41439. /**
  41440. * Function: getFirstSelectableCell
  41441. *
  41442. * Returns the first selectable cell in the given array of cells.
  41443. */
  41444. mxGraphSelectionModel.prototype.getFirstSelectableCell = function(cells)
  41445. {
  41446. if (cells != null)
  41447. {
  41448. for (var i = 0; i < cells.length; i++)
  41449. {
  41450. if (this.graph.isCellSelectable(cells[i]))
  41451. {
  41452. return cells[i];
  41453. }
  41454. }
  41455. }
  41456. return null;
  41457. };
  41458. /**
  41459. * Function: addCell
  41460. *
  41461. * Adds the given <mxCell> to the selection and fires a <select> event.
  41462. *
  41463. * Parameters:
  41464. *
  41465. * cell - <mxCell> to add to the selection.
  41466. */
  41467. mxGraphSelectionModel.prototype.addCell = function(cell)
  41468. {
  41469. if (cell != null)
  41470. {
  41471. this.addCells([cell]);
  41472. }
  41473. };
  41474. /**
  41475. * Function: addCells
  41476. *
  41477. * Adds the given array of <mxCells> to the selection and fires a <select>
  41478. * event.
  41479. *
  41480. * Parameters:
  41481. *
  41482. * cells - Array of <mxCells> to add to the selection.
  41483. */
  41484. mxGraphSelectionModel.prototype.addCells = function(cells)
  41485. {
  41486. if (cells != null)
  41487. {
  41488. var remove = null;
  41489. if (this.singleSelection)
  41490. {
  41491. remove = this.cells;
  41492. cells = [this.getFirstSelectableCell(cells)];
  41493. }
  41494. var tmp = [];
  41495. for (var i = 0; i < cells.length; i++)
  41496. {
  41497. if (!this.isSelected(cells[i]) &&
  41498. this.graph.isCellSelectable(cells[i]))
  41499. {
  41500. tmp.push(cells[i]);
  41501. }
  41502. }
  41503. this.changeSelection(tmp, remove);
  41504. }
  41505. };
  41506. /**
  41507. * Function: removeCell
  41508. *
  41509. * Removes the specified <mxCell> from the selection and fires a <select>
  41510. * event for the remaining cells.
  41511. *
  41512. * Parameters:
  41513. *
  41514. * cell - <mxCell> to remove from the selection.
  41515. */
  41516. mxGraphSelectionModel.prototype.removeCell = function(cell)
  41517. {
  41518. if (cell != null)
  41519. {
  41520. this.removeCells([cell]);
  41521. }
  41522. };
  41523. /**
  41524. * Function: removeCells
  41525. */
  41526. mxGraphSelectionModel.prototype.removeCells = function(cells)
  41527. {
  41528. if (cells != null)
  41529. {
  41530. var tmp = [];
  41531. for (var i = 0; i < cells.length; i++)
  41532. {
  41533. if (this.isSelected(cells[i]))
  41534. {
  41535. tmp.push(cells[i]);
  41536. }
  41537. }
  41538. this.changeSelection(null, tmp);
  41539. }
  41540. };
  41541. /**
  41542. * Function: changeSelection
  41543. *
  41544. * Adds/removes the specified arrays of <mxCell> to/from the selection.
  41545. *
  41546. * Parameters:
  41547. *
  41548. * added - Array of <mxCell> to add to the selection.
  41549. * remove - Array of <mxCell> to remove from the selection.
  41550. */
  41551. mxGraphSelectionModel.prototype.changeSelection = function(added, removed)
  41552. {
  41553. if ((added != null &&
  41554. added.length > 0 &&
  41555. added[0] != null) ||
  41556. (removed != null &&
  41557. removed.length > 0 &&
  41558. removed[0] != null))
  41559. {
  41560. var change = new mxSelectionChange(this, added, removed);
  41561. change.execute();
  41562. var edit = new mxUndoableEdit(this, false);
  41563. edit.add(change);
  41564. this.fireEvent(new mxEventObject(mxEvent.UNDO, 'edit', edit));
  41565. }
  41566. };
  41567. /**
  41568. * Function: cellAdded
  41569. *
  41570. * Inner callback to add the specified <mxCell> to the selection. No event
  41571. * is fired in this implementation.
  41572. *
  41573. * Paramters:
  41574. *
  41575. * cell - <mxCell> to add to the selection.
  41576. */
  41577. mxGraphSelectionModel.prototype.cellAdded = function(cell)
  41578. {
  41579. if (cell != null &&
  41580. !this.isSelected(cell))
  41581. {
  41582. this.cells.push(cell);
  41583. }
  41584. };
  41585. /**
  41586. * Function: cellRemoved
  41587. *
  41588. * Inner callback to remove the specified <mxCell> from the selection. No
  41589. * event is fired in this implementation.
  41590. *
  41591. * Parameters:
  41592. *
  41593. * cell - <mxCell> to remove from the selection.
  41594. */
  41595. mxGraphSelectionModel.prototype.cellRemoved = function(cell)
  41596. {
  41597. if (cell != null)
  41598. {
  41599. var index = mxUtils.indexOf(this.cells, cell);
  41600. if (index >= 0)
  41601. {
  41602. this.cells.splice(index, 1);
  41603. }
  41604. }
  41605. };
  41606. /**
  41607. * Class: mxSelectionChange
  41608. *
  41609. * Action to change the current root in a view.
  41610. *
  41611. * Constructor: mxCurrentRootChange
  41612. *
  41613. * Constructs a change of the current root in the given view.
  41614. */
  41615. function mxSelectionChange(selectionModel, added, removed)
  41616. {
  41617. this.selectionModel = selectionModel;
  41618. this.added = (added != null) ? added.slice() : null;
  41619. this.removed = (removed != null) ? removed.slice() : null;
  41620. };
  41621. /**
  41622. * Function: execute
  41623. *
  41624. * Changes the current root of the view.
  41625. */
  41626. mxSelectionChange.prototype.execute = function()
  41627. {
  41628. var t0 = mxLog.enter('mxSelectionChange.execute');
  41629. window.status = mxResources.get(
  41630. this.selectionModel.updatingSelectionResource) ||
  41631. this.selectionModel.updatingSelectionResource;
  41632. if (this.removed != null)
  41633. {
  41634. for (var i = 0; i < this.removed.length; i++)
  41635. {
  41636. this.selectionModel.cellRemoved(this.removed[i]);
  41637. }
  41638. }
  41639. if (this.added != null)
  41640. {
  41641. for (var i = 0; i < this.added.length; i++)
  41642. {
  41643. this.selectionModel.cellAdded(this.added[i]);
  41644. }
  41645. }
  41646. var tmp = this.added;
  41647. this.added = this.removed;
  41648. this.removed = tmp;
  41649. window.status = mxResources.get(this.selectionModel.doneResource) ||
  41650. this.selectionModel.doneResource;
  41651. mxLog.leave('mxSelectionChange.execute', t0);
  41652. this.selectionModel.fireEvent(new mxEventObject(mxEvent.CHANGE,
  41653. 'added', this.added, 'removed', this.removed));
  41654. };
  41655. /**
  41656. * Copyright (c) 2006-2015, JGraph Ltd
  41657. * Copyright (c) 2006-2015, Gaudenz Alder
  41658. */
  41659. /**
  41660. * Class: mxCellEditor
  41661. *
  41662. * In-place editor for the graph. To control this editor, use
  41663. * <mxGraph.invokesStopCellEditing>, <mxGraph.enterStopsCellEditing> and
  41664. * <mxGraph.escapeEnabled>. If <mxGraph.enterStopsCellEditing> is true then
  41665. * ctrl-enter or shift-enter can be used to create a linefeed. The F2 and
  41666. * escape keys can always be used to stop editing.
  41667. *
  41668. * To customize the location of the textbox in the graph, override
  41669. * <getEditorBounds> as follows:
  41670. *
  41671. * (code)
  41672. * graph.cellEditor.getEditorBounds = function(state)
  41673. * {
  41674. * var result = mxCellEditor.prototype.getEditorBounds.apply(this, arguments);
  41675. *
  41676. * if (this.graph.getModel().isEdge(state.cell))
  41677. * {
  41678. * result.x = state.getCenterX() - result.width / 2;
  41679. * result.y = state.getCenterY() - result.height / 2;
  41680. * }
  41681. *
  41682. * return result;
  41683. * };
  41684. * (end)
  41685. *
  41686. * Note that this hook is only called if <autoSize> is false. If <autoSize> is true,
  41687. * then <mxShape.getLabelBounds> is used to compute the current bounds of the textbox.
  41688. *
  41689. * The textarea uses the mxCellEditor CSS class. You can modify this class in
  41690. * your custom CSS. Note: You should modify the CSS after loading the client
  41691. * in the page.
  41692. *
  41693. * Example:
  41694. *
  41695. * To only allow numeric input in the in-place editor, use the following code.
  41696. *
  41697. * (code)
  41698. * var text = graph.cellEditor.textarea;
  41699. *
  41700. * mxEvent.addListener(text, 'keydown', function (evt)
  41701. * {
  41702. * if (!(evt.keyCode >= 48 && evt.keyCode <= 57) &&
  41703. * !(evt.keyCode >= 96 && evt.keyCode <= 105))
  41704. * {
  41705. * mxEvent.consume(evt);
  41706. * }
  41707. * });
  41708. * (end)
  41709. *
  41710. * Placeholder:
  41711. *
  41712. * To implement a placeholder for cells without a label, use the
  41713. * <emptyLabelText> variable.
  41714. *
  41715. * Resize in Chrome:
  41716. *
  41717. * Resize of the textarea is disabled by default. If you want to enable
  41718. * this feature extend <init> and set this.textarea.style.resize = ''.
  41719. *
  41720. * To start editing on a key press event, the container of the graph
  41721. * should have focus or a focusable parent should be used to add the
  41722. * key press handler as follows.
  41723. *
  41724. * (code)
  41725. * mxEvent.addListener(graph.container, 'keypress', mxUtils.bind(this, function(evt)
  41726. * {
  41727. * if (!graph.isEditing() && !graph.isSelectionEmpty() && evt.which !== 0 &&
  41728. * !mxEvent.isAltDown(evt) && !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt))
  41729. * {
  41730. * graph.startEditing();
  41731. *
  41732. * if (mxClient.IS_FF)
  41733. * {
  41734. * graph.cellEditor.textarea.value = String.fromCharCode(evt.which);
  41735. * }
  41736. * }
  41737. * }));
  41738. * (end)
  41739. *
  41740. * To allow focus for a DIV, and hence to receive key press events, some browsers
  41741. * require it to have a valid tabindex attribute. In this case the following
  41742. * code may be used to keep the container focused.
  41743. *
  41744. * (code)
  41745. * var graphFireMouseEvent = graph.fireMouseEvent;
  41746. * graph.fireMouseEvent = function(evtName, me, sender)
  41747. * {
  41748. * if (evtName == mxEvent.MOUSE_DOWN)
  41749. * {
  41750. * this.container.focus();
  41751. * }
  41752. *
  41753. * graphFireMouseEvent.apply(this, arguments);
  41754. * };
  41755. * (end)
  41756. *
  41757. * Constructor: mxCellEditor
  41758. *
  41759. * Constructs a new in-place editor for the specified graph.
  41760. *
  41761. * Parameters:
  41762. *
  41763. * graph - Reference to the enclosing <mxGraph>.
  41764. */
  41765. function mxCellEditor(graph)
  41766. {
  41767. this.graph = graph;
  41768. // Stops editing after zoom changes
  41769. this.zoomHandler = mxUtils.bind(this, function()
  41770. {
  41771. if (this.graph.isEditing())
  41772. {
  41773. this.resize();
  41774. }
  41775. });
  41776. this.graph.view.addListener(mxEvent.SCALE, this.zoomHandler);
  41777. this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.zoomHandler);
  41778. // Adds handling of deleted cells while editing
  41779. this.changeHandler = mxUtils.bind(this, function(sender)
  41780. {
  41781. if (this.editingCell != null && this.graph.getView().getState(this.editingCell) == null)
  41782. {
  41783. this.stopEditing(true);
  41784. }
  41785. });
  41786. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  41787. };
  41788. /**
  41789. * Variable: graph
  41790. *
  41791. * Reference to the enclosing <mxGraph>.
  41792. */
  41793. mxCellEditor.prototype.graph = null;
  41794. /**
  41795. * Variable: textarea
  41796. *
  41797. * Holds the DIV that is used for text editing. Note that this may be null before the first
  41798. * edit. Instantiated in <init>.
  41799. */
  41800. mxCellEditor.prototype.textarea = null;
  41801. /**
  41802. * Variable: editingCell
  41803. *
  41804. * Reference to the <mxCell> that is currently being edited.
  41805. */
  41806. mxCellEditor.prototype.editingCell = null;
  41807. /**
  41808. * Variable: trigger
  41809. *
  41810. * Reference to the event that was used to start editing.
  41811. */
  41812. mxCellEditor.prototype.trigger = null;
  41813. /**
  41814. * Variable: modified
  41815. *
  41816. * Specifies if the label has been modified.
  41817. */
  41818. mxCellEditor.prototype.modified = false;
  41819. /**
  41820. * Variable: autoSize
  41821. *
  41822. * Specifies if the textarea should be resized while the text is being edited.
  41823. * Default is true.
  41824. */
  41825. mxCellEditor.prototype.autoSize = true;
  41826. /**
  41827. * Variable: selectText
  41828. *
  41829. * Specifies if the text should be selected when editing starts. Default is
  41830. * true.
  41831. */
  41832. mxCellEditor.prototype.selectText = true;
  41833. /**
  41834. * Variable: emptyLabelText
  41835. *
  41836. * Text to be displayed for empty labels. Default is '' or '<br>' in Firefox as
  41837. * a workaround for the missing cursor bug for empty content editable. This can
  41838. * be set to eg. "[Type Here]" to easier visualize editing of empty labels. The
  41839. * value is only displayed before the first keystroke and is never used as the
  41840. * actual editing value.
  41841. */
  41842. mxCellEditor.prototype.emptyLabelText = (mxClient.IS_FF) ? '<br>' : '';
  41843. /**
  41844. * Variable: escapeCancelsEditing
  41845. *
  41846. * If true, pressing the escape key will stop editing and not accept the new
  41847. * value. Change this to false to accept the new value on escape, and cancel
  41848. * editing on Shift+Escape instead. Default is true.
  41849. */
  41850. mxCellEditor.prototype.escapeCancelsEditing = true;
  41851. /**
  41852. * Variable: textNode
  41853. *
  41854. * Reference to the label DOM node that has been hidden.
  41855. */
  41856. mxCellEditor.prototype.textNode = '';
  41857. /**
  41858. * Variable: zIndex
  41859. *
  41860. * Specifies the zIndex for the textarea. Default is 5.
  41861. */
  41862. mxCellEditor.prototype.zIndex = 5;
  41863. /**
  41864. * Variable: minResize
  41865. *
  41866. * Defines the minimum width and height to be used in <resize>. Default is 0x20px.
  41867. */
  41868. mxCellEditor.prototype.minResize = new mxRectangle(0, 20);
  41869. /**
  41870. * Variable: wordWrapPadding
  41871. *
  41872. * Correction factor for word wrapping width. Default is 2 in quirks, 0 in IE
  41873. * 11 and 1 in all other browsers and modes.
  41874. */
  41875. mxCellEditor.prototype.wordWrapPadding = (mxClient.IS_QUIRKS) ? 2 : (!mxClient.IS_IE11) ? 1 : 0;
  41876. /**
  41877. * Variable: blurEnabled
  41878. *
  41879. * If <focusLost> should be called if <textarea> loses the focus. Default is false.
  41880. */
  41881. mxCellEditor.prototype.blurEnabled = false;
  41882. /**
  41883. * Variable: initialValue
  41884. *
  41885. * Holds the initial editing value to check if the current value was modified.
  41886. */
  41887. mxCellEditor.prototype.initialValue = null;
  41888. /**
  41889. * Variable: align
  41890. *
  41891. * Holds the current temporary horizontal alignment for the cell style. If this
  41892. * is modified then the current text alignment is changed and the cell style is
  41893. * updated when the value is applied.
  41894. */
  41895. mxCellEditor.prototype.align = null;
  41896. /**
  41897. * Function: init
  41898. *
  41899. * Creates the <textarea> and installs the event listeners. The key handler
  41900. * updates the <modified> state.
  41901. */
  41902. mxCellEditor.prototype.init = function ()
  41903. {
  41904. this.textarea = document.createElement('div');
  41905. this.textarea.className = 'mxCellEditor mxPlainTextEditor';
  41906. this.textarea.contentEditable = true;
  41907. // Workaround for selection outside of DIV if height is 0
  41908. if (mxClient.IS_GC)
  41909. {
  41910. this.textarea.style.minHeight = '1em';
  41911. }
  41912. this.textarea.style.position = ((this.isLegacyEditor())) ? 'absolute' : 'relative';
  41913. this.installListeners(this.textarea);
  41914. };
  41915. /**
  41916. * Function: applyValue
  41917. *
  41918. * Called in <stopEditing> if cancel is false to invoke <mxGraph.labelChanged>.
  41919. */
  41920. mxCellEditor.prototype.applyValue = function(state, value)
  41921. {
  41922. this.graph.labelChanged(state.cell, value, this.trigger);
  41923. };
  41924. /**
  41925. * Function: setAlign
  41926. *
  41927. * Sets the temporary horizontal alignment for the current editing session.
  41928. */
  41929. mxCellEditor.prototype.setAlign = function (align)
  41930. {
  41931. if (this.textarea != null)
  41932. {
  41933. this.textarea.style.textAlign = align;
  41934. }
  41935. this.align = align;
  41936. this.resize();
  41937. };
  41938. /**
  41939. * Function: getInitialValue
  41940. *
  41941. * Gets the initial editing value for the given cell.
  41942. */
  41943. mxCellEditor.prototype.getInitialValue = function(state, trigger)
  41944. {
  41945. var result = mxUtils.htmlEntities(this.graph.getEditingValue(state.cell, trigger), false);
  41946. // Workaround for trailing line breaks being ignored in the editor
  41947. if (!mxClient.IS_QUIRKS && document.documentMode != 8 && document.documentMode != 9 &&
  41948. document.documentMode != 10)
  41949. {
  41950. result = mxUtils.replaceTrailingNewlines(result, '<div><br></div>');
  41951. }
  41952. return result.replace(/\n/g, '<br>');
  41953. };
  41954. /**
  41955. * Function: getCurrentValue
  41956. *
  41957. * Returns the current editing value.
  41958. */
  41959. mxCellEditor.prototype.getCurrentValue = function(state)
  41960. {
  41961. return mxUtils.extractTextWithWhitespace(this.textarea.childNodes);
  41962. };
  41963. /**
  41964. * Function: isCancelEditingKeyEvent
  41965. *
  41966. * Returns true if <escapeCancelsEditing> is true and shift, control and meta
  41967. * are not pressed.
  41968. */
  41969. mxCellEditor.prototype.isCancelEditingKeyEvent = function(evt)
  41970. {
  41971. return this.escapeCancelsEditing || mxEvent.isShiftDown(evt) || mxEvent.isControlDown(evt) || mxEvent.isMetaDown(evt);
  41972. };
  41973. /**
  41974. * Function: installListeners
  41975. *
  41976. * Installs listeners for focus, change and standard key event handling.
  41977. */
  41978. mxCellEditor.prototype.installListeners = function(elt)
  41979. {
  41980. // Applies value if text is dragged
  41981. // LATER: Gesture mouse events ignored for starting move
  41982. mxEvent.addListener(elt, 'dragstart', mxUtils.bind(this, function(evt)
  41983. {
  41984. this.graph.stopEditing(false);
  41985. mxEvent.consume(evt);
  41986. }));
  41987. // Applies value if focus is lost
  41988. mxEvent.addListener(elt, 'blur', mxUtils.bind(this, function(evt)
  41989. {
  41990. if (this.blurEnabled)
  41991. {
  41992. this.focusLost(evt);
  41993. }
  41994. }));
  41995. // Updates modified state and handles placeholder text
  41996. mxEvent.addListener(elt, 'keydown', mxUtils.bind(this, function(evt)
  41997. {
  41998. if (!mxEvent.isConsumed(evt))
  41999. {
  42000. if (this.isStopEditingEvent(evt))
  42001. {
  42002. this.graph.stopEditing(false);
  42003. mxEvent.consume(evt);
  42004. }
  42005. else if (evt.keyCode == 27 /* Escape */)
  42006. {
  42007. this.graph.stopEditing(this.isCancelEditingKeyEvent(evt));
  42008. mxEvent.consume(evt);
  42009. }
  42010. }
  42011. }));
  42012. // Keypress only fires if printable key was pressed and handles removing the empty placeholder
  42013. var keypressHandler = mxUtils.bind(this, function(evt)
  42014. {
  42015. if (this.editingCell != null)
  42016. {
  42017. // Clears the initial empty label on the first keystroke
  42018. // and workaround for FF which fires keypress for delete and backspace
  42019. if (this.clearOnChange && elt.innerHTML == this.getEmptyLabelText() &&
  42020. (!mxClient.IS_FF || (evt.keyCode != 8 /* Backspace */ && evt.keyCode != 46 /* Delete */)))
  42021. {
  42022. this.clearOnChange = false;
  42023. elt.innerHTML = '';
  42024. }
  42025. }
  42026. });
  42027. mxEvent.addListener(elt, 'keypress', keypressHandler);
  42028. mxEvent.addListener(elt, 'paste', keypressHandler);
  42029. // Handler for updating the empty label text value after a change
  42030. var keyupHandler = mxUtils.bind(this, function(evt)
  42031. {
  42032. if (this.editingCell != null)
  42033. {
  42034. // Uses an optional text value for sempty labels which is cleared
  42035. // when the first keystroke appears. This makes it easier to see
  42036. // that a label is being edited even if the label is empty.
  42037. // In Safari and FF, an empty text is represented by <BR> which isn't enough to force a valid size
  42038. if (this.textarea.innerHTML.length == 0 || this.textarea.innerHTML == '<br>')
  42039. {
  42040. this.textarea.innerHTML = this.getEmptyLabelText();
  42041. this.clearOnChange = this.textarea.innerHTML.length > 0;
  42042. }
  42043. else
  42044. {
  42045. this.clearOnChange = false;
  42046. }
  42047. }
  42048. });
  42049. mxEvent.addListener(elt, (!mxClient.IS_IE11 && !mxClient.IS_IE) ? 'input' : 'keyup', keyupHandler);
  42050. mxEvent.addListener(elt, 'cut', keyupHandler);
  42051. mxEvent.addListener(elt, 'paste', keyupHandler);
  42052. // Adds automatic resizing of the textbox while typing using input, keyup and/or DOM change events
  42053. var evtName = (!mxClient.IS_IE11 && !mxClient.IS_IE) ? 'input' : 'keydown';
  42054. var resizeHandler = mxUtils.bind(this, function(evt)
  42055. {
  42056. if (this.editingCell != null && this.autoSize && !mxEvent.isConsumed(evt))
  42057. {
  42058. // Asynchronous is needed for keydown and shows better results for input events overall
  42059. // (ie non-blocking and cases where the offsetWidth/-Height was wrong at this time)
  42060. if (this.resizeThread != null)
  42061. {
  42062. window.clearTimeout(this.resizeThread);
  42063. }
  42064. this.resizeThread = window.setTimeout(mxUtils.bind(this, function()
  42065. {
  42066. this.resizeThread = null;
  42067. this.resize();
  42068. }), 0);
  42069. }
  42070. });
  42071. mxEvent.addListener(elt, evtName, resizeHandler);
  42072. mxEvent.addListener(window, 'resize', resizeHandler);
  42073. if (document.documentMode >= 9)
  42074. {
  42075. mxEvent.addListener(elt, 'DOMNodeRemoved', resizeHandler);
  42076. mxEvent.addListener(elt, 'DOMNodeInserted', resizeHandler);
  42077. }
  42078. else
  42079. {
  42080. mxEvent.addListener(elt, 'cut', resizeHandler);
  42081. mxEvent.addListener(elt, 'paste', resizeHandler);
  42082. }
  42083. };
  42084. /**
  42085. * Function: isStopEditingEvent
  42086. *
  42087. * Returns true if the given keydown event should stop cell editing. This
  42088. * returns true if F2 is pressed of if <mxGraph.enterStopsCellEditing> is true
  42089. * and enter is pressed without control or shift.
  42090. */
  42091. mxCellEditor.prototype.isStopEditingEvent = function(evt)
  42092. {
  42093. return evt.keyCode == 113 /* F2 */ || (this.graph.isEnterStopsCellEditing() &&
  42094. evt.keyCode == 13 /* Enter */ && !mxEvent.isControlDown(evt) &&
  42095. !mxEvent.isShiftDown(evt));
  42096. };
  42097. /**
  42098. * Function: isEventSource
  42099. *
  42100. * Returns true if this editor is the source for the given native event.
  42101. */
  42102. mxCellEditor.prototype.isEventSource = function(evt)
  42103. {
  42104. return mxEvent.getSource(evt) == this.textarea;
  42105. };
  42106. /**
  42107. * Function: resize
  42108. *
  42109. * Returns <modified>.
  42110. */
  42111. mxCellEditor.prototype.resize = function()
  42112. {
  42113. var state = this.graph.getView().getState(this.editingCell);
  42114. if (state == null)
  42115. {
  42116. this.stopEditing(true);
  42117. }
  42118. else if (this.textarea != null)
  42119. {
  42120. var isEdge = this.graph.getModel().isEdge(state.cell);
  42121. var scale = this.graph.getView().scale;
  42122. var m = null;
  42123. if (!this.autoSize || (state.style[mxConstants.STYLE_OVERFLOW] == 'fill'))
  42124. {
  42125. // Specifies the bounds of the editor box
  42126. this.bounds = this.getEditorBounds(state);
  42127. this.textarea.style.width = Math.round(this.bounds.width / scale) + 'px';
  42128. this.textarea.style.height = Math.round(this.bounds.height / scale) + 'px';
  42129. // FIXME: Offset when scaled
  42130. if (document.documentMode == 8 || mxClient.IS_QUIRKS)
  42131. {
  42132. this.textarea.style.left = Math.round(this.bounds.x) + 'px';
  42133. this.textarea.style.top = Math.round(this.bounds.y) + 'px';
  42134. }
  42135. else
  42136. {
  42137. this.textarea.style.left = Math.max(0, Math.round(this.bounds.x + 1)) + 'px';
  42138. this.textarea.style.top = Math.max(0, Math.round(this.bounds.y + 1)) + 'px';
  42139. }
  42140. // Installs native word wrapping and avoids word wrap for empty label placeholder
  42141. if (this.graph.isWrapping(state.cell) && (this.bounds.width >= 2 || this.bounds.height >= 2) &&
  42142. this.textarea.innerHTML != this.getEmptyLabelText())
  42143. {
  42144. this.textarea.style.wordWrap = mxConstants.WORD_WRAP;
  42145. this.textarea.style.whiteSpace = 'normal';
  42146. if (state.style[mxConstants.STYLE_OVERFLOW] != 'fill')
  42147. {
  42148. this.textarea.style.width = Math.round(this.bounds.width / scale) + this.wordWrapPadding + 'px';
  42149. }
  42150. }
  42151. else
  42152. {
  42153. this.textarea.style.whiteSpace = 'nowrap';
  42154. if (state.style[mxConstants.STYLE_OVERFLOW] != 'fill')
  42155. {
  42156. this.textarea.style.width = '';
  42157. }
  42158. }
  42159. }
  42160. else
  42161. {
  42162. var lw = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_WIDTH, null);
  42163. m = (state.text != null && this.align == null) ? state.text.margin : null;
  42164. if (m == null)
  42165. {
  42166. m = mxUtils.getAlignmentAsPoint(this.align || mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER),
  42167. mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE));
  42168. }
  42169. if (isEdge)
  42170. {
  42171. this.bounds = new mxRectangle(state.absoluteOffset.x, state.absoluteOffset.y, 0, 0);
  42172. if (lw != null)
  42173. {
  42174. var tmp = (parseFloat(lw) + 2) * scale;
  42175. this.bounds.width = tmp;
  42176. this.bounds.x += m.x * tmp;
  42177. }
  42178. }
  42179. else
  42180. {
  42181. var bds = mxRectangle.fromRectangle(state);
  42182. var hpos = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  42183. var vpos = mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  42184. bds = (state.shape != null && hpos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_MIDDLE) ? state.shape.getLabelBounds(bds) : bds;
  42185. if (lw != null)
  42186. {
  42187. bds.width = parseFloat(lw) * scale;
  42188. }
  42189. if (!state.view.graph.cellRenderer.legacySpacing || state.style[mxConstants.STYLE_OVERFLOW] != 'width')
  42190. {
  42191. var spacing = parseInt(state.style[mxConstants.STYLE_SPACING] || 2) * scale;
  42192. var spacingTop = (parseInt(state.style[mxConstants.STYLE_SPACING_TOP] || 0) + mxText.prototype.baseSpacingTop) * scale + spacing;
  42193. var spacingRight = (parseInt(state.style[mxConstants.STYLE_SPACING_RIGHT] || 0) + mxText.prototype.baseSpacingRight) * scale + spacing;
  42194. var spacingBottom = (parseInt(state.style[mxConstants.STYLE_SPACING_BOTTOM] || 0) + mxText.prototype.baseSpacingBottom) * scale + spacing;
  42195. var spacingLeft = (parseInt(state.style[mxConstants.STYLE_SPACING_LEFT] || 0) + mxText.prototype.baseSpacingLeft) * scale + spacing;
  42196. var hpos = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  42197. var vpos = mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  42198. bds = new mxRectangle(bds.x + spacingLeft, bds.y + spacingTop,
  42199. bds.width - ((hpos == mxConstants.ALIGN_CENTER && lw == null) ? (spacingLeft + spacingRight) : 0),
  42200. bds.height - ((vpos == mxConstants.ALIGN_MIDDLE) ? (spacingTop + spacingBottom) : 0));
  42201. }
  42202. this.bounds = new mxRectangle(bds.x + state.absoluteOffset.x, bds.y + state.absoluteOffset.y, bds.width, bds.height);
  42203. }
  42204. // Needed for word wrap inside text blocks with oversize lines to match the final result where
  42205. // the width of the longest line is used as the reference for text alignment in the cell
  42206. // TODO: Fix word wrapping preview for edge labels in helloworld.html
  42207. if (this.graph.isWrapping(state.cell) && (this.bounds.width >= 2 || this.bounds.height >= 2) &&
  42208. this.textarea.innerHTML != this.getEmptyLabelText())
  42209. {
  42210. this.textarea.style.wordWrap = mxConstants.WORD_WRAP;
  42211. this.textarea.style.whiteSpace = 'normal';
  42212. // Forces automatic reflow if text is removed from an oversize label and normal word wrap
  42213. var tmp = Math.round(this.bounds.width / ((document.documentMode == 8) ? scale : scale)) + this.wordWrapPadding;
  42214. if (this.textarea.style.position != 'relative')
  42215. {
  42216. this.textarea.style.width = tmp + 'px';
  42217. if (this.textarea.scrollWidth > tmp)
  42218. {
  42219. this.textarea.style.width = this.textarea.scrollWidth + 'px';
  42220. }
  42221. }
  42222. else
  42223. {
  42224. this.textarea.style.maxWidth = tmp + 'px';
  42225. }
  42226. }
  42227. else
  42228. {
  42229. // KNOWN: Trailing cursor in IE9 quirks mode is not visible
  42230. this.textarea.style.whiteSpace = 'nowrap';
  42231. this.textarea.style.width = '';
  42232. }
  42233. // LATER: Keep in visible area, add fine tuning for pixel precision
  42234. // Workaround for wrong measuring in IE8 standards
  42235. if (document.documentMode == 8)
  42236. {
  42237. this.textarea.style.zoom = '1';
  42238. this.textarea.style.height = 'auto';
  42239. }
  42240. var ow = this.textarea.scrollWidth;
  42241. var oh = this.textarea.scrollHeight;
  42242. // TODO: Update CSS width and height if smaller than minResize or remove minResize
  42243. //if (this.minResize != null)
  42244. //{
  42245. // ow = Math.max(ow, this.minResize.width);
  42246. // oh = Math.max(oh, this.minResize.height);
  42247. //}
  42248. // LATER: Keep in visible area, add fine tuning for pixel precision
  42249. if (document.documentMode == 8)
  42250. {
  42251. // LATER: Scaled wrapping and position is wrong in IE8
  42252. this.textarea.style.left = Math.max(0, Math.ceil((this.bounds.x - m.x * (this.bounds.width - (ow + 1) * scale) + ow * (scale - 1) * 0 + (m.x + 0.5) * 2) / scale)) + 'px';
  42253. this.textarea.style.top = Math.max(0, Math.ceil((this.bounds.y - m.y * (this.bounds.height - (oh + 0.5) * scale) + oh * (scale - 1) * 0 + Math.abs(m.y + 0.5) * 1) / scale)) + 'px';
  42254. // Workaround for wrong event handling width and height
  42255. this.textarea.style.width = Math.round(ow * scale) + 'px';
  42256. this.textarea.style.height = Math.round(oh * scale) + 'px';
  42257. }
  42258. else if (mxClient.IS_QUIRKS)
  42259. {
  42260. this.textarea.style.left = Math.max(0, Math.ceil(this.bounds.x - m.x * (this.bounds.width - (ow + 1) * scale) + ow * (scale - 1) * 0 + (m.x + 0.5) * 2)) + 'px';
  42261. this.textarea.style.top = Math.max(0, Math.ceil(this.bounds.y - m.y * (this.bounds.height - (oh + 0.5) * scale) + oh * (scale - 1) * 0 + Math.abs(m.y + 0.5) * 1)) + 'px';
  42262. }
  42263. else
  42264. {
  42265. this.textarea.style.left = Math.max(0, Math.round(this.bounds.x - m.x * (this.bounds.width - 2)) + 1) + 'px';
  42266. this.textarea.style.top = Math.max(0, Math.round(this.bounds.y - m.y * (this.bounds.height - 4) + ((m.y == -1) ? 3 : 0)) + 1) + 'px';
  42267. }
  42268. }
  42269. if (mxClient.IS_VML)
  42270. {
  42271. this.textarea.style.zoom = scale;
  42272. }
  42273. else
  42274. {
  42275. mxUtils.setPrefixedStyle(this.textarea.style, 'transformOrigin', '0px 0px');
  42276. mxUtils.setPrefixedStyle(this.textarea.style, 'transform',
  42277. 'scale(' + scale + ',' + scale + ')' + ((m == null) ? '' :
  42278. ' translate(' + (m.x * 100) + '%,' + (m.y * 100) + '%)'));
  42279. }
  42280. }
  42281. };
  42282. /**
  42283. * Function: focusLost
  42284. *
  42285. * Called if the textarea has lost focus.
  42286. */
  42287. mxCellEditor.prototype.focusLost = function()
  42288. {
  42289. this.stopEditing(!this.graph.isInvokesStopCellEditing());
  42290. };
  42291. /**
  42292. * Function: getBackgroundColor
  42293. *
  42294. * Returns the background color for the in-place editor. This implementation
  42295. * always returns null.
  42296. */
  42297. mxCellEditor.prototype.getBackgroundColor = function(state)
  42298. {
  42299. return null;
  42300. };
  42301. /**
  42302. * Function: isLegacyEditor
  42303. *
  42304. * Returns true if max-width is not supported or if the SVG root element in
  42305. * in the graph does not have CSS position absolute. In these cases the text
  42306. * editor must use CSS position absolute to avoid an offset but it will have
  42307. * a less accurate line wrapping width during the text editing preview. This
  42308. * implementation returns true for IE8- and quirks mode or if the CSS position
  42309. * of the SVG element is not absolute.
  42310. */
  42311. mxCellEditor.prototype.isLegacyEditor = function()
  42312. {
  42313. if (mxClient.IS_VML)
  42314. {
  42315. return true;
  42316. }
  42317. else
  42318. {
  42319. var absoluteRoot = false;
  42320. if (mxClient.IS_SVG)
  42321. {
  42322. var root = this.graph.view.getDrawPane().ownerSVGElement;
  42323. if (root != null)
  42324. {
  42325. var css = mxUtils.getCurrentStyle(root);
  42326. if (css != null)
  42327. {
  42328. absoluteRoot = css.position == 'absolute';
  42329. }
  42330. }
  42331. }
  42332. return !absoluteRoot;
  42333. }
  42334. };
  42335. /**
  42336. * Function: startEditing
  42337. *
  42338. * Starts the editor for the given cell.
  42339. *
  42340. * Parameters:
  42341. *
  42342. * cell - <mxCell> to start editing.
  42343. * trigger - Optional mouse event that triggered the editor.
  42344. */
  42345. mxCellEditor.prototype.startEditing = function(cell, trigger)
  42346. {
  42347. this.stopEditing(true);
  42348. this.align = null;
  42349. // Creates new textarea instance
  42350. if (this.textarea == null)
  42351. {
  42352. this.init();
  42353. }
  42354. if (this.graph.tooltipHandler != null)
  42355. {
  42356. this.graph.tooltipHandler.hideTooltip();
  42357. }
  42358. var state = this.graph.getView().getState(cell);
  42359. if (state != null)
  42360. {
  42361. // Configures the style of the in-place editor
  42362. var scale = this.graph.getView().scale;
  42363. var size = mxUtils.getValue(state.style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  42364. var family = mxUtils.getValue(state.style, mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY);
  42365. var color = mxUtils.getValue(state.style, mxConstants.STYLE_FONTCOLOR, 'black');
  42366. var align = mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_LEFT);
  42367. var bold = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  42368. mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD;
  42369. var italic = (mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  42370. mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC;
  42371. var txtDecor = [];
  42372. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  42373. mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  42374. {
  42375. txtDecor.push('underline');
  42376. }
  42377. if ((mxUtils.getValue(state.style, mxConstants.STYLE_FONTSTYLE, 0) &
  42378. mxConstants.FONT_STRIKETHROUGH) == mxConstants.FONT_STRIKETHROUGH)
  42379. {
  42380. txtDecor.push('line-through');
  42381. }
  42382. this.textarea.style.lineHeight = (mxConstants.ABSOLUTE_LINE_HEIGHT) ? Math.round(size * mxConstants.LINE_HEIGHT) + 'px' : mxConstants.LINE_HEIGHT;
  42383. this.textarea.style.backgroundColor = this.getBackgroundColor(state);
  42384. this.textarea.style.textDecoration = txtDecor.join(' ');
  42385. this.textarea.style.fontWeight = (bold) ? 'bold' : 'normal';
  42386. this.textarea.style.fontStyle = (italic) ? 'italic' : '';
  42387. this.textarea.style.fontSize = Math.round(size) + 'px';
  42388. this.textarea.style.zIndex = this.zIndex;
  42389. this.textarea.style.fontFamily = family;
  42390. this.textarea.style.textAlign = align;
  42391. this.textarea.style.outline = 'none';
  42392. this.textarea.style.color = color;
  42393. var dir = this.textDirection = mxUtils.getValue(state.style, mxConstants.STYLE_TEXT_DIRECTION, mxConstants.DEFAULT_TEXT_DIRECTION);
  42394. if (dir == mxConstants.TEXT_DIRECTION_AUTO)
  42395. {
  42396. if (state != null && state.text != null && state.text.dialect != mxConstants.DIALECT_STRICTHTML &&
  42397. !mxUtils.isNode(state.text.value))
  42398. {
  42399. dir = state.text.getAutoDirection();
  42400. }
  42401. }
  42402. if (dir == mxConstants.TEXT_DIRECTION_LTR || dir == mxConstants.TEXT_DIRECTION_RTL)
  42403. {
  42404. this.textarea.setAttribute('dir', dir);
  42405. }
  42406. else
  42407. {
  42408. this.textarea.removeAttribute('dir');
  42409. }
  42410. // Sets the initial editing value
  42411. this.textarea.innerHTML = this.getInitialValue(state, trigger) || '';
  42412. this.initialValue = this.textarea.innerHTML;
  42413. // Uses an optional text value for empty labels which is cleared
  42414. // when the first keystroke appears. This makes it easier to see
  42415. // that a label is being edited even if the label is empty.
  42416. if (this.textarea.innerHTML.length == 0 || this.textarea.innerHTML == '<br>')
  42417. {
  42418. this.textarea.innerHTML = this.getEmptyLabelText();
  42419. this.clearOnChange = true;
  42420. }
  42421. else
  42422. {
  42423. this.clearOnChange = this.textarea.innerHTML == this.getEmptyLabelText();
  42424. }
  42425. this.graph.container.appendChild(this.textarea);
  42426. // Update this after firing all potential events that could update the cleanOnChange flag
  42427. this.editingCell = cell;
  42428. this.trigger = trigger;
  42429. this.textNode = null;
  42430. if (state.text != null && this.isHideLabel(state))
  42431. {
  42432. this.textNode = state.text.node;
  42433. this.textNode.style.visibility = 'hidden';
  42434. }
  42435. // Workaround for initial offsetHeight not ready for heading in markup
  42436. if (this.autoSize && (this.graph.model.isEdge(state.cell) || state.style[mxConstants.STYLE_OVERFLOW] != 'fill'))
  42437. {
  42438. window.setTimeout(mxUtils.bind(this, function()
  42439. {
  42440. this.resize();
  42441. }), 0);
  42442. }
  42443. this.resize();
  42444. // Workaround for NS_ERROR_FAILURE in FF
  42445. try
  42446. {
  42447. // Prefers blinking cursor over no selected text if empty
  42448. this.textarea.focus();
  42449. if (this.isSelectText() && this.textarea.innerHTML.length > 0 &&
  42450. (this.textarea.innerHTML != this.getEmptyLabelText() || !this.clearOnChange))
  42451. {
  42452. document.execCommand('selectAll', false, null);
  42453. }
  42454. }
  42455. catch (e)
  42456. {
  42457. // ignore
  42458. }
  42459. }
  42460. };
  42461. /**
  42462. * Function: isSelectText
  42463. *
  42464. * Returns <selectText>.
  42465. */
  42466. mxCellEditor.prototype.isSelectText = function()
  42467. {
  42468. return this.selectText;
  42469. };
  42470. /**
  42471. * Function: isSelectText
  42472. *
  42473. * Returns <selectText>.
  42474. */
  42475. mxCellEditor.prototype.clearSelection = function()
  42476. {
  42477. var selection = null;
  42478. if (window.getSelection)
  42479. {
  42480. selection = window.getSelection();
  42481. }
  42482. else if (document.selection)
  42483. {
  42484. selection = document.selection;
  42485. }
  42486. if (selection != null)
  42487. {
  42488. if (selection.empty)
  42489. {
  42490. selection.empty();
  42491. }
  42492. else if (selection.removeAllRanges)
  42493. {
  42494. selection.removeAllRanges();
  42495. }
  42496. }
  42497. };
  42498. /**
  42499. * Function: stopEditing
  42500. *
  42501. * Stops the editor and applies the value if cancel is false.
  42502. */
  42503. mxCellEditor.prototype.stopEditing = function(cancel)
  42504. {
  42505. cancel = cancel || false;
  42506. if (this.editingCell != null)
  42507. {
  42508. if (this.textNode != null)
  42509. {
  42510. this.textNode.style.visibility = 'visible';
  42511. this.textNode = null;
  42512. }
  42513. var state = (!cancel) ? this.graph.view.getState(this.editingCell) : null;
  42514. var initial = this.initialValue;
  42515. this.initialValue = null;
  42516. this.editingCell = null;
  42517. this.trigger = null;
  42518. this.bounds = null;
  42519. this.textarea.blur();
  42520. this.clearSelection();
  42521. if (this.textarea.parentNode != null)
  42522. {
  42523. this.textarea.parentNode.removeChild(this.textarea);
  42524. }
  42525. if (this.clearOnChange && this.textarea.innerHTML == this.getEmptyLabelText())
  42526. {
  42527. this.textarea.innerHTML = '';
  42528. this.clearOnChange = false;
  42529. }
  42530. if (state != null && (this.textarea.innerHTML != initial || this.align != null))
  42531. {
  42532. this.prepareTextarea();
  42533. var value = this.getCurrentValue(state);
  42534. this.graph.getModel().beginUpdate();
  42535. try
  42536. {
  42537. if (value != null)
  42538. {
  42539. this.applyValue(state, value);
  42540. }
  42541. if (this.align != null)
  42542. {
  42543. this.graph.setCellStyles(mxConstants.STYLE_ALIGN, this.align, [state.cell]);
  42544. }
  42545. }
  42546. finally
  42547. {
  42548. this.graph.getModel().endUpdate();
  42549. }
  42550. }
  42551. // Forces new instance on next edit for undo history reset
  42552. mxEvent.release(this.textarea);
  42553. this.textarea = null;
  42554. this.align = null;
  42555. }
  42556. };
  42557. /**
  42558. * Function: prepareTextarea
  42559. *
  42560. * Prepares the textarea for getting its value in <stopEditing>.
  42561. * This implementation removes the extra trailing linefeed in Firefox.
  42562. */
  42563. mxCellEditor.prototype.prepareTextarea = function()
  42564. {
  42565. if (this.textarea.lastChild != null &&
  42566. this.textarea.lastChild.nodeName == 'BR')
  42567. {
  42568. this.textarea.removeChild(this.textarea.lastChild);
  42569. }
  42570. };
  42571. /**
  42572. * Function: isHideLabel
  42573. *
  42574. * Returns true if the label should be hidden while the cell is being
  42575. * edited.
  42576. */
  42577. mxCellEditor.prototype.isHideLabel = function(state)
  42578. {
  42579. return true;
  42580. };
  42581. /**
  42582. * Function: getMinimumSize
  42583. *
  42584. * Returns the minimum width and height for editing the given state.
  42585. */
  42586. mxCellEditor.prototype.getMinimumSize = function(state)
  42587. {
  42588. var scale = this.graph.getView().scale;
  42589. return new mxRectangle(0, 0, (state.text == null) ? 30 : state.text.size * scale + 20,
  42590. (this.textarea.style.textAlign == 'left') ? 120 : 40);
  42591. };
  42592. /**
  42593. * Function: getEditorBounds
  42594. *
  42595. * Returns the <mxRectangle> that defines the bounds of the editor.
  42596. */
  42597. mxCellEditor.prototype.getEditorBounds = function(state)
  42598. {
  42599. var isEdge = this.graph.getModel().isEdge(state.cell);
  42600. var scale = this.graph.getView().scale;
  42601. var minSize = this.getMinimumSize(state);
  42602. var minWidth = minSize.width;
  42603. var minHeight = minSize.height;
  42604. var result = null;
  42605. if (!isEdge && state.view.graph.cellRenderer.legacySpacing && state.style[mxConstants.STYLE_OVERFLOW] == 'fill')
  42606. {
  42607. result = state.shape.getLabelBounds(mxRectangle.fromRectangle(state));
  42608. }
  42609. else
  42610. {
  42611. var spacing = parseInt(state.style[mxConstants.STYLE_SPACING] || 0) * scale;
  42612. var spacingTop = (parseInt(state.style[mxConstants.STYLE_SPACING_TOP] || 0) + mxText.prototype.baseSpacingTop) * scale + spacing;
  42613. var spacingRight = (parseInt(state.style[mxConstants.STYLE_SPACING_RIGHT] || 0) + mxText.prototype.baseSpacingRight) * scale + spacing;
  42614. var spacingBottom = (parseInt(state.style[mxConstants.STYLE_SPACING_BOTTOM] || 0) + mxText.prototype.baseSpacingBottom) * scale + spacing;
  42615. var spacingLeft = (parseInt(state.style[mxConstants.STYLE_SPACING_LEFT] || 0) + mxText.prototype.baseSpacingLeft) * scale + spacing;
  42616. result = new mxRectangle(state.x, state.y,
  42617. Math.max(minWidth, state.width - spacingLeft - spacingRight),
  42618. Math.max(minHeight, state.height - spacingTop - spacingBottom));
  42619. var hpos = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  42620. var vpos = mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  42621. result = (state.shape != null && hpos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_MIDDLE) ? state.shape.getLabelBounds(result) : result;
  42622. if (isEdge)
  42623. {
  42624. result.x = state.absoluteOffset.x;
  42625. result.y = state.absoluteOffset.y;
  42626. if (state.text != null && state.text.boundingBox != null)
  42627. {
  42628. // Workaround for label containing just spaces in which case
  42629. // the bounding box location contains negative numbers
  42630. if (state.text.boundingBox.x > 0)
  42631. {
  42632. result.x = state.text.boundingBox.x;
  42633. }
  42634. if (state.text.boundingBox.y > 0)
  42635. {
  42636. result.y = state.text.boundingBox.y;
  42637. }
  42638. }
  42639. }
  42640. else if (state.text != null && state.text.boundingBox != null)
  42641. {
  42642. result.x = Math.min(result.x, state.text.boundingBox.x);
  42643. result.y = Math.min(result.y, state.text.boundingBox.y);
  42644. }
  42645. result.x += spacingLeft;
  42646. result.y += spacingTop;
  42647. if (state.text != null && state.text.boundingBox != null)
  42648. {
  42649. if (!isEdge)
  42650. {
  42651. result.width = Math.max(result.width, state.text.boundingBox.width);
  42652. result.height = Math.max(result.height, state.text.boundingBox.height);
  42653. }
  42654. else
  42655. {
  42656. result.width = Math.max(minWidth, state.text.boundingBox.width);
  42657. result.height = Math.max(minHeight, state.text.boundingBox.height);
  42658. }
  42659. }
  42660. // Applies the horizontal and vertical label positions
  42661. if (this.graph.getModel().isVertex(state.cell))
  42662. {
  42663. var horizontal = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  42664. if (horizontal == mxConstants.ALIGN_LEFT)
  42665. {
  42666. result.x -= state.width;
  42667. }
  42668. else if (horizontal == mxConstants.ALIGN_RIGHT)
  42669. {
  42670. result.x += state.width;
  42671. }
  42672. var vertical = mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  42673. if (vertical == mxConstants.ALIGN_TOP)
  42674. {
  42675. result.y -= state.height;
  42676. }
  42677. else if (vertical == mxConstants.ALIGN_BOTTOM)
  42678. {
  42679. result.y += state.height;
  42680. }
  42681. }
  42682. }
  42683. return new mxRectangle(Math.round(result.x), Math.round(result.y), Math.round(result.width), Math.round(result.height));
  42684. };
  42685. /**
  42686. * Function: getEmptyLabelText
  42687. *
  42688. * Returns the initial label value to be used of the label of the given
  42689. * cell is empty. This label is displayed and cleared on the first keystroke.
  42690. * This implementation returns <emptyLabelText>.
  42691. *
  42692. * Parameters:
  42693. *
  42694. * cell - <mxCell> for which a text for an empty editing box should be
  42695. * returned.
  42696. */
  42697. mxCellEditor.prototype.getEmptyLabelText = function (cell)
  42698. {
  42699. return this.emptyLabelText;
  42700. };
  42701. /**
  42702. * Function: getEditingCell
  42703. *
  42704. * Returns the cell that is currently being edited or null if no cell is
  42705. * being edited.
  42706. */
  42707. mxCellEditor.prototype.getEditingCell = function ()
  42708. {
  42709. return this.editingCell;
  42710. };
  42711. /**
  42712. * Function: destroy
  42713. *
  42714. * Destroys the editor and removes all associated resources.
  42715. */
  42716. mxCellEditor.prototype.destroy = function ()
  42717. {
  42718. if (this.textarea != null)
  42719. {
  42720. mxEvent.release(this.textarea);
  42721. if (this.textarea.parentNode != null)
  42722. {
  42723. this.textarea.parentNode.removeChild(this.textarea);
  42724. }
  42725. this.textarea = null;
  42726. }
  42727. if (this.changeHandler != null)
  42728. {
  42729. this.graph.getModel().removeListener(this.changeHandler);
  42730. this.changeHandler = null;
  42731. }
  42732. if (this.zoomHandler)
  42733. {
  42734. this.graph.view.removeListener(this.zoomHandler);
  42735. this.zoomHandler = null;
  42736. }
  42737. };
  42738. /**
  42739. * Copyright (c) 2006-2017, JGraph Ltd
  42740. * Copyright (c) 2006-2017, Gaudenz Alder
  42741. */
  42742. /**
  42743. * Class: mxCellRenderer
  42744. *
  42745. * Renders cells into a document object model. The <defaultShapes> is a global
  42746. * map of shapename, constructor pairs that is used in all instances. You can
  42747. * get a list of all available shape names using the following code.
  42748. *
  42749. * In general the cell renderer is in charge of creating, redrawing and
  42750. * destroying the shape and label associated with a cell state, as well as
  42751. * some other graphical objects, namely controls and overlays. The shape
  42752. * hieararchy in the display (ie. the hierarchy in which the DOM nodes
  42753. * appear in the document) does not reflect the cell hierarchy. The shapes
  42754. * are a (flat) sequence of shapes and labels inside the draw pane of the
  42755. * graph view, with some exceptions, namely the HTML labels being placed
  42756. * directly inside the graph container for certain browsers.
  42757. *
  42758. * (code)
  42759. * mxLog.show();
  42760. * for (var i in mxCellRenderer.defaultShapes)
  42761. * {
  42762. * mxLog.debug(i);
  42763. * }
  42764. * (end)
  42765. *
  42766. * Constructor: mxCellRenderer
  42767. *
  42768. * Constructs a new cell renderer with the following built-in shapes:
  42769. * arrow, rectangle, ellipse, rhombus, image, line, label, cylinder,
  42770. * swimlane, connector, actor and cloud.
  42771. */
  42772. function mxCellRenderer() { };
  42773. /**
  42774. * Variable: defaultShapes
  42775. *
  42776. * Static array that contains the globally registered shapes which are
  42777. * known to all instances of this class. For adding new shapes you should
  42778. * use the static <mxCellRenderer.registerShape> function.
  42779. */
  42780. mxCellRenderer.defaultShapes = new Object();
  42781. /**
  42782. * Variable: defaultEdgeShape
  42783. *
  42784. * Defines the default shape for edges. Default is <mxConnector>.
  42785. */
  42786. mxCellRenderer.prototype.defaultEdgeShape = mxConnector;
  42787. /**
  42788. * Variable: defaultVertexShape
  42789. *
  42790. * Defines the default shape for vertices. Default is <mxRectangleShape>.
  42791. */
  42792. mxCellRenderer.prototype.defaultVertexShape = mxRectangleShape;
  42793. /**
  42794. * Variable: defaultTextShape
  42795. *
  42796. * Defines the default shape for labels. Default is <mxText>.
  42797. */
  42798. mxCellRenderer.prototype.defaultTextShape = mxText;
  42799. /**
  42800. * Variable: legacyControlPosition
  42801. *
  42802. * Specifies if the folding icon should ignore the horizontal
  42803. * orientation of a swimlane. Default is true.
  42804. */
  42805. mxCellRenderer.prototype.legacyControlPosition = true;
  42806. /**
  42807. * Variable: legacySpacing
  42808. *
  42809. * Specifies if spacing and label position should be ignored if overflow is
  42810. * fill or width. Default is true for backwards compatiblity.
  42811. */
  42812. mxCellRenderer.prototype.legacySpacing = true;
  42813. /**
  42814. * Variable: antiAlias
  42815. *
  42816. * Anti-aliasing option for new shapes. Default is true.
  42817. */
  42818. mxCellRenderer.prototype.antiAlias = true;
  42819. /**
  42820. * Variable: minSvgStrokeWidth
  42821. *
  42822. * Minimum stroke width for SVG output.
  42823. */
  42824. mxCellRenderer.prototype.minSvgStrokeWidth = 1;
  42825. /**
  42826. * Variable: forceControlClickHandler
  42827. *
  42828. * Specifies if the enabled state of the graph should be ignored in the control
  42829. * click handler (to allow folding in disabled graphs). Default is false.
  42830. */
  42831. mxCellRenderer.prototype.forceControlClickHandler = false;
  42832. /**
  42833. * Function: registerShape
  42834. *
  42835. * Registers the given constructor under the specified key in this instance
  42836. * of the renderer.
  42837. *
  42838. * Example:
  42839. *
  42840. * (code)
  42841. * mxCellRenderer.registerShape(mxConstants.SHAPE_RECTANGLE, mxRectangleShape);
  42842. * (end)
  42843. *
  42844. * Parameters:
  42845. *
  42846. * key - String representing the shape name.
  42847. * shape - Constructor of the <mxShape> subclass.
  42848. */
  42849. mxCellRenderer.registerShape = function(key, shape)
  42850. {
  42851. mxCellRenderer.defaultShapes[key] = shape;
  42852. };
  42853. // Adds default shapes into the default shapes array
  42854. mxCellRenderer.registerShape(mxConstants.SHAPE_RECTANGLE, mxRectangleShape);
  42855. mxCellRenderer.registerShape(mxConstants.SHAPE_ELLIPSE, mxEllipse);
  42856. mxCellRenderer.registerShape(mxConstants.SHAPE_RHOMBUS, mxRhombus);
  42857. mxCellRenderer.registerShape(mxConstants.SHAPE_CYLINDER, mxCylinder);
  42858. mxCellRenderer.registerShape(mxConstants.SHAPE_CONNECTOR, mxConnector);
  42859. mxCellRenderer.registerShape(mxConstants.SHAPE_ACTOR, mxActor);
  42860. mxCellRenderer.registerShape(mxConstants.SHAPE_TRIANGLE, mxTriangle);
  42861. mxCellRenderer.registerShape(mxConstants.SHAPE_HEXAGON, mxHexagon);
  42862. mxCellRenderer.registerShape(mxConstants.SHAPE_CLOUD, mxCloud);
  42863. mxCellRenderer.registerShape(mxConstants.SHAPE_LINE, mxLine);
  42864. mxCellRenderer.registerShape(mxConstants.SHAPE_ARROW, mxArrow);
  42865. mxCellRenderer.registerShape(mxConstants.SHAPE_ARROW_CONNECTOR, mxArrowConnector);
  42866. mxCellRenderer.registerShape(mxConstants.SHAPE_DOUBLE_ELLIPSE, mxDoubleEllipse);
  42867. mxCellRenderer.registerShape(mxConstants.SHAPE_SWIMLANE, mxSwimlane);
  42868. mxCellRenderer.registerShape(mxConstants.SHAPE_IMAGE, mxImageShape);
  42869. mxCellRenderer.registerShape(mxConstants.SHAPE_LABEL, mxLabel);
  42870. /**
  42871. * Function: initializeShape
  42872. *
  42873. * Initializes the shape in the given state by calling its init method with
  42874. * the correct container after configuring it using <configureShape>.
  42875. *
  42876. * Parameters:
  42877. *
  42878. * state - <mxCellState> for which the shape should be initialized.
  42879. */
  42880. mxCellRenderer.prototype.initializeShape = function(state)
  42881. {
  42882. state.shape.dialect = state.view.graph.dialect;
  42883. this.configureShape(state);
  42884. state.shape.init(state.view.getDrawPane());
  42885. };
  42886. /**
  42887. * Function: createShape
  42888. *
  42889. * Creates and returns the shape for the given cell state.
  42890. *
  42891. * Parameters:
  42892. *
  42893. * state - <mxCellState> for which the shape should be created.
  42894. */
  42895. mxCellRenderer.prototype.createShape = function(state)
  42896. {
  42897. var shape = null;
  42898. if (state.style != null)
  42899. {
  42900. // Checks if there is a stencil for the name and creates
  42901. // a shape instance for the stencil if one exists
  42902. var stencil = mxStencilRegistry.getStencil(state.style[mxConstants.STYLE_SHAPE]);
  42903. if (stencil != null)
  42904. {
  42905. shape = new mxShape(stencil);
  42906. }
  42907. else
  42908. {
  42909. var ctor = this.getShapeConstructor(state);
  42910. shape = new ctor();
  42911. }
  42912. }
  42913. return shape;
  42914. };
  42915. /**
  42916. * Function: createIndicatorShape
  42917. *
  42918. * Creates the indicator shape for the given cell state.
  42919. *
  42920. * Parameters:
  42921. *
  42922. * state - <mxCellState> for which the indicator shape should be created.
  42923. */
  42924. mxCellRenderer.prototype.createIndicatorShape = function(state)
  42925. {
  42926. state.shape.indicatorShape = this.getShape(state.view.graph.getIndicatorShape(state));
  42927. };
  42928. /**
  42929. * Function: getShape
  42930. *
  42931. * Returns the shape for the given name from <defaultShapes>.
  42932. */
  42933. mxCellRenderer.prototype.getShape = function(name)
  42934. {
  42935. return (name != null) ? mxCellRenderer.defaultShapes[name] : null;
  42936. };
  42937. /**
  42938. * Function: getShapeConstructor
  42939. *
  42940. * Returns the constructor to be used for creating the shape.
  42941. */
  42942. mxCellRenderer.prototype.getShapeConstructor = function(state)
  42943. {
  42944. var ctor = this.getShape(state.style[mxConstants.STYLE_SHAPE]);
  42945. if (ctor == null)
  42946. {
  42947. ctor = (state.view.graph.getModel().isEdge(state.cell)) ?
  42948. this.defaultEdgeShape : this.defaultVertexShape;
  42949. }
  42950. return ctor;
  42951. };
  42952. /**
  42953. * Function: configureShape
  42954. *
  42955. * Configures the shape for the given cell state.
  42956. *
  42957. * Parameters:
  42958. *
  42959. * state - <mxCellState> for which the shape should be configured.
  42960. */
  42961. mxCellRenderer.prototype.configureShape = function(state)
  42962. {
  42963. state.shape.apply(state);
  42964. state.shape.image = state.view.graph.getImage(state);
  42965. state.shape.indicatorColor = state.view.graph.getIndicatorColor(state);
  42966. state.shape.indicatorStrokeColor = state.style[mxConstants.STYLE_INDICATOR_STROKECOLOR];
  42967. state.shape.indicatorGradientColor = state.view.graph.getIndicatorGradientColor(state);
  42968. state.shape.indicatorDirection = state.style[mxConstants.STYLE_INDICATOR_DIRECTION];
  42969. state.shape.indicatorImage = state.view.graph.getIndicatorImage(state);
  42970. this.postConfigureShape(state);
  42971. };
  42972. /**
  42973. * Function: postConfigureShape
  42974. *
  42975. * Replaces any reserved words used for attributes, eg. inherit,
  42976. * indicated or swimlane for colors in the shape for the given state.
  42977. * This implementation resolves these keywords on the fill, stroke
  42978. * and gradient color keys.
  42979. */
  42980. mxCellRenderer.prototype.postConfigureShape = function(state)
  42981. {
  42982. if (state.shape != null)
  42983. {
  42984. this.resolveColor(state, 'indicatorGradientColor', mxConstants.STYLE_GRADIENTCOLOR);
  42985. this.resolveColor(state, 'indicatorColor', mxConstants.STYLE_FILLCOLOR);
  42986. this.resolveColor(state, 'gradient', mxConstants.STYLE_GRADIENTCOLOR);
  42987. this.resolveColor(state, 'stroke', mxConstants.STYLE_STROKECOLOR);
  42988. this.resolveColor(state, 'fill', mxConstants.STYLE_FILLCOLOR);
  42989. }
  42990. };
  42991. /**
  42992. * Function: checkPlaceholderStyles
  42993. *
  42994. * Checks if the style of the given <mxCellState> contains 'inherit',
  42995. * 'indicated' or 'swimlane' for colors that support those keywords.
  42996. */
  42997. mxCellRenderer.prototype.checkPlaceholderStyles = function(state)
  42998. {
  42999. // LATER: Check if the color has actually changed
  43000. if (state.style != null)
  43001. {
  43002. var values = ['inherit', 'swimlane', 'indicated'];
  43003. var styles = [mxConstants.STYLE_FILLCOLOR, mxConstants.STYLE_STROKECOLOR,
  43004. mxConstants.STYLE_GRADIENTCOLOR, mxConstants.STYLE_FONTCOLOR];
  43005. for (var i = 0; i < styles.length; i++)
  43006. {
  43007. if (mxUtils.indexOf(values, state.style[styles[i]]) >= 0)
  43008. {
  43009. return true;
  43010. }
  43011. }
  43012. }
  43013. return false;
  43014. };
  43015. /**
  43016. * Function: resolveColor
  43017. *
  43018. * Resolves special keywords 'inherit', 'indicated' and 'swimlane' and sets
  43019. * the respective color on the shape.
  43020. */
  43021. mxCellRenderer.prototype.resolveColor = function(state, field, key)
  43022. {
  43023. var shape = (key == mxConstants.STYLE_FONTCOLOR) ?
  43024. state.text : state.shape;
  43025. if (shape != null)
  43026. {
  43027. var graph = state.view.graph;
  43028. var value = shape[field];
  43029. var referenced = null;
  43030. if (value == 'inherit')
  43031. {
  43032. referenced = graph.model.getParent(state.cell);
  43033. }
  43034. else if (value == 'swimlane')
  43035. {
  43036. shape[field] = (key == mxConstants.STYLE_STROKECOLOR ||
  43037. key == mxConstants.STYLE_FONTCOLOR) ?
  43038. '#000000' : '#ffffff';
  43039. if (graph.model.getTerminal(state.cell, false) != null)
  43040. {
  43041. referenced = graph.model.getTerminal(state.cell, false);
  43042. }
  43043. else
  43044. {
  43045. referenced = state.cell;
  43046. }
  43047. referenced = graph.getSwimlane(referenced);
  43048. key = graph.swimlaneIndicatorColorAttribute;
  43049. }
  43050. else if (value == 'indicated' && state.shape != null)
  43051. {
  43052. shape[field] = state.shape.indicatorColor;
  43053. }
  43054. if (referenced != null)
  43055. {
  43056. var rstate = graph.getView().getState(referenced);
  43057. shape[field] = null;
  43058. if (rstate != null)
  43059. {
  43060. var rshape = (key == mxConstants.STYLE_FONTCOLOR) ? rstate.text : rstate.shape;
  43061. if (rshape != null && field != 'indicatorColor')
  43062. {
  43063. shape[field] = rshape[field];
  43064. }
  43065. else
  43066. {
  43067. shape[field] = rstate.style[key];
  43068. }
  43069. }
  43070. }
  43071. }
  43072. };
  43073. /**
  43074. * Function: getLabelValue
  43075. *
  43076. * Returns the value to be used for the label.
  43077. *
  43078. * Parameters:
  43079. *
  43080. * state - <mxCellState> for which the label should be created.
  43081. */
  43082. mxCellRenderer.prototype.getLabelValue = function(state)
  43083. {
  43084. return state.view.graph.getLabel(state.cell);
  43085. };
  43086. /**
  43087. * Function: createLabel
  43088. *
  43089. * Creates the label for the given cell state.
  43090. *
  43091. * Parameters:
  43092. *
  43093. * state - <mxCellState> for which the label should be created.
  43094. */
  43095. mxCellRenderer.prototype.createLabel = function(state, value)
  43096. {
  43097. var graph = state.view.graph;
  43098. var isEdge = graph.getModel().isEdge(state.cell);
  43099. if (state.style[mxConstants.STYLE_FONTSIZE] > 0 || state.style[mxConstants.STYLE_FONTSIZE] == null)
  43100. {
  43101. // Avoids using DOM node for empty labels
  43102. var isForceHtml = (graph.isHtmlLabel(state.cell) || (value != null && mxUtils.isNode(value)));
  43103. state.text = new this.defaultTextShape(value, new mxRectangle(),
  43104. (state.style[mxConstants.STYLE_ALIGN] || mxConstants.ALIGN_CENTER),
  43105. graph.getVerticalAlign(state),
  43106. state.style[mxConstants.STYLE_FONTCOLOR],
  43107. state.style[mxConstants.STYLE_FONTFAMILY],
  43108. state.style[mxConstants.STYLE_FONTSIZE],
  43109. state.style[mxConstants.STYLE_FONTSTYLE],
  43110. state.style[mxConstants.STYLE_SPACING],
  43111. state.style[mxConstants.STYLE_SPACING_TOP],
  43112. state.style[mxConstants.STYLE_SPACING_RIGHT],
  43113. state.style[mxConstants.STYLE_SPACING_BOTTOM],
  43114. state.style[mxConstants.STYLE_SPACING_LEFT],
  43115. state.style[mxConstants.STYLE_HORIZONTAL],
  43116. state.style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR],
  43117. state.style[mxConstants.STYLE_LABEL_BORDERCOLOR],
  43118. graph.isWrapping(state.cell) && graph.isHtmlLabel(state.cell),
  43119. graph.isLabelClipped(state.cell),
  43120. state.style[mxConstants.STYLE_OVERFLOW],
  43121. state.style[mxConstants.STYLE_LABEL_PADDING],
  43122. mxUtils.getValue(state.style, mxConstants.STYLE_TEXT_DIRECTION, mxConstants.DEFAULT_TEXT_DIRECTION));
  43123. state.text.opacity = mxUtils.getValue(state.style, mxConstants.STYLE_TEXT_OPACITY, 100);
  43124. state.text.dialect = (isForceHtml) ? mxConstants.DIALECT_STRICTHTML : state.view.graph.dialect;
  43125. state.text.style = state.style;
  43126. state.text.state = state;
  43127. this.initializeLabel(state, state.text);
  43128. // Workaround for touch devices routing all events for a mouse gesture
  43129. // (down, move, up) via the initial DOM node. IE additionally redirects
  43130. // the event via the initial DOM node but the event source is the node
  43131. // under the mouse, so we need to check if this is the case and force
  43132. // getCellAt for the subsequent mouseMoves and the final mouseUp.
  43133. var forceGetCell = false;
  43134. var getState = function(evt)
  43135. {
  43136. var result = state;
  43137. if (mxClient.IS_TOUCH || forceGetCell)
  43138. {
  43139. var x = mxEvent.getClientX(evt);
  43140. var y = mxEvent.getClientY(evt);
  43141. // Dispatches the drop event to the graph which
  43142. // consumes and executes the source function
  43143. var pt = mxUtils.convertPoint(graph.container, x, y);
  43144. result = graph.view.getState(graph.getCellAt(pt.x, pt.y));
  43145. }
  43146. return result;
  43147. };
  43148. // TODO: Add handling for special touch device gestures
  43149. mxEvent.addGestureListeners(state.text.node,
  43150. mxUtils.bind(this, function(evt)
  43151. {
  43152. if (this.isLabelEvent(state, evt))
  43153. {
  43154. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt, state));
  43155. forceGetCell = graph.dialect != mxConstants.DIALECT_SVG &&
  43156. mxEvent.getSource(evt).nodeName == 'IMG';
  43157. }
  43158. }),
  43159. mxUtils.bind(this, function(evt)
  43160. {
  43161. if (this.isLabelEvent(state, evt))
  43162. {
  43163. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt, getState(evt)));
  43164. }
  43165. }),
  43166. mxUtils.bind(this, function(evt)
  43167. {
  43168. if (this.isLabelEvent(state, evt))
  43169. {
  43170. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt, getState(evt)));
  43171. forceGetCell = false;
  43172. }
  43173. })
  43174. );
  43175. // Uses double click timeout in mxGraph for quirks mode
  43176. if (graph.nativeDblClickEnabled)
  43177. {
  43178. mxEvent.addListener(state.text.node, 'dblclick',
  43179. mxUtils.bind(this, function(evt)
  43180. {
  43181. if (this.isLabelEvent(state, evt))
  43182. {
  43183. graph.dblClick(evt, state.cell);
  43184. mxEvent.consume(evt);
  43185. }
  43186. })
  43187. );
  43188. }
  43189. }
  43190. };
  43191. /**
  43192. * Function: initializeLabel
  43193. *
  43194. * Initiailzes the label with a suitable container.
  43195. *
  43196. * Parameters:
  43197. *
  43198. * state - <mxCellState> whose label should be initialized.
  43199. */
  43200. mxCellRenderer.prototype.initializeLabel = function(state, shape)
  43201. {
  43202. if (mxClient.IS_SVG && mxClient.NO_FO && shape.dialect != mxConstants.DIALECT_SVG)
  43203. {
  43204. shape.init(state.view.graph.container);
  43205. }
  43206. else
  43207. {
  43208. shape.init(state.view.getDrawPane());
  43209. }
  43210. };
  43211. /**
  43212. * Function: createCellOverlays
  43213. *
  43214. * Creates the actual shape for showing the overlay for the given cell state.
  43215. *
  43216. * Parameters:
  43217. *
  43218. * state - <mxCellState> for which the overlay should be created.
  43219. */
  43220. mxCellRenderer.prototype.createCellOverlays = function(state)
  43221. {
  43222. var graph = state.view.graph;
  43223. var overlays = graph.getCellOverlays(state.cell);
  43224. var dict = null;
  43225. if (overlays != null)
  43226. {
  43227. dict = new mxDictionary();
  43228. for (var i = 0; i < overlays.length; i++)
  43229. {
  43230. var shape = (state.overlays != null) ? state.overlays.remove(overlays[i]) : null;
  43231. if (shape == null)
  43232. {
  43233. var tmp = new mxImageShape(new mxRectangle(), overlays[i].image.src);
  43234. tmp.dialect = state.view.graph.dialect;
  43235. tmp.preserveImageAspect = false;
  43236. tmp.overlay = overlays[i];
  43237. this.initializeOverlay(state, tmp);
  43238. this.installCellOverlayListeners(state, overlays[i], tmp);
  43239. if (overlays[i].cursor != null)
  43240. {
  43241. tmp.node.style.cursor = overlays[i].cursor;
  43242. }
  43243. dict.put(overlays[i], tmp);
  43244. }
  43245. else
  43246. {
  43247. dict.put(overlays[i], shape);
  43248. }
  43249. }
  43250. }
  43251. // Removes unused
  43252. if (state.overlays != null)
  43253. {
  43254. state.overlays.visit(function(id, shape)
  43255. {
  43256. shape.destroy();
  43257. });
  43258. }
  43259. state.overlays = dict;
  43260. };
  43261. /**
  43262. * Function: initializeOverlay
  43263. *
  43264. * Initializes the given overlay.
  43265. *
  43266. * Parameters:
  43267. *
  43268. * state - <mxCellState> for which the overlay should be created.
  43269. * overlay - <mxImageShape> that represents the overlay.
  43270. */
  43271. mxCellRenderer.prototype.initializeOverlay = function(state, overlay)
  43272. {
  43273. overlay.init(state.view.getOverlayPane());
  43274. };
  43275. /**
  43276. * Function: installOverlayListeners
  43277. *
  43278. * Installs the listeners for the given <mxCellState>, <mxCellOverlay> and
  43279. * <mxShape> that represents the overlay.
  43280. */
  43281. mxCellRenderer.prototype.installCellOverlayListeners = function(state, overlay, shape)
  43282. {
  43283. var graph = state.view.graph;
  43284. mxEvent.addListener(shape.node, 'click', function (evt)
  43285. {
  43286. if (graph.isEditing())
  43287. {
  43288. graph.stopEditing(!graph.isInvokesStopCellEditing());
  43289. }
  43290. overlay.fireEvent(new mxEventObject(mxEvent.CLICK,
  43291. 'event', evt, 'cell', state.cell));
  43292. });
  43293. mxEvent.addGestureListeners(shape.node,
  43294. function (evt)
  43295. {
  43296. mxEvent.consume(evt);
  43297. },
  43298. function (evt)
  43299. {
  43300. graph.fireMouseEvent(mxEvent.MOUSE_MOVE,
  43301. new mxMouseEvent(evt, state));
  43302. });
  43303. if (mxClient.IS_TOUCH)
  43304. {
  43305. mxEvent.addListener(shape.node, 'touchend', function (evt)
  43306. {
  43307. overlay.fireEvent(new mxEventObject(mxEvent.CLICK,
  43308. 'event', evt, 'cell', state.cell));
  43309. });
  43310. }
  43311. };
  43312. /**
  43313. * Function: createControl
  43314. *
  43315. * Creates the control for the given cell state.
  43316. *
  43317. * Parameters:
  43318. *
  43319. * state - <mxCellState> for which the control should be created.
  43320. */
  43321. mxCellRenderer.prototype.createControl = function(state)
  43322. {
  43323. var graph = state.view.graph;
  43324. var image = graph.getFoldingImage(state);
  43325. if (graph.foldingEnabled && image != null)
  43326. {
  43327. if (state.control == null)
  43328. {
  43329. var b = new mxRectangle(0, 0, image.width, image.height);
  43330. state.control = new mxImageShape(b, image.src);
  43331. state.control.preserveImageAspect = false;
  43332. state.control.dialect = graph.dialect;
  43333. this.initControl(state, state.control, true, this.createControlClickHandler(state));
  43334. }
  43335. }
  43336. else if (state.control != null)
  43337. {
  43338. state.control.destroy();
  43339. state.control = null;
  43340. }
  43341. };
  43342. /**
  43343. * Function: createControlClickHandler
  43344. *
  43345. * Hook for creating the click handler for the folding icon.
  43346. *
  43347. * Parameters:
  43348. *
  43349. * state - <mxCellState> whose control click handler should be returned.
  43350. */
  43351. mxCellRenderer.prototype.createControlClickHandler = function(state)
  43352. {
  43353. var graph = state.view.graph;
  43354. return mxUtils.bind(this, function (evt)
  43355. {
  43356. if (this.forceControlClickHandler || graph.isEnabled())
  43357. {
  43358. var collapse = !graph.isCellCollapsed(state.cell);
  43359. graph.foldCells(collapse, false, [state.cell], null, evt);
  43360. mxEvent.consume(evt);
  43361. }
  43362. });
  43363. };
  43364. /**
  43365. * Function: initControl
  43366. *
  43367. * Initializes the given control and returns the corresponding DOM node.
  43368. *
  43369. * Parameters:
  43370. *
  43371. * state - <mxCellState> for which the control should be initialized.
  43372. * control - <mxShape> to be initialized.
  43373. * handleEvents - Boolean indicating if mousedown and mousemove should fire events via the graph.
  43374. * clickHandler - Optional function to implement clicks on the control.
  43375. */
  43376. mxCellRenderer.prototype.initControl = function(state, control, handleEvents, clickHandler)
  43377. {
  43378. var graph = state.view.graph;
  43379. // In the special case where the label is in HTML and the display is SVG the image
  43380. // should go into the graph container directly in order to be clickable. Otherwise
  43381. // it is obscured by the HTML label that overlaps the cell.
  43382. var isForceHtml = graph.isHtmlLabel(state.cell) && mxClient.NO_FO &&
  43383. graph.dialect == mxConstants.DIALECT_SVG;
  43384. if (isForceHtml)
  43385. {
  43386. control.dialect = mxConstants.DIALECT_PREFERHTML;
  43387. control.init(graph.container);
  43388. control.node.style.zIndex = 1;
  43389. }
  43390. else
  43391. {
  43392. control.init(state.view.getOverlayPane());
  43393. }
  43394. var node = control.innerNode || control.node;
  43395. // Workaround for missing click event on iOS is to check tolerance below
  43396. if (clickHandler != null && !mxClient.IS_IOS)
  43397. {
  43398. if (graph.isEnabled())
  43399. {
  43400. node.style.cursor = 'pointer';
  43401. }
  43402. mxEvent.addListener(node, 'click', clickHandler);
  43403. }
  43404. if (handleEvents)
  43405. {
  43406. var first = null;
  43407. mxEvent.addGestureListeners(node,
  43408. function (evt)
  43409. {
  43410. first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  43411. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt, state));
  43412. mxEvent.consume(evt);
  43413. },
  43414. function (evt)
  43415. {
  43416. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt, state));
  43417. },
  43418. function (evt)
  43419. {
  43420. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt, state));
  43421. mxEvent.consume(evt);
  43422. });
  43423. // Uses capture phase for event interception to stop bubble phase
  43424. if (clickHandler != null && mxClient.IS_IOS)
  43425. {
  43426. node.addEventListener('touchend', function(evt)
  43427. {
  43428. if (first != null)
  43429. {
  43430. var tol = graph.tolerance;
  43431. if (Math.abs(first.x - mxEvent.getClientX(evt)) < tol &&
  43432. Math.abs(first.y - mxEvent.getClientY(evt)) < tol)
  43433. {
  43434. clickHandler.call(clickHandler, evt);
  43435. mxEvent.consume(evt);
  43436. }
  43437. }
  43438. }, true);
  43439. }
  43440. }
  43441. return node;
  43442. };
  43443. /**
  43444. * Function: isShapeEvent
  43445. *
  43446. * Returns true if the event is for the shape of the given state. This
  43447. * implementation always returns true.
  43448. *
  43449. * Parameters:
  43450. *
  43451. * state - <mxCellState> whose shape fired the event.
  43452. * evt - Mouse event which was fired.
  43453. */
  43454. mxCellRenderer.prototype.isShapeEvent = function(state, evt)
  43455. {
  43456. return true;
  43457. };
  43458. /**
  43459. * Function: isLabelEvent
  43460. *
  43461. * Returns true if the event is for the label of the given state. This
  43462. * implementation always returns true.
  43463. *
  43464. * Parameters:
  43465. *
  43466. * state - <mxCellState> whose label fired the event.
  43467. * evt - Mouse event which was fired.
  43468. */
  43469. mxCellRenderer.prototype.isLabelEvent = function(state, evt)
  43470. {
  43471. return true;
  43472. };
  43473. /**
  43474. * Function: installListeners
  43475. *
  43476. * Installs the event listeners for the given cell state.
  43477. *
  43478. * Parameters:
  43479. *
  43480. * state - <mxCellState> for which the event listeners should be isntalled.
  43481. */
  43482. mxCellRenderer.prototype.installListeners = function(state)
  43483. {
  43484. var graph = state.view.graph;
  43485. // Workaround for touch devices routing all events for a mouse
  43486. // gesture (down, move, up) via the initial DOM node. Same for
  43487. // HTML images in all IE versions (VML images are working).
  43488. var getState = function(evt)
  43489. {
  43490. var result = state;
  43491. if ((graph.dialect != mxConstants.DIALECT_SVG && mxEvent.getSource(evt).nodeName == 'IMG') || mxClient.IS_TOUCH)
  43492. {
  43493. var x = mxEvent.getClientX(evt);
  43494. var y = mxEvent.getClientY(evt);
  43495. // Dispatches the drop event to the graph which
  43496. // consumes and executes the source function
  43497. var pt = mxUtils.convertPoint(graph.container, x, y);
  43498. result = graph.view.getState(graph.getCellAt(pt.x, pt.y));
  43499. }
  43500. return result;
  43501. };
  43502. mxEvent.addGestureListeners(state.shape.node,
  43503. mxUtils.bind(this, function(evt)
  43504. {
  43505. if (this.isShapeEvent(state, evt))
  43506. {
  43507. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt, state));
  43508. }
  43509. }),
  43510. mxUtils.bind(this, function(evt)
  43511. {
  43512. if (this.isShapeEvent(state, evt))
  43513. {
  43514. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt, getState(evt)));
  43515. }
  43516. }),
  43517. mxUtils.bind(this, function(evt)
  43518. {
  43519. if (this.isShapeEvent(state, evt))
  43520. {
  43521. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt, getState(evt)));
  43522. }
  43523. })
  43524. );
  43525. // Uses double click timeout in mxGraph for quirks mode
  43526. if (graph.nativeDblClickEnabled)
  43527. {
  43528. mxEvent.addListener(state.shape.node, 'dblclick',
  43529. mxUtils.bind(this, function(evt)
  43530. {
  43531. if (this.isShapeEvent(state, evt))
  43532. {
  43533. graph.dblClick(evt, state.cell);
  43534. mxEvent.consume(evt);
  43535. }
  43536. })
  43537. );
  43538. }
  43539. };
  43540. /**
  43541. * Function: redrawLabel
  43542. *
  43543. * Redraws the label for the given cell state.
  43544. *
  43545. * Parameters:
  43546. *
  43547. * state - <mxCellState> whose label should be redrawn.
  43548. */
  43549. mxCellRenderer.prototype.redrawLabel = function(state, forced)
  43550. {
  43551. var graph = state.view.graph;
  43552. var value = this.getLabelValue(state);
  43553. var wrapping = graph.isWrapping(state.cell);
  43554. var clipping = graph.isLabelClipped(state.cell);
  43555. var isForceHtml = (state.view.graph.isHtmlLabel(state.cell) || (value != null && mxUtils.isNode(value)));
  43556. var dialect = (isForceHtml) ? mxConstants.DIALECT_STRICTHTML : state.view.graph.dialect;
  43557. var overflow = state.style[mxConstants.STYLE_OVERFLOW] || 'visible';
  43558. if (state.text != null && (state.text.wrap != wrapping || state.text.clipped != clipping ||
  43559. state.text.overflow != overflow || state.text.dialect != dialect))
  43560. {
  43561. state.text.destroy();
  43562. state.text = null;
  43563. }
  43564. if (state.text == null && value != null && (mxUtils.isNode(value) || value.length > 0))
  43565. {
  43566. this.createLabel(state, value);
  43567. }
  43568. else if (state.text != null && (value == null || value.length == 0))
  43569. {
  43570. state.text.destroy();
  43571. state.text = null;
  43572. }
  43573. if (state.text != null)
  43574. {
  43575. // Forced is true if the style has changed, so to get the updated
  43576. // result in getLabelBounds we apply the new style to the shape
  43577. if (forced)
  43578. {
  43579. // Checks if a full repaint is needed
  43580. if (state.text.lastValue != null && this.isTextShapeInvalid(state, state.text))
  43581. {
  43582. // Forces a full repaint
  43583. state.text.lastValue = null;
  43584. }
  43585. state.text.resetStyles();
  43586. state.text.apply(state);
  43587. // Special case where value is obtained via hook in graph
  43588. state.text.valign = graph.getVerticalAlign(state);
  43589. }
  43590. var bounds = this.getLabelBounds(state);
  43591. var nextScale = this.getTextScale(state);
  43592. this.resolveColor(state, 'color', mxConstants.STYLE_FONTCOLOR);
  43593. if (forced || state.text.value != value || state.text.isWrapping != wrapping ||
  43594. state.text.overflow != overflow || state.text.isClipping != clipping ||
  43595. state.text.scale != nextScale || state.text.dialect != dialect ||
  43596. state.text.bounds == null || !state.text.bounds.equals(bounds))
  43597. {
  43598. state.text.dialect = dialect;
  43599. state.text.value = value;
  43600. state.text.bounds = bounds;
  43601. state.text.scale = nextScale;
  43602. state.text.wrap = wrapping;
  43603. state.text.clipped = clipping;
  43604. state.text.overflow = overflow;
  43605. // Preserves visible state
  43606. var vis = state.text.node.style.visibility;
  43607. this.redrawLabelShape(state.text);
  43608. state.text.node.style.visibility = vis;
  43609. }
  43610. }
  43611. };
  43612. /**
  43613. * Function: isTextShapeInvalid
  43614. *
  43615. * Returns true if the style for the text shape has changed.
  43616. *
  43617. * Parameters:
  43618. *
  43619. * state - <mxCellState> whose label should be checked.
  43620. * shape - <mxText> shape to be checked.
  43621. */
  43622. mxCellRenderer.prototype.isTextShapeInvalid = function(state, shape)
  43623. {
  43624. function check(property, stylename, defaultValue)
  43625. {
  43626. var result = false;
  43627. // Workaround for spacing added to directional spacing
  43628. if (stylename == 'spacingTop' || stylename == 'spacingRight' ||
  43629. stylename == 'spacingBottom' || stylename == 'spacingLeft')
  43630. {
  43631. result = parseFloat(shape[property]) - parseFloat(shape.spacing) !=
  43632. (state.style[stylename] || defaultValue);
  43633. }
  43634. else
  43635. {
  43636. result = shape[property] != (state.style[stylename] || defaultValue);
  43637. }
  43638. return result;
  43639. };
  43640. return check('fontStyle', mxConstants.STYLE_FONTSTYLE, mxConstants.DEFAULT_FONTSTYLE) ||
  43641. check('family', mxConstants.STYLE_FONTFAMILY, mxConstants.DEFAULT_FONTFAMILY) ||
  43642. check('size', mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE) ||
  43643. check('color', mxConstants.STYLE_FONTCOLOR, 'black') ||
  43644. check('align', mxConstants.STYLE_ALIGN, '') ||
  43645. check('valign', mxConstants.STYLE_VERTICAL_ALIGN, '') ||
  43646. check('spacing', mxConstants.STYLE_SPACING, 2) ||
  43647. check('spacingTop', mxConstants.STYLE_SPACING_TOP, 0) ||
  43648. check('spacingRight', mxConstants.STYLE_SPACING_RIGHT, 0) ||
  43649. check('spacingBottom', mxConstants.STYLE_SPACING_BOTTOM, 0) ||
  43650. check('spacingLeft', mxConstants.STYLE_SPACING_LEFT, 0) ||
  43651. check('horizontal', mxConstants.STYLE_HORIZONTAL, true) ||
  43652. check('background', mxConstants.STYLE_LABEL_BACKGROUNDCOLOR) ||
  43653. check('border', mxConstants.STYLE_LABEL_BORDERCOLOR) ||
  43654. check('opacity', mxConstants.STYLE_TEXT_OPACITY, 100) ||
  43655. check('textDirection', mxConstants.STYLE_TEXT_DIRECTION, mxConstants.DEFAULT_TEXT_DIRECTION);
  43656. };
  43657. /**
  43658. * Function: redrawLabelShape
  43659. *
  43660. * Called to invoked redraw on the given text shape.
  43661. *
  43662. * Parameters:
  43663. *
  43664. * shape - <mxText> shape to be redrawn.
  43665. */
  43666. mxCellRenderer.prototype.redrawLabelShape = function(shape)
  43667. {
  43668. shape.redraw();
  43669. };
  43670. /**
  43671. * Function: getTextScale
  43672. *
  43673. * Returns the scaling used for the label of the given state
  43674. *
  43675. * Parameters:
  43676. *
  43677. * state - <mxCellState> whose label scale should be returned.
  43678. */
  43679. mxCellRenderer.prototype.getTextScale = function(state)
  43680. {
  43681. return state.view.scale;
  43682. };
  43683. /**
  43684. * Function: getLabelBounds
  43685. *
  43686. * Returns the bounds to be used to draw the label of the given state.
  43687. *
  43688. * Parameters:
  43689. *
  43690. * state - <mxCellState> whose label bounds should be returned.
  43691. */
  43692. mxCellRenderer.prototype.getLabelBounds = function(state)
  43693. {
  43694. var graph = state.view.graph;
  43695. var scale = state.view.scale;
  43696. var isEdge = graph.getModel().isEdge(state.cell);
  43697. var bounds = new mxRectangle(state.absoluteOffset.x, state.absoluteOffset.y);
  43698. if (isEdge)
  43699. {
  43700. var spacing = state.text.getSpacing();
  43701. bounds.x += spacing.x * scale;
  43702. bounds.y += spacing.y * scale;
  43703. var geo = graph.getCellGeometry(state.cell);
  43704. if (geo != null)
  43705. {
  43706. bounds.width = Math.max(0, geo.width * scale);
  43707. bounds.height = Math.max(0, geo.height * scale);
  43708. }
  43709. }
  43710. else
  43711. {
  43712. // Inverts label position
  43713. if (state.text.isPaintBoundsInverted())
  43714. {
  43715. var tmp = bounds.x;
  43716. bounds.x = bounds.y;
  43717. bounds.y = tmp;
  43718. }
  43719. bounds.x += state.x;
  43720. bounds.y += state.y;
  43721. // Minimum of 1 fixes alignment bug in HTML labels
  43722. bounds.width = Math.max(1, state.width);
  43723. bounds.height = Math.max(1, state.height);
  43724. }
  43725. if (state.text.isPaintBoundsInverted())
  43726. {
  43727. // Rotates around center of state
  43728. var t = (state.width - state.height) / 2;
  43729. bounds.x += t;
  43730. bounds.y -= t;
  43731. var tmp = bounds.width;
  43732. bounds.width = bounds.height;
  43733. bounds.height = tmp;
  43734. }
  43735. // Shape can modify its label bounds
  43736. if (state.shape != null)
  43737. {
  43738. var hpos = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  43739. var vpos = mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  43740. if (hpos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_MIDDLE)
  43741. {
  43742. bounds = state.shape.getLabelBounds(bounds);
  43743. }
  43744. }
  43745. // Label width style overrides actual label width
  43746. var lw = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_WIDTH, null);
  43747. if (lw != null)
  43748. {
  43749. bounds.width = parseFloat(lw) * scale;
  43750. }
  43751. if (!isEdge)
  43752. {
  43753. this.rotateLabelBounds(state, bounds);
  43754. }
  43755. return bounds;
  43756. };
  43757. /**
  43758. * Function: rotateLabelBounds
  43759. *
  43760. * Adds the shape rotation to the given label bounds and
  43761. * applies the alignment and offsets.
  43762. *
  43763. * Parameters:
  43764. *
  43765. * state - <mxCellState> whose label bounds should be rotated.
  43766. * bounds - <mxRectangle> the rectangle to be rotated.
  43767. */
  43768. mxCellRenderer.prototype.rotateLabelBounds = function(state, bounds)
  43769. {
  43770. bounds.y -= state.text.margin.y * bounds.height;
  43771. bounds.x -= state.text.margin.x * bounds.width;
  43772. if (!this.legacySpacing || (state.style[mxConstants.STYLE_OVERFLOW] != 'fill' && state.style[mxConstants.STYLE_OVERFLOW] != 'width'))
  43773. {
  43774. var s = state.view.scale;
  43775. var spacing = state.text.getSpacing();
  43776. bounds.x += spacing.x * s;
  43777. bounds.y += spacing.y * s;
  43778. var hpos = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  43779. var vpos = mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  43780. var lw = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_WIDTH, null);
  43781. bounds.width = Math.max(0, bounds.width - ((hpos == mxConstants.ALIGN_CENTER && lw == null) ? (state.text.spacingLeft * s + state.text.spacingRight * s) : 0));
  43782. bounds.height = Math.max(0, bounds.height - ((vpos == mxConstants.ALIGN_MIDDLE) ? (state.text.spacingTop * s + state.text.spacingBottom * s) : 0));
  43783. }
  43784. var theta = state.text.getTextRotation();
  43785. // Only needed if rotated around another center
  43786. if (theta != 0 && state != null && state.view.graph.model.isVertex(state.cell))
  43787. {
  43788. var cx = state.getCenterX();
  43789. var cy = state.getCenterY();
  43790. if (bounds.x != cx || bounds.y != cy)
  43791. {
  43792. var rad = theta * (Math.PI / 180);
  43793. var pt = mxUtils.getRotatedPoint(new mxPoint(bounds.x, bounds.y),
  43794. Math.cos(rad), Math.sin(rad), new mxPoint(cx, cy));
  43795. bounds.x = pt.x;
  43796. bounds.y = pt.y;
  43797. }
  43798. }
  43799. };
  43800. /**
  43801. * Function: redrawCellOverlays
  43802. *
  43803. * Redraws the overlays for the given cell state.
  43804. *
  43805. * Parameters:
  43806. *
  43807. * state - <mxCellState> whose overlays should be redrawn.
  43808. */
  43809. mxCellRenderer.prototype.redrawCellOverlays = function(state, forced)
  43810. {
  43811. this.createCellOverlays(state);
  43812. if (state.overlays != null)
  43813. {
  43814. var rot = mxUtils.mod(mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION, 0), 90);
  43815. var rad = mxUtils.toRadians(rot);
  43816. var cos = Math.cos(rad);
  43817. var sin = Math.sin(rad);
  43818. state.overlays.visit(function(id, shape)
  43819. {
  43820. var bounds = shape.overlay.getBounds(state);
  43821. if (!state.view.graph.getModel().isEdge(state.cell))
  43822. {
  43823. if (state.shape != null && rot != 0)
  43824. {
  43825. var cx = bounds.getCenterX();
  43826. var cy = bounds.getCenterY();
  43827. var point = mxUtils.getRotatedPoint(new mxPoint(cx, cy), cos, sin,
  43828. new mxPoint(state.getCenterX(), state.getCenterY()));
  43829. cx = point.x;
  43830. cy = point.y;
  43831. bounds.x = Math.round(cx - bounds.width / 2);
  43832. bounds.y = Math.round(cy - bounds.height / 2);
  43833. }
  43834. }
  43835. if (forced || shape.bounds == null || shape.scale != state.view.scale ||
  43836. !shape.bounds.equals(bounds))
  43837. {
  43838. shape.bounds = bounds;
  43839. shape.scale = state.view.scale;
  43840. shape.redraw();
  43841. }
  43842. });
  43843. }
  43844. };
  43845. /**
  43846. * Function: redrawControl
  43847. *
  43848. * Redraws the control for the given cell state.
  43849. *
  43850. * Parameters:
  43851. *
  43852. * state - <mxCellState> whose control should be redrawn.
  43853. */
  43854. mxCellRenderer.prototype.redrawControl = function(state, forced)
  43855. {
  43856. var image = state.view.graph.getFoldingImage(state);
  43857. if (state.control != null && image != null)
  43858. {
  43859. var bounds = this.getControlBounds(state, image.width, image.height);
  43860. var r = (this.legacyControlPosition) ?
  43861. mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION, 0) :
  43862. state.shape.getTextRotation();
  43863. var s = state.view.scale;
  43864. if (forced || state.control.scale != s || !state.control.bounds.equals(bounds) ||
  43865. state.control.rotation != r)
  43866. {
  43867. state.control.rotation = r;
  43868. state.control.bounds = bounds;
  43869. state.control.scale = s;
  43870. state.control.redraw();
  43871. }
  43872. }
  43873. };
  43874. /**
  43875. * Function: getControlBounds
  43876. *
  43877. * Returns the bounds to be used to draw the control (folding icon) of the
  43878. * given state.
  43879. */
  43880. mxCellRenderer.prototype.getControlBounds = function(state, w, h)
  43881. {
  43882. if (state.control != null)
  43883. {
  43884. var s = state.view.scale;
  43885. var cx = state.getCenterX();
  43886. var cy = state.getCenterY();
  43887. if (!state.view.graph.getModel().isEdge(state.cell))
  43888. {
  43889. cx = state.x + w * s;
  43890. cy = state.y + h * s;
  43891. if (state.shape != null)
  43892. {
  43893. // TODO: Factor out common code
  43894. var rot = state.shape.getShapeRotation();
  43895. if (this.legacyControlPosition)
  43896. {
  43897. rot = mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION, 0);
  43898. }
  43899. else
  43900. {
  43901. if (state.shape.isPaintBoundsInverted())
  43902. {
  43903. var t = (state.width - state.height) / 2;
  43904. cx += t;
  43905. cy -= t;
  43906. }
  43907. }
  43908. if (rot != 0)
  43909. {
  43910. var rad = mxUtils.toRadians(rot);
  43911. var cos = Math.cos(rad);
  43912. var sin = Math.sin(rad);
  43913. var point = mxUtils.getRotatedPoint(new mxPoint(cx, cy), cos, sin,
  43914. new mxPoint(state.getCenterX(), state.getCenterY()));
  43915. cx = point.x;
  43916. cy = point.y;
  43917. }
  43918. }
  43919. }
  43920. return (state.view.graph.getModel().isEdge(state.cell)) ?
  43921. new mxRectangle(Math.round(cx - w / 2 * s), Math.round(cy - h / 2 * s), Math.round(w * s), Math.round(h * s))
  43922. : new mxRectangle(Math.round(cx - w / 2 * s), Math.round(cy - h / 2 * s), Math.round(w * s), Math.round(h * s));
  43923. }
  43924. return null;
  43925. };
  43926. /**
  43927. * Function: insertStateAfter
  43928. *
  43929. * Inserts the given array of <mxShapes> after the given nodes in the DOM.
  43930. *
  43931. * Parameters:
  43932. *
  43933. * shapes - Array of <mxShapes> to be inserted.
  43934. * node - Node in <drawPane> after which the shapes should be inserted.
  43935. * htmlNode - Node in the graph container after which the shapes should be inserted that
  43936. * will not go into the <drawPane> (eg. HTML labels without foreignObjects).
  43937. */
  43938. mxCellRenderer.prototype.insertStateAfter = function(state, node, htmlNode)
  43939. {
  43940. var shapes = this.getShapesForState(state);
  43941. for (var i = 0; i < shapes.length; i++)
  43942. {
  43943. if (shapes[i] != null && shapes[i].node != null)
  43944. {
  43945. var html = shapes[i].node.parentNode != state.view.getDrawPane() &&
  43946. shapes[i].node.parentNode != state.view.getOverlayPane();
  43947. var temp = (html) ? htmlNode : node;
  43948. if (temp != null && temp.nextSibling != shapes[i].node)
  43949. {
  43950. if (temp.nextSibling == null)
  43951. {
  43952. temp.parentNode.appendChild(shapes[i].node);
  43953. }
  43954. else
  43955. {
  43956. temp.parentNode.insertBefore(shapes[i].node, temp.nextSibling);
  43957. }
  43958. }
  43959. else if (temp == null)
  43960. {
  43961. // Special case: First HTML node should be first sibling after canvas
  43962. if (shapes[i].node.parentNode == state.view.graph.container)
  43963. {
  43964. var canvas = state.view.canvas;
  43965. while (canvas != null && canvas.parentNode != state.view.graph.container)
  43966. {
  43967. canvas = canvas.parentNode;
  43968. }
  43969. if (canvas != null && canvas.nextSibling != null)
  43970. {
  43971. if (canvas.nextSibling != shapes[i].node)
  43972. {
  43973. shapes[i].node.parentNode.insertBefore(shapes[i].node, canvas.nextSibling);
  43974. }
  43975. }
  43976. else
  43977. {
  43978. shapes[i].node.parentNode.appendChild(shapes[i].node);
  43979. }
  43980. }
  43981. else if (shapes[i].node.parentNode != null &&
  43982. shapes[i].node.parentNode.firstChild != null &&
  43983. shapes[i].node.parentNode.firstChild != shapes[i].node)
  43984. {
  43985. // Inserts the node as the first child of the parent to implement the order
  43986. shapes[i].node.parentNode.insertBefore(shapes[i].node, shapes[i].node.parentNode.firstChild);
  43987. }
  43988. }
  43989. if (html)
  43990. {
  43991. htmlNode = shapes[i].node;
  43992. }
  43993. else
  43994. {
  43995. node = shapes[i].node;
  43996. }
  43997. }
  43998. }
  43999. return [node, htmlNode];
  44000. };
  44001. /**
  44002. * Function: getShapesForState
  44003. *
  44004. * Returns the <mxShapes> for the given cell state in the order in which they should
  44005. * appear in the DOM.
  44006. *
  44007. * Parameters:
  44008. *
  44009. * state - <mxCellState> whose shapes should be returned.
  44010. */
  44011. mxCellRenderer.prototype.getShapesForState = function(state)
  44012. {
  44013. return [state.shape, state.text, state.control];
  44014. };
  44015. /**
  44016. * Function: redraw
  44017. *
  44018. * Updates the bounds or points and scale of the shapes for the given cell
  44019. * state. This is called in mxGraphView.validatePoints as the last step of
  44020. * updating all cells.
  44021. *
  44022. * Parameters:
  44023. *
  44024. * state - <mxCellState> for which the shapes should be updated.
  44025. * force - Optional boolean that specifies if the cell should be reconfiured
  44026. * and redrawn without any additional checks.
  44027. * rendering - Optional boolean that specifies if the cell should actually
  44028. * be drawn into the DOM. If this is false then redraw and/or reconfigure
  44029. * will not be called on the shape.
  44030. */
  44031. mxCellRenderer.prototype.redraw = function(state, force, rendering)
  44032. {
  44033. var shapeChanged = this.redrawShape(state, force, rendering);
  44034. if (state.shape != null && (rendering == null || rendering))
  44035. {
  44036. this.redrawLabel(state, shapeChanged);
  44037. this.redrawCellOverlays(state, shapeChanged);
  44038. this.redrawControl(state, shapeChanged);
  44039. }
  44040. };
  44041. /**
  44042. * Function: redrawShape
  44043. *
  44044. * Redraws the shape for the given cell state.
  44045. *
  44046. * Parameters:
  44047. *
  44048. * state - <mxCellState> whose label should be redrawn.
  44049. */
  44050. mxCellRenderer.prototype.redrawShape = function(state, force, rendering)
  44051. {
  44052. var model = state.view.graph.model;
  44053. var shapeChanged = false;
  44054. // Forces creation of new shape if shape style has changed
  44055. if (state.shape != null && state.shape.style != null && state.style != null &&
  44056. state.shape.style[mxConstants.STYLE_SHAPE] != state.style[mxConstants.STYLE_SHAPE])
  44057. {
  44058. state.shape.destroy();
  44059. state.shape = null;
  44060. }
  44061. if (state.shape == null && state.view.graph.container != null &&
  44062. state.cell != state.view.currentRoot &&
  44063. (model.isVertex(state.cell) || model.isEdge(state.cell)))
  44064. {
  44065. state.shape = this.createShape(state);
  44066. if (state.shape != null)
  44067. {
  44068. state.shape.minSvgStrokeWidth = this.minSvgStrokeWidth;
  44069. state.shape.antiAlias = this.antiAlias;
  44070. this.createIndicatorShape(state);
  44071. this.initializeShape(state);
  44072. this.createCellOverlays(state);
  44073. this.installListeners(state);
  44074. // Forces a refresh of the handler if one exists
  44075. state.view.graph.selectionCellsHandler.updateHandler(state);
  44076. }
  44077. }
  44078. else if (!force && state.shape != null && (!mxUtils.equalEntries(state.shape.style,
  44079. state.style) || this.checkPlaceholderStyles(state)))
  44080. {
  44081. state.shape.resetStyles();
  44082. this.configureShape(state);
  44083. // LATER: Ignore update for realtime to fix reset of current gesture
  44084. state.view.graph.selectionCellsHandler.updateHandler(state);
  44085. force = true;
  44086. }
  44087. // Updates indicator shape
  44088. if (state.shape != null && state.shape.indicatorShape !=
  44089. this.getShape(state.view.graph.getIndicatorShape(state)))
  44090. {
  44091. if (state.shape.indicator != null)
  44092. {
  44093. state.shape.indicator.destroy();
  44094. state.shape.indicator = null;
  44095. }
  44096. this.createIndicatorShape(state);
  44097. if (state.shape.indicatorShape != null)
  44098. {
  44099. state.shape.indicator = new state.shape.indicatorShape();
  44100. state.shape.indicator.dialect = state.shape.dialect;
  44101. state.shape.indicator.init(state.node);
  44102. force = true;
  44103. }
  44104. }
  44105. if (state.shape != null)
  44106. {
  44107. // Handles changes of the collapse icon
  44108. this.createControl(state);
  44109. // Redraws the cell if required, ignores changes to bounds if points are
  44110. // defined as the bounds are updated for the given points inside the shape
  44111. if (force || this.isShapeInvalid(state, state.shape))
  44112. {
  44113. if (state.absolutePoints != null)
  44114. {
  44115. state.shape.points = state.absolutePoints.slice();
  44116. state.shape.bounds = null;
  44117. }
  44118. else
  44119. {
  44120. state.shape.points = null;
  44121. state.shape.bounds = new mxRectangle(state.x, state.y, state.width, state.height);
  44122. }
  44123. state.shape.scale = state.view.scale;
  44124. if (rendering == null || rendering)
  44125. {
  44126. this.doRedrawShape(state);
  44127. }
  44128. else
  44129. {
  44130. state.shape.updateBoundingBox();
  44131. }
  44132. shapeChanged = true;
  44133. }
  44134. }
  44135. return shapeChanged;
  44136. };
  44137. /**
  44138. * Function: doRedrawShape
  44139. *
  44140. * Invokes redraw on the shape of the given state.
  44141. */
  44142. mxCellRenderer.prototype.doRedrawShape = function(state)
  44143. {
  44144. state.shape.redraw();
  44145. };
  44146. /**
  44147. * Function: isShapeInvalid
  44148. *
  44149. * Returns true if the given shape must be repainted.
  44150. */
  44151. mxCellRenderer.prototype.isShapeInvalid = function(state, shape)
  44152. {
  44153. return shape.bounds == null || shape.scale != state.view.scale ||
  44154. (state.absolutePoints == null && !shape.bounds.equals(state)) ||
  44155. (state.absolutePoints != null && !mxUtils.equalPoints(shape.points, state.absolutePoints))
  44156. };
  44157. /**
  44158. * Function: destroy
  44159. *
  44160. * Destroys the shapes associated with the given cell state.
  44161. *
  44162. * Parameters:
  44163. *
  44164. * state - <mxCellState> for which the shapes should be destroyed.
  44165. */
  44166. mxCellRenderer.prototype.destroy = function(state)
  44167. {
  44168. if (state.shape != null)
  44169. {
  44170. if (state.text != null)
  44171. {
  44172. state.text.destroy();
  44173. state.text = null;
  44174. }
  44175. if (state.overlays != null)
  44176. {
  44177. state.overlays.visit(function(id, shape)
  44178. {
  44179. shape.destroy();
  44180. });
  44181. state.overlays = null;
  44182. }
  44183. if (state.control != null)
  44184. {
  44185. state.control.destroy();
  44186. state.control = null;
  44187. }
  44188. state.shape.destroy();
  44189. state.shape = null;
  44190. }
  44191. };
  44192. /**
  44193. * Copyright (c) 2006-2015, JGraph Ltd
  44194. * Copyright (c) 2006-2015, Gaudenz Alder
  44195. */
  44196. var mxEdgeStyle =
  44197. {
  44198. /**
  44199. * Class: mxEdgeStyle
  44200. *
  44201. * Provides various edge styles to be used as the values for
  44202. * <mxConstants.STYLE_EDGE> in a cell style.
  44203. *
  44204. * Example:
  44205. *
  44206. * (code)
  44207. * var style = stylesheet.getDefaultEdgeStyle();
  44208. * style[mxConstants.STYLE_EDGE] = mxEdgeStyle.ElbowConnector;
  44209. * (end)
  44210. *
  44211. * Sets the default edge style to <ElbowConnector>.
  44212. *
  44213. * Custom edge style:
  44214. *
  44215. * To write a custom edge style, a function must be added to the mxEdgeStyle
  44216. * object as follows:
  44217. *
  44218. * (code)
  44219. * mxEdgeStyle.MyStyle = function(state, source, target, points, result)
  44220. * {
  44221. * if (source != null && target != null)
  44222. * {
  44223. * var pt = new mxPoint(target.getCenterX(), source.getCenterY());
  44224. *
  44225. * if (mxUtils.contains(source, pt.x, pt.y))
  44226. * {
  44227. * pt.y = source.y + source.height;
  44228. * }
  44229. *
  44230. * result.push(pt);
  44231. * }
  44232. * };
  44233. * (end)
  44234. *
  44235. * In the above example, a right angle is created using a point on the
  44236. * horizontal center of the target vertex and the vertical center of the source
  44237. * vertex. The code checks if that point intersects the source vertex and makes
  44238. * the edge straight if it does. The point is then added into the result array,
  44239. * which acts as the return value of the function.
  44240. *
  44241. * The new edge style should then be registered in the <mxStyleRegistry> as follows:
  44242. * (code)
  44243. * mxStyleRegistry.putValue('myEdgeStyle', mxEdgeStyle.MyStyle);
  44244. * (end)
  44245. *
  44246. * The custom edge style above can now be used in a specific edge as follows:
  44247. *
  44248. * (code)
  44249. * model.setStyle(edge, 'edgeStyle=myEdgeStyle');
  44250. * (end)
  44251. *
  44252. * Note that the key of the <mxStyleRegistry> entry for the function should
  44253. * be used in string values, unless <mxGraphView.allowEval> is true, in
  44254. * which case you can also use mxEdgeStyle.MyStyle for the value in the
  44255. * cell style above.
  44256. *
  44257. * Or it can be used for all edges in the graph as follows:
  44258. *
  44259. * (code)
  44260. * var style = graph.getStylesheet().getDefaultEdgeStyle();
  44261. * style[mxConstants.STYLE_EDGE] = mxEdgeStyle.MyStyle;
  44262. * (end)
  44263. *
  44264. * Note that the object can be used directly when programmatically setting
  44265. * the value, but the key in the <mxStyleRegistry> should be used when
  44266. * setting the value via a key, value pair in a cell style.
  44267. *
  44268. * Function: EntityRelation
  44269. *
  44270. * Implements an entity relation style for edges (as used in database
  44271. * schema diagrams). At the time the function is called, the result
  44272. * array contains a placeholder (null) for the first absolute point,
  44273. * that is, the point where the edge and source terminal are connected.
  44274. * The implementation of the style then adds all intermediate waypoints
  44275. * except for the last point, that is, the connection point between the
  44276. * edge and the target terminal. The first ant the last point in the
  44277. * result array are then replaced with mxPoints that take into account
  44278. * the terminal's perimeter and next point on the edge.
  44279. *
  44280. * Parameters:
  44281. *
  44282. * state - <mxCellState> that represents the edge to be updated.
  44283. * source - <mxCellState> that represents the source terminal.
  44284. * target - <mxCellState> that represents the target terminal.
  44285. * points - List of relative control points.
  44286. * result - Array of <mxPoints> that represent the actual points of the
  44287. * edge.
  44288. */
  44289. EntityRelation: function(state, source, target, points, result)
  44290. {
  44291. var view = state.view;
  44292. var graph = view.graph;
  44293. var segment = mxUtils.getValue(state.style,
  44294. mxConstants.STYLE_SEGMENT,
  44295. mxConstants.ENTITY_SEGMENT) * view.scale;
  44296. var pts = state.absolutePoints;
  44297. var p0 = pts[0];
  44298. var pe = pts[pts.length-1];
  44299. var isSourceLeft = false;
  44300. if (p0 != null)
  44301. {
  44302. source = new mxCellState();
  44303. source.x = p0.x;
  44304. source.y = p0.y;
  44305. }
  44306. else if (source != null)
  44307. {
  44308. var constraint = mxUtils.getPortConstraints(source, state, true, mxConstants.DIRECTION_MASK_NONE);
  44309. if (constraint != mxConstants.DIRECTION_MASK_NONE && constraint != mxConstants.DIRECTION_MASK_WEST +
  44310. mxConstants.DIRECTION_MASK_EAST)
  44311. {
  44312. isSourceLeft = constraint == mxConstants.DIRECTION_MASK_WEST;
  44313. }
  44314. else
  44315. {
  44316. var sourceGeometry = graph.getCellGeometry(source.cell);
  44317. if (sourceGeometry.relative)
  44318. {
  44319. isSourceLeft = sourceGeometry.x <= 0.5;
  44320. }
  44321. else if (target != null)
  44322. {
  44323. isSourceLeft = target.x + target.width < source.x;
  44324. }
  44325. }
  44326. }
  44327. else
  44328. {
  44329. return;
  44330. }
  44331. var isTargetLeft = true;
  44332. if (pe != null)
  44333. {
  44334. target = new mxCellState();
  44335. target.x = pe.x;
  44336. target.y = pe.y;
  44337. }
  44338. else if (target != null)
  44339. {
  44340. var constraint = mxUtils.getPortConstraints(target, state, false, mxConstants.DIRECTION_MASK_NONE);
  44341. if (constraint != mxConstants.DIRECTION_MASK_NONE && constraint != mxConstants.DIRECTION_MASK_WEST +
  44342. mxConstants.DIRECTION_MASK_EAST)
  44343. {
  44344. isTargetLeft = constraint == mxConstants.DIRECTION_MASK_WEST;
  44345. }
  44346. else
  44347. {
  44348. var targetGeometry = graph.getCellGeometry(target.cell);
  44349. if (targetGeometry.relative)
  44350. {
  44351. isTargetLeft = targetGeometry.x <= 0.5;
  44352. }
  44353. else if (source != null)
  44354. {
  44355. isTargetLeft = source.x + source.width < target.x;
  44356. }
  44357. }
  44358. }
  44359. if (source != null && target != null)
  44360. {
  44361. var x0 = (isSourceLeft) ? source.x : source.x + source.width;
  44362. var y0 = view.getRoutingCenterY(source);
  44363. var xe = (isTargetLeft) ? target.x : target.x + target.width;
  44364. var ye = view.getRoutingCenterY(target);
  44365. var seg = segment;
  44366. var dx = (isSourceLeft) ? -seg : seg;
  44367. var dep = new mxPoint(x0 + dx, y0);
  44368. dx = (isTargetLeft) ? -seg : seg;
  44369. var arr = new mxPoint(xe + dx, ye);
  44370. // Adds intermediate points if both go out on same side
  44371. if (isSourceLeft == isTargetLeft)
  44372. {
  44373. var x = (isSourceLeft) ?
  44374. Math.min(x0, xe)-segment :
  44375. Math.max(x0, xe)+segment;
  44376. result.push(new mxPoint(x, y0));
  44377. result.push(new mxPoint(x, ye));
  44378. }
  44379. else if ((dep.x < arr.x) == isSourceLeft)
  44380. {
  44381. var midY = y0 + (ye - y0) / 2;
  44382. result.push(dep);
  44383. result.push(new mxPoint(dep.x, midY));
  44384. result.push(new mxPoint(arr.x, midY));
  44385. result.push(arr);
  44386. }
  44387. else
  44388. {
  44389. result.push(dep);
  44390. result.push(arr);
  44391. }
  44392. }
  44393. },
  44394. /**
  44395. * Function: Loop
  44396. *
  44397. * Implements a self-reference, aka. loop.
  44398. */
  44399. Loop: function(state, source, target, points, result)
  44400. {
  44401. var pts = state.absolutePoints;
  44402. var p0 = pts[0];
  44403. var pe = pts[pts.length-1];
  44404. if (p0 != null && pe != null)
  44405. {
  44406. if (points != null && points.length > 0)
  44407. {
  44408. for (var i = 0; i < points.length; i++)
  44409. {
  44410. var pt = points[i];
  44411. pt = state.view.transformControlPoint(state, pt);
  44412. result.push(new mxPoint(pt.x, pt.y));
  44413. }
  44414. }
  44415. return;
  44416. }
  44417. if (source != null)
  44418. {
  44419. var view = state.view;
  44420. var graph = view.graph;
  44421. var pt = (points != null && points.length > 0) ? points[0] : null;
  44422. if (pt != null)
  44423. {
  44424. pt = view.transformControlPoint(state, pt);
  44425. if (mxUtils.contains(source, pt.x, pt.y))
  44426. {
  44427. pt = null;
  44428. }
  44429. }
  44430. var x = 0;
  44431. var dx = 0;
  44432. var y = 0;
  44433. var dy = 0;
  44434. var seg = mxUtils.getValue(state.style, mxConstants.STYLE_SEGMENT,
  44435. graph.gridSize) * view.scale;
  44436. var dir = mxUtils.getValue(state.style, mxConstants.STYLE_DIRECTION,
  44437. mxConstants.DIRECTION_WEST);
  44438. if (dir == mxConstants.DIRECTION_NORTH ||
  44439. dir == mxConstants.DIRECTION_SOUTH)
  44440. {
  44441. x = view.getRoutingCenterX(source);
  44442. dx = seg;
  44443. }
  44444. else
  44445. {
  44446. y = view.getRoutingCenterY(source);
  44447. dy = seg;
  44448. }
  44449. if (pt == null ||
  44450. pt.x < source.x ||
  44451. pt.x > source.x + source.width)
  44452. {
  44453. if (pt != null)
  44454. {
  44455. x = pt.x;
  44456. dy = Math.max(Math.abs(y - pt.y), dy);
  44457. }
  44458. else
  44459. {
  44460. if (dir == mxConstants.DIRECTION_NORTH)
  44461. {
  44462. y = source.y - 2 * dx;
  44463. }
  44464. else if (dir == mxConstants.DIRECTION_SOUTH)
  44465. {
  44466. y = source.y + source.height + 2 * dx;
  44467. }
  44468. else if (dir == mxConstants.DIRECTION_EAST)
  44469. {
  44470. x = source.x - 2 * dy;
  44471. }
  44472. else
  44473. {
  44474. x = source.x + source.width + 2 * dy;
  44475. }
  44476. }
  44477. }
  44478. else if (pt != null)
  44479. {
  44480. x = view.getRoutingCenterX(source);
  44481. dx = Math.max(Math.abs(x - pt.x), dy);
  44482. y = pt.y;
  44483. dy = 0;
  44484. }
  44485. result.push(new mxPoint(x - dx, y - dy));
  44486. result.push(new mxPoint(x + dx, y + dy));
  44487. }
  44488. },
  44489. /**
  44490. * Function: ElbowConnector
  44491. *
  44492. * Uses either <SideToSide> or <TopToBottom> depending on the horizontal
  44493. * flag in the cell style. <SideToSide> is used if horizontal is true or
  44494. * unspecified. See <EntityRelation> for a description of the
  44495. * parameters.
  44496. */
  44497. ElbowConnector: function(state, source, target, points, result)
  44498. {
  44499. var pt = (points != null && points.length > 0) ? points[0] : null;
  44500. var vertical = false;
  44501. var horizontal = false;
  44502. if (source != null && target != null)
  44503. {
  44504. if (pt != null)
  44505. {
  44506. var left = Math.min(source.x, target.x);
  44507. var right = Math.max(source.x + source.width,
  44508. target.x + target.width);
  44509. var top = Math.min(source.y, target.y);
  44510. var bottom = Math.max(source.y + source.height,
  44511. target.y + target.height);
  44512. pt = state.view.transformControlPoint(state, pt);
  44513. vertical = pt.y < top || pt.y > bottom;
  44514. horizontal = pt.x < left || pt.x > right;
  44515. }
  44516. else
  44517. {
  44518. var left = Math.max(source.x, target.x);
  44519. var right = Math.min(source.x + source.width,
  44520. target.x + target.width);
  44521. vertical = left == right;
  44522. if (!vertical)
  44523. {
  44524. var top = Math.max(source.y, target.y);
  44525. var bottom = Math.min(source.y + source.height,
  44526. target.y + target.height);
  44527. horizontal = top == bottom;
  44528. }
  44529. }
  44530. }
  44531. if (!horizontal && (vertical ||
  44532. state.style[mxConstants.STYLE_ELBOW] == mxConstants.ELBOW_VERTICAL))
  44533. {
  44534. mxEdgeStyle.TopToBottom(state, source, target, points, result);
  44535. }
  44536. else
  44537. {
  44538. mxEdgeStyle.SideToSide(state, source, target, points, result);
  44539. }
  44540. },
  44541. /**
  44542. * Function: SideToSide
  44543. *
  44544. * Implements a vertical elbow edge. See <EntityRelation> for a description
  44545. * of the parameters.
  44546. */
  44547. SideToSide: function(state, source, target, points, result)
  44548. {
  44549. var view = state.view;
  44550. var pt = (points != null && points.length > 0) ? points[0] : null;
  44551. var pts = state.absolutePoints;
  44552. var p0 = pts[0];
  44553. var pe = pts[pts.length-1];
  44554. if (pt != null)
  44555. {
  44556. pt = view.transformControlPoint(state, pt);
  44557. }
  44558. if (p0 != null)
  44559. {
  44560. source = new mxCellState();
  44561. source.x = p0.x;
  44562. source.y = p0.y;
  44563. }
  44564. if (pe != null)
  44565. {
  44566. target = new mxCellState();
  44567. target.x = pe.x;
  44568. target.y = pe.y;
  44569. }
  44570. if (source != null && target != null)
  44571. {
  44572. var l = Math.max(source.x, target.x);
  44573. var r = Math.min(source.x + source.width,
  44574. target.x + target.width);
  44575. var x = (pt != null) ? pt.x : Math.round(r + (l - r) / 2);
  44576. var y1 = view.getRoutingCenterY(source);
  44577. var y2 = view.getRoutingCenterY(target);
  44578. if (pt != null)
  44579. {
  44580. if (pt.y >= source.y && pt.y <= source.y + source.height)
  44581. {
  44582. y1 = pt.y;
  44583. }
  44584. if (pt.y >= target.y && pt.y <= target.y + target.height)
  44585. {
  44586. y2 = pt.y;
  44587. }
  44588. }
  44589. if (!mxUtils.contains(target, x, y1) &&
  44590. !mxUtils.contains(source, x, y1))
  44591. {
  44592. result.push(new mxPoint(x, y1));
  44593. }
  44594. if (!mxUtils.contains(target, x, y2) &&
  44595. !mxUtils.contains(source, x, y2))
  44596. {
  44597. result.push(new mxPoint(x, y2));
  44598. }
  44599. if (result.length == 1)
  44600. {
  44601. if (pt != null)
  44602. {
  44603. if (!mxUtils.contains(target, x, pt.y) &&
  44604. !mxUtils.contains(source, x, pt.y))
  44605. {
  44606. result.push(new mxPoint(x, pt.y));
  44607. }
  44608. }
  44609. else
  44610. {
  44611. var t = Math.max(source.y, target.y);
  44612. var b = Math.min(source.y + source.height,
  44613. target.y + target.height);
  44614. result.push(new mxPoint(x, t + (b - t) / 2));
  44615. }
  44616. }
  44617. }
  44618. },
  44619. /**
  44620. * Function: TopToBottom
  44621. *
  44622. * Implements a horizontal elbow edge. See <EntityRelation> for a
  44623. * description of the parameters.
  44624. */
  44625. TopToBottom: function(state, source, target, points, result)
  44626. {
  44627. var view = state.view;
  44628. var pt = (points != null && points.length > 0) ? points[0] : null;
  44629. var pts = state.absolutePoints;
  44630. var p0 = pts[0];
  44631. var pe = pts[pts.length-1];
  44632. if (pt != null)
  44633. {
  44634. pt = view.transformControlPoint(state, pt);
  44635. }
  44636. if (p0 != null)
  44637. {
  44638. source = new mxCellState();
  44639. source.x = p0.x;
  44640. source.y = p0.y;
  44641. }
  44642. if (pe != null)
  44643. {
  44644. target = new mxCellState();
  44645. target.x = pe.x;
  44646. target.y = pe.y;
  44647. }
  44648. if (source != null && target != null)
  44649. {
  44650. var t = Math.max(source.y, target.y);
  44651. var b = Math.min(source.y + source.height,
  44652. target.y + target.height);
  44653. var x = view.getRoutingCenterX(source);
  44654. if (pt != null &&
  44655. pt.x >= source.x &&
  44656. pt.x <= source.x + source.width)
  44657. {
  44658. x = pt.x;
  44659. }
  44660. var y = (pt != null) ? pt.y : Math.round(b + (t - b) / 2);
  44661. if (!mxUtils.contains(target, x, y) &&
  44662. !mxUtils.contains(source, x, y))
  44663. {
  44664. result.push(new mxPoint(x, y));
  44665. }
  44666. if (pt != null &&
  44667. pt.x >= target.x &&
  44668. pt.x <= target.x + target.width)
  44669. {
  44670. x = pt.x;
  44671. }
  44672. else
  44673. {
  44674. x = view.getRoutingCenterX(target);
  44675. }
  44676. if (!mxUtils.contains(target, x, y) &&
  44677. !mxUtils.contains(source, x, y))
  44678. {
  44679. result.push(new mxPoint(x, y));
  44680. }
  44681. if (result.length == 1)
  44682. {
  44683. if (pt != null && result.length == 1)
  44684. {
  44685. if (!mxUtils.contains(target, pt.x, y) &&
  44686. !mxUtils.contains(source, pt.x, y))
  44687. {
  44688. result.push(new mxPoint(pt.x, y));
  44689. }
  44690. }
  44691. else
  44692. {
  44693. var l = Math.max(source.x, target.x);
  44694. var r = Math.min(source.x + source.width,
  44695. target.x + target.width);
  44696. result.push(new mxPoint(l + (r - l) / 2, y));
  44697. }
  44698. }
  44699. }
  44700. },
  44701. /**
  44702. * Function: SegmentConnector
  44703. *
  44704. * Implements an orthogonal edge style. Use <mxEdgeSegmentHandler>
  44705. * as an interactive handler for this style.
  44706. *
  44707. * state - <mxCellState> that represents the edge to be updated.
  44708. * sourceScaled - <mxCellState> that represents the source terminal.
  44709. * targetScaled - <mxCellState> that represents the target terminal.
  44710. * controlHints - List of relative control points.
  44711. * result - Array of <mxPoints> that represent the actual points of the
  44712. * edge.
  44713. *
  44714. */
  44715. SegmentConnector: function(state, sourceScaled, targetScaled, controlHints, result)
  44716. {
  44717. // Creates array of all way- and terminalpoints
  44718. var pts = mxEdgeStyle.scalePointArray(state.absolutePoints, state.view.scale);
  44719. var source = mxEdgeStyle.scaleCellState(sourceScaled, state.view.scale);
  44720. var target = mxEdgeStyle.scaleCellState(targetScaled, state.view.scale);
  44721. var tol = 1;
  44722. // Whether the first segment outgoing from the source end is horizontal
  44723. var lastPushed = (result.length > 0) ? result[0] : null;
  44724. var horizontal = true;
  44725. var hint = null;
  44726. // Adds waypoints only if outside of tolerance
  44727. function pushPoint(pt)
  44728. {
  44729. pt.x = Math.round(pt.x * state.view.scale * 10) / 10;
  44730. pt.y = Math.round(pt.y * state.view.scale * 10) / 10;
  44731. if (lastPushed == null || Math.abs(lastPushed.x - pt.x) >= tol || Math.abs(lastPushed.y - pt.y) >= Math.max(1, state.view.scale))
  44732. {
  44733. result.push(pt);
  44734. lastPushed = pt;
  44735. }
  44736. return lastPushed;
  44737. };
  44738. // Adds the first point
  44739. var pt = pts[0];
  44740. if (pt == null && source != null)
  44741. {
  44742. pt = new mxPoint(state.view.getRoutingCenterX(source), state.view.getRoutingCenterY(source));
  44743. }
  44744. else if (pt != null)
  44745. {
  44746. pt = pt.clone();
  44747. }
  44748. var lastInx = pts.length - 1;
  44749. // Adds the waypoints
  44750. if (controlHints != null && controlHints.length > 0)
  44751. {
  44752. // Converts all hints and removes nulls
  44753. var hints = [];
  44754. for (var i = 0; i < controlHints.length; i++)
  44755. {
  44756. var tmp = state.view.transformControlPoint(state, controlHints[i], true);
  44757. if (tmp != null)
  44758. {
  44759. hints.push(tmp);
  44760. }
  44761. }
  44762. if (hints.length == 0)
  44763. {
  44764. return;
  44765. }
  44766. // Aligns source and target hint to fixed points
  44767. if (pt != null && hints[0] != null)
  44768. {
  44769. if (Math.abs(hints[0].x - pt.x) < tol)
  44770. {
  44771. hints[0].x = pt.x;
  44772. }
  44773. if (Math.abs(hints[0].y - pt.y) < tol)
  44774. {
  44775. hints[0].y = pt.y;
  44776. }
  44777. }
  44778. var pe = pts[lastInx];
  44779. if (pe != null && hints[hints.length - 1] != null)
  44780. {
  44781. if (Math.abs(hints[hints.length - 1].x - pe.x) < tol)
  44782. {
  44783. hints[hints.length - 1].x = pe.x;
  44784. }
  44785. if (Math.abs(hints[hints.length - 1].y - pe.y) < tol)
  44786. {
  44787. hints[hints.length - 1].y = pe.y;
  44788. }
  44789. }
  44790. hint = hints[0];
  44791. var currentTerm = source;
  44792. var currentPt = pts[0];
  44793. var hozChan = false;
  44794. var vertChan = false;
  44795. var currentHint = hint;
  44796. if (currentPt != null)
  44797. {
  44798. currentTerm = null;
  44799. }
  44800. // Check for alignment with fixed points and with channels
  44801. // at source and target segments only
  44802. for (var i = 0; i < 2; i++)
  44803. {
  44804. var fixedVertAlign = currentPt != null && currentPt.x == currentHint.x;
  44805. var fixedHozAlign = currentPt != null && currentPt.y == currentHint.y;
  44806. var inHozChan = currentTerm != null && (currentHint.y >= currentTerm.y &&
  44807. currentHint.y <= currentTerm.y + currentTerm.height);
  44808. var inVertChan = currentTerm != null && (currentHint.x >= currentTerm.x &&
  44809. currentHint.x <= currentTerm.x + currentTerm.width);
  44810. hozChan = fixedHozAlign || (currentPt == null && inHozChan);
  44811. vertChan = fixedVertAlign || (currentPt == null && inVertChan);
  44812. // If the current hint falls in both the hor and vert channels in the case
  44813. // of a floating port, or if the hint is exactly co-incident with a
  44814. // fixed point, ignore the source and try to work out the orientation
  44815. // from the target end
  44816. if (i==0 && ((hozChan && vertChan) || (fixedVertAlign && fixedHozAlign)))
  44817. {
  44818. }
  44819. else
  44820. {
  44821. if (currentPt != null && (!fixedHozAlign && !fixedVertAlign) && (inHozChan || inVertChan))
  44822. {
  44823. horizontal = inHozChan ? false : true;
  44824. break;
  44825. }
  44826. if (vertChan || hozChan)
  44827. {
  44828. horizontal = hozChan;
  44829. if (i == 1)
  44830. {
  44831. // Work back from target end
  44832. horizontal = hints.length % 2 == 0 ? hozChan : vertChan;
  44833. }
  44834. break;
  44835. }
  44836. }
  44837. currentTerm = target;
  44838. currentPt = pts[lastInx];
  44839. if (currentPt != null)
  44840. {
  44841. currentTerm = null;
  44842. }
  44843. currentHint = hints[hints.length - 1];
  44844. if (fixedVertAlign && fixedHozAlign)
  44845. {
  44846. hints = hints.slice(1);
  44847. }
  44848. }
  44849. if (horizontal && ((pts[0] != null && pts[0].y != hint.y) ||
  44850. (pts[0] == null && source != null &&
  44851. (hint.y < source.y || hint.y > source.y + source.height))))
  44852. {
  44853. pushPoint(new mxPoint(pt.x, hint.y));
  44854. }
  44855. else if (!horizontal && ((pts[0] != null && pts[0].x != hint.x) ||
  44856. (pts[0] == null && source != null &&
  44857. (hint.x < source.x || hint.x > source.x + source.width))))
  44858. {
  44859. pushPoint(new mxPoint(hint.x, pt.y));
  44860. }
  44861. if (horizontal)
  44862. {
  44863. pt.y = hint.y;
  44864. }
  44865. else
  44866. {
  44867. pt.x = hint.x;
  44868. }
  44869. for (var i = 0; i < hints.length; i++)
  44870. {
  44871. horizontal = !horizontal;
  44872. hint = hints[i];
  44873. // mxLog.show();
  44874. // mxLog.debug('hint', i, hint.x, hint.y);
  44875. if (horizontal)
  44876. {
  44877. pt.y = hint.y;
  44878. }
  44879. else
  44880. {
  44881. pt.x = hint.x;
  44882. }
  44883. pushPoint(pt.clone());
  44884. }
  44885. }
  44886. else
  44887. {
  44888. hint = pt;
  44889. // FIXME: First click in connect preview toggles orientation
  44890. horizontal = true;
  44891. }
  44892. // Adds the last point
  44893. pt = pts[lastInx];
  44894. if (pt == null && target != null)
  44895. {
  44896. pt = new mxPoint(state.view.getRoutingCenterX(target), state.view.getRoutingCenterY(target));
  44897. }
  44898. if (pt != null)
  44899. {
  44900. if (hint != null)
  44901. {
  44902. if (horizontal && ((pts[lastInx] != null && pts[lastInx].y != hint.y) ||
  44903. (pts[lastInx] == null && target != null &&
  44904. (hint.y < target.y || hint.y > target.y + target.height))))
  44905. {
  44906. pushPoint(new mxPoint(pt.x, hint.y));
  44907. }
  44908. else if (!horizontal && ((pts[lastInx] != null && pts[lastInx].x != hint.x) ||
  44909. (pts[lastInx] == null && target != null &&
  44910. (hint.x < target.x || hint.x > target.x + target.width))))
  44911. {
  44912. pushPoint(new mxPoint(hint.x, pt.y));
  44913. }
  44914. }
  44915. }
  44916. // Removes bends inside the source terminal for floating ports
  44917. if (pts[0] == null && source != null)
  44918. {
  44919. while (result.length > 1 && result[1] != null &&
  44920. mxUtils.contains(source, result[1].x, result[1].y))
  44921. {
  44922. result.splice(1, 1);
  44923. }
  44924. }
  44925. // Removes bends inside the target terminal
  44926. if (pts[lastInx] == null && target != null)
  44927. {
  44928. while (result.length > 1 && result[result.length - 1] != null &&
  44929. mxUtils.contains(target, result[result.length - 1].x, result[result.length - 1].y))
  44930. {
  44931. result.splice(result.length - 1, 1);
  44932. }
  44933. }
  44934. // Removes last point if inside tolerance with end point
  44935. if (pe != null && result[result.length - 1] != null &&
  44936. Math.abs(pe.x - result[result.length - 1].x) <= tol &&
  44937. Math.abs(pe.y - result[result.length - 1].y) <= tol)
  44938. {
  44939. result.splice(result.length - 1, 1);
  44940. // Lines up second last point in result with end point
  44941. if (result[result.length - 1] != null)
  44942. {
  44943. if (Math.abs(result[result.length - 1].x - pe.x) < tol)
  44944. {
  44945. result[result.length - 1].x = pe.x;
  44946. }
  44947. if (Math.abs(result[result.length - 1].y - pe.y) < tol)
  44948. {
  44949. result[result.length - 1].y = pe.y;
  44950. }
  44951. }
  44952. }
  44953. },
  44954. orthBuffer: 10,
  44955. orthPointsFallback: true,
  44956. dirVectors: [ [ -1, 0 ],
  44957. [ 0, -1 ], [ 1, 0 ], [ 0, 1 ], [ -1, 0 ], [ 0, -1 ], [ 1, 0 ] ],
  44958. wayPoints1: [ [ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0],
  44959. [ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0] ],
  44960. routePatterns: [
  44961. [ [ 513, 2308, 2081, 2562 ], [ 513, 1090, 514, 2184, 2114, 2561 ],
  44962. [ 513, 1090, 514, 2564, 2184, 2562 ],
  44963. [ 513, 2308, 2561, 1090, 514, 2568, 2308 ] ],
  44964. [ [ 514, 1057, 513, 2308, 2081, 2562 ], [ 514, 2184, 2114, 2561 ],
  44965. [ 514, 2184, 2562, 1057, 513, 2564, 2184 ],
  44966. [ 514, 1057, 513, 2568, 2308, 2561 ] ],
  44967. [ [ 1090, 514, 1057, 513, 2308, 2081, 2562 ], [ 2114, 2561 ],
  44968. [ 1090, 2562, 1057, 513, 2564, 2184 ],
  44969. [ 1090, 514, 1057, 513, 2308, 2561, 2568 ] ],
  44970. [ [ 2081, 2562 ], [ 1057, 513, 1090, 514, 2184, 2114, 2561 ],
  44971. [ 1057, 513, 1090, 514, 2184, 2562, 2564 ],
  44972. [ 1057, 2561, 1090, 514, 2568, 2308 ] ] ],
  44973. inlineRoutePatterns: [
  44974. [ null, [ 2114, 2568 ], null, null ],
  44975. [ null, [ 514, 2081, 2114, 2568 ] , null, null ],
  44976. [ null, [ 2114, 2561 ], null, null ],
  44977. [ [ 2081, 2562 ], [ 1057, 2114, 2568 ],
  44978. [ 2184, 2562 ],
  44979. null ] ],
  44980. vertexSeperations: [],
  44981. limits: [
  44982. [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  44983. [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ],
  44984. LEFT_MASK: 32,
  44985. TOP_MASK: 64,
  44986. RIGHT_MASK: 128,
  44987. BOTTOM_MASK: 256,
  44988. LEFT: 1,
  44989. TOP: 2,
  44990. RIGHT: 4,
  44991. BOTTOM: 8,
  44992. // TODO remove magic numbers
  44993. SIDE_MASK: 480,
  44994. //mxEdgeStyle.LEFT_MASK | mxEdgeStyle.TOP_MASK | mxEdgeStyle.RIGHT_MASK
  44995. //| mxEdgeStyle.BOTTOM_MASK,
  44996. CENTER_MASK: 512,
  44997. SOURCE_MASK: 1024,
  44998. TARGET_MASK: 2048,
  44999. VERTEX_MASK: 3072,
  45000. // mxEdgeStyle.SOURCE_MASK | mxEdgeStyle.TARGET_MASK,
  45001. getJettySize: function(state, isSource)
  45002. {
  45003. var value = mxUtils.getValue(state.style, (isSource) ? mxConstants.STYLE_SOURCE_JETTY_SIZE :
  45004. mxConstants.STYLE_TARGET_JETTY_SIZE, mxUtils.getValue(state.style,
  45005. mxConstants.STYLE_JETTY_SIZE, mxEdgeStyle.orthBuffer));
  45006. if (value == 'auto')
  45007. {
  45008. // Computes the automatic jetty size
  45009. var type = mxUtils.getValue(state.style, (isSource) ? mxConstants.STYLE_STARTARROW : mxConstants.STYLE_ENDARROW, mxConstants.NONE);
  45010. if (type != mxConstants.NONE)
  45011. {
  45012. var size = mxUtils.getNumber(state.style, (isSource) ? mxConstants.STYLE_STARTSIZE : mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE);
  45013. value = Math.max(2, Math.ceil((size + mxEdgeStyle.orthBuffer) / mxEdgeStyle.orthBuffer)) * mxEdgeStyle.orthBuffer;
  45014. }
  45015. else
  45016. {
  45017. value = 2 * mxEdgeStyle.orthBuffer;
  45018. }
  45019. }
  45020. return value;
  45021. },
  45022. /**
  45023. * Function: scalePointArray
  45024. *
  45025. * Scales an array of <mxPoint>
  45026. *
  45027. * Parameters:
  45028. *
  45029. * points - array of <mxPoint> to scale
  45030. * scale - the scaling to divide by
  45031. *
  45032. */
  45033. scalePointArray: function(points, scale)
  45034. {
  45035. var result = [];
  45036. if (points != null)
  45037. {
  45038. for (var i = 0; i < points.length; i++)
  45039. {
  45040. if (points[i] != null)
  45041. {
  45042. var pt = new mxPoint(Math.round(points[i].x / scale * 10) / 10,
  45043. Math.round(points[i].y / scale * 10) / 10);
  45044. result[i] = pt;
  45045. }
  45046. else
  45047. {
  45048. result[i] = null;
  45049. }
  45050. }
  45051. }
  45052. else
  45053. {
  45054. result = null;
  45055. }
  45056. return result;
  45057. },
  45058. /**
  45059. * Function: scaleCellState
  45060. *
  45061. * Scales an <mxCellState>
  45062. *
  45063. * Parameters:
  45064. *
  45065. * state - <mxCellState> to scale
  45066. * scale - the scaling to divide by
  45067. *
  45068. */
  45069. scaleCellState: function(state, scale)
  45070. {
  45071. var result = null;
  45072. if (state != null)
  45073. {
  45074. result = state.clone();
  45075. result.setRect(Math.round(state.x / scale * 10) / 10,
  45076. Math.round(state.y / scale * 10) / 10,
  45077. Math.round(state.width / scale * 10) / 10,
  45078. Math.round(state.height / scale * 10) / 10);
  45079. }
  45080. else
  45081. {
  45082. result = null;
  45083. }
  45084. return result;
  45085. },
  45086. /**
  45087. * Function: OrthConnector
  45088. *
  45089. * Implements a local orthogonal router between the given
  45090. * cells.
  45091. *
  45092. * Parameters:
  45093. *
  45094. * state - <mxCellState> that represents the edge to be updated.
  45095. * sourceScaled - <mxCellState> that represents the source terminal.
  45096. * targetScaled - <mxCellState> that represents the target terminal.
  45097. * controlHints - List of relative control points.
  45098. * result - Array of <mxPoints> that represent the actual points of the
  45099. * edge.
  45100. *
  45101. */
  45102. OrthConnector: function(state, sourceScaled, targetScaled, controlHints, result)
  45103. {
  45104. var graph = state.view.graph;
  45105. var sourceEdge = source == null ? false : graph.getModel().isEdge(source.cell);
  45106. var targetEdge = target == null ? false : graph.getModel().isEdge(target.cell);
  45107. var pts = mxEdgeStyle.scalePointArray(state.absolutePoints, state.view.scale);
  45108. var source = mxEdgeStyle.scaleCellState(sourceScaled, state.view.scale);
  45109. var target = mxEdgeStyle.scaleCellState(targetScaled, state.view.scale);
  45110. var p0 = pts[0];
  45111. var pe = pts[pts.length-1];
  45112. var sourceX = source != null ? source.x : p0.x;
  45113. var sourceY = source != null ? source.y : p0.y;
  45114. var sourceWidth = source != null ? source.width : 0;
  45115. var sourceHeight = source != null ? source.height : 0;
  45116. var targetX = target != null ? target.x : pe.x;
  45117. var targetY = target != null ? target.y : pe.y;
  45118. var targetWidth = target != null ? target.width : 0;
  45119. var targetHeight = target != null ? target.height : 0;
  45120. var sourceBuffer = mxEdgeStyle.getJettySize(state, true);
  45121. var targetBuffer = mxEdgeStyle.getJettySize(state, false);
  45122. //console.log('sourceBuffer', sourceBuffer);
  45123. //console.log('targetBuffer', targetBuffer);
  45124. // Workaround for loop routing within buffer zone
  45125. if (source != null && target == source)
  45126. {
  45127. targetBuffer = Math.max(sourceBuffer, targetBuffer);
  45128. sourceBuffer = targetBuffer;
  45129. }
  45130. var totalBuffer = targetBuffer + sourceBuffer;
  45131. // console.log('totalBuffer', totalBuffer);
  45132. var tooShort = false;
  45133. // Checks minimum distance for fixed points and falls back to segment connector
  45134. if (p0 != null && pe != null)
  45135. {
  45136. var dx = pe.x - p0.x;
  45137. var dy = pe.y - p0.y;
  45138. tooShort = dx * dx + dy * dy < totalBuffer * totalBuffer;
  45139. }
  45140. if (tooShort || (mxEdgeStyle.orthPointsFallback && (controlHints != null &&
  45141. controlHints.length > 0)) || sourceEdge || targetEdge)
  45142. {
  45143. mxEdgeStyle.SegmentConnector(state, sourceScaled, targetScaled, controlHints, result);
  45144. return;
  45145. }
  45146. // Determine the side(s) of the source and target vertices
  45147. // that the edge may connect to
  45148. // portConstraint [source, target]
  45149. var portConstraint = [mxConstants.DIRECTION_MASK_ALL, mxConstants.DIRECTION_MASK_ALL];
  45150. var rotation = 0;
  45151. if (source != null)
  45152. {
  45153. portConstraint[0] = mxUtils.getPortConstraints(source, state, true,
  45154. mxConstants.DIRECTION_MASK_ALL);
  45155. rotation = mxUtils.getValue(source.style, mxConstants.STYLE_ROTATION, 0);
  45156. //console.log('source rotation', rotation);
  45157. if (rotation != 0)
  45158. {
  45159. var newRect = mxUtils.getBoundingBox(new mxRectangle(sourceX, sourceY, sourceWidth, sourceHeight), rotation);
  45160. sourceX = newRect.x;
  45161. sourceY = newRect.y;
  45162. sourceWidth = newRect.width;
  45163. sourceHeight = newRect.height;
  45164. }
  45165. }
  45166. if (target != null)
  45167. {
  45168. portConstraint[1] = mxUtils.getPortConstraints(target, state, false,
  45169. mxConstants.DIRECTION_MASK_ALL);
  45170. rotation = mxUtils.getValue(target.style, mxConstants.STYLE_ROTATION, 0);
  45171. //console.log('target rotation', rotation);
  45172. if (rotation != 0)
  45173. {
  45174. var newRect = mxUtils.getBoundingBox(new mxRectangle(targetX, targetY, targetWidth, targetHeight), rotation);
  45175. targetX = newRect.x;
  45176. targetY = newRect.y;
  45177. targetWidth = newRect.width;
  45178. targetHeight = newRect.height;
  45179. }
  45180. }
  45181. //console.log('source' , sourceX, sourceY, sourceWidth, sourceHeight);
  45182. //console.log('targetX' , targetX, targetY, targetWidth, targetHeight);
  45183. var dir = [0, 0];
  45184. // Work out which faces of the vertices present against each other
  45185. // in a way that would allow a 3-segment connection if port constraints
  45186. // permitted.
  45187. // geo -> [source, target] [x, y, width, height]
  45188. var geo = [ [sourceX, sourceY, sourceWidth, sourceHeight] ,
  45189. [targetX, targetY, targetWidth, targetHeight] ];
  45190. var buffer = [sourceBuffer, targetBuffer];
  45191. for (var i = 0; i < 2; i++)
  45192. {
  45193. mxEdgeStyle.limits[i][1] = geo[i][0] - buffer[i];
  45194. mxEdgeStyle.limits[i][2] = geo[i][1] - buffer[i];
  45195. mxEdgeStyle.limits[i][4] = geo[i][0] + geo[i][2] + buffer[i];
  45196. mxEdgeStyle.limits[i][8] = geo[i][1] + geo[i][3] + buffer[i];
  45197. }
  45198. // Work out which quad the target is in
  45199. var sourceCenX = geo[0][0] + geo[0][2] / 2.0;
  45200. var sourceCenY = geo[0][1] + geo[0][3] / 2.0;
  45201. var targetCenX = geo[1][0] + geo[1][2] / 2.0;
  45202. var targetCenY = geo[1][1] + geo[1][3] / 2.0;
  45203. var dx = sourceCenX - targetCenX;
  45204. var dy = sourceCenY - targetCenY;
  45205. var quad = 0;
  45206. // 0 | 1
  45207. // -----
  45208. // 3 | 2
  45209. if (dx < 0)
  45210. {
  45211. if (dy < 0)
  45212. {
  45213. quad = 2;
  45214. }
  45215. else
  45216. {
  45217. quad = 1;
  45218. }
  45219. }
  45220. else
  45221. {
  45222. if (dy <= 0)
  45223. {
  45224. quad = 3;
  45225. // Special case on x = 0 and negative y
  45226. if (dx == 0)
  45227. {
  45228. quad = 2;
  45229. }
  45230. }
  45231. }
  45232. //console.log('quad', quad);
  45233. // Check for connection constraints
  45234. var currentTerm = null;
  45235. if (source != null)
  45236. {
  45237. currentTerm = p0;
  45238. }
  45239. var constraint = [ [0.5, 0.5] , [0.5, 0.5] ];
  45240. for (var i = 0; i < 2; i++)
  45241. {
  45242. if (currentTerm != null)
  45243. {
  45244. constraint[i][0] = (currentTerm.x - geo[i][0]) / geo[i][2];
  45245. if (Math.abs(currentTerm.x - geo[i][0]) <= 1)
  45246. {
  45247. dir[i] = mxConstants.DIRECTION_MASK_WEST;
  45248. }
  45249. else if (Math.abs(currentTerm.x - geo[i][0] - geo[i][2]) <= 1)
  45250. {
  45251. dir[i] = mxConstants.DIRECTION_MASK_EAST;
  45252. }
  45253. constraint[i][1] = (currentTerm.y - geo[i][1]) / geo[i][3];
  45254. if (Math.abs(currentTerm.y - geo[i][1]) <= 1)
  45255. {
  45256. dir[i] = mxConstants.DIRECTION_MASK_NORTH;
  45257. }
  45258. else if (Math.abs(currentTerm.y - geo[i][1] - geo[i][3]) <= 1)
  45259. {
  45260. dir[i] = mxConstants.DIRECTION_MASK_SOUTH;
  45261. }
  45262. }
  45263. currentTerm = null;
  45264. if (target != null)
  45265. {
  45266. currentTerm = pe;
  45267. }
  45268. }
  45269. var sourceTopDist = geo[0][1] - (geo[1][1] + geo[1][3]);
  45270. var sourceLeftDist = geo[0][0] - (geo[1][0] + geo[1][2]);
  45271. var sourceBottomDist = geo[1][1] - (geo[0][1] + geo[0][3]);
  45272. var sourceRightDist = geo[1][0] - (geo[0][0] + geo[0][2]);
  45273. mxEdgeStyle.vertexSeperations[1] = Math.max(sourceLeftDist - totalBuffer, 0);
  45274. mxEdgeStyle.vertexSeperations[2] = Math.max(sourceTopDist - totalBuffer, 0);
  45275. mxEdgeStyle.vertexSeperations[4] = Math.max(sourceBottomDist - totalBuffer, 0);
  45276. mxEdgeStyle.vertexSeperations[3] = Math.max(sourceRightDist - totalBuffer, 0);
  45277. //==============================================================
  45278. // Start of source and target direction determination
  45279. // Work through the preferred orientations by relative positioning
  45280. // of the vertices and list them in preferred and available order
  45281. var dirPref = [];
  45282. var horPref = [];
  45283. var vertPref = [];
  45284. horPref[0] = (sourceLeftDist >= sourceRightDist) ? mxConstants.DIRECTION_MASK_WEST
  45285. : mxConstants.DIRECTION_MASK_EAST;
  45286. vertPref[0] = (sourceTopDist >= sourceBottomDist) ? mxConstants.DIRECTION_MASK_NORTH
  45287. : mxConstants.DIRECTION_MASK_SOUTH;
  45288. horPref[1] = mxUtils.reversePortConstraints(horPref[0]);
  45289. vertPref[1] = mxUtils.reversePortConstraints(vertPref[0]);
  45290. var preferredHorizDist = sourceLeftDist >= sourceRightDist ? sourceLeftDist
  45291. : sourceRightDist;
  45292. var preferredVertDist = sourceTopDist >= sourceBottomDist ? sourceTopDist
  45293. : sourceBottomDist;
  45294. var prefOrdering = [ [0, 0] , [0, 0] ];
  45295. var preferredOrderSet = false;
  45296. // If the preferred port isn't available, switch it
  45297. for (var i = 0; i < 2; i++)
  45298. {
  45299. if (dir[i] != 0x0)
  45300. {
  45301. continue;
  45302. }
  45303. if ((horPref[i] & portConstraint[i]) == 0)
  45304. {
  45305. horPref[i] = mxUtils.reversePortConstraints(horPref[i]);
  45306. }
  45307. if ((vertPref[i] & portConstraint[i]) == 0)
  45308. {
  45309. vertPref[i] = mxUtils
  45310. .reversePortConstraints(vertPref[i]);
  45311. }
  45312. prefOrdering[i][0] = vertPref[i];
  45313. prefOrdering[i][1] = horPref[i];
  45314. }
  45315. if (preferredVertDist > 0
  45316. && preferredHorizDist > 0)
  45317. {
  45318. // Possibility of two segment edge connection
  45319. if (((horPref[0] & portConstraint[0]) > 0)
  45320. && ((vertPref[1] & portConstraint[1]) > 0))
  45321. {
  45322. prefOrdering[0][0] = horPref[0];
  45323. prefOrdering[0][1] = vertPref[0];
  45324. prefOrdering[1][0] = vertPref[1];
  45325. prefOrdering[1][1] = horPref[1];
  45326. preferredOrderSet = true;
  45327. }
  45328. else if (((vertPref[0] & portConstraint[0]) > 0)
  45329. && ((horPref[1] & portConstraint[1]) > 0))
  45330. {
  45331. prefOrdering[0][0] = vertPref[0];
  45332. prefOrdering[0][1] = horPref[0];
  45333. prefOrdering[1][0] = horPref[1];
  45334. prefOrdering[1][1] = vertPref[1];
  45335. preferredOrderSet = true;
  45336. }
  45337. }
  45338. if (preferredVertDist > 0 && !preferredOrderSet)
  45339. {
  45340. prefOrdering[0][0] = vertPref[0];
  45341. prefOrdering[0][1] = horPref[0];
  45342. prefOrdering[1][0] = vertPref[1];
  45343. prefOrdering[1][1] = horPref[1];
  45344. preferredOrderSet = true;
  45345. }
  45346. if (preferredHorizDist > 0 && !preferredOrderSet)
  45347. {
  45348. prefOrdering[0][0] = horPref[0];
  45349. prefOrdering[0][1] = vertPref[0];
  45350. prefOrdering[1][0] = horPref[1];
  45351. prefOrdering[1][1] = vertPref[1];
  45352. preferredOrderSet = true;
  45353. }
  45354. // The source and target prefs are now an ordered list of
  45355. // the preferred port selections
  45356. // If the list contains gaps, compact it
  45357. for (var i = 0; i < 2; i++)
  45358. {
  45359. if (dir[i] != 0x0)
  45360. {
  45361. continue;
  45362. }
  45363. if ((prefOrdering[i][0] & portConstraint[i]) == 0)
  45364. {
  45365. prefOrdering[i][0] = prefOrdering[i][1];
  45366. }
  45367. dirPref[i] = prefOrdering[i][0] & portConstraint[i];
  45368. dirPref[i] |= (prefOrdering[i][1] & portConstraint[i]) << 8;
  45369. dirPref[i] |= (prefOrdering[1 - i][i] & portConstraint[i]) << 16;
  45370. dirPref[i] |= (prefOrdering[1 - i][1 - i] & portConstraint[i]) << 24;
  45371. if ((dirPref[i] & 0xF) == 0)
  45372. {
  45373. dirPref[i] = dirPref[i] << 8;
  45374. }
  45375. if ((dirPref[i] & 0xF00) == 0)
  45376. {
  45377. dirPref[i] = (dirPref[i] & 0xF) | dirPref[i] >> 8;
  45378. }
  45379. if ((dirPref[i] & 0xF0000) == 0)
  45380. {
  45381. dirPref[i] = (dirPref[i] & 0xFFFF)
  45382. | ((dirPref[i] & 0xF000000) >> 8);
  45383. }
  45384. dir[i] = dirPref[i] & 0xF;
  45385. if (portConstraint[i] == mxConstants.DIRECTION_MASK_WEST
  45386. || portConstraint[i] == mxConstants.DIRECTION_MASK_NORTH
  45387. || portConstraint[i] == mxConstants.DIRECTION_MASK_EAST
  45388. || portConstraint[i] == mxConstants.DIRECTION_MASK_SOUTH)
  45389. {
  45390. dir[i] = portConstraint[i];
  45391. }
  45392. }
  45393. //==============================================================
  45394. // End of source and target direction determination
  45395. var sourceIndex = dir[0] == mxConstants.DIRECTION_MASK_EAST ? 3
  45396. : dir[0];
  45397. var targetIndex = dir[1] == mxConstants.DIRECTION_MASK_EAST ? 3
  45398. : dir[1];
  45399. sourceIndex -= quad;
  45400. targetIndex -= quad;
  45401. if (sourceIndex < 1)
  45402. {
  45403. sourceIndex += 4;
  45404. }
  45405. if (targetIndex < 1)
  45406. {
  45407. targetIndex += 4;
  45408. }
  45409. var routePattern = mxEdgeStyle.routePatterns[sourceIndex - 1][targetIndex - 1];
  45410. //console.log('routePattern', routePattern);
  45411. mxEdgeStyle.wayPoints1[0][0] = geo[0][0];
  45412. mxEdgeStyle.wayPoints1[0][1] = geo[0][1];
  45413. switch (dir[0])
  45414. {
  45415. case mxConstants.DIRECTION_MASK_WEST:
  45416. mxEdgeStyle.wayPoints1[0][0] -= sourceBuffer;
  45417. mxEdgeStyle.wayPoints1[0][1] += constraint[0][1] * geo[0][3];
  45418. break;
  45419. case mxConstants.DIRECTION_MASK_SOUTH:
  45420. mxEdgeStyle.wayPoints1[0][0] += constraint[0][0] * geo[0][2];
  45421. mxEdgeStyle.wayPoints1[0][1] += geo[0][3] + sourceBuffer;
  45422. break;
  45423. case mxConstants.DIRECTION_MASK_EAST:
  45424. mxEdgeStyle.wayPoints1[0][0] += geo[0][2] + sourceBuffer;
  45425. mxEdgeStyle.wayPoints1[0][1] += constraint[0][1] * geo[0][3];
  45426. break;
  45427. case mxConstants.DIRECTION_MASK_NORTH:
  45428. mxEdgeStyle.wayPoints1[0][0] += constraint[0][0] * geo[0][2];
  45429. mxEdgeStyle.wayPoints1[0][1] -= sourceBuffer;
  45430. break;
  45431. }
  45432. var currentIndex = 0;
  45433. // Orientation, 0 horizontal, 1 vertical
  45434. var lastOrientation = (dir[0] & (mxConstants.DIRECTION_MASK_EAST | mxConstants.DIRECTION_MASK_WEST)) > 0 ? 0
  45435. : 1;
  45436. var initialOrientation = lastOrientation;
  45437. var currentOrientation = 0;
  45438. for (var i = 0; i < routePattern.length; i++)
  45439. {
  45440. var nextDirection = routePattern[i] & 0xF;
  45441. // Rotate the index of this direction by the quad
  45442. // to get the real direction
  45443. var directionIndex = nextDirection == mxConstants.DIRECTION_MASK_EAST ? 3
  45444. : nextDirection;
  45445. directionIndex += quad;
  45446. if (directionIndex > 4)
  45447. {
  45448. directionIndex -= 4;
  45449. }
  45450. var direction = mxEdgeStyle.dirVectors[directionIndex - 1];
  45451. currentOrientation = (directionIndex % 2 > 0) ? 0 : 1;
  45452. // Only update the current index if the point moved
  45453. // in the direction of the current segment move,
  45454. // otherwise the same point is moved until there is
  45455. // a segment direction change
  45456. if (currentOrientation != lastOrientation)
  45457. {
  45458. currentIndex++;
  45459. // Copy the previous way point into the new one
  45460. // We can't base the new position on index - 1
  45461. // because sometime elbows turn out not to exist,
  45462. // then we'd have to rewind.
  45463. mxEdgeStyle.wayPoints1[currentIndex][0] = mxEdgeStyle.wayPoints1[currentIndex - 1][0];
  45464. mxEdgeStyle.wayPoints1[currentIndex][1] = mxEdgeStyle.wayPoints1[currentIndex - 1][1];
  45465. }
  45466. var tar = (routePattern[i] & mxEdgeStyle.TARGET_MASK) > 0;
  45467. var sou = (routePattern[i] & mxEdgeStyle.SOURCE_MASK) > 0;
  45468. var side = (routePattern[i] & mxEdgeStyle.SIDE_MASK) >> 5;
  45469. side = side << quad;
  45470. if (side > 0xF)
  45471. {
  45472. side = side >> 4;
  45473. }
  45474. var center = (routePattern[i] & mxEdgeStyle.CENTER_MASK) > 0;
  45475. if ((sou || tar) && side < 9)
  45476. {
  45477. var limit = 0;
  45478. var souTar = sou ? 0 : 1;
  45479. if (center && currentOrientation == 0)
  45480. {
  45481. limit = geo[souTar][0] + constraint[souTar][0] * geo[souTar][2];
  45482. }
  45483. else if (center)
  45484. {
  45485. limit = geo[souTar][1] + constraint[souTar][1] * geo[souTar][3];
  45486. }
  45487. else
  45488. {
  45489. limit = mxEdgeStyle.limits[souTar][side];
  45490. }
  45491. if (currentOrientation == 0)
  45492. {
  45493. var lastX = mxEdgeStyle.wayPoints1[currentIndex][0];
  45494. var deltaX = (limit - lastX) * direction[0];
  45495. if (deltaX > 0)
  45496. {
  45497. mxEdgeStyle.wayPoints1[currentIndex][0] += direction[0]
  45498. * deltaX;
  45499. }
  45500. }
  45501. else
  45502. {
  45503. var lastY = mxEdgeStyle.wayPoints1[currentIndex][1];
  45504. var deltaY = (limit - lastY) * direction[1];
  45505. if (deltaY > 0)
  45506. {
  45507. mxEdgeStyle.wayPoints1[currentIndex][1] += direction[1]
  45508. * deltaY;
  45509. }
  45510. }
  45511. }
  45512. else if (center)
  45513. {
  45514. // Which center we're travelling to depend on the current direction
  45515. mxEdgeStyle.wayPoints1[currentIndex][0] += direction[0]
  45516. * Math.abs(mxEdgeStyle.vertexSeperations[directionIndex] / 2);
  45517. mxEdgeStyle.wayPoints1[currentIndex][1] += direction[1]
  45518. * Math.abs(mxEdgeStyle.vertexSeperations[directionIndex] / 2);
  45519. }
  45520. if (currentIndex > 0
  45521. && mxEdgeStyle.wayPoints1[currentIndex][currentOrientation] == mxEdgeStyle.wayPoints1[currentIndex - 1][currentOrientation])
  45522. {
  45523. currentIndex--;
  45524. }
  45525. else
  45526. {
  45527. lastOrientation = currentOrientation;
  45528. }
  45529. }
  45530. for (var i = 0; i <= currentIndex; i++)
  45531. {
  45532. if (i == currentIndex)
  45533. {
  45534. // Last point can cause last segment to be in
  45535. // same direction as jetty/approach. If so,
  45536. // check the number of points is consistent
  45537. // with the relative orientation of source and target
  45538. // jx. Same orientation requires an even
  45539. // number of turns (points), different requires
  45540. // odd.
  45541. var targetOrientation = (dir[1] & (mxConstants.DIRECTION_MASK_EAST | mxConstants.DIRECTION_MASK_WEST)) > 0 ? 0
  45542. : 1;
  45543. var sameOrient = targetOrientation == initialOrientation ? 0 : 1;
  45544. // (currentIndex + 1) % 2 is 0 for even number of points,
  45545. // 1 for odd
  45546. if (sameOrient != (currentIndex + 1) % 2)
  45547. {
  45548. // The last point isn't required
  45549. break;
  45550. }
  45551. }
  45552. result.push(new mxPoint(Math.round(mxEdgeStyle.wayPoints1[i][0] * state.view.scale * 10) / 10,
  45553. Math.round(mxEdgeStyle.wayPoints1[i][1] * state.view.scale * 10) / 10));
  45554. }
  45555. //console.log(result);
  45556. // Removes duplicates
  45557. var index = 1;
  45558. while (index < result.length)
  45559. {
  45560. if (result[index - 1] == null || result[index] == null ||
  45561. result[index - 1].x != result[index].x ||
  45562. result[index - 1].y != result[index].y)
  45563. {
  45564. index++;
  45565. }
  45566. else
  45567. {
  45568. result.splice(index, 1);
  45569. }
  45570. }
  45571. },
  45572. getRoutePattern: function(dir, quad, dx, dy)
  45573. {
  45574. var sourceIndex = dir[0] == mxConstants.DIRECTION_MASK_EAST ? 3
  45575. : dir[0];
  45576. var targetIndex = dir[1] == mxConstants.DIRECTION_MASK_EAST ? 3
  45577. : dir[1];
  45578. sourceIndex -= quad;
  45579. targetIndex -= quad;
  45580. if (sourceIndex < 1)
  45581. {
  45582. sourceIndex += 4;
  45583. }
  45584. if (targetIndex < 1)
  45585. {
  45586. targetIndex += 4;
  45587. }
  45588. var result = routePatterns[sourceIndex - 1][targetIndex - 1];
  45589. if (dx == 0 || dy == 0)
  45590. {
  45591. if (inlineRoutePatterns[sourceIndex - 1][targetIndex - 1] != null)
  45592. {
  45593. result = inlineRoutePatterns[sourceIndex - 1][targetIndex - 1];
  45594. }
  45595. }
  45596. return result;
  45597. }
  45598. };
  45599. /**
  45600. * Copyright (c) 2006-2015, JGraph Ltd
  45601. * Copyright (c) 2006-2015, Gaudenz Alder
  45602. */
  45603. var mxStyleRegistry =
  45604. {
  45605. /**
  45606. * Class: mxStyleRegistry
  45607. *
  45608. * Singleton class that acts as a global converter from string to object values
  45609. * in a style. This is currently only used to perimeters and edge styles.
  45610. *
  45611. * Variable: values
  45612. *
  45613. * Maps from strings to objects.
  45614. */
  45615. values: [],
  45616. /**
  45617. * Function: putValue
  45618. *
  45619. * Puts the given object into the registry under the given name.
  45620. */
  45621. putValue: function(name, obj)
  45622. {
  45623. mxStyleRegistry.values[name] = obj;
  45624. },
  45625. /**
  45626. * Function: getValue
  45627. *
  45628. * Returns the value associated with the given name.
  45629. */
  45630. getValue: function(name)
  45631. {
  45632. return mxStyleRegistry.values[name];
  45633. },
  45634. /**
  45635. * Function: getName
  45636. *
  45637. * Returns the name for the given value.
  45638. */
  45639. getName: function(value)
  45640. {
  45641. for (var key in mxStyleRegistry.values)
  45642. {
  45643. if (mxStyleRegistry.values[key] == value)
  45644. {
  45645. return key;
  45646. }
  45647. }
  45648. return null;
  45649. }
  45650. };
  45651. mxStyleRegistry.putValue(mxConstants.EDGESTYLE_ELBOW, mxEdgeStyle.ElbowConnector);
  45652. mxStyleRegistry.putValue(mxConstants.EDGESTYLE_ENTITY_RELATION, mxEdgeStyle.EntityRelation);
  45653. mxStyleRegistry.putValue(mxConstants.EDGESTYLE_LOOP, mxEdgeStyle.Loop);
  45654. mxStyleRegistry.putValue(mxConstants.EDGESTYLE_SIDETOSIDE, mxEdgeStyle.SideToSide);
  45655. mxStyleRegistry.putValue(mxConstants.EDGESTYLE_TOPTOBOTTOM, mxEdgeStyle.TopToBottom);
  45656. mxStyleRegistry.putValue(mxConstants.EDGESTYLE_ORTHOGONAL, mxEdgeStyle.OrthConnector);
  45657. mxStyleRegistry.putValue(mxConstants.EDGESTYLE_SEGMENT, mxEdgeStyle.SegmentConnector);
  45658. mxStyleRegistry.putValue(mxConstants.PERIMETER_ELLIPSE, mxPerimeter.EllipsePerimeter);
  45659. mxStyleRegistry.putValue(mxConstants.PERIMETER_RECTANGLE, mxPerimeter.RectanglePerimeter);
  45660. mxStyleRegistry.putValue(mxConstants.PERIMETER_RHOMBUS, mxPerimeter.RhombusPerimeter);
  45661. mxStyleRegistry.putValue(mxConstants.PERIMETER_TRIANGLE, mxPerimeter.TrianglePerimeter);
  45662. mxStyleRegistry.putValue(mxConstants.PERIMETER_HEXAGON, mxPerimeter.HexagonPerimeter);
  45663. /**
  45664. * Copyright (c) 2006-2015, JGraph Ltd
  45665. * Copyright (c) 2006-2015, Gaudenz Alder
  45666. */
  45667. /**
  45668. * Class: mxGraphView
  45669. *
  45670. * Extends <mxEventSource> to implement a view for a graph. This class is in
  45671. * charge of computing the absolute coordinates for the relative child
  45672. * geometries, the points for perimeters and edge styles and keeping them
  45673. * cached in <mxCellStates> for faster retrieval. The states are updated
  45674. * whenever the model or the view state (translate, scale) changes. The scale
  45675. * and translate are honoured in the bounds.
  45676. *
  45677. * Event: mxEvent.UNDO
  45678. *
  45679. * Fires after the root was changed in <setCurrentRoot>. The <code>edit</code>
  45680. * property contains the <mxUndoableEdit> which contains the
  45681. * <mxCurrentRootChange>.
  45682. *
  45683. * Event: mxEvent.SCALE_AND_TRANSLATE
  45684. *
  45685. * Fires after the scale and translate have been changed in <scaleAndTranslate>.
  45686. * The <code>scale</code>, <code>previousScale</code>, <code>translate</code>
  45687. * and <code>previousTranslate</code> properties contain the new and previous
  45688. * scale and translate, respectively.
  45689. *
  45690. * Event: mxEvent.SCALE
  45691. *
  45692. * Fires after the scale was changed in <setScale>. The <code>scale</code> and
  45693. * <code>previousScale</code> properties contain the new and previous scale.
  45694. *
  45695. * Event: mxEvent.TRANSLATE
  45696. *
  45697. * Fires after the translate was changed in <setTranslate>. The
  45698. * <code>translate</code> and <code>previousTranslate</code> properties contain
  45699. * the new and previous value for translate.
  45700. *
  45701. * Event: mxEvent.DOWN and mxEvent.UP
  45702. *
  45703. * Fire if the current root is changed by executing an <mxCurrentRootChange>.
  45704. * The event name depends on the location of the root in the cell hierarchy
  45705. * with respect to the current root. The <code>root</code> and
  45706. * <code>previous</code> properties contain the new and previous root,
  45707. * respectively.
  45708. *
  45709. * Constructor: mxGraphView
  45710. *
  45711. * Constructs a new view for the given <mxGraph>.
  45712. *
  45713. * Parameters:
  45714. *
  45715. * graph - Reference to the enclosing <mxGraph>.
  45716. */
  45717. function mxGraphView(graph)
  45718. {
  45719. this.graph = graph;
  45720. this.translate = new mxPoint();
  45721. this.graphBounds = new mxRectangle();
  45722. this.states = new mxDictionary();
  45723. };
  45724. /**
  45725. * Extends mxEventSource.
  45726. */
  45727. mxGraphView.prototype = new mxEventSource();
  45728. mxGraphView.prototype.constructor = mxGraphView;
  45729. /**
  45730. *
  45731. */
  45732. mxGraphView.prototype.EMPTY_POINT = new mxPoint();
  45733. /**
  45734. * Variable: doneResource
  45735. *
  45736. * Specifies the resource key for the status message after a long operation.
  45737. * If the resource for this key does not exist then the value is used as
  45738. * the status message. Default is 'done'.
  45739. */
  45740. mxGraphView.prototype.doneResource = (mxClient.language != 'none') ? 'done' : '';
  45741. /**
  45742. * Function: updatingDocumentResource
  45743. *
  45744. * Specifies the resource key for the status message while the document is
  45745. * being updated. If the resource for this key does not exist then the
  45746. * value is used as the status message. Default is 'updatingDocument'.
  45747. */
  45748. mxGraphView.prototype.updatingDocumentResource = (mxClient.language != 'none') ? 'updatingDocument' : '';
  45749. /**
  45750. * Variable: allowEval
  45751. *
  45752. * Specifies if string values in cell styles should be evaluated using
  45753. * <mxUtils.eval>. This will only be used if the string values can't be mapped
  45754. * to objects using <mxStyleRegistry>. Default is false. NOTE: Enabling this
  45755. * switch carries a possible security risk.
  45756. */
  45757. mxGraphView.prototype.allowEval = false;
  45758. /**
  45759. * Variable: captureDocumentGesture
  45760. *
  45761. * Specifies if a gesture should be captured when it goes outside of the
  45762. * graph container. Default is true.
  45763. */
  45764. mxGraphView.prototype.captureDocumentGesture = true;
  45765. /**
  45766. * Variable: optimizeVmlReflows
  45767. *
  45768. * Specifies if the <canvas> should be hidden while rendering in IE8 standards
  45769. * mode and quirks mode. This will significantly improve rendering performance.
  45770. * Default is true.
  45771. */
  45772. mxGraphView.prototype.optimizeVmlReflows = true;
  45773. /**
  45774. * Variable: rendering
  45775. *
  45776. * Specifies if shapes should be created, updated and destroyed using the
  45777. * methods of <mxCellRenderer> in <graph>. Default is true.
  45778. */
  45779. mxGraphView.prototype.rendering = true;
  45780. /**
  45781. * Variable: graph
  45782. *
  45783. * Reference to the enclosing <mxGraph>.
  45784. */
  45785. mxGraphView.prototype.graph = null;
  45786. /**
  45787. * Variable: currentRoot
  45788. *
  45789. * <mxCell> that acts as the root of the displayed cell hierarchy.
  45790. */
  45791. mxGraphView.prototype.currentRoot = null;
  45792. /**
  45793. * Variable: graphBounds
  45794. *
  45795. * <mxRectangle> that caches the scales, translated bounds of the current view.
  45796. */
  45797. mxGraphView.prototype.graphBounds = null;
  45798. /**
  45799. * Variable: scale
  45800. *
  45801. * Specifies the scale. Default is 1 (100%).
  45802. */
  45803. mxGraphView.prototype.scale = 1;
  45804. /**
  45805. * Variable: translate
  45806. *
  45807. * <mxPoint> that specifies the current translation. Default is a new
  45808. * empty <mxPoint>.
  45809. */
  45810. mxGraphView.prototype.translate = null;
  45811. /**
  45812. * Variable: states
  45813. *
  45814. * <mxDictionary> that maps from cell IDs to <mxCellStates>.
  45815. */
  45816. mxGraphView.prototype.states = null;
  45817. /**
  45818. * Variable: updateStyle
  45819. *
  45820. * Specifies if the style should be updated in each validation step. If this
  45821. * is false then the style is only updated if the state is created or if the
  45822. * style of the cell was changed. Default is false.
  45823. */
  45824. mxGraphView.prototype.updateStyle = false;
  45825. /**
  45826. * Variable: lastNode
  45827. *
  45828. * During validation, this contains the last DOM node that was processed.
  45829. */
  45830. mxGraphView.prototype.lastNode = null;
  45831. /**
  45832. * Variable: lastHtmlNode
  45833. *
  45834. * During validation, this contains the last HTML DOM node that was processed.
  45835. */
  45836. mxGraphView.prototype.lastHtmlNode = null;
  45837. /**
  45838. * Variable: lastForegroundNode
  45839. *
  45840. * During validation, this contains the last edge's DOM node that was processed.
  45841. */
  45842. mxGraphView.prototype.lastForegroundNode = null;
  45843. /**
  45844. * Variable: lastForegroundHtmlNode
  45845. *
  45846. * During validation, this contains the last edge HTML DOM node that was processed.
  45847. */
  45848. mxGraphView.prototype.lastForegroundHtmlNode = null;
  45849. /**
  45850. * Function: getGraphBounds
  45851. *
  45852. * Returns <graphBounds>.
  45853. */
  45854. mxGraphView.prototype.getGraphBounds = function()
  45855. {
  45856. return this.graphBounds;
  45857. };
  45858. /**
  45859. * Function: setGraphBounds
  45860. *
  45861. * Sets <graphBounds>.
  45862. */
  45863. mxGraphView.prototype.setGraphBounds = function(value)
  45864. {
  45865. this.graphBounds = value;
  45866. };
  45867. /**
  45868. * Function: getBounds
  45869. *
  45870. * Returns the union of all <mxCellStates> for the given array of <mxCells>.
  45871. *
  45872. * Parameters:
  45873. *
  45874. * cells - Array of <mxCells> whose bounds should be returned.
  45875. */
  45876. mxGraphView.prototype.getBounds = function(cells)
  45877. {
  45878. var result = null;
  45879. if (cells != null && cells.length > 0)
  45880. {
  45881. var model = this.graph.getModel();
  45882. for (var i = 0; i < cells.length; i++)
  45883. {
  45884. if (model.isVertex(cells[i]) || model.isEdge(cells[i]))
  45885. {
  45886. var state = this.getState(cells[i]);
  45887. if (state != null)
  45888. {
  45889. if (result == null)
  45890. {
  45891. result = mxRectangle.fromRectangle(state);
  45892. }
  45893. else
  45894. {
  45895. result.add(state);
  45896. }
  45897. }
  45898. }
  45899. }
  45900. }
  45901. return result;
  45902. };
  45903. /**
  45904. * Function: setCurrentRoot
  45905. *
  45906. * Sets and returns the current root and fires an <undo> event before
  45907. * calling <mxGraph.sizeDidChange>.
  45908. *
  45909. * Parameters:
  45910. *
  45911. * root - <mxCell> that specifies the root of the displayed cell hierarchy.
  45912. */
  45913. mxGraphView.prototype.setCurrentRoot = function(root)
  45914. {
  45915. if (this.currentRoot != root)
  45916. {
  45917. var change = new mxCurrentRootChange(this, root);
  45918. change.execute();
  45919. var edit = new mxUndoableEdit(this, true);
  45920. edit.add(change);
  45921. this.fireEvent(new mxEventObject(mxEvent.UNDO, 'edit', edit));
  45922. this.graph.sizeDidChange();
  45923. }
  45924. return root;
  45925. };
  45926. /**
  45927. * Function: scaleAndTranslate
  45928. *
  45929. * Sets the scale and translation and fires a <scale> and <translate> event
  45930. * before calling <revalidate> followed by <mxGraph.sizeDidChange>.
  45931. *
  45932. * Parameters:
  45933. *
  45934. * scale - Decimal value that specifies the new scale (1 is 100%).
  45935. * dx - X-coordinate of the translation.
  45936. * dy - Y-coordinate of the translation.
  45937. */
  45938. mxGraphView.prototype.scaleAndTranslate = function(scale, dx, dy)
  45939. {
  45940. var previousScale = this.scale;
  45941. var previousTranslate = new mxPoint(this.translate.x, this.translate.y);
  45942. if (this.scale != scale || this.translate.x != dx || this.translate.y != dy)
  45943. {
  45944. this.scale = scale;
  45945. this.translate.x = dx;
  45946. this.translate.y = dy;
  45947. if (this.isEventsEnabled())
  45948. {
  45949. this.viewStateChanged();
  45950. }
  45951. }
  45952. this.fireEvent(new mxEventObject(mxEvent.SCALE_AND_TRANSLATE,
  45953. 'scale', scale, 'previousScale', previousScale,
  45954. 'translate', this.translate, 'previousTranslate', previousTranslate));
  45955. };
  45956. /**
  45957. * Function: getScale
  45958. *
  45959. * Returns the <scale>.
  45960. */
  45961. mxGraphView.prototype.getScale = function()
  45962. {
  45963. return this.scale;
  45964. };
  45965. /**
  45966. * Function: setScale
  45967. *
  45968. * Sets the scale and fires a <scale> event before calling <revalidate> followed
  45969. * by <mxGraph.sizeDidChange>.
  45970. *
  45971. * Parameters:
  45972. *
  45973. * value - Decimal value that specifies the new scale (1 is 100%).
  45974. */
  45975. mxGraphView.prototype.setScale = function(value)
  45976. {
  45977. var previousScale = this.scale;
  45978. if (this.scale != value)
  45979. {
  45980. this.scale = value;
  45981. if (this.isEventsEnabled())
  45982. {
  45983. this.viewStateChanged();
  45984. }
  45985. }
  45986. this.fireEvent(new mxEventObject(mxEvent.SCALE,
  45987. 'scale', value, 'previousScale', previousScale));
  45988. };
  45989. /**
  45990. * Function: getTranslate
  45991. *
  45992. * Returns the <translate>.
  45993. */
  45994. mxGraphView.prototype.getTranslate = function()
  45995. {
  45996. return this.translate;
  45997. };
  45998. /**
  45999. * Function: setTranslate
  46000. *
  46001. * Sets the translation and fires a <translate> event before calling
  46002. * <revalidate> followed by <mxGraph.sizeDidChange>. The translation is the
  46003. * negative of the origin.
  46004. *
  46005. * Parameters:
  46006. *
  46007. * dx - X-coordinate of the translation.
  46008. * dy - Y-coordinate of the translation.
  46009. */
  46010. mxGraphView.prototype.setTranslate = function(dx, dy)
  46011. {
  46012. var previousTranslate = new mxPoint(this.translate.x, this.translate.y);
  46013. if (this.translate.x != dx || this.translate.y != dy)
  46014. {
  46015. this.translate.x = dx;
  46016. this.translate.y = dy;
  46017. if (this.isEventsEnabled())
  46018. {
  46019. this.viewStateChanged();
  46020. }
  46021. }
  46022. this.fireEvent(new mxEventObject(mxEvent.TRANSLATE,
  46023. 'translate', this.translate, 'previousTranslate', previousTranslate));
  46024. };
  46025. /**
  46026. * Function: viewStateChanged
  46027. *
  46028. * Invoked after <scale> and/or <translate> has changed.
  46029. */
  46030. mxGraphView.prototype.viewStateChanged = function()
  46031. {
  46032. this.revalidate();
  46033. this.graph.sizeDidChange();
  46034. };
  46035. /**
  46036. * Function: refresh
  46037. *
  46038. * Clears the view if <currentRoot> is not null and revalidates.
  46039. */
  46040. mxGraphView.prototype.refresh = function()
  46041. {
  46042. if (this.currentRoot != null)
  46043. {
  46044. this.clear();
  46045. }
  46046. this.revalidate();
  46047. };
  46048. /**
  46049. * Function: revalidate
  46050. *
  46051. * Revalidates the complete view with all cell states.
  46052. */
  46053. mxGraphView.prototype.revalidate = function()
  46054. {
  46055. this.invalidate();
  46056. this.validate();
  46057. };
  46058. /**
  46059. * Function: clear
  46060. *
  46061. * Removes the state of the given cell and all descendants if the given
  46062. * cell is not the current root.
  46063. *
  46064. * Parameters:
  46065. *
  46066. * cell - Optional <mxCell> for which the state should be removed. Default
  46067. * is the root of the model.
  46068. * force - Boolean indicating if the current root should be ignored for
  46069. * recursion.
  46070. */
  46071. mxGraphView.prototype.clear = function(cell, force, recurse)
  46072. {
  46073. var model = this.graph.getModel();
  46074. cell = cell || model.getRoot();
  46075. force = (force != null) ? force : false;
  46076. recurse = (recurse != null) ? recurse : true;
  46077. this.removeState(cell);
  46078. if (recurse && (force || cell != this.currentRoot))
  46079. {
  46080. var childCount = model.getChildCount(cell);
  46081. for (var i = 0; i < childCount; i++)
  46082. {
  46083. this.clear(model.getChildAt(cell, i), force);
  46084. }
  46085. }
  46086. else
  46087. {
  46088. this.invalidate(cell);
  46089. }
  46090. };
  46091. /**
  46092. * Function: invalidate
  46093. *
  46094. * Invalidates the state of the given cell, all its descendants and
  46095. * connected edges.
  46096. *
  46097. * Parameters:
  46098. *
  46099. * cell - Optional <mxCell> to be invalidated. Default is the root of the
  46100. * model.
  46101. */
  46102. mxGraphView.prototype.invalidate = function(cell, recurse, includeEdges)
  46103. {
  46104. var model = this.graph.getModel();
  46105. cell = cell || model.getRoot();
  46106. recurse = (recurse != null) ? recurse : true;
  46107. includeEdges = (includeEdges != null) ? includeEdges : true;
  46108. var state = this.getState(cell);
  46109. if (state != null)
  46110. {
  46111. state.invalid = true;
  46112. }
  46113. // Avoids infinite loops for invalid graphs
  46114. if (!cell.invalidating)
  46115. {
  46116. cell.invalidating = true;
  46117. // Recursively invalidates all descendants
  46118. if (recurse)
  46119. {
  46120. var childCount = model.getChildCount(cell);
  46121. for (var i = 0; i < childCount; i++)
  46122. {
  46123. var child = model.getChildAt(cell, i);
  46124. this.invalidate(child, recurse, includeEdges);
  46125. }
  46126. }
  46127. // Propagates invalidation to all connected edges
  46128. if (includeEdges)
  46129. {
  46130. var edgeCount = model.getEdgeCount(cell);
  46131. for (var i = 0; i < edgeCount; i++)
  46132. {
  46133. this.invalidate(model.getEdgeAt(cell, i), recurse, includeEdges);
  46134. }
  46135. }
  46136. delete cell.invalidating;
  46137. }
  46138. };
  46139. /**
  46140. * Function: validate
  46141. *
  46142. * Calls <validateCell> and <validateCellState> and updates the <graphBounds>
  46143. * using <getBoundingBox>. Finally the background is validated using
  46144. * <validateBackground>.
  46145. *
  46146. * Parameters:
  46147. *
  46148. * cell - Optional <mxCell> to be used as the root of the validation.
  46149. * Default is <currentRoot> or the root of the model.
  46150. */
  46151. mxGraphView.prototype.validate = function(cell)
  46152. {
  46153. var t0 = mxLog.enter('mxGraphView.validate');
  46154. window.status = mxResources.get(this.updatingDocumentResource) ||
  46155. this.updatingDocumentResource;
  46156. this.resetValidationState();
  46157. // Improves IE rendering speed by minimizing reflows
  46158. var prevDisplay = null;
  46159. if (this.optimizeVmlReflows && this.canvas != null && this.textDiv == null &&
  46160. ((document.documentMode == 8 && !mxClient.IS_EM) || mxClient.IS_QUIRKS))
  46161. {
  46162. // Placeholder keeps scrollbar positions when canvas is hidden
  46163. this.placeholder = document.createElement('div');
  46164. this.placeholder.style.position = 'absolute';
  46165. this.placeholder.style.width = this.canvas.clientWidth + 'px';
  46166. this.placeholder.style.height = this.canvas.clientHeight + 'px';
  46167. this.canvas.parentNode.appendChild(this.placeholder);
  46168. prevDisplay = this.drawPane.style.display;
  46169. this.canvas.style.display = 'none';
  46170. // Creates temporary DIV used for text measuring in mxText.updateBoundingBox
  46171. this.textDiv = document.createElement('div');
  46172. this.textDiv.style.position = 'absolute';
  46173. this.textDiv.style.whiteSpace = 'nowrap';
  46174. this.textDiv.style.visibility = 'hidden';
  46175. this.textDiv.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  46176. this.textDiv.style.zoom = '1';
  46177. document.body.appendChild(this.textDiv);
  46178. }
  46179. var graphBounds = this.getBoundingBox(this.validateCellState(
  46180. this.validateCell(cell || ((this.currentRoot != null) ?
  46181. this.currentRoot : this.graph.getModel().getRoot()))));
  46182. this.setGraphBounds((graphBounds != null) ? graphBounds : this.getEmptyBounds());
  46183. this.validateBackground();
  46184. if (prevDisplay != null)
  46185. {
  46186. this.canvas.style.display = prevDisplay;
  46187. this.textDiv.parentNode.removeChild(this.textDiv);
  46188. if (this.placeholder != null)
  46189. {
  46190. this.placeholder.parentNode.removeChild(this.placeholder);
  46191. }
  46192. // Textdiv cannot be reused
  46193. this.textDiv = null;
  46194. }
  46195. this.resetValidationState();
  46196. window.status = mxResources.get(this.doneResource) ||
  46197. this.doneResource;
  46198. mxLog.leave('mxGraphView.validate', t0);
  46199. };
  46200. /**
  46201. * Function: getEmptyBounds
  46202. *
  46203. * Returns the bounds for an empty graph. This returns a rectangle at
  46204. * <translate> with the size of 0 x 0.
  46205. */
  46206. mxGraphView.prototype.getEmptyBounds = function()
  46207. {
  46208. return new mxRectangle(this.translate.x * this.scale, this.translate.y * this.scale);
  46209. };
  46210. /**
  46211. * Function: getBoundingBox
  46212. *
  46213. * Returns the bounding box of the shape and the label for the given
  46214. * <mxCellState> and its children if recurse is true.
  46215. *
  46216. * Parameters:
  46217. *
  46218. * state - <mxCellState> whose bounding box should be returned.
  46219. * recurse - Optional boolean indicating if the children should be included.
  46220. * Default is true.
  46221. */
  46222. mxGraphView.prototype.getBoundingBox = function(state, recurse)
  46223. {
  46224. recurse = (recurse != null) ? recurse : true;
  46225. var bbox = null;
  46226. if (state != null)
  46227. {
  46228. if (state.shape != null && state.shape.boundingBox != null)
  46229. {
  46230. bbox = state.shape.boundingBox.clone();
  46231. }
  46232. // Adds label bounding box to graph bounds
  46233. if (state.text != null && state.text.boundingBox != null)
  46234. {
  46235. if (bbox != null)
  46236. {
  46237. bbox.add(state.text.boundingBox);
  46238. }
  46239. else
  46240. {
  46241. bbox = state.text.boundingBox.clone();
  46242. }
  46243. }
  46244. if (recurse)
  46245. {
  46246. var model = this.graph.getModel();
  46247. var childCount = model.getChildCount(state.cell);
  46248. for (var i = 0; i < childCount; i++)
  46249. {
  46250. var bounds = this.getBoundingBox(this.getState(model.getChildAt(state.cell, i)));
  46251. if (bounds != null)
  46252. {
  46253. if (bbox == null)
  46254. {
  46255. bbox = bounds;
  46256. }
  46257. else
  46258. {
  46259. bbox.add(bounds);
  46260. }
  46261. }
  46262. }
  46263. }
  46264. }
  46265. return bbox;
  46266. };
  46267. /**
  46268. * Function: createBackgroundPageShape
  46269. *
  46270. * Creates and returns the shape used as the background page.
  46271. *
  46272. * Parameters:
  46273. *
  46274. * bounds - <mxRectangle> that represents the bounds of the shape.
  46275. */
  46276. mxGraphView.prototype.createBackgroundPageShape = function(bounds)
  46277. {
  46278. return new mxRectangleShape(bounds, 'white', 'black');
  46279. };
  46280. /**
  46281. * Function: validateBackground
  46282. *
  46283. * Calls <validateBackgroundImage> and <validateBackgroundPage>.
  46284. */
  46285. mxGraphView.prototype.validateBackground = function()
  46286. {
  46287. this.validateBackgroundImage();
  46288. this.validateBackgroundPage();
  46289. };
  46290. /**
  46291. * Function: validateBackgroundImage
  46292. *
  46293. * Validates the background image.
  46294. */
  46295. mxGraphView.prototype.validateBackgroundImage = function()
  46296. {
  46297. var bg = this.graph.getBackgroundImage();
  46298. if (bg != null)
  46299. {
  46300. if (this.backgroundImage == null || this.backgroundImage.image != bg.src)
  46301. {
  46302. if (this.backgroundImage != null)
  46303. {
  46304. this.backgroundImage.destroy();
  46305. }
  46306. var bounds = new mxRectangle(0, 0, 1, 1);
  46307. this.backgroundImage = new mxImageShape(bounds, bg.src);
  46308. this.backgroundImage.dialect = this.graph.dialect;
  46309. this.backgroundImage.init(this.backgroundPane);
  46310. this.backgroundImage.redraw();
  46311. // Workaround for ignored event on background in IE8 standards mode
  46312. if (document.documentMode == 8 && !mxClient.IS_EM)
  46313. {
  46314. mxEvent.addGestureListeners(this.backgroundImage.node,
  46315. mxUtils.bind(this, function(evt)
  46316. {
  46317. this.graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt));
  46318. }),
  46319. mxUtils.bind(this, function(evt)
  46320. {
  46321. this.graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt));
  46322. }),
  46323. mxUtils.bind(this, function(evt)
  46324. {
  46325. this.graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  46326. })
  46327. );
  46328. }
  46329. }
  46330. this.redrawBackgroundImage(this.backgroundImage, bg);
  46331. }
  46332. else if (this.backgroundImage != null)
  46333. {
  46334. this.backgroundImage.destroy();
  46335. this.backgroundImage = null;
  46336. }
  46337. };
  46338. /**
  46339. * Function: validateBackgroundPage
  46340. *
  46341. * Validates the background page.
  46342. */
  46343. mxGraphView.prototype.validateBackgroundPage = function()
  46344. {
  46345. if (this.graph.pageVisible)
  46346. {
  46347. var bounds = this.getBackgroundPageBounds();
  46348. if (this.backgroundPageShape == null)
  46349. {
  46350. this.backgroundPageShape = this.createBackgroundPageShape(bounds);
  46351. this.backgroundPageShape.scale = this.scale;
  46352. this.backgroundPageShape.isShadow = true;
  46353. this.backgroundPageShape.dialect = this.graph.dialect;
  46354. this.backgroundPageShape.init(this.backgroundPane);
  46355. this.backgroundPageShape.redraw();
  46356. // Adds listener for double click handling on background
  46357. if (this.graph.nativeDblClickEnabled)
  46358. {
  46359. mxEvent.addListener(this.backgroundPageShape.node, 'dblclick', mxUtils.bind(this, function(evt)
  46360. {
  46361. this.graph.dblClick(evt);
  46362. }));
  46363. }
  46364. // Adds basic listeners for graph event dispatching outside of the
  46365. // container and finishing the handling of a single gesture
  46366. mxEvent.addGestureListeners(this.backgroundPageShape.node,
  46367. mxUtils.bind(this, function(evt)
  46368. {
  46369. this.graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt));
  46370. }),
  46371. mxUtils.bind(this, function(evt)
  46372. {
  46373. // Hides the tooltip if mouse is outside container
  46374. if (this.graph.tooltipHandler != null && this.graph.tooltipHandler.isHideOnHover())
  46375. {
  46376. this.graph.tooltipHandler.hide();
  46377. }
  46378. if (this.graph.isMouseDown && !mxEvent.isConsumed(evt))
  46379. {
  46380. this.graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt));
  46381. }
  46382. }),
  46383. mxUtils.bind(this, function(evt)
  46384. {
  46385. this.graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  46386. })
  46387. );
  46388. }
  46389. else
  46390. {
  46391. this.backgroundPageShape.scale = this.scale;
  46392. this.backgroundPageShape.bounds = bounds;
  46393. this.backgroundPageShape.redraw();
  46394. }
  46395. }
  46396. else if (this.backgroundPageShape != null)
  46397. {
  46398. this.backgroundPageShape.destroy();
  46399. this.backgroundPageShape = null;
  46400. }
  46401. };
  46402. /**
  46403. * Function: getBackgroundPageBounds
  46404. *
  46405. * Returns the bounds for the background page.
  46406. */
  46407. mxGraphView.prototype.getBackgroundPageBounds = function()
  46408. {
  46409. var fmt = this.graph.pageFormat;
  46410. var ps = this.scale * this.graph.pageScale;
  46411. var bounds = new mxRectangle(this.scale * this.translate.x, this.scale * this.translate.y,
  46412. fmt.width * ps, fmt.height * ps);
  46413. return bounds;
  46414. };
  46415. /**
  46416. * Function: redrawBackgroundImage
  46417. *
  46418. * Updates the bounds and redraws the background image.
  46419. *
  46420. * Example:
  46421. *
  46422. * If the background image should not be scaled, this can be replaced with
  46423. * the following.
  46424. *
  46425. * (code)
  46426. * mxGraphView.prototype.redrawBackground = function(backgroundImage, bg)
  46427. * {
  46428. * backgroundImage.bounds.x = this.translate.x;
  46429. * backgroundImage.bounds.y = this.translate.y;
  46430. * backgroundImage.bounds.width = bg.width;
  46431. * backgroundImage.bounds.height = bg.height;
  46432. *
  46433. * backgroundImage.redraw();
  46434. * };
  46435. * (end)
  46436. *
  46437. * Parameters:
  46438. *
  46439. * backgroundImage - <mxImageShape> that represents the background image.
  46440. * bg - <mxImage> that specifies the image and its dimensions.
  46441. */
  46442. mxGraphView.prototype.redrawBackgroundImage = function(backgroundImage, bg)
  46443. {
  46444. backgroundImage.scale = this.scale;
  46445. backgroundImage.bounds.x = this.scale * this.translate.x;
  46446. backgroundImage.bounds.y = this.scale * this.translate.y;
  46447. backgroundImage.bounds.width = this.scale * bg.width;
  46448. backgroundImage.bounds.height = this.scale * bg.height;
  46449. backgroundImage.redraw();
  46450. };
  46451. /**
  46452. * Function: validateCell
  46453. *
  46454. * Recursively creates the cell state for the given cell if visible is true and
  46455. * the given cell is visible. If the cell is not visible but the state exists
  46456. * then it is removed using <removeState>.
  46457. *
  46458. * Parameters:
  46459. *
  46460. * cell - <mxCell> whose <mxCellState> should be created.
  46461. * visible - Optional boolean indicating if the cell should be visible. Default
  46462. * is true.
  46463. */
  46464. mxGraphView.prototype.validateCell = function(cell, visible)
  46465. {
  46466. visible = (visible != null) ? visible : true;
  46467. if (cell != null)
  46468. {
  46469. visible = visible && this.graph.isCellVisible(cell);
  46470. var state = this.getState(cell, visible);
  46471. if (state != null && !visible)
  46472. {
  46473. this.removeState(cell);
  46474. }
  46475. else
  46476. {
  46477. var model = this.graph.getModel();
  46478. var childCount = model.getChildCount(cell);
  46479. for (var i = 0; i < childCount; i++)
  46480. {
  46481. this.validateCell(model.getChildAt(cell, i), visible &&
  46482. (!this.isCellCollapsed(cell) || cell == this.currentRoot));
  46483. }
  46484. }
  46485. }
  46486. return cell;
  46487. };
  46488. /**
  46489. * Function: validateCellState
  46490. *
  46491. * Validates and repaints the <mxCellState> for the given <mxCell>.
  46492. *
  46493. * Parameters:
  46494. *
  46495. * cell - <mxCell> whose <mxCellState> should be validated.
  46496. * recurse - Optional boolean indicating if the children of the cell should be
  46497. * validated. Default is true.
  46498. */
  46499. mxGraphView.prototype.validateCellState = function(cell, recurse)
  46500. {
  46501. recurse = (recurse != null) ? recurse : true;
  46502. var state = null;
  46503. if (cell != null)
  46504. {
  46505. state = this.getState(cell);
  46506. if (state != null)
  46507. {
  46508. var model = this.graph.getModel();
  46509. if (state.invalid)
  46510. {
  46511. state.invalid = false;
  46512. if (state.style == null || state.invalidStyle)
  46513. {
  46514. state.style = this.graph.getCellStyle(state.cell);
  46515. state.invalidStyle = false;
  46516. }
  46517. if (cell != this.currentRoot)
  46518. {
  46519. this.validateCellState(model.getParent(cell), false);
  46520. }
  46521. state.setVisibleTerminalState(this.validateCellState(this.getVisibleTerminal(cell, true), false), true);
  46522. state.setVisibleTerminalState(this.validateCellState(this.getVisibleTerminal(cell, false), false), false);
  46523. this.updateCellState(state);
  46524. // Repaint happens immediately after the cell is validated
  46525. if (cell != this.currentRoot && !state.invalid)
  46526. {
  46527. this.graph.cellRenderer.redraw(state, false, this.isRendering());
  46528. // Handles changes to invertex paintbounds after update of rendering shape
  46529. state.updateCachedBounds();
  46530. }
  46531. }
  46532. if (recurse && !state.invalid)
  46533. {
  46534. // Updates order in DOM if recursively traversing
  46535. if (state.shape != null)
  46536. {
  46537. this.stateValidated(state);
  46538. }
  46539. var childCount = model.getChildCount(cell);
  46540. for (var i = 0; i < childCount; i++)
  46541. {
  46542. this.validateCellState(model.getChildAt(cell, i));
  46543. }
  46544. }
  46545. }
  46546. }
  46547. return state;
  46548. };
  46549. /**
  46550. * Function: updateCellState
  46551. *
  46552. * Updates the given <mxCellState>.
  46553. *
  46554. * Parameters:
  46555. *
  46556. * state - <mxCellState> to be updated.
  46557. */
  46558. mxGraphView.prototype.updateCellState = function(state)
  46559. {
  46560. state.absoluteOffset.x = 0;
  46561. state.absoluteOffset.y = 0;
  46562. state.origin.x = 0;
  46563. state.origin.y = 0;
  46564. state.length = 0;
  46565. if (state.cell != this.currentRoot)
  46566. {
  46567. var model = this.graph.getModel();
  46568. var pState = this.getState(model.getParent(state.cell));
  46569. if (pState != null && pState.cell != this.currentRoot)
  46570. {
  46571. state.origin.x += pState.origin.x;
  46572. state.origin.y += pState.origin.y;
  46573. }
  46574. var offset = this.graph.getChildOffsetForCell(state.cell);
  46575. if (offset != null)
  46576. {
  46577. state.origin.x += offset.x;
  46578. state.origin.y += offset.y;
  46579. }
  46580. var geo = this.graph.getCellGeometry(state.cell);
  46581. if (geo != null)
  46582. {
  46583. if (!model.isEdge(state.cell))
  46584. {
  46585. offset = (geo.offset != null) ? geo.offset : this.EMPTY_POINT;
  46586. if (geo.relative && pState != null)
  46587. {
  46588. if (model.isEdge(pState.cell))
  46589. {
  46590. var origin = this.getPoint(pState, geo);
  46591. if (origin != null)
  46592. {
  46593. state.origin.x += (origin.x / this.scale) - pState.origin.x - this.translate.x;
  46594. state.origin.y += (origin.y / this.scale) - pState.origin.y - this.translate.y;
  46595. }
  46596. }
  46597. else
  46598. {
  46599. state.origin.x += geo.x * pState.unscaledWidth + offset.x;
  46600. state.origin.y += geo.y * pState.unscaledHeight + offset.y;
  46601. }
  46602. }
  46603. else
  46604. {
  46605. state.absoluteOffset.x = this.scale * offset.x;
  46606. state.absoluteOffset.y = this.scale * offset.y;
  46607. state.origin.x += geo.x;
  46608. state.origin.y += geo.y;
  46609. }
  46610. }
  46611. state.x = this.scale * (this.translate.x + state.origin.x);
  46612. state.y = this.scale * (this.translate.y + state.origin.y);
  46613. state.width = this.scale * geo.width;
  46614. state.unscaledWidth = geo.width;
  46615. state.height = this.scale * geo.height;
  46616. state.unscaledHeight = geo.height;
  46617. if (model.isVertex(state.cell))
  46618. {
  46619. this.updateVertexState(state, geo);
  46620. }
  46621. if (model.isEdge(state.cell))
  46622. {
  46623. this.updateEdgeState(state, geo);
  46624. }
  46625. }
  46626. }
  46627. state.updateCachedBounds();
  46628. };
  46629. /**
  46630. * Function: isCellCollapsed
  46631. *
  46632. * Returns true if the children of the given cell should not be visible in the
  46633. * view. This implementation uses <mxGraph.isCellVisible> but it can be
  46634. * overidden to use a separate condition.
  46635. */
  46636. mxGraphView.prototype.isCellCollapsed = function(cell)
  46637. {
  46638. return this.graph.isCellCollapsed(cell);
  46639. };
  46640. /**
  46641. * Function: updateVertexState
  46642. *
  46643. * Validates the given cell state.
  46644. */
  46645. mxGraphView.prototype.updateVertexState = function(state, geo)
  46646. {
  46647. var model = this.graph.getModel();
  46648. var pState = this.getState(model.getParent(state.cell));
  46649. if (geo.relative && pState != null && !model.isEdge(pState.cell))
  46650. {
  46651. var alpha = mxUtils.toRadians(pState.style[mxConstants.STYLE_ROTATION] || '0');
  46652. if (alpha != 0)
  46653. {
  46654. var cos = Math.cos(alpha);
  46655. var sin = Math.sin(alpha);
  46656. var ct = new mxPoint(state.getCenterX(), state.getCenterY());
  46657. var cx = new mxPoint(pState.getCenterX(), pState.getCenterY());
  46658. var pt = mxUtils.getRotatedPoint(ct, cos, sin, cx);
  46659. state.x = pt.x - state.width / 2;
  46660. state.y = pt.y - state.height / 2;
  46661. }
  46662. }
  46663. this.updateVertexLabelOffset(state);
  46664. };
  46665. /**
  46666. * Function: updateEdgeState
  46667. *
  46668. * Validates the given cell state.
  46669. */
  46670. mxGraphView.prototype.updateEdgeState = function(state, geo)
  46671. {
  46672. var source = state.getVisibleTerminalState(true);
  46673. var target = state.getVisibleTerminalState(false);
  46674. // This will remove edges with no terminals and no terminal points
  46675. // as such edges are invalid and produce NPEs in the edge styles.
  46676. // Also removes connected edges that have no visible terminals.
  46677. if ((this.graph.model.getTerminal(state.cell, true) != null && source == null) ||
  46678. (source == null && geo.getTerminalPoint(true) == null) ||
  46679. (this.graph.model.getTerminal(state.cell, false) != null && target == null) ||
  46680. (target == null && geo.getTerminalPoint(false) == null))
  46681. {
  46682. this.clear(state.cell, true);
  46683. }
  46684. else
  46685. {
  46686. this.updateFixedTerminalPoints(state, source, target);
  46687. this.updatePoints(state, geo.points, source, target);
  46688. this.updateFloatingTerminalPoints(state, source, target);
  46689. var pts = state.absolutePoints;
  46690. if (state.cell != this.currentRoot && (pts == null || pts.length < 2 ||
  46691. pts[0] == null || pts[pts.length - 1] == null))
  46692. {
  46693. // This will remove edges with invalid points from the list of states in the view.
  46694. // Happens if the one of the terminals and the corresponding terminal point is null.
  46695. this.clear(state.cell, true);
  46696. }
  46697. else
  46698. {
  46699. this.updateEdgeBounds(state);
  46700. this.updateEdgeLabelOffset(state);
  46701. }
  46702. }
  46703. };
  46704. /**
  46705. * Function: updateVertexLabelOffset
  46706. *
  46707. * Updates the absoluteOffset of the given vertex cell state. This takes
  46708. * into account the label position styles.
  46709. *
  46710. * Parameters:
  46711. *
  46712. * state - <mxCellState> whose absolute offset should be updated.
  46713. */
  46714. mxGraphView.prototype.updateVertexLabelOffset = function(state)
  46715. {
  46716. var h = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  46717. if (h == mxConstants.ALIGN_LEFT)
  46718. {
  46719. var lw = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_WIDTH, null);
  46720. if (lw != null)
  46721. {
  46722. lw *= this.scale;
  46723. }
  46724. else
  46725. {
  46726. lw = state.width;
  46727. }
  46728. state.absoluteOffset.x -= lw;
  46729. }
  46730. else if (h == mxConstants.ALIGN_RIGHT)
  46731. {
  46732. state.absoluteOffset.x += state.width;
  46733. }
  46734. else if (h == mxConstants.ALIGN_CENTER)
  46735. {
  46736. var lw = mxUtils.getValue(state.style, mxConstants.STYLE_LABEL_WIDTH, null);
  46737. if (lw != null)
  46738. {
  46739. // Aligns text block with given width inside the vertex width
  46740. var align = mxUtils.getValue(state.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
  46741. var dx = 0;
  46742. if (align == mxConstants.ALIGN_CENTER)
  46743. {
  46744. dx = 0.5;
  46745. }
  46746. else if (align == mxConstants.ALIGN_RIGHT)
  46747. {
  46748. dx = 1;
  46749. }
  46750. if (dx != 0)
  46751. {
  46752. state.absoluteOffset.x -= (lw * this.scale - state.width) * dx;
  46753. }
  46754. }
  46755. }
  46756. var v = mxUtils.getValue(state.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  46757. if (v == mxConstants.ALIGN_TOP)
  46758. {
  46759. state.absoluteOffset.y -= state.height;
  46760. }
  46761. else if (v == mxConstants.ALIGN_BOTTOM)
  46762. {
  46763. state.absoluteOffset.y += state.height;
  46764. }
  46765. };
  46766. /**
  46767. * Function: resetValidationState
  46768. *
  46769. * Resets the current validation state.
  46770. */
  46771. mxGraphView.prototype.resetValidationState = function()
  46772. {
  46773. this.lastNode = null;
  46774. this.lastHtmlNode = null;
  46775. this.lastForegroundNode = null;
  46776. this.lastForegroundHtmlNode = null;
  46777. };
  46778. /**
  46779. * Function: stateValidated
  46780. *
  46781. * Invoked when a state has been processed in <validatePoints>. This is used
  46782. * to update the order of the DOM nodes of the shape.
  46783. *
  46784. * Parameters:
  46785. *
  46786. * state - <mxCellState> that represents the cell state.
  46787. */
  46788. mxGraphView.prototype.stateValidated = function(state)
  46789. {
  46790. var fg = (this.graph.getModel().isEdge(state.cell) && this.graph.keepEdgesInForeground) ||
  46791. (this.graph.getModel().isVertex(state.cell) && this.graph.keepEdgesInBackground);
  46792. var htmlNode = (fg) ? this.lastForegroundHtmlNode || this.lastHtmlNode : this.lastHtmlNode;
  46793. var node = (fg) ? this.lastForegroundNode || this.lastNode : this.lastNode;
  46794. var result = this.graph.cellRenderer.insertStateAfter(state, node, htmlNode);
  46795. if (fg)
  46796. {
  46797. this.lastForegroundHtmlNode = result[1];
  46798. this.lastForegroundNode = result[0];
  46799. }
  46800. else
  46801. {
  46802. this.lastHtmlNode = result[1];
  46803. this.lastNode = result[0];
  46804. }
  46805. };
  46806. /**
  46807. * Function: updateFixedTerminalPoints
  46808. *
  46809. * Sets the initial absolute terminal points in the given state before the edge
  46810. * style is computed.
  46811. *
  46812. * Parameters:
  46813. *
  46814. * edge - <mxCellState> whose initial terminal points should be updated.
  46815. * source - <mxCellState> which represents the source terminal.
  46816. * target - <mxCellState> which represents the target terminal.
  46817. */
  46818. mxGraphView.prototype.updateFixedTerminalPoints = function(edge, source, target)
  46819. {
  46820. this.updateFixedTerminalPoint(edge, source, true,
  46821. this.graph.getConnectionConstraint(edge, source, true));
  46822. this.updateFixedTerminalPoint(edge, target, false,
  46823. this.graph.getConnectionConstraint(edge, target, false));
  46824. };
  46825. /**
  46826. * Function: updateFixedTerminalPoint
  46827. *
  46828. * Sets the fixed source or target terminal point on the given edge.
  46829. *
  46830. * Parameters:
  46831. *
  46832. * edge - <mxCellState> whose terminal point should be updated.
  46833. * terminal - <mxCellState> which represents the actual terminal.
  46834. * source - Boolean that specifies if the terminal is the source.
  46835. * constraint - <mxConnectionConstraint> that specifies the connection.
  46836. */
  46837. mxGraphView.prototype.updateFixedTerminalPoint = function(edge, terminal, source, constraint)
  46838. {
  46839. edge.setAbsoluteTerminalPoint(this.getFixedTerminalPoint(edge, terminal, source, constraint), source);
  46840. };
  46841. /**
  46842. * Function: getFixedTerminalPoint
  46843. *
  46844. * Returns the fixed source or target terminal point for the given edge.
  46845. *
  46846. * Parameters:
  46847. *
  46848. * edge - <mxCellState> whose terminal point should be returned.
  46849. * terminal - <mxCellState> which represents the actual terminal.
  46850. * source - Boolean that specifies if the terminal is the source.
  46851. * constraint - <mxConnectionConstraint> that specifies the connection.
  46852. */
  46853. mxGraphView.prototype.getFixedTerminalPoint = function(edge, terminal, source, constraint)
  46854. {
  46855. var pt = null;
  46856. if (constraint != null)
  46857. {
  46858. pt = this.graph.getConnectionPoint(terminal, constraint, false); // FIXME Rounding introduced bugs when calculating label positions -> , this.graph.isOrthogonal(edge));
  46859. }
  46860. if (pt == null && terminal == null)
  46861. {
  46862. var s = this.scale;
  46863. var tr = this.translate;
  46864. var orig = edge.origin;
  46865. var geo = this.graph.getCellGeometry(edge.cell);
  46866. pt = geo.getTerminalPoint(source);
  46867. if (pt != null)
  46868. {
  46869. pt = new mxPoint(s * (tr.x + pt.x + orig.x),
  46870. s * (tr.y + pt.y + orig.y));
  46871. }
  46872. }
  46873. return pt;
  46874. };
  46875. /**
  46876. * Function: updateBoundsFromStencil
  46877. *
  46878. * Updates the bounds of the given cell state to reflect the bounds of the stencil
  46879. * if it has a fixed aspect and returns the previous bounds as an <mxRectangle> if
  46880. * the bounds have been modified or null otherwise.
  46881. *
  46882. * Parameters:
  46883. *
  46884. * edge - <mxCellState> whose bounds should be updated.
  46885. */
  46886. mxGraphView.prototype.updateBoundsFromStencil = function(state)
  46887. {
  46888. var previous = null;
  46889. if (state != null && state.shape != null && state.shape.stencil != null && state.shape.stencil.aspect == 'fixed')
  46890. {
  46891. previous = mxRectangle.fromRectangle(state);
  46892. var asp = state.shape.stencil.computeAspect(state.style, state.x, state.y, state.width, state.height);
  46893. state.setRect(asp.x, asp.y, state.shape.stencil.w0 * asp.width, state.shape.stencil.h0 * asp.height);
  46894. }
  46895. return previous;
  46896. };
  46897. /**
  46898. * Function: updatePoints
  46899. *
  46900. * Updates the absolute points in the given state using the specified array
  46901. * of <mxPoints> as the relative points.
  46902. *
  46903. * Parameters:
  46904. *
  46905. * edge - <mxCellState> whose absolute points should be updated.
  46906. * points - Array of <mxPoints> that constitute the relative points.
  46907. * source - <mxCellState> that represents the source terminal.
  46908. * target - <mxCellState> that represents the target terminal.
  46909. */
  46910. mxGraphView.prototype.updatePoints = function(edge, points, source, target)
  46911. {
  46912. if (edge != null)
  46913. {
  46914. var pts = [];
  46915. pts.push(edge.absolutePoints[0]);
  46916. var edgeStyle = this.getEdgeStyle(edge, points, source, target);
  46917. if (edgeStyle != null)
  46918. {
  46919. var src = this.getTerminalPort(edge, source, true);
  46920. var trg = this.getTerminalPort(edge, target, false);
  46921. // Uses the stencil bounds for routing and restores after routing
  46922. var srcBounds = this.updateBoundsFromStencil(src);
  46923. var trgBounds = this.updateBoundsFromStencil(trg);
  46924. edgeStyle(edge, src, trg, points, pts);
  46925. // Restores previous bounds
  46926. if (srcBounds != null)
  46927. {
  46928. src.setRect(srcBounds.x, srcBounds.y, srcBounds.width, srcBounds.height);
  46929. }
  46930. if (trgBounds != null)
  46931. {
  46932. trg.setRect(trgBounds.x, trgBounds.y, trgBounds.width, trgBounds.height);
  46933. }
  46934. }
  46935. else if (points != null)
  46936. {
  46937. for (var i = 0; i < points.length; i++)
  46938. {
  46939. if (points[i] != null)
  46940. {
  46941. var pt = mxUtils.clone(points[i]);
  46942. pts.push(this.transformControlPoint(edge, pt));
  46943. }
  46944. }
  46945. }
  46946. var tmp = edge.absolutePoints;
  46947. pts.push(tmp[tmp.length-1]);
  46948. edge.absolutePoints = pts;
  46949. }
  46950. };
  46951. /**
  46952. * Function: transformControlPoint
  46953. *
  46954. * Transforms the given control point to an absolute point.
  46955. */
  46956. mxGraphView.prototype.transformControlPoint = function(state, pt, ignoreScale)
  46957. {
  46958. if (state != null && pt != null)
  46959. {
  46960. var orig = state.origin;
  46961. var scale = ignoreScale ? 1 : this.scale
  46962. return new mxPoint(scale * (pt.x + this.translate.x + orig.x),
  46963. scale * (pt.y + this.translate.y + orig.y));
  46964. }
  46965. return null;
  46966. };
  46967. /**
  46968. * Function: isLoopStyleEnabled
  46969. *
  46970. * Returns true if the given edge should be routed with <mxGraph.defaultLoopStyle>
  46971. * or the <mxConstants.STYLE_LOOP> defined for the given edge. This implementation
  46972. * returns true if the given edge is a loop and does not have connections constraints
  46973. * associated.
  46974. */
  46975. mxGraphView.prototype.isLoopStyleEnabled = function(edge, points, source, target)
  46976. {
  46977. var sc = this.graph.getConnectionConstraint(edge, source, true);
  46978. var tc = this.graph.getConnectionConstraint(edge, target, false);
  46979. if ((points == null || points.length < 2) &&
  46980. (!mxUtils.getValue(edge.style, mxConstants.STYLE_ORTHOGONAL_LOOP, false) ||
  46981. ((sc == null || sc.point == null) && (tc == null || tc.point == null))))
  46982. {
  46983. return source != null && source == target;
  46984. }
  46985. return false;
  46986. };
  46987. /**
  46988. * Function: getEdgeStyle
  46989. *
  46990. * Returns the edge style function to be used to render the given edge state.
  46991. */
  46992. mxGraphView.prototype.getEdgeStyle = function(edge, points, source, target)
  46993. {
  46994. var edgeStyle = this.isLoopStyleEnabled(edge, points, source, target) ?
  46995. mxUtils.getValue(edge.style, mxConstants.STYLE_LOOP, this.graph.defaultLoopStyle) :
  46996. (!mxUtils.getValue(edge.style, mxConstants.STYLE_NOEDGESTYLE, false) ?
  46997. edge.style[mxConstants.STYLE_EDGE] : null);
  46998. // Converts string values to objects
  46999. if (typeof(edgeStyle) == "string")
  47000. {
  47001. var tmp = mxStyleRegistry.getValue(edgeStyle);
  47002. if (tmp == null && this.isAllowEval())
  47003. {
  47004. tmp = mxUtils.eval(edgeStyle);
  47005. }
  47006. edgeStyle = tmp;
  47007. }
  47008. if (typeof(edgeStyle) == "function")
  47009. {
  47010. return edgeStyle;
  47011. }
  47012. return null;
  47013. };
  47014. /**
  47015. * Function: updateFloatingTerminalPoints
  47016. *
  47017. * Updates the terminal points in the given state after the edge style was
  47018. * computed for the edge.
  47019. *
  47020. * Parameters:
  47021. *
  47022. * state - <mxCellState> whose terminal points should be updated.
  47023. * source - <mxCellState> that represents the source terminal.
  47024. * target - <mxCellState> that represents the target terminal.
  47025. */
  47026. mxGraphView.prototype.updateFloatingTerminalPoints = function(state, source, target)
  47027. {
  47028. var pts = state.absolutePoints;
  47029. var p0 = pts[0];
  47030. var pe = pts[pts.length - 1];
  47031. if (pe == null && target != null)
  47032. {
  47033. this.updateFloatingTerminalPoint(state, target, source, false);
  47034. }
  47035. if (p0 == null && source != null)
  47036. {
  47037. this.updateFloatingTerminalPoint(state, source, target, true);
  47038. }
  47039. };
  47040. /**
  47041. * Function: updateFloatingTerminalPoint
  47042. *
  47043. * Updates the absolute terminal point in the given state for the given
  47044. * start and end state, where start is the source if source is true.
  47045. *
  47046. * Parameters:
  47047. *
  47048. * edge - <mxCellState> whose terminal point should be updated.
  47049. * start - <mxCellState> for the terminal on "this" side of the edge.
  47050. * end - <mxCellState> for the terminal on the other side of the edge.
  47051. * source - Boolean indicating if start is the source terminal state.
  47052. */
  47053. mxGraphView.prototype.updateFloatingTerminalPoint = function(edge, start, end, source)
  47054. {
  47055. edge.setAbsoluteTerminalPoint(this.getFloatingTerminalPoint(edge, start, end, source), source);
  47056. };
  47057. /**
  47058. * Function: getFloatingTerminalPoint
  47059. *
  47060. * Returns the floating terminal point for the given edge, start and end
  47061. * state, where start is the source if source is true.
  47062. *
  47063. * Parameters:
  47064. *
  47065. * edge - <mxCellState> whose terminal point should be returned.
  47066. * start - <mxCellState> for the terminal on "this" side of the edge.
  47067. * end - <mxCellState> for the terminal on the other side of the edge.
  47068. * source - Boolean indicating if start is the source terminal state.
  47069. */
  47070. mxGraphView.prototype.getFloatingTerminalPoint = function(edge, start, end, source)
  47071. {
  47072. start = this.getTerminalPort(edge, start, source);
  47073. var next = this.getNextPoint(edge, end, source);
  47074. var orth = this.graph.isOrthogonal(edge);
  47075. var alpha = mxUtils.toRadians(Number(start.style[mxConstants.STYLE_ROTATION] || '0'));
  47076. var center = new mxPoint(start.getCenterX(), start.getCenterY());
  47077. if (alpha != 0)
  47078. {
  47079. var cos = Math.cos(-alpha);
  47080. var sin = Math.sin(-alpha);
  47081. next = mxUtils.getRotatedPoint(next, cos, sin, center);
  47082. }
  47083. var border = parseFloat(edge.style[mxConstants.STYLE_PERIMETER_SPACING] || 0);
  47084. border += parseFloat(edge.style[(source) ?
  47085. mxConstants.STYLE_SOURCE_PERIMETER_SPACING :
  47086. mxConstants.STYLE_TARGET_PERIMETER_SPACING] || 0);
  47087. var pt = this.getPerimeterPoint(start, next, alpha == 0 && orth, border);
  47088. if (alpha != 0)
  47089. {
  47090. var cos = Math.cos(alpha);
  47091. var sin = Math.sin(alpha);
  47092. pt = mxUtils.getRotatedPoint(pt, cos, sin, center);
  47093. }
  47094. return pt;
  47095. };
  47096. /**
  47097. * Function: getTerminalPort
  47098. *
  47099. * Returns an <mxCellState> that represents the source or target terminal or
  47100. * port for the given edge.
  47101. *
  47102. * Parameters:
  47103. *
  47104. * state - <mxCellState> that represents the state of the edge.
  47105. * terminal - <mxCellState> that represents the terminal.
  47106. * source - Boolean indicating if the given terminal is the source terminal.
  47107. */
  47108. mxGraphView.prototype.getTerminalPort = function(state, terminal, source)
  47109. {
  47110. var key = (source) ? mxConstants.STYLE_SOURCE_PORT :
  47111. mxConstants.STYLE_TARGET_PORT;
  47112. var id = mxUtils.getValue(state.style, key);
  47113. if (id != null)
  47114. {
  47115. var tmp = this.getState(this.graph.getModel().getCell(id));
  47116. // Only uses ports where a cell state exists
  47117. if (tmp != null)
  47118. {
  47119. terminal = tmp;
  47120. }
  47121. }
  47122. return terminal;
  47123. };
  47124. /**
  47125. * Function: getPerimeterPoint
  47126. *
  47127. * Returns an <mxPoint> that defines the location of the intersection point between
  47128. * the perimeter and the line between the center of the shape and the given point.
  47129. *
  47130. * Parameters:
  47131. *
  47132. * terminal - <mxCellState> for the source or target terminal.
  47133. * next - <mxPoint> that lies outside of the given terminal.
  47134. * orthogonal - Boolean that specifies if the orthogonal projection onto
  47135. * the perimeter should be returned. If this is false then the intersection
  47136. * of the perimeter and the line between the next and the center point is
  47137. * returned.
  47138. * border - Optional border between the perimeter and the shape.
  47139. */
  47140. mxGraphView.prototype.getPerimeterPoint = function(terminal, next, orthogonal, border)
  47141. {
  47142. var point = null;
  47143. if (terminal != null)
  47144. {
  47145. var perimeter = this.getPerimeterFunction(terminal);
  47146. if (perimeter != null && next != null)
  47147. {
  47148. var bounds = this.getPerimeterBounds(terminal, border);
  47149. if (bounds.width > 0 || bounds.height > 0)
  47150. {
  47151. point = new mxPoint(next.x, next.y);
  47152. var flipH = false;
  47153. var flipV = false;
  47154. if (this.graph.model.isVertex(terminal.cell))
  47155. {
  47156. flipH = mxUtils.getValue(terminal.style, mxConstants.STYLE_FLIPH, 0) == 1;
  47157. flipV = mxUtils.getValue(terminal.style, mxConstants.STYLE_FLIPV, 0) == 1;
  47158. // Legacy support for stencilFlipH/V
  47159. if (terminal.shape != null && terminal.shape.stencil != null)
  47160. {
  47161. flipH = (mxUtils.getValue(terminal.style, 'stencilFlipH', 0) == 1) || flipH;
  47162. flipV = (mxUtils.getValue(terminal.style, 'stencilFlipV', 0) == 1) || flipV;
  47163. }
  47164. if (flipH)
  47165. {
  47166. point.x = 2 * bounds.getCenterX() - point.x;
  47167. }
  47168. if (flipV)
  47169. {
  47170. point.y = 2 * bounds.getCenterY() - point.y;
  47171. }
  47172. }
  47173. point = perimeter(bounds, terminal, point, orthogonal);
  47174. if (point != null)
  47175. {
  47176. if (flipH)
  47177. {
  47178. point.x = 2 * bounds.getCenterX() - point.x;
  47179. }
  47180. if (flipV)
  47181. {
  47182. point.y = 2 * bounds.getCenterY() - point.y;
  47183. }
  47184. }
  47185. }
  47186. }
  47187. if (point == null)
  47188. {
  47189. point = this.getPoint(terminal);
  47190. }
  47191. }
  47192. return point;
  47193. };
  47194. /**
  47195. * Function: getRoutingCenterX
  47196. *
  47197. * Returns the x-coordinate of the center point for automatic routing.
  47198. */
  47199. mxGraphView.prototype.getRoutingCenterX = function (state)
  47200. {
  47201. var f = (state.style != null) ? parseFloat(state.style
  47202. [mxConstants.STYLE_ROUTING_CENTER_X]) || 0 : 0;
  47203. return state.getCenterX() + f * state.width;
  47204. };
  47205. /**
  47206. * Function: getRoutingCenterY
  47207. *
  47208. * Returns the y-coordinate of the center point for automatic routing.
  47209. */
  47210. mxGraphView.prototype.getRoutingCenterY = function (state)
  47211. {
  47212. var f = (state.style != null) ? parseFloat(state.style
  47213. [mxConstants.STYLE_ROUTING_CENTER_Y]) || 0 : 0;
  47214. return state.getCenterY() + f * state.height;
  47215. };
  47216. /**
  47217. * Function: getPerimeterBounds
  47218. *
  47219. * Returns the perimeter bounds for the given terminal, edge pair as an
  47220. * <mxRectangle>.
  47221. *
  47222. * If you have a model where each terminal has a relative child that should
  47223. * act as the graphical endpoint for a connection from/to the terminal, then
  47224. * this method can be replaced as follows:
  47225. *
  47226. * (code)
  47227. * var oldGetPerimeterBounds = mxGraphView.prototype.getPerimeterBounds;
  47228. * mxGraphView.prototype.getPerimeterBounds = function(terminal, edge, isSource)
  47229. * {
  47230. * var model = this.graph.getModel();
  47231. * var childCount = model.getChildCount(terminal.cell);
  47232. *
  47233. * if (childCount > 0)
  47234. * {
  47235. * var child = model.getChildAt(terminal.cell, 0);
  47236. * var geo = model.getGeometry(child);
  47237. *
  47238. * if (geo != null &&
  47239. * geo.relative)
  47240. * {
  47241. * var state = this.getState(child);
  47242. *
  47243. * if (state != null)
  47244. * {
  47245. * terminal = state;
  47246. * }
  47247. * }
  47248. * }
  47249. *
  47250. * return oldGetPerimeterBounds.apply(this, arguments);
  47251. * };
  47252. * (end)
  47253. *
  47254. * Parameters:
  47255. *
  47256. * terminal - <mxCellState> that represents the terminal.
  47257. * border - Number that adds a border between the shape and the perimeter.
  47258. */
  47259. mxGraphView.prototype.getPerimeterBounds = function(terminal, border)
  47260. {
  47261. border = (border != null) ? border : 0;
  47262. if (terminal != null)
  47263. {
  47264. border += parseFloat(terminal.style[mxConstants.STYLE_PERIMETER_SPACING] || 0);
  47265. }
  47266. return terminal.getPerimeterBounds(border * this.scale);
  47267. };
  47268. /**
  47269. * Function: getPerimeterFunction
  47270. *
  47271. * Returns the perimeter function for the given state.
  47272. */
  47273. mxGraphView.prototype.getPerimeterFunction = function(state)
  47274. {
  47275. var perimeter = state.style[mxConstants.STYLE_PERIMETER];
  47276. // Converts string values to objects
  47277. if (typeof(perimeter) == "string")
  47278. {
  47279. var tmp = mxStyleRegistry.getValue(perimeter);
  47280. if (tmp == null && this.isAllowEval())
  47281. {
  47282. tmp = mxUtils.eval(perimeter);
  47283. }
  47284. perimeter = tmp;
  47285. }
  47286. if (typeof(perimeter) == "function")
  47287. {
  47288. return perimeter;
  47289. }
  47290. return null;
  47291. };
  47292. /**
  47293. * Function: getNextPoint
  47294. *
  47295. * Returns the nearest point in the list of absolute points or the center
  47296. * of the opposite terminal.
  47297. *
  47298. * Parameters:
  47299. *
  47300. * edge - <mxCellState> that represents the edge.
  47301. * opposite - <mxCellState> that represents the opposite terminal.
  47302. * source - Boolean indicating if the next point for the source or target
  47303. * should be returned.
  47304. */
  47305. mxGraphView.prototype.getNextPoint = function(edge, opposite, source)
  47306. {
  47307. var pts = edge.absolutePoints;
  47308. var point = null;
  47309. if (pts != null && pts.length >= 2)
  47310. {
  47311. var count = pts.length;
  47312. point = pts[(source) ? Math.min(1, count - 1) : Math.max(0, count - 2)];
  47313. }
  47314. if (point == null && opposite != null)
  47315. {
  47316. point = new mxPoint(opposite.getCenterX(), opposite.getCenterY());
  47317. }
  47318. return point;
  47319. };
  47320. /**
  47321. * Function: getVisibleTerminal
  47322. *
  47323. * Returns the nearest ancestor terminal that is visible. The edge appears
  47324. * to be connected to this terminal on the display. The result of this method
  47325. * is cached in <mxCellState.getVisibleTerminalState>.
  47326. *
  47327. * Parameters:
  47328. *
  47329. * edge - <mxCell> whose visible terminal should be returned.
  47330. * source - Boolean that specifies if the source or target terminal
  47331. * should be returned.
  47332. */
  47333. mxGraphView.prototype.getVisibleTerminal = function(edge, source)
  47334. {
  47335. var model = this.graph.getModel();
  47336. var result = model.getTerminal(edge, source);
  47337. var best = result;
  47338. while (result != null && result != this.currentRoot)
  47339. {
  47340. if (!this.graph.isCellVisible(best) || this.isCellCollapsed(result))
  47341. {
  47342. best = result;
  47343. }
  47344. result = model.getParent(result);
  47345. }
  47346. // Checks if the result is valid for the current view state
  47347. if (best != null && (!model.contains(best) ||
  47348. model.getParent(best) == model.getRoot() ||
  47349. best == this.currentRoot))
  47350. {
  47351. best = null;
  47352. }
  47353. return best;
  47354. };
  47355. /**
  47356. * Function: updateEdgeBounds
  47357. *
  47358. * Updates the given state using the bounding box of t
  47359. * he absolute points.
  47360. * Also updates <mxCellState.terminalDistance>, <mxCellState.length> and
  47361. * <mxCellState.segments>.
  47362. *
  47363. * Parameters:
  47364. *
  47365. * state - <mxCellState> whose bounds should be updated.
  47366. */
  47367. mxGraphView.prototype.updateEdgeBounds = function(state)
  47368. {
  47369. var points = state.absolutePoints;
  47370. var p0 = points[0];
  47371. var pe = points[points.length - 1];
  47372. if (p0.x != pe.x || p0.y != pe.y)
  47373. {
  47374. var dx = pe.x - p0.x;
  47375. var dy = pe.y - p0.y;
  47376. state.terminalDistance = Math.sqrt(dx * dx + dy * dy);
  47377. }
  47378. else
  47379. {
  47380. state.terminalDistance = 0;
  47381. }
  47382. var length = 0;
  47383. var segments = [];
  47384. var pt = p0;
  47385. if (pt != null)
  47386. {
  47387. var minX = pt.x;
  47388. var minY = pt.y;
  47389. var maxX = minX;
  47390. var maxY = minY;
  47391. for (var i = 1; i < points.length; i++)
  47392. {
  47393. var tmp = points[i];
  47394. if (tmp != null)
  47395. {
  47396. var dx = pt.x - tmp.x;
  47397. var dy = pt.y - tmp.y;
  47398. var segment = Math.sqrt(dx * dx + dy * dy);
  47399. segments.push(segment);
  47400. length += segment;
  47401. pt = tmp;
  47402. minX = Math.min(pt.x, minX);
  47403. minY = Math.min(pt.y, minY);
  47404. maxX = Math.max(pt.x, maxX);
  47405. maxY = Math.max(pt.y, maxY);
  47406. }
  47407. }
  47408. state.length = length;
  47409. state.segments = segments;
  47410. var markerSize = 1; // TODO: include marker size
  47411. state.x = minX;
  47412. state.y = minY;
  47413. state.width = Math.max(markerSize, maxX - minX);
  47414. state.height = Math.max(markerSize, maxY - minY);
  47415. }
  47416. };
  47417. /**
  47418. * Function: getPoint
  47419. *
  47420. * Returns the absolute point on the edge for the given relative
  47421. * <mxGeometry> as an <mxPoint>. The edge is represented by the given
  47422. * <mxCellState>.
  47423. *
  47424. * Parameters:
  47425. *
  47426. * state - <mxCellState> that represents the state of the parent edge.
  47427. * geometry - <mxGeometry> that represents the relative location.
  47428. */
  47429. mxGraphView.prototype.getPoint = function(state, geometry)
  47430. {
  47431. var x = state.getCenterX();
  47432. var y = state.getCenterY();
  47433. if (state.segments != null && (geometry == null || geometry.relative))
  47434. {
  47435. var gx = (geometry != null) ? geometry.x / 2 : 0;
  47436. var pointCount = state.absolutePoints.length;
  47437. var dist = Math.round((gx + 0.5) * state.length);
  47438. var segment = state.segments[0];
  47439. var length = 0;
  47440. var index = 1;
  47441. while (dist >= Math.round(length + segment) && index < pointCount - 1)
  47442. {
  47443. length += segment;
  47444. segment = state.segments[index++];
  47445. }
  47446. var factor = (segment == 0) ? 0 : (dist - length) / segment;
  47447. var p0 = state.absolutePoints[index-1];
  47448. var pe = state.absolutePoints[index];
  47449. if (p0 != null && pe != null)
  47450. {
  47451. var gy = 0;
  47452. var offsetX = 0;
  47453. var offsetY = 0;
  47454. if (geometry != null)
  47455. {
  47456. gy = geometry.y;
  47457. var offset = geometry.offset;
  47458. if (offset != null)
  47459. {
  47460. offsetX = offset.x;
  47461. offsetY = offset.y;
  47462. }
  47463. }
  47464. var dx = pe.x - p0.x;
  47465. var dy = pe.y - p0.y;
  47466. var nx = (segment == 0) ? 0 : dy / segment;
  47467. var ny = (segment == 0) ? 0 : dx / segment;
  47468. x = p0.x + dx * factor + (nx * gy + offsetX) * this.scale;
  47469. y = p0.y + dy * factor - (ny * gy - offsetY) * this.scale;
  47470. }
  47471. }
  47472. else if (geometry != null)
  47473. {
  47474. var offset = geometry.offset;
  47475. if (offset != null)
  47476. {
  47477. x += offset.x;
  47478. y += offset.y;
  47479. }
  47480. }
  47481. return new mxPoint(x, y);
  47482. };
  47483. /**
  47484. * Function: getRelativePoint
  47485. *
  47486. * Gets the relative point that describes the given, absolute label
  47487. * position for the given edge state.
  47488. *
  47489. * Parameters:
  47490. *
  47491. * state - <mxCellState> that represents the state of the parent edge.
  47492. * x - Specifies the x-coordinate of the absolute label location.
  47493. * y - Specifies the y-coordinate of the absolute label location.
  47494. */
  47495. mxGraphView.prototype.getRelativePoint = function(edgeState, x, y)
  47496. {
  47497. var model = this.graph.getModel();
  47498. var geometry = model.getGeometry(edgeState.cell);
  47499. if (geometry != null)
  47500. {
  47501. var pointCount = edgeState.absolutePoints.length;
  47502. if (geometry.relative && pointCount > 1)
  47503. {
  47504. var totalLength = edgeState.length;
  47505. var segments = edgeState.segments;
  47506. // Works which line segment the point of the label is closest to
  47507. var p0 = edgeState.absolutePoints[0];
  47508. var pe = edgeState.absolutePoints[1];
  47509. var minDist = mxUtils.ptSegDistSq(p0.x, p0.y, pe.x, pe.y, x, y);
  47510. var index = 0;
  47511. var tmp = 0;
  47512. var length = 0;
  47513. for (var i = 2; i < pointCount; i++)
  47514. {
  47515. tmp += segments[i - 2];
  47516. pe = edgeState.absolutePoints[i];
  47517. var dist = mxUtils.ptSegDistSq(p0.x, p0.y, pe.x, pe.y, x, y);
  47518. if (dist <= minDist)
  47519. {
  47520. minDist = dist;
  47521. index = i - 1;
  47522. length = tmp;
  47523. }
  47524. p0 = pe;
  47525. }
  47526. var seg = segments[index];
  47527. p0 = edgeState.absolutePoints[index];
  47528. pe = edgeState.absolutePoints[index + 1];
  47529. var x2 = p0.x;
  47530. var y2 = p0.y;
  47531. var x1 = pe.x;
  47532. var y1 = pe.y;
  47533. var px = x;
  47534. var py = y;
  47535. var xSegment = x2 - x1;
  47536. var ySegment = y2 - y1;
  47537. px -= x1;
  47538. py -= y1;
  47539. var projlenSq = 0;
  47540. px = xSegment - px;
  47541. py = ySegment - py;
  47542. var dotprod = px * xSegment + py * ySegment;
  47543. if (dotprod <= 0.0)
  47544. {
  47545. projlenSq = 0;
  47546. }
  47547. else
  47548. {
  47549. projlenSq = dotprod * dotprod
  47550. / (xSegment * xSegment + ySegment * ySegment);
  47551. }
  47552. var projlen = Math.sqrt(projlenSq);
  47553. if (projlen > seg)
  47554. {
  47555. projlen = seg;
  47556. }
  47557. var yDistance = Math.sqrt(mxUtils.ptSegDistSq(p0.x, p0.y, pe
  47558. .x, pe.y, x, y));
  47559. var direction = mxUtils.relativeCcw(p0.x, p0.y, pe.x, pe.y, x, y);
  47560. if (direction == -1)
  47561. {
  47562. yDistance = -yDistance;
  47563. }
  47564. // Constructs the relative point for the label
  47565. return new mxPoint(((totalLength / 2 - length - projlen) / totalLength) * -2,
  47566. yDistance / this.scale);
  47567. }
  47568. }
  47569. return new mxPoint();
  47570. };
  47571. /**
  47572. * Function: updateEdgeLabelOffset
  47573. *
  47574. * Updates <mxCellState.absoluteOffset> for the given state. The absolute
  47575. * offset is normally used for the position of the edge label. Is is
  47576. * calculated from the geometry as an absolute offset from the center
  47577. * between the two endpoints if the geometry is absolute, or as the
  47578. * relative distance between the center along the line and the absolute
  47579. * orthogonal distance if the geometry is relative.
  47580. *
  47581. * Parameters:
  47582. *
  47583. * state - <mxCellState> whose absolute offset should be updated.
  47584. */
  47585. mxGraphView.prototype.updateEdgeLabelOffset = function(state)
  47586. {
  47587. var points = state.absolutePoints;
  47588. state.absoluteOffset.x = state.getCenterX();
  47589. state.absoluteOffset.y = state.getCenterY();
  47590. if (points != null && points.length > 0 && state.segments != null)
  47591. {
  47592. var geometry = this.graph.getCellGeometry(state.cell);
  47593. if (geometry.relative)
  47594. {
  47595. var offset = this.getPoint(state, geometry);
  47596. if (offset != null)
  47597. {
  47598. state.absoluteOffset = offset;
  47599. }
  47600. }
  47601. else
  47602. {
  47603. var p0 = points[0];
  47604. var pe = points[points.length - 1];
  47605. if (p0 != null && pe != null)
  47606. {
  47607. var dx = pe.x - p0.x;
  47608. var dy = pe.y - p0.y;
  47609. var x0 = 0;
  47610. var y0 = 0;
  47611. var off = geometry.offset;
  47612. if (off != null)
  47613. {
  47614. x0 = off.x;
  47615. y0 = off.y;
  47616. }
  47617. var x = p0.x + dx / 2 + x0 * this.scale;
  47618. var y = p0.y + dy / 2 + y0 * this.scale;
  47619. state.absoluteOffset.x = x;
  47620. state.absoluteOffset.y = y;
  47621. }
  47622. }
  47623. }
  47624. };
  47625. /**
  47626. * Function: getState
  47627. *
  47628. * Returns the <mxCellState> for the given cell. If create is true, then
  47629. * the state is created if it does not yet exist.
  47630. *
  47631. * Parameters:
  47632. *
  47633. * cell - <mxCell> for which the <mxCellState> should be returned.
  47634. * create - Optional boolean indicating if a new state should be created
  47635. * if it does not yet exist. Default is false.
  47636. */
  47637. mxGraphView.prototype.getState = function(cell, create)
  47638. {
  47639. create = create || false;
  47640. var state = null;
  47641. if (cell != null)
  47642. {
  47643. state = this.states.get(cell);
  47644. if (create && (state == null || this.updateStyle) && this.graph.isCellVisible(cell))
  47645. {
  47646. if (state == null)
  47647. {
  47648. state = this.createState(cell);
  47649. this.states.put(cell, state);
  47650. }
  47651. else
  47652. {
  47653. state.style = this.graph.getCellStyle(cell);
  47654. }
  47655. }
  47656. }
  47657. return state;
  47658. };
  47659. /**
  47660. * Function: isRendering
  47661. *
  47662. * Returns <rendering>.
  47663. */
  47664. mxGraphView.prototype.isRendering = function()
  47665. {
  47666. return this.rendering;
  47667. };
  47668. /**
  47669. * Function: setRendering
  47670. *
  47671. * Sets <rendering>.
  47672. */
  47673. mxGraphView.prototype.setRendering = function(value)
  47674. {
  47675. this.rendering = value;
  47676. };
  47677. /**
  47678. * Function: isAllowEval
  47679. *
  47680. * Returns <allowEval>.
  47681. */
  47682. mxGraphView.prototype.isAllowEval = function()
  47683. {
  47684. return this.allowEval;
  47685. };
  47686. /**
  47687. * Function: setAllowEval
  47688. *
  47689. * Sets <allowEval>.
  47690. */
  47691. mxGraphView.prototype.setAllowEval = function(value)
  47692. {
  47693. this.allowEval = value;
  47694. };
  47695. /**
  47696. * Function: getStates
  47697. *
  47698. * Returns <states>.
  47699. */
  47700. mxGraphView.prototype.getStates = function()
  47701. {
  47702. return this.states;
  47703. };
  47704. /**
  47705. * Function: setStates
  47706. *
  47707. * Sets <states>.
  47708. */
  47709. mxGraphView.prototype.setStates = function(value)
  47710. {
  47711. this.states = value;
  47712. };
  47713. /**
  47714. * Function: getCellStates
  47715. *
  47716. * Returns the <mxCellStates> for the given array of <mxCells>. The array
  47717. * contains all states that are not null, that is, the returned array may
  47718. * have less elements than the given array. If no argument is given, then
  47719. * this returns <states>.
  47720. */
  47721. mxGraphView.prototype.getCellStates = function(cells)
  47722. {
  47723. if (cells == null)
  47724. {
  47725. return this.states;
  47726. }
  47727. else
  47728. {
  47729. var result = [];
  47730. for (var i = 0; i < cells.length; i++)
  47731. {
  47732. var state = this.getState(cells[i]);
  47733. if (state != null)
  47734. {
  47735. result.push(state);
  47736. }
  47737. }
  47738. return result;
  47739. }
  47740. };
  47741. /**
  47742. * Function: removeState
  47743. *
  47744. * Removes and returns the <mxCellState> for the given cell.
  47745. *
  47746. * Parameters:
  47747. *
  47748. * cell - <mxCell> for which the <mxCellState> should be removed.
  47749. */
  47750. mxGraphView.prototype.removeState = function(cell)
  47751. {
  47752. var state = null;
  47753. if (cell != null)
  47754. {
  47755. state = this.states.remove(cell);
  47756. if (state != null)
  47757. {
  47758. this.graph.cellRenderer.destroy(state);
  47759. state.invalid = true;
  47760. state.destroy();
  47761. }
  47762. }
  47763. return state;
  47764. };
  47765. /**
  47766. * Function: createState
  47767. *
  47768. * Creates and returns an <mxCellState> for the given cell and initializes
  47769. * it using <mxCellRenderer.initialize>.
  47770. *
  47771. * Parameters:
  47772. *
  47773. * cell - <mxCell> for which a new <mxCellState> should be created.
  47774. */
  47775. mxGraphView.prototype.createState = function(cell)
  47776. {
  47777. return new mxCellState(this, cell, this.graph.getCellStyle(cell));
  47778. };
  47779. /**
  47780. * Function: getCanvas
  47781. *
  47782. * Returns the DOM node that contains the background-, draw- and
  47783. * overlay- and decoratorpanes.
  47784. */
  47785. mxGraphView.prototype.getCanvas = function()
  47786. {
  47787. return this.canvas;
  47788. };
  47789. /**
  47790. * Function: getBackgroundPane
  47791. *
  47792. * Returns the DOM node that represents the background layer.
  47793. */
  47794. mxGraphView.prototype.getBackgroundPane = function()
  47795. {
  47796. return this.backgroundPane;
  47797. };
  47798. /**
  47799. * Function: getDrawPane
  47800. *
  47801. * Returns the DOM node that represents the main drawing layer.
  47802. */
  47803. mxGraphView.prototype.getDrawPane = function()
  47804. {
  47805. return this.drawPane;
  47806. };
  47807. /**
  47808. * Function: getOverlayPane
  47809. *
  47810. * Returns the DOM node that represents the layer above the drawing layer.
  47811. */
  47812. mxGraphView.prototype.getOverlayPane = function()
  47813. {
  47814. return this.overlayPane;
  47815. };
  47816. /**
  47817. * Function: getDecoratorPane
  47818. *
  47819. * Returns the DOM node that represents the topmost drawing layer.
  47820. */
  47821. mxGraphView.prototype.getDecoratorPane = function()
  47822. {
  47823. return this.decoratorPane;
  47824. };
  47825. /**
  47826. * Function: isContainerEvent
  47827. *
  47828. * Returns true if the event origin is one of the drawing panes or
  47829. * containers of the view.
  47830. */
  47831. mxGraphView.prototype.isContainerEvent = function(evt)
  47832. {
  47833. var source = mxEvent.getSource(evt);
  47834. return (source == this.graph.container ||
  47835. source.parentNode == this.backgroundPane ||
  47836. (source.parentNode != null &&
  47837. source.parentNode.parentNode == this.backgroundPane) ||
  47838. source == this.canvas.parentNode ||
  47839. source == this.canvas ||
  47840. source == this.backgroundPane ||
  47841. source == this.drawPane ||
  47842. source == this.overlayPane ||
  47843. source == this.decoratorPane);
  47844. };
  47845. /**
  47846. * Function: isScrollEvent
  47847. *
  47848. * Returns true if the event origin is one of the scrollbars of the
  47849. * container in IE. Such events are ignored.
  47850. */
  47851. mxGraphView.prototype.isScrollEvent = function(evt)
  47852. {
  47853. var offset = mxUtils.getOffset(this.graph.container);
  47854. var pt = new mxPoint(evt.clientX - offset.x, evt.clientY - offset.y);
  47855. var outWidth = this.graph.container.offsetWidth;
  47856. var inWidth = this.graph.container.clientWidth;
  47857. if (outWidth > inWidth && pt.x > inWidth + 2 && pt.x <= outWidth)
  47858. {
  47859. return true;
  47860. }
  47861. var outHeight = this.graph.container.offsetHeight;
  47862. var inHeight = this.graph.container.clientHeight;
  47863. if (outHeight > inHeight && pt.y > inHeight + 2 && pt.y <= outHeight)
  47864. {
  47865. return true;
  47866. }
  47867. return false;
  47868. };
  47869. /**
  47870. * Function: init
  47871. *
  47872. * Initializes the graph event dispatch loop for the specified container
  47873. * and invokes <create> to create the required DOM nodes for the display.
  47874. */
  47875. mxGraphView.prototype.init = function()
  47876. {
  47877. this.installListeners();
  47878. // Creates the DOM nodes for the respective display dialect
  47879. var graph = this.graph;
  47880. if (graph.dialect == mxConstants.DIALECT_SVG)
  47881. {
  47882. this.createSvg();
  47883. }
  47884. else if (graph.dialect == mxConstants.DIALECT_VML)
  47885. {
  47886. this.createVml();
  47887. }
  47888. else
  47889. {
  47890. this.createHtml();
  47891. }
  47892. };
  47893. /**
  47894. * Function: installListeners
  47895. *
  47896. * Installs the required listeners in the container.
  47897. */
  47898. mxGraphView.prototype.installListeners = function()
  47899. {
  47900. var graph = this.graph;
  47901. var container = graph.container;
  47902. if (container != null)
  47903. {
  47904. // Support for touch device gestures (eg. pinch to zoom)
  47905. // Double-tap handling is implemented in mxGraph.fireMouseEvent
  47906. if (mxClient.IS_TOUCH)
  47907. {
  47908. mxEvent.addListener(container, 'gesturestart', mxUtils.bind(this, function(evt)
  47909. {
  47910. graph.fireGestureEvent(evt);
  47911. mxEvent.consume(evt);
  47912. }));
  47913. mxEvent.addListener(container, 'gesturechange', mxUtils.bind(this, function(evt)
  47914. {
  47915. graph.fireGestureEvent(evt);
  47916. mxEvent.consume(evt);
  47917. }));
  47918. mxEvent.addListener(container, 'gestureend', mxUtils.bind(this, function(evt)
  47919. {
  47920. graph.fireGestureEvent(evt);
  47921. mxEvent.consume(evt);
  47922. }));
  47923. }
  47924. // Adds basic listeners for graph event dispatching
  47925. mxEvent.addGestureListeners(container, mxUtils.bind(this, function(evt)
  47926. {
  47927. // Condition to avoid scrollbar events starting a rubberband selection
  47928. if (this.isContainerEvent(evt) && ((!mxClient.IS_IE && !mxClient.IS_IE11 && !mxClient.IS_GC &&
  47929. !mxClient.IS_OP && !mxClient.IS_SF) || !this.isScrollEvent(evt)))
  47930. {
  47931. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt));
  47932. }
  47933. }),
  47934. mxUtils.bind(this, function(evt)
  47935. {
  47936. if (this.isContainerEvent(evt))
  47937. {
  47938. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt));
  47939. }
  47940. }),
  47941. mxUtils.bind(this, function(evt)
  47942. {
  47943. if (this.isContainerEvent(evt))
  47944. {
  47945. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  47946. }
  47947. }));
  47948. // Adds listener for double click handling on background, this does always
  47949. // use native event handler, we assume that the DOM of the background
  47950. // does not change during the double click
  47951. mxEvent.addListener(container, 'dblclick', mxUtils.bind(this, function(evt)
  47952. {
  47953. if (this.isContainerEvent(evt))
  47954. {
  47955. graph.dblClick(evt);
  47956. }
  47957. }));
  47958. // Workaround for touch events which started on some DOM node
  47959. // on top of the container, in which case the cells under the
  47960. // mouse for the move and up events are not detected.
  47961. var getState = function(evt)
  47962. {
  47963. var state = null;
  47964. // Workaround for touch events which started on some DOM node
  47965. // on top of the container, in which case the cells under the
  47966. // mouse for the move and up events are not detected.
  47967. if (mxClient.IS_TOUCH)
  47968. {
  47969. var x = mxEvent.getClientX(evt);
  47970. var y = mxEvent.getClientY(evt);
  47971. // Dispatches the drop event to the graph which
  47972. // consumes and executes the source function
  47973. var pt = mxUtils.convertPoint(container, x, y);
  47974. state = graph.view.getState(graph.getCellAt(pt.x, pt.y));
  47975. }
  47976. return state;
  47977. };
  47978. // Adds basic listeners for graph event dispatching outside of the
  47979. // container and finishing the handling of a single gesture
  47980. // Implemented via graph event dispatch loop to avoid duplicate events
  47981. // in Firefox and Chrome
  47982. graph.addMouseListener(
  47983. {
  47984. mouseDown: function(sender, me)
  47985. {
  47986. graph.popupMenuHandler.hideMenu();
  47987. },
  47988. mouseMove: function() { },
  47989. mouseUp: function() { }
  47990. });
  47991. this.moveHandler = mxUtils.bind(this, function(evt)
  47992. {
  47993. // Hides the tooltip if mouse is outside container
  47994. if (graph.tooltipHandler != null && graph.tooltipHandler.isHideOnHover())
  47995. {
  47996. graph.tooltipHandler.hide();
  47997. }
  47998. if (this.captureDocumentGesture && graph.isMouseDown && graph.container != null &&
  47999. !this.isContainerEvent(evt) && graph.container.style.display != 'none' &&
  48000. graph.container.style.visibility != 'hidden' && !mxEvent.isConsumed(evt))
  48001. {
  48002. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt, getState(evt)));
  48003. }
  48004. });
  48005. this.endHandler = mxUtils.bind(this, function(evt)
  48006. {
  48007. if (this.captureDocumentGesture && graph.isMouseDown && graph.container != null &&
  48008. !this.isContainerEvent(evt) && graph.container.style.display != 'none' &&
  48009. graph.container.style.visibility != 'hidden')
  48010. {
  48011. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  48012. }
  48013. });
  48014. mxEvent.addGestureListeners(document, null, this.moveHandler, this.endHandler);
  48015. }
  48016. };
  48017. /**
  48018. * Function: create
  48019. *
  48020. * Creates the DOM nodes for the HTML display.
  48021. */
  48022. mxGraphView.prototype.createHtml = function()
  48023. {
  48024. var container = this.graph.container;
  48025. if (container != null)
  48026. {
  48027. this.canvas = this.createHtmlPane('100%', '100%');
  48028. this.canvas.style.overflow = 'hidden';
  48029. // Uses minimal size for inner DIVs on Canvas. This is required
  48030. // for correct event processing in IE. If we have an overlapping
  48031. // DIV then the events on the cells are only fired for labels.
  48032. this.backgroundPane = this.createHtmlPane('1px', '1px');
  48033. this.drawPane = this.createHtmlPane('1px', '1px');
  48034. this.overlayPane = this.createHtmlPane('1px', '1px');
  48035. this.decoratorPane = this.createHtmlPane('1px', '1px');
  48036. this.canvas.appendChild(this.backgroundPane);
  48037. this.canvas.appendChild(this.drawPane);
  48038. this.canvas.appendChild(this.overlayPane);
  48039. this.canvas.appendChild(this.decoratorPane);
  48040. container.appendChild(this.canvas);
  48041. this.updateContainerStyle(container);
  48042. // Implements minWidth/minHeight in quirks mode
  48043. if (mxClient.IS_QUIRKS)
  48044. {
  48045. var onResize = mxUtils.bind(this, function(evt)
  48046. {
  48047. var bounds = this.getGraphBounds();
  48048. var width = bounds.x + bounds.width + this.graph.border;
  48049. var height = bounds.y + bounds.height + this.graph.border;
  48050. this.updateHtmlCanvasSize(width, height);
  48051. });
  48052. mxEvent.addListener(window, 'resize', onResize);
  48053. }
  48054. }
  48055. };
  48056. /**
  48057. * Function: updateHtmlCanvasSize
  48058. *
  48059. * Updates the size of the HTML canvas.
  48060. */
  48061. mxGraphView.prototype.updateHtmlCanvasSize = function(width, height)
  48062. {
  48063. if (this.graph.container != null)
  48064. {
  48065. var ow = this.graph.container.offsetWidth;
  48066. var oh = this.graph.container.offsetHeight;
  48067. if (ow < width)
  48068. {
  48069. this.canvas.style.width = width + 'px';
  48070. }
  48071. else
  48072. {
  48073. this.canvas.style.width = '100%';
  48074. }
  48075. if (oh < height)
  48076. {
  48077. this.canvas.style.height = height + 'px';
  48078. }
  48079. else
  48080. {
  48081. this.canvas.style.height = '100%';
  48082. }
  48083. }
  48084. };
  48085. /**
  48086. * Function: createHtmlPane
  48087. *
  48088. * Creates and returns a drawing pane in HTML (DIV).
  48089. */
  48090. mxGraphView.prototype.createHtmlPane = function(width, height)
  48091. {
  48092. var pane = document.createElement('DIV');
  48093. if (width != null && height != null)
  48094. {
  48095. pane.style.position = 'absolute';
  48096. pane.style.left = '0px';
  48097. pane.style.top = '0px';
  48098. pane.style.width = width;
  48099. pane.style.height = height;
  48100. }
  48101. else
  48102. {
  48103. pane.style.position = 'relative';
  48104. }
  48105. return pane;
  48106. };
  48107. /**
  48108. * Function: create
  48109. *
  48110. * Creates the DOM nodes for the VML display.
  48111. */
  48112. mxGraphView.prototype.createVml = function()
  48113. {
  48114. var container = this.graph.container;
  48115. if (container != null)
  48116. {
  48117. var width = container.offsetWidth;
  48118. var height = container.offsetHeight;
  48119. this.canvas = this.createVmlPane(width, height);
  48120. this.canvas.style.overflow = 'hidden';
  48121. this.backgroundPane = this.createVmlPane(width, height);
  48122. this.drawPane = this.createVmlPane(width, height);
  48123. this.overlayPane = this.createVmlPane(width, height);
  48124. this.decoratorPane = this.createVmlPane(width, height);
  48125. this.canvas.appendChild(this.backgroundPane);
  48126. this.canvas.appendChild(this.drawPane);
  48127. this.canvas.appendChild(this.overlayPane);
  48128. this.canvas.appendChild(this.decoratorPane);
  48129. container.appendChild(this.canvas);
  48130. }
  48131. };
  48132. /**
  48133. * Function: createVmlPane
  48134. *
  48135. * Creates a drawing pane in VML (group).
  48136. */
  48137. mxGraphView.prototype.createVmlPane = function(width, height)
  48138. {
  48139. var pane = document.createElement(mxClient.VML_PREFIX + ':group');
  48140. // At this point the width and height are potentially
  48141. // uninitialized. That's OK.
  48142. pane.style.position = 'absolute';
  48143. pane.style.left = '0px';
  48144. pane.style.top = '0px';
  48145. pane.style.width = width + 'px';
  48146. pane.style.height = height + 'px';
  48147. pane.setAttribute('coordsize', width + ',' + height);
  48148. pane.setAttribute('coordorigin', '0,0');
  48149. return pane;
  48150. };
  48151. /**
  48152. * Function: create
  48153. *
  48154. * Creates and returns the DOM nodes for the SVG display.
  48155. */
  48156. mxGraphView.prototype.createSvg = function()
  48157. {
  48158. var container = this.graph.container;
  48159. this.canvas = document.createElementNS(mxConstants.NS_SVG, 'g');
  48160. // For background image
  48161. this.backgroundPane = document.createElementNS(mxConstants.NS_SVG, 'g');
  48162. this.canvas.appendChild(this.backgroundPane);
  48163. // Adds two layers (background is early feature)
  48164. this.drawPane = document.createElementNS(mxConstants.NS_SVG, 'g');
  48165. this.canvas.appendChild(this.drawPane);
  48166. this.overlayPane = document.createElementNS(mxConstants.NS_SVG, 'g');
  48167. this.canvas.appendChild(this.overlayPane);
  48168. this.decoratorPane = document.createElementNS(mxConstants.NS_SVG, 'g');
  48169. this.canvas.appendChild(this.decoratorPane);
  48170. var root = document.createElementNS(mxConstants.NS_SVG, 'svg');
  48171. root.style.left = '0px';
  48172. root.style.top = '0px';
  48173. root.style.width = '100%';
  48174. root.style.height = '100%';
  48175. // NOTE: In standards mode, the SVG must have block layout
  48176. // in order for the container DIV to not show scrollbars.
  48177. root.style.display = 'block';
  48178. root.appendChild(this.canvas);
  48179. // Workaround for scrollbars in IE11 and below
  48180. if (mxClient.IS_IE || mxClient.IS_IE11)
  48181. {
  48182. root.style.overflow = 'hidden';
  48183. }
  48184. if (container != null)
  48185. {
  48186. container.appendChild(root);
  48187. this.updateContainerStyle(container);
  48188. }
  48189. };
  48190. /**
  48191. * Function: updateContainerStyle
  48192. *
  48193. * Updates the style of the container after installing the SVG DOM elements.
  48194. */
  48195. mxGraphView.prototype.updateContainerStyle = function(container)
  48196. {
  48197. // Workaround for offset of container
  48198. var style = mxUtils.getCurrentStyle(container);
  48199. if (style != null && style.position == 'static')
  48200. {
  48201. container.style.position = 'relative';
  48202. }
  48203. // Disables built-in pan and zoom in IE10 and later
  48204. if (mxClient.IS_POINTER)
  48205. {
  48206. container.style.touchAction = 'none';
  48207. }
  48208. };
  48209. /**
  48210. * Function: destroy
  48211. *
  48212. * Destroys the view and all its resources.
  48213. */
  48214. mxGraphView.prototype.destroy = function()
  48215. {
  48216. var root = (this.canvas != null) ? this.canvas.ownerSVGElement : null;
  48217. if (root == null)
  48218. {
  48219. root = this.canvas;
  48220. }
  48221. if (root != null && root.parentNode != null)
  48222. {
  48223. this.clear(this.currentRoot, true);
  48224. mxEvent.removeGestureListeners(document, null, this.moveHandler, this.endHandler);
  48225. mxEvent.release(this.graph.container);
  48226. root.parentNode.removeChild(root);
  48227. this.moveHandler = null;
  48228. this.endHandler = null;
  48229. this.canvas = null;
  48230. this.backgroundPane = null;
  48231. this.drawPane = null;
  48232. this.overlayPane = null;
  48233. this.decoratorPane = null;
  48234. }
  48235. };
  48236. /**
  48237. * Class: mxCurrentRootChange
  48238. *
  48239. * Action to change the current root in a view.
  48240. *
  48241. * Constructor: mxCurrentRootChange
  48242. *
  48243. * Constructs a change of the current root in the given view.
  48244. */
  48245. function mxCurrentRootChange(view, root)
  48246. {
  48247. this.view = view;
  48248. this.root = root;
  48249. this.previous = root;
  48250. this.isUp = root == null;
  48251. if (!this.isUp)
  48252. {
  48253. var tmp = this.view.currentRoot;
  48254. var model = this.view.graph.getModel();
  48255. while (tmp != null)
  48256. {
  48257. if (tmp == root)
  48258. {
  48259. this.isUp = true;
  48260. break;
  48261. }
  48262. tmp = model.getParent(tmp);
  48263. }
  48264. }
  48265. };
  48266. /**
  48267. * Function: execute
  48268. *
  48269. * Changes the current root of the view.
  48270. */
  48271. mxCurrentRootChange.prototype.execute = function()
  48272. {
  48273. var tmp = this.view.currentRoot;
  48274. this.view.currentRoot = this.previous;
  48275. this.previous = tmp;
  48276. var translate = this.view.graph.getTranslateForRoot(this.view.currentRoot);
  48277. if (translate != null)
  48278. {
  48279. this.view.translate = new mxPoint(-translate.x, -translate.y);
  48280. }
  48281. if (this.isUp)
  48282. {
  48283. this.view.clear(this.view.currentRoot, true);
  48284. this.view.validate();
  48285. }
  48286. else
  48287. {
  48288. this.view.refresh();
  48289. }
  48290. var name = (this.isUp) ? mxEvent.UP : mxEvent.DOWN;
  48291. this.view.fireEvent(new mxEventObject(name,
  48292. 'root', this.view.currentRoot, 'previous', this.previous));
  48293. this.isUp = !this.isUp;
  48294. };
  48295. /**
  48296. * Copyright (c) 2006-2015, JGraph Ltd
  48297. * Copyright (c) 2006-2015, Gaudenz Alder
  48298. */
  48299. /**
  48300. * Class: mxGraph
  48301. *
  48302. * Extends <mxEventSource> to implement a graph component for
  48303. * the browser. This is the main class of the package. To activate
  48304. * panning and connections use <setPanning> and <setConnectable>.
  48305. * For rubberband selection you must create a new instance of
  48306. * <mxRubberband>. The following listeners are added to
  48307. * <mouseListeners> by default:
  48308. *
  48309. * - <tooltipHandler>: <mxTooltipHandler> that displays tooltips
  48310. * - <panningHandler>: <mxPanningHandler> for panning and popup menus
  48311. * - <connectionHandler>: <mxConnectionHandler> for creating connections
  48312. * - <graphHandler>: <mxGraphHandler> for moving and cloning cells
  48313. *
  48314. * These listeners will be called in the above order if they are enabled.
  48315. *
  48316. * Background Images:
  48317. *
  48318. * To display a background image, set the image, image width and
  48319. * image height using <setBackgroundImage>. If one of the
  48320. * above values has changed then the <view>'s <mxGraphView.validate>
  48321. * should be invoked.
  48322. *
  48323. * Cell Images:
  48324. *
  48325. * To use images in cells, a shape must be specified in the default
  48326. * vertex style (or any named style). Possible shapes are
  48327. * <mxConstants.SHAPE_IMAGE> and <mxConstants.SHAPE_LABEL>.
  48328. * The code to change the shape used in the default vertex style,
  48329. * the following code is used:
  48330. *
  48331. * (code)
  48332. * var style = graph.getStylesheet().getDefaultVertexStyle();
  48333. * style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_IMAGE;
  48334. * (end)
  48335. *
  48336. * For the default vertex style, the image to be displayed can be
  48337. * specified in a cell's style using the <mxConstants.STYLE_IMAGE>
  48338. * key and the image URL as a value, for example:
  48339. *
  48340. * (code)
  48341. * image=http://www.example.com/image.gif
  48342. * (end)
  48343. *
  48344. * For a named style, the the stylename must be the first element
  48345. * of the cell style:
  48346. *
  48347. * (code)
  48348. * stylename;image=http://www.example.com/image.gif
  48349. * (end)
  48350. *
  48351. * A cell style can have any number of key=value pairs added, divided
  48352. * by a semicolon as follows:
  48353. *
  48354. * (code)
  48355. * [stylename;|key=value;]
  48356. * (end)
  48357. *
  48358. * Labels:
  48359. *
  48360. * The cell labels are defined by <getLabel> which uses <convertValueToString>
  48361. * if <labelsVisible> is true. If a label must be rendered as HTML markup, then
  48362. * <isHtmlLabel> should return true for the respective cell. If all labels
  48363. * contain HTML markup, <htmlLabels> can be set to true. NOTE: Enabling HTML
  48364. * labels carries a possible security risk (see the section on security in
  48365. * the manual).
  48366. *
  48367. * If wrapping is needed for a label, then <isHtmlLabel> and <isWrapping> must
  48368. * return true for the cell whose label should be wrapped. See <isWrapping> for
  48369. * an example.
  48370. *
  48371. * If clipping is needed to keep the rendering of a HTML label inside the
  48372. * bounds of its vertex, then <isClipping> should return true for the
  48373. * respective cell.
  48374. *
  48375. * By default, edge labels are movable and vertex labels are fixed. This can be
  48376. * changed by setting <edgeLabelsMovable> and <vertexLabelsMovable>, or by
  48377. * overriding <isLabelMovable>.
  48378. *
  48379. * In-place Editing:
  48380. *
  48381. * In-place editing is started with a doubleclick or by typing F2.
  48382. * Programmatically, <edit> is used to check if the cell is editable
  48383. * (<isCellEditable>) and call <startEditingAtCell>, which invokes
  48384. * <mxCellEditor.startEditing>. The editor uses the value returned
  48385. * by <getEditingValue> as the editing value.
  48386. *
  48387. * After in-place editing, <labelChanged> is called, which invokes
  48388. * <mxGraphModel.setValue>, which in turn calls
  48389. * <mxGraphModel.valueForCellChanged> via <mxValueChange>.
  48390. *
  48391. * The event that triggers in-place editing is passed through to the
  48392. * <cellEditor>, which may take special actions depending on the type of the
  48393. * event or mouse location, and is also passed to <getEditingValue>. The event
  48394. * is then passed back to the event processing functions which can perform
  48395. * specific actions based on the trigger event.
  48396. *
  48397. * Tooltips:
  48398. *
  48399. * Tooltips are implemented by <getTooltip>, which calls <getTooltipForCell>
  48400. * if a cell is under the mousepointer. The default implementation checks if
  48401. * the cell has a getTooltip function and calls it if it exists. Hence, in order
  48402. * to provide custom tooltips, the cell must provide a getTooltip function, or
  48403. * one of the two above functions must be overridden.
  48404. *
  48405. * Typically, for custom cell tooltips, the latter function is overridden as
  48406. * follows:
  48407. *
  48408. * (code)
  48409. * graph.getTooltipForCell = function(cell)
  48410. * {
  48411. * var label = this.convertValueToString(cell);
  48412. * return 'Tooltip for '+label;
  48413. * }
  48414. * (end)
  48415. *
  48416. * When using a config file, the function is overridden in the mxGraph section
  48417. * using the following entry:
  48418. *
  48419. * (code)
  48420. * <add as="getTooltipForCell"><![CDATA[
  48421. * function(cell)
  48422. * {
  48423. * var label = this.convertValueToString(cell);
  48424. * return 'Tooltip for '+label;
  48425. * }
  48426. * ]]></add>
  48427. * (end)
  48428. *
  48429. * "this" refers to the graph in the implementation, so for example to check if
  48430. * a cell is an edge, you use this.getModel().isEdge(cell)
  48431. *
  48432. * For replacing the default implementation of <getTooltipForCell> (rather than
  48433. * replacing the function on a specific instance), the following code should be
  48434. * used after loading the JavaScript files, but before creating a new mxGraph
  48435. * instance using <mxGraph>:
  48436. *
  48437. * (code)
  48438. * mxGraph.prototype.getTooltipForCell = function(cell)
  48439. * {
  48440. * var label = this.convertValueToString(cell);
  48441. * return 'Tooltip for '+label;
  48442. * }
  48443. * (end)
  48444. *
  48445. * Shapes & Styles:
  48446. *
  48447. * The implementation of new shapes is demonstrated in the examples. We'll assume
  48448. * that we have implemented a custom shape with the name BoxShape which we want
  48449. * to use for drawing vertices. To use this shape, it must first be registered in
  48450. * the cell renderer as follows:
  48451. *
  48452. * (code)
  48453. * mxCellRenderer.registerShape('box', BoxShape);
  48454. * (end)
  48455. *
  48456. * The code registers the BoxShape constructor under the name box in the cell
  48457. * renderer of the graph. The shape can now be referenced using the shape-key in
  48458. * a style definition. (The cell renderer contains a set of additional shapes,
  48459. * namely one for each constant with a SHAPE-prefix in <mxConstants>.)
  48460. *
  48461. * Styles are a collection of key, value pairs and a stylesheet is a collection
  48462. * of named styles. The names are referenced by the cellstyle, which is stored
  48463. * in <mxCell.style> with the following format: [stylename;|key=value;]. The
  48464. * string is resolved to a collection of key, value pairs, where the keys are
  48465. * overridden with the values in the string.
  48466. *
  48467. * When introducing a new shape, the name under which the shape is registered
  48468. * must be used in the stylesheet. There are three ways of doing this:
  48469. *
  48470. * - By changing the default style, so that all vertices will use the new
  48471. * shape
  48472. * - By defining a new style, so that only vertices with the respective
  48473. * cellstyle will use the new shape
  48474. * - By using shape=box in the cellstyle's optional list of key, value pairs
  48475. * to be overridden
  48476. *
  48477. * In the first case, the code to fetch and modify the default style for
  48478. * vertices is as follows:
  48479. *
  48480. * (code)
  48481. * var style = graph.getStylesheet().getDefaultVertexStyle();
  48482. * style[mxConstants.STYLE_SHAPE] = 'box';
  48483. * (end)
  48484. *
  48485. * The code takes the default vertex style, which is used for all vertices that
  48486. * do not have a specific cellstyle, and modifies the value for the shape-key
  48487. * in-place to use the new BoxShape for drawing vertices. This is done by
  48488. * assigning the box value in the second line, which refers to the name of the
  48489. * BoxShape in the cell renderer.
  48490. *
  48491. * In the second case, a collection of key, value pairs is created and then
  48492. * added to the stylesheet under a new name. In order to distinguish the
  48493. * shapename and the stylename we'll use boxstyle for the stylename:
  48494. *
  48495. * (code)
  48496. * var style = new Object();
  48497. * style[mxConstants.STYLE_SHAPE] = 'box';
  48498. * style[mxConstants.STYLE_STROKECOLOR] = '#000000';
  48499. * style[mxConstants.STYLE_FONTCOLOR] = '#000000';
  48500. * graph.getStylesheet().putCellStyle('boxstyle', style);
  48501. * (end)
  48502. *
  48503. * The code adds a new style with the name boxstyle to the stylesheet. To use
  48504. * this style with a cell, it must be referenced from the cellstyle as follows:
  48505. *
  48506. * (code)
  48507. * var vertex = graph.insertVertex(parent, null, 'Hello, World!', 20, 20, 80, 20,
  48508. * 'boxstyle');
  48509. * (end)
  48510. *
  48511. * To summarize, each new shape must be registered in the <mxCellRenderer> with
  48512. * a unique name. That name is then used as the value of the shape-key in a
  48513. * default or custom style. If there are multiple custom shapes, then there
  48514. * should be a separate style for each shape.
  48515. *
  48516. * Inheriting Styles:
  48517. *
  48518. * For fill-, stroke-, gradient-, font- and indicatorColors special keywords
  48519. * can be used. The inherit keyword for one of these colors will inherit the
  48520. * color for the same key from the parent cell. The swimlane keyword does the
  48521. * same, but inherits from the nearest swimlane in the ancestor hierarchy.
  48522. * Finally, the indicated keyword will use the color of the indicator as the
  48523. * color for the given key.
  48524. *
  48525. * Scrollbars:
  48526. *
  48527. * The <containers> overflow CSS property defines if scrollbars are used to
  48528. * display the graph. For values of 'auto' or 'scroll', the scrollbars will
  48529. * be shown. Note that the <resizeContainer> flag is normally not used
  48530. * together with scrollbars, as it will resize the container to match the
  48531. * size of the graph after each change.
  48532. *
  48533. * Multiplicities and Validation:
  48534. *
  48535. * To control the possible connections in mxGraph, <getEdgeValidationError> is
  48536. * used. The default implementation of the function uses <multiplicities>,
  48537. * which is an array of <mxMultiplicity>. Using this class allows to establish
  48538. * simple multiplicities, which are enforced by the graph.
  48539. *
  48540. * The <mxMultiplicity> uses <mxCell.is> to determine for which terminals it
  48541. * applies. The default implementation of <mxCell.is> works with DOM nodes (XML
  48542. * nodes) and checks if the given type parameter matches the nodeName of the
  48543. * node (case insensitive). Optionally, an attributename and value can be
  48544. * specified which are also checked.
  48545. *
  48546. * <getEdgeValidationError> is called whenever the connectivity of an edge
  48547. * changes. It returns an empty string or an error message if the edge is
  48548. * invalid or null if the edge is valid. If the returned string is not empty
  48549. * then it is displayed as an error message.
  48550. *
  48551. * <mxMultiplicity> allows to specify the multiplicity between a terminal and
  48552. * its possible neighbors. For example, if any rectangle may only be connected
  48553. * to, say, a maximum of two circles you can add the following rule to
  48554. * <multiplicities>:
  48555. *
  48556. * (code)
  48557. * graph.multiplicities.push(new mxMultiplicity(
  48558. * true, 'rectangle', null, null, 0, 2, ['circle'],
  48559. * 'Only 2 targets allowed',
  48560. * 'Only shape targets allowed'));
  48561. * (end)
  48562. *
  48563. * This will display the first error message whenever a rectangle is connected
  48564. * to more than two circles and the second error message if a rectangle is
  48565. * connected to anything but a circle.
  48566. *
  48567. * For certain multiplicities, such as a minimum of 1 connection, which cannot
  48568. * be enforced at cell creation time (unless the cell is created together with
  48569. * the connection), mxGraph offers <validate> which checks all multiplicities
  48570. * for all cells and displays the respective error messages in an overlay icon
  48571. * on the cells.
  48572. *
  48573. * If a cell is collapsed and contains validation errors, a respective warning
  48574. * icon is attached to the collapsed cell.
  48575. *
  48576. * Auto-Layout:
  48577. *
  48578. * For automatic layout, the <getLayout> hook is provided in <mxLayoutManager>.
  48579. * It can be overridden to return a layout algorithm for the children of a
  48580. * given cell.
  48581. *
  48582. * Unconnected edges:
  48583. *
  48584. * The default values for all switches are designed to meet the requirements of
  48585. * general diagram drawing applications. A very typical set of settings to
  48586. * avoid edges that are not connected is the following:
  48587. *
  48588. * (code)
  48589. * graph.setAllowDanglingEdges(false);
  48590. * graph.setDisconnectOnMove(false);
  48591. * (end)
  48592. *
  48593. * Setting the <cloneInvalidEdges> switch to true is optional. This switch
  48594. * controls if edges are inserted after a copy, paste or clone-drag if they are
  48595. * invalid. For example, edges are invalid if copied or control-dragged without
  48596. * having selected the corresponding terminals and allowDanglingEdges is
  48597. * false, in which case the edges will not be cloned if the switch is false.
  48598. *
  48599. * Output:
  48600. *
  48601. * To produce an XML representation for a diagram, the following code can be
  48602. * used.
  48603. *
  48604. * (code)
  48605. * var enc = new mxCodec(mxUtils.createXmlDocument());
  48606. * var node = enc.encode(graph.getModel());
  48607. * (end)
  48608. *
  48609. * This will produce an XML node than can be handled using the DOM API or
  48610. * turned into a string representation using the following code:
  48611. *
  48612. * (code)
  48613. * var xml = mxUtils.getXml(node);
  48614. * (end)
  48615. *
  48616. * To obtain a formatted string, mxUtils.getPrettyXml can be used instead.
  48617. *
  48618. * This string can now be stored in a local persistent storage (for example
  48619. * using Google Gears) or it can be passed to a backend using mxUtils.post as
  48620. * follows. The url variable is the URL of the Java servlet, PHP page or HTTP
  48621. * handler, depending on the server.
  48622. *
  48623. * (code)
  48624. * var xmlString = encodeURIComponent(mxUtils.getXml(node));
  48625. * mxUtils.post(url, 'xml='+xmlString, function(req)
  48626. * {
  48627. * // Process server response using req of type mxXmlRequest
  48628. * });
  48629. * (end)
  48630. *
  48631. * Input:
  48632. *
  48633. * To load an XML representation of a diagram into an existing graph object
  48634. * mxUtils.load can be used as follows. The url variable is the URL of the Java
  48635. * servlet, PHP page or HTTP handler that produces the XML string.
  48636. *
  48637. * (code)
  48638. * var xmlDoc = mxUtils.load(url).getXml();
  48639. * var node = xmlDoc.documentElement;
  48640. * var dec = new mxCodec(node.ownerDocument);
  48641. * dec.decode(node, graph.getModel());
  48642. * (end)
  48643. *
  48644. * For creating a page that loads the client and a diagram using a single
  48645. * request please refer to the deployment examples in the backends.
  48646. *
  48647. * Functional dependencies:
  48648. *
  48649. * (see images/callgraph.png)
  48650. *
  48651. * Resources:
  48652. *
  48653. * resources/graph - Language resources for mxGraph
  48654. *
  48655. * Group: Events
  48656. *
  48657. * Event: mxEvent.ROOT
  48658. *
  48659. * Fires if the root in the model has changed. This event has no properties.
  48660. *
  48661. * Event: mxEvent.ALIGN_CELLS
  48662. *
  48663. * Fires between begin- and endUpdate in <alignCells>. The <code>cells</code>
  48664. * and <code>align</code> properties contain the respective arguments that were
  48665. * passed to <alignCells>.
  48666. *
  48667. * Event: mxEvent.FLIP_EDGE
  48668. *
  48669. * Fires between begin- and endUpdate in <flipEdge>. The <code>edge</code>
  48670. * property contains the edge passed to <flipEdge>.
  48671. *
  48672. * Event: mxEvent.ORDER_CELLS
  48673. *
  48674. * Fires between begin- and endUpdate in <orderCells>. The <code>cells</code>
  48675. * and <code>back</code> properties contain the respective arguments that were
  48676. * passed to <orderCells>.
  48677. *
  48678. * Event: mxEvent.CELLS_ORDERED
  48679. *
  48680. * Fires between begin- and endUpdate in <cellsOrdered>. The <code>cells</code>
  48681. * and <code>back</code> arguments contain the respective arguments that were
  48682. * passed to <cellsOrdered>.
  48683. *
  48684. * Event: mxEvent.GROUP_CELLS
  48685. *
  48686. * Fires between begin- and endUpdate in <groupCells>. The <code>group</code>,
  48687. * <code>cells</code> and <code>border</code> arguments contain the respective
  48688. * arguments that were passed to <groupCells>.
  48689. *
  48690. * Event: mxEvent.UNGROUP_CELLS
  48691. *
  48692. * Fires between begin- and endUpdate in <ungroupCells>. The <code>cells</code>
  48693. * property contains the array of cells that was passed to <ungroupCells>.
  48694. *
  48695. * Event: mxEvent.REMOVE_CELLS_FROM_PARENT
  48696. *
  48697. * Fires between begin- and endUpdate in <removeCellsFromParent>. The
  48698. * <code>cells</code> property contains the array of cells that was passed to
  48699. * <removeCellsFromParent>.
  48700. *
  48701. * Event: mxEvent.ADD_CELLS
  48702. *
  48703. * Fires between begin- and endUpdate in <addCells>. The <code>cells</code>,
  48704. * <code>parent</code>, <code>index</code>, <code>source</code> and
  48705. * <code>target</code> properties contain the respective arguments that were
  48706. * passed to <addCells>.
  48707. *
  48708. * Event: mxEvent.CELLS_ADDED
  48709. *
  48710. * Fires between begin- and endUpdate in <cellsAdded>. The <code>cells</code>,
  48711. * <code>parent</code>, <code>index</code>, <code>source</code>,
  48712. * <code>target</code> and <code>absolute</code> properties contain the
  48713. * respective arguments that were passed to <cellsAdded>.
  48714. *
  48715. * Event: mxEvent.REMOVE_CELLS
  48716. *
  48717. * Fires between begin- and endUpdate in <removeCells>. The <code>cells</code>
  48718. * and <code>includeEdges</code> arguments contain the respective arguments
  48719. * that were passed to <removeCells>.
  48720. *
  48721. * Event: mxEvent.CELLS_REMOVED
  48722. *
  48723. * Fires between begin- and endUpdate in <cellsRemoved>. The <code>cells</code>
  48724. * argument contains the array of cells that was removed.
  48725. *
  48726. * Event: mxEvent.SPLIT_EDGE
  48727. *
  48728. * Fires between begin- and endUpdate in <splitEdge>. The <code>edge</code>
  48729. * property contains the edge to be splitted, the <code>cells</code>,
  48730. * <code>newEdge</code>, <code>dx</code> and <code>dy</code> properties contain
  48731. * the respective arguments that were passed to <splitEdge>.
  48732. *
  48733. * Event: mxEvent.TOGGLE_CELLS
  48734. *
  48735. * Fires between begin- and endUpdate in <toggleCells>. The <code>show</code>,
  48736. * <code>cells</code> and <code>includeEdges</code> properties contain the
  48737. * respective arguments that were passed to <toggleCells>.
  48738. *
  48739. * Event: mxEvent.FOLD_CELLS
  48740. *
  48741. * Fires between begin- and endUpdate in <foldCells>. The
  48742. * <code>collapse</code>, <code>cells</code> and <code>recurse</code>
  48743. * properties contain the respective arguments that were passed to <foldCells>.
  48744. *
  48745. * Event: mxEvent.CELLS_FOLDED
  48746. *
  48747. * Fires between begin- and endUpdate in cellsFolded. The
  48748. * <code>collapse</code>, <code>cells</code> and <code>recurse</code>
  48749. * properties contain the respective arguments that were passed to
  48750. * <cellsFolded>.
  48751. *
  48752. * Event: mxEvent.UPDATE_CELL_SIZE
  48753. *
  48754. * Fires between begin- and endUpdate in <updateCellSize>. The
  48755. * <code>cell</code> and <code>ignoreChildren</code> properties contain the
  48756. * respective arguments that were passed to <updateCellSize>.
  48757. *
  48758. * Event: mxEvent.RESIZE_CELLS
  48759. *
  48760. * Fires between begin- and endUpdate in <resizeCells>. The <code>cells</code>
  48761. * and <code>bounds</code> properties contain the respective arguments that
  48762. * were passed to <resizeCells>.
  48763. *
  48764. * Event: mxEvent.CELLS_RESIZED
  48765. *
  48766. * Fires between begin- and endUpdate in <cellsResized>. The <code>cells</code>
  48767. * and <code>bounds</code> properties contain the respective arguments that
  48768. * were passed to <cellsResized>.
  48769. *
  48770. * Event: mxEvent.MOVE_CELLS
  48771. *
  48772. * Fires between begin- and endUpdate in <moveCells>. The <code>cells</code>,
  48773. * <code>dx</code>, <code>dy</code>, <code>clone</code>, <code>target</code>
  48774. * and <code>event</code> properties contain the respective arguments that
  48775. * were passed to <moveCells>.
  48776. *
  48777. * Event: mxEvent.CELLS_MOVED
  48778. *
  48779. * Fires between begin- and endUpdate in <cellsMoved>. The <code>cells</code>,
  48780. * <code>dx</code>, <code>dy</code> and <code>disconnect</code> properties
  48781. * contain the respective arguments that were passed to <cellsMoved>.
  48782. *
  48783. * Event: mxEvent.CONNECT_CELL
  48784. *
  48785. * Fires between begin- and endUpdate in <connectCell>. The <code>edge</code>,
  48786. * <code>terminal</code> and <code>source</code> properties contain the
  48787. * respective arguments that were passed to <connectCell>.
  48788. *
  48789. * Event: mxEvent.CELL_CONNECTED
  48790. *
  48791. * Fires between begin- and endUpdate in <cellConnected>. The
  48792. * <code>edge</code>, <code>terminal</code> and <code>source</code> properties
  48793. * contain the respective arguments that were passed to <cellConnected>.
  48794. *
  48795. * Event: mxEvent.REFRESH
  48796. *
  48797. * Fires after <refresh> was executed. This event has no properties.
  48798. *
  48799. * Event: mxEvent.CLICK
  48800. *
  48801. * Fires in <click> after a click event. The <code>event</code> property
  48802. * contains the original mouse event and <code>cell</code> property contains
  48803. * the cell under the mouse or null if the background was clicked.
  48804. *
  48805. * Event: mxEvent.DOUBLE_CLICK
  48806. *
  48807. * Fires in <dblClick> after a double click. The <code>event</code> property
  48808. * contains the original mouse event and the <code>cell</code> property
  48809. * contains the cell under the mouse or null if the background was clicked.
  48810. *
  48811. * Event: mxEvent.GESTURE
  48812. *
  48813. * Fires in <fireGestureEvent> after a touch gesture. The <code>event</code>
  48814. * property contains the original gesture end event and the <code>cell</code>
  48815. * property contains the optional cell associated with the gesture.
  48816. *
  48817. * Event: mxEvent.TAP_AND_HOLD
  48818. *
  48819. * Fires in <tapAndHold> if a tap and hold event was detected. The <code>event</code>
  48820. * property contains the initial touch event and the <code>cell</code> property
  48821. * contains the cell under the mouse or null if the background was clicked.
  48822. *
  48823. * Event: mxEvent.FIRE_MOUSE_EVENT
  48824. *
  48825. * Fires in <fireMouseEvent> before the mouse listeners are invoked. The
  48826. * <code>eventName</code> property contains the event name and the
  48827. * <code>event</code> property contains the <mxMouseEvent>.
  48828. *
  48829. * Event: mxEvent.SIZE
  48830. *
  48831. * Fires after <sizeDidChange> was executed. The <code>bounds</code> property
  48832. * contains the new graph bounds.
  48833. *
  48834. * Event: mxEvent.START_EDITING
  48835. *
  48836. * Fires before the in-place editor starts in <startEditingAtCell>. The
  48837. * <code>cell</code> property contains the cell that is being edited and the
  48838. * <code>event</code> property contains the optional event argument that was
  48839. * passed to <startEditingAtCell>.
  48840. *
  48841. * Event: mxEvent.EDITING_STARTED
  48842. *
  48843. * Fires after the in-place editor starts in <startEditingAtCell>. The
  48844. * <code>cell</code> property contains the cell that is being edited and the
  48845. * <code>event</code> property contains the optional event argument that was
  48846. * passed to <startEditingAtCell>.
  48847. *
  48848. * Event: mxEvent.EDITING_STOPPED
  48849. *
  48850. * Fires after the in-place editor stops in <stopEditing>.
  48851. *
  48852. * Event: mxEvent.LABEL_CHANGED
  48853. *
  48854. * Fires between begin- and endUpdate in <cellLabelChanged>. The
  48855. * <code>cell</code> property contains the cell, the <code>value</code>
  48856. * property contains the new value for the cell, the <code>old</code> property
  48857. * contains the old value and the optional <code>event</code> property contains
  48858. * the mouse event that started the edit.
  48859. *
  48860. * Event: mxEvent.ADD_OVERLAY
  48861. *
  48862. * Fires after an overlay is added in <addCellOverlay>. The <code>cell</code>
  48863. * property contains the cell and the <code>overlay</code> property contains
  48864. * the <mxCellOverlay> that was added.
  48865. *
  48866. * Event: mxEvent.REMOVE_OVERLAY
  48867. *
  48868. * Fires after an overlay is removed in <removeCellOverlay> and
  48869. * <removeCellOverlays>. The <code>cell</code> property contains the cell and
  48870. * the <code>overlay</code> property contains the <mxCellOverlay> that was
  48871. * removed.
  48872. *
  48873. * Constructor: mxGraph
  48874. *
  48875. * Constructs a new mxGraph in the specified container. Model is an optional
  48876. * mxGraphModel. If no model is provided, a new mxGraphModel instance is
  48877. * used as the model. The container must have a valid owner document prior
  48878. * to calling this function in Internet Explorer. RenderHint is a string to
  48879. * affect the display performance and rendering in IE, but not in SVG-based
  48880. * browsers. The parameter is mapped to <dialect>, which may
  48881. * be one of <mxConstants.DIALECT_SVG> for SVG-based browsers,
  48882. * <mxConstants.DIALECT_STRICTHTML> for fastest display mode,
  48883. * <mxConstants.DIALECT_PREFERHTML> for faster display mode,
  48884. * <mxConstants.DIALECT_MIXEDHTML> for fast and <mxConstants.DIALECT_VML>
  48885. * for exact display mode (slowest). The dialects are defined in mxConstants.
  48886. * The default values are DIALECT_SVG for SVG-based browsers and
  48887. * DIALECT_MIXED for IE.
  48888. *
  48889. * The possible values for the renderingHint parameter are explained below:
  48890. *
  48891. * fast - The parameter is based on the fact that the display performance is
  48892. * highly improved in IE if the VML is not contained within a VML group
  48893. * element. The lack of a group element only slightly affects the display while
  48894. * panning, but improves the performance by almost a factor of 2, while keeping
  48895. * the display sufficiently accurate. This also allows to render certain shapes as HTML
  48896. * if the display accuracy is not affected, which is implemented by
  48897. * <mxShape.isMixedModeHtml>. This is the default setting and is mapped to
  48898. * DIALECT_MIXEDHTML.
  48899. * faster - Same as fast, but more expensive shapes are avoided. This is
  48900. * controlled by <mxShape.preferModeHtml>. The default implementation will
  48901. * avoid gradients and rounded rectangles, but more significant shapes, such
  48902. * as rhombus, ellipse, actor and cylinder will be rendered accurately. This
  48903. * setting is mapped to DIALECT_PREFERHTML.
  48904. * fastest - Almost anything will be rendered in Html. This allows for
  48905. * rectangles, labels and images. This setting is mapped to
  48906. * DIALECT_STRICTHTML.
  48907. * exact - If accurate panning is required and if the diagram is small (up
  48908. * to 100 cells), then this value should be used. In this mode, a group is
  48909. * created that contains the VML. This allows for accurate panning and is
  48910. * mapped to DIALECT_VML.
  48911. *
  48912. * Example:
  48913. *
  48914. * To create a graph inside a DOM node with an id of graph:
  48915. * (code)
  48916. * var container = document.getElementById('graph');
  48917. * var graph = new mxGraph(container);
  48918. * (end)
  48919. *
  48920. * Parameters:
  48921. *
  48922. * container - Optional DOM node that acts as a container for the graph.
  48923. * If this is null then the container can be initialized later using
  48924. * <init>.
  48925. * model - Optional <mxGraphModel> that constitutes the graph data.
  48926. * renderHint - Optional string that specifies the display accuracy and
  48927. * performance. Default is mxConstants.DIALECT_MIXEDHTML (for IE).
  48928. * stylesheet - Optional <mxStylesheet> to be used in the graph.
  48929. */
  48930. function mxGraph(container, model, renderHint, stylesheet)
  48931. {
  48932. // Initializes the variable in case the prototype has been
  48933. // modified to hold some listeners (which is possible because
  48934. // the createHandlers call is executed regardless of the
  48935. // arguments passed into the ctor).
  48936. this.mouseListeners = null;
  48937. // Converts the renderHint into a dialect
  48938. this.renderHint = renderHint;
  48939. if (mxClient.IS_SVG)
  48940. {
  48941. this.dialect = mxConstants.DIALECT_SVG;
  48942. }
  48943. else if (renderHint == mxConstants.RENDERING_HINT_EXACT && mxClient.IS_VML)
  48944. {
  48945. this.dialect = mxConstants.DIALECT_VML;
  48946. }
  48947. else if (renderHint == mxConstants.RENDERING_HINT_FASTEST)
  48948. {
  48949. this.dialect = mxConstants.DIALECT_STRICTHTML;
  48950. }
  48951. else if (renderHint == mxConstants.RENDERING_HINT_FASTER)
  48952. {
  48953. this.dialect = mxConstants.DIALECT_PREFERHTML;
  48954. }
  48955. else // default for VML
  48956. {
  48957. this.dialect = mxConstants.DIALECT_MIXEDHTML;
  48958. }
  48959. // Initializes the main members that do not require a container
  48960. this.model = (model != null) ? model : new mxGraphModel();
  48961. this.multiplicities = [];
  48962. this.imageBundles = [];
  48963. this.cellRenderer = this.createCellRenderer();
  48964. this.setSelectionModel(this.createSelectionModel());
  48965. this.setStylesheet((stylesheet != null) ? stylesheet : this.createStylesheet());
  48966. this.view = this.createGraphView();
  48967. // Adds a graph model listener to update the view
  48968. this.graphModelChangeListener = mxUtils.bind(this, function(sender, evt)
  48969. {
  48970. this.graphModelChanged(evt.getProperty('edit').changes);
  48971. });
  48972. this.model.addListener(mxEvent.CHANGE, this.graphModelChangeListener);
  48973. // Installs basic event handlers with disabled default settings.
  48974. this.createHandlers();
  48975. // Initializes the display if a container was specified
  48976. if (container != null)
  48977. {
  48978. this.init(container);
  48979. }
  48980. this.view.revalidate();
  48981. };
  48982. /**
  48983. * Installs the required language resources at class
  48984. * loading time.
  48985. */
  48986. if (mxLoadResources)
  48987. {
  48988. mxResources.add(mxClient.basePath + '/resources/graph');
  48989. }
  48990. else
  48991. {
  48992. mxClient.defaultBundles.push(mxClient.basePath + '/resources/graph');
  48993. }
  48994. /**
  48995. * Extends mxEventSource.
  48996. */
  48997. mxGraph.prototype = new mxEventSource();
  48998. mxGraph.prototype.constructor = mxGraph;
  48999. /**
  49000. * Group: Variables
  49001. */
  49002. /**
  49003. * Variable: mouseListeners
  49004. *
  49005. * Holds the mouse event listeners. See <fireMouseEvent>.
  49006. */
  49007. mxGraph.prototype.mouseListeners = null;
  49008. /**
  49009. * Variable: isMouseDown
  49010. *
  49011. * Holds the state of the mouse button.
  49012. */
  49013. mxGraph.prototype.isMouseDown = false;
  49014. /**
  49015. * Variable: model
  49016. *
  49017. * Holds the <mxGraphModel> that contains the cells to be displayed.
  49018. */
  49019. mxGraph.prototype.model = null;
  49020. /**
  49021. * Variable: view
  49022. *
  49023. * Holds the <mxGraphView> that caches the <mxCellStates> for the cells.
  49024. */
  49025. mxGraph.prototype.view = null;
  49026. /**
  49027. * Variable: stylesheet
  49028. *
  49029. * Holds the <mxStylesheet> that defines the appearance of the cells.
  49030. *
  49031. *
  49032. * Example:
  49033. *
  49034. * Use the following code to read a stylesheet into an existing graph.
  49035. *
  49036. * (code)
  49037. * var req = mxUtils.load('stylesheet.xml');
  49038. * var root = req.getDocumentElement();
  49039. * var dec = new mxCodec(root.ownerDocument);
  49040. * dec.decode(root, graph.stylesheet);
  49041. * (end)
  49042. */
  49043. mxGraph.prototype.stylesheet = null;
  49044. /**
  49045. * Variable: selectionModel
  49046. *
  49047. * Holds the <mxGraphSelectionModel> that models the current selection.
  49048. */
  49049. mxGraph.prototype.selectionModel = null;
  49050. /**
  49051. * Variable: cellEditor
  49052. *
  49053. * Holds the <mxCellEditor> that is used as the in-place editing.
  49054. */
  49055. mxGraph.prototype.cellEditor = null;
  49056. /**
  49057. * Variable: cellRenderer
  49058. *
  49059. * Holds the <mxCellRenderer> for rendering the cells in the graph.
  49060. */
  49061. mxGraph.prototype.cellRenderer = null;
  49062. /**
  49063. * Variable: multiplicities
  49064. *
  49065. * An array of <mxMultiplicities> describing the allowed
  49066. * connections in a graph.
  49067. */
  49068. mxGraph.prototype.multiplicities = null;
  49069. /**
  49070. * Variable: renderHint
  49071. *
  49072. * RenderHint as it was passed to the constructor.
  49073. */
  49074. mxGraph.prototype.renderHint = null;
  49075. /**
  49076. * Variable: dialect
  49077. *
  49078. * Dialect to be used for drawing the graph. Possible values are all
  49079. * constants in <mxConstants> with a DIALECT-prefix.
  49080. */
  49081. mxGraph.prototype.dialect = null;
  49082. /**
  49083. * Variable: gridSize
  49084. *
  49085. * Specifies the grid size. Default is 10.
  49086. */
  49087. mxGraph.prototype.gridSize = 10;
  49088. /**
  49089. * Variable: gridEnabled
  49090. *
  49091. * Specifies if the grid is enabled. This is used in <snap>. Default is
  49092. * true.
  49093. */
  49094. mxGraph.prototype.gridEnabled = true;
  49095. /**
  49096. * Variable: portsEnabled
  49097. *
  49098. * Specifies if ports are enabled. This is used in <cellConnected> to update
  49099. * the respective style. Default is true.
  49100. */
  49101. mxGraph.prototype.portsEnabled = true;
  49102. /**
  49103. * Variable: nativeDoubleClickEnabled
  49104. *
  49105. * Specifies if native double click events should be detected. Default is true.
  49106. */
  49107. mxGraph.prototype.nativeDblClickEnabled = true;
  49108. /**
  49109. * Variable: doubleTapEnabled
  49110. *
  49111. * Specifies if double taps on touch-based devices should be handled as a
  49112. * double click. Default is true.
  49113. */
  49114. mxGraph.prototype.doubleTapEnabled = true;
  49115. /**
  49116. * Variable: doubleTapTimeout
  49117. *
  49118. * Specifies the timeout for double taps and non-native double clicks. Default
  49119. * is 500 ms.
  49120. */
  49121. mxGraph.prototype.doubleTapTimeout = 500;
  49122. /**
  49123. * Variable: doubleTapTolerance
  49124. *
  49125. * Specifies the tolerance for double taps and double clicks in quirks mode.
  49126. * Default is 25 pixels.
  49127. */
  49128. mxGraph.prototype.doubleTapTolerance = 25;
  49129. /**
  49130. * Variable: lastTouchX
  49131. *
  49132. * Holds the x-coordinate of the last touch event for double tap detection.
  49133. */
  49134. mxGraph.prototype.lastTouchY = 0;
  49135. /**
  49136. * Variable: lastTouchX
  49137. *
  49138. * Holds the y-coordinate of the last touch event for double tap detection.
  49139. */
  49140. mxGraph.prototype.lastTouchY = 0;
  49141. /**
  49142. * Variable: lastTouchTime
  49143. *
  49144. * Holds the time of the last touch event for double click detection.
  49145. */
  49146. mxGraph.prototype.lastTouchTime = 0;
  49147. /**
  49148. * Variable: tapAndHoldEnabled
  49149. *
  49150. * Specifies if tap and hold should be used for starting connections on touch-based
  49151. * devices. Default is true.
  49152. */
  49153. mxGraph.prototype.tapAndHoldEnabled = true;
  49154. /**
  49155. * Variable: tapAndHoldDelay
  49156. *
  49157. * Specifies the time for a tap and hold. Default is 500 ms.
  49158. */
  49159. mxGraph.prototype.tapAndHoldDelay = 500;
  49160. /**
  49161. * Variable: tapAndHoldInProgress
  49162. *
  49163. * True if the timer for tap and hold events is running.
  49164. */
  49165. mxGraph.prototype.tapAndHoldInProgress = false;
  49166. /**
  49167. * Variable: tapAndHoldValid
  49168. *
  49169. * True as long as the timer is running and the touch events
  49170. * stay within the given <tapAndHoldTolerance>.
  49171. */
  49172. mxGraph.prototype.tapAndHoldValid = false;
  49173. /**
  49174. * Variable: initialTouchX
  49175. *
  49176. * Holds the x-coordinate of the intial touch event for tap and hold.
  49177. */
  49178. mxGraph.prototype.initialTouchX = 0;
  49179. /**
  49180. * Variable: initialTouchY
  49181. *
  49182. * Holds the y-coordinate of the intial touch event for tap and hold.
  49183. */
  49184. mxGraph.prototype.initialTouchY = 0;
  49185. /**
  49186. * Variable: tolerance
  49187. *
  49188. * Tolerance for a move to be handled as a single click.
  49189. * Default is 4 pixels.
  49190. */
  49191. mxGraph.prototype.tolerance = 4;
  49192. /**
  49193. * Variable: defaultOverlap
  49194. *
  49195. * Value returned by <getOverlap> if <isAllowOverlapParent> returns
  49196. * true for the given cell. <getOverlap> is used in <constrainChild> if
  49197. * <isConstrainChild> returns true. The value specifies the
  49198. * portion of the child which is allowed to overlap the parent.
  49199. */
  49200. mxGraph.prototype.defaultOverlap = 0.5;
  49201. /**
  49202. * Variable: defaultParent
  49203. *
  49204. * Specifies the default parent to be used to insert new cells.
  49205. * This is used in <getDefaultParent>. Default is null.
  49206. */
  49207. mxGraph.prototype.defaultParent = null;
  49208. /**
  49209. * Variable: alternateEdgeStyle
  49210. *
  49211. * Specifies the alternate edge style to be used if the main control point
  49212. * on an edge is being doubleclicked. Default is null.
  49213. */
  49214. mxGraph.prototype.alternateEdgeStyle = null;
  49215. /**
  49216. * Variable: backgroundImage
  49217. *
  49218. * Specifies the <mxImage> to be returned by <getBackgroundImage>. Default
  49219. * is null.
  49220. *
  49221. * Example:
  49222. *
  49223. * (code)
  49224. * var img = new mxImage('http://www.example.com/maps/examplemap.jpg', 1024, 768);
  49225. * graph.setBackgroundImage(img);
  49226. * graph.view.validate();
  49227. * (end)
  49228. */
  49229. mxGraph.prototype.backgroundImage = null;
  49230. /**
  49231. * Variable: pageVisible
  49232. *
  49233. * Specifies if the background page should be visible. Default is false.
  49234. * Not yet implemented.
  49235. */
  49236. mxGraph.prototype.pageVisible = false;
  49237. /**
  49238. * Variable: pageBreaksVisible
  49239. *
  49240. * Specifies if a dashed line should be drawn between multiple pages. Default
  49241. * is false. If you change this value while a graph is being displayed then you
  49242. * should call <sizeDidChange> to force an update of the display.
  49243. */
  49244. mxGraph.prototype.pageBreaksVisible = false;
  49245. /**
  49246. * Variable: pageBreakColor
  49247. *
  49248. * Specifies the color for page breaks. Default is 'gray'.
  49249. */
  49250. mxGraph.prototype.pageBreakColor = 'gray';
  49251. /**
  49252. * Variable: pageBreakDashed
  49253. *
  49254. * Specifies the page breaks should be dashed. Default is true.
  49255. */
  49256. mxGraph.prototype.pageBreakDashed = true;
  49257. /**
  49258. * Variable: minPageBreakDist
  49259. *
  49260. * Specifies the minimum distance for page breaks to be visible. Default is
  49261. * 20 (in pixels).
  49262. */
  49263. mxGraph.prototype.minPageBreakDist = 20;
  49264. /**
  49265. * Variable: preferPageSize
  49266. *
  49267. * Specifies if the graph size should be rounded to the next page number in
  49268. * <sizeDidChange>. This is only used if the graph container has scrollbars.
  49269. * Default is false.
  49270. */
  49271. mxGraph.prototype.preferPageSize = false;
  49272. /**
  49273. * Variable: pageFormat
  49274. *
  49275. * Specifies the page format for the background page. Default is
  49276. * <mxConstants.PAGE_FORMAT_A4_PORTRAIT>. This is used as the default in
  49277. * <mxPrintPreview> and for painting the background page if <pageVisible> is
  49278. * true and the pagebreaks if <pageBreaksVisible> is true.
  49279. */
  49280. mxGraph.prototype.pageFormat = mxConstants.PAGE_FORMAT_A4_PORTRAIT;
  49281. /**
  49282. * Variable: pageScale
  49283. *
  49284. * Specifies the scale of the background page. Default is 1.5.
  49285. * Not yet implemented.
  49286. */
  49287. mxGraph.prototype.pageScale = 1.5;
  49288. /**
  49289. * Variable: enabled
  49290. *
  49291. * Specifies the return value for <isEnabled>. Default is true.
  49292. */
  49293. mxGraph.prototype.enabled = true;
  49294. /**
  49295. * Variable: escapeEnabled
  49296. *
  49297. * Specifies if <mxKeyHandler> should invoke <escape> when the escape key
  49298. * is pressed. Default is true.
  49299. */
  49300. mxGraph.prototype.escapeEnabled = true;
  49301. /**
  49302. * Variable: invokesStopCellEditing
  49303. *
  49304. * If true, when editing is to be stopped by way of selection changing,
  49305. * data in diagram changing or other means stopCellEditing is invoked, and
  49306. * changes are saved. This is implemented in a focus handler in
  49307. * <mxCellEditor>. Default is true.
  49308. */
  49309. mxGraph.prototype.invokesStopCellEditing = true;
  49310. /**
  49311. * Variable: enterStopsCellEditing
  49312. *
  49313. * If true, pressing the enter key without pressing control or shift will stop
  49314. * editing and accept the new value. This is used in <mxCellEditor> to stop
  49315. * cell editing. Note: You can always use F2 and escape to stop editing.
  49316. * Default is false.
  49317. */
  49318. mxGraph.prototype.enterStopsCellEditing = false;
  49319. /**
  49320. * Variable: useScrollbarsForPanning
  49321. *
  49322. * Specifies if scrollbars should be used for panning in <panGraph> if
  49323. * any scrollbars are available. If scrollbars are enabled in CSS, but no
  49324. * scrollbars appear because the graph is smaller than the container size,
  49325. * then no panning occurs if this is true. Default is true.
  49326. */
  49327. mxGraph.prototype.useScrollbarsForPanning = true;
  49328. /**
  49329. * Variable: exportEnabled
  49330. *
  49331. * Specifies the return value for <canExportCell>. Default is true.
  49332. */
  49333. mxGraph.prototype.exportEnabled = true;
  49334. /**
  49335. * Variable: importEnabled
  49336. *
  49337. * Specifies the return value for <canImportCell>. Default is true.
  49338. */
  49339. mxGraph.prototype.importEnabled = true;
  49340. /**
  49341. * Variable: cellsLocked
  49342. *
  49343. * Specifies the return value for <isCellLocked>. Default is false.
  49344. */
  49345. mxGraph.prototype.cellsLocked = false;
  49346. /**
  49347. * Variable: cellsCloneable
  49348. *
  49349. * Specifies the return value for <isCellCloneable>. Default is true.
  49350. */
  49351. mxGraph.prototype.cellsCloneable = true;
  49352. /**
  49353. * Variable: foldingEnabled
  49354. *
  49355. * Specifies if folding (collapse and expand via an image icon in the graph
  49356. * should be enabled). Default is true.
  49357. */
  49358. mxGraph.prototype.foldingEnabled = true;
  49359. /**
  49360. * Variable: cellsEditable
  49361. *
  49362. * Specifies the return value for <isCellEditable>. Default is true.
  49363. */
  49364. mxGraph.prototype.cellsEditable = true;
  49365. /**
  49366. * Variable: cellsDeletable
  49367. *
  49368. * Specifies the return value for <isCellDeletable>. Default is true.
  49369. */
  49370. mxGraph.prototype.cellsDeletable = true;
  49371. /**
  49372. * Variable: cellsMovable
  49373. *
  49374. * Specifies the return value for <isCellMovable>. Default is true.
  49375. */
  49376. mxGraph.prototype.cellsMovable = true;
  49377. /**
  49378. * Variable: edgeLabelsMovable
  49379. *
  49380. * Specifies the return value for edges in <isLabelMovable>. Default is true.
  49381. */
  49382. mxGraph.prototype.edgeLabelsMovable = true;
  49383. /**
  49384. * Variable: vertexLabelsMovable
  49385. *
  49386. * Specifies the return value for vertices in <isLabelMovable>. Default is false.
  49387. */
  49388. mxGraph.prototype.vertexLabelsMovable = false;
  49389. /**
  49390. * Variable: dropEnabled
  49391. *
  49392. * Specifies the return value for <isDropEnabled>. Default is false.
  49393. */
  49394. mxGraph.prototype.dropEnabled = false;
  49395. /**
  49396. * Variable: splitEnabled
  49397. *
  49398. * Specifies if dropping onto edges should be enabled. This is ignored if
  49399. * <dropEnabled> is false. If enabled, it will call <splitEdge> to carry
  49400. * out the drop operation. Default is true.
  49401. */
  49402. mxGraph.prototype.splitEnabled = true;
  49403. /**
  49404. * Variable: cellsResizable
  49405. *
  49406. * Specifies the return value for <isCellResizable>. Default is true.
  49407. */
  49408. mxGraph.prototype.cellsResizable = true;
  49409. /**
  49410. * Variable: cellsBendable
  49411. *
  49412. * Specifies the return value for <isCellsBendable>. Default is true.
  49413. */
  49414. mxGraph.prototype.cellsBendable = true;
  49415. /**
  49416. * Variable: cellsSelectable
  49417. *
  49418. * Specifies the return value for <isCellSelectable>. Default is true.
  49419. */
  49420. mxGraph.prototype.cellsSelectable = true;
  49421. /**
  49422. * Variable: cellsDisconnectable
  49423. *
  49424. * Specifies the return value for <isCellDisconntable>. Default is true.
  49425. */
  49426. mxGraph.prototype.cellsDisconnectable = true;
  49427. /**
  49428. * Variable: autoSizeCells
  49429. *
  49430. * Specifies if the graph should automatically update the cell size after an
  49431. * edit. This is used in <isAutoSizeCell>. Default is false.
  49432. */
  49433. mxGraph.prototype.autoSizeCells = false;
  49434. /**
  49435. * Variable: autoSizeCellsOnAdd
  49436. *
  49437. * Specifies if autoSize style should be applied when cells are added. Default is false.
  49438. */
  49439. mxGraph.prototype.autoSizeCellsOnAdd = false;
  49440. /**
  49441. * Variable: autoScroll
  49442. *
  49443. * Specifies if the graph should automatically scroll if the mouse goes near
  49444. * the container edge while dragging. This is only taken into account if the
  49445. * container has scrollbars. Default is true.
  49446. *
  49447. * If you need this to work without scrollbars then set <ignoreScrollbars> to
  49448. * true. Please consult the <ignoreScrollbars> for details. In general, with
  49449. * no scrollbars, the use of <allowAutoPanning> is recommended.
  49450. */
  49451. mxGraph.prototype.autoScroll = true;
  49452. /**
  49453. * Variable: ignoreScrollbars
  49454. *
  49455. * Specifies if the graph should automatically scroll regardless of the
  49456. * scrollbars. This will scroll the container using positive values for
  49457. * scroll positions (ie usually only rightwards and downwards). To avoid
  49458. * possible conflicts with panning, set <translateToScrollPosition> to true.
  49459. */
  49460. mxGraph.prototype.ignoreScrollbars = false;
  49461. /**
  49462. * Variable: translateToScrollPosition
  49463. *
  49464. * Specifies if the graph should automatically convert the current scroll
  49465. * position to a translate in the graph view when a mouseUp event is received.
  49466. * This can be used to avoid conflicts when using <autoScroll> and
  49467. * <ignoreScrollbars> with no scrollbars in the container.
  49468. */
  49469. mxGraph.prototype.translateToScrollPosition = false;
  49470. /**
  49471. * Variable: timerAutoScroll
  49472. *
  49473. * Specifies if autoscrolling should be carried out via mxPanningManager even
  49474. * if the container has scrollbars. This disables <scrollPointToVisible> and
  49475. * uses <mxPanningManager> instead. If this is true then <autoExtend> is
  49476. * disabled. It should only be used with a scroll buffer or when scollbars
  49477. * are visible and scrollable in all directions. Default is false.
  49478. */
  49479. mxGraph.prototype.timerAutoScroll = false;
  49480. /**
  49481. * Variable: allowAutoPanning
  49482. *
  49483. * Specifies if panning via <panGraph> should be allowed to implement autoscroll
  49484. * if no scrollbars are available in <scrollPointToVisible>. To enable panning
  49485. * inside the container, near the edge, set <mxPanningManager.border> to a
  49486. * positive value. Default is false.
  49487. */
  49488. mxGraph.prototype.allowAutoPanning = false;
  49489. /**
  49490. * Variable: autoExtend
  49491. *
  49492. * Specifies if the size of the graph should be automatically extended if the
  49493. * mouse goes near the container edge while dragging. This is only taken into
  49494. * account if the container has scrollbars. Default is true. See <autoScroll>.
  49495. */
  49496. mxGraph.prototype.autoExtend = true;
  49497. /**
  49498. * Variable: maximumGraphBounds
  49499. *
  49500. * <mxRectangle> that specifies the area in which all cells in the diagram
  49501. * should be placed. Uses in <getMaximumGraphBounds>. Use a width or height of
  49502. * 0 if you only want to give a upper, left corner.
  49503. */
  49504. mxGraph.prototype.maximumGraphBounds = null;
  49505. /**
  49506. * Variable: minimumGraphSize
  49507. *
  49508. * <mxRectangle> that specifies the minimum size of the graph. This is ignored
  49509. * if the graph container has no scrollbars. Default is null.
  49510. */
  49511. mxGraph.prototype.minimumGraphSize = null;
  49512. /**
  49513. * Variable: minimumContainerSize
  49514. *
  49515. * <mxRectangle> that specifies the minimum size of the <container> if
  49516. * <resizeContainer> is true.
  49517. */
  49518. mxGraph.prototype.minimumContainerSize = null;
  49519. /**
  49520. * Variable: maximumContainerSize
  49521. *
  49522. * <mxRectangle> that specifies the maximum size of the container if
  49523. * <resizeContainer> is true.
  49524. */
  49525. mxGraph.prototype.maximumContainerSize = null;
  49526. /**
  49527. * Variable: resizeContainer
  49528. *
  49529. * Specifies if the container should be resized to the graph size when
  49530. * the graph size has changed. Default is false.
  49531. */
  49532. mxGraph.prototype.resizeContainer = false;
  49533. /**
  49534. * Variable: border
  49535. *
  49536. * Border to be added to the bottom and right side when the container is
  49537. * being resized after the graph has been changed. Default is 0.
  49538. */
  49539. mxGraph.prototype.border = 0;
  49540. /**
  49541. * Variable: keepEdgesInForeground
  49542. *
  49543. * Specifies if edges should appear in the foreground regardless of their order
  49544. * in the model. If <keepEdgesInForeground> and <keepEdgesInBackground> are
  49545. * both true then the normal order is applied. Default is false.
  49546. */
  49547. mxGraph.prototype.keepEdgesInForeground = false;
  49548. /**
  49549. * Variable: keepEdgesInBackground
  49550. *
  49551. * Specifies if edges should appear in the background regardless of their order
  49552. * in the model. If <keepEdgesInForeground> and <keepEdgesInBackground> are
  49553. * both true then the normal order is applied. Default is false.
  49554. */
  49555. mxGraph.prototype.keepEdgesInBackground = false;
  49556. /**
  49557. * Variable: allowNegativeCoordinates
  49558. *
  49559. * Specifies if negative coordinates for vertices are allowed. Default is true.
  49560. */
  49561. mxGraph.prototype.allowNegativeCoordinates = true;
  49562. /**
  49563. * Variable: constrainChildren
  49564. *
  49565. * Specifies if a child should be constrained inside the parent bounds after a
  49566. * move or resize of the child. Default is true.
  49567. */
  49568. mxGraph.prototype.constrainChildren = true;
  49569. /**
  49570. * Variable: constrainRelativeChildren
  49571. *
  49572. * Specifies if child cells with relative geometries should be constrained
  49573. * inside the parent bounds, if <constrainChildren> is true, and/or the
  49574. * <maximumGraphBounds>. Default is false.
  49575. */
  49576. mxGraph.prototype.constrainRelativeChildren = false;
  49577. /**
  49578. * Variable: extendParents
  49579. *
  49580. * Specifies if a parent should contain the child bounds after a resize of
  49581. * the child. Default is true. This has precedence over <constrainChildren>.
  49582. */
  49583. mxGraph.prototype.extendParents = true;
  49584. /**
  49585. * Variable: extendParentsOnAdd
  49586. *
  49587. * Specifies if parents should be extended according to the <extendParents>
  49588. * switch if cells are added. Default is true.
  49589. */
  49590. mxGraph.prototype.extendParentsOnAdd = true;
  49591. /**
  49592. * Variable: extendParentsOnAdd
  49593. *
  49594. * Specifies if parents should be extended according to the <extendParents>
  49595. * switch if cells are added. Default is false for backwards compatiblity.
  49596. */
  49597. mxGraph.prototype.extendParentsOnMove = false;
  49598. /**
  49599. * Variable: recursiveResize
  49600. *
  49601. * Specifies the return value for <isRecursiveResize>. Default is
  49602. * false for backwards compatiblity.
  49603. */
  49604. mxGraph.prototype.recursiveResize = false;
  49605. /**
  49606. * Variable: collapseToPreferredSize
  49607. *
  49608. * Specifies if the cell size should be changed to the preferred size when
  49609. * a cell is first collapsed. Default is true.
  49610. */
  49611. mxGraph.prototype.collapseToPreferredSize = true;
  49612. /**
  49613. * Variable: zoomFactor
  49614. *
  49615. * Specifies the factor used for <zoomIn> and <zoomOut>. Default is 1.2
  49616. * (120%).
  49617. */
  49618. mxGraph.prototype.zoomFactor = 1.2;
  49619. /**
  49620. * Variable: keepSelectionVisibleOnZoom
  49621. *
  49622. * Specifies if the viewport should automatically contain the selection cells
  49623. * after a zoom operation. Default is false.
  49624. */
  49625. mxGraph.prototype.keepSelectionVisibleOnZoom = false;
  49626. /**
  49627. * Variable: centerZoom
  49628. *
  49629. * Specifies if the zoom operations should go into the center of the actual
  49630. * diagram rather than going from top, left. Default is true.
  49631. */
  49632. mxGraph.prototype.centerZoom = true;
  49633. /**
  49634. * Variable: resetViewOnRootChange
  49635. *
  49636. * Specifies if the scale and translate should be reset if the root changes in
  49637. * the model. Default is true.
  49638. */
  49639. mxGraph.prototype.resetViewOnRootChange = true;
  49640. /**
  49641. * Variable: resetEdgesOnResize
  49642. *
  49643. * Specifies if edge control points should be reset after the resize of a
  49644. * connected cell. Default is false.
  49645. */
  49646. mxGraph.prototype.resetEdgesOnResize = false;
  49647. /**
  49648. * Variable: resetEdgesOnMove
  49649. *
  49650. * Specifies if edge control points should be reset after the move of a
  49651. * connected cell. Default is false.
  49652. */
  49653. mxGraph.prototype.resetEdgesOnMove = false;
  49654. /**
  49655. * Variable: resetEdgesOnConnect
  49656. *
  49657. * Specifies if edge control points should be reset after the the edge has been
  49658. * reconnected. Default is true.
  49659. */
  49660. mxGraph.prototype.resetEdgesOnConnect = true;
  49661. /**
  49662. * Variable: allowLoops
  49663. *
  49664. * Specifies if loops (aka self-references) are allowed. Default is false.
  49665. */
  49666. mxGraph.prototype.allowLoops = false;
  49667. /**
  49668. * Variable: defaultLoopStyle
  49669. *
  49670. * <mxEdgeStyle> to be used for loops. This is a fallback for loops if the
  49671. * <mxConstants.STYLE_LOOP> is undefined. Default is <mxEdgeStyle.Loop>.
  49672. */
  49673. mxGraph.prototype.defaultLoopStyle = mxEdgeStyle.Loop;
  49674. /**
  49675. * Variable: multigraph
  49676. *
  49677. * Specifies if multiple edges in the same direction between the same pair of
  49678. * vertices are allowed. Default is true.
  49679. */
  49680. mxGraph.prototype.multigraph = true;
  49681. /**
  49682. * Variable: connectableEdges
  49683. *
  49684. * Specifies if edges are connectable. Default is false. This overrides the
  49685. * connectable field in edges.
  49686. */
  49687. mxGraph.prototype.connectableEdges = false;
  49688. /**
  49689. * Variable: allowDanglingEdges
  49690. *
  49691. * Specifies if edges with disconnected terminals are allowed in the graph.
  49692. * Default is true.
  49693. */
  49694. mxGraph.prototype.allowDanglingEdges = true;
  49695. /**
  49696. * Variable: cloneInvalidEdges
  49697. *
  49698. * Specifies if edges that are cloned should be validated and only inserted
  49699. * if they are valid. Default is true.
  49700. */
  49701. mxGraph.prototype.cloneInvalidEdges = false;
  49702. /**
  49703. * Variable: disconnectOnMove
  49704. *
  49705. * Specifies if edges should be disconnected from their terminals when they
  49706. * are moved. Default is true.
  49707. */
  49708. mxGraph.prototype.disconnectOnMove = true;
  49709. /**
  49710. * Variable: labelsVisible
  49711. *
  49712. * Specifies if labels should be visible. This is used in <getLabel>. Default
  49713. * is true.
  49714. */
  49715. mxGraph.prototype.labelsVisible = true;
  49716. /**
  49717. * Variable: htmlLabels
  49718. *
  49719. * Specifies the return value for <isHtmlLabel>. Default is false.
  49720. */
  49721. mxGraph.prototype.htmlLabels = false;
  49722. /**
  49723. * Variable: swimlaneSelectionEnabled
  49724. *
  49725. * Specifies if swimlanes should be selectable via the content if the
  49726. * mouse is released. Default is true.
  49727. */
  49728. mxGraph.prototype.swimlaneSelectionEnabled = true;
  49729. /**
  49730. * Variable: swimlaneNesting
  49731. *
  49732. * Specifies if nesting of swimlanes is allowed. Default is true.
  49733. */
  49734. mxGraph.prototype.swimlaneNesting = true;
  49735. /**
  49736. * Variable: swimlaneIndicatorColorAttribute
  49737. *
  49738. * The attribute used to find the color for the indicator if the indicator
  49739. * color is set to 'swimlane'. Default is <mxConstants.STYLE_FILLCOLOR>.
  49740. */
  49741. mxGraph.prototype.swimlaneIndicatorColorAttribute = mxConstants.STYLE_FILLCOLOR;
  49742. /**
  49743. * Variable: imageBundles
  49744. *
  49745. * Holds the list of image bundles.
  49746. */
  49747. mxGraph.prototype.imageBundles = null;
  49748. /**
  49749. * Variable: minFitScale
  49750. *
  49751. * Specifies the minimum scale to be applied in <fit>. Default is 0.1. Set this
  49752. * to null to allow any value.
  49753. */
  49754. mxGraph.prototype.minFitScale = 0.1;
  49755. /**
  49756. * Variable: maxFitScale
  49757. *
  49758. * Specifies the maximum scale to be applied in <fit>. Default is 8. Set this
  49759. * to null to allow any value.
  49760. */
  49761. mxGraph.prototype.maxFitScale = 8;
  49762. /**
  49763. * Variable: panDx
  49764. *
  49765. * Current horizontal panning value. Default is 0.
  49766. */
  49767. mxGraph.prototype.panDx = 0;
  49768. /**
  49769. * Variable: panDy
  49770. *
  49771. * Current vertical panning value. Default is 0.
  49772. */
  49773. mxGraph.prototype.panDy = 0;
  49774. /**
  49775. * Variable: collapsedImage
  49776. *
  49777. * Specifies the <mxImage> to indicate a collapsed state.
  49778. * Default value is mxClient.imageBasePath + '/collapsed.gif'
  49779. */
  49780. mxGraph.prototype.collapsedImage = new mxImage(mxClient.imageBasePath + '/collapsed.gif', 9, 9);
  49781. /**
  49782. * Variable: expandedImage
  49783. *
  49784. * Specifies the <mxImage> to indicate a expanded state.
  49785. * Default value is mxClient.imageBasePath + '/expanded.gif'
  49786. */
  49787. mxGraph.prototype.expandedImage = new mxImage(mxClient.imageBasePath + '/expanded.gif', 9, 9);
  49788. /**
  49789. * Variable: warningImage
  49790. *
  49791. * Specifies the <mxImage> for the image to be used to display a warning
  49792. * overlay. See <setCellWarning>. Default value is mxClient.imageBasePath +
  49793. * '/warning'. The extension for the image depends on the platform. It is
  49794. * '.png' on the Mac and '.gif' on all other platforms.
  49795. */
  49796. mxGraph.prototype.warningImage = new mxImage(mxClient.imageBasePath + '/warning'+
  49797. ((mxClient.IS_MAC) ? '.png' : '.gif'), 16, 16);
  49798. /**
  49799. * Variable: alreadyConnectedResource
  49800. *
  49801. * Specifies the resource key for the error message to be displayed in
  49802. * non-multigraphs when two vertices are already connected. If the resource
  49803. * for this key does not exist then the value is used as the error message.
  49804. * Default is 'alreadyConnected'.
  49805. */
  49806. mxGraph.prototype.alreadyConnectedResource = (mxClient.language != 'none') ? 'alreadyConnected' : '';
  49807. /**
  49808. * Variable: containsValidationErrorsResource
  49809. *
  49810. * Specifies the resource key for the warning message to be displayed when
  49811. * a collapsed cell contains validation errors. If the resource for this
  49812. * key does not exist then the value is used as the warning message.
  49813. * Default is 'containsValidationErrors'.
  49814. */
  49815. mxGraph.prototype.containsValidationErrorsResource = (mxClient.language != 'none') ? 'containsValidationErrors' : '';
  49816. /**
  49817. * Variable: collapseExpandResource
  49818. *
  49819. * Specifies the resource key for the tooltip on the collapse/expand icon.
  49820. * If the resource for this key does not exist then the value is used as
  49821. * the tooltip. Default is 'collapse-expand'.
  49822. */
  49823. mxGraph.prototype.collapseExpandResource = (mxClient.language != 'none') ? 'collapse-expand' : '';
  49824. /**
  49825. * Function: init
  49826. *
  49827. * Initializes the <container> and creates the respective datastructures.
  49828. *
  49829. * Parameters:
  49830. *
  49831. * container - DOM node that will contain the graph display.
  49832. */
  49833. mxGraph.prototype.init = function(container)
  49834. {
  49835. this.container = container;
  49836. // Initializes the in-place editor
  49837. this.cellEditor = this.createCellEditor();
  49838. // Initializes the container using the view
  49839. this.view.init();
  49840. // Updates the size of the container for the current graph
  49841. this.sizeDidChange();
  49842. // Hides tooltips and resets tooltip timer if mouse leaves container
  49843. mxEvent.addListener(container, 'mouseleave', mxUtils.bind(this, function()
  49844. {
  49845. if (this.tooltipHandler != null)
  49846. {
  49847. this.tooltipHandler.hide();
  49848. }
  49849. }));
  49850. // Automatic deallocation of memory
  49851. if (mxClient.IS_IE)
  49852. {
  49853. mxEvent.addListener(window, 'unload', mxUtils.bind(this, function()
  49854. {
  49855. this.destroy();
  49856. }));
  49857. // Disable shift-click for text
  49858. mxEvent.addListener(container, 'selectstart',
  49859. mxUtils.bind(this, function(evt)
  49860. {
  49861. return this.isEditing() || (!this.isMouseDown && !mxEvent.isShiftDown(evt));
  49862. })
  49863. );
  49864. }
  49865. // Workaround for missing last shape and connect preview in IE8 standards
  49866. // mode if no initial graph displayed or no label for shape defined
  49867. if (document.documentMode == 8)
  49868. {
  49869. container.insertAdjacentHTML('beforeend', '<' + mxClient.VML_PREFIX + ':group' +
  49870. ' style="DISPLAY: none;"></' + mxClient.VML_PREFIX + ':group>');
  49871. }
  49872. };
  49873. /**
  49874. * Function: createHandlers
  49875. *
  49876. * Creates the tooltip-, panning-, connection- and graph-handler (in this
  49877. * order). This is called in the constructor before <init> is called.
  49878. */
  49879. mxGraph.prototype.createHandlers = function()
  49880. {
  49881. this.tooltipHandler = this.createTooltipHandler();
  49882. this.tooltipHandler.setEnabled(false);
  49883. this.selectionCellsHandler = this.createSelectionCellsHandler();
  49884. this.connectionHandler = this.createConnectionHandler();
  49885. this.connectionHandler.setEnabled(false);
  49886. this.graphHandler = this.createGraphHandler();
  49887. this.panningHandler = this.createPanningHandler();
  49888. this.panningHandler.panningEnabled = false;
  49889. this.popupMenuHandler = this.createPopupMenuHandler();
  49890. };
  49891. /**
  49892. * Function: createTooltipHandler
  49893. *
  49894. * Creates and returns a new <mxTooltipHandler> to be used in this graph.
  49895. */
  49896. mxGraph.prototype.createTooltipHandler = function()
  49897. {
  49898. return new mxTooltipHandler(this);
  49899. };
  49900. /**
  49901. * Function: createSelectionCellsHandler
  49902. *
  49903. * Creates and returns a new <mxTooltipHandler> to be used in this graph.
  49904. */
  49905. mxGraph.prototype.createSelectionCellsHandler = function()
  49906. {
  49907. return new mxSelectionCellsHandler(this);
  49908. };
  49909. /**
  49910. * Function: createConnectionHandler
  49911. *
  49912. * Creates and returns a new <mxConnectionHandler> to be used in this graph.
  49913. */
  49914. mxGraph.prototype.createConnectionHandler = function()
  49915. {
  49916. return new mxConnectionHandler(this);
  49917. };
  49918. /**
  49919. * Function: createGraphHandler
  49920. *
  49921. * Creates and returns a new <mxGraphHandler> to be used in this graph.
  49922. */
  49923. mxGraph.prototype.createGraphHandler = function()
  49924. {
  49925. return new mxGraphHandler(this);
  49926. };
  49927. /**
  49928. * Function: createPanningHandler
  49929. *
  49930. * Creates and returns a new <mxPanningHandler> to be used in this graph.
  49931. */
  49932. mxGraph.prototype.createPanningHandler = function()
  49933. {
  49934. return new mxPanningHandler(this);
  49935. };
  49936. /**
  49937. * Function: createPopupMenuHandler
  49938. *
  49939. * Creates and returns a new <mxPopupMenuHandler> to be used in this graph.
  49940. */
  49941. mxGraph.prototype.createPopupMenuHandler = function()
  49942. {
  49943. return new mxPopupMenuHandler(this);
  49944. };
  49945. /**
  49946. * Function: createSelectionModel
  49947. *
  49948. * Creates a new <mxGraphSelectionModel> to be used in this graph.
  49949. */
  49950. mxGraph.prototype.createSelectionModel = function()
  49951. {
  49952. return new mxGraphSelectionModel(this);
  49953. };
  49954. /**
  49955. * Function: createStylesheet
  49956. *
  49957. * Creates a new <mxGraphSelectionModel> to be used in this graph.
  49958. */
  49959. mxGraph.prototype.createStylesheet = function()
  49960. {
  49961. return new mxStylesheet();
  49962. };
  49963. /**
  49964. * Function: createGraphView
  49965. *
  49966. * Creates a new <mxGraphView> to be used in this graph.
  49967. */
  49968. mxGraph.prototype.createGraphView = function()
  49969. {
  49970. return new mxGraphView(this);
  49971. };
  49972. /**
  49973. * Function: createCellRenderer
  49974. *
  49975. * Creates a new <mxCellRenderer> to be used in this graph.
  49976. */
  49977. mxGraph.prototype.createCellRenderer = function()
  49978. {
  49979. return new mxCellRenderer();
  49980. };
  49981. /**
  49982. * Function: createCellEditor
  49983. *
  49984. * Creates a new <mxCellEditor> to be used in this graph.
  49985. */
  49986. mxGraph.prototype.createCellEditor = function()
  49987. {
  49988. return new mxCellEditor(this);
  49989. };
  49990. /**
  49991. * Function: getModel
  49992. *
  49993. * Returns the <mxGraphModel> that contains the cells.
  49994. */
  49995. mxGraph.prototype.getModel = function()
  49996. {
  49997. return this.model;
  49998. };
  49999. /**
  50000. * Function: getView
  50001. *
  50002. * Returns the <mxGraphView> that contains the <mxCellStates>.
  50003. */
  50004. mxGraph.prototype.getView = function()
  50005. {
  50006. return this.view;
  50007. };
  50008. /**
  50009. * Function: getStylesheet
  50010. *
  50011. * Returns the <mxStylesheet> that defines the style.
  50012. */
  50013. mxGraph.prototype.getStylesheet = function()
  50014. {
  50015. return this.stylesheet;
  50016. };
  50017. /**
  50018. * Function: setStylesheet
  50019. *
  50020. * Sets the <mxStylesheet> that defines the style.
  50021. */
  50022. mxGraph.prototype.setStylesheet = function(stylesheet)
  50023. {
  50024. this.stylesheet = stylesheet;
  50025. };
  50026. /**
  50027. * Function: getSelectionModel
  50028. *
  50029. * Returns the <mxGraphSelectionModel> that contains the selection.
  50030. */
  50031. mxGraph.prototype.getSelectionModel = function()
  50032. {
  50033. return this.selectionModel;
  50034. };
  50035. /**
  50036. * Function: setSelectionModel
  50037. *
  50038. * Sets the <mxSelectionModel> that contains the selection.
  50039. */
  50040. mxGraph.prototype.setSelectionModel = function(selectionModel)
  50041. {
  50042. this.selectionModel = selectionModel;
  50043. };
  50044. /**
  50045. * Function: getSelectionCellsForChanges
  50046. *
  50047. * Returns the cells to be selected for the given array of changes.
  50048. *
  50049. * Parameters:
  50050. *
  50051. * ignoreFn - Optional function that takes a change and returns true if the
  50052. * change should be ignored.
  50053. *
  50054. */
  50055. mxGraph.prototype.getSelectionCellsForChanges = function(changes, ignoreFn)
  50056. {
  50057. var dict = new mxDictionary();
  50058. var cells = [];
  50059. var addCell = mxUtils.bind(this, function(cell)
  50060. {
  50061. if (!dict.get(cell) && this.model.contains(cell))
  50062. {
  50063. if (this.model.isEdge(cell) || this.model.isVertex(cell))
  50064. {
  50065. dict.put(cell, true);
  50066. cells.push(cell);
  50067. }
  50068. else
  50069. {
  50070. var childCount = this.model.getChildCount(cell);
  50071. for (var i = 0; i < childCount; i++)
  50072. {
  50073. addCell(this.model.getChildAt(cell, i));
  50074. }
  50075. }
  50076. }
  50077. });
  50078. for (var i = 0; i < changes.length; i++)
  50079. {
  50080. var change = changes[i];
  50081. if (change.constructor != mxRootChange &&
  50082. (ignoreFn == null || !ignoreFn(change)))
  50083. {
  50084. var cell = null;
  50085. if (change instanceof mxChildChange)
  50086. {
  50087. cell = change.child;
  50088. }
  50089. else if (change.cell != null &&
  50090. change.cell instanceof mxCell)
  50091. {
  50092. cell = change.cell;
  50093. }
  50094. if (cell != null)
  50095. {
  50096. addCell(cell);
  50097. }
  50098. }
  50099. }
  50100. return cells;
  50101. };
  50102. /**
  50103. * Function: graphModelChanged
  50104. *
  50105. * Called when the graph model changes. Invokes <processChange> on each
  50106. * item of the given array to update the view accordingly.
  50107. *
  50108. * Parameters:
  50109. *
  50110. * changes - Array that contains the individual changes.
  50111. */
  50112. mxGraph.prototype.graphModelChanged = function(changes)
  50113. {
  50114. for (var i = 0; i < changes.length; i++)
  50115. {
  50116. this.processChange(changes[i]);
  50117. }
  50118. this.updateSelection();
  50119. this.view.validate();
  50120. this.sizeDidChange();
  50121. };
  50122. /**
  50123. * Function: updateSelection
  50124. *
  50125. * Removes selection cells that are not in the model from the selection.
  50126. */
  50127. mxGraph.prototype.updateSelection = function()
  50128. {
  50129. var cells = this.getSelectionCells();
  50130. var removed = [];
  50131. for (var i = 0; i < cells.length; i++)
  50132. {
  50133. if (!this.model.contains(cells[i]) || !this.isCellVisible(cells[i]))
  50134. {
  50135. removed.push(cells[i]);
  50136. }
  50137. else
  50138. {
  50139. var par = this.model.getParent(cells[i]);
  50140. while (par != null && par != this.view.currentRoot)
  50141. {
  50142. if (this.isCellCollapsed(par) || !this.isCellVisible(par))
  50143. {
  50144. removed.push(cells[i]);
  50145. break;
  50146. }
  50147. par = this.model.getParent(par);
  50148. }
  50149. }
  50150. }
  50151. this.removeSelectionCells(removed);
  50152. };
  50153. /**
  50154. * Function: processChange
  50155. *
  50156. * Processes the given change and invalidates the respective cached data
  50157. * in <view>. This fires a <root> event if the root has changed in the
  50158. * model.
  50159. *
  50160. * Parameters:
  50161. *
  50162. * change - Object that represents the change on the model.
  50163. */
  50164. mxGraph.prototype.processChange = function(change)
  50165. {
  50166. // Resets the view settings, removes all cells and clears
  50167. // the selection if the root changes.
  50168. if (change instanceof mxRootChange)
  50169. {
  50170. this.clearSelection();
  50171. this.setDefaultParent(null);
  50172. this.removeStateForCell(change.previous);
  50173. if (this.resetViewOnRootChange)
  50174. {
  50175. this.view.scale = 1;
  50176. this.view.translate.x = 0;
  50177. this.view.translate.y = 0;
  50178. }
  50179. this.fireEvent(new mxEventObject(mxEvent.ROOT));
  50180. }
  50181. // Adds or removes a child to the view by online invaliding
  50182. // the minimal required portions of the cache, namely, the
  50183. // old and new parent and the child.
  50184. else if (change instanceof mxChildChange)
  50185. {
  50186. var newParent = this.model.getParent(change.child);
  50187. this.view.invalidate(change.child, true, true);
  50188. if (!this.model.contains(newParent) || this.isCellCollapsed(newParent))
  50189. {
  50190. this.view.invalidate(change.child, true, true);
  50191. this.removeStateForCell(change.child);
  50192. // Handles special case of current root of view being removed
  50193. if (this.view.currentRoot == change.child)
  50194. {
  50195. this.home();
  50196. }
  50197. }
  50198. if (newParent != change.previous)
  50199. {
  50200. // Refreshes the collapse/expand icons on the parents
  50201. if (newParent != null)
  50202. {
  50203. this.view.invalidate(newParent, false, false);
  50204. }
  50205. if (change.previous != null)
  50206. {
  50207. this.view.invalidate(change.previous, false, false);
  50208. }
  50209. }
  50210. }
  50211. // Handles two special cases where the shape does not need to be
  50212. // recreated from scratch, it only needs to be invalidated.
  50213. else if (change instanceof mxTerminalChange || change instanceof mxGeometryChange)
  50214. {
  50215. // Checks if the geometry has changed to avoid unnessecary revalidation
  50216. if (change instanceof mxTerminalChange || ((change.previous == null && change.geometry != null) ||
  50217. (change.previous != null && !change.previous.equals(change.geometry))))
  50218. {
  50219. this.view.invalidate(change.cell);
  50220. }
  50221. }
  50222. // Handles two special cases where only the shape, but no
  50223. // descendants need to be recreated
  50224. else if (change instanceof mxValueChange)
  50225. {
  50226. this.view.invalidate(change.cell, false, false);
  50227. }
  50228. // Requires a new mxShape in JavaScript
  50229. else if (change instanceof mxStyleChange)
  50230. {
  50231. this.view.invalidate(change.cell, true, true);
  50232. var state = this.view.getState(change.cell);
  50233. if (state != null)
  50234. {
  50235. state.invalidStyle = true;
  50236. }
  50237. }
  50238. // Removes the state from the cache by default
  50239. else if (change.cell != null && change.cell instanceof mxCell)
  50240. {
  50241. this.removeStateForCell(change.cell);
  50242. }
  50243. };
  50244. /**
  50245. * Function: removeStateForCell
  50246. *
  50247. * Removes all cached information for the given cell and its descendants.
  50248. * This is called when a cell was removed from the model.
  50249. *
  50250. * Paramters:
  50251. *
  50252. * cell - <mxCell> that was removed from the model.
  50253. */
  50254. mxGraph.prototype.removeStateForCell = function(cell)
  50255. {
  50256. var childCount = this.model.getChildCount(cell);
  50257. for (var i = 0; i < childCount; i++)
  50258. {
  50259. this.removeStateForCell(this.model.getChildAt(cell, i));
  50260. }
  50261. this.view.invalidate(cell, false, true);
  50262. this.view.removeState(cell);
  50263. };
  50264. /**
  50265. * Group: Overlays
  50266. */
  50267. /**
  50268. * Function: addCellOverlay
  50269. *
  50270. * Adds an <mxCellOverlay> for the specified cell. This method fires an
  50271. * <addoverlay> event and returns the new <mxCellOverlay>.
  50272. *
  50273. * Parameters:
  50274. *
  50275. * cell - <mxCell> to add the overlay for.
  50276. * overlay - <mxCellOverlay> to be added for the cell.
  50277. */
  50278. mxGraph.prototype.addCellOverlay = function(cell, overlay)
  50279. {
  50280. if (cell.overlays == null)
  50281. {
  50282. cell.overlays = [];
  50283. }
  50284. cell.overlays.push(overlay);
  50285. var state = this.view.getState(cell);
  50286. // Immediately updates the cell display if the state exists
  50287. if (state != null)
  50288. {
  50289. this.cellRenderer.redraw(state);
  50290. }
  50291. this.fireEvent(new mxEventObject(mxEvent.ADD_OVERLAY,
  50292. 'cell', cell, 'overlay', overlay));
  50293. return overlay;
  50294. };
  50295. /**
  50296. * Function: getCellOverlays
  50297. *
  50298. * Returns the array of <mxCellOverlays> for the given cell or null, if
  50299. * no overlays are defined.
  50300. *
  50301. * Parameters:
  50302. *
  50303. * cell - <mxCell> whose overlays should be returned.
  50304. */
  50305. mxGraph.prototype.getCellOverlays = function(cell)
  50306. {
  50307. return cell.overlays;
  50308. };
  50309. /**
  50310. * Function: removeCellOverlay
  50311. *
  50312. * Removes and returns the given <mxCellOverlay> from the given cell. This
  50313. * method fires a <removeoverlay> event. If no overlay is given, then all
  50314. * overlays are removed using <removeOverlays>.
  50315. *
  50316. * Parameters:
  50317. *
  50318. * cell - <mxCell> whose overlay should be removed.
  50319. * overlay - Optional <mxCellOverlay> to be removed.
  50320. */
  50321. mxGraph.prototype.removeCellOverlay = function(cell, overlay)
  50322. {
  50323. if (overlay == null)
  50324. {
  50325. this.removeCellOverlays(cell);
  50326. }
  50327. else
  50328. {
  50329. var index = mxUtils.indexOf(cell.overlays, overlay);
  50330. if (index >= 0)
  50331. {
  50332. cell.overlays.splice(index, 1);
  50333. if (cell.overlays.length == 0)
  50334. {
  50335. cell.overlays = null;
  50336. }
  50337. // Immediately updates the cell display if the state exists
  50338. var state = this.view.getState(cell);
  50339. if (state != null)
  50340. {
  50341. this.cellRenderer.redraw(state);
  50342. }
  50343. this.fireEvent(new mxEventObject(mxEvent.REMOVE_OVERLAY,
  50344. 'cell', cell, 'overlay', overlay));
  50345. }
  50346. else
  50347. {
  50348. overlay = null;
  50349. }
  50350. }
  50351. return overlay;
  50352. };
  50353. /**
  50354. * Function: removeCellOverlays
  50355. *
  50356. * Removes all <mxCellOverlays> from the given cell. This method
  50357. * fires a <removeoverlay> event for each <mxCellOverlay> and returns
  50358. * the array of <mxCellOverlays> that was removed from the cell.
  50359. *
  50360. * Parameters:
  50361. *
  50362. * cell - <mxCell> whose overlays should be removed
  50363. */
  50364. mxGraph.prototype.removeCellOverlays = function(cell)
  50365. {
  50366. var overlays = cell.overlays;
  50367. if (overlays != null)
  50368. {
  50369. cell.overlays = null;
  50370. // Immediately updates the cell display if the state exists
  50371. var state = this.view.getState(cell);
  50372. if (state != null)
  50373. {
  50374. this.cellRenderer.redraw(state);
  50375. }
  50376. for (var i = 0; i < overlays.length; i++)
  50377. {
  50378. this.fireEvent(new mxEventObject(mxEvent.REMOVE_OVERLAY,
  50379. 'cell', cell, 'overlay', overlays[i]));
  50380. }
  50381. }
  50382. return overlays;
  50383. };
  50384. /**
  50385. * Function: clearCellOverlays
  50386. *
  50387. * Removes all <mxCellOverlays> in the graph for the given cell and all its
  50388. * descendants. If no cell is specified then all overlays are removed from
  50389. * the graph. This implementation uses <removeCellOverlays> to remove the
  50390. * overlays from the individual cells.
  50391. *
  50392. * Parameters:
  50393. *
  50394. * cell - Optional <mxCell> that represents the root of the subtree to
  50395. * remove the overlays from. Default is the root in the model.
  50396. */
  50397. mxGraph.prototype.clearCellOverlays = function(cell)
  50398. {
  50399. cell = (cell != null) ? cell : this.model.getRoot();
  50400. this.removeCellOverlays(cell);
  50401. // Recursively removes all overlays from the children
  50402. var childCount = this.model.getChildCount(cell);
  50403. for (var i = 0; i < childCount; i++)
  50404. {
  50405. var child = this.model.getChildAt(cell, i);
  50406. this.clearCellOverlays(child); // recurse
  50407. }
  50408. };
  50409. /**
  50410. * Function: setCellWarning
  50411. *
  50412. * Creates an overlay for the given cell using the warning and image or
  50413. * <warningImage> and returns the new <mxCellOverlay>. The warning is
  50414. * displayed as a tooltip in a red font and may contain HTML markup. If
  50415. * the warning is null or a zero length string, then all overlays are
  50416. * removed from the cell.
  50417. *
  50418. * Example:
  50419. *
  50420. * (code)
  50421. * graph.setCellWarning(cell, '<b>Warning:</b>: Hello, World!');
  50422. * (end)
  50423. *
  50424. * Parameters:
  50425. *
  50426. * cell - <mxCell> whose warning should be set.
  50427. * warning - String that represents the warning to be displayed.
  50428. * img - Optional <mxImage> to be used for the overlay. Default is
  50429. * <warningImage>.
  50430. * isSelect - Optional boolean indicating if a click on the overlay
  50431. * should select the corresponding cell. Default is false.
  50432. */
  50433. mxGraph.prototype.setCellWarning = function(cell, warning, img, isSelect)
  50434. {
  50435. if (warning != null && warning.length > 0)
  50436. {
  50437. img = (img != null) ? img : this.warningImage;
  50438. // Creates the overlay with the image and warning
  50439. var overlay = new mxCellOverlay(img,
  50440. '<font color=red>'+warning+'</font>');
  50441. // Adds a handler for single mouseclicks to select the cell
  50442. if (isSelect)
  50443. {
  50444. overlay.addListener(mxEvent.CLICK,
  50445. mxUtils.bind(this, function(sender, evt)
  50446. {
  50447. if (this.isEnabled())
  50448. {
  50449. this.setSelectionCell(cell);
  50450. }
  50451. })
  50452. );
  50453. }
  50454. // Sets and returns the overlay in the graph
  50455. return this.addCellOverlay(cell, overlay);
  50456. }
  50457. else
  50458. {
  50459. this.removeCellOverlays(cell);
  50460. }
  50461. return null;
  50462. };
  50463. /**
  50464. * Group: In-place editing
  50465. */
  50466. /**
  50467. * Function: startEditing
  50468. *
  50469. * Calls <startEditingAtCell> using the given cell or the first selection
  50470. * cell.
  50471. *
  50472. * Parameters:
  50473. *
  50474. * evt - Optional mouse event that triggered the editing.
  50475. */
  50476. mxGraph.prototype.startEditing = function(evt)
  50477. {
  50478. this.startEditingAtCell(null, evt);
  50479. };
  50480. /**
  50481. * Function: startEditingAtCell
  50482. *
  50483. * Fires a <startEditing> event and invokes <mxCellEditor.startEditing>
  50484. * on <editor>. After editing was started, a <editingStarted> event is
  50485. * fired.
  50486. *
  50487. * Parameters:
  50488. *
  50489. * cell - <mxCell> to start the in-place editor for.
  50490. * evt - Optional mouse event that triggered the editing.
  50491. */
  50492. mxGraph.prototype.startEditingAtCell = function(cell, evt)
  50493. {
  50494. if (evt == null || !mxEvent.isMultiTouchEvent(evt))
  50495. {
  50496. if (cell == null)
  50497. {
  50498. cell = this.getSelectionCell();
  50499. if (cell != null && !this.isCellEditable(cell))
  50500. {
  50501. cell = null;
  50502. }
  50503. }
  50504. if (cell != null)
  50505. {
  50506. this.fireEvent(new mxEventObject(mxEvent.START_EDITING,
  50507. 'cell', cell, 'event', evt));
  50508. this.cellEditor.startEditing(cell, evt);
  50509. this.fireEvent(new mxEventObject(mxEvent.EDITING_STARTED,
  50510. 'cell', cell, 'event', evt));
  50511. }
  50512. }
  50513. };
  50514. /**
  50515. * Function: getEditingValue
  50516. *
  50517. * Returns the initial value for in-place editing. This implementation
  50518. * returns <convertValueToString> for the given cell. If this function is
  50519. * overridden, then <mxGraphModel.valueForCellChanged> should take care
  50520. * of correctly storing the actual new value inside the user object.
  50521. *
  50522. * Parameters:
  50523. *
  50524. * cell - <mxCell> for which the initial editing value should be returned.
  50525. * evt - Optional mouse event that triggered the editor.
  50526. */
  50527. mxGraph.prototype.getEditingValue = function(cell, evt)
  50528. {
  50529. return this.convertValueToString(cell);
  50530. };
  50531. /**
  50532. * Function: stopEditing
  50533. *
  50534. * Stops the current editing and fires a <editingStopped> event.
  50535. *
  50536. * Parameters:
  50537. *
  50538. * cancel - Boolean that specifies if the current editing value
  50539. * should be stored.
  50540. */
  50541. mxGraph.prototype.stopEditing = function(cancel)
  50542. {
  50543. this.cellEditor.stopEditing(cancel);
  50544. this.fireEvent(new mxEventObject(mxEvent.EDITING_STOPPED, 'cancel', cancel));
  50545. };
  50546. /**
  50547. * Function: labelChanged
  50548. *
  50549. * Sets the label of the specified cell to the given value using
  50550. * <cellLabelChanged> and fires <mxEvent.LABEL_CHANGED> while the
  50551. * transaction is in progress. Returns the cell whose label was changed.
  50552. *
  50553. * Parameters:
  50554. *
  50555. * cell - <mxCell> whose label should be changed.
  50556. * value - New label to be assigned.
  50557. * evt - Optional event that triggered the change.
  50558. */
  50559. mxGraph.prototype.labelChanged = function(cell, value, evt)
  50560. {
  50561. this.model.beginUpdate();
  50562. try
  50563. {
  50564. var old = cell.value;
  50565. this.cellLabelChanged(cell, value, this.isAutoSizeCell(cell));
  50566. this.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED,
  50567. 'cell', cell, 'value', value, 'old', old, 'event', evt));
  50568. }
  50569. finally
  50570. {
  50571. this.model.endUpdate();
  50572. }
  50573. return cell;
  50574. };
  50575. /**
  50576. * Function: cellLabelChanged
  50577. *
  50578. * Sets the new label for a cell. If autoSize is true then
  50579. * <cellSizeUpdated> will be called.
  50580. *
  50581. * In the following example, the function is extended to map changes to
  50582. * attributes in an XML node, as shown in <convertValueToString>.
  50583. * Alternatively, the handling of this can be implemented as shown in
  50584. * <mxGraphModel.valueForCellChanged> without the need to clone the
  50585. * user object.
  50586. *
  50587. * (code)
  50588. * var graphCellLabelChanged = graph.cellLabelChanged;
  50589. * graph.cellLabelChanged = function(cell, newValue, autoSize)
  50590. * {
  50591. * // Cloned for correct undo/redo
  50592. * var elt = cell.value.cloneNode(true);
  50593. * elt.setAttribute('label', newValue);
  50594. *
  50595. * newValue = elt;
  50596. * graphCellLabelChanged.apply(this, arguments);
  50597. * };
  50598. * (end)
  50599. *
  50600. * Parameters:
  50601. *
  50602. * cell - <mxCell> whose label should be changed.
  50603. * value - New label to be assigned.
  50604. * autoSize - Boolean that specifies if <cellSizeUpdated> should be called.
  50605. */
  50606. mxGraph.prototype.cellLabelChanged = function(cell, value, autoSize)
  50607. {
  50608. this.model.beginUpdate();
  50609. try
  50610. {
  50611. this.model.setValue(cell, value);
  50612. if (autoSize)
  50613. {
  50614. this.cellSizeUpdated(cell, false);
  50615. }
  50616. }
  50617. finally
  50618. {
  50619. this.model.endUpdate();
  50620. }
  50621. };
  50622. /**
  50623. * Group: Event processing
  50624. */
  50625. /**
  50626. * Function: escape
  50627. *
  50628. * Processes an escape keystroke.
  50629. *
  50630. * Parameters:
  50631. *
  50632. * evt - Mouseevent that represents the keystroke.
  50633. */
  50634. mxGraph.prototype.escape = function(evt)
  50635. {
  50636. this.fireEvent(new mxEventObject(mxEvent.ESCAPE, 'event', evt));
  50637. };
  50638. /**
  50639. * Function: click
  50640. *
  50641. * Processes a singleclick on an optional cell and fires a <click> event.
  50642. * The click event is fired initially. If the graph is enabled and the
  50643. * event has not been consumed, then the cell is selected using
  50644. * <selectCellForEvent> or the selection is cleared using
  50645. * <clearSelection>. The events consumed state is set to true if the
  50646. * corresponding <mxMouseEvent> has been consumed.
  50647. *
  50648. * To handle a click event, use the following code.
  50649. *
  50650. * (code)
  50651. * graph.addListener(mxEvent.CLICK, function(sender, evt)
  50652. * {
  50653. * var e = evt.getProperty('event'); // mouse event
  50654. * var cell = evt.getProperty('cell'); // cell may be null
  50655. *
  50656. * if (cell != null)
  50657. * {
  50658. * // Do something useful with cell and consume the event
  50659. * evt.consume();
  50660. * }
  50661. * });
  50662. * (end)
  50663. *
  50664. * Parameters:
  50665. *
  50666. * me - <mxMouseEvent> that represents the single click.
  50667. */
  50668. mxGraph.prototype.click = function(me)
  50669. {
  50670. var evt = me.getEvent();
  50671. var cell = me.getCell();
  50672. var mxe = new mxEventObject(mxEvent.CLICK, 'event', evt, 'cell', cell);
  50673. if (me.isConsumed())
  50674. {
  50675. mxe.consume();
  50676. }
  50677. this.fireEvent(mxe);
  50678. if (this.isEnabled() && !mxEvent.isConsumed(evt) && !mxe.isConsumed())
  50679. {
  50680. if (cell != null)
  50681. {
  50682. if (this.isTransparentClickEvent(evt))
  50683. {
  50684. var active = false;
  50685. var tmp = this.getCellAt(me.graphX, me.graphY, null, null, null,
  50686. mxUtils.bind(this, function(state)
  50687. {
  50688. var selected = this.isCellSelected(state.cell);
  50689. active = active || selected;
  50690. return !active || selected || (state.cell != cell &&
  50691. this.model.isAncestor(state.cell, cell));
  50692. }));
  50693. if (tmp != null)
  50694. {
  50695. cell = tmp;
  50696. }
  50697. }
  50698. }
  50699. else if (this.isSwimlaneSelectionEnabled())
  50700. {
  50701. cell = this.getSwimlaneAt(me.getGraphX(), me.getGraphY());
  50702. if (cell != null && (!this.isToggleEvent(evt) ||
  50703. !mxEvent.isAltDown(evt)))
  50704. {
  50705. var temp = cell;
  50706. var swimlanes = [];
  50707. while (temp != null)
  50708. {
  50709. temp = this.model.getParent(temp);
  50710. var state = this.view.getState(temp);
  50711. if (this.isSwimlane(temp) && state != null)
  50712. {
  50713. swimlanes.push(temp);
  50714. }
  50715. }
  50716. // Selects ancestors for selected swimlanes
  50717. if (swimlanes.length > 0)
  50718. {
  50719. swimlanes = swimlanes.reverse();
  50720. swimlanes.splice(0, 0, cell);
  50721. swimlanes.push(cell);
  50722. for (var i = 0; i < swimlanes.length - 1; i++)
  50723. {
  50724. if (this.isCellSelected(swimlanes[i]))
  50725. {
  50726. cell = swimlanes[(this.isToggleEvent(evt)) ?
  50727. i : i + 1];
  50728. }
  50729. }
  50730. }
  50731. }
  50732. }
  50733. if (cell != null)
  50734. {
  50735. this.selectCellForEvent(cell, evt);
  50736. }
  50737. else if (!this.isToggleEvent(evt))
  50738. {
  50739. this.clearSelection();
  50740. }
  50741. }
  50742. };
  50743. /**
  50744. * Function: isSiblingSelected
  50745. *
  50746. * Returns true if any sibling of the given cell is selected.
  50747. */
  50748. mxGraph.prototype.isSiblingSelected = function(cell)
  50749. {
  50750. var model = this.model;
  50751. var parent = model.getParent(cell);
  50752. var childCount = model.getChildCount(parent);
  50753. for (var i = 0; i < childCount; i++)
  50754. {
  50755. var child = model.getChildAt(parent, i);
  50756. if (cell != child && this.isCellSelected(child))
  50757. {
  50758. return true;
  50759. }
  50760. }
  50761. return false;
  50762. };
  50763. /**
  50764. * Function: dblClick
  50765. *
  50766. * Processes a doubleclick on an optional cell and fires a <dblclick>
  50767. * event. The event is fired initially. If the graph is enabled and the
  50768. * event has not been consumed, then <edit> is called with the given
  50769. * cell. The event is ignored if no cell was specified.
  50770. *
  50771. * Example for overriding this method.
  50772. *
  50773. * (code)
  50774. * graph.dblClick = function(evt, cell)
  50775. * {
  50776. * var mxe = new mxEventObject(mxEvent.DOUBLE_CLICK, 'event', evt, 'cell', cell);
  50777. * this.fireEvent(mxe);
  50778. *
  50779. * if (this.isEnabled() && !mxEvent.isConsumed(evt) && !mxe.isConsumed())
  50780. * {
  50781. * mxUtils.alert('Hello, World!');
  50782. * mxe.consume();
  50783. * }
  50784. * }
  50785. * (end)
  50786. *
  50787. * Example listener for this event.
  50788. *
  50789. * (code)
  50790. * graph.addListener(mxEvent.DOUBLE_CLICK, function(sender, evt)
  50791. * {
  50792. * var cell = evt.getProperty('cell');
  50793. * // do something with the cell and consume the
  50794. * // event to prevent in-place editing from start
  50795. * });
  50796. * (end)
  50797. *
  50798. * Parameters:
  50799. *
  50800. * evt - Mouseevent that represents the doubleclick.
  50801. * cell - Optional <mxCell> under the mousepointer.
  50802. */
  50803. mxGraph.prototype.dblClick = function(evt, cell)
  50804. {
  50805. var mxe = new mxEventObject(mxEvent.DOUBLE_CLICK, 'event', evt, 'cell', cell);
  50806. this.fireEvent(mxe);
  50807. // Handles the event if it has not been consumed
  50808. if (this.isEnabled() && !mxEvent.isConsumed(evt) && !mxe.isConsumed() &&
  50809. cell != null && this.isCellEditable(cell) && !this.isEditing(cell))
  50810. {
  50811. this.startEditingAtCell(cell, evt);
  50812. mxEvent.consume(evt);
  50813. }
  50814. };
  50815. /**
  50816. * Function: tapAndHold
  50817. *
  50818. * Handles the <mxMouseEvent> by highlighting the <mxCellState>.
  50819. *
  50820. * Parameters:
  50821. *
  50822. * me - <mxMouseEvent> that represents the touch event.
  50823. * state - Optional <mxCellState> that is associated with the event.
  50824. */
  50825. mxGraph.prototype.tapAndHold = function(me)
  50826. {
  50827. var evt = me.getEvent();
  50828. var mxe = new mxEventObject(mxEvent.TAP_AND_HOLD, 'event', evt, 'cell', me.getCell());
  50829. // LATER: Check if event should be consumed if me is consumed
  50830. this.fireEvent(mxe);
  50831. if (mxe.isConsumed())
  50832. {
  50833. // Resets the state of the panning handler
  50834. this.panningHandler.panningTrigger = false;
  50835. }
  50836. // Handles the event if it has not been consumed
  50837. if (this.isEnabled() && !mxEvent.isConsumed(evt) && !mxe.isConsumed() && this.connectionHandler.isEnabled())
  50838. {
  50839. var state = this.view.getState(this.connectionHandler.marker.getCell(me));
  50840. if (state != null)
  50841. {
  50842. this.connectionHandler.marker.currentColor = this.connectionHandler.marker.validColor;
  50843. this.connectionHandler.marker.markedState = state;
  50844. this.connectionHandler.marker.mark();
  50845. this.connectionHandler.first = new mxPoint(me.getGraphX(), me.getGraphY());
  50846. this.connectionHandler.edgeState = this.connectionHandler.createEdgeState(me);
  50847. this.connectionHandler.previous = state;
  50848. this.connectionHandler.fireEvent(new mxEventObject(mxEvent.START, 'state', this.connectionHandler.previous));
  50849. }
  50850. }
  50851. };
  50852. /**
  50853. * Function: scrollPointToVisible
  50854. *
  50855. * Scrolls the graph to the given point, extending the graph container if
  50856. * specified.
  50857. */
  50858. mxGraph.prototype.scrollPointToVisible = function(x, y, extend, border)
  50859. {
  50860. if (!this.timerAutoScroll && (this.ignoreScrollbars || mxUtils.hasScrollbars(this.container)))
  50861. {
  50862. var c = this.container;
  50863. border = (border != null) ? border : 20;
  50864. if (x >= c.scrollLeft && y >= c.scrollTop && x <= c.scrollLeft + c.clientWidth &&
  50865. y <= c.scrollTop + c.clientHeight)
  50866. {
  50867. var dx = c.scrollLeft + c.clientWidth - x;
  50868. if (dx < border)
  50869. {
  50870. var old = c.scrollLeft;
  50871. c.scrollLeft += border - dx;
  50872. // Automatically extends the canvas size to the bottom, right
  50873. // if the event is outside of the canvas and the edge of the
  50874. // canvas has been reached. Notes: Needs fix for IE.
  50875. if (extend && old == c.scrollLeft)
  50876. {
  50877. if (this.dialect == mxConstants.DIALECT_SVG)
  50878. {
  50879. var root = this.view.getDrawPane().ownerSVGElement;
  50880. var width = this.container.scrollWidth + border - dx;
  50881. // Updates the clipping region. This is an expensive
  50882. // operation that should not be executed too often.
  50883. root.style.width = width + 'px';
  50884. }
  50885. else
  50886. {
  50887. var width = Math.max(c.clientWidth, c.scrollWidth) + border - dx;
  50888. var canvas = this.view.getCanvas();
  50889. canvas.style.width = width + 'px';
  50890. }
  50891. c.scrollLeft += border - dx;
  50892. }
  50893. }
  50894. else
  50895. {
  50896. dx = x - c.scrollLeft;
  50897. if (dx < border)
  50898. {
  50899. c.scrollLeft -= border - dx;
  50900. }
  50901. }
  50902. var dy = c.scrollTop + c.clientHeight - y;
  50903. if (dy < border)
  50904. {
  50905. var old = c.scrollTop;
  50906. c.scrollTop += border - dy;
  50907. if (old == c.scrollTop && extend)
  50908. {
  50909. if (this.dialect == mxConstants.DIALECT_SVG)
  50910. {
  50911. var root = this.view.getDrawPane().ownerSVGElement;
  50912. var height = this.container.scrollHeight + border - dy;
  50913. // Updates the clipping region. This is an expensive
  50914. // operation that should not be executed too often.
  50915. root.style.height = height + 'px';
  50916. }
  50917. else
  50918. {
  50919. var height = Math.max(c.clientHeight, c.scrollHeight) + border - dy;
  50920. var canvas = this.view.getCanvas();
  50921. canvas.style.height = height + 'px';
  50922. }
  50923. c.scrollTop += border - dy;
  50924. }
  50925. }
  50926. else
  50927. {
  50928. dy = y - c.scrollTop;
  50929. if (dy < border)
  50930. {
  50931. c.scrollTop -= border - dy;
  50932. }
  50933. }
  50934. }
  50935. }
  50936. else if (this.allowAutoPanning && !this.panningHandler.isActive())
  50937. {
  50938. if (this.panningManager == null)
  50939. {
  50940. this.panningManager = this.createPanningManager();
  50941. }
  50942. this.panningManager.panTo(x + this.panDx, y + this.panDy);
  50943. }
  50944. };
  50945. /**
  50946. * Function: createPanningManager
  50947. *
  50948. * Creates and returns an <mxPanningManager>.
  50949. */
  50950. mxGraph.prototype.createPanningManager = function()
  50951. {
  50952. return new mxPanningManager(this);
  50953. };
  50954. /**
  50955. * Function: getBorderSizes
  50956. *
  50957. * Returns the size of the border and padding on all four sides of the
  50958. * container. The left, top, right and bottom borders are stored in the x, y,
  50959. * width and height of the returned <mxRectangle>, respectively.
  50960. */
  50961. mxGraph.prototype.getBorderSizes = function()
  50962. {
  50963. var css = mxUtils.getCurrentStyle(this.container);
  50964. return new mxRectangle(mxUtils.parseCssNumber(css.paddingLeft) +
  50965. ((css.borderLeftStyle != 'none') ? mxUtils.parseCssNumber(css.borderLeftWidth) : 0),
  50966. mxUtils.parseCssNumber(css.paddingTop) +
  50967. ((css.borderTopStyle != 'none') ? mxUtils.parseCssNumber(css.borderTopWidth) : 0),
  50968. mxUtils.parseCssNumber(css.paddingRight) +
  50969. ((css.borderRightStyle != 'none') ? mxUtils.parseCssNumber(css.borderRightWidth) : 0),
  50970. mxUtils.parseCssNumber(css.paddingBottom) +
  50971. ((css.borderBottomStyle != 'none') ? mxUtils.parseCssNumber(css.borderBottomWidth) : 0));
  50972. };
  50973. /**
  50974. * Function: getPreferredPageSize
  50975. *
  50976. * Returns the preferred size of the background page if <preferPageSize> is true.
  50977. */
  50978. mxGraph.prototype.getPreferredPageSize = function(bounds, width, height)
  50979. {
  50980. var scale = this.view.scale;
  50981. var tr = this.view.translate;
  50982. var fmt = this.pageFormat;
  50983. var ps = this.pageScale;
  50984. var page = new mxRectangle(0, 0, Math.ceil(fmt.width * ps), Math.ceil(fmt.height * ps));
  50985. var hCount = (this.pageBreaksVisible) ? Math.ceil(width / page.width) : 1;
  50986. var vCount = (this.pageBreaksVisible) ? Math.ceil(height / page.height) : 1;
  50987. return new mxRectangle(0, 0, hCount * page.width + 2 + tr.x, vCount * page.height + 2 + tr.y);
  50988. };
  50989. /**
  50990. * Function: fit
  50991. *
  50992. * Scales the graph such that the complete diagram fits into <container> and
  50993. * returns the current scale in the view. To fit an initial graph prior to
  50994. * rendering, set <mxGraphView.rendering> to false prior to changing the model
  50995. * and execute the following after changing the model.
  50996. *
  50997. * (code)
  50998. * graph.fit();
  50999. * graph.view.rendering = true;
  51000. * graph.refresh();
  51001. * (end)
  51002. *
  51003. * To fit and center the graph, the following code can be used.
  51004. *
  51005. * (code)
  51006. * var margin = 2;
  51007. * var max = 3;
  51008. *
  51009. * var bounds = graph.getGraphBounds();
  51010. * var cw = graph.container.clientWidth - margin;
  51011. * var ch = graph.container.clientHeight - margin;
  51012. * var w = bounds.width / graph.view.scale;
  51013. * var h = bounds.height / graph.view.scale;
  51014. * var s = Math.min(max, Math.min(cw / w, ch / h));
  51015. *
  51016. * graph.view.scaleAndTranslate(s,
  51017. * (margin + cw - w * s) / (2 * s) - bounds.x / graph.view.scale,
  51018. * (margin + ch - h * s) / (2 * s) - bounds.y / graph.view.scale);
  51019. * (end)
  51020. *
  51021. * Parameters:
  51022. *
  51023. * border - Optional number that specifies the border. Default is <border>.
  51024. * keepOrigin - Optional boolean that specifies if the translate should be
  51025. * changed. Default is false.
  51026. * margin - Optional margin in pixels. Default is 0.
  51027. * enabled - Optional boolean that specifies if the scale should be set or
  51028. * just returned. Default is true.
  51029. * ignoreWidth - Optional boolean that specifies if the width should be
  51030. * ignored. Default is false.
  51031. * ignoreHeight - Optional boolean that specifies if the height should be
  51032. * ignored. Default is false.
  51033. * maxHeight - Optional maximum height.
  51034. */
  51035. mxGraph.prototype.fit = function(border, keepOrigin, margin, enabled, ignoreWidth, ignoreHeight, maxHeight)
  51036. {
  51037. if (this.container != null)
  51038. {
  51039. border = (border != null) ? border : this.getBorder();
  51040. keepOrigin = (keepOrigin != null) ? keepOrigin : false;
  51041. margin = (margin != null) ? margin : 0;
  51042. enabled = (enabled != null) ? enabled : true;
  51043. ignoreWidth = (ignoreWidth != null) ? ignoreWidth : false;
  51044. ignoreHeight = (ignoreHeight != null) ? ignoreHeight : false;
  51045. // Adds spacing and border from css
  51046. var cssBorder = this.getBorderSizes();
  51047. var w1 = this.container.offsetWidth - cssBorder.x - cssBorder.width - 1;
  51048. var h1 = (maxHeight != null) ? maxHeight : this.container.offsetHeight - cssBorder.y - cssBorder.height - 1;
  51049. var bounds = this.view.getGraphBounds();
  51050. if (bounds.width > 0 && bounds.height > 0)
  51051. {
  51052. if (keepOrigin && bounds.x != null && bounds.y != null)
  51053. {
  51054. bounds = bounds.clone();
  51055. bounds.width += bounds.x;
  51056. bounds.height += bounds.y;
  51057. bounds.x = 0;
  51058. bounds.y = 0;
  51059. }
  51060. // LATER: Use unscaled bounding boxes to fix rounding errors
  51061. var s = this.view.scale;
  51062. var w2 = bounds.width / s;
  51063. var h2 = bounds.height / s;
  51064. // Fits to the size of the background image if required
  51065. if (this.backgroundImage != null)
  51066. {
  51067. w2 = Math.max(w2, this.backgroundImage.width - bounds.x / s);
  51068. h2 = Math.max(h2, this.backgroundImage.height - bounds.y / s);
  51069. }
  51070. var b = ((keepOrigin) ? border : 2 * border) + margin + 1;
  51071. w1 -= b;
  51072. h1 -= b;
  51073. var s2 = (((ignoreWidth) ? h1 / h2 : (ignoreHeight) ? w1 / w2 :
  51074. Math.min(w1 / w2, h1 / h2)));
  51075. if (this.minFitScale != null)
  51076. {
  51077. s2 = Math.max(s2, this.minFitScale);
  51078. }
  51079. if (this.maxFitScale != null)
  51080. {
  51081. s2 = Math.min(s2, this.maxFitScale);
  51082. }
  51083. if (enabled)
  51084. {
  51085. if (!keepOrigin)
  51086. {
  51087. if (!mxUtils.hasScrollbars(this.container))
  51088. {
  51089. var x0 = (bounds.x != null) ? Math.floor(this.view.translate.x - bounds.x / s + border / s2 + margin / 2) : border;
  51090. var y0 = (bounds.y != null) ? Math.floor(this.view.translate.y - bounds.y / s + border / s2 + margin / 2) : border;
  51091. this.view.scaleAndTranslate(s2, x0, y0);
  51092. }
  51093. else
  51094. {
  51095. this.view.setScale(s2);
  51096. var b2 = this.getGraphBounds();
  51097. if (b2.x != null)
  51098. {
  51099. this.container.scrollLeft = b2.x;
  51100. }
  51101. if (b2.y != null)
  51102. {
  51103. this.container.scrollTop = b2.y;
  51104. }
  51105. }
  51106. }
  51107. else if (this.view.scale != s2)
  51108. {
  51109. this.view.setScale(s2);
  51110. }
  51111. }
  51112. else
  51113. {
  51114. return s2;
  51115. }
  51116. }
  51117. }
  51118. return this.view.scale;
  51119. };
  51120. /**
  51121. * Function: sizeDidChange
  51122. *
  51123. * Called when the size of the graph has changed. This implementation fires
  51124. * a <size> event after updating the clipping region of the SVG element in
  51125. * SVG-bases browsers.
  51126. */
  51127. mxGraph.prototype.sizeDidChange = function()
  51128. {
  51129. var bounds = this.getGraphBounds();
  51130. if (this.container != null)
  51131. {
  51132. var border = this.getBorder();
  51133. var width = Math.max(0, bounds.x) + bounds.width + 2 * border;
  51134. var height = Math.max(0, bounds.y) + bounds.height + 2 * border;
  51135. if (this.minimumContainerSize != null)
  51136. {
  51137. width = Math.max(width, this.minimumContainerSize.width);
  51138. height = Math.max(height, this.minimumContainerSize.height);
  51139. }
  51140. if (this.resizeContainer)
  51141. {
  51142. this.doResizeContainer(width, height);
  51143. }
  51144. if (this.preferPageSize || (!mxClient.IS_IE && this.pageVisible))
  51145. {
  51146. var size = this.getPreferredPageSize(bounds, Math.max(1, width), Math.max(1, height));
  51147. if (size != null)
  51148. {
  51149. width = size.width * this.view.scale;
  51150. height = size.height * this.view.scale;
  51151. }
  51152. }
  51153. if (this.minimumGraphSize != null)
  51154. {
  51155. width = Math.max(width, this.minimumGraphSize.width * this.view.scale);
  51156. height = Math.max(height, this.minimumGraphSize.height * this.view.scale);
  51157. }
  51158. width = Math.ceil(width);
  51159. height = Math.ceil(height);
  51160. if (this.dialect == mxConstants.DIALECT_SVG)
  51161. {
  51162. var root = this.view.getDrawPane().ownerSVGElement;
  51163. if (root != null)
  51164. {
  51165. root.style.minWidth = Math.max(1, width) + 'px';
  51166. root.style.minHeight = Math.max(1, height) + 'px';
  51167. root.style.width = '100%';
  51168. root.style.height = '100%';
  51169. }
  51170. }
  51171. else
  51172. {
  51173. if (mxClient.IS_QUIRKS)
  51174. {
  51175. // Quirks mode does not support minWidth/-Height
  51176. this.view.updateHtmlCanvasSize(Math.max(1, width), Math.max(1, height));
  51177. }
  51178. else
  51179. {
  51180. this.view.canvas.style.minWidth = Math.max(1, width) + 'px';
  51181. this.view.canvas.style.minHeight = Math.max(1, height) + 'px';
  51182. }
  51183. }
  51184. this.updatePageBreaks(this.pageBreaksVisible, width, height);
  51185. }
  51186. this.fireEvent(new mxEventObject(mxEvent.SIZE, 'bounds', bounds));
  51187. };
  51188. /**
  51189. * Function: doResizeContainer
  51190. *
  51191. * Resizes the container for the given graph width and height.
  51192. */
  51193. mxGraph.prototype.doResizeContainer = function(width, height)
  51194. {
  51195. if (this.maximumContainerSize != null)
  51196. {
  51197. width = Math.min(this.maximumContainerSize.width, width);
  51198. height = Math.min(this.maximumContainerSize.height, height);
  51199. }
  51200. this.container.style.width = Math.ceil(width) + 'px';
  51201. this.container.style.height = Math.ceil(height) + 'px';
  51202. };
  51203. /**
  51204. * Function: updatePageBreaks
  51205. *
  51206. * Invokes from <sizeDidChange> to redraw the page breaks.
  51207. *
  51208. * Parameters:
  51209. *
  51210. * visible - Boolean that specifies if page breaks should be shown.
  51211. * width - Specifies the width of the container in pixels.
  51212. * height - Specifies the height of the container in pixels.
  51213. */
  51214. mxGraph.prototype.updatePageBreaks = function(visible, width, height)
  51215. {
  51216. var scale = this.view.scale;
  51217. var tr = this.view.translate;
  51218. var fmt = this.pageFormat;
  51219. var ps = scale * this.pageScale;
  51220. var bounds = new mxRectangle(0, 0, fmt.width * ps, fmt.height * ps);
  51221. var gb = mxRectangle.fromRectangle(this.getGraphBounds());
  51222. gb.width = Math.max(1, gb.width);
  51223. gb.height = Math.max(1, gb.height);
  51224. bounds.x = Math.floor((gb.x - tr.x * scale) / bounds.width) * bounds.width + tr.x * scale;
  51225. bounds.y = Math.floor((gb.y - tr.y * scale) / bounds.height) * bounds.height + tr.y * scale;
  51226. gb.width = Math.ceil((gb.width + (gb.x - bounds.x)) / bounds.width) * bounds.width;
  51227. gb.height = Math.ceil((gb.height + (gb.y - bounds.y)) / bounds.height) * bounds.height;
  51228. // Does not show page breaks if the scale is too small
  51229. visible = visible && Math.min(bounds.width, bounds.height) > this.minPageBreakDist;
  51230. var horizontalCount = (visible) ? Math.ceil(gb.height / bounds.height) + 1 : 0;
  51231. var verticalCount = (visible) ? Math.ceil(gb.width / bounds.width) + 1 : 0;
  51232. var right = (verticalCount - 1) * bounds.width;
  51233. var bottom = (horizontalCount - 1) * bounds.height;
  51234. if (this.horizontalPageBreaks == null && horizontalCount > 0)
  51235. {
  51236. this.horizontalPageBreaks = [];
  51237. }
  51238. if (this.verticalPageBreaks == null && verticalCount > 0)
  51239. {
  51240. this.verticalPageBreaks = [];
  51241. }
  51242. var drawPageBreaks = mxUtils.bind(this, function(breaks)
  51243. {
  51244. if (breaks != null)
  51245. {
  51246. var count = (breaks == this.horizontalPageBreaks) ? horizontalCount : verticalCount;
  51247. for (var i = 0; i <= count; i++)
  51248. {
  51249. var pts = (breaks == this.horizontalPageBreaks) ?
  51250. [new mxPoint(Math.round(bounds.x), Math.round(bounds.y + i * bounds.height)),
  51251. new mxPoint(Math.round(bounds.x + right), Math.round(bounds.y + i * bounds.height))] :
  51252. [new mxPoint(Math.round(bounds.x + i * bounds.width), Math.round(bounds.y)),
  51253. new mxPoint(Math.round(bounds.x + i * bounds.width), Math.round(bounds.y + bottom))];
  51254. if (breaks[i] != null)
  51255. {
  51256. breaks[i].points = pts;
  51257. breaks[i].redraw();
  51258. }
  51259. else
  51260. {
  51261. var pageBreak = new mxPolyline(pts, this.pageBreakColor);
  51262. pageBreak.dialect = this.dialect;
  51263. pageBreak.pointerEvents = false;
  51264. pageBreak.isDashed = this.pageBreakDashed;
  51265. pageBreak.init(this.view.backgroundPane);
  51266. pageBreak.redraw();
  51267. breaks[i] = pageBreak;
  51268. }
  51269. }
  51270. for (var i = count; i < breaks.length; i++)
  51271. {
  51272. breaks[i].destroy();
  51273. }
  51274. breaks.splice(count, breaks.length - count);
  51275. }
  51276. });
  51277. drawPageBreaks(this.horizontalPageBreaks);
  51278. drawPageBreaks(this.verticalPageBreaks);
  51279. };
  51280. /**
  51281. * Group: Cell styles
  51282. */
  51283. /**
  51284. * Function: getCurrentCellStyle
  51285. *
  51286. * Returns the style for the given cell from the cell state, if one exists,
  51287. * or using <getCellStyle>.
  51288. *
  51289. * Parameters:
  51290. *
  51291. * cell - <mxCell> whose style should be returned as an array.
  51292. * ignoreState - Optional boolean that specifies if the cell state should be ignored.
  51293. */
  51294. mxGraph.prototype.getCurrentCellStyle = function(cell, ignoreState)
  51295. {
  51296. var state = (ignoreState) ? null : this.view.getState(cell);
  51297. return (state != null) ? state.style : this.getCellStyle(cell);
  51298. };
  51299. /**
  51300. * Function: getCellStyle
  51301. *
  51302. * Returns an array of key, value pairs representing the cell style for the
  51303. * given cell. If no string is defined in the model that specifies the
  51304. * style, then the default style for the cell is returned or an empty object,
  51305. * if no style can be found. Note: You should try and get the cell state
  51306. * for the given cell and use the cached style in the state before using
  51307. * this method.
  51308. *
  51309. * Parameters:
  51310. *
  51311. * cell - <mxCell> whose style should be returned as an array.
  51312. */
  51313. mxGraph.prototype.getCellStyle = function(cell)
  51314. {
  51315. var stylename = this.model.getStyle(cell);
  51316. var style = null;
  51317. // Gets the default style for the cell
  51318. if (this.model.isEdge(cell))
  51319. {
  51320. style = this.stylesheet.getDefaultEdgeStyle();
  51321. }
  51322. else
  51323. {
  51324. style = this.stylesheet.getDefaultVertexStyle();
  51325. }
  51326. // Resolves the stylename using the above as the default
  51327. if (stylename != null)
  51328. {
  51329. style = this.postProcessCellStyle(this.stylesheet.getCellStyle(stylename, style));
  51330. }
  51331. // Returns a non-null value if no style can be found
  51332. if (style == null)
  51333. {
  51334. style = new Object();
  51335. }
  51336. return style;
  51337. };
  51338. /**
  51339. * Function: postProcessCellStyle
  51340. *
  51341. * Tries to resolve the value for the image style in the image bundles and
  51342. * turns short data URIs as defined in mxImageBundle to data URIs as
  51343. * defined in RFC 2397 of the IETF.
  51344. */
  51345. mxGraph.prototype.postProcessCellStyle = function(style)
  51346. {
  51347. if (style != null)
  51348. {
  51349. var key = style[mxConstants.STYLE_IMAGE];
  51350. var image = this.getImageFromBundles(key);
  51351. if (image != null)
  51352. {
  51353. style[mxConstants.STYLE_IMAGE] = image;
  51354. }
  51355. else
  51356. {
  51357. image = key;
  51358. }
  51359. // Converts short data uris to normal data uris
  51360. if (image != null && image.substring(0, 11) == 'data:image/')
  51361. {
  51362. if (image.substring(0, 20) == 'data:image/svg+xml,<')
  51363. {
  51364. // Required for FF and IE11
  51365. image = image.substring(0, 19) + encodeURIComponent(image.substring(19));
  51366. }
  51367. else if (image.substring(0, 22) != 'data:image/svg+xml,%3C')
  51368. {
  51369. var comma = image.indexOf(',');
  51370. // Adds base64 encoding prefix if needed
  51371. if (comma > 0 && image.substring(comma - 7, comma + 1) != ';base64,')
  51372. {
  51373. image = image.substring(0, comma) + ';base64,'
  51374. + image.substring(comma + 1);
  51375. }
  51376. }
  51377. style[mxConstants.STYLE_IMAGE] = image;
  51378. }
  51379. }
  51380. return style;
  51381. };
  51382. /**
  51383. * Function: setCellStyle
  51384. *
  51385. * Sets the style of the specified cells. If no cells are given, then the
  51386. * selection cells are changed.
  51387. *
  51388. * Parameters:
  51389. *
  51390. * style - String representing the new style of the cells.
  51391. * cells - Optional array of <mxCells> to set the style for. Default is the
  51392. * selection cells.
  51393. */
  51394. mxGraph.prototype.setCellStyle = function(style, cells)
  51395. {
  51396. cells = cells || this.getSelectionCells();
  51397. if (cells != null)
  51398. {
  51399. this.model.beginUpdate();
  51400. try
  51401. {
  51402. for (var i = 0; i < cells.length; i++)
  51403. {
  51404. this.model.setStyle(cells[i], style);
  51405. }
  51406. }
  51407. finally
  51408. {
  51409. this.model.endUpdate();
  51410. }
  51411. }
  51412. };
  51413. /**
  51414. * Function: toggleCellStyle
  51415. *
  51416. * Toggles the boolean value for the given key in the style of the given cell
  51417. * and returns the new value as 0 or 1. If no cell is specified then the
  51418. * selection cell is used.
  51419. *
  51420. * Parameter:
  51421. *
  51422. * key - String representing the key for the boolean value to be toggled.
  51423. * defaultValue - Optional boolean default value if no value is defined.
  51424. * Default is false.
  51425. * cell - Optional <mxCell> whose style should be modified. Default is
  51426. * the selection cell.
  51427. */
  51428. mxGraph.prototype.toggleCellStyle = function(key, defaultValue, cell)
  51429. {
  51430. cell = cell || this.getSelectionCell();
  51431. return this.toggleCellStyles(key, defaultValue, [cell]);
  51432. };
  51433. /**
  51434. * Function: toggleCellStyles
  51435. *
  51436. * Toggles the boolean value for the given key in the style of the given cells
  51437. * and returns the new value as 0 or 1. If no cells are specified, then the
  51438. * selection cells are used. For example, this can be used to toggle
  51439. * <mxConstants.STYLE_ROUNDED> or any other style with a boolean value.
  51440. *
  51441. * Parameter:
  51442. *
  51443. * key - String representing the key for the boolean value to be toggled.
  51444. * defaultValue - Optional boolean default value if no value is defined.
  51445. * Default is false.
  51446. * cells - Optional array of <mxCells> whose styles should be modified.
  51447. * Default is the selection cells.
  51448. */
  51449. mxGraph.prototype.toggleCellStyles = function(key, defaultValue, cells)
  51450. {
  51451. defaultValue = (defaultValue != null) ? defaultValue : false;
  51452. cells = cells || this.getSelectionCells();
  51453. var value = null;
  51454. if (cells != null && cells.length > 0)
  51455. {
  51456. var style = this.getCurrentCellStyle(cells[0]);
  51457. value = (mxUtils.getValue(style, key, defaultValue)) ? 0 : 1;
  51458. this.setCellStyles(key, value, cells);
  51459. }
  51460. return value;
  51461. };
  51462. /**
  51463. * Function: setCellStyles
  51464. *
  51465. * Sets the key to value in the styles of the given cells. This will modify
  51466. * the existing cell styles in-place and override any existing assignment
  51467. * for the given key. If no cells are specified, then the selection cells
  51468. * are changed. If no value is specified, then the respective key is
  51469. * removed from the styles.
  51470. *
  51471. * Parameters:
  51472. *
  51473. * key - String representing the key to be assigned.
  51474. * value - String representing the new value for the key.
  51475. * cells - Optional array of <mxCells> to change the style for. Default is
  51476. * the selection cells.
  51477. */
  51478. mxGraph.prototype.setCellStyles = function(key, value, cells)
  51479. {
  51480. cells = cells || this.getSelectionCells();
  51481. mxUtils.setCellStyles(this.model, cells, key, value);
  51482. };
  51483. /**
  51484. * Function: toggleCellStyleFlags
  51485. *
  51486. * Toggles the given bit for the given key in the styles of the specified
  51487. * cells.
  51488. *
  51489. * Parameters:
  51490. *
  51491. * key - String representing the key to toggle the flag in.
  51492. * flag - Integer that represents the bit to be toggled.
  51493. * cells - Optional array of <mxCells> to change the style for. Default is
  51494. * the selection cells.
  51495. */
  51496. mxGraph.prototype.toggleCellStyleFlags = function(key, flag, cells)
  51497. {
  51498. this.setCellStyleFlags(key, flag, null, cells);
  51499. };
  51500. /**
  51501. * Function: setCellStyleFlags
  51502. *
  51503. * Sets or toggles the given bit for the given key in the styles of the
  51504. * specified cells.
  51505. *
  51506. * Parameters:
  51507. *
  51508. * key - String representing the key to toggle the flag in.
  51509. * flag - Integer that represents the bit to be toggled.
  51510. * value - Boolean value to be used or null if the value should be toggled.
  51511. * cells - Optional array of <mxCells> to change the style for. Default is
  51512. * the selection cells.
  51513. */
  51514. mxGraph.prototype.setCellStyleFlags = function(key, flag, value, cells)
  51515. {
  51516. cells = cells || this.getSelectionCells();
  51517. if (cells != null && cells.length > 0)
  51518. {
  51519. if (value == null)
  51520. {
  51521. var style = this.getCurrentCellStyle(cells[0]);
  51522. var current = parseInt(style[key] || 0);
  51523. value = !((current & flag) == flag);
  51524. }
  51525. mxUtils.setCellStyleFlags(this.model, cells, key, flag, value);
  51526. }
  51527. };
  51528. /**
  51529. * Group: Cell alignment and orientation
  51530. */
  51531. /**
  51532. * Function: alignCells
  51533. *
  51534. * Aligns the given cells vertically or horizontally according to the given
  51535. * alignment using the optional parameter as the coordinate.
  51536. *
  51537. * Parameters:
  51538. *
  51539. * align - Specifies the alignment. Possible values are all constants in
  51540. * mxConstants with an ALIGN prefix.
  51541. * cells - Array of <mxCells> to be aligned.
  51542. * param - Optional coordinate for the alignment.
  51543. */
  51544. mxGraph.prototype.alignCells = function(align, cells, param)
  51545. {
  51546. if (cells == null)
  51547. {
  51548. cells = this.getSelectionCells();
  51549. }
  51550. if (cells != null && cells.length > 1)
  51551. {
  51552. // Finds the required coordinate for the alignment
  51553. if (param == null)
  51554. {
  51555. for (var i = 0; i < cells.length; i++)
  51556. {
  51557. var state = this.view.getState(cells[i]);
  51558. if (state != null && !this.model.isEdge(cells[i]))
  51559. {
  51560. if (param == null)
  51561. {
  51562. if (align == mxConstants.ALIGN_CENTER)
  51563. {
  51564. param = state.x + state.width / 2;
  51565. break;
  51566. }
  51567. else if (align == mxConstants.ALIGN_RIGHT)
  51568. {
  51569. param = state.x + state.width;
  51570. }
  51571. else if (align == mxConstants.ALIGN_TOP)
  51572. {
  51573. param = state.y;
  51574. }
  51575. else if (align == mxConstants.ALIGN_MIDDLE)
  51576. {
  51577. param = state.y + state.height / 2;
  51578. break;
  51579. }
  51580. else if (align == mxConstants.ALIGN_BOTTOM)
  51581. {
  51582. param = state.y + state.height;
  51583. }
  51584. else
  51585. {
  51586. param = state.x;
  51587. }
  51588. }
  51589. else
  51590. {
  51591. if (align == mxConstants.ALIGN_RIGHT)
  51592. {
  51593. param = Math.max(param, state.x + state.width);
  51594. }
  51595. else if (align == mxConstants.ALIGN_TOP)
  51596. {
  51597. param = Math.min(param, state.y);
  51598. }
  51599. else if (align == mxConstants.ALIGN_BOTTOM)
  51600. {
  51601. param = Math.max(param, state.y + state.height);
  51602. }
  51603. else
  51604. {
  51605. param = Math.min(param, state.x);
  51606. }
  51607. }
  51608. }
  51609. }
  51610. }
  51611. // Aligns the cells to the coordinate
  51612. if (param != null)
  51613. {
  51614. var s = this.view.scale;
  51615. this.model.beginUpdate();
  51616. try
  51617. {
  51618. for (var i = 0; i < cells.length; i++)
  51619. {
  51620. var state = this.view.getState(cells[i]);
  51621. if (state != null)
  51622. {
  51623. var geo = this.getCellGeometry(cells[i]);
  51624. if (geo != null && !this.model.isEdge(cells[i]))
  51625. {
  51626. geo = geo.clone();
  51627. if (align == mxConstants.ALIGN_CENTER)
  51628. {
  51629. geo.x += (param - state.x - state.width / 2) / s;
  51630. }
  51631. else if (align == mxConstants.ALIGN_RIGHT)
  51632. {
  51633. geo.x += (param - state.x - state.width) / s;
  51634. }
  51635. else if (align == mxConstants.ALIGN_TOP)
  51636. {
  51637. geo.y += (param - state.y) / s;
  51638. }
  51639. else if (align == mxConstants.ALIGN_MIDDLE)
  51640. {
  51641. geo.y += (param - state.y - state.height / 2) / s;
  51642. }
  51643. else if (align == mxConstants.ALIGN_BOTTOM)
  51644. {
  51645. geo.y += (param - state.y - state.height) / s;
  51646. }
  51647. else
  51648. {
  51649. geo.x += (param - state.x) / s;
  51650. }
  51651. this.resizeCell(cells[i], geo);
  51652. }
  51653. }
  51654. }
  51655. this.fireEvent(new mxEventObject(mxEvent.ALIGN_CELLS,
  51656. 'align', align, 'cells', cells));
  51657. }
  51658. finally
  51659. {
  51660. this.model.endUpdate();
  51661. }
  51662. }
  51663. }
  51664. return cells;
  51665. };
  51666. /**
  51667. * Function: flipEdge
  51668. *
  51669. * Toggles the style of the given edge between null (or empty) and
  51670. * <alternateEdgeStyle>. This method fires <mxEvent.FLIP_EDGE> while the
  51671. * transaction is in progress. Returns the edge that was flipped.
  51672. *
  51673. * Here is an example that overrides this implementation to invert the
  51674. * value of <mxConstants.STYLE_ELBOW> without removing any existing styles.
  51675. *
  51676. * (code)
  51677. * graph.flipEdge = function(edge)
  51678. * {
  51679. * if (edge != null)
  51680. * {
  51681. * var style = this.getCurrentCellStyle(edge);
  51682. * var elbow = mxUtils.getValue(style, mxConstants.STYLE_ELBOW,
  51683. * mxConstants.ELBOW_HORIZONTAL);
  51684. * var value = (elbow == mxConstants.ELBOW_HORIZONTAL) ?
  51685. * mxConstants.ELBOW_VERTICAL : mxConstants.ELBOW_HORIZONTAL;
  51686. * this.setCellStyles(mxConstants.STYLE_ELBOW, value, [edge]);
  51687. * }
  51688. * };
  51689. * (end)
  51690. *
  51691. * Parameters:
  51692. *
  51693. * edge - <mxCell> whose style should be changed.
  51694. */
  51695. mxGraph.prototype.flipEdge = function(edge)
  51696. {
  51697. if (edge != null &&
  51698. this.alternateEdgeStyle != null)
  51699. {
  51700. this.model.beginUpdate();
  51701. try
  51702. {
  51703. var style = this.model.getStyle(edge);
  51704. if (style == null || style.length == 0)
  51705. {
  51706. this.model.setStyle(edge, this.alternateEdgeStyle);
  51707. }
  51708. else
  51709. {
  51710. this.model.setStyle(edge, null);
  51711. }
  51712. // Removes all existing control points
  51713. this.resetEdge(edge);
  51714. this.fireEvent(new mxEventObject(mxEvent.FLIP_EDGE, 'edge', edge));
  51715. }
  51716. finally
  51717. {
  51718. this.model.endUpdate();
  51719. }
  51720. }
  51721. return edge;
  51722. };
  51723. /**
  51724. * Function: addImageBundle
  51725. *
  51726. * Adds the specified <mxImageBundle>.
  51727. */
  51728. mxGraph.prototype.addImageBundle = function(bundle)
  51729. {
  51730. this.imageBundles.push(bundle);
  51731. };
  51732. /**
  51733. * Function: removeImageBundle
  51734. *
  51735. * Removes the specified <mxImageBundle>.
  51736. */
  51737. mxGraph.prototype.removeImageBundle = function(bundle)
  51738. {
  51739. var tmp = [];
  51740. for (var i = 0; i < this.imageBundles.length; i++)
  51741. {
  51742. if (this.imageBundles[i] != bundle)
  51743. {
  51744. tmp.push(this.imageBundles[i]);
  51745. }
  51746. }
  51747. this.imageBundles = tmp;
  51748. };
  51749. /**
  51750. * Function: getImageFromBundles
  51751. *
  51752. * Searches all <imageBundles> for the specified key and returns the value
  51753. * for the first match or null if the key is not found.
  51754. */
  51755. mxGraph.prototype.getImageFromBundles = function(key)
  51756. {
  51757. if (key != null)
  51758. {
  51759. for (var i = 0; i < this.imageBundles.length; i++)
  51760. {
  51761. var image = this.imageBundles[i].getImage(key);
  51762. if (image != null)
  51763. {
  51764. return image;
  51765. }
  51766. }
  51767. }
  51768. return null;
  51769. };
  51770. /**
  51771. * Group: Order
  51772. */
  51773. /**
  51774. * Function: orderCells
  51775. *
  51776. * Moves the given cells to the front or back. The change is carried out
  51777. * using <cellsOrdered>. This method fires <mxEvent.ORDER_CELLS> while the
  51778. * transaction is in progress.
  51779. *
  51780. * Parameters:
  51781. *
  51782. * back - Boolean that specifies if the cells should be moved to back.
  51783. * cells - Array of <mxCells> to move to the background. If null is
  51784. * specified then the selection cells are used.
  51785. */
  51786. mxGraph.prototype.orderCells = function(back, cells)
  51787. {
  51788. if (cells == null)
  51789. {
  51790. cells = mxUtils.sortCells(this.getSelectionCells(), true);
  51791. }
  51792. this.model.beginUpdate();
  51793. try
  51794. {
  51795. this.cellsOrdered(cells, back);
  51796. this.fireEvent(new mxEventObject(mxEvent.ORDER_CELLS,
  51797. 'back', back, 'cells', cells));
  51798. }
  51799. finally
  51800. {
  51801. this.model.endUpdate();
  51802. }
  51803. return cells;
  51804. };
  51805. /**
  51806. * Function: cellsOrdered
  51807. *
  51808. * Moves the given cells to the front or back. This method fires
  51809. * <mxEvent.CELLS_ORDERED> while the transaction is in progress.
  51810. *
  51811. * Parameters:
  51812. *
  51813. * cells - Array of <mxCells> whose order should be changed.
  51814. * back - Boolean that specifies if the cells should be moved to back.
  51815. */
  51816. mxGraph.prototype.cellsOrdered = function(cells, back)
  51817. {
  51818. if (cells != null)
  51819. {
  51820. this.model.beginUpdate();
  51821. try
  51822. {
  51823. for (var i = 0; i < cells.length; i++)
  51824. {
  51825. var parent = this.model.getParent(cells[i]);
  51826. if (back)
  51827. {
  51828. this.model.add(parent, cells[i], i);
  51829. }
  51830. else
  51831. {
  51832. this.model.add(parent, cells[i],
  51833. this.model.getChildCount(parent) - 1);
  51834. }
  51835. }
  51836. this.fireEvent(new mxEventObject(mxEvent.CELLS_ORDERED,
  51837. 'back', back, 'cells', cells));
  51838. }
  51839. finally
  51840. {
  51841. this.model.endUpdate();
  51842. }
  51843. }
  51844. };
  51845. /**
  51846. * Group: Grouping
  51847. */
  51848. /**
  51849. * Function: groupCells
  51850. *
  51851. * Adds the cells into the given group. The change is carried out using
  51852. * <cellsAdded>, <cellsMoved> and <cellsResized>. This method fires
  51853. * <mxEvent.GROUP_CELLS> while the transaction is in progress. Returns the
  51854. * new group. A group is only created if there is at least one entry in the
  51855. * given array of cells.
  51856. *
  51857. * Parameters:
  51858. *
  51859. * group - <mxCell> that represents the target group. If null is specified
  51860. * then a new group is created using <createGroupCell>.
  51861. * border - Optional integer that specifies the border between the child
  51862. * area and the group bounds. Default is 0.
  51863. * cells - Optional array of <mxCells> to be grouped. If null is specified
  51864. * then the selection cells are used.
  51865. */
  51866. mxGraph.prototype.groupCells = function(group, border, cells)
  51867. {
  51868. if (cells == null)
  51869. {
  51870. cells = mxUtils.sortCells(this.getSelectionCells(), true);
  51871. }
  51872. cells = this.getCellsForGroup(cells);
  51873. if (group == null)
  51874. {
  51875. group = this.createGroupCell(cells);
  51876. }
  51877. var bounds = this.getBoundsForGroup(group, cells, border);
  51878. if (cells.length > 0 && bounds != null)
  51879. {
  51880. // Uses parent of group or previous parent of first child
  51881. var parent = this.model.getParent(group);
  51882. if (parent == null)
  51883. {
  51884. parent = this.model.getParent(cells[0]);
  51885. }
  51886. this.model.beginUpdate();
  51887. try
  51888. {
  51889. // Checks if the group has a geometry and
  51890. // creates one if one does not exist
  51891. if (this.getCellGeometry(group) == null)
  51892. {
  51893. this.model.setGeometry(group, new mxGeometry());
  51894. }
  51895. // Adds the group into the parent
  51896. var index = this.model.getChildCount(parent);
  51897. this.cellsAdded([group], parent, index, null, null, false, false, false);
  51898. // Adds the children into the group and moves
  51899. index = this.model.getChildCount(group);
  51900. this.cellsAdded(cells, group, index, null, null, false, false, false);
  51901. this.cellsMoved(cells, -bounds.x, -bounds.y, false, false, false);
  51902. // Resizes the group
  51903. this.cellsResized([group], [bounds], false);
  51904. this.fireEvent(new mxEventObject(mxEvent.GROUP_CELLS,
  51905. 'group', group, 'border', border, 'cells', cells));
  51906. }
  51907. finally
  51908. {
  51909. this.model.endUpdate();
  51910. }
  51911. }
  51912. return group;
  51913. };
  51914. /**
  51915. * Function: getCellsForGroup
  51916. *
  51917. * Returns the cells with the same parent as the first cell
  51918. * in the given array.
  51919. */
  51920. mxGraph.prototype.getCellsForGroup = function(cells)
  51921. {
  51922. var result = [];
  51923. if (cells != null && cells.length > 0)
  51924. {
  51925. var parent = this.model.getParent(cells[0]);
  51926. result.push(cells[0]);
  51927. // Filters selection cells with the same parent
  51928. for (var i = 1; i < cells.length; i++)
  51929. {
  51930. if (this.model.getParent(cells[i]) == parent)
  51931. {
  51932. result.push(cells[i]);
  51933. }
  51934. }
  51935. }
  51936. return result;
  51937. };
  51938. /**
  51939. * Function: getBoundsForGroup
  51940. *
  51941. * Returns the bounds to be used for the given group and children.
  51942. */
  51943. mxGraph.prototype.getBoundsForGroup = function(group, children, border)
  51944. {
  51945. var result = this.getBoundingBoxFromGeometry(children, true);
  51946. if (result != null)
  51947. {
  51948. if (this.isSwimlane(group))
  51949. {
  51950. var size = this.getStartSize(group);
  51951. result.x -= size.width;
  51952. result.y -= size.height;
  51953. result.width += size.width;
  51954. result.height += size.height;
  51955. }
  51956. // Adds the border
  51957. if (border != null)
  51958. {
  51959. result.x -= border;
  51960. result.y -= border;
  51961. result.width += 2 * border;
  51962. result.height += 2 * border;
  51963. }
  51964. }
  51965. return result;
  51966. };
  51967. /**
  51968. * Function: createGroupCell
  51969. *
  51970. * Hook for creating the group cell to hold the given array of <mxCells> if
  51971. * no group cell was given to the <group> function.
  51972. *
  51973. * The following code can be used to set the style of new group cells.
  51974. *
  51975. * (code)
  51976. * var graphCreateGroupCell = graph.createGroupCell;
  51977. * graph.createGroupCell = function(cells)
  51978. * {
  51979. * var group = graphCreateGroupCell.apply(this, arguments);
  51980. * group.setStyle('group');
  51981. *
  51982. * return group;
  51983. * };
  51984. */
  51985. mxGraph.prototype.createGroupCell = function(cells)
  51986. {
  51987. var group = new mxCell('');
  51988. group.setVertex(true);
  51989. group.setConnectable(false);
  51990. return group;
  51991. };
  51992. /**
  51993. * Function: ungroupCells
  51994. *
  51995. * Ungroups the given cells by moving the children the children to their
  51996. * parents parent and removing the empty groups. Returns the children that
  51997. * have been removed from the groups.
  51998. *
  51999. * Parameters:
  52000. *
  52001. * cells - Array of cells to be ungrouped. If null is specified then the
  52002. * selection cells are used.
  52003. */
  52004. mxGraph.prototype.ungroupCells = function(cells)
  52005. {
  52006. var result = [];
  52007. if (cells == null)
  52008. {
  52009. cells = this.getSelectionCells();
  52010. // Finds the cells with children
  52011. var tmp = [];
  52012. for (var i = 0; i < cells.length; i++)
  52013. {
  52014. if (this.model.getChildCount(cells[i]) > 0)
  52015. {
  52016. tmp.push(cells[i]);
  52017. }
  52018. }
  52019. cells = tmp;
  52020. }
  52021. if (cells != null && cells.length > 0)
  52022. {
  52023. this.model.beginUpdate();
  52024. try
  52025. {
  52026. for (var i = 0; i < cells.length; i++)
  52027. {
  52028. var children = this.model.getChildren(cells[i]);
  52029. if (children != null && children.length > 0)
  52030. {
  52031. children = children.slice();
  52032. var parent = this.model.getParent(cells[i]);
  52033. var index = this.model.getChildCount(parent);
  52034. this.cellsAdded(children, parent, index, null, null, true);
  52035. result = result.concat(children);
  52036. }
  52037. }
  52038. this.removeCellsAfterUngroup(cells);
  52039. this.fireEvent(new mxEventObject(mxEvent.UNGROUP_CELLS, 'cells', cells));
  52040. }
  52041. finally
  52042. {
  52043. this.model.endUpdate();
  52044. }
  52045. }
  52046. return result;
  52047. };
  52048. /**
  52049. * Function: removeCellsAfterUngroup
  52050. *
  52051. * Hook to remove the groups after <ungroupCells>.
  52052. *
  52053. * Parameters:
  52054. *
  52055. * cells - Array of <mxCells> that were ungrouped.
  52056. */
  52057. mxGraph.prototype.removeCellsAfterUngroup = function(cells)
  52058. {
  52059. this.cellsRemoved(this.addAllEdges(cells));
  52060. };
  52061. /**
  52062. * Function: removeCellsFromParent
  52063. *
  52064. * Removes the specified cells from their parents and adds them to the
  52065. * default parent. Returns the cells that were removed from their parents.
  52066. *
  52067. * Parameters:
  52068. *
  52069. * cells - Array of <mxCells> to be removed from their parents.
  52070. */
  52071. mxGraph.prototype.removeCellsFromParent = function(cells)
  52072. {
  52073. if (cells == null)
  52074. {
  52075. cells = this.getSelectionCells();
  52076. }
  52077. this.model.beginUpdate();
  52078. try
  52079. {
  52080. var parent = this.getDefaultParent();
  52081. var index = this.model.getChildCount(parent);
  52082. this.cellsAdded(cells, parent, index, null, null, true);
  52083. this.fireEvent(new mxEventObject(mxEvent.REMOVE_CELLS_FROM_PARENT, 'cells', cells));
  52084. }
  52085. finally
  52086. {
  52087. this.model.endUpdate();
  52088. }
  52089. return cells;
  52090. };
  52091. /**
  52092. * Function: updateGroupBounds
  52093. *
  52094. * Updates the bounds of the given groups to include all children and returns
  52095. * the passed-in cells. Call this with the groups in parent to child order,
  52096. * top-most group first, the cells are processed in reverse order and cells
  52097. * with no children are ignored.
  52098. *
  52099. * Parameters:
  52100. *
  52101. * cells - The groups whose bounds should be updated. If this is null, then
  52102. * the selection cells are used.
  52103. * border - Optional border to be added in the group. Default is 0.
  52104. * moveGroup - Optional boolean that allows the group to be moved. Default
  52105. * is false.
  52106. * topBorder - Optional top border to be added in the group. Default is 0.
  52107. * rightBorder - Optional top border to be added in the group. Default is 0.
  52108. * bottomBorder - Optional top border to be added in the group. Default is 0.
  52109. * leftBorder - Optional top border to be added in the group. Default is 0.
  52110. */
  52111. mxGraph.prototype.updateGroupBounds = function(cells, border, moveGroup, topBorder, rightBorder, bottomBorder, leftBorder)
  52112. {
  52113. if (cells == null)
  52114. {
  52115. cells = this.getSelectionCells();
  52116. }
  52117. border = (border != null) ? border : 0;
  52118. moveGroup = (moveGroup != null) ? moveGroup : false;
  52119. topBorder = (topBorder != null) ? topBorder : 0;
  52120. rightBorder = (rightBorder != null) ? rightBorder : 0;
  52121. bottomBorder = (bottomBorder != null) ? bottomBorder : 0;
  52122. leftBorder = (leftBorder != null) ? leftBorder : 0;
  52123. this.model.beginUpdate();
  52124. try
  52125. {
  52126. for (var i = cells.length - 1; i >= 0; i--)
  52127. {
  52128. var geo = this.getCellGeometry(cells[i]);
  52129. if (geo != null)
  52130. {
  52131. var children = this.getChildCells(cells[i]);
  52132. if (children != null && children.length > 0)
  52133. {
  52134. var bounds = this.getBoundingBoxFromGeometry(children, true);
  52135. if (bounds != null && bounds.width > 0 && bounds.height > 0)
  52136. {
  52137. var left = 0;
  52138. var top = 0;
  52139. // Adds the size of the title area for swimlanes
  52140. if (this.isSwimlane(cells[i]))
  52141. {
  52142. var size = this.getStartSize(cells[i]);
  52143. left = size.width;
  52144. top = size.height;
  52145. }
  52146. geo = geo.clone();
  52147. if (moveGroup)
  52148. {
  52149. geo.x = Math.round(geo.x + bounds.x - border - left - leftBorder);
  52150. geo.y = Math.round(geo.y + bounds.y - border - top - topBorder);
  52151. }
  52152. geo.width = Math.round(bounds.width + 2 * border + left + leftBorder + rightBorder);
  52153. geo.height = Math.round(bounds.height + 2 * border + top + topBorder + bottomBorder);
  52154. this.model.setGeometry(cells[i], geo);
  52155. this.moveCells(children, border + left - bounds.x + leftBorder,
  52156. border + top - bounds.y + topBorder);
  52157. }
  52158. }
  52159. }
  52160. }
  52161. }
  52162. finally
  52163. {
  52164. this.model.endUpdate();
  52165. }
  52166. return cells;
  52167. };
  52168. /**
  52169. * Function: getBoundingBox
  52170. *
  52171. * Returns the bounding box for the given array of <mxCells>. The bounding box for
  52172. * each cell and its descendants is computed using <mxGraphView.getBoundingBox>.
  52173. *
  52174. * Parameters:
  52175. *
  52176. * cells - Array of <mxCells> whose bounding box should be returned.
  52177. */
  52178. mxGraph.prototype.getBoundingBox = function(cells)
  52179. {
  52180. var result = null;
  52181. if (cells != null && cells.length > 0)
  52182. {
  52183. for (var i = 0; i < cells.length; i++)
  52184. {
  52185. if (this.model.isVertex(cells[i]) || this.model.isEdge(cells[i]))
  52186. {
  52187. var bbox = this.view.getBoundingBox(this.view.getState(cells[i]), true);
  52188. if (bbox != null)
  52189. {
  52190. if (result == null)
  52191. {
  52192. result = mxRectangle.fromRectangle(bbox);
  52193. }
  52194. else
  52195. {
  52196. result.add(bbox);
  52197. }
  52198. }
  52199. }
  52200. }
  52201. }
  52202. return result;
  52203. };
  52204. /**
  52205. * Group: Cell cloning, insertion and removal
  52206. */
  52207. /**
  52208. * Function: cloneCell
  52209. *
  52210. * Returns the clone for the given cell. Uses <cloneCells>.
  52211. *
  52212. * Parameters:
  52213. *
  52214. * cell - <mxCell> to be cloned.
  52215. * allowInvalidEdges - Optional boolean that specifies if invalid edges
  52216. * should be cloned. Default is true.
  52217. * mapping - Optional mapping for existing clones.
  52218. * keepPosition - Optional boolean indicating if the position of the cells should
  52219. * be updated to reflect the lost parent cell. Default is false.
  52220. */
  52221. mxGraph.prototype.cloneCell = function(cell, allowInvalidEdges, mapping, keepPosition)
  52222. {
  52223. return this.cloneCells([cell], allowInvalidEdges, mapping, keepPosition)[0];
  52224. };
  52225. /**
  52226. * Function: cloneCells
  52227. *
  52228. * Returns the clones for the given cells. The clones are created recursively
  52229. * using <mxGraphModel.cloneCells>. If the terminal of an edge is not in the
  52230. * given array, then the respective end is assigned a terminal point and the
  52231. * terminal is removed.
  52232. *
  52233. * Parameters:
  52234. *
  52235. * cells - Array of <mxCells> to be cloned.
  52236. * allowInvalidEdges - Optional boolean that specifies if invalid edges
  52237. * should be cloned. Default is true.
  52238. * mapping - Optional mapping for existing clones.
  52239. * keepPosition - Optional boolean indicating if the position of the cells should
  52240. * be updated to reflect the lost parent cell. Default is false.
  52241. */
  52242. mxGraph.prototype.cloneCells = function(cells, allowInvalidEdges, mapping, keepPosition)
  52243. {
  52244. allowInvalidEdges = (allowInvalidEdges != null) ? allowInvalidEdges : true;
  52245. var clones = null;
  52246. if (cells != null)
  52247. {
  52248. // Creates a dictionary for fast lookups
  52249. var dict = new mxDictionary();
  52250. var tmp = [];
  52251. for (var i = 0; i < cells.length; i++)
  52252. {
  52253. dict.put(cells[i], true);
  52254. tmp.push(cells[i]);
  52255. }
  52256. if (tmp.length > 0)
  52257. {
  52258. var scale = this.view.scale;
  52259. var trans = this.view.translate;
  52260. clones = this.model.cloneCells(cells, true, mapping);
  52261. for (var i = 0; i < cells.length; i++)
  52262. {
  52263. if (!allowInvalidEdges && this.model.isEdge(clones[i]) &&
  52264. this.getEdgeValidationError(clones[i],
  52265. this.model.getTerminal(clones[i], true),
  52266. this.model.getTerminal(clones[i], false)) != null)
  52267. {
  52268. clones[i] = null;
  52269. }
  52270. else
  52271. {
  52272. var g = this.model.getGeometry(clones[i]);
  52273. if (g != null)
  52274. {
  52275. var state = this.view.getState(cells[i]);
  52276. var pstate = this.view.getState(this.model.getParent(cells[i]));
  52277. if (state != null && pstate != null)
  52278. {
  52279. var dx = (keepPosition) ? 0 : pstate.origin.x;
  52280. var dy = (keepPosition) ? 0 : pstate.origin.y;
  52281. if (this.model.isEdge(clones[i]))
  52282. {
  52283. var pts = state.absolutePoints;
  52284. if (pts != null)
  52285. {
  52286. // Checks if the source is cloned or sets the terminal point
  52287. var src = this.model.getTerminal(cells[i], true);
  52288. while (src != null && !dict.get(src))
  52289. {
  52290. src = this.model.getParent(src);
  52291. }
  52292. if (src == null && pts[0] != null)
  52293. {
  52294. g.setTerminalPoint(
  52295. new mxPoint(pts[0].x / scale - trans.x,
  52296. pts[0].y / scale - trans.y), true);
  52297. }
  52298. // Checks if the target is cloned or sets the terminal point
  52299. var trg = this.model.getTerminal(cells[i], false);
  52300. while (trg != null && !dict.get(trg))
  52301. {
  52302. trg = this.model.getParent(trg);
  52303. }
  52304. var n = pts.length - 1;
  52305. if (trg == null && pts[n] != null)
  52306. {
  52307. g.setTerminalPoint(
  52308. new mxPoint(pts[n].x / scale - trans.x,
  52309. pts[n].y / scale - trans.y), false);
  52310. }
  52311. // Translates the control points
  52312. var points = g.points;
  52313. if (points != null)
  52314. {
  52315. for (var j = 0; j < points.length; j++)
  52316. {
  52317. points[j].x += dx;
  52318. points[j].y += dy;
  52319. }
  52320. }
  52321. }
  52322. }
  52323. else
  52324. {
  52325. g.translate(dx, dy);
  52326. }
  52327. }
  52328. }
  52329. }
  52330. }
  52331. }
  52332. else
  52333. {
  52334. clones = [];
  52335. }
  52336. }
  52337. return clones;
  52338. };
  52339. /**
  52340. * Function: insertVertex
  52341. *
  52342. * Adds a new vertex into the given parent <mxCell> using value as the user
  52343. * object and the given coordinates as the <mxGeometry> of the new vertex.
  52344. * The id and style are used for the respective properties of the new
  52345. * <mxCell>, which is returned.
  52346. *
  52347. * When adding new vertices from a mouse event, one should take into
  52348. * account the offset of the graph container and the scale and translation
  52349. * of the view in order to find the correct unscaled, untranslated
  52350. * coordinates using <mxGraph.getPointForEvent> as follows:
  52351. *
  52352. * (code)
  52353. * var pt = graph.getPointForEvent(evt);
  52354. * var parent = graph.getDefaultParent();
  52355. * graph.insertVertex(parent, null,
  52356. * 'Hello, World!', x, y, 220, 30);
  52357. * (end)
  52358. *
  52359. * For adding image cells, the style parameter can be assigned as
  52360. *
  52361. * (code)
  52362. * stylename;image=imageUrl
  52363. * (end)
  52364. *
  52365. * See <mxGraph> for more information on using images.
  52366. *
  52367. * Parameters:
  52368. *
  52369. * parent - <mxCell> that specifies the parent of the new vertex.
  52370. * id - Optional string that defines the Id of the new vertex.
  52371. * value - Object to be used as the user object.
  52372. * x - Integer that defines the x coordinate of the vertex.
  52373. * y - Integer that defines the y coordinate of the vertex.
  52374. * width - Integer that defines the width of the vertex.
  52375. * height - Integer that defines the height of the vertex.
  52376. * style - Optional string that defines the cell style.
  52377. * relative - Optional boolean that specifies if the geometry is relative.
  52378. * Default is false.
  52379. */
  52380. mxGraph.prototype.insertVertex = function(parent, id, value,
  52381. x, y, width, height, style, relative)
  52382. {
  52383. var vertex = this.createVertex(parent, id, value, x, y, width, height, style, relative);
  52384. return this.addCell(vertex, parent);
  52385. };
  52386. /**
  52387. * Function: createVertex
  52388. *
  52389. * Hook method that creates the new vertex for <insertVertex>.
  52390. */
  52391. mxGraph.prototype.createVertex = function(parent, id, value,
  52392. x, y, width, height, style, relative)
  52393. {
  52394. // Creates the geometry for the vertex
  52395. var geometry = new mxGeometry(x, y, width, height);
  52396. geometry.relative = (relative != null) ? relative : false;
  52397. // Creates the vertex
  52398. var vertex = new mxCell(value, geometry, style);
  52399. vertex.setId(id);
  52400. vertex.setVertex(true);
  52401. vertex.setConnectable(true);
  52402. return vertex;
  52403. };
  52404. /**
  52405. * Function: insertEdge
  52406. *
  52407. * Adds a new edge into the given parent <mxCell> using value as the user
  52408. * object and the given source and target as the terminals of the new edge.
  52409. * The id and style are used for the respective properties of the new
  52410. * <mxCell>, which is returned.
  52411. *
  52412. * Parameters:
  52413. *
  52414. * parent - <mxCell> that specifies the parent of the new edge.
  52415. * id - Optional string that defines the Id of the new edge.
  52416. * value - JavaScript object to be used as the user object.
  52417. * source - <mxCell> that defines the source of the edge.
  52418. * target - <mxCell> that defines the target of the edge.
  52419. * style - Optional string that defines the cell style.
  52420. */
  52421. mxGraph.prototype.insertEdge = function(parent, id, value, source, target, style)
  52422. {
  52423. var edge = this.createEdge(parent, id, value, source, target, style);
  52424. return this.addEdge(edge, parent, source, target);
  52425. };
  52426. /**
  52427. * Function: createEdge
  52428. *
  52429. * Hook method that creates the new edge for <insertEdge>. This
  52430. * implementation does not set the source and target of the edge, these
  52431. * are set when the edge is added to the model.
  52432. *
  52433. */
  52434. mxGraph.prototype.createEdge = function(parent, id, value, source, target, style)
  52435. {
  52436. // Creates the edge
  52437. var edge = new mxCell(value, new mxGeometry(), style);
  52438. edge.setId(id);
  52439. edge.setEdge(true);
  52440. edge.geometry.relative = true;
  52441. return edge;
  52442. };
  52443. /**
  52444. * Function: addEdge
  52445. *
  52446. * Adds the edge to the parent and connects it to the given source and
  52447. * target terminals. This is a shortcut method. Returns the edge that was
  52448. * added.
  52449. *
  52450. * Parameters:
  52451. *
  52452. * edge - <mxCell> to be inserted into the given parent.
  52453. * parent - <mxCell> that represents the new parent. If no parent is
  52454. * given then the default parent is used.
  52455. * source - Optional <mxCell> that represents the source terminal.
  52456. * target - Optional <mxCell> that represents the target terminal.
  52457. * index - Optional index to insert the cells at. Default is to append.
  52458. */
  52459. mxGraph.prototype.addEdge = function(edge, parent, source, target, index)
  52460. {
  52461. return this.addCell(edge, parent, index, source, target);
  52462. };
  52463. /**
  52464. * Function: addCell
  52465. *
  52466. * Adds the cell to the parent and connects it to the given source and
  52467. * target terminals. This is a shortcut method. Returns the cell that was
  52468. * added.
  52469. *
  52470. * Parameters:
  52471. *
  52472. * cell - <mxCell> to be inserted into the given parent.
  52473. * parent - <mxCell> that represents the new parent. If no parent is
  52474. * given then the default parent is used.
  52475. * index - Optional index to insert the cells at. Default is to append.
  52476. * source - Optional <mxCell> that represents the source terminal.
  52477. * target - Optional <mxCell> that represents the target terminal.
  52478. */
  52479. mxGraph.prototype.addCell = function(cell, parent, index, source, target)
  52480. {
  52481. return this.addCells([cell], parent, index, source, target)[0];
  52482. };
  52483. /**
  52484. * Function: addCells
  52485. *
  52486. * Adds the cells to the parent at the given index, connecting each cell to
  52487. * the optional source and target terminal. The change is carried out using
  52488. * <cellsAdded>. This method fires <mxEvent.ADD_CELLS> while the
  52489. * transaction is in progress. Returns the cells that were added.
  52490. *
  52491. * Parameters:
  52492. *
  52493. * cells - Array of <mxCells> to be inserted.
  52494. * parent - <mxCell> that represents the new parent. If no parent is
  52495. * given then the default parent is used.
  52496. * index - Optional index to insert the cells at. Default is to append.
  52497. * source - Optional source <mxCell> for all inserted cells.
  52498. * target - Optional target <mxCell> for all inserted cells.
  52499. * absolute - Optional boolean indicating of cells should be kept at
  52500. * their absolute position. Default is false.
  52501. */
  52502. mxGraph.prototype.addCells = function(cells, parent, index, source, target, absolute)
  52503. {
  52504. if (parent == null)
  52505. {
  52506. parent = this.getDefaultParent();
  52507. }
  52508. if (index == null)
  52509. {
  52510. index = this.model.getChildCount(parent);
  52511. }
  52512. this.model.beginUpdate();
  52513. try
  52514. {
  52515. this.cellsAdded(cells, parent, index, source, target, (absolute != null) ? absolute : false, true);
  52516. this.fireEvent(new mxEventObject(mxEvent.ADD_CELLS, 'cells', cells,
  52517. 'parent', parent, 'index', index, 'source', source, 'target', target));
  52518. }
  52519. finally
  52520. {
  52521. this.model.endUpdate();
  52522. }
  52523. return cells;
  52524. };
  52525. /**
  52526. * Function: cellsAdded
  52527. *
  52528. * Adds the specified cells to the given parent. This method fires
  52529. * <mxEvent.CELLS_ADDED> while the transaction is in progress.
  52530. */
  52531. mxGraph.prototype.cellsAdded = function(cells, parent, index, source, target, absolute, constrain, extend)
  52532. {
  52533. if (cells != null && parent != null && index != null)
  52534. {
  52535. this.model.beginUpdate();
  52536. try
  52537. {
  52538. var parentState = (absolute) ? this.view.getState(parent) : null;
  52539. var o1 = (parentState != null) ? parentState.origin : null;
  52540. var zero = new mxPoint(0, 0);
  52541. for (var i = 0; i < cells.length; i++)
  52542. {
  52543. if (cells[i] == null)
  52544. {
  52545. index--;
  52546. }
  52547. else
  52548. {
  52549. var previous = this.model.getParent(cells[i]);
  52550. // Keeps the cell at its absolute location
  52551. if (o1 != null && cells[i] != parent && parent != previous)
  52552. {
  52553. var oldState = this.view.getState(previous);
  52554. var o2 = (oldState != null) ? oldState.origin : zero;
  52555. var geo = this.model.getGeometry(cells[i]);
  52556. if (geo != null)
  52557. {
  52558. var dx = o2.x - o1.x;
  52559. var dy = o2.y - o1.y;
  52560. // FIXME: Cells should always be inserted first before any other edit
  52561. // to avoid forward references in sessions.
  52562. geo = geo.clone();
  52563. geo.translate(dx, dy);
  52564. if (!geo.relative && this.model.isVertex(cells[i]) &&
  52565. !this.isAllowNegativeCoordinates())
  52566. {
  52567. geo.x = Math.max(0, geo.x);
  52568. geo.y = Math.max(0, geo.y);
  52569. }
  52570. this.model.setGeometry(cells[i], geo);
  52571. }
  52572. }
  52573. // Decrements all following indices
  52574. // if cell is already in parent
  52575. if (parent == previous && index + i > this.model.getChildCount(parent))
  52576. {
  52577. index--;
  52578. }
  52579. this.model.add(parent, cells[i], index + i);
  52580. if (this.autoSizeCellsOnAdd)
  52581. {
  52582. this.autoSizeCell(cells[i], true);
  52583. }
  52584. // Extends the parent or constrains the child
  52585. if ((extend == null || extend) &&
  52586. this.isExtendParentsOnAdd(cells[i]) && this.isExtendParent(cells[i]))
  52587. {
  52588. this.extendParent(cells[i]);
  52589. }
  52590. // Additionally constrains the child after extending the parent
  52591. if (constrain == null || constrain)
  52592. {
  52593. this.constrainChild(cells[i]);
  52594. }
  52595. // Sets the source terminal
  52596. if (source != null)
  52597. {
  52598. this.cellConnected(cells[i], source, true);
  52599. }
  52600. // Sets the target terminal
  52601. if (target != null)
  52602. {
  52603. this.cellConnected(cells[i], target, false);
  52604. }
  52605. }
  52606. }
  52607. this.fireEvent(new mxEventObject(mxEvent.CELLS_ADDED, 'cells', cells,
  52608. 'parent', parent, 'index', index, 'source', source, 'target', target,
  52609. 'absolute', absolute));
  52610. }
  52611. finally
  52612. {
  52613. this.model.endUpdate();
  52614. }
  52615. }
  52616. };
  52617. /**
  52618. * Function: autoSizeCell
  52619. *
  52620. * Resizes the specified cell to just fit around the its label and/or children
  52621. *
  52622. * Parameters:
  52623. *
  52624. * cell - <mxCells> to be resized.
  52625. * recurse - Optional boolean which specifies if all descendants should be
  52626. * autosized. Default is true.
  52627. */
  52628. mxGraph.prototype.autoSizeCell = function(cell, recurse)
  52629. {
  52630. recurse = (recurse != null) ? recurse : true;
  52631. if (recurse)
  52632. {
  52633. var childCount = this.model.getChildCount(cell);
  52634. for (var i = 0; i < childCount; i++)
  52635. {
  52636. this.autoSizeCell(this.model.getChildAt(cell, i));
  52637. }
  52638. }
  52639. if (this.getModel().isVertex(cell) && this.isAutoSizeCell(cell))
  52640. {
  52641. this.updateCellSize(cell);
  52642. }
  52643. };
  52644. /**
  52645. * Function: removeCells
  52646. *
  52647. * Removes the given cells from the graph including all connected edges if
  52648. * includeEdges is true. The change is carried out using <cellsRemoved>.
  52649. * This method fires <mxEvent.REMOVE_CELLS> while the transaction is in
  52650. * progress. The removed cells are returned as an array.
  52651. *
  52652. * Parameters:
  52653. *
  52654. * cells - Array of <mxCells> to remove. If null is specified then the
  52655. * selection cells which are deletable are used.
  52656. * includeEdges - Optional boolean which specifies if all connected edges
  52657. * should be removed as well. Default is true.
  52658. */
  52659. mxGraph.prototype.removeCells = function(cells, includeEdges)
  52660. {
  52661. includeEdges = (includeEdges != null) ? includeEdges : true;
  52662. if (cells == null)
  52663. {
  52664. cells = this.getDeletableCells(this.getSelectionCells());
  52665. }
  52666. // Adds all edges to the cells
  52667. if (includeEdges)
  52668. {
  52669. // FIXME: Remove duplicate cells in result or do not add if
  52670. // in cells or descendant of cells
  52671. cells = this.getDeletableCells(this.addAllEdges(cells));
  52672. }
  52673. else
  52674. {
  52675. cells = cells.slice();
  52676. // Removes edges that are currently not
  52677. // visible as those cannot be updated
  52678. var edges = this.getDeletableCells(this.getAllEdges(cells));
  52679. var dict = new mxDictionary();
  52680. for (var i = 0; i < cells.length; i++)
  52681. {
  52682. dict.put(cells[i], true);
  52683. }
  52684. for (var i = 0; i < edges.length; i++)
  52685. {
  52686. if (this.view.getState(edges[i]) == null &&
  52687. !dict.get(edges[i]))
  52688. {
  52689. dict.put(edges[i], true);
  52690. cells.push(edges[i]);
  52691. }
  52692. }
  52693. }
  52694. this.model.beginUpdate();
  52695. try
  52696. {
  52697. this.cellsRemoved(cells);
  52698. this.fireEvent(new mxEventObject(mxEvent.REMOVE_CELLS,
  52699. 'cells', cells, 'includeEdges', includeEdges));
  52700. }
  52701. finally
  52702. {
  52703. this.model.endUpdate();
  52704. }
  52705. return cells;
  52706. };
  52707. /**
  52708. * Function: cellsRemoved
  52709. *
  52710. * Removes the given cells from the model. This method fires
  52711. * <mxEvent.CELLS_REMOVED> while the transaction is in progress.
  52712. *
  52713. * Parameters:
  52714. *
  52715. * cells - Array of <mxCells> to remove.
  52716. */
  52717. mxGraph.prototype.cellsRemoved = function(cells)
  52718. {
  52719. if (cells != null && cells.length > 0)
  52720. {
  52721. var scale = this.view.scale;
  52722. var tr = this.view.translate;
  52723. this.model.beginUpdate();
  52724. try
  52725. {
  52726. // Creates hashtable for faster lookup
  52727. var dict = new mxDictionary();
  52728. for (var i = 0; i < cells.length; i++)
  52729. {
  52730. dict.put(cells[i], true);
  52731. }
  52732. for (var i = 0; i < cells.length; i++)
  52733. {
  52734. // Disconnects edges which are not being removed
  52735. var edges = this.getAllEdges([cells[i]]);
  52736. var disconnectTerminal = mxUtils.bind(this, function(edge, source)
  52737. {
  52738. var geo = this.model.getGeometry(edge);
  52739. if (geo != null)
  52740. {
  52741. // Checks if terminal is being removed
  52742. var terminal = this.model.getTerminal(edge, source);
  52743. var connected = false;
  52744. var tmp = terminal;
  52745. while (tmp != null)
  52746. {
  52747. if (cells[i] == tmp)
  52748. {
  52749. connected = true;
  52750. break;
  52751. }
  52752. tmp = this.model.getParent(tmp);
  52753. }
  52754. if (connected)
  52755. {
  52756. geo = geo.clone();
  52757. var state = this.view.getState(edge);
  52758. if (state != null && state.absolutePoints != null)
  52759. {
  52760. var pts = state.absolutePoints;
  52761. var n = (source) ? 0 : pts.length - 1;
  52762. geo.setTerminalPoint(new mxPoint(
  52763. pts[n].x / scale - tr.x - state.origin.x,
  52764. pts[n].y / scale - tr.y - state.origin.y), source);
  52765. }
  52766. else
  52767. {
  52768. // Fallback to center of terminal if routing
  52769. // points are not available to add new point
  52770. // KNOWN: Should recurse to find parent offset
  52771. // of edge for nested groups but invisible edges
  52772. // should be removed in removeCells step
  52773. var tstate = this.view.getState(terminal);
  52774. if (tstate != null)
  52775. {
  52776. geo.setTerminalPoint(new mxPoint(
  52777. tstate.getCenterX() / scale - tr.x,
  52778. tstate.getCenterY() / scale - tr.y), source);
  52779. }
  52780. }
  52781. this.model.setGeometry(edge, geo);
  52782. this.model.setTerminal(edge, null, source);
  52783. }
  52784. }
  52785. });
  52786. for (var j = 0; j < edges.length; j++)
  52787. {
  52788. if (!dict.get(edges[j]))
  52789. {
  52790. dict.put(edges[j], true);
  52791. disconnectTerminal(edges[j], true);
  52792. disconnectTerminal(edges[j], false);
  52793. }
  52794. }
  52795. this.model.remove(cells[i]);
  52796. }
  52797. this.fireEvent(new mxEventObject(mxEvent.CELLS_REMOVED, 'cells', cells));
  52798. }
  52799. finally
  52800. {
  52801. this.model.endUpdate();
  52802. }
  52803. }
  52804. };
  52805. /**
  52806. * Function: splitEdge
  52807. *
  52808. * Splits the given edge by adding the newEdge between the previous source
  52809. * and the given cell and reconnecting the source of the given edge to the
  52810. * given cell. This method fires <mxEvent.SPLIT_EDGE> while the transaction
  52811. * is in progress. Returns the new edge that was inserted.
  52812. *
  52813. * Parameters:
  52814. *
  52815. * edge - <mxCell> that represents the edge to be splitted.
  52816. * cells - <mxCells> that represents the cells to insert into the edge.
  52817. * newEdge - <mxCell> that represents the edge to be inserted.
  52818. * dx - Optional integer that specifies the vector to move the cells.
  52819. * dy - Optional integer that specifies the vector to move the cells.
  52820. * x - Integer that specifies the x-coordinate of the drop location.
  52821. * y - Integer that specifies the y-coordinate of the drop location.
  52822. * parent - Optional parent to insert the cell. If null the parent of
  52823. * the edge is used.
  52824. */
  52825. mxGraph.prototype.splitEdge = function(edge, cells, newEdge, dx, dy, x, y, parent)
  52826. {
  52827. dx = dx || 0;
  52828. dy = dy || 0;
  52829. parent = (parent != null) ? parent : this.model.getParent(edge);
  52830. var source = this.model.getTerminal(edge, true);
  52831. this.model.beginUpdate();
  52832. try
  52833. {
  52834. if (newEdge == null)
  52835. {
  52836. newEdge = this.cloneCell(edge);
  52837. // Removes waypoints before/after new cell
  52838. var state = this.view.getState(edge);
  52839. var geo = this.getCellGeometry(newEdge);
  52840. if (geo != null && geo.points != null && state != null)
  52841. {
  52842. var t = this.view.translate;
  52843. var s = this.view.scale;
  52844. var idx = mxUtils.findNearestSegment(state, (dx + t.x) * s, (dy + t.y) * s);
  52845. geo.points = geo.points.slice(0, idx);
  52846. geo = this.getCellGeometry(edge);
  52847. if (geo != null && geo.points != null)
  52848. {
  52849. geo = geo.clone();
  52850. geo.points = geo.points.slice(idx);
  52851. this.model.setGeometry(edge, geo);
  52852. }
  52853. }
  52854. }
  52855. this.cellsMoved(cells, dx, dy, false, false);
  52856. this.cellsAdded(cells, parent, this.model.getChildCount(parent), null, null,
  52857. true);
  52858. this.cellsAdded([newEdge], parent, this.model.getChildCount(parent),
  52859. source, cells[0], false);
  52860. this.cellConnected(edge, cells[0], true);
  52861. this.fireEvent(new mxEventObject(mxEvent.SPLIT_EDGE, 'edge', edge,
  52862. 'cells', cells, 'newEdge', newEdge, 'dx', dx, 'dy', dy));
  52863. }
  52864. finally
  52865. {
  52866. this.model.endUpdate();
  52867. }
  52868. return newEdge;
  52869. };
  52870. /**
  52871. * Group: Cell visibility
  52872. */
  52873. /**
  52874. * Function: toggleCells
  52875. *
  52876. * Sets the visible state of the specified cells and all connected edges
  52877. * if includeEdges is true. The change is carried out using <cellsToggled>.
  52878. * This method fires <mxEvent.TOGGLE_CELLS> while the transaction is in
  52879. * progress. Returns the cells whose visible state was changed.
  52880. *
  52881. * Parameters:
  52882. *
  52883. * show - Boolean that specifies the visible state to be assigned.
  52884. * cells - Array of <mxCells> whose visible state should be changed. If
  52885. * null is specified then the selection cells are used.
  52886. * includeEdges - Optional boolean indicating if the visible state of all
  52887. * connected edges should be changed as well. Default is true.
  52888. */
  52889. mxGraph.prototype.toggleCells = function(show, cells, includeEdges)
  52890. {
  52891. if (cells == null)
  52892. {
  52893. cells = this.getSelectionCells();
  52894. }
  52895. // Adds all connected edges recursively
  52896. if (includeEdges)
  52897. {
  52898. cells = this.addAllEdges(cells);
  52899. }
  52900. this.model.beginUpdate();
  52901. try
  52902. {
  52903. this.cellsToggled(cells, show);
  52904. this.fireEvent(new mxEventObject(mxEvent.TOGGLE_CELLS,
  52905. 'show', show, 'cells', cells, 'includeEdges', includeEdges));
  52906. }
  52907. finally
  52908. {
  52909. this.model.endUpdate();
  52910. }
  52911. return cells;
  52912. };
  52913. /**
  52914. * Function: cellsToggled
  52915. *
  52916. * Sets the visible state of the specified cells.
  52917. *
  52918. * Parameters:
  52919. *
  52920. * cells - Array of <mxCells> whose visible state should be changed.
  52921. * show - Boolean that specifies the visible state to be assigned.
  52922. */
  52923. mxGraph.prototype.cellsToggled = function(cells, show)
  52924. {
  52925. if (cells != null && cells.length > 0)
  52926. {
  52927. this.model.beginUpdate();
  52928. try
  52929. {
  52930. for (var i = 0; i < cells.length; i++)
  52931. {
  52932. this.model.setVisible(cells[i], show);
  52933. }
  52934. }
  52935. finally
  52936. {
  52937. this.model.endUpdate();
  52938. }
  52939. }
  52940. };
  52941. /**
  52942. * Group: Folding
  52943. */
  52944. /**
  52945. * Function: foldCells
  52946. *
  52947. * Sets the collapsed state of the specified cells and all descendants
  52948. * if recurse is true. The change is carried out using <cellsFolded>.
  52949. * This method fires <mxEvent.FOLD_CELLS> while the transaction is in
  52950. * progress. Returns the cells whose collapsed state was changed.
  52951. *
  52952. * Parameters:
  52953. *
  52954. * collapsed - Boolean indicating the collapsed state to be assigned.
  52955. * recurse - Optional boolean indicating if the collapsed state of all
  52956. * descendants should be set. Default is false.
  52957. * cells - Array of <mxCells> whose collapsed state should be set. If
  52958. * null is specified then the foldable selection cells are used.
  52959. * checkFoldable - Optional boolean indicating of isCellFoldable should be
  52960. * checked. Default is false.
  52961. * evt - Optional native event that triggered the invocation.
  52962. */
  52963. mxGraph.prototype.foldCells = function(collapse, recurse, cells, checkFoldable, evt)
  52964. {
  52965. recurse = (recurse != null) ? recurse : false;
  52966. if (cells == null)
  52967. {
  52968. cells = this.getFoldableCells(this.getSelectionCells(), collapse);
  52969. }
  52970. this.stopEditing(false);
  52971. this.model.beginUpdate();
  52972. try
  52973. {
  52974. this.cellsFolded(cells, collapse, recurse, checkFoldable);
  52975. this.fireEvent(new mxEventObject(mxEvent.FOLD_CELLS,
  52976. 'collapse', collapse, 'recurse', recurse, 'cells', cells));
  52977. }
  52978. finally
  52979. {
  52980. this.model.endUpdate();
  52981. }
  52982. return cells;
  52983. };
  52984. /**
  52985. * Function: cellsFolded
  52986. *
  52987. * Sets the collapsed state of the specified cells. This method fires
  52988. * <mxEvent.CELLS_FOLDED> while the transaction is in progress. Returns the
  52989. * cells whose collapsed state was changed.
  52990. *
  52991. * Parameters:
  52992. *
  52993. * cells - Array of <mxCells> whose collapsed state should be set.
  52994. * collapsed - Boolean indicating the collapsed state to be assigned.
  52995. * recurse - Boolean indicating if the collapsed state of all descendants
  52996. * should be set.
  52997. * checkFoldable - Optional boolean indicating of isCellFoldable should be
  52998. * checked. Default is false.
  52999. */
  53000. mxGraph.prototype.cellsFolded = function(cells, collapse, recurse, checkFoldable)
  53001. {
  53002. if (cells != null && cells.length > 0)
  53003. {
  53004. this.model.beginUpdate();
  53005. try
  53006. {
  53007. for (var i = 0; i < cells.length; i++)
  53008. {
  53009. if ((!checkFoldable || this.isCellFoldable(cells[i], collapse)) &&
  53010. collapse != this.isCellCollapsed(cells[i]))
  53011. {
  53012. this.model.setCollapsed(cells[i], collapse);
  53013. this.swapBounds(cells[i], collapse);
  53014. if (this.isExtendParent(cells[i]))
  53015. {
  53016. this.extendParent(cells[i]);
  53017. }
  53018. if (recurse)
  53019. {
  53020. var children = this.model.getChildren(cells[i]);
  53021. this.cellsFolded(children, collapse, recurse);
  53022. }
  53023. this.constrainChild(cells[i]);
  53024. }
  53025. }
  53026. this.fireEvent(new mxEventObject(mxEvent.CELLS_FOLDED,
  53027. 'cells', cells, 'collapse', collapse, 'recurse', recurse));
  53028. }
  53029. finally
  53030. {
  53031. this.model.endUpdate();
  53032. }
  53033. }
  53034. };
  53035. /**
  53036. * Function: swapBounds
  53037. *
  53038. * Swaps the alternate and the actual bounds in the geometry of the given
  53039. * cell invoking <updateAlternateBounds> before carrying out the swap.
  53040. *
  53041. * Parameters:
  53042. *
  53043. * cell - <mxCell> for which the bounds should be swapped.
  53044. * willCollapse - Boolean indicating if the cell is going to be collapsed.
  53045. */
  53046. mxGraph.prototype.swapBounds = function(cell, willCollapse)
  53047. {
  53048. if (cell != null)
  53049. {
  53050. var geo = this.model.getGeometry(cell);
  53051. if (geo != null)
  53052. {
  53053. geo = geo.clone();
  53054. this.updateAlternateBounds(cell, geo, willCollapse);
  53055. geo.swap();
  53056. this.model.setGeometry(cell, geo);
  53057. }
  53058. }
  53059. };
  53060. /**
  53061. * Function: updateAlternateBounds
  53062. *
  53063. * Updates or sets the alternate bounds in the given geometry for the given
  53064. * cell depending on whether the cell is going to be collapsed. If no
  53065. * alternate bounds are defined in the geometry and
  53066. * <collapseToPreferredSize> is true, then the preferred size is used for
  53067. * the alternate bounds. The top, left corner is always kept at the same
  53068. * location.
  53069. *
  53070. * Parameters:
  53071. *
  53072. * cell - <mxCell> for which the geometry is being udpated.
  53073. * g - <mxGeometry> for which the alternate bounds should be updated.
  53074. * willCollapse - Boolean indicating if the cell is going to be collapsed.
  53075. */
  53076. mxGraph.prototype.updateAlternateBounds = function(cell, geo, willCollapse)
  53077. {
  53078. if (cell != null && geo != null)
  53079. {
  53080. var style = this.getCurrentCellStyle(cell);
  53081. if (geo.alternateBounds == null)
  53082. {
  53083. var bounds = geo;
  53084. if (this.collapseToPreferredSize)
  53085. {
  53086. var tmp = this.getPreferredSizeForCell(cell);
  53087. if (tmp != null)
  53088. {
  53089. bounds = tmp;
  53090. var startSize = mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE);
  53091. if (startSize > 0)
  53092. {
  53093. bounds.height = Math.max(bounds.height, startSize);
  53094. }
  53095. }
  53096. }
  53097. geo.alternateBounds = new mxRectangle(0, 0, bounds.width, bounds.height);
  53098. }
  53099. if (geo.alternateBounds != null)
  53100. {
  53101. geo.alternateBounds.x = geo.x;
  53102. geo.alternateBounds.y = geo.y;
  53103. var alpha = mxUtils.toRadians(style[mxConstants.STYLE_ROTATION] || 0);
  53104. if (alpha != 0)
  53105. {
  53106. var dx = geo.alternateBounds.getCenterX() - geo.getCenterX();
  53107. var dy = geo.alternateBounds.getCenterY() - geo.getCenterY();
  53108. var cos = Math.cos(alpha);
  53109. var sin = Math.sin(alpha);
  53110. var dx2 = cos * dx - sin * dy;
  53111. var dy2 = sin * dx + cos * dy;
  53112. geo.alternateBounds.x += dx2 - dx;
  53113. geo.alternateBounds.y += dy2 - dy;
  53114. }
  53115. }
  53116. }
  53117. };
  53118. /**
  53119. * Function: addAllEdges
  53120. *
  53121. * Returns an array with the given cells and all edges that are connected
  53122. * to a cell or one of its descendants.
  53123. */
  53124. mxGraph.prototype.addAllEdges = function(cells)
  53125. {
  53126. var allCells = cells.slice();
  53127. return mxUtils.removeDuplicates(allCells.concat(this.getAllEdges(cells)));
  53128. };
  53129. /**
  53130. * Function: getAllEdges
  53131. *
  53132. * Returns all edges connected to the given cells or its descendants.
  53133. */
  53134. mxGraph.prototype.getAllEdges = function(cells)
  53135. {
  53136. var edges = [];
  53137. if (cells != null)
  53138. {
  53139. for (var i = 0; i < cells.length; i++)
  53140. {
  53141. var edgeCount = this.model.getEdgeCount(cells[i]);
  53142. for (var j = 0; j < edgeCount; j++)
  53143. {
  53144. edges.push(this.model.getEdgeAt(cells[i], j));
  53145. }
  53146. // Recurses
  53147. var children = this.model.getChildren(cells[i]);
  53148. edges = edges.concat(this.getAllEdges(children));
  53149. }
  53150. }
  53151. return edges;
  53152. };
  53153. /**
  53154. * Group: Cell sizing
  53155. */
  53156. /**
  53157. * Function: updateCellSize
  53158. *
  53159. * Updates the size of the given cell in the model using <cellSizeUpdated>.
  53160. * This method fires <mxEvent.UPDATE_CELL_SIZE> while the transaction is in
  53161. * progress. Returns the cell whose size was updated.
  53162. *
  53163. * Parameters:
  53164. *
  53165. * cell - <mxCell> whose size should be updated.
  53166. */
  53167. mxGraph.prototype.updateCellSize = function(cell, ignoreChildren)
  53168. {
  53169. ignoreChildren = (ignoreChildren != null) ? ignoreChildren : false;
  53170. this.model.beginUpdate();
  53171. try
  53172. {
  53173. this.cellSizeUpdated(cell, ignoreChildren);
  53174. this.fireEvent(new mxEventObject(mxEvent.UPDATE_CELL_SIZE,
  53175. 'cell', cell, 'ignoreChildren', ignoreChildren));
  53176. }
  53177. finally
  53178. {
  53179. this.model.endUpdate();
  53180. }
  53181. return cell;
  53182. };
  53183. /**
  53184. * Function: cellSizeUpdated
  53185. *
  53186. * Updates the size of the given cell in the model using
  53187. * <getPreferredSizeForCell> to get the new size.
  53188. *
  53189. * Parameters:
  53190. *
  53191. * cell - <mxCell> for which the size should be changed.
  53192. */
  53193. mxGraph.prototype.cellSizeUpdated = function(cell, ignoreChildren)
  53194. {
  53195. if (cell != null)
  53196. {
  53197. this.model.beginUpdate();
  53198. try
  53199. {
  53200. var size = this.getPreferredSizeForCell(cell);
  53201. var geo = this.model.getGeometry(cell);
  53202. if (size != null && geo != null)
  53203. {
  53204. var collapsed = this.isCellCollapsed(cell);
  53205. geo = geo.clone();
  53206. if (this.isSwimlane(cell))
  53207. {
  53208. var style = this.getCellStyle(cell);
  53209. var cellStyle = this.model.getStyle(cell);
  53210. if (cellStyle == null)
  53211. {
  53212. cellStyle = '';
  53213. }
  53214. if (mxUtils.getValue(style, mxConstants.STYLE_HORIZONTAL, true))
  53215. {
  53216. cellStyle = mxUtils.setStyle(cellStyle,
  53217. mxConstants.STYLE_STARTSIZE, size.height + 8);
  53218. if (collapsed)
  53219. {
  53220. geo.height = size.height + 8;
  53221. }
  53222. geo.width = size.width;
  53223. }
  53224. else
  53225. {
  53226. cellStyle = mxUtils.setStyle(cellStyle,
  53227. mxConstants.STYLE_STARTSIZE, size.width + 8);
  53228. if (collapsed)
  53229. {
  53230. geo.width = size.width + 8;
  53231. }
  53232. geo.height = size.height;
  53233. }
  53234. this.model.setStyle(cell, cellStyle);
  53235. }
  53236. else
  53237. {
  53238. var state = this.view.createState(cell);
  53239. var align = (state.style[mxConstants.STYLE_ALIGN] || mxConstants.ALIGN_CENTER);
  53240. if (align == mxConstants.ALIGN_RIGHT)
  53241. {
  53242. geo.x += geo.width - size.width;
  53243. }
  53244. else if (align == mxConstants.ALIGN_CENTER)
  53245. {
  53246. geo.x += Math.round((geo.width - size.width) / 2);
  53247. }
  53248. var valign = this.getVerticalAlign(state);
  53249. if (valign == mxConstants.ALIGN_BOTTOM)
  53250. {
  53251. geo.y += geo.height - size.height;
  53252. }
  53253. else if (valign == mxConstants.ALIGN_MIDDLE)
  53254. {
  53255. geo.y += Math.round((geo.height - size.height) / 2);
  53256. }
  53257. geo.width = size.width;
  53258. geo.height = size.height;
  53259. }
  53260. if (!ignoreChildren && !collapsed)
  53261. {
  53262. var bounds = this.view.getBounds(this.model.getChildren(cell));
  53263. if (bounds != null)
  53264. {
  53265. var tr = this.view.translate;
  53266. var scale = this.view.scale;
  53267. var width = (bounds.x + bounds.width) / scale - geo.x - tr.x;
  53268. var height = (bounds.y + bounds.height) / scale - geo.y - tr.y;
  53269. geo.width = Math.max(geo.width, width);
  53270. geo.height = Math.max(geo.height, height);
  53271. }
  53272. }
  53273. this.cellsResized([cell], [geo], false);
  53274. }
  53275. }
  53276. finally
  53277. {
  53278. this.model.endUpdate();
  53279. }
  53280. }
  53281. };
  53282. /**
  53283. * Function: getPreferredSizeForCell
  53284. *
  53285. * Returns the preferred width and height of the given <mxCell> as an
  53286. * <mxRectangle>. To implement a minimum width, add a new style eg.
  53287. * minWidth in the vertex and override this method as follows.
  53288. *
  53289. * (code)
  53290. * var graphGetPreferredSizeForCell = graph.getPreferredSizeForCell;
  53291. * graph.getPreferredSizeForCell = function(cell)
  53292. * {
  53293. * var result = graphGetPreferredSizeForCell.apply(this, arguments);
  53294. * var style = this.getCellStyle(cell);
  53295. *
  53296. * if (style['minWidth'] > 0)
  53297. * {
  53298. * result.width = Math.max(style['minWidth'], result.width);
  53299. * }
  53300. *
  53301. * return result;
  53302. * };
  53303. * (end)
  53304. *
  53305. * Parameters:
  53306. *
  53307. * cell - <mxCell> for which the preferred size should be returned.
  53308. * textWidth - Optional maximum text width for word wrapping.
  53309. */
  53310. mxGraph.prototype.getPreferredSizeForCell = function(cell, textWidth)
  53311. {
  53312. var result = null;
  53313. if (cell != null)
  53314. {
  53315. var state = this.view.createState(cell);
  53316. var style = state.style;
  53317. if (!this.model.isEdge(cell))
  53318. {
  53319. var fontSize = style[mxConstants.STYLE_FONTSIZE] || mxConstants.DEFAULT_FONTSIZE;
  53320. var dx = 0;
  53321. var dy = 0;
  53322. // Adds dimension of image if shape is a label
  53323. if (this.getImage(state) != null || style[mxConstants.STYLE_IMAGE] != null)
  53324. {
  53325. if (style[mxConstants.STYLE_SHAPE] == mxConstants.SHAPE_LABEL)
  53326. {
  53327. if (style[mxConstants.STYLE_VERTICAL_ALIGN] == mxConstants.ALIGN_MIDDLE)
  53328. {
  53329. dx += parseFloat(style[mxConstants.STYLE_IMAGE_WIDTH]) || mxLabel.prototype.imageSize;
  53330. }
  53331. if (style[mxConstants.STYLE_ALIGN] != mxConstants.ALIGN_CENTER)
  53332. {
  53333. dy += parseFloat(style[mxConstants.STYLE_IMAGE_HEIGHT]) || mxLabel.prototype.imageSize;
  53334. }
  53335. }
  53336. }
  53337. // Adds spacings
  53338. dx += 2 * (style[mxConstants.STYLE_SPACING] || 0);
  53339. dx += style[mxConstants.STYLE_SPACING_LEFT] || 0;
  53340. dx += style[mxConstants.STYLE_SPACING_RIGHT] || 0;
  53341. dy += 2 * (style[mxConstants.STYLE_SPACING] || 0);
  53342. dy += style[mxConstants.STYLE_SPACING_TOP] || 0;
  53343. dy += style[mxConstants.STYLE_SPACING_BOTTOM] || 0;
  53344. // Add spacing for collapse/expand icon
  53345. // LATER: Check alignment and use constants
  53346. // for image spacing
  53347. var image = this.getFoldingImage(state);
  53348. if (image != null)
  53349. {
  53350. dx += image.width + 8;
  53351. }
  53352. // Adds space for label
  53353. var value = this.cellRenderer.getLabelValue(state);
  53354. if (value != null && value.length > 0)
  53355. {
  53356. if (!this.isHtmlLabel(state.cell))
  53357. {
  53358. value = mxUtils.htmlEntities(value, false);
  53359. }
  53360. value = value.replace(/\n/g, '<br>');
  53361. var size = mxUtils.getSizeForString(value, fontSize,
  53362. style[mxConstants.STYLE_FONTFAMILY], textWidth,
  53363. style[mxConstants.STYLE_FONTSTYLE]);
  53364. var width = size.width + dx;
  53365. var height = size.height + dy;
  53366. if (!mxUtils.getValue(style, mxConstants.STYLE_HORIZONTAL, true))
  53367. {
  53368. var tmp = height;
  53369. height = width;
  53370. width = tmp;
  53371. }
  53372. if (this.gridEnabled)
  53373. {
  53374. width = this.snap(width + this.gridSize / 2);
  53375. height = this.snap(height + this.gridSize / 2);
  53376. }
  53377. result = new mxRectangle(0, 0, width, height);
  53378. }
  53379. else
  53380. {
  53381. var gs2 = 4 * this.gridSize;
  53382. result = new mxRectangle(0, 0, gs2, gs2);
  53383. }
  53384. }
  53385. }
  53386. return result;
  53387. };
  53388. /**
  53389. * Function: resizeCell
  53390. *
  53391. * Sets the bounds of the given cell using <resizeCells>. Returns the
  53392. * cell which was passed to the function.
  53393. *
  53394. * Parameters:
  53395. *
  53396. * cell - <mxCell> whose bounds should be changed.
  53397. * bounds - <mxRectangle> that represents the new bounds.
  53398. */
  53399. mxGraph.prototype.resizeCell = function(cell, bounds, recurse)
  53400. {
  53401. return this.resizeCells([cell], [bounds], recurse)[0];
  53402. };
  53403. /**
  53404. * Function: resizeCells
  53405. *
  53406. * Sets the bounds of the given cells and fires a <mxEvent.RESIZE_CELLS>
  53407. * event while the transaction is in progress. Returns the cells which
  53408. * have been passed to the function.
  53409. *
  53410. * Parameters:
  53411. *
  53412. * cells - Array of <mxCells> whose bounds should be changed.
  53413. * bounds - Array of <mxRectangles> that represent the new bounds.
  53414. */
  53415. mxGraph.prototype.resizeCells = function(cells, bounds, recurse)
  53416. {
  53417. recurse = (recurse != null) ? recurse : this.isRecursiveResize();
  53418. this.model.beginUpdate();
  53419. try
  53420. {
  53421. var prev = this.cellsResized(cells, bounds, recurse);
  53422. this.fireEvent(new mxEventObject(mxEvent.RESIZE_CELLS,
  53423. 'cells', cells, 'bounds', bounds, 'previous', prev));
  53424. }
  53425. finally
  53426. {
  53427. this.model.endUpdate();
  53428. }
  53429. return cells;
  53430. };
  53431. /**
  53432. * Function: cellsResized
  53433. *
  53434. * Sets the bounds of the given cells and fires a <mxEvent.CELLS_RESIZED>
  53435. * event. If <extendParents> is true, then the parent is extended if a
  53436. * child size is changed so that it overlaps with the parent.
  53437. *
  53438. * The following example shows how to control group resizes to make sure
  53439. * that all child cells stay within the group.
  53440. *
  53441. * (code)
  53442. * graph.addListener(mxEvent.CELLS_RESIZED, function(sender, evt)
  53443. * {
  53444. * var cells = evt.getProperty('cells');
  53445. *
  53446. * if (cells != null)
  53447. * {
  53448. * for (var i = 0; i < cells.length; i++)
  53449. * {
  53450. * if (graph.getModel().getChildCount(cells[i]) > 0)
  53451. * {
  53452. * var geo = graph.getCellGeometry(cells[i]);
  53453. *
  53454. * if (geo != null)
  53455. * {
  53456. * var children = graph.getChildCells(cells[i], true, true);
  53457. * var bounds = graph.getBoundingBoxFromGeometry(children, true);
  53458. *
  53459. * geo = geo.clone();
  53460. * geo.width = Math.max(geo.width, bounds.width);
  53461. * geo.height = Math.max(geo.height, bounds.height);
  53462. *
  53463. * graph.getModel().setGeometry(cells[i], geo);
  53464. * }
  53465. * }
  53466. * }
  53467. * }
  53468. * });
  53469. * (end)
  53470. *
  53471. * Parameters:
  53472. *
  53473. * cells - Array of <mxCells> whose bounds should be changed.
  53474. * bounds - Array of <mxRectangles> that represent the new bounds.
  53475. * recurse - Optional boolean that specifies if the children should be resized.
  53476. */
  53477. mxGraph.prototype.cellsResized = function(cells, bounds, recurse)
  53478. {
  53479. recurse = (recurse != null) ? recurse : false;
  53480. var prev = [];
  53481. if (cells != null && bounds != null && cells.length == bounds.length)
  53482. {
  53483. this.model.beginUpdate();
  53484. try
  53485. {
  53486. for (var i = 0; i < cells.length; i++)
  53487. {
  53488. prev.push(this.cellResized(cells[i], bounds[i], false, recurse));
  53489. if (this.isExtendParent(cells[i]))
  53490. {
  53491. this.extendParent(cells[i]);
  53492. }
  53493. this.constrainChild(cells[i]);
  53494. }
  53495. if (this.resetEdgesOnResize)
  53496. {
  53497. this.resetEdges(cells);
  53498. }
  53499. this.fireEvent(new mxEventObject(mxEvent.CELLS_RESIZED,
  53500. 'cells', cells, 'bounds', bounds, 'previous', prev));
  53501. }
  53502. finally
  53503. {
  53504. this.model.endUpdate();
  53505. }
  53506. }
  53507. return prev;
  53508. };
  53509. /**
  53510. * Function: cellResized
  53511. *
  53512. * Resizes the parents recursively so that they contain the complete area
  53513. * of the resized child cell.
  53514. *
  53515. * Parameters:
  53516. *
  53517. * cell - <mxCell> whose bounds should be changed.
  53518. * bounds - <mxRectangles> that represent the new bounds.
  53519. * ignoreRelative - Boolean that indicates if relative cells should be ignored.
  53520. * recurse - Optional boolean that specifies if the children should be resized.
  53521. */
  53522. mxGraph.prototype.cellResized = function(cell, bounds, ignoreRelative, recurse)
  53523. {
  53524. var prev = this.model.getGeometry(cell);
  53525. if (prev != null && (prev.x != bounds.x || prev.y != bounds.y ||
  53526. prev.width != bounds.width || prev.height != bounds.height))
  53527. {
  53528. var geo = prev.clone();
  53529. if (!ignoreRelative && geo.relative)
  53530. {
  53531. var offset = geo.offset;
  53532. if (offset != null)
  53533. {
  53534. offset.x += bounds.x - geo.x;
  53535. offset.y += bounds.y - geo.y;
  53536. }
  53537. }
  53538. else
  53539. {
  53540. geo.x = bounds.x;
  53541. geo.y = bounds.y;
  53542. }
  53543. geo.width = bounds.width;
  53544. geo.height = bounds.height;
  53545. if (!geo.relative && this.model.isVertex(cell) && !this.isAllowNegativeCoordinates())
  53546. {
  53547. geo.x = Math.max(0, geo.x);
  53548. geo.y = Math.max(0, geo.y);
  53549. }
  53550. this.model.beginUpdate();
  53551. try
  53552. {
  53553. if (recurse)
  53554. {
  53555. this.resizeChildCells(cell, geo);
  53556. }
  53557. this.model.setGeometry(cell, geo);
  53558. this.constrainChildCells(cell);
  53559. }
  53560. finally
  53561. {
  53562. this.model.endUpdate();
  53563. }
  53564. }
  53565. return prev;
  53566. };
  53567. /**
  53568. * Function: resizeChildCells
  53569. *
  53570. * Resizes the child cells of the given cell for the given new geometry with
  53571. * respect to the current geometry of the cell.
  53572. *
  53573. * Parameters:
  53574. *
  53575. * cell - <mxCell> that has been resized.
  53576. * newGeo - <mxGeometry> that represents the new bounds.
  53577. */
  53578. mxGraph.prototype.resizeChildCells = function(cell, newGeo)
  53579. {
  53580. var geo = this.model.getGeometry(cell);
  53581. var dx = newGeo.width / geo.width;
  53582. var dy = newGeo.height / geo.height;
  53583. var childCount = this.model.getChildCount(cell);
  53584. for (var i = 0; i < childCount; i++)
  53585. {
  53586. this.scaleCell(this.model.getChildAt(cell, i), dx, dy, true);
  53587. }
  53588. };
  53589. /**
  53590. * Function: constrainChildCells
  53591. *
  53592. * Constrains the children of the given cell using <constrainChild>.
  53593. *
  53594. * Parameters:
  53595. *
  53596. * cell - <mxCell> that has been resized.
  53597. */
  53598. mxGraph.prototype.constrainChildCells = function(cell)
  53599. {
  53600. var childCount = this.model.getChildCount(cell);
  53601. for (var i = 0; i < childCount; i++)
  53602. {
  53603. this.constrainChild(this.model.getChildAt(cell, i));
  53604. }
  53605. };
  53606. /**
  53607. * Function: scaleCell
  53608. *
  53609. * Scales the points, position and size of the given cell according to the
  53610. * given vertical and horizontal scaling factors.
  53611. *
  53612. * Parameters:
  53613. *
  53614. * cell - <mxCell> whose geometry should be scaled.
  53615. * dx - Horizontal scaling factor.
  53616. * dy - Vertical scaling factor.
  53617. * recurse - Boolean indicating if the child cells should be scaled.
  53618. */
  53619. mxGraph.prototype.scaleCell = function(cell, dx, dy, recurse)
  53620. {
  53621. var geo = this.model.getGeometry(cell);
  53622. if (geo != null)
  53623. {
  53624. var style = this.getCurrentCellStyle(cell);
  53625. geo = geo.clone();
  53626. // Stores values for restoring based on style
  53627. var x = geo.x;
  53628. var y = geo.y
  53629. var w = geo.width;
  53630. var h = geo.height;
  53631. geo.scale(dx, dy, style[mxConstants.STYLE_ASPECT] == 'fixed');
  53632. if (style[mxConstants.STYLE_RESIZE_WIDTH] == '1')
  53633. {
  53634. geo.width = w * dx;
  53635. }
  53636. else if (style[mxConstants.STYLE_RESIZE_WIDTH] == '0')
  53637. {
  53638. geo.width = w;
  53639. }
  53640. if (style[mxConstants.STYLE_RESIZE_HEIGHT] == '1')
  53641. {
  53642. geo.height = h * dy;
  53643. }
  53644. else if (style[mxConstants.STYLE_RESIZE_HEIGHT] == '0')
  53645. {
  53646. geo.height = h;
  53647. }
  53648. if (!this.isCellMovable(cell))
  53649. {
  53650. geo.x = x;
  53651. geo.y = y;
  53652. }
  53653. if (!this.isCellResizable(cell))
  53654. {
  53655. geo.width = w;
  53656. geo.height = h;
  53657. }
  53658. if (this.model.isVertex(cell))
  53659. {
  53660. this.cellResized(cell, geo, true, recurse);
  53661. }
  53662. else
  53663. {
  53664. this.model.setGeometry(cell, geo);
  53665. }
  53666. }
  53667. };
  53668. /**
  53669. * Function: extendParent
  53670. *
  53671. * Resizes the parents recursively so that they contain the complete area
  53672. * of the resized child cell.
  53673. *
  53674. * Parameters:
  53675. *
  53676. * cell - <mxCell> that has been resized.
  53677. */
  53678. mxGraph.prototype.extendParent = function(cell)
  53679. {
  53680. if (cell != null)
  53681. {
  53682. var parent = this.model.getParent(cell);
  53683. var p = this.getCellGeometry(parent);
  53684. if (parent != null && p != null && !this.isCellCollapsed(parent))
  53685. {
  53686. var geo = this.getCellGeometry(cell);
  53687. if (geo != null && !geo.relative &&
  53688. (p.width < geo.x + geo.width ||
  53689. p.height < geo.y + geo.height))
  53690. {
  53691. p = p.clone();
  53692. p.width = Math.max(p.width, geo.x + geo.width);
  53693. p.height = Math.max(p.height, geo.y + geo.height);
  53694. this.cellsResized([parent], [p], false);
  53695. }
  53696. }
  53697. }
  53698. };
  53699. /**
  53700. * Group: Cell moving
  53701. */
  53702. /**
  53703. * Function: importCells
  53704. *
  53705. * Clones and inserts the given cells into the graph using the move
  53706. * method and returns the inserted cells. This shortcut is used if
  53707. * cells are inserted via datatransfer.
  53708. *
  53709. * Parameters:
  53710. *
  53711. * cells - Array of <mxCells> to be imported.
  53712. * dx - Integer that specifies the x-coordinate of the vector. Default is 0.
  53713. * dy - Integer that specifies the y-coordinate of the vector. Default is 0.
  53714. * target - <mxCell> that represents the new parent of the cells.
  53715. * evt - Mouseevent that triggered the invocation.
  53716. * mapping - Optional mapping for existing clones.
  53717. */
  53718. mxGraph.prototype.importCells = function(cells, dx, dy, target, evt, mapping)
  53719. {
  53720. return this.moveCells(cells, dx, dy, true, target, evt, mapping);
  53721. };
  53722. /**
  53723. * Function: moveCells
  53724. *
  53725. * Moves or clones the specified cells and moves the cells or clones by the
  53726. * given amount, adding them to the optional target cell. The evt is the
  53727. * mouse event as the mouse was released. The change is carried out using
  53728. * <cellsMoved>. This method fires <mxEvent.MOVE_CELLS> while the
  53729. * transaction is in progress. Returns the cells that were moved.
  53730. *
  53731. * Use the following code to move all cells in the graph.
  53732. *
  53733. * (code)
  53734. * graph.moveCells(graph.getChildCells(null, true, true), 10, 10);
  53735. * (end)
  53736. *
  53737. * Parameters:
  53738. *
  53739. * cells - Array of <mxCells> to be moved, cloned or added to the target.
  53740. * dx - Integer that specifies the x-coordinate of the vector. Default is 0.
  53741. * dy - Integer that specifies the y-coordinate of the vector. Default is 0.
  53742. * clone - Boolean indicating if the cells should be cloned. Default is false.
  53743. * target - <mxCell> that represents the new parent of the cells.
  53744. * evt - Mouseevent that triggered the invocation.
  53745. * mapping - Optional mapping for existing clones.
  53746. */
  53747. mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt, mapping)
  53748. {
  53749. dx = (dx != null) ? dx : 0;
  53750. dy = (dy != null) ? dy : 0;
  53751. clone = (clone != null) ? clone : false;
  53752. if (cells != null && (dx != 0 || dy != 0 || clone || target != null))
  53753. {
  53754. // Removes descendants with ancestors in cells to avoid multiple moving
  53755. cells = this.model.getTopmostCells(cells);
  53756. this.model.beginUpdate();
  53757. try
  53758. {
  53759. // Faster cell lookups to remove relative edge labels with selected
  53760. // terminals to avoid explicit and implicit move at same time
  53761. var dict = new mxDictionary();
  53762. for (var i = 0; i < cells.length; i++)
  53763. {
  53764. dict.put(cells[i], true);
  53765. }
  53766. var isSelected = mxUtils.bind(this, function(cell)
  53767. {
  53768. while (cell != null)
  53769. {
  53770. if (dict.get(cell))
  53771. {
  53772. return true;
  53773. }
  53774. cell = this.model.getParent(cell);
  53775. }
  53776. return false;
  53777. });
  53778. // Removes relative edge labels with selected terminals
  53779. var checked = [];
  53780. for (var i = 0; i < cells.length; i++)
  53781. {
  53782. var geo = this.getCellGeometry(cells[i]);
  53783. var parent = this.model.getParent(cells[i]);
  53784. if ((geo == null || !geo.relative) || !this.model.isEdge(parent) ||
  53785. (!isSelected(this.model.getTerminal(parent, true)) &&
  53786. !isSelected(this.model.getTerminal(parent, false))))
  53787. {
  53788. checked.push(cells[i]);
  53789. }
  53790. }
  53791. cells = checked;
  53792. if (clone)
  53793. {
  53794. cells = this.cloneCells(cells, this.isCloneInvalidEdges(), mapping);
  53795. if (target == null)
  53796. {
  53797. target = this.getDefaultParent();
  53798. }
  53799. }
  53800. // FIXME: Cells should always be inserted first before any other edit
  53801. // to avoid forward references in sessions.
  53802. // Need to disable allowNegativeCoordinates if target not null to
  53803. // allow for temporary negative numbers until cellsAdded is called.
  53804. var previous = this.isAllowNegativeCoordinates();
  53805. if (target != null)
  53806. {
  53807. this.setAllowNegativeCoordinates(true);
  53808. }
  53809. this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove()
  53810. && this.isAllowDanglingEdges(), target == null,
  53811. this.isExtendParentsOnMove() && target == null);
  53812. this.setAllowNegativeCoordinates(previous);
  53813. if (target != null)
  53814. {
  53815. var index = this.model.getChildCount(target);
  53816. this.cellsAdded(cells, target, index, null, null, true);
  53817. }
  53818. // Dispatches a move event
  53819. this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells,
  53820. 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt));
  53821. }
  53822. finally
  53823. {
  53824. this.model.endUpdate();
  53825. }
  53826. }
  53827. return cells;
  53828. };
  53829. /**
  53830. * Function: cellsMoved
  53831. *
  53832. * Moves the specified cells by the given vector, disconnecting the cells
  53833. * using disconnectGraph is disconnect is true. This method fires
  53834. * <mxEvent.CELLS_MOVED> while the transaction is in progress.
  53835. */
  53836. mxGraph.prototype.cellsMoved = function(cells, dx, dy, disconnect, constrain, extend)
  53837. {
  53838. if (cells != null && (dx != 0 || dy != 0))
  53839. {
  53840. extend = (extend != null) ? extend : false;
  53841. this.model.beginUpdate();
  53842. try
  53843. {
  53844. if (disconnect)
  53845. {
  53846. this.disconnectGraph(cells);
  53847. }
  53848. for (var i = 0; i < cells.length; i++)
  53849. {
  53850. this.translateCell(cells[i], dx, dy);
  53851. if (extend && this.isExtendParent(cells[i]))
  53852. {
  53853. this.extendParent(cells[i]);
  53854. }
  53855. else if (constrain)
  53856. {
  53857. this.constrainChild(cells[i]);
  53858. }
  53859. }
  53860. if (this.resetEdgesOnMove)
  53861. {
  53862. this.resetEdges(cells);
  53863. }
  53864. this.fireEvent(new mxEventObject(mxEvent.CELLS_MOVED,
  53865. 'cells', cells, 'dx', dx, 'dy', dy, 'disconnect', disconnect));
  53866. }
  53867. finally
  53868. {
  53869. this.model.endUpdate();
  53870. }
  53871. }
  53872. };
  53873. /**
  53874. * Function: translateCell
  53875. *
  53876. * Translates the geometry of the given cell and stores the new,
  53877. * translated geometry in the model as an atomic change.
  53878. */
  53879. mxGraph.prototype.translateCell = function(cell, dx, dy)
  53880. {
  53881. var geo = this.model.getGeometry(cell);
  53882. if (geo != null)
  53883. {
  53884. dx = parseFloat(dx);
  53885. dy = parseFloat(dy);
  53886. geo = geo.clone();
  53887. geo.translate(dx, dy);
  53888. if (!geo.relative && this.model.isVertex(cell) && !this.isAllowNegativeCoordinates())
  53889. {
  53890. geo.x = Math.max(0, parseFloat(geo.x));
  53891. geo.y = Math.max(0, parseFloat(geo.y));
  53892. }
  53893. if (geo.relative && !this.model.isEdge(cell))
  53894. {
  53895. var parent = this.model.getParent(cell);
  53896. var angle = 0;
  53897. if (this.model.isVertex(parent))
  53898. {
  53899. var style = this.getCurrentCellStyle(parent);
  53900. angle = mxUtils.getValue(style, mxConstants.STYLE_ROTATION, 0);
  53901. }
  53902. if (angle != 0)
  53903. {
  53904. var rad = mxUtils.toRadians(-angle);
  53905. var cos = Math.cos(rad);
  53906. var sin = Math.sin(rad);
  53907. var pt = mxUtils.getRotatedPoint(new mxPoint(dx, dy), cos, sin, new mxPoint(0, 0));
  53908. dx = pt.x;
  53909. dy = pt.y;
  53910. }
  53911. if (geo.offset == null)
  53912. {
  53913. geo.offset = new mxPoint(dx, dy);
  53914. }
  53915. else
  53916. {
  53917. geo.offset.x = parseFloat(geo.offset.x) + dx;
  53918. geo.offset.y = parseFloat(geo.offset.y) + dy;
  53919. }
  53920. }
  53921. this.model.setGeometry(cell, geo);
  53922. }
  53923. };
  53924. /**
  53925. * Function: getCellContainmentArea
  53926. *
  53927. * Returns the <mxRectangle> inside which a cell is to be kept.
  53928. *
  53929. * Parameters:
  53930. *
  53931. * cell - <mxCell> for which the area should be returned.
  53932. */
  53933. mxGraph.prototype.getCellContainmentArea = function(cell)
  53934. {
  53935. if (cell != null && !this.model.isEdge(cell))
  53936. {
  53937. var parent = this.model.getParent(cell);
  53938. if (parent != null && parent != this.getDefaultParent())
  53939. {
  53940. var g = this.model.getGeometry(parent);
  53941. if (g != null)
  53942. {
  53943. var x = 0;
  53944. var y = 0;
  53945. var w = g.width;
  53946. var h = g.height;
  53947. if (this.isSwimlane(parent))
  53948. {
  53949. var size = this.getStartSize(parent);
  53950. var style = this.getCurrentCellStyle(parent);
  53951. var dir = mxUtils.getValue(style, mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
  53952. var flipH = mxUtils.getValue(style, mxConstants.STYLE_FLIPH, 0) == 1;
  53953. var flipV = mxUtils.getValue(style, mxConstants.STYLE_FLIPV, 0) == 1;
  53954. if (dir == mxConstants.DIRECTION_SOUTH || dir == mxConstants.DIRECTION_NORTH)
  53955. {
  53956. var tmp = size.width;
  53957. size.width = size.height;
  53958. size.height = tmp;
  53959. }
  53960. if ((dir == mxConstants.DIRECTION_EAST && !flipV) || (dir == mxConstants.DIRECTION_NORTH && !flipH) ||
  53961. (dir == mxConstants.DIRECTION_WEST && flipV) || (dir == mxConstants.DIRECTION_SOUTH && flipH))
  53962. {
  53963. x = size.width;
  53964. y = size.height;
  53965. }
  53966. w -= size.width;
  53967. h -= size.height;
  53968. }
  53969. return new mxRectangle(x, y, w, h);
  53970. }
  53971. }
  53972. }
  53973. return null;
  53974. };
  53975. /**
  53976. * Function: getMaximumGraphBounds
  53977. *
  53978. * Returns the bounds inside which the diagram should be kept as an
  53979. * <mxRectangle>.
  53980. */
  53981. mxGraph.prototype.getMaximumGraphBounds = function()
  53982. {
  53983. return this.maximumGraphBounds;
  53984. };
  53985. /**
  53986. * Function: constrainChild
  53987. *
  53988. * Keeps the given cell inside the bounds returned by
  53989. * <getCellContainmentArea> for its parent, according to the rules defined by
  53990. * <getOverlap> and <isConstrainChild>. This modifies the cell's geometry
  53991. * in-place and does not clone it.
  53992. *
  53993. * Parameters:
  53994. *
  53995. * cells - <mxCell> which should be constrained.
  53996. * sizeFirst - Specifies if the size should be changed first. Default is true.
  53997. */
  53998. mxGraph.prototype.constrainChild = function(cell, sizeFirst)
  53999. {
  54000. sizeFirst = (sizeFirst != null) ? sizeFirst : true;
  54001. if (cell != null)
  54002. {
  54003. var geo = this.getCellGeometry(cell);
  54004. if (geo != null && (this.isConstrainRelativeChildren() || !geo.relative))
  54005. {
  54006. var parent = this.model.getParent(cell);
  54007. var pgeo = this.getCellGeometry(parent);
  54008. var max = this.getMaximumGraphBounds();
  54009. // Finds parent offset
  54010. if (max != null)
  54011. {
  54012. var off = this.getBoundingBoxFromGeometry([parent], false);
  54013. if (off != null)
  54014. {
  54015. max = mxRectangle.fromRectangle(max);
  54016. max.x -= off.x;
  54017. max.y -= off.y;
  54018. }
  54019. }
  54020. if (this.isConstrainChild(cell))
  54021. {
  54022. var tmp = this.getCellContainmentArea(cell);
  54023. if (tmp != null)
  54024. {
  54025. var overlap = this.getOverlap(cell);
  54026. if (overlap > 0)
  54027. {
  54028. tmp = mxRectangle.fromRectangle(tmp);
  54029. tmp.x -= tmp.width * overlap;
  54030. tmp.y -= tmp.height * overlap;
  54031. tmp.width += 2 * tmp.width * overlap;
  54032. tmp.height += 2 * tmp.height * overlap;
  54033. }
  54034. // Find the intersection between max and tmp
  54035. if (max == null)
  54036. {
  54037. max = tmp;
  54038. }
  54039. else
  54040. {
  54041. max = mxRectangle.fromRectangle(max);
  54042. max.intersect(tmp);
  54043. }
  54044. }
  54045. }
  54046. if (max != null)
  54047. {
  54048. var cells = [cell];
  54049. if (!this.isCellCollapsed(cell))
  54050. {
  54051. var desc = this.model.getDescendants(cell);
  54052. for (var i = 0; i < desc.length; i++)
  54053. {
  54054. if (this.isCellVisible(desc[i]))
  54055. {
  54056. cells.push(desc[i]);
  54057. }
  54058. }
  54059. }
  54060. var bbox = this.getBoundingBoxFromGeometry(cells, false);
  54061. if (bbox != null)
  54062. {
  54063. geo = geo.clone();
  54064. // Cumulative horizontal movement
  54065. var dx = 0;
  54066. if (geo.width > max.width)
  54067. {
  54068. dx = geo.width - max.width;
  54069. geo.width -= dx;
  54070. }
  54071. if (bbox.x + bbox.width > max.x + max.width)
  54072. {
  54073. dx -= bbox.x + bbox.width - max.x - max.width - dx;
  54074. }
  54075. // Cumulative vertical movement
  54076. var dy = 0;
  54077. if (geo.height > max.height)
  54078. {
  54079. dy = geo.height - max.height;
  54080. geo.height -= dy;
  54081. }
  54082. if (bbox.y + bbox.height > max.y + max.height)
  54083. {
  54084. dy -= bbox.y + bbox.height - max.y - max.height - dy;
  54085. }
  54086. if (bbox.x < max.x)
  54087. {
  54088. dx -= bbox.x - max.x;
  54089. }
  54090. if (bbox.y < max.y)
  54091. {
  54092. dy -= bbox.y - max.y;
  54093. }
  54094. if (dx != 0 || dy != 0)
  54095. {
  54096. if (geo.relative)
  54097. {
  54098. // Relative geometries are moved via absolute offset
  54099. if (geo.offset == null)
  54100. {
  54101. geo.offset = new mxPoint();
  54102. }
  54103. geo.offset.x += dx;
  54104. geo.offset.y += dy;
  54105. }
  54106. else
  54107. {
  54108. geo.x += dx;
  54109. geo.y += dy;
  54110. }
  54111. }
  54112. this.model.setGeometry(cell, geo);
  54113. }
  54114. }
  54115. }
  54116. }
  54117. };
  54118. /**
  54119. * Function: resetEdges
  54120. *
  54121. * Resets the control points of the edges that are connected to the given
  54122. * cells if not both ends of the edge are in the given cells array.
  54123. *
  54124. * Parameters:
  54125. *
  54126. * cells - Array of <mxCells> for which the connected edges should be
  54127. * reset.
  54128. */
  54129. mxGraph.prototype.resetEdges = function(cells)
  54130. {
  54131. if (cells != null)
  54132. {
  54133. // Prepares faster cells lookup
  54134. var dict = new mxDictionary();
  54135. for (var i = 0; i < cells.length; i++)
  54136. {
  54137. dict.put(cells[i], true);
  54138. }
  54139. this.model.beginUpdate();
  54140. try
  54141. {
  54142. for (var i = 0; i < cells.length; i++)
  54143. {
  54144. var edges = this.model.getEdges(cells[i]);
  54145. if (edges != null)
  54146. {
  54147. for (var j = 0; j < edges.length; j++)
  54148. {
  54149. var state = this.view.getState(edges[j]);
  54150. var source = (state != null) ? state.getVisibleTerminal(true) : this.view.getVisibleTerminal(edges[j], true);
  54151. var target = (state != null) ? state.getVisibleTerminal(false) : this.view.getVisibleTerminal(edges[j], false);
  54152. // Checks if one of the terminals is not in the given array
  54153. if (!dict.get(source) || !dict.get(target))
  54154. {
  54155. this.resetEdge(edges[j]);
  54156. }
  54157. }
  54158. }
  54159. this.resetEdges(this.model.getChildren(cells[i]));
  54160. }
  54161. }
  54162. finally
  54163. {
  54164. this.model.endUpdate();
  54165. }
  54166. }
  54167. };
  54168. /**
  54169. * Function: resetEdge
  54170. *
  54171. * Resets the control points of the given edge.
  54172. *
  54173. * Parameters:
  54174. *
  54175. * edge - <mxCell> whose points should be reset.
  54176. */
  54177. mxGraph.prototype.resetEdge = function(edge)
  54178. {
  54179. var geo = this.model.getGeometry(edge);
  54180. // Resets the control points
  54181. if (geo != null && geo.points != null && geo.points.length > 0)
  54182. {
  54183. geo = geo.clone();
  54184. geo.points = [];
  54185. this.model.setGeometry(edge, geo);
  54186. }
  54187. return edge;
  54188. };
  54189. /**
  54190. * Group: Cell connecting and connection constraints
  54191. */
  54192. /**
  54193. * Function: getOutlineConstraint
  54194. *
  54195. * Returns the constraint used to connect to the outline of the given state.
  54196. */
  54197. mxGraph.prototype.getOutlineConstraint = function(point, terminalState, me)
  54198. {
  54199. if (terminalState.shape != null)
  54200. {
  54201. var bounds = this.view.getPerimeterBounds(terminalState);
  54202. var direction = terminalState.style[mxConstants.STYLE_DIRECTION];
  54203. if (direction == mxConstants.DIRECTION_NORTH || direction == mxConstants.DIRECTION_SOUTH)
  54204. {
  54205. bounds.x += bounds.width / 2 - bounds.height / 2;
  54206. bounds.y += bounds.height / 2 - bounds.width / 2;
  54207. var tmp = bounds.width;
  54208. bounds.width = bounds.height;
  54209. bounds.height = tmp;
  54210. }
  54211. var alpha = mxUtils.toRadians(terminalState.shape.getShapeRotation());
  54212. if (alpha != 0)
  54213. {
  54214. var cos = Math.cos(-alpha);
  54215. var sin = Math.sin(-alpha);
  54216. var ct = new mxPoint(bounds.getCenterX(), bounds.getCenterY());
  54217. point = mxUtils.getRotatedPoint(point, cos, sin, ct);
  54218. }
  54219. var sx = 1;
  54220. var sy = 1;
  54221. var dx = 0;
  54222. var dy = 0;
  54223. // LATER: Add flipping support for image shapes
  54224. if (this.getModel().isVertex(terminalState.cell))
  54225. {
  54226. var flipH = terminalState.style[mxConstants.STYLE_FLIPH];
  54227. var flipV = terminalState.style[mxConstants.STYLE_FLIPV];
  54228. // Legacy support for stencilFlipH/V
  54229. if (terminalState.shape != null && terminalState.shape.stencil != null)
  54230. {
  54231. flipH = mxUtils.getValue(terminalState.style, 'stencilFlipH', 0) == 1 || flipH;
  54232. flipV = mxUtils.getValue(terminalState.style, 'stencilFlipV', 0) == 1 || flipV;
  54233. }
  54234. if (direction == mxConstants.DIRECTION_NORTH || direction == mxConstants.DIRECTION_SOUTH)
  54235. {
  54236. var tmp = flipH;
  54237. flipH = flipV;
  54238. flipV = tmp;
  54239. }
  54240. if (flipH)
  54241. {
  54242. sx = -1;
  54243. dx = -bounds.width;
  54244. }
  54245. if (flipV)
  54246. {
  54247. sy = -1;
  54248. dy = -bounds.height ;
  54249. }
  54250. }
  54251. point = new mxPoint((point.x - bounds.x) * sx - dx + bounds.x, (point.y - bounds.y) * sy - dy + bounds.y);
  54252. var x = (bounds.width == 0) ? 0 : Math.round((point.x - bounds.x) * 1000 / bounds.width) / 1000;
  54253. var y = (bounds.height == 0) ? 0 : Math.round((point.y - bounds.y) * 1000 / bounds.height) / 1000;
  54254. return new mxConnectionConstraint(new mxPoint(x, y), false);
  54255. }
  54256. return null;
  54257. };
  54258. /**
  54259. * Function: getAllConnectionConstraints
  54260. *
  54261. * Returns an array of all <mxConnectionConstraints> for the given terminal. If
  54262. * the shape of the given terminal is a <mxStencilShape> then the constraints
  54263. * of the corresponding <mxStencil> are returned.
  54264. *
  54265. * Parameters:
  54266. *
  54267. * terminal - <mxCellState> that represents the terminal.
  54268. * source - Boolean that specifies if the terminal is the source or target.
  54269. */
  54270. mxGraph.prototype.getAllConnectionConstraints = function(terminal, source)
  54271. {
  54272. if (terminal != null && terminal.shape != null && terminal.shape.stencil != null)
  54273. {
  54274. return terminal.shape.stencil.constraints;
  54275. }
  54276. return null;
  54277. };
  54278. /**
  54279. * Function: getConnectionConstraint
  54280. *
  54281. * Returns an <mxConnectionConstraint> that describes the given connection
  54282. * point. This result can then be passed to <getConnectionPoint>.
  54283. *
  54284. * Parameters:
  54285. *
  54286. * edge - <mxCellState> that represents the edge.
  54287. * terminal - <mxCellState> that represents the terminal.
  54288. * source - Boolean indicating if the terminal is the source or target.
  54289. */
  54290. mxGraph.prototype.getConnectionConstraint = function(edge, terminal, source)
  54291. {
  54292. var point = null;
  54293. var x = edge.style[(source) ? mxConstants.STYLE_EXIT_X : mxConstants.STYLE_ENTRY_X];
  54294. if (x != null)
  54295. {
  54296. var y = edge.style[(source) ? mxConstants.STYLE_EXIT_Y : mxConstants.STYLE_ENTRY_Y];
  54297. if (y != null)
  54298. {
  54299. point = new mxPoint(parseFloat(x), parseFloat(y));
  54300. }
  54301. }
  54302. var perimeter = false;
  54303. var dx = 0, dy = 0;
  54304. if (point != null)
  54305. {
  54306. perimeter = mxUtils.getValue(edge.style, (source) ? mxConstants.STYLE_EXIT_PERIMETER :
  54307. mxConstants.STYLE_ENTRY_PERIMETER, true);
  54308. //Add entry/exit offset
  54309. dx = parseFloat(edge.style[(source) ? mxConstants.STYLE_EXIT_DX : mxConstants.STYLE_ENTRY_DX]);
  54310. dy = parseFloat(edge.style[(source) ? mxConstants.STYLE_EXIT_DY : mxConstants.STYLE_ENTRY_DY]);
  54311. dx = isFinite(dx)? dx : 0;
  54312. dy = isFinite(dy)? dy : 0;
  54313. }
  54314. return new mxConnectionConstraint(point, perimeter, null, dx, dy);
  54315. };
  54316. /**
  54317. * Function: setConnectionConstraint
  54318. *
  54319. * Sets the <mxConnectionConstraint> that describes the given connection point.
  54320. * If no constraint is given then nothing is changed. To remove an existing
  54321. * constraint from the given edge, use an empty constraint instead.
  54322. *
  54323. * Parameters:
  54324. *
  54325. * edge - <mxCell> that represents the edge.
  54326. * terminal - <mxCell> that represents the terminal.
  54327. * source - Boolean indicating if the terminal is the source or target.
  54328. * constraint - Optional <mxConnectionConstraint> to be used for this
  54329. * connection.
  54330. */
  54331. mxGraph.prototype.setConnectionConstraint = function(edge, terminal, source, constraint)
  54332. {
  54333. if (constraint != null)
  54334. {
  54335. this.model.beginUpdate();
  54336. try
  54337. {
  54338. if (constraint == null || constraint.point == null)
  54339. {
  54340. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_X :
  54341. mxConstants.STYLE_ENTRY_X, null, [edge]);
  54342. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_Y :
  54343. mxConstants.STYLE_ENTRY_Y, null, [edge]);
  54344. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_DX :
  54345. mxConstants.STYLE_ENTRY_DX, null, [edge]);
  54346. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_DY :
  54347. mxConstants.STYLE_ENTRY_DY, null, [edge]);
  54348. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_PERIMETER :
  54349. mxConstants.STYLE_ENTRY_PERIMETER, null, [edge]);
  54350. }
  54351. else if (constraint.point != null)
  54352. {
  54353. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_X :
  54354. mxConstants.STYLE_ENTRY_X, constraint.point.x, [edge]);
  54355. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_Y :
  54356. mxConstants.STYLE_ENTRY_Y, constraint.point.y, [edge]);
  54357. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_DX :
  54358. mxConstants.STYLE_ENTRY_DX, constraint.dx, [edge]);
  54359. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_DY :
  54360. mxConstants.STYLE_ENTRY_DY, constraint.dy, [edge]);
  54361. // Only writes 0 since 1 is default
  54362. if (!constraint.perimeter)
  54363. {
  54364. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_PERIMETER :
  54365. mxConstants.STYLE_ENTRY_PERIMETER, '0', [edge]);
  54366. }
  54367. else
  54368. {
  54369. this.setCellStyles((source) ? mxConstants.STYLE_EXIT_PERIMETER :
  54370. mxConstants.STYLE_ENTRY_PERIMETER, null, [edge]);
  54371. }
  54372. }
  54373. }
  54374. finally
  54375. {
  54376. this.model.endUpdate();
  54377. }
  54378. }
  54379. };
  54380. /**
  54381. * Function: getConnectionPoint
  54382. *
  54383. * Returns the nearest point in the list of absolute points or the center
  54384. * of the opposite terminal.
  54385. *
  54386. * Parameters:
  54387. *
  54388. * vertex - <mxCellState> that represents the vertex.
  54389. * constraint - <mxConnectionConstraint> that represents the connection point
  54390. * constraint as returned by <getConnectionConstraint>.
  54391. */
  54392. mxGraph.prototype.getConnectionPoint = function(vertex, constraint, round)
  54393. {
  54394. round = (round != null) ? round : true;
  54395. var point = null;
  54396. if (vertex != null && constraint.point != null)
  54397. {
  54398. var bounds = this.view.getPerimeterBounds(vertex);
  54399. var cx = new mxPoint(bounds.getCenterX(), bounds.getCenterY());
  54400. var direction = vertex.style[mxConstants.STYLE_DIRECTION];
  54401. var r1 = 0;
  54402. // Bounds need to be rotated by 90 degrees for further computation
  54403. if (direction != null && mxUtils.getValue(vertex.style,
  54404. mxConstants.STYLE_ANCHOR_POINT_DIRECTION, 1) == 1)
  54405. {
  54406. if (direction == mxConstants.DIRECTION_NORTH)
  54407. {
  54408. r1 += 270;
  54409. }
  54410. else if (direction == mxConstants.DIRECTION_WEST)
  54411. {
  54412. r1 += 180;
  54413. }
  54414. else if (direction == mxConstants.DIRECTION_SOUTH)
  54415. {
  54416. r1 += 90;
  54417. }
  54418. // Bounds need to be rotated by 90 degrees for further computation
  54419. if (direction == mxConstants.DIRECTION_NORTH ||
  54420. direction == mxConstants.DIRECTION_SOUTH)
  54421. {
  54422. bounds.rotate90();
  54423. }
  54424. }
  54425. var scale = this.view.scale;
  54426. point = new mxPoint(bounds.x + constraint.point.x * bounds.width + constraint.dx * scale,
  54427. bounds.y + constraint.point.y * bounds.height + constraint.dy * scale);
  54428. // Rotation for direction before projection on perimeter
  54429. var r2 = vertex.style[mxConstants.STYLE_ROTATION] || 0;
  54430. if (constraint.perimeter)
  54431. {
  54432. if (r1 != 0)
  54433. {
  54434. // Only 90 degrees steps possible here so no trig needed
  54435. var cos = 0;
  54436. var sin = 0;
  54437. if (r1 == 90)
  54438. {
  54439. sin = 1;
  54440. }
  54441. else if (r1 == 180)
  54442. {
  54443. cos = -1;
  54444. }
  54445. else if (r1 == 270)
  54446. {
  54447. sin = -1;
  54448. }
  54449. point = mxUtils.getRotatedPoint(point, cos, sin, cx);
  54450. }
  54451. point = this.view.getPerimeterPoint(vertex, point, false);
  54452. }
  54453. else
  54454. {
  54455. r2 += r1;
  54456. if (this.getModel().isVertex(vertex.cell))
  54457. {
  54458. var flipH = vertex.style[mxConstants.STYLE_FLIPH] == 1;
  54459. var flipV = vertex.style[mxConstants.STYLE_FLIPV] == 1;
  54460. // Legacy support for stencilFlipH/V
  54461. if (vertex.shape != null && vertex.shape.stencil != null)
  54462. {
  54463. flipH = (mxUtils.getValue(vertex.style, 'stencilFlipH', 0) == 1) || flipH;
  54464. flipV = (mxUtils.getValue(vertex.style, 'stencilFlipV', 0) == 1) || flipV;
  54465. }
  54466. if (direction == mxConstants.DIRECTION_NORTH ||
  54467. direction == mxConstants.DIRECTION_SOUTH)
  54468. {
  54469. var temp = flipH;
  54470. flipH = flipV
  54471. flipV = temp;
  54472. }
  54473. if (flipH)
  54474. {
  54475. point.x = 2 * bounds.getCenterX() - point.x;
  54476. }
  54477. if (flipV)
  54478. {
  54479. point.y = 2 * bounds.getCenterY() - point.y;
  54480. }
  54481. }
  54482. }
  54483. // Generic rotation after projection on perimeter
  54484. if (r2 != 0 && point != null)
  54485. {
  54486. var rad = mxUtils.toRadians(r2);
  54487. var cos = Math.cos(rad);
  54488. var sin = Math.sin(rad);
  54489. point = mxUtils.getRotatedPoint(point, cos, sin, cx);
  54490. }
  54491. }
  54492. if (round && point != null)
  54493. {
  54494. point.x = Math.round(point.x);
  54495. point.y = Math.round(point.y);
  54496. }
  54497. return point;
  54498. };
  54499. /**
  54500. * Function: connectCell
  54501. *
  54502. * Connects the specified end of the given edge to the given terminal
  54503. * using <cellConnected> and fires <mxEvent.CONNECT_CELL> while the
  54504. * transaction is in progress. Returns the updated edge.
  54505. *
  54506. * Parameters:
  54507. *
  54508. * edge - <mxCell> whose terminal should be updated.
  54509. * terminal - <mxCell> that represents the new terminal to be used.
  54510. * source - Boolean indicating if the new terminal is the source or target.
  54511. * constraint - Optional <mxConnectionConstraint> to be used for this
  54512. * connection.
  54513. */
  54514. mxGraph.prototype.connectCell = function(edge, terminal, source, constraint)
  54515. {
  54516. this.model.beginUpdate();
  54517. try
  54518. {
  54519. var previous = this.model.getTerminal(edge, source);
  54520. this.cellConnected(edge, terminal, source, constraint);
  54521. this.fireEvent(new mxEventObject(mxEvent.CONNECT_CELL,
  54522. 'edge', edge, 'terminal', terminal, 'source', source,
  54523. 'previous', previous));
  54524. }
  54525. finally
  54526. {
  54527. this.model.endUpdate();
  54528. }
  54529. return edge;
  54530. };
  54531. /**
  54532. * Function: cellConnected
  54533. *
  54534. * Sets the new terminal for the given edge and resets the edge points if
  54535. * <resetEdgesOnConnect> is true. This method fires
  54536. * <mxEvent.CELL_CONNECTED> while the transaction is in progress.
  54537. *
  54538. * Parameters:
  54539. *
  54540. * edge - <mxCell> whose terminal should be updated.
  54541. * terminal - <mxCell> that represents the new terminal to be used.
  54542. * source - Boolean indicating if the new terminal is the source or target.
  54543. * constraint - <mxConnectionConstraint> to be used for this connection.
  54544. */
  54545. mxGraph.prototype.cellConnected = function(edge, terminal, source, constraint)
  54546. {
  54547. if (edge != null)
  54548. {
  54549. this.model.beginUpdate();
  54550. try
  54551. {
  54552. var previous = this.model.getTerminal(edge, source);
  54553. // Updates the constraint
  54554. this.setConnectionConstraint(edge, terminal, source, constraint);
  54555. // Checks if the new terminal is a port, uses the ID of the port in the
  54556. // style and the parent of the port as the actual terminal of the edge.
  54557. if (this.isPortsEnabled())
  54558. {
  54559. var id = null;
  54560. if (this.isPort(terminal))
  54561. {
  54562. id = terminal.getId();
  54563. terminal = this.getTerminalForPort(terminal, source);
  54564. }
  54565. // Sets or resets all previous information for connecting to a child port
  54566. var key = (source) ? mxConstants.STYLE_SOURCE_PORT :
  54567. mxConstants.STYLE_TARGET_PORT;
  54568. this.setCellStyles(key, id, [edge]);
  54569. }
  54570. this.model.setTerminal(edge, terminal, source);
  54571. if (this.resetEdgesOnConnect)
  54572. {
  54573. this.resetEdge(edge);
  54574. }
  54575. this.fireEvent(new mxEventObject(mxEvent.CELL_CONNECTED,
  54576. 'edge', edge, 'terminal', terminal, 'source', source,
  54577. 'previous', previous));
  54578. }
  54579. finally
  54580. {
  54581. this.model.endUpdate();
  54582. }
  54583. }
  54584. };
  54585. /**
  54586. * Function: disconnectGraph
  54587. *
  54588. * Disconnects the given edges from the terminals which are not in the
  54589. * given array.
  54590. *
  54591. * Parameters:
  54592. *
  54593. * cells - Array of <mxCells> to be disconnected.
  54594. */
  54595. mxGraph.prototype.disconnectGraph = function(cells)
  54596. {
  54597. if (cells != null)
  54598. {
  54599. this.model.beginUpdate();
  54600. try
  54601. {
  54602. var scale = this.view.scale;
  54603. var tr = this.view.translate;
  54604. // Fast lookup for finding cells in array
  54605. var dict = new mxDictionary();
  54606. for (var i = 0; i < cells.length; i++)
  54607. {
  54608. dict.put(cells[i], true);
  54609. }
  54610. for (var i = 0; i < cells.length; i++)
  54611. {
  54612. if (this.model.isEdge(cells[i]))
  54613. {
  54614. var geo = this.model.getGeometry(cells[i]);
  54615. if (geo != null)
  54616. {
  54617. var state = this.view.getState(cells[i]);
  54618. var pstate = this.view.getState(
  54619. this.model.getParent(cells[i]));
  54620. if (state != null &&
  54621. pstate != null)
  54622. {
  54623. geo = geo.clone();
  54624. var dx = -pstate.origin.x;
  54625. var dy = -pstate.origin.y;
  54626. var pts = state.absolutePoints;
  54627. var src = this.model.getTerminal(cells[i], true);
  54628. if (src != null && this.isCellDisconnectable(cells[i], src, true))
  54629. {
  54630. while (src != null && !dict.get(src))
  54631. {
  54632. src = this.model.getParent(src);
  54633. }
  54634. if (src == null)
  54635. {
  54636. geo.setTerminalPoint(
  54637. new mxPoint(pts[0].x / scale - tr.x + dx,
  54638. pts[0].y / scale - tr.y + dy), true);
  54639. this.model.setTerminal(cells[i], null, true);
  54640. }
  54641. }
  54642. var trg = this.model.getTerminal(cells[i], false);
  54643. if (trg != null && this.isCellDisconnectable(cells[i], trg, false))
  54644. {
  54645. while (trg != null && !dict.get(trg))
  54646. {
  54647. trg = this.model.getParent(trg);
  54648. }
  54649. if (trg == null)
  54650. {
  54651. var n = pts.length - 1;
  54652. geo.setTerminalPoint(
  54653. new mxPoint(pts[n].x / scale - tr.x + dx,
  54654. pts[n].y / scale - tr.y + dy), false);
  54655. this.model.setTerminal(cells[i], null, false);
  54656. }
  54657. }
  54658. this.model.setGeometry(cells[i], geo);
  54659. }
  54660. }
  54661. }
  54662. }
  54663. }
  54664. finally
  54665. {
  54666. this.model.endUpdate();
  54667. }
  54668. }
  54669. };
  54670. /**
  54671. * Group: Drilldown
  54672. */
  54673. /**
  54674. * Function: getCurrentRoot
  54675. *
  54676. * Returns the current root of the displayed cell hierarchy. This is a
  54677. * shortcut to <mxGraphView.currentRoot> in <view>.
  54678. */
  54679. mxGraph.prototype.getCurrentRoot = function()
  54680. {
  54681. return this.view.currentRoot;
  54682. };
  54683. /**
  54684. * Function: getTranslateForRoot
  54685. *
  54686. * Returns the translation to be used if the given cell is the root cell as
  54687. * an <mxPoint>. This implementation returns null.
  54688. *
  54689. * Example:
  54690. *
  54691. * To keep the children at their absolute position while stepping into groups,
  54692. * this function can be overridden as follows.
  54693. *
  54694. * (code)
  54695. * var offset = new mxPoint(0, 0);
  54696. *
  54697. * while (cell != null)
  54698. * {
  54699. * var geo = this.model.getGeometry(cell);
  54700. *
  54701. * if (geo != null)
  54702. * {
  54703. * offset.x -= geo.x;
  54704. * offset.y -= geo.y;
  54705. * }
  54706. *
  54707. * cell = this.model.getParent(cell);
  54708. * }
  54709. *
  54710. * return offset;
  54711. * (end)
  54712. *
  54713. * Parameters:
  54714. *
  54715. * cell - <mxCell> that represents the root.
  54716. */
  54717. mxGraph.prototype.getTranslateForRoot = function(cell)
  54718. {
  54719. return null;
  54720. };
  54721. /**
  54722. * Function: isPort
  54723. *
  54724. * Returns true if the given cell is a "port", that is, when connecting to
  54725. * it, the cell returned by getTerminalForPort should be used as the
  54726. * terminal and the port should be referenced by the ID in either the
  54727. * mxConstants.STYLE_SOURCE_PORT or the or the
  54728. * mxConstants.STYLE_TARGET_PORT. Note that a port should not be movable.
  54729. * This implementation always returns false.
  54730. *
  54731. * A typical implementation is the following:
  54732. *
  54733. * (code)
  54734. * graph.isPort = function(cell)
  54735. * {
  54736. * var geo = this.getCellGeometry(cell);
  54737. *
  54738. * return (geo != null) ? geo.relative : false;
  54739. * };
  54740. * (end)
  54741. *
  54742. * Parameters:
  54743. *
  54744. * cell - <mxCell> that represents the port.
  54745. */
  54746. mxGraph.prototype.isPort = function(cell)
  54747. {
  54748. return false;
  54749. };
  54750. /**
  54751. * Function: getTerminalForPort
  54752. *
  54753. * Returns the terminal to be used for a given port. This implementation
  54754. * always returns the parent cell.
  54755. *
  54756. * Parameters:
  54757. *
  54758. * cell - <mxCell> that represents the port.
  54759. * source - If the cell is the source or target port.
  54760. */
  54761. mxGraph.prototype.getTerminalForPort = function(cell, source)
  54762. {
  54763. return this.model.getParent(cell);
  54764. };
  54765. /**
  54766. * Function: getChildOffsetForCell
  54767. *
  54768. * Returns the offset to be used for the cells inside the given cell. The
  54769. * root and layer cells may be identified using <mxGraphModel.isRoot> and
  54770. * <mxGraphModel.isLayer>. For all other current roots, the
  54771. * <mxGraphView.currentRoot> field points to the respective cell, so that
  54772. * the following holds: cell == this.view.currentRoot. This implementation
  54773. * returns null.
  54774. *
  54775. * Parameters:
  54776. *
  54777. * cell - <mxCell> whose offset should be returned.
  54778. */
  54779. mxGraph.prototype.getChildOffsetForCell = function(cell)
  54780. {
  54781. return null;
  54782. };
  54783. /**
  54784. * Function: enterGroup
  54785. *
  54786. * Uses the given cell as the root of the displayed cell hierarchy. If no
  54787. * cell is specified then the selection cell is used. The cell is only used
  54788. * if <isValidRoot> returns true.
  54789. *
  54790. * Parameters:
  54791. *
  54792. * cell - Optional <mxCell> to be used as the new root. Default is the
  54793. * selection cell.
  54794. */
  54795. mxGraph.prototype.enterGroup = function(cell)
  54796. {
  54797. cell = cell || this.getSelectionCell();
  54798. if (cell != null && this.isValidRoot(cell))
  54799. {
  54800. this.view.setCurrentRoot(cell);
  54801. this.clearSelection();
  54802. }
  54803. };
  54804. /**
  54805. * Function: exitGroup
  54806. *
  54807. * Changes the current root to the next valid root in the displayed cell
  54808. * hierarchy.
  54809. */
  54810. mxGraph.prototype.exitGroup = function()
  54811. {
  54812. var root = this.model.getRoot();
  54813. var current = this.getCurrentRoot();
  54814. if (current != null)
  54815. {
  54816. var next = this.model.getParent(current);
  54817. // Finds the next valid root in the hierarchy
  54818. while (next != root && !this.isValidRoot(next) &&
  54819. this.model.getParent(next) != root)
  54820. {
  54821. next = this.model.getParent(next);
  54822. }
  54823. // Clears the current root if the new root is
  54824. // the model's root or one of the layers.
  54825. if (next == root || this.model.getParent(next) == root)
  54826. {
  54827. this.view.setCurrentRoot(null);
  54828. }
  54829. else
  54830. {
  54831. this.view.setCurrentRoot(next);
  54832. }
  54833. var state = this.view.getState(current);
  54834. // Selects the previous root in the graph
  54835. if (state != null)
  54836. {
  54837. this.setSelectionCell(current);
  54838. }
  54839. }
  54840. };
  54841. /**
  54842. * Function: home
  54843. *
  54844. * Uses the root of the model as the root of the displayed cell hierarchy
  54845. * and selects the previous root.
  54846. */
  54847. mxGraph.prototype.home = function()
  54848. {
  54849. var current = this.getCurrentRoot();
  54850. if (current != null)
  54851. {
  54852. this.view.setCurrentRoot(null);
  54853. var state = this.view.getState(current);
  54854. if (state != null)
  54855. {
  54856. this.setSelectionCell(current);
  54857. }
  54858. }
  54859. };
  54860. /**
  54861. * Function: isValidRoot
  54862. *
  54863. * Returns true if the given cell is a valid root for the cell display
  54864. * hierarchy. This implementation returns true for all non-null values.
  54865. *
  54866. * Parameters:
  54867. *
  54868. * cell - <mxCell> which should be checked as a possible root.
  54869. */
  54870. mxGraph.prototype.isValidRoot = function(cell)
  54871. {
  54872. return (cell != null);
  54873. };
  54874. /**
  54875. * Group: Graph display
  54876. */
  54877. /**
  54878. * Function: getGraphBounds
  54879. *
  54880. * Returns the bounds of the visible graph. Shortcut to
  54881. * <mxGraphView.getGraphBounds>. See also: <getBoundingBoxFromGeometry>.
  54882. */
  54883. mxGraph.prototype.getGraphBounds = function()
  54884. {
  54885. return this.view.getGraphBounds();
  54886. };
  54887. /**
  54888. * Function: getCellBounds
  54889. *
  54890. * Returns the scaled, translated bounds for the given cell. See
  54891. * <mxGraphView.getBounds> for arrays.
  54892. *
  54893. * Parameters:
  54894. *
  54895. * cell - <mxCell> whose bounds should be returned.
  54896. * includeEdge - Optional boolean that specifies if the bounds of
  54897. * the connected edges should be included. Default is false.
  54898. * includeDescendants - Optional boolean that specifies if the bounds
  54899. * of all descendants should be included. Default is false.
  54900. */
  54901. mxGraph.prototype.getCellBounds = function(cell, includeEdges, includeDescendants)
  54902. {
  54903. var cells = [cell];
  54904. // Includes all connected edges
  54905. if (includeEdges)
  54906. {
  54907. cells = cells.concat(this.model.getEdges(cell));
  54908. }
  54909. var result = this.view.getBounds(cells);
  54910. // Recursively includes the bounds of the children
  54911. if (includeDescendants)
  54912. {
  54913. var childCount = this.model.getChildCount(cell);
  54914. for (var i = 0; i < childCount; i++)
  54915. {
  54916. var tmp = this.getCellBounds(this.model.getChildAt(cell, i),
  54917. includeEdges, true);
  54918. if (result != null)
  54919. {
  54920. result.add(tmp);
  54921. }
  54922. else
  54923. {
  54924. result = tmp;
  54925. }
  54926. }
  54927. }
  54928. return result;
  54929. };
  54930. /**
  54931. * Function: getBoundingBoxFromGeometry
  54932. *
  54933. * Returns the bounding box for the geometries of the vertices in the
  54934. * given array of cells. This can be used to find the graph bounds during
  54935. * a layout operation (ie. before the last endUpdate) as follows:
  54936. *
  54937. * (code)
  54938. * var cells = graph.getChildCells(graph.getDefaultParent(), true, true);
  54939. * var bounds = graph.getBoundingBoxFromGeometry(cells, true);
  54940. * (end)
  54941. *
  54942. * This can then be used to move cells to the origin:
  54943. *
  54944. * (code)
  54945. * if (bounds.x < 0 || bounds.y < 0)
  54946. * {
  54947. * graph.moveCells(cells, -Math.min(bounds.x, 0), -Math.min(bounds.y, 0))
  54948. * }
  54949. * (end)
  54950. *
  54951. * Or to translate the graph view:
  54952. *
  54953. * (code)
  54954. * if (bounds.x < 0 || bounds.y < 0)
  54955. * {
  54956. * graph.view.setTranslate(-Math.min(bounds.x, 0), -Math.min(bounds.y, 0));
  54957. * }
  54958. * (end)
  54959. *
  54960. * Parameters:
  54961. *
  54962. * cells - Array of <mxCells> whose bounds should be returned.
  54963. * includeEdges - Specifies if edge bounds should be included by computing
  54964. * the bounding box for all points in geometry. Default is false.
  54965. */
  54966. mxGraph.prototype.getBoundingBoxFromGeometry = function(cells, includeEdges)
  54967. {
  54968. includeEdges = (includeEdges != null) ? includeEdges : false;
  54969. var result = null;
  54970. if (cells != null)
  54971. {
  54972. for (var i = 0; i < cells.length; i++)
  54973. {
  54974. if (includeEdges || this.model.isVertex(cells[i]))
  54975. {
  54976. // Computes the bounding box for the points in the geometry
  54977. var geo = this.getCellGeometry(cells[i]);
  54978. if (geo != null)
  54979. {
  54980. var bbox = null;
  54981. if (this.model.isEdge(cells[i]))
  54982. {
  54983. var addPoint = function(pt)
  54984. {
  54985. if (pt != null)
  54986. {
  54987. if (tmp == null)
  54988. {
  54989. tmp = new mxRectangle(pt.x, pt.y, 0, 0);
  54990. }
  54991. else
  54992. {
  54993. tmp.add(new mxRectangle(pt.x, pt.y, 0, 0));
  54994. }
  54995. }
  54996. };
  54997. if (this.model.getTerminal(cells[i], true) == null)
  54998. {
  54999. addPoint(geo.getTerminalPoint(true));
  55000. }
  55001. if (this.model.getTerminal(cells[i], false) == null)
  55002. {
  55003. addPoint(geo.getTerminalPoint(false));
  55004. }
  55005. var pts = geo.points;
  55006. if (pts != null && pts.length > 0)
  55007. {
  55008. var tmp = new mxRectangle(pts[0].x, pts[0].y, 0, 0);
  55009. for (var j = 1; j < pts.length; j++)
  55010. {
  55011. addPoint(pts[j]);
  55012. }
  55013. }
  55014. bbox = tmp;
  55015. }
  55016. else
  55017. {
  55018. var parent = this.model.getParent(cells[i]);
  55019. if (geo.relative)
  55020. {
  55021. if (this.model.isVertex(parent) && parent != this.view.currentRoot)
  55022. {
  55023. var tmp = this.getBoundingBoxFromGeometry([parent], false);
  55024. if (tmp != null)
  55025. {
  55026. bbox = new mxRectangle(geo.x * tmp.width, geo.y * tmp.height, geo.width, geo.height);
  55027. if (mxUtils.indexOf(cells, parent) >= 0)
  55028. {
  55029. bbox.x += tmp.x;
  55030. bbox.y += tmp.y;
  55031. }
  55032. }
  55033. }
  55034. }
  55035. else
  55036. {
  55037. bbox = mxRectangle.fromRectangle(geo);
  55038. if (this.model.isVertex(parent) && mxUtils.indexOf(cells, parent) >= 0)
  55039. {
  55040. var tmp = this.getBoundingBoxFromGeometry([parent], false);
  55041. if (tmp != null)
  55042. {
  55043. bbox.x += tmp.x;
  55044. bbox.y += tmp.y;
  55045. }
  55046. }
  55047. }
  55048. if (bbox != null && geo.offset != null)
  55049. {
  55050. bbox.x += geo.offset.x;
  55051. bbox.y += geo.offset.y;
  55052. }
  55053. var style = this.getCurrentCellStyle(cells[i]);
  55054. if (bbox != null)
  55055. {
  55056. var angle = mxUtils.getValue(style, mxConstants.STYLE_ROTATION, 0);
  55057. if (angle != 0)
  55058. {
  55059. bbox = mxUtils.getBoundingBox(bbox, angle);
  55060. }
  55061. }
  55062. }
  55063. if (bbox != null)
  55064. {
  55065. if (result == null)
  55066. {
  55067. result = mxRectangle.fromRectangle(bbox);
  55068. }
  55069. else
  55070. {
  55071. result.add(bbox);
  55072. }
  55073. }
  55074. }
  55075. }
  55076. }
  55077. }
  55078. return result;
  55079. };
  55080. /**
  55081. * Function: refresh
  55082. *
  55083. * Clears all cell states or the states for the hierarchy starting at the
  55084. * given cell and validates the graph. This fires a refresh event as the
  55085. * last step.
  55086. *
  55087. * Parameters:
  55088. *
  55089. * cell - Optional <mxCell> for which the cell states should be cleared.
  55090. */
  55091. mxGraph.prototype.refresh = function(cell)
  55092. {
  55093. this.view.clear(cell, cell == null);
  55094. this.view.validate();
  55095. this.sizeDidChange();
  55096. this.fireEvent(new mxEventObject(mxEvent.REFRESH));
  55097. };
  55098. /**
  55099. * Function: snap
  55100. *
  55101. * Snaps the given numeric value to the grid if <gridEnabled> is true.
  55102. *
  55103. * Parameters:
  55104. *
  55105. * value - Numeric value to be snapped to the grid.
  55106. */
  55107. mxGraph.prototype.snap = function(value)
  55108. {
  55109. if (this.gridEnabled)
  55110. {
  55111. value = Math.round(value / this.gridSize ) * this.gridSize;
  55112. }
  55113. return value;
  55114. };
  55115. /**
  55116. * Function: snapDelta
  55117. *
  55118. * Snaps the given delta with the given scaled bounds.
  55119. */
  55120. mxGraph.prototype.snapDelta = function(delta, bounds, ignoreGrid, ignoreHorizontal, ignoreVertical)
  55121. {
  55122. var t = this.view.translate;
  55123. var s = this.view.scale;
  55124. if (!ignoreGrid && this.gridEnabled)
  55125. {
  55126. var tol = this.gridSize * s * 0.5;
  55127. if (!ignoreHorizontal)
  55128. {
  55129. var tx = bounds.x - (this.snap(bounds.x / s - t.x) + t.x) * s;
  55130. if (Math.abs(delta.x- tx) < tol)
  55131. {
  55132. delta.x = 0;
  55133. }
  55134. else
  55135. {
  55136. delta.x = this.snap(delta.x / s) * s - tx;
  55137. }
  55138. }
  55139. if (!ignoreVertical)
  55140. {
  55141. var ty = bounds.y - (this.snap(bounds.y / s - t.y) + t.y) * s;
  55142. if (Math.abs(delta.y - ty) < tol)
  55143. {
  55144. delta.y = 0;
  55145. }
  55146. else
  55147. {
  55148. delta.y = this.snap(delta.y / s) * s - ty;
  55149. }
  55150. }
  55151. }
  55152. else
  55153. {
  55154. var tol = 0.5 * s;
  55155. if (!ignoreHorizontal)
  55156. {
  55157. var tx = bounds.x - (Math.round(bounds.x / s - t.x) + t.x) * s;
  55158. if (Math.abs(delta.x - tx) < tol)
  55159. {
  55160. delta.x = 0;
  55161. }
  55162. else
  55163. {
  55164. delta.x = Math.round(delta.x / s) * s - tx;
  55165. }
  55166. }
  55167. if (!ignoreVertical)
  55168. {
  55169. var ty = bounds.y - (Math.round(bounds.y / s - t.y) + t.y) * s;
  55170. if (Math.abs(delta.y - ty) < tol)
  55171. {
  55172. delta.y = 0;
  55173. }
  55174. else
  55175. {
  55176. delta.y = Math.round(delta.y / s) * s - ty;
  55177. }
  55178. }
  55179. }
  55180. return delta;
  55181. };
  55182. /**
  55183. * Function: panGraph
  55184. *
  55185. * Shifts the graph display by the given amount. This is used to preview
  55186. * panning operations, use <mxGraphView.setTranslate> to set a persistent
  55187. * translation of the view. Fires <mxEvent.PAN>.
  55188. *
  55189. * Parameters:
  55190. *
  55191. * dx - Amount to shift the graph along the x-axis.
  55192. * dy - Amount to shift the graph along the y-axis.
  55193. */
  55194. mxGraph.prototype.panGraph = function(dx, dy)
  55195. {
  55196. if (this.useScrollbarsForPanning && mxUtils.hasScrollbars(this.container))
  55197. {
  55198. this.container.scrollLeft = -dx;
  55199. this.container.scrollTop = -dy;
  55200. }
  55201. else
  55202. {
  55203. var canvas = this.view.getCanvas();
  55204. if (this.dialect == mxConstants.DIALECT_SVG)
  55205. {
  55206. // Puts everything inside the container in a DIV so that it
  55207. // can be moved without changing the state of the container
  55208. if (dx == 0 && dy == 0)
  55209. {
  55210. // Workaround for ignored removeAttribute on SVG element in IE9 standards
  55211. if (mxClient.IS_IE)
  55212. {
  55213. canvas.setAttribute('transform', 'translate(' + dx + ',' + dy + ')');
  55214. }
  55215. else
  55216. {
  55217. canvas.removeAttribute('transform');
  55218. }
  55219. if (this.shiftPreview1 != null)
  55220. {
  55221. var child = this.shiftPreview1.firstChild;
  55222. while (child != null)
  55223. {
  55224. var next = child.nextSibling;
  55225. this.container.appendChild(child);
  55226. child = next;
  55227. }
  55228. if (this.shiftPreview1.parentNode != null)
  55229. {
  55230. this.shiftPreview1.parentNode.removeChild(this.shiftPreview1);
  55231. }
  55232. this.shiftPreview1 = null;
  55233. this.container.appendChild(canvas.parentNode);
  55234. child = this.shiftPreview2.firstChild;
  55235. while (child != null)
  55236. {
  55237. var next = child.nextSibling;
  55238. this.container.appendChild(child);
  55239. child = next;
  55240. }
  55241. if (this.shiftPreview2.parentNode != null)
  55242. {
  55243. this.shiftPreview2.parentNode.removeChild(this.shiftPreview2);
  55244. }
  55245. this.shiftPreview2 = null;
  55246. }
  55247. }
  55248. else
  55249. {
  55250. canvas.setAttribute('transform', 'translate(' + dx + ',' + dy + ')');
  55251. if (this.shiftPreview1 == null)
  55252. {
  55253. // Needs two divs for stuff before and after the SVG element
  55254. this.shiftPreview1 = document.createElement('div');
  55255. this.shiftPreview1.style.position = 'absolute';
  55256. this.shiftPreview1.style.overflow = 'visible';
  55257. this.shiftPreview2 = document.createElement('div');
  55258. this.shiftPreview2.style.position = 'absolute';
  55259. this.shiftPreview2.style.overflow = 'visible';
  55260. var current = this.shiftPreview1;
  55261. var child = this.container.firstChild;
  55262. while (child != null)
  55263. {
  55264. var next = child.nextSibling;
  55265. // SVG element is moved via transform attribute
  55266. if (child != canvas.parentNode)
  55267. {
  55268. current.appendChild(child);
  55269. }
  55270. else
  55271. {
  55272. current = this.shiftPreview2;
  55273. }
  55274. child = next;
  55275. }
  55276. // Inserts elements only if not empty
  55277. if (this.shiftPreview1.firstChild != null)
  55278. {
  55279. this.container.insertBefore(this.shiftPreview1, canvas.parentNode);
  55280. }
  55281. if (this.shiftPreview2.firstChild != null)
  55282. {
  55283. this.container.appendChild(this.shiftPreview2);
  55284. }
  55285. }
  55286. this.shiftPreview1.style.left = dx + 'px';
  55287. this.shiftPreview1.style.top = dy + 'px';
  55288. this.shiftPreview2.style.left = dx + 'px';
  55289. this.shiftPreview2.style.top = dy + 'px';
  55290. }
  55291. }
  55292. else
  55293. {
  55294. canvas.style.left = dx + 'px';
  55295. canvas.style.top = dy + 'px';
  55296. }
  55297. this.panDx = dx;
  55298. this.panDy = dy;
  55299. this.fireEvent(new mxEventObject(mxEvent.PAN));
  55300. }
  55301. };
  55302. /**
  55303. * Function: zoomIn
  55304. *
  55305. * Zooms into the graph by <zoomFactor>.
  55306. */
  55307. mxGraph.prototype.zoomIn = function()
  55308. {
  55309. this.zoom(this.zoomFactor);
  55310. };
  55311. /**
  55312. * Function: zoomOut
  55313. *
  55314. * Zooms out of the graph by <zoomFactor>.
  55315. */
  55316. mxGraph.prototype.zoomOut = function()
  55317. {
  55318. this.zoom(1 / this.zoomFactor);
  55319. };
  55320. /**
  55321. * Function: zoomActual
  55322. *
  55323. * Resets the zoom and panning in the view.
  55324. */
  55325. mxGraph.prototype.zoomActual = function()
  55326. {
  55327. if (this.view.scale == 1)
  55328. {
  55329. this.view.setTranslate(0, 0);
  55330. }
  55331. else
  55332. {
  55333. this.view.translate.x = 0;
  55334. this.view.translate.y = 0;
  55335. this.view.setScale(1);
  55336. }
  55337. };
  55338. /**
  55339. * Function: zoomTo
  55340. *
  55341. * Zooms the graph to the given scale with an optional boolean center
  55342. * argument, which is passd to <zoom>.
  55343. */
  55344. mxGraph.prototype.zoomTo = function(scale, center)
  55345. {
  55346. this.zoom(scale / this.view.scale, center);
  55347. };
  55348. /**
  55349. * Function: center
  55350. *
  55351. * Centers the graph in the container.
  55352. *
  55353. * Parameters:
  55354. *
  55355. * horizontal - Optional boolean that specifies if the graph should be centered
  55356. * horizontally. Default is true.
  55357. * vertical - Optional boolean that specifies if the graph should be centered
  55358. * vertically. Default is true.
  55359. * cx - Optional float that specifies the horizontal center. Default is 0.5.
  55360. * cy - Optional float that specifies the vertical center. Default is 0.5.
  55361. */
  55362. mxGraph.prototype.center = function(horizontal, vertical, cx, cy)
  55363. {
  55364. horizontal = (horizontal != null) ? horizontal : true;
  55365. vertical = (vertical != null) ? vertical : true;
  55366. cx = (cx != null) ? cx : 0.5;
  55367. cy = (cy != null) ? cy : 0.5;
  55368. var hasScrollbars = mxUtils.hasScrollbars(this.container);
  55369. var padding = 2 * this.getBorder();
  55370. var cw = this.container.clientWidth - padding;
  55371. var ch = this.container.clientHeight - padding;
  55372. var bounds = this.getGraphBounds();
  55373. var t = this.view.translate;
  55374. var s = this.view.scale;
  55375. var dx = (horizontal) ? cw - bounds.width : 0;
  55376. var dy = (vertical) ? ch - bounds.height : 0;
  55377. if (!hasScrollbars)
  55378. {
  55379. this.view.setTranslate((horizontal) ? Math.floor(t.x - bounds.x * s + dx * cx / s) : t.x,
  55380. (vertical) ? Math.floor(t.y - bounds.y * s + dy * cy / s) : t.y);
  55381. }
  55382. else
  55383. {
  55384. bounds.x -= t.x;
  55385. bounds.y -= t.y;
  55386. var sw = this.container.scrollWidth;
  55387. var sh = this.container.scrollHeight;
  55388. if (sw > cw)
  55389. {
  55390. dx = 0;
  55391. }
  55392. if (sh > ch)
  55393. {
  55394. dy = 0;
  55395. }
  55396. this.view.setTranslate(Math.floor(dx / 2 - bounds.x), Math.floor(dy / 2 - bounds.y));
  55397. this.container.scrollLeft = (sw - cw) / 2;
  55398. this.container.scrollTop = (sh - ch) / 2;
  55399. }
  55400. };
  55401. /**
  55402. * Function: zoom
  55403. *
  55404. * Zooms the graph using the given factor. Center is an optional boolean
  55405. * argument that keeps the graph scrolled to the center. If the center argument
  55406. * is omitted, then <centerZoom> will be used as its value.
  55407. */
  55408. mxGraph.prototype.zoom = function(factor, center)
  55409. {
  55410. center = (center != null) ? center : this.centerZoom;
  55411. var scale = Math.round(this.view.scale * factor * 100) / 100;
  55412. var state = this.view.getState(this.getSelectionCell());
  55413. factor = scale / this.view.scale;
  55414. if (this.keepSelectionVisibleOnZoom && state != null)
  55415. {
  55416. var rect = new mxRectangle(state.x * factor, state.y * factor,
  55417. state.width * factor, state.height * factor);
  55418. // Refreshes the display only once if a scroll is carried out
  55419. this.view.scale = scale;
  55420. if (!this.scrollRectToVisible(rect))
  55421. {
  55422. this.view.revalidate();
  55423. // Forces an event to be fired but does not revalidate again
  55424. this.view.setScale(scale);
  55425. }
  55426. }
  55427. else
  55428. {
  55429. var hasScrollbars = mxUtils.hasScrollbars(this.container);
  55430. if (center && !hasScrollbars)
  55431. {
  55432. var dx = this.container.offsetWidth;
  55433. var dy = this.container.offsetHeight;
  55434. if (factor > 1)
  55435. {
  55436. var f = (factor - 1) / (scale * 2);
  55437. dx *= -f;
  55438. dy *= -f;
  55439. }
  55440. else
  55441. {
  55442. var f = (1 / factor - 1) / (this.view.scale * 2);
  55443. dx *= f;
  55444. dy *= f;
  55445. }
  55446. this.view.scaleAndTranslate(scale,
  55447. this.view.translate.x + dx,
  55448. this.view.translate.y + dy);
  55449. }
  55450. else
  55451. {
  55452. // Allows for changes of translate and scrollbars during setscale
  55453. var tx = this.view.translate.x;
  55454. var ty = this.view.translate.y;
  55455. var sl = this.container.scrollLeft;
  55456. var st = this.container.scrollTop;
  55457. this.view.setScale(scale);
  55458. if (hasScrollbars)
  55459. {
  55460. var dx = 0;
  55461. var dy = 0;
  55462. if (center)
  55463. {
  55464. dx = this.container.offsetWidth * (factor - 1) / 2;
  55465. dy = this.container.offsetHeight * (factor - 1) / 2;
  55466. }
  55467. this.container.scrollLeft = (this.view.translate.x - tx) * this.view.scale + Math.round(sl * factor + dx);
  55468. this.container.scrollTop = (this.view.translate.y - ty) * this.view.scale + Math.round(st * factor + dy);
  55469. }
  55470. }
  55471. }
  55472. };
  55473. /**
  55474. * Function: zoomToRect
  55475. *
  55476. * Zooms the graph to the specified rectangle. If the rectangle does not have same aspect
  55477. * ratio as the display container, it is increased in the smaller relative dimension only
  55478. * until the aspect match. The original rectangle is centralised within this expanded one.
  55479. *
  55480. * Note that the input rectangular must be un-scaled and un-translated.
  55481. *
  55482. * Parameters:
  55483. *
  55484. * rect - The un-scaled and un-translated rectangluar region that should be just visible
  55485. * after the operation
  55486. */
  55487. mxGraph.prototype.zoomToRect = function(rect)
  55488. {
  55489. var scaleX = this.container.clientWidth / rect.width;
  55490. var scaleY = this.container.clientHeight / rect.height;
  55491. var aspectFactor = scaleX / scaleY;
  55492. // Remove any overlap of the rect outside the client area
  55493. rect.x = Math.max(0, rect.x);
  55494. rect.y = Math.max(0, rect.y);
  55495. var rectRight = Math.min(this.container.scrollWidth, rect.x + rect.width);
  55496. var rectBottom = Math.min(this.container.scrollHeight, rect.y + rect.height);
  55497. rect.width = rectRight - rect.x;
  55498. rect.height = rectBottom - rect.y;
  55499. // The selection area has to be increased to the same aspect
  55500. // ratio as the container, centred around the centre point of the
  55501. // original rect passed in.
  55502. if (aspectFactor < 1.0)
  55503. {
  55504. // Height needs increasing
  55505. var newHeight = rect.height / aspectFactor;
  55506. var deltaHeightBuffer = (newHeight - rect.height) / 2.0;
  55507. rect.height = newHeight;
  55508. // Assign up to half the buffer to the upper part of the rect, not crossing 0
  55509. // put the rest on the bottom
  55510. var upperBuffer = Math.min(rect.y , deltaHeightBuffer);
  55511. rect.y = rect.y - upperBuffer;
  55512. // Check if the bottom has extended too far
  55513. rectBottom = Math.min(this.container.scrollHeight, rect.y + rect.height);
  55514. rect.height = rectBottom - rect.y;
  55515. }
  55516. else
  55517. {
  55518. // Width needs increasing
  55519. var newWidth = rect.width * aspectFactor;
  55520. var deltaWidthBuffer = (newWidth - rect.width) / 2.0;
  55521. rect.width = newWidth;
  55522. // Assign up to half the buffer to the upper part of the rect, not crossing 0
  55523. // put the rest on the bottom
  55524. var leftBuffer = Math.min(rect.x , deltaWidthBuffer);
  55525. rect.x = rect.x - leftBuffer;
  55526. // Check if the right hand side has extended too far
  55527. rectRight = Math.min(this.container.scrollWidth, rect.x + rect.width);
  55528. rect.width = rectRight - rect.x;
  55529. }
  55530. var scale = this.container.clientWidth / rect.width;
  55531. var newScale = this.view.scale * scale;
  55532. if (!mxUtils.hasScrollbars(this.container))
  55533. {
  55534. this.view.scaleAndTranslate(newScale, (this.view.translate.x - rect.x / this.view.scale), (this.view.translate.y - rect.y / this.view.scale));
  55535. }
  55536. else
  55537. {
  55538. this.view.setScale(newScale);
  55539. this.container.scrollLeft = Math.round(rect.x * scale);
  55540. this.container.scrollTop = Math.round(rect.y * scale);
  55541. }
  55542. };
  55543. /**
  55544. * Function: scrollCellToVisible
  55545. *
  55546. * Pans the graph so that it shows the given cell. Optionally the cell may
  55547. * be centered in the container.
  55548. *
  55549. * To center a given graph if the <container> has no scrollbars, use the following code.
  55550. *
  55551. * [code]
  55552. * var bounds = graph.getGraphBounds();
  55553. * graph.view.setTranslate(-bounds.x - (bounds.width - container.clientWidth) / 2,
  55554. * -bounds.y - (bounds.height - container.clientHeight) / 2);
  55555. * [/code]
  55556. *
  55557. * Parameters:
  55558. *
  55559. * cell - <mxCell> to be made visible.
  55560. * center - Optional boolean flag. Default is false.
  55561. */
  55562. mxGraph.prototype.scrollCellToVisible = function(cell, center)
  55563. {
  55564. var x = -this.view.translate.x;
  55565. var y = -this.view.translate.y;
  55566. var state = this.view.getState(cell);
  55567. if (state != null)
  55568. {
  55569. var bounds = new mxRectangle(x + state.x, y + state.y, state.width,
  55570. state.height);
  55571. if (center && this.container != null)
  55572. {
  55573. var w = this.container.clientWidth;
  55574. var h = this.container.clientHeight;
  55575. bounds.x = bounds.getCenterX() - w / 2;
  55576. bounds.width = w;
  55577. bounds.y = bounds.getCenterY() - h / 2;
  55578. bounds.height = h;
  55579. }
  55580. var tr = new mxPoint(this.view.translate.x, this.view.translate.y);
  55581. if (this.scrollRectToVisible(bounds))
  55582. {
  55583. // Triggers an update via the view's event source
  55584. var tr2 = new mxPoint(this.view.translate.x, this.view.translate.y);
  55585. this.view.translate.x = tr.x;
  55586. this.view.translate.y = tr.y;
  55587. this.view.setTranslate(tr2.x, tr2.y);
  55588. }
  55589. }
  55590. };
  55591. /**
  55592. * Function: scrollRectToVisible
  55593. *
  55594. * Pans the graph so that it shows the given rectangle.
  55595. *
  55596. * Parameters:
  55597. *
  55598. * rect - <mxRectangle> to be made visible.
  55599. */
  55600. mxGraph.prototype.scrollRectToVisible = function(rect)
  55601. {
  55602. var isChanged = false;
  55603. if (rect != null)
  55604. {
  55605. var w = this.container.offsetWidth;
  55606. var h = this.container.offsetHeight;
  55607. var widthLimit = Math.min(w, rect.width);
  55608. var heightLimit = Math.min(h, rect.height);
  55609. if (mxUtils.hasScrollbars(this.container))
  55610. {
  55611. var c = this.container;
  55612. rect.x += this.view.translate.x;
  55613. rect.y += this.view.translate.y;
  55614. var dx = c.scrollLeft - rect.x;
  55615. var ddx = Math.max(dx - c.scrollLeft, 0);
  55616. if (dx > 0)
  55617. {
  55618. c.scrollLeft -= dx + 2;
  55619. }
  55620. else
  55621. {
  55622. dx = rect.x + widthLimit - c.scrollLeft - c.clientWidth;
  55623. if (dx > 0)
  55624. {
  55625. c.scrollLeft += dx + 2;
  55626. }
  55627. }
  55628. var dy = c.scrollTop - rect.y;
  55629. var ddy = Math.max(0, dy - c.scrollTop);
  55630. if (dy > 0)
  55631. {
  55632. c.scrollTop -= dy + 2;
  55633. }
  55634. else
  55635. {
  55636. dy = rect.y + heightLimit - c.scrollTop - c.clientHeight;
  55637. if (dy > 0)
  55638. {
  55639. c.scrollTop += dy + 2;
  55640. }
  55641. }
  55642. if (!this.useScrollbarsForPanning && (ddx != 0 || ddy != 0))
  55643. {
  55644. this.view.setTranslate(ddx, ddy);
  55645. }
  55646. }
  55647. else
  55648. {
  55649. var x = -this.view.translate.x;
  55650. var y = -this.view.translate.y;
  55651. var s = this.view.scale;
  55652. if (rect.x + widthLimit > x + w)
  55653. {
  55654. this.view.translate.x -= (rect.x + widthLimit - w - x) / s;
  55655. isChanged = true;
  55656. }
  55657. if (rect.y + heightLimit > y + h)
  55658. {
  55659. this.view.translate.y -= (rect.y + heightLimit - h - y) / s;
  55660. isChanged = true;
  55661. }
  55662. if (rect.x < x)
  55663. {
  55664. this.view.translate.x += (x - rect.x) / s;
  55665. isChanged = true;
  55666. }
  55667. if (rect.y < y)
  55668. {
  55669. this.view.translate.y += (y - rect.y) / s;
  55670. isChanged = true;
  55671. }
  55672. if (isChanged)
  55673. {
  55674. this.view.refresh();
  55675. // Repaints selection marker (ticket 18)
  55676. if (this.selectionCellsHandler != null)
  55677. {
  55678. this.selectionCellsHandler.refresh();
  55679. }
  55680. }
  55681. }
  55682. }
  55683. return isChanged;
  55684. };
  55685. /**
  55686. * Function: getCellGeometry
  55687. *
  55688. * Returns the <mxGeometry> for the given cell. This implementation uses
  55689. * <mxGraphModel.getGeometry>. Subclasses can override this to implement
  55690. * specific geometries for cells in only one graph, that is, it can return
  55691. * geometries that depend on the current state of the view.
  55692. *
  55693. * Parameters:
  55694. *
  55695. * cell - <mxCell> whose geometry should be returned.
  55696. */
  55697. mxGraph.prototype.getCellGeometry = function(cell)
  55698. {
  55699. return this.model.getGeometry(cell);
  55700. };
  55701. /**
  55702. * Function: isCellVisible
  55703. *
  55704. * Returns true if the given cell is visible in this graph. This
  55705. * implementation uses <mxGraphModel.isVisible>. Subclassers can override
  55706. * this to implement specific visibility for cells in only one graph, that
  55707. * is, without affecting the visible state of the cell.
  55708. *
  55709. * When using dynamic filter expressions for cell visibility, then the
  55710. * graph should be revalidated after the filter expression has changed.
  55711. *
  55712. * Parameters:
  55713. *
  55714. * cell - <mxCell> whose visible state should be returned.
  55715. */
  55716. mxGraph.prototype.isCellVisible = function(cell)
  55717. {
  55718. return this.model.isVisible(cell);
  55719. };
  55720. /**
  55721. * Function: isCellCollapsed
  55722. *
  55723. * Returns true if the given cell is collapsed in this graph. This
  55724. * implementation uses <mxGraphModel.isCollapsed>. Subclassers can override
  55725. * this to implement specific collapsed states for cells in only one graph,
  55726. * that is, without affecting the collapsed state of the cell.
  55727. *
  55728. * When using dynamic filter expressions for the collapsed state, then the
  55729. * graph should be revalidated after the filter expression has changed.
  55730. *
  55731. * Parameters:
  55732. *
  55733. * cell - <mxCell> whose collapsed state should be returned.
  55734. */
  55735. mxGraph.prototype.isCellCollapsed = function(cell)
  55736. {
  55737. return this.model.isCollapsed(cell);
  55738. };
  55739. /**
  55740. * Function: isCellConnectable
  55741. *
  55742. * Returns true if the given cell is connectable in this graph. This
  55743. * implementation uses <mxGraphModel.isConnectable>. Subclassers can override
  55744. * this to implement specific connectable states for cells in only one graph,
  55745. * that is, without affecting the connectable state of the cell in the model.
  55746. *
  55747. * Parameters:
  55748. *
  55749. * cell - <mxCell> whose connectable state should be returned.
  55750. */
  55751. mxGraph.prototype.isCellConnectable = function(cell)
  55752. {
  55753. return this.model.isConnectable(cell);
  55754. };
  55755. /**
  55756. * Function: isOrthogonal
  55757. *
  55758. * Returns true if perimeter points should be computed such that the
  55759. * resulting edge has only horizontal or vertical segments.
  55760. *
  55761. * Parameters:
  55762. *
  55763. * edge - <mxCellState> that represents the edge.
  55764. */
  55765. mxGraph.prototype.isOrthogonal = function(edge)
  55766. {
  55767. var orthogonal = edge.style[mxConstants.STYLE_ORTHOGONAL];
  55768. if (orthogonal != null)
  55769. {
  55770. return orthogonal;
  55771. }
  55772. var tmp = this.view.getEdgeStyle(edge);
  55773. return tmp == mxEdgeStyle.SegmentConnector ||
  55774. tmp == mxEdgeStyle.ElbowConnector ||
  55775. tmp == mxEdgeStyle.SideToSide ||
  55776. tmp == mxEdgeStyle.TopToBottom ||
  55777. tmp == mxEdgeStyle.EntityRelation ||
  55778. tmp == mxEdgeStyle.OrthConnector;
  55779. };
  55780. /**
  55781. * Function: isLoop
  55782. *
  55783. * Returns true if the given cell state is a loop.
  55784. *
  55785. * Parameters:
  55786. *
  55787. * state - <mxCellState> that represents a potential loop.
  55788. */
  55789. mxGraph.prototype.isLoop = function(state)
  55790. {
  55791. var src = state.getVisibleTerminalState(true);
  55792. var trg = state.getVisibleTerminalState(false);
  55793. return (src != null && src == trg);
  55794. };
  55795. /**
  55796. * Function: isCloneEvent
  55797. *
  55798. * Returns true if the given event is a clone event. This implementation
  55799. * returns true if control is pressed.
  55800. */
  55801. mxGraph.prototype.isCloneEvent = function(evt)
  55802. {
  55803. return mxEvent.isControlDown(evt);
  55804. };
  55805. /**
  55806. * Function: isTransparentClickEvent
  55807. *
  55808. * Hook for implementing click-through behaviour on selected cells. If this
  55809. * returns true the cell behind the selected cell will be selected. This
  55810. * implementation returns false;
  55811. */
  55812. mxGraph.prototype.isTransparentClickEvent = function(evt)
  55813. {
  55814. return false;
  55815. };
  55816. /**
  55817. * Function: isToggleEvent
  55818. *
  55819. * Returns true if the given event is a toggle event. This implementation
  55820. * returns true if the meta key (Cmd) is pressed on Macs or if control is
  55821. * pressed on any other platform.
  55822. */
  55823. mxGraph.prototype.isToggleEvent = function(evt)
  55824. {
  55825. return (mxClient.IS_MAC) ? mxEvent.isMetaDown(evt) : mxEvent.isControlDown(evt);
  55826. };
  55827. /**
  55828. * Function: isGridEnabledEvent
  55829. *
  55830. * Returns true if the given mouse event should be aligned to the grid.
  55831. */
  55832. mxGraph.prototype.isGridEnabledEvent = function(evt)
  55833. {
  55834. return evt != null && !mxEvent.isAltDown(evt);
  55835. };
  55836. /**
  55837. * Function: isConstrainedEvent
  55838. *
  55839. * Returns true if the given mouse event should be aligned to the grid.
  55840. */
  55841. mxGraph.prototype.isConstrainedEvent = function(evt)
  55842. {
  55843. return mxEvent.isShiftDown(evt);
  55844. };
  55845. /**
  55846. * Function: isIgnoreTerminalEvent
  55847. *
  55848. * Returns true if the given mouse event should not allow any connections to be
  55849. * made. This implementation returns false.
  55850. */
  55851. mxGraph.prototype.isIgnoreTerminalEvent = function(evt)
  55852. {
  55853. return false;
  55854. };
  55855. /**
  55856. * Group: Validation
  55857. */
  55858. /**
  55859. * Function: validationAlert
  55860. *
  55861. * Displays the given validation error in a dialog. This implementation uses
  55862. * mxUtils.alert.
  55863. */
  55864. mxGraph.prototype.validationAlert = function(message)
  55865. {
  55866. mxUtils.alert(message);
  55867. };
  55868. /**
  55869. * Function: isEdgeValid
  55870. *
  55871. * Checks if the return value of <getEdgeValidationError> for the given
  55872. * arguments is null.
  55873. *
  55874. * Parameters:
  55875. *
  55876. * edge - <mxCell> that represents the edge to validate.
  55877. * source - <mxCell> that represents the source terminal.
  55878. * target - <mxCell> that represents the target terminal.
  55879. */
  55880. mxGraph.prototype.isEdgeValid = function(edge, source, target)
  55881. {
  55882. return this.getEdgeValidationError(edge, source, target) == null;
  55883. };
  55884. /**
  55885. * Function: getEdgeValidationError
  55886. *
  55887. * Returns the validation error message to be displayed when inserting or
  55888. * changing an edges' connectivity. A return value of null means the edge
  55889. * is valid, a return value of '' means it's not valid, but do not display
  55890. * an error message. Any other (non-empty) string returned from this method
  55891. * is displayed as an error message when trying to connect an edge to a
  55892. * source and target. This implementation uses the <multiplicities>, and
  55893. * checks <multigraph>, <allowDanglingEdges> and <allowLoops> to generate
  55894. * validation errors.
  55895. *
  55896. * For extending this method with specific checks for source/target cells,
  55897. * the method can be extended as follows. Returning an empty string means
  55898. * the edge is invalid with no error message, a non-null string specifies
  55899. * the error message, and null means the edge is valid.
  55900. *
  55901. * (code)
  55902. * graph.getEdgeValidationError = function(edge, source, target)
  55903. * {
  55904. * if (source != null && target != null &&
  55905. * this.model.getValue(source) != null &&
  55906. * this.model.getValue(target) != null)
  55907. * {
  55908. * if (target is not valid for source)
  55909. * {
  55910. * return 'Invalid Target';
  55911. * }
  55912. * }
  55913. *
  55914. * // "Supercall"
  55915. * return mxGraph.prototype.getEdgeValidationError.apply(this, arguments);
  55916. * }
  55917. * (end)
  55918. *
  55919. * Parameters:
  55920. *
  55921. * edge - <mxCell> that represents the edge to validate.
  55922. * source - <mxCell> that represents the source terminal.
  55923. * target - <mxCell> that represents the target terminal.
  55924. */
  55925. mxGraph.prototype.getEdgeValidationError = function(edge, source, target)
  55926. {
  55927. if (edge != null && !this.isAllowDanglingEdges() && (source == null || target == null))
  55928. {
  55929. return '';
  55930. }
  55931. if (edge != null && this.model.getTerminal(edge, true) == null &&
  55932. this.model.getTerminal(edge, false) == null)
  55933. {
  55934. return null;
  55935. }
  55936. // Checks if we're dealing with a loop
  55937. if (!this.allowLoops && source == target && source != null)
  55938. {
  55939. return '';
  55940. }
  55941. // Checks if the connection is generally allowed
  55942. if (!this.isValidConnection(source, target))
  55943. {
  55944. return '';
  55945. }
  55946. if (source != null && target != null)
  55947. {
  55948. var error = '';
  55949. // Checks if the cells are already connected
  55950. // and adds an error message if required
  55951. if (!this.multigraph)
  55952. {
  55953. var tmp = this.model.getEdgesBetween(source, target, true);
  55954. // Checks if the source and target are not connected by another edge
  55955. if (tmp.length > 1 || (tmp.length == 1 && tmp[0] != edge))
  55956. {
  55957. error += (mxResources.get(this.alreadyConnectedResource) ||
  55958. this.alreadyConnectedResource)+'\n';
  55959. }
  55960. }
  55961. // Gets the number of outgoing edges from the source
  55962. // and the number of incoming edges from the target
  55963. // without counting the edge being currently changed.
  55964. var sourceOut = this.model.getDirectedEdgeCount(source, true, edge);
  55965. var targetIn = this.model.getDirectedEdgeCount(target, false, edge);
  55966. // Checks the change against each multiplicity rule
  55967. if (this.multiplicities != null)
  55968. {
  55969. for (var i = 0; i < this.multiplicities.length; i++)
  55970. {
  55971. var err = this.multiplicities[i].check(this, edge, source,
  55972. target, sourceOut, targetIn);
  55973. if (err != null)
  55974. {
  55975. error += err;
  55976. }
  55977. }
  55978. }
  55979. // Validates the source and target terminals independently
  55980. var err = this.validateEdge(edge, source, target);
  55981. if (err != null)
  55982. {
  55983. error += err;
  55984. }
  55985. return (error.length > 0) ? error : null;
  55986. }
  55987. return (this.allowDanglingEdges) ? null : '';
  55988. };
  55989. /**
  55990. * Function: validateEdge
  55991. *
  55992. * Hook method for subclassers to return an error message for the given
  55993. * edge and terminals. This implementation returns null.
  55994. *
  55995. * Parameters:
  55996. *
  55997. * edge - <mxCell> that represents the edge to validate.
  55998. * source - <mxCell> that represents the source terminal.
  55999. * target - <mxCell> that represents the target terminal.
  56000. */
  56001. mxGraph.prototype.validateEdge = function(edge, source, target)
  56002. {
  56003. return null;
  56004. };
  56005. /**
  56006. * Function: validateGraph
  56007. *
  56008. * Validates the graph by validating each descendant of the given cell or
  56009. * the root of the model. Context is an object that contains the validation
  56010. * state for the complete validation run. The validation errors are
  56011. * attached to their cells using <setCellWarning>. Returns null in the case of
  56012. * successful validation or an array of strings (warnings) in the case of
  56013. * failed validations.
  56014. *
  56015. * Paramters:
  56016. *
  56017. * cell - Optional <mxCell> to start the validation recursion. Default is
  56018. * the graph root.
  56019. * context - Object that represents the global validation state.
  56020. */
  56021. mxGraph.prototype.validateGraph = function(cell, context)
  56022. {
  56023. cell = (cell != null) ? cell : this.model.getRoot();
  56024. context = (context != null) ? context : new Object();
  56025. var isValid = true;
  56026. var childCount = this.model.getChildCount(cell);
  56027. for (var i = 0; i < childCount; i++)
  56028. {
  56029. var tmp = this.model.getChildAt(cell, i);
  56030. var ctx = context;
  56031. if (this.isValidRoot(tmp))
  56032. {
  56033. ctx = new Object();
  56034. }
  56035. var warn = this.validateGraph(tmp, ctx);
  56036. if (warn != null)
  56037. {
  56038. this.setCellWarning(tmp, warn.replace(/\n/g, '<br>'));
  56039. }
  56040. else
  56041. {
  56042. this.setCellWarning(tmp, null);
  56043. }
  56044. isValid = isValid && warn == null;
  56045. }
  56046. var warning = '';
  56047. // Adds error for invalid children if collapsed (children invisible)
  56048. if (this.isCellCollapsed(cell) && !isValid)
  56049. {
  56050. warning += (mxResources.get(this.containsValidationErrorsResource) ||
  56051. this.containsValidationErrorsResource) + '\n';
  56052. }
  56053. // Checks edges and cells using the defined multiplicities
  56054. if (this.model.isEdge(cell))
  56055. {
  56056. warning += this.getEdgeValidationError(cell,
  56057. this.model.getTerminal(cell, true),
  56058. this.model.getTerminal(cell, false)) || '';
  56059. }
  56060. else
  56061. {
  56062. warning += this.getCellValidationError(cell) || '';
  56063. }
  56064. // Checks custom validation rules
  56065. var err = this.validateCell(cell, context);
  56066. if (err != null)
  56067. {
  56068. warning += err;
  56069. }
  56070. // Updates the display with the warning icons
  56071. // before any potential alerts are displayed.
  56072. // LATER: Move this into addCellOverlay. Redraw
  56073. // should check if overlay was added or removed.
  56074. if (this.model.getParent(cell) == null)
  56075. {
  56076. this.view.validate();
  56077. }
  56078. return (warning.length > 0 || !isValid) ? warning : null;
  56079. };
  56080. /**
  56081. * Function: getCellValidationError
  56082. *
  56083. * Checks all <multiplicities> that cannot be enforced while the graph is
  56084. * being modified, namely, all multiplicities that require a minimum of
  56085. * 1 edge.
  56086. *
  56087. * Parameters:
  56088. *
  56089. * cell - <mxCell> for which the multiplicities should be checked.
  56090. */
  56091. mxGraph.prototype.getCellValidationError = function(cell)
  56092. {
  56093. var outCount = this.model.getDirectedEdgeCount(cell, true);
  56094. var inCount = this.model.getDirectedEdgeCount(cell, false);
  56095. var value = this.model.getValue(cell);
  56096. var error = '';
  56097. if (this.multiplicities != null)
  56098. {
  56099. for (var i = 0; i < this.multiplicities.length; i++)
  56100. {
  56101. var rule = this.multiplicities[i];
  56102. if (rule.source && mxUtils.isNode(value, rule.type,
  56103. rule.attr, rule.value) && (outCount > rule.max ||
  56104. outCount < rule.min))
  56105. {
  56106. error += rule.countError + '\n';
  56107. }
  56108. else if (!rule.source && mxUtils.isNode(value, rule.type,
  56109. rule.attr, rule.value) && (inCount > rule.max ||
  56110. inCount < rule.min))
  56111. {
  56112. error += rule.countError + '\n';
  56113. }
  56114. }
  56115. }
  56116. return (error.length > 0) ? error : null;
  56117. };
  56118. /**
  56119. * Function: validateCell
  56120. *
  56121. * Hook method for subclassers to return an error message for the given
  56122. * cell and validation context. This implementation returns null. Any HTML
  56123. * breaks will be converted to linefeeds in the calling method.
  56124. *
  56125. * Parameters:
  56126. *
  56127. * cell - <mxCell> that represents the cell to validate.
  56128. * context - Object that represents the global validation state.
  56129. */
  56130. mxGraph.prototype.validateCell = function(cell, context)
  56131. {
  56132. return null;
  56133. };
  56134. /**
  56135. * Group: Graph appearance
  56136. */
  56137. /**
  56138. * Function: getBackgroundImage
  56139. *
  56140. * Returns the <backgroundImage> as an <mxImage>.
  56141. */
  56142. mxGraph.prototype.getBackgroundImage = function()
  56143. {
  56144. return this.backgroundImage;
  56145. };
  56146. /**
  56147. * Function: setBackgroundImage
  56148. *
  56149. * Sets the new <backgroundImage>.
  56150. *
  56151. * Parameters:
  56152. *
  56153. * image - New <mxImage> to be used for the background.
  56154. */
  56155. mxGraph.prototype.setBackgroundImage = function(image)
  56156. {
  56157. this.backgroundImage = image;
  56158. };
  56159. /**
  56160. * Function: getFoldingImage
  56161. *
  56162. * Returns the <mxImage> used to display the collapsed state of
  56163. * the specified cell state. This returns null for all edges.
  56164. */
  56165. mxGraph.prototype.getFoldingImage = function(state)
  56166. {
  56167. if (state != null && this.foldingEnabled && !this.getModel().isEdge(state.cell))
  56168. {
  56169. var tmp = this.isCellCollapsed(state.cell);
  56170. if (this.isCellFoldable(state.cell, !tmp))
  56171. {
  56172. return (tmp) ? this.collapsedImage : this.expandedImage;
  56173. }
  56174. }
  56175. return null;
  56176. };
  56177. /**
  56178. * Function: convertValueToString
  56179. *
  56180. * Returns the textual representation for the given cell. This
  56181. * implementation returns the nodename or string-representation of the user
  56182. * object.
  56183. *
  56184. * Example:
  56185. *
  56186. * The following returns the label attribute from the cells user
  56187. * object if it is an XML node.
  56188. *
  56189. * (code)
  56190. * graph.convertValueToString = function(cell)
  56191. * {
  56192. * return cell.getAttribute('label');
  56193. * }
  56194. * (end)
  56195. *
  56196. * See also: <cellLabelChanged>.
  56197. *
  56198. * Parameters:
  56199. *
  56200. * cell - <mxCell> whose textual representation should be returned.
  56201. */
  56202. mxGraph.prototype.convertValueToString = function(cell)
  56203. {
  56204. var value = this.model.getValue(cell);
  56205. if (value != null)
  56206. {
  56207. if (mxUtils.isNode(value))
  56208. {
  56209. return value.nodeName;
  56210. }
  56211. else if (typeof(value.toString) == 'function')
  56212. {
  56213. return value.toString();
  56214. }
  56215. }
  56216. return '';
  56217. };
  56218. /**
  56219. * Function: getLabel
  56220. *
  56221. * Returns a string or DOM node that represents the label for the given
  56222. * cell. This implementation uses <convertValueToString> if <labelsVisible>
  56223. * is true. Otherwise it returns an empty string.
  56224. *
  56225. * To truncate a label to match the size of the cell, the following code
  56226. * can be used.
  56227. *
  56228. * (code)
  56229. * graph.getLabel = function(cell)
  56230. * {
  56231. * var label = mxGraph.prototype.getLabel.apply(this, arguments);
  56232. *
  56233. * if (label != null && this.model.isVertex(cell))
  56234. * {
  56235. * var geo = this.getCellGeometry(cell);
  56236. *
  56237. * if (geo != null)
  56238. * {
  56239. * var max = parseInt(geo.width / 8);
  56240. *
  56241. * if (label.length > max)
  56242. * {
  56243. * label = label.substring(0, max)+'...';
  56244. * }
  56245. * }
  56246. * }
  56247. * return mxUtils.htmlEntities(label);
  56248. * }
  56249. * (end)
  56250. *
  56251. * A resize listener is needed in the graph to force a repaint of the label
  56252. * after a resize.
  56253. *
  56254. * (code)
  56255. * graph.addListener(mxEvent.RESIZE_CELLS, function(sender, evt)
  56256. * {
  56257. * var cells = evt.getProperty('cells');
  56258. *
  56259. * for (var i = 0; i < cells.length; i++)
  56260. * {
  56261. * this.view.removeState(cells[i]);
  56262. * }
  56263. * });
  56264. * (end)
  56265. *
  56266. * Parameters:
  56267. *
  56268. * cell - <mxCell> whose label should be returned.
  56269. */
  56270. mxGraph.prototype.getLabel = function(cell)
  56271. {
  56272. var result = '';
  56273. if (this.labelsVisible && cell != null)
  56274. {
  56275. var style = this.getCurrentCellStyle(cell);
  56276. if (!mxUtils.getValue(style, mxConstants.STYLE_NOLABEL, false))
  56277. {
  56278. result = this.convertValueToString(cell);
  56279. }
  56280. }
  56281. return result;
  56282. };
  56283. /**
  56284. * Function: isHtmlLabel
  56285. *
  56286. * Returns true if the label must be rendered as HTML markup. The default
  56287. * implementation returns <htmlLabels>.
  56288. *
  56289. * Parameters:
  56290. *
  56291. * cell - <mxCell> whose label should be displayed as HTML markup.
  56292. */
  56293. mxGraph.prototype.isHtmlLabel = function(cell)
  56294. {
  56295. return this.isHtmlLabels();
  56296. };
  56297. /**
  56298. * Function: isHtmlLabels
  56299. *
  56300. * Returns <htmlLabels>.
  56301. */
  56302. mxGraph.prototype.isHtmlLabels = function()
  56303. {
  56304. return this.htmlLabels;
  56305. };
  56306. /**
  56307. * Function: setHtmlLabels
  56308. *
  56309. * Sets <htmlLabels>.
  56310. */
  56311. mxGraph.prototype.setHtmlLabels = function(value)
  56312. {
  56313. this.htmlLabels = value;
  56314. };
  56315. /**
  56316. * Function: isWrapping
  56317. *
  56318. * This enables wrapping for HTML labels.
  56319. *
  56320. * Returns true if no white-space CSS style directive should be used for
  56321. * displaying the given cells label. This implementation returns true if
  56322. * <mxConstants.STYLE_WHITE_SPACE> in the style of the given cell is 'wrap'.
  56323. *
  56324. * This is used as a workaround for IE ignoring the white-space directive
  56325. * of child elements if the directive appears in a parent element. It
  56326. * should be overridden to return true if a white-space directive is used
  56327. * in the HTML markup that represents the given cells label. In order for
  56328. * HTML markup to work in labels, <isHtmlLabel> must also return true
  56329. * for the given cell.
  56330. *
  56331. * Example:
  56332. *
  56333. * (code)
  56334. * graph.getLabel = function(cell)
  56335. * {
  56336. * var tmp = mxGraph.prototype.getLabel.apply(this, arguments); // "supercall"
  56337. *
  56338. * if (this.model.isEdge(cell))
  56339. * {
  56340. * tmp = '<div style="width: 150px; white-space:normal;">'+tmp+'</div>';
  56341. * }
  56342. *
  56343. * return tmp;
  56344. * }
  56345. *
  56346. * graph.isWrapping = function(state)
  56347. * {
  56348. * return this.model.isEdge(state.cell);
  56349. * }
  56350. * (end)
  56351. *
  56352. * Makes sure no edge label is wider than 150 pixels, otherwise the content
  56353. * is wrapped. Note: No width must be specified for wrapped vertex labels as
  56354. * the vertex defines the width in its geometry.
  56355. *
  56356. * Parameters:
  56357. *
  56358. * state - <mxCell> whose label should be wrapped.
  56359. */
  56360. mxGraph.prototype.isWrapping = function(cell)
  56361. {
  56362. return this.getCurrentCellStyle(cell)[mxConstants.STYLE_WHITE_SPACE] == 'wrap';
  56363. };
  56364. /**
  56365. * Function: isLabelClipped
  56366. *
  56367. * Returns true if the overflow portion of labels should be hidden. If this
  56368. * returns true then vertex labels will be clipped to the size of the vertices.
  56369. * This implementation returns true if <mxConstants.STYLE_OVERFLOW> in the
  56370. * style of the given cell is 'hidden'.
  56371. *
  56372. * Parameters:
  56373. *
  56374. * state - <mxCell> whose label should be clipped.
  56375. */
  56376. mxGraph.prototype.isLabelClipped = function(cell)
  56377. {
  56378. return this.getCurrentCellStyle(cell)[mxConstants.STYLE_OVERFLOW] == 'hidden';
  56379. };
  56380. /**
  56381. * Function: getTooltip
  56382. *
  56383. * Returns the string or DOM node that represents the tooltip for the given
  56384. * state, node and coordinate pair. This implementation checks if the given
  56385. * node is a folding icon or overlay and returns the respective tooltip. If
  56386. * this does not result in a tooltip, the handler for the cell is retrieved
  56387. * from <selectionCellsHandler> and the optional getTooltipForNode method is
  56388. * called. If no special tooltip exists here then <getTooltipForCell> is used
  56389. * with the cell in the given state as the argument to return a tooltip for the
  56390. * given state.
  56391. *
  56392. * Parameters:
  56393. *
  56394. * state - <mxCellState> whose tooltip should be returned.
  56395. * node - DOM node that is currently under the mouse.
  56396. * x - X-coordinate of the mouse.
  56397. * y - Y-coordinate of the mouse.
  56398. */
  56399. mxGraph.prototype.getTooltip = function(state, node, x, y)
  56400. {
  56401. var tip = null;
  56402. if (state != null)
  56403. {
  56404. // Checks if the mouse is over the folding icon
  56405. if (state.control != null && (node == state.control.node ||
  56406. node.parentNode == state.control.node))
  56407. {
  56408. tip = this.collapseExpandResource;
  56409. tip = mxUtils.htmlEntities(mxResources.get(tip) || tip).replace(/\\n/g, '<br>');
  56410. }
  56411. if (tip == null && state.overlays != null)
  56412. {
  56413. state.overlays.visit(function(id, shape)
  56414. {
  56415. // LATER: Exit loop if tip is not null
  56416. if (tip == null && (node == shape.node || node.parentNode == shape.node))
  56417. {
  56418. tip = shape.overlay.toString();
  56419. }
  56420. });
  56421. }
  56422. if (tip == null)
  56423. {
  56424. var handler = this.selectionCellsHandler.getHandler(state.cell);
  56425. if (handler != null && typeof(handler.getTooltipForNode) == 'function')
  56426. {
  56427. tip = handler.getTooltipForNode(node);
  56428. }
  56429. }
  56430. if (tip == null)
  56431. {
  56432. tip = this.getTooltipForCell(state.cell);
  56433. }
  56434. }
  56435. return tip;
  56436. };
  56437. /**
  56438. * Function: getTooltipForCell
  56439. *
  56440. * Returns the string or DOM node to be used as the tooltip for the given
  56441. * cell. This implementation uses the cells getTooltip function if it
  56442. * exists, or else it returns <convertValueToString> for the cell.
  56443. *
  56444. * Example:
  56445. *
  56446. * (code)
  56447. * graph.getTooltipForCell = function(cell)
  56448. * {
  56449. * return 'Hello, World!';
  56450. * }
  56451. * (end)
  56452. *
  56453. * Replaces all tooltips with the string Hello, World!
  56454. *
  56455. * Parameters:
  56456. *
  56457. * cell - <mxCell> whose tooltip should be returned.
  56458. */
  56459. mxGraph.prototype.getTooltipForCell = function(cell)
  56460. {
  56461. var tip = null;
  56462. if (cell != null && cell.getTooltip != null)
  56463. {
  56464. tip = cell.getTooltip();
  56465. }
  56466. else
  56467. {
  56468. tip = this.convertValueToString(cell);
  56469. }
  56470. return tip;
  56471. };
  56472. /**
  56473. * Function: getLinkForCell
  56474. *
  56475. * Returns the string to be used as the link for the given cell. This
  56476. * implementation returns null.
  56477. *
  56478. * Parameters:
  56479. *
  56480. * cell - <mxCell> whose tooltip should be returned.
  56481. */
  56482. mxGraph.prototype.getLinkForCell = function(cell)
  56483. {
  56484. return null;
  56485. };
  56486. /**
  56487. * Function: getCursorForMouseEvent
  56488. *
  56489. * Returns the cursor value to be used for the CSS of the shape for the
  56490. * given event. This implementation calls <getCursorForCell>.
  56491. *
  56492. * Parameters:
  56493. *
  56494. * me - <mxMouseEvent> whose cursor should be returned.
  56495. */
  56496. mxGraph.prototype.getCursorForMouseEvent = function(me)
  56497. {
  56498. return this.getCursorForCell(me.getCell());
  56499. };
  56500. /**
  56501. * Function: getCursorForCell
  56502. *
  56503. * Returns the cursor value to be used for the CSS of the shape for the
  56504. * given cell. This implementation returns null.
  56505. *
  56506. * Parameters:
  56507. *
  56508. * cell - <mxCell> whose cursor should be returned.
  56509. */
  56510. mxGraph.prototype.getCursorForCell = function(cell)
  56511. {
  56512. return null;
  56513. };
  56514. /**
  56515. * Function: getStartSize
  56516. *
  56517. * Returns the start size of the given swimlane, that is, the width or
  56518. * height of the part that contains the title, depending on the
  56519. * horizontal style. The return value is an <mxRectangle> with either
  56520. * width or height set as appropriate.
  56521. *
  56522. * Parameters:
  56523. *
  56524. * swimlane - <mxCell> whose start size should be returned.
  56525. * ignoreState - Optional boolean that specifies if cell state should be ignored.
  56526. */
  56527. mxGraph.prototype.getStartSize = function(swimlane, ignoreState)
  56528. {
  56529. var result = new mxRectangle();
  56530. var style = this.getCurrentCellStyle(swimlane, ignoreState);
  56531. var size = parseInt(mxUtils.getValue(style,
  56532. mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE));
  56533. if (mxUtils.getValue(style, mxConstants.STYLE_HORIZONTAL, true))
  56534. {
  56535. result.height = size;
  56536. }
  56537. else
  56538. {
  56539. result.width = size;
  56540. }
  56541. return result;
  56542. };
  56543. /**
  56544. * Function: getSwimlaneDirection
  56545. *
  56546. * Returns the direction for the given swimlane style.
  56547. */
  56548. mxGraph.prototype.getSwimlaneDirection = function(style)
  56549. {
  56550. var dir = mxUtils.getValue(style, mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);
  56551. var flipH = mxUtils.getValue(style, mxConstants.STYLE_FLIPH, 0) == 1;
  56552. var flipV = mxUtils.getValue(style, mxConstants.STYLE_FLIPV, 0) == 1;
  56553. var h = mxUtils.getValue(style, mxConstants.STYLE_HORIZONTAL, true);
  56554. var n = (h) ? 0 : 3;
  56555. if (dir == mxConstants.DIRECTION_NORTH)
  56556. {
  56557. n--;
  56558. }
  56559. else if (dir == mxConstants.DIRECTION_WEST)
  56560. {
  56561. n += 2;
  56562. }
  56563. else if (dir == mxConstants.DIRECTION_SOUTH)
  56564. {
  56565. n += 1;
  56566. }
  56567. var mod = mxUtils.mod(n, 2);
  56568. if (flipH && mod == 1)
  56569. {
  56570. n += 2;
  56571. }
  56572. if (flipV && mod == 0)
  56573. {
  56574. n += 2;
  56575. }
  56576. return [mxConstants.DIRECTION_NORTH, mxConstants.DIRECTION_EAST,
  56577. mxConstants.DIRECTION_SOUTH, mxConstants.DIRECTION_WEST]
  56578. [mxUtils.mod(n, 4)];
  56579. };
  56580. /**
  56581. * Function: getActualStartSize
  56582. *
  56583. * Returns the actual start size of the given swimlane taking into account
  56584. * direction and horizontal and vertial flip styles. The start size is
  56585. * returned as an <mxRectangle> where top, left, bottom, right start sizes
  56586. * are returned as x, y, height and width, respectively.
  56587. *
  56588. * Parameters:
  56589. *
  56590. * swimlane - <mxCell> whose start size should be returned.
  56591. * ignoreState - Optional boolean that specifies if cell state should be ignored.
  56592. */
  56593. mxGraph.prototype.getActualStartSize = function(swimlane, ignoreState)
  56594. {
  56595. var result = new mxRectangle();
  56596. if (this.isSwimlane(swimlane, ignoreState))
  56597. {
  56598. var style = this.getCurrentCellStyle(swimlane, ignoreState);
  56599. var size = parseInt(mxUtils.getValue(style, mxConstants.STYLE_STARTSIZE,
  56600. mxConstants.DEFAULT_STARTSIZE));
  56601. var dir = this.getSwimlaneDirection(style);
  56602. if (dir == mxConstants.DIRECTION_NORTH)
  56603. {
  56604. result.y = size;
  56605. }
  56606. else if (dir == mxConstants.DIRECTION_WEST)
  56607. {
  56608. result.x = size;
  56609. }
  56610. else if (dir == mxConstants.DIRECTION_SOUTH)
  56611. {
  56612. result.height = size;
  56613. }
  56614. else
  56615. {
  56616. result.width = size;
  56617. }
  56618. }
  56619. return result;
  56620. };
  56621. /**
  56622. * Function: getImage
  56623. *
  56624. * Returns the image URL for the given cell state. This implementation
  56625. * returns the value stored under <mxConstants.STYLE_IMAGE> in the cell
  56626. * style.
  56627. *
  56628. * Parameters:
  56629. *
  56630. * state - <mxCellState> whose image URL should be returned.
  56631. */
  56632. mxGraph.prototype.getImage = function(state)
  56633. {
  56634. return (state != null && state.style != null) ? state.style[mxConstants.STYLE_IMAGE] : null;
  56635. };
  56636. /**
  56637. * Function: isTransparentState
  56638. *
  56639. * Returns true if the given state has no stroke- or fillcolor and no image.
  56640. *
  56641. * Parameters:
  56642. *
  56643. * state - <mxCellState> to check.
  56644. */
  56645. mxGraph.prototype.isTransparentState = function(state)
  56646. {
  56647. var result = false;
  56648. if (state != null)
  56649. {
  56650. var stroke = mxUtils.getValue(state.style, mxConstants.STYLE_STROKECOLOR, mxConstants.NONE);
  56651. var fill = mxUtils.getValue(state.style, mxConstants.STYLE_FILLCOLOR, mxConstants.NONE);
  56652. result = stroke == mxConstants.NONE && fill == mxConstants.NONE && this.getImage(state) == null;
  56653. }
  56654. return result;
  56655. };
  56656. /**
  56657. * Function: getVerticalAlign
  56658. *
  56659. * Returns the vertical alignment for the given cell state. This
  56660. * implementation returns the value stored under
  56661. * <mxConstants.STYLE_VERTICAL_ALIGN> in the cell style.
  56662. *
  56663. * Parameters:
  56664. *
  56665. * state - <mxCellState> whose vertical alignment should be
  56666. * returned.
  56667. */
  56668. mxGraph.prototype.getVerticalAlign = function(state)
  56669. {
  56670. return (state != null && state.style != null) ?
  56671. (state.style[mxConstants.STYLE_VERTICAL_ALIGN] ||
  56672. mxConstants.ALIGN_MIDDLE) : null;
  56673. };
  56674. /**
  56675. * Function: getIndicatorColor
  56676. *
  56677. * Returns the indicator color for the given cell state. This
  56678. * implementation returns the value stored under
  56679. * <mxConstants.STYLE_INDICATOR_COLOR> in the cell style.
  56680. *
  56681. * Parameters:
  56682. *
  56683. * state - <mxCellState> whose indicator color should be
  56684. * returned.
  56685. */
  56686. mxGraph.prototype.getIndicatorColor = function(state)
  56687. {
  56688. return (state != null && state.style != null) ? state.style[mxConstants.STYLE_INDICATOR_COLOR] : null;
  56689. };
  56690. /**
  56691. * Function: getIndicatorGradientColor
  56692. *
  56693. * Returns the indicator gradient color for the given cell state. This
  56694. * implementation returns the value stored under
  56695. * <mxConstants.STYLE_INDICATOR_GRADIENTCOLOR> in the cell style.
  56696. *
  56697. * Parameters:
  56698. *
  56699. * state - <mxCellState> whose indicator gradient color should be
  56700. * returned.
  56701. */
  56702. mxGraph.prototype.getIndicatorGradientColor = function(state)
  56703. {
  56704. return (state != null && state.style != null) ? state.style[mxConstants.STYLE_INDICATOR_GRADIENTCOLOR] : null;
  56705. };
  56706. /**
  56707. * Function: getIndicatorShape
  56708. *
  56709. * Returns the indicator shape for the given cell state. This
  56710. * implementation returns the value stored under
  56711. * <mxConstants.STYLE_INDICATOR_SHAPE> in the cell style.
  56712. *
  56713. * Parameters:
  56714. *
  56715. * state - <mxCellState> whose indicator shape should be returned.
  56716. */
  56717. mxGraph.prototype.getIndicatorShape = function(state)
  56718. {
  56719. return (state != null && state.style != null) ? state.style[mxConstants.STYLE_INDICATOR_SHAPE] : null;
  56720. };
  56721. /**
  56722. * Function: getIndicatorImage
  56723. *
  56724. * Returns the indicator image for the given cell state. This
  56725. * implementation returns the value stored under
  56726. * <mxConstants.STYLE_INDICATOR_IMAGE> in the cell style.
  56727. *
  56728. * Parameters:
  56729. *
  56730. * state - <mxCellState> whose indicator image should be returned.
  56731. */
  56732. mxGraph.prototype.getIndicatorImage = function(state)
  56733. {
  56734. return (state != null && state.style != null) ? state.style[mxConstants.STYLE_INDICATOR_IMAGE] : null;
  56735. };
  56736. /**
  56737. * Function: getBorder
  56738. *
  56739. * Returns the value of <border>.
  56740. */
  56741. mxGraph.prototype.getBorder = function()
  56742. {
  56743. return this.border;
  56744. };
  56745. /**
  56746. * Function: setBorder
  56747. *
  56748. * Sets the value of <border>.
  56749. *
  56750. * Parameters:
  56751. *
  56752. * value - Positive integer that represents the border to be used.
  56753. */
  56754. mxGraph.prototype.setBorder = function(value)
  56755. {
  56756. this.border = value;
  56757. };
  56758. /**
  56759. * Function: isSwimlane
  56760. *
  56761. * Returns true if the given cell is a swimlane in the graph. A swimlane is
  56762. * a container cell with some specific behaviour. This implementation
  56763. * checks if the shape associated with the given cell is a <mxSwimlane>.
  56764. *
  56765. * Parameters:
  56766. *
  56767. * cell - <mxCell> to be checked.
  56768. * ignoreState - Optional boolean that specifies if the cell state should be ignored.
  56769. */
  56770. mxGraph.prototype.isSwimlane = function(cell, ignoreState)
  56771. {
  56772. if (cell != null && this.model.getParent(cell) != this.model.getRoot() &&
  56773. !this.model.isEdge(cell))
  56774. {
  56775. return this.getCurrentCellStyle(cell, ignoreState)
  56776. [mxConstants.STYLE_SHAPE] == mxConstants.SHAPE_SWIMLANE;
  56777. }
  56778. return false;
  56779. };
  56780. /**
  56781. * Group: Graph behaviour
  56782. */
  56783. /**
  56784. * Function: isResizeContainer
  56785. *
  56786. * Returns <resizeContainer>.
  56787. */
  56788. mxGraph.prototype.isResizeContainer = function()
  56789. {
  56790. return this.resizeContainer;
  56791. };
  56792. /**
  56793. * Function: setResizeContainer
  56794. *
  56795. * Sets <resizeContainer>.
  56796. *
  56797. * Parameters:
  56798. *
  56799. * value - Boolean indicating if the container should be resized.
  56800. */
  56801. mxGraph.prototype.setResizeContainer = function(value)
  56802. {
  56803. this.resizeContainer = value;
  56804. };
  56805. /**
  56806. * Function: isEnabled
  56807. *
  56808. * Returns true if the graph is <enabled>.
  56809. */
  56810. mxGraph.prototype.isEnabled = function()
  56811. {
  56812. return this.enabled;
  56813. };
  56814. /**
  56815. * Function: setEnabled
  56816. *
  56817. * Specifies if the graph should allow any interactions. This
  56818. * implementation updates <enabled>.
  56819. *
  56820. * Parameters:
  56821. *
  56822. * value - Boolean indicating if the graph should be enabled.
  56823. */
  56824. mxGraph.prototype.setEnabled = function(value)
  56825. {
  56826. this.enabled = value;
  56827. };
  56828. /**
  56829. * Function: isEscapeEnabled
  56830. *
  56831. * Returns <escapeEnabled>.
  56832. */
  56833. mxGraph.prototype.isEscapeEnabled = function()
  56834. {
  56835. return this.escapeEnabled;
  56836. };
  56837. /**
  56838. * Function: setEscapeEnabled
  56839. *
  56840. * Sets <escapeEnabled>.
  56841. *
  56842. * Parameters:
  56843. *
  56844. * enabled - Boolean indicating if escape should be enabled.
  56845. */
  56846. mxGraph.prototype.setEscapeEnabled = function(value)
  56847. {
  56848. this.escapeEnabled = value;
  56849. };
  56850. /**
  56851. * Function: isInvokesStopCellEditing
  56852. *
  56853. * Returns <invokesStopCellEditing>.
  56854. */
  56855. mxGraph.prototype.isInvokesStopCellEditing = function()
  56856. {
  56857. return this.invokesStopCellEditing;
  56858. };
  56859. /**
  56860. * Function: setInvokesStopCellEditing
  56861. *
  56862. * Sets <invokesStopCellEditing>.
  56863. */
  56864. mxGraph.prototype.setInvokesStopCellEditing = function(value)
  56865. {
  56866. this.invokesStopCellEditing = value;
  56867. };
  56868. /**
  56869. * Function: isEnterStopsCellEditing
  56870. *
  56871. * Returns <enterStopsCellEditing>.
  56872. */
  56873. mxGraph.prototype.isEnterStopsCellEditing = function()
  56874. {
  56875. return this.enterStopsCellEditing;
  56876. };
  56877. /**
  56878. * Function: setEnterStopsCellEditing
  56879. *
  56880. * Sets <enterStopsCellEditing>.
  56881. */
  56882. mxGraph.prototype.setEnterStopsCellEditing = function(value)
  56883. {
  56884. this.enterStopsCellEditing = value;
  56885. };
  56886. /**
  56887. * Function: isCellLocked
  56888. *
  56889. * Returns true if the given cell may not be moved, sized, bended,
  56890. * disconnected, edited or selected. This implementation returns true for
  56891. * all vertices with a relative geometry if <locked> is false.
  56892. *
  56893. * Parameters:
  56894. *
  56895. * cell - <mxCell> whose locked state should be returned.
  56896. */
  56897. mxGraph.prototype.isCellLocked = function(cell)
  56898. {
  56899. var geometry = this.model.getGeometry(cell);
  56900. return this.isCellsLocked() || (geometry != null && this.model.isVertex(cell) && geometry.relative);
  56901. };
  56902. /**
  56903. * Function: isCellsLocked
  56904. *
  56905. * Returns true if the given cell may not be moved, sized, bended,
  56906. * disconnected, edited or selected. This implementation returns true for
  56907. * all vertices with a relative geometry if <locked> is false.
  56908. *
  56909. * Parameters:
  56910. *
  56911. * cell - <mxCell> whose locked state should be returned.
  56912. */
  56913. mxGraph.prototype.isCellsLocked = function()
  56914. {
  56915. return this.cellsLocked;
  56916. };
  56917. /**
  56918. * Function: setCellsLocked
  56919. *
  56920. * Sets if any cell may be moved, sized, bended, disconnected, edited or
  56921. * selected.
  56922. *
  56923. * Parameters:
  56924. *
  56925. * value - Boolean that defines the new value for <cellsLocked>.
  56926. */
  56927. mxGraph.prototype.setCellsLocked = function(value)
  56928. {
  56929. this.cellsLocked = value;
  56930. };
  56931. /**
  56932. * Function: getCloneableCells
  56933. *
  56934. * Returns the cells which may be exported in the given array of cells.
  56935. */
  56936. mxGraph.prototype.getCloneableCells = function(cells)
  56937. {
  56938. return this.model.filterCells(cells, mxUtils.bind(this, function(cell)
  56939. {
  56940. return this.isCellCloneable(cell);
  56941. }));
  56942. };
  56943. /**
  56944. * Function: isCellCloneable
  56945. *
  56946. * Returns true if the given cell is cloneable. This implementation returns
  56947. * <isCellsCloneable> for all cells unless a cell style specifies
  56948. * <mxConstants.STYLE_CLONEABLE> to be 0.
  56949. *
  56950. * Parameters:
  56951. *
  56952. * cell - Optional <mxCell> whose cloneable state should be returned.
  56953. */
  56954. mxGraph.prototype.isCellCloneable = function(cell)
  56955. {
  56956. var style = this.getCurrentCellStyle(cell);
  56957. return this.isCellsCloneable() && style[mxConstants.STYLE_CLONEABLE] != 0;
  56958. };
  56959. /**
  56960. * Function: isCellsCloneable
  56961. *
  56962. * Returns <cellsCloneable>, that is, if the graph allows cloning of cells
  56963. * by using control-drag.
  56964. */
  56965. mxGraph.prototype.isCellsCloneable = function()
  56966. {
  56967. return this.cellsCloneable;
  56968. };
  56969. /**
  56970. * Function: setCellsCloneable
  56971. *
  56972. * Specifies if the graph should allow cloning of cells by holding down the
  56973. * control key while cells are being moved. This implementation updates
  56974. * <cellsCloneable>.
  56975. *
  56976. * Parameters:
  56977. *
  56978. * value - Boolean indicating if the graph should be cloneable.
  56979. */
  56980. mxGraph.prototype.setCellsCloneable = function(value)
  56981. {
  56982. this.cellsCloneable = value;
  56983. };
  56984. /**
  56985. * Function: getExportableCells
  56986. *
  56987. * Returns the cells which may be exported in the given array of cells.
  56988. */
  56989. mxGraph.prototype.getExportableCells = function(cells)
  56990. {
  56991. return this.model.filterCells(cells, mxUtils.bind(this, function(cell)
  56992. {
  56993. return this.canExportCell(cell);
  56994. }));
  56995. };
  56996. /**
  56997. * Function: canExportCell
  56998. *
  56999. * Returns true if the given cell may be exported to the clipboard. This
  57000. * implementation returns <exportEnabled> for all cells.
  57001. *
  57002. * Parameters:
  57003. *
  57004. * cell - <mxCell> that represents the cell to be exported.
  57005. */
  57006. mxGraph.prototype.canExportCell = function(cell)
  57007. {
  57008. return this.exportEnabled;
  57009. };
  57010. /**
  57011. * Function: getImportableCells
  57012. *
  57013. * Returns the cells which may be imported in the given array of cells.
  57014. */
  57015. mxGraph.prototype.getImportableCells = function(cells)
  57016. {
  57017. return this.model.filterCells(cells, mxUtils.bind(this, function(cell)
  57018. {
  57019. return this.canImportCell(cell);
  57020. }));
  57021. };
  57022. /**
  57023. * Function: canImportCell
  57024. *
  57025. * Returns true if the given cell may be imported from the clipboard.
  57026. * This implementation returns <importEnabled> for all cells.
  57027. *
  57028. * Parameters:
  57029. *
  57030. * cell - <mxCell> that represents the cell to be imported.
  57031. */
  57032. mxGraph.prototype.canImportCell = function(cell)
  57033. {
  57034. return this.importEnabled;
  57035. };
  57036. /**
  57037. * Function: isCellSelectable
  57038. *
  57039. * Returns true if the given cell is selectable. This implementation
  57040. * returns <cellsSelectable>.
  57041. *
  57042. * To add a new style for making cells (un)selectable, use the following code.
  57043. *
  57044. * (code)
  57045. * mxGraph.prototype.isCellSelectable = function(cell)
  57046. * {
  57047. * var style = this.getCurrentCellStyle(cell);
  57048. *
  57049. * return this.isCellsSelectable() && !this.isCellLocked(cell) && style['selectable'] != 0;
  57050. * };
  57051. * (end)
  57052. *
  57053. * You can then use the new style as shown in this example.
  57054. *
  57055. * (code)
  57056. * graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30, 'selectable=0');
  57057. * (end)
  57058. *
  57059. * Parameters:
  57060. *
  57061. * cell - <mxCell> whose selectable state should be returned.
  57062. */
  57063. mxGraph.prototype.isCellSelectable = function(cell)
  57064. {
  57065. return this.isCellsSelectable();
  57066. };
  57067. /**
  57068. * Function: isCellsSelectable
  57069. *
  57070. * Returns <cellsSelectable>.
  57071. */
  57072. mxGraph.prototype.isCellsSelectable = function()
  57073. {
  57074. return this.cellsSelectable;
  57075. };
  57076. /**
  57077. * Function: setCellsSelectable
  57078. *
  57079. * Sets <cellsSelectable>.
  57080. */
  57081. mxGraph.prototype.setCellsSelectable = function(value)
  57082. {
  57083. this.cellsSelectable = value;
  57084. };
  57085. /**
  57086. * Function: getDeletableCells
  57087. *
  57088. * Returns the cells which may be exported in the given array of cells.
  57089. */
  57090. mxGraph.prototype.getDeletableCells = function(cells)
  57091. {
  57092. return this.model.filterCells(cells, mxUtils.bind(this, function(cell)
  57093. {
  57094. return this.isCellDeletable(cell);
  57095. }));
  57096. };
  57097. /**
  57098. * Function: isCellDeletable
  57099. *
  57100. * Returns true if the given cell is moveable. This returns
  57101. * <cellsDeletable> for all given cells if a cells style does not specify
  57102. * <mxConstants.STYLE_DELETABLE> to be 0.
  57103. *
  57104. * Parameters:
  57105. *
  57106. * cell - <mxCell> whose deletable state should be returned.
  57107. */
  57108. mxGraph.prototype.isCellDeletable = function(cell)
  57109. {
  57110. var style = this.getCurrentCellStyle(cell);
  57111. return this.isCellsDeletable() && style[mxConstants.STYLE_DELETABLE] != 0;
  57112. };
  57113. /**
  57114. * Function: isCellsDeletable
  57115. *
  57116. * Returns <cellsDeletable>.
  57117. */
  57118. mxGraph.prototype.isCellsDeletable = function()
  57119. {
  57120. return this.cellsDeletable;
  57121. };
  57122. /**
  57123. * Function: setCellsDeletable
  57124. *
  57125. * Sets <cellsDeletable>.
  57126. *
  57127. * Parameters:
  57128. *
  57129. * value - Boolean indicating if the graph should allow deletion of cells.
  57130. */
  57131. mxGraph.prototype.setCellsDeletable = function(value)
  57132. {
  57133. this.cellsDeletable = value;
  57134. };
  57135. /**
  57136. * Function: isLabelMovable
  57137. *
  57138. * Returns true if the given edges's label is moveable. This returns
  57139. * <movable> for all given cells if <isLocked> does not return true
  57140. * for the given cell.
  57141. *
  57142. * Parameters:
  57143. *
  57144. * cell - <mxCell> whose label should be moved.
  57145. */
  57146. mxGraph.prototype.isLabelMovable = function(cell)
  57147. {
  57148. return !this.isCellLocked(cell) &&
  57149. ((this.model.isEdge(cell) && this.edgeLabelsMovable) ||
  57150. (this.model.isVertex(cell) && this.vertexLabelsMovable));
  57151. };
  57152. /**
  57153. * Function: isCellRotatable
  57154. *
  57155. * Returns true if the given cell is rotatable. This returns true for the given
  57156. * cell if its style does not specify <mxConstants.STYLE_ROTATABLE> to be 0.
  57157. *
  57158. * Parameters:
  57159. *
  57160. * cell - <mxCell> whose rotatable state should be returned.
  57161. */
  57162. mxGraph.prototype.isCellRotatable = function(cell)
  57163. {
  57164. var style = this.getCurrentCellStyle(cell);
  57165. return style[mxConstants.STYLE_ROTATABLE] != 0;
  57166. };
  57167. /**
  57168. * Function: getMovableCells
  57169. *
  57170. * Returns the cells which are movable in the given array of cells.
  57171. */
  57172. mxGraph.prototype.getMovableCells = function(cells)
  57173. {
  57174. return this.model.filterCells(cells, mxUtils.bind(this, function(cell)
  57175. {
  57176. return this.isCellMovable(cell);
  57177. }));
  57178. };
  57179. /**
  57180. * Function: isCellMovable
  57181. *
  57182. * Returns true if the given cell is moveable. This returns <cellsMovable>
  57183. * for all given cells if <isCellLocked> does not return true for the given
  57184. * cell and its style does not specify <mxConstants.STYLE_MOVABLE> to be 0.
  57185. *
  57186. * Parameters:
  57187. *
  57188. * cell - <mxCell> whose movable state should be returned.
  57189. */
  57190. mxGraph.prototype.isCellMovable = function(cell)
  57191. {
  57192. var style = this.getCurrentCellStyle(cell);
  57193. return this.isCellsMovable() && !this.isCellLocked(cell) && style[mxConstants.STYLE_MOVABLE] != 0;
  57194. };
  57195. /**
  57196. * Function: isCellsMovable
  57197. *
  57198. * Returns <cellsMovable>.
  57199. */
  57200. mxGraph.prototype.isCellsMovable = function()
  57201. {
  57202. return this.cellsMovable;
  57203. };
  57204. /**
  57205. * Function: setCellsMovable
  57206. *
  57207. * Specifies if the graph should allow moving of cells. This implementation
  57208. * updates <cellsMsovable>.
  57209. *
  57210. * Parameters:
  57211. *
  57212. * value - Boolean indicating if the graph should allow moving of cells.
  57213. */
  57214. mxGraph.prototype.setCellsMovable = function(value)
  57215. {
  57216. this.cellsMovable = value;
  57217. };
  57218. /**
  57219. * Function: isGridEnabled
  57220. *
  57221. * Returns <gridEnabled> as a boolean.
  57222. */
  57223. mxGraph.prototype.isGridEnabled = function()
  57224. {
  57225. return this.gridEnabled;
  57226. };
  57227. /**
  57228. * Function: setGridEnabled
  57229. *
  57230. * Specifies if the grid should be enabled.
  57231. *
  57232. * Parameters:
  57233. *
  57234. * value - Boolean indicating if the grid should be enabled.
  57235. */
  57236. mxGraph.prototype.setGridEnabled = function(value)
  57237. {
  57238. this.gridEnabled = value;
  57239. };
  57240. /**
  57241. * Function: isPortsEnabled
  57242. *
  57243. * Returns <portsEnabled> as a boolean.
  57244. */
  57245. mxGraph.prototype.isPortsEnabled = function()
  57246. {
  57247. return this.portsEnabled;
  57248. };
  57249. /**
  57250. * Function: setPortsEnabled
  57251. *
  57252. * Specifies if the ports should be enabled.
  57253. *
  57254. * Parameters:
  57255. *
  57256. * value - Boolean indicating if the ports should be enabled.
  57257. */
  57258. mxGraph.prototype.setPortsEnabled = function(value)
  57259. {
  57260. this.portsEnabled = value;
  57261. };
  57262. /**
  57263. * Function: getGridSize
  57264. *
  57265. * Returns <gridSize>.
  57266. */
  57267. mxGraph.prototype.getGridSize = function()
  57268. {
  57269. return this.gridSize;
  57270. };
  57271. /**
  57272. * Function: setGridSize
  57273. *
  57274. * Sets <gridSize>.
  57275. */
  57276. mxGraph.prototype.setGridSize = function(value)
  57277. {
  57278. this.gridSize = value;
  57279. };
  57280. /**
  57281. * Function: getTolerance
  57282. *
  57283. * Returns <tolerance>.
  57284. */
  57285. mxGraph.prototype.getTolerance = function()
  57286. {
  57287. return this.tolerance;
  57288. };
  57289. /**
  57290. * Function: setTolerance
  57291. *
  57292. * Sets <tolerance>.
  57293. */
  57294. mxGraph.prototype.setTolerance = function(value)
  57295. {
  57296. this.tolerance = value;
  57297. };
  57298. /**
  57299. * Function: isVertexLabelsMovable
  57300. *
  57301. * Returns <vertexLabelsMovable>.
  57302. */
  57303. mxGraph.prototype.isVertexLabelsMovable = function()
  57304. {
  57305. return this.vertexLabelsMovable;
  57306. };
  57307. /**
  57308. * Function: setVertexLabelsMovable
  57309. *
  57310. * Sets <vertexLabelsMovable>.
  57311. */
  57312. mxGraph.prototype.setVertexLabelsMovable = function(value)
  57313. {
  57314. this.vertexLabelsMovable = value;
  57315. };
  57316. /**
  57317. * Function: isEdgeLabelsMovable
  57318. *
  57319. * Returns <edgeLabelsMovable>.
  57320. */
  57321. mxGraph.prototype.isEdgeLabelsMovable = function()
  57322. {
  57323. return this.edgeLabelsMovable;
  57324. };
  57325. /**
  57326. * Function: isEdgeLabelsMovable
  57327. *
  57328. * Sets <edgeLabelsMovable>.
  57329. */
  57330. mxGraph.prototype.setEdgeLabelsMovable = function(value)
  57331. {
  57332. this.edgeLabelsMovable = value;
  57333. };
  57334. /**
  57335. * Function: isSwimlaneNesting
  57336. *
  57337. * Returns <swimlaneNesting> as a boolean.
  57338. */
  57339. mxGraph.prototype.isSwimlaneNesting = function()
  57340. {
  57341. return this.swimlaneNesting;
  57342. };
  57343. /**
  57344. * Function: setSwimlaneNesting
  57345. *
  57346. * Specifies if swimlanes can be nested by drag and drop. This is only
  57347. * taken into account if dropEnabled is true.
  57348. *
  57349. * Parameters:
  57350. *
  57351. * value - Boolean indicating if swimlanes can be nested.
  57352. */
  57353. mxGraph.prototype.setSwimlaneNesting = function(value)
  57354. {
  57355. this.swimlaneNesting = value;
  57356. };
  57357. /**
  57358. * Function: isSwimlaneSelectionEnabled
  57359. *
  57360. * Returns <swimlaneSelectionEnabled> as a boolean.
  57361. */
  57362. mxGraph.prototype.isSwimlaneSelectionEnabled = function()
  57363. {
  57364. return this.swimlaneSelectionEnabled;
  57365. };
  57366. /**
  57367. * Function: setSwimlaneSelectionEnabled
  57368. *
  57369. * Specifies if swimlanes should be selected if the mouse is released
  57370. * over their content area.
  57371. *
  57372. * Parameters:
  57373. *
  57374. * value - Boolean indicating if swimlanes content areas
  57375. * should be selected when the mouse is released over them.
  57376. */
  57377. mxGraph.prototype.setSwimlaneSelectionEnabled = function(value)
  57378. {
  57379. this.swimlaneSelectionEnabled = value;
  57380. };
  57381. /**
  57382. * Function: isMultigraph
  57383. *
  57384. * Returns <multigraph> as a boolean.
  57385. */
  57386. mxGraph.prototype.isMultigraph = function()
  57387. {
  57388. return this.multigraph;
  57389. };
  57390. /**
  57391. * Function: setMultigraph
  57392. *
  57393. * Specifies if the graph should allow multiple connections between the
  57394. * same pair of vertices.
  57395. *
  57396. * Parameters:
  57397. *
  57398. * value - Boolean indicating if the graph allows multiple connections
  57399. * between the same pair of vertices.
  57400. */
  57401. mxGraph.prototype.setMultigraph = function(value)
  57402. {
  57403. this.multigraph = value;
  57404. };
  57405. /**
  57406. * Function: isAllowLoops
  57407. *
  57408. * Returns <allowLoops> as a boolean.
  57409. */
  57410. mxGraph.prototype.isAllowLoops = function()
  57411. {
  57412. return this.allowLoops;
  57413. };
  57414. /**
  57415. * Function: setAllowDanglingEdges
  57416. *
  57417. * Specifies if dangling edges are allowed, that is, if edges are allowed
  57418. * that do not have a source and/or target terminal defined.
  57419. *
  57420. * Parameters:
  57421. *
  57422. * value - Boolean indicating if dangling edges are allowed.
  57423. */
  57424. mxGraph.prototype.setAllowDanglingEdges = function(value)
  57425. {
  57426. this.allowDanglingEdges = value;
  57427. };
  57428. /**
  57429. * Function: isAllowDanglingEdges
  57430. *
  57431. * Returns <allowDanglingEdges> as a boolean.
  57432. */
  57433. mxGraph.prototype.isAllowDanglingEdges = function()
  57434. {
  57435. return this.allowDanglingEdges;
  57436. };
  57437. /**
  57438. * Function: setConnectableEdges
  57439. *
  57440. * Specifies if edges should be connectable.
  57441. *
  57442. * Parameters:
  57443. *
  57444. * value - Boolean indicating if edges should be connectable.
  57445. */
  57446. mxGraph.prototype.setConnectableEdges = function(value)
  57447. {
  57448. this.connectableEdges = value;
  57449. };
  57450. /**
  57451. * Function: isConnectableEdges
  57452. *
  57453. * Returns <connectableEdges> as a boolean.
  57454. */
  57455. mxGraph.prototype.isConnectableEdges = function()
  57456. {
  57457. return this.connectableEdges;
  57458. };
  57459. /**
  57460. * Function: setCloneInvalidEdges
  57461. *
  57462. * Specifies if edges should be inserted when cloned but not valid wrt.
  57463. * <getEdgeValidationError>. If false such edges will be silently ignored.
  57464. *
  57465. * Parameters:
  57466. *
  57467. * value - Boolean indicating if cloned invalid edges should be
  57468. * inserted into the graph or ignored.
  57469. */
  57470. mxGraph.prototype.setCloneInvalidEdges = function(value)
  57471. {
  57472. this.cloneInvalidEdges = value;
  57473. };
  57474. /**
  57475. * Function: isCloneInvalidEdges
  57476. *
  57477. * Returns <cloneInvalidEdges> as a boolean.
  57478. */
  57479. mxGraph.prototype.isCloneInvalidEdges = function()
  57480. {
  57481. return this.cloneInvalidEdges;
  57482. };
  57483. /**
  57484. * Function: setAllowLoops
  57485. *
  57486. * Specifies if loops are allowed.
  57487. *
  57488. * Parameters:
  57489. *
  57490. * value - Boolean indicating if loops are allowed.
  57491. */
  57492. mxGraph.prototype.setAllowLoops = function(value)
  57493. {
  57494. this.allowLoops = value;
  57495. };
  57496. /**
  57497. * Function: isDisconnectOnMove
  57498. *
  57499. * Returns <disconnectOnMove> as a boolean.
  57500. */
  57501. mxGraph.prototype.isDisconnectOnMove = function()
  57502. {
  57503. return this.disconnectOnMove;
  57504. };
  57505. /**
  57506. * Function: setDisconnectOnMove
  57507. *
  57508. * Specifies if edges should be disconnected when moved. (Note: Cloned
  57509. * edges are always disconnected.)
  57510. *
  57511. * Parameters:
  57512. *
  57513. * value - Boolean indicating if edges should be disconnected
  57514. * when moved.
  57515. */
  57516. mxGraph.prototype.setDisconnectOnMove = function(value)
  57517. {
  57518. this.disconnectOnMove = value;
  57519. };
  57520. /**
  57521. * Function: isDropEnabled
  57522. *
  57523. * Returns <dropEnabled> as a boolean.
  57524. */
  57525. mxGraph.prototype.isDropEnabled = function()
  57526. {
  57527. return this.dropEnabled;
  57528. };
  57529. /**
  57530. * Function: setDropEnabled
  57531. *
  57532. * Specifies if the graph should allow dropping of cells onto or into other
  57533. * cells.
  57534. *
  57535. * Parameters:
  57536. *
  57537. * dropEnabled - Boolean indicating if the graph should allow dropping
  57538. * of cells into other cells.
  57539. */
  57540. mxGraph.prototype.setDropEnabled = function(value)
  57541. {
  57542. this.dropEnabled = value;
  57543. };
  57544. /**
  57545. * Function: isSplitEnabled
  57546. *
  57547. * Returns <splitEnabled> as a boolean.
  57548. */
  57549. mxGraph.prototype.isSplitEnabled = function()
  57550. {
  57551. return this.splitEnabled;
  57552. };
  57553. /**
  57554. * Function: setSplitEnabled
  57555. *
  57556. * Specifies if the graph should allow dropping of cells onto or into other
  57557. * cells.
  57558. *
  57559. * Parameters:
  57560. *
  57561. * dropEnabled - Boolean indicating if the graph should allow dropping
  57562. * of cells into other cells.
  57563. */
  57564. mxGraph.prototype.setSplitEnabled = function(value)
  57565. {
  57566. this.splitEnabled = value;
  57567. };
  57568. /**
  57569. * Function: isCellResizable
  57570. *
  57571. * Returns true if the given cell is resizable. This returns
  57572. * <cellsResizable> for all given cells if <isCellLocked> does not return
  57573. * true for the given cell and its style does not specify
  57574. * <mxConstants.STYLE_RESIZABLE> to be 0.
  57575. *
  57576. * Parameters:
  57577. *
  57578. * cell - <mxCell> whose resizable state should be returned.
  57579. */
  57580. mxGraph.prototype.isCellResizable = function(cell)
  57581. {
  57582. var style = this.getCurrentCellStyle(cell);
  57583. return this.isCellsResizable() && !this.isCellLocked(cell) &&
  57584. mxUtils.getValue(style, mxConstants.STYLE_RESIZABLE, '1') != '0';
  57585. };
  57586. /**
  57587. * Function: isCellsResizable
  57588. *
  57589. * Returns <cellsResizable>.
  57590. */
  57591. mxGraph.prototype.isCellsResizable = function()
  57592. {
  57593. return this.cellsResizable;
  57594. };
  57595. /**
  57596. * Function: setCellsResizable
  57597. *
  57598. * Specifies if the graph should allow resizing of cells. This
  57599. * implementation updates <cellsResizable>.
  57600. *
  57601. * Parameters:
  57602. *
  57603. * value - Boolean indicating if the graph should allow resizing of
  57604. * cells.
  57605. */
  57606. mxGraph.prototype.setCellsResizable = function(value)
  57607. {
  57608. this.cellsResizable = value;
  57609. };
  57610. /**
  57611. * Function: isTerminalPointMovable
  57612. *
  57613. * Returns true if the given terminal point is movable. This is independent
  57614. * from <isCellConnectable> and <isCellDisconnectable> and controls if terminal
  57615. * points can be moved in the graph if the edge is not connected. Note that it
  57616. * is required for this to return true to connect unconnected edges. This
  57617. * implementation returns true.
  57618. *
  57619. * Parameters:
  57620. *
  57621. * cell - <mxCell> whose terminal point should be moved.
  57622. * source - Boolean indicating if the source or target terminal should be moved.
  57623. */
  57624. mxGraph.prototype.isTerminalPointMovable = function(cell, source)
  57625. {
  57626. return true;
  57627. };
  57628. /**
  57629. * Function: isCellBendable
  57630. *
  57631. * Returns true if the given cell is bendable. This returns <cellsBendable>
  57632. * for all given cells if <isLocked> does not return true for the given
  57633. * cell and its style does not specify <mxConstants.STYLE_BENDABLE> to be 0.
  57634. *
  57635. * Parameters:
  57636. *
  57637. * cell - <mxCell> whose bendable state should be returned.
  57638. */
  57639. mxGraph.prototype.isCellBendable = function(cell)
  57640. {
  57641. var style = this.getCurrentCellStyle(cell);
  57642. return this.isCellsBendable() && !this.isCellLocked(cell) && style[mxConstants.STYLE_BENDABLE] != 0;
  57643. };
  57644. /**
  57645. * Function: isCellsBendable
  57646. *
  57647. * Returns <cellsBenadable>.
  57648. */
  57649. mxGraph.prototype.isCellsBendable = function()
  57650. {
  57651. return this.cellsBendable;
  57652. };
  57653. /**
  57654. * Function: setCellsBendable
  57655. *
  57656. * Specifies if the graph should allow bending of edges. This
  57657. * implementation updates <bendable>.
  57658. *
  57659. * Parameters:
  57660. *
  57661. * value - Boolean indicating if the graph should allow bending of
  57662. * edges.
  57663. */
  57664. mxGraph.prototype.setCellsBendable = function(value)
  57665. {
  57666. this.cellsBendable = value;
  57667. };
  57668. /**
  57669. * Function: isCellEditable
  57670. *
  57671. * Returns true if the given cell is editable. This returns <cellsEditable> for
  57672. * all given cells if <isCellLocked> does not return true for the given cell
  57673. * and its style does not specify <mxConstants.STYLE_EDITABLE> to be 0.
  57674. *
  57675. * Parameters:
  57676. *
  57677. * cell - <mxCell> whose editable state should be returned.
  57678. */
  57679. mxGraph.prototype.isCellEditable = function(cell)
  57680. {
  57681. var style = this.getCurrentCellStyle(cell);
  57682. return this.isCellsEditable() && !this.isCellLocked(cell) && style[mxConstants.STYLE_EDITABLE] != 0;
  57683. };
  57684. /**
  57685. * Function: isCellsEditable
  57686. *
  57687. * Returns <cellsEditable>.
  57688. */
  57689. mxGraph.prototype.isCellsEditable = function()
  57690. {
  57691. return this.cellsEditable;
  57692. };
  57693. /**
  57694. * Function: setCellsEditable
  57695. *
  57696. * Specifies if the graph should allow in-place editing for cell labels.
  57697. * This implementation updates <cellsEditable>.
  57698. *
  57699. * Parameters:
  57700. *
  57701. * value - Boolean indicating if the graph should allow in-place
  57702. * editing.
  57703. */
  57704. mxGraph.prototype.setCellsEditable = function(value)
  57705. {
  57706. this.cellsEditable = value;
  57707. };
  57708. /**
  57709. * Function: isCellDisconnectable
  57710. *
  57711. * Returns true if the given cell is disconnectable from the source or
  57712. * target terminal. This returns <isCellsDisconnectable> for all given
  57713. * cells if <isCellLocked> does not return true for the given cell.
  57714. *
  57715. * Parameters:
  57716. *
  57717. * cell - <mxCell> whose disconnectable state should be returned.
  57718. * terminal - <mxCell> that represents the source or target terminal.
  57719. * source - Boolean indicating if the source or target terminal is to be
  57720. * disconnected.
  57721. */
  57722. mxGraph.prototype.isCellDisconnectable = function(cell, terminal, source)
  57723. {
  57724. return this.isCellsDisconnectable() && !this.isCellLocked(cell);
  57725. };
  57726. /**
  57727. * Function: isCellsDisconnectable
  57728. *
  57729. * Returns <cellsDisconnectable>.
  57730. */
  57731. mxGraph.prototype.isCellsDisconnectable = function()
  57732. {
  57733. return this.cellsDisconnectable;
  57734. };
  57735. /**
  57736. * Function: setCellsDisconnectable
  57737. *
  57738. * Sets <cellsDisconnectable>.
  57739. */
  57740. mxGraph.prototype.setCellsDisconnectable = function(value)
  57741. {
  57742. this.cellsDisconnectable = value;
  57743. };
  57744. /**
  57745. * Function: isValidSource
  57746. *
  57747. * Returns true if the given cell is a valid source for new connections.
  57748. * This implementation returns true for all non-null values and is
  57749. * called by is called by <isValidConnection>.
  57750. *
  57751. * Parameters:
  57752. *
  57753. * cell - <mxCell> that represents a possible source or null.
  57754. */
  57755. mxGraph.prototype.isValidSource = function(cell)
  57756. {
  57757. return (cell == null && this.allowDanglingEdges) ||
  57758. (cell != null && (!this.model.isEdge(cell) ||
  57759. this.connectableEdges) && this.isCellConnectable(cell));
  57760. };
  57761. /**
  57762. * Function: isValidTarget
  57763. *
  57764. * Returns <isValidSource> for the given cell. This is called by
  57765. * <isValidConnection>.
  57766. *
  57767. * Parameters:
  57768. *
  57769. * cell - <mxCell> that represents a possible target or null.
  57770. */
  57771. mxGraph.prototype.isValidTarget = function(cell)
  57772. {
  57773. return this.isValidSource(cell);
  57774. };
  57775. /**
  57776. * Function: isValidConnection
  57777. *
  57778. * Returns true if the given target cell is a valid target for source.
  57779. * This is a boolean implementation for not allowing connections between
  57780. * certain pairs of vertices and is called by <getEdgeValidationError>.
  57781. * This implementation returns true if <isValidSource> returns true for
  57782. * the source and <isValidTarget> returns true for the target.
  57783. *
  57784. * Parameters:
  57785. *
  57786. * source - <mxCell> that represents the source cell.
  57787. * target - <mxCell> that represents the target cell.
  57788. */
  57789. mxGraph.prototype.isValidConnection = function(source, target)
  57790. {
  57791. return this.isValidSource(source) && this.isValidTarget(target);
  57792. };
  57793. /**
  57794. * Function: setConnectable
  57795. *
  57796. * Specifies if the graph should allow new connections. This implementation
  57797. * updates <mxConnectionHandler.enabled> in <connectionHandler>.
  57798. *
  57799. * Parameters:
  57800. *
  57801. * connectable - Boolean indicating if new connections should be allowed.
  57802. */
  57803. mxGraph.prototype.setConnectable = function(connectable)
  57804. {
  57805. this.connectionHandler.setEnabled(connectable);
  57806. };
  57807. /**
  57808. * Function: isConnectable
  57809. *
  57810. * Returns true if the <connectionHandler> is enabled.
  57811. */
  57812. mxGraph.prototype.isConnectable = function()
  57813. {
  57814. return this.connectionHandler.isEnabled();
  57815. };
  57816. /**
  57817. * Function: setTooltips
  57818. *
  57819. * Specifies if tooltips should be enabled. This implementation updates
  57820. * <mxTooltipHandler.enabled> in <tooltipHandler>.
  57821. *
  57822. * Parameters:
  57823. *
  57824. * enabled - Boolean indicating if tooltips should be enabled.
  57825. */
  57826. mxGraph.prototype.setTooltips = function (enabled)
  57827. {
  57828. this.tooltipHandler.setEnabled(enabled);
  57829. };
  57830. /**
  57831. * Function: setPanning
  57832. *
  57833. * Specifies if panning should be enabled. This implementation updates
  57834. * <mxPanningHandler.panningEnabled> in <panningHandler>.
  57835. *
  57836. * Parameters:
  57837. *
  57838. * enabled - Boolean indicating if panning should be enabled.
  57839. */
  57840. mxGraph.prototype.setPanning = function(enabled)
  57841. {
  57842. this.panningHandler.panningEnabled = enabled;
  57843. };
  57844. /**
  57845. * Function: isEditing
  57846. *
  57847. * Returns true if the given cell is currently being edited.
  57848. * If no cell is specified then this returns true if any
  57849. * cell is currently being edited.
  57850. *
  57851. * Parameters:
  57852. *
  57853. * cell - <mxCell> that should be checked.
  57854. */
  57855. mxGraph.prototype.isEditing = function(cell)
  57856. {
  57857. if (this.cellEditor != null)
  57858. {
  57859. var editingCell = this.cellEditor.getEditingCell();
  57860. return (cell == null) ? editingCell != null : cell == editingCell;
  57861. }
  57862. return false;
  57863. };
  57864. /**
  57865. * Function: isAutoSizeCell
  57866. *
  57867. * Returns true if the size of the given cell should automatically be
  57868. * updated after a change of the label. This implementation returns
  57869. * <autoSizeCells> or checks if the cell style does specify
  57870. * <mxConstants.STYLE_AUTOSIZE> to be 1.
  57871. *
  57872. * Parameters:
  57873. *
  57874. * cell - <mxCell> that should be resized.
  57875. */
  57876. mxGraph.prototype.isAutoSizeCell = function(cell)
  57877. {
  57878. var style = this.getCurrentCellStyle(cell);
  57879. return this.isAutoSizeCells() || style[mxConstants.STYLE_AUTOSIZE] == 1;
  57880. };
  57881. /**
  57882. * Function: isAutoSizeCells
  57883. *
  57884. * Returns <autoSizeCells>.
  57885. */
  57886. mxGraph.prototype.isAutoSizeCells = function()
  57887. {
  57888. return this.autoSizeCells;
  57889. };
  57890. /**
  57891. * Function: setAutoSizeCells
  57892. *
  57893. * Specifies if cell sizes should be automatically updated after a label
  57894. * change. This implementation sets <autoSizeCells> to the given parameter.
  57895. * To update the size of cells when the cells are added, set
  57896. * <autoSizeCellsOnAdd> to true.
  57897. *
  57898. * Parameters:
  57899. *
  57900. * value - Boolean indicating if cells should be resized
  57901. * automatically.
  57902. */
  57903. mxGraph.prototype.setAutoSizeCells = function(value)
  57904. {
  57905. this.autoSizeCells = value;
  57906. };
  57907. /**
  57908. * Function: isExtendParent
  57909. *
  57910. * Returns true if the parent of the given cell should be extended if the
  57911. * child has been resized so that it overlaps the parent. This
  57912. * implementation returns <isExtendParents> if the cell is not an edge.
  57913. *
  57914. * Parameters:
  57915. *
  57916. * cell - <mxCell> that has been resized.
  57917. */
  57918. mxGraph.prototype.isExtendParent = function(cell)
  57919. {
  57920. return !this.getModel().isEdge(cell) && this.isExtendParents();
  57921. };
  57922. /**
  57923. * Function: isExtendParents
  57924. *
  57925. * Returns <extendParents>.
  57926. */
  57927. mxGraph.prototype.isExtendParents = function()
  57928. {
  57929. return this.extendParents;
  57930. };
  57931. /**
  57932. * Function: setExtendParents
  57933. *
  57934. * Sets <extendParents>.
  57935. *
  57936. * Parameters:
  57937. *
  57938. * value - New boolean value for <extendParents>.
  57939. */
  57940. mxGraph.prototype.setExtendParents = function(value)
  57941. {
  57942. this.extendParents = value;
  57943. };
  57944. /**
  57945. * Function: isExtendParentsOnAdd
  57946. *
  57947. * Returns <extendParentsOnAdd>.
  57948. */
  57949. mxGraph.prototype.isExtendParentsOnAdd = function(cell)
  57950. {
  57951. return this.extendParentsOnAdd;
  57952. };
  57953. /**
  57954. * Function: setExtendParentsOnAdd
  57955. *
  57956. * Sets <extendParentsOnAdd>.
  57957. *
  57958. * Parameters:
  57959. *
  57960. * value - New boolean value for <extendParentsOnAdd>.
  57961. */
  57962. mxGraph.prototype.setExtendParentsOnAdd = function(value)
  57963. {
  57964. this.extendParentsOnAdd = value;
  57965. };
  57966. /**
  57967. * Function: isExtendParentsOnMove
  57968. *
  57969. * Returns <extendParentsOnMove>.
  57970. */
  57971. mxGraph.prototype.isExtendParentsOnMove = function()
  57972. {
  57973. return this.extendParentsOnMove;
  57974. };
  57975. /**
  57976. * Function: setExtendParentsOnMove
  57977. *
  57978. * Sets <extendParentsOnMove>.
  57979. *
  57980. * Parameters:
  57981. *
  57982. * value - New boolean value for <extendParentsOnAdd>.
  57983. */
  57984. mxGraph.prototype.setExtendParentsOnMove = function(value)
  57985. {
  57986. this.extendParentsOnMove = value;
  57987. };
  57988. /**
  57989. * Function: isRecursiveResize
  57990. *
  57991. * Returns <recursiveResize>.
  57992. *
  57993. * Parameters:
  57994. *
  57995. * state - <mxCellState> that is being resized.
  57996. */
  57997. mxGraph.prototype.isRecursiveResize = function(state)
  57998. {
  57999. return this.recursiveResize;
  58000. };
  58001. /**
  58002. * Function: setRecursiveResize
  58003. *
  58004. * Sets <recursiveResize>.
  58005. *
  58006. * Parameters:
  58007. *
  58008. * value - New boolean value for <recursiveResize>.
  58009. */
  58010. mxGraph.prototype.setRecursiveResize = function(value)
  58011. {
  58012. this.recursiveResize = value;
  58013. };
  58014. /**
  58015. * Function: isConstrainChild
  58016. *
  58017. * Returns true if the given cell should be kept inside the bounds of its
  58018. * parent according to the rules defined by <getOverlap> and
  58019. * <isAllowOverlapParent>. This implementation returns false for all children
  58020. * of edges and <isConstrainChildren> otherwise.
  58021. *
  58022. * Parameters:
  58023. *
  58024. * cell - <mxCell> that should be constrained.
  58025. */
  58026. mxGraph.prototype.isConstrainChild = function(cell)
  58027. {
  58028. return this.isConstrainChildren() && !this.getModel().isEdge(this.getModel().getParent(cell));
  58029. };
  58030. /**
  58031. * Function: isConstrainChildren
  58032. *
  58033. * Returns <constrainChildren>.
  58034. */
  58035. mxGraph.prototype.isConstrainChildren = function()
  58036. {
  58037. return this.constrainChildren;
  58038. };
  58039. /**
  58040. * Function: setConstrainChildren
  58041. *
  58042. * Sets <constrainChildren>.
  58043. */
  58044. mxGraph.prototype.setConstrainChildren = function(value)
  58045. {
  58046. this.constrainChildren = value;
  58047. };
  58048. /**
  58049. * Function: isConstrainRelativeChildren
  58050. *
  58051. * Returns <constrainRelativeChildren>.
  58052. */
  58053. mxGraph.prototype.isConstrainRelativeChildren = function()
  58054. {
  58055. return this.constrainRelativeChildren;
  58056. };
  58057. /**
  58058. * Function: setConstrainRelativeChildren
  58059. *
  58060. * Sets <constrainRelativeChildren>.
  58061. */
  58062. mxGraph.prototype.setConstrainRelativeChildren = function(value)
  58063. {
  58064. this.constrainRelativeChildren = value;
  58065. };
  58066. /**
  58067. * Function: isConstrainChildren
  58068. *
  58069. * Returns <allowNegativeCoordinates>.
  58070. */
  58071. mxGraph.prototype.isAllowNegativeCoordinates = function()
  58072. {
  58073. return this.allowNegativeCoordinates;
  58074. };
  58075. /**
  58076. * Function: setConstrainChildren
  58077. *
  58078. * Sets <allowNegativeCoordinates>.
  58079. */
  58080. mxGraph.prototype.setAllowNegativeCoordinates = function(value)
  58081. {
  58082. this.allowNegativeCoordinates = value;
  58083. };
  58084. /**
  58085. * Function: getOverlap
  58086. *
  58087. * Returns a decimal number representing the amount of the width and height
  58088. * of the given cell that is allowed to overlap its parent. A value of 0
  58089. * means all children must stay inside the parent, 1 means the child is
  58090. * allowed to be placed outside of the parent such that it touches one of
  58091. * the parents sides. If <isAllowOverlapParent> returns false for the given
  58092. * cell, then this method returns 0.
  58093. *
  58094. * Parameters:
  58095. *
  58096. * cell - <mxCell> for which the overlap ratio should be returned.
  58097. */
  58098. mxGraph.prototype.getOverlap = function(cell)
  58099. {
  58100. return (this.isAllowOverlapParent(cell)) ? this.defaultOverlap : 0;
  58101. };
  58102. /**
  58103. * Function: isAllowOverlapParent
  58104. *
  58105. * Returns true if the given cell is allowed to be placed outside of the
  58106. * parents area.
  58107. *
  58108. * Parameters:
  58109. *
  58110. * cell - <mxCell> that represents the child to be checked.
  58111. */
  58112. mxGraph.prototype.isAllowOverlapParent = function(cell)
  58113. {
  58114. return false;
  58115. };
  58116. /**
  58117. * Function: getFoldableCells
  58118. *
  58119. * Returns the cells which are movable in the given array of cells.
  58120. */
  58121. mxGraph.prototype.getFoldableCells = function(cells, collapse)
  58122. {
  58123. return this.model.filterCells(cells, mxUtils.bind(this, function(cell)
  58124. {
  58125. return this.isCellFoldable(cell, collapse);
  58126. }));
  58127. };
  58128. /**
  58129. * Function: isCellFoldable
  58130. *
  58131. * Returns true if the given cell is foldable. This implementation
  58132. * returns true if the cell has at least one child and its style
  58133. * does not specify <mxConstants.STYLE_FOLDABLE> to be 0.
  58134. *
  58135. * Parameters:
  58136. *
  58137. * cell - <mxCell> whose foldable state should be returned.
  58138. */
  58139. mxGraph.prototype.isCellFoldable = function(cell, collapse)
  58140. {
  58141. var style = this.getCurrentCellStyle(cell);
  58142. return this.model.getChildCount(cell) > 0 && style[mxConstants.STYLE_FOLDABLE] != 0;
  58143. };
  58144. /**
  58145. * Function: isValidDropTarget
  58146. *
  58147. * Returns true if the given cell is a valid drop target for the specified
  58148. * cells. If <splitEnabled> is true then this returns <isSplitTarget> for
  58149. * the given arguments else it returns true if the cell is not collapsed
  58150. * and its child count is greater than 0.
  58151. *
  58152. * Parameters:
  58153. *
  58154. * cell - <mxCell> that represents the possible drop target.
  58155. * cells - <mxCells> that should be dropped into the target.
  58156. * evt - Mouseevent that triggered the invocation.
  58157. */
  58158. mxGraph.prototype.isValidDropTarget = function(cell, cells, evt)
  58159. {
  58160. return cell != null && ((this.isSplitEnabled() &&
  58161. this.isSplitTarget(cell, cells, evt)) || (!this.model.isEdge(cell) &&
  58162. (this.isSwimlane(cell) || (this.model.getChildCount(cell) > 0 &&
  58163. !this.isCellCollapsed(cell)))));
  58164. };
  58165. /**
  58166. * Function: isSplitTarget
  58167. *
  58168. * Returns true if the given edge may be splitted into two edges with the
  58169. * given cell as a new terminal between the two.
  58170. *
  58171. * Parameters:
  58172. *
  58173. * target - <mxCell> that represents the edge to be splitted.
  58174. * cells - <mxCells> that should split the edge.
  58175. * evt - Mouseevent that triggered the invocation.
  58176. */
  58177. mxGraph.prototype.isSplitTarget = function(target, cells, evt)
  58178. {
  58179. if (this.model.isEdge(target) && cells != null && cells.length == 1 &&
  58180. this.isCellConnectable(cells[0]) && this.getEdgeValidationError(target,
  58181. this.model.getTerminal(target, true), cells[0]) == null)
  58182. {
  58183. var src = this.model.getTerminal(target, true);
  58184. var trg = this.model.getTerminal(target, false);
  58185. return (!this.model.isAncestor(cells[0], src) &&
  58186. !this.model.isAncestor(cells[0], trg));
  58187. }
  58188. return false;
  58189. };
  58190. /**
  58191. * Function: getDropTarget
  58192. *
  58193. * Returns the given cell if it is a drop target for the given cells or the
  58194. * nearest ancestor that may be used as a drop target for the given cells.
  58195. * If the given array contains a swimlane and <swimlaneNesting> is false
  58196. * then this always returns null. If no cell is given, then the bottommost
  58197. * swimlane at the location of the given event is returned.
  58198. *
  58199. * This function should only be used if <isDropEnabled> returns true.
  58200. *
  58201. * Parameters:
  58202. *
  58203. * cells - Array of <mxCells> which are to be dropped onto the target.
  58204. * evt - Mouseevent for the drag and drop.
  58205. * cell - <mxCell> that is under the mousepointer.
  58206. * clone - Optional boolean to indicate of cells will be cloned.
  58207. */
  58208. mxGraph.prototype.getDropTarget = function(cells, evt, cell, clone)
  58209. {
  58210. if (!this.isSwimlaneNesting())
  58211. {
  58212. for (var i = 0; i < cells.length; i++)
  58213. {
  58214. if (this.isSwimlane(cells[i]))
  58215. {
  58216. return null;
  58217. }
  58218. }
  58219. }
  58220. var pt = mxUtils.convertPoint(this.container,
  58221. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  58222. pt.x -= this.panDx;
  58223. pt.y -= this.panDy;
  58224. var swimlane = this.getSwimlaneAt(pt.x, pt.y);
  58225. if (cell == null)
  58226. {
  58227. cell = swimlane;
  58228. }
  58229. else if (swimlane != null)
  58230. {
  58231. // Checks if the cell is an ancestor of the swimlane
  58232. // under the mouse and uses the swimlane in that case
  58233. var tmp = this.model.getParent(swimlane);
  58234. while (tmp != null && this.isSwimlane(tmp) && tmp != cell)
  58235. {
  58236. tmp = this.model.getParent(tmp);
  58237. }
  58238. if (tmp == cell)
  58239. {
  58240. cell = swimlane;
  58241. }
  58242. }
  58243. while (cell != null && !this.isValidDropTarget(cell, cells, evt) &&
  58244. !this.model.isLayer(cell))
  58245. {
  58246. cell = this.model.getParent(cell);
  58247. }
  58248. // Checks if parent is dropped into child if not cloning
  58249. if (clone == null || !clone)
  58250. {
  58251. var parent = cell;
  58252. while (parent != null && mxUtils.indexOf(cells, parent) < 0)
  58253. {
  58254. parent = this.model.getParent(parent);
  58255. }
  58256. }
  58257. return (!this.model.isLayer(cell) && parent == null) ? cell : null;
  58258. };
  58259. /**
  58260. * Group: Cell retrieval
  58261. */
  58262. /**
  58263. * Function: getDefaultParent
  58264. *
  58265. * Returns <defaultParent> or <mxGraphView.currentRoot> or the first child
  58266. * child of <mxGraphModel.root> if both are null. The value returned by
  58267. * this function should be used as the parent for new cells (aka default
  58268. * layer).
  58269. */
  58270. mxGraph.prototype.getDefaultParent = function()
  58271. {
  58272. var parent = this.getCurrentRoot();
  58273. if (parent == null)
  58274. {
  58275. parent = this.defaultParent;
  58276. if (parent == null)
  58277. {
  58278. var root = this.model.getRoot();
  58279. parent = this.model.getChildAt(root, 0);
  58280. }
  58281. }
  58282. return parent;
  58283. };
  58284. /**
  58285. * Function: setDefaultParent
  58286. *
  58287. * Sets the <defaultParent> to the given cell. Set this to null to return
  58288. * the first child of the root in getDefaultParent.
  58289. */
  58290. mxGraph.prototype.setDefaultParent = function(cell)
  58291. {
  58292. this.defaultParent = cell;
  58293. };
  58294. /**
  58295. * Function: getSwimlane
  58296. *
  58297. * Returns the nearest ancestor of the given cell which is a swimlane, or
  58298. * the given cell, if it is itself a swimlane.
  58299. *
  58300. * Parameters:
  58301. *
  58302. * cell - <mxCell> for which the ancestor swimlane should be returned.
  58303. */
  58304. mxGraph.prototype.getSwimlane = function(cell)
  58305. {
  58306. while (cell != null && !this.isSwimlane(cell))
  58307. {
  58308. cell = this.model.getParent(cell);
  58309. }
  58310. return cell;
  58311. };
  58312. /**
  58313. * Function: getSwimlaneAt
  58314. *
  58315. * Returns the bottom-most swimlane that intersects the given point (x, y)
  58316. * in the cell hierarchy that starts at the given parent.
  58317. *
  58318. * Parameters:
  58319. *
  58320. * x - X-coordinate of the location to be checked.
  58321. * y - Y-coordinate of the location to be checked.
  58322. * parent - <mxCell> that should be used as the root of the recursion.
  58323. * Default is <defaultParent>.
  58324. */
  58325. mxGraph.prototype.getSwimlaneAt = function (x, y, parent)
  58326. {
  58327. if (parent == null)
  58328. {
  58329. parent = this.getCurrentRoot();
  58330. if (parent == null)
  58331. {
  58332. parent = this.model.getRoot();
  58333. }
  58334. }
  58335. if (parent != null)
  58336. {
  58337. var childCount = this.model.getChildCount(parent);
  58338. for (var i = 0; i < childCount; i++)
  58339. {
  58340. var child = this.model.getChildAt(parent, i);
  58341. if (child != null)
  58342. {
  58343. var result = this.getSwimlaneAt(x, y, child);
  58344. if (result != null)
  58345. {
  58346. return result;
  58347. }
  58348. else if (this.isCellVisible(child) && this.isSwimlane(child))
  58349. {
  58350. var state = this.view.getState(child);
  58351. if (this.intersects(state, x, y))
  58352. {
  58353. return child;
  58354. }
  58355. }
  58356. }
  58357. }
  58358. }
  58359. return null;
  58360. };
  58361. /**
  58362. * Function: getCellAt
  58363. *
  58364. * Returns the bottom-most cell that intersects the given point (x, y) in
  58365. * the cell hierarchy starting at the given parent. This will also return
  58366. * swimlanes if the given location intersects the content area of the
  58367. * swimlane. If this is not desired, then the <hitsSwimlaneContent> may be
  58368. * used if the returned cell is a swimlane to determine if the location
  58369. * is inside the content area or on the actual title of the swimlane.
  58370. *
  58371. * Parameters:
  58372. *
  58373. * x - X-coordinate of the location to be checked.
  58374. * y - Y-coordinate of the location to be checked.
  58375. * parent - <mxCell> that should be used as the root of the recursion.
  58376. * Default is current root of the view or the root of the model.
  58377. * vertices - Optional boolean indicating if vertices should be returned.
  58378. * Default is true.
  58379. * edges - Optional boolean indicating if edges should be returned. Default
  58380. * is true.
  58381. * ignoreFn - Optional function that returns true if cell should be ignored.
  58382. * The function is passed the cell state and the x and y parameter.
  58383. */
  58384. mxGraph.prototype.getCellAt = function(x, y, parent, vertices, edges, ignoreFn)
  58385. {
  58386. vertices = (vertices != null) ? vertices : true;
  58387. edges = (edges != null) ? edges : true;
  58388. if (parent == null)
  58389. {
  58390. parent = this.getCurrentRoot();
  58391. if (parent == null)
  58392. {
  58393. parent = this.getModel().getRoot();
  58394. }
  58395. }
  58396. if (parent != null)
  58397. {
  58398. var childCount = this.model.getChildCount(parent);
  58399. for (var i = childCount - 1; i >= 0; i--)
  58400. {
  58401. var cell = this.model.getChildAt(parent, i);
  58402. var result = this.getCellAt(x, y, cell, vertices, edges, ignoreFn);
  58403. if (result != null)
  58404. {
  58405. return result;
  58406. }
  58407. else if (this.isCellVisible(cell) && (edges && this.model.isEdge(cell) ||
  58408. vertices && this.model.isVertex(cell)))
  58409. {
  58410. var state = this.view.getState(cell);
  58411. if (state != null && (ignoreFn == null || !ignoreFn(state, x, y)) &&
  58412. this.intersects(state, x, y))
  58413. {
  58414. return cell;
  58415. }
  58416. }
  58417. }
  58418. }
  58419. return null;
  58420. };
  58421. /**
  58422. * Function: intersects
  58423. *
  58424. * Returns the bottom-most cell that intersects the given point (x, y) in
  58425. * the cell hierarchy that starts at the given parent.
  58426. *
  58427. * Parameters:
  58428. *
  58429. * state - <mxCellState> that represents the cell state.
  58430. * x - X-coordinate of the location to be checked.
  58431. * y - Y-coordinate of the location to be checked.
  58432. */
  58433. mxGraph.prototype.intersects = function(state, x, y)
  58434. {
  58435. if (state != null)
  58436. {
  58437. var pts = state.absolutePoints;
  58438. if (pts != null)
  58439. {
  58440. var t2 = this.tolerance * this.tolerance;
  58441. var pt = pts[0];
  58442. for (var i = 1; i < pts.length; i++)
  58443. {
  58444. var next = pts[i];
  58445. var dist = mxUtils.ptSegDistSq(pt.x, pt.y, next.x, next.y, x, y);
  58446. if (dist <= t2)
  58447. {
  58448. return true;
  58449. }
  58450. pt = next;
  58451. }
  58452. }
  58453. else
  58454. {
  58455. var alpha = mxUtils.toRadians(mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION) || 0);
  58456. if (alpha != 0)
  58457. {
  58458. var cos = Math.cos(-alpha);
  58459. var sin = Math.sin(-alpha);
  58460. var cx = new mxPoint(state.getCenterX(), state.getCenterY());
  58461. var pt = mxUtils.getRotatedPoint(new mxPoint(x, y), cos, sin, cx);
  58462. x = pt.x;
  58463. y = pt.y;
  58464. }
  58465. if (mxUtils.contains(state, x, y))
  58466. {
  58467. return true;
  58468. }
  58469. }
  58470. }
  58471. return false;
  58472. };
  58473. /**
  58474. * Function: hitsSwimlaneContent
  58475. *
  58476. * Returns true if the given coordinate pair is inside the content
  58477. * are of the given swimlane.
  58478. *
  58479. * Parameters:
  58480. *
  58481. * swimlane - <mxCell> that specifies the swimlane.
  58482. * x - X-coordinate of the mouse event.
  58483. * y - Y-coordinate of the mouse event.
  58484. */
  58485. mxGraph.prototype.hitsSwimlaneContent = function(swimlane, x, y)
  58486. {
  58487. var state = this.getView().getState(swimlane);
  58488. var size = this.getStartSize(swimlane);
  58489. if (state != null)
  58490. {
  58491. var scale = this.getView().getScale();
  58492. x -= state.x;
  58493. y -= state.y;
  58494. if (size.width > 0 && x > 0 && x > size.width * scale)
  58495. {
  58496. return true;
  58497. }
  58498. else if (size.height > 0 && y > 0 && y > size.height * scale)
  58499. {
  58500. return true;
  58501. }
  58502. }
  58503. return false;
  58504. };
  58505. /**
  58506. * Function: getChildVertices
  58507. *
  58508. * Returns the visible child vertices of the given parent.
  58509. *
  58510. * Parameters:
  58511. *
  58512. * parent - <mxCell> whose children should be returned.
  58513. */
  58514. mxGraph.prototype.getChildVertices = function(parent)
  58515. {
  58516. return this.getChildCells(parent, true, false);
  58517. };
  58518. /**
  58519. * Function: getChildEdges
  58520. *
  58521. * Returns the visible child edges of the given parent.
  58522. *
  58523. * Parameters:
  58524. *
  58525. * parent - <mxCell> whose child vertices should be returned.
  58526. */
  58527. mxGraph.prototype.getChildEdges = function(parent)
  58528. {
  58529. return this.getChildCells(parent, false, true);
  58530. };
  58531. /**
  58532. * Function: getChildCells
  58533. *
  58534. * Returns the visible child vertices or edges in the given parent. If
  58535. * vertices and edges is false, then all children are returned.
  58536. *
  58537. * Parameters:
  58538. *
  58539. * parent - <mxCell> whose children should be returned.
  58540. * vertices - Optional boolean that specifies if child vertices should
  58541. * be returned. Default is false.
  58542. * edges - Optional boolean that specifies if child edges should
  58543. * be returned. Default is false.
  58544. */
  58545. mxGraph.prototype.getChildCells = function(parent, vertices, edges)
  58546. {
  58547. parent = (parent != null) ? parent : this.getDefaultParent();
  58548. vertices = (vertices != null) ? vertices : false;
  58549. edges = (edges != null) ? edges : false;
  58550. var cells = this.model.getChildCells(parent, vertices, edges);
  58551. var result = [];
  58552. // Filters out the non-visible child cells
  58553. for (var i = 0; i < cells.length; i++)
  58554. {
  58555. if (this.isCellVisible(cells[i]))
  58556. {
  58557. result.push(cells[i]);
  58558. }
  58559. }
  58560. return result;
  58561. };
  58562. /**
  58563. * Function: getConnections
  58564. *
  58565. * Returns all visible edges connected to the given cell without loops.
  58566. *
  58567. * Parameters:
  58568. *
  58569. * cell - <mxCell> whose connections should be returned.
  58570. * parent - Optional parent of the opposite end for a connection to be
  58571. * returned.
  58572. */
  58573. mxGraph.prototype.getConnections = function(cell, parent)
  58574. {
  58575. return this.getEdges(cell, parent, true, true, false);
  58576. };
  58577. /**
  58578. * Function: getIncomingEdges
  58579. *
  58580. * Returns the visible incoming edges for the given cell. If the optional
  58581. * parent argument is specified, then only child edges of the given parent
  58582. * are returned.
  58583. *
  58584. * Parameters:
  58585. *
  58586. * cell - <mxCell> whose incoming edges should be returned.
  58587. * parent - Optional parent of the opposite end for an edge to be
  58588. * returned.
  58589. */
  58590. mxGraph.prototype.getIncomingEdges = function(cell, parent)
  58591. {
  58592. return this.getEdges(cell, parent, true, false, false);
  58593. };
  58594. /**
  58595. * Function: getOutgoingEdges
  58596. *
  58597. * Returns the visible outgoing edges for the given cell. If the optional
  58598. * parent argument is specified, then only child edges of the given parent
  58599. * are returned.
  58600. *
  58601. * Parameters:
  58602. *
  58603. * cell - <mxCell> whose outgoing edges should be returned.
  58604. * parent - Optional parent of the opposite end for an edge to be
  58605. * returned.
  58606. */
  58607. mxGraph.prototype.getOutgoingEdges = function(cell, parent)
  58608. {
  58609. return this.getEdges(cell, parent, false, true, false);
  58610. };
  58611. /**
  58612. * Function: getEdges
  58613. *
  58614. * Returns the incoming and/or outgoing edges for the given cell.
  58615. * If the optional parent argument is specified, then only edges are returned
  58616. * where the opposite is in the given parent cell. If at least one of incoming
  58617. * or outgoing is true, then loops are ignored, if both are false, then all
  58618. * edges connected to the given cell are returned including loops.
  58619. *
  58620. * Parameters:
  58621. *
  58622. * cell - <mxCell> whose edges should be returned.
  58623. * parent - Optional parent of the opposite end for an edge to be
  58624. * returned.
  58625. * incoming - Optional boolean that specifies if incoming edges should
  58626. * be included in the result. Default is true.
  58627. * outgoing - Optional boolean that specifies if outgoing edges should
  58628. * be included in the result. Default is true.
  58629. * includeLoops - Optional boolean that specifies if loops should be
  58630. * included in the result. Default is true.
  58631. * recurse - Optional boolean the specifies if the parent specified only
  58632. * need be an ancestral parent, true, or the direct parent, false.
  58633. * Default is false
  58634. */
  58635. mxGraph.prototype.getEdges = function(cell, parent, incoming, outgoing, includeLoops, recurse)
  58636. {
  58637. incoming = (incoming != null) ? incoming : true;
  58638. outgoing = (outgoing != null) ? outgoing : true;
  58639. includeLoops = (includeLoops != null) ? includeLoops : true;
  58640. recurse = (recurse != null) ? recurse : false;
  58641. var edges = [];
  58642. var isCollapsed = this.isCellCollapsed(cell);
  58643. var childCount = this.model.getChildCount(cell);
  58644. for (var i = 0; i < childCount; i++)
  58645. {
  58646. var child = this.model.getChildAt(cell, i);
  58647. if (isCollapsed || !this.isCellVisible(child))
  58648. {
  58649. edges = edges.concat(this.model.getEdges(child, incoming, outgoing));
  58650. }
  58651. }
  58652. edges = edges.concat(this.model.getEdges(cell, incoming, outgoing));
  58653. var result = [];
  58654. for (var i = 0; i < edges.length; i++)
  58655. {
  58656. var state = this.view.getState(edges[i]);
  58657. var source = (state != null) ? state.getVisibleTerminal(true) : this.view.getVisibleTerminal(edges[i], true);
  58658. var target = (state != null) ? state.getVisibleTerminal(false) : this.view.getVisibleTerminal(edges[i], false);
  58659. if ((includeLoops && source == target) || ((source != target) && ((incoming &&
  58660. target == cell && (parent == null || this.isValidAncestor(source, parent, recurse))) ||
  58661. (outgoing && source == cell && (parent == null ||
  58662. this.isValidAncestor(target, parent, recurse))))))
  58663. {
  58664. result.push(edges[i]);
  58665. }
  58666. }
  58667. return result;
  58668. };
  58669. /**
  58670. * Function: isValidAncestor
  58671. *
  58672. * Returns whether or not the specified parent is a valid
  58673. * ancestor of the specified cell, either direct or indirectly
  58674. * based on whether ancestor recursion is enabled.
  58675. *
  58676. * Parameters:
  58677. *
  58678. * cell - <mxCell> the possible child cell
  58679. * parent - <mxCell> the possible parent cell
  58680. * recurse - boolean whether or not to recurse the child ancestors
  58681. */
  58682. mxGraph.prototype.isValidAncestor = function(cell, parent, recurse)
  58683. {
  58684. return (recurse ? this.model.isAncestor(parent, cell) : this.model
  58685. .getParent(cell) == parent);
  58686. };
  58687. /**
  58688. * Function: getOpposites
  58689. *
  58690. * Returns all distinct visible opposite cells for the specified terminal
  58691. * on the given edges.
  58692. *
  58693. * Parameters:
  58694. *
  58695. * edges - Array of <mxCells> that contains the edges whose opposite
  58696. * terminals should be returned.
  58697. * terminal - Terminal that specifies the end whose opposite should be
  58698. * returned.
  58699. * sources - Optional boolean that specifies if source terminals should be
  58700. * included in the result. Default is true.
  58701. * targets - Optional boolean that specifies if targer terminals should be
  58702. * included in the result. Default is true.
  58703. */
  58704. mxGraph.prototype.getOpposites = function(edges, terminal, sources, targets)
  58705. {
  58706. sources = (sources != null) ? sources : true;
  58707. targets = (targets != null) ? targets : true;
  58708. var terminals = [];
  58709. // Fast lookup to avoid duplicates in terminals array
  58710. var dict = new mxDictionary();
  58711. if (edges != null)
  58712. {
  58713. for (var i = 0; i < edges.length; i++)
  58714. {
  58715. var state = this.view.getState(edges[i]);
  58716. var source = (state != null) ? state.getVisibleTerminal(true) : this.view.getVisibleTerminal(edges[i], true);
  58717. var target = (state != null) ? state.getVisibleTerminal(false) : this.view.getVisibleTerminal(edges[i], false);
  58718. // Checks if the terminal is the source of the edge and if the
  58719. // target should be stored in the result
  58720. if (source == terminal && target != null && target != terminal && targets)
  58721. {
  58722. if (!dict.get(target))
  58723. {
  58724. dict.put(target, true);
  58725. terminals.push(target);
  58726. }
  58727. }
  58728. // Checks if the terminal is the taget of the edge and if the
  58729. // source should be stored in the result
  58730. else if (target == terminal && source != null && source != terminal && sources)
  58731. {
  58732. if (!dict.get(source))
  58733. {
  58734. dict.put(source, true);
  58735. terminals.push(source);
  58736. }
  58737. }
  58738. }
  58739. }
  58740. return terminals;
  58741. };
  58742. /**
  58743. * Function: getEdgesBetween
  58744. *
  58745. * Returns the edges between the given source and target. This takes into
  58746. * account collapsed and invisible cells and returns the connected edges
  58747. * as displayed on the screen.
  58748. *
  58749. * Parameters:
  58750. *
  58751. * source -
  58752. * target -
  58753. * directed -
  58754. */
  58755. mxGraph.prototype.getEdgesBetween = function(source, target, directed)
  58756. {
  58757. directed = (directed != null) ? directed : false;
  58758. var edges = this.getEdges(source);
  58759. var result = [];
  58760. // Checks if the edge is connected to the correct
  58761. // cell and returns the first match
  58762. for (var i = 0; i < edges.length; i++)
  58763. {
  58764. var state = this.view.getState(edges[i]);
  58765. var src = (state != null) ? state.getVisibleTerminal(true) : this.view.getVisibleTerminal(edges[i], true);
  58766. var trg = (state != null) ? state.getVisibleTerminal(false) : this.view.getVisibleTerminal(edges[i], false);
  58767. if ((src == source && trg == target) || (!directed && src == target && trg == source))
  58768. {
  58769. result.push(edges[i]);
  58770. }
  58771. }
  58772. return result;
  58773. };
  58774. /**
  58775. * Function: getPointForEvent
  58776. *
  58777. * Returns an <mxPoint> representing the given event in the unscaled,
  58778. * non-translated coordinate space of <container> and applies the grid.
  58779. *
  58780. * Parameters:
  58781. *
  58782. * evt - Mousevent that contains the mouse pointer location.
  58783. * addOffset - Optional boolean that specifies if the position should be
  58784. * offset by half of the <gridSize>. Default is true.
  58785. */
  58786. mxGraph.prototype.getPointForEvent = function(evt, addOffset)
  58787. {
  58788. var p = mxUtils.convertPoint(this.container,
  58789. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  58790. var s = this.view.scale;
  58791. var tr = this.view.translate;
  58792. var off = (addOffset != false) ? this.gridSize / 2 : 0;
  58793. p.x = this.snap(p.x / s - tr.x - off);
  58794. p.y = this.snap(p.y / s - tr.y - off);
  58795. return p;
  58796. };
  58797. /**
  58798. * Function: getCells
  58799. *
  58800. * Returns the child vertices and edges of the given parent that are contained
  58801. * in the given rectangle. The result is added to the optional result array,
  58802. * which is returned. If no result array is specified then a new array is
  58803. * created and returned.
  58804. *
  58805. * Parameters:
  58806. *
  58807. * x - X-coordinate of the rectangle.
  58808. * y - Y-coordinate of the rectangle.
  58809. * width - Width of the rectangle.
  58810. * height - Height of the rectangle.
  58811. * parent - <mxCell> that should be used as the root of the recursion.
  58812. * Default is current root of the view or the root of the model.
  58813. * result - Optional array to store the result in.
  58814. */
  58815. mxGraph.prototype.getCells = function(x, y, width, height, parent, result)
  58816. {
  58817. result = (result != null) ? result : [];
  58818. if (width > 0 || height > 0)
  58819. {
  58820. var model = this.getModel();
  58821. var right = x + width;
  58822. var bottom = y + height;
  58823. if (parent == null)
  58824. {
  58825. parent = this.getCurrentRoot();
  58826. if (parent == null)
  58827. {
  58828. parent = model.getRoot();
  58829. }
  58830. }
  58831. if (parent != null)
  58832. {
  58833. var childCount = model.getChildCount(parent);
  58834. for (var i = 0; i < childCount; i++)
  58835. {
  58836. var cell = model.getChildAt(parent, i);
  58837. var state = this.view.getState(cell);
  58838. if (state != null && this.isCellVisible(cell))
  58839. {
  58840. var deg = mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION) || 0;
  58841. var box = state;
  58842. if (deg != 0)
  58843. {
  58844. box = mxUtils.getBoundingBox(box, deg);
  58845. }
  58846. if ((model.isEdge(cell) || model.isVertex(cell)) &&
  58847. box.x >= x && box.y + box.height <= bottom &&
  58848. box.y >= y && box.x + box.width <= right)
  58849. {
  58850. result.push(cell);
  58851. }
  58852. else
  58853. {
  58854. this.getCells(x, y, width, height, cell, result);
  58855. }
  58856. }
  58857. }
  58858. }
  58859. }
  58860. return result;
  58861. };
  58862. /**
  58863. * Function: getCellsBeyond
  58864. *
  58865. * Returns the children of the given parent that are contained in the
  58866. * halfpane from the given point (x0, y0) rightwards or downwards
  58867. * depending on rightHalfpane and bottomHalfpane.
  58868. *
  58869. * Parameters:
  58870. *
  58871. * x0 - X-coordinate of the origin.
  58872. * y0 - Y-coordinate of the origin.
  58873. * parent - Optional <mxCell> whose children should be checked. Default is
  58874. * <defaultParent>.
  58875. * rightHalfpane - Boolean indicating if the cells in the right halfpane
  58876. * from the origin should be returned.
  58877. * bottomHalfpane - Boolean indicating if the cells in the bottom halfpane
  58878. * from the origin should be returned.
  58879. */
  58880. mxGraph.prototype.getCellsBeyond = function(x0, y0, parent, rightHalfpane, bottomHalfpane)
  58881. {
  58882. var result = [];
  58883. if (rightHalfpane || bottomHalfpane)
  58884. {
  58885. if (parent == null)
  58886. {
  58887. parent = this.getDefaultParent();
  58888. }
  58889. if (parent != null)
  58890. {
  58891. var childCount = this.model.getChildCount(parent);
  58892. for (var i = 0; i < childCount; i++)
  58893. {
  58894. var child = this.model.getChildAt(parent, i);
  58895. var state = this.view.getState(child);
  58896. if (this.isCellVisible(child) && state != null)
  58897. {
  58898. if ((!rightHalfpane || state.x >= x0) &&
  58899. (!bottomHalfpane || state.y >= y0))
  58900. {
  58901. result.push(child);
  58902. }
  58903. }
  58904. }
  58905. }
  58906. }
  58907. return result;
  58908. };
  58909. /**
  58910. * Function: findTreeRoots
  58911. *
  58912. * Returns all children in the given parent which do not have incoming
  58913. * edges. If the result is empty then the with the greatest difference
  58914. * between incoming and outgoing edges is returned.
  58915. *
  58916. * Parameters:
  58917. *
  58918. * parent - <mxCell> whose children should be checked.
  58919. * isolate - Optional boolean that specifies if edges should be ignored if
  58920. * the opposite end is not a child of the given parent cell. Default is
  58921. * false.
  58922. * invert - Optional boolean that specifies if outgoing or incoming edges
  58923. * should be counted for a tree root. If false then outgoing edges will be
  58924. * counted. Default is false.
  58925. */
  58926. mxGraph.prototype.findTreeRoots = function(parent, isolate, invert)
  58927. {
  58928. isolate = (isolate != null) ? isolate : false;
  58929. invert = (invert != null) ? invert : false;
  58930. var roots = [];
  58931. if (parent != null)
  58932. {
  58933. var model = this.getModel();
  58934. var childCount = model.getChildCount(parent);
  58935. var best = null;
  58936. var maxDiff = 0;
  58937. for (var i=0; i<childCount; i++)
  58938. {
  58939. var cell = model.getChildAt(parent, i);
  58940. if (this.model.isVertex(cell) && this.isCellVisible(cell))
  58941. {
  58942. var conns = this.getConnections(cell, (isolate) ? parent : null);
  58943. var fanOut = 0;
  58944. var fanIn = 0;
  58945. for (var j = 0; j < conns.length; j++)
  58946. {
  58947. var src = this.view.getVisibleTerminal(conns[j], true);
  58948. if (src == cell)
  58949. {
  58950. fanOut++;
  58951. }
  58952. else
  58953. {
  58954. fanIn++;
  58955. }
  58956. }
  58957. if ((invert && fanOut == 0 && fanIn > 0) ||
  58958. (!invert && fanIn == 0 && fanOut > 0))
  58959. {
  58960. roots.push(cell);
  58961. }
  58962. var diff = (invert) ? fanIn - fanOut : fanOut - fanIn;
  58963. if (diff > maxDiff)
  58964. {
  58965. maxDiff = diff;
  58966. best = cell;
  58967. }
  58968. }
  58969. }
  58970. if (roots.length == 0 && best != null)
  58971. {
  58972. roots.push(best);
  58973. }
  58974. }
  58975. return roots;
  58976. };
  58977. /**
  58978. * Function: traverse
  58979. *
  58980. * Traverses the (directed) graph invoking the given function for each
  58981. * visited vertex and edge. The function is invoked with the current vertex
  58982. * and the incoming edge as a parameter. This implementation makes sure
  58983. * each vertex is only visited once. The function may return false if the
  58984. * traversal should stop at the given vertex.
  58985. *
  58986. * Example:
  58987. *
  58988. * (code)
  58989. * mxLog.show();
  58990. * var cell = graph.getSelectionCell();
  58991. * graph.traverse(cell, false, function(vertex, edge)
  58992. * {
  58993. * mxLog.debug(graph.getLabel(vertex));
  58994. * });
  58995. * (end)
  58996. *
  58997. * Parameters:
  58998. *
  58999. * vertex - <mxCell> that represents the vertex where the traversal starts.
  59000. * directed - Optional boolean indicating if edges should only be traversed
  59001. * from source to target. Default is true.
  59002. * func - Visitor function that takes the current vertex and the incoming
  59003. * edge as arguments. The traversal stops if the function returns false.
  59004. * edge - Optional <mxCell> that represents the incoming edge. This is
  59005. * null for the first step of the traversal.
  59006. * visited - Optional <mxDictionary> from cells to true for the visited cells.
  59007. * inverse - Optional boolean to traverse in inverse direction. Default is false.
  59008. * This is ignored if directed is false.
  59009. */
  59010. mxGraph.prototype.traverse = function(vertex, directed, func, edge, visited, inverse)
  59011. {
  59012. if (func != null && vertex != null)
  59013. {
  59014. directed = (directed != null) ? directed : true;
  59015. inverse = (inverse != null) ? inverse : false;
  59016. visited = visited || new mxDictionary();
  59017. if (!visited.get(vertex))
  59018. {
  59019. visited.put(vertex, true);
  59020. var result = func(vertex, edge);
  59021. if (result == null || result)
  59022. {
  59023. var edgeCount = this.model.getEdgeCount(vertex);
  59024. if (edgeCount > 0)
  59025. {
  59026. for (var i = 0; i < edgeCount; i++)
  59027. {
  59028. var e = this.model.getEdgeAt(vertex, i);
  59029. var isSource = this.model.getTerminal(e, true) == vertex;
  59030. if (!directed || (!inverse == isSource))
  59031. {
  59032. var next = this.model.getTerminal(e, !isSource);
  59033. this.traverse(next, directed, func, e, visited, inverse);
  59034. }
  59035. }
  59036. }
  59037. }
  59038. }
  59039. }
  59040. };
  59041. /**
  59042. * Group: Selection
  59043. */
  59044. /**
  59045. * Function: isCellSelected
  59046. *
  59047. * Returns true if the given cell is selected.
  59048. *
  59049. * Parameters:
  59050. *
  59051. * cell - <mxCell> for which the selection state should be returned.
  59052. */
  59053. mxGraph.prototype.isCellSelected = function(cell)
  59054. {
  59055. return this.getSelectionModel().isSelected(cell);
  59056. };
  59057. /**
  59058. * Function: isSelectionEmpty
  59059. *
  59060. * Returns true if the selection is empty.
  59061. */
  59062. mxGraph.prototype.isSelectionEmpty = function()
  59063. {
  59064. return this.getSelectionModel().isEmpty();
  59065. };
  59066. /**
  59067. * Function: clearSelection
  59068. *
  59069. * Clears the selection using <mxGraphSelectionModel.clear>.
  59070. */
  59071. mxGraph.prototype.clearSelection = function()
  59072. {
  59073. return this.getSelectionModel().clear();
  59074. };
  59075. /**
  59076. * Function: getSelectionCount
  59077. *
  59078. * Returns the number of selected cells.
  59079. */
  59080. mxGraph.prototype.getSelectionCount = function()
  59081. {
  59082. return this.getSelectionModel().cells.length;
  59083. };
  59084. /**
  59085. * Function: getSelectionCell
  59086. *
  59087. * Returns the first cell from the array of selected <mxCells>.
  59088. */
  59089. mxGraph.prototype.getSelectionCell = function()
  59090. {
  59091. return this.getSelectionModel().cells[0];
  59092. };
  59093. /**
  59094. * Function: getSelectionCells
  59095. *
  59096. * Returns the array of selected <mxCells>.
  59097. */
  59098. mxGraph.prototype.getSelectionCells = function()
  59099. {
  59100. return this.getSelectionModel().cells.slice();
  59101. };
  59102. /**
  59103. * Function: setSelectionCell
  59104. *
  59105. * Sets the selection cell.
  59106. *
  59107. * Parameters:
  59108. *
  59109. * cell - <mxCell> to be selected.
  59110. */
  59111. mxGraph.prototype.setSelectionCell = function(cell)
  59112. {
  59113. this.getSelectionModel().setCell(cell);
  59114. };
  59115. /**
  59116. * Function: setSelectionCells
  59117. *
  59118. * Sets the selection cell.
  59119. *
  59120. * Parameters:
  59121. *
  59122. * cells - Array of <mxCells> to be selected.
  59123. */
  59124. mxGraph.prototype.setSelectionCells = function(cells)
  59125. {
  59126. this.getSelectionModel().setCells(cells);
  59127. };
  59128. /**
  59129. * Function: addSelectionCell
  59130. *
  59131. * Adds the given cell to the selection.
  59132. *
  59133. * Parameters:
  59134. *
  59135. * cell - <mxCell> to be add to the selection.
  59136. */
  59137. mxGraph.prototype.addSelectionCell = function(cell)
  59138. {
  59139. this.getSelectionModel().addCell(cell);
  59140. };
  59141. /**
  59142. * Function: addSelectionCells
  59143. *
  59144. * Adds the given cells to the selection.
  59145. *
  59146. * Parameters:
  59147. *
  59148. * cells - Array of <mxCells> to be added to the selection.
  59149. */
  59150. mxGraph.prototype.addSelectionCells = function(cells)
  59151. {
  59152. this.getSelectionModel().addCells(cells);
  59153. };
  59154. /**
  59155. * Function: removeSelectionCell
  59156. *
  59157. * Removes the given cell from the selection.
  59158. *
  59159. * Parameters:
  59160. *
  59161. * cell - <mxCell> to be removed from the selection.
  59162. */
  59163. mxGraph.prototype.removeSelectionCell = function(cell)
  59164. {
  59165. this.getSelectionModel().removeCell(cell);
  59166. };
  59167. /**
  59168. * Function: removeSelectionCells
  59169. *
  59170. * Removes the given cells from the selection.
  59171. *
  59172. * Parameters:
  59173. *
  59174. * cells - Array of <mxCells> to be removed from the selection.
  59175. */
  59176. mxGraph.prototype.removeSelectionCells = function(cells)
  59177. {
  59178. this.getSelectionModel().removeCells(cells);
  59179. };
  59180. /**
  59181. * Function: selectRegion
  59182. *
  59183. * Selects and returns the cells inside the given rectangle for the
  59184. * specified event.
  59185. *
  59186. * Parameters:
  59187. *
  59188. * rect - <mxRectangle> that represents the region to be selected.
  59189. * evt - Mouseevent that triggered the selection.
  59190. */
  59191. mxGraph.prototype.selectRegion = function(rect, evt)
  59192. {
  59193. var cells = this.getCells(rect.x, rect.y, rect.width, rect.height);
  59194. this.selectCellsForEvent(cells, evt);
  59195. return cells;
  59196. };
  59197. /**
  59198. * Function: selectNextCell
  59199. *
  59200. * Selects the next cell.
  59201. */
  59202. mxGraph.prototype.selectNextCell = function()
  59203. {
  59204. this.selectCell(true);
  59205. };
  59206. /**
  59207. * Function: selectPreviousCell
  59208. *
  59209. * Selects the previous cell.
  59210. */
  59211. mxGraph.prototype.selectPreviousCell = function()
  59212. {
  59213. this.selectCell();
  59214. };
  59215. /**
  59216. * Function: selectParentCell
  59217. *
  59218. * Selects the parent cell.
  59219. */
  59220. mxGraph.prototype.selectParentCell = function()
  59221. {
  59222. this.selectCell(false, true);
  59223. };
  59224. /**
  59225. * Function: selectChildCell
  59226. *
  59227. * Selects the first child cell.
  59228. */
  59229. mxGraph.prototype.selectChildCell = function()
  59230. {
  59231. this.selectCell(false, false, true);
  59232. };
  59233. /**
  59234. * Function: selectCell
  59235. *
  59236. * Selects the next, parent, first child or previous cell, if all arguments
  59237. * are false.
  59238. *
  59239. * Parameters:
  59240. *
  59241. * isNext - Boolean indicating if the next cell should be selected.
  59242. * isParent - Boolean indicating if the parent cell should be selected.
  59243. * isChild - Boolean indicating if the first child cell should be selected.
  59244. */
  59245. mxGraph.prototype.selectCell = function(isNext, isParent, isChild)
  59246. {
  59247. var sel = this.selectionModel;
  59248. var cell = (sel.cells.length > 0) ? sel.cells[0] : null;
  59249. if (sel.cells.length > 1)
  59250. {
  59251. sel.clear();
  59252. }
  59253. var parent = (cell != null) ?
  59254. this.model.getParent(cell) :
  59255. this.getDefaultParent();
  59256. var childCount = this.model.getChildCount(parent);
  59257. if (cell == null && childCount > 0)
  59258. {
  59259. var child = this.model.getChildAt(parent, 0);
  59260. this.setSelectionCell(child);
  59261. }
  59262. else if ((cell == null || isParent) &&
  59263. this.view.getState(parent) != null &&
  59264. this.model.getGeometry(parent) != null)
  59265. {
  59266. if (this.getCurrentRoot() != parent)
  59267. {
  59268. this.setSelectionCell(parent);
  59269. }
  59270. }
  59271. else if (cell != null && isChild)
  59272. {
  59273. var tmp = this.model.getChildCount(cell);
  59274. if (tmp > 0)
  59275. {
  59276. var child = this.model.getChildAt(cell, 0);
  59277. this.setSelectionCell(child);
  59278. }
  59279. }
  59280. else if (childCount > 0)
  59281. {
  59282. var i = parent.getIndex(cell);
  59283. if (isNext)
  59284. {
  59285. i++;
  59286. var child = this.model.getChildAt(parent, i % childCount);
  59287. this.setSelectionCell(child);
  59288. }
  59289. else
  59290. {
  59291. i--;
  59292. var index = (i < 0) ? childCount - 1 : i;
  59293. var child = this.model.getChildAt(parent, index);
  59294. this.setSelectionCell(child);
  59295. }
  59296. }
  59297. };
  59298. /**
  59299. * Function: selectAll
  59300. *
  59301. * Selects all children of the given parent cell or the children of the
  59302. * default parent if no parent is specified. To select leaf vertices and/or
  59303. * edges use <selectCells>.
  59304. *
  59305. * Parameters:
  59306. *
  59307. * parent - Optional <mxCell> whose children should be selected.
  59308. * Default is <defaultParent>.
  59309. * descendants - Optional boolean specifying whether all descendants should be
  59310. * selected. Default is false.
  59311. */
  59312. mxGraph.prototype.selectAll = function(parent, descendants)
  59313. {
  59314. parent = parent || this.getDefaultParent();
  59315. var cells = (descendants) ? this.model.filterDescendants(mxUtils.bind(this, function(cell)
  59316. {
  59317. return cell != parent && this.view.getState(cell) != null;
  59318. }), parent) : this.model.getChildren(parent);
  59319. if (cells != null)
  59320. {
  59321. this.setSelectionCells(cells);
  59322. }
  59323. };
  59324. /**
  59325. * Function: selectVertices
  59326. *
  59327. * Select all vertices inside the given parent or the default parent.
  59328. */
  59329. mxGraph.prototype.selectVertices = function(parent, selectGroups)
  59330. {
  59331. this.selectCells(true, false, parent, selectGroups);
  59332. };
  59333. /**
  59334. * Function: selectVertices
  59335. *
  59336. * Select all vertices inside the given parent or the default parent.
  59337. */
  59338. mxGraph.prototype.selectEdges = function(parent)
  59339. {
  59340. this.selectCells(false, true, parent);
  59341. };
  59342. /**
  59343. * Function: selectCells
  59344. *
  59345. * Selects all vertices and/or edges depending on the given boolean
  59346. * arguments recursively, starting at the given parent or the default
  59347. * parent if no parent is specified. Use <selectAll> to select all cells.
  59348. * For vertices, only cells with no children are selected.
  59349. *
  59350. * Parameters:
  59351. *
  59352. * vertices - Boolean indicating if vertices should be selected.
  59353. * edges - Boolean indicating if edges should be selected.
  59354. * parent - Optional <mxCell> that acts as the root of the recursion.
  59355. * Default is <defaultParent>.
  59356. * selectGroups - Optional boolean that specifies if groups should be
  59357. * selected. Default is false.
  59358. */
  59359. mxGraph.prototype.selectCells = function(vertices, edges, parent, selectGroups)
  59360. {
  59361. parent = parent || this.getDefaultParent();
  59362. var filter = mxUtils.bind(this, function(cell)
  59363. {
  59364. return this.view.getState(cell) != null &&
  59365. (((selectGroups || this.model.getChildCount(cell) == 0) &&
  59366. this.model.isVertex(cell) && vertices
  59367. && !this.model.isEdge(this.model.getParent(cell))) ||
  59368. (this.model.isEdge(cell) && edges));
  59369. });
  59370. var cells = this.model.filterDescendants(filter, parent);
  59371. if (cells != null)
  59372. {
  59373. this.setSelectionCells(cells);
  59374. }
  59375. };
  59376. /**
  59377. * Function: selectCellForEvent
  59378. *
  59379. * Selects the given cell by either adding it to the selection or
  59380. * replacing the selection depending on whether the given mouse event is a
  59381. * toggle event.
  59382. *
  59383. * Parameters:
  59384. *
  59385. * cell - <mxCell> to be selected.
  59386. * evt - Optional mouseevent that triggered the selection.
  59387. */
  59388. mxGraph.prototype.selectCellForEvent = function(cell, evt)
  59389. {
  59390. var isSelected = this.isCellSelected(cell);
  59391. if (this.isToggleEvent(evt))
  59392. {
  59393. if (isSelected)
  59394. {
  59395. this.removeSelectionCell(cell);
  59396. }
  59397. else
  59398. {
  59399. this.addSelectionCell(cell);
  59400. }
  59401. }
  59402. else if (!isSelected || this.getSelectionCount() != 1)
  59403. {
  59404. this.setSelectionCell(cell);
  59405. }
  59406. };
  59407. /**
  59408. * Function: selectCellsForEvent
  59409. *
  59410. * Selects the given cells by either adding them to the selection or
  59411. * replacing the selection depending on whether the given mouse event is a
  59412. * toggle event.
  59413. *
  59414. * Parameters:
  59415. *
  59416. * cells - Array of <mxCells> to be selected.
  59417. * evt - Optional mouseevent that triggered the selection.
  59418. */
  59419. mxGraph.prototype.selectCellsForEvent = function(cells, evt)
  59420. {
  59421. if (this.isToggleEvent(evt))
  59422. {
  59423. this.addSelectionCells(cells);
  59424. }
  59425. else
  59426. {
  59427. this.setSelectionCells(cells);
  59428. }
  59429. };
  59430. /**
  59431. * Group: Selection state
  59432. */
  59433. /**
  59434. * Function: createHandler
  59435. *
  59436. * Creates a new handler for the given cell state. This implementation
  59437. * returns a new <mxEdgeHandler> of the corresponding cell is an edge,
  59438. * otherwise it returns an <mxVertexHandler>.
  59439. *
  59440. * Parameters:
  59441. *
  59442. * state - <mxCellState> whose handler should be created.
  59443. */
  59444. mxGraph.prototype.createHandler = function(state)
  59445. {
  59446. var result = null;
  59447. if (state != null)
  59448. {
  59449. if (this.model.isEdge(state.cell))
  59450. {
  59451. var source = state.getVisibleTerminalState(true);
  59452. var target = state.getVisibleTerminalState(false);
  59453. var geo = this.getCellGeometry(state.cell);
  59454. var edgeStyle = this.view.getEdgeStyle(state, (geo != null) ? geo.points : null, source, target);
  59455. result = this.createEdgeHandler(state, edgeStyle);
  59456. }
  59457. else
  59458. {
  59459. result = this.createVertexHandler(state);
  59460. }
  59461. }
  59462. return result;
  59463. };
  59464. /**
  59465. * Function: createVertexHandler
  59466. *
  59467. * Hooks to create a new <mxVertexHandler> for the given <mxCellState>.
  59468. *
  59469. * Parameters:
  59470. *
  59471. * state - <mxCellState> to create the handler for.
  59472. */
  59473. mxGraph.prototype.createVertexHandler = function(state)
  59474. {
  59475. return new mxVertexHandler(state);
  59476. };
  59477. /**
  59478. * Function: createEdgeHandler
  59479. *
  59480. * Hooks to create a new <mxEdgeHandler> for the given <mxCellState>.
  59481. *
  59482. * Parameters:
  59483. *
  59484. * state - <mxCellState> to create the handler for.
  59485. */
  59486. mxGraph.prototype.createEdgeHandler = function(state, edgeStyle)
  59487. {
  59488. var result = null;
  59489. if (edgeStyle == mxEdgeStyle.Loop ||
  59490. edgeStyle == mxEdgeStyle.ElbowConnector ||
  59491. edgeStyle == mxEdgeStyle.SideToSide ||
  59492. edgeStyle == mxEdgeStyle.TopToBottom)
  59493. {
  59494. result = this.createElbowEdgeHandler(state);
  59495. }
  59496. else if (edgeStyle == mxEdgeStyle.SegmentConnector ||
  59497. edgeStyle == mxEdgeStyle.OrthConnector)
  59498. {
  59499. result = this.createEdgeSegmentHandler(state);
  59500. }
  59501. else
  59502. {
  59503. result = new mxEdgeHandler(state);
  59504. }
  59505. return result;
  59506. };
  59507. /**
  59508. * Function: createEdgeSegmentHandler
  59509. *
  59510. * Hooks to create a new <mxEdgeSegmentHandler> for the given <mxCellState>.
  59511. *
  59512. * Parameters:
  59513. *
  59514. * state - <mxCellState> to create the handler for.
  59515. */
  59516. mxGraph.prototype.createEdgeSegmentHandler = function(state)
  59517. {
  59518. return new mxEdgeSegmentHandler(state);
  59519. };
  59520. /**
  59521. * Function: createElbowEdgeHandler
  59522. *
  59523. * Hooks to create a new <mxElbowEdgeHandler> for the given <mxCellState>.
  59524. *
  59525. * Parameters:
  59526. *
  59527. * state - <mxCellState> to create the handler for.
  59528. */
  59529. mxGraph.prototype.createElbowEdgeHandler = function(state)
  59530. {
  59531. return new mxElbowEdgeHandler(state);
  59532. };
  59533. /**
  59534. * Group: Graph events
  59535. */
  59536. /**
  59537. * Function: addMouseListener
  59538. *
  59539. * Adds a listener to the graph event dispatch loop. The listener
  59540. * must implement the mouseDown, mouseMove and mouseUp methods
  59541. * as shown in the <mxMouseEvent> class.
  59542. *
  59543. * Parameters:
  59544. *
  59545. * listener - Listener to be added to the graph event listeners.
  59546. */
  59547. mxGraph.prototype.addMouseListener = function(listener)
  59548. {
  59549. if (this.mouseListeners == null)
  59550. {
  59551. this.mouseListeners = [];
  59552. }
  59553. this.mouseListeners.push(listener);
  59554. };
  59555. /**
  59556. * Function: removeMouseListener
  59557. *
  59558. * Removes the specified graph listener.
  59559. *
  59560. * Parameters:
  59561. *
  59562. * listener - Listener to be removed from the graph event listeners.
  59563. */
  59564. mxGraph.prototype.removeMouseListener = function(listener)
  59565. {
  59566. if (this.mouseListeners != null)
  59567. {
  59568. for (var i = 0; i < this.mouseListeners.length; i++)
  59569. {
  59570. if (this.mouseListeners[i] == listener)
  59571. {
  59572. this.mouseListeners.splice(i, 1);
  59573. break;
  59574. }
  59575. }
  59576. }
  59577. };
  59578. /**
  59579. * Function: updateMouseEvent
  59580. *
  59581. * Sets the graphX and graphY properties if the given <mxMouseEvent> if
  59582. * required and returned the event.
  59583. *
  59584. * Parameters:
  59585. *
  59586. * me - <mxMouseEvent> to be updated.
  59587. * evtName - Name of the mouse event.
  59588. */
  59589. mxGraph.prototype.updateMouseEvent = function(me, evtName)
  59590. {
  59591. if (me.graphX == null || me.graphY == null)
  59592. {
  59593. var pt = mxUtils.convertPoint(this.container, me.getX(), me.getY());
  59594. me.graphX = pt.x - this.panDx;
  59595. me.graphY = pt.y - this.panDy;
  59596. // Searches for rectangles using method if native hit detection is disabled on shape
  59597. if (me.getCell() == null && this.isMouseDown && evtName == mxEvent.MOUSE_MOVE)
  59598. {
  59599. me.state = this.view.getState(this.getCellAt(pt.x, pt.y, null, null, null, function(state)
  59600. {
  59601. return state.shape == null || state.shape.paintBackground != mxRectangleShape.prototype.paintBackground ||
  59602. mxUtils.getValue(state.style, mxConstants.STYLE_POINTER_EVENTS, '1') == '1' ||
  59603. (state.shape.fill != null && state.shape.fill != mxConstants.NONE);
  59604. }));
  59605. }
  59606. }
  59607. return me;
  59608. };
  59609. /**
  59610. * Function: getStateForEvent
  59611. *
  59612. * Returns the state for the given touch event.
  59613. */
  59614. mxGraph.prototype.getStateForTouchEvent = function(evt)
  59615. {
  59616. var x = mxEvent.getClientX(evt);
  59617. var y = mxEvent.getClientY(evt);
  59618. // Dispatches the drop event to the graph which
  59619. // consumes and executes the source function
  59620. var pt = mxUtils.convertPoint(this.container, x, y);
  59621. return this.view.getState(this.getCellAt(pt.x, pt.y));
  59622. };
  59623. /**
  59624. * Function: isEventIgnored
  59625. *
  59626. * Returns true if the event should be ignored in <fireMouseEvent>.
  59627. */
  59628. mxGraph.prototype.isEventIgnored = function(evtName, me, sender)
  59629. {
  59630. var mouseEvent = mxEvent.isMouseEvent(me.getEvent());
  59631. var result = false;
  59632. // Drops events that are fired more than once
  59633. if (me.getEvent() == this.lastEvent)
  59634. {
  59635. result = true;
  59636. }
  59637. else
  59638. {
  59639. this.lastEvent = me.getEvent();
  59640. }
  59641. // Installs event listeners to capture the complete gesture from the event source
  59642. // for non-MS touch events as a workaround for all events for the same geture being
  59643. // fired from the event source even if that was removed from the DOM.
  59644. if (this.eventSource != null && evtName != mxEvent.MOUSE_MOVE)
  59645. {
  59646. mxEvent.removeGestureListeners(this.eventSource, null, this.mouseMoveRedirect, this.mouseUpRedirect);
  59647. this.mouseMoveRedirect = null;
  59648. this.mouseUpRedirect = null;
  59649. this.eventSource = null;
  59650. }
  59651. else if (!mxClient.IS_GC && this.eventSource != null && me.getSource() != this.eventSource)
  59652. {
  59653. result = true;
  59654. }
  59655. else if (mxClient.IS_TOUCH && evtName == mxEvent.MOUSE_DOWN &&
  59656. !mouseEvent && !mxEvent.isPenEvent(me.getEvent()))
  59657. {
  59658. this.eventSource = me.getSource();
  59659. this.mouseMoveRedirect = mxUtils.bind(this, function(evt)
  59660. {
  59661. this.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt, this.getStateForTouchEvent(evt)));
  59662. });
  59663. this.mouseUpRedirect = mxUtils.bind(this, function(evt)
  59664. {
  59665. this.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt, this.getStateForTouchEvent(evt)));
  59666. });
  59667. mxEvent.addGestureListeners(this.eventSource, null, this.mouseMoveRedirect, this.mouseUpRedirect);
  59668. }
  59669. // Factored out the workarounds for FF to make it easier to override/remove
  59670. // Note this method has side-effects!
  59671. if (this.isSyntheticEventIgnored(evtName, me, sender))
  59672. {
  59673. result = true;
  59674. }
  59675. // Never fires mouseUp/-Down for double clicks
  59676. if (!mxEvent.isPopupTrigger(this.lastEvent) && evtName != mxEvent.MOUSE_MOVE && this.lastEvent.detail == 2)
  59677. {
  59678. return true;
  59679. }
  59680. // Filters out of sequence events or mixed event types during a gesture
  59681. if (evtName == mxEvent.MOUSE_UP && this.isMouseDown)
  59682. {
  59683. this.isMouseDown = false;
  59684. }
  59685. else if (evtName == mxEvent.MOUSE_DOWN && !this.isMouseDown)
  59686. {
  59687. this.isMouseDown = true;
  59688. this.isMouseTrigger = mouseEvent;
  59689. }
  59690. // Drops mouse events that are fired during touch gestures as a workaround for Webkit
  59691. // and mouse events that are not in sync with the current internal button state
  59692. else if (!result && (((!mxClient.IS_FF || evtName != mxEvent.MOUSE_MOVE) &&
  59693. this.isMouseDown && this.isMouseTrigger != mouseEvent) ||
  59694. (evtName == mxEvent.MOUSE_DOWN && this.isMouseDown) ||
  59695. (evtName == mxEvent.MOUSE_UP && !this.isMouseDown)))
  59696. {
  59697. result = true;
  59698. }
  59699. if (!result && evtName == mxEvent.MOUSE_DOWN)
  59700. {
  59701. this.lastMouseX = me.getX();
  59702. this.lastMouseY = me.getY();
  59703. }
  59704. return result;
  59705. };
  59706. /**
  59707. * Function: isSyntheticEventIgnored
  59708. *
  59709. * Hook for ignoring synthetic mouse events after touchend in Firefox.
  59710. */
  59711. mxGraph.prototype.isSyntheticEventIgnored = function(evtName, me, sender)
  59712. {
  59713. var result = false;
  59714. var mouseEvent = mxEvent.isMouseEvent(me.getEvent());
  59715. // LATER: This does not cover all possible cases that can go wrong in FF
  59716. if (this.ignoreMouseEvents && mouseEvent && evtName != mxEvent.MOUSE_MOVE)
  59717. {
  59718. this.ignoreMouseEvents = evtName != mxEvent.MOUSE_UP;
  59719. result = true;
  59720. }
  59721. else if (mxClient.IS_FF && !mouseEvent && evtName == mxEvent.MOUSE_UP)
  59722. {
  59723. this.ignoreMouseEvents = true;
  59724. }
  59725. return result;
  59726. };
  59727. /**
  59728. * Function: isEventSourceIgnored
  59729. *
  59730. * Returns true if the event should be ignored in <fireMouseEvent>. This
  59731. * implementation returns true for select, option and input (if not of type
  59732. * checkbox, radio, button, submit or file) event sources if the event is not
  59733. * a mouse event or a left mouse button press event.
  59734. *
  59735. * Parameters:
  59736. *
  59737. * evtName - The name of the event.
  59738. * me - <mxMouseEvent> that should be ignored.
  59739. */
  59740. mxGraph.prototype.isEventSourceIgnored = function(evtName, me)
  59741. {
  59742. var source = me.getSource();
  59743. var name = (source.nodeName != null) ? source.nodeName.toLowerCase() : '';
  59744. var candidate = !mxEvent.isMouseEvent(me.getEvent()) || mxEvent.isLeftMouseButton(me.getEvent());
  59745. return evtName == mxEvent.MOUSE_DOWN && candidate && (name == 'select' || name == 'option' ||
  59746. (name == 'input' && source.type != 'checkbox' && source.type != 'radio' &&
  59747. source.type != 'button' && source.type != 'submit' && source.type != 'file'));
  59748. };
  59749. /**
  59750. * Function: getEventState
  59751. *
  59752. * Returns the <mxCellState> to be used when firing the mouse event for the
  59753. * given state. This implementation returns the given state.
  59754. *
  59755. * Parameters:
  59756. *
  59757. * <mxCellState> - State whose event source should be returned.
  59758. */
  59759. mxGraph.prototype.getEventState = function(state)
  59760. {
  59761. return state;
  59762. };
  59763. /**
  59764. * Function: fireMouseEvent
  59765. *
  59766. * Dispatches the given event in the graph event dispatch loop. Possible
  59767. * event names are <mxEvent.MOUSE_DOWN>, <mxEvent.MOUSE_MOVE> and
  59768. * <mxEvent.MOUSE_UP>. All listeners are invoked for all events regardless
  59769. * of the consumed state of the event.
  59770. *
  59771. * Parameters:
  59772. *
  59773. * evtName - String that specifies the type of event to be dispatched.
  59774. * me - <mxMouseEvent> to be fired.
  59775. * sender - Optional sender argument. Default is this.
  59776. */
  59777. mxGraph.prototype.fireMouseEvent = function(evtName, me, sender)
  59778. {
  59779. if (this.isEventSourceIgnored(evtName, me))
  59780. {
  59781. if (this.tooltipHandler != null)
  59782. {
  59783. this.tooltipHandler.hide();
  59784. }
  59785. return;
  59786. }
  59787. if (sender == null)
  59788. {
  59789. sender = this;
  59790. }
  59791. // Updates the graph coordinates in the event
  59792. me = this.updateMouseEvent(me, evtName);
  59793. // Detects and processes double taps for touch-based devices which do not have native double click events
  59794. // or where detection of double click is not always possible (quirks, IE10+). Note that this can only handle
  59795. // double clicks on cells because the sequence of events in IE prevents detection on the background, it fires
  59796. // two mouse ups, one of which without a cell but no mousedown for the second click which means we cannot
  59797. // detect which mouseup(s) are part of the first click, ie we do not know when the first click ends.
  59798. if ((!this.nativeDblClickEnabled && !mxEvent.isPopupTrigger(me.getEvent())) || (this.doubleTapEnabled &&
  59799. mxClient.IS_TOUCH && (mxEvent.isTouchEvent(me.getEvent()) || mxEvent.isPenEvent(me.getEvent()))))
  59800. {
  59801. var currentTime = new Date().getTime();
  59802. // NOTE: Second mouseDown for double click missing in quirks mode
  59803. if ((!mxClient.IS_QUIRKS && evtName == mxEvent.MOUSE_DOWN) || (mxClient.IS_QUIRKS && evtName == mxEvent.MOUSE_UP && !this.fireDoubleClick))
  59804. {
  59805. if (this.lastTouchEvent != null && this.lastTouchEvent != me.getEvent() &&
  59806. currentTime - this.lastTouchTime < this.doubleTapTimeout &&
  59807. Math.abs(this.lastTouchX - me.getX()) < this.doubleTapTolerance &&
  59808. Math.abs(this.lastTouchY - me.getY()) < this.doubleTapTolerance &&
  59809. this.doubleClickCounter < 2)
  59810. {
  59811. this.doubleClickCounter++;
  59812. var doubleClickFired = false;
  59813. if (evtName == mxEvent.MOUSE_UP)
  59814. {
  59815. if (me.getCell() == this.lastTouchCell && this.lastTouchCell != null)
  59816. {
  59817. this.lastTouchTime = 0;
  59818. var cell = this.lastTouchCell;
  59819. this.lastTouchCell = null;
  59820. // Fires native dblclick event via event source
  59821. // NOTE: This fires two double click events on edges in quirks mode. While
  59822. // trying to fix this, we realized that nativeDoubleClick can be disabled for
  59823. // quirks and IE10+ (or we didn't find the case mentioned above where it
  59824. // would not work), ie. all double clicks seem to be working without this.
  59825. if (mxClient.IS_QUIRKS)
  59826. {
  59827. me.getSource().fireEvent('ondblclick');
  59828. }
  59829. this.dblClick(me.getEvent(), cell);
  59830. doubleClickFired = true;
  59831. }
  59832. }
  59833. else
  59834. {
  59835. this.fireDoubleClick = true;
  59836. this.lastTouchTime = 0;
  59837. }
  59838. // Do not ignore mouse up in quirks in this case
  59839. if (!mxClient.IS_QUIRKS || doubleClickFired)
  59840. {
  59841. mxEvent.consume(me.getEvent());
  59842. return;
  59843. }
  59844. }
  59845. else if (this.lastTouchEvent == null || this.lastTouchEvent != me.getEvent())
  59846. {
  59847. this.lastTouchCell = me.getCell();
  59848. this.lastTouchX = me.getX();
  59849. this.lastTouchY = me.getY();
  59850. this.lastTouchTime = currentTime;
  59851. this.lastTouchEvent = me.getEvent();
  59852. this.doubleClickCounter = 0;
  59853. }
  59854. }
  59855. else if ((this.isMouseDown || evtName == mxEvent.MOUSE_UP) && this.fireDoubleClick)
  59856. {
  59857. this.fireDoubleClick = false;
  59858. var cell = this.lastTouchCell;
  59859. this.lastTouchCell = null;
  59860. this.isMouseDown = false;
  59861. // Workaround for Chrome/Safari not firing native double click events for double touch on background
  59862. var valid = (cell != null) || ((mxEvent.isTouchEvent(me.getEvent()) || mxEvent.isPenEvent(me.getEvent())) &&
  59863. (mxClient.IS_GC || mxClient.IS_SF));
  59864. if (valid && Math.abs(this.lastTouchX - me.getX()) < this.doubleTapTolerance &&
  59865. Math.abs(this.lastTouchY - me.getY()) < this.doubleTapTolerance)
  59866. {
  59867. this.dblClick(me.getEvent(), cell);
  59868. }
  59869. else
  59870. {
  59871. mxEvent.consume(me.getEvent());
  59872. }
  59873. return;
  59874. }
  59875. }
  59876. if (!this.isEventIgnored(evtName, me, sender))
  59877. {
  59878. // Updates the event state via getEventState
  59879. me.state = this.getEventState(me.getState());
  59880. this.fireEvent(new mxEventObject(mxEvent.FIRE_MOUSE_EVENT, 'eventName', evtName, 'event', me));
  59881. if ((mxClient.IS_OP || mxClient.IS_SF || mxClient.IS_GC || mxClient.IS_IE11 ||
  59882. (mxClient.IS_IE && mxClient.IS_SVG) || me.getEvent().target != this.container))
  59883. {
  59884. if (evtName == mxEvent.MOUSE_MOVE && this.isMouseDown && this.autoScroll && !mxEvent.isMultiTouchEvent(me.getEvent))
  59885. {
  59886. this.scrollPointToVisible(me.getGraphX(), me.getGraphY(), this.autoExtend);
  59887. }
  59888. else if (evtName == mxEvent.MOUSE_UP && this.ignoreScrollbars && this.translateToScrollPosition &&
  59889. (this.container.scrollLeft != 0 || this.container.scrollTop != 0))
  59890. {
  59891. var s = this.view.scale;
  59892. var tr = this.view.translate;
  59893. this.view.setTranslate(tr.x - this.container.scrollLeft / s, tr.y - this.container.scrollTop / s);
  59894. this.container.scrollLeft = 0;
  59895. this.container.scrollTop = 0;
  59896. }
  59897. if (this.mouseListeners != null)
  59898. {
  59899. var args = [sender, me];
  59900. // Does not change returnValue in Opera
  59901. if (!me.getEvent().preventDefault)
  59902. {
  59903. me.getEvent().returnValue = true;
  59904. }
  59905. for (var i = 0; i < this.mouseListeners.length; i++)
  59906. {
  59907. var l = this.mouseListeners[i];
  59908. if (evtName == mxEvent.MOUSE_DOWN)
  59909. {
  59910. l.mouseDown.apply(l, args);
  59911. }
  59912. else if (evtName == mxEvent.MOUSE_MOVE)
  59913. {
  59914. l.mouseMove.apply(l, args);
  59915. }
  59916. else if (evtName == mxEvent.MOUSE_UP)
  59917. {
  59918. l.mouseUp.apply(l, args);
  59919. }
  59920. }
  59921. }
  59922. // Invokes the click handler
  59923. if (evtName == mxEvent.MOUSE_UP)
  59924. {
  59925. this.click(me);
  59926. }
  59927. }
  59928. // Detects tapAndHold events using a timer
  59929. if ((mxEvent.isTouchEvent(me.getEvent()) || mxEvent.isPenEvent(me.getEvent())) &&
  59930. evtName == mxEvent.MOUSE_DOWN && this.tapAndHoldEnabled && !this.tapAndHoldInProgress)
  59931. {
  59932. this.tapAndHoldInProgress = true;
  59933. this.initialTouchX = me.getGraphX();
  59934. this.initialTouchY = me.getGraphY();
  59935. var handler = function()
  59936. {
  59937. if (this.tapAndHoldValid)
  59938. {
  59939. this.tapAndHold(me);
  59940. }
  59941. this.tapAndHoldInProgress = false;
  59942. this.tapAndHoldValid = false;
  59943. };
  59944. if (this.tapAndHoldThread)
  59945. {
  59946. window.clearTimeout(this.tapAndHoldThread);
  59947. }
  59948. this.tapAndHoldThread = window.setTimeout(mxUtils.bind(this, handler), this.tapAndHoldDelay);
  59949. this.tapAndHoldValid = true;
  59950. }
  59951. else if (evtName == mxEvent.MOUSE_UP)
  59952. {
  59953. this.tapAndHoldInProgress = false;
  59954. this.tapAndHoldValid = false;
  59955. }
  59956. else if (this.tapAndHoldValid)
  59957. {
  59958. this.tapAndHoldValid =
  59959. Math.abs(this.initialTouchX - me.getGraphX()) < this.tolerance &&
  59960. Math.abs(this.initialTouchY - me.getGraphY()) < this.tolerance;
  59961. }
  59962. // Stops editing for all events other than from cellEditor
  59963. if (evtName == mxEvent.MOUSE_DOWN && this.isEditing() && !this.cellEditor.isEventSource(me.getEvent()))
  59964. {
  59965. this.stopEditing(!this.isInvokesStopCellEditing());
  59966. }
  59967. this.consumeMouseEvent(evtName, me, sender);
  59968. }
  59969. };
  59970. /**
  59971. * Function: consumeMouseEvent
  59972. *
  59973. * Consumes the given <mxMouseEvent> if it's a touchStart event.
  59974. */
  59975. mxGraph.prototype.consumeMouseEvent = function(evtName, me, sender)
  59976. {
  59977. // Workaround for duplicate click in Windows 8 with Chrome/FF/Opera with touch
  59978. if (evtName == mxEvent.MOUSE_DOWN && mxEvent.isTouchEvent(me.getEvent()))
  59979. {
  59980. me.consume(false);
  59981. }
  59982. };
  59983. /**
  59984. * Function: fireGestureEvent
  59985. *
  59986. * Dispatches a <mxEvent.GESTURE> event. The following example will resize the
  59987. * cell under the mouse based on the scale property of the native touch event.
  59988. *
  59989. * (code)
  59990. * graph.addListener(mxEvent.GESTURE, function(sender, eo)
  59991. * {
  59992. * var evt = eo.getProperty('event');
  59993. * var state = graph.view.getState(eo.getProperty('cell'));
  59994. *
  59995. * if (graph.isEnabled() && graph.isCellResizable(state.cell) && Math.abs(1 - evt.scale) > 0.2)
  59996. * {
  59997. * var scale = graph.view.scale;
  59998. * var tr = graph.view.translate;
  59999. *
  60000. * var w = state.width * evt.scale;
  60001. * var h = state.height * evt.scale;
  60002. * var x = state.x - (w - state.width) / 2;
  60003. * var y = state.y - (h - state.height) / 2;
  60004. *
  60005. * var bounds = new mxRectangle(graph.snap(x / scale) - tr.x,
  60006. * graph.snap(y / scale) - tr.y, graph.snap(w / scale), graph.snap(h / scale));
  60007. * graph.resizeCell(state.cell, bounds);
  60008. * eo.consume();
  60009. * }
  60010. * });
  60011. * (end)
  60012. *
  60013. * Parameters:
  60014. *
  60015. * evt - Gestureend event that represents the gesture.
  60016. * cell - Optional <mxCell> associated with the gesture.
  60017. */
  60018. mxGraph.prototype.fireGestureEvent = function(evt, cell)
  60019. {
  60020. // Resets double tap event handling when gestures take place
  60021. this.lastTouchTime = 0;
  60022. this.fireEvent(new mxEventObject(mxEvent.GESTURE, 'event', evt, 'cell', cell));
  60023. };
  60024. /**
  60025. * Function: destroy
  60026. *
  60027. * Destroys the graph and all its resources.
  60028. */
  60029. mxGraph.prototype.destroy = function()
  60030. {
  60031. if (!this.destroyed)
  60032. {
  60033. this.destroyed = true;
  60034. if (this.tooltipHandler != null)
  60035. {
  60036. this.tooltipHandler.destroy();
  60037. }
  60038. if (this.selectionCellsHandler != null)
  60039. {
  60040. this.selectionCellsHandler.destroy();
  60041. }
  60042. if (this.panningHandler != null)
  60043. {
  60044. this.panningHandler.destroy();
  60045. }
  60046. if (this.popupMenuHandler != null)
  60047. {
  60048. this.popupMenuHandler.destroy();
  60049. }
  60050. if (this.connectionHandler != null)
  60051. {
  60052. this.connectionHandler.destroy();
  60053. }
  60054. if (this.graphHandler != null)
  60055. {
  60056. this.graphHandler.destroy();
  60057. }
  60058. if (this.cellEditor != null)
  60059. {
  60060. this.cellEditor.destroy();
  60061. }
  60062. if (this.view != null)
  60063. {
  60064. this.view.destroy();
  60065. }
  60066. if (this.model != null && this.graphModelChangeListener != null)
  60067. {
  60068. this.model.removeListener(this.graphModelChangeListener);
  60069. this.graphModelChangeListener = null;
  60070. }
  60071. this.container = null;
  60072. }
  60073. };
  60074. /**
  60075. * Copyright (c) 2006-2015, JGraph Ltd
  60076. * Copyright (c) 2006-2015, Gaudenz Alder
  60077. */
  60078. /**
  60079. * Class: mxCellOverlay
  60080. *
  60081. * Extends <mxEventSource> to implement a graph overlay, represented by an icon
  60082. * and a tooltip. Overlays can handle and fire <click> events and are added to
  60083. * the graph using <mxGraph.addCellOverlay>, and removed using
  60084. * <mxGraph.removeCellOverlay>, or <mxGraph.removeCellOverlays> to remove all overlays.
  60085. * The <mxGraph.getCellOverlays> function returns the array of overlays for a given
  60086. * cell in a graph. If multiple overlays exist for the same cell, then
  60087. * <getBounds> should be overridden in at least one of the overlays.
  60088. *
  60089. * Overlays appear on top of all cells in a special layer. If this is not
  60090. * desirable, then the image must be rendered as part of the shape or label of
  60091. * the cell instead.
  60092. *
  60093. * Example:
  60094. *
  60095. * The following adds a new overlays for a given vertex and selects the cell
  60096. * if the overlay is clicked.
  60097. *
  60098. * (code)
  60099. * var overlay = new mxCellOverlay(img, html);
  60100. * graph.addCellOverlay(vertex, overlay);
  60101. * overlay.addListener(mxEvent.CLICK, function(sender, evt)
  60102. * {
  60103. * var cell = evt.getProperty('cell');
  60104. * graph.setSelectionCell(cell);
  60105. * });
  60106. * (end)
  60107. *
  60108. * For cell overlays to be printed use <mxPrintPreview.printOverlays>.
  60109. *
  60110. * Event: mxEvent.CLICK
  60111. *
  60112. * Fires when the user clicks on the overlay. The <code>event</code> property
  60113. * contains the corresponding mouse event and the <code>cell</code> property
  60114. * contains the cell. For touch devices this is fired if the element receives
  60115. * a touchend event.
  60116. *
  60117. * Constructor: mxCellOverlay
  60118. *
  60119. * Constructs a new overlay using the given image and tooltip.
  60120. *
  60121. * Parameters:
  60122. *
  60123. * image - <mxImage> that represents the icon to be displayed.
  60124. * tooltip - Optional string that specifies the tooltip.
  60125. * align - Optional horizontal alignment for the overlay. Possible
  60126. * values are <ALIGN_LEFT>, <ALIGN_CENTER> and <ALIGN_RIGHT>
  60127. * (default).
  60128. * verticalAlign - Vertical alignment for the overlay. Possible
  60129. * values are <ALIGN_TOP>, <ALIGN_MIDDLE> and <ALIGN_BOTTOM>
  60130. * (default).
  60131. */
  60132. function mxCellOverlay(image, tooltip, align, verticalAlign, offset, cursor)
  60133. {
  60134. this.image = image;
  60135. this.tooltip = tooltip;
  60136. this.align = (align != null) ? align : this.align;
  60137. this.verticalAlign = (verticalAlign != null) ? verticalAlign : this.verticalAlign;
  60138. this.offset = (offset != null) ? offset : new mxPoint();
  60139. this.cursor = (cursor != null) ? cursor : 'help';
  60140. };
  60141. /**
  60142. * Extends mxEventSource.
  60143. */
  60144. mxCellOverlay.prototype = new mxEventSource();
  60145. mxCellOverlay.prototype.constructor = mxCellOverlay;
  60146. /**
  60147. * Variable: image
  60148. *
  60149. * Holds the <mxImage> to be used as the icon.
  60150. */
  60151. mxCellOverlay.prototype.image = null;
  60152. /**
  60153. * Variable: tooltip
  60154. *
  60155. * Holds the optional string to be used as the tooltip.
  60156. */
  60157. mxCellOverlay.prototype.tooltip = null;
  60158. /**
  60159. * Variable: align
  60160. *
  60161. * Holds the horizontal alignment for the overlay. Default is
  60162. * <mxConstants.ALIGN_RIGHT>. For edges, the overlay always appears in the
  60163. * center of the edge.
  60164. */
  60165. mxCellOverlay.prototype.align = mxConstants.ALIGN_RIGHT;
  60166. /**
  60167. * Variable: verticalAlign
  60168. *
  60169. * Holds the vertical alignment for the overlay. Default is
  60170. * <mxConstants.ALIGN_BOTTOM>. For edges, the overlay always appears in the
  60171. * center of the edge.
  60172. */
  60173. mxCellOverlay.prototype.verticalAlign = mxConstants.ALIGN_BOTTOM;
  60174. /**
  60175. * Variable: offset
  60176. *
  60177. * Holds the offset as an <mxPoint>. The offset will be scaled according to the
  60178. * current scale.
  60179. */
  60180. mxCellOverlay.prototype.offset = null;
  60181. /**
  60182. * Variable: cursor
  60183. *
  60184. * Holds the cursor for the overlay. Default is 'help'.
  60185. */
  60186. mxCellOverlay.prototype.cursor = null;
  60187. /**
  60188. * Variable: defaultOverlap
  60189. *
  60190. * Defines the overlapping for the overlay, that is, the proportional distance
  60191. * from the origin to the point defined by the alignment. Default is 0.5.
  60192. */
  60193. mxCellOverlay.prototype.defaultOverlap = 0.5;
  60194. /**
  60195. * Function: getBounds
  60196. *
  60197. * Returns the bounds of the overlay for the given <mxCellState> as an
  60198. * <mxRectangle>. This should be overridden when using multiple overlays
  60199. * per cell so that the overlays do not overlap.
  60200. *
  60201. * The following example will place the overlay along an edge (where
  60202. * x=[-1..1] from the start to the end of the edge and y is the
  60203. * orthogonal offset in px).
  60204. *
  60205. * (code)
  60206. * overlay.getBounds = function(state)
  60207. * {
  60208. * var bounds = mxCellOverlay.prototype.getBounds.apply(this, arguments);
  60209. *
  60210. * if (state.view.graph.getModel().isEdge(state.cell))
  60211. * {
  60212. * var pt = state.view.getPoint(state, {x: 0, y: 0, relative: true});
  60213. *
  60214. * bounds.x = pt.x - bounds.width / 2;
  60215. * bounds.y = pt.y - bounds.height / 2;
  60216. * }
  60217. *
  60218. * return bounds;
  60219. * };
  60220. * (end)
  60221. *
  60222. * Parameters:
  60223. *
  60224. * state - <mxCellState> that represents the current state of the
  60225. * associated cell.
  60226. */
  60227. mxCellOverlay.prototype.getBounds = function(state)
  60228. {
  60229. var isEdge = state.view.graph.getModel().isEdge(state.cell);
  60230. var s = state.view.scale;
  60231. var pt = null;
  60232. var w = this.image.width;
  60233. var h = this.image.height;
  60234. if (isEdge)
  60235. {
  60236. var pts = state.absolutePoints;
  60237. if (pts.length % 2 == 1)
  60238. {
  60239. pt = pts[Math.floor(pts.length / 2)];
  60240. }
  60241. else
  60242. {
  60243. var idx = pts.length / 2;
  60244. var p0 = pts[idx-1];
  60245. var p1 = pts[idx];
  60246. pt = new mxPoint(p0.x + (p1.x - p0.x) / 2,
  60247. p0.y + (p1.y - p0.y) / 2);
  60248. }
  60249. }
  60250. else
  60251. {
  60252. pt = new mxPoint();
  60253. if (this.align == mxConstants.ALIGN_LEFT)
  60254. {
  60255. pt.x = state.x;
  60256. }
  60257. else if (this.align == mxConstants.ALIGN_CENTER)
  60258. {
  60259. pt.x = state.x + state.width / 2;
  60260. }
  60261. else
  60262. {
  60263. pt.x = state.x + state.width;
  60264. }
  60265. if (this.verticalAlign == mxConstants.ALIGN_TOP)
  60266. {
  60267. pt.y = state.y;
  60268. }
  60269. else if (this.verticalAlign == mxConstants.ALIGN_MIDDLE)
  60270. {
  60271. pt.y = state.y + state.height / 2;
  60272. }
  60273. else
  60274. {
  60275. pt.y = state.y + state.height;
  60276. }
  60277. }
  60278. return new mxRectangle(Math.round(pt.x - (w * this.defaultOverlap - this.offset.x) * s),
  60279. Math.round(pt.y - (h * this.defaultOverlap - this.offset.y) * s), w * s, h * s);
  60280. };
  60281. /**
  60282. * Function: toString
  60283. *
  60284. * Returns the textual representation of the overlay to be used as the
  60285. * tooltip. This implementation returns <tooltip>.
  60286. */
  60287. mxCellOverlay.prototype.toString = function()
  60288. {
  60289. return this.tooltip;
  60290. };
  60291. /**
  60292. * Copyright (c) 2006-2015, JGraph Ltd
  60293. * Copyright (c) 2006-2015, Gaudenz Alder
  60294. */
  60295. /**
  60296. * Class: mxOutline
  60297. *
  60298. * Implements an outline (aka overview) for a graph. Set <updateOnPan> to true
  60299. * to enable updates while the source graph is panning.
  60300. *
  60301. * Example:
  60302. *
  60303. * (code)
  60304. * var outline = new mxOutline(graph, div);
  60305. * (end)
  60306. *
  60307. * If an outline is used in an <mxWindow> in IE8 standards mode, the following
  60308. * code makes sure that the shadow filter is not inherited and that any
  60309. * transparent elements in the graph do not show the page background, but the
  60310. * background of the graph container.
  60311. *
  60312. * (code)
  60313. * if (document.documentMode == 8)
  60314. * {
  60315. * container.style.filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=100)';
  60316. * }
  60317. * (end)
  60318. *
  60319. * To move the graph to the top, left corner the following code can be used.
  60320. *
  60321. * (code)
  60322. * var scale = graph.view.scale;
  60323. * var bounds = graph.getGraphBounds();
  60324. * graph.view.setTranslate(-bounds.x / scale, -bounds.y / scale);
  60325. * (end)
  60326. *
  60327. * To toggle the suspended mode, the following can be used.
  60328. *
  60329. * (code)
  60330. * outline.suspended = !outln.suspended;
  60331. * if (!outline.suspended)
  60332. * {
  60333. * outline.update(true);
  60334. * }
  60335. * (end)
  60336. *
  60337. * Constructor: mxOutline
  60338. *
  60339. * Constructs a new outline for the specified graph inside the given
  60340. * container.
  60341. *
  60342. * Parameters:
  60343. *
  60344. * source - <mxGraph> to create the outline for.
  60345. * container - DOM node that will contain the outline.
  60346. */
  60347. function mxOutline(source, container)
  60348. {
  60349. this.source = source;
  60350. if (container != null)
  60351. {
  60352. this.init(container);
  60353. }
  60354. };
  60355. /**
  60356. * Function: source
  60357. *
  60358. * Reference to the source <mxGraph>.
  60359. */
  60360. mxOutline.prototype.source = null;
  60361. /**
  60362. * Function: outline
  60363. *
  60364. * Reference to the <mxGraph> that renders the outline.
  60365. */
  60366. mxOutline.prototype.outline = null;
  60367. /**
  60368. * Function: graphRenderHint
  60369. *
  60370. * Renderhint to be used for the outline graph. Default is faster.
  60371. */
  60372. mxOutline.prototype.graphRenderHint = mxConstants.RENDERING_HINT_FASTER;
  60373. /**
  60374. * Variable: enabled
  60375. *
  60376. * Specifies if events are handled. Default is true.
  60377. */
  60378. mxOutline.prototype.enabled = true;
  60379. /**
  60380. * Variable: showViewport
  60381. *
  60382. * Specifies a viewport rectangle should be shown. Default is true.
  60383. */
  60384. mxOutline.prototype.showViewport = true;
  60385. /**
  60386. * Variable: border
  60387. *
  60388. * Border to be added at the bottom and right. Default is 10.
  60389. */
  60390. mxOutline.prototype.border = 10;
  60391. /**
  60392. * Variable: enabled
  60393. *
  60394. * Specifies the size of the sizer handler. Default is 8.
  60395. */
  60396. mxOutline.prototype.sizerSize = 8;
  60397. /**
  60398. * Variable: labelsVisible
  60399. *
  60400. * Specifies if labels should be visible in the outline. Default is false.
  60401. */
  60402. mxOutline.prototype.labelsVisible = false;
  60403. /**
  60404. * Variable: updateOnPan
  60405. *
  60406. * Specifies if <update> should be called for <mxEvent.PAN> in the source
  60407. * graph. Default is false.
  60408. */
  60409. mxOutline.prototype.updateOnPan = false;
  60410. /**
  60411. * Variable: sizerImage
  60412. *
  60413. * Optional <mxImage> to be used for the sizer. Default is null.
  60414. */
  60415. mxOutline.prototype.sizerImage = null;
  60416. /**
  60417. * Variable: minScale
  60418. *
  60419. * Minimum scale to be used. Default is 0.0001.
  60420. */
  60421. mxOutline.prototype.minScale = 0.0001;
  60422. /**
  60423. * Variable: suspended
  60424. *
  60425. * Optional boolean flag to suspend updates. Default is false. This flag will
  60426. * also suspend repaints of the outline. To toggle this switch, use the
  60427. * following code.
  60428. *
  60429. * (code)
  60430. * nav.suspended = !nav.suspended;
  60431. *
  60432. * if (!nav.suspended)
  60433. * {
  60434. * nav.update(true);
  60435. * }
  60436. * (end)
  60437. */
  60438. mxOutline.prototype.suspended = false;
  60439. /**
  60440. * Variable: forceVmlHandles
  60441. *
  60442. * Specifies if VML should be used to render the handles in this control. This
  60443. * is true for IE8 standards mode and false for all other browsers and modes.
  60444. * This is a workaround for rendering issues of HTML elements over elements
  60445. * with filters in IE 8 standards mode.
  60446. */
  60447. mxOutline.prototype.forceVmlHandles = document.documentMode == 8;
  60448. /**
  60449. * Function: createGraph
  60450. *
  60451. * Creates the <mxGraph> used in the outline.
  60452. */
  60453. mxOutline.prototype.createGraph = function(container)
  60454. {
  60455. var graph = new mxGraph(container, this.source.getModel(), this.graphRenderHint, this.source.getStylesheet());
  60456. graph.foldingEnabled = false;
  60457. graph.autoScroll = false;
  60458. return graph;
  60459. };
  60460. /**
  60461. * Function: init
  60462. *
  60463. * Initializes the outline inside the given container.
  60464. */
  60465. mxOutline.prototype.init = function(container)
  60466. {
  60467. this.outline = this.createGraph(container);
  60468. // Do not repaint when suspended
  60469. var outlineGraphModelChanged = this.outline.graphModelChanged;
  60470. this.outline.graphModelChanged = mxUtils.bind(this, function(changes)
  60471. {
  60472. if (!this.suspended && this.outline != null)
  60473. {
  60474. outlineGraphModelChanged.apply(this.outline, arguments);
  60475. }
  60476. });
  60477. // Enables faster painting in SVG
  60478. if (mxClient.IS_SVG)
  60479. {
  60480. var node = this.outline.getView().getCanvas().parentNode;
  60481. node.setAttribute('shape-rendering', 'optimizeSpeed');
  60482. node.setAttribute('image-rendering', 'optimizeSpeed');
  60483. }
  60484. // Hides cursors and labels
  60485. this.outline.labelsVisible = this.labelsVisible;
  60486. this.outline.setEnabled(false);
  60487. this.updateHandler = mxUtils.bind(this, function(sender, evt)
  60488. {
  60489. if (!this.suspended && !this.active)
  60490. {
  60491. this.update();
  60492. }
  60493. });
  60494. // Updates the scale of the outline after a change of the main graph
  60495. this.source.getModel().addListener(mxEvent.CHANGE, this.updateHandler);
  60496. this.outline.addMouseListener(this);
  60497. // Adds listeners to keep the outline in sync with the source graph
  60498. var view = this.source.getView();
  60499. view.addListener(mxEvent.SCALE, this.updateHandler);
  60500. view.addListener(mxEvent.TRANSLATE, this.updateHandler);
  60501. view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.updateHandler);
  60502. view.addListener(mxEvent.DOWN, this.updateHandler);
  60503. view.addListener(mxEvent.UP, this.updateHandler);
  60504. // Updates blue rectangle on scroll
  60505. mxEvent.addListener(this.source.container, 'scroll', this.updateHandler);
  60506. this.panHandler = mxUtils.bind(this, function(sender)
  60507. {
  60508. if (this.updateOnPan)
  60509. {
  60510. this.updateHandler.apply(this, arguments);
  60511. }
  60512. });
  60513. this.source.addListener(mxEvent.PAN, this.panHandler);
  60514. // Refreshes the graph in the outline after a refresh of the main graph
  60515. this.refreshHandler = mxUtils.bind(this, function(sender)
  60516. {
  60517. this.outline.setStylesheet(this.source.getStylesheet());
  60518. this.outline.refresh();
  60519. });
  60520. this.source.addListener(mxEvent.REFRESH, this.refreshHandler);
  60521. // Creates the blue rectangle for the viewport
  60522. this.bounds = new mxRectangle(0, 0, 0, 0);
  60523. this.selectionBorder = new mxRectangleShape(this.bounds, null,
  60524. mxConstants.OUTLINE_COLOR, mxConstants.OUTLINE_STROKEWIDTH);
  60525. this.selectionBorder.dialect = this.outline.dialect;
  60526. if (this.forceVmlHandles)
  60527. {
  60528. this.selectionBorder.isHtmlAllowed = function()
  60529. {
  60530. return false;
  60531. };
  60532. }
  60533. this.selectionBorder.init(this.outline.getView().getOverlayPane());
  60534. // Handles event by catching the initial pointer start and then listening to the
  60535. // complete gesture on the event target. This is needed because all the events
  60536. // are routed via the initial element even if that element is removed from the
  60537. // DOM, which happens when we repaint the selection border and zoom handles.
  60538. var handler = mxUtils.bind(this, function(evt)
  60539. {
  60540. var t = mxEvent.getSource(evt);
  60541. var redirect = mxUtils.bind(this, function(evt)
  60542. {
  60543. this.outline.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt));
  60544. });
  60545. var redirect2 = mxUtils.bind(this, function(evt)
  60546. {
  60547. mxEvent.removeGestureListeners(t, null, redirect, redirect2);
  60548. this.outline.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt));
  60549. });
  60550. mxEvent.addGestureListeners(t, null, redirect, redirect2);
  60551. this.outline.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt));
  60552. });
  60553. mxEvent.addGestureListeners(this.selectionBorder.node, handler);
  60554. // Creates a small blue rectangle for sizing (sizer handle)
  60555. this.sizer = this.createSizer();
  60556. if (this.forceVmlHandles)
  60557. {
  60558. this.sizer.isHtmlAllowed = function()
  60559. {
  60560. return false;
  60561. };
  60562. }
  60563. this.sizer.init(this.outline.getView().getOverlayPane());
  60564. if (this.enabled)
  60565. {
  60566. this.sizer.node.style.cursor = 'nwse-resize';
  60567. }
  60568. mxEvent.addGestureListeners(this.sizer.node, handler);
  60569. this.selectionBorder.node.style.display = (this.showViewport) ? '' : 'none';
  60570. this.sizer.node.style.display = this.selectionBorder.node.style.display;
  60571. this.selectionBorder.node.style.cursor = 'move';
  60572. this.update(false);
  60573. };
  60574. /**
  60575. * Function: isEnabled
  60576. *
  60577. * Returns true if events are handled. This implementation
  60578. * returns <enabled>.
  60579. */
  60580. mxOutline.prototype.isEnabled = function()
  60581. {
  60582. return this.enabled;
  60583. };
  60584. /**
  60585. * Function: setEnabled
  60586. *
  60587. * Enables or disables event handling. This implementation
  60588. * updates <enabled>.
  60589. *
  60590. * Parameters:
  60591. *
  60592. * value - Boolean that specifies the new enabled state.
  60593. */
  60594. mxOutline.prototype.setEnabled = function(value)
  60595. {
  60596. this.enabled = value;
  60597. };
  60598. /**
  60599. * Function: setZoomEnabled
  60600. *
  60601. * Enables or disables the zoom handling by showing or hiding the respective
  60602. * handle.
  60603. *
  60604. * Parameters:
  60605. *
  60606. * value - Boolean that specifies the new enabled state.
  60607. */
  60608. mxOutline.prototype.setZoomEnabled = function(value)
  60609. {
  60610. this.sizer.node.style.visibility = (value) ? 'visible' : 'hidden';
  60611. };
  60612. /**
  60613. * Function: refresh
  60614. *
  60615. * Invokes <update> and revalidate the outline. This method is deprecated.
  60616. */
  60617. mxOutline.prototype.refresh = function()
  60618. {
  60619. this.update(true);
  60620. };
  60621. /**
  60622. * Function: createSizer
  60623. *
  60624. * Creates the shape used as the sizer.
  60625. */
  60626. mxOutline.prototype.createSizer = function()
  60627. {
  60628. if (this.sizerImage != null)
  60629. {
  60630. var sizer = new mxImageShape(new mxRectangle(0, 0, this.sizerImage.width, this.sizerImage.height), this.sizerImage.src);
  60631. sizer.dialect = this.outline.dialect;
  60632. return sizer;
  60633. }
  60634. else
  60635. {
  60636. var sizer = new mxRectangleShape(new mxRectangle(0, 0, this.sizerSize, this.sizerSize),
  60637. mxConstants.OUTLINE_HANDLE_FILLCOLOR, mxConstants.OUTLINE_HANDLE_STROKECOLOR);
  60638. sizer.dialect = this.outline.dialect;
  60639. return sizer;
  60640. }
  60641. };
  60642. /**
  60643. * Function: getSourceContainerSize
  60644. *
  60645. * Returns the size of the source container.
  60646. */
  60647. mxOutline.prototype.getSourceContainerSize = function()
  60648. {
  60649. return new mxRectangle(0, 0, this.source.container.scrollWidth, this.source.container.scrollHeight);
  60650. };
  60651. /**
  60652. * Function: getOutlineOffset
  60653. *
  60654. * Returns the offset for drawing the outline graph.
  60655. */
  60656. mxOutline.prototype.getOutlineOffset = function(scale)
  60657. {
  60658. return null;
  60659. };
  60660. /**
  60661. * Function: getOutlineOffset
  60662. *
  60663. * Returns the offset for drawing the outline graph.
  60664. */
  60665. mxOutline.prototype.getSourceGraphBounds = function()
  60666. {
  60667. return this.source.getGraphBounds();
  60668. };
  60669. /**
  60670. * Function: update
  60671. *
  60672. * Updates the outline.
  60673. */
  60674. mxOutline.prototype.update = function(revalidate)
  60675. {
  60676. if (this.source != null && this.source.container != null &&
  60677. this.outline != null && this.outline.container != null)
  60678. {
  60679. var sourceScale = this.source.view.scale;
  60680. var scaledGraphBounds = this.getSourceGraphBounds();
  60681. var unscaledGraphBounds = new mxRectangle(scaledGraphBounds.x / sourceScale + this.source.panDx,
  60682. scaledGraphBounds.y / sourceScale + this.source.panDy, scaledGraphBounds.width / sourceScale,
  60683. scaledGraphBounds.height / sourceScale);
  60684. var unscaledFinderBounds = new mxRectangle(0, 0,
  60685. this.source.container.clientWidth / sourceScale,
  60686. this.source.container.clientHeight / sourceScale);
  60687. var union = unscaledGraphBounds.clone();
  60688. union.add(unscaledFinderBounds);
  60689. // Zooms to the scrollable area if that is bigger than the graph
  60690. var size = this.getSourceContainerSize();
  60691. var completeWidth = Math.max(size.width / sourceScale, union.width);
  60692. var completeHeight = Math.max(size.height / sourceScale, union.height);
  60693. var availableWidth = Math.max(0, this.outline.container.clientWidth - this.border);
  60694. var availableHeight = Math.max(0, this.outline.container.clientHeight - this.border);
  60695. var outlineScale = Math.min(availableWidth / completeWidth, availableHeight / completeHeight);
  60696. var scale = (isNaN(outlineScale)) ? this.minScale : Math.max(this.minScale, outlineScale);
  60697. if (scale > 0)
  60698. {
  60699. if (this.outline.getView().scale != scale)
  60700. {
  60701. this.outline.getView().scale = scale;
  60702. revalidate = true;
  60703. }
  60704. var navView = this.outline.getView();
  60705. if (navView.currentRoot != this.source.getView().currentRoot)
  60706. {
  60707. navView.setCurrentRoot(this.source.getView().currentRoot);
  60708. }
  60709. var t = this.source.view.translate;
  60710. var tx = t.x + this.source.panDx;
  60711. var ty = t.y + this.source.panDy;
  60712. var off = this.getOutlineOffset(scale);
  60713. if (off != null)
  60714. {
  60715. tx += off.x;
  60716. ty += off.y;
  60717. }
  60718. if (unscaledGraphBounds.x < 0)
  60719. {
  60720. tx = tx - unscaledGraphBounds.x;
  60721. }
  60722. if (unscaledGraphBounds.y < 0)
  60723. {
  60724. ty = ty - unscaledGraphBounds.y;
  60725. }
  60726. if (navView.translate.x != tx || navView.translate.y != ty)
  60727. {
  60728. navView.translate.x = tx;
  60729. navView.translate.y = ty;
  60730. revalidate = true;
  60731. }
  60732. // Prepares local variables for computations
  60733. var t2 = navView.translate;
  60734. scale = this.source.getView().scale;
  60735. var scale2 = scale / navView.scale;
  60736. var scale3 = 1.0 / navView.scale;
  60737. var container = this.source.container;
  60738. // Updates the bounds of the viewrect in the navigation
  60739. this.bounds = new mxRectangle(
  60740. (t2.x - t.x - this.source.panDx) / scale3,
  60741. (t2.y - t.y - this.source.panDy) / scale3,
  60742. (container.clientWidth / scale2),
  60743. (container.clientHeight / scale2));
  60744. // Adds the scrollbar offset to the finder
  60745. this.bounds.x += this.source.container.scrollLeft * navView.scale / scale;
  60746. this.bounds.y += this.source.container.scrollTop * navView.scale / scale;
  60747. var b = this.selectionBorder.bounds;
  60748. if (b.x != this.bounds.x || b.y != this.bounds.y || b.width != this.bounds.width || b.height != this.bounds.height)
  60749. {
  60750. this.selectionBorder.bounds = this.bounds;
  60751. this.selectionBorder.redraw();
  60752. }
  60753. // Updates the bounds of the zoom handle at the bottom right
  60754. var b = this.sizer.bounds;
  60755. var b2 = new mxRectangle(this.bounds.x + this.bounds.width - b.width / 2,
  60756. this.bounds.y + this.bounds.height - b.height / 2, b.width, b.height);
  60757. if (b.x != b2.x || b.y != b2.y || b.width != b2.width || b.height != b2.height)
  60758. {
  60759. this.sizer.bounds = b2;
  60760. // Avoids update of visibility in redraw for VML
  60761. if (this.sizer.node.style.visibility != 'hidden')
  60762. {
  60763. this.sizer.redraw();
  60764. }
  60765. }
  60766. if (revalidate)
  60767. {
  60768. this.outline.view.revalidate();
  60769. }
  60770. }
  60771. }
  60772. };
  60773. /**
  60774. * Function: mouseDown
  60775. *
  60776. * Handles the event by starting a translation or zoom.
  60777. */
  60778. mxOutline.prototype.mouseDown = function(sender, me)
  60779. {
  60780. if (this.enabled && this.showViewport)
  60781. {
  60782. var tol = (!mxEvent.isMouseEvent(me.getEvent())) ? this.source.tolerance : 0;
  60783. var hit = (this.source.allowHandleBoundsCheck && (mxClient.IS_IE || tol > 0)) ?
  60784. new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol) : null;
  60785. this.zoom = me.isSource(this.sizer) || (hit != null && mxUtils.intersects(shape.bounds, hit));
  60786. this.startX = me.getX();
  60787. this.startY = me.getY();
  60788. this.active = true;
  60789. if (this.source.useScrollbarsForPanning && mxUtils.hasScrollbars(this.source.container))
  60790. {
  60791. this.dx0 = this.source.container.scrollLeft;
  60792. this.dy0 = this.source.container.scrollTop;
  60793. }
  60794. else
  60795. {
  60796. this.dx0 = 0;
  60797. this.dy0 = 0;
  60798. }
  60799. }
  60800. me.consume();
  60801. };
  60802. /**
  60803. * Function: mouseMove
  60804. *
  60805. * Handles the event by previewing the viewrect in <graph> and updating the
  60806. * rectangle that represents the viewrect in the outline.
  60807. */
  60808. mxOutline.prototype.mouseMove = function(sender, me)
  60809. {
  60810. if (this.active)
  60811. {
  60812. this.selectionBorder.node.style.display = (this.showViewport) ? '' : 'none';
  60813. this.sizer.node.style.display = this.selectionBorder.node.style.display;
  60814. var delta = this.getTranslateForEvent(me);
  60815. var dx = delta.x;
  60816. var dy = delta.y;
  60817. var bounds = null;
  60818. if (!this.zoom)
  60819. {
  60820. // Previews the panning on the source graph
  60821. var scale = this.outline.getView().scale;
  60822. bounds = new mxRectangle(this.bounds.x + dx,
  60823. this.bounds.y + dy, this.bounds.width, this.bounds.height);
  60824. this.selectionBorder.bounds = bounds;
  60825. this.selectionBorder.redraw();
  60826. dx /= scale;
  60827. dx *= this.source.getView().scale;
  60828. dy /= scale;
  60829. dy *= this.source.getView().scale;
  60830. this.source.panGraph(-dx - this.dx0, -dy - this.dy0);
  60831. }
  60832. else
  60833. {
  60834. // Does *not* preview zooming on the source graph
  60835. var container = this.source.container;
  60836. var viewRatio = container.clientWidth / container.clientHeight;
  60837. dy = dx / viewRatio;
  60838. bounds = new mxRectangle(this.bounds.x,
  60839. this.bounds.y,
  60840. Math.max(1, this.bounds.width + dx),
  60841. Math.max(1, this.bounds.height + dy));
  60842. this.selectionBorder.bounds = bounds;
  60843. this.selectionBorder.redraw();
  60844. }
  60845. // Updates the zoom handle
  60846. var b = this.sizer.bounds;
  60847. this.sizer.bounds = new mxRectangle(
  60848. bounds.x + bounds.width - b.width / 2,
  60849. bounds.y + bounds.height - b.height / 2,
  60850. b.width, b.height);
  60851. // Avoids update of visibility in redraw for VML
  60852. if (this.sizer.node.style.visibility != 'hidden')
  60853. {
  60854. this.sizer.redraw();
  60855. }
  60856. me.consume();
  60857. }
  60858. };
  60859. /**
  60860. * Function: getTranslateForEvent
  60861. *
  60862. * Gets the translate for the given mouse event. Here is an example to limit
  60863. * the outline to stay within positive coordinates:
  60864. *
  60865. * (code)
  60866. * outline.getTranslateForEvent = function(me)
  60867. * {
  60868. * var pt = new mxPoint(me.getX() - this.startX, me.getY() - this.startY);
  60869. *
  60870. * if (!this.zoom)
  60871. * {
  60872. * var tr = this.source.view.translate;
  60873. * pt.x = Math.max(tr.x * this.outline.view.scale, pt.x);
  60874. * pt.y = Math.max(tr.y * this.outline.view.scale, pt.y);
  60875. * }
  60876. *
  60877. * return pt;
  60878. * };
  60879. * (end)
  60880. */
  60881. mxOutline.prototype.getTranslateForEvent = function(me)
  60882. {
  60883. return new mxPoint(me.getX() - this.startX, me.getY() - this.startY);
  60884. };
  60885. /**
  60886. * Function: mouseUp
  60887. *
  60888. * Handles the event by applying the translation or zoom to <graph>.
  60889. */
  60890. mxOutline.prototype.mouseUp = function(sender, me)
  60891. {
  60892. if (this.active)
  60893. {
  60894. var delta = this.getTranslateForEvent(me);
  60895. var dx = delta.x;
  60896. var dy = delta.y;
  60897. if (Math.abs(dx) > 0 || Math.abs(dy) > 0)
  60898. {
  60899. if (!this.zoom)
  60900. {
  60901. // Applies the new translation if the source
  60902. // has no scrollbars
  60903. if (!this.source.useScrollbarsForPanning ||
  60904. !mxUtils.hasScrollbars(this.source.container))
  60905. {
  60906. this.source.panGraph(0, 0);
  60907. dx /= this.outline.getView().scale;
  60908. dy /= this.outline.getView().scale;
  60909. var t = this.source.getView().translate;
  60910. this.source.getView().setTranslate(t.x - dx, t.y - dy);
  60911. }
  60912. }
  60913. else
  60914. {
  60915. // Applies the new zoom
  60916. var w = this.selectionBorder.bounds.width;
  60917. var scale = this.source.getView().scale;
  60918. this.source.zoomTo(Math.max(this.minScale, scale - (dx * scale) / w), false);
  60919. }
  60920. this.update();
  60921. me.consume();
  60922. }
  60923. // Resets the state of the handler
  60924. this.index = null;
  60925. this.active = false;
  60926. }
  60927. };
  60928. /**
  60929. * Function: destroy
  60930. *
  60931. * Destroy this outline and removes all listeners from <source>.
  60932. */
  60933. mxOutline.prototype.destroy = function()
  60934. {
  60935. if (this.source != null)
  60936. {
  60937. this.source.removeListener(this.panHandler);
  60938. this.source.removeListener(this.refreshHandler);
  60939. this.source.getModel().removeListener(this.updateHandler);
  60940. this.source.getView().removeListener(this.updateHandler);
  60941. mxEvent.removeListener(this.source.container, 'scroll', this.updateHandler);
  60942. this.source = null;
  60943. }
  60944. if (this.outline != null)
  60945. {
  60946. this.outline.removeMouseListener(this);
  60947. this.outline.destroy();
  60948. this.outline = null;
  60949. }
  60950. if (this.selectionBorder != null)
  60951. {
  60952. this.selectionBorder.destroy();
  60953. this.selectionBorder = null;
  60954. }
  60955. if (this.sizer != null)
  60956. {
  60957. this.sizer.destroy();
  60958. this.sizer = null;
  60959. }
  60960. };
  60961. /**
  60962. * Copyright (c) 2006-2015, JGraph Ltd
  60963. * Copyright (c) 2006-2015, Gaudenz Alder
  60964. */
  60965. /**
  60966. * Class: mxMultiplicity
  60967. *
  60968. * Defines invalid connections along with the error messages that they produce.
  60969. * To add or remove rules on a graph, you must add/remove instances of this
  60970. * class to <mxGraph.multiplicities>.
  60971. *
  60972. * Example:
  60973. *
  60974. * (code)
  60975. * graph.multiplicities.push(new mxMultiplicity(
  60976. * true, 'rectangle', null, null, 0, 2, ['circle'],
  60977. * 'Only 2 targets allowed',
  60978. * 'Only circle targets allowed'));
  60979. * (end)
  60980. *
  60981. * Defines a rule where each rectangle must be connected to no more than 2
  60982. * circles and no other types of targets are allowed.
  60983. *
  60984. * Constructor: mxMultiplicity
  60985. *
  60986. * Instantiate class mxMultiplicity in order to describe allowed
  60987. * connections in a graph. Not all constraints can be enforced while
  60988. * editing, some must be checked at validation time. The <countError> and
  60989. * <typeError> are treated as resource keys in <mxResources>.
  60990. *
  60991. * Parameters:
  60992. *
  60993. * source - Boolean indicating if this rule applies to the source or target
  60994. * terminal.
  60995. * type - Type of the source or target terminal that this rule applies to.
  60996. * See <type> for more information.
  60997. * attr - Optional attribute name to match the source or target terminal.
  60998. * value - Optional attribute value to match the source or target terminal.
  60999. * min - Minimum number of edges for this rule. Default is 1.
  61000. * max - Maximum number of edges for this rule. n means infinite. Default
  61001. * is n.
  61002. * validNeighbors - Array of types of the opposite terminal for which this
  61003. * rule applies.
  61004. * countError - Error to be displayed for invalid number of edges.
  61005. * typeError - Error to be displayed for invalid opposite terminals.
  61006. * validNeighborsAllowed - Optional boolean indicating if the array of
  61007. * opposite types should be valid or invalid.
  61008. */
  61009. function mxMultiplicity(source, type, attr, value, min, max,
  61010. validNeighbors, countError, typeError, validNeighborsAllowed)
  61011. {
  61012. this.source = source;
  61013. this.type = type;
  61014. this.attr = attr;
  61015. this.value = value;
  61016. this.min = (min != null) ? min : 0;
  61017. this.max = (max != null) ? max : 'n';
  61018. this.validNeighbors = validNeighbors;
  61019. this.countError = mxResources.get(countError) || countError;
  61020. this.typeError = mxResources.get(typeError) || typeError;
  61021. this.validNeighborsAllowed = (validNeighborsAllowed != null) ?
  61022. validNeighborsAllowed : true;
  61023. };
  61024. /**
  61025. * Variable: type
  61026. *
  61027. * Defines the type of the source or target terminal. The type is a string
  61028. * passed to <mxUtils.isNode> together with the source or target vertex
  61029. * value as the first argument.
  61030. */
  61031. mxMultiplicity.prototype.type = null;
  61032. /**
  61033. * Variable: attr
  61034. *
  61035. * Optional string that specifies the attributename to be passed to
  61036. * <mxUtils.isNode> to check if the rule applies to a cell.
  61037. */
  61038. mxMultiplicity.prototype.attr = null;
  61039. /**
  61040. * Variable: value
  61041. *
  61042. * Optional string that specifies the value of the attribute to be passed
  61043. * to <mxUtils.isNode> to check if the rule applies to a cell.
  61044. */
  61045. mxMultiplicity.prototype.value = null;
  61046. /**
  61047. * Variable: source
  61048. *
  61049. * Boolean that specifies if the rule is applied to the source or target
  61050. * terminal of an edge.
  61051. */
  61052. mxMultiplicity.prototype.source = null;
  61053. /**
  61054. * Variable: min
  61055. *
  61056. * Defines the minimum number of connections for which this rule applies.
  61057. * Default is 0.
  61058. */
  61059. mxMultiplicity.prototype.min = null;
  61060. /**
  61061. * Variable: max
  61062. *
  61063. * Defines the maximum number of connections for which this rule applies.
  61064. * A value of 'n' means unlimited times. Default is 'n'.
  61065. */
  61066. mxMultiplicity.prototype.max = null;
  61067. /**
  61068. * Variable: validNeighbors
  61069. *
  61070. * Holds an array of strings that specify the type of neighbor for which
  61071. * this rule applies. The strings are used in <mxCell.is> on the opposite
  61072. * terminal to check if the rule applies to the connection.
  61073. */
  61074. mxMultiplicity.prototype.validNeighbors = null;
  61075. /**
  61076. * Variable: validNeighborsAllowed
  61077. *
  61078. * Boolean indicating if the list of validNeighbors are those that are allowed
  61079. * for this rule or those that are not allowed for this rule.
  61080. */
  61081. mxMultiplicity.prototype.validNeighborsAllowed = true;
  61082. /**
  61083. * Variable: countError
  61084. *
  61085. * Holds the localized error message to be displayed if the number of
  61086. * connections for which the rule applies is smaller than <min> or greater
  61087. * than <max>.
  61088. */
  61089. mxMultiplicity.prototype.countError = null;
  61090. /**
  61091. * Variable: typeError
  61092. *
  61093. * Holds the localized error message to be displayed if the type of the
  61094. * neighbor for a connection does not match the rule.
  61095. */
  61096. mxMultiplicity.prototype.typeError = null;
  61097. /**
  61098. * Function: check
  61099. *
  61100. * Checks the multiplicity for the given arguments and returns the error
  61101. * for the given connection or null if the multiplicity does not apply.
  61102. *
  61103. * Parameters:
  61104. *
  61105. * graph - Reference to the enclosing <mxGraph> instance.
  61106. * edge - <mxCell> that represents the edge to validate.
  61107. * source - <mxCell> that represents the source terminal.
  61108. * target - <mxCell> that represents the target terminal.
  61109. * sourceOut - Number of outgoing edges from the source terminal.
  61110. * targetIn - Number of incoming edges for the target terminal.
  61111. */
  61112. mxMultiplicity.prototype.check = function(graph, edge, source, target, sourceOut, targetIn)
  61113. {
  61114. var error = '';
  61115. if ((this.source && this.checkTerminal(graph, source, edge)) ||
  61116. (!this.source && this.checkTerminal(graph, target, edge)))
  61117. {
  61118. if (this.countError != null &&
  61119. ((this.source && (this.max == 0 || (sourceOut >= this.max))) ||
  61120. (!this.source && (this.max == 0 || (targetIn >= this.max)))))
  61121. {
  61122. error += this.countError + '\n';
  61123. }
  61124. if (this.validNeighbors != null && this.typeError != null && this.validNeighbors.length > 0)
  61125. {
  61126. var isValid = this.checkNeighbors(graph, edge, source, target);
  61127. if (!isValid)
  61128. {
  61129. error += this.typeError + '\n';
  61130. }
  61131. }
  61132. }
  61133. return (error.length > 0) ? error : null;
  61134. };
  61135. /**
  61136. * Function: checkNeighbors
  61137. *
  61138. * Checks if there are any valid neighbours in <validNeighbors>. This is only
  61139. * called if <validNeighbors> is a non-empty array.
  61140. */
  61141. mxMultiplicity.prototype.checkNeighbors = function(graph, edge, source, target)
  61142. {
  61143. var sourceValue = graph.model.getValue(source);
  61144. var targetValue = graph.model.getValue(target);
  61145. var isValid = !this.validNeighborsAllowed;
  61146. var valid = this.validNeighbors;
  61147. for (var j = 0; j < valid.length; j++)
  61148. {
  61149. if (this.source &&
  61150. this.checkType(graph, targetValue, valid[j]))
  61151. {
  61152. isValid = this.validNeighborsAllowed;
  61153. break;
  61154. }
  61155. else if (!this.source &&
  61156. this.checkType(graph, sourceValue, valid[j]))
  61157. {
  61158. isValid = this.validNeighborsAllowed;
  61159. break;
  61160. }
  61161. }
  61162. return isValid;
  61163. };
  61164. /**
  61165. * Function: checkTerminal
  61166. *
  61167. * Checks the given terminal cell and returns true if this rule applies. The
  61168. * given cell is the source or target of the given edge, depending on
  61169. * <source>. This implementation uses <checkType> on the terminal's value.
  61170. */
  61171. mxMultiplicity.prototype.checkTerminal = function(graph, terminal, edge)
  61172. {
  61173. var value = graph.model.getValue(terminal);
  61174. return this.checkType(graph, value, this.type, this.attr, this.value);
  61175. };
  61176. /**
  61177. * Function: checkType
  61178. *
  61179. * Checks the type of the given value.
  61180. */
  61181. mxMultiplicity.prototype.checkType = function(graph, value, type, attr, attrValue)
  61182. {
  61183. if (value != null)
  61184. {
  61185. if (!isNaN(value.nodeType)) // Checks if value is a DOM node
  61186. {
  61187. return mxUtils.isNode(value, type, attr, attrValue);
  61188. }
  61189. else
  61190. {
  61191. return value == type;
  61192. }
  61193. }
  61194. return false;
  61195. };
  61196. /**
  61197. * Copyright (c) 2006-2015, JGraph Ltd
  61198. * Copyright (c) 2006-2015, Gaudenz Alder
  61199. */
  61200. /**
  61201. * Class: mxLayoutManager
  61202. *
  61203. * Implements a layout manager that runs a given layout after any changes to the graph:
  61204. *
  61205. * Example:
  61206. *
  61207. * (code)
  61208. * var layoutMgr = new mxLayoutManager(graph);
  61209. * layoutMgr.getLayout = function(cell, eventName)
  61210. * {
  61211. * return layout;
  61212. * };
  61213. * (end)
  61214. *
  61215. * See <getLayout> for a description of the possible eventNames.
  61216. *
  61217. * Event: mxEvent.LAYOUT_CELLS
  61218. *
  61219. * Fires between begin- and endUpdate after all cells have been layouted in
  61220. * <layoutCells>. The <code>cells</code> property contains all cells that have
  61221. * been passed to <layoutCells>.
  61222. *
  61223. * Constructor: mxLayoutManager
  61224. *
  61225. * Constructs a new automatic layout for the given graph.
  61226. *
  61227. * Arguments:
  61228. *
  61229. * graph - Reference to the enclosing graph.
  61230. */
  61231. function mxLayoutManager(graph)
  61232. {
  61233. // Executes the layout before the changes are dispatched
  61234. this.undoHandler = mxUtils.bind(this, function(sender, evt)
  61235. {
  61236. if (this.isEnabled())
  61237. {
  61238. this.beforeUndo(evt.getProperty('edit'));
  61239. }
  61240. });
  61241. // Notifies the layout of a move operation inside a parent
  61242. this.moveHandler = mxUtils.bind(this, function(sender, evt)
  61243. {
  61244. if (this.isEnabled())
  61245. {
  61246. this.cellsMoved(evt.getProperty('cells'), evt.getProperty('event'));
  61247. }
  61248. });
  61249. // Notifies the layout of a move operation inside a parent
  61250. this.resizeHandler = mxUtils.bind(this, function(sender, evt)
  61251. {
  61252. if (this.isEnabled())
  61253. {
  61254. this.cellsResized(evt.getProperty('cells'), evt.getProperty('bounds'),
  61255. evt.getProperty('previous'));
  61256. }
  61257. });
  61258. this.setGraph(graph);
  61259. };
  61260. /**
  61261. * Extends mxEventSource.
  61262. */
  61263. mxLayoutManager.prototype = new mxEventSource();
  61264. mxLayoutManager.prototype.constructor = mxLayoutManager;
  61265. /**
  61266. * Variable: graph
  61267. *
  61268. * Reference to the enclosing <mxGraph>.
  61269. */
  61270. mxLayoutManager.prototype.graph = null;
  61271. /**
  61272. * Variable: bubbling
  61273. *
  61274. * Specifies if the layout should bubble along
  61275. * the cell hierarchy. Default is true.
  61276. */
  61277. mxLayoutManager.prototype.bubbling = true;
  61278. /**
  61279. * Variable: enabled
  61280. *
  61281. * Specifies if event handling is enabled. Default is true.
  61282. */
  61283. mxLayoutManager.prototype.enabled = true;
  61284. /**
  61285. * Variable: undoHandler
  61286. *
  61287. * Holds the function that handles the endUpdate event.
  61288. */
  61289. mxLayoutManager.prototype.undoHandler = null;
  61290. /**
  61291. * Variable: moveHandler
  61292. *
  61293. * Holds the function that handles the move event.
  61294. */
  61295. mxLayoutManager.prototype.moveHandler = null;
  61296. /**
  61297. * Variable: resizeHandler
  61298. *
  61299. * Holds the function that handles the resize event.
  61300. */
  61301. mxLayoutManager.prototype.resizeHandler = null;
  61302. /**
  61303. * Function: isEnabled
  61304. *
  61305. * Returns true if events are handled. This implementation
  61306. * returns <enabled>.
  61307. */
  61308. mxLayoutManager.prototype.isEnabled = function()
  61309. {
  61310. return this.enabled;
  61311. };
  61312. /**
  61313. * Function: setEnabled
  61314. *
  61315. * Enables or disables event handling. This implementation
  61316. * updates <enabled>.
  61317. *
  61318. * Parameters:
  61319. *
  61320. * enabled - Boolean that specifies the new enabled state.
  61321. */
  61322. mxLayoutManager.prototype.setEnabled = function(enabled)
  61323. {
  61324. this.enabled = enabled;
  61325. };
  61326. /**
  61327. * Function: isBubbling
  61328. *
  61329. * Returns true if a layout should bubble, that is, if the parent layout
  61330. * should be executed whenever a cell layout (layout of the children of
  61331. * a cell) has been executed. This implementation returns <bubbling>.
  61332. */
  61333. mxLayoutManager.prototype.isBubbling = function()
  61334. {
  61335. return this.bubbling;
  61336. };
  61337. /**
  61338. * Function: setBubbling
  61339. *
  61340. * Sets <bubbling>.
  61341. */
  61342. mxLayoutManager.prototype.setBubbling = function(value)
  61343. {
  61344. this.bubbling = value;
  61345. };
  61346. /**
  61347. * Function: getGraph
  61348. *
  61349. * Returns the graph that this layout operates on.
  61350. */
  61351. mxLayoutManager.prototype.getGraph = function()
  61352. {
  61353. return this.graph;
  61354. };
  61355. /**
  61356. * Function: setGraph
  61357. *
  61358. * Sets the graph that the layouts operate on.
  61359. */
  61360. mxLayoutManager.prototype.setGraph = function(graph)
  61361. {
  61362. if (this.graph != null)
  61363. {
  61364. var model = this.graph.getModel();
  61365. model.removeListener(this.undoHandler);
  61366. this.graph.removeListener(this.moveHandler);
  61367. this.graph.removeListener(this.resizeHandler);
  61368. }
  61369. this.graph = graph;
  61370. if (this.graph != null)
  61371. {
  61372. var model = this.graph.getModel();
  61373. model.addListener(mxEvent.BEFORE_UNDO, this.undoHandler);
  61374. this.graph.addListener(mxEvent.MOVE_CELLS, this.moveHandler);
  61375. this.graph.addListener(mxEvent.RESIZE_CELLS, this.resizeHandler);
  61376. }
  61377. };
  61378. /**
  61379. * Function: hasLayout
  61380. *
  61381. * Returns true if the given cell has a layout. This implementation invokes
  61382. * <getLayout> with <mxEvent.LAYOUT_CELLS> as the eventName. Override this
  61383. * if creating layouts in <getLayout> is expensive and return true if
  61384. * <getLayout> will return a layout for the given cell for
  61385. * <mxEvent.BEGIN_UPDATE> or <mxEvent.END_UPDATE>.
  61386. */
  61387. mxLayoutManager.prototype.hasLayout = function(cell)
  61388. {
  61389. return this.getLayout(cell, mxEvent.LAYOUT_CELLS);
  61390. };
  61391. /**
  61392. * Function: getLayout
  61393. *
  61394. * Returns the layout for the given cell and eventName. Possible
  61395. * event names are <mxEvent.MOVE_CELLS> and <mxEvent.RESIZE_CELLS>
  61396. * when cells are moved or resized and <mxEvent.BEGIN_UPDATE> or
  61397. * <mxEvent.END_UPDATE> for the bottom up and top down phases after
  61398. * changes to the graph model. <mxEvent.LAYOUT_CELLS> is used to
  61399. * check if a layout exists for the given cell. This is called
  61400. * from <hasLayout>.
  61401. */
  61402. mxLayoutManager.prototype.getLayout = function(cell, eventName)
  61403. {
  61404. return null;
  61405. };
  61406. /**
  61407. * Function: beforeUndo
  61408. *
  61409. * Called from <undoHandler>.
  61410. *
  61411. * Parameters:
  61412. *
  61413. * cell - Array of <mxCells> that have been moved.
  61414. * evt - Mouse event that represents the mousedown.
  61415. */
  61416. mxLayoutManager.prototype.beforeUndo = function(undoableEdit)
  61417. {
  61418. this.executeLayoutForCells(this.getCellsForChanges(undoableEdit.changes));
  61419. };
  61420. /**
  61421. * Function: cellsMoved
  61422. *
  61423. * Called from <moveHandler>.
  61424. *
  61425. * Parameters:
  61426. *
  61427. * cell - Array of <mxCells> that have been moved.
  61428. * evt - Mouse event that represents the mousedown.
  61429. */
  61430. mxLayoutManager.prototype.cellsMoved = function(cells, evt)
  61431. {
  61432. if (cells != null && evt != null)
  61433. {
  61434. var point = mxUtils.convertPoint(this.getGraph().container,
  61435. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  61436. // Checks if a layout exists to take care of the moving if the
  61437. // parent itself is not being moved
  61438. for (var i = 0; i < cells.length; i++)
  61439. {
  61440. var layout = this.getAncestorLayout(cells[i], mxEvent.MOVE_CELLS);
  61441. if (layout != null)
  61442. {
  61443. layout.moveCell(cells[i], point.x, point.y);
  61444. }
  61445. }
  61446. }
  61447. };
  61448. /**
  61449. * Function: cellsResized
  61450. *
  61451. * Called from <resizeHandler>.
  61452. *
  61453. * Parameters:
  61454. *
  61455. * cell - Array of <mxCells> that have been resized.
  61456. * bounds - <mxRectangle> taht represents the new bounds.
  61457. */
  61458. mxLayoutManager.prototype.cellsResized = function(cells, bounds, prev)
  61459. {
  61460. if (cells != null && bounds != null)
  61461. {
  61462. // Checks if a layout exists to take care of the resize if the
  61463. // parent itself is not being resized
  61464. for (var i = 0; i < cells.length; i++)
  61465. {
  61466. var layout = this.getAncestorLayout(cells[i], mxEvent.RESIZE_CELLS);
  61467. if (layout != null)
  61468. {
  61469. layout.resizeCell(cells[i], bounds[i], prev[i]);
  61470. }
  61471. }
  61472. }
  61473. };
  61474. /**
  61475. * Function: getAncestorLayout
  61476. *
  61477. * Returns the cells to be layouted for the given sequence of changes.
  61478. */
  61479. mxLayoutManager.prototype.getAncestorLayout = function(cell, eventName)
  61480. {
  61481. var model = this.getGraph().getModel();
  61482. while (cell != null)
  61483. {
  61484. var layout = this.getLayout(cell, eventName);
  61485. if (layout != null)
  61486. {
  61487. return layout;
  61488. }
  61489. cell = model.getParent(cell);
  61490. }
  61491. return null;
  61492. };
  61493. /**
  61494. * Function: getCellsForChanges
  61495. *
  61496. * Returns the cells for which a layout should be executed.
  61497. */
  61498. mxLayoutManager.prototype.getCellsForChanges = function(changes)
  61499. {
  61500. var result = [];
  61501. for (var i = 0; i < changes.length; i++)
  61502. {
  61503. var change = changes[i];
  61504. if (change instanceof mxRootChange)
  61505. {
  61506. return [];
  61507. }
  61508. else
  61509. {
  61510. result = result.concat(this.getCellsForChange(change));
  61511. }
  61512. }
  61513. return result;
  61514. };
  61515. /**
  61516. * Function: getCellsForChange
  61517. *
  61518. * Executes all layouts which have been scheduled during the
  61519. * changes.
  61520. */
  61521. mxLayoutManager.prototype.getCellsForChange = function(change)
  61522. {
  61523. if (change instanceof mxChildChange)
  61524. {
  61525. return this.addCellsWithLayout(change.child,
  61526. this.addCellsWithLayout(change.previous));
  61527. }
  61528. else if (change instanceof mxTerminalChange ||
  61529. change instanceof mxGeometryChange)
  61530. {
  61531. return this.addCellsWithLayout(change.cell);
  61532. }
  61533. else if (change instanceof mxVisibleChange ||
  61534. change instanceof mxStyleChange)
  61535. {
  61536. return this.addCellsWithLayout(change.cell);
  61537. }
  61538. return [];
  61539. };
  61540. /**
  61541. * Function: addCellsWithLayout
  61542. *
  61543. * Adds all ancestors of the given cell that have a layout.
  61544. */
  61545. mxLayoutManager.prototype.addCellsWithLayout = function(cell, result)
  61546. {
  61547. return this.addDescendantsWithLayout(cell,
  61548. this.addAncestorsWithLayout(cell, result));
  61549. };
  61550. /**
  61551. * Function: addAncestorsWithLayout
  61552. *
  61553. * Adds all ancestors of the given cell that have a layout.
  61554. */
  61555. mxLayoutManager.prototype.addAncestorsWithLayout = function(cell, result)
  61556. {
  61557. result = (result != null) ? result : [];
  61558. if (cell != null)
  61559. {
  61560. var layout = this.hasLayout(cell);
  61561. if (layout != null)
  61562. {
  61563. result.push(cell);
  61564. }
  61565. if (this.isBubbling())
  61566. {
  61567. var model = this.getGraph().getModel();
  61568. this.addAncestorsWithLayout(
  61569. model.getParent(cell), result);
  61570. }
  61571. }
  61572. return result;
  61573. };
  61574. /**
  61575. * Function: addDescendantsWithLayout
  61576. *
  61577. * Adds all descendants of the given cell that have a layout.
  61578. */
  61579. mxLayoutManager.prototype.addDescendantsWithLayout = function(cell, result)
  61580. {
  61581. result = (result != null) ? result : [];
  61582. if (cell != null && this.hasLayout(cell))
  61583. {
  61584. var model = this.getGraph().getModel();
  61585. for (var i = 0; i < model.getChildCount(cell); i++)
  61586. {
  61587. var child = model.getChildAt(cell, i);
  61588. if (this.hasLayout(child))
  61589. {
  61590. result.push(child);
  61591. this.addDescendantsWithLayout(child, result);
  61592. }
  61593. }
  61594. }
  61595. return result;
  61596. };
  61597. /**
  61598. * Function: executeLayoutForCells
  61599. *
  61600. * Executes all layouts for the given cells in two phases: In the first phase
  61601. * layouts for child cells are executed before layouts for parent cells with
  61602. * <mxEvent.BEGIN_UPDATE>, in the second phase layouts for parent cells are
  61603. * executed before layouts for child cells with <mxEvent.END_UPDATE>.
  61604. */
  61605. mxLayoutManager.prototype.executeLayoutForCells = function(cells)
  61606. {
  61607. var sorted = mxUtils.sortCells(cells, false);
  61608. this.layoutCells(sorted, true);
  61609. this.layoutCells(sorted.reverse(), false);
  61610. };
  61611. /**
  61612. * Function: layoutCells
  61613. *
  61614. * Executes all layouts which have been scheduled during the changes.
  61615. */
  61616. mxLayoutManager.prototype.layoutCells = function(cells, bubble)
  61617. {
  61618. if (cells.length > 0)
  61619. {
  61620. // Invokes the layouts while removing duplicates
  61621. var model = this.getGraph().getModel();
  61622. model.beginUpdate();
  61623. try
  61624. {
  61625. var last = null;
  61626. for (var i = 0; i < cells.length; i++)
  61627. {
  61628. if (cells[i] != model.getRoot() && cells[i] != last)
  61629. {
  61630. this.executeLayout(cells[i], bubble);
  61631. last = cells[i];
  61632. }
  61633. }
  61634. this.fireEvent(new mxEventObject(mxEvent.LAYOUT_CELLS, 'cells', cells));
  61635. }
  61636. finally
  61637. {
  61638. model.endUpdate();
  61639. }
  61640. }
  61641. };
  61642. /**
  61643. * Function: executeLayout
  61644. *
  61645. * Executes the given layout on the given parent.
  61646. */
  61647. mxLayoutManager.prototype.executeLayout = function(cell, bubble)
  61648. {
  61649. var layout = this.getLayout(cell, (bubble) ?
  61650. mxEvent.BEGIN_UPDATE : mxEvent.END_UPDATE);
  61651. if (layout != null)
  61652. {
  61653. layout.execute(cell);
  61654. }
  61655. };
  61656. /**
  61657. * Function: destroy
  61658. *
  61659. * Removes all handlers from the <graph> and deletes the reference to it.
  61660. */
  61661. mxLayoutManager.prototype.destroy = function()
  61662. {
  61663. this.setGraph(null);
  61664. };
  61665. /**
  61666. * Copyright (c) 2006-2015, JGraph Ltd
  61667. * Copyright (c) 2006-2015, Gaudenz Alder
  61668. */
  61669. /**
  61670. * Class: mxSwimlaneManager
  61671. *
  61672. * Manager for swimlanes and nested swimlanes that sets the size of newly added
  61673. * swimlanes to that of their siblings, and propagates changes to the size of a
  61674. * swimlane to its siblings, if <siblings> is true, and its ancestors, if
  61675. * <bubbling> is true.
  61676. *
  61677. * Constructor: mxSwimlaneManager
  61678. *
  61679. * Constructs a new swimlane manager for the given graph.
  61680. *
  61681. * Arguments:
  61682. *
  61683. * graph - Reference to the enclosing graph.
  61684. */
  61685. function mxSwimlaneManager(graph, horizontal, addEnabled, resizeEnabled)
  61686. {
  61687. this.horizontal = (horizontal != null) ? horizontal : true;
  61688. this.addEnabled = (addEnabled != null) ? addEnabled : true;
  61689. this.resizeEnabled = (resizeEnabled != null) ? resizeEnabled : true;
  61690. this.addHandler = mxUtils.bind(this, function(sender, evt)
  61691. {
  61692. if (this.isEnabled() && this.isAddEnabled())
  61693. {
  61694. this.cellsAdded(evt.getProperty('cells'));
  61695. }
  61696. });
  61697. this.resizeHandler = mxUtils.bind(this, function(sender, evt)
  61698. {
  61699. if (this.isEnabled() && this.isResizeEnabled())
  61700. {
  61701. this.cellsResized(evt.getProperty('cells'));
  61702. }
  61703. });
  61704. this.setGraph(graph);
  61705. };
  61706. /**
  61707. * Extends mxEventSource.
  61708. */
  61709. mxSwimlaneManager.prototype = new mxEventSource();
  61710. mxSwimlaneManager.prototype.constructor = mxSwimlaneManager;
  61711. /**
  61712. * Variable: graph
  61713. *
  61714. * Reference to the enclosing <mxGraph>.
  61715. */
  61716. mxSwimlaneManager.prototype.graph = null;
  61717. /**
  61718. * Variable: enabled
  61719. *
  61720. * Specifies if event handling is enabled. Default is true.
  61721. */
  61722. mxSwimlaneManager.prototype.enabled = true;
  61723. /**
  61724. * Variable: horizontal
  61725. *
  61726. * Specifies the orientation of the swimlanes. Default is true.
  61727. */
  61728. mxSwimlaneManager.prototype.horizontal = true;
  61729. /**
  61730. * Variable: addEnabled
  61731. *
  61732. * Specifies if newly added cells should be resized to match the size of their
  61733. * existing siblings. Default is true.
  61734. */
  61735. mxSwimlaneManager.prototype.addEnabled = true;
  61736. /**
  61737. * Variable: resizeEnabled
  61738. *
  61739. * Specifies if resizing of swimlanes should be handled. Default is true.
  61740. */
  61741. mxSwimlaneManager.prototype.resizeEnabled = true;
  61742. /**
  61743. * Variable: moveHandler
  61744. *
  61745. * Holds the function that handles the move event.
  61746. */
  61747. mxSwimlaneManager.prototype.addHandler = null;
  61748. /**
  61749. * Variable: moveHandler
  61750. *
  61751. * Holds the function that handles the move event.
  61752. */
  61753. mxSwimlaneManager.prototype.resizeHandler = null;
  61754. /**
  61755. * Function: isEnabled
  61756. *
  61757. * Returns true if events are handled. This implementation
  61758. * returns <enabled>.
  61759. */
  61760. mxSwimlaneManager.prototype.isEnabled = function()
  61761. {
  61762. return this.enabled;
  61763. };
  61764. /**
  61765. * Function: setEnabled
  61766. *
  61767. * Enables or disables event handling. This implementation
  61768. * updates <enabled>.
  61769. *
  61770. * Parameters:
  61771. *
  61772. * enabled - Boolean that specifies the new enabled state.
  61773. */
  61774. mxSwimlaneManager.prototype.setEnabled = function(value)
  61775. {
  61776. this.enabled = value;
  61777. };
  61778. /**
  61779. * Function: isHorizontal
  61780. *
  61781. * Returns <horizontal>.
  61782. */
  61783. mxSwimlaneManager.prototype.isHorizontal = function()
  61784. {
  61785. return this.horizontal;
  61786. };
  61787. /**
  61788. * Function: setHorizontal
  61789. *
  61790. * Sets <horizontal>.
  61791. */
  61792. mxSwimlaneManager.prototype.setHorizontal = function(value)
  61793. {
  61794. this.horizontal = value;
  61795. };
  61796. /**
  61797. * Function: isAddEnabled
  61798. *
  61799. * Returns <addEnabled>.
  61800. */
  61801. mxSwimlaneManager.prototype.isAddEnabled = function()
  61802. {
  61803. return this.addEnabled;
  61804. };
  61805. /**
  61806. * Function: setAddEnabled
  61807. *
  61808. * Sets <addEnabled>.
  61809. */
  61810. mxSwimlaneManager.prototype.setAddEnabled = function(value)
  61811. {
  61812. this.addEnabled = value;
  61813. };
  61814. /**
  61815. * Function: isResizeEnabled
  61816. *
  61817. * Returns <resizeEnabled>.
  61818. */
  61819. mxSwimlaneManager.prototype.isResizeEnabled = function()
  61820. {
  61821. return this.resizeEnabled;
  61822. };
  61823. /**
  61824. * Function: setResizeEnabled
  61825. *
  61826. * Sets <resizeEnabled>.
  61827. */
  61828. mxSwimlaneManager.prototype.setResizeEnabled = function(value)
  61829. {
  61830. this.resizeEnabled = value;
  61831. };
  61832. /**
  61833. * Function: getGraph
  61834. *
  61835. * Returns the graph that this manager operates on.
  61836. */
  61837. mxSwimlaneManager.prototype.getGraph = function()
  61838. {
  61839. return this.graph;
  61840. };
  61841. /**
  61842. * Function: setGraph
  61843. *
  61844. * Sets the graph that the manager operates on.
  61845. */
  61846. mxSwimlaneManager.prototype.setGraph = function(graph)
  61847. {
  61848. if (this.graph != null)
  61849. {
  61850. this.graph.removeListener(this.addHandler);
  61851. this.graph.removeListener(this.resizeHandler);
  61852. }
  61853. this.graph = graph;
  61854. if (this.graph != null)
  61855. {
  61856. this.graph.addListener(mxEvent.ADD_CELLS, this.addHandler);
  61857. this.graph.addListener(mxEvent.CELLS_RESIZED, this.resizeHandler);
  61858. }
  61859. };
  61860. /**
  61861. * Function: isSwimlaneIgnored
  61862. *
  61863. * Returns true if the given swimlane should be ignored.
  61864. */
  61865. mxSwimlaneManager.prototype.isSwimlaneIgnored = function(swimlane)
  61866. {
  61867. return !this.getGraph().isSwimlane(swimlane);
  61868. };
  61869. /**
  61870. * Function: isCellHorizontal
  61871. *
  61872. * Returns true if the given cell is horizontal. If the given cell is not a
  61873. * swimlane, then the global orientation is returned.
  61874. */
  61875. mxSwimlaneManager.prototype.isCellHorizontal = function(cell)
  61876. {
  61877. if (this.graph.isSwimlane(cell))
  61878. {
  61879. var style = this.graph.getCellStyle(cell);
  61880. return mxUtils.getValue(style, mxConstants.STYLE_HORIZONTAL, 1) == 1;
  61881. }
  61882. return !this.isHorizontal();
  61883. };
  61884. /**
  61885. * Function: cellsAdded
  61886. *
  61887. * Called if any cells have been added.
  61888. *
  61889. * Parameters:
  61890. *
  61891. * cell - Array of <mxCells> that have been added.
  61892. */
  61893. mxSwimlaneManager.prototype.cellsAdded = function(cells)
  61894. {
  61895. if (cells != null)
  61896. {
  61897. var model = this.getGraph().getModel();
  61898. model.beginUpdate();
  61899. try
  61900. {
  61901. for (var i = 0; i < cells.length; i++)
  61902. {
  61903. if (!this.isSwimlaneIgnored(cells[i]))
  61904. {
  61905. this.swimlaneAdded(cells[i]);
  61906. }
  61907. }
  61908. }
  61909. finally
  61910. {
  61911. model.endUpdate();
  61912. }
  61913. }
  61914. };
  61915. /**
  61916. * Function: swimlaneAdded
  61917. *
  61918. * Updates the size of the given swimlane to match that of any existing
  61919. * siblings swimlanes.
  61920. *
  61921. * Parameters:
  61922. *
  61923. * swimlane - <mxCell> that represents the new swimlane.
  61924. */
  61925. mxSwimlaneManager.prototype.swimlaneAdded = function(swimlane)
  61926. {
  61927. var model = this.getGraph().getModel();
  61928. var parent = model.getParent(swimlane);
  61929. var childCount = model.getChildCount(parent);
  61930. var geo = null;
  61931. // Finds the first valid sibling swimlane as reference
  61932. for (var i = 0; i < childCount; i++)
  61933. {
  61934. var child = model.getChildAt(parent, i);
  61935. if (child != swimlane && !this.isSwimlaneIgnored(child))
  61936. {
  61937. geo = model.getGeometry(child);
  61938. if (geo != null)
  61939. {
  61940. break;
  61941. }
  61942. }
  61943. }
  61944. // Applies the size of the refernece to the newly added swimlane
  61945. if (geo != null)
  61946. {
  61947. var parentHorizontal = (parent != null) ? this.isCellHorizontal(parent) : this.horizontal;
  61948. this.resizeSwimlane(swimlane, geo.width, geo.height, parentHorizontal);
  61949. }
  61950. };
  61951. /**
  61952. * Function: cellsResized
  61953. *
  61954. * Called if any cells have been resizes. Calls <swimlaneResized> for all
  61955. * swimlanes where <isSwimlaneIgnored> returns false.
  61956. *
  61957. * Parameters:
  61958. *
  61959. * cells - Array of <mxCells> whose size was changed.
  61960. */
  61961. mxSwimlaneManager.prototype.cellsResized = function(cells)
  61962. {
  61963. if (cells != null)
  61964. {
  61965. var model = this.getGraph().getModel();
  61966. model.beginUpdate();
  61967. try
  61968. {
  61969. // Finds the top-level swimlanes and adds offsets
  61970. for (var i = 0; i < cells.length; i++)
  61971. {
  61972. if (!this.isSwimlaneIgnored(cells[i]))
  61973. {
  61974. var geo = model.getGeometry(cells[i]);
  61975. if (geo != null)
  61976. {
  61977. var size = new mxRectangle(0, 0, geo.width, geo.height);
  61978. var top = cells[i];
  61979. var current = top;
  61980. while (current != null)
  61981. {
  61982. top = current;
  61983. current = model.getParent(current);
  61984. var tmp = (this.graph.isSwimlane(current)) ?
  61985. this.graph.getStartSize(current) :
  61986. new mxRectangle();
  61987. size.width += tmp.width;
  61988. size.height += tmp.height;
  61989. }
  61990. var parentHorizontal = (current != null) ? this.isCellHorizontal(current) : this.horizontal;
  61991. this.resizeSwimlane(top, size.width, size.height, parentHorizontal);
  61992. }
  61993. }
  61994. }
  61995. }
  61996. finally
  61997. {
  61998. model.endUpdate();
  61999. }
  62000. }
  62001. };
  62002. /**
  62003. * Function: resizeSwimlane
  62004. *
  62005. * Called from <cellsResized> for all swimlanes that are not ignored to update
  62006. * the size of the siblings and the size of the parent swimlanes, recursively,
  62007. * if <bubbling> is true.
  62008. *
  62009. * Parameters:
  62010. *
  62011. * swimlane - <mxCell> whose size has changed.
  62012. */
  62013. mxSwimlaneManager.prototype.resizeSwimlane = function(swimlane, w, h, parentHorizontal)
  62014. {
  62015. var model = this.getGraph().getModel();
  62016. model.beginUpdate();
  62017. try
  62018. {
  62019. var horizontal = this.isCellHorizontal(swimlane);
  62020. if (!this.isSwimlaneIgnored(swimlane))
  62021. {
  62022. var geo = model.getGeometry(swimlane);
  62023. if (geo != null)
  62024. {
  62025. if ((parentHorizontal && geo.height != h) || (!parentHorizontal && geo.width != w))
  62026. {
  62027. geo = geo.clone();
  62028. if (parentHorizontal)
  62029. {
  62030. geo.height = h;
  62031. }
  62032. else
  62033. {
  62034. geo.width = w;
  62035. }
  62036. model.setGeometry(swimlane, geo);
  62037. }
  62038. }
  62039. }
  62040. var tmp = (this.graph.isSwimlane(swimlane)) ?
  62041. this.graph.getStartSize(swimlane) :
  62042. new mxRectangle();
  62043. w -= tmp.width;
  62044. h -= tmp.height;
  62045. var childCount = model.getChildCount(swimlane);
  62046. for (var i = 0; i < childCount; i++)
  62047. {
  62048. var child = model.getChildAt(swimlane, i);
  62049. this.resizeSwimlane(child, w, h, horizontal);
  62050. }
  62051. }
  62052. finally
  62053. {
  62054. model.endUpdate();
  62055. }
  62056. };
  62057. /**
  62058. * Function: destroy
  62059. *
  62060. * Removes all handlers from the <graph> and deletes the reference to it.
  62061. */
  62062. mxSwimlaneManager.prototype.destroy = function()
  62063. {
  62064. this.setGraph(null);
  62065. };
  62066. /**
  62067. * Copyright (c) 2006-2017, JGraph Ltd
  62068. * Copyright (c) 2006-2017, Gaudenz Alder
  62069. */
  62070. /**
  62071. * Class: mxTemporaryCellStates
  62072. *
  62073. * Creates a temporary set of cell states.
  62074. */
  62075. function mxTemporaryCellStates(view, scale, cells, isCellVisibleFn, getLinkForCellState)
  62076. {
  62077. scale = (scale != null) ? scale : 1;
  62078. this.view = view;
  62079. // Stores the previous state
  62080. this.oldValidateCellState = view.validateCellState;
  62081. this.oldBounds = view.getGraphBounds();
  62082. this.oldStates = view.getStates();
  62083. this.oldScale = view.getScale();
  62084. this.oldDoRedrawShape = view.graph.cellRenderer.doRedrawShape;
  62085. var self = this;
  62086. // Overrides doRedrawShape and paint shape to add links on shapes
  62087. if (getLinkForCellState != null)
  62088. {
  62089. view.graph.cellRenderer.doRedrawShape = function(state)
  62090. {
  62091. var oldPaint = state.shape.paint;
  62092. state.shape.paint = function(c)
  62093. {
  62094. var link = getLinkForCellState(state);
  62095. if (link != null)
  62096. {
  62097. c.setLink(link);
  62098. }
  62099. oldPaint.apply(this, arguments);
  62100. if (link != null)
  62101. {
  62102. c.setLink(null);
  62103. }
  62104. };
  62105. self.oldDoRedrawShape.apply(view.graph.cellRenderer, arguments);
  62106. state.shape.paint = oldPaint;
  62107. };
  62108. }
  62109. // Overrides validateCellState to ignore invisible cells
  62110. view.validateCellState = function(cell, resurse)
  62111. {
  62112. if (cell == null || isCellVisibleFn == null || isCellVisibleFn(cell))
  62113. {
  62114. return self.oldValidateCellState.apply(view, arguments);
  62115. }
  62116. return null;
  62117. };
  62118. // Creates space for new states
  62119. view.setStates(new mxDictionary());
  62120. view.setScale(scale);
  62121. if (cells != null)
  62122. {
  62123. view.resetValidationState();
  62124. var bbox = null;
  62125. // Validates the vertices and edges without adding them to
  62126. // the model so that the original cells are not modified
  62127. for (var i = 0; i < cells.length; i++)
  62128. {
  62129. var bounds = view.getBoundingBox(view.validateCellState(view.validateCell(cells[i])));
  62130. if (bbox == null)
  62131. {
  62132. bbox = bounds;
  62133. }
  62134. else
  62135. {
  62136. bbox.add(bounds);
  62137. }
  62138. }
  62139. view.setGraphBounds(bbox || new mxRectangle());
  62140. }
  62141. };
  62142. /**
  62143. * Variable: view
  62144. *
  62145. * Holds the width of the rectangle. Default is 0.
  62146. */
  62147. mxTemporaryCellStates.prototype.view = null;
  62148. /**
  62149. * Variable: oldStates
  62150. *
  62151. * Holds the height of the rectangle. Default is 0.
  62152. */
  62153. mxTemporaryCellStates.prototype.oldStates = null;
  62154. /**
  62155. * Variable: oldBounds
  62156. *
  62157. * Holds the height of the rectangle. Default is 0.
  62158. */
  62159. mxTemporaryCellStates.prototype.oldBounds = null;
  62160. /**
  62161. * Variable: oldScale
  62162. *
  62163. * Holds the height of the rectangle. Default is 0.
  62164. */
  62165. mxTemporaryCellStates.prototype.oldScale = null;
  62166. /**
  62167. * Function: destroy
  62168. *
  62169. * Returns the top, left corner as a new <mxPoint>.
  62170. */
  62171. mxTemporaryCellStates.prototype.destroy = function()
  62172. {
  62173. this.view.setScale(this.oldScale);
  62174. this.view.setStates(this.oldStates);
  62175. this.view.setGraphBounds(this.oldBounds);
  62176. this.view.validateCellState = this.oldValidateCellState;
  62177. this.view.graph.cellRenderer.doRedrawShape = this.oldDoRedrawShape;
  62178. };
  62179. /**
  62180. * Copyright (c) 2006-2015, JGraph Ltd
  62181. * Copyright (c) 2006-2015, Gaudenz Alder
  62182. */
  62183. /**
  62184. *
  62185. * Class: mxCellStatePreview
  62186. *
  62187. * Implements a live preview for moving cells.
  62188. *
  62189. * Constructor: mxCellStatePreview
  62190. *
  62191. * Constructs a move preview for the given graph.
  62192. *
  62193. * Parameters:
  62194. *
  62195. * graph - Reference to the enclosing <mxGraph>.
  62196. */
  62197. function mxCellStatePreview(graph)
  62198. {
  62199. this.deltas = new mxDictionary();
  62200. this.graph = graph;
  62201. };
  62202. /**
  62203. * Variable: graph
  62204. *
  62205. * Reference to the enclosing <mxGraph>.
  62206. */
  62207. mxCellStatePreview.prototype.graph = null;
  62208. /**
  62209. * Variable: deltas
  62210. *
  62211. * Reference to the enclosing <mxGraph>.
  62212. */
  62213. mxCellStatePreview.prototype.deltas = null;
  62214. /**
  62215. * Variable: count
  62216. *
  62217. * Contains the number of entries in the map.
  62218. */
  62219. mxCellStatePreview.prototype.count = 0;
  62220. /**
  62221. * Function: isEmpty
  62222. *
  62223. * Returns true if this contains no entries.
  62224. */
  62225. mxCellStatePreview.prototype.isEmpty = function()
  62226. {
  62227. return this.count == 0;
  62228. };
  62229. /**
  62230. * Function: moveState
  62231. */
  62232. mxCellStatePreview.prototype.moveState = function(state, dx, dy, add, includeEdges)
  62233. {
  62234. add = (add != null) ? add : true;
  62235. includeEdges = (includeEdges != null) ? includeEdges : true;
  62236. var delta = this.deltas.get(state.cell);
  62237. if (delta == null)
  62238. {
  62239. // Note: Deltas stores the point and the state since the key is a string.
  62240. delta = {point: new mxPoint(dx, dy), state: state};
  62241. this.deltas.put(state.cell, delta);
  62242. this.count++;
  62243. }
  62244. else if (add)
  62245. {
  62246. delta.point.x += dx;
  62247. delta.point.y += dy;
  62248. }
  62249. else
  62250. {
  62251. delta.point.x = dx;
  62252. delta.point.y = dy;
  62253. }
  62254. if (includeEdges)
  62255. {
  62256. this.addEdges(state);
  62257. }
  62258. return delta.point;
  62259. };
  62260. /**
  62261. * Function: show
  62262. */
  62263. mxCellStatePreview.prototype.show = function(visitor)
  62264. {
  62265. this.deltas.visit(mxUtils.bind(this, function(key, delta)
  62266. {
  62267. this.translateState(delta.state, delta.point.x, delta.point.y);
  62268. }));
  62269. this.deltas.visit(mxUtils.bind(this, function(key, delta)
  62270. {
  62271. this.revalidateState(delta.state, delta.point.x, delta.point.y, visitor);
  62272. }));
  62273. };
  62274. /**
  62275. * Function: translateState
  62276. */
  62277. mxCellStatePreview.prototype.translateState = function(state, dx, dy)
  62278. {
  62279. if (state != null)
  62280. {
  62281. var model = this.graph.getModel();
  62282. if (model.isVertex(state.cell))
  62283. {
  62284. state.view.updateCellState(state);
  62285. var geo = model.getGeometry(state.cell);
  62286. // Moves selection cells and non-relative vertices in
  62287. // the first phase so that edge terminal points will
  62288. // be updated in the second phase
  62289. if ((dx != 0 || dy != 0) && geo != null && (!geo.relative || this.deltas.get(state.cell) != null))
  62290. {
  62291. state.x += dx;
  62292. state.y += dy;
  62293. }
  62294. }
  62295. var childCount = model.getChildCount(state.cell);
  62296. for (var i = 0; i < childCount; i++)
  62297. {
  62298. this.translateState(state.view.getState(model.getChildAt(state.cell, i)), dx, dy);
  62299. }
  62300. }
  62301. };
  62302. /**
  62303. * Function: revalidateState
  62304. */
  62305. mxCellStatePreview.prototype.revalidateState = function(state, dx, dy, visitor)
  62306. {
  62307. if (state != null)
  62308. {
  62309. var model = this.graph.getModel();
  62310. // Updates the edge terminal points and restores the
  62311. // (relative) positions of any (relative) children
  62312. if (model.isEdge(state.cell))
  62313. {
  62314. state.view.updateCellState(state);
  62315. }
  62316. var geo = this.graph.getCellGeometry(state.cell);
  62317. var pState = state.view.getState(model.getParent(state.cell));
  62318. // Moves selection vertices which are relative
  62319. if ((dx != 0 || dy != 0) && geo != null && geo.relative &&
  62320. model.isVertex(state.cell) && (pState == null ||
  62321. model.isVertex(pState.cell) || this.deltas.get(state.cell) != null))
  62322. {
  62323. state.x += dx;
  62324. state.y += dy;
  62325. }
  62326. this.graph.cellRenderer.redraw(state);
  62327. // Invokes the visitor on the given state
  62328. if (visitor != null)
  62329. {
  62330. visitor(state);
  62331. }
  62332. var childCount = model.getChildCount(state.cell);
  62333. for (var i = 0; i < childCount; i++)
  62334. {
  62335. this.revalidateState(this.graph.view.getState(model.getChildAt(state.cell, i)), dx, dy, visitor);
  62336. }
  62337. }
  62338. };
  62339. /**
  62340. * Function: addEdges
  62341. */
  62342. mxCellStatePreview.prototype.addEdges = function(state)
  62343. {
  62344. var model = this.graph.getModel();
  62345. var edgeCount = model.getEdgeCount(state.cell);
  62346. for (var i = 0; i < edgeCount; i++)
  62347. {
  62348. var s = state.view.getState(model.getEdgeAt(state.cell, i));
  62349. if (s != null)
  62350. {
  62351. this.moveState(s, 0, 0);
  62352. }
  62353. }
  62354. };
  62355. /**
  62356. * Copyright (c) 2006-2015, JGraph Ltd
  62357. * Copyright (c) 2006-2015, Gaudenz Alder
  62358. */
  62359. /**
  62360. * Class: mxConnectionConstraint
  62361. *
  62362. * Defines an object that contains the constraints about how to connect one
  62363. * side of an edge to its terminal.
  62364. *
  62365. * Constructor: mxConnectionConstraint
  62366. *
  62367. * Constructs a new connection constraint for the given point and boolean
  62368. * arguments.
  62369. *
  62370. * Parameters:
  62371. *
  62372. * point - Optional <mxPoint> that specifies the fixed location of the point
  62373. * in relative coordinates. Default is null.
  62374. * perimeter - Optional boolean that specifies if the fixed point should be
  62375. * projected onto the perimeter of the terminal. Default is true.
  62376. */
  62377. function mxConnectionConstraint(point, perimeter, name, dx, dy)
  62378. {
  62379. this.point = point;
  62380. this.perimeter = (perimeter != null) ? perimeter : true;
  62381. this.name = name;
  62382. this.dx = dx? dx : 0;
  62383. this.dy = dy? dy : 0;
  62384. };
  62385. /**
  62386. * Variable: point
  62387. *
  62388. * <mxPoint> that specifies the fixed location of the connection point.
  62389. */
  62390. mxConnectionConstraint.prototype.point = null;
  62391. /**
  62392. * Variable: perimeter
  62393. *
  62394. * Boolean that specifies if the point should be projected onto the perimeter
  62395. * of the terminal.
  62396. */
  62397. mxConnectionConstraint.prototype.perimeter = null;
  62398. /**
  62399. * Variable: name
  62400. *
  62401. * Optional string that specifies the name of the constraint.
  62402. */
  62403. mxConnectionConstraint.prototype.name = null;
  62404. /**
  62405. * Variable: dx
  62406. *
  62407. * Optional float that specifies the horizontal offset of the constraint.
  62408. */
  62409. mxConnectionConstraint.prototype.dx = null;
  62410. /**
  62411. * Variable: dy
  62412. *
  62413. * Optional float that specifies the vertical offset of the constraint.
  62414. */
  62415. mxConnectionConstraint.prototype.dy = null;
  62416. /**
  62417. * Copyright (c) 2006-2015, JGraph Ltd
  62418. * Copyright (c) 2006-2015, Gaudenz Alder
  62419. */
  62420. /**
  62421. * Class: mxGraphHandler
  62422. *
  62423. * Graph event handler that handles selection. Individual cells are handled
  62424. * separately using <mxVertexHandler> or one of the edge handlers. These
  62425. * handlers are created using <mxGraph.createHandler> in
  62426. * <mxGraphSelectionModel.cellAdded>.
  62427. *
  62428. * To avoid the container to scroll a moved cell into view, set
  62429. * <scrollAfterMove> to false.
  62430. *
  62431. * Constructor: mxGraphHandler
  62432. *
  62433. * Constructs an event handler that creates handles for the
  62434. * selection cells.
  62435. *
  62436. * Parameters:
  62437. *
  62438. * graph - Reference to the enclosing <mxGraph>.
  62439. */
  62440. function mxGraphHandler(graph)
  62441. {
  62442. this.graph = graph;
  62443. this.graph.addMouseListener(this);
  62444. // Repaints the handler after autoscroll
  62445. this.panHandler = mxUtils.bind(this, function()
  62446. {
  62447. if (!this.suspended)
  62448. {
  62449. this.updatePreview();
  62450. this.updateHint();
  62451. }
  62452. });
  62453. this.graph.addListener(mxEvent.PAN, this.panHandler);
  62454. // Handles escape keystrokes
  62455. this.escapeHandler = mxUtils.bind(this, function(sender, evt)
  62456. {
  62457. this.reset();
  62458. });
  62459. this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
  62460. // Updates the preview box for remote changes
  62461. this.refreshHandler = mxUtils.bind(this, function(sender, evt)
  62462. {
  62463. // Waits for the states and handlers to be updated
  62464. window.setTimeout(mxUtils.bind(this, function()
  62465. {
  62466. if (this.first != null && !this.suspended)
  62467. {
  62468. // Updates preview with no translate to compute bounding box
  62469. var dx = this.currentDx;
  62470. var dy = this.currentDy;
  62471. this.currentDx = 0;
  62472. this.currentDy = 0;
  62473. this.updatePreview();
  62474. this.bounds = this.graph.getView().getBounds(this.cells);
  62475. this.pBounds = this.getPreviewBounds(this.cells);
  62476. if (this.pBounds == null)
  62477. {
  62478. this.reset();
  62479. }
  62480. else
  62481. {
  62482. // Restores translate and updates preview
  62483. this.currentDx = dx;
  62484. this.currentDy = dy;
  62485. this.updatePreview();
  62486. this.updateHint();
  62487. if (this.livePreviewUsed)
  62488. {
  62489. this.setHandlesVisibleForCells(
  62490. this.graph.selectionCellsHandler.
  62491. getHandledSelectionCells(), false);
  62492. }
  62493. }
  62494. }
  62495. }), 0);
  62496. });
  62497. this.graph.getModel().addListener(mxEvent.CHANGE, this.refreshHandler);
  62498. this.keyHandler = mxUtils.bind(this, function(e)
  62499. {
  62500. if (this.graph.container != null && this.graph.container.style.visibility != 'hidden' &&
  62501. this.first != null && !this.suspended)
  62502. {
  62503. var clone = this.graph.isCloneEvent(e) &&
  62504. this.graph.isCellsCloneable() &&
  62505. this.isCloneEnabled();
  62506. if (clone != this.cloning)
  62507. {
  62508. this.cloning = clone;
  62509. this.checkPreview();
  62510. this.updatePreview();
  62511. }
  62512. }
  62513. });
  62514. mxEvent.addListener(document, 'keydown', this.keyHandler);
  62515. mxEvent.addListener(document, 'keyup', this.keyHandler);
  62516. };
  62517. /**
  62518. * Variable: graph
  62519. *
  62520. * Reference to the enclosing <mxGraph>.
  62521. */
  62522. mxGraphHandler.prototype.graph = null;
  62523. /**
  62524. * Variable: maxCells
  62525. *
  62526. * Defines the maximum number of cells to paint subhandles
  62527. * for. Default is 50 for Firefox and 20 for IE. Set this
  62528. * to 0 if you want an unlimited number of handles to be
  62529. * displayed. This is only recommended if the number of
  62530. * cells in the graph is limited to a small number, eg.
  62531. * 500.
  62532. */
  62533. mxGraphHandler.prototype.maxCells = (mxClient.IS_IE) ? 20 : 50;
  62534. /**
  62535. * Variable: enabled
  62536. *
  62537. * Specifies if events are handled. Default is true.
  62538. */
  62539. mxGraphHandler.prototype.enabled = true;
  62540. /**
  62541. * Variable: highlightEnabled
  62542. *
  62543. * Specifies if drop targets under the mouse should be enabled. Default is
  62544. * true.
  62545. */
  62546. mxGraphHandler.prototype.highlightEnabled = true;
  62547. /**
  62548. * Variable: cloneEnabled
  62549. *
  62550. * Specifies if cloning by control-drag is enabled. Default is true.
  62551. */
  62552. mxGraphHandler.prototype.cloneEnabled = true;
  62553. /**
  62554. * Variable: moveEnabled
  62555. *
  62556. * Specifies if moving is enabled. Default is true.
  62557. */
  62558. mxGraphHandler.prototype.moveEnabled = true;
  62559. /**
  62560. * Variable: guidesEnabled
  62561. *
  62562. * Specifies if other cells should be used for snapping the right, center or
  62563. * left side of the current selection. Default is false.
  62564. */
  62565. mxGraphHandler.prototype.guidesEnabled = false;
  62566. /**
  62567. * Variable: handlesVisible
  62568. *
  62569. * Whether the handles of the selection are currently visible.
  62570. */
  62571. mxGraphHandler.prototype.handlesVisible = true;
  62572. /**
  62573. * Variable: guide
  62574. *
  62575. * Holds the <mxGuide> instance that is used for alignment.
  62576. */
  62577. mxGraphHandler.prototype.guide = null;
  62578. /**
  62579. * Variable: currentDx
  62580. *
  62581. * Stores the x-coordinate of the current mouse move.
  62582. */
  62583. mxGraphHandler.prototype.currentDx = null;
  62584. /**
  62585. * Variable: currentDy
  62586. *
  62587. * Stores the y-coordinate of the current mouse move.
  62588. */
  62589. mxGraphHandler.prototype.currentDy = null;
  62590. /**
  62591. * Variable: updateCursor
  62592. *
  62593. * Specifies if a move cursor should be shown if the mouse is over a movable
  62594. * cell. Default is true.
  62595. */
  62596. mxGraphHandler.prototype.updateCursor = true;
  62597. /**
  62598. * Variable: selectEnabled
  62599. *
  62600. * Specifies if selecting is enabled. Default is true.
  62601. */
  62602. mxGraphHandler.prototype.selectEnabled = true;
  62603. /**
  62604. * Variable: removeCellsFromParent
  62605. *
  62606. * Specifies if cells may be moved out of their parents. Default is true.
  62607. */
  62608. mxGraphHandler.prototype.removeCellsFromParent = true;
  62609. /**
  62610. * Variable: removeEmptyParents
  62611. *
  62612. * If empty parents should be removed from the model after all child cells
  62613. * have been moved out. Default is true.
  62614. */
  62615. mxGraphHandler.prototype.removeEmptyParents = false;
  62616. /**
  62617. * Variable: connectOnDrop
  62618. *
  62619. * Specifies if drop events are interpreted as new connections if no other
  62620. * drop action is defined. Default is false.
  62621. */
  62622. mxGraphHandler.prototype.connectOnDrop = false;
  62623. /**
  62624. * Variable: scrollOnMove
  62625. *
  62626. * Specifies if the view should be scrolled so that a moved cell is
  62627. * visible. Default is true.
  62628. */
  62629. mxGraphHandler.prototype.scrollOnMove = true;
  62630. /**
  62631. * Variable: minimumSize
  62632. *
  62633. * Specifies the minimum number of pixels for the width and height of a
  62634. * selection border. Default is 6.
  62635. */
  62636. mxGraphHandler.prototype.minimumSize = 6;
  62637. /**
  62638. * Variable: previewColor
  62639. *
  62640. * Specifies the color of the preview shape. Default is black.
  62641. */
  62642. mxGraphHandler.prototype.previewColor = 'black';
  62643. /**
  62644. * Variable: htmlPreview
  62645. *
  62646. * Specifies if the graph container should be used for preview. If this is used
  62647. * then drop target detection relies entirely on <mxGraph.getCellAt> because
  62648. * the HTML preview does not "let events through". Default is false.
  62649. */
  62650. mxGraphHandler.prototype.htmlPreview = false;
  62651. /**
  62652. * Variable: shape
  62653. *
  62654. * Reference to the <mxShape> that represents the preview.
  62655. */
  62656. mxGraphHandler.prototype.shape = null;
  62657. /**
  62658. * Variable: scaleGrid
  62659. *
  62660. * Specifies if the grid should be scaled. Default is false.
  62661. */
  62662. mxGraphHandler.prototype.scaleGrid = false;
  62663. /**
  62664. * Variable: rotationEnabled
  62665. *
  62666. * Specifies if the bounding box should allow for rotation. Default is true.
  62667. */
  62668. mxGraphHandler.prototype.rotationEnabled = true;
  62669. /**
  62670. * Variable: maxLivePreview
  62671. *
  62672. * Maximum number of cells for which live preview should be used. Default is 0
  62673. * which means no live preview.
  62674. */
  62675. mxGraphHandler.prototype.maxLivePreview = 0;
  62676. /**
  62677. * Variable: allowLivePreview
  62678. *
  62679. * If live preview is allowed on this system. Default is true for systems with
  62680. * SVG support.
  62681. */
  62682. mxGraphHandler.prototype.allowLivePreview = mxClient.IS_SVG;
  62683. /**
  62684. * Function: isEnabled
  62685. *
  62686. * Returns <enabled>.
  62687. */
  62688. mxGraphHandler.prototype.isEnabled = function()
  62689. {
  62690. return this.enabled;
  62691. };
  62692. /**
  62693. * Function: setEnabled
  62694. *
  62695. * Sets <enabled>.
  62696. */
  62697. mxGraphHandler.prototype.setEnabled = function(value)
  62698. {
  62699. this.enabled = value;
  62700. };
  62701. /**
  62702. * Function: isCloneEnabled
  62703. *
  62704. * Returns <cloneEnabled>.
  62705. */
  62706. mxGraphHandler.prototype.isCloneEnabled = function()
  62707. {
  62708. return this.cloneEnabled;
  62709. };
  62710. /**
  62711. * Function: setCloneEnabled
  62712. *
  62713. * Sets <cloneEnabled>.
  62714. *
  62715. * Parameters:
  62716. *
  62717. * value - Boolean that specifies the new clone enabled state.
  62718. */
  62719. mxGraphHandler.prototype.setCloneEnabled = function(value)
  62720. {
  62721. this.cloneEnabled = value;
  62722. };
  62723. /**
  62724. * Function: isMoveEnabled
  62725. *
  62726. * Returns <moveEnabled>.
  62727. */
  62728. mxGraphHandler.prototype.isMoveEnabled = function()
  62729. {
  62730. return this.moveEnabled;
  62731. };
  62732. /**
  62733. * Function: setMoveEnabled
  62734. *
  62735. * Sets <moveEnabled>.
  62736. */
  62737. mxGraphHandler.prototype.setMoveEnabled = function(value)
  62738. {
  62739. this.moveEnabled = value;
  62740. };
  62741. /**
  62742. * Function: isSelectEnabled
  62743. *
  62744. * Returns <selectEnabled>.
  62745. */
  62746. mxGraphHandler.prototype.isSelectEnabled = function()
  62747. {
  62748. return this.selectEnabled;
  62749. };
  62750. /**
  62751. * Function: setSelectEnabled
  62752. *
  62753. * Sets <selectEnabled>.
  62754. */
  62755. mxGraphHandler.prototype.setSelectEnabled = function(value)
  62756. {
  62757. this.selectEnabled = value;
  62758. };
  62759. /**
  62760. * Function: isRemoveCellsFromParent
  62761. *
  62762. * Returns <removeCellsFromParent>.
  62763. */
  62764. mxGraphHandler.prototype.isRemoveCellsFromParent = function()
  62765. {
  62766. return this.removeCellsFromParent;
  62767. };
  62768. /**
  62769. * Function: setRemoveCellsFromParent
  62770. *
  62771. * Sets <removeCellsFromParent>.
  62772. */
  62773. mxGraphHandler.prototype.setRemoveCellsFromParent = function(value)
  62774. {
  62775. this.removeCellsFromParent = value;
  62776. };
  62777. /**
  62778. * Function: isPropagateSelectionCell
  62779. *
  62780. * Returns true if the given cell and parent should propagate
  62781. * selection state to the parent.
  62782. */
  62783. mxGraphHandler.prototype.isPropagateSelectionCell = function(cell, immediate, me)
  62784. {
  62785. var parent = this.graph.model.getParent(cell);
  62786. if (immediate)
  62787. {
  62788. var geo = this.graph.getCellGeometry(cell);
  62789. return !this.graph.model.isEdge(cell) &&
  62790. !this.graph.model.isEdge(parent) &&
  62791. !this.graph.isSiblingSelected(cell) &&
  62792. (geo == null || geo.relative ||
  62793. !this.graph.isSwimlane(parent));
  62794. }
  62795. else
  62796. {
  62797. return (!this.graph.isToggleEvent(me.getEvent()) ||
  62798. (!this.graph.isSiblingSelected(cell) &&
  62799. !this.graph.isCellSelected(cell) &&
  62800. (!this.graph.isSwimlane(parent)) ||
  62801. this.graph.isCellSelected(parent))) &&
  62802. (this.graph.isToggleEvent(me.getEvent()) ||
  62803. !this.graph.isCellSelected(parent));
  62804. }
  62805. };
  62806. /**
  62807. * Function: getInitialCellForEvent
  62808. *
  62809. * Hook to return initial cell for the given event. This returns
  62810. * the topmost cell that is not a swimlane or is selected.
  62811. */
  62812. mxGraphHandler.prototype.getInitialCellForEvent = function(me)
  62813. {
  62814. var state = me.getState();
  62815. if ((!this.graph.isToggleEvent(me.getEvent()) || !mxEvent.isAltDown(me.getEvent())) &&
  62816. state != null && !this.graph.isCellSelected(state.cell))
  62817. {
  62818. var model = this.graph.model;
  62819. var next = this.graph.view.getState(model.getParent(state.cell));
  62820. while (next != null && !this.graph.isCellSelected(next.cell) &&
  62821. (model.isVertex(next.cell) || model.isEdge(next.cell)) &&
  62822. this.isPropagateSelectionCell(state.cell, true, me))
  62823. {
  62824. state = next;
  62825. next = this.graph.view.getState(this.graph.getModel().getParent(state.cell));
  62826. }
  62827. }
  62828. return (state != null) ? state.cell : null;
  62829. };
  62830. /**
  62831. * Function: isDelayedSelection
  62832. *
  62833. * Returns true if the cell or one of its ancestors is selected.
  62834. */
  62835. mxGraphHandler.prototype.isDelayedSelection = function(cell, me)
  62836. {
  62837. if (!this.graph.isToggleEvent(me.getEvent()) || !mxEvent.isAltDown(me.getEvent()))
  62838. {
  62839. while (cell != null)
  62840. {
  62841. if (this.graph.selectionCellsHandler.isHandled(cell))
  62842. {
  62843. return this.graph.cellEditor.getEditingCell() != cell;
  62844. }
  62845. cell = this.graph.model.getParent(cell);
  62846. }
  62847. }
  62848. return this.graph.isToggleEvent(me.getEvent()) && !mxEvent.isAltDown(me.getEvent());
  62849. };
  62850. /**
  62851. * Function: selectDelayed
  62852. *
  62853. * Implements the delayed selection for the given mouse event.
  62854. */
  62855. mxGraphHandler.prototype.selectDelayed = function(me)
  62856. {
  62857. if (!this.graph.popupMenuHandler.isPopupTrigger(me))
  62858. {
  62859. var cell = me.getCell();
  62860. if (cell == null)
  62861. {
  62862. cell = this.cell;
  62863. }
  62864. // Selects folded cell for hit on folding icon
  62865. var state = this.graph.view.getState(cell)
  62866. if (state != null)
  62867. {
  62868. if (me.isSource(state.control))
  62869. {
  62870. this.graph.selectCellForEvent(cell, me.getEvent());
  62871. }
  62872. else
  62873. {
  62874. if (!this.graph.isToggleEvent(me.getEvent()) ||
  62875. !mxEvent.isAltDown(me.getEvent()))
  62876. {
  62877. var model = this.graph.getModel();
  62878. var parent = model.getParent(cell);
  62879. while (this.graph.view.getState(parent) != null &&
  62880. (model.isVertex(parent) || model.isEdge(parent)) &&
  62881. this.isPropagateSelectionCell(cell, false, me))
  62882. {
  62883. cell = parent;
  62884. parent = model.getParent(cell);
  62885. }
  62886. }
  62887. this.graph.selectCellForEvent(cell, me.getEvent());
  62888. }
  62889. }
  62890. }
  62891. };
  62892. /**
  62893. * Function: consumeMouseEvent
  62894. *
  62895. * Consumes the given mouse event. NOTE: This may be used to enable click
  62896. * events for links in labels on iOS as follows as consuming the initial
  62897. * touchStart disables firing the subsequent click event on the link.
  62898. *
  62899. * <code>
  62900. * mxGraphHandler.prototype.consumeMouseEvent = function(evtName, me)
  62901. * {
  62902. * var source = mxEvent.getSource(me.getEvent());
  62903. *
  62904. * if (!mxEvent.isTouchEvent(me.getEvent()) || source.nodeName != 'A')
  62905. * {
  62906. * me.consume();
  62907. * }
  62908. * }
  62909. * </code>
  62910. */
  62911. mxGraphHandler.prototype.consumeMouseEvent = function(evtName, me)
  62912. {
  62913. me.consume();
  62914. };
  62915. /**
  62916. * Function: mouseDown
  62917. *
  62918. * Handles the event by selecing the given cell and creating a handle for
  62919. * it. By consuming the event all subsequent events of the gesture are
  62920. * redirected to this handler.
  62921. */
  62922. mxGraphHandler.prototype.mouseDown = function(sender, me)
  62923. {
  62924. if (!me.isConsumed() && this.isEnabled() && this.graph.isEnabled() &&
  62925. me.getState() != null && !mxEvent.isMultiTouchEvent(me.getEvent()))
  62926. {
  62927. var cell = this.getInitialCellForEvent(me);
  62928. this.delayedSelection = this.isDelayedSelection(cell, me);
  62929. this.cell = null;
  62930. if (this.isSelectEnabled() && !this.delayedSelection)
  62931. {
  62932. this.graph.selectCellForEvent(cell, me.getEvent());
  62933. }
  62934. if (this.isMoveEnabled())
  62935. {
  62936. var model = this.graph.model;
  62937. var geo = model.getGeometry(cell);
  62938. if (this.graph.isCellMovable(cell) && ((!model.isEdge(cell) || this.graph.getSelectionCount() > 1 ||
  62939. (geo.points != null && geo.points.length > 0) || model.getTerminal(cell, true) == null ||
  62940. model.getTerminal(cell, false) == null) || this.graph.allowDanglingEdges ||
  62941. (this.graph.isCloneEvent(me.getEvent()) && this.graph.isCellsCloneable())))
  62942. {
  62943. this.start(cell, me.getX(), me.getY());
  62944. }
  62945. else if (this.delayedSelection)
  62946. {
  62947. this.cell = cell;
  62948. }
  62949. this.cellWasClicked = true;
  62950. this.consumeMouseEvent(mxEvent.MOUSE_DOWN, me);
  62951. }
  62952. }
  62953. };
  62954. /**
  62955. * Function: getGuideStates
  62956. *
  62957. * Creates an array of cell states which should be used as guides.
  62958. */
  62959. mxGraphHandler.prototype.getGuideStates = function()
  62960. {
  62961. var parent = this.graph.getDefaultParent();
  62962. var model = this.graph.getModel();
  62963. var filter = mxUtils.bind(this, function(cell)
  62964. {
  62965. return this.graph.view.getState(cell) != null &&
  62966. model.isVertex(cell) &&
  62967. model.getGeometry(cell) != null &&
  62968. !model.getGeometry(cell).relative;
  62969. });
  62970. return this.graph.view.getCellStates(model.filterDescendants(filter, parent));
  62971. };
  62972. /**
  62973. * Function: getCells
  62974. *
  62975. * Returns the cells to be modified by this handler. This implementation
  62976. * returns all selection cells that are movable, or the given initial cell if
  62977. * the given cell is not selected and movable. This handles the case of moving
  62978. * unselectable or unselected cells.
  62979. *
  62980. * Parameters:
  62981. *
  62982. * initialCell - <mxCell> that triggered this handler.
  62983. */
  62984. mxGraphHandler.prototype.getCells = function(initialCell)
  62985. {
  62986. if (!this.delayedSelection && this.graph.isCellMovable(initialCell))
  62987. {
  62988. return [initialCell];
  62989. }
  62990. else
  62991. {
  62992. return this.graph.getMovableCells(this.graph.getSelectionCells());
  62993. }
  62994. };
  62995. /**
  62996. * Function: getPreviewBounds
  62997. *
  62998. * Returns the <mxRectangle> used as the preview bounds for
  62999. * moving the given cells.
  63000. */
  63001. mxGraphHandler.prototype.getPreviewBounds = function(cells)
  63002. {
  63003. var bounds = this.getBoundingBox(cells);
  63004. if (bounds != null)
  63005. {
  63006. // Corrects width and height
  63007. bounds.width = Math.max(0, bounds.width - 1);
  63008. bounds.height = Math.max(0, bounds.height - 1);
  63009. if (bounds.width < this.minimumSize)
  63010. {
  63011. var dx = this.minimumSize - bounds.width;
  63012. bounds.x -= dx / 2;
  63013. bounds.width = this.minimumSize;
  63014. }
  63015. else
  63016. {
  63017. bounds.x = Math.round(bounds.x);
  63018. bounds.width = Math.ceil(bounds.width);
  63019. }
  63020. var tr = this.graph.view.translate;
  63021. var s = this.graph.view.scale;
  63022. if (bounds.height < this.minimumSize)
  63023. {
  63024. var dy = this.minimumSize - bounds.height;
  63025. bounds.y -= dy / 2;
  63026. bounds.height = this.minimumSize;
  63027. }
  63028. else
  63029. {
  63030. bounds.y = Math.round(bounds.y);
  63031. bounds.height = Math.ceil(bounds.height);
  63032. }
  63033. }
  63034. return bounds;
  63035. };
  63036. /**
  63037. * Function: getBoundingBox
  63038. *
  63039. * Returns the union of the <mxCellStates> for the given array of <mxCells>.
  63040. * For vertices, this method uses the bounding box of the corresponding shape
  63041. * if one exists. The bounding box of the corresponding text label and all
  63042. * controls and overlays are ignored. See also: <mxGraphView.getBounds> and
  63043. * <mxGraph.getBoundingBox>.
  63044. *
  63045. * Parameters:
  63046. *
  63047. * cells - Array of <mxCells> whose bounding box should be returned.
  63048. */
  63049. mxGraphHandler.prototype.getBoundingBox = function(cells)
  63050. {
  63051. var result = null;
  63052. if (cells != null && cells.length > 0)
  63053. {
  63054. var model = this.graph.getModel();
  63055. for (var i = 0; i < cells.length; i++)
  63056. {
  63057. if (model.isVertex(cells[i]) || model.isEdge(cells[i]))
  63058. {
  63059. var state = this.graph.view.getState(cells[i]);
  63060. if (state != null)
  63061. {
  63062. var bbox = state;
  63063. if (model.isVertex(cells[i]) && state.shape != null && state.shape.boundingBox != null)
  63064. {
  63065. bbox = state.shape.boundingBox;
  63066. }
  63067. if (result == null)
  63068. {
  63069. result = mxRectangle.fromRectangle(bbox);
  63070. }
  63071. else
  63072. {
  63073. result.add(bbox);
  63074. }
  63075. }
  63076. }
  63077. }
  63078. }
  63079. return result;
  63080. };
  63081. /**
  63082. * Function: createPreviewShape
  63083. *
  63084. * Creates the shape used to draw the preview for the given bounds.
  63085. */
  63086. mxGraphHandler.prototype.createPreviewShape = function(bounds)
  63087. {
  63088. var shape = new mxRectangleShape(bounds, null, this.previewColor);
  63089. shape.isDashed = true;
  63090. if (this.htmlPreview)
  63091. {
  63092. shape.dialect = mxConstants.DIALECT_STRICTHTML;
  63093. shape.init(this.graph.container);
  63094. }
  63095. else
  63096. {
  63097. // Makes sure to use either VML or SVG shapes in order to implement
  63098. // event-transparency on the background area of the rectangle since
  63099. // HTML shapes do not let mouseevents through even when transparent
  63100. shape.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  63101. mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  63102. shape.init(this.graph.getView().getOverlayPane());
  63103. shape.pointerEvents = false;
  63104. // Workaround for artifacts on iOS
  63105. if (mxClient.IS_IOS)
  63106. {
  63107. shape.getSvgScreenOffset = function()
  63108. {
  63109. return 0;
  63110. };
  63111. }
  63112. }
  63113. return shape;
  63114. };
  63115. /**
  63116. * Function: start
  63117. *
  63118. * Starts the handling of the mouse gesture.
  63119. */
  63120. mxGraphHandler.prototype.start = function(cell, x, y, cells)
  63121. {
  63122. this.cell = cell;
  63123. this.first = mxUtils.convertPoint(this.graph.container, x, y);
  63124. this.cells = (cells != null) ? cells : this.getCells(this.cell);
  63125. this.bounds = this.graph.getView().getBounds(this.cells);
  63126. this.pBounds = this.getPreviewBounds(this.cells);
  63127. this.allCells = new mxDictionary();
  63128. this.cloning = false;
  63129. this.cellCount = 0;
  63130. for (var i = 0; i < this.cells.length; i++)
  63131. {
  63132. this.cellCount += this.addStates(this.cells[i], this.allCells);
  63133. }
  63134. if (this.guidesEnabled)
  63135. {
  63136. this.guide = new mxGuide(this.graph, this.getGuideStates());
  63137. var parent = this.graph.model.getParent(cell);
  63138. var ignore = this.graph.model.getChildCount(parent) < 2;
  63139. // Uses connected states as guides
  63140. var connected = new mxDictionary();
  63141. var opps = this.graph.getOpposites(this.graph.getEdges(this.cell), this.cell);
  63142. for (var i = 0; i < opps.length; i++)
  63143. {
  63144. var state = this.graph.view.getState(opps[i]);
  63145. if (state != null && !connected.get(state))
  63146. {
  63147. connected.put(state, true);
  63148. }
  63149. }
  63150. this.guide.isStateIgnored = mxUtils.bind(this, function(state)
  63151. {
  63152. var p = this.graph.model.getParent(state.cell);
  63153. return state.cell != null && ((!this.cloning &&
  63154. this.isCellMoving(state.cell)) ||
  63155. (state.cell != (this.target || parent) && !ignore &&
  63156. !connected.get(state) &&
  63157. (this.target == null || this.graph.model.getChildCount(
  63158. this.target) >= 2) && p != (this.target || parent)));
  63159. });
  63160. }
  63161. };
  63162. /**
  63163. * Function: addStates
  63164. *
  63165. * Adds the states for the given cell recursively to the given dictionary.
  63166. */
  63167. mxGraphHandler.prototype.addStates = function(cell, dict)
  63168. {
  63169. var state = this.graph.view.getState(cell);
  63170. var count = 0;
  63171. if (state != null && dict.get(cell) == null)
  63172. {
  63173. dict.put(cell, state);
  63174. count++;
  63175. var childCount = this.graph.model.getChildCount(cell);
  63176. for (var i = 0; i < childCount; i++)
  63177. {
  63178. count += this.addStates(this.graph.model.getChildAt(cell, i), dict);
  63179. }
  63180. }
  63181. return count;
  63182. };
  63183. /**
  63184. * Function: isCellMoving
  63185. *
  63186. * Returns true if the given cell is currently being moved.
  63187. */
  63188. mxGraphHandler.prototype.isCellMoving = function(cell)
  63189. {
  63190. return this.allCells.get(cell) != null;
  63191. };
  63192. /**
  63193. * Function: useGuidesForEvent
  63194. *
  63195. * Returns true if the guides should be used for the given <mxMouseEvent>.
  63196. * This implementation returns <mxGuide.isEnabledForEvent>.
  63197. */
  63198. mxGraphHandler.prototype.useGuidesForEvent = function(me)
  63199. {
  63200. return (this.guide != null) ? this.guide.isEnabledForEvent(me.getEvent()) &&
  63201. !this.graph.isConstrainedEvent(me.getEvent()) : true;
  63202. };
  63203. /**
  63204. * Function: snap
  63205. *
  63206. * Snaps the given vector to the grid and returns the given mxPoint instance.
  63207. */
  63208. mxGraphHandler.prototype.snap = function(vector)
  63209. {
  63210. var scale = (this.scaleGrid) ? this.graph.view.scale : 1;
  63211. vector.x = this.graph.snap(vector.x / scale) * scale;
  63212. vector.y = this.graph.snap(vector.y / scale) * scale;
  63213. return vector;
  63214. };
  63215. /**
  63216. * Function: getDelta
  63217. *
  63218. * Returns an <mxPoint> that represents the vector for moving the cells
  63219. * for the given <mxMouseEvent>.
  63220. */
  63221. mxGraphHandler.prototype.getDelta = function(me)
  63222. {
  63223. var point = mxUtils.convertPoint(this.graph.container, me.getX(), me.getY());
  63224. return new mxPoint(point.x - this.first.x - this.graph.panDx,
  63225. point.y - this.first.y - this.graph.panDy);
  63226. };
  63227. /**
  63228. * Function: updateHint
  63229. *
  63230. * Hook for subclassers do show details while the handler is active.
  63231. */
  63232. mxGraphHandler.prototype.updateHint = function(me) { };
  63233. /**
  63234. * Function: removeHint
  63235. *
  63236. * Hooks for subclassers to hide details when the handler gets inactive.
  63237. */
  63238. mxGraphHandler.prototype.removeHint = function() { };
  63239. /**
  63240. * Function: roundLength
  63241. *
  63242. * Hook for rounding the unscaled vector. Allows for half steps in the raster so
  63243. * numbers coming in should be rounded if no half steps are allowed (ie for non
  63244. * aligned standard moving where pixel steps should be preferred).
  63245. */
  63246. mxGraphHandler.prototype.roundLength = function(length)
  63247. {
  63248. return Math.round(length * 100) / 100;
  63249. };
  63250. /**
  63251. * Function: isValidDropTarget
  63252. *
  63253. * Returns true if the given cell is a valid drop target.
  63254. */
  63255. mxGraphHandler.prototype.isValidDropTarget = function(target, me)
  63256. {
  63257. return this.graph.model.getParent(this.cell) != target;
  63258. };
  63259. /**
  63260. * Function: checkPreview
  63261. *
  63262. * Updates the preview if cloning state has changed.
  63263. */
  63264. mxGraphHandler.prototype.checkPreview = function()
  63265. {
  63266. if (this.livePreviewActive && this.cloning)
  63267. {
  63268. this.resetLivePreview();
  63269. this.livePreviewActive = false;
  63270. }
  63271. else if (this.maxLivePreview >= this.cellCount && !this.livePreviewActive && this.allowLivePreview)
  63272. {
  63273. if (!this.cloning || !this.livePreviewActive)
  63274. {
  63275. this.livePreviewActive = true;
  63276. this.livePreviewUsed = true;
  63277. }
  63278. }
  63279. else if (!this.livePreviewUsed && this.shape == null)
  63280. {
  63281. this.shape = this.createPreviewShape(this.bounds);
  63282. }
  63283. };
  63284. /**
  63285. * Function: mouseMove
  63286. *
  63287. * Handles the event by highlighting possible drop targets and updating the
  63288. * preview.
  63289. */
  63290. mxGraphHandler.prototype.mouseMove = function(sender, me)
  63291. {
  63292. var graph = this.graph;
  63293. if (!me.isConsumed() && graph.isMouseDown && this.cell != null &&
  63294. this.first != null && this.bounds != null && !this.suspended)
  63295. {
  63296. // Stops moving if a multi touch event is received
  63297. if (mxEvent.isMultiTouchEvent(me.getEvent()))
  63298. {
  63299. this.reset();
  63300. return;
  63301. }
  63302. var delta = this.getDelta(me);
  63303. var tol = graph.tolerance;
  63304. if (this.shape != null || this.livePreviewActive || Math.abs(delta.x) > tol || Math.abs(delta.y) > tol)
  63305. {
  63306. // Highlight is used for highlighting drop targets
  63307. if (this.highlight == null)
  63308. {
  63309. this.highlight = new mxCellHighlight(this.graph,
  63310. mxConstants.DROP_TARGET_COLOR, 3);
  63311. }
  63312. var clone = graph.isCloneEvent(me.getEvent()) && graph.isCellsCloneable() && this.isCloneEnabled();
  63313. var gridEnabled = graph.isGridEnabledEvent(me.getEvent());
  63314. var cell = me.getCell();
  63315. var hideGuide = true;
  63316. var target = null;
  63317. this.cloning = clone;
  63318. if (graph.isDropEnabled() && this.highlightEnabled)
  63319. {
  63320. // Contains a call to getCellAt to find the cell under the mouse
  63321. target = graph.getDropTarget(this.cells, me.getEvent(), cell, clone);
  63322. }
  63323. var state = graph.getView().getState(target);
  63324. var highlight = false;
  63325. if (state != null && (clone || this.isValidDropTarget(target, me)))
  63326. {
  63327. if (this.target != target)
  63328. {
  63329. this.target = target;
  63330. this.setHighlightColor(mxConstants.DROP_TARGET_COLOR);
  63331. }
  63332. highlight = true;
  63333. }
  63334. else
  63335. {
  63336. this.target = null;
  63337. if (this.connectOnDrop && cell != null && this.cells.length == 1 &&
  63338. graph.getModel().isVertex(cell) && graph.isCellConnectable(cell))
  63339. {
  63340. state = graph.getView().getState(cell);
  63341. if (state != null)
  63342. {
  63343. var error = graph.getEdgeValidationError(null, this.cell, cell);
  63344. var color = (error == null) ?
  63345. mxConstants.VALID_COLOR :
  63346. mxConstants.INVALID_CONNECT_TARGET_COLOR;
  63347. this.setHighlightColor(color);
  63348. highlight = true;
  63349. }
  63350. }
  63351. }
  63352. if (state != null && highlight)
  63353. {
  63354. this.highlight.highlight(state);
  63355. }
  63356. else
  63357. {
  63358. this.highlight.hide();
  63359. }
  63360. if (this.guide != null && this.useGuidesForEvent(me))
  63361. {
  63362. delta = this.guide.move(this.bounds, delta, gridEnabled, clone);
  63363. hideGuide = false;
  63364. }
  63365. else
  63366. {
  63367. delta = this.graph.snapDelta(delta, this.bounds, !gridEnabled, false, false);
  63368. }
  63369. if (this.guide != null && hideGuide)
  63370. {
  63371. this.guide.hide();
  63372. }
  63373. // Constrained movement if shift key is pressed
  63374. if (graph.isConstrainedEvent(me.getEvent()))
  63375. {
  63376. if (Math.abs(delta.x) > Math.abs(delta.y))
  63377. {
  63378. delta.y = 0;
  63379. }
  63380. else
  63381. {
  63382. delta.x = 0;
  63383. }
  63384. }
  63385. this.checkPreview();
  63386. if (this.currentDx != delta.x || this.currentDy != delta.y)
  63387. {
  63388. this.currentDx = delta.x;
  63389. this.currentDy = delta.y;
  63390. this.updatePreview();
  63391. }
  63392. }
  63393. this.updateHint(me);
  63394. this.consumeMouseEvent(mxEvent.MOUSE_MOVE, me);
  63395. // Cancels the bubbling of events to the container so
  63396. // that the droptarget is not reset due to an mouseMove
  63397. // fired on the container with no associated state.
  63398. mxEvent.consume(me.getEvent());
  63399. }
  63400. else if ((this.isMoveEnabled() || this.isCloneEnabled()) && this.updateCursor && !me.isConsumed() &&
  63401. (me.getState() != null || me.sourceState != null) && !graph.isMouseDown)
  63402. {
  63403. var cursor = graph.getCursorForMouseEvent(me);
  63404. if (cursor == null && graph.isEnabled() && graph.isCellMovable(me.getCell()))
  63405. {
  63406. if (graph.getModel().isEdge(me.getCell()))
  63407. {
  63408. cursor = mxConstants.CURSOR_MOVABLE_EDGE;
  63409. }
  63410. else
  63411. {
  63412. cursor = mxConstants.CURSOR_MOVABLE_VERTEX;
  63413. }
  63414. }
  63415. // Sets the cursor on the original source state under the mouse
  63416. // instead of the event source state which can be the parent
  63417. if (cursor != null && me.sourceState != null)
  63418. {
  63419. me.sourceState.setCursor(cursor);
  63420. }
  63421. }
  63422. };
  63423. /**
  63424. * Function: updatePreview
  63425. *
  63426. * Updates the bounds of the preview shape.
  63427. */
  63428. mxGraphHandler.prototype.updatePreview = function(remote)
  63429. {
  63430. if (this.livePreviewUsed && !remote)
  63431. {
  63432. if (this.cells != null)
  63433. {
  63434. this.setHandlesVisibleForCells(
  63435. this.graph.selectionCellsHandler.
  63436. getHandledSelectionCells(), false);
  63437. this.updateLivePreview(this.currentDx, this.currentDy);
  63438. }
  63439. }
  63440. else
  63441. {
  63442. this.updatePreviewShape();
  63443. }
  63444. };
  63445. /**
  63446. * Function: updatePreviewShape
  63447. *
  63448. * Updates the bounds of the preview shape.
  63449. */
  63450. mxGraphHandler.prototype.updatePreviewShape = function()
  63451. {
  63452. if (this.shape != null && this.pBounds != null)
  63453. {
  63454. this.shape.bounds = new mxRectangle(Math.round(this.pBounds.x + this.currentDx),
  63455. Math.round(this.pBounds.y + this.currentDy), this.pBounds.width, this.pBounds.height);
  63456. this.shape.redraw();
  63457. }
  63458. };
  63459. /**
  63460. * Function: updateLivePreview
  63461. *
  63462. * Updates the bounds of the preview shape.
  63463. */
  63464. mxGraphHandler.prototype.updateLivePreview = function(dx, dy)
  63465. {
  63466. if (!this.suspended)
  63467. {
  63468. var states = [];
  63469. if (this.allCells != null)
  63470. {
  63471. this.allCells.visit(mxUtils.bind(this, function(key, state)
  63472. {
  63473. // Checks if cell was removed
  63474. if (this.graph.view.getState(state.cell) == null)
  63475. {
  63476. state.destroy();
  63477. }
  63478. else
  63479. {
  63480. // Saves current state
  63481. var tempState = state.clone();
  63482. states.push([state, tempState]);
  63483. // Makes transparent for events to detect drop targets
  63484. if (state.shape != null)
  63485. {
  63486. if (state.shape.originalPointerEvents == null)
  63487. {
  63488. state.shape.originalPointerEvents = state.shape.pointerEvents;
  63489. }
  63490. state.shape.pointerEvents = false;
  63491. if (state.text != null)
  63492. {
  63493. if (state.text.originalPointerEvents == null)
  63494. {
  63495. state.text.originalPointerEvents = state.text.pointerEvents;
  63496. }
  63497. state.text.pointerEvents = false;
  63498. }
  63499. }
  63500. // Temporarily changes position
  63501. if (this.graph.model.isVertex(state.cell))
  63502. {
  63503. state.x += dx;
  63504. state.y += dy;
  63505. // Draws the live preview
  63506. if (!this.cloning)
  63507. {
  63508. state.view.graph.cellRenderer.redraw(state, true);
  63509. // Forces redraw of connected edges after all states
  63510. // have been updated but avoids update of state
  63511. state.view.invalidate(state.cell);
  63512. state.invalid = false;
  63513. // Hides folding icon
  63514. if (state.control != null && state.control.node != null)
  63515. {
  63516. state.control.node.style.visibility = 'hidden';
  63517. }
  63518. }
  63519. }
  63520. }
  63521. }));
  63522. }
  63523. // Resets the handler if everything was removed
  63524. if (states.length == 0)
  63525. {
  63526. this.reset();
  63527. }
  63528. else
  63529. {
  63530. // Redraws connected edges
  63531. var s = this.graph.view.scale;
  63532. for (var i = 0; i < states.length; i++)
  63533. {
  63534. var state = states[i][0];
  63535. if (this.graph.model.isEdge(state.cell))
  63536. {
  63537. var geometry = this.graph.getCellGeometry(state.cell);
  63538. var points = [];
  63539. if (geometry != null && geometry.points != null)
  63540. {
  63541. for (var j = 0; j < geometry.points.length; j++)
  63542. {
  63543. if (geometry.points[j] != null)
  63544. {
  63545. points.push(new mxPoint(
  63546. geometry.points[j].x + dx / s,
  63547. geometry.points[j].y + dy / s));
  63548. }
  63549. }
  63550. }
  63551. var source = state.visibleSourceState;
  63552. var target = state.visibleTargetState;
  63553. var pts = states[i][1].absolutePoints;
  63554. if (source == null || !this.isCellMoving(source.cell))
  63555. {
  63556. var pt0 = pts[0];
  63557. state.setAbsoluteTerminalPoint(new mxPoint(pt0.x + dx, pt0.y + dy), true);
  63558. source = null;
  63559. }
  63560. else
  63561. {
  63562. state.view.updateFixedTerminalPoint(state, source, true,
  63563. this.graph.getConnectionConstraint(state, source, true));
  63564. }
  63565. if (target == null || !this.isCellMoving(target.cell))
  63566. {
  63567. var ptn = pts[pts.length - 1];
  63568. state.setAbsoluteTerminalPoint(new mxPoint(ptn.x + dx, ptn.y + dy), false);
  63569. target = null;
  63570. }
  63571. else
  63572. {
  63573. state.view.updateFixedTerminalPoint(state, target, false,
  63574. this.graph.getConnectionConstraint(state, target, false));
  63575. }
  63576. state.view.updatePoints(state, points, source, target);
  63577. state.view.updateFloatingTerminalPoints(state, source, target);
  63578. state.view.updateEdgeLabelOffset(state);
  63579. state.invalid = false;
  63580. // Draws the live preview but avoids update of state
  63581. if (!this.cloning)
  63582. {
  63583. state.view.graph.cellRenderer.redraw(state, true);
  63584. }
  63585. }
  63586. }
  63587. this.graph.view.validate();
  63588. this.redrawHandles(states);
  63589. this.resetPreviewStates(states);
  63590. }
  63591. }
  63592. };
  63593. /**
  63594. * Function: redrawHandles
  63595. *
  63596. * Redraws the preview shape for the given states array.
  63597. */
  63598. mxGraphHandler.prototype.redrawHandles = function(states)
  63599. {
  63600. for (var i = 0; i < states.length; i++)
  63601. {
  63602. var handler = this.graph.selectionCellsHandler.getHandler(states[i][0].cell);
  63603. if (handler != null)
  63604. {
  63605. handler.redraw(true);
  63606. }
  63607. }
  63608. };
  63609. /**
  63610. * Function: resetPreviewStates
  63611. *
  63612. * Resets the given preview states array.
  63613. */
  63614. mxGraphHandler.prototype.resetPreviewStates = function(states)
  63615. {
  63616. for (var i = 0; i < states.length; i++)
  63617. {
  63618. states[i][0].setState(states[i][1]);
  63619. }
  63620. };
  63621. /**
  63622. * Function: suspend
  63623. *
  63624. * Suspends the livew preview.
  63625. */
  63626. mxGraphHandler.prototype.suspend = function()
  63627. {
  63628. if (!this.suspended)
  63629. {
  63630. if (this.livePreviewUsed)
  63631. {
  63632. this.updateLivePreview(0, 0);
  63633. }
  63634. if (this.shape != null)
  63635. {
  63636. this.shape.node.style.visibility = 'hidden';
  63637. }
  63638. if (this.guide != null)
  63639. {
  63640. this.guide.setVisible(false);
  63641. }
  63642. this.suspended = true;
  63643. }
  63644. };
  63645. /**
  63646. * Function: resume
  63647. *
  63648. * Suspends the livew preview.
  63649. */
  63650. mxGraphHandler.prototype.resume = function()
  63651. {
  63652. if (this.suspended)
  63653. {
  63654. this.suspended = null;
  63655. if (this.livePreviewUsed)
  63656. {
  63657. this.livePreviewActive = true;
  63658. }
  63659. if (this.shape != null)
  63660. {
  63661. this.shape.node.style.visibility = 'visible';
  63662. }
  63663. if (this.guide != null)
  63664. {
  63665. this.guide.setVisible(true);
  63666. }
  63667. }
  63668. };
  63669. /**
  63670. * Function: resetLivePreview
  63671. *
  63672. * Resets the livew preview.
  63673. */
  63674. mxGraphHandler.prototype.resetLivePreview = function()
  63675. {
  63676. if (this.allCells != null)
  63677. {
  63678. this.allCells.visit(mxUtils.bind(this, function(key, state)
  63679. {
  63680. // Restores event handling
  63681. if (state.shape != null && state.shape.originalPointerEvents != null)
  63682. {
  63683. state.shape.pointerEvents = state.shape.originalPointerEvents;
  63684. state.shape.originalPointerEvents = null;
  63685. // Forces repaint even if not moved to update pointer events
  63686. state.shape.bounds = null;
  63687. if (state.text != null)
  63688. {
  63689. state.text.pointerEvents = state.text.originalPointerEvents;
  63690. state.text.originalPointerEvents = null;
  63691. }
  63692. }
  63693. // Shows folding icon
  63694. if (state.control != null && state.control.node != null &&
  63695. state.control.node.style.visibility == 'hidden')
  63696. {
  63697. state.control.node.style.visibility = '';
  63698. }
  63699. // Forces repaint of connected edges
  63700. state.view.invalidate(state.cell);
  63701. }));
  63702. // Repaints all invalid states
  63703. this.graph.view.validate();
  63704. }
  63705. };
  63706. /**
  63707. * Function: reset
  63708. *
  63709. * Resets the state of this handler.
  63710. */
  63711. mxGraphHandler.prototype.setHandlesVisibleForCells = function(cells, visible)
  63712. {
  63713. if (this.handlesVisible != visible)
  63714. {
  63715. this.handlesVisible = visible;
  63716. for (var i = 0; i < cells.length; i++)
  63717. {
  63718. var handler = this.graph.selectionCellsHandler.getHandler(cells[i]);
  63719. if (handler != null)
  63720. {
  63721. handler.setHandlesVisible(visible);
  63722. if (visible)
  63723. {
  63724. handler.redraw();
  63725. }
  63726. }
  63727. }
  63728. }
  63729. };
  63730. /**
  63731. * Function: setHighlightColor
  63732. *
  63733. * Sets the color of the rectangle used to highlight drop targets.
  63734. *
  63735. * Parameters:
  63736. *
  63737. * color - String that represents the new highlight color.
  63738. */
  63739. mxGraphHandler.prototype.setHighlightColor = function(color)
  63740. {
  63741. if (this.highlight != null)
  63742. {
  63743. this.highlight.setHighlightColor(color);
  63744. }
  63745. };
  63746. /**
  63747. * Function: mouseUp
  63748. *
  63749. * Handles the event by applying the changes to the selection cells.
  63750. */
  63751. mxGraphHandler.prototype.mouseUp = function(sender, me)
  63752. {
  63753. if (!me.isConsumed())
  63754. {
  63755. if (this.livePreviewUsed)
  63756. {
  63757. this.resetLivePreview();
  63758. }
  63759. if (this.cell != null && this.first != null && (this.shape != null || this.livePreviewUsed) &&
  63760. this.currentDx != null && this.currentDy != null)
  63761. {
  63762. var graph = this.graph;
  63763. var cell = me.getCell();
  63764. if (this.connectOnDrop && this.target == null && cell != null && graph.getModel().isVertex(cell) &&
  63765. graph.isCellConnectable(cell) && graph.isEdgeValid(null, this.cell, cell))
  63766. {
  63767. graph.connectionHandler.connect(this.cell, cell, me.getEvent());
  63768. }
  63769. else
  63770. {
  63771. var clone = graph.isCloneEvent(me.getEvent()) && graph.isCellsCloneable() && this.isCloneEnabled();
  63772. var scale = graph.getView().scale;
  63773. var dx = this.roundLength(this.currentDx / scale);
  63774. var dy = this.roundLength(this.currentDy / scale);
  63775. var target = this.target;
  63776. if (graph.isSplitEnabled() && graph.isSplitTarget(target, this.cells, me.getEvent()))
  63777. {
  63778. graph.splitEdge(target, this.cells, null, dx, dy,
  63779. me.getGraphX(), me.getGraphY());
  63780. }
  63781. else
  63782. {
  63783. this.moveCells(this.cells, dx, dy, clone, this.target, me.getEvent());
  63784. }
  63785. }
  63786. }
  63787. else if (this.isSelectEnabled() && this.delayedSelection && this.cell != null)
  63788. {
  63789. this.selectDelayed(me);
  63790. }
  63791. }
  63792. // Consumes the event if a cell was initially clicked
  63793. if (this.cellWasClicked)
  63794. {
  63795. this.consumeMouseEvent(mxEvent.MOUSE_UP, me);
  63796. }
  63797. this.reset();
  63798. };
  63799. /**
  63800. * Function: reset
  63801. *
  63802. * Resets the state of this handler.
  63803. */
  63804. mxGraphHandler.prototype.reset = function()
  63805. {
  63806. if (this.livePreviewUsed)
  63807. {
  63808. this.resetLivePreview();
  63809. this.setHandlesVisibleForCells(
  63810. this.graph.selectionCellsHandler.
  63811. getHandledSelectionCells(), true);
  63812. }
  63813. this.destroyShapes();
  63814. this.removeHint();
  63815. this.delayedSelection = false;
  63816. this.livePreviewActive = null;
  63817. this.livePreviewUsed = null;
  63818. this.cellWasClicked = false;
  63819. this.suspended = null;
  63820. this.currentDx = null;
  63821. this.currentDy = null;
  63822. this.cellCount = null;
  63823. this.cloning = false;
  63824. this.allCells = null;
  63825. this.pBounds = null;
  63826. this.guides = null;
  63827. this.target = null;
  63828. this.first = null;
  63829. this.cells = null;
  63830. this.cell = null;
  63831. };
  63832. /**
  63833. * Function: shouldRemoveCellsFromParent
  63834. *
  63835. * Returns true if the given cells should be removed from the parent for the specified
  63836. * mousereleased event.
  63837. */
  63838. mxGraphHandler.prototype.shouldRemoveCellsFromParent = function(parent, cells, evt)
  63839. {
  63840. if (this.graph.getModel().isVertex(parent))
  63841. {
  63842. var pState = this.graph.getView().getState(parent);
  63843. if (pState != null)
  63844. {
  63845. var pt = mxUtils.convertPoint(this.graph.container,
  63846. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  63847. var alpha = mxUtils.toRadians(mxUtils.getValue(pState.style, mxConstants.STYLE_ROTATION) || 0);
  63848. if (alpha != 0)
  63849. {
  63850. var cos = Math.cos(-alpha);
  63851. var sin = Math.sin(-alpha);
  63852. var cx = new mxPoint(pState.getCenterX(), pState.getCenterY());
  63853. pt = mxUtils.getRotatedPoint(pt, cos, sin, cx);
  63854. }
  63855. return !mxUtils.contains(pState, pt.x, pt.y);
  63856. }
  63857. }
  63858. return false;
  63859. };
  63860. /**
  63861. * Function: moveCells
  63862. *
  63863. * Moves the given cells by the specified amount.
  63864. */
  63865. mxGraphHandler.prototype.moveCells = function(cells, dx, dy, clone, target, evt)
  63866. {
  63867. if (clone)
  63868. {
  63869. cells = this.graph.getCloneableCells(cells);
  63870. }
  63871. // Removes cells from parent
  63872. var parent = this.graph.getModel().getParent(this.cell);
  63873. if (target == null && this.isRemoveCellsFromParent() &&
  63874. this.shouldRemoveCellsFromParent(parent, cells, evt))
  63875. {
  63876. target = this.graph.getDefaultParent();
  63877. }
  63878. // Cloning into locked cells is not allowed
  63879. clone = clone && !this.graph.isCellLocked(target || this.graph.getDefaultParent());
  63880. this.graph.getModel().beginUpdate();
  63881. try
  63882. {
  63883. var parents = [];
  63884. // Removes parent if all child cells are removed
  63885. if (!clone && target != null && this.removeEmptyParents)
  63886. {
  63887. // Collects all non-selected parents
  63888. var dict = new mxDictionary();
  63889. for (var i = 0; i < cells.length; i++)
  63890. {
  63891. dict.put(cells[i], true);
  63892. }
  63893. // LATER: Recurse up the cell hierarchy
  63894. for (var i = 0; i < cells.length; i++)
  63895. {
  63896. var par = this.graph.model.getParent(cells[i]);
  63897. if (par != null && !dict.get(par))
  63898. {
  63899. dict.put(par, true);
  63900. parents.push(par);
  63901. }
  63902. }
  63903. }
  63904. // Passes all selected cells in order to correctly clone or move into
  63905. // the target cell. The method checks for each cell if its movable.
  63906. cells = this.graph.moveCells(cells, dx, dy, clone, target, evt);
  63907. // Removes parent if all child cells are removed
  63908. var temp = [];
  63909. for (var i = 0; i < parents.length; i++)
  63910. {
  63911. if (this.shouldRemoveParent(parents[i]))
  63912. {
  63913. temp.push(parents[i]);
  63914. }
  63915. }
  63916. this.graph.removeCells(temp, false);
  63917. }
  63918. finally
  63919. {
  63920. this.graph.getModel().endUpdate();
  63921. }
  63922. // Selects the new cells if cells have been cloned
  63923. if (clone)
  63924. {
  63925. this.graph.setSelectionCells(cells);
  63926. }
  63927. if (this.isSelectEnabled() && this.scrollOnMove)
  63928. {
  63929. this.graph.scrollCellToVisible(cells[0]);
  63930. }
  63931. };
  63932. /**
  63933. * Function: shouldRemoveParent
  63934. *
  63935. * Returns true if the given parent should be removed after removal of child cells.
  63936. */
  63937. mxGraphHandler.prototype.shouldRemoveParent = function(parent)
  63938. {
  63939. var state = this.graph.view.getState(parent);
  63940. return state != null && (this.graph.model.isEdge(state.cell) || this.graph.model.isVertex(state.cell)) &&
  63941. this.graph.isCellDeletable(state.cell) && this.graph.model.getChildCount(state.cell) == 0 &&
  63942. this.graph.isTransparentState(state);
  63943. };
  63944. /**
  63945. * Function: destroyShapes
  63946. *
  63947. * Destroy the preview and highlight shapes.
  63948. */
  63949. mxGraphHandler.prototype.destroyShapes = function()
  63950. {
  63951. // Destroys the preview dashed rectangle
  63952. if (this.shape != null)
  63953. {
  63954. this.shape.destroy();
  63955. this.shape = null;
  63956. }
  63957. if (this.guide != null)
  63958. {
  63959. this.guide.destroy();
  63960. this.guide = null;
  63961. }
  63962. // Destroys the drop target highlight
  63963. if (this.highlight != null)
  63964. {
  63965. this.highlight.destroy();
  63966. this.highlight = null;
  63967. }
  63968. };
  63969. /**
  63970. * Function: destroy
  63971. *
  63972. * Destroys the handler and all its resources and DOM nodes.
  63973. */
  63974. mxGraphHandler.prototype.destroy = function()
  63975. {
  63976. this.graph.removeMouseListener(this);
  63977. this.graph.removeListener(this.panHandler);
  63978. if (this.escapeHandler != null)
  63979. {
  63980. this.graph.removeListener(this.escapeHandler);
  63981. this.escapeHandler = null;
  63982. }
  63983. if (this.refreshHandler != null)
  63984. {
  63985. this.graph.getModel().removeListener(this.refreshHandler);
  63986. this.refreshHandler = null;
  63987. }
  63988. mxEvent.removeListener(document, 'keydown', this.keyHandler);
  63989. mxEvent.removeListener(document, 'keyup', this.keyHandler);
  63990. this.destroyShapes();
  63991. this.removeHint();
  63992. };
  63993. /**
  63994. * Copyright (c) 2006-2015, JGraph Ltd
  63995. * Copyright (c) 2006-2015, Gaudenz Alder
  63996. */
  63997. /**
  63998. * Class: mxPanningHandler
  63999. *
  64000. * Event handler that pans and creates popupmenus. To use the left
  64001. * mousebutton for panning without interfering with cell moving and
  64002. * resizing, use <isUseLeftButton> and <isIgnoreCell>. For grid size
  64003. * steps while panning, use <useGrid>. This handler is built-into
  64004. * <mxGraph.panningHandler> and enabled using <mxGraph.setPanning>.
  64005. *
  64006. * Constructor: mxPanningHandler
  64007. *
  64008. * Constructs an event handler that creates a <mxPopupMenu>
  64009. * and pans the graph.
  64010. *
  64011. * Event: mxEvent.PAN_START
  64012. *
  64013. * Fires when the panning handler changes its <active> state to true. The
  64014. * <code>event</code> property contains the corresponding <mxMouseEvent>.
  64015. *
  64016. * Event: mxEvent.PAN
  64017. *
  64018. * Fires while handle is processing events. The <code>event</code> property contains
  64019. * the corresponding <mxMouseEvent>.
  64020. *
  64021. * Event: mxEvent.PAN_END
  64022. *
  64023. * Fires when the panning handler changes its <active> state to false. The
  64024. * <code>event</code> property contains the corresponding <mxMouseEvent>.
  64025. */
  64026. function mxPanningHandler(graph)
  64027. {
  64028. if (graph != null)
  64029. {
  64030. this.graph = graph;
  64031. this.graph.addMouseListener(this);
  64032. // Handles force panning event
  64033. this.forcePanningHandler = mxUtils.bind(this, function(sender, evt)
  64034. {
  64035. var evtName = evt.getProperty('eventName');
  64036. var me = evt.getProperty('event');
  64037. if (evtName == mxEvent.MOUSE_DOWN && this.isForcePanningEvent(me))
  64038. {
  64039. this.start(me);
  64040. this.active = true;
  64041. this.fireEvent(new mxEventObject(mxEvent.PAN_START, 'event', me));
  64042. me.consume();
  64043. }
  64044. });
  64045. this.graph.addListener(mxEvent.FIRE_MOUSE_EVENT, this.forcePanningHandler);
  64046. // Handles pinch gestures
  64047. this.gestureHandler = mxUtils.bind(this, function(sender, eo)
  64048. {
  64049. if (this.isPinchEnabled())
  64050. {
  64051. var evt = eo.getProperty('event');
  64052. if (!mxEvent.isConsumed(evt) && evt.type == 'gesturestart')
  64053. {
  64054. this.initialScale = this.graph.view.scale;
  64055. // Forces start of panning when pinch gesture starts
  64056. if (!this.active && this.mouseDownEvent != null)
  64057. {
  64058. this.start(this.mouseDownEvent);
  64059. this.mouseDownEvent = null;
  64060. }
  64061. }
  64062. else if (evt.type == 'gestureend' && this.initialScale != null)
  64063. {
  64064. this.initialScale = null;
  64065. }
  64066. if (this.initialScale != null)
  64067. {
  64068. this.zoomGraph(evt);
  64069. }
  64070. }
  64071. });
  64072. this.graph.addListener(mxEvent.GESTURE, this.gestureHandler);
  64073. this.mouseUpListener = mxUtils.bind(this, function()
  64074. {
  64075. if (this.active)
  64076. {
  64077. this.reset();
  64078. }
  64079. });
  64080. // Stops scrolling on every mouseup anywhere in the document
  64081. mxEvent.addListener(document, 'mouseup', this.mouseUpListener);
  64082. }
  64083. };
  64084. /**
  64085. * Extends mxEventSource.
  64086. */
  64087. mxPanningHandler.prototype = new mxEventSource();
  64088. mxPanningHandler.prototype.constructor = mxPanningHandler;
  64089. /**
  64090. * Variable: graph
  64091. *
  64092. * Reference to the enclosing <mxGraph>.
  64093. */
  64094. mxPanningHandler.prototype.graph = null;
  64095. /**
  64096. * Variable: useLeftButtonForPanning
  64097. *
  64098. * Specifies if panning should be active for the left mouse button.
  64099. * Setting this to true may conflict with <mxRubberband>. Default is false.
  64100. */
  64101. mxPanningHandler.prototype.useLeftButtonForPanning = false;
  64102. /**
  64103. * Variable: usePopupTrigger
  64104. *
  64105. * Specifies if <mxEvent.isPopupTrigger> should also be used for panning.
  64106. */
  64107. mxPanningHandler.prototype.usePopupTrigger = true;
  64108. /**
  64109. * Variable: ignoreCell
  64110. *
  64111. * Specifies if panning should be active even if there is a cell under the
  64112. * mousepointer. Default is false.
  64113. */
  64114. mxPanningHandler.prototype.ignoreCell = false;
  64115. /**
  64116. * Variable: previewEnabled
  64117. *
  64118. * Specifies if the panning should be previewed. Default is true.
  64119. */
  64120. mxPanningHandler.prototype.previewEnabled = true;
  64121. /**
  64122. * Variable: useGrid
  64123. *
  64124. * Specifies if the panning steps should be aligned to the grid size.
  64125. * Default is false.
  64126. */
  64127. mxPanningHandler.prototype.useGrid = false;
  64128. /**
  64129. * Variable: panningEnabled
  64130. *
  64131. * Specifies if panning should be enabled. Default is true.
  64132. */
  64133. mxPanningHandler.prototype.panningEnabled = true;
  64134. /**
  64135. * Variable: pinchEnabled
  64136. *
  64137. * Specifies if pinch gestures should be handled as zoom. Default is true.
  64138. */
  64139. mxPanningHandler.prototype.pinchEnabled = true;
  64140. /**
  64141. * Variable: maxScale
  64142. *
  64143. * Specifies the maximum scale. Default is 8.
  64144. */
  64145. mxPanningHandler.prototype.maxScale = 8;
  64146. /**
  64147. * Variable: minScale
  64148. *
  64149. * Specifies the minimum scale. Default is 0.01.
  64150. */
  64151. mxPanningHandler.prototype.minScale = 0.01;
  64152. /**
  64153. * Variable: dx
  64154. *
  64155. * Holds the current horizontal offset.
  64156. */
  64157. mxPanningHandler.prototype.dx = null;
  64158. /**
  64159. * Variable: dy
  64160. *
  64161. * Holds the current vertical offset.
  64162. */
  64163. mxPanningHandler.prototype.dy = null;
  64164. /**
  64165. * Variable: startX
  64166. *
  64167. * Holds the x-coordinate of the start point.
  64168. */
  64169. mxPanningHandler.prototype.startX = 0;
  64170. /**
  64171. * Variable: startY
  64172. *
  64173. * Holds the y-coordinate of the start point.
  64174. */
  64175. mxPanningHandler.prototype.startY = 0;
  64176. /**
  64177. * Function: isActive
  64178. *
  64179. * Returns true if the handler is currently active.
  64180. */
  64181. mxPanningHandler.prototype.isActive = function()
  64182. {
  64183. return this.active || this.initialScale != null;
  64184. };
  64185. /**
  64186. * Function: isPanningEnabled
  64187. *
  64188. * Returns <panningEnabled>.
  64189. */
  64190. mxPanningHandler.prototype.isPanningEnabled = function()
  64191. {
  64192. return this.panningEnabled;
  64193. };
  64194. /**
  64195. * Function: setPanningEnabled
  64196. *
  64197. * Sets <panningEnabled>.
  64198. */
  64199. mxPanningHandler.prototype.setPanningEnabled = function(value)
  64200. {
  64201. this.panningEnabled = value;
  64202. };
  64203. /**
  64204. * Function: isPinchEnabled
  64205. *
  64206. * Returns <pinchEnabled>.
  64207. */
  64208. mxPanningHandler.prototype.isPinchEnabled = function()
  64209. {
  64210. return this.pinchEnabled;
  64211. };
  64212. /**
  64213. * Function: setPinchEnabled
  64214. *
  64215. * Sets <pinchEnabled>.
  64216. */
  64217. mxPanningHandler.prototype.setPinchEnabled = function(value)
  64218. {
  64219. this.pinchEnabled = value;
  64220. };
  64221. /**
  64222. * Function: isPanningTrigger
  64223. *
  64224. * Returns true if the given event is a panning trigger for the optional
  64225. * given cell. This returns true if control-shift is pressed or if
  64226. * <usePopupTrigger> is true and the event is a popup trigger.
  64227. */
  64228. mxPanningHandler.prototype.isPanningTrigger = function(me)
  64229. {
  64230. var evt = me.getEvent();
  64231. return (this.useLeftButtonForPanning && me.getState() == null &&
  64232. mxEvent.isLeftMouseButton(evt)) || (mxEvent.isControlDown(evt) &&
  64233. mxEvent.isShiftDown(evt)) || (this.usePopupTrigger && mxEvent.isPopupTrigger(evt));
  64234. };
  64235. /**
  64236. * Function: isForcePanningEvent
  64237. *
  64238. * Returns true if the given <mxMouseEvent> should start panning. This
  64239. * implementation always returns true if <ignoreCell> is true or for
  64240. * multi touch events.
  64241. */
  64242. mxPanningHandler.prototype.isForcePanningEvent = function(me)
  64243. {
  64244. return this.ignoreCell || mxEvent.isMultiTouchEvent(me.getEvent());
  64245. };
  64246. /**
  64247. * Function: mouseDown
  64248. *
  64249. * Handles the event by initiating the panning. By consuming the event all
  64250. * subsequent events of the gesture are redirected to this handler.
  64251. */
  64252. mxPanningHandler.prototype.mouseDown = function(sender, me)
  64253. {
  64254. this.mouseDownEvent = me;
  64255. if (!me.isConsumed() && this.isPanningEnabled() && !this.active && this.isPanningTrigger(me))
  64256. {
  64257. this.start(me);
  64258. this.consumePanningTrigger(me);
  64259. }
  64260. };
  64261. /**
  64262. * Function: start
  64263. *
  64264. * Starts panning at the given event.
  64265. */
  64266. mxPanningHandler.prototype.start = function(me)
  64267. {
  64268. this.dx0 = -this.graph.container.scrollLeft;
  64269. this.dy0 = -this.graph.container.scrollTop;
  64270. // Stores the location of the trigger event
  64271. this.startX = me.getX();
  64272. this.startY = me.getY();
  64273. this.dx = null;
  64274. this.dy = null;
  64275. this.panningTrigger = true;
  64276. };
  64277. /**
  64278. * Function: consumePanningTrigger
  64279. *
  64280. * Consumes the given <mxMouseEvent> if it was a panning trigger in
  64281. * <mouseDown>. The default is to invoke <mxMouseEvent.consume>. Note that this
  64282. * will block any further event processing. If you haven't disabled built-in
  64283. * context menus and require immediate selection of the cell on mouseDown in
  64284. * Safari and/or on the Mac, then use the following code:
  64285. *
  64286. * (code)
  64287. * mxPanningHandler.prototype.consumePanningTrigger = function(me)
  64288. * {
  64289. * if (me.evt.preventDefault)
  64290. * {
  64291. * me.evt.preventDefault();
  64292. * }
  64293. *
  64294. * // Stops event processing in IE
  64295. * me.evt.returnValue = false;
  64296. *
  64297. * // Sets local consumed state
  64298. * if (!mxClient.IS_SF && !mxClient.IS_MAC)
  64299. * {
  64300. * me.consumed = true;
  64301. * }
  64302. * };
  64303. * (end)
  64304. */
  64305. mxPanningHandler.prototype.consumePanningTrigger = function(me)
  64306. {
  64307. me.consume();
  64308. };
  64309. /**
  64310. * Function: mouseMove
  64311. *
  64312. * Handles the event by updating the panning on the graph.
  64313. */
  64314. mxPanningHandler.prototype.mouseMove = function(sender, me)
  64315. {
  64316. this.dx = me.getX() - this.startX;
  64317. this.dy = me.getY() - this.startY;
  64318. if (this.active)
  64319. {
  64320. if (this.previewEnabled)
  64321. {
  64322. // Applies the grid to the panning steps
  64323. if (this.useGrid)
  64324. {
  64325. this.dx = this.graph.snap(this.dx);
  64326. this.dy = this.graph.snap(this.dy);
  64327. }
  64328. this.graph.panGraph(this.dx + this.dx0, this.dy + this.dy0);
  64329. }
  64330. this.fireEvent(new mxEventObject(mxEvent.PAN, 'event', me));
  64331. }
  64332. else if (this.panningTrigger)
  64333. {
  64334. var tmp = this.active;
  64335. // Panning is activated only if the mouse is moved
  64336. // beyond the graph tolerance
  64337. this.active = Math.abs(this.dx) > this.graph.tolerance || Math.abs(this.dy) > this.graph.tolerance;
  64338. if (!tmp && this.active)
  64339. {
  64340. this.fireEvent(new mxEventObject(mxEvent.PAN_START, 'event', me));
  64341. }
  64342. }
  64343. if (this.active || this.panningTrigger)
  64344. {
  64345. me.consume();
  64346. }
  64347. };
  64348. /**
  64349. * Function: mouseUp
  64350. *
  64351. * Handles the event by setting the translation on the view or showing the
  64352. * popupmenu.
  64353. */
  64354. mxPanningHandler.prototype.mouseUp = function(sender, me)
  64355. {
  64356. if (this.active)
  64357. {
  64358. if (this.dx != null && this.dy != null)
  64359. {
  64360. // Ignores if scrollbars have been used for panning
  64361. if (!this.graph.useScrollbarsForPanning || !mxUtils.hasScrollbars(this.graph.container))
  64362. {
  64363. var scale = this.graph.getView().scale;
  64364. var t = this.graph.getView().translate;
  64365. this.graph.panGraph(0, 0);
  64366. this.panGraph(t.x + this.dx / scale, t.y + this.dy / scale);
  64367. }
  64368. me.consume();
  64369. }
  64370. this.fireEvent(new mxEventObject(mxEvent.PAN_END, 'event', me));
  64371. }
  64372. this.reset();
  64373. };
  64374. /**
  64375. * Function: zoomGraph
  64376. *
  64377. * Zooms the graph to the given value and consumed the event if needed.
  64378. */
  64379. mxPanningHandler.prototype.zoomGraph = function(evt)
  64380. {
  64381. var value = Math.round(this.initialScale * evt.scale * 100) / 100;
  64382. if (this.minScale != null)
  64383. {
  64384. value = Math.max(this.minScale, value);
  64385. }
  64386. if (this.maxScale != null)
  64387. {
  64388. value = Math.min(this.maxScale, value);
  64389. }
  64390. if (this.graph.view.scale != value)
  64391. {
  64392. this.graph.zoomTo(value);
  64393. mxEvent.consume(evt);
  64394. }
  64395. };
  64396. /**
  64397. * Function: mouseUp
  64398. *
  64399. * Handles the event by setting the translation on the view or showing the
  64400. * popupmenu.
  64401. */
  64402. mxPanningHandler.prototype.reset = function()
  64403. {
  64404. this.panningTrigger = false;
  64405. this.mouseDownEvent = null;
  64406. this.active = false;
  64407. this.dx = null;
  64408. this.dy = null;
  64409. };
  64410. /**
  64411. * Function: panGraph
  64412. *
  64413. * Pans <graph> by the given amount.
  64414. */
  64415. mxPanningHandler.prototype.panGraph = function(dx, dy)
  64416. {
  64417. this.graph.getView().setTranslate(dx, dy);
  64418. };
  64419. /**
  64420. * Function: destroy
  64421. *
  64422. * Destroys the handler and all its resources and DOM nodes.
  64423. */
  64424. mxPanningHandler.prototype.destroy = function()
  64425. {
  64426. this.graph.removeMouseListener(this);
  64427. this.graph.removeListener(this.forcePanningHandler);
  64428. this.graph.removeListener(this.gestureHandler);
  64429. mxEvent.removeListener(document, 'mouseup', this.mouseUpListener);
  64430. };
  64431. /**
  64432. * Copyright (c) 2006-2015, JGraph Ltd
  64433. * Copyright (c) 2006-2015, Gaudenz Alder
  64434. */
  64435. /**
  64436. * Class: mxPopupMenuHandler
  64437. *
  64438. * Event handler that creates popupmenus.
  64439. *
  64440. * Constructor: mxPopupMenuHandler
  64441. *
  64442. * Constructs an event handler that creates a <mxPopupMenu>.
  64443. */
  64444. function mxPopupMenuHandler(graph, factoryMethod)
  64445. {
  64446. if (graph != null)
  64447. {
  64448. this.graph = graph;
  64449. this.factoryMethod = factoryMethod;
  64450. this.graph.addMouseListener(this);
  64451. // Does not show menu if any touch gestures take place after the trigger
  64452. this.gestureHandler = mxUtils.bind(this, function(sender, eo)
  64453. {
  64454. this.inTolerance = false;
  64455. });
  64456. this.graph.addListener(mxEvent.GESTURE, this.gestureHandler);
  64457. this.init();
  64458. }
  64459. };
  64460. /**
  64461. * Extends mxPopupMenu.
  64462. */
  64463. mxPopupMenuHandler.prototype = new mxPopupMenu();
  64464. mxPopupMenuHandler.prototype.constructor = mxPopupMenuHandler;
  64465. /**
  64466. * Variable: graph
  64467. *
  64468. * Reference to the enclosing <mxGraph>.
  64469. */
  64470. mxPopupMenuHandler.prototype.graph = null;
  64471. /**
  64472. * Variable: selectOnPopup
  64473. *
  64474. * Specifies if cells should be selected if a popupmenu is displayed for
  64475. * them. Default is true.
  64476. */
  64477. mxPopupMenuHandler.prototype.selectOnPopup = true;
  64478. /**
  64479. * Variable: clearSelectionOnBackground
  64480. *
  64481. * Specifies if cells should be deselected if a popupmenu is displayed for
  64482. * the diagram background. Default is true.
  64483. */
  64484. mxPopupMenuHandler.prototype.clearSelectionOnBackground = true;
  64485. /**
  64486. * Variable: triggerX
  64487. *
  64488. * X-coordinate of the mouse down event.
  64489. */
  64490. mxPopupMenuHandler.prototype.triggerX = null;
  64491. /**
  64492. * Variable: triggerY
  64493. *
  64494. * Y-coordinate of the mouse down event.
  64495. */
  64496. mxPopupMenuHandler.prototype.triggerY = null;
  64497. /**
  64498. * Variable: screenX
  64499. *
  64500. * Screen X-coordinate of the mouse down event.
  64501. */
  64502. mxPopupMenuHandler.prototype.screenX = null;
  64503. /**
  64504. * Variable: screenY
  64505. *
  64506. * Screen Y-coordinate of the mouse down event.
  64507. */
  64508. mxPopupMenuHandler.prototype.screenY = null;
  64509. /**
  64510. * Function: init
  64511. *
  64512. * Initializes the shapes required for this vertex handler.
  64513. */
  64514. mxPopupMenuHandler.prototype.init = function()
  64515. {
  64516. // Supercall
  64517. mxPopupMenu.prototype.init.apply(this);
  64518. // Hides the tooltip if the mouse is over
  64519. // the context menu
  64520. mxEvent.addGestureListeners(this.div, mxUtils.bind(this, function(evt)
  64521. {
  64522. this.graph.tooltipHandler.hide();
  64523. }));
  64524. };
  64525. /**
  64526. * Function: isSelectOnPopup
  64527. *
  64528. * Hook for returning if a cell should be selected for a given <mxMouseEvent>.
  64529. * This implementation returns <selectOnPopup>.
  64530. */
  64531. mxPopupMenuHandler.prototype.isSelectOnPopup = function(me)
  64532. {
  64533. return this.selectOnPopup;
  64534. };
  64535. /**
  64536. * Function: mouseDown
  64537. *
  64538. * Handles the event by initiating the panning. By consuming the event all
  64539. * subsequent events of the gesture are redirected to this handler.
  64540. */
  64541. mxPopupMenuHandler.prototype.mouseDown = function(sender, me)
  64542. {
  64543. if (this.isEnabled() && !mxEvent.isMultiTouchEvent(me.getEvent()))
  64544. {
  64545. // Hides the popupmenu if is is being displayed
  64546. this.hideMenu();
  64547. this.triggerX = me.getGraphX();
  64548. this.triggerY = me.getGraphY();
  64549. this.screenX = mxEvent.getMainEvent(me.getEvent()).screenX;
  64550. this.screenY = mxEvent.getMainEvent(me.getEvent()).screenY;
  64551. this.popupTrigger = this.isPopupTrigger(me);
  64552. this.inTolerance = true;
  64553. }
  64554. };
  64555. /**
  64556. * Function: mouseMove
  64557. *
  64558. * Handles the event by updating the panning on the graph.
  64559. */
  64560. mxPopupMenuHandler.prototype.mouseMove = function(sender, me)
  64561. {
  64562. // Popup trigger may change on mouseUp so ignore it
  64563. if (this.inTolerance && this.screenX != null && this.screenY != null)
  64564. {
  64565. if (Math.abs(mxEvent.getMainEvent(me.getEvent()).screenX - this.screenX) > this.graph.tolerance ||
  64566. Math.abs(mxEvent.getMainEvent(me.getEvent()).screenY - this.screenY) > this.graph.tolerance)
  64567. {
  64568. this.inTolerance = false;
  64569. }
  64570. }
  64571. };
  64572. /**
  64573. * Function: mouseUp
  64574. *
  64575. * Handles the event by setting the translation on the view or showing the
  64576. * popupmenu.
  64577. */
  64578. mxPopupMenuHandler.prototype.mouseUp = function(sender, me)
  64579. {
  64580. if (this.popupTrigger && this.inTolerance && this.triggerX != null && this.triggerY != null)
  64581. {
  64582. var cell = this.getCellForPopupEvent(me);
  64583. // Selects the cell for which the context menu is being displayed
  64584. if (this.graph.isEnabled() && this.isSelectOnPopup(me) &&
  64585. cell != null && !this.graph.isCellSelected(cell))
  64586. {
  64587. this.graph.setSelectionCell(cell);
  64588. }
  64589. else if (this.clearSelectionOnBackground && cell == null)
  64590. {
  64591. this.graph.clearSelection();
  64592. }
  64593. // Hides the tooltip if there is one
  64594. this.graph.tooltipHandler.hide();
  64595. // Menu is shifted by 1 pixel so that the mouse up event
  64596. // is routed via the underlying shape instead of the DIV
  64597. var origin = mxUtils.getScrollOrigin();
  64598. this.popup(me.getX() + origin.x + 1, me.getY() + origin.y + 1, cell, me.getEvent());
  64599. me.consume();
  64600. }
  64601. this.popupTrigger = false;
  64602. this.inTolerance = false;
  64603. };
  64604. /**
  64605. * Function: getCellForPopupEvent
  64606. *
  64607. * Hook to return the cell for the mouse up popup trigger handling.
  64608. */
  64609. mxPopupMenuHandler.prototype.getCellForPopupEvent = function(me)
  64610. {
  64611. return me.getCell();
  64612. };
  64613. /**
  64614. * Function: destroy
  64615. *
  64616. * Destroys the handler and all its resources and DOM nodes.
  64617. */
  64618. mxPopupMenuHandler.prototype.destroy = function()
  64619. {
  64620. this.graph.removeMouseListener(this);
  64621. this.graph.removeListener(this.gestureHandler);
  64622. // Supercall
  64623. mxPopupMenu.prototype.destroy.apply(this);
  64624. };
  64625. /**
  64626. * Copyright (c) 2006-2015, JGraph Ltd
  64627. * Copyright (c) 2006-2015, Gaudenz Alder
  64628. */
  64629. /**
  64630. * Class: mxCellMarker
  64631. *
  64632. * A helper class to process mouse locations and highlight cells.
  64633. *
  64634. * Helper class to highlight cells. To add a cell marker to an existing graph
  64635. * for highlighting all cells, the following code is used:
  64636. *
  64637. * (code)
  64638. * var marker = new mxCellMarker(graph);
  64639. * graph.addMouseListener({
  64640. * mouseDown: function() {},
  64641. * mouseMove: function(sender, me)
  64642. * {
  64643. * marker.process(me);
  64644. * },
  64645. * mouseUp: function() {}
  64646. * });
  64647. * (end)
  64648. *
  64649. * Event: mxEvent.MARK
  64650. *
  64651. * Fires after a cell has been marked or unmarked. The <code>state</code>
  64652. * property contains the marked <mxCellState> or null if no state is marked.
  64653. *
  64654. * Constructor: mxCellMarker
  64655. *
  64656. * Constructs a new cell marker.
  64657. *
  64658. * Parameters:
  64659. *
  64660. * graph - Reference to the enclosing <mxGraph>.
  64661. * validColor - Optional marker color for valid states. Default is
  64662. * <mxConstants.DEFAULT_VALID_COLOR>.
  64663. * invalidColor - Optional marker color for invalid states. Default is
  64664. * <mxConstants.DEFAULT_INVALID_COLOR>.
  64665. * hotspot - Portion of the width and hight where a state intersects a
  64666. * given coordinate pair. A value of 0 means always highlight. Default is
  64667. * <mxConstants.DEFAULT_HOTSPOT>.
  64668. */
  64669. function mxCellMarker(graph, validColor, invalidColor, hotspot)
  64670. {
  64671. mxEventSource.call(this);
  64672. if (graph != null)
  64673. {
  64674. this.graph = graph;
  64675. this.validColor = (validColor != null) ? validColor : mxConstants.DEFAULT_VALID_COLOR;
  64676. this.invalidColor = (invalidColor != null) ? invalidColor : mxConstants.DEFAULT_INVALID_COLOR;
  64677. this.hotspot = (hotspot != null) ? hotspot : mxConstants.DEFAULT_HOTSPOT;
  64678. this.highlight = new mxCellHighlight(graph);
  64679. }
  64680. };
  64681. /**
  64682. * Extends mxEventSource.
  64683. */
  64684. mxUtils.extend(mxCellMarker, mxEventSource);
  64685. /**
  64686. * Variable: graph
  64687. *
  64688. * Reference to the enclosing <mxGraph>.
  64689. */
  64690. mxCellMarker.prototype.graph = null;
  64691. /**
  64692. * Variable: enabled
  64693. *
  64694. * Specifies if the marker is enabled. Default is true.
  64695. */
  64696. mxCellMarker.prototype.enabled = true;
  64697. /**
  64698. * Variable: hotspot
  64699. *
  64700. * Specifies the portion of the width and height that should trigger
  64701. * a highlight. The area around the center of the cell to be marked is used
  64702. * as the hotspot. Possible values are between 0 and 1. Default is
  64703. * mxConstants.DEFAULT_HOTSPOT.
  64704. */
  64705. mxCellMarker.prototype.hotspot = mxConstants.DEFAULT_HOTSPOT;
  64706. /**
  64707. * Variable: hotspotEnabled
  64708. *
  64709. * Specifies if the hotspot is enabled. Default is false.
  64710. */
  64711. mxCellMarker.prototype.hotspotEnabled = false;
  64712. /**
  64713. * Variable: validColor
  64714. *
  64715. * Holds the valid marker color.
  64716. */
  64717. mxCellMarker.prototype.validColor = null;
  64718. /**
  64719. * Variable: invalidColor
  64720. *
  64721. * Holds the invalid marker color.
  64722. */
  64723. mxCellMarker.prototype.invalidColor = null;
  64724. /**
  64725. * Variable: currentColor
  64726. *
  64727. * Holds the current marker color.
  64728. */
  64729. mxCellMarker.prototype.currentColor = null;
  64730. /**
  64731. * Variable: validState
  64732. *
  64733. * Holds the marked <mxCellState> if it is valid.
  64734. */
  64735. mxCellMarker.prototype.validState = null;
  64736. /**
  64737. * Variable: markedState
  64738. *
  64739. * Holds the marked <mxCellState>.
  64740. */
  64741. mxCellMarker.prototype.markedState = null;
  64742. /**
  64743. * Function: setEnabled
  64744. *
  64745. * Enables or disables event handling. This implementation
  64746. * updates <enabled>.
  64747. *
  64748. * Parameters:
  64749. *
  64750. * enabled - Boolean that specifies the new enabled state.
  64751. */
  64752. mxCellMarker.prototype.setEnabled = function(enabled)
  64753. {
  64754. this.enabled = enabled;
  64755. };
  64756. /**
  64757. * Function: isEnabled
  64758. *
  64759. * Returns true if events are handled. This implementation
  64760. * returns <enabled>.
  64761. */
  64762. mxCellMarker.prototype.isEnabled = function()
  64763. {
  64764. return this.enabled;
  64765. };
  64766. /**
  64767. * Function: setHotspot
  64768. *
  64769. * Sets the <hotspot>.
  64770. */
  64771. mxCellMarker.prototype.setHotspot = function(hotspot)
  64772. {
  64773. this.hotspot = hotspot;
  64774. };
  64775. /**
  64776. * Function: getHotspot
  64777. *
  64778. * Returns the <hotspot>.
  64779. */
  64780. mxCellMarker.prototype.getHotspot = function()
  64781. {
  64782. return this.hotspot;
  64783. };
  64784. /**
  64785. * Function: setHotspotEnabled
  64786. *
  64787. * Specifies whether the hotspot should be used in <intersects>.
  64788. */
  64789. mxCellMarker.prototype.setHotspotEnabled = function(enabled)
  64790. {
  64791. this.hotspotEnabled = enabled;
  64792. };
  64793. /**
  64794. * Function: isHotspotEnabled
  64795. *
  64796. * Returns true if hotspot is used in <intersects>.
  64797. */
  64798. mxCellMarker.prototype.isHotspotEnabled = function()
  64799. {
  64800. return this.hotspotEnabled;
  64801. };
  64802. /**
  64803. * Function: hasValidState
  64804. *
  64805. * Returns true if <validState> is not null.
  64806. */
  64807. mxCellMarker.prototype.hasValidState = function()
  64808. {
  64809. return this.validState != null;
  64810. };
  64811. /**
  64812. * Function: getValidState
  64813. *
  64814. * Returns the <validState>.
  64815. */
  64816. mxCellMarker.prototype.getValidState = function()
  64817. {
  64818. return this.validState;
  64819. };
  64820. /**
  64821. * Function: getMarkedState
  64822. *
  64823. * Returns the <markedState>.
  64824. */
  64825. mxCellMarker.prototype.getMarkedState = function()
  64826. {
  64827. return this.markedState;
  64828. };
  64829. /**
  64830. * Function: reset
  64831. *
  64832. * Resets the state of the cell marker.
  64833. */
  64834. mxCellMarker.prototype.reset = function()
  64835. {
  64836. this.validState = null;
  64837. if (this.markedState != null)
  64838. {
  64839. this.markedState = null;
  64840. this.unmark();
  64841. }
  64842. };
  64843. /**
  64844. * Function: process
  64845. *
  64846. * Processes the given event and cell and marks the state returned by
  64847. * <getState> with the color returned by <getMarkerColor>. If the
  64848. * markerColor is not null, then the state is stored in <markedState>. If
  64849. * <isValidState> returns true, then the state is stored in <validState>
  64850. * regardless of the marker color. The state is returned regardless of the
  64851. * marker color and valid state.
  64852. */
  64853. mxCellMarker.prototype.process = function(me)
  64854. {
  64855. var state = null;
  64856. if (this.isEnabled())
  64857. {
  64858. state = this.getState(me);
  64859. this.setCurrentState(state, me);
  64860. }
  64861. return state;
  64862. };
  64863. /**
  64864. * Function: setCurrentState
  64865. *
  64866. * Sets and marks the current valid state.
  64867. */
  64868. mxCellMarker.prototype.setCurrentState = function(state, me, color)
  64869. {
  64870. var isValid = (state != null) ? this.isValidState(state) : false;
  64871. color = (color != null) ? color : this.getMarkerColor(me.getEvent(), state, isValid);
  64872. if (isValid)
  64873. {
  64874. this.validState = state;
  64875. }
  64876. else
  64877. {
  64878. this.validState = null;
  64879. }
  64880. if (state != this.markedState || color != this.currentColor)
  64881. {
  64882. this.currentColor = color;
  64883. if (state != null && this.currentColor != null)
  64884. {
  64885. this.markedState = state;
  64886. this.mark();
  64887. }
  64888. else if (this.markedState != null)
  64889. {
  64890. this.markedState = null;
  64891. this.unmark();
  64892. }
  64893. }
  64894. };
  64895. /**
  64896. * Function: markCell
  64897. *
  64898. * Marks the given cell using the given color, or <validColor> if no color is specified.
  64899. */
  64900. mxCellMarker.prototype.markCell = function(cell, color)
  64901. {
  64902. var state = this.graph.getView().getState(cell);
  64903. if (state != null)
  64904. {
  64905. this.currentColor = (color != null) ? color : this.validColor;
  64906. this.markedState = state;
  64907. this.mark();
  64908. }
  64909. };
  64910. /**
  64911. * Function: mark
  64912. *
  64913. * Marks the <markedState> and fires a <mark> event.
  64914. */
  64915. mxCellMarker.prototype.mark = function()
  64916. {
  64917. this.highlight.setHighlightColor(this.currentColor);
  64918. this.highlight.highlight(this.markedState);
  64919. this.fireEvent(new mxEventObject(mxEvent.MARK, 'state', this.markedState));
  64920. };
  64921. /**
  64922. * Function: unmark
  64923. *
  64924. * Hides the marker and fires a <mark> event.
  64925. */
  64926. mxCellMarker.prototype.unmark = function()
  64927. {
  64928. this.mark();
  64929. };
  64930. /**
  64931. * Function: isValidState
  64932. *
  64933. * Returns true if the given <mxCellState> is a valid state. If this
  64934. * returns true, then the state is stored in <validState>. The return value
  64935. * of this method is used as the argument for <getMarkerColor>.
  64936. */
  64937. mxCellMarker.prototype.isValidState = function(state)
  64938. {
  64939. return true;
  64940. };
  64941. /**
  64942. * Function: getMarkerColor
  64943. *
  64944. * Returns the valid- or invalidColor depending on the value of isValid.
  64945. * The given <mxCellState> is ignored by this implementation.
  64946. */
  64947. mxCellMarker.prototype.getMarkerColor = function(evt, state, isValid)
  64948. {
  64949. return (isValid) ? this.validColor : this.invalidColor;
  64950. };
  64951. /**
  64952. * Function: getState
  64953. *
  64954. * Uses <getCell>, <getStateToMark> and <intersects> to return the
  64955. * <mxCellState> for the given <mxMouseEvent>.
  64956. */
  64957. mxCellMarker.prototype.getState = function(me)
  64958. {
  64959. var view = this.graph.getView();
  64960. var cell = this.getCell(me);
  64961. var state = this.getStateToMark(view.getState(cell));
  64962. return (state != null && this.intersects(state, me)) ? state : null;
  64963. };
  64964. /**
  64965. * Function: getCell
  64966. *
  64967. * Returns the <mxCell> for the given event and cell. This returns the
  64968. * given cell.
  64969. */
  64970. mxCellMarker.prototype.getCell = function(me)
  64971. {
  64972. return me.getCell();
  64973. };
  64974. /**
  64975. * Function: getStateToMark
  64976. *
  64977. * Returns the <mxCellState> to be marked for the given <mxCellState> under
  64978. * the mouse. This returns the given state.
  64979. */
  64980. mxCellMarker.prototype.getStateToMark = function(state)
  64981. {
  64982. return state;
  64983. };
  64984. /**
  64985. * Function: intersects
  64986. *
  64987. * Returns true if the given coordinate pair intersects the given state.
  64988. * This returns true if the <hotspot> is 0 or the coordinates are inside
  64989. * the hotspot for the given cell state.
  64990. */
  64991. mxCellMarker.prototype.intersects = function(state, me)
  64992. {
  64993. if (this.hotspotEnabled)
  64994. {
  64995. return mxUtils.intersectsHotspot(state, me.getGraphX(), me.getGraphY(),
  64996. this.hotspot, mxConstants.MIN_HOTSPOT_SIZE,
  64997. mxConstants.MAX_HOTSPOT_SIZE);
  64998. }
  64999. return true;
  65000. };
  65001. /**
  65002. * Function: destroy
  65003. *
  65004. * Destroys the handler and all its resources and DOM nodes.
  65005. */
  65006. mxCellMarker.prototype.destroy = function()
  65007. {
  65008. this.graph.getView().removeListener(this.resetHandler);
  65009. this.graph.getModel().removeListener(this.resetHandler);
  65010. this.highlight.destroy();
  65011. };
  65012. /**
  65013. * Copyright (c) 2006-2015, JGraph Ltd
  65014. * Copyright (c) 2006-2015, Gaudenz Alder
  65015. */
  65016. /**
  65017. * Class: mxSelectionCellsHandler
  65018. *
  65019. * An event handler that manages cell handlers and invokes their mouse event
  65020. * processing functions.
  65021. *
  65022. * Group: Events
  65023. *
  65024. * Event: mxEvent.ADD
  65025. *
  65026. * Fires if a cell has been added to the selection. The <code>state</code>
  65027. * property contains the <mxCellState> that has been added.
  65028. *
  65029. * Event: mxEvent.REMOVE
  65030. *
  65031. * Fires if a cell has been remove from the selection. The <code>state</code>
  65032. * property contains the <mxCellState> that has been removed.
  65033. *
  65034. * Parameters:
  65035. *
  65036. * graph - Reference to the enclosing <mxGraph>.
  65037. */
  65038. function mxSelectionCellsHandler(graph)
  65039. {
  65040. mxEventSource.call(this);
  65041. this.graph = graph;
  65042. this.handlers = new mxDictionary();
  65043. this.graph.addMouseListener(this);
  65044. this.refreshHandler = mxUtils.bind(this, function(sender, evt)
  65045. {
  65046. if (this.isEnabled())
  65047. {
  65048. this.refresh();
  65049. }
  65050. });
  65051. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.refreshHandler);
  65052. this.graph.getModel().addListener(mxEvent.CHANGE, this.refreshHandler);
  65053. this.graph.getView().addListener(mxEvent.SCALE, this.refreshHandler);
  65054. this.graph.getView().addListener(mxEvent.TRANSLATE, this.refreshHandler);
  65055. this.graph.getView().addListener(mxEvent.SCALE_AND_TRANSLATE, this.refreshHandler);
  65056. this.graph.getView().addListener(mxEvent.DOWN, this.refreshHandler);
  65057. this.graph.getView().addListener(mxEvent.UP, this.refreshHandler);
  65058. };
  65059. /**
  65060. * Extends mxEventSource.
  65061. */
  65062. mxUtils.extend(mxSelectionCellsHandler, mxEventSource);
  65063. /**
  65064. * Variable: graph
  65065. *
  65066. * Reference to the enclosing <mxGraph>.
  65067. */
  65068. mxSelectionCellsHandler.prototype.graph = null;
  65069. /**
  65070. * Variable: enabled
  65071. *
  65072. * Specifies if events are handled. Default is true.
  65073. */
  65074. mxSelectionCellsHandler.prototype.enabled = true;
  65075. /**
  65076. * Variable: refreshHandler
  65077. *
  65078. * Keeps a reference to an event listener for later removal.
  65079. */
  65080. mxSelectionCellsHandler.prototype.refreshHandler = null;
  65081. /**
  65082. * Variable: maxHandlers
  65083. *
  65084. * Defines the maximum number of handlers to paint individually. Default is 100.
  65085. */
  65086. mxSelectionCellsHandler.prototype.maxHandlers = 100;
  65087. /**
  65088. * Variable: handlers
  65089. *
  65090. * <mxDictionary> that maps from cells to handlers.
  65091. */
  65092. mxSelectionCellsHandler.prototype.handlers = null;
  65093. /**
  65094. * Function: isEnabled
  65095. *
  65096. * Returns <enabled>.
  65097. */
  65098. mxSelectionCellsHandler.prototype.isEnabled = function()
  65099. {
  65100. return this.enabled;
  65101. };
  65102. /**
  65103. * Function: setEnabled
  65104. *
  65105. * Sets <enabled>.
  65106. */
  65107. mxSelectionCellsHandler.prototype.setEnabled = function(value)
  65108. {
  65109. this.enabled = value;
  65110. };
  65111. /**
  65112. * Function: getHandler
  65113. *
  65114. * Returns the handler for the given cell.
  65115. */
  65116. mxSelectionCellsHandler.prototype.getHandler = function(cell)
  65117. {
  65118. return this.handlers.get(cell);
  65119. };
  65120. /**
  65121. * Function: isHandled
  65122. *
  65123. * Returns true if the given cell has a handler.
  65124. */
  65125. mxSelectionCellsHandler.prototype.isHandled = function(cell)
  65126. {
  65127. return this.getHandler(cell) != null;
  65128. };
  65129. /**
  65130. * Function: reset
  65131. *
  65132. * Resets all handlers.
  65133. */
  65134. mxSelectionCellsHandler.prototype.reset = function()
  65135. {
  65136. this.handlers.visit(function(key, handler)
  65137. {
  65138. handler.reset.apply(handler);
  65139. });
  65140. };
  65141. /**
  65142. * Function: getHandledSelectionCells
  65143. *
  65144. * Reloads or updates all handlers.
  65145. */
  65146. mxSelectionCellsHandler.prototype.getHandledSelectionCells = function()
  65147. {
  65148. return this.graph.getSelectionCells();
  65149. };
  65150. /**
  65151. * Function: refresh
  65152. *
  65153. * Reloads or updates all handlers.
  65154. */
  65155. mxSelectionCellsHandler.prototype.refresh = function()
  65156. {
  65157. // Removes all existing handlers
  65158. var oldHandlers = this.handlers;
  65159. this.handlers = new mxDictionary();
  65160. // Creates handles for all selection cells
  65161. var tmp = mxUtils.sortCells(this.getHandledSelectionCells(), false);
  65162. for (var i = 0; i < tmp.length; i++)
  65163. {
  65164. var state = this.graph.view.getState(tmp[i]);
  65165. if (state != null)
  65166. {
  65167. var handler = oldHandlers.remove(tmp[i]);
  65168. if (handler != null)
  65169. {
  65170. if (handler.state != state)
  65171. {
  65172. handler.destroy();
  65173. handler = null;
  65174. }
  65175. else if (!this.isHandlerActive(handler))
  65176. {
  65177. if (handler.refresh != null)
  65178. {
  65179. handler.refresh();
  65180. }
  65181. handler.redraw();
  65182. }
  65183. }
  65184. if (handler == null)
  65185. {
  65186. handler = this.graph.createHandler(state);
  65187. this.fireEvent(new mxEventObject(mxEvent.ADD, 'state', state));
  65188. }
  65189. if (handler != null)
  65190. {
  65191. this.handlers.put(tmp[i], handler);
  65192. }
  65193. }
  65194. }
  65195. // Destroys all unused handlers
  65196. oldHandlers.visit(mxUtils.bind(this, function(key, handler)
  65197. {
  65198. this.fireEvent(new mxEventObject(mxEvent.REMOVE, 'state', handler.state));
  65199. handler.destroy();
  65200. }));
  65201. };
  65202. /**
  65203. * Function: isHandlerActive
  65204. *
  65205. * Returns true if the given handler is active and should not be redrawn.
  65206. */
  65207. mxSelectionCellsHandler.prototype.isHandlerActive = function(handler)
  65208. {
  65209. return handler.index != null;
  65210. };
  65211. /**
  65212. * Function: updateHandler
  65213. *
  65214. * Updates the handler for the given shape if one exists.
  65215. */
  65216. mxSelectionCellsHandler.prototype.updateHandler = function(state)
  65217. {
  65218. var handler = this.handlers.remove(state.cell);
  65219. if (handler != null)
  65220. {
  65221. // Transfers the current state to the new handler
  65222. var index = handler.index;
  65223. var x = handler.startX;
  65224. var y = handler.startY;
  65225. handler.destroy();
  65226. handler = this.graph.createHandler(state);
  65227. if (handler != null)
  65228. {
  65229. this.handlers.put(state.cell, handler);
  65230. if (index != null && x != null && y != null)
  65231. {
  65232. handler.start(x, y, index);
  65233. }
  65234. }
  65235. }
  65236. };
  65237. /**
  65238. * Function: mouseDown
  65239. *
  65240. * Redirects the given event to the handlers.
  65241. */
  65242. mxSelectionCellsHandler.prototype.mouseDown = function(sender, me)
  65243. {
  65244. if (this.graph.isEnabled() && this.isEnabled())
  65245. {
  65246. var args = [sender, me];
  65247. this.handlers.visit(function(key, handler)
  65248. {
  65249. handler.mouseDown.apply(handler, args);
  65250. });
  65251. }
  65252. };
  65253. /**
  65254. * Function: mouseMove
  65255. *
  65256. * Redirects the given event to the handlers.
  65257. */
  65258. mxSelectionCellsHandler.prototype.mouseMove = function(sender, me)
  65259. {
  65260. if (this.graph.isEnabled() && this.isEnabled())
  65261. {
  65262. var args = [sender, me];
  65263. this.handlers.visit(function(key, handler)
  65264. {
  65265. handler.mouseMove.apply(handler, args);
  65266. });
  65267. }
  65268. };
  65269. /**
  65270. * Function: mouseUp
  65271. *
  65272. * Redirects the given event to the handlers.
  65273. */
  65274. mxSelectionCellsHandler.prototype.mouseUp = function(sender, me)
  65275. {
  65276. if (this.graph.isEnabled() && this.isEnabled())
  65277. {
  65278. var args = [sender, me];
  65279. this.handlers.visit(function(key, handler)
  65280. {
  65281. handler.mouseUp.apply(handler, args);
  65282. });
  65283. }
  65284. };
  65285. /**
  65286. * Function: destroy
  65287. *
  65288. * Destroys the handler and all its resources and DOM nodes.
  65289. */
  65290. mxSelectionCellsHandler.prototype.destroy = function()
  65291. {
  65292. this.graph.removeMouseListener(this);
  65293. if (this.refreshHandler != null)
  65294. {
  65295. this.graph.getSelectionModel().removeListener(this.refreshHandler);
  65296. this.graph.getModel().removeListener(this.refreshHandler);
  65297. this.graph.getView().removeListener(this.refreshHandler);
  65298. this.refreshHandler = null;
  65299. }
  65300. };
  65301. /**
  65302. * Copyright (c) 2006-2016, JGraph Ltd
  65303. * Copyright (c) 2006-2016, Gaudenz Alder
  65304. */
  65305. /**
  65306. * Class: mxConnectionHandler
  65307. *
  65308. * Graph event handler that creates new connections. Uses <mxTerminalMarker>
  65309. * for finding and highlighting the source and target vertices and
  65310. * <factoryMethod> to create the edge instance. This handler is built-into
  65311. * <mxGraph.connectionHandler> and enabled using <mxGraph.setConnectable>.
  65312. *
  65313. * Example:
  65314. *
  65315. * (code)
  65316. * new mxConnectionHandler(graph, function(source, target, style)
  65317. * {
  65318. * edge = new mxCell('', new mxGeometry());
  65319. * edge.setEdge(true);
  65320. * edge.setStyle(style);
  65321. * edge.geometry.relative = true;
  65322. * return edge;
  65323. * });
  65324. * (end)
  65325. *
  65326. * Here is an alternative solution that just sets a specific user object for
  65327. * new edges by overriding <insertEdge>.
  65328. *
  65329. * (code)
  65330. * mxConnectionHandlerInsertEdge = mxConnectionHandler.prototype.insertEdge;
  65331. * mxConnectionHandler.prototype.insertEdge = function(parent, id, value, source, target, style)
  65332. * {
  65333. * value = 'Test';
  65334. *
  65335. * return mxConnectionHandlerInsertEdge.apply(this, arguments);
  65336. * };
  65337. * (end)
  65338. *
  65339. * Using images to trigger connections:
  65340. *
  65341. * This handler uses mxTerminalMarker to find the source and target cell for
  65342. * the new connection and creates a new edge using <connect>. The new edge is
  65343. * created using <createEdge> which in turn uses <factoryMethod> or creates a
  65344. * new default edge.
  65345. *
  65346. * The handler uses a "highlight-paradigm" for indicating if a cell is being
  65347. * used as a source or target terminal, as seen in other diagramming products.
  65348. * In order to allow both, moving and connecting cells at the same time,
  65349. * <mxConstants.DEFAULT_HOTSPOT> is used in the handler to determine the hotspot
  65350. * of a cell, that is, the region of the cell which is used to trigger a new
  65351. * connection. The constant is a value between 0 and 1 that specifies the
  65352. * amount of the width and height around the center to be used for the hotspot
  65353. * of a cell and its default value is 0.5. In addition,
  65354. * <mxConstants.MIN_HOTSPOT_SIZE> defines the minimum number of pixels for the
  65355. * width and height of the hotspot.
  65356. *
  65357. * This solution, while standards compliant, may be somewhat confusing because
  65358. * there is no visual indicator for the hotspot and the highlight is seen to
  65359. * switch on and off while the mouse is being moved in and out. Furthermore,
  65360. * this paradigm does not allow to create different connections depending on
  65361. * the highlighted hotspot as there is only one hotspot per cell and it
  65362. * normally does not allow cells to be moved and connected at the same time as
  65363. * there is no clear indication of the connectable area of the cell.
  65364. *
  65365. * To come across these issues, the handle has an additional <createIcons> hook
  65366. * with a default implementation that allows to create one icon to be used to
  65367. * trigger new connections. If this icon is specified, then new connections can
  65368. * only be created if the image is clicked while the cell is being highlighted.
  65369. * The <createIcons> hook may be overridden to create more than one
  65370. * <mxImageShape> for creating new connections, but the default implementation
  65371. * supports one image and is used as follows:
  65372. *
  65373. * In order to display the "connect image" whenever the mouse is over the cell,
  65374. * an DEFAULT_HOTSPOT of 1 should be used:
  65375. *
  65376. * (code)
  65377. * mxConstants.DEFAULT_HOTSPOT = 1;
  65378. * (end)
  65379. *
  65380. * In order to avoid confusion with the highlighting, the highlight color
  65381. * should not be used with a connect image:
  65382. *
  65383. * (code)
  65384. * mxConstants.HIGHLIGHT_COLOR = null;
  65385. * (end)
  65386. *
  65387. * To install the image, the connectImage field of the mxConnectionHandler must
  65388. * be assigned a new <mxImage> instance:
  65389. *
  65390. * (code)
  65391. * mxConnectionHandler.prototype.connectImage = new mxImage('images/green-dot.gif', 14, 14);
  65392. * (end)
  65393. *
  65394. * This will use the green-dot.gif with a width and height of 14 pixels as the
  65395. * image to trigger new connections. In createIcons the icon field of the
  65396. * handler will be set in order to remember the icon that has been clicked for
  65397. * creating the new connection. This field will be available under selectedIcon
  65398. * in the connect method, which may be overridden to take the icon that
  65399. * triggered the new connection into account. This is useful if more than one
  65400. * icon may be used to create a connection.
  65401. *
  65402. * Group: Events
  65403. *
  65404. * Event: mxEvent.START
  65405. *
  65406. * Fires when a new connection is being created by the user. The <code>state</code>
  65407. * property contains the state of the source cell.
  65408. *
  65409. * Event: mxEvent.CONNECT
  65410. *
  65411. * Fires between begin- and endUpdate in <connect>. The <code>cell</code>
  65412. * property contains the inserted edge, the <code>event</code> and <code>target</code>
  65413. * properties contain the respective arguments that were passed to <connect> (where
  65414. * target corresponds to the dropTarget argument). Finally, the <code>terminal</code>
  65415. * property corresponds to the target argument in <connect> or the clone of the source
  65416. * terminal if <createTarget> is enabled.
  65417. *
  65418. * Note that the target is the cell under the mouse where the mouse button was released.
  65419. * Depending on the logic in the handler, this doesn't necessarily have to be the target
  65420. * of the inserted edge. To print the source, target or any optional ports IDs that the
  65421. * edge is connected to, the following code can be used. To get more details about the
  65422. * actual connection point, <mxGraph.getConnectionConstraint> can be used. To resolve
  65423. * the port IDs, use <mxGraphModel.getCell>.
  65424. *
  65425. * (code)
  65426. * graph.connectionHandler.addListener(mxEvent.CONNECT, function(sender, evt)
  65427. * {
  65428. * var edge = evt.getProperty('cell');
  65429. * var source = graph.getModel().getTerminal(edge, true);
  65430. * var target = graph.getModel().getTerminal(edge, false);
  65431. *
  65432. * var style = graph.getCellStyle(edge);
  65433. * var sourcePortId = style[mxConstants.STYLE_SOURCE_PORT];
  65434. * var targetPortId = style[mxConstants.STYLE_TARGET_PORT];
  65435. *
  65436. * mxLog.show();
  65437. * mxLog.debug('connect', edge, source.id, target.id, sourcePortId, targetPortId);
  65438. * });
  65439. * (end)
  65440. *
  65441. * Event: mxEvent.RESET
  65442. *
  65443. * Fires when the <reset> method is invoked.
  65444. *
  65445. * Constructor: mxConnectionHandler
  65446. *
  65447. * Constructs an event handler that connects vertices using the specified
  65448. * factory method to create the new edges. Modify
  65449. * <mxConstants.ACTIVE_REGION> to setup the region on a cell which triggers
  65450. * the creation of a new connection or use connect icons as explained
  65451. * above.
  65452. *
  65453. * Parameters:
  65454. *
  65455. * graph - Reference to the enclosing <mxGraph>.
  65456. * factoryMethod - Optional function to create the edge. The function takes
  65457. * the source and target <mxCell> as the first and second argument and an
  65458. * optional cell style from the preview as the third argument. It returns
  65459. * the <mxCell> that represents the new edge.
  65460. */
  65461. function mxConnectionHandler(graph, factoryMethod)
  65462. {
  65463. mxEventSource.call(this);
  65464. if (graph != null)
  65465. {
  65466. this.graph = graph;
  65467. this.factoryMethod = factoryMethod;
  65468. this.init();
  65469. // Handles escape keystrokes
  65470. this.escapeHandler = mxUtils.bind(this, function(sender, evt)
  65471. {
  65472. this.reset();
  65473. });
  65474. this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
  65475. }
  65476. };
  65477. /**
  65478. * Extends mxEventSource.
  65479. */
  65480. mxUtils.extend(mxConnectionHandler, mxEventSource);
  65481. /**
  65482. * Variable: graph
  65483. *
  65484. * Reference to the enclosing <mxGraph>.
  65485. */
  65486. mxConnectionHandler.prototype.graph = null;
  65487. /**
  65488. * Variable: factoryMethod
  65489. *
  65490. * Function that is used for creating new edges. The function takes the
  65491. * source and target <mxCell> as the first and second argument and returns
  65492. * a new <mxCell> that represents the edge. This is used in <createEdge>.
  65493. */
  65494. mxConnectionHandler.prototype.factoryMethod = true;
  65495. /**
  65496. * Variable: moveIconFront
  65497. *
  65498. * Specifies if icons should be displayed inside the graph container instead
  65499. * of the overlay pane. This is used for HTML labels on vertices which hide
  65500. * the connect icon. This has precendence over <moveIconBack> when set
  65501. * to true. Default is false.
  65502. */
  65503. mxConnectionHandler.prototype.moveIconFront = false;
  65504. /**
  65505. * Variable: moveIconBack
  65506. *
  65507. * Specifies if icons should be moved to the back of the overlay pane. This can
  65508. * be set to true if the icons of the connection handler conflict with other
  65509. * handles, such as the vertex label move handle. Default is false.
  65510. */
  65511. mxConnectionHandler.prototype.moveIconBack = false;
  65512. /**
  65513. * Variable: connectImage
  65514. *
  65515. * <mxImage> that is used to trigger the creation of a new connection. This
  65516. * is used in <createIcons>. Default is null.
  65517. */
  65518. mxConnectionHandler.prototype.connectImage = null;
  65519. /**
  65520. * Variable: targetConnectImage
  65521. *
  65522. * Specifies if the connect icon should be centered on the target state
  65523. * while connections are being previewed. Default is false.
  65524. */
  65525. mxConnectionHandler.prototype.targetConnectImage = false;
  65526. /**
  65527. * Variable: enabled
  65528. *
  65529. * Specifies if events are handled. Default is true.
  65530. */
  65531. mxConnectionHandler.prototype.enabled = true;
  65532. /**
  65533. * Variable: select
  65534. *
  65535. * Specifies if new edges should be selected. Default is true.
  65536. */
  65537. mxConnectionHandler.prototype.select = true;
  65538. /**
  65539. * Variable: createTarget
  65540. *
  65541. * Specifies if <createTargetVertex> should be called if no target was under the
  65542. * mouse for the new connection. Setting this to true means the connection
  65543. * will be drawn as valid if no target is under the mouse, and
  65544. * <createTargetVertex> will be called before the connection is created between
  65545. * the source cell and the newly created vertex in <createTargetVertex>, which
  65546. * can be overridden to create a new target. Default is false.
  65547. */
  65548. mxConnectionHandler.prototype.createTarget = false;
  65549. /**
  65550. * Variable: marker
  65551. *
  65552. * Holds the <mxTerminalMarker> used for finding source and target cells.
  65553. */
  65554. mxConnectionHandler.prototype.marker = null;
  65555. /**
  65556. * Variable: constraintHandler
  65557. *
  65558. * Holds the <mxConstraintHandler> used for drawing and highlighting
  65559. * constraints.
  65560. */
  65561. mxConnectionHandler.prototype.constraintHandler = null;
  65562. /**
  65563. * Variable: error
  65564. *
  65565. * Holds the current validation error while connections are being created.
  65566. */
  65567. mxConnectionHandler.prototype.error = null;
  65568. /**
  65569. * Variable: waypointsEnabled
  65570. *
  65571. * Specifies if single clicks should add waypoints on the new edge. Default is
  65572. * false.
  65573. */
  65574. mxConnectionHandler.prototype.waypointsEnabled = false;
  65575. /**
  65576. * Variable: ignoreMouseDown
  65577. *
  65578. * Specifies if the connection handler should ignore the state of the mouse
  65579. * button when highlighting the source. Default is false, that is, the
  65580. * handler only highlights the source if no button is being pressed.
  65581. */
  65582. mxConnectionHandler.prototype.ignoreMouseDown = false;
  65583. /**
  65584. * Variable: first
  65585. *
  65586. * Holds the <mxPoint> where the mouseDown took place while the handler is
  65587. * active.
  65588. */
  65589. mxConnectionHandler.prototype.first = null;
  65590. /**
  65591. * Variable: connectIconOffset
  65592. *
  65593. * Holds the offset for connect icons during connection preview.
  65594. * Default is mxPoint(0, <mxConstants.TOOLTIP_VERTICAL_OFFSET>).
  65595. * Note that placing the icon under the mouse pointer with an
  65596. * offset of (0,0) will affect hit detection.
  65597. */
  65598. mxConnectionHandler.prototype.connectIconOffset = new mxPoint(0, mxConstants.TOOLTIP_VERTICAL_OFFSET);
  65599. /**
  65600. * Variable: edgeState
  65601. *
  65602. * Optional <mxCellState> that represents the preview edge while the
  65603. * handler is active. This is created in <createEdgeState>.
  65604. */
  65605. mxConnectionHandler.prototype.edgeState = null;
  65606. /**
  65607. * Variable: changeHandler
  65608. *
  65609. * Holds the change event listener for later removal.
  65610. */
  65611. mxConnectionHandler.prototype.changeHandler = null;
  65612. /**
  65613. * Variable: drillHandler
  65614. *
  65615. * Holds the drill event listener for later removal.
  65616. */
  65617. mxConnectionHandler.prototype.drillHandler = null;
  65618. /**
  65619. * Variable: mouseDownCounter
  65620. *
  65621. * Counts the number of mouseDown events since the start. The initial mouse
  65622. * down event counts as 1.
  65623. */
  65624. mxConnectionHandler.prototype.mouseDownCounter = 0;
  65625. /**
  65626. * Variable: movePreviewAway
  65627. *
  65628. * Switch to enable moving the preview away from the mousepointer. This is required in browsers
  65629. * where the preview cannot be made transparent to events and if the built-in hit detection on
  65630. * the HTML elements in the page should be used. Default is the value of <mxClient.IS_VML>.
  65631. */
  65632. mxConnectionHandler.prototype.movePreviewAway = mxClient.IS_VML;
  65633. /**
  65634. * Variable: outlineConnect
  65635. *
  65636. * Specifies if connections to the outline of a highlighted target should be
  65637. * enabled. This will allow to place the connection point along the outline of
  65638. * the highlighted target. Default is false.
  65639. */
  65640. mxConnectionHandler.prototype.outlineConnect = false;
  65641. /**
  65642. * Variable: livePreview
  65643. *
  65644. * Specifies if the actual shape of the edge state should be used for the preview.
  65645. * Default is false. (Ignored if no edge state is created in <createEdgeState>.)
  65646. */
  65647. mxConnectionHandler.prototype.livePreview = false;
  65648. /**
  65649. * Variable: cursor
  65650. *
  65651. * Specifies the cursor to be used while the handler is active. Default is null.
  65652. */
  65653. mxConnectionHandler.prototype.cursor = null;
  65654. /**
  65655. * Variable: insertBeforeSource
  65656. *
  65657. * Specifies if new edges should be inserted before the source vertex in the
  65658. * cell hierarchy. Default is false for backwards compatibility.
  65659. */
  65660. mxConnectionHandler.prototype.insertBeforeSource = false;
  65661. /**
  65662. * Function: isEnabled
  65663. *
  65664. * Returns true if events are handled. This implementation
  65665. * returns <enabled>.
  65666. */
  65667. mxConnectionHandler.prototype.isEnabled = function()
  65668. {
  65669. return this.enabled;
  65670. };
  65671. /**
  65672. * Function: setEnabled
  65673. *
  65674. * Enables or disables event handling. This implementation
  65675. * updates <enabled>.
  65676. *
  65677. * Parameters:
  65678. *
  65679. * enabled - Boolean that specifies the new enabled state.
  65680. */
  65681. mxConnectionHandler.prototype.setEnabled = function(enabled)
  65682. {
  65683. this.enabled = enabled;
  65684. };
  65685. /**
  65686. * Function: isInsertBefore
  65687. *
  65688. * Returns <insertBeforeSource> for non-loops and false for loops.
  65689. *
  65690. * Parameters:
  65691. *
  65692. * edge - <mxCell> that represents the edge to be inserted.
  65693. * source - <mxCell> that represents the source terminal.
  65694. * target - <mxCell> that represents the target terminal.
  65695. * evt - Mousedown event of the connect gesture.
  65696. * dropTarget - <mxCell> that represents the cell under the mouse when it was
  65697. * released.
  65698. */
  65699. mxConnectionHandler.prototype.isInsertBefore = function(edge, source, target, evt, dropTarget)
  65700. {
  65701. return this.insertBeforeSource && source != target;
  65702. };
  65703. /**
  65704. * Function: isCreateTarget
  65705. *
  65706. * Returns <createTarget>.
  65707. *
  65708. * Parameters:
  65709. *
  65710. * evt - Current active native pointer event.
  65711. */
  65712. mxConnectionHandler.prototype.isCreateTarget = function(evt)
  65713. {
  65714. return this.createTarget;
  65715. };
  65716. /**
  65717. * Function: setCreateTarget
  65718. *
  65719. * Sets <createTarget>.
  65720. */
  65721. mxConnectionHandler.prototype.setCreateTarget = function(value)
  65722. {
  65723. this.createTarget = value;
  65724. };
  65725. /**
  65726. * Function: createShape
  65727. *
  65728. * Creates the preview shape for new connections.
  65729. */
  65730. mxConnectionHandler.prototype.createShape = function()
  65731. {
  65732. // Creates the edge preview
  65733. var shape = (this.livePreview && this.edgeState != null) ?
  65734. this.graph.cellRenderer.createShape(this.edgeState) :
  65735. new mxPolyline([], mxConstants.INVALID_COLOR);
  65736. shape.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  65737. mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  65738. shape.scale = this.graph.view.scale;
  65739. shape.pointerEvents = false;
  65740. shape.isDashed = true;
  65741. shape.init(this.graph.getView().getOverlayPane());
  65742. mxEvent.redirectMouseEvents(shape.node, this.graph, null);
  65743. return shape;
  65744. };
  65745. /**
  65746. * Function: init
  65747. *
  65748. * Initializes the shapes required for this connection handler. This should
  65749. * be invoked if <mxGraph.container> is assigned after the connection
  65750. * handler has been created.
  65751. */
  65752. mxConnectionHandler.prototype.init = function()
  65753. {
  65754. this.graph.addMouseListener(this);
  65755. this.marker = this.createMarker();
  65756. this.constraintHandler = new mxConstraintHandler(this.graph);
  65757. // Redraws the icons if the graph changes
  65758. this.changeHandler = mxUtils.bind(this, function(sender)
  65759. {
  65760. if (this.iconState != null)
  65761. {
  65762. this.iconState = this.graph.getView().getState(this.iconState.cell);
  65763. }
  65764. if (this.iconState != null)
  65765. {
  65766. this.redrawIcons(this.icons, this.iconState);
  65767. this.constraintHandler.reset();
  65768. }
  65769. else if (this.previous != null && this.graph.view.getState(this.previous.cell) == null)
  65770. {
  65771. this.reset();
  65772. }
  65773. });
  65774. this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler);
  65775. this.graph.getView().addListener(mxEvent.SCALE, this.changeHandler);
  65776. this.graph.getView().addListener(mxEvent.TRANSLATE, this.changeHandler);
  65777. this.graph.getView().addListener(mxEvent.SCALE_AND_TRANSLATE, this.changeHandler);
  65778. // Removes the icon if we step into/up or start editing
  65779. this.drillHandler = mxUtils.bind(this, function(sender)
  65780. {
  65781. this.reset();
  65782. });
  65783. this.graph.addListener(mxEvent.START_EDITING, this.drillHandler);
  65784. this.graph.getView().addListener(mxEvent.DOWN, this.drillHandler);
  65785. this.graph.getView().addListener(mxEvent.UP, this.drillHandler);
  65786. };
  65787. /**
  65788. * Function: isConnectableCell
  65789. *
  65790. * Returns true if the given cell is connectable. This is a hook to
  65791. * disable floating connections. This implementation returns true.
  65792. */
  65793. mxConnectionHandler.prototype.isConnectableCell = function(cell)
  65794. {
  65795. return true;
  65796. };
  65797. /**
  65798. * Function: createMarker
  65799. *
  65800. * Creates and returns the <mxCellMarker> used in <marker>.
  65801. */
  65802. mxConnectionHandler.prototype.createMarker = function()
  65803. {
  65804. var marker = new mxCellMarker(this.graph);
  65805. marker.hotspotEnabled = true;
  65806. // Overrides to return cell at location only if valid (so that
  65807. // there is no highlight for invalid cells)
  65808. marker.getCell = mxUtils.bind(this, function(me)
  65809. {
  65810. var cell = mxCellMarker.prototype.getCell.apply(marker, arguments);
  65811. this.error = null;
  65812. // Checks for cell at preview point (with grid)
  65813. if (cell == null && this.currentPoint != null)
  65814. {
  65815. cell = this.graph.getCellAt(this.currentPoint.x, this.currentPoint.y);
  65816. }
  65817. // Uses connectable parent vertex if one exists
  65818. if (cell != null && !this.graph.isCellConnectable(cell))
  65819. {
  65820. var parent = this.graph.getModel().getParent(cell);
  65821. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  65822. {
  65823. cell = parent;
  65824. }
  65825. }
  65826. if ((this.graph.isSwimlane(cell) && this.currentPoint != null &&
  65827. this.graph.hitsSwimlaneContent(cell, this.currentPoint.x, this.currentPoint.y)) ||
  65828. !this.isConnectableCell(cell))
  65829. {
  65830. cell = null;
  65831. }
  65832. if (cell != null)
  65833. {
  65834. if (this.isConnecting())
  65835. {
  65836. if (this.previous != null)
  65837. {
  65838. this.error = this.validateConnection(this.previous.cell, cell);
  65839. if (this.error != null && this.error.length == 0)
  65840. {
  65841. cell = null;
  65842. // Enables create target inside groups
  65843. if (this.isCreateTarget(me.getEvent()))
  65844. {
  65845. this.error = null;
  65846. }
  65847. }
  65848. }
  65849. }
  65850. else if (!this.isValidSource(cell, me))
  65851. {
  65852. cell = null;
  65853. }
  65854. }
  65855. else if (this.isConnecting() && !this.isCreateTarget(me.getEvent()) &&
  65856. !this.graph.allowDanglingEdges)
  65857. {
  65858. this.error = '';
  65859. }
  65860. return cell;
  65861. });
  65862. // Sets the highlight color according to validateConnection
  65863. marker.isValidState = mxUtils.bind(this, function(state)
  65864. {
  65865. if (this.isConnecting())
  65866. {
  65867. return this.error == null;
  65868. }
  65869. else
  65870. {
  65871. return mxCellMarker.prototype.isValidState.apply(marker, arguments);
  65872. }
  65873. });
  65874. // Overrides to use marker color only in highlight mode or for
  65875. // target selection
  65876. marker.getMarkerColor = mxUtils.bind(this, function(evt, state, isValid)
  65877. {
  65878. return (this.connectImage == null || this.isConnecting()) ?
  65879. mxCellMarker.prototype.getMarkerColor.apply(marker, arguments) :
  65880. null;
  65881. });
  65882. // Overrides to use hotspot only for source selection otherwise
  65883. // intersects always returns true when over a cell
  65884. marker.intersects = mxUtils.bind(this, function(state, evt)
  65885. {
  65886. if (this.connectImage != null || this.isConnecting())
  65887. {
  65888. return true;
  65889. }
  65890. return mxCellMarker.prototype.intersects.apply(marker, arguments);
  65891. });
  65892. return marker;
  65893. };
  65894. /**
  65895. * Function: start
  65896. *
  65897. * Starts a new connection for the given state and coordinates.
  65898. */
  65899. mxConnectionHandler.prototype.start = function(state, x, y, edgeState)
  65900. {
  65901. this.previous = state;
  65902. this.first = new mxPoint(x, y);
  65903. this.edgeState = (edgeState != null) ? edgeState : this.createEdgeState(null);
  65904. // Marks the source state
  65905. this.marker.currentColor = this.marker.validColor;
  65906. this.marker.markedState = state;
  65907. this.marker.mark();
  65908. this.fireEvent(new mxEventObject(mxEvent.START, 'state', this.previous));
  65909. };
  65910. /**
  65911. * Function: isConnecting
  65912. *
  65913. * Returns true if the source terminal has been clicked and a new
  65914. * connection is currently being previewed.
  65915. */
  65916. mxConnectionHandler.prototype.isConnecting = function()
  65917. {
  65918. return this.first != null && this.shape != null;
  65919. };
  65920. /**
  65921. * Function: isValidSource
  65922. *
  65923. * Returns <mxGraph.isValidSource> for the given source terminal.
  65924. *
  65925. * Parameters:
  65926. *
  65927. * cell - <mxCell> that represents the source terminal.
  65928. * me - <mxMouseEvent> that is associated with this call.
  65929. */
  65930. mxConnectionHandler.prototype.isValidSource = function(cell, me)
  65931. {
  65932. return this.graph.isValidSource(cell);
  65933. };
  65934. /**
  65935. * Function: isValidTarget
  65936. *
  65937. * Returns true. The call to <mxGraph.isValidTarget> is implicit by calling
  65938. * <mxGraph.getEdgeValidationError> in <validateConnection>. This is an
  65939. * additional hook for disabling certain targets in this specific handler.
  65940. *
  65941. * Parameters:
  65942. *
  65943. * cell - <mxCell> that represents the target terminal.
  65944. */
  65945. mxConnectionHandler.prototype.isValidTarget = function(cell)
  65946. {
  65947. return true;
  65948. };
  65949. /**
  65950. * Function: validateConnection
  65951. *
  65952. * Returns the error message or an empty string if the connection for the
  65953. * given source target pair is not valid. Otherwise it returns null. This
  65954. * implementation uses <mxGraph.getEdgeValidationError>.
  65955. *
  65956. * Parameters:
  65957. *
  65958. * source - <mxCell> that represents the source terminal.
  65959. * target - <mxCell> that represents the target terminal.
  65960. */
  65961. mxConnectionHandler.prototype.validateConnection = function(source, target)
  65962. {
  65963. if (!this.isValidTarget(target))
  65964. {
  65965. return '';
  65966. }
  65967. return this.graph.getEdgeValidationError(null, source, target);
  65968. };
  65969. /**
  65970. * Function: getConnectImage
  65971. *
  65972. * Hook to return the <mxImage> used for the connection icon of the given
  65973. * <mxCellState>. This implementation returns <connectImage>.
  65974. *
  65975. * Parameters:
  65976. *
  65977. * state - <mxCellState> whose connect image should be returned.
  65978. */
  65979. mxConnectionHandler.prototype.getConnectImage = function(state)
  65980. {
  65981. return this.connectImage;
  65982. };
  65983. /**
  65984. * Function: isMoveIconToFrontForState
  65985. *
  65986. * Returns true if the state has a HTML label in the graph's container, otherwise
  65987. * it returns <moveIconFront>.
  65988. *
  65989. * Parameters:
  65990. *
  65991. * state - <mxCellState> whose connect icons should be returned.
  65992. */
  65993. mxConnectionHandler.prototype.isMoveIconToFrontForState = function(state)
  65994. {
  65995. if (state.text != null && state.text.node.parentNode == this.graph.container)
  65996. {
  65997. return true;
  65998. }
  65999. return this.moveIconFront;
  66000. };
  66001. /**
  66002. * Function: createIcons
  66003. *
  66004. * Creates the array <mxImageShapes> that represent the connect icons for
  66005. * the given <mxCellState>.
  66006. *
  66007. * Parameters:
  66008. *
  66009. * state - <mxCellState> whose connect icons should be returned.
  66010. */
  66011. mxConnectionHandler.prototype.createIcons = function(state)
  66012. {
  66013. var image = this.getConnectImage(state);
  66014. if (image != null && state != null)
  66015. {
  66016. this.iconState = state;
  66017. var icons = [];
  66018. // Cannot use HTML for the connect icons because the icon receives all
  66019. // mouse move events in IE, must use VML and SVG instead even if the
  66020. // connect-icon appears behind the selection border and the selection
  66021. // border consumes the events before the icon gets a chance
  66022. var bounds = new mxRectangle(0, 0, image.width, image.height);
  66023. var icon = new mxImageShape(bounds, image.src, null, null, 0);
  66024. icon.preserveImageAspect = false;
  66025. if (this.isMoveIconToFrontForState(state))
  66026. {
  66027. icon.dialect = mxConstants.DIALECT_STRICTHTML;
  66028. icon.init(this.graph.container);
  66029. }
  66030. else
  66031. {
  66032. icon.dialect = (this.graph.dialect == mxConstants.DIALECT_SVG) ?
  66033. mxConstants.DIALECT_SVG : mxConstants.DIALECT_VML;
  66034. icon.init(this.graph.getView().getOverlayPane());
  66035. // Move the icon back in the overlay pane
  66036. if (this.moveIconBack && icon.node.previousSibling != null)
  66037. {
  66038. icon.node.parentNode.insertBefore(icon.node, icon.node.parentNode.firstChild);
  66039. }
  66040. }
  66041. icon.node.style.cursor = mxConstants.CURSOR_CONNECT;
  66042. // Events transparency
  66043. var getState = mxUtils.bind(this, function()
  66044. {
  66045. return (this.currentState != null) ? this.currentState : state;
  66046. });
  66047. // Updates the local icon before firing the mouse down event.
  66048. var mouseDown = mxUtils.bind(this, function(evt)
  66049. {
  66050. if (!mxEvent.isConsumed(evt))
  66051. {
  66052. this.icon = icon;
  66053. this.graph.fireMouseEvent(mxEvent.MOUSE_DOWN,
  66054. new mxMouseEvent(evt, getState()));
  66055. }
  66056. });
  66057. mxEvent.redirectMouseEvents(icon.node, this.graph, getState, mouseDown);
  66058. icons.push(icon);
  66059. this.redrawIcons(icons, this.iconState);
  66060. return icons;
  66061. }
  66062. return null;
  66063. };
  66064. /**
  66065. * Function: redrawIcons
  66066. *
  66067. * Redraws the given array of <mxImageShapes>.
  66068. *
  66069. * Parameters:
  66070. *
  66071. * icons - Optional array of <mxImageShapes> to be redrawn.
  66072. */
  66073. mxConnectionHandler.prototype.redrawIcons = function(icons, state)
  66074. {
  66075. if (icons != null && icons[0] != null && state != null)
  66076. {
  66077. var pos = this.getIconPosition(icons[0], state);
  66078. icons[0].bounds.x = pos.x;
  66079. icons[0].bounds.y = pos.y;
  66080. icons[0].redraw();
  66081. }
  66082. };
  66083. /**
  66084. * Function: redrawIcons
  66085. *
  66086. * Redraws the given array of <mxImageShapes>.
  66087. *
  66088. * Parameters:
  66089. *
  66090. * icons - Optional array of <mxImageShapes> to be redrawn.
  66091. */
  66092. mxConnectionHandler.prototype.getIconPosition = function(icon, state)
  66093. {
  66094. var scale = this.graph.getView().scale;
  66095. var cx = state.getCenterX();
  66096. var cy = state.getCenterY();
  66097. if (this.graph.isSwimlane(state.cell))
  66098. {
  66099. var size = this.graph.getStartSize(state.cell);
  66100. cx = (size.width != 0) ? state.x + size.width * scale / 2 : cx;
  66101. cy = (size.height != 0) ? state.y + size.height * scale / 2 : cy;
  66102. var alpha = mxUtils.toRadians(mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION) || 0);
  66103. if (alpha != 0)
  66104. {
  66105. var cos = Math.cos(alpha);
  66106. var sin = Math.sin(alpha);
  66107. var ct = new mxPoint(state.getCenterX(), state.getCenterY());
  66108. var pt = mxUtils.getRotatedPoint(new mxPoint(cx, cy), cos, sin, ct);
  66109. cx = pt.x;
  66110. cy = pt.y;
  66111. }
  66112. }
  66113. return new mxPoint(cx - icon.bounds.width / 2,
  66114. cy - icon.bounds.height / 2);
  66115. };
  66116. /**
  66117. * Function: destroyIcons
  66118. *
  66119. * Destroys the connect icons and resets the respective state.
  66120. */
  66121. mxConnectionHandler.prototype.destroyIcons = function()
  66122. {
  66123. if (this.icons != null)
  66124. {
  66125. for (var i = 0; i < this.icons.length; i++)
  66126. {
  66127. this.icons[i].destroy();
  66128. }
  66129. this.icons = null;
  66130. this.icon = null;
  66131. this.selectedIcon = null;
  66132. this.iconState = null;
  66133. }
  66134. };
  66135. /**
  66136. * Function: isStartEvent
  66137. *
  66138. * Returns true if the given mouse down event should start this handler. The
  66139. * This implementation returns true if the event does not force marquee
  66140. * selection, and the currentConstraint and currentFocus of the
  66141. * <constraintHandler> are not null, or <previous> and <error> are not null and
  66142. * <icons> is null or <icons> and <icon> are not null.
  66143. */
  66144. mxConnectionHandler.prototype.isStartEvent = function(me)
  66145. {
  66146. return ((this.constraintHandler.currentFocus != null && this.constraintHandler.currentConstraint != null) ||
  66147. (this.previous != null && this.error == null && (this.icons == null || (this.icons != null &&
  66148. this.icon != null))));
  66149. };
  66150. /**
  66151. * Function: mouseDown
  66152. *
  66153. * Handles the event by initiating a new connection.
  66154. */
  66155. mxConnectionHandler.prototype.mouseDown = function(sender, me)
  66156. {
  66157. this.mouseDownCounter++;
  66158. if (this.isEnabled() && this.graph.isEnabled() && !me.isConsumed() &&
  66159. !this.isConnecting() && this.isStartEvent(me))
  66160. {
  66161. if (this.constraintHandler.currentConstraint != null &&
  66162. this.constraintHandler.currentFocus != null &&
  66163. this.constraintHandler.currentPoint != null)
  66164. {
  66165. this.sourceConstraint = this.constraintHandler.currentConstraint;
  66166. this.previous = this.constraintHandler.currentFocus;
  66167. this.first = this.constraintHandler.currentPoint.clone();
  66168. }
  66169. else
  66170. {
  66171. // Stores the location of the initial mousedown
  66172. this.first = new mxPoint(me.getGraphX(), me.getGraphY());
  66173. }
  66174. this.edgeState = this.createEdgeState(me);
  66175. this.mouseDownCounter = 1;
  66176. if (this.waypointsEnabled && this.shape == null)
  66177. {
  66178. this.waypoints = null;
  66179. this.shape = this.createShape();
  66180. if (this.edgeState != null)
  66181. {
  66182. this.shape.apply(this.edgeState);
  66183. }
  66184. }
  66185. // Stores the starting point in the geometry of the preview
  66186. if (this.previous == null && this.edgeState != null)
  66187. {
  66188. var pt = this.graph.getPointForEvent(me.getEvent());
  66189. this.edgeState.cell.geometry.setTerminalPoint(pt, true);
  66190. }
  66191. this.fireEvent(new mxEventObject(mxEvent.START, 'state', this.previous));
  66192. me.consume();
  66193. }
  66194. this.selectedIcon = this.icon;
  66195. this.icon = null;
  66196. };
  66197. /**
  66198. * Function: isImmediateConnectSource
  66199. *
  66200. * Returns true if a tap on the given source state should immediately start
  66201. * connecting. This implementation returns true if the state is not movable
  66202. * in the graph.
  66203. */
  66204. mxConnectionHandler.prototype.isImmediateConnectSource = function(state)
  66205. {
  66206. return !this.graph.isCellMovable(state.cell);
  66207. };
  66208. /**
  66209. * Function: createEdgeState
  66210. *
  66211. * Hook to return an <mxCellState> which may be used during the preview.
  66212. * This implementation returns null.
  66213. *
  66214. * Use the following code to create a preview for an existing edge style:
  66215. *
  66216. * (code)
  66217. * graph.connectionHandler.createEdgeState = function(me)
  66218. * {
  66219. * var edge = graph.createEdge(null, null, null, null, null, 'edgeStyle=elbowEdgeStyle');
  66220. *
  66221. * return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  66222. * };
  66223. * (end)
  66224. */
  66225. mxConnectionHandler.prototype.createEdgeState = function(me)
  66226. {
  66227. return null;
  66228. };
  66229. /**
  66230. * Function: isOutlineConnectEvent
  66231. *
  66232. * Returns true if <outlineConnect> is true and the source of the event is the outline shape
  66233. * or shift is pressed.
  66234. */
  66235. mxConnectionHandler.prototype.isOutlineConnectEvent = function(me)
  66236. {
  66237. var offset = mxUtils.getOffset(this.graph.container);
  66238. var evt = me.getEvent();
  66239. var clientX = mxEvent.getClientX(evt);
  66240. var clientY = mxEvent.getClientY(evt);
  66241. var doc = document.documentElement;
  66242. var left = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
  66243. var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
  66244. var gridX = this.currentPoint.x - this.graph.container.scrollLeft + offset.x - left;
  66245. var gridY = this.currentPoint.y - this.graph.container.scrollTop + offset.y - top;
  66246. return this.outlineConnect && !mxEvent.isShiftDown(me.getEvent()) &&
  66247. (me.isSource(this.marker.highlight.shape) ||
  66248. (mxEvent.isAltDown(me.getEvent()) && me.getState() != null) ||
  66249. this.marker.highlight.isHighlightAt(clientX, clientY) ||
  66250. ((gridX != clientX || gridY != clientY) && me.getState() == null &&
  66251. this.marker.highlight.isHighlightAt(gridX, gridY)));
  66252. };
  66253. /**
  66254. * Function: updateCurrentState
  66255. *
  66256. * Updates the current state for a given mouse move event by using
  66257. * the <marker>.
  66258. */
  66259. mxConnectionHandler.prototype.updateCurrentState = function(me, point)
  66260. {
  66261. this.constraintHandler.update(me, this.first == null, false, (this.first == null ||
  66262. me.isSource(this.marker.highlight.shape)) ? null : point);
  66263. if (this.constraintHandler.currentFocus != null && this.constraintHandler.currentConstraint != null)
  66264. {
  66265. // Handles special case where grid is large and connection point is at actual point in which
  66266. // case the outline is not followed as long as we're < gridSize / 2 away from that point
  66267. if (this.marker.highlight != null && this.marker.highlight.state != null &&
  66268. this.marker.highlight.state.cell == this.constraintHandler.currentFocus.cell)
  66269. {
  66270. // Direct repaint needed if cell already highlighted
  66271. if (this.marker.highlight.shape.stroke != 'transparent')
  66272. {
  66273. this.marker.highlight.shape.stroke = 'transparent';
  66274. this.marker.highlight.repaint();
  66275. }
  66276. }
  66277. else
  66278. {
  66279. this.marker.markCell(this.constraintHandler.currentFocus.cell, 'transparent');
  66280. }
  66281. // Updates validation state
  66282. if (this.previous != null)
  66283. {
  66284. this.error = this.validateConnection(this.previous.cell, this.constraintHandler.currentFocus.cell);
  66285. if (this.error == null)
  66286. {
  66287. this.currentState = this.constraintHandler.currentFocus;
  66288. }
  66289. if (this.error != null || (this.currentState != null &&
  66290. !this.isCellEnabled(this.currentState.cell)))
  66291. {
  66292. this.constraintHandler.reset();
  66293. }
  66294. }
  66295. }
  66296. else
  66297. {
  66298. if (this.graph.isIgnoreTerminalEvent(me.getEvent()))
  66299. {
  66300. this.marker.reset();
  66301. this.currentState = null;
  66302. }
  66303. else
  66304. {
  66305. this.marker.process(me);
  66306. this.currentState = this.marker.getValidState();
  66307. }
  66308. if (this.currentState != null && !this.isCellEnabled(this.currentState.cell))
  66309. {
  66310. this.constraintHandler.reset();
  66311. this.marker.reset();
  66312. this.currentState = null;
  66313. }
  66314. var outline = this.isOutlineConnectEvent(me);
  66315. if (this.currentState != null && outline)
  66316. {
  66317. // Handles special case where mouse is on outline away from actual end point
  66318. // in which case the grid is ignored and mouse point is used instead
  66319. if (me.isSource(this.marker.highlight.shape))
  66320. {
  66321. point = new mxPoint(me.getGraphX(), me.getGraphY());
  66322. }
  66323. var constraint = this.graph.getOutlineConstraint(point, this.currentState, me);
  66324. this.constraintHandler.setFocus(me, this.currentState, false);
  66325. this.constraintHandler.currentConstraint = constraint;
  66326. this.constraintHandler.currentPoint = point;
  66327. }
  66328. if (this.outlineConnect)
  66329. {
  66330. if (this.marker.highlight != null && this.marker.highlight.shape != null)
  66331. {
  66332. var s = this.graph.view.scale;
  66333. if (this.constraintHandler.currentConstraint != null &&
  66334. this.constraintHandler.currentFocus != null)
  66335. {
  66336. this.marker.highlight.shape.stroke = mxConstants.OUTLINE_HIGHLIGHT_COLOR;
  66337. this.marker.highlight.shape.strokewidth = mxConstants.OUTLINE_HIGHLIGHT_STROKEWIDTH / s / s;
  66338. this.marker.highlight.repaint();
  66339. }
  66340. else if (this.marker.hasValidState())
  66341. {
  66342. // Handles special case where actual end point of edge and current mouse point
  66343. // are not equal (due to grid snapping) and there is no hit on shape or highlight
  66344. // but ignores cases where parent is used for non-connectable child cells
  66345. if (this.graph.isCellConnectable(me.getCell()) &&
  66346. this.marker.getValidState() != me.getState())
  66347. {
  66348. this.marker.highlight.shape.stroke = 'transparent';
  66349. this.currentState = null;
  66350. }
  66351. else
  66352. {
  66353. this.marker.highlight.shape.stroke = mxConstants.DEFAULT_VALID_COLOR;
  66354. }
  66355. this.marker.highlight.shape.strokewidth = mxConstants.HIGHLIGHT_STROKEWIDTH / s / s;
  66356. this.marker.highlight.repaint();
  66357. }
  66358. }
  66359. }
  66360. }
  66361. };
  66362. /**
  66363. * Function: isCellEnabled
  66364. *
  66365. * Returns true if the given cell allows new connections to be created. This implementation
  66366. * always returns true.
  66367. */
  66368. mxConnectionHandler.prototype.isCellEnabled = function(cell)
  66369. {
  66370. return true;
  66371. };
  66372. /**
  66373. * Function: convertWaypoint
  66374. *
  66375. * Converts the given point from screen coordinates to model coordinates.
  66376. */
  66377. mxConnectionHandler.prototype.convertWaypoint = function(point)
  66378. {
  66379. var scale = this.graph.getView().getScale();
  66380. var tr = this.graph.getView().getTranslate();
  66381. point.x = point.x / scale - tr.x;
  66382. point.y = point.y / scale - tr.y;
  66383. };
  66384. /**
  66385. * Function: snapToPreview
  66386. *
  66387. * Called to snap the given point to the current preview. This snaps to the
  66388. * first point of the preview if alt is not pressed.
  66389. */
  66390. mxConnectionHandler.prototype.snapToPreview = function(me, point)
  66391. {
  66392. if (!mxEvent.isAltDown(me.getEvent()) && this.previous != null)
  66393. {
  66394. var tol = this.graph.gridSize * this.graph.view.scale / 2;
  66395. var tmp = (this.sourceConstraint != null) ? this.first :
  66396. new mxPoint(this.previous.getCenterX(), this.previous.getCenterY());
  66397. if (Math.abs(tmp.x - me.getGraphX()) < tol)
  66398. {
  66399. point.x = tmp.x;
  66400. }
  66401. if (Math.abs(tmp.y - me.getGraphY()) < tol)
  66402. {
  66403. point.y = tmp.y;
  66404. }
  66405. }
  66406. };
  66407. /**
  66408. * Function: mouseMove
  66409. *
  66410. * Handles the event by updating the preview edge or by highlighting
  66411. * a possible source or target terminal.
  66412. */
  66413. mxConnectionHandler.prototype.mouseMove = function(sender, me)
  66414. {
  66415. if (!me.isConsumed() && (this.ignoreMouseDown || this.first != null || !this.graph.isMouseDown))
  66416. {
  66417. // Handles special case when handler is disabled during highlight
  66418. if (!this.isEnabled() && this.currentState != null)
  66419. {
  66420. this.destroyIcons();
  66421. this.currentState = null;
  66422. }
  66423. var view = this.graph.getView();
  66424. var scale = view.scale;
  66425. var tr = view.translate;
  66426. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  66427. this.error = null;
  66428. if (this.graph.isGridEnabledEvent(me.getEvent()))
  66429. {
  66430. point = new mxPoint((this.graph.snap(point.x / scale - tr.x) + tr.x) * scale,
  66431. (this.graph.snap(point.y / scale - tr.y) + tr.y) * scale);
  66432. }
  66433. this.snapToPreview(me, point);
  66434. this.currentPoint = point;
  66435. if ((this.first != null || (this.isEnabled() && this.graph.isEnabled())) &&
  66436. (this.shape != null || this.first == null ||
  66437. Math.abs(me.getGraphX() - this.first.x) > this.graph.tolerance ||
  66438. Math.abs(me.getGraphY() - this.first.y) > this.graph.tolerance))
  66439. {
  66440. this.updateCurrentState(me, point);
  66441. }
  66442. if (this.first != null)
  66443. {
  66444. var constraint = null;
  66445. var current = point;
  66446. // Uses the current point from the constraint handler if available
  66447. if (this.constraintHandler.currentConstraint != null &&
  66448. this.constraintHandler.currentFocus != null &&
  66449. this.constraintHandler.currentPoint != null)
  66450. {
  66451. constraint = this.constraintHandler.currentConstraint;
  66452. current = this.constraintHandler.currentPoint.clone();
  66453. }
  66454. else if (this.previous != null && !this.graph.isIgnoreTerminalEvent(me.getEvent()) &&
  66455. mxEvent.isShiftDown(me.getEvent()))
  66456. {
  66457. if (Math.abs(this.previous.getCenterX() - point.x) <
  66458. Math.abs(this.previous.getCenterY() - point.y))
  66459. {
  66460. point.x = this.previous.getCenterX();
  66461. }
  66462. else
  66463. {
  66464. point.y = this.previous.getCenterY();
  66465. }
  66466. }
  66467. var pt2 = this.first;
  66468. // Moves the connect icon with the mouse
  66469. if (this.selectedIcon != null)
  66470. {
  66471. var w = this.selectedIcon.bounds.width;
  66472. var h = this.selectedIcon.bounds.height;
  66473. if (this.currentState != null && this.targetConnectImage)
  66474. {
  66475. var pos = this.getIconPosition(this.selectedIcon, this.currentState);
  66476. this.selectedIcon.bounds.x = pos.x;
  66477. this.selectedIcon.bounds.y = pos.y;
  66478. }
  66479. else
  66480. {
  66481. var bounds = new mxRectangle(me.getGraphX() + this.connectIconOffset.x,
  66482. me.getGraphY() + this.connectIconOffset.y, w, h);
  66483. this.selectedIcon.bounds = bounds;
  66484. }
  66485. this.selectedIcon.redraw();
  66486. }
  66487. // Uses edge state to compute the terminal points
  66488. if (this.edgeState != null)
  66489. {
  66490. this.updateEdgeState(current, constraint);
  66491. current = this.edgeState.absolutePoints[this.edgeState.absolutePoints.length - 1];
  66492. pt2 = this.edgeState.absolutePoints[0];
  66493. }
  66494. else
  66495. {
  66496. if (this.currentState != null)
  66497. {
  66498. if (this.constraintHandler.currentConstraint == null)
  66499. {
  66500. var tmp = this.getTargetPerimeterPoint(this.currentState, me);
  66501. if (tmp != null)
  66502. {
  66503. current = tmp;
  66504. }
  66505. }
  66506. }
  66507. // Computes the source perimeter point
  66508. if (this.sourceConstraint == null && this.previous != null)
  66509. {
  66510. var next = (this.waypoints != null && this.waypoints.length > 0) ?
  66511. this.waypoints[0] : current;
  66512. var tmp = this.getSourcePerimeterPoint(this.previous, next, me);
  66513. if (tmp != null)
  66514. {
  66515. pt2 = tmp;
  66516. }
  66517. }
  66518. }
  66519. // Makes sure the cell under the mousepointer can be detected
  66520. // by moving the preview shape away from the mouse. This
  66521. // makes sure the preview shape does not prevent the detection
  66522. // of the cell under the mousepointer even for slow gestures.
  66523. if (this.currentState == null && this.movePreviewAway)
  66524. {
  66525. var tmp = pt2;
  66526. if (this.edgeState != null && this.edgeState.absolutePoints.length >= 2)
  66527. {
  66528. var tmp2 = this.edgeState.absolutePoints[this.edgeState.absolutePoints.length - 2];
  66529. if (tmp2 != null)
  66530. {
  66531. tmp = tmp2;
  66532. }
  66533. }
  66534. var dx = current.x - tmp.x;
  66535. var dy = current.y - tmp.y;
  66536. var len = Math.sqrt(dx * dx + dy * dy);
  66537. if (len == 0)
  66538. {
  66539. return;
  66540. }
  66541. // Stores old point to reuse when creating edge
  66542. this.originalPoint = current.clone();
  66543. current.x -= dx * 4 / len;
  66544. current.y -= dy * 4 / len;
  66545. }
  66546. else
  66547. {
  66548. this.originalPoint = null;
  66549. }
  66550. // Creates the preview shape (lazy)
  66551. if (this.shape == null)
  66552. {
  66553. var dx = Math.abs(me.getGraphX() - this.first.x);
  66554. var dy = Math.abs(me.getGraphY() - this.first.y);
  66555. if (dx > this.graph.tolerance || dy > this.graph.tolerance)
  66556. {
  66557. this.shape = this.createShape();
  66558. if (this.edgeState != null)
  66559. {
  66560. this.shape.apply(this.edgeState);
  66561. }
  66562. // Revalidates current connection
  66563. this.updateCurrentState(me, point);
  66564. }
  66565. }
  66566. // Updates the points in the preview edge
  66567. if (this.shape != null)
  66568. {
  66569. if (this.edgeState != null)
  66570. {
  66571. this.shape.points = this.edgeState.absolutePoints;
  66572. }
  66573. else
  66574. {
  66575. var pts = [pt2];
  66576. if (this.waypoints != null)
  66577. {
  66578. pts = pts.concat(this.waypoints);
  66579. }
  66580. pts.push(current);
  66581. this.shape.points = pts;
  66582. }
  66583. this.drawPreview();
  66584. }
  66585. // Makes sure endpoint of edge is visible during connect
  66586. if (this.cursor != null)
  66587. {
  66588. this.graph.container.style.cursor = this.cursor;
  66589. }
  66590. mxEvent.consume(me.getEvent());
  66591. me.consume();
  66592. }
  66593. else if (!this.isEnabled() || !this.graph.isEnabled())
  66594. {
  66595. this.constraintHandler.reset();
  66596. }
  66597. else if (this.previous != this.currentState && this.edgeState == null)
  66598. {
  66599. this.destroyIcons();
  66600. // Sets the cursor on the current shape
  66601. if (this.currentState != null && this.error == null && this.constraintHandler.currentConstraint == null)
  66602. {
  66603. this.icons = this.createIcons(this.currentState);
  66604. if (this.icons == null)
  66605. {
  66606. this.currentState.setCursor(mxConstants.CURSOR_CONNECT);
  66607. me.consume();
  66608. }
  66609. }
  66610. this.previous = this.currentState;
  66611. }
  66612. else if (this.previous == this.currentState && this.currentState != null && this.icons == null &&
  66613. !this.graph.isMouseDown)
  66614. {
  66615. // Makes sure that no cursors are changed
  66616. me.consume();
  66617. }
  66618. if (!this.graph.isMouseDown && this.currentState != null && this.icons != null)
  66619. {
  66620. var hitsIcon = false;
  66621. var target = me.getSource();
  66622. for (var i = 0; i < this.icons.length && !hitsIcon; i++)
  66623. {
  66624. hitsIcon = target == this.icons[i].node || target.parentNode == this.icons[i].node;
  66625. }
  66626. if (!hitsIcon)
  66627. {
  66628. this.updateIcons(this.currentState, this.icons, me);
  66629. }
  66630. }
  66631. }
  66632. else
  66633. {
  66634. this.constraintHandler.reset();
  66635. }
  66636. };
  66637. /**
  66638. * Function: updateEdgeState
  66639. *
  66640. * Updates <edgeState>.
  66641. */
  66642. mxConnectionHandler.prototype.updateEdgeState = function(current, constraint)
  66643. {
  66644. // TODO: Use generic method for writing constraint to style
  66645. if (this.sourceConstraint != null && this.sourceConstraint.point != null)
  66646. {
  66647. this.edgeState.style[mxConstants.STYLE_EXIT_X] = this.sourceConstraint.point.x;
  66648. this.edgeState.style[mxConstants.STYLE_EXIT_Y] = this.sourceConstraint.point.y;
  66649. }
  66650. if (constraint != null && constraint.point != null)
  66651. {
  66652. this.edgeState.style[mxConstants.STYLE_ENTRY_X] = constraint.point.x;
  66653. this.edgeState.style[mxConstants.STYLE_ENTRY_Y] = constraint.point.y;
  66654. }
  66655. else
  66656. {
  66657. delete this.edgeState.style[mxConstants.STYLE_ENTRY_X];
  66658. delete this.edgeState.style[mxConstants.STYLE_ENTRY_Y];
  66659. }
  66660. this.edgeState.absolutePoints = [null, (this.currentState != null) ? null : current];
  66661. this.graph.view.updateFixedTerminalPoint(this.edgeState, this.previous, true, this.sourceConstraint);
  66662. if (this.currentState != null)
  66663. {
  66664. if (constraint == null)
  66665. {
  66666. constraint = this.graph.getConnectionConstraint(this.edgeState, this.previous, false);
  66667. }
  66668. this.edgeState.setAbsoluteTerminalPoint(null, false);
  66669. this.graph.view.updateFixedTerminalPoint(this.edgeState, this.currentState, false, constraint);
  66670. }
  66671. // Scales and translates the waypoints to the model
  66672. var realPoints = null;
  66673. if (this.waypoints != null)
  66674. {
  66675. realPoints = [];
  66676. for (var i = 0; i < this.waypoints.length; i++)
  66677. {
  66678. var pt = this.waypoints[i].clone();
  66679. this.convertWaypoint(pt);
  66680. realPoints[i] = pt;
  66681. }
  66682. }
  66683. this.graph.view.updatePoints(this.edgeState, realPoints, this.previous, this.currentState);
  66684. this.graph.view.updateFloatingTerminalPoints(this.edgeState, this.previous, this.currentState);
  66685. };
  66686. /**
  66687. * Function: getTargetPerimeterPoint
  66688. *
  66689. * Returns the perimeter point for the given target state.
  66690. *
  66691. * Parameters:
  66692. *
  66693. * state - <mxCellState> that represents the target cell state.
  66694. * me - <mxMouseEvent> that represents the mouse move.
  66695. */
  66696. mxConnectionHandler.prototype.getTargetPerimeterPoint = function(state, me)
  66697. {
  66698. var result = null;
  66699. var view = state.view;
  66700. var targetPerimeter = view.getPerimeterFunction(state);
  66701. if (targetPerimeter != null)
  66702. {
  66703. var next = (this.waypoints != null && this.waypoints.length > 0) ?
  66704. this.waypoints[this.waypoints.length - 1] :
  66705. new mxPoint(this.previous.getCenterX(), this.previous.getCenterY());
  66706. var tmp = targetPerimeter(view.getPerimeterBounds(state),
  66707. this.edgeState, next, false);
  66708. if (tmp != null)
  66709. {
  66710. result = tmp;
  66711. }
  66712. }
  66713. else
  66714. {
  66715. result = new mxPoint(state.getCenterX(), state.getCenterY());
  66716. }
  66717. return result;
  66718. };
  66719. /**
  66720. * Function: getSourcePerimeterPoint
  66721. *
  66722. * Hook to update the icon position(s) based on a mouseOver event. This is
  66723. * an empty implementation.
  66724. *
  66725. * Parameters:
  66726. *
  66727. * state - <mxCellState> that represents the target cell state.
  66728. * next - <mxPoint> that represents the next point along the previewed edge.
  66729. * me - <mxMouseEvent> that represents the mouse move.
  66730. */
  66731. mxConnectionHandler.prototype.getSourcePerimeterPoint = function(state, next, me)
  66732. {
  66733. var result = null;
  66734. var view = state.view;
  66735. var sourcePerimeter = view.getPerimeterFunction(state);
  66736. var c = new mxPoint(state.getCenterX(), state.getCenterY());
  66737. if (sourcePerimeter != null)
  66738. {
  66739. var theta = mxUtils.getValue(state.style, mxConstants.STYLE_ROTATION, 0);
  66740. var rad = -theta * (Math.PI / 180);
  66741. if (theta != 0)
  66742. {
  66743. next = mxUtils.getRotatedPoint(new mxPoint(next.x, next.y), Math.cos(rad), Math.sin(rad), c);
  66744. }
  66745. var tmp = sourcePerimeter(view.getPerimeterBounds(state), state, next, false);
  66746. if (tmp != null)
  66747. {
  66748. if (theta != 0)
  66749. {
  66750. tmp = mxUtils.getRotatedPoint(new mxPoint(tmp.x, tmp.y), Math.cos(-rad), Math.sin(-rad), c);
  66751. }
  66752. result = tmp;
  66753. }
  66754. }
  66755. else
  66756. {
  66757. result = c;
  66758. }
  66759. return result;
  66760. };
  66761. /**
  66762. * Function: updateIcons
  66763. *
  66764. * Hook to update the icon position(s) based on a mouseOver event. This is
  66765. * an empty implementation.
  66766. *
  66767. * Parameters:
  66768. *
  66769. * state - <mxCellState> under the mouse.
  66770. * icons - Array of currently displayed icons.
  66771. * me - <mxMouseEvent> that contains the mouse event.
  66772. */
  66773. mxConnectionHandler.prototype.updateIcons = function(state, icons, me)
  66774. {
  66775. // empty
  66776. };
  66777. /**
  66778. * Function: isStopEvent
  66779. *
  66780. * Returns true if the given mouse up event should stop this handler. The
  66781. * connection will be created if <error> is null. Note that this is only
  66782. * called if <waypointsEnabled> is true. This implemtation returns true
  66783. * if there is a cell state in the given event.
  66784. */
  66785. mxConnectionHandler.prototype.isStopEvent = function(me)
  66786. {
  66787. return me.getState() != null;
  66788. };
  66789. /**
  66790. * Function: addWaypoint
  66791. *
  66792. * Adds the waypoint for the given event to <waypoints>.
  66793. */
  66794. mxConnectionHandler.prototype.addWaypointForEvent = function(me)
  66795. {
  66796. var point = mxUtils.convertPoint(this.graph.container, me.getX(), me.getY());
  66797. var dx = Math.abs(point.x - this.first.x);
  66798. var dy = Math.abs(point.y - this.first.y);
  66799. var addPoint = this.waypoints != null || (this.mouseDownCounter > 1 &&
  66800. (dx > this.graph.tolerance || dy > this.graph.tolerance));
  66801. if (addPoint)
  66802. {
  66803. if (this.waypoints == null)
  66804. {
  66805. this.waypoints = [];
  66806. }
  66807. var scale = this.graph.view.scale;
  66808. var point = new mxPoint(this.graph.snap(me.getGraphX() / scale) * scale,
  66809. this.graph.snap(me.getGraphY() / scale) * scale);
  66810. this.waypoints.push(point);
  66811. }
  66812. };
  66813. /**
  66814. * Function: checkConstraints
  66815. *
  66816. * Returns true if the connection for the given constraints is valid. This
  66817. * implementation returns true if the constraints are not pointing to the
  66818. * same fixed connection point.
  66819. */
  66820. mxConnectionHandler.prototype.checkConstraints = function(c1, c2)
  66821. {
  66822. return (c1 == null || c2 == null || c1.point == null || c2.point == null ||
  66823. !c1.point.equals(c2.point) || c1.dx != c2.dx || c1.dy != c2.dy ||
  66824. c1.perimeter != c2.perimeter);
  66825. };
  66826. /**
  66827. * Function: mouseUp
  66828. *
  66829. * Handles the event by inserting the new connection.
  66830. */
  66831. mxConnectionHandler.prototype.mouseUp = function(sender, me)
  66832. {
  66833. if (!me.isConsumed() && this.isConnecting())
  66834. {
  66835. if (this.waypointsEnabled && !this.isStopEvent(me))
  66836. {
  66837. this.addWaypointForEvent(me);
  66838. me.consume();
  66839. return;
  66840. }
  66841. var c1 = this.sourceConstraint;
  66842. var c2 = this.constraintHandler.currentConstraint;
  66843. var source = (this.previous != null) ? this.previous.cell : null;
  66844. var target = null;
  66845. if (this.constraintHandler.currentConstraint != null &&
  66846. this.constraintHandler.currentFocus != null)
  66847. {
  66848. target = this.constraintHandler.currentFocus.cell;
  66849. }
  66850. if (target == null && this.currentState != null)
  66851. {
  66852. target = this.currentState.cell;
  66853. }
  66854. // Inserts the edge if no validation error exists and if constraints differ
  66855. if (this.error == null && (source == null || target == null ||
  66856. source != target || this.checkConstraints(c1, c2)))
  66857. {
  66858. this.connect(source, target, me.getEvent(), me.getCell());
  66859. }
  66860. else
  66861. {
  66862. // Selects the source terminal for self-references
  66863. if (this.previous != null && this.marker.validState != null &&
  66864. this.previous.cell == this.marker.validState.cell)
  66865. {
  66866. this.graph.selectCellForEvent(this.marker.source, me.getEvent());
  66867. }
  66868. // Displays the error message if it is not an empty string,
  66869. // for empty error messages, the event is silently dropped
  66870. if (this.error != null && this.error.length > 0)
  66871. {
  66872. this.graph.validationAlert(this.error);
  66873. }
  66874. }
  66875. // Redraws the connect icons and resets the handler state
  66876. this.destroyIcons();
  66877. me.consume();
  66878. }
  66879. if (this.first != null)
  66880. {
  66881. this.reset();
  66882. }
  66883. };
  66884. /**
  66885. * Function: reset
  66886. *
  66887. * Resets the state of this handler.
  66888. */
  66889. mxConnectionHandler.prototype.reset = function()
  66890. {
  66891. if (this.shape != null)
  66892. {
  66893. this.shape.destroy();
  66894. this.shape = null;
  66895. }
  66896. // Resets the cursor on the container
  66897. if (this.cursor != null && this.graph.container != null)
  66898. {
  66899. this.graph.container.style.cursor = '';
  66900. }
  66901. this.destroyIcons();
  66902. this.marker.reset();
  66903. this.constraintHandler.reset();
  66904. this.originalPoint = null;
  66905. this.currentPoint = null;
  66906. this.edgeState = null;
  66907. this.previous = null;
  66908. this.error = null;
  66909. this.sourceConstraint = null;
  66910. this.mouseDownCounter = 0;
  66911. this.first = null;
  66912. this.fireEvent(new mxEventObject(mxEvent.RESET));
  66913. };
  66914. /**
  66915. * Function: drawPreview
  66916. *
  66917. * Redraws the preview edge using the color and width returned by
  66918. * <getEdgeColor> and <getEdgeWidth>.
  66919. */
  66920. mxConnectionHandler.prototype.drawPreview = function()
  66921. {
  66922. this.updatePreview(this.error == null);
  66923. this.shape.redraw();
  66924. };
  66925. /**
  66926. * Function: getEdgeColor
  66927. *
  66928. * Returns the color used to draw the preview edge. This returns green if
  66929. * there is no edge validation error and red otherwise.
  66930. *
  66931. * Parameters:
  66932. *
  66933. * valid - Boolean indicating if the color for a valid edge should be
  66934. * returned.
  66935. */
  66936. mxConnectionHandler.prototype.updatePreview = function(valid)
  66937. {
  66938. this.shape.strokewidth = this.getEdgeWidth(valid);
  66939. this.shape.stroke = this.getEdgeColor(valid);
  66940. };
  66941. /**
  66942. * Function: getEdgeColor
  66943. *
  66944. * Returns the color used to draw the preview edge. This returns green if
  66945. * there is no edge validation error and red otherwise.
  66946. *
  66947. * Parameters:
  66948. *
  66949. * valid - Boolean indicating if the color for a valid edge should be
  66950. * returned.
  66951. */
  66952. mxConnectionHandler.prototype.getEdgeColor = function(valid)
  66953. {
  66954. return (valid) ? mxConstants.VALID_COLOR : mxConstants.INVALID_COLOR;
  66955. };
  66956. /**
  66957. * Function: getEdgeWidth
  66958. *
  66959. * Returns the width used to draw the preview edge. This returns 3 if
  66960. * there is no edge validation error and 1 otherwise.
  66961. *
  66962. * Parameters:
  66963. *
  66964. * valid - Boolean indicating if the width for a valid edge should be
  66965. * returned.
  66966. */
  66967. mxConnectionHandler.prototype.getEdgeWidth = function(valid)
  66968. {
  66969. return (valid) ? 3 : 1;
  66970. };
  66971. /**
  66972. * Function: connect
  66973. *
  66974. * Connects the given source and target using a new edge. This
  66975. * implementation uses <createEdge> to create the edge.
  66976. *
  66977. * Parameters:
  66978. *
  66979. * source - <mxCell> that represents the source terminal.
  66980. * target - <mxCell> that represents the target terminal.
  66981. * evt - Mousedown event of the connect gesture.
  66982. * dropTarget - <mxCell> that represents the cell under the mouse when it was
  66983. * released.
  66984. */
  66985. mxConnectionHandler.prototype.connect = function(source, target, evt, dropTarget)
  66986. {
  66987. if (target != null || this.isCreateTarget(evt) || this.graph.allowDanglingEdges)
  66988. {
  66989. // Uses the common parent of source and target or
  66990. // the default parent to insert the edge
  66991. var model = this.graph.getModel();
  66992. var terminalInserted = false;
  66993. var edge = null;
  66994. model.beginUpdate();
  66995. try
  66996. {
  66997. if (source != null && target == null && !this.graph.isIgnoreTerminalEvent(evt) && this.isCreateTarget(evt))
  66998. {
  66999. target = this.createTargetVertex(evt, source);
  67000. if (target != null)
  67001. {
  67002. dropTarget = this.graph.getDropTarget([target], evt, dropTarget);
  67003. terminalInserted = true;
  67004. // Disables edges as drop targets if the target cell was created
  67005. // FIXME: Should not shift if vertex was aligned (same in Java)
  67006. if (dropTarget == null || !this.graph.getModel().isEdge(dropTarget))
  67007. {
  67008. var pstate = this.graph.getView().getState(dropTarget);
  67009. if (pstate != null)
  67010. {
  67011. var tmp = model.getGeometry(target);
  67012. tmp.x -= pstate.origin.x;
  67013. tmp.y -= pstate.origin.y;
  67014. }
  67015. }
  67016. else
  67017. {
  67018. dropTarget = this.graph.getDefaultParent();
  67019. }
  67020. this.graph.addCell(target, dropTarget);
  67021. }
  67022. }
  67023. var parent = this.graph.getDefaultParent();
  67024. if (source != null && target != null &&
  67025. model.getParent(source) == model.getParent(target) &&
  67026. model.getParent(model.getParent(source)) != model.getRoot())
  67027. {
  67028. parent = model.getParent(source);
  67029. if ((source.geometry != null && source.geometry.relative) &&
  67030. (target.geometry != null && target.geometry.relative))
  67031. {
  67032. parent = model.getParent(parent);
  67033. }
  67034. }
  67035. // Uses the value of the preview edge state for inserting
  67036. // the new edge into the graph
  67037. var value = null;
  67038. var style = null;
  67039. if (this.edgeState != null)
  67040. {
  67041. value = this.edgeState.cell.value;
  67042. style = this.edgeState.cell.style;
  67043. }
  67044. edge = this.insertEdge(parent, null, value, source, target, style);
  67045. if (edge != null)
  67046. {
  67047. // Updates the connection constraints
  67048. this.graph.setConnectionConstraint(edge, source, true, this.sourceConstraint);
  67049. this.graph.setConnectionConstraint(edge, target, false, this.constraintHandler.currentConstraint);
  67050. // Uses geometry of the preview edge state
  67051. if (this.edgeState != null)
  67052. {
  67053. model.setGeometry(edge, this.edgeState.cell.geometry);
  67054. }
  67055. var parent = model.getParent(source);
  67056. // Inserts edge before source
  67057. if (this.isInsertBefore(edge, source, target, evt, dropTarget))
  67058. {
  67059. var index = null;
  67060. var tmp = source;
  67061. while (tmp.parent != null && tmp.geometry != null &&
  67062. tmp.geometry.relative && tmp.parent != edge.parent)
  67063. {
  67064. tmp = this.graph.model.getParent(tmp);
  67065. }
  67066. if (tmp != null && tmp.parent != null && tmp.parent == edge.parent)
  67067. {
  67068. model.add(parent, edge, tmp.parent.getIndex(tmp));
  67069. }
  67070. }
  67071. // Makes sure the edge has a non-null, relative geometry
  67072. var geo = model.getGeometry(edge);
  67073. if (geo == null)
  67074. {
  67075. geo = new mxGeometry();
  67076. geo.relative = true;
  67077. model.setGeometry(edge, geo);
  67078. }
  67079. // Uses scaled waypoints in geometry
  67080. if (this.waypoints != null && this.waypoints.length > 0)
  67081. {
  67082. var s = this.graph.view.scale;
  67083. var tr = this.graph.view.translate;
  67084. geo.points = [];
  67085. for (var i = 0; i < this.waypoints.length; i++)
  67086. {
  67087. var pt = this.waypoints[i];
  67088. geo.points.push(new mxPoint(pt.x / s - tr.x, pt.y / s - tr.y));
  67089. }
  67090. }
  67091. if (target == null)
  67092. {
  67093. var t = this.graph.view.translate;
  67094. var s = this.graph.view.scale;
  67095. var pt = (this.originalPoint != null) ?
  67096. new mxPoint(this.originalPoint.x / s - t.x, this.originalPoint.y / s - t.y) :
  67097. new mxPoint(this.currentPoint.x / s - t.x, this.currentPoint.y / s - t.y);
  67098. pt.x -= this.graph.panDx / this.graph.view.scale;
  67099. pt.y -= this.graph.panDy / this.graph.view.scale;
  67100. geo.setTerminalPoint(pt, false);
  67101. }
  67102. this.fireEvent(new mxEventObject(mxEvent.CONNECT, 'cell', edge, 'terminal', target,
  67103. 'event', evt, 'target', dropTarget, 'terminalInserted', terminalInserted));
  67104. }
  67105. }
  67106. catch (e)
  67107. {
  67108. mxLog.show();
  67109. mxLog.debug(e.message);
  67110. }
  67111. finally
  67112. {
  67113. model.endUpdate();
  67114. }
  67115. if (this.select)
  67116. {
  67117. this.selectCells(edge, (terminalInserted) ? target : null);
  67118. }
  67119. }
  67120. };
  67121. /**
  67122. * Function: selectCells
  67123. *
  67124. * Selects the given edge after adding a new connection. The target argument
  67125. * contains the target vertex if one has been inserted.
  67126. */
  67127. mxConnectionHandler.prototype.selectCells = function(edge, target)
  67128. {
  67129. this.graph.setSelectionCell(edge);
  67130. };
  67131. /**
  67132. * Function: insertEdge
  67133. *
  67134. * Creates, inserts and returns the new edge for the given parameters. This
  67135. * implementation does only use <createEdge> if <factoryMethod> is defined,
  67136. * otherwise <mxGraph.insertEdge> will be used.
  67137. */
  67138. mxConnectionHandler.prototype.insertEdge = function(parent, id, value, source, target, style)
  67139. {
  67140. if (this.factoryMethod == null)
  67141. {
  67142. return this.graph.insertEdge(parent, id, value, source, target, style);
  67143. }
  67144. else
  67145. {
  67146. var edge = this.createEdge(value, source, target, style);
  67147. edge = this.graph.addEdge(edge, parent, source, target);
  67148. return edge;
  67149. }
  67150. };
  67151. /**
  67152. * Function: createTargetVertex
  67153. *
  67154. * Hook method for creating new vertices on the fly if no target was
  67155. * under the mouse. This is only called if <createTarget> is true and
  67156. * returns null.
  67157. *
  67158. * Parameters:
  67159. *
  67160. * evt - Mousedown event of the connect gesture.
  67161. * source - <mxCell> that represents the source terminal.
  67162. */
  67163. mxConnectionHandler.prototype.createTargetVertex = function(evt, source)
  67164. {
  67165. // Uses the first non-relative source
  67166. var geo = this.graph.getCellGeometry(source);
  67167. while (geo != null && geo.relative)
  67168. {
  67169. source = this.graph.getModel().getParent(source);
  67170. geo = this.graph.getCellGeometry(source);
  67171. }
  67172. var clone = this.graph.cloneCell(source);
  67173. var geo = this.graph.getModel().getGeometry(clone);
  67174. if (geo != null)
  67175. {
  67176. var t = this.graph.view.translate;
  67177. var s = this.graph.view.scale;
  67178. var point = new mxPoint(this.currentPoint.x / s - t.x, this.currentPoint.y / s - t.y);
  67179. geo.x = Math.round(point.x - geo.width / 2 - this.graph.panDx / s);
  67180. geo.y = Math.round(point.y - geo.height / 2 - this.graph.panDy / s);
  67181. // Aligns with source if within certain tolerance
  67182. var tol = this.getAlignmentTolerance();
  67183. if (tol > 0)
  67184. {
  67185. var sourceState = this.graph.view.getState(source);
  67186. if (sourceState != null)
  67187. {
  67188. var x = sourceState.x / s - t.x;
  67189. var y = sourceState.y / s - t.y;
  67190. if (Math.abs(x - geo.x) <= tol)
  67191. {
  67192. geo.x = Math.round(x);
  67193. }
  67194. if (Math.abs(y - geo.y) <= tol)
  67195. {
  67196. geo.y = Math.round(y);
  67197. }
  67198. }
  67199. }
  67200. }
  67201. return clone;
  67202. };
  67203. /**
  67204. * Function: getAlignmentTolerance
  67205. *
  67206. * Returns the tolerance for aligning new targets to sources. This returns the grid size / 2.
  67207. */
  67208. mxConnectionHandler.prototype.getAlignmentTolerance = function(evt)
  67209. {
  67210. return (this.graph.isGridEnabled()) ? this.graph.gridSize / 2 : this.graph.tolerance;
  67211. };
  67212. /**
  67213. * Function: createEdge
  67214. *
  67215. * Creates and returns a new edge using <factoryMethod> if one exists. If
  67216. * no factory method is defined, then a new default edge is returned. The
  67217. * source and target arguments are informal, the actual connection is
  67218. * setup later by the caller of this function.
  67219. *
  67220. * Parameters:
  67221. *
  67222. * value - Value to be used for creating the edge.
  67223. * source - <mxCell> that represents the source terminal.
  67224. * target - <mxCell> that represents the target terminal.
  67225. * style - Optional style from the preview edge.
  67226. */
  67227. mxConnectionHandler.prototype.createEdge = function(value, source, target, style)
  67228. {
  67229. var edge = null;
  67230. // Creates a new edge using the factoryMethod
  67231. if (this.factoryMethod != null)
  67232. {
  67233. edge = this.factoryMethod(source, target, style);
  67234. }
  67235. if (edge == null)
  67236. {
  67237. edge = new mxCell(value || '');
  67238. edge.setEdge(true);
  67239. edge.setStyle(style);
  67240. var geo = new mxGeometry();
  67241. geo.relative = true;
  67242. edge.setGeometry(geo);
  67243. }
  67244. return edge;
  67245. };
  67246. /**
  67247. * Function: destroy
  67248. *
  67249. * Destroys the handler and all its resources and DOM nodes. This should be
  67250. * called on all instances. It is called automatically for the built-in
  67251. * instance created for each <mxGraph>.
  67252. */
  67253. mxConnectionHandler.prototype.destroy = function()
  67254. {
  67255. this.graph.removeMouseListener(this);
  67256. if (this.shape != null)
  67257. {
  67258. this.shape.destroy();
  67259. this.shape = null;
  67260. }
  67261. if (this.marker != null)
  67262. {
  67263. this.marker.destroy();
  67264. this.marker = null;
  67265. }
  67266. if (this.constraintHandler != null)
  67267. {
  67268. this.constraintHandler.destroy();
  67269. this.constraintHandler = null;
  67270. }
  67271. if (this.changeHandler != null)
  67272. {
  67273. this.graph.getModel().removeListener(this.changeHandler);
  67274. this.graph.getView().removeListener(this.changeHandler);
  67275. this.changeHandler = null;
  67276. }
  67277. if (this.drillHandler != null)
  67278. {
  67279. this.graph.removeListener(this.drillHandler);
  67280. this.graph.getView().removeListener(this.drillHandler);
  67281. this.drillHandler = null;
  67282. }
  67283. if (this.escapeHandler != null)
  67284. {
  67285. this.graph.removeListener(this.escapeHandler);
  67286. this.escapeHandler = null;
  67287. }
  67288. };
  67289. /**
  67290. * Copyright (c) 2006-2015, JGraph Ltd
  67291. * Copyright (c) 2006-2015, Gaudenz Alder
  67292. */
  67293. /**
  67294. * Class: mxConstraintHandler
  67295. *
  67296. * Handles constraints on connection targets. This class is in charge of
  67297. * showing fixed points when the mouse is over a vertex and handles constraints
  67298. * to establish new connections.
  67299. *
  67300. * Constructor: mxConstraintHandler
  67301. *
  67302. * Constructs an new constraint handler.
  67303. *
  67304. * Parameters:
  67305. *
  67306. * graph - Reference to the enclosing <mxGraph>.
  67307. * factoryMethod - Optional function to create the edge. The function takes
  67308. * the source and target <mxCell> as the first and second argument and
  67309. * returns the <mxCell> that represents the new edge.
  67310. */
  67311. function mxConstraintHandler(graph)
  67312. {
  67313. this.graph = graph;
  67314. // Adds a graph model listener to update the current focus on changes
  67315. this.resetHandler = mxUtils.bind(this, function(sender, evt)
  67316. {
  67317. if (this.currentFocus != null && this.graph.view.getState(this.currentFocus.cell) == null)
  67318. {
  67319. this.reset();
  67320. }
  67321. else
  67322. {
  67323. this.redraw();
  67324. }
  67325. });
  67326. this.graph.model.addListener(mxEvent.CHANGE, this.resetHandler);
  67327. this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.resetHandler);
  67328. this.graph.view.addListener(mxEvent.TRANSLATE, this.resetHandler);
  67329. this.graph.view.addListener(mxEvent.SCALE, this.resetHandler);
  67330. this.graph.addListener(mxEvent.ROOT, this.resetHandler);
  67331. };
  67332. /**
  67333. * Variable: pointImage
  67334. *
  67335. * <mxImage> to be used as the image for fixed connection points.
  67336. */
  67337. mxConstraintHandler.prototype.pointImage = new mxImage(mxClient.imageBasePath + '/point.gif', 5, 5);
  67338. /**
  67339. * Variable: graph
  67340. *
  67341. * Reference to the enclosing <mxGraph>.
  67342. */
  67343. mxConstraintHandler.prototype.graph = null;
  67344. /**
  67345. * Variable: enabled
  67346. *
  67347. * Specifies if events are handled. Default is true.
  67348. */
  67349. mxConstraintHandler.prototype.enabled = true;
  67350. /**
  67351. * Variable: highlightColor
  67352. *
  67353. * Specifies the color for the highlight. Default is <mxConstants.DEFAULT_VALID_COLOR>.
  67354. */
  67355. mxConstraintHandler.prototype.highlightColor = mxConstants.DEFAULT_VALID_COLOR;
  67356. /**
  67357. * Function: isEnabled
  67358. *
  67359. * Returns true if events are handled. This implementation
  67360. * returns <enabled>.
  67361. */
  67362. mxConstraintHandler.prototype.isEnabled = function()
  67363. {
  67364. return this.enabled;
  67365. };
  67366. /**
  67367. * Function: setEnabled
  67368. *
  67369. * Enables or disables event handling. This implementation
  67370. * updates <enabled>.
  67371. *
  67372. * Parameters:
  67373. *
  67374. * enabled - Boolean that specifies the new enabled state.
  67375. */
  67376. mxConstraintHandler.prototype.setEnabled = function(enabled)
  67377. {
  67378. this.enabled = enabled;
  67379. };
  67380. /**
  67381. * Function: reset
  67382. *
  67383. * Resets the state of this handler.
  67384. */
  67385. mxConstraintHandler.prototype.reset = function()
  67386. {
  67387. if (this.focusIcons != null)
  67388. {
  67389. for (var i = 0; i < this.focusIcons.length; i++)
  67390. {
  67391. this.focusIcons[i].destroy();
  67392. }
  67393. this.focusIcons = null;
  67394. }
  67395. if (this.focusHighlight != null)
  67396. {
  67397. this.focusHighlight.destroy();
  67398. this.focusHighlight = null;
  67399. }
  67400. this.currentConstraint = null;
  67401. this.currentFocusArea = null;
  67402. this.currentPoint = null;
  67403. this.currentFocus = null;
  67404. this.focusPoints = null;
  67405. };
  67406. /**
  67407. * Function: getTolerance
  67408. *
  67409. * Returns the tolerance to be used for intersecting connection points. This
  67410. * implementation returns <mxGraph.tolerance>.
  67411. *
  67412. * Parameters:
  67413. *
  67414. * me - <mxMouseEvent> whose tolerance should be returned.
  67415. */
  67416. mxConstraintHandler.prototype.getTolerance = function(me)
  67417. {
  67418. return this.graph.getTolerance();
  67419. };
  67420. /**
  67421. * Function: getImageForConstraint
  67422. *
  67423. * Returns the tolerance to be used for intersecting connection points.
  67424. */
  67425. mxConstraintHandler.prototype.getImageForConstraint = function(state, constraint, point)
  67426. {
  67427. return this.pointImage;
  67428. };
  67429. /**
  67430. * Function: isEventIgnored
  67431. *
  67432. * Returns true if the given <mxMouseEvent> should be ignored in <update>. This
  67433. * implementation always returns false.
  67434. */
  67435. mxConstraintHandler.prototype.isEventIgnored = function(me, source)
  67436. {
  67437. return false;
  67438. };
  67439. /**
  67440. * Function: isStateIgnored
  67441. *
  67442. * Returns true if the given state should be ignored. This always returns false.
  67443. */
  67444. mxConstraintHandler.prototype.isStateIgnored = function(state, source)
  67445. {
  67446. return false;
  67447. };
  67448. /**
  67449. * Function: destroyIcons
  67450. *
  67451. * Destroys the <focusIcons> if they exist.
  67452. */
  67453. mxConstraintHandler.prototype.destroyIcons = function()
  67454. {
  67455. if (this.focusIcons != null)
  67456. {
  67457. for (var i = 0; i < this.focusIcons.length; i++)
  67458. {
  67459. this.focusIcons[i].destroy();
  67460. }
  67461. this.focusIcons = null;
  67462. this.focusPoints = null;
  67463. }
  67464. };
  67465. /**
  67466. * Function: destroyFocusHighlight
  67467. *
  67468. * Destroys the <focusHighlight> if one exists.
  67469. */
  67470. mxConstraintHandler.prototype.destroyFocusHighlight = function()
  67471. {
  67472. if (this.focusHighlight != null)
  67473. {
  67474. this.focusHighlight.destroy();
  67475. this.focusHighlight = null;
  67476. }
  67477. };
  67478. /**
  67479. * Function: isKeepFocusEvent
  67480. *
  67481. * Returns true if the current focused state should not be changed for the given event.
  67482. * This returns true if shift and alt are pressed.
  67483. */
  67484. mxConstraintHandler.prototype.isKeepFocusEvent = function(me)
  67485. {
  67486. return mxEvent.isShiftDown(me.getEvent());
  67487. };
  67488. /**
  67489. * Function: getCellForEvent
  67490. *
  67491. * Returns the cell for the given event.
  67492. */
  67493. mxConstraintHandler.prototype.getCellForEvent = function(me, point)
  67494. {
  67495. var cell = me.getCell();
  67496. // Gets cell under actual point if different from event location
  67497. if (cell == null && point != null && (me.getGraphX() != point.x || me.getGraphY() != point.y))
  67498. {
  67499. cell = this.graph.getCellAt(point.x, point.y);
  67500. }
  67501. // Uses connectable parent vertex if one exists
  67502. if (cell != null && !this.graph.isCellConnectable(cell))
  67503. {
  67504. var parent = this.graph.getModel().getParent(cell);
  67505. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  67506. {
  67507. cell = parent;
  67508. }
  67509. }
  67510. return (this.graph.isCellLocked(cell)) ? null : cell;
  67511. };
  67512. /**
  67513. * Function: update
  67514. *
  67515. * Updates the state of this handler based on the given <mxMouseEvent>.
  67516. * Source is a boolean indicating if the cell is a source or target.
  67517. */
  67518. mxConstraintHandler.prototype.update = function(me, source, existingEdge, point)
  67519. {
  67520. if (this.isEnabled() && !this.isEventIgnored(me))
  67521. {
  67522. // Lazy installation of mouseleave handler
  67523. if (this.mouseleaveHandler == null && this.graph.container != null)
  67524. {
  67525. this.mouseleaveHandler = mxUtils.bind(this, function()
  67526. {
  67527. this.reset();
  67528. });
  67529. mxEvent.addListener(this.graph.container, 'mouseleave', this.resetHandler);
  67530. }
  67531. var tol = this.getTolerance(me);
  67532. var x = (point != null) ? point.x : me.getGraphX();
  67533. var y = (point != null) ? point.y : me.getGraphY();
  67534. var grid = new mxRectangle(x - tol, y - tol, 2 * tol, 2 * tol);
  67535. var mouse = new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol);
  67536. var state = this.graph.view.getState(this.getCellForEvent(me, point));
  67537. // Keeps focus icons visible while over vertex bounds and no other cell under mouse or shift is pressed
  67538. if (!this.isKeepFocusEvent(me) && (this.currentFocusArea == null || this.currentFocus == null ||
  67539. (state != null) || !this.graph.getModel().isVertex(this.currentFocus.cell) ||
  67540. !mxUtils.intersects(this.currentFocusArea, mouse)) && (state != this.currentFocus))
  67541. {
  67542. this.currentFocusArea = null;
  67543. this.currentFocus = null;
  67544. this.setFocus(me, state, source);
  67545. }
  67546. this.currentConstraint = null;
  67547. this.currentPoint = null;
  67548. var minDistSq = null;
  67549. if (this.focusIcons != null && this.constraints != null &&
  67550. (state == null || this.currentFocus == state))
  67551. {
  67552. var cx = mouse.getCenterX();
  67553. var cy = mouse.getCenterY();
  67554. for (var i = 0; i < this.focusIcons.length; i++)
  67555. {
  67556. var dx = cx - this.focusIcons[i].bounds.getCenterX();
  67557. var dy = cy - this.focusIcons[i].bounds.getCenterY();
  67558. var tmp = dx * dx + dy * dy;
  67559. if ((this.intersects(this.focusIcons[i], mouse, source, existingEdge) || (point != null &&
  67560. this.intersects(this.focusIcons[i], grid, source, existingEdge))) &&
  67561. (minDistSq == null || tmp < minDistSq))
  67562. {
  67563. this.currentConstraint = this.constraints[i];
  67564. this.currentPoint = this.focusPoints[i];
  67565. minDistSq = tmp;
  67566. var tmp = this.focusIcons[i].bounds.clone();
  67567. tmp.grow(mxConstants.HIGHLIGHT_SIZE + 1);
  67568. tmp.width -= 1;
  67569. tmp.height -= 1;
  67570. if (this.focusHighlight == null)
  67571. {
  67572. var hl = this.createHighlightShape();
  67573. hl.dialect = (this.graph.dialect == mxConstants.DIALECT_SVG) ?
  67574. mxConstants.DIALECT_SVG : mxConstants.DIALECT_VML;
  67575. hl.pointerEvents = false;
  67576. hl.init(this.graph.getView().getOverlayPane());
  67577. this.focusHighlight = hl;
  67578. var getState = mxUtils.bind(this, function()
  67579. {
  67580. return (this.currentFocus != null) ? this.currentFocus : state;
  67581. });
  67582. mxEvent.redirectMouseEvents(hl.node, this.graph, getState);
  67583. }
  67584. this.focusHighlight.bounds = tmp;
  67585. this.focusHighlight.redraw();
  67586. }
  67587. }
  67588. }
  67589. if (this.currentConstraint == null)
  67590. {
  67591. this.destroyFocusHighlight();
  67592. }
  67593. }
  67594. else
  67595. {
  67596. this.currentConstraint = null;
  67597. this.currentFocus = null;
  67598. this.currentPoint = null;
  67599. }
  67600. };
  67601. /**
  67602. * Function: redraw
  67603. *
  67604. * Transfers the focus to the given state as a source or target terminal. If
  67605. * the handler is not enabled then the outline is painted, but the constraints
  67606. * are ignored.
  67607. */
  67608. mxConstraintHandler.prototype.redraw = function()
  67609. {
  67610. if (this.currentFocus != null && this.constraints != null && this.focusIcons != null)
  67611. {
  67612. var state = this.graph.view.getState(this.currentFocus.cell);
  67613. this.currentFocus = state;
  67614. this.currentFocusArea = new mxRectangle(state.x, state.y, state.width, state.height);
  67615. for (var i = 0; i < this.constraints.length; i++)
  67616. {
  67617. var cp = this.graph.getConnectionPoint(state, this.constraints[i]);
  67618. var img = this.getImageForConstraint(state, this.constraints[i], cp);
  67619. var bounds = new mxRectangle(Math.round(cp.x - img.width / 2),
  67620. Math.round(cp.y - img.height / 2), img.width, img.height);
  67621. this.focusIcons[i].bounds = bounds;
  67622. this.focusIcons[i].redraw();
  67623. this.currentFocusArea.add(this.focusIcons[i].bounds);
  67624. this.focusPoints[i] = cp;
  67625. }
  67626. }
  67627. };
  67628. /**
  67629. * Function: setFocus
  67630. *
  67631. * Transfers the focus to the given state as a source or target terminal. If
  67632. * the handler is not enabled then the outline is painted, but the constraints
  67633. * are ignored.
  67634. */
  67635. mxConstraintHandler.prototype.setFocus = function(me, state, source)
  67636. {
  67637. this.constraints = (state != null && !this.isStateIgnored(state, source) &&
  67638. this.graph.isCellConnectable(state.cell)) ? ((this.isEnabled()) ?
  67639. (this.graph.getAllConnectionConstraints(state, source) || []) : []) : null;
  67640. // Only uses cells which have constraints
  67641. if (this.constraints != null)
  67642. {
  67643. this.currentFocus = state;
  67644. this.currentFocusArea = new mxRectangle(state.x, state.y, state.width, state.height);
  67645. if (this.focusIcons != null)
  67646. {
  67647. for (var i = 0; i < this.focusIcons.length; i++)
  67648. {
  67649. this.focusIcons[i].destroy();
  67650. }
  67651. this.focusIcons = null;
  67652. this.focusPoints = null;
  67653. }
  67654. this.focusPoints = [];
  67655. this.focusIcons = [];
  67656. for (var i = 0; i < this.constraints.length; i++)
  67657. {
  67658. var cp = this.graph.getConnectionPoint(state, this.constraints[i]);
  67659. var img = this.getImageForConstraint(state, this.constraints[i], cp);
  67660. var src = img.src;
  67661. var bounds = new mxRectangle(Math.round(cp.x - img.width / 2),
  67662. Math.round(cp.y - img.height / 2), img.width, img.height);
  67663. var icon = new mxImageShape(bounds, src);
  67664. icon.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  67665. mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
  67666. icon.preserveImageAspect = false;
  67667. icon.init(this.graph.getView().getDecoratorPane());
  67668. // Fixes lost event tracking for images in quirks / IE8 standards
  67669. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  67670. {
  67671. mxEvent.addListener(icon.node, 'dragstart', function(evt)
  67672. {
  67673. mxEvent.consume(evt);
  67674. return false;
  67675. });
  67676. }
  67677. // Move the icon behind all other overlays
  67678. if (icon.node.previousSibling != null)
  67679. {
  67680. icon.node.parentNode.insertBefore(icon.node, icon.node.parentNode.firstChild);
  67681. }
  67682. var getState = mxUtils.bind(this, function()
  67683. {
  67684. return (this.currentFocus != null) ? this.currentFocus : state;
  67685. });
  67686. icon.redraw();
  67687. mxEvent.redirectMouseEvents(icon.node, this.graph, getState);
  67688. this.currentFocusArea.add(icon.bounds);
  67689. this.focusIcons.push(icon);
  67690. this.focusPoints.push(cp);
  67691. }
  67692. this.currentFocusArea.grow(this.getTolerance(me));
  67693. }
  67694. else
  67695. {
  67696. this.destroyIcons();
  67697. this.destroyFocusHighlight();
  67698. }
  67699. };
  67700. /**
  67701. * Function: createHighlightShape
  67702. *
  67703. * Create the shape used to paint the highlight.
  67704. *
  67705. * Returns true if the given icon intersects the given point.
  67706. */
  67707. mxConstraintHandler.prototype.createHighlightShape = function()
  67708. {
  67709. var hl = new mxRectangleShape(null, this.highlightColor, this.highlightColor, mxConstants.HIGHLIGHT_STROKEWIDTH);
  67710. hl.opacity = mxConstants.HIGHLIGHT_OPACITY;
  67711. return hl;
  67712. };
  67713. /**
  67714. * Function: intersects
  67715. *
  67716. * Returns true if the given icon intersects the given rectangle.
  67717. */
  67718. mxConstraintHandler.prototype.intersects = function(icon, mouse, source, existingEdge)
  67719. {
  67720. return mxUtils.intersects(icon.bounds, mouse);
  67721. };
  67722. /**
  67723. * Function: destroy
  67724. *
  67725. * Destroy this handler.
  67726. */
  67727. mxConstraintHandler.prototype.destroy = function()
  67728. {
  67729. this.reset();
  67730. if (this.resetHandler != null)
  67731. {
  67732. this.graph.model.removeListener(this.resetHandler);
  67733. this.graph.view.removeListener(this.resetHandler);
  67734. this.graph.removeListener(this.resetHandler);
  67735. this.resetHandler = null;
  67736. }
  67737. if (this.mouseleaveHandler != null && this.graph.container != null)
  67738. {
  67739. mxEvent.removeListener(this.graph.container, 'mouseleave', this.mouseleaveHandler);
  67740. this.mouseleaveHandler = null;
  67741. }
  67742. };
  67743. /**
  67744. * Copyright (c) 2006-2016, JGraph Ltd
  67745. * Copyright (c) 2006-2016, Gaudenz Alder
  67746. */
  67747. /**
  67748. * Class: mxRubberband
  67749. *
  67750. * Event handler that selects rectangular regions. This is not built-into
  67751. * <mxGraph>. To enable rubberband selection in a graph, use the following code.
  67752. *
  67753. * Example:
  67754. *
  67755. * (code)
  67756. * var rubberband = new mxRubberband(graph);
  67757. * (end)
  67758. *
  67759. * Constructor: mxRubberband
  67760. *
  67761. * Constructs an event handler that selects rectangular regions in the graph
  67762. * using rubberband selection.
  67763. */
  67764. function mxRubberband(graph)
  67765. {
  67766. if (graph != null)
  67767. {
  67768. this.graph = graph;
  67769. this.graph.addMouseListener(this);
  67770. // Handles force rubberband event
  67771. this.forceRubberbandHandler = mxUtils.bind(this, function(sender, evt)
  67772. {
  67773. var evtName = evt.getProperty('eventName');
  67774. var me = evt.getProperty('event');
  67775. if (evtName == mxEvent.MOUSE_DOWN && this.isForceRubberbandEvent(me))
  67776. {
  67777. var offset = mxUtils.getOffset(this.graph.container);
  67778. var origin = mxUtils.getScrollOrigin(this.graph.container);
  67779. origin.x -= offset.x;
  67780. origin.y -= offset.y;
  67781. this.start(me.getX() + origin.x, me.getY() + origin.y);
  67782. me.consume(false);
  67783. }
  67784. });
  67785. this.graph.addListener(mxEvent.FIRE_MOUSE_EVENT, this.forceRubberbandHandler);
  67786. // Repaints the marquee after autoscroll
  67787. this.panHandler = mxUtils.bind(this, function()
  67788. {
  67789. this.repaint();
  67790. });
  67791. this.graph.addListener(mxEvent.PAN, this.panHandler);
  67792. // Does not show menu if any touch gestures take place after the trigger
  67793. this.gestureHandler = mxUtils.bind(this, function(sender, eo)
  67794. {
  67795. if (this.first != null)
  67796. {
  67797. this.reset();
  67798. }
  67799. });
  67800. this.graph.addListener(mxEvent.GESTURE, this.gestureHandler);
  67801. // Automatic deallocation of memory
  67802. if (mxClient.IS_IE)
  67803. {
  67804. mxEvent.addListener(window, 'unload',
  67805. mxUtils.bind(this, function()
  67806. {
  67807. this.destroy();
  67808. })
  67809. );
  67810. }
  67811. }
  67812. };
  67813. /**
  67814. * Variable: defaultOpacity
  67815. *
  67816. * Specifies the default opacity to be used for the rubberband div. Default
  67817. * is 20.
  67818. */
  67819. mxRubberband.prototype.defaultOpacity = 20;
  67820. /**
  67821. * Variable: enabled
  67822. *
  67823. * Specifies if events are handled. Default is true.
  67824. */
  67825. mxRubberband.prototype.enabled = true;
  67826. /**
  67827. * Variable: div
  67828. *
  67829. * Holds the DIV element which is currently visible.
  67830. */
  67831. mxRubberband.prototype.div = null;
  67832. /**
  67833. * Variable: sharedDiv
  67834. *
  67835. * Holds the DIV element which is used to display the rubberband.
  67836. */
  67837. mxRubberband.prototype.sharedDiv = null;
  67838. /**
  67839. * Variable: currentX
  67840. *
  67841. * Holds the value of the x argument in the last call to <update>.
  67842. */
  67843. mxRubberband.prototype.currentX = 0;
  67844. /**
  67845. * Variable: currentY
  67846. *
  67847. * Holds the value of the y argument in the last call to <update>.
  67848. */
  67849. mxRubberband.prototype.currentY = 0;
  67850. /**
  67851. * Variable: fadeOut
  67852. *
  67853. * Optional fade out effect. Default is false.
  67854. */
  67855. mxRubberband.prototype.fadeOut = false;
  67856. /**
  67857. * Function: isEnabled
  67858. *
  67859. * Returns true if events are handled. This implementation returns
  67860. * <enabled>.
  67861. */
  67862. mxRubberband.prototype.isEnabled = function()
  67863. {
  67864. return this.enabled;
  67865. };
  67866. /**
  67867. * Function: setEnabled
  67868. *
  67869. * Enables or disables event handling. This implementation updates
  67870. * <enabled>.
  67871. */
  67872. mxRubberband.prototype.setEnabled = function(enabled)
  67873. {
  67874. this.enabled = enabled;
  67875. };
  67876. /**
  67877. * Function: isForceRubberbandEvent
  67878. *
  67879. * Returns true if the given <mxMouseEvent> should start rubberband selection.
  67880. * This implementation returns true if the alt key is pressed.
  67881. */
  67882. mxRubberband.prototype.isForceRubberbandEvent = function(me)
  67883. {
  67884. return mxEvent.isAltDown(me.getEvent());
  67885. };
  67886. /**
  67887. * Function: mouseDown
  67888. *
  67889. * Handles the event by initiating a rubberband selection. By consuming the
  67890. * event all subsequent events of the gesture are redirected to this
  67891. * handler.
  67892. */
  67893. mxRubberband.prototype.mouseDown = function(sender, me)
  67894. {
  67895. if (!me.isConsumed() && this.isEnabled() && this.graph.isEnabled() &&
  67896. me.getState() == null && !mxEvent.isMultiTouchEvent(me.getEvent()))
  67897. {
  67898. var offset = mxUtils.getOffset(this.graph.container);
  67899. var origin = mxUtils.getScrollOrigin(this.graph.container);
  67900. origin.x -= offset.x;
  67901. origin.y -= offset.y;
  67902. this.start(me.getX() + origin.x, me.getY() + origin.y);
  67903. // Does not prevent the default for this event so that the
  67904. // event processing chain is still executed even if we start
  67905. // rubberbanding. This is required eg. in ExtJs to hide the
  67906. // current context menu. In mouseMove we'll make sure we're
  67907. // not selecting anything while we're rubberbanding.
  67908. me.consume(false);
  67909. }
  67910. };
  67911. /**
  67912. * Function: start
  67913. *
  67914. * Sets the start point for the rubberband selection.
  67915. */
  67916. mxRubberband.prototype.start = function(x, y)
  67917. {
  67918. this.first = new mxPoint(x, y);
  67919. var container = this.graph.container;
  67920. function createMouseEvent(evt)
  67921. {
  67922. var me = new mxMouseEvent(evt);
  67923. var pt = mxUtils.convertPoint(container, me.getX(), me.getY());
  67924. me.graphX = pt.x;
  67925. me.graphY = pt.y;
  67926. return me;
  67927. };
  67928. this.dragHandler = mxUtils.bind(this, function(evt)
  67929. {
  67930. this.mouseMove(this.graph, createMouseEvent(evt));
  67931. });
  67932. this.dropHandler = mxUtils.bind(this, function(evt)
  67933. {
  67934. this.mouseUp(this.graph, createMouseEvent(evt));
  67935. });
  67936. // Workaround for rubberband stopping if the mouse leaves the container in Firefox
  67937. if (mxClient.IS_FF)
  67938. {
  67939. mxEvent.addGestureListeners(document, null, this.dragHandler, this.dropHandler);
  67940. }
  67941. };
  67942. /**
  67943. * Function: mouseMove
  67944. *
  67945. * Handles the event by updating therubberband selection.
  67946. */
  67947. mxRubberband.prototype.mouseMove = function(sender, me)
  67948. {
  67949. if (!me.isConsumed() && this.first != null)
  67950. {
  67951. var origin = mxUtils.getScrollOrigin(this.graph.container);
  67952. var offset = mxUtils.getOffset(this.graph.container);
  67953. origin.x -= offset.x;
  67954. origin.y -= offset.y;
  67955. var x = me.getX() + origin.x;
  67956. var y = me.getY() + origin.y;
  67957. var dx = this.first.x - x;
  67958. var dy = this.first.y - y;
  67959. var tol = this.graph.tolerance;
  67960. if (this.div != null || Math.abs(dx) > tol || Math.abs(dy) > tol)
  67961. {
  67962. if (this.div == null)
  67963. {
  67964. this.div = this.createShape();
  67965. }
  67966. // Clears selection while rubberbanding. This is required because
  67967. // the event is not consumed in mouseDown.
  67968. mxUtils.clearSelection();
  67969. this.update(x, y);
  67970. me.consume();
  67971. }
  67972. }
  67973. };
  67974. /**
  67975. * Function: createShape
  67976. *
  67977. * Creates the rubberband selection shape.
  67978. */
  67979. mxRubberband.prototype.createShape = function()
  67980. {
  67981. if (this.sharedDiv == null)
  67982. {
  67983. this.sharedDiv = document.createElement('div');
  67984. this.sharedDiv.className = 'mxRubberband';
  67985. mxUtils.setOpacity(this.sharedDiv, this.defaultOpacity);
  67986. }
  67987. this.graph.container.appendChild(this.sharedDiv);
  67988. var result = this.sharedDiv;
  67989. if (mxClient.IS_SVG && (!mxClient.IS_IE || document.documentMode >= 10) && this.fadeOut)
  67990. {
  67991. this.sharedDiv = null;
  67992. }
  67993. return result;
  67994. };
  67995. /**
  67996. * Function: isActive
  67997. *
  67998. * Returns true if this handler is active.
  67999. */
  68000. mxRubberband.prototype.isActive = function(sender, me)
  68001. {
  68002. return this.div != null && this.div.style.display != 'none';
  68003. };
  68004. /**
  68005. * Function: mouseUp
  68006. *
  68007. * Handles the event by selecting the region of the rubberband using
  68008. * <mxGraph.selectRegion>.
  68009. */
  68010. mxRubberband.prototype.mouseUp = function(sender, me)
  68011. {
  68012. var active = this.isActive();
  68013. this.reset();
  68014. if (active)
  68015. {
  68016. this.execute(me.getEvent());
  68017. me.consume();
  68018. }
  68019. };
  68020. /**
  68021. * Function: execute
  68022. *
  68023. * Resets the state of this handler and selects the current region
  68024. * for the given event.
  68025. */
  68026. mxRubberband.prototype.execute = function(evt)
  68027. {
  68028. var rect = new mxRectangle(this.x, this.y, this.width, this.height);
  68029. this.graph.selectRegion(rect, evt);
  68030. };
  68031. /**
  68032. * Function: reset
  68033. *
  68034. * Resets the state of the rubberband selection.
  68035. */
  68036. mxRubberband.prototype.reset = function()
  68037. {
  68038. if (this.div != null)
  68039. {
  68040. if (mxClient.IS_SVG && (!mxClient.IS_IE || document.documentMode >= 10) && this.fadeOut)
  68041. {
  68042. var temp = this.div;
  68043. mxUtils.setPrefixedStyle(temp.style, 'transition', 'all 0.2s linear');
  68044. temp.style.pointerEvents = 'none';
  68045. temp.style.opacity = 0;
  68046. window.setTimeout(function()
  68047. {
  68048. temp.parentNode.removeChild(temp);
  68049. }, 200);
  68050. }
  68051. else
  68052. {
  68053. this.div.parentNode.removeChild(this.div);
  68054. }
  68055. }
  68056. mxEvent.removeGestureListeners(document, null, this.dragHandler, this.dropHandler);
  68057. this.dragHandler = null;
  68058. this.dropHandler = null;
  68059. this.currentX = 0;
  68060. this.currentY = 0;
  68061. this.first = null;
  68062. this.div = null;
  68063. };
  68064. /**
  68065. * Function: update
  68066. *
  68067. * Sets <currentX> and <currentY> and calls <repaint>.
  68068. */
  68069. mxRubberband.prototype.update = function(x, y)
  68070. {
  68071. this.currentX = x;
  68072. this.currentY = y;
  68073. this.repaint();
  68074. };
  68075. /**
  68076. * Function: repaint
  68077. *
  68078. * Computes the bounding box and updates the style of the <div>.
  68079. */
  68080. mxRubberband.prototype.repaint = function()
  68081. {
  68082. if (this.div != null)
  68083. {
  68084. var x = this.currentX - this.graph.panDx;
  68085. var y = this.currentY - this.graph.panDy;
  68086. this.x = Math.min(this.first.x, x);
  68087. this.y = Math.min(this.first.y, y);
  68088. this.width = Math.max(this.first.x, x) - this.x;
  68089. this.height = Math.max(this.first.y, y) - this.y;
  68090. var dx = (mxClient.IS_VML) ? this.graph.panDx : 0;
  68091. var dy = (mxClient.IS_VML) ? this.graph.panDy : 0;
  68092. this.div.style.left = (this.x + dx) + 'px';
  68093. this.div.style.top = (this.y + dy) + 'px';
  68094. this.div.style.width = Math.max(1, this.width) + 'px';
  68095. this.div.style.height = Math.max(1, this.height) + 'px';
  68096. }
  68097. };
  68098. /**
  68099. * Function: destroy
  68100. *
  68101. * Destroys the handler and all its resources and DOM nodes. This does
  68102. * normally not need to be called, it is called automatically when the
  68103. * window unloads.
  68104. */
  68105. mxRubberband.prototype.destroy = function()
  68106. {
  68107. if (!this.destroyed)
  68108. {
  68109. this.destroyed = true;
  68110. this.graph.removeMouseListener(this);
  68111. this.graph.removeListener(this.forceRubberbandHandler);
  68112. this.graph.removeListener(this.panHandler);
  68113. this.reset();
  68114. if (this.sharedDiv != null)
  68115. {
  68116. this.sharedDiv = null;
  68117. }
  68118. }
  68119. };
  68120. /**
  68121. * Copyright (c) 2006-2015, JGraph Ltd
  68122. * Copyright (c) 2006-2015, Gaudenz Alder
  68123. */
  68124. /**
  68125. * Class: mxHandle
  68126. *
  68127. * Implements a single custom handle for vertices.
  68128. *
  68129. * Constructor: mxHandle
  68130. *
  68131. * Constructs a new handle for the given state.
  68132. *
  68133. * Parameters:
  68134. *
  68135. * state - <mxCellState> of the cell to be handled.
  68136. */
  68137. function mxHandle(state, cursor, image, shape)
  68138. {
  68139. this.graph = state.view.graph;
  68140. this.state = state;
  68141. this.cursor = (cursor != null) ? cursor : this.cursor;
  68142. this.image = (image != null) ? image : this.image;
  68143. this.shape = (shape != null) ? shape : null;
  68144. this.init();
  68145. };
  68146. /**
  68147. * Variable: cursor
  68148. *
  68149. * Specifies the cursor to be used for this handle. Default is 'default'.
  68150. */
  68151. mxHandle.prototype.cursor = 'default';
  68152. /**
  68153. * Variable: image
  68154. *
  68155. * Specifies the <mxImage> to be used to render the handle. Default is null.
  68156. */
  68157. mxHandle.prototype.image = null;
  68158. /**
  68159. * Variable: ignoreGrid
  68160. *
  68161. * Default is false.
  68162. */
  68163. mxHandle.prototype.ignoreGrid = false;
  68164. /**
  68165. * Function: getPosition
  68166. *
  68167. * Hook for subclassers to return the current position of the handle.
  68168. */
  68169. mxHandle.prototype.getPosition = function(bounds) { };
  68170. /**
  68171. * Function: setPosition
  68172. *
  68173. * Hooks for subclassers to update the style in the <state>.
  68174. */
  68175. mxHandle.prototype.setPosition = function(bounds, pt, me) { };
  68176. /**
  68177. * Function: execute
  68178. *
  68179. * Hook for subclassers to execute the handle.
  68180. */
  68181. mxHandle.prototype.execute = function(me) { };
  68182. /**
  68183. * Function: copyStyle
  68184. *
  68185. * Sets the cell style with the given name to the corresponding value in <state>.
  68186. */
  68187. mxHandle.prototype.copyStyle = function(key)
  68188. {
  68189. this.graph.setCellStyles(key, this.state.style[key], [this.state.cell]);
  68190. };
  68191. /**
  68192. * Function: processEvent
  68193. *
  68194. * Processes the given <mxMouseEvent> and invokes <setPosition>.
  68195. */
  68196. mxHandle.prototype.processEvent = function(me)
  68197. {
  68198. var scale = this.graph.view.scale;
  68199. var tr = this.graph.view.translate;
  68200. var pt = new mxPoint(me.getGraphX() / scale - tr.x, me.getGraphY() / scale - tr.y);
  68201. // Center shape on mouse cursor
  68202. if (this.shape != null && this.shape.bounds != null)
  68203. {
  68204. pt.x -= this.shape.bounds.width / scale / 4;
  68205. pt.y -= this.shape.bounds.height / scale / 4;
  68206. }
  68207. // Snaps to grid for the rotated position then applies the rotation for the direction after that
  68208. var alpha1 = -mxUtils.toRadians(this.getRotation());
  68209. var alpha2 = -mxUtils.toRadians(this.getTotalRotation()) - alpha1;
  68210. pt = this.flipPoint(this.rotatePoint(this.snapPoint(this.rotatePoint(pt, alpha1),
  68211. this.ignoreGrid || !this.graph.isGridEnabledEvent(me.getEvent())), alpha2));
  68212. this.setPosition(this.state.getPaintBounds(), pt, me);
  68213. this.redraw();
  68214. };
  68215. /**
  68216. * Function: positionChanged
  68217. *
  68218. * Should be called after <setPosition> in <processEvent>.
  68219. * This repaints the state using <mxCellRenderer>.
  68220. */
  68221. mxHandle.prototype.positionChanged = function()
  68222. {
  68223. if (this.state.text != null)
  68224. {
  68225. this.state.text.apply(this.state);
  68226. }
  68227. if (this.state.shape != null)
  68228. {
  68229. this.state.shape.apply(this.state);
  68230. }
  68231. this.graph.cellRenderer.redraw(this.state, true);
  68232. };
  68233. /**
  68234. * Function: getRotation
  68235. *
  68236. * Returns the rotation defined in the style of the cell.
  68237. */
  68238. mxHandle.prototype.getRotation = function()
  68239. {
  68240. if (this.state.shape != null)
  68241. {
  68242. return this.state.shape.getRotation();
  68243. }
  68244. return 0;
  68245. };
  68246. /**
  68247. * Function: getTotalRotation
  68248. *
  68249. * Returns the rotation from the style and the rotation from the direction of
  68250. * the cell.
  68251. */
  68252. mxHandle.prototype.getTotalRotation = function()
  68253. {
  68254. if (this.state.shape != null)
  68255. {
  68256. return this.state.shape.getShapeRotation();
  68257. }
  68258. return 0;
  68259. };
  68260. /**
  68261. * Function: init
  68262. *
  68263. * Creates and initializes the shapes required for this handle.
  68264. */
  68265. mxHandle.prototype.init = function()
  68266. {
  68267. var html = this.isHtmlRequired();
  68268. if (this.image != null)
  68269. {
  68270. this.shape = new mxImageShape(new mxRectangle(0, 0, this.image.width, this.image.height), this.image.src);
  68271. this.shape.preserveImageAspect = false;
  68272. }
  68273. else if (this.shape == null)
  68274. {
  68275. this.shape = this.createShape(html);
  68276. }
  68277. this.initShape(html);
  68278. };
  68279. /**
  68280. * Function: createShape
  68281. *
  68282. * Creates and returns the shape for this handle.
  68283. */
  68284. mxHandle.prototype.createShape = function(html)
  68285. {
  68286. var bounds = new mxRectangle(0, 0, mxConstants.HANDLE_SIZE, mxConstants.HANDLE_SIZE);
  68287. return new mxRectangleShape(bounds, mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  68288. };
  68289. /**
  68290. * Function: initShape
  68291. *
  68292. * Initializes <shape> and sets its cursor.
  68293. */
  68294. mxHandle.prototype.initShape = function(html)
  68295. {
  68296. if (html && this.shape.isHtmlAllowed())
  68297. {
  68298. this.shape.dialect = mxConstants.DIALECT_STRICTHTML;
  68299. this.shape.init(this.graph.container);
  68300. }
  68301. else
  68302. {
  68303. this.shape.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  68304. mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
  68305. if (this.cursor != null)
  68306. {
  68307. this.shape.init(this.graph.getView().getOverlayPane());
  68308. }
  68309. }
  68310. mxEvent.redirectMouseEvents(this.shape.node, this.graph, this.state);
  68311. this.shape.node.style.cursor = this.cursor;
  68312. };
  68313. /**
  68314. * Function: redraw
  68315. *
  68316. * Renders the shape for this handle.
  68317. */
  68318. mxHandle.prototype.redraw = function()
  68319. {
  68320. if (this.shape != null && this.state.shape != null)
  68321. {
  68322. var pt = this.getPosition(this.state.getPaintBounds());
  68323. if (pt != null)
  68324. {
  68325. var alpha = mxUtils.toRadians(this.getTotalRotation());
  68326. pt = this.rotatePoint(this.flipPoint(pt), alpha);
  68327. var scale = this.graph.view.scale;
  68328. var tr = this.graph.view.translate;
  68329. this.shape.bounds.x = Math.floor((pt.x + tr.x) * scale - this.shape.bounds.width / 2);
  68330. this.shape.bounds.y = Math.floor((pt.y + tr.y) * scale - this.shape.bounds.height / 2);
  68331. // Needed to force update of text bounds
  68332. this.shape.redraw();
  68333. }
  68334. }
  68335. };
  68336. /**
  68337. * Function: isHtmlRequired
  68338. *
  68339. * Returns true if this handle should be rendered in HTML. This returns true if
  68340. * the text node is in the graph container.
  68341. */
  68342. mxHandle.prototype.isHtmlRequired = function()
  68343. {
  68344. return this.state.text != null && this.state.text.node.parentNode == this.graph.container;
  68345. };
  68346. /**
  68347. * Function: rotatePoint
  68348. *
  68349. * Rotates the point by the given angle.
  68350. */
  68351. mxHandle.prototype.rotatePoint = function(pt, alpha)
  68352. {
  68353. var bounds = this.state.getCellBounds();
  68354. var cx = new mxPoint(bounds.getCenterX(), bounds.getCenterY());
  68355. var cos = Math.cos(alpha);
  68356. var sin = Math.sin(alpha);
  68357. return mxUtils.getRotatedPoint(pt, cos, sin, cx);
  68358. };
  68359. /**
  68360. * Function: flipPoint
  68361. *
  68362. * Flips the given point vertically and/or horizontally.
  68363. */
  68364. mxHandle.prototype.flipPoint = function(pt)
  68365. {
  68366. if (this.state.shape != null)
  68367. {
  68368. var bounds = this.state.getCellBounds();
  68369. if (this.state.shape.flipH)
  68370. {
  68371. pt.x = 2 * bounds.x + bounds.width - pt.x;
  68372. }
  68373. if (this.state.shape.flipV)
  68374. {
  68375. pt.y = 2 * bounds.y + bounds.height - pt.y;
  68376. }
  68377. }
  68378. return pt;
  68379. };
  68380. /**
  68381. * Function: snapPoint
  68382. *
  68383. * Snaps the given point to the grid if ignore is false. This modifies
  68384. * the given point in-place and also returns it.
  68385. */
  68386. mxHandle.prototype.snapPoint = function(pt, ignore)
  68387. {
  68388. if (!ignore)
  68389. {
  68390. pt.x = this.graph.snap(pt.x);
  68391. pt.y = this.graph.snap(pt.y);
  68392. }
  68393. return pt;
  68394. };
  68395. /**
  68396. * Function: setVisible
  68397. *
  68398. * Shows or hides this handle.
  68399. */
  68400. mxHandle.prototype.setVisible = function(visible)
  68401. {
  68402. if (this.shape != null && this.shape.node != null)
  68403. {
  68404. this.shape.node.style.display = (visible) ? '' : 'none';
  68405. }
  68406. };
  68407. /**
  68408. * Function: reset
  68409. *
  68410. * Resets the state of this handle by setting its visibility to true.
  68411. */
  68412. mxHandle.prototype.reset = function()
  68413. {
  68414. this.setVisible(true);
  68415. this.state.style = this.graph.getCellStyle(this.state.cell);
  68416. this.positionChanged();
  68417. };
  68418. /**
  68419. * Function: destroy
  68420. *
  68421. * Destroys this handle.
  68422. */
  68423. mxHandle.prototype.destroy = function()
  68424. {
  68425. if (this.shape != null)
  68426. {
  68427. this.shape.destroy();
  68428. this.shape = null;
  68429. }
  68430. };
  68431. /**
  68432. * Copyright (c) 2006-2015, JGraph Ltd
  68433. * Copyright (c) 2006-2015, Gaudenz Alder
  68434. */
  68435. /**
  68436. * Class: mxVertexHandler
  68437. *
  68438. * Event handler for resizing cells. This handler is automatically created in
  68439. * <mxGraph.createHandler>.
  68440. *
  68441. * Constructor: mxVertexHandler
  68442. *
  68443. * Constructs an event handler that allows to resize vertices
  68444. * and groups.
  68445. *
  68446. * Parameters:
  68447. *
  68448. * state - <mxCellState> of the cell to be resized.
  68449. */
  68450. function mxVertexHandler(state)
  68451. {
  68452. if (state != null)
  68453. {
  68454. this.state = state;
  68455. this.init();
  68456. // Handles escape keystrokes
  68457. this.escapeHandler = mxUtils.bind(this, function(sender, evt)
  68458. {
  68459. if (this.livePreview && this.index != null)
  68460. {
  68461. // Redraws the live preview
  68462. this.state.view.graph.cellRenderer.redraw(this.state, true);
  68463. // Redraws connected edges
  68464. this.state.view.invalidate(this.state.cell);
  68465. this.state.invalid = false;
  68466. this.state.view.validate();
  68467. }
  68468. this.reset();
  68469. });
  68470. this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
  68471. }
  68472. };
  68473. /**
  68474. * Variable: graph
  68475. *
  68476. * Reference to the enclosing <mxGraph>.
  68477. */
  68478. mxVertexHandler.prototype.graph = null;
  68479. /**
  68480. * Variable: state
  68481. *
  68482. * Reference to the <mxCellState> being modified.
  68483. */
  68484. mxVertexHandler.prototype.state = null;
  68485. /**
  68486. * Variable: singleSizer
  68487. *
  68488. * Specifies if only one sizer handle at the bottom, right corner should be
  68489. * used. Default is false.
  68490. */
  68491. mxVertexHandler.prototype.singleSizer = false;
  68492. /**
  68493. * Variable: index
  68494. *
  68495. * Holds the index of the current handle.
  68496. */
  68497. mxVertexHandler.prototype.index = null;
  68498. /**
  68499. * Variable: allowHandleBoundsCheck
  68500. *
  68501. * Specifies if the bounds of handles should be used for hit-detection in IE or
  68502. * if <tolerance> > 0. Default is true.
  68503. */
  68504. mxVertexHandler.prototype.allowHandleBoundsCheck = true;
  68505. /**
  68506. * Variable: handleImage
  68507. *
  68508. * Optional <mxImage> to be used as handles. Default is null.
  68509. */
  68510. mxVertexHandler.prototype.handleImage = null;
  68511. /**
  68512. * Variable: tolerance
  68513. *
  68514. * Optional tolerance for hit-detection in <getHandleForEvent>. Default is 0.
  68515. */
  68516. mxVertexHandler.prototype.tolerance = 0;
  68517. /**
  68518. * Variable: rotationEnabled
  68519. *
  68520. * Specifies if a rotation handle should be visible. Default is false.
  68521. */
  68522. mxVertexHandler.prototype.rotationEnabled = false;
  68523. /**
  68524. * Variable: parentHighlightEnabled
  68525. *
  68526. * Specifies if the parent should be highlighted if a child cell is selected.
  68527. * Default is false.
  68528. */
  68529. mxVertexHandler.prototype.parentHighlightEnabled = false;
  68530. /**
  68531. * Variable: rotationRaster
  68532. *
  68533. * Specifies if rotation steps should be "rasterized" depening on the distance
  68534. * to the handle. Default is true.
  68535. */
  68536. mxVertexHandler.prototype.rotationRaster = true;
  68537. /**
  68538. * Variable: rotationCursor
  68539. *
  68540. * Specifies the cursor for the rotation handle. Default is 'crosshair'.
  68541. */
  68542. mxVertexHandler.prototype.rotationCursor = 'crosshair';
  68543. /**
  68544. * Variable: livePreview
  68545. *
  68546. * Specifies if resize should change the cell in-place. This is an experimental
  68547. * feature for non-touch devices. Default is false.
  68548. */
  68549. mxVertexHandler.prototype.livePreview = false;
  68550. /**
  68551. * Variable: manageSizers
  68552. *
  68553. * Specifies if sizers should be hidden and spaced if the vertex is small.
  68554. * Default is false.
  68555. */
  68556. mxVertexHandler.prototype.manageSizers = false;
  68557. /**
  68558. * Variable: constrainGroupByChildren
  68559. *
  68560. * Specifies if the size of groups should be constrained by the children.
  68561. * Default is false.
  68562. */
  68563. mxVertexHandler.prototype.constrainGroupByChildren = false;
  68564. /**
  68565. * Variable: rotationHandleVSpacing
  68566. *
  68567. * Vertical spacing for rotation icon. Default is -16.
  68568. */
  68569. mxVertexHandler.prototype.rotationHandleVSpacing = -16;
  68570. /**
  68571. * Variable: horizontalOffset
  68572. *
  68573. * The horizontal offset for the handles. This is updated in <redrawHandles>
  68574. * if <manageSizers> is true and the sizers are offset horizontally.
  68575. */
  68576. mxVertexHandler.prototype.horizontalOffset = 0;
  68577. /**
  68578. * Variable: verticalOffset
  68579. *
  68580. * The horizontal offset for the handles. This is updated in <redrawHandles>
  68581. * if <manageSizers> is true and the sizers are offset vertically.
  68582. */
  68583. mxVertexHandler.prototype.verticalOffset = 0;
  68584. /**
  68585. * Function: init
  68586. *
  68587. * Initializes the shapes required for this vertex handler.
  68588. */
  68589. mxVertexHandler.prototype.init = function()
  68590. {
  68591. this.graph = this.state.view.graph;
  68592. this.selectionBounds = this.getSelectionBounds(this.state);
  68593. this.bounds = new mxRectangle(this.selectionBounds.x, this.selectionBounds.y, this.selectionBounds.width, this.selectionBounds.height);
  68594. this.selectionBorder = this.createSelectionShape(this.bounds);
  68595. // VML dialect required here for event transparency in IE
  68596. this.selectionBorder.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ? mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  68597. this.selectionBorder.pointerEvents = false;
  68598. this.selectionBorder.rotation = Number(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  68599. this.selectionBorder.init(this.graph.getView().getOverlayPane());
  68600. mxEvent.redirectMouseEvents(this.selectionBorder.node, this.graph, this.state);
  68601. if (this.graph.isCellMovable(this.state.cell))
  68602. {
  68603. this.selectionBorder.setCursor(mxConstants.CURSOR_MOVABLE_VERTEX);
  68604. }
  68605. // Adds the sizer handles
  68606. if (mxGraphHandler.prototype.maxCells <= 0 || this.graph.getSelectionCount() < mxGraphHandler.prototype.maxCells)
  68607. {
  68608. var resizable = this.graph.isCellResizable(this.state.cell);
  68609. this.sizers = [];
  68610. if (resizable || (this.graph.isLabelMovable(this.state.cell) &&
  68611. this.state.width >= 2 && this.state.height >= 2))
  68612. {
  68613. var i = 0;
  68614. if (resizable)
  68615. {
  68616. if (!this.singleSizer)
  68617. {
  68618. this.sizers.push(this.createSizer('nw-resize', i++));
  68619. this.sizers.push(this.createSizer('n-resize', i++));
  68620. this.sizers.push(this.createSizer('ne-resize', i++));
  68621. this.sizers.push(this.createSizer('w-resize', i++));
  68622. this.sizers.push(this.createSizer('e-resize', i++));
  68623. this.sizers.push(this.createSizer('sw-resize', i++));
  68624. this.sizers.push(this.createSizer('s-resize', i++));
  68625. }
  68626. this.sizers.push(this.createSizer('se-resize', i++));
  68627. }
  68628. var geo = this.graph.model.getGeometry(this.state.cell);
  68629. if (geo != null && !geo.relative && !this.graph.isSwimlane(this.state.cell) &&
  68630. this.graph.isLabelMovable(this.state.cell))
  68631. {
  68632. // Marks this as the label handle for getHandleForEvent
  68633. this.labelShape = this.createSizer(mxConstants.CURSOR_LABEL_HANDLE, mxEvent.LABEL_HANDLE,
  68634. mxConstants.LABEL_HANDLE_SIZE, mxConstants.LABEL_HANDLE_FILLCOLOR);
  68635. this.sizers.push(this.labelShape);
  68636. }
  68637. }
  68638. else if (this.graph.isCellMovable(this.state.cell) && !this.graph.isCellResizable(this.state.cell) &&
  68639. this.state.width < 2 && this.state.height < 2)
  68640. {
  68641. this.labelShape = this.createSizer(mxConstants.CURSOR_MOVABLE_VERTEX,
  68642. mxEvent.LABEL_HANDLE, null, mxConstants.LABEL_HANDLE_FILLCOLOR);
  68643. this.sizers.push(this.labelShape);
  68644. }
  68645. }
  68646. // Adds the rotation handler
  68647. if (this.isRotationHandleVisible())
  68648. {
  68649. this.rotationShape = this.createSizer(this.rotationCursor, mxEvent.ROTATION_HANDLE,
  68650. mxConstants.HANDLE_SIZE + 3, mxConstants.HANDLE_FILLCOLOR);
  68651. this.sizers.push(this.rotationShape);
  68652. }
  68653. this.customHandles = this.createCustomHandles();
  68654. this.redraw();
  68655. if (this.constrainGroupByChildren)
  68656. {
  68657. this.updateMinBounds();
  68658. }
  68659. };
  68660. /**
  68661. * Function: isRotationHandleVisible
  68662. *
  68663. * Returns true if the rotation handle should be showing.
  68664. */
  68665. mxVertexHandler.prototype.isRotationHandleVisible = function()
  68666. {
  68667. return this.graph.isEnabled() && this.rotationEnabled && this.graph.isCellRotatable(this.state.cell) &&
  68668. (mxGraphHandler.prototype.maxCells <= 0 || this.graph.getSelectionCount() < mxGraphHandler.prototype.maxCells);
  68669. };
  68670. /**
  68671. * Function: isConstrainedEvent
  68672. *
  68673. * Returns true if the aspect ratio if the cell should be maintained.
  68674. */
  68675. mxVertexHandler.prototype.isConstrainedEvent = function(me)
  68676. {
  68677. return mxEvent.isShiftDown(me.getEvent()) || this.state.style[mxConstants.STYLE_ASPECT] == 'fixed';
  68678. };
  68679. /**
  68680. * Function: isCenteredEvent
  68681. *
  68682. * Returns true if the center of the vertex should be maintained during the resize.
  68683. */
  68684. mxVertexHandler.prototype.isCenteredEvent = function(state, me)
  68685. {
  68686. return false;
  68687. };
  68688. /**
  68689. * Function: createCustomHandles
  68690. *
  68691. * Returns an array of custom handles. This implementation returns null.
  68692. */
  68693. mxVertexHandler.prototype.createCustomHandles = function()
  68694. {
  68695. return null;
  68696. };
  68697. /**
  68698. * Function: updateMinBounds
  68699. *
  68700. * Initializes the shapes required for this vertex handler.
  68701. */
  68702. mxVertexHandler.prototype.updateMinBounds = function()
  68703. {
  68704. var children = this.graph.getChildCells(this.state.cell);
  68705. if (children.length > 0)
  68706. {
  68707. this.minBounds = this.graph.view.getBounds(children);
  68708. if (this.minBounds != null)
  68709. {
  68710. var s = this.state.view.scale;
  68711. var t = this.state.view.translate;
  68712. this.minBounds.x -= this.state.x;
  68713. this.minBounds.y -= this.state.y;
  68714. this.minBounds.x /= s;
  68715. this.minBounds.y /= s;
  68716. this.minBounds.width /= s;
  68717. this.minBounds.height /= s;
  68718. this.x0 = this.state.x / s - t.x;
  68719. this.y0 = this.state.y / s - t.y;
  68720. }
  68721. }
  68722. };
  68723. /**
  68724. * Function: getSelectionBounds
  68725. *
  68726. * Returns the mxRectangle that defines the bounds of the selection
  68727. * border.
  68728. */
  68729. mxVertexHandler.prototype.getSelectionBounds = function(state)
  68730. {
  68731. return new mxRectangle(Math.round(state.x), Math.round(state.y), Math.round(state.width), Math.round(state.height));
  68732. };
  68733. /**
  68734. * Function: createParentHighlightShape
  68735. *
  68736. * Creates the shape used to draw the selection border.
  68737. */
  68738. mxVertexHandler.prototype.createParentHighlightShape = function(bounds)
  68739. {
  68740. return this.createSelectionShape(bounds);
  68741. };
  68742. /**
  68743. * Function: createSelectionShape
  68744. *
  68745. * Creates the shape used to draw the selection border.
  68746. */
  68747. mxVertexHandler.prototype.createSelectionShape = function(bounds)
  68748. {
  68749. var shape = new mxRectangleShape(
  68750. mxRectangle.fromRectangle(bounds),
  68751. null, this.getSelectionColor());
  68752. shape.strokewidth = this.getSelectionStrokeWidth();
  68753. shape.isDashed = this.isSelectionDashed();
  68754. return shape;
  68755. };
  68756. /**
  68757. * Function: getSelectionColor
  68758. *
  68759. * Returns <mxConstants.VERTEX_SELECTION_COLOR>.
  68760. */
  68761. mxVertexHandler.prototype.getSelectionColor = function()
  68762. {
  68763. return mxConstants.VERTEX_SELECTION_COLOR;
  68764. };
  68765. /**
  68766. * Function: getSelectionStrokeWidth
  68767. *
  68768. * Returns <mxConstants.VERTEX_SELECTION_STROKEWIDTH>.
  68769. */
  68770. mxVertexHandler.prototype.getSelectionStrokeWidth = function()
  68771. {
  68772. return mxConstants.VERTEX_SELECTION_STROKEWIDTH;
  68773. };
  68774. /**
  68775. * Function: isSelectionDashed
  68776. *
  68777. * Returns <mxConstants.VERTEX_SELECTION_DASHED>.
  68778. */
  68779. mxVertexHandler.prototype.isSelectionDashed = function()
  68780. {
  68781. return mxConstants.VERTEX_SELECTION_DASHED;
  68782. };
  68783. /**
  68784. * Function: createSizer
  68785. *
  68786. * Creates a sizer handle for the specified cursor and index and returns
  68787. * the new <mxRectangleShape> that represents the handle.
  68788. */
  68789. mxVertexHandler.prototype.createSizer = function(cursor, index, size, fillColor)
  68790. {
  68791. size = size || mxConstants.HANDLE_SIZE;
  68792. var bounds = new mxRectangle(0, 0, size, size);
  68793. var sizer = this.createSizerShape(bounds, index, fillColor);
  68794. if (sizer.isHtmlAllowed() && this.state.text != null && this.state.text.node.parentNode == this.graph.container)
  68795. {
  68796. sizer.bounds.height -= 1;
  68797. sizer.bounds.width -= 1;
  68798. sizer.dialect = mxConstants.DIALECT_STRICTHTML;
  68799. sizer.init(this.graph.container);
  68800. }
  68801. else
  68802. {
  68803. sizer.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  68804. mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
  68805. sizer.init(this.graph.getView().getOverlayPane());
  68806. }
  68807. mxEvent.redirectMouseEvents(sizer.node, this.graph, this.state);
  68808. if (this.graph.isEnabled())
  68809. {
  68810. sizer.setCursor(cursor);
  68811. }
  68812. if (!this.isSizerVisible(index))
  68813. {
  68814. sizer.visible = false;
  68815. }
  68816. return sizer;
  68817. };
  68818. /**
  68819. * Function: isSizerVisible
  68820. *
  68821. * Returns true if the sizer for the given index is visible.
  68822. * This returns true for all given indices.
  68823. */
  68824. mxVertexHandler.prototype.isSizerVisible = function(index)
  68825. {
  68826. return true;
  68827. };
  68828. /**
  68829. * Function: createSizerShape
  68830. *
  68831. * Creates the shape used for the sizer handle for the specified bounds an
  68832. * index. Only images and rectangles should be returned if support for HTML
  68833. * labels with not foreign objects is required.
  68834. */
  68835. mxVertexHandler.prototype.createSizerShape = function(bounds, index, fillColor)
  68836. {
  68837. if (this.handleImage != null)
  68838. {
  68839. bounds = new mxRectangle(bounds.x, bounds.y, this.handleImage.width, this.handleImage.height);
  68840. var shape = new mxImageShape(bounds, this.handleImage.src);
  68841. // Allows HTML rendering of the images
  68842. shape.preserveImageAspect = false;
  68843. return shape;
  68844. }
  68845. else if (index == mxEvent.ROTATION_HANDLE)
  68846. {
  68847. return new mxEllipse(bounds, fillColor || mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  68848. }
  68849. else
  68850. {
  68851. return new mxRectangleShape(bounds, fillColor || mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  68852. }
  68853. };
  68854. /**
  68855. * Function: createBounds
  68856. *
  68857. * Helper method to create an <mxRectangle> around the given centerpoint
  68858. * with a width and height of 2*s or 6, if no s is given.
  68859. */
  68860. mxVertexHandler.prototype.moveSizerTo = function(shape, x, y)
  68861. {
  68862. if (shape != null)
  68863. {
  68864. shape.bounds.x = Math.floor(x - shape.bounds.width / 2);
  68865. shape.bounds.y = Math.floor(y - shape.bounds.height / 2);
  68866. // Fixes visible inactive handles in VML
  68867. if (shape.node != null && shape.node.style.display != 'none')
  68868. {
  68869. shape.redraw();
  68870. }
  68871. }
  68872. };
  68873. /**
  68874. * Function: getHandleForEvent
  68875. *
  68876. * Returns the index of the handle for the given event. This returns the index
  68877. * of the sizer from where the event originated or <mxEvent.LABEL_INDEX>.
  68878. */
  68879. mxVertexHandler.prototype.getHandleForEvent = function(me)
  68880. {
  68881. // Connection highlight may consume events before they reach sizer handle
  68882. var tol = (!mxEvent.isMouseEvent(me.getEvent())) ? this.tolerance : 1;
  68883. var hit = (this.allowHandleBoundsCheck && (mxClient.IS_IE || tol > 0)) ?
  68884. new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol) : null;
  68885. var checkShape = mxUtils.bind(this, function(shape)
  68886. {
  68887. var real = (shape != null && shape.constructor != mxImageShape && this.allowHandleBoundsCheck) ?
  68888. new mxRectangle(me.getGraphX() - shape.svgStrokeTolerance, me.getGraphY() - shape.svgStrokeTolerance,
  68889. 2 * shape.svgStrokeTolerance, 2 * shape.svgStrokeTolerance) : hit;
  68890. return shape != null && (me.isSource(shape) || (real != null && mxUtils.intersects(shape.bounds, real) &&
  68891. shape.node.style.display != 'none' && shape.node.style.visibility != 'hidden'));
  68892. });
  68893. if (checkShape(this.rotationShape))
  68894. {
  68895. return mxEvent.ROTATION_HANDLE;
  68896. }
  68897. else if (checkShape(this.labelShape))
  68898. {
  68899. return mxEvent.LABEL_HANDLE;
  68900. }
  68901. if (this.sizers != null)
  68902. {
  68903. for (var i = 0; i < this.sizers.length; i++)
  68904. {
  68905. if (checkShape(this.sizers[i]))
  68906. {
  68907. return i;
  68908. }
  68909. }
  68910. }
  68911. if (this.customHandles != null && this.isCustomHandleEvent(me))
  68912. {
  68913. // Inverse loop order to match display order
  68914. for (var i = this.customHandles.length - 1; i >= 0; i--)
  68915. {
  68916. if (checkShape(this.customHandles[i].shape))
  68917. {
  68918. // LATER: Return reference to active shape
  68919. return mxEvent.CUSTOM_HANDLE - i;
  68920. }
  68921. }
  68922. }
  68923. return null;
  68924. };
  68925. /**
  68926. * Function: isCustomHandleEvent
  68927. *
  68928. * Returns true if the given event allows custom handles to be changed. This
  68929. * implementation returns true.
  68930. */
  68931. mxVertexHandler.prototype.isCustomHandleEvent = function(me)
  68932. {
  68933. return true;
  68934. };
  68935. /**
  68936. * Function: mouseDown
  68937. *
  68938. * Handles the event if a handle has been clicked. By consuming the
  68939. * event all subsequent events of the gesture are redirected to this
  68940. * handler.
  68941. */
  68942. mxVertexHandler.prototype.mouseDown = function(sender, me)
  68943. {
  68944. if (!me.isConsumed() && this.graph.isEnabled())
  68945. {
  68946. var handle = this.getHandleForEvent(me);
  68947. if (handle != null)
  68948. {
  68949. this.start(me.getGraphX(), me.getGraphY(), handle);
  68950. me.consume();
  68951. }
  68952. }
  68953. };
  68954. /**
  68955. * Function: isLivePreviewBorder
  68956. *
  68957. * Called if <livePreview> is enabled to check if a border should be painted.
  68958. * This implementation returns true if the shape is transparent.
  68959. */
  68960. mxVertexHandler.prototype.isLivePreviewBorder = function()
  68961. {
  68962. return this.state.shape != null && this.state.shape.fill == null && this.state.shape.stroke == null;
  68963. };
  68964. /**
  68965. * Function: start
  68966. *
  68967. * Starts the handling of the mouse gesture.
  68968. */
  68969. mxVertexHandler.prototype.start = function(x, y, index)
  68970. {
  68971. if (this.selectionBorder != null)
  68972. {
  68973. this.livePreviewActive = this.livePreview && this.graph.model.getChildCount(this.state.cell) == 0;
  68974. this.inTolerance = true;
  68975. this.childOffsetX = 0;
  68976. this.childOffsetY = 0;
  68977. this.index = index;
  68978. this.startX = x;
  68979. this.startY = y;
  68980. if (this.index <= mxEvent.CUSTOM_HANDLE && this.isGhostPreview())
  68981. {
  68982. this.ghostPreview = this.createGhostPreview();
  68983. }
  68984. else
  68985. {
  68986. // Saves reference to parent state
  68987. var model = this.state.view.graph.model;
  68988. var parent = model.getParent(this.state.cell);
  68989. if (this.state.view.currentRoot != parent && (model.isVertex(parent) || model.isEdge(parent)))
  68990. {
  68991. this.parentState = this.state.view.graph.view.getState(parent);
  68992. }
  68993. // Creates a preview that can be on top of any HTML label
  68994. this.selectionBorder.node.style.display = (index == mxEvent.ROTATION_HANDLE) ? 'inline' : 'none';
  68995. // Creates the border that represents the new bounds
  68996. if (!this.livePreviewActive || this.isLivePreviewBorder())
  68997. {
  68998. this.preview = this.createSelectionShape(this.bounds);
  68999. if (!(mxClient.IS_SVG && Number(this.state.style[mxConstants.STYLE_ROTATION] || '0') != 0) &&
  69000. this.state.text != null && this.state.text.node.parentNode == this.graph.container)
  69001. {
  69002. this.preview.dialect = mxConstants.DIALECT_STRICTHTML;
  69003. this.preview.init(this.graph.container);
  69004. }
  69005. else
  69006. {
  69007. this.preview.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  69008. mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  69009. this.preview.init(this.graph.view.getOverlayPane());
  69010. }
  69011. }
  69012. if (index == mxEvent.ROTATION_HANDLE)
  69013. {
  69014. // With the rotation handle in a corner, need the angle and distance
  69015. var pos = this.getRotationHandlePosition();
  69016. var dx = pos.x - this.state.getCenterX();
  69017. var dy = pos.y - this.state.getCenterY();
  69018. this.startAngle = (dx != 0) ? Math.atan(dy / dx) * 180 / Math.PI + 90 : ((dy < 0) ? 180 : 0);
  69019. this.startDist = Math.sqrt(dx * dx + dy * dy);
  69020. }
  69021. // Prepares the handles for live preview
  69022. if (this.livePreviewActive)
  69023. {
  69024. this.hideSizers();
  69025. if (index == mxEvent.ROTATION_HANDLE)
  69026. {
  69027. this.rotationShape.node.style.display = '';
  69028. }
  69029. else if (index == mxEvent.LABEL_HANDLE)
  69030. {
  69031. this.labelShape.node.style.display = '';
  69032. }
  69033. else if (this.sizers != null && this.sizers[index] != null)
  69034. {
  69035. this.sizers[index].node.style.display = '';
  69036. }
  69037. else if (index <= mxEvent.CUSTOM_HANDLE && this.customHandles != null)
  69038. {
  69039. this.customHandles[mxEvent.CUSTOM_HANDLE - index].setVisible(true);
  69040. }
  69041. // Gets the array of connected edge handlers for redrawing
  69042. var edges = this.graph.getEdges(this.state.cell);
  69043. this.edgeHandlers = [];
  69044. for (var i = 0; i < edges.length; i++)
  69045. {
  69046. var handler = this.graph.selectionCellsHandler.getHandler(edges[i]);
  69047. if (handler != null)
  69048. {
  69049. this.edgeHandlers.push(handler);
  69050. }
  69051. }
  69052. }
  69053. }
  69054. }
  69055. };
  69056. /**
  69057. * Function: createGhostPreview
  69058. *
  69059. * Starts the handling of the mouse gesture.
  69060. */
  69061. mxVertexHandler.prototype.createGhostPreview = function()
  69062. {
  69063. var shape = this.graph.cellRenderer.createShape(this.state);
  69064. shape.init(this.graph.view.getOverlayPane());
  69065. shape.scale = this.state.view.scale;
  69066. shape.bounds = this.bounds;
  69067. shape.outline = true;
  69068. return shape;
  69069. };
  69070. /**
  69071. * Function: hideHandles
  69072. *
  69073. * Shortcut to <hideSizers>.
  69074. */
  69075. mxVertexHandler.prototype.setHandlesVisible = function(visible)
  69076. {
  69077. if (this.sizers != null)
  69078. {
  69079. for (var i = 0; i < this.sizers.length; i++)
  69080. {
  69081. this.sizers[i].node.style.display = (visible) ? '' : 'none';
  69082. }
  69083. }
  69084. if (this.customHandles != null)
  69085. {
  69086. for (var i = 0; i < this.customHandles.length; i++)
  69087. {
  69088. this.customHandles[i].setVisible(visible);
  69089. }
  69090. }
  69091. };
  69092. /**
  69093. * Function: hideSizers
  69094. *
  69095. * Hides all sizers except.
  69096. *
  69097. * Starts the handling of the mouse gesture.
  69098. */
  69099. mxVertexHandler.prototype.hideSizers = function()
  69100. {
  69101. this.setHandlesVisible(false);
  69102. };
  69103. /**
  69104. * Function: checkTolerance
  69105. *
  69106. * Checks if the coordinates for the given event are within the
  69107. * <mxGraph.tolerance>. If the event is a mouse event then the tolerance is
  69108. * ignored.
  69109. */
  69110. mxVertexHandler.prototype.checkTolerance = function(me)
  69111. {
  69112. if (this.inTolerance && this.startX != null && this.startY != null)
  69113. {
  69114. if (mxEvent.isMouseEvent(me.getEvent()) ||
  69115. Math.abs(me.getGraphX() - this.startX) > this.graph.tolerance ||
  69116. Math.abs(me.getGraphY() - this.startY) > this.graph.tolerance)
  69117. {
  69118. this.inTolerance = false;
  69119. }
  69120. }
  69121. };
  69122. /**
  69123. * Function: updateHint
  69124. *
  69125. * Hook for subclassers do show details while the handler is active.
  69126. */
  69127. mxVertexHandler.prototype.updateHint = function(me) { };
  69128. /**
  69129. * Function: removeHint
  69130. *
  69131. * Hooks for subclassers to hide details when the handler gets inactive.
  69132. */
  69133. mxVertexHandler.prototype.removeHint = function() { };
  69134. /**
  69135. * Function: roundAngle
  69136. *
  69137. * Hook for rounding the angle. This uses Math.round.
  69138. */
  69139. mxVertexHandler.prototype.roundAngle = function(angle)
  69140. {
  69141. return Math.round(angle * 10) / 10;
  69142. };
  69143. /**
  69144. * Function: roundLength
  69145. *
  69146. * Hook for rounding the unscaled width or height. This uses Math.round.
  69147. */
  69148. mxVertexHandler.prototype.roundLength = function(length)
  69149. {
  69150. return Math.round(length * 100) / 100;
  69151. };
  69152. /**
  69153. * Function: mouseMove
  69154. *
  69155. * Handles the event by updating the preview.
  69156. */
  69157. mxVertexHandler.prototype.mouseMove = function(sender, me)
  69158. {
  69159. if (!me.isConsumed() && this.index != null)
  69160. {
  69161. // Checks tolerance for ignoring single clicks
  69162. this.checkTolerance(me);
  69163. if (!this.inTolerance)
  69164. {
  69165. if (this.index <= mxEvent.CUSTOM_HANDLE)
  69166. {
  69167. if (this.customHandles != null)
  69168. {
  69169. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].processEvent(me);
  69170. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].active = true;
  69171. if (this.ghostPreview != null)
  69172. {
  69173. this.ghostPreview.apply(this.state);
  69174. this.ghostPreview.strokewidth = this.getSelectionStrokeWidth() /
  69175. this.ghostPreview.scale / this.ghostPreview.scale;
  69176. this.ghostPreview.isDashed = this.isSelectionDashed();
  69177. this.ghostPreview.stroke = this.getSelectionColor();
  69178. this.ghostPreview.redraw();
  69179. if (this.selectionBounds != null)
  69180. {
  69181. this.selectionBorder.node.style.display = 'none';
  69182. }
  69183. }
  69184. else
  69185. {
  69186. this.moveToFront();
  69187. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].positionChanged();
  69188. }
  69189. }
  69190. }
  69191. else if (this.index == mxEvent.LABEL_HANDLE)
  69192. {
  69193. this.moveLabel(me);
  69194. }
  69195. else if (this.index == mxEvent.ROTATION_HANDLE)
  69196. {
  69197. this.rotateVertex(me);
  69198. }
  69199. else
  69200. {
  69201. this.resizeVertex(me);
  69202. this.updateHint(me);
  69203. }
  69204. }
  69205. me.consume();
  69206. }
  69207. // Workaround for disabling the connect highlight when over handle
  69208. else if (!this.graph.isMouseDown && this.getHandleForEvent(me) != null)
  69209. {
  69210. me.consume(false);
  69211. }
  69212. };
  69213. /**
  69214. * Function: isGhostPreview
  69215. *
  69216. * Returns true if a ghost preview should be used for custom handles.
  69217. */
  69218. mxVertexHandler.prototype.isGhostPreview = function()
  69219. {
  69220. return this.state.view.graph.model.getChildCount(this.state.cell) > 0;
  69221. };
  69222. /**
  69223. * Function: rotateVertex
  69224. *
  69225. * Rotates the vertex.
  69226. */
  69227. mxVertexHandler.prototype.moveLabel = function(me)
  69228. {
  69229. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  69230. var tr = this.graph.view.translate;
  69231. var scale = this.graph.view.scale;
  69232. if (this.graph.isGridEnabledEvent(me.getEvent()))
  69233. {
  69234. point.x = (this.graph.snap(point.x / scale - tr.x) + tr.x) * scale;
  69235. point.y = (this.graph.snap(point.y / scale - tr.y) + tr.y) * scale;
  69236. }
  69237. var index = (this.rotationShape != null) ? this.sizers.length - 2 : this.sizers.length - 1;
  69238. this.moveSizerTo(this.sizers[index], point.x, point.y);
  69239. };
  69240. /**
  69241. * Function: rotateVertex
  69242. *
  69243. * Rotates the vertex.
  69244. */
  69245. mxVertexHandler.prototype.rotateVertex = function(me)
  69246. {
  69247. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  69248. var dx = this.state.x + this.state.width / 2 - point.x;
  69249. var dy = this.state.y + this.state.height / 2 - point.y;
  69250. this.currentAlpha = (dx != 0) ? Math.atan(dy / dx) * 180 / Math.PI + 90 : ((dy < 0) ? 180 : 0);
  69251. if (dx > 0)
  69252. {
  69253. this.currentAlpha -= 180;
  69254. }
  69255. this.currentAlpha -= this.startAngle;
  69256. // Rotation raster
  69257. if (this.rotationRaster && this.graph.isGridEnabledEvent(me.getEvent()))
  69258. {
  69259. var dx = point.x - this.state.getCenterX();
  69260. var dy = point.y - this.state.getCenterY();
  69261. var dist = Math.sqrt(dx * dx + dy * dy);
  69262. if (dist - this.startDist < 2)
  69263. {
  69264. raster = 15;
  69265. }
  69266. else if (dist - this.startDist < 25)
  69267. {
  69268. raster = 5;
  69269. }
  69270. else
  69271. {
  69272. raster = 1;
  69273. }
  69274. this.currentAlpha = Math.round(this.currentAlpha / raster) * raster;
  69275. }
  69276. else
  69277. {
  69278. this.currentAlpha = this.roundAngle(this.currentAlpha);
  69279. }
  69280. this.selectionBorder.rotation = this.currentAlpha;
  69281. this.selectionBorder.redraw();
  69282. if (this.livePreviewActive)
  69283. {
  69284. this.redrawHandles();
  69285. }
  69286. };
  69287. /**
  69288. * Function: rotateVertex
  69289. *
  69290. * Rotates the vertex.
  69291. */
  69292. mxVertexHandler.prototype.resizeVertex = function(me)
  69293. {
  69294. var ct = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  69295. var alpha = mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  69296. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  69297. var tr = this.graph.view.translate;
  69298. var scale = this.graph.view.scale;
  69299. var cos = Math.cos(-alpha);
  69300. var sin = Math.sin(-alpha);
  69301. var dx = point.x - this.startX;
  69302. var dy = point.y - this.startY;
  69303. // Rotates vector for mouse gesture
  69304. var tx = cos * dx - sin * dy;
  69305. var ty = sin * dx + cos * dy;
  69306. dx = tx;
  69307. dy = ty;
  69308. var geo = this.graph.getCellGeometry(this.state.cell);
  69309. this.unscaledBounds = this.union(geo, dx / scale, dy / scale, this.index,
  69310. this.graph.isGridEnabledEvent(me.getEvent()), 1,
  69311. new mxPoint(0, 0), this.isConstrainedEvent(me),
  69312. this.isCenteredEvent(this.state, me));
  69313. // Keeps vertex within maximum graph or parent bounds
  69314. if (!geo.relative)
  69315. {
  69316. var max = this.graph.getMaximumGraphBounds();
  69317. // Handles child cells
  69318. if (max != null && this.parentState != null)
  69319. {
  69320. max = mxRectangle.fromRectangle(max);
  69321. max.x -= (this.parentState.x - tr.x * scale) / scale;
  69322. max.y -= (this.parentState.y - tr.y * scale) / scale;
  69323. }
  69324. if (this.graph.isConstrainChild(this.state.cell))
  69325. {
  69326. var tmp = this.graph.getCellContainmentArea(this.state.cell);
  69327. if (tmp != null)
  69328. {
  69329. var overlap = this.graph.getOverlap(this.state.cell);
  69330. if (overlap > 0)
  69331. {
  69332. tmp = mxRectangle.fromRectangle(tmp);
  69333. tmp.x -= tmp.width * overlap;
  69334. tmp.y -= tmp.height * overlap;
  69335. tmp.width += 2 * tmp.width * overlap;
  69336. tmp.height += 2 * tmp.height * overlap;
  69337. }
  69338. if (max == null)
  69339. {
  69340. max = tmp;
  69341. }
  69342. else
  69343. {
  69344. max = mxRectangle.fromRectangle(max);
  69345. max.intersect(tmp);
  69346. }
  69347. }
  69348. }
  69349. if (max != null)
  69350. {
  69351. if (this.unscaledBounds.x < max.x)
  69352. {
  69353. this.unscaledBounds.width -= max.x - this.unscaledBounds.x;
  69354. this.unscaledBounds.x = max.x;
  69355. }
  69356. if (this.unscaledBounds.y < max.y)
  69357. {
  69358. this.unscaledBounds.height -= max.y - this.unscaledBounds.y;
  69359. this.unscaledBounds.y = max.y;
  69360. }
  69361. if (this.unscaledBounds.x + this.unscaledBounds.width > max.x + max.width)
  69362. {
  69363. this.unscaledBounds.width -= this.unscaledBounds.x +
  69364. this.unscaledBounds.width - max.x - max.width;
  69365. }
  69366. if (this.unscaledBounds.y + this.unscaledBounds.height > max.y + max.height)
  69367. {
  69368. this.unscaledBounds.height -= this.unscaledBounds.y +
  69369. this.unscaledBounds.height - max.y - max.height;
  69370. }
  69371. }
  69372. }
  69373. var old = this.bounds;
  69374. this.bounds = new mxRectangle(((this.parentState != null) ? this.parentState.x : tr.x * scale) +
  69375. (this.unscaledBounds.x) * scale, ((this.parentState != null) ? this.parentState.y : tr.y * scale) +
  69376. (this.unscaledBounds.y) * scale, this.unscaledBounds.width * scale, this.unscaledBounds.height * scale);
  69377. if (geo.relative && this.parentState != null)
  69378. {
  69379. this.bounds.x += this.state.x - this.parentState.x;
  69380. this.bounds.y += this.state.y - this.parentState.y;
  69381. }
  69382. cos = Math.cos(alpha);
  69383. sin = Math.sin(alpha);
  69384. var c2 = new mxPoint(this.bounds.getCenterX(), this.bounds.getCenterY());
  69385. var dx = c2.x - ct.x;
  69386. var dy = c2.y - ct.y;
  69387. var dx2 = cos * dx - sin * dy;
  69388. var dy2 = sin * dx + cos * dy;
  69389. var dx3 = dx2 - dx;
  69390. var dy3 = dy2 - dy;
  69391. var dx4 = this.bounds.x - this.state.x;
  69392. var dy4 = this.bounds.y - this.state.y;
  69393. var dx5 = cos * dx4 - sin * dy4;
  69394. var dy5 = sin * dx4 + cos * dy4;
  69395. this.bounds.x += dx3;
  69396. this.bounds.y += dy3;
  69397. // Rounds unscaled bounds to int
  69398. this.unscaledBounds.x = this.roundLength(this.unscaledBounds.x + dx3 / scale);
  69399. this.unscaledBounds.y = this.roundLength(this.unscaledBounds.y + dy3 / scale);
  69400. this.unscaledBounds.width = this.roundLength(this.unscaledBounds.width);
  69401. this.unscaledBounds.height = this.roundLength(this.unscaledBounds.height);
  69402. // Shifts the children according to parent offset
  69403. if (!this.graph.isCellCollapsed(this.state.cell) && (dx3 != 0 || dy3 != 0))
  69404. {
  69405. this.childOffsetX = this.state.x - this.bounds.x + dx5;
  69406. this.childOffsetY = this.state.y - this.bounds.y + dy5;
  69407. }
  69408. else
  69409. {
  69410. this.childOffsetX = 0;
  69411. this.childOffsetY = 0;
  69412. }
  69413. if (!old.equals(this.bounds))
  69414. {
  69415. if (this.livePreviewActive)
  69416. {
  69417. this.updateLivePreview(me);
  69418. }
  69419. if (this.preview != null)
  69420. {
  69421. this.drawPreview();
  69422. }
  69423. else
  69424. {
  69425. this.updateParentHighlight();
  69426. }
  69427. }
  69428. };
  69429. /**
  69430. * Function: updateLivePreview
  69431. *
  69432. * Repaints the live preview.
  69433. */
  69434. mxVertexHandler.prototype.updateLivePreview = function(me)
  69435. {
  69436. // TODO: Apply child offset to children in live preview
  69437. var scale = this.graph.view.scale;
  69438. var tr = this.graph.view.translate;
  69439. // Saves current state
  69440. var tempState = this.state.clone();
  69441. // Temporarily changes size and origin
  69442. this.state.x = this.bounds.x;
  69443. this.state.y = this.bounds.y;
  69444. this.state.origin = new mxPoint(this.state.x / scale - tr.x, this.state.y / scale - tr.y);
  69445. this.state.width = this.bounds.width;
  69446. this.state.height = this.bounds.height;
  69447. // Redraws cell and handles
  69448. var off = this.state.absoluteOffset;
  69449. off = new mxPoint(off.x, off.y);
  69450. // Required to store and reset absolute offset for updating label position
  69451. this.state.absoluteOffset.x = 0;
  69452. this.state.absoluteOffset.y = 0;
  69453. var geo = this.graph.getCellGeometry(this.state.cell);
  69454. if (geo != null)
  69455. {
  69456. var offset = geo.offset || this.EMPTY_POINT;
  69457. if (offset != null && !geo.relative)
  69458. {
  69459. this.state.absoluteOffset.x = this.state.view.scale * offset.x;
  69460. this.state.absoluteOffset.y = this.state.view.scale * offset.y;
  69461. }
  69462. this.state.view.updateVertexLabelOffset(this.state);
  69463. }
  69464. // Draws the live preview
  69465. this.state.view.graph.cellRenderer.redraw(this.state, true);
  69466. // Redraws connected edges TODO: Include child edges
  69467. this.state.view.invalidate(this.state.cell);
  69468. this.state.invalid = false;
  69469. this.state.view.validate();
  69470. this.redrawHandles();
  69471. // Moves live preview to front
  69472. this.moveToFront();
  69473. // Hides folding icon
  69474. if (this.state.control != null && this.state.control.node != null)
  69475. {
  69476. this.state.control.node.style.visibility = 'hidden';
  69477. }
  69478. // Restores current state
  69479. this.state.setState(tempState);
  69480. };
  69481. /**
  69482. * Function: moveToFront
  69483. *
  69484. * Handles the event by applying the changes to the geometry.
  69485. */
  69486. mxVertexHandler.prototype.moveToFront = function()
  69487. {
  69488. if ((this.state.text != null && this.state.text.node != null &&
  69489. this.state.text.node.nextSibling != null) ||
  69490. (this.state.shape != null && this.state.shape.node != null &&
  69491. this.state.shape.node.nextSibling != null && (this.state.text == null ||
  69492. this.state.shape.node.nextSibling != this.state.text.node)))
  69493. {
  69494. if (this.state.shape != null && this.state.shape.node != null)
  69495. {
  69496. this.state.shape.node.parentNode.appendChild(this.state.shape.node);
  69497. }
  69498. if (this.state.text != null && this.state.text.node != null)
  69499. {
  69500. this.state.text.node.parentNode.appendChild(this.state.text.node);
  69501. }
  69502. }
  69503. };
  69504. /**
  69505. * Function: mouseUp
  69506. *
  69507. * Handles the event by applying the changes to the geometry.
  69508. */
  69509. mxVertexHandler.prototype.mouseUp = function(sender, me)
  69510. {
  69511. if (this.index != null && this.state != null)
  69512. {
  69513. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  69514. var index = this.index;
  69515. this.index = null;
  69516. if (this.ghostPreview == null)
  69517. {
  69518. // Required to restore order in case of no change
  69519. this.state.view.invalidate(this.state.cell, false, false);
  69520. this.state.view.validate();
  69521. }
  69522. this.graph.getModel().beginUpdate();
  69523. try
  69524. {
  69525. if (index <= mxEvent.CUSTOM_HANDLE)
  69526. {
  69527. if (this.customHandles != null)
  69528. {
  69529. // Creates style before changing cell state
  69530. var style = this.state.view.graph.getCellStyle(this.state.cell);
  69531. this.customHandles[mxEvent.CUSTOM_HANDLE - index].active = false;
  69532. this.customHandles[mxEvent.CUSTOM_HANDLE - index].execute(me);
  69533. // Sets style and apply on shape to force repaint and
  69534. // check if execute has removed custom handles
  69535. if (this.customHandles != null &&
  69536. this.customHandles[mxEvent.CUSTOM_HANDLE - index] != null)
  69537. {
  69538. this.state.style = style;
  69539. this.customHandles[mxEvent.CUSTOM_HANDLE - index].positionChanged();
  69540. }
  69541. }
  69542. }
  69543. else if (index == mxEvent.ROTATION_HANDLE)
  69544. {
  69545. if (this.currentAlpha != null)
  69546. {
  69547. var delta = this.currentAlpha - (this.state.style[mxConstants.STYLE_ROTATION] || 0);
  69548. if (delta != 0)
  69549. {
  69550. this.rotateCell(this.state.cell, delta);
  69551. }
  69552. }
  69553. else
  69554. {
  69555. this.rotateClick();
  69556. }
  69557. }
  69558. else
  69559. {
  69560. var gridEnabled = this.graph.isGridEnabledEvent(me.getEvent());
  69561. var alpha = mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  69562. var cos = Math.cos(-alpha);
  69563. var sin = Math.sin(-alpha);
  69564. var dx = point.x - this.startX;
  69565. var dy = point.y - this.startY;
  69566. // Rotates vector for mouse gesture
  69567. var tx = cos * dx - sin * dy;
  69568. var ty = sin * dx + cos * dy;
  69569. dx = tx;
  69570. dy = ty;
  69571. var s = this.graph.view.scale;
  69572. var recurse = this.isRecursiveResize(this.state, me);
  69573. this.resizeCell(this.state.cell, this.roundLength(dx / s), this.roundLength(dy / s),
  69574. index, gridEnabled, this.isConstrainedEvent(me), recurse);
  69575. }
  69576. }
  69577. finally
  69578. {
  69579. this.graph.getModel().endUpdate();
  69580. }
  69581. me.consume();
  69582. this.reset();
  69583. }
  69584. };
  69585. /**
  69586. * Function: rotateCell
  69587. *
  69588. * Rotates the given cell to the given rotation.
  69589. */
  69590. mxVertexHandler.prototype.isRecursiveResize = function(state, me)
  69591. {
  69592. return this.graph.isRecursiveResize(this.state);
  69593. };
  69594. /**
  69595. * Function: rotateClick
  69596. *
  69597. * Hook for subclassers to implement a single click on the rotation handle.
  69598. * This code is executed as part of the model transaction. This implementation
  69599. * is empty.
  69600. */
  69601. mxVertexHandler.prototype.rotateClick = function() { };
  69602. /**
  69603. * Function: rotateCell
  69604. *
  69605. * Rotates the given cell and its children by the given angle in degrees.
  69606. *
  69607. * Parameters:
  69608. *
  69609. * cell - <mxCell> to be rotated.
  69610. * angle - Angle in degrees.
  69611. */
  69612. mxVertexHandler.prototype.rotateCell = function(cell, angle, parent)
  69613. {
  69614. if (angle != 0)
  69615. {
  69616. var model = this.graph.getModel();
  69617. if (model.isVertex(cell) || model.isEdge(cell))
  69618. {
  69619. if (!model.isEdge(cell))
  69620. {
  69621. var style = this.graph.getCurrentCellStyle(cell);
  69622. var total = (style[mxConstants.STYLE_ROTATION] || 0) + angle;
  69623. this.graph.setCellStyles(mxConstants.STYLE_ROTATION, total, [cell]);
  69624. }
  69625. var geo = this.graph.getCellGeometry(cell);
  69626. if (geo != null)
  69627. {
  69628. var pgeo = this.graph.getCellGeometry(parent);
  69629. if (pgeo != null && !model.isEdge(parent))
  69630. {
  69631. geo = geo.clone();
  69632. geo.rotate(angle, new mxPoint(pgeo.width / 2, pgeo.height / 2));
  69633. model.setGeometry(cell, geo);
  69634. }
  69635. if ((model.isVertex(cell) && !geo.relative) || model.isEdge(cell))
  69636. {
  69637. // Recursive rotation
  69638. var childCount = model.getChildCount(cell);
  69639. for (var i = 0; i < childCount; i++)
  69640. {
  69641. this.rotateCell(model.getChildAt(cell, i), angle, cell);
  69642. }
  69643. }
  69644. }
  69645. }
  69646. }
  69647. };
  69648. /**
  69649. * Function: reset
  69650. *
  69651. * Resets the state of this handler.
  69652. */
  69653. mxVertexHandler.prototype.reset = function()
  69654. {
  69655. if (this.sizers != null && this.index != null && this.sizers[this.index] != null &&
  69656. this.sizers[this.index].node.style.display == 'none')
  69657. {
  69658. this.sizers[this.index].node.style.display = '';
  69659. }
  69660. this.currentAlpha = null;
  69661. this.inTolerance = null;
  69662. this.index = null;
  69663. // TODO: Reset and redraw cell states for live preview
  69664. if (this.preview != null)
  69665. {
  69666. this.preview.destroy();
  69667. this.preview = null;
  69668. }
  69669. if (this.ghostPreview != null)
  69670. {
  69671. this.ghostPreview.destroy();
  69672. this.ghostPreview = null;
  69673. }
  69674. if (this.livePreviewActive && this.sizers != null)
  69675. {
  69676. for (var i = 0; i < this.sizers.length; i++)
  69677. {
  69678. if (this.sizers[i] != null)
  69679. {
  69680. this.sizers[i].node.style.display = '';
  69681. }
  69682. }
  69683. // Shows folding icon
  69684. if (this.state.control != null && this.state.control.node != null)
  69685. {
  69686. this.state.control.node.style.visibility = '';
  69687. }
  69688. }
  69689. if (this.customHandles != null)
  69690. {
  69691. for (var i = 0; i < this.customHandles.length; i++)
  69692. {
  69693. if (this.customHandles[i].active)
  69694. {
  69695. this.customHandles[i].active = false;
  69696. this.customHandles[i].reset();
  69697. }
  69698. else
  69699. {
  69700. this.customHandles[i].setVisible(true);
  69701. }
  69702. }
  69703. }
  69704. // Checks if handler has been destroyed
  69705. if (this.selectionBorder != null)
  69706. {
  69707. this.selectionBorder.node.style.display = 'inline';
  69708. this.selectionBounds = this.getSelectionBounds(this.state);
  69709. this.bounds = new mxRectangle(this.selectionBounds.x, this.selectionBounds.y,
  69710. this.selectionBounds.width, this.selectionBounds.height);
  69711. this.drawPreview();
  69712. }
  69713. this.removeHint();
  69714. this.redrawHandles();
  69715. this.edgeHandlers = null;
  69716. this.unscaledBounds = null;
  69717. this.livePreviewActive = null;
  69718. };
  69719. /**
  69720. * Function: resizeCell
  69721. *
  69722. * Uses the given vector to change the bounds of the given cell
  69723. * in the graph using <mxGraph.resizeCell>.
  69724. */
  69725. mxVertexHandler.prototype.resizeCell = function(cell, dx, dy, index, gridEnabled, constrained, recurse)
  69726. {
  69727. var geo = this.graph.model.getGeometry(cell);
  69728. if (geo != null)
  69729. {
  69730. if (index == mxEvent.LABEL_HANDLE)
  69731. {
  69732. var alpha = -mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  69733. var cos = Math.cos(alpha);
  69734. var sin = Math.sin(alpha);
  69735. var scale = this.graph.view.scale;
  69736. var pt = mxUtils.getRotatedPoint(new mxPoint(
  69737. Math.round((this.labelShape.bounds.getCenterX() - this.startX) / scale),
  69738. Math.round((this.labelShape.bounds.getCenterY() - this.startY) / scale)),
  69739. cos, sin);
  69740. geo = geo.clone();
  69741. if (geo.offset == null)
  69742. {
  69743. geo.offset = pt;
  69744. }
  69745. else
  69746. {
  69747. geo.offset.x += pt.x;
  69748. geo.offset.y += pt.y;
  69749. }
  69750. this.graph.model.setGeometry(cell, geo);
  69751. }
  69752. else if (this.unscaledBounds != null)
  69753. {
  69754. var scale = this.graph.view.scale;
  69755. if (this.childOffsetX != 0 || this.childOffsetY != 0)
  69756. {
  69757. this.moveChildren(cell, Math.round(this.childOffsetX / scale), Math.round(this.childOffsetY / scale));
  69758. }
  69759. this.graph.resizeCell(cell, this.unscaledBounds, recurse);
  69760. }
  69761. }
  69762. };
  69763. /**
  69764. * Function: moveChildren
  69765. *
  69766. * Moves the children of the given cell by the given vector.
  69767. */
  69768. mxVertexHandler.prototype.moveChildren = function(cell, dx, dy)
  69769. {
  69770. var model = this.graph.getModel();
  69771. var childCount = model.getChildCount(cell);
  69772. for (var i = 0; i < childCount; i++)
  69773. {
  69774. var child = model.getChildAt(cell, i);
  69775. var geo = this.graph.getCellGeometry(child);
  69776. if (geo != null)
  69777. {
  69778. geo = geo.clone();
  69779. geo.translate(dx, dy);
  69780. model.setGeometry(child, geo);
  69781. }
  69782. }
  69783. };
  69784. /**
  69785. * Function: union
  69786. *
  69787. * Returns the union of the given bounds and location for the specified
  69788. * handle index.
  69789. *
  69790. * To override this to limit the size of vertex via a minWidth/-Height style,
  69791. * the following code can be used.
  69792. *
  69793. * (code)
  69794. * var vertexHandlerUnion = mxVertexHandler.prototype.union;
  69795. * mxVertexHandler.prototype.union = function(bounds, dx, dy, index, gridEnabled, scale, tr, constrained)
  69796. * {
  69797. * var result = vertexHandlerUnion.apply(this, arguments);
  69798. *
  69799. * result.width = Math.max(result.width, mxUtils.getNumber(this.state.style, 'minWidth', 0));
  69800. * result.height = Math.max(result.height, mxUtils.getNumber(this.state.style, 'minHeight', 0));
  69801. *
  69802. * return result;
  69803. * };
  69804. * (end)
  69805. *
  69806. * The minWidth/-Height style can then be used as follows:
  69807. *
  69808. * (code)
  69809. * graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30, 'minWidth=100;minHeight=100;');
  69810. * (end)
  69811. *
  69812. * To override this to update the height for a wrapped text if the width of a vertex is
  69813. * changed, the following can be used.
  69814. *
  69815. * (code)
  69816. * var mxVertexHandlerUnion = mxVertexHandler.prototype.union;
  69817. * mxVertexHandler.prototype.union = function(bounds, dx, dy, index, gridEnabled, scale, tr, constrained)
  69818. * {
  69819. * var result = mxVertexHandlerUnion.apply(this, arguments);
  69820. * var s = this.state;
  69821. *
  69822. * if (this.graph.isHtmlLabel(s.cell) && (index == 3 || index == 4) &&
  69823. * s.text != null && s.style[mxConstants.STYLE_WHITE_SPACE] == 'wrap')
  69824. * {
  69825. * var label = this.graph.getLabel(s.cell);
  69826. * var fontSize = mxUtils.getNumber(s.style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  69827. * var ww = result.width / s.view.scale - s.text.spacingRight - s.text.spacingLeft
  69828. *
  69829. * result.height = mxUtils.getSizeForString(label, fontSize, s.style[mxConstants.STYLE_FONTFAMILY], ww).height;
  69830. * }
  69831. *
  69832. * return result;
  69833. * };
  69834. * (end)
  69835. */
  69836. mxVertexHandler.prototype.union = function(bounds, dx, dy, index, gridEnabled, scale, tr, constrained, centered)
  69837. {
  69838. gridEnabled = (gridEnabled != null) ? gridEnabled && this.graph.gridEnabled : this.graph.gridEnabled;
  69839. if (this.singleSizer)
  69840. {
  69841. var x = bounds.x + bounds.width + dx;
  69842. var y = bounds.y + bounds.height + dy;
  69843. if (gridEnabled)
  69844. {
  69845. x = this.graph.snap(x / scale) * scale;
  69846. y = this.graph.snap(y / scale) * scale;
  69847. }
  69848. var rect = new mxRectangle(bounds.x, bounds.y, 0, 0);
  69849. rect.add(new mxRectangle(x, y, 0, 0));
  69850. return rect;
  69851. }
  69852. else
  69853. {
  69854. var w0 = bounds.width;
  69855. var h0 = bounds.height;
  69856. var left = bounds.x - tr.x * scale;
  69857. var right = left + w0;
  69858. var top = bounds.y - tr.y * scale;
  69859. var bottom = top + h0;
  69860. var cx = left + w0 / 2;
  69861. var cy = top + h0 / 2;
  69862. if (index > 4 /* Bottom Row */)
  69863. {
  69864. bottom = bottom + dy;
  69865. if (gridEnabled)
  69866. {
  69867. bottom = this.graph.snap(bottom / scale) * scale;
  69868. }
  69869. else
  69870. {
  69871. bottom = Math.round(bottom / scale) * scale;
  69872. }
  69873. }
  69874. else if (index < 3 /* Top Row */)
  69875. {
  69876. top = top + dy;
  69877. if (gridEnabled)
  69878. {
  69879. top = this.graph.snap(top / scale) * scale;
  69880. }
  69881. else
  69882. {
  69883. top = Math.round(top / scale) * scale;
  69884. }
  69885. }
  69886. if (index == 0 || index == 3 || index == 5 /* Left */)
  69887. {
  69888. left += dx;
  69889. if (gridEnabled)
  69890. {
  69891. left = this.graph.snap(left / scale) * scale;
  69892. }
  69893. else
  69894. {
  69895. left = Math.round(left / scale) * scale;
  69896. }
  69897. }
  69898. else if (index == 2 || index == 4 || index == 7 /* Right */)
  69899. {
  69900. right += dx;
  69901. if (gridEnabled)
  69902. {
  69903. right = this.graph.snap(right / scale) * scale;
  69904. }
  69905. else
  69906. {
  69907. right = Math.round(right / scale) * scale;
  69908. }
  69909. }
  69910. var width = right - left;
  69911. var height = bottom - top;
  69912. if (constrained)
  69913. {
  69914. var geo = this.graph.getCellGeometry(this.state.cell);
  69915. if (geo != null)
  69916. {
  69917. var aspect = geo.width / geo.height;
  69918. if (index== 1 || index== 2 || index == 7 || index == 6)
  69919. {
  69920. width = height * aspect;
  69921. }
  69922. else
  69923. {
  69924. height = width / aspect;
  69925. }
  69926. if (index == 0)
  69927. {
  69928. left = right - width;
  69929. top = bottom - height;
  69930. }
  69931. }
  69932. }
  69933. if (centered)
  69934. {
  69935. width += (width - w0);
  69936. height += (height - h0);
  69937. var cdx = cx - (left + width / 2);
  69938. var cdy = cy - (top + height / 2);
  69939. left += cdx;
  69940. top += cdy;
  69941. right += cdx;
  69942. bottom += cdy;
  69943. }
  69944. // Flips over left side
  69945. if (width < 0)
  69946. {
  69947. left += width;
  69948. width = Math.abs(width);
  69949. }
  69950. // Flips over top side
  69951. if (height < 0)
  69952. {
  69953. top += height;
  69954. height = Math.abs(height);
  69955. }
  69956. var result = new mxRectangle(left + tr.x * scale, top + tr.y * scale, width, height);
  69957. if (this.minBounds != null)
  69958. {
  69959. result.width = Math.max(result.width, this.minBounds.x * scale + this.minBounds.width * scale +
  69960. Math.max(0, this.x0 * scale - result.x));
  69961. result.height = Math.max(result.height, this.minBounds.y * scale + this.minBounds.height * scale +
  69962. Math.max(0, this.y0 * scale - result.y));
  69963. }
  69964. return result;
  69965. }
  69966. };
  69967. /**
  69968. * Function: redraw
  69969. *
  69970. * Redraws the handles and the preview.
  69971. */
  69972. mxVertexHandler.prototype.redraw = function(ignoreHandles)
  69973. {
  69974. this.selectionBounds = this.getSelectionBounds(this.state);
  69975. this.bounds = new mxRectangle(this.selectionBounds.x, this.selectionBounds.y,
  69976. this.selectionBounds.width, this.selectionBounds.height);
  69977. this.drawPreview();
  69978. if (!ignoreHandles)
  69979. {
  69980. this.redrawHandles();
  69981. }
  69982. };
  69983. /**
  69984. * Returns the padding to be used for drawing handles for the current <bounds>.
  69985. */
  69986. mxVertexHandler.prototype.getHandlePadding = function()
  69987. {
  69988. // KNOWN: Tolerance depends on event type (eg. 0 for mouse events)
  69989. var result = new mxPoint(0, 0);
  69990. var tol = this.tolerance;
  69991. if (this.sizers != null && this.sizers.length > 0 && this.sizers[0] != null &&
  69992. (this.bounds.width < 2 * this.sizers[0].bounds.width + 2 * tol ||
  69993. this.bounds.height < 2 * this.sizers[0].bounds.height + 2 * tol))
  69994. {
  69995. tol /= 2;
  69996. result.x = this.sizers[0].bounds.width + tol;
  69997. result.y = this.sizers[0].bounds.height + tol;
  69998. }
  69999. return result;
  70000. };
  70001. /**
  70002. * Function: getSizerBounds
  70003. *
  70004. * Returns the bounds used to paint the resize handles.
  70005. */
  70006. mxVertexHandler.prototype.getSizerBounds = function()
  70007. {
  70008. return this.bounds;
  70009. };
  70010. /**
  70011. * Function: redrawHandles
  70012. *
  70013. * Redraws the handles. To hide certain handles the following code can be used.
  70014. *
  70015. * (code)
  70016. * mxVertexHandler.prototype.redrawHandles = function()
  70017. * {
  70018. * mxVertexHandlerRedrawHandles.apply(this, arguments);
  70019. *
  70020. * if (this.sizers != null && this.sizers.length > 7)
  70021. * {
  70022. * this.sizers[1].node.style.display = 'none';
  70023. * this.sizers[6].node.style.display = 'none';
  70024. * }
  70025. * };
  70026. * (end)
  70027. */
  70028. mxVertexHandler.prototype.redrawHandles = function()
  70029. {
  70030. var s = this.getSizerBounds();
  70031. var tol = this.tolerance;
  70032. this.horizontalOffset = 0;
  70033. this.verticalOffset = 0;
  70034. if (this.customHandles != null)
  70035. {
  70036. for (var i = 0; i < this.customHandles.length; i++)
  70037. {
  70038. var temp = this.customHandles[i].shape.node.style.display;
  70039. this.customHandles[i].redraw();
  70040. this.customHandles[i].shape.node.style.display = temp;
  70041. // Hides custom handles during text editing
  70042. this.customHandles[i].shape.node.style.visibility =
  70043. (this.isCustomHandleVisible(this.customHandles[i])) ?
  70044. '' : 'hidden';
  70045. }
  70046. }
  70047. if (this.sizers != null && this.sizers.length > 0 && this.sizers[0] != null)
  70048. {
  70049. if (this.index == null && this.manageSizers && this.sizers.length >= 8)
  70050. {
  70051. // KNOWN: Tolerance depends on event type (eg. 0 for mouse events)
  70052. var padding = this.getHandlePadding();
  70053. this.horizontalOffset = padding.x;
  70054. this.verticalOffset = padding.y;
  70055. if (this.horizontalOffset != 0 || this.verticalOffset != 0)
  70056. {
  70057. s = new mxRectangle(s.x, s.y, s.width, s.height);
  70058. s.x -= this.horizontalOffset / 2;
  70059. s.width += this.horizontalOffset;
  70060. s.y -= this.verticalOffset / 2;
  70061. s.height += this.verticalOffset;
  70062. }
  70063. if (this.sizers.length >= 8)
  70064. {
  70065. if ((s.width < 2 * this.sizers[0].bounds.width + 2 * tol) ||
  70066. (s.height < 2 * this.sizers[0].bounds.height + 2 * tol))
  70067. {
  70068. this.sizers[0].node.style.display = 'none';
  70069. this.sizers[2].node.style.display = 'none';
  70070. this.sizers[5].node.style.display = 'none';
  70071. this.sizers[7].node.style.display = 'none';
  70072. }
  70073. else
  70074. {
  70075. this.sizers[0].node.style.display = '';
  70076. this.sizers[2].node.style.display = '';
  70077. this.sizers[5].node.style.display = '';
  70078. this.sizers[7].node.style.display = '';
  70079. }
  70080. }
  70081. }
  70082. var r = s.x + s.width;
  70083. var b = s.y + s.height;
  70084. if (this.singleSizer)
  70085. {
  70086. this.moveSizerTo(this.sizers[0], r, b);
  70087. }
  70088. else
  70089. {
  70090. var cx = s.x + s.width / 2;
  70091. var cy = s.y + s.height / 2;
  70092. if (this.sizers.length >= 8)
  70093. {
  70094. var crs = ['nw-resize', 'n-resize', 'ne-resize', 'e-resize', 'se-resize', 's-resize', 'sw-resize', 'w-resize'];
  70095. var alpha = mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  70096. var cos = Math.cos(alpha);
  70097. var sin = Math.sin(alpha);
  70098. var da = Math.round(alpha * 4 / Math.PI);
  70099. var ct = new mxPoint(s.getCenterX(), s.getCenterY());
  70100. var pt = mxUtils.getRotatedPoint(new mxPoint(s.x, s.y), cos, sin, ct);
  70101. this.moveSizerTo(this.sizers[0], pt.x, pt.y);
  70102. this.sizers[0].setCursor(crs[mxUtils.mod(0 + da, crs.length)]);
  70103. pt.x = cx;
  70104. pt.y = s.y;
  70105. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70106. this.moveSizerTo(this.sizers[1], pt.x, pt.y);
  70107. this.sizers[1].setCursor(crs[mxUtils.mod(1 + da, crs.length)]);
  70108. pt.x = r;
  70109. pt.y = s.y;
  70110. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70111. this.moveSizerTo(this.sizers[2], pt.x, pt.y);
  70112. this.sizers[2].setCursor(crs[mxUtils.mod(2 + da, crs.length)]);
  70113. pt.x = s.x;
  70114. pt.y = cy;
  70115. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70116. this.moveSizerTo(this.sizers[3], pt.x, pt.y);
  70117. this.sizers[3].setCursor(crs[mxUtils.mod(7 + da, crs.length)]);
  70118. pt.x = r;
  70119. pt.y = cy;
  70120. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70121. this.moveSizerTo(this.sizers[4], pt.x, pt.y);
  70122. this.sizers[4].setCursor(crs[mxUtils.mod(3 + da, crs.length)]);
  70123. pt.x = s.x;
  70124. pt.y = b;
  70125. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70126. this.moveSizerTo(this.sizers[5], pt.x, pt.y);
  70127. this.sizers[5].setCursor(crs[mxUtils.mod(6 + da, crs.length)]);
  70128. pt.x = cx;
  70129. pt.y = b;
  70130. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70131. this.moveSizerTo(this.sizers[6], pt.x, pt.y);
  70132. this.sizers[6].setCursor(crs[mxUtils.mod(5 + da, crs.length)]);
  70133. pt.x = r;
  70134. pt.y = b;
  70135. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70136. this.moveSizerTo(this.sizers[7], pt.x, pt.y);
  70137. this.sizers[7].setCursor(crs[mxUtils.mod(4 + da, crs.length)]);
  70138. pt.x = cx + this.state.absoluteOffset.x;
  70139. pt.y = cy + this.state.absoluteOffset.y;
  70140. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  70141. this.moveSizerTo(this.sizers[8], pt.x, pt.y);
  70142. }
  70143. else if (this.state.width >= 2 && this.state.height >= 2)
  70144. {
  70145. this.moveSizerTo(this.sizers[0], cx + this.state.absoluteOffset.x, cy + this.state.absoluteOffset.y);
  70146. }
  70147. else
  70148. {
  70149. this.moveSizerTo(this.sizers[0], this.state.x, this.state.y);
  70150. }
  70151. }
  70152. }
  70153. if (this.rotationShape != null)
  70154. {
  70155. var alpha = mxUtils.toRadians((this.currentAlpha != null) ? this.currentAlpha : this.state.style[mxConstants.STYLE_ROTATION] || '0');
  70156. var cos = Math.cos(alpha);
  70157. var sin = Math.sin(alpha);
  70158. var ct = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  70159. var pt = mxUtils.getRotatedPoint(this.getRotationHandlePosition(), cos, sin, ct);
  70160. if (this.rotationShape.node != null)
  70161. {
  70162. this.moveSizerTo(this.rotationShape, pt.x, pt.y);
  70163. // Hides rotation handle during text editing
  70164. this.rotationShape.node.style.visibility = (this.state.view.graph.isEditing()) ? 'hidden' : '';
  70165. }
  70166. }
  70167. if (this.selectionBorder != null)
  70168. {
  70169. this.selectionBorder.rotation = Number(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  70170. }
  70171. if (this.edgeHandlers != null)
  70172. {
  70173. for (var i = 0; i < this.edgeHandlers.length; i++)
  70174. {
  70175. this.edgeHandlers[i].redraw();
  70176. }
  70177. }
  70178. };
  70179. /**
  70180. * Function: isCustomHandleVisible
  70181. *
  70182. * Returns true if the given custom handle is visible.
  70183. */
  70184. mxVertexHandler.prototype.isCustomHandleVisible = function(handle)
  70185. {
  70186. return !this.graph.isEditing() && this.state.view.graph.getSelectionCount() == 1;
  70187. };
  70188. /**
  70189. * Function: getRotationHandlePosition
  70190. *
  70191. * Returns an <mxPoint> that defines the rotation handle position.
  70192. */
  70193. mxVertexHandler.prototype.getRotationHandlePosition = function()
  70194. {
  70195. return new mxPoint(this.bounds.x + this.bounds.width / 2, this.bounds.y + this.rotationHandleVSpacing)
  70196. };
  70197. /**
  70198. * Function: isParentHighlightVisible
  70199. *
  70200. * Returns true if the parent highlight should be visible. This implementation
  70201. * always returns true.
  70202. */
  70203. mxVertexHandler.prototype.isParentHighlightVisible = function()
  70204. {
  70205. return true;
  70206. };
  70207. /**
  70208. * Function: updateParentHighlight
  70209. *
  70210. * Updates the highlight of the parent if <parentHighlightEnabled> is true.
  70211. */
  70212. mxVertexHandler.prototype.updateParentHighlight = function()
  70213. {
  70214. // If not destroyed
  70215. if (this.selectionBorder != null && this.isParentHighlightVisible())
  70216. {
  70217. if (this.parentHighlight != null)
  70218. {
  70219. var parent = this.graph.model.getParent(this.state.cell);
  70220. if (this.graph.model.isVertex(parent))
  70221. {
  70222. var pstate = this.graph.view.getState(parent);
  70223. var b = this.parentHighlight.bounds;
  70224. if (pstate != null && (b.x != pstate.x || b.y != pstate.y ||
  70225. b.width != pstate.width || b.height != pstate.height))
  70226. {
  70227. this.parentHighlight.bounds = mxRectangle.fromRectangle(pstate);
  70228. this.parentHighlight.redraw();
  70229. }
  70230. }
  70231. else
  70232. {
  70233. this.parentHighlight.destroy();
  70234. this.parentHighlight = null;
  70235. }
  70236. }
  70237. else if (this.parentHighlightEnabled)
  70238. {
  70239. var parent = this.graph.model.getParent(this.state.cell);
  70240. if (this.graph.model.isVertex(parent))
  70241. {
  70242. var pstate = this.graph.view.getState(parent);
  70243. if (pstate != null)
  70244. {
  70245. this.parentHighlight = this.createParentHighlightShape(pstate);
  70246. // VML dialect required here for event transparency in IE
  70247. this.parentHighlight.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ? mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  70248. this.parentHighlight.pointerEvents = false;
  70249. this.parentHighlight.rotation = Number(pstate.style[mxConstants.STYLE_ROTATION] || '0');
  70250. this.parentHighlight.init(this.graph.getView().getOverlayPane());
  70251. this.parentHighlight.redraw();
  70252. }
  70253. }
  70254. }
  70255. }
  70256. };
  70257. /**
  70258. * Function: drawPreview
  70259. *
  70260. * Redraws the preview.
  70261. */
  70262. mxVertexHandler.prototype.drawPreview = function()
  70263. {
  70264. if (this.preview != null)
  70265. {
  70266. this.preview.bounds = this.bounds;
  70267. if (this.preview.node.parentNode == this.graph.container)
  70268. {
  70269. this.preview.bounds.width = Math.max(0, this.preview.bounds.width - 1);
  70270. this.preview.bounds.height = Math.max(0, this.preview.bounds.height - 1);
  70271. }
  70272. this.preview.rotation = Number(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  70273. this.preview.redraw();
  70274. }
  70275. this.selectionBorder.bounds = this.getSelectionBorderBounds();
  70276. this.selectionBorder.redraw();
  70277. this.updateParentHighlight();
  70278. };
  70279. /**
  70280. * Function: getSelectionBorderBounds
  70281. *
  70282. * Returns the bounds for the selection border.
  70283. */
  70284. mxVertexHandler.prototype.getSelectionBorderBounds = function()
  70285. {
  70286. return this.bounds;
  70287. };
  70288. /**
  70289. * Function: destroy
  70290. *
  70291. * Destroys the handler and all its resources and DOM nodes.
  70292. */
  70293. mxVertexHandler.prototype.destroy = function()
  70294. {
  70295. if (this.escapeHandler != null)
  70296. {
  70297. this.state.view.graph.removeListener(this.escapeHandler);
  70298. this.escapeHandler = null;
  70299. }
  70300. if (this.preview != null)
  70301. {
  70302. this.preview.destroy();
  70303. this.preview = null;
  70304. }
  70305. if (this.parentHighlight != null)
  70306. {
  70307. this.parentHighlight.destroy();
  70308. this.parentHighlight = null;
  70309. }
  70310. if (this.ghostPreview != null)
  70311. {
  70312. this.ghostPreview.destroy();
  70313. this.ghostPreview = null;
  70314. }
  70315. if (this.selectionBorder != null)
  70316. {
  70317. this.selectionBorder.destroy();
  70318. this.selectionBorder = null;
  70319. }
  70320. this.labelShape = null;
  70321. this.removeHint();
  70322. if (this.sizers != null)
  70323. {
  70324. for (var i = 0; i < this.sizers.length; i++)
  70325. {
  70326. this.sizers[i].destroy();
  70327. }
  70328. this.sizers = null;
  70329. }
  70330. if (this.customHandles != null)
  70331. {
  70332. for (var i = 0; i < this.customHandles.length; i++)
  70333. {
  70334. this.customHandles[i].destroy();
  70335. }
  70336. this.customHandles = null;
  70337. }
  70338. };
  70339. /**
  70340. * Copyright (c) 2006-2015, JGraph Ltd
  70341. * Copyright (c) 2006-2015, Gaudenz Alder
  70342. */
  70343. /**
  70344. * Class: mxEdgeHandler
  70345. *
  70346. * Graph event handler that reconnects edges and modifies control points and
  70347. * the edge label location. Uses <mxTerminalMarker> for finding and
  70348. * highlighting new source and target vertices. This handler is automatically
  70349. * created in <mxGraph.createHandler> for each selected edge.
  70350. *
  70351. * To enable adding/removing control points, the following code can be used:
  70352. *
  70353. * (code)
  70354. * mxEdgeHandler.prototype.addEnabled = true;
  70355. * mxEdgeHandler.prototype.removeEnabled = true;
  70356. * (end)
  70357. *
  70358. * Note: This experimental feature is not recommended for production use.
  70359. *
  70360. * Constructor: mxEdgeHandler
  70361. *
  70362. * Constructs an edge handler for the specified <mxCellState>.
  70363. *
  70364. * Parameters:
  70365. *
  70366. * state - <mxCellState> of the cell to be handled.
  70367. */
  70368. function mxEdgeHandler(state)
  70369. {
  70370. if (state != null)
  70371. {
  70372. this.state = state;
  70373. this.init();
  70374. // Handles escape keystrokes
  70375. this.escapeHandler = mxUtils.bind(this, function(sender, evt)
  70376. {
  70377. var dirty = this.index != null;
  70378. this.reset();
  70379. if (dirty)
  70380. {
  70381. this.graph.cellRenderer.redraw(this.state, false, state.view.isRendering());
  70382. }
  70383. });
  70384. this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
  70385. }
  70386. };
  70387. /**
  70388. * Variable: graph
  70389. *
  70390. * Reference to the enclosing <mxGraph>.
  70391. */
  70392. mxEdgeHandler.prototype.graph = null;
  70393. /**
  70394. * Variable: state
  70395. *
  70396. * Reference to the <mxCellState> being modified.
  70397. */
  70398. mxEdgeHandler.prototype.state = null;
  70399. /**
  70400. * Variable: marker
  70401. *
  70402. * Holds the <mxTerminalMarker> which is used for highlighting terminals.
  70403. */
  70404. mxEdgeHandler.prototype.marker = null;
  70405. /**
  70406. * Variable: constraintHandler
  70407. *
  70408. * Holds the <mxConstraintHandler> used for drawing and highlighting
  70409. * constraints.
  70410. */
  70411. mxEdgeHandler.prototype.constraintHandler = null;
  70412. /**
  70413. * Variable: error
  70414. *
  70415. * Holds the current validation error while a connection is being changed.
  70416. */
  70417. mxEdgeHandler.prototype.error = null;
  70418. /**
  70419. * Variable: shape
  70420. *
  70421. * Holds the <mxShape> that represents the preview edge.
  70422. */
  70423. mxEdgeHandler.prototype.shape = null;
  70424. /**
  70425. * Variable: bends
  70426. *
  70427. * Holds the <mxShapes> that represent the points.
  70428. */
  70429. mxEdgeHandler.prototype.bends = null;
  70430. /**
  70431. * Variable: labelShape
  70432. *
  70433. * Holds the <mxShape> that represents the label position.
  70434. */
  70435. mxEdgeHandler.prototype.labelShape = null;
  70436. /**
  70437. * Variable: cloneEnabled
  70438. *
  70439. * Specifies if cloning by control-drag is enabled. Default is true.
  70440. */
  70441. mxEdgeHandler.prototype.cloneEnabled = true;
  70442. /**
  70443. * Variable: addEnabled
  70444. *
  70445. * Specifies if adding bends by shift-click is enabled. Default is false.
  70446. * Note: This experimental feature is not recommended for production use.
  70447. */
  70448. mxEdgeHandler.prototype.addEnabled = false;
  70449. /**
  70450. * Variable: removeEnabled
  70451. *
  70452. * Specifies if removing bends by shift-click is enabled. Default is false.
  70453. * Note: This experimental feature is not recommended for production use.
  70454. */
  70455. mxEdgeHandler.prototype.removeEnabled = false;
  70456. /**
  70457. * Variable: dblClickRemoveEnabled
  70458. *
  70459. * Specifies if removing bends by double click is enabled. Default is false.
  70460. */
  70461. mxEdgeHandler.prototype.dblClickRemoveEnabled = false;
  70462. /**
  70463. * Variable: mergeRemoveEnabled
  70464. *
  70465. * Specifies if removing bends by dropping them on other bends is enabled.
  70466. * Default is false.
  70467. */
  70468. mxEdgeHandler.prototype.mergeRemoveEnabled = false;
  70469. /**
  70470. * Variable: straightRemoveEnabled
  70471. *
  70472. * Specifies if removing bends by creating straight segments should be enabled.
  70473. * If enabled, this can be overridden by holding down the alt key while moving.
  70474. * Default is false.
  70475. */
  70476. mxEdgeHandler.prototype.straightRemoveEnabled = false;
  70477. /**
  70478. * Variable: virtualBendsEnabled
  70479. *
  70480. * Specifies if virtual bends should be added in the center of each
  70481. * segments. These bends can then be used to add new waypoints.
  70482. * Default is false.
  70483. */
  70484. mxEdgeHandler.prototype.virtualBendsEnabled = false;
  70485. /**
  70486. * Variable: virtualBendOpacity
  70487. *
  70488. * Opacity to be used for virtual bends (see <virtualBendsEnabled>).
  70489. * Default is 20.
  70490. */
  70491. mxEdgeHandler.prototype.virtualBendOpacity = 20;
  70492. /**
  70493. * Variable: parentHighlightEnabled
  70494. *
  70495. * Specifies if the parent should be highlighted if a child cell is selected.
  70496. * Default is false.
  70497. */
  70498. mxEdgeHandler.prototype.parentHighlightEnabled = false;
  70499. /**
  70500. * Variable: preferHtml
  70501. *
  70502. * Specifies if bends should be added to the graph container. This is updated
  70503. * in <init> based on whether the edge or one of its terminals has an HTML
  70504. * label in the container.
  70505. */
  70506. mxEdgeHandler.prototype.preferHtml = false;
  70507. /**
  70508. * Variable: allowHandleBoundsCheck
  70509. *
  70510. * Specifies if the bounds of handles should be used for hit-detection in IE
  70511. * Default is true.
  70512. */
  70513. mxEdgeHandler.prototype.allowHandleBoundsCheck = true;
  70514. /**
  70515. * Variable: snapToTerminals
  70516. *
  70517. * Specifies if waypoints should snap to the routing centers of terminals.
  70518. * Default is false.
  70519. */
  70520. mxEdgeHandler.prototype.snapToTerminals = false;
  70521. /**
  70522. * Variable: handleImage
  70523. *
  70524. * Optional <mxImage> to be used as handles. Default is null.
  70525. */
  70526. mxEdgeHandler.prototype.handleImage = null;
  70527. /**
  70528. * Variable: tolerance
  70529. *
  70530. * Optional tolerance for hit-detection in <getHandleForEvent>. Default is 0.
  70531. */
  70532. mxEdgeHandler.prototype.tolerance = 0;
  70533. /**
  70534. * Variable: outlineConnect
  70535. *
  70536. * Specifies if connections to the outline of a highlighted target should be
  70537. * enabled. This will allow to place the connection point along the outline of
  70538. * the highlighted target. Default is false.
  70539. */
  70540. mxEdgeHandler.prototype.outlineConnect = false;
  70541. /**
  70542. * Variable: manageLabelHandle
  70543. *
  70544. * Specifies if the label handle should be moved if it intersects with another
  70545. * handle. Uses <checkLabelHandle> for checking and moving. Default is false.
  70546. */
  70547. mxEdgeHandler.prototype.manageLabelHandle = false;
  70548. /**
  70549. * Function: init
  70550. *
  70551. * Initializes the shapes required for this edge handler.
  70552. */
  70553. mxEdgeHandler.prototype.init = function()
  70554. {
  70555. this.graph = this.state.view.graph;
  70556. this.marker = this.createMarker();
  70557. this.constraintHandler = new mxConstraintHandler(this.graph);
  70558. // Clones the original points from the cell
  70559. // and makes sure at least one point exists
  70560. this.points = [];
  70561. // Uses the absolute points of the state
  70562. // for the initial configuration and preview
  70563. this.abspoints = this.getSelectionPoints(this.state);
  70564. this.shape = this.createSelectionShape(this.abspoints);
  70565. this.shape.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  70566. mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
  70567. this.shape.init(this.graph.getView().getOverlayPane());
  70568. this.shape.pointerEvents = false;
  70569. this.shape.setCursor(mxConstants.CURSOR_MOVABLE_EDGE);
  70570. mxEvent.redirectMouseEvents(this.shape.node, this.graph, this.state);
  70571. // Updates preferHtml
  70572. this.preferHtml = this.state.text != null &&
  70573. this.state.text.node.parentNode == this.graph.container;
  70574. if (!this.preferHtml)
  70575. {
  70576. // Checks source terminal
  70577. var sourceState = this.state.getVisibleTerminalState(true);
  70578. if (sourceState != null)
  70579. {
  70580. this.preferHtml = sourceState.text != null &&
  70581. sourceState.text.node.parentNode == this.graph.container;
  70582. }
  70583. if (!this.preferHtml)
  70584. {
  70585. // Checks target terminal
  70586. var targetState = this.state.getVisibleTerminalState(false);
  70587. if (targetState != null)
  70588. {
  70589. this.preferHtml = targetState.text != null &&
  70590. targetState.text.node.parentNode == this.graph.container;
  70591. }
  70592. }
  70593. }
  70594. // Adds highlight for parent group
  70595. if (this.parentHighlightEnabled)
  70596. {
  70597. var parent = this.graph.model.getParent(this.state.cell);
  70598. if (this.graph.model.isVertex(parent))
  70599. {
  70600. var pstate = this.graph.view.getState(parent);
  70601. if (pstate != null)
  70602. {
  70603. this.parentHighlight = this.createParentHighlightShape(pstate);
  70604. // VML dialect required here for event transparency in IE
  70605. this.parentHighlight.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ? mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  70606. this.parentHighlight.pointerEvents = false;
  70607. this.parentHighlight.rotation = Number(pstate.style[mxConstants.STYLE_ROTATION] || '0');
  70608. this.parentHighlight.init(this.graph.getView().getOverlayPane());
  70609. }
  70610. }
  70611. }
  70612. // Creates bends for the non-routed absolute points
  70613. // or bends that don't correspond to points
  70614. if (this.graph.getSelectionCount() < mxGraphHandler.prototype.maxCells ||
  70615. mxGraphHandler.prototype.maxCells <= 0)
  70616. {
  70617. this.bends = this.createBends();
  70618. if (this.isVirtualBendsEnabled())
  70619. {
  70620. this.virtualBends = this.createVirtualBends();
  70621. }
  70622. }
  70623. // Adds a rectangular handle for the label position
  70624. this.label = new mxPoint(this.state.absoluteOffset.x, this.state.absoluteOffset.y);
  70625. this.labelShape = this.createLabelHandleShape();
  70626. this.initBend(this.labelShape);
  70627. this.labelShape.setCursor(mxConstants.CURSOR_LABEL_HANDLE);
  70628. this.customHandles = this.createCustomHandles();
  70629. this.redraw();
  70630. };
  70631. /**
  70632. * Function: createCustomHandles
  70633. *
  70634. * Returns an array of custom handles. This implementation returns null.
  70635. */
  70636. mxEdgeHandler.prototype.createCustomHandles = function()
  70637. {
  70638. return null;
  70639. };
  70640. /**
  70641. * Function: isVirtualBendsEnabled
  70642. *
  70643. * Returns true if virtual bends should be added. This returns true if
  70644. * <virtualBendsEnabled> is true and the current style allows and
  70645. * renders custom waypoints.
  70646. */
  70647. mxEdgeHandler.prototype.isVirtualBendsEnabled = function(evt)
  70648. {
  70649. return this.virtualBendsEnabled && (this.state.style[mxConstants.STYLE_EDGE] == null ||
  70650. this.state.style[mxConstants.STYLE_EDGE] == mxConstants.NONE ||
  70651. this.state.style[mxConstants.STYLE_NOEDGESTYLE] == 1) &&
  70652. mxUtils.getValue(this.state.style, mxConstants.STYLE_SHAPE, null) != 'arrow';
  70653. };
  70654. /**
  70655. * Function: isCellEnabled
  70656. *
  70657. * Returns true if the given cell allows new connections to be created. This implementation
  70658. * always returns true.
  70659. */
  70660. mxEdgeHandler.prototype.isCellEnabled = function(cell)
  70661. {
  70662. return true;
  70663. };
  70664. /**
  70665. * Function: isAddPointEvent
  70666. *
  70667. * Returns true if the given event is a trigger to add a new point. This
  70668. * implementation returns true if shift is pressed.
  70669. */
  70670. mxEdgeHandler.prototype.isAddPointEvent = function(evt)
  70671. {
  70672. return mxEvent.isShiftDown(evt);
  70673. };
  70674. /**
  70675. * Function: isRemovePointEvent
  70676. *
  70677. * Returns true if the given event is a trigger to remove a point. This
  70678. * implementation returns true if shift is pressed.
  70679. */
  70680. mxEdgeHandler.prototype.isRemovePointEvent = function(evt)
  70681. {
  70682. return mxEvent.isShiftDown(evt);
  70683. };
  70684. /**
  70685. * Function: getSelectionPoints
  70686. *
  70687. * Returns the list of points that defines the selection stroke.
  70688. */
  70689. mxEdgeHandler.prototype.getSelectionPoints = function(state)
  70690. {
  70691. return state.absolutePoints;
  70692. };
  70693. /**
  70694. * Function: createSelectionShape
  70695. *
  70696. * Creates the shape used to draw the selection border.
  70697. */
  70698. mxEdgeHandler.prototype.createParentHighlightShape = function(bounds)
  70699. {
  70700. var shape = new mxRectangleShape(bounds, null, this.getSelectionColor());
  70701. shape.strokewidth = this.getSelectionStrokeWidth();
  70702. shape.isDashed = this.isSelectionDashed();
  70703. return shape;
  70704. };
  70705. /**
  70706. * Function: createSelectionShape
  70707. *
  70708. * Creates the shape used to draw the selection border.
  70709. */
  70710. mxEdgeHandler.prototype.createSelectionShape = function(points)
  70711. {
  70712. var shape = new this.state.shape.constructor();
  70713. shape.outline = true;
  70714. shape.apply(this.state);
  70715. shape.isDashed = this.isSelectionDashed();
  70716. shape.stroke = this.getSelectionColor();
  70717. shape.isShadow = false;
  70718. return shape;
  70719. };
  70720. /**
  70721. * Function: getSelectionColor
  70722. *
  70723. * Returns <mxConstants.EDGE_SELECTION_COLOR>.
  70724. */
  70725. mxEdgeHandler.prototype.getSelectionColor = function()
  70726. {
  70727. return mxConstants.EDGE_SELECTION_COLOR;
  70728. };
  70729. /**
  70730. * Function: getSelectionStrokeWidth
  70731. *
  70732. * Returns <mxConstants.EDGE_SELECTION_STROKEWIDTH>.
  70733. */
  70734. mxEdgeHandler.prototype.getSelectionStrokeWidth = function()
  70735. {
  70736. return mxConstants.EDGE_SELECTION_STROKEWIDTH;
  70737. };
  70738. /**
  70739. * Function: isSelectionDashed
  70740. *
  70741. * Returns <mxConstants.EDGE_SELECTION_DASHED>.
  70742. */
  70743. mxEdgeHandler.prototype.isSelectionDashed = function()
  70744. {
  70745. return mxConstants.EDGE_SELECTION_DASHED;
  70746. };
  70747. /**
  70748. * Function: isConnectableCell
  70749. *
  70750. * Returns true if the given cell is connectable. This is a hook to
  70751. * disable floating connections. This implementation returns true.
  70752. */
  70753. mxEdgeHandler.prototype.isConnectableCell = function(cell)
  70754. {
  70755. return true;
  70756. };
  70757. /**
  70758. * Function: getCellAt
  70759. *
  70760. * Creates and returns the <mxCellMarker> used in <marker>.
  70761. */
  70762. mxEdgeHandler.prototype.getCellAt = function(x, y)
  70763. {
  70764. return (!this.outlineConnect) ? this.graph.getCellAt(x, y) : null;
  70765. };
  70766. /**
  70767. * Function: createMarker
  70768. *
  70769. * Creates and returns the <mxCellMarker> used in <marker>.
  70770. */
  70771. mxEdgeHandler.prototype.createMarker = function()
  70772. {
  70773. var marker = new mxCellMarker(this.graph);
  70774. var self = this; // closure
  70775. // Only returns edges if they are connectable and never returns
  70776. // the edge that is currently being modified
  70777. marker.getCell = function(me)
  70778. {
  70779. var cell = mxCellMarker.prototype.getCell.apply(this, arguments);
  70780. // Checks for cell at preview point (with grid)
  70781. if ((cell == self.state.cell || cell == null) && self.currentPoint != null)
  70782. {
  70783. cell = self.graph.getCellAt(self.currentPoint.x, self.currentPoint.y);
  70784. }
  70785. // Uses connectable parent vertex if one exists
  70786. if (cell != null && !this.graph.isCellConnectable(cell))
  70787. {
  70788. var parent = this.graph.getModel().getParent(cell);
  70789. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  70790. {
  70791. cell = parent;
  70792. }
  70793. }
  70794. var model = self.graph.getModel();
  70795. if ((this.graph.isSwimlane(cell) && self.currentPoint != null &&
  70796. this.graph.hitsSwimlaneContent(cell, self.currentPoint.x, self.currentPoint.y)) ||
  70797. (!self.isConnectableCell(cell)) || (cell == self.state.cell ||
  70798. (cell != null && !self.graph.connectableEdges && model.isEdge(cell))) ||
  70799. model.isAncestor(self.state.cell, cell))
  70800. {
  70801. cell = null;
  70802. }
  70803. if (!this.graph.isCellConnectable(cell))
  70804. {
  70805. cell = null;
  70806. }
  70807. return cell;
  70808. };
  70809. // Sets the highlight color according to validateConnection
  70810. marker.isValidState = function(state)
  70811. {
  70812. var model = self.graph.getModel();
  70813. var other = self.graph.view.getTerminalPort(state,
  70814. self.graph.view.getState(model.getTerminal(self.state.cell,
  70815. !self.isSource)), !self.isSource);
  70816. var otherCell = (other != null) ? other.cell : null;
  70817. var source = (self.isSource) ? state.cell : otherCell;
  70818. var target = (self.isSource) ? otherCell : state.cell;
  70819. // Updates the error message of the handler
  70820. self.error = self.validateConnection(source, target);
  70821. return self.error == null;
  70822. };
  70823. return marker;
  70824. };
  70825. /**
  70826. * Function: validateConnection
  70827. *
  70828. * Returns the error message or an empty string if the connection for the
  70829. * given source, target pair is not valid. Otherwise it returns null. This
  70830. * implementation uses <mxGraph.getEdgeValidationError>.
  70831. *
  70832. * Parameters:
  70833. *
  70834. * source - <mxCell> that represents the source terminal.
  70835. * target - <mxCell> that represents the target terminal.
  70836. */
  70837. mxEdgeHandler.prototype.validateConnection = function(source, target)
  70838. {
  70839. return this.graph.getEdgeValidationError(this.state.cell, source, target);
  70840. };
  70841. /**
  70842. * Function: createBends
  70843. *
  70844. * Creates and returns the bends used for modifying the edge. This is
  70845. * typically an array of <mxRectangleShapes>.
  70846. */
  70847. mxEdgeHandler.prototype.createBends = function()
  70848. {
  70849. var cell = this.state.cell;
  70850. var bends = [];
  70851. for (var i = 0; i < this.abspoints.length; i++)
  70852. {
  70853. if (this.isHandleVisible(i))
  70854. {
  70855. var source = i == 0;
  70856. var target = i == this.abspoints.length - 1;
  70857. var terminal = source || target;
  70858. if (terminal || this.graph.isCellBendable(cell))
  70859. {
  70860. (mxUtils.bind(this, function(index)
  70861. {
  70862. var bend = this.createHandleShape(index);
  70863. this.initBend(bend, mxUtils.bind(this, mxUtils.bind(this, function()
  70864. {
  70865. if (this.dblClickRemoveEnabled)
  70866. {
  70867. this.removePoint(this.state, index);
  70868. }
  70869. })));
  70870. if (this.isHandleEnabled(i))
  70871. {
  70872. bend.setCursor((terminal) ? mxConstants.CURSOR_TERMINAL_HANDLE : mxConstants.CURSOR_BEND_HANDLE);
  70873. }
  70874. bends.push(bend);
  70875. if (!terminal)
  70876. {
  70877. this.points.push(new mxPoint(0,0));
  70878. bend.node.style.visibility = 'hidden';
  70879. }
  70880. }))(i);
  70881. }
  70882. }
  70883. }
  70884. return bends;
  70885. };
  70886. /**
  70887. * Function: createVirtualBends
  70888. *
  70889. * Creates and returns the bends used for modifying the edge. This is
  70890. * typically an array of <mxRectangleShapes>.
  70891. */
  70892. mxEdgeHandler.prototype.createVirtualBends = function()
  70893. {
  70894. var cell = this.state.cell;
  70895. var last = this.abspoints[0];
  70896. var bends = [];
  70897. if (this.graph.isCellBendable(cell))
  70898. {
  70899. for (var i = 1; i < this.abspoints.length; i++)
  70900. {
  70901. (mxUtils.bind(this, function(bend)
  70902. {
  70903. this.initBend(bend);
  70904. bend.setCursor(mxConstants.CURSOR_VIRTUAL_BEND_HANDLE);
  70905. bends.push(bend);
  70906. }))(this.createHandleShape());
  70907. }
  70908. }
  70909. return bends;
  70910. };
  70911. /**
  70912. * Function: isHandleEnabled
  70913. *
  70914. * Creates the shape used to display the given bend.
  70915. */
  70916. mxEdgeHandler.prototype.isHandleEnabled = function(index)
  70917. {
  70918. return true;
  70919. };
  70920. /**
  70921. * Function: isHandleVisible
  70922. *
  70923. * Returns true if the handle at the given index is visible.
  70924. */
  70925. mxEdgeHandler.prototype.isHandleVisible = function(index)
  70926. {
  70927. var source = this.state.getVisibleTerminalState(true);
  70928. var target = this.state.getVisibleTerminalState(false);
  70929. var geo = this.graph.getCellGeometry(this.state.cell);
  70930. var edgeStyle = (geo != null) ? this.graph.view.getEdgeStyle(this.state, geo.points, source, target) : null;
  70931. return edgeStyle != mxEdgeStyle.EntityRelation || index == 0 || index == this.abspoints.length - 1;
  70932. };
  70933. /**
  70934. * Function: createHandleShape
  70935. *
  70936. * Creates the shape used to display the given bend. Note that the index may be
  70937. * null for special cases, such as when called from
  70938. * <mxElbowEdgeHandler.createVirtualBend>. Only images and rectangles should be
  70939. * returned if support for HTML labels with not foreign objects is required.
  70940. * Index if null for virtual handles.
  70941. */
  70942. mxEdgeHandler.prototype.createHandleShape = function(index)
  70943. {
  70944. if (this.handleImage != null)
  70945. {
  70946. var shape = new mxImageShape(new mxRectangle(0, 0, this.handleImage.width, this.handleImage.height), this.handleImage.src);
  70947. // Allows HTML rendering of the images
  70948. shape.preserveImageAspect = false;
  70949. return shape;
  70950. }
  70951. else
  70952. {
  70953. var s = mxConstants.HANDLE_SIZE;
  70954. if (this.preferHtml)
  70955. {
  70956. s -= 1;
  70957. }
  70958. return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  70959. }
  70960. };
  70961. /**
  70962. * Function: createLabelHandleShape
  70963. *
  70964. * Creates the shape used to display the the label handle.
  70965. */
  70966. mxEdgeHandler.prototype.createLabelHandleShape = function()
  70967. {
  70968. if (this.labelHandleImage != null)
  70969. {
  70970. var shape = new mxImageShape(new mxRectangle(0, 0, this.labelHandleImage.width, this.labelHandleImage.height), this.labelHandleImage.src);
  70971. // Allows HTML rendering of the images
  70972. shape.preserveImageAspect = false;
  70973. return shape;
  70974. }
  70975. else
  70976. {
  70977. var s = mxConstants.LABEL_HANDLE_SIZE;
  70978. return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.LABEL_HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  70979. }
  70980. };
  70981. /**
  70982. * Function: initBend
  70983. *
  70984. * Helper method to initialize the given bend.
  70985. *
  70986. * Parameters:
  70987. *
  70988. * bend - <mxShape> that represents the bend to be initialized.
  70989. */
  70990. mxEdgeHandler.prototype.initBend = function(bend, dblClick)
  70991. {
  70992. if (this.preferHtml)
  70993. {
  70994. bend.dialect = mxConstants.DIALECT_STRICTHTML;
  70995. bend.init(this.graph.container);
  70996. }
  70997. else
  70998. {
  70999. bend.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  71000. mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
  71001. bend.init(this.graph.getView().getOverlayPane());
  71002. }
  71003. mxEvent.redirectMouseEvents(bend.node, this.graph, this.state,
  71004. null, null, null, dblClick);
  71005. // Fixes lost event tracking for images in quirks / IE8 standards
  71006. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  71007. {
  71008. mxEvent.addListener(bend.node, 'dragstart', function(evt)
  71009. {
  71010. mxEvent.consume(evt);
  71011. return false;
  71012. });
  71013. }
  71014. if (mxClient.IS_TOUCH)
  71015. {
  71016. bend.node.setAttribute('pointer-events', 'none');
  71017. }
  71018. };
  71019. /**
  71020. * Function: getHandleForEvent
  71021. *
  71022. * Returns the index of the handle for the given event.
  71023. */
  71024. mxEdgeHandler.prototype.getHandleForEvent = function(me)
  71025. {
  71026. // Connection highlight may consume events before they reach sizer handle
  71027. var tol = (!mxEvent.isMouseEvent(me.getEvent())) ? this.tolerance : 1;
  71028. var hit = (this.allowHandleBoundsCheck && (mxClient.IS_IE || tol > 0)) ?
  71029. new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol) : null;
  71030. var minDistSq = null;
  71031. var result = null;
  71032. function checkShape(shape)
  71033. {
  71034. if (shape != null && shape.node != null && shape.node.style.display != 'none' &&
  71035. shape.node.style.visibility != 'hidden' &&
  71036. (me.isSource(shape) || (hit != null && mxUtils.intersects(shape.bounds, hit))))
  71037. {
  71038. var dx = me.getGraphX() - shape.bounds.getCenterX();
  71039. var dy = me.getGraphY() - shape.bounds.getCenterY();
  71040. var tmp = dx * dx + dy * dy;
  71041. if (minDistSq == null || tmp <= minDistSq)
  71042. {
  71043. minDistSq = tmp;
  71044. return true;
  71045. }
  71046. }
  71047. return false;
  71048. }
  71049. if (this.customHandles != null && this.isCustomHandleEvent(me))
  71050. {
  71051. // Inverse loop order to match display order
  71052. for (var i = this.customHandles.length - 1; i >= 0; i--)
  71053. {
  71054. if (checkShape(this.customHandles[i].shape))
  71055. {
  71056. // LATER: Return reference to active shape
  71057. return mxEvent.CUSTOM_HANDLE - i;
  71058. }
  71059. }
  71060. }
  71061. if (me.isSource(this.state.text) || checkShape(this.labelShape))
  71062. {
  71063. result = mxEvent.LABEL_HANDLE;
  71064. }
  71065. if (this.bends != null)
  71066. {
  71067. for (var i = 0; i < this.bends.length; i++)
  71068. {
  71069. if (checkShape(this.bends[i]))
  71070. {
  71071. result = i;
  71072. }
  71073. }
  71074. }
  71075. if (this.virtualBends != null && this.isAddVirtualBendEvent(me))
  71076. {
  71077. for (var i = 0; i < this.virtualBends.length; i++)
  71078. {
  71079. if (checkShape(this.virtualBends[i]))
  71080. {
  71081. result = mxEvent.VIRTUAL_HANDLE - i;
  71082. }
  71083. }
  71084. }
  71085. return result;
  71086. };
  71087. /**
  71088. * Function: isAddVirtualBendEvent
  71089. *
  71090. * Returns true if the given event allows virtual bends to be added. This
  71091. * implementation returns true.
  71092. */
  71093. mxEdgeHandler.prototype.isAddVirtualBendEvent = function(me)
  71094. {
  71095. return true;
  71096. };
  71097. /**
  71098. * Function: isCustomHandleEvent
  71099. *
  71100. * Returns true if the given event allows custom handles to be changed. This
  71101. * implementation returns true.
  71102. */
  71103. mxEdgeHandler.prototype.isCustomHandleEvent = function(me)
  71104. {
  71105. return true;
  71106. };
  71107. /**
  71108. * Function: mouseDown
  71109. *
  71110. * Handles the event by checking if a special element of the handler
  71111. * was clicked, in which case the index parameter is non-null. The
  71112. * indices may be one of <LABEL_HANDLE> or the number of the respective
  71113. * control point. The source and target points are used for reconnecting
  71114. * the edge.
  71115. */
  71116. mxEdgeHandler.prototype.mouseDown = function(sender, me)
  71117. {
  71118. var handle = this.getHandleForEvent(me);
  71119. if (this.bends != null && this.bends[handle] != null)
  71120. {
  71121. var b = this.bends[handle].bounds;
  71122. this.snapPoint = new mxPoint(b.getCenterX(), b.getCenterY());
  71123. }
  71124. if (this.addEnabled && handle == null && this.isAddPointEvent(me.getEvent()))
  71125. {
  71126. this.addPoint(this.state, me.getEvent());
  71127. me.consume();
  71128. }
  71129. else if (handle != null && !me.isConsumed() && this.graph.isEnabled())
  71130. {
  71131. if (this.removeEnabled && this.isRemovePointEvent(me.getEvent()))
  71132. {
  71133. this.removePoint(this.state, handle);
  71134. }
  71135. else if (handle != mxEvent.LABEL_HANDLE || this.graph.isLabelMovable(me.getCell()))
  71136. {
  71137. if (handle <= mxEvent.VIRTUAL_HANDLE)
  71138. {
  71139. mxUtils.setOpacity(this.virtualBends[mxEvent.VIRTUAL_HANDLE - handle].node, 100);
  71140. }
  71141. this.start(me.getX(), me.getY(), handle);
  71142. }
  71143. me.consume();
  71144. }
  71145. };
  71146. /**
  71147. * Function: start
  71148. *
  71149. * Starts the handling of the mouse gesture.
  71150. */
  71151. mxEdgeHandler.prototype.start = function(x, y, index)
  71152. {
  71153. this.startX = x;
  71154. this.startY = y;
  71155. this.isSource = (this.bends == null) ? false : index == 0;
  71156. this.isTarget = (this.bends == null) ? false : index == this.bends.length - 1;
  71157. this.isLabel = index == mxEvent.LABEL_HANDLE;
  71158. if (this.isSource || this.isTarget)
  71159. {
  71160. var cell = this.state.cell;
  71161. var terminal = this.graph.model.getTerminal(cell, this.isSource);
  71162. if ((terminal == null && this.graph.isTerminalPointMovable(cell, this.isSource)) ||
  71163. (terminal != null && this.graph.isCellDisconnectable(cell, terminal, this.isSource)))
  71164. {
  71165. this.index = index;
  71166. }
  71167. }
  71168. else
  71169. {
  71170. this.index = index;
  71171. }
  71172. // Hides other custom handles
  71173. if (this.index <= mxEvent.CUSTOM_HANDLE && this.index > mxEvent.VIRTUAL_HANDLE)
  71174. {
  71175. if (this.customHandles != null)
  71176. {
  71177. for (var i = 0; i < this.customHandles.length; i++)
  71178. {
  71179. if (i != mxEvent.CUSTOM_HANDLE - this.index)
  71180. {
  71181. this.customHandles[i].setVisible(false);
  71182. }
  71183. }
  71184. }
  71185. }
  71186. };
  71187. /**
  71188. * Function: clonePreviewState
  71189. *
  71190. * Returns a clone of the current preview state for the given point and terminal.
  71191. */
  71192. mxEdgeHandler.prototype.clonePreviewState = function(point, terminal)
  71193. {
  71194. return this.state.clone();
  71195. };
  71196. /**
  71197. * Function: getSnapToTerminalTolerance
  71198. *
  71199. * Returns the tolerance for the guides. Default value is
  71200. * gridSize * scale / 2.
  71201. */
  71202. mxEdgeHandler.prototype.getSnapToTerminalTolerance = function()
  71203. {
  71204. return this.graph.gridSize * this.graph.view.scale / 2;
  71205. };
  71206. /**
  71207. * Function: updateHint
  71208. *
  71209. * Hook for subclassers do show details while the handler is active.
  71210. */
  71211. mxEdgeHandler.prototype.updateHint = function(me, point) { };
  71212. /**
  71213. * Function: removeHint
  71214. *
  71215. * Hooks for subclassers to hide details when the handler gets inactive.
  71216. */
  71217. mxEdgeHandler.prototype.removeHint = function() { };
  71218. /**
  71219. * Function: roundLength
  71220. *
  71221. * Hook for rounding the unscaled width or height. This uses Math.round.
  71222. */
  71223. mxEdgeHandler.prototype.roundLength = function(length)
  71224. {
  71225. return Math.round(length);
  71226. };
  71227. /**
  71228. * Function: isSnapToTerminalsEvent
  71229. *
  71230. * Returns true if <snapToTerminals> is true and if alt is not pressed.
  71231. */
  71232. mxEdgeHandler.prototype.isSnapToTerminalsEvent = function(me)
  71233. {
  71234. return this.snapToTerminals && !mxEvent.isAltDown(me.getEvent());
  71235. };
  71236. /**
  71237. * Function: getPointForEvent
  71238. *
  71239. * Returns the point for the given event.
  71240. */
  71241. mxEdgeHandler.prototype.getPointForEvent = function(me)
  71242. {
  71243. var view = this.graph.getView();
  71244. var scale = view.scale;
  71245. var point = new mxPoint(this.roundLength(me.getGraphX() / scale) * scale,
  71246. this.roundLength(me.getGraphY() / scale) * scale);
  71247. var tt = this.getSnapToTerminalTolerance();
  71248. var overrideX = false;
  71249. var overrideY = false;
  71250. if (tt > 0 && this.isSnapToTerminalsEvent(me))
  71251. {
  71252. function snapToPoint(pt)
  71253. {
  71254. if (pt != null)
  71255. {
  71256. var x = pt.x;
  71257. if (Math.abs(point.x - x) < tt)
  71258. {
  71259. point.x = x;
  71260. overrideX = true;
  71261. }
  71262. var y = pt.y;
  71263. if (Math.abs(point.y - y) < tt)
  71264. {
  71265. point.y = y;
  71266. overrideY = true;
  71267. }
  71268. }
  71269. }
  71270. // Temporary function
  71271. function snapToTerminal(terminal)
  71272. {
  71273. if (terminal != null)
  71274. {
  71275. snapToPoint.call(this, new mxPoint(view.getRoutingCenterX(terminal),
  71276. view.getRoutingCenterY(terminal)));
  71277. }
  71278. };
  71279. snapToTerminal.call(this, this.state.getVisibleTerminalState(true));
  71280. snapToTerminal.call(this, this.state.getVisibleTerminalState(false));
  71281. if (this.state.absolutePoints != null)
  71282. {
  71283. for (var i = 0; i < this.state.absolutePoints.length; i++)
  71284. {
  71285. snapToPoint.call(this, this.state.absolutePoints[i]);
  71286. }
  71287. }
  71288. }
  71289. if (this.graph.isGridEnabledEvent(me.getEvent()))
  71290. {
  71291. var tr = view.translate;
  71292. if (!overrideX)
  71293. {
  71294. point.x = (this.graph.snap(point.x / scale - tr.x) + tr.x) * scale;
  71295. }
  71296. if (!overrideY)
  71297. {
  71298. point.y = (this.graph.snap(point.y / scale - tr.y) + tr.y) * scale;
  71299. }
  71300. }
  71301. return point;
  71302. };
  71303. /**
  71304. * Function: getPreviewTerminalState
  71305. *
  71306. * Updates the given preview state taking into account the state of the constraint handler.
  71307. */
  71308. mxEdgeHandler.prototype.getPreviewTerminalState = function(me)
  71309. {
  71310. this.constraintHandler.update(me, this.isSource, true, me.isSource(this.marker.highlight.shape) ? null : this.currentPoint);
  71311. if (this.constraintHandler.currentFocus != null && this.constraintHandler.currentConstraint != null)
  71312. {
  71313. // Handles special case where grid is large and connection point is at actual point in which
  71314. // case the outline is not followed as long as we're < gridSize / 2 away from that point
  71315. if (this.marker.highlight != null && this.marker.highlight.state != null &&
  71316. this.marker.highlight.state.cell == this.constraintHandler.currentFocus.cell)
  71317. {
  71318. // Direct repaint needed if cell already highlighted
  71319. if (this.marker.highlight.shape.stroke != 'transparent')
  71320. {
  71321. this.marker.highlight.shape.stroke = 'transparent';
  71322. this.marker.highlight.repaint();
  71323. }
  71324. }
  71325. else
  71326. {
  71327. this.marker.markCell(this.constraintHandler.currentFocus.cell, 'transparent');
  71328. }
  71329. var model = this.graph.getModel();
  71330. var other = this.graph.view.getTerminalPort(this.state,
  71331. this.graph.view.getState(model.getTerminal(this.state.cell,
  71332. !this.isSource)), !this.isSource);
  71333. var otherCell = (other != null) ? other.cell : null;
  71334. var source = (this.isSource) ? this.constraintHandler.currentFocus.cell : otherCell;
  71335. var target = (this.isSource) ? otherCell : this.constraintHandler.currentFocus.cell;
  71336. // Updates the error message of the handler
  71337. this.error = this.validateConnection(source, target);
  71338. var result = null;
  71339. if (this.error == null)
  71340. {
  71341. result = this.constraintHandler.currentFocus;
  71342. }
  71343. if (this.error != null || (result != null &&
  71344. !this.isCellEnabled(result.cell)))
  71345. {
  71346. this.constraintHandler.reset();
  71347. }
  71348. return result;
  71349. }
  71350. else if (!this.graph.isIgnoreTerminalEvent(me.getEvent()))
  71351. {
  71352. this.marker.process(me);
  71353. var state = this.marker.getValidState();
  71354. if (state != null && !this.isCellEnabled(state.cell))
  71355. {
  71356. this.constraintHandler.reset();
  71357. this.marker.reset();
  71358. }
  71359. return this.marker.getValidState();
  71360. }
  71361. else
  71362. {
  71363. this.marker.reset();
  71364. return null;
  71365. }
  71366. };
  71367. /**
  71368. * Function: getPreviewPoints
  71369. *
  71370. * Updates the given preview state taking into account the state of the constraint handler.
  71371. *
  71372. * Parameters:
  71373. *
  71374. * pt - <mxPoint> that contains the current pointer position.
  71375. * me - Optional <mxMouseEvent> that contains the current event.
  71376. */
  71377. mxEdgeHandler.prototype.getPreviewPoints = function(pt, me)
  71378. {
  71379. var geometry = this.graph.getCellGeometry(this.state.cell);
  71380. var points = (geometry.points != null) ? geometry.points.slice() : null;
  71381. var point = new mxPoint(pt.x, pt.y);
  71382. var result = null;
  71383. if (!this.isSource && !this.isTarget)
  71384. {
  71385. this.convertPoint(point, false);
  71386. if (points == null)
  71387. {
  71388. points = [point];
  71389. }
  71390. else
  71391. {
  71392. // Adds point from virtual bend
  71393. if (this.index <= mxEvent.VIRTUAL_HANDLE)
  71394. {
  71395. points.splice(mxEvent.VIRTUAL_HANDLE - this.index, 0, point);
  71396. }
  71397. // Removes point if dragged on terminal point
  71398. if (!this.isSource && !this.isTarget)
  71399. {
  71400. for (var i = 0; i < this.bends.length; i++)
  71401. {
  71402. if (i != this.index)
  71403. {
  71404. var bend = this.bends[i];
  71405. if (bend != null && mxUtils.contains(bend.bounds, pt.x, pt.y))
  71406. {
  71407. if (this.index <= mxEvent.VIRTUAL_HANDLE)
  71408. {
  71409. points.splice(mxEvent.VIRTUAL_HANDLE - this.index, 1);
  71410. }
  71411. else
  71412. {
  71413. points.splice(this.index - 1, 1);
  71414. }
  71415. result = points;
  71416. }
  71417. }
  71418. }
  71419. // Removes point if user tries to straighten a segment
  71420. if (result == null && this.straightRemoveEnabled && (me == null || !mxEvent.isAltDown(me.getEvent())))
  71421. {
  71422. var tol = this.graph.tolerance * this.graph.tolerance;
  71423. var abs = this.state.absolutePoints.slice();
  71424. abs[this.index] = pt;
  71425. // Handes special case where removing waypoint affects tolerance (flickering)
  71426. var src = this.state.getVisibleTerminalState(true);
  71427. if (src != null)
  71428. {
  71429. var c = this.graph.getConnectionConstraint(this.state, src, true);
  71430. // Checks if point is not fixed
  71431. if (c == null || this.graph.getConnectionPoint(src, c) == null)
  71432. {
  71433. abs[0] = new mxPoint(src.view.getRoutingCenterX(src), src.view.getRoutingCenterY(src));
  71434. }
  71435. }
  71436. var trg = this.state.getVisibleTerminalState(false);
  71437. if (trg != null)
  71438. {
  71439. var c = this.graph.getConnectionConstraint(this.state, trg, false);
  71440. // Checks if point is not fixed
  71441. if (c == null || this.graph.getConnectionPoint(trg, c) == null)
  71442. {
  71443. abs[abs.length - 1] = new mxPoint(trg.view.getRoutingCenterX(trg), trg.view.getRoutingCenterY(trg));
  71444. }
  71445. }
  71446. function checkRemove(idx, tmp)
  71447. {
  71448. if (idx > 0 && idx < abs.length - 1 &&
  71449. mxUtils.ptSegDistSq(abs[idx - 1].x, abs[idx - 1].y,
  71450. abs[idx + 1].x, abs[idx + 1].y, tmp.x, tmp.y) < tol)
  71451. {
  71452. points.splice(idx - 1, 1);
  71453. result = points;
  71454. }
  71455. };
  71456. // LATER: Check if other points can be removed if a segment is made straight
  71457. checkRemove(this.index, pt);
  71458. }
  71459. }
  71460. // Updates existing point
  71461. if (result == null && this.index > mxEvent.VIRTUAL_HANDLE)
  71462. {
  71463. points[this.index - 1] = point;
  71464. }
  71465. }
  71466. }
  71467. else if (this.graph.resetEdgesOnConnect)
  71468. {
  71469. points = null;
  71470. }
  71471. return (result != null) ? result : points;
  71472. };
  71473. /**
  71474. * Function: isOutlineConnectEvent
  71475. *
  71476. * Returns true if <outlineConnect> is true and the source of the event is the outline shape
  71477. * or shift is pressed.
  71478. */
  71479. mxEdgeHandler.prototype.isOutlineConnectEvent = function(me)
  71480. {
  71481. var offset = mxUtils.getOffset(this.graph.container);
  71482. var evt = me.getEvent();
  71483. var clientX = mxEvent.getClientX(evt);
  71484. var clientY = mxEvent.getClientY(evt);
  71485. var doc = document.documentElement;
  71486. var left = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
  71487. var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
  71488. var gridX = this.currentPoint.x - this.graph.container.scrollLeft + offset.x - left;
  71489. var gridY = this.currentPoint.y - this.graph.container.scrollTop + offset.y - top;
  71490. return this.outlineConnect && !mxEvent.isShiftDown(me.getEvent()) &&
  71491. (me.isSource(this.marker.highlight.shape) ||
  71492. (mxEvent.isAltDown(me.getEvent()) && me.getState() != null) ||
  71493. this.marker.highlight.isHighlightAt(clientX, clientY) ||
  71494. ((gridX != clientX || gridY != clientY) && me.getState() == null &&
  71495. this.marker.highlight.isHighlightAt(gridX, gridY)));
  71496. };
  71497. /**
  71498. * Function: updatePreviewState
  71499. *
  71500. * Updates the given preview state taking into account the state of the constraint handler.
  71501. */
  71502. mxEdgeHandler.prototype.updatePreviewState = function(edge, point, terminalState, me, outline)
  71503. {
  71504. // Computes the points for the edge style and terminals
  71505. var sourceState = (this.isSource) ? terminalState : this.state.getVisibleTerminalState(true);
  71506. var targetState = (this.isTarget) ? terminalState : this.state.getVisibleTerminalState(false);
  71507. var sourceConstraint = this.graph.getConnectionConstraint(edge, sourceState, true);
  71508. var targetConstraint = this.graph.getConnectionConstraint(edge, targetState, false);
  71509. var constraint = this.constraintHandler.currentConstraint;
  71510. if (constraint == null && outline)
  71511. {
  71512. if (terminalState != null)
  71513. {
  71514. // Handles special case where mouse is on outline away from actual end point
  71515. // in which case the grid is ignored and mouse point is used instead
  71516. if (me.isSource(this.marker.highlight.shape))
  71517. {
  71518. point = new mxPoint(me.getGraphX(), me.getGraphY());
  71519. }
  71520. constraint = this.graph.getOutlineConstraint(point, terminalState, me);
  71521. this.constraintHandler.setFocus(me, terminalState, this.isSource);
  71522. this.constraintHandler.currentConstraint = constraint;
  71523. this.constraintHandler.currentPoint = point;
  71524. }
  71525. else
  71526. {
  71527. constraint = new mxConnectionConstraint();
  71528. }
  71529. }
  71530. if (this.outlineConnect && this.marker.highlight != null && this.marker.highlight.shape != null)
  71531. {
  71532. var s = this.graph.view.scale;
  71533. if (this.constraintHandler.currentConstraint != null &&
  71534. this.constraintHandler.currentFocus != null)
  71535. {
  71536. this.marker.highlight.shape.stroke = (outline) ? mxConstants.OUTLINE_HIGHLIGHT_COLOR : 'transparent';
  71537. this.marker.highlight.shape.strokewidth = mxConstants.OUTLINE_HIGHLIGHT_STROKEWIDTH / s / s;
  71538. this.marker.highlight.repaint();
  71539. }
  71540. else if (this.marker.hasValidState())
  71541. {
  71542. this.marker.highlight.shape.stroke = (this.graph.isCellConnectable(me.getCell()) &&
  71543. this.marker.getValidState() != me.getState()) ?
  71544. 'transparent' : mxConstants.DEFAULT_VALID_COLOR;
  71545. this.marker.highlight.shape.strokewidth = mxConstants.HIGHLIGHT_STROKEWIDTH / s / s;
  71546. this.marker.highlight.repaint();
  71547. }
  71548. }
  71549. if (this.isSource)
  71550. {
  71551. sourceConstraint = constraint;
  71552. }
  71553. else if (this.isTarget)
  71554. {
  71555. targetConstraint = constraint;
  71556. }
  71557. if (this.isSource || this.isTarget)
  71558. {
  71559. if (constraint != null && constraint.point != null)
  71560. {
  71561. edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_X : mxConstants.STYLE_ENTRY_X] = constraint.point.x;
  71562. edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_Y : mxConstants.STYLE_ENTRY_Y] = constraint.point.y;
  71563. }
  71564. else
  71565. {
  71566. delete edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_X : mxConstants.STYLE_ENTRY_X];
  71567. delete edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_Y : mxConstants.STYLE_ENTRY_Y];
  71568. }
  71569. }
  71570. edge.setVisibleTerminalState(sourceState, true);
  71571. edge.setVisibleTerminalState(targetState, false);
  71572. if (!this.isSource || sourceState != null)
  71573. {
  71574. edge.view.updateFixedTerminalPoint(edge, sourceState, true, sourceConstraint);
  71575. }
  71576. if (!this.isTarget || targetState != null)
  71577. {
  71578. edge.view.updateFixedTerminalPoint(edge, targetState, false, targetConstraint);
  71579. }
  71580. if ((this.isSource || this.isTarget) && terminalState == null)
  71581. {
  71582. edge.setAbsoluteTerminalPoint(point, this.isSource);
  71583. if (this.marker.getMarkedState() == null)
  71584. {
  71585. this.error = (this.graph.allowDanglingEdges) ? null : '';
  71586. }
  71587. }
  71588. edge.view.updatePoints(edge, this.points, sourceState, targetState);
  71589. edge.view.updateFloatingTerminalPoints(edge, sourceState, targetState);
  71590. };
  71591. /**
  71592. * Function: mouseMove
  71593. *
  71594. * Handles the event by updating the preview.
  71595. */
  71596. mxEdgeHandler.prototype.mouseMove = function(sender, me)
  71597. {
  71598. if (this.index != null && this.marker != null)
  71599. {
  71600. this.currentPoint = this.getPointForEvent(me);
  71601. this.error = null;
  71602. // Uses the current point from the constraint handler if available
  71603. if (!this.graph.isIgnoreTerminalEvent(me.getEvent()) && mxEvent.isShiftDown(me.getEvent()) && this.snapPoint != null)
  71604. {
  71605. if (Math.abs(this.snapPoint.x - this.currentPoint.x) < Math.abs(this.snapPoint.y - this.currentPoint.y))
  71606. {
  71607. this.currentPoint.x = this.snapPoint.x;
  71608. }
  71609. else
  71610. {
  71611. this.currentPoint.y = this.snapPoint.y;
  71612. }
  71613. }
  71614. if (this.index <= mxEvent.CUSTOM_HANDLE && this.index > mxEvent.VIRTUAL_HANDLE)
  71615. {
  71616. if (this.customHandles != null)
  71617. {
  71618. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].processEvent(me);
  71619. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].positionChanged();
  71620. }
  71621. }
  71622. else if (this.isLabel)
  71623. {
  71624. this.label.x = this.currentPoint.x;
  71625. this.label.y = this.currentPoint.y;
  71626. }
  71627. else
  71628. {
  71629. this.points = this.getPreviewPoints(this.currentPoint, me);
  71630. var terminalState = (this.isSource || this.isTarget) ? this.getPreviewTerminalState(me) : null;
  71631. if (this.constraintHandler.currentConstraint != null &&
  71632. this.constraintHandler.currentFocus != null &&
  71633. this.constraintHandler.currentPoint != null)
  71634. {
  71635. this.currentPoint = this.constraintHandler.currentPoint.clone();
  71636. }
  71637. else if (this.outlineConnect)
  71638. {
  71639. // Need to check outline before cloning terminal state
  71640. var outline = (this.isSource || this.isTarget) ? this.isOutlineConnectEvent(me) : false
  71641. if (outline)
  71642. {
  71643. terminalState = this.marker.highlight.state;
  71644. }
  71645. else if (terminalState != null && terminalState != me.getState() &&
  71646. this.graph.isCellConnectable(me.getCell()) &&
  71647. this.marker.highlight.shape != null)
  71648. {
  71649. this.marker.highlight.shape.stroke = 'transparent';
  71650. this.marker.highlight.repaint();
  71651. terminalState = null;
  71652. }
  71653. }
  71654. if (terminalState != null && !this.isCellEnabled(terminalState.cell))
  71655. {
  71656. terminalState = null;
  71657. this.marker.reset();
  71658. }
  71659. var clone = this.clonePreviewState(this.currentPoint, (terminalState != null) ? terminalState.cell : null);
  71660. this.updatePreviewState(clone, this.currentPoint, terminalState, me, outline);
  71661. // Sets the color of the preview to valid or invalid, updates the
  71662. // points of the preview and redraws
  71663. var color = (this.error == null) ? this.marker.validColor : this.marker.invalidColor;
  71664. this.setPreviewColor(color);
  71665. this.abspoints = clone.absolutePoints;
  71666. this.active = true;
  71667. this.updateHint(me, this.currentPoint);
  71668. }
  71669. // This should go before calling isOutlineConnectEvent above. As a workaround
  71670. // we add an offset of gridSize to the hint to avoid problem with hit detection
  71671. // in highlight.isHighlightAt (which uses comonentFromPoint)
  71672. this.drawPreview();
  71673. mxEvent.consume(me.getEvent());
  71674. me.consume();
  71675. }
  71676. // Workaround for disabling the connect highlight when over handle
  71677. else if (mxClient.IS_IE && this.getHandleForEvent(me) != null)
  71678. {
  71679. me.consume(false);
  71680. }
  71681. };
  71682. /**
  71683. * Function: mouseUp
  71684. *
  71685. * Handles the event to applying the previewed changes on the edge by
  71686. * using <moveLabel>, <connect> or <changePoints>.
  71687. */
  71688. mxEdgeHandler.prototype.mouseUp = function(sender, me)
  71689. {
  71690. // Workaround for wrong event source in Webkit
  71691. if (this.index != null && this.marker != null)
  71692. {
  71693. var edge = this.state.cell;
  71694. var index = this.index;
  71695. this.index = null;
  71696. // Ignores event if mouse has not been moved
  71697. if (me.getX() != this.startX || me.getY() != this.startY)
  71698. {
  71699. var clone = !this.graph.isIgnoreTerminalEvent(me.getEvent()) && this.graph.isCloneEvent(me.getEvent()) &&
  71700. this.cloneEnabled && this.graph.isCellsCloneable();
  71701. // Displays the reason for not carriying out the change
  71702. // if there is an error message with non-zero length
  71703. if (this.error != null)
  71704. {
  71705. if (this.error.length > 0)
  71706. {
  71707. this.graph.validationAlert(this.error);
  71708. }
  71709. }
  71710. else if (index <= mxEvent.CUSTOM_HANDLE && index > mxEvent.VIRTUAL_HANDLE)
  71711. {
  71712. if (this.customHandles != null)
  71713. {
  71714. var model = this.graph.getModel();
  71715. model.beginUpdate();
  71716. try
  71717. {
  71718. this.customHandles[mxEvent.CUSTOM_HANDLE - index].execute(me);
  71719. }
  71720. finally
  71721. {
  71722. model.endUpdate();
  71723. }
  71724. }
  71725. }
  71726. else if (this.isLabel)
  71727. {
  71728. this.moveLabel(this.state, this.label.x, this.label.y);
  71729. }
  71730. else if (this.isSource || this.isTarget)
  71731. {
  71732. var terminal = null;
  71733. if (this.constraintHandler.currentConstraint != null &&
  71734. this.constraintHandler.currentFocus != null)
  71735. {
  71736. terminal = this.constraintHandler.currentFocus.cell;
  71737. }
  71738. if (terminal == null && this.marker.hasValidState() && this.marker.highlight != null &&
  71739. this.marker.highlight.shape != null &&
  71740. this.marker.highlight.shape.stroke != 'transparent' &&
  71741. this.marker.highlight.shape.stroke != 'white')
  71742. {
  71743. terminal = this.marker.validState.cell;
  71744. }
  71745. if (terminal != null)
  71746. {
  71747. var model = this.graph.getModel();
  71748. var parent = model.getParent(edge);
  71749. model.beginUpdate();
  71750. try
  71751. {
  71752. // Clones and adds the cell
  71753. if (clone)
  71754. {
  71755. var geo = model.getGeometry(edge);
  71756. var clone = this.graph.cloneCell(edge);
  71757. model.add(parent, clone, model.getChildCount(parent));
  71758. if (geo != null)
  71759. {
  71760. geo = geo.clone();
  71761. model.setGeometry(clone, geo);
  71762. }
  71763. var other = model.getTerminal(edge, !this.isSource);
  71764. this.graph.connectCell(clone, other, !this.isSource);
  71765. edge = clone;
  71766. }
  71767. edge = this.connect(edge, terminal, this.isSource, clone, me);
  71768. }
  71769. finally
  71770. {
  71771. model.endUpdate();
  71772. }
  71773. }
  71774. else if (this.graph.isAllowDanglingEdges())
  71775. {
  71776. var pt = this.abspoints[(this.isSource) ? 0 : this.abspoints.length - 1];
  71777. pt.x = this.roundLength(pt.x / this.graph.view.scale - this.graph.view.translate.x);
  71778. pt.y = this.roundLength(pt.y / this.graph.view.scale - this.graph.view.translate.y);
  71779. var pstate = this.graph.getView().getState(
  71780. this.graph.getModel().getParent(edge));
  71781. if (pstate != null)
  71782. {
  71783. pt.x -= pstate.origin.x;
  71784. pt.y -= pstate.origin.y;
  71785. }
  71786. pt.x -= this.graph.panDx / this.graph.view.scale;
  71787. pt.y -= this.graph.panDy / this.graph.view.scale;
  71788. // Destroys and recreates this handler
  71789. edge = this.changeTerminalPoint(edge, pt, this.isSource, clone);
  71790. }
  71791. }
  71792. else if (this.active)
  71793. {
  71794. edge = this.changePoints(edge, this.points, clone);
  71795. }
  71796. else
  71797. {
  71798. this.graph.getView().invalidate(this.state.cell);
  71799. this.graph.getView().validate(this.state.cell);
  71800. }
  71801. }
  71802. else if (this.graph.isToggleEvent(me.getEvent()))
  71803. {
  71804. this.graph.selectCellForEvent(this.state.cell, me.getEvent());
  71805. }
  71806. // Resets the preview color the state of the handler if this
  71807. // handler has not been recreated
  71808. if (this.marker != null)
  71809. {
  71810. this.reset();
  71811. // Updates the selection if the edge has been cloned
  71812. if (edge != this.state.cell)
  71813. {
  71814. this.graph.setSelectionCell(edge);
  71815. }
  71816. }
  71817. me.consume();
  71818. }
  71819. };
  71820. /**
  71821. * Function: reset
  71822. *
  71823. * Resets the state of this handler.
  71824. */
  71825. mxEdgeHandler.prototype.reset = function()
  71826. {
  71827. if (this.active)
  71828. {
  71829. this.refresh();
  71830. }
  71831. this.error = null;
  71832. this.index = null;
  71833. this.label = null;
  71834. this.points = null;
  71835. this.snapPoint = null;
  71836. this.isLabel = false;
  71837. this.isSource = false;
  71838. this.isTarget = false;
  71839. this.active = false;
  71840. if (this.livePreview && this.sizers != null)
  71841. {
  71842. for (var i = 0; i < this.sizers.length; i++)
  71843. {
  71844. if (this.sizers[i] != null)
  71845. {
  71846. this.sizers[i].node.style.display = '';
  71847. }
  71848. }
  71849. }
  71850. if (this.marker != null)
  71851. {
  71852. this.marker.reset();
  71853. }
  71854. if (this.constraintHandler != null)
  71855. {
  71856. this.constraintHandler.reset();
  71857. }
  71858. if (this.customHandles != null)
  71859. {
  71860. for (var i = 0; i < this.customHandles.length; i++)
  71861. {
  71862. this.customHandles[i].reset();
  71863. }
  71864. }
  71865. this.setPreviewColor(mxConstants.EDGE_SELECTION_COLOR);
  71866. this.removeHint();
  71867. this.redraw();
  71868. };
  71869. /**
  71870. * Function: setPreviewColor
  71871. *
  71872. * Sets the color of the preview to the given value.
  71873. */
  71874. mxEdgeHandler.prototype.setPreviewColor = function(color)
  71875. {
  71876. if (this.shape != null)
  71877. {
  71878. this.shape.stroke = color;
  71879. }
  71880. };
  71881. /**
  71882. * Function: convertPoint
  71883. *
  71884. * Converts the given point in-place from screen to unscaled, untranslated
  71885. * graph coordinates and applies the grid. Returns the given, modified
  71886. * point instance.
  71887. *
  71888. * Parameters:
  71889. *
  71890. * point - <mxPoint> to be converted.
  71891. * gridEnabled - Boolean that specifies if the grid should be applied.
  71892. */
  71893. mxEdgeHandler.prototype.convertPoint = function(point, gridEnabled)
  71894. {
  71895. var scale = this.graph.getView().getScale();
  71896. var tr = this.graph.getView().getTranslate();
  71897. if (gridEnabled)
  71898. {
  71899. point.x = this.graph.snap(point.x);
  71900. point.y = this.graph.snap(point.y);
  71901. }
  71902. point.x = Math.round(point.x / scale - tr.x);
  71903. point.y = Math.round(point.y / scale - tr.y);
  71904. var pstate = this.graph.getView().getState(
  71905. this.graph.getModel().getParent(this.state.cell));
  71906. if (pstate != null)
  71907. {
  71908. point.x -= pstate.origin.x;
  71909. point.y -= pstate.origin.y;
  71910. }
  71911. return point;
  71912. };
  71913. /**
  71914. * Function: moveLabel
  71915. *
  71916. * Changes the coordinates for the label of the given edge.
  71917. *
  71918. * Parameters:
  71919. *
  71920. * edge - <mxCell> that represents the edge.
  71921. * x - Integer that specifies the x-coordinate of the new location.
  71922. * y - Integer that specifies the y-coordinate of the new location.
  71923. */
  71924. mxEdgeHandler.prototype.moveLabel = function(edgeState, x, y)
  71925. {
  71926. var model = this.graph.getModel();
  71927. var geometry = model.getGeometry(edgeState.cell);
  71928. if (geometry != null)
  71929. {
  71930. var scale = this.graph.getView().scale;
  71931. geometry = geometry.clone();
  71932. if (geometry.relative)
  71933. {
  71934. // Resets the relative location stored inside the geometry
  71935. var pt = this.graph.getView().getRelativePoint(edgeState, x, y);
  71936. geometry.x = Math.round(pt.x * 10000) / 10000;
  71937. geometry.y = Math.round(pt.y);
  71938. // Resets the offset inside the geometry to find the offset
  71939. // from the resulting point
  71940. geometry.offset = new mxPoint(0, 0);
  71941. var pt = this.graph.view.getPoint(edgeState, geometry);
  71942. geometry.offset = new mxPoint(Math.round((x - pt.x) / scale), Math.round((y - pt.y) / scale));
  71943. }
  71944. else
  71945. {
  71946. var points = edgeState.absolutePoints;
  71947. var p0 = points[0];
  71948. var pe = points[points.length - 1];
  71949. if (p0 != null && pe != null)
  71950. {
  71951. var cx = p0.x + (pe.x - p0.x) / 2;
  71952. var cy = p0.y + (pe.y - p0.y) / 2;
  71953. geometry.offset = new mxPoint(Math.round((x - cx) / scale), Math.round((y - cy) / scale));
  71954. geometry.x = 0;
  71955. geometry.y = 0;
  71956. }
  71957. }
  71958. model.setGeometry(edgeState.cell, geometry);
  71959. }
  71960. };
  71961. /**
  71962. * Function: connect
  71963. *
  71964. * Changes the terminal or terminal point of the given edge in the graph
  71965. * model.
  71966. *
  71967. * Parameters:
  71968. *
  71969. * edge - <mxCell> that represents the edge to be reconnected.
  71970. * terminal - <mxCell> that represents the new terminal.
  71971. * isSource - Boolean indicating if the new terminal is the source or
  71972. * target terminal.
  71973. * isClone - Boolean indicating if the new connection should be a clone of
  71974. * the old edge.
  71975. * me - <mxMouseEvent> that contains the mouse up event.
  71976. */
  71977. mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
  71978. {
  71979. var model = this.graph.getModel();
  71980. var parent = model.getParent(edge);
  71981. model.beginUpdate();
  71982. try
  71983. {
  71984. var constraint = this.constraintHandler.currentConstraint;
  71985. if (constraint == null)
  71986. {
  71987. constraint = new mxConnectionConstraint();
  71988. }
  71989. this.graph.connectCell(edge, terminal, isSource, constraint);
  71990. }
  71991. finally
  71992. {
  71993. model.endUpdate();
  71994. }
  71995. return edge;
  71996. };
  71997. /**
  71998. * Function: changeTerminalPoint
  71999. *
  72000. * Changes the terminal point of the given edge.
  72001. */
  72002. mxEdgeHandler.prototype.changeTerminalPoint = function(edge, point, isSource, clone)
  72003. {
  72004. var model = this.graph.getModel();
  72005. model.beginUpdate();
  72006. try
  72007. {
  72008. if (clone)
  72009. {
  72010. var parent = model.getParent(edge);
  72011. var terminal = model.getTerminal(edge, !isSource);
  72012. edge = this.graph.cloneCell(edge);
  72013. model.add(parent, edge, model.getChildCount(parent));
  72014. model.setTerminal(edge, terminal, !isSource);
  72015. }
  72016. var geo = model.getGeometry(edge);
  72017. if (geo != null)
  72018. {
  72019. geo = geo.clone();
  72020. geo.setTerminalPoint(point, isSource);
  72021. model.setGeometry(edge, geo);
  72022. this.graph.connectCell(edge, null, isSource, new mxConnectionConstraint());
  72023. }
  72024. }
  72025. finally
  72026. {
  72027. model.endUpdate();
  72028. }
  72029. return edge;
  72030. };
  72031. /**
  72032. * Function: changePoints
  72033. *
  72034. * Changes the control points of the given edge in the graph model.
  72035. */
  72036. mxEdgeHandler.prototype.changePoints = function(edge, points, clone)
  72037. {
  72038. var model = this.graph.getModel();
  72039. model.beginUpdate();
  72040. try
  72041. {
  72042. if (clone)
  72043. {
  72044. var parent = model.getParent(edge);
  72045. var source = model.getTerminal(edge, true);
  72046. var target = model.getTerminal(edge, false);
  72047. edge = this.graph.cloneCell(edge);
  72048. model.add(parent, edge, model.getChildCount(parent));
  72049. model.setTerminal(edge, source, true);
  72050. model.setTerminal(edge, target, false);
  72051. }
  72052. var geo = model.getGeometry(edge);
  72053. if (geo != null)
  72054. {
  72055. geo = geo.clone();
  72056. geo.points = points;
  72057. model.setGeometry(edge, geo);
  72058. }
  72059. }
  72060. finally
  72061. {
  72062. model.endUpdate();
  72063. }
  72064. return edge;
  72065. };
  72066. /**
  72067. * Function: addPoint
  72068. *
  72069. * Adds a control point for the given state and event.
  72070. */
  72071. mxEdgeHandler.prototype.addPoint = function(state, evt)
  72072. {
  72073. var pt = mxUtils.convertPoint(this.graph.container, mxEvent.getClientX(evt),
  72074. mxEvent.getClientY(evt));
  72075. var gridEnabled = this.graph.isGridEnabledEvent(evt);
  72076. this.convertPoint(pt, gridEnabled);
  72077. this.addPointAt(state, pt.x, pt.y);
  72078. mxEvent.consume(evt);
  72079. };
  72080. /**
  72081. * Function: addPointAt
  72082. *
  72083. * Adds a control point at the given point.
  72084. */
  72085. mxEdgeHandler.prototype.addPointAt = function(state, x, y)
  72086. {
  72087. var geo = this.graph.getCellGeometry(state.cell);
  72088. var pt = new mxPoint(x, y);
  72089. if (geo != null)
  72090. {
  72091. geo = geo.clone();
  72092. var t = this.graph.view.translate;
  72093. var s = this.graph.view.scale;
  72094. var offset = new mxPoint(t.x * s, t.y * s);
  72095. var parent = this.graph.model.getParent(this.state.cell);
  72096. if (this.graph.model.isVertex(parent))
  72097. {
  72098. var pState = this.graph.view.getState(parent);
  72099. offset = new mxPoint(pState.x, pState.y);
  72100. }
  72101. var index = mxUtils.findNearestSegment(state, pt.x * s + offset.x, pt.y * s + offset.y);
  72102. if (geo.points == null)
  72103. {
  72104. geo.points = [pt];
  72105. }
  72106. else
  72107. {
  72108. geo.points.splice(index, 0, pt);
  72109. }
  72110. this.graph.getModel().setGeometry(state.cell, geo);
  72111. this.refresh();
  72112. this.redraw();
  72113. }
  72114. };
  72115. /**
  72116. * Function: removePoint
  72117. *
  72118. * Removes the control point at the given index from the given state.
  72119. */
  72120. mxEdgeHandler.prototype.removePoint = function(state, index)
  72121. {
  72122. if (index > 0 && index < this.abspoints.length - 1)
  72123. {
  72124. var geo = this.graph.getCellGeometry(this.state.cell);
  72125. if (geo != null && geo.points != null)
  72126. {
  72127. geo = geo.clone();
  72128. geo.points.splice(index - 1, 1);
  72129. this.graph.getModel().setGeometry(state.cell, geo);
  72130. this.refresh();
  72131. this.redraw();
  72132. }
  72133. }
  72134. };
  72135. /**
  72136. * Function: getHandleFillColor
  72137. *
  72138. * Returns the fillcolor for the handle at the given index.
  72139. */
  72140. mxEdgeHandler.prototype.getHandleFillColor = function(index)
  72141. {
  72142. var isSource = index == 0;
  72143. var cell = this.state.cell;
  72144. var terminal = this.graph.getModel().getTerminal(cell, isSource);
  72145. var color = mxConstants.HANDLE_FILLCOLOR;
  72146. if ((terminal != null && !this.graph.isCellDisconnectable(cell, terminal, isSource)) ||
  72147. (terminal == null && !this.graph.isTerminalPointMovable(cell, isSource)))
  72148. {
  72149. color = mxConstants.LOCKED_HANDLE_FILLCOLOR;
  72150. }
  72151. else if (terminal != null && this.graph.isCellDisconnectable(cell, terminal, isSource))
  72152. {
  72153. color = mxConstants.CONNECT_HANDLE_FILLCOLOR;
  72154. }
  72155. return color;
  72156. };
  72157. /**
  72158. * Function: redraw
  72159. *
  72160. * Redraws the preview, and the bends- and label control points.
  72161. */
  72162. mxEdgeHandler.prototype.redraw = function(ignoreHandles)
  72163. {
  72164. this.abspoints = this.state.absolutePoints.slice();
  72165. var g = this.graph.getModel().getGeometry(this.state.cell);
  72166. if (g != null)
  72167. {
  72168. var pts = g.points;
  72169. if (this.bends != null && this.bends.length > 0)
  72170. {
  72171. if (pts != null)
  72172. {
  72173. if (this.points == null)
  72174. {
  72175. this.points = [];
  72176. }
  72177. for (var i = 1; i < this.bends.length - 1; i++)
  72178. {
  72179. if (this.bends[i] != null && this.abspoints[i] != null)
  72180. {
  72181. this.points[i - 1] = pts[i - 1];
  72182. }
  72183. }
  72184. }
  72185. }
  72186. }
  72187. this.drawPreview();
  72188. if (!ignoreHandles)
  72189. {
  72190. this.redrawHandles();
  72191. }
  72192. };
  72193. /**
  72194. * Function: redrawHandles
  72195. *
  72196. * Redraws the handles.
  72197. */
  72198. mxEdgeHandler.prototype.redrawHandles = function()
  72199. {
  72200. var cell = this.state.cell;
  72201. // Updates the handle for the label position
  72202. var b = this.labelShape.bounds;
  72203. this.label = new mxPoint(this.state.absoluteOffset.x, this.state.absoluteOffset.y);
  72204. this.labelShape.bounds = new mxRectangle(Math.round(this.label.x - b.width / 2),
  72205. Math.round(this.label.y - b.height / 2), b.width, b.height);
  72206. // Shows or hides the label handle depending on the label
  72207. var lab = this.graph.getLabel(cell);
  72208. this.labelShape.visible = (lab != null && lab.length > 0 && this.graph.isLabelMovable(cell));
  72209. if (this.bends != null && this.bends.length > 0)
  72210. {
  72211. var n = this.abspoints.length - 1;
  72212. var p0 = this.abspoints[0];
  72213. var x0 = p0.x;
  72214. var y0 = p0.y;
  72215. b = this.bends[0].bounds;
  72216. this.bends[0].bounds = new mxRectangle(Math.floor(x0 - b.width / 2),
  72217. Math.floor(y0 - b.height / 2), b.width, b.height);
  72218. this.bends[0].fill = this.getHandleFillColor(0);
  72219. this.bends[0].redraw();
  72220. if (this.manageLabelHandle)
  72221. {
  72222. this.checkLabelHandle(this.bends[0].bounds);
  72223. }
  72224. var pe = this.abspoints[n];
  72225. var xn = pe.x;
  72226. var yn = pe.y;
  72227. var bn = this.bends.length - 1;
  72228. b = this.bends[bn].bounds;
  72229. this.bends[bn].bounds = new mxRectangle(Math.floor(xn - b.width / 2),
  72230. Math.floor(yn - b.height / 2), b.width, b.height);
  72231. this.bends[bn].fill = this.getHandleFillColor(bn);
  72232. this.bends[bn].redraw();
  72233. if (this.manageLabelHandle)
  72234. {
  72235. this.checkLabelHandle(this.bends[bn].bounds);
  72236. }
  72237. this.redrawInnerBends(p0, pe);
  72238. }
  72239. if (this.abspoints != null && this.virtualBends != null && this.virtualBends.length > 0)
  72240. {
  72241. var last = this.abspoints[0];
  72242. for (var i = 0; i < this.virtualBends.length; i++)
  72243. {
  72244. if (this.virtualBends[i] != null && this.abspoints[i + 1] != null)
  72245. {
  72246. var pt = this.abspoints[i + 1];
  72247. var b = this.virtualBends[i];
  72248. var x = last.x + (pt.x - last.x) / 2;
  72249. var y = last.y + (pt.y - last.y) / 2;
  72250. b.bounds = new mxRectangle(Math.floor(x - b.bounds.width / 2),
  72251. Math.floor(y - b.bounds.height / 2), b.bounds.width, b.bounds.height);
  72252. b.redraw();
  72253. mxUtils.setOpacity(b.node, this.virtualBendOpacity);
  72254. last = pt;
  72255. if (this.manageLabelHandle)
  72256. {
  72257. this.checkLabelHandle(b.bounds);
  72258. }
  72259. }
  72260. }
  72261. }
  72262. if (this.labelShape != null)
  72263. {
  72264. this.labelShape.redraw();
  72265. }
  72266. if (this.customHandles != null)
  72267. {
  72268. for (var i = 0; i < this.customHandles.length; i++)
  72269. {
  72270. var temp = this.customHandles[i].shape.node.style.display;
  72271. this.customHandles[i].redraw();
  72272. this.customHandles[i].shape.node.style.display = temp;
  72273. // Hides custom handles during text editing
  72274. this.customHandles[i].shape.node.style.visibility =
  72275. (this.isCustomHandleVisible(this.customHandles[i])) ?
  72276. '' : 'hidden';
  72277. }
  72278. }
  72279. };
  72280. /**
  72281. * Function: isCustomHandleVisible
  72282. *
  72283. * Returns true if the given custom handle is visible.
  72284. */
  72285. mxEdgeHandler.prototype.isCustomHandleVisible = function(handle)
  72286. {
  72287. return !this.graph.isEditing() && this.state.view.graph.getSelectionCount() == 1;
  72288. };
  72289. /**
  72290. * Function: hideHandles
  72291. *
  72292. * Shortcut to <hideSizers>.
  72293. */
  72294. mxEdgeHandler.prototype.setHandlesVisible = function(visible)
  72295. {
  72296. if (this.bends != null)
  72297. {
  72298. for (var i = 0; i < this.bends.length; i++)
  72299. {
  72300. this.bends[i].node.style.display = (visible) ? '' : 'none';
  72301. }
  72302. }
  72303. if (this.virtualBends != null)
  72304. {
  72305. for (var i = 0; i < this.virtualBends.length; i++)
  72306. {
  72307. this.virtualBends[i].node.style.display = (visible) ? '' : 'none';
  72308. }
  72309. }
  72310. if (this.labelShape != null)
  72311. {
  72312. this.labelShape.node.style.display = (visible) ? '' : 'none';
  72313. }
  72314. if (this.customHandles != null)
  72315. {
  72316. for (var i = 0; i < this.customHandles.length; i++)
  72317. {
  72318. this.customHandles[i].setVisible(visible);
  72319. }
  72320. }
  72321. };
  72322. /**
  72323. * Function: redrawInnerBends
  72324. *
  72325. * Updates and redraws the inner bends.
  72326. *
  72327. * Parameters:
  72328. *
  72329. * p0 - <mxPoint> that represents the location of the first point.
  72330. * pe - <mxPoint> that represents the location of the last point.
  72331. */
  72332. mxEdgeHandler.prototype.redrawInnerBends = function(p0, pe)
  72333. {
  72334. for (var i = 1; i < this.bends.length - 1; i++)
  72335. {
  72336. if (this.bends[i] != null)
  72337. {
  72338. if (this.abspoints[i] != null)
  72339. {
  72340. var x = this.abspoints[i].x;
  72341. var y = this.abspoints[i].y;
  72342. var b = this.bends[i].bounds;
  72343. this.bends[i].node.style.visibility = 'visible';
  72344. this.bends[i].bounds = new mxRectangle(Math.round(x - b.width / 2),
  72345. Math.round(y - b.height / 2), b.width, b.height);
  72346. if (this.manageLabelHandle)
  72347. {
  72348. this.checkLabelHandle(this.bends[i].bounds);
  72349. }
  72350. else if (this.handleImage == null && this.labelShape.visible && mxUtils.intersects(this.bends[i].bounds, this.labelShape.bounds))
  72351. {
  72352. w = mxConstants.HANDLE_SIZE + 3;
  72353. h = mxConstants.HANDLE_SIZE + 3;
  72354. this.bends[i].bounds = new mxRectangle(Math.round(x - w / 2), Math.round(y - h / 2), w, h);
  72355. }
  72356. this.bends[i].redraw();
  72357. }
  72358. else
  72359. {
  72360. this.bends[i].destroy();
  72361. this.bends[i] = null;
  72362. }
  72363. }
  72364. }
  72365. };
  72366. /**
  72367. * Function: checkLabelHandle
  72368. *
  72369. * Checks if the label handle intersects the given bounds and moves it if it
  72370. * intersects.
  72371. */
  72372. mxEdgeHandler.prototype.checkLabelHandle = function(b)
  72373. {
  72374. if (this.labelShape != null)
  72375. {
  72376. var b2 = this.labelShape.bounds;
  72377. if (mxUtils.intersects(b, b2))
  72378. {
  72379. if (b.getCenterY() < b2.getCenterY())
  72380. {
  72381. b2.y = b.y + b.height;
  72382. }
  72383. else
  72384. {
  72385. b2.y = b.y - b2.height;
  72386. }
  72387. }
  72388. }
  72389. };
  72390. /**
  72391. * Function: drawPreview
  72392. *
  72393. * Redraws the preview.
  72394. */
  72395. mxEdgeHandler.prototype.drawPreview = function()
  72396. {
  72397. if (this.isLabel)
  72398. {
  72399. var b = this.labelShape.bounds;
  72400. var bounds = new mxRectangle(Math.round(this.label.x - b.width / 2),
  72401. Math.round(this.label.y - b.height / 2), b.width, b.height);
  72402. if (!this.labelShape.bounds.equals(bounds))
  72403. {
  72404. this.labelShape.bounds = bounds;
  72405. this.labelShape.redraw();
  72406. }
  72407. }
  72408. if (this.shape != null && !mxUtils.equalPoints(this.shape.points, this.abspoints))
  72409. {
  72410. this.shape.apply(this.state);
  72411. this.shape.points = this.abspoints.slice();
  72412. this.shape.scale = this.state.view.scale;
  72413. this.shape.isDashed = this.isSelectionDashed();
  72414. this.shape.stroke = this.getSelectionColor();
  72415. this.shape.strokewidth = this.getSelectionStrokeWidth() / this.shape.scale / this.shape.scale;
  72416. this.shape.isShadow = false;
  72417. this.shape.redraw();
  72418. }
  72419. if (this.parentHighlight != null)
  72420. {
  72421. this.parentHighlight.redraw();
  72422. }
  72423. };
  72424. /**
  72425. * Function: refresh
  72426. *
  72427. * Refreshes the bends of this handler.
  72428. */
  72429. mxEdgeHandler.prototype.refresh = function()
  72430. {
  72431. this.abspoints = this.getSelectionPoints(this.state);
  72432. this.points = [];
  72433. if (this.bends != null)
  72434. {
  72435. this.destroyBends(this.bends);
  72436. this.bends = this.createBends();
  72437. }
  72438. if (this.virtualBends != null)
  72439. {
  72440. this.destroyBends(this.virtualBends);
  72441. this.virtualBends = this.createVirtualBends();
  72442. }
  72443. if (this.customHandles != null)
  72444. {
  72445. this.destroyBends(this.customHandles);
  72446. this.customHandles = this.createCustomHandles();
  72447. }
  72448. // Puts label node on top of bends
  72449. if (this.labelShape != null && this.labelShape.node != null && this.labelShape.node.parentNode != null)
  72450. {
  72451. this.labelShape.node.parentNode.appendChild(this.labelShape.node);
  72452. }
  72453. };
  72454. /**
  72455. * Function: destroyBends
  72456. *
  72457. * Destroys all elements in <bends>.
  72458. */
  72459. mxEdgeHandler.prototype.destroyBends = function(bends)
  72460. {
  72461. if (bends != null)
  72462. {
  72463. for (var i = 0; i < bends.length; i++)
  72464. {
  72465. if (bends[i] != null)
  72466. {
  72467. bends[i].destroy();
  72468. }
  72469. }
  72470. }
  72471. };
  72472. /**
  72473. * Function: destroy
  72474. *
  72475. * Destroys the handler and all its resources and DOM nodes. This does
  72476. * normally not need to be called as handlers are destroyed automatically
  72477. * when the corresponding cell is deselected.
  72478. */
  72479. mxEdgeHandler.prototype.destroy = function()
  72480. {
  72481. if (this.escapeHandler != null)
  72482. {
  72483. this.state.view.graph.removeListener(this.escapeHandler);
  72484. this.escapeHandler = null;
  72485. }
  72486. if (this.marker != null)
  72487. {
  72488. this.marker.destroy();
  72489. this.marker = null;
  72490. }
  72491. if (this.shape != null)
  72492. {
  72493. this.shape.destroy();
  72494. this.shape = null;
  72495. }
  72496. if (this.parentHighlight != null)
  72497. {
  72498. this.parentHighlight.destroy();
  72499. this.parentHighlight = null;
  72500. }
  72501. if (this.labelShape != null)
  72502. {
  72503. this.labelShape.destroy();
  72504. this.labelShape = null;
  72505. }
  72506. if (this.constraintHandler != null)
  72507. {
  72508. this.constraintHandler.destroy();
  72509. this.constraintHandler = null;
  72510. }
  72511. this.destroyBends(this.virtualBends);
  72512. this.virtualBends = null;
  72513. this.destroyBends(this.customHandles);
  72514. this.customHandles = null;
  72515. this.destroyBends(this.bends);
  72516. this.bends = null;
  72517. this.removeHint();
  72518. };
  72519. /**
  72520. * Copyright (c) 2006-2015, JGraph Ltd
  72521. * Copyright (c) 2006-2015, Gaudenz Alder
  72522. */
  72523. /**
  72524. * Class: mxElbowEdgeHandler
  72525. *
  72526. * Graph event handler that reconnects edges and modifies control points and
  72527. * the edge label location. Uses <mxTerminalMarker> for finding and
  72528. * highlighting new source and target vertices. This handler is automatically
  72529. * created in <mxGraph.createHandler>. It extends <mxEdgeHandler>.
  72530. *
  72531. * Constructor: mxEdgeHandler
  72532. *
  72533. * Constructs an edge handler for the specified <mxCellState>.
  72534. *
  72535. * Parameters:
  72536. *
  72537. * state - <mxCellState> of the cell to be modified.
  72538. */
  72539. function mxElbowEdgeHandler(state)
  72540. {
  72541. mxEdgeHandler.call(this, state);
  72542. };
  72543. /**
  72544. * Extends mxEdgeHandler.
  72545. */
  72546. mxUtils.extend(mxElbowEdgeHandler, mxEdgeHandler);
  72547. /**
  72548. * Specifies if a double click on the middle handle should call
  72549. * <mxGraph.flipEdge>. Default is true.
  72550. */
  72551. mxElbowEdgeHandler.prototype.flipEnabled = true;
  72552. /**
  72553. * Variable: doubleClickOrientationResource
  72554. *
  72555. * Specifies the resource key for the tooltip to be displayed on the single
  72556. * control point for routed edges. If the resource for this key does not
  72557. * exist then the value is used as the error message. Default is
  72558. * 'doubleClickOrientation'.
  72559. */
  72560. mxElbowEdgeHandler.prototype.doubleClickOrientationResource =
  72561. (mxClient.language != 'none') ? 'doubleClickOrientation' : '';
  72562. /**
  72563. * Function: createBends
  72564. *
  72565. * Overrides <mxEdgeHandler.createBends> to create custom bends.
  72566. */
  72567. mxElbowEdgeHandler.prototype.createBends = function()
  72568. {
  72569. var bends = [];
  72570. // Source
  72571. var bend = this.createHandleShape(0);
  72572. this.initBend(bend);
  72573. bend.setCursor(mxConstants.CURSOR_TERMINAL_HANDLE);
  72574. bends.push(bend);
  72575. // Virtual
  72576. bends.push(this.createVirtualBend(mxUtils.bind(this, function(evt)
  72577. {
  72578. if (!mxEvent.isConsumed(evt) && this.flipEnabled)
  72579. {
  72580. this.graph.flipEdge(this.state.cell, evt);
  72581. mxEvent.consume(evt);
  72582. }
  72583. })));
  72584. this.points.push(new mxPoint(0,0));
  72585. // Target
  72586. bend = this.createHandleShape(2);
  72587. this.initBend(bend);
  72588. bend.setCursor(mxConstants.CURSOR_TERMINAL_HANDLE);
  72589. bends.push(bend);
  72590. return bends;
  72591. };
  72592. /**
  72593. * Function: createVirtualBend
  72594. *
  72595. * Creates a virtual bend that supports double clicking and calls
  72596. * <mxGraph.flipEdge>.
  72597. */
  72598. mxElbowEdgeHandler.prototype.createVirtualBend = function(dblClickHandler)
  72599. {
  72600. var bend = this.createHandleShape();
  72601. this.initBend(bend, dblClickHandler);
  72602. bend.setCursor(this.getCursorForBend());
  72603. if (!this.graph.isCellBendable(this.state.cell))
  72604. {
  72605. bend.node.style.display = 'none';
  72606. }
  72607. return bend;
  72608. };
  72609. /**
  72610. * Function: getCursorForBend
  72611. *
  72612. * Returns the cursor to be used for the bend.
  72613. */
  72614. mxElbowEdgeHandler.prototype.getCursorForBend = function()
  72615. {
  72616. return (this.state.style[mxConstants.STYLE_EDGE] == mxEdgeStyle.TopToBottom ||
  72617. this.state.style[mxConstants.STYLE_EDGE] == mxConstants.EDGESTYLE_TOPTOBOTTOM ||
  72618. ((this.state.style[mxConstants.STYLE_EDGE] == mxEdgeStyle.ElbowConnector ||
  72619. this.state.style[mxConstants.STYLE_EDGE] == mxConstants.EDGESTYLE_ELBOW)&&
  72620. this.state.style[mxConstants.STYLE_ELBOW] == mxConstants.ELBOW_VERTICAL)) ?
  72621. 'row-resize' : 'col-resize';
  72622. };
  72623. /**
  72624. * Function: getTooltipForNode
  72625. *
  72626. * Returns the tooltip for the given node.
  72627. */
  72628. mxElbowEdgeHandler.prototype.getTooltipForNode = function(node)
  72629. {
  72630. var tip = null;
  72631. if (this.bends != null && this.bends[1] != null && (node == this.bends[1].node ||
  72632. node.parentNode == this.bends[1].node))
  72633. {
  72634. tip = this.doubleClickOrientationResource;
  72635. tip = mxResources.get(tip) || tip; // translate
  72636. }
  72637. return tip;
  72638. };
  72639. /**
  72640. * Function: convertPoint
  72641. *
  72642. * Converts the given point in-place from screen to unscaled, untranslated
  72643. * graph coordinates and applies the grid.
  72644. *
  72645. * Parameters:
  72646. *
  72647. * point - <mxPoint> to be converted.
  72648. * gridEnabled - Boolean that specifies if the grid should be applied.
  72649. */
  72650. mxElbowEdgeHandler.prototype.convertPoint = function(point, gridEnabled)
  72651. {
  72652. var scale = this.graph.getView().getScale();
  72653. var tr = this.graph.getView().getTranslate();
  72654. var origin = this.state.origin;
  72655. if (gridEnabled)
  72656. {
  72657. point.x = this.graph.snap(point.x);
  72658. point.y = this.graph.snap(point.y);
  72659. }
  72660. point.x = Math.round(point.x / scale - tr.x - origin.x);
  72661. point.y = Math.round(point.y / scale - tr.y - origin.y);
  72662. return point;
  72663. };
  72664. /**
  72665. * Function: redrawInnerBends
  72666. *
  72667. * Updates and redraws the inner bends.
  72668. *
  72669. * Parameters:
  72670. *
  72671. * p0 - <mxPoint> that represents the location of the first point.
  72672. * pe - <mxPoint> that represents the location of the last point.
  72673. */
  72674. mxElbowEdgeHandler.prototype.redrawInnerBends = function(p0, pe)
  72675. {
  72676. var g = this.graph.getModel().getGeometry(this.state.cell);
  72677. var pts = this.state.absolutePoints;
  72678. var pt = null;
  72679. // Keeps the virtual bend on the edge shape
  72680. if (pts.length > 1)
  72681. {
  72682. p0 = pts[1];
  72683. pe = pts[pts.length - 2];
  72684. }
  72685. else if (g.points != null && g.points.length > 0)
  72686. {
  72687. pt = pts[0];
  72688. }
  72689. if (pt == null)
  72690. {
  72691. pt = new mxPoint(p0.x + (pe.x - p0.x) / 2, p0.y + (pe.y - p0.y) / 2);
  72692. }
  72693. else
  72694. {
  72695. pt = new mxPoint(this.graph.getView().scale * (pt.x + this.graph.getView().translate.x + this.state.origin.x),
  72696. this.graph.getView().scale * (pt.y + this.graph.getView().translate.y + this.state.origin.y));
  72697. }
  72698. // Makes handle slightly bigger if the yellow label handle
  72699. // exists and intersects this green handle
  72700. var b = this.bends[1].bounds;
  72701. var w = b.width;
  72702. var h = b.height;
  72703. var bounds = new mxRectangle(Math.round(pt.x - w / 2), Math.round(pt.y - h / 2), w, h);
  72704. if (this.manageLabelHandle)
  72705. {
  72706. this.checkLabelHandle(bounds);
  72707. }
  72708. else if (this.handleImage == null && this.labelShape.visible && mxUtils.intersects(bounds, this.labelShape.bounds))
  72709. {
  72710. w = mxConstants.HANDLE_SIZE + 3;
  72711. h = mxConstants.HANDLE_SIZE + 3;
  72712. bounds = new mxRectangle(Math.floor(pt.x - w / 2), Math.floor(pt.y - h / 2), w, h);
  72713. }
  72714. this.bends[1].bounds = bounds;
  72715. this.bends[1].redraw();
  72716. if (this.manageLabelHandle)
  72717. {
  72718. this.checkLabelHandle(this.bends[1].bounds);
  72719. }
  72720. };
  72721. /**
  72722. * Copyright (c) 2006-2015, JGraph Ltd
  72723. * Copyright (c) 2006-2015, Gaudenz Alder
  72724. */
  72725. function mxEdgeSegmentHandler(state)
  72726. {
  72727. mxEdgeHandler.call(this, state);
  72728. };
  72729. /**
  72730. * Extends mxEdgeHandler.
  72731. */
  72732. mxUtils.extend(mxEdgeSegmentHandler, mxElbowEdgeHandler);
  72733. /**
  72734. * Function: getCurrentPoints
  72735. *
  72736. * Returns the current absolute points.
  72737. */
  72738. mxEdgeSegmentHandler.prototype.getCurrentPoints = function()
  72739. {
  72740. var pts = this.state.absolutePoints;
  72741. if (pts != null)
  72742. {
  72743. // Special case for straight edges where we add a virtual middle handle for moving the edge
  72744. var tol = Math.max(1, this.graph.view.scale);
  72745. if (pts.length == 2 || (pts.length == 3 &&
  72746. (Math.abs(pts[0].x - pts[1].x) < tol && Math.abs(pts[1].x - pts[2].x) < tol ||
  72747. Math.abs(pts[0].y - pts[1].y) < tol && Math.abs(pts[1].y - pts[2].y) < tol)))
  72748. {
  72749. var cx = pts[0].x + (pts[pts.length - 1].x - pts[0].x) / 2;
  72750. var cy = pts[0].y + (pts[pts.length - 1].y - pts[0].y) / 2;
  72751. pts = [pts[0], new mxPoint(cx, cy), new mxPoint(cx, cy), pts[pts.length - 1]];
  72752. }
  72753. }
  72754. return pts;
  72755. };
  72756. /**
  72757. * Function: getPreviewPoints
  72758. *
  72759. * Updates the given preview state taking into account the state of the constraint handler.
  72760. */
  72761. mxEdgeSegmentHandler.prototype.getPreviewPoints = function(point)
  72762. {
  72763. if (this.isSource || this.isTarget)
  72764. {
  72765. return mxElbowEdgeHandler.prototype.getPreviewPoints.apply(this, arguments);
  72766. }
  72767. else
  72768. {
  72769. var pts = this.getCurrentPoints();
  72770. var last = this.convertPoint(pts[0].clone(), false);
  72771. point = this.convertPoint(point.clone(), false);
  72772. var result = [];
  72773. for (var i = 1; i < pts.length; i++)
  72774. {
  72775. var pt = this.convertPoint(pts[i].clone(), false);
  72776. if (i == this.index)
  72777. {
  72778. if (Math.round(last.x - pt.x) == 0)
  72779. {
  72780. last.x = point.x;
  72781. pt.x = point.x;
  72782. }
  72783. if (Math.round(last.y - pt.y) == 0)
  72784. {
  72785. last.y = point.y;
  72786. pt.y = point.y;
  72787. }
  72788. }
  72789. if (i < pts.length - 1)
  72790. {
  72791. result.push(pt);
  72792. }
  72793. last = pt;
  72794. }
  72795. // Replaces single point that intersects with source or target
  72796. if (result.length == 1)
  72797. {
  72798. var source = this.state.getVisibleTerminalState(true);
  72799. var target = this.state.getVisibleTerminalState(false);
  72800. var scale = this.state.view.getScale();
  72801. var tr = this.state.view.getTranslate();
  72802. var x = result[0].x * scale + tr.x;
  72803. var y = result[0].y * scale + tr.y;
  72804. if ((source != null && mxUtils.contains(source, x, y)) ||
  72805. (target != null && mxUtils.contains(target, x, y)))
  72806. {
  72807. result = [point, point];
  72808. }
  72809. }
  72810. return result;
  72811. }
  72812. };
  72813. /**
  72814. * Function: updatePreviewState
  72815. *
  72816. * Overridden to perform optimization of the edge style result.
  72817. */
  72818. mxEdgeSegmentHandler.prototype.updatePreviewState = function(edge, point, terminalState, me)
  72819. {
  72820. mxEdgeHandler.prototype.updatePreviewState.apply(this, arguments);
  72821. // Checks and corrects preview by running edge style again
  72822. if (!this.isSource && !this.isTarget)
  72823. {
  72824. point = this.convertPoint(point.clone(), false);
  72825. var pts = edge.absolutePoints;
  72826. var pt0 = pts[0];
  72827. var pt1 = pts[1];
  72828. var result = [];
  72829. for (var i = 2; i < pts.length; i++)
  72830. {
  72831. var pt2 = pts[i];
  72832. // Merges adjacent segments only if more than 2 to allow for straight edges
  72833. if ((Math.round(pt0.x - pt1.x) != 0 || Math.round(pt1.x - pt2.x) != 0) &&
  72834. (Math.round(pt0.y - pt1.y) != 0 || Math.round(pt1.y - pt2.y) != 0))
  72835. {
  72836. result.push(this.convertPoint(pt1.clone(), false));
  72837. }
  72838. pt0 = pt1;
  72839. pt1 = pt2;
  72840. }
  72841. var source = this.state.getVisibleTerminalState(true);
  72842. var target = this.state.getVisibleTerminalState(false);
  72843. var rpts = this.state.absolutePoints;
  72844. // A straight line is represented by 3 handles
  72845. if (result.length == 0 && (Math.round(pts[0].x - pts[pts.length - 1].x) == 0 ||
  72846. Math.round(pts[0].y - pts[pts.length - 1].y) == 0))
  72847. {
  72848. result = [point, point];
  72849. }
  72850. // Handles special case of transitions from straight vertical to routed
  72851. else if (pts.length == 5 && result.length == 2 && source != null && target != null &&
  72852. rpts != null && Math.round(rpts[0].x - rpts[rpts.length - 1].x) == 0)
  72853. {
  72854. var view = this.graph.getView();
  72855. var scale = view.getScale();
  72856. var tr = view.getTranslate();
  72857. var y0 = view.getRoutingCenterY(source) / scale - tr.y;
  72858. // Use fixed connection point y-coordinate if one exists
  72859. var sc = this.graph.getConnectionConstraint(edge, source, true);
  72860. if (sc != null)
  72861. {
  72862. var pt = this.graph.getConnectionPoint(source, sc);
  72863. if (pt != null)
  72864. {
  72865. this.convertPoint(pt, false);
  72866. y0 = pt.y;
  72867. }
  72868. }
  72869. var ye = view.getRoutingCenterY(target) / scale - tr.y;
  72870. // Use fixed connection point y-coordinate if one exists
  72871. var tc = this.graph.getConnectionConstraint(edge, target, false);
  72872. if (tc)
  72873. {
  72874. var pt = this.graph.getConnectionPoint(target, tc);
  72875. if (pt != null)
  72876. {
  72877. this.convertPoint(pt, false);
  72878. ye = pt.y;
  72879. }
  72880. }
  72881. result = [new mxPoint(point.x, y0), new mxPoint(point.x, ye)];
  72882. }
  72883. this.points = result;
  72884. // LATER: Check if points and result are different
  72885. edge.view.updateFixedTerminalPoints(edge, source, target);
  72886. edge.view.updatePoints(edge, this.points, source, target);
  72887. edge.view.updateFloatingTerminalPoints(edge, source, target);
  72888. }
  72889. };
  72890. /**
  72891. * Overriden to merge edge segments.
  72892. */
  72893. mxEdgeSegmentHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
  72894. {
  72895. var model = this.graph.getModel();
  72896. var geo = model.getGeometry(edge);
  72897. var result = null;
  72898. // Merges adjacent edge segments
  72899. if (geo != null && geo.points != null && geo.points.length > 0)
  72900. {
  72901. var pts = this.abspoints;
  72902. var pt0 = pts[0];
  72903. var pt1 = pts[1];
  72904. result = [];
  72905. for (var i = 2; i < pts.length; i++)
  72906. {
  72907. var pt2 = pts[i];
  72908. // Merges adjacent segments only if more than 2 to allow for straight edges
  72909. if ((Math.round(pt0.x - pt1.x) != 0 || Math.round(pt1.x - pt2.x) != 0) &&
  72910. (Math.round(pt0.y - pt1.y) != 0 || Math.round(pt1.y - pt2.y) != 0))
  72911. {
  72912. result.push(this.convertPoint(pt1.clone(), false));
  72913. }
  72914. pt0 = pt1;
  72915. pt1 = pt2;
  72916. }
  72917. }
  72918. model.beginUpdate();
  72919. try
  72920. {
  72921. if (result != null)
  72922. {
  72923. var geo = model.getGeometry(edge);
  72924. if (geo != null)
  72925. {
  72926. geo = geo.clone();
  72927. geo.points = result;
  72928. model.setGeometry(edge, geo);
  72929. }
  72930. }
  72931. edge = mxEdgeHandler.prototype.connect.apply(this, arguments);
  72932. }
  72933. finally
  72934. {
  72935. model.endUpdate();
  72936. }
  72937. return edge;
  72938. };
  72939. /**
  72940. * Function: getTooltipForNode
  72941. *
  72942. * Returns no tooltips.
  72943. */
  72944. mxEdgeSegmentHandler.prototype.getTooltipForNode = function(node)
  72945. {
  72946. return null;
  72947. };
  72948. /**
  72949. * Function: createBends
  72950. *
  72951. * Adds custom bends for the center of each segment.
  72952. */
  72953. mxEdgeSegmentHandler.prototype.start = function(x, y, index)
  72954. {
  72955. mxEdgeHandler.prototype.start.apply(this, arguments);
  72956. if (this.bends != null && this.bends[index] != null &&
  72957. !this.isSource && !this.isTarget)
  72958. {
  72959. mxUtils.setOpacity(this.bends[index].node, 100);
  72960. }
  72961. };
  72962. /**
  72963. * Function: createBends
  72964. *
  72965. * Adds custom bends for the center of each segment.
  72966. */
  72967. mxEdgeSegmentHandler.prototype.createBends = function()
  72968. {
  72969. var bends = [];
  72970. // Source
  72971. var bend = this.createHandleShape(0);
  72972. this.initBend(bend);
  72973. bend.setCursor(mxConstants.CURSOR_TERMINAL_HANDLE);
  72974. bends.push(bend);
  72975. var pts = this.getCurrentPoints();
  72976. // Waypoints (segment handles)
  72977. if (this.graph.isCellBendable(this.state.cell))
  72978. {
  72979. if (this.points == null)
  72980. {
  72981. this.points = [];
  72982. }
  72983. for (var i = 0; i < pts.length - 1; i++)
  72984. {
  72985. bend = this.createVirtualBend();
  72986. bends.push(bend);
  72987. var horizontal = Math.round(pts[i].x - pts[i + 1].x) == 0;
  72988. // Special case where dy is 0 as well
  72989. if (Math.round(pts[i].y - pts[i + 1].y) == 0 && i < pts.length - 2)
  72990. {
  72991. horizontal = Math.round(pts[i].x - pts[i + 2].x) == 0;
  72992. }
  72993. bend.setCursor((horizontal) ? 'col-resize' : 'row-resize');
  72994. this.points.push(new mxPoint(0,0));
  72995. }
  72996. }
  72997. // Target
  72998. var bend = this.createHandleShape(pts.length);
  72999. this.initBend(bend);
  73000. bend.setCursor(mxConstants.CURSOR_TERMINAL_HANDLE);
  73001. bends.push(bend);
  73002. return bends;
  73003. };
  73004. /**
  73005. * Function: redraw
  73006. *
  73007. * Overridden to invoke <refresh> before the redraw.
  73008. */
  73009. mxEdgeSegmentHandler.prototype.redraw = function()
  73010. {
  73011. this.refresh();
  73012. mxEdgeHandler.prototype.redraw.apply(this, arguments);
  73013. };
  73014. /**
  73015. * Function: redrawInnerBends
  73016. *
  73017. * Updates the position of the custom bends.
  73018. */
  73019. mxEdgeSegmentHandler.prototype.redrawInnerBends = function(p0, pe)
  73020. {
  73021. if (this.graph.isCellBendable(this.state.cell))
  73022. {
  73023. var pts = this.getCurrentPoints();
  73024. if (pts != null && pts.length > 1)
  73025. {
  73026. var straight = false;
  73027. // Puts handle in the center of straight edges
  73028. if (pts.length == 4 && Math.round(pts[1].x - pts[2].x) == 0 && Math.round(pts[1].y - pts[2].y) == 0)
  73029. {
  73030. straight = true;
  73031. if (Math.round(pts[0].y - pts[pts.length - 1].y) == 0)
  73032. {
  73033. var cx = pts[0].x + (pts[pts.length - 1].x - pts[0].x) / 2;
  73034. pts[1] = new mxPoint(cx, pts[1].y);
  73035. pts[2] = new mxPoint(cx, pts[2].y);
  73036. }
  73037. else
  73038. {
  73039. var cy = pts[0].y + (pts[pts.length - 1].y - pts[0].y) / 2;
  73040. pts[1] = new mxPoint(pts[1].x, cy);
  73041. pts[2] = new mxPoint(pts[2].x, cy);
  73042. }
  73043. }
  73044. for (var i = 0; i < pts.length - 1; i++)
  73045. {
  73046. if (this.bends[i + 1] != null)
  73047. {
  73048. var p0 = pts[i];
  73049. var pe = pts[i + 1];
  73050. var pt = new mxPoint(p0.x + (pe.x - p0.x) / 2, p0.y + (pe.y - p0.y) / 2);
  73051. var b = this.bends[i + 1].bounds;
  73052. this.bends[i + 1].bounds = new mxRectangle(Math.floor(pt.x - b.width / 2),
  73053. Math.floor(pt.y - b.height / 2), b.width, b.height);
  73054. this.bends[i + 1].redraw();
  73055. if (this.manageLabelHandle)
  73056. {
  73057. this.checkLabelHandle(this.bends[i + 1].bounds);
  73058. }
  73059. }
  73060. }
  73061. if (straight)
  73062. {
  73063. mxUtils.setOpacity(this.bends[1].node, this.virtualBendOpacity);
  73064. mxUtils.setOpacity(this.bends[3].node, this.virtualBendOpacity);
  73065. }
  73066. }
  73067. }
  73068. };
  73069. /**
  73070. * Copyright (c) 2006-2015, JGraph Ltd
  73071. * Copyright (c) 2006-2015, Gaudenz Alder
  73072. */
  73073. /**
  73074. * Class: mxKeyHandler
  73075. *
  73076. * Event handler that listens to keystroke events. This is not a singleton,
  73077. * however, it is normally only required once if the target is the document
  73078. * element (default).
  73079. *
  73080. * This handler installs a key event listener in the topmost DOM node and
  73081. * processes all events that originate from descandants of <mxGraph.container>
  73082. * or from the topmost DOM node. The latter means that all unhandled keystrokes
  73083. * are handled by this object regardless of the focused state of the <graph>.
  73084. *
  73085. * Example:
  73086. *
  73087. * The following example creates a key handler that listens to the delete key
  73088. * (46) and deletes the selection cells if the graph is enabled.
  73089. *
  73090. * (code)
  73091. * var keyHandler = new mxKeyHandler(graph);
  73092. * keyHandler.bindKey(46, function(evt)
  73093. * {
  73094. * if (graph.isEnabled())
  73095. * {
  73096. * graph.removeCells();
  73097. * }
  73098. * });
  73099. * (end)
  73100. *
  73101. * Keycodes:
  73102. *
  73103. * See http://tinyurl.com/yp8jgl or http://tinyurl.com/229yqw for a list of
  73104. * keycodes or install a key event listener into the document element and print
  73105. * the key codes of the respective events to the console.
  73106. *
  73107. * To support the Command key and the Control key on the Mac, the following
  73108. * code can be used.
  73109. *
  73110. * (code)
  73111. * keyHandler.getFunction = function(evt)
  73112. * {
  73113. * if (evt != null)
  73114. * {
  73115. * return (mxEvent.isControlDown(evt) || (mxClient.IS_MAC && evt.metaKey)) ? this.controlKeys[evt.keyCode] : this.normalKeys[evt.keyCode];
  73116. * }
  73117. *
  73118. * return null;
  73119. * };
  73120. * (end)
  73121. *
  73122. * Constructor: mxKeyHandler
  73123. *
  73124. * Constructs an event handler that executes functions bound to specific
  73125. * keystrokes.
  73126. *
  73127. * Parameters:
  73128. *
  73129. * graph - Reference to the associated <mxGraph>.
  73130. * target - Optional reference to the event target. If null, the document
  73131. * element is used as the event target, that is, the object where the key
  73132. * event listener is installed.
  73133. */
  73134. function mxKeyHandler(graph, target)
  73135. {
  73136. if (graph != null)
  73137. {
  73138. this.graph = graph;
  73139. this.target = target || document.documentElement;
  73140. // Creates the arrays to map from keycodes to functions
  73141. this.normalKeys = [];
  73142. this.shiftKeys = [];
  73143. this.controlKeys = [];
  73144. this.controlShiftKeys = [];
  73145. this.keydownHandler = mxUtils.bind(this, function(evt)
  73146. {
  73147. this.keyDown(evt);
  73148. });
  73149. // Installs the keystroke listener in the target
  73150. mxEvent.addListener(this.target, 'keydown', this.keydownHandler);
  73151. // Automatically deallocates memory in IE
  73152. if (mxClient.IS_IE)
  73153. {
  73154. mxEvent.addListener(window, 'unload',
  73155. mxUtils.bind(this, function()
  73156. {
  73157. this.destroy();
  73158. })
  73159. );
  73160. }
  73161. }
  73162. };
  73163. /**
  73164. * Variable: graph
  73165. *
  73166. * Reference to the <mxGraph> associated with this handler.
  73167. */
  73168. mxKeyHandler.prototype.graph = null;
  73169. /**
  73170. * Variable: target
  73171. *
  73172. * Reference to the target DOM, that is, the DOM node where the key event
  73173. * listeners are installed.
  73174. */
  73175. mxKeyHandler.prototype.target = null;
  73176. /**
  73177. * Variable: normalKeys
  73178. *
  73179. * Maps from keycodes to functions for non-pressed control keys.
  73180. */
  73181. mxKeyHandler.prototype.normalKeys = null;
  73182. /**
  73183. * Variable: shiftKeys
  73184. *
  73185. * Maps from keycodes to functions for pressed shift keys.
  73186. */
  73187. mxKeyHandler.prototype.shiftKeys = null;
  73188. /**
  73189. * Variable: controlKeys
  73190. *
  73191. * Maps from keycodes to functions for pressed control keys.
  73192. */
  73193. mxKeyHandler.prototype.controlKeys = null;
  73194. /**
  73195. * Variable: controlShiftKeys
  73196. *
  73197. * Maps from keycodes to functions for pressed control and shift keys.
  73198. */
  73199. mxKeyHandler.prototype.controlShiftKeys = null;
  73200. /**
  73201. * Variable: enabled
  73202. *
  73203. * Specifies if events are handled. Default is true.
  73204. */
  73205. mxKeyHandler.prototype.enabled = true;
  73206. /**
  73207. * Function: isEnabled
  73208. *
  73209. * Returns true if events are handled. This implementation returns
  73210. * <enabled>.
  73211. */
  73212. mxKeyHandler.prototype.isEnabled = function()
  73213. {
  73214. return this.enabled;
  73215. };
  73216. /**
  73217. * Function: setEnabled
  73218. *
  73219. * Enables or disables event handling by updating <enabled>.
  73220. *
  73221. * Parameters:
  73222. *
  73223. * enabled - Boolean that specifies the new enabled state.
  73224. */
  73225. mxKeyHandler.prototype.setEnabled = function(enabled)
  73226. {
  73227. this.enabled = enabled;
  73228. };
  73229. /**
  73230. * Function: bindKey
  73231. *
  73232. * Binds the specified keycode to the given function. This binding is used
  73233. * if the control key is not pressed.
  73234. *
  73235. * Parameters:
  73236. *
  73237. * code - Integer that specifies the keycode.
  73238. * funct - JavaScript function that takes the key event as an argument.
  73239. */
  73240. mxKeyHandler.prototype.bindKey = function(code, funct)
  73241. {
  73242. this.normalKeys[code] = funct;
  73243. };
  73244. /**
  73245. * Function: bindShiftKey
  73246. *
  73247. * Binds the specified keycode to the given function. This binding is used
  73248. * if the shift key is pressed.
  73249. *
  73250. * Parameters:
  73251. *
  73252. * code - Integer that specifies the keycode.
  73253. * funct - JavaScript function that takes the key event as an argument.
  73254. */
  73255. mxKeyHandler.prototype.bindShiftKey = function(code, funct)
  73256. {
  73257. this.shiftKeys[code] = funct;
  73258. };
  73259. /**
  73260. * Function: bindControlKey
  73261. *
  73262. * Binds the specified keycode to the given function. This binding is used
  73263. * if the control key is pressed.
  73264. *
  73265. * Parameters:
  73266. *
  73267. * code - Integer that specifies the keycode.
  73268. * funct - JavaScript function that takes the key event as an argument.
  73269. */
  73270. mxKeyHandler.prototype.bindControlKey = function(code, funct)
  73271. {
  73272. this.controlKeys[code] = funct;
  73273. };
  73274. /**
  73275. * Function: bindControlShiftKey
  73276. *
  73277. * Binds the specified keycode to the given function. This binding is used
  73278. * if the control and shift key are pressed.
  73279. *
  73280. * Parameters:
  73281. *
  73282. * code - Integer that specifies the keycode.
  73283. * funct - JavaScript function that takes the key event as an argument.
  73284. */
  73285. mxKeyHandler.prototype.bindControlShiftKey = function(code, funct)
  73286. {
  73287. this.controlShiftKeys[code] = funct;
  73288. };
  73289. /**
  73290. * Function: isControlDown
  73291. *
  73292. * Returns true if the control key is pressed. This uses <mxEvent.isControlDown>.
  73293. *
  73294. * Parameters:
  73295. *
  73296. * evt - Key event whose control key pressed state should be returned.
  73297. */
  73298. mxKeyHandler.prototype.isControlDown = function(evt)
  73299. {
  73300. return mxEvent.isControlDown(evt);
  73301. };
  73302. /**
  73303. * Function: getFunction
  73304. *
  73305. * Returns the function associated with the given key event or null if no
  73306. * function is associated with the given event.
  73307. *
  73308. * Parameters:
  73309. *
  73310. * evt - Key event whose associated function should be returned.
  73311. */
  73312. mxKeyHandler.prototype.getFunction = function(evt)
  73313. {
  73314. if (evt != null && !mxEvent.isAltDown(evt))
  73315. {
  73316. if (this.isControlDown(evt))
  73317. {
  73318. if (mxEvent.isShiftDown(evt))
  73319. {
  73320. return this.controlShiftKeys[evt.keyCode];
  73321. }
  73322. else
  73323. {
  73324. return this.controlKeys[evt.keyCode];
  73325. }
  73326. }
  73327. else
  73328. {
  73329. if (mxEvent.isShiftDown(evt))
  73330. {
  73331. return this.shiftKeys[evt.keyCode];
  73332. }
  73333. else
  73334. {
  73335. return this.normalKeys[evt.keyCode];
  73336. }
  73337. }
  73338. }
  73339. return null;
  73340. };
  73341. /**
  73342. * Function: isGraphEvent
  73343. *
  73344. * Returns true if the event should be processed by this handler, that is,
  73345. * if the event source is either the target, one of its direct children, a
  73346. * descendant of the <mxGraph.container>, or the <mxGraph.cellEditor> of the
  73347. * <graph>.
  73348. *
  73349. * Parameters:
  73350. *
  73351. * evt - Key event that represents the keystroke.
  73352. */
  73353. mxKeyHandler.prototype.isGraphEvent = function(evt)
  73354. {
  73355. var source = mxEvent.getSource(evt);
  73356. // Accepts events from the target object or
  73357. // in-place editing inside graph
  73358. if ((source == this.target || source.parentNode == this.target) ||
  73359. (this.graph.cellEditor != null && this.graph.cellEditor.isEventSource(evt)))
  73360. {
  73361. return true;
  73362. }
  73363. // Accepts events from inside the container
  73364. return mxUtils.isAncestorNode(this.graph.container, source);
  73365. };
  73366. /**
  73367. * Function: keyDown
  73368. *
  73369. * Handles the event by invoking the function bound to the respective keystroke
  73370. * if <isEnabledForEvent> returns true for the given event and if
  73371. * <isEventIgnored> returns false, except for escape for which
  73372. * <isEventIgnored> is not invoked.
  73373. *
  73374. * Parameters:
  73375. *
  73376. * evt - Key event that represents the keystroke.
  73377. */
  73378. mxKeyHandler.prototype.keyDown = function(evt)
  73379. {
  73380. if (this.isEnabledForEvent(evt))
  73381. {
  73382. // Cancels the editing if escape is pressed
  73383. if (evt.keyCode == 27 /* Escape */)
  73384. {
  73385. this.escape(evt);
  73386. }
  73387. // Invokes the function for the keystroke
  73388. else if (!this.isEventIgnored(evt))
  73389. {
  73390. var boundFunction = this.getFunction(evt);
  73391. if (boundFunction != null)
  73392. {
  73393. boundFunction(evt);
  73394. mxEvent.consume(evt);
  73395. }
  73396. }
  73397. }
  73398. };
  73399. /**
  73400. * Function: isEnabledForEvent
  73401. *
  73402. * Returns true if the given event should be handled. <isEventIgnored> is
  73403. * called later if the event is not an escape key stroke, in which case
  73404. * <escape> is called. This implementation returns true if <isEnabled>
  73405. * returns true for both, this handler and <graph>, if the event is not
  73406. * consumed and if <isGraphEvent> returns true.
  73407. *
  73408. * Parameters:
  73409. *
  73410. * evt - Key event that represents the keystroke.
  73411. */
  73412. mxKeyHandler.prototype.isEnabledForEvent = function(evt)
  73413. {
  73414. return (this.graph.isEnabled() && !mxEvent.isConsumed(evt) &&
  73415. this.isGraphEvent(evt) && this.isEnabled());
  73416. };
  73417. /**
  73418. * Function: isEventIgnored
  73419. *
  73420. * Returns true if the given keystroke should be ignored. This returns
  73421. * graph.isEditing().
  73422. *
  73423. * Parameters:
  73424. *
  73425. * evt - Key event that represents the keystroke.
  73426. */
  73427. mxKeyHandler.prototype.isEventIgnored = function(evt)
  73428. {
  73429. return this.graph.isEditing();
  73430. };
  73431. /**
  73432. * Function: escape
  73433. *
  73434. * Hook to process ESCAPE keystrokes. This implementation invokes
  73435. * <mxGraph.stopEditing> to cancel the current editing, connecting
  73436. * and/or other ongoing modifications.
  73437. *
  73438. * Parameters:
  73439. *
  73440. * evt - Key event that represents the keystroke. Possible keycode in this
  73441. * case is 27 (ESCAPE).
  73442. */
  73443. mxKeyHandler.prototype.escape = function(evt)
  73444. {
  73445. if (this.graph.isEscapeEnabled())
  73446. {
  73447. this.graph.escape(evt);
  73448. }
  73449. };
  73450. /**
  73451. * Function: destroy
  73452. *
  73453. * Destroys the handler and all its references into the DOM. This does
  73454. * normally not need to be called, it is called automatically when the
  73455. * window unloads (in IE).
  73456. */
  73457. mxKeyHandler.prototype.destroy = function()
  73458. {
  73459. if (this.target != null && this.keydownHandler != null)
  73460. {
  73461. mxEvent.removeListener(this.target, 'keydown', this.keydownHandler);
  73462. this.keydownHandler = null;
  73463. }
  73464. this.target = null;
  73465. };
  73466. /**
  73467. * Copyright (c) 2006-2015, JGraph Ltd
  73468. * Copyright (c) 2006-2015, Gaudenz Alder
  73469. */
  73470. /**
  73471. * Class: mxTooltipHandler
  73472. *
  73473. * Graph event handler that displays tooltips. <mxGraph.getTooltip> is used to
  73474. * get the tooltip for a cell or handle. This handler is built-into
  73475. * <mxGraph.tooltipHandler> and enabled using <mxGraph.setTooltips>.
  73476. *
  73477. * Example:
  73478. *
  73479. * (code>
  73480. * new mxTooltipHandler(graph);
  73481. * (end)
  73482. *
  73483. * Constructor: mxTooltipHandler
  73484. *
  73485. * Constructs an event handler that displays tooltips with the specified
  73486. * delay (in milliseconds). If no delay is specified then a default delay
  73487. * of 500 ms (0.5 sec) is used.
  73488. *
  73489. * Parameters:
  73490. *
  73491. * graph - Reference to the enclosing <mxGraph>.
  73492. * delay - Optional delay in milliseconds.
  73493. */
  73494. function mxTooltipHandler(graph, delay)
  73495. {
  73496. if (graph != null)
  73497. {
  73498. this.graph = graph;
  73499. this.delay = delay || 500;
  73500. this.graph.addMouseListener(this);
  73501. }
  73502. };
  73503. /**
  73504. * Variable: zIndex
  73505. *
  73506. * Specifies the zIndex for the tooltip and its shadow. Default is 10005.
  73507. */
  73508. mxTooltipHandler.prototype.zIndex = 10005;
  73509. /**
  73510. * Variable: graph
  73511. *
  73512. * Reference to the enclosing <mxGraph>.
  73513. */
  73514. mxTooltipHandler.prototype.graph = null;
  73515. /**
  73516. * Variable: delay
  73517. *
  73518. * Delay to show the tooltip in milliseconds. Default is 500.
  73519. */
  73520. mxTooltipHandler.prototype.delay = null;
  73521. /**
  73522. * Variable: ignoreTouchEvents
  73523. *
  73524. * Specifies if touch and pen events should be ignored. Default is true.
  73525. */
  73526. mxTooltipHandler.prototype.ignoreTouchEvents = true;
  73527. /**
  73528. * Variable: hideOnHover
  73529. *
  73530. * Specifies if the tooltip should be hidden if the mouse is moved over the
  73531. * current cell. Default is false.
  73532. */
  73533. mxTooltipHandler.prototype.hideOnHover = false;
  73534. /**
  73535. * Variable: destroyed
  73536. *
  73537. * True if this handler was destroyed using <destroy>.
  73538. */
  73539. mxTooltipHandler.prototype.destroyed = false;
  73540. /**
  73541. * Variable: enabled
  73542. *
  73543. * Specifies if events are handled. Default is true.
  73544. */
  73545. mxTooltipHandler.prototype.enabled = true;
  73546. /**
  73547. * Function: isEnabled
  73548. *
  73549. * Returns true if events are handled. This implementation
  73550. * returns <enabled>.
  73551. */
  73552. mxTooltipHandler.prototype.isEnabled = function()
  73553. {
  73554. return this.enabled;
  73555. };
  73556. /**
  73557. * Function: setEnabled
  73558. *
  73559. * Enables or disables event handling. This implementation
  73560. * updates <enabled>.
  73561. */
  73562. mxTooltipHandler.prototype.setEnabled = function(enabled)
  73563. {
  73564. this.enabled = enabled;
  73565. };
  73566. /**
  73567. * Function: isHideOnHover
  73568. *
  73569. * Returns <hideOnHover>.
  73570. */
  73571. mxTooltipHandler.prototype.isHideOnHover = function()
  73572. {
  73573. return this.hideOnHover;
  73574. };
  73575. /**
  73576. * Function: setHideOnHover
  73577. *
  73578. * Sets <hideOnHover>.
  73579. */
  73580. mxTooltipHandler.prototype.setHideOnHover = function(value)
  73581. {
  73582. this.hideOnHover = value;
  73583. };
  73584. /**
  73585. * Function: init
  73586. *
  73587. * Initializes the DOM nodes required for this tooltip handler.
  73588. */
  73589. mxTooltipHandler.prototype.init = function()
  73590. {
  73591. if (document.body != null)
  73592. {
  73593. this.div = document.createElement('div');
  73594. this.div.className = 'mxTooltip';
  73595. this.div.style.visibility = 'hidden';
  73596. document.body.appendChild(this.div);
  73597. mxEvent.addGestureListeners(this.div, mxUtils.bind(this, function(evt)
  73598. {
  73599. this.hideTooltip();
  73600. }));
  73601. }
  73602. };
  73603. /**
  73604. * Function: getStateForEvent
  73605. *
  73606. * Returns the <mxCellState> to be used for showing a tooltip for this event.
  73607. */
  73608. mxTooltipHandler.prototype.getStateForEvent = function(me)
  73609. {
  73610. return me.getState();
  73611. };
  73612. /**
  73613. * Function: mouseDown
  73614. *
  73615. * Handles the event by initiating a rubberband selection. By consuming the
  73616. * event all subsequent events of the gesture are redirected to this
  73617. * handler.
  73618. */
  73619. mxTooltipHandler.prototype.mouseDown = function(sender, me)
  73620. {
  73621. this.reset(me, false);
  73622. this.hideTooltip();
  73623. };
  73624. /**
  73625. * Function: mouseMove
  73626. *
  73627. * Handles the event by updating the rubberband selection.
  73628. */
  73629. mxTooltipHandler.prototype.mouseMove = function(sender, me)
  73630. {
  73631. if (me.getX() != this.lastX || me.getY() != this.lastY)
  73632. {
  73633. this.reset(me, true);
  73634. var state = this.getStateForEvent(me);
  73635. if (this.isHideOnHover() || state != this.state || (me.getSource() != this.node &&
  73636. (!this.stateSource || (state != null && this.stateSource ==
  73637. (me.isSource(state.shape) || !me.isSource(state.text))))))
  73638. {
  73639. this.hideTooltip();
  73640. }
  73641. }
  73642. this.lastX = me.getX();
  73643. this.lastY = me.getY();
  73644. };
  73645. /**
  73646. * Function: mouseUp
  73647. *
  73648. * Handles the event by resetting the tooltip timer or hiding the existing
  73649. * tooltip.
  73650. */
  73651. mxTooltipHandler.prototype.mouseUp = function(sender, me)
  73652. {
  73653. this.reset(me, true);
  73654. this.hideTooltip();
  73655. };
  73656. /**
  73657. * Function: resetTimer
  73658. *
  73659. * Resets the timer.
  73660. */
  73661. mxTooltipHandler.prototype.resetTimer = function()
  73662. {
  73663. if (this.thread != null)
  73664. {
  73665. window.clearTimeout(this.thread);
  73666. this.thread = null;
  73667. }
  73668. };
  73669. /**
  73670. * Function: reset
  73671. *
  73672. * Resets and/or restarts the timer to trigger the display of the tooltip.
  73673. */
  73674. mxTooltipHandler.prototype.reset = function(me, restart, state)
  73675. {
  73676. if (!this.ignoreTouchEvents || mxEvent.isMouseEvent(me.getEvent()))
  73677. {
  73678. this.resetTimer();
  73679. state = (state != null) ? state : this.getStateForEvent(me);
  73680. if (restart && this.isEnabled() && state != null && (this.div == null ||
  73681. this.div.style.visibility == 'hidden'))
  73682. {
  73683. var node = me.getSource();
  73684. var x = me.getX();
  73685. var y = me.getY();
  73686. var stateSource = me.isSource(state.shape) || me.isSource(state.text);
  73687. this.thread = window.setTimeout(mxUtils.bind(this, function()
  73688. {
  73689. if (!this.graph.isEditing() && !this.graph.popupMenuHandler.isMenuShowing() && !this.graph.isMouseDown)
  73690. {
  73691. // Uses information from inside event cause using the event at
  73692. // this (delayed) point in time is not possible in IE as it no
  73693. // longer contains the required information (member not found)
  73694. var tip = this.graph.getTooltip(state, node, x, y);
  73695. this.show(tip, x, y);
  73696. this.state = state;
  73697. this.node = node;
  73698. this.stateSource = stateSource;
  73699. }
  73700. }), this.delay);
  73701. }
  73702. }
  73703. };
  73704. /**
  73705. * Function: hide
  73706. *
  73707. * Hides the tooltip and resets the timer.
  73708. */
  73709. mxTooltipHandler.prototype.hide = function()
  73710. {
  73711. this.resetTimer();
  73712. this.hideTooltip();
  73713. };
  73714. /**
  73715. * Function: hideTooltip
  73716. *
  73717. * Hides the tooltip.
  73718. */
  73719. mxTooltipHandler.prototype.hideTooltip = function()
  73720. {
  73721. if (this.div != null)
  73722. {
  73723. this.div.style.visibility = 'hidden';
  73724. this.div.innerHTML = '';
  73725. }
  73726. };
  73727. /**
  73728. * Function: show
  73729. *
  73730. * Shows the tooltip for the specified cell and optional index at the
  73731. * specified location (with a vertical offset of 10 pixels).
  73732. */
  73733. mxTooltipHandler.prototype.show = function(tip, x, y)
  73734. {
  73735. if (!this.destroyed && tip != null && tip.length > 0)
  73736. {
  73737. // Initializes the DOM nodes if required
  73738. if (this.div == null)
  73739. {
  73740. this.init();
  73741. }
  73742. var origin = mxUtils.getScrollOrigin();
  73743. this.div.style.zIndex = this.zIndex;
  73744. this.div.style.left = (x + origin.x) + 'px';
  73745. this.div.style.top = (y + mxConstants.TOOLTIP_VERTICAL_OFFSET +
  73746. origin.y) + 'px';
  73747. if (!mxUtils.isNode(tip))
  73748. {
  73749. this.div.innerHTML = tip.replace(/\n/g, '<br>');
  73750. }
  73751. else
  73752. {
  73753. this.div.innerHTML = '';
  73754. this.div.appendChild(tip);
  73755. }
  73756. this.div.style.visibility = '';
  73757. mxUtils.fit(this.div);
  73758. }
  73759. };
  73760. /**
  73761. * Function: destroy
  73762. *
  73763. * Destroys the handler and all its resources and DOM nodes.
  73764. */
  73765. mxTooltipHandler.prototype.destroy = function()
  73766. {
  73767. if (!this.destroyed)
  73768. {
  73769. this.graph.removeMouseListener(this);
  73770. mxEvent.release(this.div);
  73771. if (this.div != null && this.div.parentNode != null)
  73772. {
  73773. this.div.parentNode.removeChild(this.div);
  73774. }
  73775. this.destroyed = true;
  73776. this.div = null;
  73777. }
  73778. };
  73779. /**
  73780. * Copyright (c) 2006-2015, JGraph Ltd
  73781. * Copyright (c) 2006-2015, Gaudenz Alder
  73782. */
  73783. /**
  73784. * Class: mxCellTracker
  73785. *
  73786. * Event handler that highlights cells. Inherits from <mxCellMarker>.
  73787. *
  73788. * Example:
  73789. *
  73790. * (code)
  73791. * new mxCellTracker(graph, '#00FF00');
  73792. * (end)
  73793. *
  73794. * For detecting dragEnter, dragOver and dragLeave on cells, the following
  73795. * code can be used:
  73796. *
  73797. * (code)
  73798. * graph.addMouseListener(
  73799. * {
  73800. * cell: null,
  73801. * mouseDown: function(sender, me) { },
  73802. * mouseMove: function(sender, me)
  73803. * {
  73804. * var tmp = me.getCell();
  73805. *
  73806. * if (tmp != this.cell)
  73807. * {
  73808. * if (this.cell != null)
  73809. * {
  73810. * this.dragLeave(me.getEvent(), this.cell);
  73811. * }
  73812. *
  73813. * this.cell = tmp;
  73814. *
  73815. * if (this.cell != null)
  73816. * {
  73817. * this.dragEnter(me.getEvent(), this.cell);
  73818. * }
  73819. * }
  73820. *
  73821. * if (this.cell != null)
  73822. * {
  73823. * this.dragOver(me.getEvent(), this.cell);
  73824. * }
  73825. * },
  73826. * mouseUp: function(sender, me) { },
  73827. * dragEnter: function(evt, cell)
  73828. * {
  73829. * mxLog.debug('dragEnter', cell.value);
  73830. * },
  73831. * dragOver: function(evt, cell)
  73832. * {
  73833. * mxLog.debug('dragOver', cell.value);
  73834. * },
  73835. * dragLeave: function(evt, cell)
  73836. * {
  73837. * mxLog.debug('dragLeave', cell.value);
  73838. * }
  73839. * });
  73840. * (end)
  73841. *
  73842. * Constructor: mxCellTracker
  73843. *
  73844. * Constructs an event handler that highlights cells.
  73845. *
  73846. * Parameters:
  73847. *
  73848. * graph - Reference to the enclosing <mxGraph>.
  73849. * color - Color of the highlight. Default is blue.
  73850. * funct - Optional JavaScript function that is used to override
  73851. * <mxCellMarker.getCell>.
  73852. */
  73853. function mxCellTracker(graph, color, funct)
  73854. {
  73855. mxCellMarker.call(this, graph, color);
  73856. this.graph.addMouseListener(this);
  73857. if (funct != null)
  73858. {
  73859. this.getCell = funct;
  73860. }
  73861. // Automatic deallocation of memory
  73862. if (mxClient.IS_IE)
  73863. {
  73864. mxEvent.addListener(window, 'unload', mxUtils.bind(this, function()
  73865. {
  73866. this.destroy();
  73867. }));
  73868. }
  73869. };
  73870. /**
  73871. * Extends mxCellMarker.
  73872. */
  73873. mxUtils.extend(mxCellTracker, mxCellMarker);
  73874. /**
  73875. * Function: mouseDown
  73876. *
  73877. * Ignores the event. The event is not consumed.
  73878. */
  73879. mxCellTracker.prototype.mouseDown = function(sender, me) { };
  73880. /**
  73881. * Function: mouseMove
  73882. *
  73883. * Handles the event by highlighting the cell under the mousepointer if it
  73884. * is over the hotspot region of the cell.
  73885. */
  73886. mxCellTracker.prototype.mouseMove = function(sender, me)
  73887. {
  73888. if (this.isEnabled())
  73889. {
  73890. this.process(me);
  73891. }
  73892. };
  73893. /**
  73894. * Function: mouseUp
  73895. *
  73896. * Handles the event by reseting the highlight.
  73897. */
  73898. mxCellTracker.prototype.mouseUp = function(sender, me) { };
  73899. /**
  73900. * Function: destroy
  73901. *
  73902. * Destroys the object and all its resources and DOM nodes. This doesn't
  73903. * normally need to be called. It is called automatically when the window
  73904. * unloads.
  73905. */
  73906. mxCellTracker.prototype.destroy = function()
  73907. {
  73908. if (!this.destroyed)
  73909. {
  73910. this.destroyed = true;
  73911. this.graph.removeMouseListener(this);
  73912. mxCellMarker.prototype.destroy.apply(this);
  73913. }
  73914. };
  73915. /**
  73916. * Copyright (c) 2006-2015, JGraph Ltd
  73917. * Copyright (c) 2006-2015, Gaudenz Alder
  73918. */
  73919. /**
  73920. * Class: mxCellHighlight
  73921. *
  73922. * A helper class to highlight cells. Here is an example for a given cell.
  73923. *
  73924. * (code)
  73925. * var highlight = new mxCellHighlight(graph, '#ff0000', 2);
  73926. * highlight.highlight(graph.view.getState(cell)));
  73927. * (end)
  73928. *
  73929. * Constructor: mxCellHighlight
  73930. *
  73931. * Constructs a cell highlight.
  73932. */
  73933. function mxCellHighlight(graph, highlightColor, strokeWidth, dashed)
  73934. {
  73935. if (graph != null)
  73936. {
  73937. this.graph = graph;
  73938. this.highlightColor = (highlightColor != null) ? highlightColor : mxConstants.DEFAULT_VALID_COLOR;
  73939. this.strokeWidth = (strokeWidth != null) ? strokeWidth : mxConstants.HIGHLIGHT_STROKEWIDTH;
  73940. this.dashed = (dashed != null) ? dashed : false;
  73941. this.opacity = mxConstants.HIGHLIGHT_OPACITY;
  73942. // Updates the marker if the graph changes
  73943. this.repaintHandler = mxUtils.bind(this, function()
  73944. {
  73945. // Updates reference to state
  73946. if (this.state != null)
  73947. {
  73948. var tmp = this.graph.view.getState(this.state.cell);
  73949. if (tmp == null)
  73950. {
  73951. this.hide();
  73952. }
  73953. else
  73954. {
  73955. this.state = tmp;
  73956. this.repaint();
  73957. }
  73958. }
  73959. });
  73960. this.graph.getView().addListener(mxEvent.SCALE, this.repaintHandler);
  73961. this.graph.getView().addListener(mxEvent.TRANSLATE, this.repaintHandler);
  73962. this.graph.getView().addListener(mxEvent.SCALE_AND_TRANSLATE, this.repaintHandler);
  73963. this.graph.getModel().addListener(mxEvent.CHANGE, this.repaintHandler);
  73964. // Hides the marker if the current root changes
  73965. this.resetHandler = mxUtils.bind(this, function()
  73966. {
  73967. this.hide();
  73968. });
  73969. this.graph.getView().addListener(mxEvent.DOWN, this.resetHandler);
  73970. this.graph.getView().addListener(mxEvent.UP, this.resetHandler);
  73971. }
  73972. };
  73973. /**
  73974. * Variable: keepOnTop
  73975. *
  73976. * Specifies if the highlights should appear on top of everything
  73977. * else in the overlay pane. Default is false.
  73978. */
  73979. mxCellHighlight.prototype.keepOnTop = false;
  73980. /**
  73981. * Variable: graph
  73982. *
  73983. * Reference to the enclosing <mxGraph>.
  73984. */
  73985. mxCellHighlight.prototype.graph = null;
  73986. /**
  73987. * Variable: state
  73988. *
  73989. * Reference to the <mxCellState>.
  73990. */
  73991. mxCellHighlight.prototype.state = null;
  73992. /**
  73993. * Variable: spacing
  73994. *
  73995. * Specifies the spacing between the highlight for vertices and the vertex.
  73996. * Default is 2.
  73997. */
  73998. mxCellHighlight.prototype.spacing = 2;
  73999. /**
  74000. * Variable: resetHandler
  74001. *
  74002. * Holds the handler that automatically invokes reset if the highlight
  74003. * should be hidden.
  74004. */
  74005. mxCellHighlight.prototype.resetHandler = null;
  74006. /**
  74007. * Function: setHighlightColor
  74008. *
  74009. * Sets the color of the rectangle used to highlight drop targets.
  74010. *
  74011. * Parameters:
  74012. *
  74013. * color - String that represents the new highlight color.
  74014. */
  74015. mxCellHighlight.prototype.setHighlightColor = function(color)
  74016. {
  74017. this.highlightColor = color;
  74018. if (this.shape != null)
  74019. {
  74020. this.shape.stroke = color;
  74021. }
  74022. };
  74023. /**
  74024. * Function: drawHighlight
  74025. *
  74026. * Creates and returns the highlight shape for the given state.
  74027. */
  74028. mxCellHighlight.prototype.drawHighlight = function()
  74029. {
  74030. this.shape = this.createShape();
  74031. this.repaint();
  74032. if (!this.keepOnTop && this.shape.node.parentNode.firstChild != this.shape.node)
  74033. {
  74034. this.shape.node.parentNode.insertBefore(this.shape.node, this.shape.node.parentNode.firstChild);
  74035. }
  74036. };
  74037. /**
  74038. * Function: createShape
  74039. *
  74040. * Creates and returns the highlight shape for the given state.
  74041. */
  74042. mxCellHighlight.prototype.createShape = function()
  74043. {
  74044. var shape = this.graph.cellRenderer.createShape(this.state);
  74045. shape.svgStrokeTolerance = this.graph.tolerance;
  74046. shape.points = this.state.absolutePoints;
  74047. shape.apply(this.state);
  74048. shape.stroke = this.highlightColor;
  74049. shape.opacity = this.opacity;
  74050. shape.isDashed = this.dashed;
  74051. shape.isShadow = false;
  74052. shape.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ? mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  74053. shape.init(this.graph.getView().getOverlayPane());
  74054. mxEvent.redirectMouseEvents(shape.node, this.graph, this.state);
  74055. if (this.graph.dialect != mxConstants.DIALECT_SVG)
  74056. {
  74057. shape.pointerEvents = false;
  74058. }
  74059. else
  74060. {
  74061. shape.svgPointerEvents = 'stroke';
  74062. }
  74063. return shape;
  74064. };
  74065. /**
  74066. * Function: repaint
  74067. *
  74068. * Updates the highlight after a change of the model or view.
  74069. */
  74070. mxCellHighlight.prototype.getStrokeWidth = function(state)
  74071. {
  74072. return this.strokeWidth;
  74073. };
  74074. /**
  74075. * Function: repaint
  74076. *
  74077. * Updates the highlight after a change of the model or view.
  74078. */
  74079. mxCellHighlight.prototype.repaint = function()
  74080. {
  74081. if (this.state != null && this.shape != null)
  74082. {
  74083. this.shape.scale = this.state.view.scale;
  74084. if (this.graph.model.isEdge(this.state.cell))
  74085. {
  74086. this.shape.strokewidth = this.getStrokeWidth();
  74087. this.shape.points = this.state.absolutePoints;
  74088. this.shape.outline = false;
  74089. }
  74090. else
  74091. {
  74092. this.shape.bounds = new mxRectangle(this.state.x - this.spacing, this.state.y - this.spacing,
  74093. this.state.width + 2 * this.spacing, this.state.height + 2 * this.spacing);
  74094. this.shape.rotation = Number(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  74095. this.shape.strokewidth = this.getStrokeWidth() / this.state.view.scale;
  74096. this.shape.outline = true;
  74097. }
  74098. // Uses cursor from shape in highlight
  74099. if (this.state.shape != null)
  74100. {
  74101. this.shape.setCursor(this.state.shape.getCursor());
  74102. }
  74103. // Workaround for event transparency in VML with transparent color
  74104. // is to use a non-transparent color with near zero opacity
  74105. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  74106. {
  74107. if (this.shape.stroke == 'transparent')
  74108. {
  74109. // KNOWN: Quirks mode does not seem to catch events if
  74110. // we do not force an update of the DOM via a change such
  74111. // as mxLog.debug. Since IE6 is EOL we do not add a fix.
  74112. this.shape.stroke = 'white';
  74113. this.shape.opacity = 1;
  74114. }
  74115. else
  74116. {
  74117. this.shape.opacity = this.opacity;
  74118. }
  74119. }
  74120. this.shape.redraw();
  74121. }
  74122. };
  74123. /**
  74124. * Function: hide
  74125. *
  74126. * Resets the state of the cell marker.
  74127. */
  74128. mxCellHighlight.prototype.hide = function()
  74129. {
  74130. this.highlight(null);
  74131. };
  74132. /**
  74133. * Function: mark
  74134. *
  74135. * Marks the <markedState> and fires a <mark> event.
  74136. */
  74137. mxCellHighlight.prototype.highlight = function(state)
  74138. {
  74139. if (this.state != state)
  74140. {
  74141. if (this.shape != null)
  74142. {
  74143. this.shape.destroy();
  74144. this.shape = null;
  74145. }
  74146. this.state = state;
  74147. if (this.state != null)
  74148. {
  74149. this.drawHighlight();
  74150. }
  74151. }
  74152. };
  74153. /**
  74154. * Function: isHighlightAt
  74155. *
  74156. * Returns true if this highlight is at the given position.
  74157. */
  74158. mxCellHighlight.prototype.isHighlightAt = function(x, y)
  74159. {
  74160. var hit = false;
  74161. // Quirks mode is currently not supported as it used a different coordinate system
  74162. if (this.shape != null && document.elementFromPoint != null && !mxClient.IS_QUIRKS)
  74163. {
  74164. var elt = document.elementFromPoint(x, y);
  74165. while (elt != null)
  74166. {
  74167. if (elt == this.shape.node)
  74168. {
  74169. hit = true;
  74170. break;
  74171. }
  74172. elt = elt.parentNode;
  74173. }
  74174. }
  74175. return hit;
  74176. };
  74177. /**
  74178. * Function: destroy
  74179. *
  74180. * Destroys the handler and all its resources and DOM nodes.
  74181. */
  74182. mxCellHighlight.prototype.destroy = function()
  74183. {
  74184. this.graph.getView().removeListener(this.resetHandler);
  74185. this.graph.getView().removeListener(this.repaintHandler);
  74186. this.graph.getModel().removeListener(this.repaintHandler);
  74187. if (this.shape != null)
  74188. {
  74189. this.shape.destroy();
  74190. this.shape = null;
  74191. }
  74192. };
  74193. /**
  74194. * Copyright (c) 2006-2015, JGraph Ltd
  74195. * Copyright (c) 2006-2015, Gaudenz Alder
  74196. */
  74197. /**
  74198. * Class: mxDefaultKeyHandler
  74199. *
  74200. * Binds keycodes to actionnames in an editor. This aggregates an internal
  74201. * <handler> and extends the implementation of <mxKeyHandler.escape> to not
  74202. * only cancel the editing, but also hide the properties dialog and fire an
  74203. * <mxEditor.escape> event via <editor>. An instance of this class is created
  74204. * by <mxEditor> and stored in <mxEditor.keyHandler>.
  74205. *
  74206. * Example:
  74207. *
  74208. * Bind the delete key to the delete action in an existing editor.
  74209. *
  74210. * (code)
  74211. * var keyHandler = new mxDefaultKeyHandler(editor);
  74212. * keyHandler.bindAction(46, 'delete');
  74213. * (end)
  74214. *
  74215. * Codec:
  74216. *
  74217. * This class uses the <mxDefaultKeyHandlerCodec> to read configuration
  74218. * data into an existing instance. See <mxDefaultKeyHandlerCodec> for a
  74219. * description of the configuration format.
  74220. *
  74221. * Keycodes:
  74222. *
  74223. * See <mxKeyHandler>.
  74224. *
  74225. * An <mxEvent.ESCAPE> event is fired via the editor if the escape key is
  74226. * pressed.
  74227. *
  74228. * Constructor: mxDefaultKeyHandler
  74229. *
  74230. * Constructs a new default key handler for the <mxEditor.graph> in the
  74231. * given <mxEditor>. (The editor may be null if a prototypical instance for
  74232. * a <mxDefaultKeyHandlerCodec> is created.)
  74233. *
  74234. * Parameters:
  74235. *
  74236. * editor - Reference to the enclosing <mxEditor>.
  74237. */
  74238. function mxDefaultKeyHandler(editor)
  74239. {
  74240. if (editor != null)
  74241. {
  74242. this.editor = editor;
  74243. this.handler = new mxKeyHandler(editor.graph);
  74244. // Extends the escape function of the internal key
  74245. // handle to hide the properties dialog and fire
  74246. // the escape event via the editor instance
  74247. var old = this.handler.escape;
  74248. this.handler.escape = function(evt)
  74249. {
  74250. old.apply(this, arguments);
  74251. editor.hideProperties();
  74252. editor.fireEvent(new mxEventObject(mxEvent.ESCAPE, 'event', evt));
  74253. };
  74254. }
  74255. };
  74256. /**
  74257. * Variable: editor
  74258. *
  74259. * Reference to the enclosing <mxEditor>.
  74260. */
  74261. mxDefaultKeyHandler.prototype.editor = null;
  74262. /**
  74263. * Variable: handler
  74264. *
  74265. * Holds the <mxKeyHandler> for key event handling.
  74266. */
  74267. mxDefaultKeyHandler.prototype.handler = null;
  74268. /**
  74269. * Function: bindAction
  74270. *
  74271. * Binds the specified keycode to the given action in <editor>. The
  74272. * optional control flag specifies if the control key must be pressed
  74273. * to trigger the action.
  74274. *
  74275. * Parameters:
  74276. *
  74277. * code - Integer that specifies the keycode.
  74278. * action - Name of the action to execute in <editor>.
  74279. * control - Optional boolean that specifies if control must be pressed.
  74280. * Default is false.
  74281. */
  74282. mxDefaultKeyHandler.prototype.bindAction = function (code, action, control)
  74283. {
  74284. var keyHandler = mxUtils.bind(this, function()
  74285. {
  74286. this.editor.execute(action);
  74287. });
  74288. // Binds the function to control-down keycode
  74289. if (control)
  74290. {
  74291. this.handler.bindControlKey(code, keyHandler);
  74292. }
  74293. // Binds the function to the normal keycode
  74294. else
  74295. {
  74296. this.handler.bindKey(code, keyHandler);
  74297. }
  74298. };
  74299. /**
  74300. * Function: destroy
  74301. *
  74302. * Destroys the <handler> associated with this object. This does normally
  74303. * not need to be called, the <handler> is destroyed automatically when the
  74304. * window unloads (in IE) by <mxEditor>.
  74305. */
  74306. mxDefaultKeyHandler.prototype.destroy = function ()
  74307. {
  74308. this.handler.destroy();
  74309. this.handler = null;
  74310. };
  74311. /**
  74312. * Copyright (c) 2006-2015, JGraph Ltd
  74313. * Copyright (c) 2006-2015, Gaudenz Alder
  74314. */
  74315. /**
  74316. * Class: mxDefaultPopupMenu
  74317. *
  74318. * Creates popupmenus for mouse events. This object holds an XML node
  74319. * which is a description of the popup menu to be created. In
  74320. * <createMenu>, the configuration is applied to the context and
  74321. * the resulting menu items are added to the menu dynamically. See
  74322. * <createMenu> for a description of the configuration format.
  74323. *
  74324. * This class does not create the DOM nodes required for the popup menu, it
  74325. * only parses an XML description to invoke the respective methods on an
  74326. * <mxPopupMenu> each time the menu is displayed.
  74327. *
  74328. * Codec:
  74329. *
  74330. * This class uses the <mxDefaultPopupMenuCodec> to read configuration
  74331. * data into an existing instance, however, the actual parsing is done
  74332. * by this class during program execution, so the format is described
  74333. * below.
  74334. *
  74335. * Constructor: mxDefaultPopupMenu
  74336. *
  74337. * Constructs a new popupmenu-factory based on given configuration.
  74338. *
  74339. * Paramaters:
  74340. *
  74341. * config - XML node that contains the configuration data.
  74342. */
  74343. function mxDefaultPopupMenu(config)
  74344. {
  74345. this.config = config;
  74346. };
  74347. /**
  74348. * Variable: imageBasePath
  74349. *
  74350. * Base path for all icon attributes in the config. Default is null.
  74351. */
  74352. mxDefaultPopupMenu.prototype.imageBasePath = null;
  74353. /**
  74354. * Variable: config
  74355. *
  74356. * XML node used as the description of new menu items. This node is
  74357. * used in <createMenu> to dynamically create the menu items if their
  74358. * respective conditions evaluate to true for the given arguments.
  74359. */
  74360. mxDefaultPopupMenu.prototype.config = null;
  74361. /**
  74362. * Function: createMenu
  74363. *
  74364. * This function is called from <mxEditor> to add items to the
  74365. * given menu based on <config>. The config is a sequence of
  74366. * the following nodes and attributes.
  74367. *
  74368. * Child Nodes:
  74369. *
  74370. * add - Adds a new menu item. See below for attributes.
  74371. * separator - Adds a separator. No attributes.
  74372. * condition - Adds a custom condition. Name attribute.
  74373. *
  74374. * The add-node may have a child node that defines a function to be invoked
  74375. * before the action is executed (or instead of an action to be executed).
  74376. *
  74377. * Attributes:
  74378. *
  74379. * as - Resource key for the label (needs entry in property file).
  74380. * action - Name of the action to execute in enclosing editor.
  74381. * icon - Optional icon (relative/absolute URL).
  74382. * iconCls - Optional CSS class for the icon.
  74383. * if - Optional name of condition that must be true (see below).
  74384. * enabled-if - Optional name of condition that specifies if the menu item
  74385. * should be enabled.
  74386. * name - Name of custom condition. Only for condition nodes.
  74387. *
  74388. * Conditions:
  74389. *
  74390. * nocell - No cell under the mouse.
  74391. * ncells - More than one cell selected.
  74392. * notRoot - Drilling position is other than home.
  74393. * cell - Cell under the mouse.
  74394. * notEmpty - Exactly one cell with children under mouse.
  74395. * expandable - Exactly one expandable cell under mouse.
  74396. * collapsable - Exactly one collapsable cell under mouse.
  74397. * validRoot - Exactly one cell which is a possible root under mouse.
  74398. * swimlane - Exactly one cell which is a swimlane under mouse.
  74399. *
  74400. * Example:
  74401. *
  74402. * To add a new item for a given action to the popupmenu:
  74403. *
  74404. * (code)
  74405. * <mxDefaultPopupMenu as="popupHandler">
  74406. * <add as="delete" action="delete" icon="images/delete.gif" if="cell"/>
  74407. * </mxDefaultPopupMenu>
  74408. * (end)
  74409. *
  74410. * To add a new item for a custom function:
  74411. *
  74412. * (code)
  74413. * <mxDefaultPopupMenu as="popupHandler">
  74414. * <add as="action1"><![CDATA[
  74415. * function (editor, cell, evt)
  74416. * {
  74417. * editor.execute('action1', cell, 'myArg');
  74418. * }
  74419. * ]]></add>
  74420. * </mxDefaultPopupMenu>
  74421. * (end)
  74422. *
  74423. * The above example invokes action1 with an additional third argument via
  74424. * the editor instance. The third argument is passed to the function that
  74425. * defines action1. If the add-node has no action-attribute, then only the
  74426. * function defined in the text content is executed, otherwise first the
  74427. * function and then the action defined in the action-attribute is
  74428. * executed. The function in the text content has 3 arguments, namely the
  74429. * <mxEditor> instance, the <mxCell> instance under the mouse, and the
  74430. * native mouse event.
  74431. *
  74432. * Custom Conditions:
  74433. *
  74434. * To add a new condition for popupmenu items:
  74435. *
  74436. * (code)
  74437. * <condition name="condition1"><![CDATA[
  74438. * function (editor, cell, evt)
  74439. * {
  74440. * return cell != null;
  74441. * }
  74442. * ]]></condition>
  74443. * (end)
  74444. *
  74445. * The new condition can then be used in any item as follows:
  74446. *
  74447. * (code)
  74448. * <add as="action1" action="action1" icon="action1.gif" if="condition1"/>
  74449. * (end)
  74450. *
  74451. * The order in which the items and conditions appear is not significant as
  74452. * all connditions are evaluated before any items are created.
  74453. *
  74454. * Parameters:
  74455. *
  74456. * editor - Enclosing <mxEditor> instance.
  74457. * menu - <mxPopupMenu> that is used for adding items and separators.
  74458. * cell - Optional <mxCell> which is under the mousepointer.
  74459. * evt - Optional mouse event which triggered the menu.
  74460. */
  74461. mxDefaultPopupMenu.prototype.createMenu = function(editor, menu, cell, evt)
  74462. {
  74463. if (this.config != null)
  74464. {
  74465. var conditions = this.createConditions(editor, cell, evt);
  74466. var item = this.config.firstChild;
  74467. this.addItems(editor, menu, cell, evt, conditions, item, null);
  74468. }
  74469. };
  74470. /**
  74471. * Function: addItems
  74472. *
  74473. * Recursively adds the given items and all of its children into the given menu.
  74474. *
  74475. * Parameters:
  74476. *
  74477. * editor - Enclosing <mxEditor> instance.
  74478. * menu - <mxPopupMenu> that is used for adding items and separators.
  74479. * cell - Optional <mxCell> which is under the mousepointer.
  74480. * evt - Optional mouse event which triggered the menu.
  74481. * conditions - Array of names boolean conditions.
  74482. * item - XML node that represents the current menu item.
  74483. * parent - DOM node that represents the parent menu item.
  74484. */
  74485. mxDefaultPopupMenu.prototype.addItems = function(editor, menu, cell, evt, conditions, item, parent)
  74486. {
  74487. var addSeparator = false;
  74488. while (item != null)
  74489. {
  74490. if (item.nodeName == 'add')
  74491. {
  74492. var condition = item.getAttribute('if');
  74493. if (condition == null || conditions[condition])
  74494. {
  74495. var as = item.getAttribute('as');
  74496. as = mxResources.get(as) || as;
  74497. var funct = mxUtils.eval(mxUtils.getTextContent(item));
  74498. var action = item.getAttribute('action');
  74499. var icon = item.getAttribute('icon');
  74500. var iconCls = item.getAttribute('iconCls');
  74501. var enabledCond = item.getAttribute('enabled-if');
  74502. var enabled = enabledCond == null || conditions[enabledCond];
  74503. if (addSeparator)
  74504. {
  74505. menu.addSeparator(parent);
  74506. addSeparator = false;
  74507. }
  74508. if (icon != null && this.imageBasePath)
  74509. {
  74510. icon = this.imageBasePath + icon;
  74511. }
  74512. var row = this.addAction(menu, editor, as, icon, funct, action, cell, parent, iconCls, enabled);
  74513. this.addItems(editor, menu, cell, evt, conditions, item.firstChild, row);
  74514. }
  74515. }
  74516. else if (item.nodeName == 'separator')
  74517. {
  74518. addSeparator = true;
  74519. }
  74520. item = item.nextSibling;
  74521. }
  74522. };
  74523. /**
  74524. * Function: addAction
  74525. *
  74526. * Helper method to bind an action to a new menu item.
  74527. *
  74528. * Parameters:
  74529. *
  74530. * menu - <mxPopupMenu> that is used for adding items and separators.
  74531. * editor - Enclosing <mxEditor> instance.
  74532. * lab - String that represents the label of the menu item.
  74533. * icon - Optional URL that represents the icon of the menu item.
  74534. * action - Optional name of the action to execute in the given editor.
  74535. * funct - Optional function to execute before the optional action. The
  74536. * function takes an <mxEditor>, the <mxCell> under the mouse and the
  74537. * mouse event that triggered the call.
  74538. * cell - Optional <mxCell> to use as an argument for the action.
  74539. * parent - DOM node that represents the parent menu item.
  74540. * iconCls - Optional CSS class for the menu icon.
  74541. * enabled - Optional boolean that specifies if the menu item is enabled.
  74542. * Default is true.
  74543. */
  74544. mxDefaultPopupMenu.prototype.addAction = function(menu, editor, lab, icon, funct, action, cell, parent, iconCls, enabled)
  74545. {
  74546. var clickHandler = function(evt)
  74547. {
  74548. if (typeof(funct) == 'function')
  74549. {
  74550. funct.call(editor, editor, cell, evt);
  74551. }
  74552. if (action != null)
  74553. {
  74554. editor.execute(action, cell, evt);
  74555. }
  74556. };
  74557. return menu.addItem(lab, icon, clickHandler, parent, iconCls, enabled);
  74558. };
  74559. /**
  74560. * Function: createConditions
  74561. *
  74562. * Evaluates the default conditions for the given context.
  74563. */
  74564. mxDefaultPopupMenu.prototype.createConditions = function(editor, cell, evt)
  74565. {
  74566. // Creates array with conditions
  74567. var model = editor.graph.getModel();
  74568. var childCount = model.getChildCount(cell);
  74569. // Adds some frequently used conditions
  74570. var conditions = [];
  74571. conditions['nocell'] = cell == null;
  74572. conditions['ncells'] = editor.graph.getSelectionCount() > 1;
  74573. conditions['notRoot'] = model.getRoot() !=
  74574. model.getParent(editor.graph.getDefaultParent());
  74575. conditions['cell'] = cell != null;
  74576. var isCell = cell != null && editor.graph.getSelectionCount() == 1;
  74577. conditions['nonEmpty'] = isCell && childCount > 0;
  74578. conditions['expandable'] = isCell && editor.graph.isCellFoldable(cell, false);
  74579. conditions['collapsable'] = isCell && editor.graph.isCellFoldable(cell, true);
  74580. conditions['validRoot'] = isCell && editor.graph.isValidRoot(cell);
  74581. conditions['emptyValidRoot'] = conditions['validRoot'] && childCount == 0;
  74582. conditions['swimlane'] = isCell && editor.graph.isSwimlane(cell);
  74583. // Evaluates dynamic conditions from config file
  74584. var condNodes = this.config.getElementsByTagName('condition');
  74585. for (var i=0; i<condNodes.length; i++)
  74586. {
  74587. var funct = mxUtils.eval(mxUtils.getTextContent(condNodes[i]));
  74588. var name = condNodes[i].getAttribute('name');
  74589. if (name != null && typeof(funct) == 'function')
  74590. {
  74591. conditions[name] = funct(editor, cell, evt);
  74592. }
  74593. }
  74594. return conditions;
  74595. };
  74596. /**
  74597. * Copyright (c) 2006-2015, JGraph Ltd
  74598. * Copyright (c) 2006-2015, Gaudenz Alder
  74599. */
  74600. /**
  74601. * Class: mxDefaultToolbar
  74602. *
  74603. * Toolbar for the editor. This modifies the state of the graph
  74604. * or inserts new cells upon mouse clicks.
  74605. *
  74606. * Example:
  74607. *
  74608. * Create a toolbar with a button to copy the selection into the clipboard,
  74609. * and a combo box with one action to paste the selection from the clipboard
  74610. * into the graph.
  74611. *
  74612. * (code)
  74613. * var toolbar = new mxDefaultToolbar(container, editor);
  74614. * toolbar.addItem('Copy', null, 'copy');
  74615. *
  74616. * var combo = toolbar.addActionCombo('More actions...');
  74617. * toolbar.addActionOption(combo, 'Paste', 'paste');
  74618. * (end)
  74619. *
  74620. * Codec:
  74621. *
  74622. * This class uses the <mxDefaultToolbarCodec> to read configuration
  74623. * data into an existing instance. See <mxDefaultToolbarCodec> for a
  74624. * description of the configuration format.
  74625. *
  74626. * Constructor: mxDefaultToolbar
  74627. *
  74628. * Constructs a new toolbar for the given container and editor. The
  74629. * container and editor may be null if a prototypical instance for a
  74630. * <mxDefaultKeyHandlerCodec> is created.
  74631. *
  74632. * Parameters:
  74633. *
  74634. * container - DOM node that contains the toolbar.
  74635. * editor - Reference to the enclosing <mxEditor>.
  74636. */
  74637. function mxDefaultToolbar(container, editor)
  74638. {
  74639. this.editor = editor;
  74640. if (container != null && editor != null)
  74641. {
  74642. this.init(container);
  74643. }
  74644. };
  74645. /**
  74646. * Variable: editor
  74647. *
  74648. * Reference to the enclosing <mxEditor>.
  74649. */
  74650. mxDefaultToolbar.prototype.editor = null;
  74651. /**
  74652. * Variable: toolbar
  74653. *
  74654. * Holds the internal <mxToolbar>.
  74655. */
  74656. mxDefaultToolbar.prototype.toolbar = null;
  74657. /**
  74658. * Variable: resetHandler
  74659. *
  74660. * Reference to the function used to reset the <toolbar>.
  74661. */
  74662. mxDefaultToolbar.prototype.resetHandler = null;
  74663. /**
  74664. * Variable: spacing
  74665. *
  74666. * Defines the spacing between existing and new vertices in
  74667. * gridSize units when a new vertex is dropped on an existing
  74668. * cell. Default is 4 (40 pixels).
  74669. */
  74670. mxDefaultToolbar.prototype.spacing = 4;
  74671. /**
  74672. * Variable: connectOnDrop
  74673. *
  74674. * Specifies if elements should be connected if new cells are dropped onto
  74675. * connectable elements. Default is false.
  74676. */
  74677. mxDefaultToolbar.prototype.connectOnDrop = false;
  74678. /**
  74679. * Function: init
  74680. *
  74681. * Constructs the <toolbar> for the given container and installs a listener
  74682. * that updates the <mxEditor.insertFunction> on <editor> if an item is
  74683. * selected in the toolbar. This assumes that <editor> is not null.
  74684. *
  74685. * Parameters:
  74686. *
  74687. * container - DOM node that contains the toolbar.
  74688. */
  74689. mxDefaultToolbar.prototype.init = function(container)
  74690. {
  74691. if (container != null)
  74692. {
  74693. this.toolbar = new mxToolbar(container);
  74694. // Installs the insert function in the editor if an item is
  74695. // selected in the toolbar
  74696. this.toolbar.addListener(mxEvent.SELECT, mxUtils.bind(this, function(sender, evt)
  74697. {
  74698. var funct = evt.getProperty('function');
  74699. if (funct != null)
  74700. {
  74701. this.editor.insertFunction = mxUtils.bind(this, function()
  74702. {
  74703. funct.apply(this, arguments);
  74704. this.toolbar.resetMode();
  74705. });
  74706. }
  74707. else
  74708. {
  74709. this.editor.insertFunction = null;
  74710. }
  74711. }));
  74712. // Resets the selected tool after a doubleclick or escape keystroke
  74713. this.resetHandler = mxUtils.bind(this, function()
  74714. {
  74715. if (this.toolbar != null)
  74716. {
  74717. this.toolbar.resetMode(true);
  74718. }
  74719. });
  74720. this.editor.graph.addListener(mxEvent.DOUBLE_CLICK, this.resetHandler);
  74721. this.editor.addListener(mxEvent.ESCAPE, this.resetHandler);
  74722. }
  74723. };
  74724. /**
  74725. * Function: addItem
  74726. *
  74727. * Adds a new item that executes the given action in <editor>. The title,
  74728. * icon and pressedIcon are used to display the toolbar item.
  74729. *
  74730. * Parameters:
  74731. *
  74732. * title - String that represents the title (tooltip) for the item.
  74733. * icon - URL of the icon to be used for displaying the item.
  74734. * action - Name of the action to execute when the item is clicked.
  74735. * pressed - Optional URL of the icon for the pressed state.
  74736. */
  74737. mxDefaultToolbar.prototype.addItem = function(title, icon, action, pressed)
  74738. {
  74739. var clickHandler = mxUtils.bind(this, function()
  74740. {
  74741. if (action != null && action.length > 0)
  74742. {
  74743. this.editor.execute(action);
  74744. }
  74745. });
  74746. return this.toolbar.addItem(title, icon, clickHandler, pressed);
  74747. };
  74748. /**
  74749. * Function: addSeparator
  74750. *
  74751. * Adds a vertical separator using the optional icon.
  74752. *
  74753. * Parameters:
  74754. *
  74755. * icon - Optional URL of the icon that represents the vertical separator.
  74756. * Default is <mxClient.imageBasePath> + '/separator.gif'.
  74757. */
  74758. mxDefaultToolbar.prototype.addSeparator = function(icon)
  74759. {
  74760. icon = icon || mxClient.imageBasePath + '/separator.gif';
  74761. this.toolbar.addSeparator(icon);
  74762. };
  74763. /**
  74764. * Function: addCombo
  74765. *
  74766. * Helper method to invoke <mxToolbar.addCombo> on <toolbar> and return the
  74767. * resulting DOM node.
  74768. */
  74769. mxDefaultToolbar.prototype.addCombo = function()
  74770. {
  74771. return this.toolbar.addCombo();
  74772. };
  74773. /**
  74774. * Function: addActionCombo
  74775. *
  74776. * Helper method to invoke <mxToolbar.addActionCombo> on <toolbar> using
  74777. * the given title and return the resulting DOM node.
  74778. *
  74779. * Parameters:
  74780. *
  74781. * title - String that represents the title of the combo.
  74782. */
  74783. mxDefaultToolbar.prototype.addActionCombo = function(title)
  74784. {
  74785. return this.toolbar.addActionCombo(title);
  74786. };
  74787. /**
  74788. * Function: addActionOption
  74789. *
  74790. * Binds the given action to a option with the specified label in the
  74791. * given combo. Combo is an object returned from an earlier call to
  74792. * <addCombo> or <addActionCombo>.
  74793. *
  74794. * Parameters:
  74795. *
  74796. * combo - DOM node that represents the combo box.
  74797. * title - String that represents the title of the combo.
  74798. * action - Name of the action to execute in <editor>.
  74799. */
  74800. mxDefaultToolbar.prototype.addActionOption = function(combo, title, action)
  74801. {
  74802. var clickHandler = mxUtils.bind(this, function()
  74803. {
  74804. this.editor.execute(action);
  74805. });
  74806. this.addOption(combo, title, clickHandler);
  74807. };
  74808. /**
  74809. * Function: addOption
  74810. *
  74811. * Helper method to invoke <mxToolbar.addOption> on <toolbar> and return
  74812. * the resulting DOM node that represents the option.
  74813. *
  74814. * Parameters:
  74815. *
  74816. * combo - DOM node that represents the combo box.
  74817. * title - String that represents the title of the combo.
  74818. * value - Object that represents the value of the option.
  74819. */
  74820. mxDefaultToolbar.prototype.addOption = function(combo, title, value)
  74821. {
  74822. return this.toolbar.addOption(combo, title, value);
  74823. };
  74824. /**
  74825. * Function: addMode
  74826. *
  74827. * Creates an item for selecting the given mode in the <editor>'s graph.
  74828. * Supported modenames are select, connect and pan.
  74829. *
  74830. * Parameters:
  74831. *
  74832. * title - String that represents the title of the item.
  74833. * icon - URL of the icon that represents the item.
  74834. * mode - String that represents the mode name to be used in
  74835. * <mxEditor.setMode>.
  74836. * pressed - Optional URL of the icon that represents the pressed state.
  74837. * funct - Optional JavaScript function that takes the <mxEditor> as the
  74838. * first and only argument that is executed after the mode has been
  74839. * selected.
  74840. */
  74841. mxDefaultToolbar.prototype.addMode = function(title, icon, mode, pressed, funct)
  74842. {
  74843. var clickHandler = mxUtils.bind(this, function()
  74844. {
  74845. this.editor.setMode(mode);
  74846. if (funct != null)
  74847. {
  74848. funct(this.editor);
  74849. }
  74850. });
  74851. return this.toolbar.addSwitchMode(title, icon, clickHandler, pressed);
  74852. };
  74853. /**
  74854. * Function: addPrototype
  74855. *
  74856. * Creates an item for inserting a clone of the specified prototype cell into
  74857. * the <editor>'s graph. The ptype may either be a cell or a function that
  74858. * returns a cell.
  74859. *
  74860. * Parameters:
  74861. *
  74862. * title - String that represents the title of the item.
  74863. * icon - URL of the icon that represents the item.
  74864. * ptype - Function or object that represents the prototype cell. If ptype
  74865. * is a function then it is invoked with no arguments to create new
  74866. * instances.
  74867. * pressed - Optional URL of the icon that represents the pressed state.
  74868. * insert - Optional JavaScript function that handles an insert of the new
  74869. * cell. This function takes the <mxEditor>, new cell to be inserted, mouse
  74870. * event and optional <mxCell> under the mouse pointer as arguments.
  74871. * toggle - Optional boolean that specifies if the item can be toggled.
  74872. * Default is true.
  74873. */
  74874. mxDefaultToolbar.prototype.addPrototype = function(title, icon, ptype, pressed, insert, toggle)
  74875. {
  74876. // Creates a wrapper function that is in charge of constructing
  74877. // the new cell instance to be inserted into the graph
  74878. var factory = mxUtils.bind(this, function()
  74879. {
  74880. if (typeof(ptype) == 'function')
  74881. {
  74882. return ptype();
  74883. }
  74884. else if (ptype != null)
  74885. {
  74886. return this.editor.graph.cloneCell(ptype);
  74887. }
  74888. return null;
  74889. });
  74890. // Defines the function for a click event on the graph
  74891. // after this item has been selected in the toolbar
  74892. var clickHandler = mxUtils.bind(this, function(evt, cell)
  74893. {
  74894. if (typeof(insert) == 'function')
  74895. {
  74896. insert(this.editor, factory(), evt, cell);
  74897. }
  74898. else
  74899. {
  74900. this.drop(factory(), evt, cell);
  74901. }
  74902. this.toolbar.resetMode();
  74903. mxEvent.consume(evt);
  74904. });
  74905. var img = this.toolbar.addMode(title, icon, clickHandler, pressed, null, toggle);
  74906. // Creates a wrapper function that calls the click handler without
  74907. // the graph argument
  74908. var dropHandler = function(graph, evt, cell)
  74909. {
  74910. clickHandler(evt, cell);
  74911. };
  74912. this.installDropHandler(img, dropHandler);
  74913. return img;
  74914. };
  74915. /**
  74916. * Function: drop
  74917. *
  74918. * Handles a drop from a toolbar item to the graph. The given vertex
  74919. * represents the new cell to be inserted. This invokes <insert> or
  74920. * <connect> depending on the given target cell.
  74921. *
  74922. * Parameters:
  74923. *
  74924. * vertex - <mxCell> to be inserted.
  74925. * evt - Mouse event that represents the drop.
  74926. * target - Optional <mxCell> that represents the drop target.
  74927. */
  74928. mxDefaultToolbar.prototype.drop = function(vertex, evt, target)
  74929. {
  74930. var graph = this.editor.graph;
  74931. var model = graph.getModel();
  74932. if (target == null ||
  74933. model.isEdge(target) ||
  74934. !this.connectOnDrop ||
  74935. !graph.isCellConnectable(target))
  74936. {
  74937. while (target != null &&
  74938. !graph.isValidDropTarget(target, [vertex], evt))
  74939. {
  74940. target = model.getParent(target);
  74941. }
  74942. this.insert(vertex, evt, target);
  74943. }
  74944. else
  74945. {
  74946. this.connect(vertex, evt, target);
  74947. }
  74948. };
  74949. /**
  74950. * Function: insert
  74951. *
  74952. * Handles a drop by inserting the given vertex into the given parent cell
  74953. * or the default parent if no parent is specified.
  74954. *
  74955. * Parameters:
  74956. *
  74957. * vertex - <mxCell> to be inserted.
  74958. * evt - Mouse event that represents the drop.
  74959. * parent - Optional <mxCell> that represents the parent.
  74960. */
  74961. mxDefaultToolbar.prototype.insert = function(vertex, evt, target)
  74962. {
  74963. var graph = this.editor.graph;
  74964. if (graph.canImportCell(vertex))
  74965. {
  74966. var x = mxEvent.getClientX(evt);
  74967. var y = mxEvent.getClientY(evt);
  74968. var pt = mxUtils.convertPoint(graph.container, x, y);
  74969. // Splits the target edge or inserts into target group
  74970. if (graph.isSplitEnabled() &&
  74971. graph.isSplitTarget(target, [vertex], evt))
  74972. {
  74973. return graph.splitEdge(target, [vertex], null, pt.x, pt.y);
  74974. }
  74975. else
  74976. {
  74977. return this.editor.addVertex(target, vertex, pt.x, pt.y);
  74978. }
  74979. }
  74980. return null;
  74981. };
  74982. /**
  74983. * Function: connect
  74984. *
  74985. * Handles a drop by connecting the given vertex to the given source cell.
  74986. *
  74987. * vertex - <mxCell> to be inserted.
  74988. * evt - Mouse event that represents the drop.
  74989. * source - Optional <mxCell> that represents the source terminal.
  74990. */
  74991. mxDefaultToolbar.prototype.connect = function(vertex, evt, source)
  74992. {
  74993. var graph = this.editor.graph;
  74994. var model = graph.getModel();
  74995. if (source != null &&
  74996. graph.isCellConnectable(vertex) &&
  74997. graph.isEdgeValid(null, source, vertex))
  74998. {
  74999. var edge = null;
  75000. model.beginUpdate();
  75001. try
  75002. {
  75003. var geo = model.getGeometry(source);
  75004. var g = model.getGeometry(vertex).clone();
  75005. // Moves the vertex away from the drop target that will
  75006. // be used as the source for the new connection
  75007. g.x = geo.x + (geo.width - g.width) / 2;
  75008. g.y = geo.y + (geo.height - g.height) / 2;
  75009. var step = this.spacing * graph.gridSize;
  75010. var dist = model.getDirectedEdgeCount(source, true) * 20;
  75011. if (this.editor.horizontalFlow)
  75012. {
  75013. g.x += (g.width + geo.width) / 2 + step + dist;
  75014. }
  75015. else
  75016. {
  75017. g.y += (g.height + geo.height) / 2 + step + dist;
  75018. }
  75019. vertex.setGeometry(g);
  75020. // Fires two add-events with the code below - should be fixed
  75021. // to only fire one add event for both inserts
  75022. var parent = model.getParent(source);
  75023. graph.addCell(vertex, parent);
  75024. graph.constrainChild(vertex);
  75025. // Creates the edge using the editor instance and calls
  75026. // the second function that fires an add event
  75027. edge = this.editor.createEdge(source, vertex);
  75028. if (model.getGeometry(edge) == null)
  75029. {
  75030. var edgeGeometry = new mxGeometry();
  75031. edgeGeometry.relative = true;
  75032. model.setGeometry(edge, edgeGeometry);
  75033. }
  75034. graph.addEdge(edge, parent, source, vertex);
  75035. }
  75036. finally
  75037. {
  75038. model.endUpdate();
  75039. }
  75040. graph.setSelectionCells([vertex, edge]);
  75041. graph.scrollCellToVisible(vertex);
  75042. }
  75043. };
  75044. /**
  75045. * Function: installDropHandler
  75046. *
  75047. * Makes the given img draggable using the given function for handling a
  75048. * drop event.
  75049. *
  75050. * Parameters:
  75051. *
  75052. * img - DOM node that represents the image.
  75053. * dropHandler - Function that handles a drop of the image.
  75054. */
  75055. mxDefaultToolbar.prototype.installDropHandler = function (img, dropHandler)
  75056. {
  75057. var sprite = document.createElement('img');
  75058. sprite.setAttribute('src', img.getAttribute('src'));
  75059. // Handles delayed loading of the images
  75060. var loader = mxUtils.bind(this, function(evt)
  75061. {
  75062. // Preview uses the image node with double size. Later this can be
  75063. // changed to use a separate preview and guides, but for this the
  75064. // dropHandler must use the additional x- and y-arguments and the
  75065. // dragsource which makeDraggable returns much be configured to
  75066. // use guides via mxDragSource.isGuidesEnabled.
  75067. sprite.style.width = (2 * img.offsetWidth) + 'px';
  75068. sprite.style.height = (2 * img.offsetHeight) + 'px';
  75069. mxUtils.makeDraggable(img, this.editor.graph, dropHandler,
  75070. sprite);
  75071. mxEvent.removeListener(sprite, 'load', loader);
  75072. });
  75073. if (mxClient.IS_IE)
  75074. {
  75075. loader();
  75076. }
  75077. else
  75078. {
  75079. mxEvent.addListener(sprite, 'load', loader);
  75080. }
  75081. };
  75082. /**
  75083. * Function: destroy
  75084. *
  75085. * Destroys the <toolbar> associated with this object and removes all
  75086. * installed listeners. This does normally not need to be called, the
  75087. * <toolbar> is destroyed automatically when the window unloads (in IE) by
  75088. * <mxEditor>.
  75089. */
  75090. mxDefaultToolbar.prototype.destroy = function ()
  75091. {
  75092. if (this.resetHandler != null)
  75093. {
  75094. this.editor.graph.removeListener('dblclick', this.resetHandler);
  75095. this.editor.removeListener('escape', this.resetHandler);
  75096. this.resetHandler = null;
  75097. }
  75098. if (this.toolbar != null)
  75099. {
  75100. this.toolbar.destroy();
  75101. this.toolbar = null;
  75102. }
  75103. };
  75104. /**
  75105. * Copyright (c) 2006-2019, JGraph Ltd
  75106. * Copyright (c) 2006-2019, draw.io AG
  75107. */
  75108. /**
  75109. * Class: mxEditor
  75110. *
  75111. * Extends <mxEventSource> to implement an application wrapper for a graph that
  75112. * adds <actions>, I/O using <mxCodec>, auto-layout using <mxLayoutManager>,
  75113. * command history using <undoManager>, and standard dialogs and widgets, eg.
  75114. * properties, help, outline, toolbar, and popupmenu. It also adds <templates>
  75115. * to be used as cells in toolbars, auto-validation using the <validation>
  75116. * flag, attribute cycling using <cycleAttributeValues>, higher-level events
  75117. * such as <root>, and backend integration using <urlPost> and <urlImage>.
  75118. *
  75119. * Actions:
  75120. *
  75121. * Actions are functions stored in the <actions> array under their names. The
  75122. * functions take the <mxEditor> as the first, and an optional <mxCell> as the
  75123. * second argument and are invoked using <execute>. Any additional arguments
  75124. * passed to execute are passed on to the action as-is.
  75125. *
  75126. * A list of built-in actions is available in the <addActions> description.
  75127. *
  75128. * Read/write Diagrams:
  75129. *
  75130. * To read a diagram from an XML string, for example from a textfield within the
  75131. * page, the following code is used:
  75132. *
  75133. * (code)
  75134. * var doc = mxUtils.parseXML(xmlString);
  75135. * var node = doc.documentElement;
  75136. * editor.readGraphModel(node);
  75137. * (end)
  75138. *
  75139. * For reading a diagram from a remote location, use the <open> method.
  75140. *
  75141. * To save diagrams in XML on a server, you can set the <urlPost> variable.
  75142. * This variable will be used in <getUrlPost> to construct a URL for the post
  75143. * request that is issued in the <save> method. The post request contains the
  75144. * XML representation of the diagram as returned by <writeGraphModel> in the
  75145. * xml parameter.
  75146. *
  75147. * On the server side, the post request is processed using standard
  75148. * technologies such as Java Servlets, CGI, .NET or ASP.
  75149. *
  75150. * Here are some examples of processing a post request in various languages.
  75151. *
  75152. * - Java: URLDecoder.decode(request.getParameter("xml"), "UTF-8").replace("\n", "&#xa;")
  75153. *
  75154. * Note that the linefeeds should only be replaced if the XML is
  75155. * processed in Java, for example when creating an image, but not
  75156. * if the XML is passed back to the client-side.
  75157. *
  75158. * - .NET: HttpUtility.UrlDecode(context.Request.Params["xml"])
  75159. * - PHP: urldecode($_POST["xml"])
  75160. *
  75161. * Creating images:
  75162. *
  75163. * A backend (Java, PHP or C#) is required for creating images. The
  75164. * distribution contains an example for each backend (ImageHandler.java,
  75165. * ImageHandler.cs and graph.php). More information about using a backend
  75166. * to create images can be found in the readme.html files. Note that the
  75167. * preview is implemented using VML/SVG in the browser and does not require
  75168. * a backend. The backend is only required to creates images (bitmaps).
  75169. *
  75170. * Special characters:
  75171. *
  75172. * Note There are five characters that should always appear in XML content as
  75173. * escapes, so that they do not interact with the syntax of the markup. These
  75174. * are part of the language for all documents based on XML and for HTML.
  75175. *
  75176. * - &lt; (<)
  75177. * - &gt; (>)
  75178. * - &amp; (&)
  75179. * - &quot; (")
  75180. * - &apos; (')
  75181. *
  75182. * Although it is part of the XML language, &apos; is not defined in HTML.
  75183. * For this reason the XHTML specification recommends instead the use of
  75184. * &#39; if text may be passed to a HTML user agent.
  75185. *
  75186. * If you are having problems with special characters on the server-side then
  75187. * you may want to try the <escapePostData> flag.
  75188. *
  75189. * For converting decimal escape sequences inside strings, a user has provided
  75190. * us with the following function:
  75191. *
  75192. * (code)
  75193. * function html2js(text)
  75194. * {
  75195. * var entitySearch = /&#[0-9]+;/;
  75196. * var entity;
  75197. *
  75198. * while (entity = entitySearch.exec(text))
  75199. * {
  75200. * var charCode = entity[0].substring(2, entity[0].length -1);
  75201. * text = text.substring(0, entity.index)
  75202. * + String.fromCharCode(charCode)
  75203. * + text.substring(entity.index + entity[0].length);
  75204. * }
  75205. *
  75206. * return text;
  75207. * }
  75208. * (end)
  75209. *
  75210. * Otherwise try using hex escape sequences and the built-in unescape function
  75211. * for converting such strings.
  75212. *
  75213. * Local Files:
  75214. *
  75215. * For saving and opening local files, no standardized method exists that
  75216. * works across all browsers. The recommended way of dealing with local files
  75217. * is to create a backend that streams the XML data back to the browser (echo)
  75218. * as an attachment so that a Save-dialog is displayed on the client-side and
  75219. * the file can be saved to the local disk.
  75220. *
  75221. * For example, in PHP the code that does this looks as follows.
  75222. *
  75223. * (code)
  75224. * $xml = stripslashes($_POST["xml"]);
  75225. * header("Content-Disposition: attachment; filename=\"diagram.xml\"");
  75226. * echo($xml);
  75227. * (end)
  75228. *
  75229. * To open a local file, the file should be uploaded via a form in the browser
  75230. * and then opened from the server in the editor.
  75231. *
  75232. * Cell Properties:
  75233. *
  75234. * The properties displayed in the properties dialog are the attributes and
  75235. * values of the cell's user object, which is an XML node. The XML node is
  75236. * defined in the templates section of the config file.
  75237. *
  75238. * The templates are stored in <mxEditor.templates> and contain cells which
  75239. * are cloned at insertion time to create new vertices by use of drag and
  75240. * drop from the toolbar. Each entry in the toolbar for adding a new vertex
  75241. * must refer to an existing template.
  75242. *
  75243. * In the following example, the task node is a business object and only the
  75244. * mxCell node and its mxGeometry child contain graph information:
  75245. *
  75246. * (code)
  75247. * <Task label="Task" description="">
  75248. * <mxCell vertex="true">
  75249. * <mxGeometry as="geometry" width="72" height="32"/>
  75250. * </mxCell>
  75251. * </Task>
  75252. * (end)
  75253. *
  75254. * The idea is that the XML representation is inverse from the in-memory
  75255. * representation: The outer XML node is the user object and the inner node is
  75256. * the cell. This means the user object of the cell is the Task node with no
  75257. * children for the above example:
  75258. *
  75259. * (code)
  75260. * <Task label="Task" description=""/>
  75261. * (end)
  75262. *
  75263. * The Task node can have any tag name, attributes and child nodes. The
  75264. * <mxCodec> will use the XML hierarchy as the user object, while removing the
  75265. * "known annotations", such as the mxCell node. At save-time the cell data
  75266. * will be "merged" back into the user object. The user object is only modified
  75267. * via the properties dialog during the lifecycle of the cell.
  75268. *
  75269. * In the default implementation of <createProperties>, the user object's
  75270. * attributes are put into a form for editing. Attributes are changed using
  75271. * the <mxCellAttributeChange> action in the model. The dialog can be replaced
  75272. * by overriding the <createProperties> hook or by replacing the showProperties
  75273. * action in <actions>. Alternatively, the entry in the config file's popupmenu
  75274. * section can be modified to invoke a different action.
  75275. *
  75276. * If you want to displey the properties dialog on a doubleclick, you can set
  75277. * <mxEditor.dblClickAction> to showProperties as follows:
  75278. *
  75279. * (code)
  75280. * editor.dblClickAction = 'showProperties';
  75281. * (end)
  75282. *
  75283. * Popupmenu and Toolbar:
  75284. *
  75285. * The toolbar and popupmenu are typically configured using the respective
  75286. * sections in the config file, that is, the popupmenu is defined as follows:
  75287. *
  75288. * (code)
  75289. * <mxEditor>
  75290. * <mxDefaultPopupMenu as="popupHandler">
  75291. * <add as="cut" action="cut" icon="images/cut.gif"/>
  75292. * ...
  75293. * (end)
  75294. *
  75295. * New entries can be added to the toolbar by inserting an add-node into the
  75296. * above configuration. Existing entries may be removed and changed by
  75297. * modifying or removing the respective entries in the configuration.
  75298. * The configuration is read by the <mxDefaultPopupMenuCodec>, the format of the
  75299. * configuration is explained in <mxDefaultPopupMenu.decode>.
  75300. *
  75301. * The toolbar is defined in the mxDefaultToolbar section. Items can be added
  75302. * and removed in this section.
  75303. *
  75304. * (code)
  75305. * <mxEditor>
  75306. * <mxDefaultToolbar>
  75307. * <add as="save" action="save" icon="images/save.gif"/>
  75308. * <add as="Swimlane" template="swimlane" icon="images/swimlane.gif"/>
  75309. * ...
  75310. * (end)
  75311. *
  75312. * The format of the configuration is described in
  75313. * <mxDefaultToolbarCodec.decode>.
  75314. *
  75315. * Ids:
  75316. *
  75317. * For the IDs, there is an implicit behaviour in <mxCodec>: It moves the Id
  75318. * from the cell to the user object at encoding time and vice versa at decoding
  75319. * time. For example, if the Task node from above has an id attribute, then
  75320. * the <mxCell.id> of the corresponding cell will have this value. If there
  75321. * is no Id collision in the model, then the cell may be retrieved using this
  75322. * Id with the <mxGraphModel.getCell> function. If there is a collision, a new
  75323. * Id will be created for the cell using <mxGraphModel.createId>. At encoding
  75324. * time, this new Id will replace the value previously stored under the id
  75325. * attribute in the Task node.
  75326. *
  75327. * See <mxEditorCodec>, <mxDefaultToolbarCodec> and <mxDefaultPopupMenuCodec>
  75328. * for information about configuring the editor and user interface.
  75329. *
  75330. * Programmatically inserting cells:
  75331. *
  75332. * For inserting a new cell, say, by clicking a button in the document,
  75333. * the following code can be used. This requires an reference to the editor.
  75334. *
  75335. * (code)
  75336. * var userObject = new Object();
  75337. * var parent = editor.graph.getDefaultParent();
  75338. * var model = editor.graph.model;
  75339. * model.beginUpdate();
  75340. * try
  75341. * {
  75342. * editor.graph.insertVertex(parent, null, userObject, 20, 20, 80, 30);
  75343. * }
  75344. * finally
  75345. * {
  75346. * model.endUpdate();
  75347. * }
  75348. * (end)
  75349. *
  75350. * If a template cell from the config file should be inserted, then a clone
  75351. * of the template can be created as follows. The clone is then inserted using
  75352. * the add function instead of addVertex.
  75353. *
  75354. * (code)
  75355. * var template = editor.templates['task'];
  75356. * var clone = editor.graph.model.cloneCell(template);
  75357. * (end)
  75358. *
  75359. * Resources:
  75360. *
  75361. * resources/editor - Language resources for mxEditor
  75362. *
  75363. * Callback: onInit
  75364. *
  75365. * Called from within the constructor. In the callback,
  75366. * "this" refers to the editor instance.
  75367. *
  75368. * Cookie: mxgraph=seen
  75369. *
  75370. * Set when the editor is started. Never expires. Use
  75371. * <resetFirstTime> to reset this cookie. This cookie
  75372. * only exists if <onInit> is implemented.
  75373. *
  75374. * Event: mxEvent.OPEN
  75375. *
  75376. * Fires after a file was opened in <open>. The <code>filename</code> property
  75377. * contains the filename that was used. The same value is also available in
  75378. * <filename>.
  75379. *
  75380. * Event: mxEvent.SAVE
  75381. *
  75382. * Fires after the current file was saved in <save>. The <code>url</code>
  75383. * property contains the URL that was used for saving.
  75384. *
  75385. * Event: mxEvent.POST
  75386. *
  75387. * Fires if a successful response was received in <postDiagram>. The
  75388. * <code>request</code> property contains the <mxXmlRequest>, the
  75389. * <code>url</code> and <code>data</code> properties contain the URL and the
  75390. * data that were used in the post request.
  75391. *
  75392. * Event: mxEvent.ROOT
  75393. *
  75394. * Fires when the current root has changed, or when the title of the current
  75395. * root has changed. This event has no properties.
  75396. *
  75397. * Event: mxEvent.BEFORE_ADD_VERTEX
  75398. *
  75399. * Fires before a vertex is added in <addVertex>. The <code>vertex</code>
  75400. * property contains the new vertex and the <code>parent</code> property
  75401. * contains its parent.
  75402. *
  75403. * Event: mxEvent.ADD_VERTEX
  75404. *
  75405. * Fires between begin- and endUpdate in <addVertex>. The <code>vertex</code>
  75406. * property contains the vertex that is being inserted.
  75407. *
  75408. * Event: mxEvent.AFTER_ADD_VERTEX
  75409. *
  75410. * Fires after a vertex was inserted and selected in <addVertex>. The
  75411. * <code>vertex</code> property contains the new vertex.
  75412. *
  75413. * Example:
  75414. *
  75415. * For starting an in-place edit after a new vertex has been added to the
  75416. * graph, the following code can be used.
  75417. *
  75418. * (code)
  75419. * editor.addListener(mxEvent.AFTER_ADD_VERTEX, function(sender, evt)
  75420. * {
  75421. * var vertex = evt.getProperty('vertex');
  75422. *
  75423. * if (editor.graph.isCellEditable(vertex))
  75424. * {
  75425. * editor.graph.startEditingAtCell(vertex);
  75426. * }
  75427. * });
  75428. * (end)
  75429. *
  75430. * Event: mxEvent.ESCAPE
  75431. *
  75432. * Fires when the escape key is pressed. The <code>event</code> property
  75433. * contains the key event.
  75434. *
  75435. * Constructor: mxEditor
  75436. *
  75437. * Constructs a new editor. This function invokes the <onInit> callback
  75438. * upon completion.
  75439. *
  75440. * Example:
  75441. *
  75442. * (code)
  75443. * var config = mxUtils.load('config/diagrameditor.xml').getDocumentElement();
  75444. * var editor = new mxEditor(config);
  75445. * (end)
  75446. *
  75447. * Parameters:
  75448. *
  75449. * config - Optional XML node that contains the configuration.
  75450. */
  75451. function mxEditor(config)
  75452. {
  75453. this.actions = [];
  75454. this.addActions();
  75455. // Executes the following only if a document has been instanciated.
  75456. // That is, don't execute when the editorcodec is setup.
  75457. if (document.body != null)
  75458. {
  75459. // Defines instance fields
  75460. this.cycleAttributeValues = [];
  75461. this.popupHandler = new mxDefaultPopupMenu();
  75462. this.undoManager = new mxUndoManager();
  75463. // Creates the graph and toolbar without the containers
  75464. this.graph = this.createGraph();
  75465. this.toolbar = this.createToolbar();
  75466. // Creates the global keyhandler (requires graph instance)
  75467. this.keyHandler = new mxDefaultKeyHandler(this);
  75468. // Configures the editor using the URI
  75469. // which was passed to the ctor
  75470. this.configure(config);
  75471. // Assigns the swimlaneIndicatorColorAttribute on the graph
  75472. this.graph.swimlaneIndicatorColorAttribute = this.cycleAttributeName;
  75473. // Checks if the <onInit> hook has been set
  75474. if (this.onInit != null)
  75475. {
  75476. // Invokes the <onInit> hook
  75477. this.onInit();
  75478. }
  75479. // Automatic deallocation of memory
  75480. if (mxClient.IS_IE)
  75481. {
  75482. mxEvent.addListener(window, 'unload', mxUtils.bind(this, function()
  75483. {
  75484. this.destroy();
  75485. }));
  75486. }
  75487. }
  75488. };
  75489. /**
  75490. * Installs the required language resources at class
  75491. * loading time.
  75492. */
  75493. if (mxLoadResources)
  75494. {
  75495. mxResources.add(mxClient.basePath + '/resources/editor');
  75496. }
  75497. else
  75498. {
  75499. mxClient.defaultBundles.push(mxClient.basePath + '/resources/editor');
  75500. }
  75501. /**
  75502. * Extends mxEventSource.
  75503. */
  75504. mxEditor.prototype = new mxEventSource();
  75505. mxEditor.prototype.constructor = mxEditor;
  75506. /**
  75507. * Group: Controls and Handlers
  75508. */
  75509. /**
  75510. * Variable: askZoomResource
  75511. *
  75512. * Specifies the resource key for the zoom dialog. If the resource for this
  75513. * key does not exist then the value is used as the error message. Default
  75514. * is 'askZoom'.
  75515. */
  75516. mxEditor.prototype.askZoomResource = (mxClient.language != 'none') ? 'askZoom' : '';
  75517. /**
  75518. * Variable: lastSavedResource
  75519. *
  75520. * Specifies the resource key for the last saved info. If the resource for
  75521. * this key does not exist then the value is used as the error message.
  75522. * Default is 'lastSaved'.
  75523. */
  75524. mxEditor.prototype.lastSavedResource = (mxClient.language != 'none') ? 'lastSaved' : '';
  75525. /**
  75526. * Variable: currentFileResource
  75527. *
  75528. * Specifies the resource key for the current file info. If the resource for
  75529. * this key does not exist then the value is used as the error message.
  75530. * Default is 'currentFile'.
  75531. */
  75532. mxEditor.prototype.currentFileResource = (mxClient.language != 'none') ? 'currentFile' : '';
  75533. /**
  75534. * Variable: propertiesResource
  75535. *
  75536. * Specifies the resource key for the properties window title. If the
  75537. * resource for this key does not exist then the value is used as the
  75538. * error message. Default is 'properties'.
  75539. */
  75540. mxEditor.prototype.propertiesResource = (mxClient.language != 'none') ? 'properties' : '';
  75541. /**
  75542. * Variable: tasksResource
  75543. *
  75544. * Specifies the resource key for the tasks window title. If the
  75545. * resource for this key does not exist then the value is used as the
  75546. * error message. Default is 'tasks'.
  75547. */
  75548. mxEditor.prototype.tasksResource = (mxClient.language != 'none') ? 'tasks' : '';
  75549. /**
  75550. * Variable: helpResource
  75551. *
  75552. * Specifies the resource key for the help window title. If the
  75553. * resource for this key does not exist then the value is used as the
  75554. * error message. Default is 'help'.
  75555. */
  75556. mxEditor.prototype.helpResource = (mxClient.language != 'none') ? 'help' : '';
  75557. /**
  75558. * Variable: outlineResource
  75559. *
  75560. * Specifies the resource key for the outline window title. If the
  75561. * resource for this key does not exist then the value is used as the
  75562. * error message. Default is 'outline'.
  75563. */
  75564. mxEditor.prototype.outlineResource = (mxClient.language != 'none') ? 'outline' : '';
  75565. /**
  75566. * Variable: outline
  75567. *
  75568. * Reference to the <mxWindow> that contains the outline. The <mxOutline>
  75569. * is stored in outline.outline.
  75570. */
  75571. mxEditor.prototype.outline = null;
  75572. /**
  75573. * Variable: graph
  75574. *
  75575. * Holds a <mxGraph> for displaying the diagram. The graph
  75576. * is created in <setGraphContainer>.
  75577. */
  75578. mxEditor.prototype.graph = null;
  75579. /**
  75580. * Variable: graphRenderHint
  75581. *
  75582. * Holds the render hint used for creating the
  75583. * graph in <setGraphContainer>. See <mxGraph>.
  75584. * Default is null.
  75585. */
  75586. mxEditor.prototype.graphRenderHint = null;
  75587. /**
  75588. * Variable: toolbar
  75589. *
  75590. * Holds a <mxDefaultToolbar> for displaying the toolbar. The
  75591. * toolbar is created in <setToolbarContainer>.
  75592. */
  75593. mxEditor.prototype.toolbar = null;
  75594. /**
  75595. * Variable: status
  75596. *
  75597. * DOM container that holds the statusbar. Default is null.
  75598. * Use <setStatusContainer> to set this value.
  75599. */
  75600. mxEditor.prototype.status = null;
  75601. /**
  75602. * Variable: popupHandler
  75603. *
  75604. * Holds a <mxDefaultPopupMenu> for displaying
  75605. * popupmenus.
  75606. */
  75607. mxEditor.prototype.popupHandler = null;
  75608. /**
  75609. * Variable: undoManager
  75610. *
  75611. * Holds an <mxUndoManager> for the command history.
  75612. */
  75613. mxEditor.prototype.undoManager = null;
  75614. /**
  75615. * Variable: keyHandler
  75616. *
  75617. * Holds a <mxDefaultKeyHandler> for handling keyboard events.
  75618. * The handler is created in <setGraphContainer>.
  75619. */
  75620. mxEditor.prototype.keyHandler = null;
  75621. /**
  75622. * Group: Actions and Options
  75623. */
  75624. /**
  75625. * Variable: actions
  75626. *
  75627. * Maps from actionnames to actions, which are functions taking
  75628. * the editor and the cell as arguments. Use <addAction>
  75629. * to add or replace an action and <execute> to execute an action
  75630. * by name, passing the cell to be operated upon as the second
  75631. * argument.
  75632. */
  75633. mxEditor.prototype.actions = null;
  75634. /**
  75635. * Variable: dblClickAction
  75636. *
  75637. * Specifies the name of the action to be executed
  75638. * when a cell is double clicked. Default is 'edit'.
  75639. *
  75640. * To handle a singleclick, use the following code.
  75641. *
  75642. * (code)
  75643. * editor.graph.addListener(mxEvent.CLICK, function(sender, evt)
  75644. * {
  75645. * var e = evt.getProperty('event');
  75646. * var cell = evt.getProperty('cell');
  75647. *
  75648. * if (cell != null && !e.isConsumed())
  75649. * {
  75650. * // Do something useful with cell...
  75651. * e.consume();
  75652. * }
  75653. * });
  75654. * (end)
  75655. */
  75656. mxEditor.prototype.dblClickAction = 'edit';
  75657. /**
  75658. * Variable: swimlaneRequired
  75659. *
  75660. * Specifies if new cells must be inserted
  75661. * into an existing swimlane. Otherwise, cells
  75662. * that are not swimlanes can be inserted as
  75663. * top-level cells. Default is false.
  75664. */
  75665. mxEditor.prototype.swimlaneRequired = false;
  75666. /**
  75667. * Variable: disableContextMenu
  75668. *
  75669. * Specifies if the context menu should be disabled in the graph container.
  75670. * Default is true.
  75671. */
  75672. mxEditor.prototype.disableContextMenu = true;
  75673. /**
  75674. * Group: Templates
  75675. */
  75676. /**
  75677. * Variable: insertFunction
  75678. *
  75679. * Specifies the function to be used for inserting new
  75680. * cells into the graph. This is assigned from the
  75681. * <mxDefaultToolbar> if a vertex-tool is clicked.
  75682. */
  75683. mxEditor.prototype.insertFunction = null;
  75684. /**
  75685. * Variable: forcedInserting
  75686. *
  75687. * Specifies if a new cell should be inserted on a single
  75688. * click even using <insertFunction> if there is a cell
  75689. * under the mousepointer, otherwise the cell under the
  75690. * mousepointer is selected. Default is false.
  75691. */
  75692. mxEditor.prototype.forcedInserting = false;
  75693. /**
  75694. * Variable: templates
  75695. *
  75696. * Maps from names to protoype cells to be used
  75697. * in the toolbar for inserting new cells into
  75698. * the diagram.
  75699. */
  75700. mxEditor.prototype.templates = null;
  75701. /**
  75702. * Variable: defaultEdge
  75703. *
  75704. * Prototype edge cell that is used for creating
  75705. * new edges.
  75706. */
  75707. mxEditor.prototype.defaultEdge = null;
  75708. /**
  75709. * Variable: defaultEdgeStyle
  75710. *
  75711. * Specifies the edge style to be returned in <getEdgeStyle>.
  75712. * Default is null.
  75713. */
  75714. mxEditor.prototype.defaultEdgeStyle = null;
  75715. /**
  75716. * Variable: defaultGroup
  75717. *
  75718. * Prototype group cell that is used for creating
  75719. * new groups.
  75720. */
  75721. mxEditor.prototype.defaultGroup = null;
  75722. /**
  75723. * Variable: groupBorderSize
  75724. *
  75725. * Default size for the border of new groups. If null,
  75726. * then then <mxGraph.gridSize> is used. Default is
  75727. * null.
  75728. */
  75729. mxEditor.prototype.groupBorderSize = null;
  75730. /**
  75731. * Group: Backend Integration
  75732. */
  75733. /**
  75734. * Variable: filename
  75735. *
  75736. * Contains the URL of the last opened file as a string.
  75737. * Default is null.
  75738. */
  75739. mxEditor.prototype.filename = null;
  75740. /**
  75741. * Variable: lineFeed
  75742. *
  75743. * Character to be used for encoding linefeeds in <save>. Default is '&#xa;'.
  75744. */
  75745. mxEditor.prototype.linefeed = '&#xa;';
  75746. /**
  75747. * Variable: postParameterName
  75748. *
  75749. * Specifies if the name of the post parameter that contains the diagram
  75750. * data in a post request to the server. Default is 'xml'.
  75751. */
  75752. mxEditor.prototype.postParameterName = 'xml';
  75753. /**
  75754. * Variable: escapePostData
  75755. *
  75756. * Specifies if the data in the post request for saving a diagram
  75757. * should be converted using encodeURIComponent. Default is true.
  75758. */
  75759. mxEditor.prototype.escapePostData = true;
  75760. /**
  75761. * Variable: urlPost
  75762. *
  75763. * Specifies the URL to be used for posting the diagram
  75764. * to a backend in <save>.
  75765. */
  75766. mxEditor.prototype.urlPost = null;
  75767. /**
  75768. * Variable: urlImage
  75769. *
  75770. * Specifies the URL to be used for creating a bitmap of
  75771. * the graph in the image action.
  75772. */
  75773. mxEditor.prototype.urlImage = null;
  75774. /**
  75775. * Group: Autolayout
  75776. */
  75777. /**
  75778. * Variable: horizontalFlow
  75779. *
  75780. * Specifies the direction of the flow
  75781. * in the diagram. This is used in the
  75782. * layout algorithms. Default is false,
  75783. * ie. vertical flow.
  75784. */
  75785. mxEditor.prototype.horizontalFlow = false;
  75786. /**
  75787. * Variable: layoutDiagram
  75788. *
  75789. * Specifies if the top-level elements in the
  75790. * diagram should be layed out using a vertical
  75791. * or horizontal stack depending on the setting
  75792. * of <horizontalFlow>. The spacing between the
  75793. * swimlanes is specified by <swimlaneSpacing>.
  75794. * Default is false.
  75795. *
  75796. * If the top-level elements are swimlanes, then
  75797. * the intra-swimlane layout is activated by
  75798. * the <layoutSwimlanes> switch.
  75799. */
  75800. mxEditor.prototype.layoutDiagram = false;
  75801. /**
  75802. * Variable: swimlaneSpacing
  75803. *
  75804. * Specifies the spacing between swimlanes if
  75805. * automatic layout is turned on in
  75806. * <layoutDiagram>. Default is 0.
  75807. */
  75808. mxEditor.prototype.swimlaneSpacing = 0;
  75809. /**
  75810. * Variable: maintainSwimlanes
  75811. *
  75812. * Specifies if the swimlanes should be kept at the same
  75813. * width or height depending on the setting of
  75814. * <horizontalFlow>. Default is false.
  75815. *
  75816. * For horizontal flows, all swimlanes
  75817. * have the same height and for vertical flows, all swimlanes
  75818. * have the same width. Furthermore, the swimlanes are
  75819. * automatically "stacked" if <layoutDiagram> is true.
  75820. */
  75821. mxEditor.prototype.maintainSwimlanes = false;
  75822. /**
  75823. * Variable: layoutSwimlanes
  75824. *
  75825. * Specifies if the children of swimlanes should
  75826. * be layed out, either vertically or horizontally
  75827. * depending on <horizontalFlow>.
  75828. * Default is false.
  75829. */
  75830. mxEditor.prototype.layoutSwimlanes = false;
  75831. /**
  75832. * Group: Attribute Cycling
  75833. */
  75834. /**
  75835. * Variable: cycleAttributeValues
  75836. *
  75837. * Specifies the attribute values to be cycled when
  75838. * inserting new swimlanes. Default is an empty
  75839. * array.
  75840. */
  75841. mxEditor.prototype.cycleAttributeValues = null;
  75842. /**
  75843. * Variable: cycleAttributeIndex
  75844. *
  75845. * Index of the last consumed attribute index. If a new
  75846. * swimlane is inserted, then the <cycleAttributeValues>
  75847. * at this index will be used as the value for
  75848. * <cycleAttributeName>. Default is 0.
  75849. */
  75850. mxEditor.prototype.cycleAttributeIndex = 0;
  75851. /**
  75852. * Variable: cycleAttributeName
  75853. *
  75854. * Name of the attribute to be assigned a <cycleAttributeValues>
  75855. * when inserting new swimlanes. Default is 'fillColor'.
  75856. */
  75857. mxEditor.prototype.cycleAttributeName = 'fillColor';
  75858. /**
  75859. * Group: Windows
  75860. */
  75861. /**
  75862. * Variable: tasks
  75863. *
  75864. * Holds the <mxWindow> created in <showTasks>.
  75865. */
  75866. mxEditor.prototype.tasks = null;
  75867. /**
  75868. * Variable: tasksWindowImage
  75869. *
  75870. * Icon for the tasks window.
  75871. */
  75872. mxEditor.prototype.tasksWindowImage = null;
  75873. /**
  75874. * Variable: tasksTop
  75875. *
  75876. * Specifies the top coordinate of the tasks window in pixels.
  75877. * Default is 20.
  75878. */
  75879. mxEditor.prototype.tasksTop = 20;
  75880. /**
  75881. * Variable: help
  75882. *
  75883. * Holds the <mxWindow> created in <showHelp>.
  75884. */
  75885. mxEditor.prototype.help = null;
  75886. /**
  75887. * Variable: helpWindowImage
  75888. *
  75889. * Icon for the help window.
  75890. */
  75891. mxEditor.prototype.helpWindowImage = null;
  75892. /**
  75893. * Variable: urlHelp
  75894. *
  75895. * Specifies the URL to be used for the contents of the
  75896. * Online Help window. This is usually specified in the
  75897. * resources file under urlHelp for language-specific
  75898. * online help support.
  75899. */
  75900. mxEditor.prototype.urlHelp = null;
  75901. /**
  75902. * Variable: helpWidth
  75903. *
  75904. * Specifies the width of the help window in pixels.
  75905. * Default is 300.
  75906. */
  75907. mxEditor.prototype.helpWidth = 300;
  75908. /**
  75909. * Variable: helpHeight
  75910. *
  75911. * Specifies the height of the help window in pixels.
  75912. * Default is 260.
  75913. */
  75914. mxEditor.prototype.helpHeight = 260;
  75915. /**
  75916. * Variable: propertiesWidth
  75917. *
  75918. * Specifies the width of the properties window in pixels.
  75919. * Default is 240.
  75920. */
  75921. mxEditor.prototype.propertiesWidth = 240;
  75922. /**
  75923. * Variable: propertiesHeight
  75924. *
  75925. * Specifies the height of the properties window in pixels.
  75926. * If no height is specified then the window will be automatically
  75927. * sized to fit its contents. Default is null.
  75928. */
  75929. mxEditor.prototype.propertiesHeight = null;
  75930. /**
  75931. * Variable: movePropertiesDialog
  75932. *
  75933. * Specifies if the properties dialog should be automatically
  75934. * moved near the cell it is displayed for, otherwise the
  75935. * dialog is not moved. This value is only taken into
  75936. * account if the dialog is already visible. Default is false.
  75937. */
  75938. mxEditor.prototype.movePropertiesDialog = false;
  75939. /**
  75940. * Variable: validating
  75941. *
  75942. * Specifies if <mxGraph.validateGraph> should automatically be invoked after
  75943. * each change. Default is false.
  75944. */
  75945. mxEditor.prototype.validating = false;
  75946. /**
  75947. * Variable: modified
  75948. *
  75949. * True if the graph has been modified since it was last saved.
  75950. */
  75951. mxEditor.prototype.modified = false;
  75952. /**
  75953. * Function: isModified
  75954. *
  75955. * Returns <modified>.
  75956. */
  75957. mxEditor.prototype.isModified = function ()
  75958. {
  75959. return this.modified;
  75960. };
  75961. /**
  75962. * Function: setModified
  75963. *
  75964. * Sets <modified> to the specified boolean value.
  75965. */
  75966. mxEditor.prototype.setModified = function (value)
  75967. {
  75968. this.modified = value;
  75969. };
  75970. /**
  75971. * Function: addActions
  75972. *
  75973. * Adds the built-in actions to the editor instance.
  75974. *
  75975. * save - Saves the graph using <urlPost>.
  75976. * print - Shows the graph in a new print preview window.
  75977. * show - Shows the graph in a new window.
  75978. * exportImage - Shows the graph as a bitmap image using <getUrlImage>.
  75979. * refresh - Refreshes the graph's display.
  75980. * cut - Copies the current selection into the clipboard
  75981. * and removes it from the graph.
  75982. * copy - Copies the current selection into the clipboard.
  75983. * paste - Pastes the clipboard into the graph.
  75984. * delete - Removes the current selection from the graph.
  75985. * group - Puts the current selection into a new group.
  75986. * ungroup - Removes the selected groups and selects the children.
  75987. * undo - Undoes the last change on the graph model.
  75988. * redo - Redoes the last change on the graph model.
  75989. * zoom - Sets the zoom via a dialog.
  75990. * zoomIn - Zooms into the graph.
  75991. * zoomOut - Zooms out of the graph
  75992. * actualSize - Resets the scale and translation on the graph.
  75993. * fit - Changes the scale so that the graph fits into the window.
  75994. * showProperties - Shows the properties dialog.
  75995. * selectAll - Selects all cells.
  75996. * selectNone - Clears the selection.
  75997. * selectVertices - Selects all vertices.
  75998. * selectEdges = Selects all edges.
  75999. * edit - Starts editing the current selection cell.
  76000. * enterGroup - Drills down into the current selection cell.
  76001. * exitGroup - Moves up in the drilling hierachy
  76002. * home - Moves to the topmost parent in the drilling hierarchy
  76003. * selectPrevious - Selects the previous cell.
  76004. * selectNext - Selects the next cell.
  76005. * selectParent - Selects the parent of the selection cell.
  76006. * selectChild - Selects the first child of the selection cell.
  76007. * collapse - Collapses the currently selected cells.
  76008. * expand - Expands the currently selected cells.
  76009. * bold - Toggle bold text style.
  76010. * italic - Toggle italic text style.
  76011. * underline - Toggle underline text style.
  76012. * alignCellsLeft - Aligns the selection cells at the left.
  76013. * alignCellsCenter - Aligns the selection cells in the center.
  76014. * alignCellsRight - Aligns the selection cells at the right.
  76015. * alignCellsTop - Aligns the selection cells at the top.
  76016. * alignCellsMiddle - Aligns the selection cells in the middle.
  76017. * alignCellsBottom - Aligns the selection cells at the bottom.
  76018. * alignFontLeft - Sets the horizontal text alignment to left.
  76019. * alignFontCenter - Sets the horizontal text alignment to center.
  76020. * alignFontRight - Sets the horizontal text alignment to right.
  76021. * alignFontTop - Sets the vertical text alignment to top.
  76022. * alignFontMiddle - Sets the vertical text alignment to middle.
  76023. * alignFontBottom - Sets the vertical text alignment to bottom.
  76024. * toggleTasks - Shows or hides the tasks window.
  76025. * toggleHelp - Shows or hides the help window.
  76026. * toggleOutline - Shows or hides the outline window.
  76027. * toggleConsole - Shows or hides the console window.
  76028. */
  76029. mxEditor.prototype.addActions = function ()
  76030. {
  76031. this.addAction('save', function(editor)
  76032. {
  76033. editor.save();
  76034. });
  76035. this.addAction('print', function(editor)
  76036. {
  76037. var preview = new mxPrintPreview(editor.graph, 1);
  76038. preview.open();
  76039. });
  76040. this.addAction('show', function(editor)
  76041. {
  76042. mxUtils.show(editor.graph, null, 10, 10);
  76043. });
  76044. this.addAction('exportImage', function(editor)
  76045. {
  76046. var url = editor.getUrlImage();
  76047. if (url == null || mxClient.IS_LOCAL)
  76048. {
  76049. editor.execute('show');
  76050. }
  76051. else
  76052. {
  76053. var node = mxUtils.getViewXml(editor.graph, 1);
  76054. var xml = mxUtils.getXml(node, '\n');
  76055. mxUtils.submit(url, editor.postParameterName + '=' +
  76056. encodeURIComponent(xml), document, '_blank');
  76057. }
  76058. });
  76059. this.addAction('refresh', function(editor)
  76060. {
  76061. editor.graph.refresh();
  76062. });
  76063. this.addAction('cut', function(editor)
  76064. {
  76065. if (editor.graph.isEnabled())
  76066. {
  76067. mxClipboard.cut(editor.graph);
  76068. }
  76069. });
  76070. this.addAction('copy', function(editor)
  76071. {
  76072. if (editor.graph.isEnabled())
  76073. {
  76074. mxClipboard.copy(editor.graph);
  76075. }
  76076. });
  76077. this.addAction('paste', function(editor)
  76078. {
  76079. if (editor.graph.isEnabled())
  76080. {
  76081. mxClipboard.paste(editor.graph);
  76082. }
  76083. });
  76084. this.addAction('delete', function(editor)
  76085. {
  76086. if (editor.graph.isEnabled())
  76087. {
  76088. editor.graph.removeCells();
  76089. }
  76090. });
  76091. this.addAction('group', function(editor)
  76092. {
  76093. if (editor.graph.isEnabled())
  76094. {
  76095. editor.graph.setSelectionCell(editor.groupCells());
  76096. }
  76097. });
  76098. this.addAction('ungroup', function(editor)
  76099. {
  76100. if (editor.graph.isEnabled())
  76101. {
  76102. editor.graph.setSelectionCells(editor.graph.ungroupCells());
  76103. }
  76104. });
  76105. this.addAction('removeFromParent', function(editor)
  76106. {
  76107. if (editor.graph.isEnabled())
  76108. {
  76109. editor.graph.removeCellsFromParent();
  76110. }
  76111. });
  76112. this.addAction('undo', function(editor)
  76113. {
  76114. if (editor.graph.isEnabled())
  76115. {
  76116. editor.undo();
  76117. }
  76118. });
  76119. this.addAction('redo', function(editor)
  76120. {
  76121. if (editor.graph.isEnabled())
  76122. {
  76123. editor.redo();
  76124. }
  76125. });
  76126. this.addAction('zoomIn', function(editor)
  76127. {
  76128. editor.graph.zoomIn();
  76129. });
  76130. this.addAction('zoomOut', function(editor)
  76131. {
  76132. editor.graph.zoomOut();
  76133. });
  76134. this.addAction('actualSize', function(editor)
  76135. {
  76136. editor.graph.zoomActual();
  76137. });
  76138. this.addAction('fit', function(editor)
  76139. {
  76140. editor.graph.fit();
  76141. });
  76142. this.addAction('showProperties', function(editor, cell)
  76143. {
  76144. editor.showProperties(cell);
  76145. });
  76146. this.addAction('selectAll', function(editor)
  76147. {
  76148. if (editor.graph.isEnabled())
  76149. {
  76150. editor.graph.selectAll();
  76151. }
  76152. });
  76153. this.addAction('selectNone', function(editor)
  76154. {
  76155. if (editor.graph.isEnabled())
  76156. {
  76157. editor.graph.clearSelection();
  76158. }
  76159. });
  76160. this.addAction('selectVertices', function(editor)
  76161. {
  76162. if (editor.graph.isEnabled())
  76163. {
  76164. editor.graph.selectVertices();
  76165. }
  76166. });
  76167. this.addAction('selectEdges', function(editor)
  76168. {
  76169. if (editor.graph.isEnabled())
  76170. {
  76171. editor.graph.selectEdges();
  76172. }
  76173. });
  76174. this.addAction('edit', function(editor, cell)
  76175. {
  76176. if (editor.graph.isEnabled() &&
  76177. editor.graph.isCellEditable(cell))
  76178. {
  76179. editor.graph.startEditingAtCell(cell);
  76180. }
  76181. });
  76182. this.addAction('toBack', function(editor, cell)
  76183. {
  76184. if (editor.graph.isEnabled())
  76185. {
  76186. editor.graph.orderCells(true);
  76187. }
  76188. });
  76189. this.addAction('toFront', function(editor, cell)
  76190. {
  76191. if (editor.graph.isEnabled())
  76192. {
  76193. editor.graph.orderCells(false);
  76194. }
  76195. });
  76196. this.addAction('enterGroup', function(editor, cell)
  76197. {
  76198. editor.graph.enterGroup(cell);
  76199. });
  76200. this.addAction('exitGroup', function(editor)
  76201. {
  76202. editor.graph.exitGroup();
  76203. });
  76204. this.addAction('home', function(editor)
  76205. {
  76206. editor.graph.home();
  76207. });
  76208. this.addAction('selectPrevious', function(editor)
  76209. {
  76210. if (editor.graph.isEnabled())
  76211. {
  76212. editor.graph.selectPreviousCell();
  76213. }
  76214. });
  76215. this.addAction('selectNext', function(editor)
  76216. {
  76217. if (editor.graph.isEnabled())
  76218. {
  76219. editor.graph.selectNextCell();
  76220. }
  76221. });
  76222. this.addAction('selectParent', function(editor)
  76223. {
  76224. if (editor.graph.isEnabled())
  76225. {
  76226. editor.graph.selectParentCell();
  76227. }
  76228. });
  76229. this.addAction('selectChild', function(editor)
  76230. {
  76231. if (editor.graph.isEnabled())
  76232. {
  76233. editor.graph.selectChildCell();
  76234. }
  76235. });
  76236. this.addAction('collapse', function(editor)
  76237. {
  76238. if (editor.graph.isEnabled())
  76239. {
  76240. editor.graph.foldCells(true);
  76241. }
  76242. });
  76243. this.addAction('collapseAll', function(editor)
  76244. {
  76245. if (editor.graph.isEnabled())
  76246. {
  76247. var cells = editor.graph.getChildVertices();
  76248. editor.graph.foldCells(true, false, cells);
  76249. }
  76250. });
  76251. this.addAction('expand', function(editor)
  76252. {
  76253. if (editor.graph.isEnabled())
  76254. {
  76255. editor.graph.foldCells(false);
  76256. }
  76257. });
  76258. this.addAction('expandAll', function(editor)
  76259. {
  76260. if (editor.graph.isEnabled())
  76261. {
  76262. var cells = editor.graph.getChildVertices();
  76263. editor.graph.foldCells(false, false, cells);
  76264. }
  76265. });
  76266. this.addAction('bold', function(editor)
  76267. {
  76268. if (editor.graph.isEnabled())
  76269. {
  76270. editor.graph.toggleCellStyleFlags(
  76271. mxConstants.STYLE_FONTSTYLE,
  76272. mxConstants.FONT_BOLD);
  76273. }
  76274. });
  76275. this.addAction('italic', function(editor)
  76276. {
  76277. if (editor.graph.isEnabled())
  76278. {
  76279. editor.graph.toggleCellStyleFlags(
  76280. mxConstants.STYLE_FONTSTYLE,
  76281. mxConstants.FONT_ITALIC);
  76282. }
  76283. });
  76284. this.addAction('underline', function(editor)
  76285. {
  76286. if (editor.graph.isEnabled())
  76287. {
  76288. editor.graph.toggleCellStyleFlags(
  76289. mxConstants.STYLE_FONTSTYLE,
  76290. mxConstants.FONT_UNDERLINE);
  76291. }
  76292. });
  76293. this.addAction('alignCellsLeft', function(editor)
  76294. {
  76295. if (editor.graph.isEnabled())
  76296. {
  76297. editor.graph.alignCells(mxConstants.ALIGN_LEFT);
  76298. }
  76299. });
  76300. this.addAction('alignCellsCenter', function(editor)
  76301. {
  76302. if (editor.graph.isEnabled())
  76303. {
  76304. editor.graph.alignCells(mxConstants.ALIGN_CENTER);
  76305. }
  76306. });
  76307. this.addAction('alignCellsRight', function(editor)
  76308. {
  76309. if (editor.graph.isEnabled())
  76310. {
  76311. editor.graph.alignCells(mxConstants.ALIGN_RIGHT);
  76312. }
  76313. });
  76314. this.addAction('alignCellsTop', function(editor)
  76315. {
  76316. if (editor.graph.isEnabled())
  76317. {
  76318. editor.graph.alignCells(mxConstants.ALIGN_TOP);
  76319. }
  76320. });
  76321. this.addAction('alignCellsMiddle', function(editor)
  76322. {
  76323. if (editor.graph.isEnabled())
  76324. {
  76325. editor.graph.alignCells(mxConstants.ALIGN_MIDDLE);
  76326. }
  76327. });
  76328. this.addAction('alignCellsBottom', function(editor)
  76329. {
  76330. if (editor.graph.isEnabled())
  76331. {
  76332. editor.graph.alignCells(mxConstants.ALIGN_BOTTOM);
  76333. }
  76334. });
  76335. this.addAction('alignFontLeft', function(editor)
  76336. {
  76337. editor.graph.setCellStyles(
  76338. mxConstants.STYLE_ALIGN,
  76339. mxConstants.ALIGN_LEFT);
  76340. });
  76341. this.addAction('alignFontCenter', function(editor)
  76342. {
  76343. if (editor.graph.isEnabled())
  76344. {
  76345. editor.graph.setCellStyles(
  76346. mxConstants.STYLE_ALIGN,
  76347. mxConstants.ALIGN_CENTER);
  76348. }
  76349. });
  76350. this.addAction('alignFontRight', function(editor)
  76351. {
  76352. if (editor.graph.isEnabled())
  76353. {
  76354. editor.graph.setCellStyles(
  76355. mxConstants.STYLE_ALIGN,
  76356. mxConstants.ALIGN_RIGHT);
  76357. }
  76358. });
  76359. this.addAction('alignFontTop', function(editor)
  76360. {
  76361. if (editor.graph.isEnabled())
  76362. {
  76363. editor.graph.setCellStyles(
  76364. mxConstants.STYLE_VERTICAL_ALIGN,
  76365. mxConstants.ALIGN_TOP);
  76366. }
  76367. });
  76368. this.addAction('alignFontMiddle', function(editor)
  76369. {
  76370. if (editor.graph.isEnabled())
  76371. {
  76372. editor.graph.setCellStyles(
  76373. mxConstants.STYLE_VERTICAL_ALIGN,
  76374. mxConstants.ALIGN_MIDDLE);
  76375. }
  76376. });
  76377. this.addAction('alignFontBottom', function(editor)
  76378. {
  76379. if (editor.graph.isEnabled())
  76380. {
  76381. editor.graph.setCellStyles(
  76382. mxConstants.STYLE_VERTICAL_ALIGN,
  76383. mxConstants.ALIGN_BOTTOM);
  76384. }
  76385. });
  76386. this.addAction('zoom', function(editor)
  76387. {
  76388. var current = editor.graph.getView().scale*100;
  76389. var scale = parseFloat(mxUtils.prompt(
  76390. mxResources.get(editor.askZoomResource) ||
  76391. editor.askZoomResource,
  76392. current))/100;
  76393. if (!isNaN(scale))
  76394. {
  76395. editor.graph.getView().setScale(scale);
  76396. }
  76397. });
  76398. this.addAction('toggleTasks', function(editor)
  76399. {
  76400. if (editor.tasks != null)
  76401. {
  76402. editor.tasks.setVisible(!editor.tasks.isVisible());
  76403. }
  76404. else
  76405. {
  76406. editor.showTasks();
  76407. }
  76408. });
  76409. this.addAction('toggleHelp', function(editor)
  76410. {
  76411. if (editor.help != null)
  76412. {
  76413. editor.help.setVisible(!editor.help.isVisible());
  76414. }
  76415. else
  76416. {
  76417. editor.showHelp();
  76418. }
  76419. });
  76420. this.addAction('toggleOutline', function(editor)
  76421. {
  76422. if (editor.outline == null)
  76423. {
  76424. editor.showOutline();
  76425. }
  76426. else
  76427. {
  76428. editor.outline.setVisible(!editor.outline.isVisible());
  76429. }
  76430. });
  76431. this.addAction('toggleConsole', function(editor)
  76432. {
  76433. mxLog.setVisible(!mxLog.isVisible());
  76434. });
  76435. };
  76436. /**
  76437. * Function: configure
  76438. *
  76439. * Configures the editor using the specified node. To load the
  76440. * configuration from a given URL the following code can be used to obtain
  76441. * the XML node.
  76442. *
  76443. * (code)
  76444. * var node = mxUtils.load(url).getDocumentElement();
  76445. * (end)
  76446. *
  76447. * Parameters:
  76448. *
  76449. * node - XML node that contains the configuration.
  76450. */
  76451. mxEditor.prototype.configure = function (node)
  76452. {
  76453. if (node != null)
  76454. {
  76455. // Creates a decoder for the XML data
  76456. // and uses it to configure the editor
  76457. var dec = new mxCodec(node.ownerDocument);
  76458. dec.decode(node, this);
  76459. // Resets the counters, modified state and
  76460. // command history
  76461. this.resetHistory();
  76462. }
  76463. };
  76464. /**
  76465. * Function: resetFirstTime
  76466. *
  76467. * Resets the cookie that is used to remember if the editor has already
  76468. * been used.
  76469. */
  76470. mxEditor.prototype.resetFirstTime = function ()
  76471. {
  76472. document.cookie =
  76473. 'mxgraph=seen; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/';
  76474. };
  76475. /**
  76476. * Function: resetHistory
  76477. *
  76478. * Resets the command history, modified state and counters.
  76479. */
  76480. mxEditor.prototype.resetHistory = function ()
  76481. {
  76482. this.lastSnapshot = new Date().getTime();
  76483. this.undoManager.clear();
  76484. this.ignoredChanges = 0;
  76485. this.setModified(false);
  76486. };
  76487. /**
  76488. * Function: addAction
  76489. *
  76490. * Binds the specified actionname to the specified function.
  76491. *
  76492. * Parameters:
  76493. *
  76494. * actionname - String that specifies the name of the action
  76495. * to be added.
  76496. * funct - Function that implements the new action. The first
  76497. * argument of the function is the editor it is used
  76498. * with, the second argument is the cell it operates
  76499. * upon.
  76500. *
  76501. * Example:
  76502. * (code)
  76503. * editor.addAction('test', function(editor, cell)
  76504. * {
  76505. * mxUtils.alert("test "+cell);
  76506. * });
  76507. * (end)
  76508. */
  76509. mxEditor.prototype.addAction = function (actionname, funct)
  76510. {
  76511. this.actions[actionname] = funct;
  76512. };
  76513. /**
  76514. * Function: execute
  76515. *
  76516. * Executes the function with the given name in <actions> passing the
  76517. * editor instance and given cell as the first and second argument. All
  76518. * additional arguments are passed to the action as well. This method
  76519. * contains a try-catch block and displays an error message if an action
  76520. * causes an exception. The exception is re-thrown after the error
  76521. * message was displayed.
  76522. *
  76523. * Example:
  76524. *
  76525. * (code)
  76526. * editor.execute("showProperties", cell);
  76527. * (end)
  76528. */
  76529. mxEditor.prototype.execute = function (actionname, cell, evt)
  76530. {
  76531. var action = this.actions[actionname];
  76532. if (action != null)
  76533. {
  76534. try
  76535. {
  76536. // Creates the array of arguments by replacing the actionname
  76537. // with the editor instance in the args of this function
  76538. var args = arguments;
  76539. args[0] = this;
  76540. // Invokes the function on the editor using the args
  76541. action.apply(this, args);
  76542. }
  76543. catch (e)
  76544. {
  76545. mxUtils.error('Cannot execute ' + actionname +
  76546. ': ' + e.message, 280, true);
  76547. throw e;
  76548. }
  76549. }
  76550. else
  76551. {
  76552. mxUtils.error('Cannot find action '+actionname, 280, true);
  76553. }
  76554. };
  76555. /**
  76556. * Function: addTemplate
  76557. *
  76558. * Adds the specified template under the given name in <templates>.
  76559. */
  76560. mxEditor.prototype.addTemplate = function (name, template)
  76561. {
  76562. this.templates[name] = template;
  76563. };
  76564. /**
  76565. * Function: getTemplate
  76566. *
  76567. * Returns the template for the given name.
  76568. */
  76569. mxEditor.prototype.getTemplate = function (name)
  76570. {
  76571. return this.templates[name];
  76572. };
  76573. /**
  76574. * Function: createGraph
  76575. *
  76576. * Creates the <graph> for the editor. The graph is created with no
  76577. * container and is initialized from <setGraphContainer>.
  76578. */
  76579. mxEditor.prototype.createGraph = function ()
  76580. {
  76581. var graph = new mxGraph(null, null, this.graphRenderHint);
  76582. // Enables rubberband, tooltips, panning
  76583. graph.setTooltips(true);
  76584. graph.setPanning(true);
  76585. // Overrides the dblclick method on the graph to
  76586. // invoke the dblClickAction for a cell and reset
  76587. // the selection tool in the toolbar
  76588. this.installDblClickHandler(graph);
  76589. // Installs the command history
  76590. this.installUndoHandler(graph);
  76591. // Installs the handlers for the root event
  76592. this.installDrillHandler(graph);
  76593. // Installs the handler for validation
  76594. this.installChangeHandler(graph);
  76595. // Installs the handler for calling the
  76596. // insert function and consume the
  76597. // event if an insert function is defined
  76598. this.installInsertHandler(graph);
  76599. // Redirects the function for creating the
  76600. // popupmenu items
  76601. graph.popupMenuHandler.factoryMethod =
  76602. mxUtils.bind(this, function(menu, cell, evt)
  76603. {
  76604. return this.createPopupMenu(menu, cell, evt);
  76605. });
  76606. // Redirects the function for creating
  76607. // new connections in the diagram
  76608. graph.connectionHandler.factoryMethod =
  76609. mxUtils.bind(this, function(source, target)
  76610. {
  76611. return this.createEdge(source, target);
  76612. });
  76613. // Maintains swimlanes and installs autolayout
  76614. this.createSwimlaneManager(graph);
  76615. this.createLayoutManager(graph);
  76616. return graph;
  76617. };
  76618. /**
  76619. * Function: createSwimlaneManager
  76620. *
  76621. * Sets the graph's container using <mxGraph.init>.
  76622. */
  76623. mxEditor.prototype.createSwimlaneManager = function (graph)
  76624. {
  76625. var swimlaneMgr = new mxSwimlaneManager(graph, false);
  76626. swimlaneMgr.isHorizontal = mxUtils.bind(this, function()
  76627. {
  76628. return this.horizontalFlow;
  76629. });
  76630. swimlaneMgr.isEnabled = mxUtils.bind(this, function()
  76631. {
  76632. return this.maintainSwimlanes;
  76633. });
  76634. return swimlaneMgr;
  76635. };
  76636. /**
  76637. * Function: createLayoutManager
  76638. *
  76639. * Creates a layout manager for the swimlane and diagram layouts, that
  76640. * is, the locally defined inter- and intraswimlane layouts.
  76641. */
  76642. mxEditor.prototype.createLayoutManager = function (graph)
  76643. {
  76644. var layoutMgr = new mxLayoutManager(graph);
  76645. var self = this; // closure
  76646. layoutMgr.getLayout = function(cell)
  76647. {
  76648. var layout = null;
  76649. var model = self.graph.getModel();
  76650. if (model.getParent(cell) != null)
  76651. {
  76652. // Executes the swimlane layout if a child of
  76653. // a swimlane has been changed. The layout is
  76654. // lazy created in createSwimlaneLayout.
  76655. if (self.layoutSwimlanes &&
  76656. graph.isSwimlane(cell))
  76657. {
  76658. if (self.swimlaneLayout == null)
  76659. {
  76660. self.swimlaneLayout = self.createSwimlaneLayout();
  76661. }
  76662. layout = self.swimlaneLayout;
  76663. }
  76664. // Executes the diagram layout if the modified
  76665. // cell is a top-level cell. The layout is
  76666. // lazy created in createDiagramLayout.
  76667. else if (self.layoutDiagram &&
  76668. (graph.isValidRoot(cell) ||
  76669. model.getParent(model.getParent(cell)) == null))
  76670. {
  76671. if (self.diagramLayout == null)
  76672. {
  76673. self.diagramLayout = self.createDiagramLayout();
  76674. }
  76675. layout = self.diagramLayout;
  76676. }
  76677. }
  76678. return layout;
  76679. };
  76680. return layoutMgr;
  76681. };
  76682. /**
  76683. * Function: setGraphContainer
  76684. *
  76685. * Sets the graph's container using <mxGraph.init>.
  76686. */
  76687. mxEditor.prototype.setGraphContainer = function (container)
  76688. {
  76689. if (this.graph.container == null)
  76690. {
  76691. // Creates the graph instance inside the given container and render hint
  76692. //this.graph = new mxGraph(container, null, this.graphRenderHint);
  76693. this.graph.init(container);
  76694. // Install rubberband selection as the last
  76695. // action handler in the chain
  76696. this.rubberband = new mxRubberband(this.graph);
  76697. // Disables the context menu
  76698. if (this.disableContextMenu)
  76699. {
  76700. mxEvent.disableContextMenu(container);
  76701. }
  76702. // Workaround for stylesheet directives in IE
  76703. if (mxClient.IS_QUIRKS)
  76704. {
  76705. new mxDivResizer(container);
  76706. }
  76707. }
  76708. };
  76709. /**
  76710. * Function: installDblClickHandler
  76711. *
  76712. * Overrides <mxGraph.dblClick> to invoke <dblClickAction>
  76713. * on a cell and reset the selection tool in the toolbar.
  76714. */
  76715. mxEditor.prototype.installDblClickHandler = function (graph)
  76716. {
  76717. // Installs a listener for double click events
  76718. graph.addListener(mxEvent.DOUBLE_CLICK,
  76719. mxUtils.bind(this, function(sender, evt)
  76720. {
  76721. var cell = evt.getProperty('cell');
  76722. if (cell != null &&
  76723. graph.isEnabled() &&
  76724. this.dblClickAction != null)
  76725. {
  76726. this.execute(this.dblClickAction, cell);
  76727. evt.consume();
  76728. }
  76729. })
  76730. );
  76731. };
  76732. /**
  76733. * Function: installUndoHandler
  76734. *
  76735. * Adds the <undoManager> to the graph model and the view.
  76736. */
  76737. mxEditor.prototype.installUndoHandler = function (graph)
  76738. {
  76739. var listener = mxUtils.bind(this, function(sender, evt)
  76740. {
  76741. var edit = evt.getProperty('edit');
  76742. this.undoManager.undoableEditHappened(edit);
  76743. });
  76744. graph.getModel().addListener(mxEvent.UNDO, listener);
  76745. graph.getView().addListener(mxEvent.UNDO, listener);
  76746. // Keeps the selection state in sync
  76747. var undoHandler = function(sender, evt)
  76748. {
  76749. var changes = evt.getProperty('edit').changes;
  76750. graph.setSelectionCells(graph.getSelectionCellsForChanges(changes));
  76751. };
  76752. this.undoManager.addListener(mxEvent.UNDO, undoHandler);
  76753. this.undoManager.addListener(mxEvent.REDO, undoHandler);
  76754. };
  76755. /**
  76756. * Function: installDrillHandler
  76757. *
  76758. * Installs listeners for dispatching the <root> event.
  76759. */
  76760. mxEditor.prototype.installDrillHandler = function (graph)
  76761. {
  76762. var listener = mxUtils.bind(this, function(sender)
  76763. {
  76764. this.fireEvent(new mxEventObject(mxEvent.ROOT));
  76765. });
  76766. graph.getView().addListener(mxEvent.DOWN, listener);
  76767. graph.getView().addListener(mxEvent.UP, listener);
  76768. };
  76769. /**
  76770. * Function: installChangeHandler
  76771. *
  76772. * Installs the listeners required to automatically validate
  76773. * the graph. On each change of the root, this implementation
  76774. * fires a <root> event.
  76775. */
  76776. mxEditor.prototype.installChangeHandler = function (graph)
  76777. {
  76778. var listener = mxUtils.bind(this, function(sender, evt)
  76779. {
  76780. // Updates the modified state
  76781. this.setModified(true);
  76782. // Automatically validates the graph
  76783. // after each change
  76784. if (this.validating == true)
  76785. {
  76786. graph.validateGraph();
  76787. }
  76788. // Checks if the root has been changed
  76789. var changes = evt.getProperty('edit').changes;
  76790. for (var i = 0; i < changes.length; i++)
  76791. {
  76792. var change = changes[i];
  76793. if (change instanceof mxRootChange ||
  76794. (change instanceof mxValueChange &&
  76795. change.cell == this.graph.model.root) ||
  76796. (change instanceof mxCellAttributeChange &&
  76797. change.cell == this.graph.model.root))
  76798. {
  76799. this.fireEvent(new mxEventObject(mxEvent.ROOT));
  76800. break;
  76801. }
  76802. }
  76803. });
  76804. graph.getModel().addListener(mxEvent.CHANGE, listener);
  76805. };
  76806. /**
  76807. * Function: installInsertHandler
  76808. *
  76809. * Installs the handler for invoking <insertFunction> if
  76810. * one is defined.
  76811. */
  76812. mxEditor.prototype.installInsertHandler = function (graph)
  76813. {
  76814. var self = this; // closure
  76815. var insertHandler =
  76816. {
  76817. mouseDown: function(sender, me)
  76818. {
  76819. if (self.insertFunction != null &&
  76820. !me.isPopupTrigger() &&
  76821. (self.forcedInserting ||
  76822. me.getState() == null))
  76823. {
  76824. self.graph.clearSelection();
  76825. self.insertFunction(me.getEvent(), me.getCell());
  76826. // Consumes the rest of the events
  76827. // for this gesture (down, move, up)
  76828. this.isActive = true;
  76829. me.consume();
  76830. }
  76831. },
  76832. mouseMove: function(sender, me)
  76833. {
  76834. if (this.isActive)
  76835. {
  76836. me.consume();
  76837. }
  76838. },
  76839. mouseUp: function(sender, me)
  76840. {
  76841. if (this.isActive)
  76842. {
  76843. this.isActive = false;
  76844. me.consume();
  76845. }
  76846. }
  76847. };
  76848. graph.addMouseListener(insertHandler);
  76849. };
  76850. /**
  76851. * Function: createDiagramLayout
  76852. *
  76853. * Creates the layout instance used to layout the
  76854. * swimlanes in the diagram.
  76855. */
  76856. mxEditor.prototype.createDiagramLayout = function ()
  76857. {
  76858. var gs = this.graph.gridSize;
  76859. var layout = new mxStackLayout(this.graph, !this.horizontalFlow,
  76860. this.swimlaneSpacing, 2*gs, 2*gs);
  76861. // Overrides isIgnored to only take into account swimlanes
  76862. layout.isVertexIgnored = function(cell)
  76863. {
  76864. return !layout.graph.isSwimlane(cell);
  76865. };
  76866. return layout;
  76867. };
  76868. /**
  76869. * Function: createSwimlaneLayout
  76870. *
  76871. * Creates the layout instance used to layout the
  76872. * children of each swimlane.
  76873. */
  76874. mxEditor.prototype.createSwimlaneLayout = function ()
  76875. {
  76876. return new mxCompactTreeLayout(this.graph, this.horizontalFlow);
  76877. };
  76878. /**
  76879. * Function: createToolbar
  76880. *
  76881. * Creates the <toolbar> with no container.
  76882. */
  76883. mxEditor.prototype.createToolbar = function ()
  76884. {
  76885. return new mxDefaultToolbar(null, this);
  76886. };
  76887. /**
  76888. * Function: setToolbarContainer
  76889. *
  76890. * Initializes the toolbar for the given container.
  76891. */
  76892. mxEditor.prototype.setToolbarContainer = function (container)
  76893. {
  76894. this.toolbar.init(container);
  76895. // Workaround for stylesheet directives in IE
  76896. if (mxClient.IS_QUIRKS)
  76897. {
  76898. new mxDivResizer(container);
  76899. }
  76900. };
  76901. /**
  76902. * Function: setStatusContainer
  76903. *
  76904. * Creates the <status> using the specified container.
  76905. *
  76906. * This implementation adds listeners in the editor to
  76907. * display the last saved time and the current filename
  76908. * in the status bar.
  76909. *
  76910. * Parameters:
  76911. *
  76912. * container - DOM node that will contain the statusbar.
  76913. */
  76914. mxEditor.prototype.setStatusContainer = function (container)
  76915. {
  76916. if (this.status == null)
  76917. {
  76918. this.status = container;
  76919. // Prints the last saved time in the status bar
  76920. // when files are saved
  76921. this.addListener(mxEvent.SAVE, mxUtils.bind(this, function()
  76922. {
  76923. var tstamp = new Date().toLocaleString();
  76924. this.setStatus((mxResources.get(this.lastSavedResource) ||
  76925. this.lastSavedResource)+': '+tstamp);
  76926. }));
  76927. // Updates the statusbar to display the filename
  76928. // when new files are opened
  76929. this.addListener(mxEvent.OPEN, mxUtils.bind(this, function()
  76930. {
  76931. this.setStatus((mxResources.get(this.currentFileResource) ||
  76932. this.currentFileResource)+': '+this.filename);
  76933. }));
  76934. // Workaround for stylesheet directives in IE
  76935. if (mxClient.IS_QUIRKS)
  76936. {
  76937. new mxDivResizer(container);
  76938. }
  76939. }
  76940. };
  76941. /**
  76942. * Function: setStatus
  76943. *
  76944. * Display the specified message in the status bar.
  76945. *
  76946. * Parameters:
  76947. *
  76948. * message - String the specified the message to
  76949. * be displayed.
  76950. */
  76951. mxEditor.prototype.setStatus = function (message)
  76952. {
  76953. if (this.status != null && message != null)
  76954. {
  76955. this.status.innerHTML = message;
  76956. }
  76957. };
  76958. /**
  76959. * Function: setTitleContainer
  76960. *
  76961. * Creates a listener to update the inner HTML of the
  76962. * specified DOM node with the value of <getTitle>.
  76963. *
  76964. * Parameters:
  76965. *
  76966. * container - DOM node that will contain the title.
  76967. */
  76968. mxEditor.prototype.setTitleContainer = function (container)
  76969. {
  76970. this.addListener(mxEvent.ROOT, mxUtils.bind(this, function(sender)
  76971. {
  76972. container.innerHTML = this.getTitle();
  76973. }));
  76974. // Workaround for stylesheet directives in IE
  76975. if (mxClient.IS_QUIRKS)
  76976. {
  76977. new mxDivResizer(container);
  76978. }
  76979. };
  76980. /**
  76981. * Function: treeLayout
  76982. *
  76983. * Executes a vertical or horizontal compact tree layout
  76984. * using the specified cell as an argument. The cell may
  76985. * either be a group or the root of a tree.
  76986. *
  76987. * Parameters:
  76988. *
  76989. * cell - <mxCell> to use in the compact tree layout.
  76990. * horizontal - Optional boolean to specify the tree's
  76991. * orientation. Default is true.
  76992. */
  76993. mxEditor.prototype.treeLayout = function (cell, horizontal)
  76994. {
  76995. if (cell != null)
  76996. {
  76997. var layout = new mxCompactTreeLayout(this.graph, horizontal);
  76998. layout.execute(cell);
  76999. }
  77000. };
  77001. /**
  77002. * Function: getTitle
  77003. *
  77004. * Returns the string value for the current root of the
  77005. * diagram.
  77006. */
  77007. mxEditor.prototype.getTitle = function ()
  77008. {
  77009. var title = '';
  77010. var graph = this.graph;
  77011. var cell = graph.getCurrentRoot();
  77012. while (cell != null &&
  77013. graph.getModel().getParent(
  77014. graph.getModel().getParent(cell)) != null)
  77015. {
  77016. // Append each label of a valid root
  77017. if (graph.isValidRoot(cell))
  77018. {
  77019. title = ' > ' +
  77020. graph.convertValueToString(cell) + title;
  77021. }
  77022. cell = graph.getModel().getParent(cell);
  77023. }
  77024. var prefix = this.getRootTitle();
  77025. return prefix + title;
  77026. };
  77027. /**
  77028. * Function: getRootTitle
  77029. *
  77030. * Returns the string value of the root cell in
  77031. * <mxGraph.model>.
  77032. */
  77033. mxEditor.prototype.getRootTitle = function ()
  77034. {
  77035. var root = this.graph.getModel().getRoot();
  77036. return this.graph.convertValueToString(root);
  77037. };
  77038. /**
  77039. * Function: undo
  77040. *
  77041. * Undo the last change in <graph>.
  77042. */
  77043. mxEditor.prototype.undo = function ()
  77044. {
  77045. this.undoManager.undo();
  77046. };
  77047. /**
  77048. * Function: redo
  77049. *
  77050. * Redo the last change in <graph>.
  77051. */
  77052. mxEditor.prototype.redo = function ()
  77053. {
  77054. this.undoManager.redo();
  77055. };
  77056. /**
  77057. * Function: groupCells
  77058. *
  77059. * Invokes <createGroup> to create a new group cell and the invokes
  77060. * <mxGraph.groupCells>, using the grid size of the graph as the spacing
  77061. * in the group's content area.
  77062. */
  77063. mxEditor.prototype.groupCells = function ()
  77064. {
  77065. var border = (this.groupBorderSize != null) ?
  77066. this.groupBorderSize :
  77067. this.graph.gridSize;
  77068. return this.graph.groupCells(this.createGroup(), border);
  77069. };
  77070. /**
  77071. * Function: createGroup
  77072. *
  77073. * Creates and returns a clone of <defaultGroup> to be used
  77074. * as a new group cell in <group>.
  77075. */
  77076. mxEditor.prototype.createGroup = function ()
  77077. {
  77078. var model = this.graph.getModel();
  77079. return model.cloneCell(this.defaultGroup);
  77080. };
  77081. /**
  77082. * Function: open
  77083. *
  77084. * Opens the specified file synchronously and parses it using
  77085. * <readGraphModel>. It updates <filename> and fires an <open>-event after
  77086. * the file has been opened. Exceptions should be handled as follows:
  77087. *
  77088. * (code)
  77089. * try
  77090. * {
  77091. * editor.open(filename);
  77092. * }
  77093. * catch (e)
  77094. * {
  77095. * mxUtils.error('Cannot open ' + filename +
  77096. * ': ' + e.message, 280, true);
  77097. * }
  77098. * (end)
  77099. *
  77100. * Parameters:
  77101. *
  77102. * filename - URL of the file to be opened.
  77103. */
  77104. mxEditor.prototype.open = function (filename)
  77105. {
  77106. if (filename != null)
  77107. {
  77108. var xml = mxUtils.load(filename).getXml();
  77109. this.readGraphModel(xml.documentElement);
  77110. this.filename = filename;
  77111. this.fireEvent(new mxEventObject(mxEvent.OPEN, 'filename', filename));
  77112. }
  77113. };
  77114. /**
  77115. * Function: readGraphModel
  77116. *
  77117. * Reads the specified XML node into the existing graph model and resets
  77118. * the command history and modified state.
  77119. */
  77120. mxEditor.prototype.readGraphModel = function (node)
  77121. {
  77122. var dec = new mxCodec(node.ownerDocument);
  77123. dec.decode(node, this.graph.getModel());
  77124. this.resetHistory();
  77125. };
  77126. /**
  77127. * Function: save
  77128. *
  77129. * Posts the string returned by <writeGraphModel> to the given URL or the
  77130. * URL returned by <getUrlPost>. The actual posting is carried out by
  77131. * <postDiagram>. If the URL is null then the resulting XML will be
  77132. * displayed using <mxUtils.popup>. Exceptions should be handled as
  77133. * follows:
  77134. *
  77135. * (code)
  77136. * try
  77137. * {
  77138. * editor.save();
  77139. * }
  77140. * catch (e)
  77141. * {
  77142. * mxUtils.error('Cannot save : ' + e.message, 280, true);
  77143. * }
  77144. * (end)
  77145. */
  77146. mxEditor.prototype.save = function (url, linefeed)
  77147. {
  77148. // Gets the URL to post the data to
  77149. url = url || this.getUrlPost();
  77150. // Posts the data if the URL is not empty
  77151. if (url != null && url.length > 0)
  77152. {
  77153. var data = this.writeGraphModel(linefeed);
  77154. this.postDiagram(url, data);
  77155. // Resets the modified flag
  77156. this.setModified(false);
  77157. }
  77158. // Dispatches a save event
  77159. this.fireEvent(new mxEventObject(mxEvent.SAVE, 'url', url));
  77160. };
  77161. /**
  77162. * Function: postDiagram
  77163. *
  77164. * Hook for subclassers to override the posting of a diagram
  77165. * represented by the given node to the given URL. This fires
  77166. * an asynchronous <post> event if the diagram has been posted.
  77167. *
  77168. * Example:
  77169. *
  77170. * To replace the diagram with the diagram in the response, use the
  77171. * following code.
  77172. *
  77173. * (code)
  77174. * editor.addListener(mxEvent.POST, function(sender, evt)
  77175. * {
  77176. * // Process response (replace diagram)
  77177. * var req = evt.getProperty('request');
  77178. * var root = req.getDocumentElement();
  77179. * editor.graph.readGraphModel(root)
  77180. * });
  77181. * (end)
  77182. */
  77183. mxEditor.prototype.postDiagram = function (url, data)
  77184. {
  77185. if (this.escapePostData)
  77186. {
  77187. data = encodeURIComponent(data);
  77188. }
  77189. mxUtils.post(url, this.postParameterName+'='+data,
  77190. mxUtils.bind(this, function(req)
  77191. {
  77192. this.fireEvent(new mxEventObject(mxEvent.POST,
  77193. 'request', req, 'url', url, 'data', data));
  77194. })
  77195. );
  77196. };
  77197. /**
  77198. * Function: writeGraphModel
  77199. *
  77200. * Hook to create the string representation of the diagram. The default
  77201. * implementation uses an <mxCodec> to encode the graph model as
  77202. * follows:
  77203. *
  77204. * (code)
  77205. * var enc = new mxCodec();
  77206. * var node = enc.encode(this.graph.getModel());
  77207. * return mxUtils.getXml(node, this.linefeed);
  77208. * (end)
  77209. *
  77210. * Parameters:
  77211. *
  77212. * linefeed - Optional character to be used as the linefeed. Default is
  77213. * <linefeed>.
  77214. */
  77215. mxEditor.prototype.writeGraphModel = function (linefeed)
  77216. {
  77217. linefeed = (linefeed != null) ? linefeed : this.linefeed;
  77218. var enc = new mxCodec();
  77219. var node = enc.encode(this.graph.getModel());
  77220. return mxUtils.getXml(node, linefeed);
  77221. };
  77222. /**
  77223. * Function: getUrlPost
  77224. *
  77225. * Returns the URL to post the diagram to. This is used
  77226. * in <save>. The default implementation returns <urlPost>,
  77227. * adding <code>?draft=true</code>.
  77228. */
  77229. mxEditor.prototype.getUrlPost = function ()
  77230. {
  77231. return this.urlPost;
  77232. };
  77233. /**
  77234. * Function: getUrlImage
  77235. *
  77236. * Returns the URL to create the image with. This is typically
  77237. * the URL of a backend which accepts an XML representation
  77238. * of a graph view to create an image. The function is used
  77239. * in the image action to create an image. This implementation
  77240. * returns <urlImage>.
  77241. */
  77242. mxEditor.prototype.getUrlImage = function ()
  77243. {
  77244. return this.urlImage;
  77245. };
  77246. /**
  77247. * Function: swapStyles
  77248. *
  77249. * Swaps the styles for the given names in the graph's
  77250. * stylesheet and refreshes the graph.
  77251. */
  77252. mxEditor.prototype.swapStyles = function (first, second)
  77253. {
  77254. var style = this.graph.getStylesheet().styles[second];
  77255. this.graph.getView().getStylesheet().putCellStyle(
  77256. second, this.graph.getStylesheet().styles[first]);
  77257. this.graph.getStylesheet().putCellStyle(first, style);
  77258. this.graph.refresh();
  77259. };
  77260. /**
  77261. * Function: showProperties
  77262. *
  77263. * Creates and shows the properties dialog for the given
  77264. * cell. The content area of the dialog is created using
  77265. * <createProperties>.
  77266. */
  77267. mxEditor.prototype.showProperties = function (cell)
  77268. {
  77269. cell = cell || this.graph.getSelectionCell();
  77270. // Uses the root node for the properties dialog
  77271. // if not cell was passed in and no cell is
  77272. // selected
  77273. if (cell == null)
  77274. {
  77275. cell = this.graph.getCurrentRoot();
  77276. if (cell == null)
  77277. {
  77278. cell = this.graph.getModel().getRoot();
  77279. }
  77280. }
  77281. if (cell != null)
  77282. {
  77283. // Makes sure there is no in-place editor in the
  77284. // graph and computes the location of the dialog
  77285. this.graph.stopEditing(true);
  77286. var offset = mxUtils.getOffset(this.graph.container);
  77287. var x = offset.x+10;
  77288. var y = offset.y;
  77289. // Avoids moving the dialog if it is alredy open
  77290. if (this.properties != null && !this.movePropertiesDialog)
  77291. {
  77292. x = this.properties.getX();
  77293. y = this.properties.getY();
  77294. }
  77295. // Places the dialog near the cell for which it
  77296. // displays the properties
  77297. else
  77298. {
  77299. var bounds = this.graph.getCellBounds(cell);
  77300. if (bounds != null)
  77301. {
  77302. x += bounds.x+Math.min(200, bounds.width);
  77303. y += bounds.y;
  77304. }
  77305. }
  77306. // Hides the existing properties dialog and creates a new one with the
  77307. // contents created in the hook method
  77308. this.hideProperties();
  77309. var node = this.createProperties(cell);
  77310. if (node != null)
  77311. {
  77312. // Displays the contents in a window and stores a reference to the
  77313. // window for later hiding of the window
  77314. this.properties = new mxWindow(mxResources.get(this.propertiesResource) ||
  77315. this.propertiesResource, node, x, y, this.propertiesWidth, this.propertiesHeight, false);
  77316. this.properties.setVisible(true);
  77317. }
  77318. }
  77319. };
  77320. /**
  77321. * Function: isPropertiesVisible
  77322. *
  77323. * Returns true if the properties dialog is currently visible.
  77324. */
  77325. mxEditor.prototype.isPropertiesVisible = function ()
  77326. {
  77327. return this.properties != null;
  77328. };
  77329. /**
  77330. * Function: createProperties
  77331. *
  77332. * Creates and returns the DOM node that represents the contents
  77333. * of the properties dialog for the given cell. This implementation
  77334. * works for user objects that are XML nodes and display all the
  77335. * node attributes in a form.
  77336. */
  77337. mxEditor.prototype.createProperties = function (cell)
  77338. {
  77339. var model = this.graph.getModel();
  77340. var value = model.getValue(cell);
  77341. if (mxUtils.isNode(value))
  77342. {
  77343. // Creates a form for the user object inside
  77344. // the cell
  77345. var form = new mxForm('properties');
  77346. // Adds a readonly field for the cell id
  77347. var id = form.addText('ID', cell.getId());
  77348. id.setAttribute('readonly', 'true');
  77349. var geo = null;
  77350. var yField = null;
  77351. var xField = null;
  77352. var widthField = null;
  77353. var heightField = null;
  77354. // Adds fields for the location and size
  77355. if (model.isVertex(cell))
  77356. {
  77357. geo = model.getGeometry(cell);
  77358. if (geo != null)
  77359. {
  77360. yField = form.addText('top', geo.y);
  77361. xField = form.addText('left', geo.x);
  77362. widthField = form.addText('width', geo.width);
  77363. heightField = form.addText('height', geo.height);
  77364. }
  77365. }
  77366. // Adds a field for the cell style
  77367. var tmp = model.getStyle(cell);
  77368. var style = form.addText('Style', tmp || '');
  77369. // Creates textareas for each attribute of the
  77370. // user object within the cell
  77371. var attrs = value.attributes;
  77372. var texts = [];
  77373. for (var i = 0; i < attrs.length; i++)
  77374. {
  77375. // Creates a textarea with more lines for
  77376. // the cell label
  77377. var val = attrs[i].value;
  77378. texts[i] = form.addTextarea(attrs[i].nodeName, val,
  77379. (attrs[i].nodeName == 'label') ? 4 : 2);
  77380. }
  77381. // Adds an OK and Cancel button to the dialog
  77382. // contents and implements the respective
  77383. // actions below
  77384. // Defines the function to be executed when the
  77385. // OK button is pressed in the dialog
  77386. var okFunction = mxUtils.bind(this, function()
  77387. {
  77388. // Hides the dialog
  77389. this.hideProperties();
  77390. // Supports undo for the changes on the underlying
  77391. // XML structure / XML node attribute changes.
  77392. model.beginUpdate();
  77393. try
  77394. {
  77395. if (geo != null)
  77396. {
  77397. geo = geo.clone();
  77398. geo.x = parseFloat(xField.value);
  77399. geo.y = parseFloat(yField.value);
  77400. geo.width = parseFloat(widthField.value);
  77401. geo.height = parseFloat(heightField.value);
  77402. model.setGeometry(cell, geo);
  77403. }
  77404. // Applies the style
  77405. if (style.value.length > 0)
  77406. {
  77407. model.setStyle(cell, style.value);
  77408. }
  77409. else
  77410. {
  77411. model.setStyle(cell, null);
  77412. }
  77413. // Creates an undoable change for each
  77414. // attribute and executes it using the
  77415. // model, which will also make the change
  77416. // part of the current transaction
  77417. for (var i=0; i<attrs.length; i++)
  77418. {
  77419. var edit = new mxCellAttributeChange(
  77420. cell, attrs[i].nodeName,
  77421. texts[i].value);
  77422. model.execute(edit);
  77423. }
  77424. // Checks if the graph wants cells to
  77425. // be automatically sized and updates
  77426. // the size as an undoable step if
  77427. // the feature is enabled
  77428. if (this.graph.isAutoSizeCell(cell))
  77429. {
  77430. this.graph.updateCellSize(cell);
  77431. }
  77432. }
  77433. finally
  77434. {
  77435. model.endUpdate();
  77436. }
  77437. });
  77438. // Defines the function to be executed when the
  77439. // Cancel button is pressed in the dialog
  77440. var cancelFunction = mxUtils.bind(this, function()
  77441. {
  77442. // Hides the dialog
  77443. this.hideProperties();
  77444. });
  77445. form.addButtons(okFunction, cancelFunction);
  77446. return form.table;
  77447. }
  77448. return null;
  77449. };
  77450. /**
  77451. * Function: hideProperties
  77452. *
  77453. * Hides the properties dialog.
  77454. */
  77455. mxEditor.prototype.hideProperties = function ()
  77456. {
  77457. if (this.properties != null)
  77458. {
  77459. this.properties.destroy();
  77460. this.properties = null;
  77461. }
  77462. };
  77463. /**
  77464. * Function: showTasks
  77465. *
  77466. * Shows the tasks window. The tasks window is created using <createTasks>. The
  77467. * default width of the window is 200 pixels, the y-coordinate of the location
  77468. * can be specifies in <tasksTop> and the x-coordinate is right aligned with a
  77469. * 20 pixel offset from the right border. To change the location of the tasks
  77470. * window, the following code can be used:
  77471. *
  77472. * (code)
  77473. * var oldShowTasks = mxEditor.prototype.showTasks;
  77474. * mxEditor.prototype.showTasks = function()
  77475. * {
  77476. * oldShowTasks.apply(this, arguments); // "supercall"
  77477. *
  77478. * if (this.tasks != null)
  77479. * {
  77480. * this.tasks.setLocation(10, 10);
  77481. * }
  77482. * };
  77483. * (end)
  77484. */
  77485. mxEditor.prototype.showTasks = function ()
  77486. {
  77487. if (this.tasks == null)
  77488. {
  77489. var div = document.createElement('div');
  77490. div.style.padding = '4px';
  77491. div.style.paddingLeft = '20px';
  77492. var w = document.body.clientWidth;
  77493. var wnd = new mxWindow(
  77494. mxResources.get(this.tasksResource) ||
  77495. this.tasksResource,
  77496. div, w - 220, this.tasksTop, 200);
  77497. wnd.setClosable(true);
  77498. wnd.destroyOnClose = false;
  77499. // Installs a function to update the contents
  77500. // of the tasks window on every change of the
  77501. // model, selection or root.
  77502. var funct = mxUtils.bind(this, function(sender)
  77503. {
  77504. mxEvent.release(div);
  77505. div.innerHTML = '';
  77506. this.createTasks(div);
  77507. });
  77508. this.graph.getModel().addListener(mxEvent.CHANGE, funct);
  77509. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, funct);
  77510. this.graph.addListener(mxEvent.ROOT, funct);
  77511. // Assigns the icon to the tasks window
  77512. if (this.tasksWindowImage != null)
  77513. {
  77514. wnd.setImage(this.tasksWindowImage);
  77515. }
  77516. this.tasks = wnd;
  77517. this.createTasks(div);
  77518. }
  77519. this.tasks.setVisible(true);
  77520. };
  77521. /**
  77522. * Function: refreshTasks
  77523. *
  77524. * Updates the contents of the tasks window using <createTasks>.
  77525. */
  77526. mxEditor.prototype.refreshTasks = function (div)
  77527. {
  77528. if (this.tasks != null)
  77529. {
  77530. var div = this.tasks.content;
  77531. mxEvent.release(div);
  77532. div.innerHTML = '';
  77533. this.createTasks(div);
  77534. }
  77535. };
  77536. /**
  77537. * Function: createTasks
  77538. *
  77539. * Updates the contents of the given DOM node to
  77540. * display the tasks associated with the current
  77541. * editor state. This is invoked whenever there
  77542. * is a possible change of state in the editor.
  77543. * Default implementation is empty.
  77544. */
  77545. mxEditor.prototype.createTasks = function (div)
  77546. {
  77547. // override
  77548. };
  77549. /**
  77550. * Function: showHelp
  77551. *
  77552. * Shows the help window. If the help window does not exist
  77553. * then it is created using an iframe pointing to the resource
  77554. * for the <code>urlHelp</code> key or <urlHelp> if the resource
  77555. * is undefined.
  77556. */
  77557. mxEditor.prototype.showHelp = function (tasks)
  77558. {
  77559. if (this.help == null)
  77560. {
  77561. var frame = document.createElement('iframe');
  77562. frame.setAttribute('src', mxResources.get('urlHelp') || this.urlHelp);
  77563. frame.setAttribute('height', '100%');
  77564. frame.setAttribute('width', '100%');
  77565. frame.setAttribute('frameBorder', '0');
  77566. frame.style.backgroundColor = 'white';
  77567. var w = document.body.clientWidth;
  77568. var h = (document.body.clientHeight || document.documentElement.clientHeight);
  77569. var wnd = new mxWindow(mxResources.get(this.helpResource) || this.helpResource,
  77570. frame, (w-this.helpWidth)/2, (h-this.helpHeight)/3, this.helpWidth, this.helpHeight);
  77571. wnd.setMaximizable(true);
  77572. wnd.setClosable(true);
  77573. wnd.destroyOnClose = false;
  77574. wnd.setResizable(true);
  77575. // Assigns the icon to the help window
  77576. if (this.helpWindowImage != null)
  77577. {
  77578. wnd.setImage(this.helpWindowImage);
  77579. }
  77580. // Workaround for ignored iframe height 100% in FF
  77581. if (mxClient.IS_NS)
  77582. {
  77583. var handler = function(sender)
  77584. {
  77585. var h = wnd.div.offsetHeight;
  77586. frame.setAttribute('height', (h-26)+'px');
  77587. };
  77588. wnd.addListener(mxEvent.RESIZE_END, handler);
  77589. wnd.addListener(mxEvent.MAXIMIZE, handler);
  77590. wnd.addListener(mxEvent.NORMALIZE, handler);
  77591. wnd.addListener(mxEvent.SHOW, handler);
  77592. }
  77593. this.help = wnd;
  77594. }
  77595. this.help.setVisible(true);
  77596. };
  77597. /**
  77598. * Function: showOutline
  77599. *
  77600. * Shows the outline window. If the window does not exist, then it is
  77601. * created using an <mxOutline>.
  77602. */
  77603. mxEditor.prototype.showOutline = function ()
  77604. {
  77605. var create = this.outline == null;
  77606. if (create)
  77607. {
  77608. var div = document.createElement('div');
  77609. div.style.overflow = 'hidden';
  77610. div.style.position = 'relative';
  77611. div.style.width = '100%';
  77612. div.style.height = '100%';
  77613. div.style.background = 'white';
  77614. div.style.cursor = 'move';
  77615. if (document.documentMode == 8)
  77616. {
  77617. div.style.filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=100)';
  77618. }
  77619. var wnd = new mxWindow(
  77620. mxResources.get(this.outlineResource) ||
  77621. this.outlineResource,
  77622. div, 600, 480, 200, 200, false);
  77623. // Creates the outline in the specified div
  77624. // and links it to the existing graph
  77625. var outline = new mxOutline(this.graph, div);
  77626. wnd.setClosable(true);
  77627. wnd.setResizable(true);
  77628. wnd.destroyOnClose = false;
  77629. wnd.addListener(mxEvent.RESIZE_END, function()
  77630. {
  77631. outline.update();
  77632. });
  77633. this.outline = wnd;
  77634. this.outline.outline = outline;
  77635. }
  77636. // Finally shows the outline
  77637. this.outline.setVisible(true);
  77638. this.outline.outline.update(true);
  77639. };
  77640. /**
  77641. * Function: setMode
  77642. *
  77643. * Puts the graph into the specified mode. The following modenames are
  77644. * supported:
  77645. *
  77646. * select - Selects using the left mouse button, new connections
  77647. * are disabled.
  77648. * connect - Selects using the left mouse button or creates new
  77649. * connections if mouse over cell hotspot. See <mxConnectionHandler>.
  77650. * pan - Pans using the left mouse button, new connections are disabled.
  77651. */
  77652. mxEditor.prototype.setMode = function(modename)
  77653. {
  77654. if (modename == 'select')
  77655. {
  77656. this.graph.panningHandler.useLeftButtonForPanning = false;
  77657. this.graph.setConnectable(false);
  77658. }
  77659. else if (modename == 'connect')
  77660. {
  77661. this.graph.panningHandler.useLeftButtonForPanning = false;
  77662. this.graph.setConnectable(true);
  77663. }
  77664. else if (modename == 'pan')
  77665. {
  77666. this.graph.panningHandler.useLeftButtonForPanning = true;
  77667. this.graph.setConnectable(false);
  77668. }
  77669. };
  77670. /**
  77671. * Function: createPopupMenu
  77672. *
  77673. * Uses <popupHandler> to create the menu in the graph's
  77674. * panning handler. The redirection is setup in
  77675. * <setToolbarContainer>.
  77676. */
  77677. mxEditor.prototype.createPopupMenu = function (menu, cell, evt)
  77678. {
  77679. this.popupHandler.createMenu(this, menu, cell, evt);
  77680. };
  77681. /**
  77682. * Function: createEdge
  77683. *
  77684. * Uses <defaultEdge> as the prototype for creating new edges
  77685. * in the connection handler of the graph. The style of the
  77686. * edge will be overridden with the value returned by
  77687. * <getEdgeStyle>.
  77688. */
  77689. mxEditor.prototype.createEdge = function (source, target)
  77690. {
  77691. // Clones the defaultedge prototype
  77692. var e = null;
  77693. if (this.defaultEdge != null)
  77694. {
  77695. var model = this.graph.getModel();
  77696. e = model.cloneCell(this.defaultEdge);
  77697. }
  77698. else
  77699. {
  77700. e = new mxCell('');
  77701. e.setEdge(true);
  77702. var geo = new mxGeometry();
  77703. geo.relative = true;
  77704. e.setGeometry(geo);
  77705. }
  77706. // Overrides the edge style
  77707. var style = this.getEdgeStyle();
  77708. if (style != null)
  77709. {
  77710. e.setStyle(style);
  77711. }
  77712. return e;
  77713. };
  77714. /**
  77715. * Function: getEdgeStyle
  77716. *
  77717. * Returns a string identifying the style of new edges.
  77718. * The function is used in <createEdge> when new edges
  77719. * are created in the graph.
  77720. */
  77721. mxEditor.prototype.getEdgeStyle = function ()
  77722. {
  77723. return this.defaultEdgeStyle;
  77724. };
  77725. /**
  77726. * Function: consumeCycleAttribute
  77727. *
  77728. * Returns the next attribute in <cycleAttributeValues>
  77729. * or null, if not attribute should be used in the
  77730. * specified cell.
  77731. */
  77732. mxEditor.prototype.consumeCycleAttribute = function (cell)
  77733. {
  77734. return (this.cycleAttributeValues != null &&
  77735. this.cycleAttributeValues.length > 0 &&
  77736. this.graph.isSwimlane(cell)) ?
  77737. this.cycleAttributeValues[this.cycleAttributeIndex++ %
  77738. this.cycleAttributeValues.length] : null;
  77739. };
  77740. /**
  77741. * Function: cycleAttribute
  77742. *
  77743. * Uses the returned value from <consumeCycleAttribute>
  77744. * as the value for the <cycleAttributeName> key in
  77745. * the given cell's style.
  77746. */
  77747. mxEditor.prototype.cycleAttribute = function (cell)
  77748. {
  77749. if (this.cycleAttributeName != null)
  77750. {
  77751. var value = this.consumeCycleAttribute(cell);
  77752. if (value != null)
  77753. {
  77754. cell.setStyle(cell.getStyle()+';'+
  77755. this.cycleAttributeName+'='+value);
  77756. }
  77757. }
  77758. };
  77759. /**
  77760. * Function: addVertex
  77761. *
  77762. * Adds the given vertex as a child of parent at the specified
  77763. * x and y coordinate and fires an <addVertex> event.
  77764. */
  77765. mxEditor.prototype.addVertex = function (parent, vertex, x, y)
  77766. {
  77767. var model = this.graph.getModel();
  77768. while (parent != null && !this.graph.isValidDropTarget(parent))
  77769. {
  77770. parent = model.getParent(parent);
  77771. }
  77772. parent = (parent != null) ? parent : this.graph.getSwimlaneAt(x, y);
  77773. var scale = this.graph.getView().scale;
  77774. var geo = model.getGeometry(vertex);
  77775. var pgeo = model.getGeometry(parent);
  77776. if (this.graph.isSwimlane(vertex) &&
  77777. !this.graph.swimlaneNesting)
  77778. {
  77779. parent = null;
  77780. }
  77781. else if (parent == null && this.swimlaneRequired)
  77782. {
  77783. return null;
  77784. }
  77785. else if (parent != null && pgeo != null)
  77786. {
  77787. // Keeps vertex inside parent
  77788. var state = this.graph.getView().getState(parent);
  77789. if (state != null)
  77790. {
  77791. x -= state.origin.x * scale;
  77792. y -= state.origin.y * scale;
  77793. if (this.graph.isConstrainedMoving)
  77794. {
  77795. var width = geo.width;
  77796. var height = geo.height;
  77797. var tmp = state.x+state.width;
  77798. if (x+width > tmp)
  77799. {
  77800. x -= x+width - tmp;
  77801. }
  77802. tmp = state.y+state.height;
  77803. if (y+height > tmp)
  77804. {
  77805. y -= y+height - tmp;
  77806. }
  77807. }
  77808. }
  77809. else if (pgeo != null)
  77810. {
  77811. x -= pgeo.x*scale;
  77812. y -= pgeo.y*scale;
  77813. }
  77814. }
  77815. geo = geo.clone();
  77816. geo.x = this.graph.snap(x / scale -
  77817. this.graph.getView().translate.x -
  77818. this.graph.gridSize/2);
  77819. geo.y = this.graph.snap(y / scale -
  77820. this.graph.getView().translate.y -
  77821. this.graph.gridSize/2);
  77822. vertex.setGeometry(geo);
  77823. if (parent == null)
  77824. {
  77825. parent = this.graph.getDefaultParent();
  77826. }
  77827. this.cycleAttribute(vertex);
  77828. this.fireEvent(new mxEventObject(mxEvent.BEFORE_ADD_VERTEX,
  77829. 'vertex', vertex, 'parent', parent));
  77830. model.beginUpdate();
  77831. try
  77832. {
  77833. vertex = this.graph.addCell(vertex, parent);
  77834. if (vertex != null)
  77835. {
  77836. this.graph.constrainChild(vertex);
  77837. this.fireEvent(new mxEventObject(mxEvent.ADD_VERTEX, 'vertex', vertex));
  77838. }
  77839. }
  77840. finally
  77841. {
  77842. model.endUpdate();
  77843. }
  77844. if (vertex != null)
  77845. {
  77846. this.graph.setSelectionCell(vertex);
  77847. this.graph.scrollCellToVisible(vertex);
  77848. this.fireEvent(new mxEventObject(mxEvent.AFTER_ADD_VERTEX, 'vertex', vertex));
  77849. }
  77850. return vertex;
  77851. };
  77852. /**
  77853. * Function: destroy
  77854. *
  77855. * Removes the editor and all its associated resources. This does not
  77856. * normally need to be called, it is called automatically when the window
  77857. * unloads.
  77858. */
  77859. mxEditor.prototype.destroy = function ()
  77860. {
  77861. if (!this.destroyed)
  77862. {
  77863. this.destroyed = true;
  77864. if (this.tasks != null)
  77865. {
  77866. this.tasks.destroy();
  77867. }
  77868. if (this.outline != null)
  77869. {
  77870. this.outline.destroy();
  77871. }
  77872. if (this.properties != null)
  77873. {
  77874. this.properties.destroy();
  77875. }
  77876. if (this.keyHandler != null)
  77877. {
  77878. this.keyHandler.destroy();
  77879. }
  77880. if (this.rubberband != null)
  77881. {
  77882. this.rubberband.destroy();
  77883. }
  77884. if (this.toolbar != null)
  77885. {
  77886. this.toolbar.destroy();
  77887. }
  77888. if (this.graph != null)
  77889. {
  77890. this.graph.destroy();
  77891. }
  77892. this.status = null;
  77893. this.templates = null;
  77894. }
  77895. };
  77896. /**
  77897. * Copyright (c) 2006-2015, JGraph Ltd
  77898. * Copyright (c) 2006-2015, Gaudenz Alder
  77899. */
  77900. var mxCodecRegistry =
  77901. {
  77902. /**
  77903. * Class: mxCodecRegistry
  77904. *
  77905. * Singleton class that acts as a global registry for codecs.
  77906. *
  77907. * Adding an <mxCodec>:
  77908. *
  77909. * 1. Define a default codec with a new instance of the
  77910. * object to be handled.
  77911. *
  77912. * (code)
  77913. * var codec = new mxObjectCodec(new mxGraphModel());
  77914. * (end)
  77915. *
  77916. * 2. Define the functions required for encoding and decoding
  77917. * objects.
  77918. *
  77919. * (code)
  77920. * codec.encode = function(enc, obj) { ... }
  77921. * codec.decode = function(dec, node, into) { ... }
  77922. * (end)
  77923. *
  77924. * 3. Register the codec in the <mxCodecRegistry>.
  77925. *
  77926. * (code)
  77927. * mxCodecRegistry.register(codec);
  77928. * (end)
  77929. *
  77930. * <mxObjectCodec.decode> may be used to either create a new
  77931. * instance of an object or to configure an existing instance,
  77932. * in which case the into argument points to the existing
  77933. * object. In this case, we say the codec "configures" the
  77934. * object.
  77935. *
  77936. * Variable: codecs
  77937. *
  77938. * Maps from constructor names to codecs.
  77939. */
  77940. codecs: [],
  77941. /**
  77942. * Variable: aliases
  77943. *
  77944. * Maps from classnames to codecnames.
  77945. */
  77946. aliases: [],
  77947. /**
  77948. * Function: register
  77949. *
  77950. * Registers a new codec and associates the name of the template
  77951. * constructor in the codec with the codec object.
  77952. *
  77953. * Parameters:
  77954. *
  77955. * codec - <mxObjectCodec> to be registered.
  77956. */
  77957. register: function(codec)
  77958. {
  77959. if (codec != null)
  77960. {
  77961. var name = codec.getName();
  77962. mxCodecRegistry.codecs[name] = codec;
  77963. var classname = mxUtils.getFunctionName(codec.template.constructor);
  77964. if (classname != name)
  77965. {
  77966. mxCodecRegistry.addAlias(classname, name);
  77967. }
  77968. }
  77969. return codec;
  77970. },
  77971. /**
  77972. * Function: addAlias
  77973. *
  77974. * Adds an alias for mapping a classname to a codecname.
  77975. */
  77976. addAlias: function(classname, codecname)
  77977. {
  77978. mxCodecRegistry.aliases[classname] = codecname;
  77979. },
  77980. /**
  77981. * Function: getCodec
  77982. *
  77983. * Returns a codec that handles objects that are constructed
  77984. * using the given constructor.
  77985. *
  77986. * Parameters:
  77987. *
  77988. * ctor - JavaScript constructor function.
  77989. */
  77990. getCodec: function(ctor)
  77991. {
  77992. var codec = null;
  77993. if (ctor != null)
  77994. {
  77995. var name = mxUtils.getFunctionName(ctor);
  77996. var tmp = mxCodecRegistry.aliases[name];
  77997. if (tmp != null)
  77998. {
  77999. name = tmp;
  78000. }
  78001. codec = mxCodecRegistry.codecs[name];
  78002. // Registers a new default codec for the given constructor
  78003. // if no codec has been previously defined.
  78004. if (codec == null)
  78005. {
  78006. try
  78007. {
  78008. codec = new mxObjectCodec(new ctor());
  78009. mxCodecRegistry.register(codec);
  78010. }
  78011. catch (e)
  78012. {
  78013. // ignore
  78014. }
  78015. }
  78016. }
  78017. return codec;
  78018. }
  78019. };
  78020. /**
  78021. * Copyright (c) 2006-2015, JGraph Ltd
  78022. * Copyright (c) 2006-2015, Gaudenz Alder
  78023. */
  78024. /**
  78025. * Class: mxCodec
  78026. *
  78027. * XML codec for JavaScript object graphs. See <mxObjectCodec> for a
  78028. * description of the general encoding/decoding scheme. This class uses the
  78029. * codecs registered in <mxCodecRegistry> for encoding/decoding each object.
  78030. *
  78031. * References:
  78032. *
  78033. * In order to resolve references, especially forward references, the mxCodec
  78034. * constructor must be given the document that contains the referenced
  78035. * elements.
  78036. *
  78037. * Examples:
  78038. *
  78039. * The following code is used to encode a graph model.
  78040. *
  78041. * (code)
  78042. * var encoder = new mxCodec();
  78043. * var result = encoder.encode(graph.getModel());
  78044. * var xml = mxUtils.getXml(result);
  78045. * (end)
  78046. *
  78047. * Example:
  78048. *
  78049. * Using the code below, an XML document is decoded into an existing model. The
  78050. * document may be obtained using one of the functions in mxUtils for loading
  78051. * an XML file, eg. <mxUtils.get>, or using <mxUtils.parseXml> for parsing an
  78052. * XML string.
  78053. *
  78054. * (code)
  78055. * var doc = mxUtils.parseXml(xmlString);
  78056. * var codec = new mxCodec(doc);
  78057. * codec.decode(doc.documentElement, graph.getModel());
  78058. * (end)
  78059. *
  78060. * Example:
  78061. *
  78062. * This example demonstrates parsing a list of isolated cells into an existing
  78063. * graph model. Note that the cells do not have a parent reference so they can
  78064. * be added anywhere in the cell hierarchy after parsing.
  78065. *
  78066. * (code)
  78067. * var xml = '<root><mxCell id="2" value="Hello," vertex="1"><mxGeometry x="20" y="20" width="80" height="30" as="geometry"/></mxCell><mxCell id="3" value="World!" vertex="1"><mxGeometry x="200" y="150" width="80" height="30" as="geometry"/></mxCell><mxCell id="4" value="" edge="1" source="2" target="3"><mxGeometry relative="1" as="geometry"/></mxCell></root>';
  78068. * var doc = mxUtils.parseXml(xml);
  78069. * var codec = new mxCodec(doc);
  78070. * var elt = doc.documentElement.firstChild;
  78071. * var cells = [];
  78072. *
  78073. * while (elt != null)
  78074. * {
  78075. * cells.push(codec.decode(elt));
  78076. * elt = elt.nextSibling;
  78077. * }
  78078. *
  78079. * graph.addCells(cells);
  78080. * (end)
  78081. *
  78082. * Example:
  78083. *
  78084. * Using the following code, the selection cells of a graph are encoded and the
  78085. * output is displayed in a dialog box.
  78086. *
  78087. * (code)
  78088. * var enc = new mxCodec();
  78089. * var cells = graph.getSelectionCells();
  78090. * mxUtils.alert(mxUtils.getPrettyXml(enc.encode(cells)));
  78091. * (end)
  78092. *
  78093. * Newlines in the XML can be converted to <br>, in which case a '<br>' argument
  78094. * must be passed to <mxUtils.getXml> as the second argument.
  78095. *
  78096. * Debugging:
  78097. *
  78098. * For debugging I/O you can use the following code to get the sequence of
  78099. * encoded objects:
  78100. *
  78101. * (code)
  78102. * var oldEncode = mxCodec.prototype.encode;
  78103. * mxCodec.prototype.encode = function(obj)
  78104. * {
  78105. * mxLog.show();
  78106. * mxLog.debug('mxCodec.encode: obj='+mxUtils.getFunctionName(obj.constructor));
  78107. *
  78108. * return oldEncode.apply(this, arguments);
  78109. * };
  78110. * (end)
  78111. *
  78112. * Note that the I/O system adds object codecs for new object automatically. For
  78113. * decoding those objects, the constructor should be written as follows:
  78114. *
  78115. * (code)
  78116. * var MyObj = function(name)
  78117. * {
  78118. * // ...
  78119. * };
  78120. * (end)
  78121. *
  78122. * Constructor: mxCodec
  78123. *
  78124. * Constructs an XML encoder/decoder for the specified
  78125. * owner document.
  78126. *
  78127. * Parameters:
  78128. *
  78129. * document - Optional XML document that contains the data.
  78130. * If no document is specified then a new document is created
  78131. * using <mxUtils.createXmlDocument>.
  78132. */
  78133. function mxCodec(document)
  78134. {
  78135. this.document = document || mxUtils.createXmlDocument();
  78136. this.objects = [];
  78137. };
  78138. /**
  78139. * Variable: document
  78140. *
  78141. * The owner document of the codec.
  78142. */
  78143. mxCodec.prototype.document = null;
  78144. /**
  78145. * Variable: objects
  78146. *
  78147. * Maps from IDs to objects.
  78148. */
  78149. mxCodec.prototype.objects = null;
  78150. /**
  78151. * Variable: elements
  78152. *
  78153. * Lookup table for resolving IDs to elements.
  78154. */
  78155. mxCodec.prototype.elements = null;
  78156. /**
  78157. * Variable: encodeDefaults
  78158. *
  78159. * Specifies if default values should be encoded. Default is false.
  78160. */
  78161. mxCodec.prototype.encodeDefaults = false;
  78162. /**
  78163. * Function: putObject
  78164. *
  78165. * Assoiates the given object with the given ID and returns the given object.
  78166. *
  78167. * Parameters
  78168. *
  78169. * id - ID for the object to be associated with.
  78170. * obj - Object to be associated with the ID.
  78171. */
  78172. mxCodec.prototype.putObject = function(id, obj)
  78173. {
  78174. this.objects[id] = obj;
  78175. return obj;
  78176. };
  78177. /**
  78178. * Function: getObject
  78179. *
  78180. * Returns the decoded object for the element with the specified ID in
  78181. * <document>. If the object is not known then <lookup> is used to find an
  78182. * object. If no object is found, then the element with the respective ID
  78183. * from the document is parsed using <decode>.
  78184. */
  78185. mxCodec.prototype.getObject = function(id)
  78186. {
  78187. var obj = null;
  78188. if (id != null)
  78189. {
  78190. obj = this.objects[id];
  78191. if (obj == null)
  78192. {
  78193. obj = this.lookup(id);
  78194. if (obj == null)
  78195. {
  78196. var node = this.getElementById(id);
  78197. if (node != null)
  78198. {
  78199. obj = this.decode(node);
  78200. }
  78201. }
  78202. }
  78203. }
  78204. return obj;
  78205. };
  78206. /**
  78207. * Function: lookup
  78208. *
  78209. * Hook for subclassers to implement a custom lookup mechanism for cell IDs.
  78210. * This implementation always returns null.
  78211. *
  78212. * Example:
  78213. *
  78214. * (code)
  78215. * var codec = new mxCodec();
  78216. * codec.lookup = function(id)
  78217. * {
  78218. * return model.getCell(id);
  78219. * };
  78220. * (end)
  78221. *
  78222. * Parameters:
  78223. *
  78224. * id - ID of the object to be returned.
  78225. */
  78226. mxCodec.prototype.lookup = function(id)
  78227. {
  78228. return null;
  78229. };
  78230. /**
  78231. * Function: getElementById
  78232. *
  78233. * Returns the element with the given ID from <document>.
  78234. *
  78235. * Parameters:
  78236. *
  78237. * id - String that contains the ID.
  78238. */
  78239. mxCodec.prototype.getElementById = function(id)
  78240. {
  78241. this.updateElements();
  78242. return this.elements[id];
  78243. };
  78244. /**
  78245. * Function: updateElements
  78246. *
  78247. * Returns the element with the given ID from <document>.
  78248. *
  78249. * Parameters:
  78250. *
  78251. * id - String that contains the ID.
  78252. */
  78253. mxCodec.prototype.updateElements = function()
  78254. {
  78255. if (this.elements == null)
  78256. {
  78257. this.elements = new Object();
  78258. if (this.document.documentElement != null)
  78259. {
  78260. this.addElement(this.document.documentElement);
  78261. }
  78262. }
  78263. };
  78264. /**
  78265. * Function: addElement
  78266. *
  78267. * Adds the given element to <elements> if it has an ID.
  78268. */
  78269. mxCodec.prototype.addElement = function(node)
  78270. {
  78271. if (node.nodeType == mxConstants.NODETYPE_ELEMENT)
  78272. {
  78273. var id = node.getAttribute('id');
  78274. if (id != null)
  78275. {
  78276. if (this.elements[id] == null)
  78277. {
  78278. this.elements[id] = node;
  78279. }
  78280. else if (this.elements[id] != node)
  78281. {
  78282. throw new Error(id + ': Duplicate ID');
  78283. }
  78284. }
  78285. }
  78286. node = node.firstChild;
  78287. while (node != null)
  78288. {
  78289. this.addElement(node);
  78290. node = node.nextSibling;
  78291. }
  78292. };
  78293. /**
  78294. * Function: getId
  78295. *
  78296. * Returns the ID of the specified object. This implementation
  78297. * calls <reference> first and if that returns null handles
  78298. * the object as an <mxCell> by returning their IDs using
  78299. * <mxCell.getId>. If no ID exists for the given cell, then
  78300. * an on-the-fly ID is generated using <mxCellPath.create>.
  78301. *
  78302. * Parameters:
  78303. *
  78304. * obj - Object to return the ID for.
  78305. */
  78306. mxCodec.prototype.getId = function(obj)
  78307. {
  78308. var id = null;
  78309. if (obj != null)
  78310. {
  78311. id = this.reference(obj);
  78312. if (id == null && obj instanceof mxCell)
  78313. {
  78314. id = obj.getId();
  78315. if (id == null)
  78316. {
  78317. // Uses an on-the-fly Id
  78318. id = mxCellPath.create(obj);
  78319. if (id.length == 0)
  78320. {
  78321. id = 'root';
  78322. }
  78323. }
  78324. }
  78325. }
  78326. return id;
  78327. };
  78328. /**
  78329. * Function: reference
  78330. *
  78331. * Hook for subclassers to implement a custom method
  78332. * for retrieving IDs from objects. This implementation
  78333. * always returns null.
  78334. *
  78335. * Example:
  78336. *
  78337. * (code)
  78338. * var codec = new mxCodec();
  78339. * codec.reference = function(obj)
  78340. * {
  78341. * return obj.getCustomId();
  78342. * };
  78343. * (end)
  78344. *
  78345. * Parameters:
  78346. *
  78347. * obj - Object whose ID should be returned.
  78348. */
  78349. mxCodec.prototype.reference = function(obj)
  78350. {
  78351. return null;
  78352. };
  78353. /**
  78354. * Function: encode
  78355. *
  78356. * Encodes the specified object and returns the resulting
  78357. * XML node.
  78358. *
  78359. * Parameters:
  78360. *
  78361. * obj - Object to be encoded.
  78362. */
  78363. mxCodec.prototype.encode = function(obj)
  78364. {
  78365. var node = null;
  78366. if (obj != null && obj.constructor != null)
  78367. {
  78368. var enc = mxCodecRegistry.getCodec(obj.constructor);
  78369. if (enc != null)
  78370. {
  78371. node = enc.encode(this, obj);
  78372. }
  78373. else
  78374. {
  78375. if (mxUtils.isNode(obj))
  78376. {
  78377. node = mxUtils.importNode(this.document, obj, true);
  78378. }
  78379. else
  78380. {
  78381. mxLog.warn('mxCodec.encode: No codec for ' + mxUtils.getFunctionName(obj.constructor));
  78382. }
  78383. }
  78384. }
  78385. return node;
  78386. };
  78387. /**
  78388. * Function: decode
  78389. *
  78390. * Decodes the given XML node. The optional "into"
  78391. * argument specifies an existing object to be
  78392. * used. If no object is given, then a new instance
  78393. * is created using the constructor from the codec.
  78394. *
  78395. * The function returns the passed in object or
  78396. * the new instance if no object was given.
  78397. *
  78398. * Parameters:
  78399. *
  78400. * node - XML node to be decoded.
  78401. * into - Optional object to be decodec into.
  78402. */
  78403. mxCodec.prototype.decode = function(node, into)
  78404. {
  78405. this.updateElements();
  78406. var obj = null;
  78407. if (node != null && node.nodeType == mxConstants.NODETYPE_ELEMENT)
  78408. {
  78409. var ctor = null;
  78410. try
  78411. {
  78412. ctor = window[node.nodeName];
  78413. }
  78414. catch (err)
  78415. {
  78416. // ignore
  78417. }
  78418. var dec = mxCodecRegistry.getCodec(ctor);
  78419. if (dec != null)
  78420. {
  78421. obj = dec.decode(this, node, into);
  78422. }
  78423. else
  78424. {
  78425. obj = node.cloneNode(true);
  78426. obj.removeAttribute('as');
  78427. }
  78428. }
  78429. return obj;
  78430. };
  78431. /**
  78432. * Function: encodeCell
  78433. *
  78434. * Encoding of cell hierarchies is built-into the core, but
  78435. * is a higher-level function that needs to be explicitely
  78436. * used by the respective object encoders (eg. <mxModelCodec>,
  78437. * <mxChildChangeCodec> and <mxRootChangeCodec>). This
  78438. * implementation writes the given cell and its children as a
  78439. * (flat) sequence into the given node. The children are not
  78440. * encoded if the optional includeChildren is false. The
  78441. * function is in charge of adding the result into the
  78442. * given node and has no return value.
  78443. *
  78444. * Parameters:
  78445. *
  78446. * cell - <mxCell> to be encoded.
  78447. * node - Parent XML node to add the encoded cell into.
  78448. * includeChildren - Optional boolean indicating if the
  78449. * function should include all descendents. Default is true.
  78450. */
  78451. mxCodec.prototype.encodeCell = function(cell, node, includeChildren)
  78452. {
  78453. node.appendChild(this.encode(cell));
  78454. if (includeChildren == null || includeChildren)
  78455. {
  78456. var childCount = cell.getChildCount();
  78457. for (var i = 0; i < childCount; i++)
  78458. {
  78459. this.encodeCell(cell.getChildAt(i), node);
  78460. }
  78461. }
  78462. };
  78463. /**
  78464. * Function: isCellCodec
  78465. *
  78466. * Returns true if the given codec is a cell codec. This uses
  78467. * <mxCellCodec.isCellCodec> to check if the codec is of the
  78468. * given type.
  78469. */
  78470. mxCodec.prototype.isCellCodec = function(codec)
  78471. {
  78472. if (codec != null && typeof(codec.isCellCodec) == 'function')
  78473. {
  78474. return codec.isCellCodec();
  78475. }
  78476. return false;
  78477. };
  78478. /**
  78479. * Function: decodeCell
  78480. *
  78481. * Decodes cells that have been encoded using inversion, ie.
  78482. * where the user object is the enclosing node in the XML,
  78483. * and restores the group and graph structure in the cells.
  78484. * Returns a new <mxCell> instance that represents the
  78485. * given node.
  78486. *
  78487. * Parameters:
  78488. *
  78489. * node - XML node that contains the cell data.
  78490. * restoreStructures - Optional boolean indicating whether
  78491. * the graph structure should be restored by calling insert
  78492. * and insertEdge on the parent and terminals, respectively.
  78493. * Default is true.
  78494. */
  78495. mxCodec.prototype.decodeCell = function(node, restoreStructures)
  78496. {
  78497. restoreStructures = (restoreStructures != null) ? restoreStructures : true;
  78498. var cell = null;
  78499. if (node != null && node.nodeType == mxConstants.NODETYPE_ELEMENT)
  78500. {
  78501. // Tries to find a codec for the given node name. If that does
  78502. // not return a codec then the node is the user object (an XML node
  78503. // that contains the mxCell, aka inversion).
  78504. var decoder = mxCodecRegistry.getCodec(node.nodeName);
  78505. // Tries to find the codec for the cell inside the user object.
  78506. // This assumes all node names inside the user object are either
  78507. // not registered or they correspond to a class for cells.
  78508. if (!this.isCellCodec(decoder))
  78509. {
  78510. var child = node.firstChild;
  78511. while (child != null && !this.isCellCodec(decoder))
  78512. {
  78513. decoder = mxCodecRegistry.getCodec(child.nodeName);
  78514. child = child.nextSibling;
  78515. }
  78516. }
  78517. if (!this.isCellCodec(decoder))
  78518. {
  78519. decoder = mxCodecRegistry.getCodec(mxCell);
  78520. }
  78521. cell = decoder.decode(this, node);
  78522. if (restoreStructures)
  78523. {
  78524. this.insertIntoGraph(cell);
  78525. }
  78526. }
  78527. return cell;
  78528. };
  78529. /**
  78530. * Function: insertIntoGraph
  78531. *
  78532. * Inserts the given cell into its parent and terminal cells.
  78533. */
  78534. mxCodec.prototype.insertIntoGraph = function(cell)
  78535. {
  78536. var parent = cell.parent;
  78537. var source = cell.getTerminal(true);
  78538. var target = cell.getTerminal(false);
  78539. // Fixes possible inconsistencies during insert into graph
  78540. cell.setTerminal(null, false);
  78541. cell.setTerminal(null, true);
  78542. cell.parent = null;
  78543. if (parent != null)
  78544. {
  78545. if (parent == cell)
  78546. {
  78547. throw new Error(parent.id + ': Self Reference');
  78548. }
  78549. else
  78550. {
  78551. parent.insert(cell);
  78552. }
  78553. }
  78554. if (source != null)
  78555. {
  78556. source.insertEdge(cell, true);
  78557. }
  78558. if (target != null)
  78559. {
  78560. target.insertEdge(cell, false);
  78561. }
  78562. };
  78563. /**
  78564. * Function: setAttribute
  78565. *
  78566. * Sets the attribute on the specified node to value. This is a
  78567. * helper method that makes sure the attribute and value arguments
  78568. * are not null.
  78569. *
  78570. * Parameters:
  78571. *
  78572. * node - XML node to set the attribute for.
  78573. * attributes - Attributename to be set.
  78574. * value - New value of the attribute.
  78575. */
  78576. mxCodec.prototype.setAttribute = function(node, attribute, value)
  78577. {
  78578. if (attribute != null && value != null)
  78579. {
  78580. node.setAttribute(attribute, value);
  78581. }
  78582. };
  78583. /**
  78584. * Copyright (c) 2006-2015, JGraph Ltd
  78585. * Copyright (c) 2006-2015, Gaudenz Alder
  78586. */
  78587. /**
  78588. * Class: mxObjectCodec
  78589. *
  78590. * Generic codec for JavaScript objects that implements a mapping between
  78591. * JavaScript objects and XML nodes that maps each field or element to an
  78592. * attribute or child node, and vice versa.
  78593. *
  78594. * Atomic Values:
  78595. *
  78596. * Consider the following example.
  78597. *
  78598. * (code)
  78599. * var obj = new Object();
  78600. * obj.foo = "Foo";
  78601. * obj.bar = "Bar";
  78602. * (end)
  78603. *
  78604. * This object is encoded into an XML node using the following.
  78605. *
  78606. * (code)
  78607. * var enc = new mxCodec();
  78608. * var node = enc.encode(obj);
  78609. * (end)
  78610. *
  78611. * The output of the encoding may be viewed using <mxLog> as follows.
  78612. *
  78613. * (code)
  78614. * mxLog.show();
  78615. * mxLog.debug(mxUtils.getPrettyXml(node));
  78616. * (end)
  78617. *
  78618. * Finally, the result of the encoding looks as follows.
  78619. *
  78620. * (code)
  78621. * <Object foo="Foo" bar="Bar"/>
  78622. * (end)
  78623. *
  78624. * In the above output, the foo and bar fields have been mapped to attributes
  78625. * with the same names, and the name of the constructor was used for the
  78626. * nodename.
  78627. *
  78628. * Booleans:
  78629. *
  78630. * Since booleans are numbers in JavaScript, all boolean values are encoded
  78631. * into 1 for true and 0 for false. The decoder also accepts the string true
  78632. * and false for boolean values.
  78633. *
  78634. * Objects:
  78635. *
  78636. * The above scheme is applied to all atomic fields, that is, to all non-object
  78637. * fields of an object. For object fields, a child node is created with a
  78638. * special attribute that contains the fieldname. This special attribute is
  78639. * called "as" and hence, as is a reserved word that should not be used for a
  78640. * fieldname.
  78641. *
  78642. * Consider the following example where foo is an object and bar is an atomic
  78643. * property of foo.
  78644. *
  78645. * (code)
  78646. * var obj = {foo: {bar: "Bar"}};
  78647. * (end)
  78648. *
  78649. * This will be mapped to the following XML structure by mxObjectCodec.
  78650. *
  78651. * (code)
  78652. * <Object>
  78653. * <Object bar="Bar" as="foo"/>
  78654. * </Object>
  78655. * (end)
  78656. *
  78657. * In the above output, the inner Object node contains the as-attribute that
  78658. * specifies the fieldname in the enclosing object. That is, the field foo was
  78659. * mapped to a child node with an as-attribute that has the value foo.
  78660. *
  78661. * Arrays:
  78662. *
  78663. * Arrays are special objects that are either associative, in which case each
  78664. * key, value pair is treated like a field where the key is the fieldname, or
  78665. * they are a sequence of atomic values and objects, which is mapped to a
  78666. * sequence of child nodes. For object elements, the above scheme is applied
  78667. * without the use of the special as-attribute for creating each child. For
  78668. * atomic elements, a special add-node is created with the value stored in the
  78669. * value-attribute.
  78670. *
  78671. * For example, the following array contains one atomic value and one object
  78672. * with a field called bar. Furthermore it contains two associative entries
  78673. * called bar with an atomic value, and foo with an object value.
  78674. *
  78675. * (code)
  78676. * var obj = ["Bar", {bar: "Bar"}];
  78677. * obj["bar"] = "Bar";
  78678. * obj["foo"] = {bar: "Bar"};
  78679. * (end)
  78680. *
  78681. * This array is represented by the following XML nodes.
  78682. *
  78683. * (code)
  78684. * <Array bar="Bar">
  78685. * <add value="Bar"/>
  78686. * <Object bar="Bar"/>
  78687. * <Object bar="Bar" as="foo"/>
  78688. * </Array>
  78689. * (end)
  78690. *
  78691. * The Array node name is the name of the constructor. The additional
  78692. * as-attribute in the last child contains the key of the associative entry,
  78693. * whereas the second last child is part of the array sequence and does not
  78694. * have an as-attribute.
  78695. *
  78696. * References:
  78697. *
  78698. * Objects may be represented as child nodes or attributes with ID values,
  78699. * which are used to lookup the object in a table within <mxCodec>. The
  78700. * <isReference> function is in charge of deciding if a specific field should
  78701. * be encoded as a reference or not. Its default implementation returns true if
  78702. * the fieldname is in <idrefs>, an array of strings that is used to configure
  78703. * the <mxObjectCodec>.
  78704. *
  78705. * Using this approach, the mapping does not guarantee that the referenced
  78706. * object itself exists in the document. The fields that are encoded as
  78707. * references must be carefully chosen to make sure all referenced objects
  78708. * exist in the document, or may be resolved by some other means if necessary.
  78709. *
  78710. * For example, in the case of the graph model all cells are stored in a tree
  78711. * whose root is referenced by the model's root field. A tree is a structure
  78712. * that is well suited for an XML representation, however, the additional edges
  78713. * in the graph model have a reference to a source and target cell, which are
  78714. * also contained in the tree. To handle this case, the source and target cell
  78715. * of an edge are treated as references, whereas the children are treated as
  78716. * objects. Since all cells are contained in the tree and no edge references a
  78717. * source or target outside the tree, this setup makes sure all referenced
  78718. * objects are contained in the document.
  78719. *
  78720. * In the case of a tree structure we must further avoid infinite recursion by
  78721. * ignoring the parent reference of each child. This is done by returning true
  78722. * in <isExcluded>, whose default implementation uses the array of excluded
  78723. * fieldnames passed to the mxObjectCodec constructor.
  78724. *
  78725. * References are only used for cells in mxGraph. For defining other
  78726. * referencable object types, the codec must be able to work out the ID of an
  78727. * object. This is done by implementing <mxCodec.reference>. For decoding a
  78728. * reference, the XML node with the respective id-attribute is fetched from the
  78729. * document, decoded, and stored in a lookup table for later reference. For
  78730. * looking up external objects, <mxCodec.lookup> may be implemented.
  78731. *
  78732. * Expressions:
  78733. *
  78734. * For decoding JavaScript expressions, the add-node may be used with a text
  78735. * content that contains the JavaScript expression. For example, the following
  78736. * creates a field called foo in the enclosing object and assigns it the value
  78737. * of <mxConstants.ALIGN_LEFT>.
  78738. *
  78739. * (code)
  78740. * <Object>
  78741. * <add as="foo">mxConstants.ALIGN_LEFT</add>
  78742. * </Object>
  78743. * (end)
  78744. *
  78745. * The resulting object has a field called foo with the value "left". Its XML
  78746. * representation looks as follows.
  78747. *
  78748. * (code)
  78749. * <Object foo="left"/>
  78750. * (end)
  78751. *
  78752. * This means the expression is evaluated at decoding time and the result of
  78753. * the evaluation is stored in the respective field. Valid expressions are all
  78754. * JavaScript expressions, including function definitions, which are mapped to
  78755. * functions on the resulting object.
  78756. *
  78757. * Expressions are only evaluated if <allowEval> is true.
  78758. *
  78759. * Constructor: mxObjectCodec
  78760. *
  78761. * Constructs a new codec for the specified template object.
  78762. * The variables in the optional exclude array are ignored by
  78763. * the codec. Variables in the optional idrefs array are
  78764. * turned into references in the XML. The optional mapping
  78765. * may be used to map from variable names to XML attributes.
  78766. * The argument is created as follows:
  78767. *
  78768. * (code)
  78769. * var mapping = new Object();
  78770. * mapping['variableName'] = 'attribute-name';
  78771. * (end)
  78772. *
  78773. * Parameters:
  78774. *
  78775. * template - Prototypical instance of the object to be
  78776. * encoded/decoded.
  78777. * exclude - Optional array of fieldnames to be ignored.
  78778. * idrefs - Optional array of fieldnames to be converted to/from
  78779. * references.
  78780. * mapping - Optional mapping from field- to attributenames.
  78781. */
  78782. function mxObjectCodec(template, exclude, idrefs, mapping)
  78783. {
  78784. this.template = template;
  78785. this.exclude = (exclude != null) ? exclude : [];
  78786. this.idrefs = (idrefs != null) ? idrefs : [];
  78787. this.mapping = (mapping != null) ? mapping : [];
  78788. this.reverse = new Object();
  78789. for (var i in this.mapping)
  78790. {
  78791. this.reverse[this.mapping[i]] = i;
  78792. }
  78793. };
  78794. /**
  78795. * Variable: allowEval
  78796. *
  78797. * Static global switch that specifies if expressions in arrays are allowed.
  78798. * Default is false. NOTE: Enabling this carries a possible security risk.
  78799. */
  78800. mxObjectCodec.allowEval = false;
  78801. /**
  78802. * Variable: template
  78803. *
  78804. * Holds the template object associated with this codec.
  78805. */
  78806. mxObjectCodec.prototype.template = null;
  78807. /**
  78808. * Variable: exclude
  78809. *
  78810. * Array containing the variable names that should be
  78811. * ignored by the codec.
  78812. */
  78813. mxObjectCodec.prototype.exclude = null;
  78814. /**
  78815. * Variable: idrefs
  78816. *
  78817. * Array containing the variable names that should be
  78818. * turned into or converted from references. See
  78819. * <mxCodec.getId> and <mxCodec.getObject>.
  78820. */
  78821. mxObjectCodec.prototype.idrefs = null;
  78822. /**
  78823. * Variable: mapping
  78824. *
  78825. * Maps from from fieldnames to XML attribute names.
  78826. */
  78827. mxObjectCodec.prototype.mapping = null;
  78828. /**
  78829. * Variable: reverse
  78830. *
  78831. * Maps from from XML attribute names to fieldnames.
  78832. */
  78833. mxObjectCodec.prototype.reverse = null;
  78834. /**
  78835. * Function: getName
  78836. *
  78837. * Returns the name used for the nodenames and lookup of the codec when
  78838. * classes are encoded and nodes are decoded. For classes to work with
  78839. * this the codec registry automatically adds an alias for the classname
  78840. * if that is different than what this returns. The default implementation
  78841. * returns the classname of the template class.
  78842. */
  78843. mxObjectCodec.prototype.getName = function()
  78844. {
  78845. return mxUtils.getFunctionName(this.template.constructor);
  78846. };
  78847. /**
  78848. * Function: cloneTemplate
  78849. *
  78850. * Returns a new instance of the template for this codec.
  78851. */
  78852. mxObjectCodec.prototype.cloneTemplate = function()
  78853. {
  78854. return new this.template.constructor();
  78855. };
  78856. /**
  78857. * Function: getFieldName
  78858. *
  78859. * Returns the fieldname for the given attributename.
  78860. * Looks up the value in the <reverse> mapping or returns
  78861. * the input if there is no reverse mapping for the
  78862. * given name.
  78863. */
  78864. mxObjectCodec.prototype.getFieldName = function(attributename)
  78865. {
  78866. if (attributename != null)
  78867. {
  78868. var mapped = this.reverse[attributename];
  78869. if (mapped != null)
  78870. {
  78871. attributename = mapped;
  78872. }
  78873. }
  78874. return attributename;
  78875. };
  78876. /**
  78877. * Function: getAttributeName
  78878. *
  78879. * Returns the attributename for the given fieldname.
  78880. * Looks up the value in the <mapping> or returns
  78881. * the input if there is no mapping for the
  78882. * given name.
  78883. */
  78884. mxObjectCodec.prototype.getAttributeName = function(fieldname)
  78885. {
  78886. if (fieldname != null)
  78887. {
  78888. var mapped = this.mapping[fieldname];
  78889. if (mapped != null)
  78890. {
  78891. fieldname = mapped;
  78892. }
  78893. }
  78894. return fieldname;
  78895. };
  78896. /**
  78897. * Function: isExcluded
  78898. *
  78899. * Returns true if the given attribute is to be ignored by the codec. This
  78900. * implementation returns true if the given fieldname is in <exclude> or
  78901. * if the fieldname equals <mxObjectIdentity.FIELD_NAME>.
  78902. *
  78903. * Parameters:
  78904. *
  78905. * obj - Object instance that contains the field.
  78906. * attr - Fieldname of the field.
  78907. * value - Value of the field.
  78908. * write - Boolean indicating if the field is being encoded or decoded.
  78909. * Write is true if the field is being encoded, else it is being decoded.
  78910. */
  78911. mxObjectCodec.prototype.isExcluded = function(obj, attr, value, write)
  78912. {
  78913. return attr == mxObjectIdentity.FIELD_NAME ||
  78914. mxUtils.indexOf(this.exclude, attr) >= 0;
  78915. };
  78916. /**
  78917. * Function: isReference
  78918. *
  78919. * Returns true if the given fieldname is to be treated
  78920. * as a textual reference (ID). This implementation returns
  78921. * true if the given fieldname is in <idrefs>.
  78922. *
  78923. * Parameters:
  78924. *
  78925. * obj - Object instance that contains the field.
  78926. * attr - Fieldname of the field.
  78927. * value - Value of the field.
  78928. * write - Boolean indicating if the field is being encoded or decoded.
  78929. * Write is true if the field is being encoded, else it is being decoded.
  78930. */
  78931. mxObjectCodec.prototype.isReference = function(obj, attr, value, write)
  78932. {
  78933. return mxUtils.indexOf(this.idrefs, attr) >= 0;
  78934. };
  78935. /**
  78936. * Function: encode
  78937. *
  78938. * Encodes the specified object and returns a node
  78939. * representing then given object. Calls <beforeEncode>
  78940. * after creating the node and <afterEncode> with the
  78941. * resulting node after processing.
  78942. *
  78943. * Enc is a reference to the calling encoder. It is used
  78944. * to encode complex objects and create references.
  78945. *
  78946. * This implementation encodes all variables of an
  78947. * object according to the following rules:
  78948. *
  78949. * - If the variable name is in <exclude> then it is ignored.
  78950. * - If the variable name is in <idrefs> then <mxCodec.getId>
  78951. * is used to replace the object with its ID.
  78952. * - The variable name is mapped using <mapping>.
  78953. * - If obj is an array and the variable name is numeric
  78954. * (ie. an index) then it is not encoded.
  78955. * - If the value is an object, then the codec is used to
  78956. * create a child node with the variable name encoded into
  78957. * the "as" attribute.
  78958. * - Else, if <encodeDefaults> is true or the value differs
  78959. * from the template value, then ...
  78960. * - ... if obj is not an array, then the value is mapped to
  78961. * an attribute.
  78962. * - ... else if obj is an array, the value is mapped to an
  78963. * add child with a value attribute or a text child node,
  78964. * if the value is a function.
  78965. *
  78966. * If no ID exists for a variable in <idrefs> or if an object
  78967. * cannot be encoded, a warning is issued using <mxLog.warn>.
  78968. *
  78969. * Returns the resulting XML node that represents the given
  78970. * object.
  78971. *
  78972. * Parameters:
  78973. *
  78974. * enc - <mxCodec> that controls the encoding process.
  78975. * obj - Object to be encoded.
  78976. */
  78977. mxObjectCodec.prototype.encode = function(enc, obj)
  78978. {
  78979. var node = enc.document.createElement(this.getName());
  78980. obj = this.beforeEncode(enc, obj, node);
  78981. this.encodeObject(enc, obj, node);
  78982. return this.afterEncode(enc, obj, node);
  78983. };
  78984. /**
  78985. * Function: encodeObject
  78986. *
  78987. * Encodes the value of each member in then given obj into the given node using
  78988. * <encodeValue>.
  78989. *
  78990. * Parameters:
  78991. *
  78992. * enc - <mxCodec> that controls the encoding process.
  78993. * obj - Object to be encoded.
  78994. * node - XML node that contains the encoded object.
  78995. */
  78996. mxObjectCodec.prototype.encodeObject = function(enc, obj, node)
  78997. {
  78998. enc.setAttribute(node, 'id', enc.getId(obj));
  78999. for (var i in obj)
  79000. {
  79001. var name = i;
  79002. var value = obj[name];
  79003. if (value != null && !this.isExcluded(obj, name, value, true))
  79004. {
  79005. if (mxUtils.isInteger(name))
  79006. {
  79007. name = null;
  79008. }
  79009. this.encodeValue(enc, obj, name, value, node);
  79010. }
  79011. }
  79012. };
  79013. /**
  79014. * Function: encodeValue
  79015. *
  79016. * Converts the given value according to the mappings
  79017. * and id-refs in this codec and uses <writeAttribute>
  79018. * to write the attribute into the given node.
  79019. *
  79020. * Parameters:
  79021. *
  79022. * enc - <mxCodec> that controls the encoding process.
  79023. * obj - Object whose property is going to be encoded.
  79024. * name - XML node that contains the encoded object.
  79025. * value - Value of the property to be encoded.
  79026. * node - XML node that contains the encoded object.
  79027. */
  79028. mxObjectCodec.prototype.encodeValue = function(enc, obj, name, value, node)
  79029. {
  79030. if (value != null)
  79031. {
  79032. if (this.isReference(obj, name, value, true))
  79033. {
  79034. var tmp = enc.getId(value);
  79035. if (tmp == null)
  79036. {
  79037. mxLog.warn('mxObjectCodec.encode: No ID for ' +
  79038. this.getName() + '.' + name + '=' + value);
  79039. return; // exit
  79040. }
  79041. value = tmp;
  79042. }
  79043. var defaultValue = this.template[name];
  79044. // Checks if the value is a default value and
  79045. // the name is correct
  79046. if (name == null || enc.encodeDefaults || defaultValue != value)
  79047. {
  79048. name = this.getAttributeName(name);
  79049. this.writeAttribute(enc, obj, name, value, node);
  79050. }
  79051. }
  79052. };
  79053. /**
  79054. * Function: writeAttribute
  79055. *
  79056. * Writes the given value into node using <writePrimitiveAttribute>
  79057. * or <writeComplexAttribute> depending on the type of the value.
  79058. */
  79059. mxObjectCodec.prototype.writeAttribute = function(enc, obj, name, value, node)
  79060. {
  79061. if (typeof(value) != 'object' /* primitive type */)
  79062. {
  79063. this.writePrimitiveAttribute(enc, obj, name, value, node);
  79064. }
  79065. else /* complex type */
  79066. {
  79067. this.writeComplexAttribute(enc, obj, name, value, node);
  79068. }
  79069. };
  79070. /**
  79071. * Function: writePrimitiveAttribute
  79072. *
  79073. * Writes the given value as an attribute of the given node.
  79074. */
  79075. mxObjectCodec.prototype.writePrimitiveAttribute = function(enc, obj, name, value, node)
  79076. {
  79077. value = this.convertAttributeToXml(enc, obj, name, value, node);
  79078. if (name == null)
  79079. {
  79080. var child = enc.document.createElement('add');
  79081. if (typeof(value) == 'function')
  79082. {
  79083. child.appendChild(enc.document.createTextNode(value));
  79084. }
  79085. else
  79086. {
  79087. enc.setAttribute(child, 'value', value);
  79088. }
  79089. node.appendChild(child);
  79090. }
  79091. else if (typeof(value) != 'function')
  79092. {
  79093. enc.setAttribute(node, name, value);
  79094. }
  79095. };
  79096. /**
  79097. * Function: writeComplexAttribute
  79098. *
  79099. * Writes the given value as a child node of the given node.
  79100. */
  79101. mxObjectCodec.prototype.writeComplexAttribute = function(enc, obj, name, value, node)
  79102. {
  79103. var child = enc.encode(value);
  79104. if (child != null)
  79105. {
  79106. if (name != null)
  79107. {
  79108. child.setAttribute('as', name);
  79109. }
  79110. node.appendChild(child);
  79111. }
  79112. else
  79113. {
  79114. mxLog.warn('mxObjectCodec.encode: No node for ' + this.getName() + '.' + name + ': ' + value);
  79115. }
  79116. };
  79117. /**
  79118. * Function: convertAttributeToXml
  79119. *
  79120. * Converts true to "1" and false to "0" is <isBooleanAttribute> returns true.
  79121. * All other values are not converted.
  79122. *
  79123. * Parameters:
  79124. *
  79125. * enc - <mxCodec> that controls the encoding process.
  79126. * obj - Objec to convert the attribute for.
  79127. * name - Name of the attribute to be converted.
  79128. * value - Value to be converted.
  79129. */
  79130. mxObjectCodec.prototype.convertAttributeToXml = function(enc, obj, name, value)
  79131. {
  79132. // Makes sure to encode boolean values as numeric values
  79133. if (this.isBooleanAttribute(enc, obj, name, value))
  79134. {
  79135. // Checks if the value is true (do not use the value as is, because
  79136. // this would check if the value is not null, so 0 would be true)
  79137. value = (value == true) ? '1' : '0';
  79138. }
  79139. return value;
  79140. };
  79141. /**
  79142. * Function: isBooleanAttribute
  79143. *
  79144. * Returns true if the given object attribute is a boolean value.
  79145. *
  79146. * Parameters:
  79147. *
  79148. * enc - <mxCodec> that controls the encoding process.
  79149. * obj - Objec to convert the attribute for.
  79150. * name - Name of the attribute to be converted.
  79151. * value - Value of the attribute to be converted.
  79152. */
  79153. mxObjectCodec.prototype.isBooleanAttribute = function(enc, obj, name, value)
  79154. {
  79155. return (typeof(value.length) == 'undefined' && (value == true || value == false));
  79156. };
  79157. /**
  79158. * Function: convertAttributeFromXml
  79159. *
  79160. * Converts booleans and numeric values to the respective types. Values are
  79161. * numeric if <isNumericAttribute> returns true.
  79162. *
  79163. * Parameters:
  79164. *
  79165. * dec - <mxCodec> that controls the decoding process.
  79166. * attr - XML attribute to be converted.
  79167. * obj - Objec to convert the attribute for.
  79168. */
  79169. mxObjectCodec.prototype.convertAttributeFromXml = function(dec, attr, obj)
  79170. {
  79171. var value = attr.value;
  79172. if (this.isNumericAttribute(dec, attr, obj))
  79173. {
  79174. value = parseFloat(value);
  79175. if (isNaN(value) || !isFinite(value))
  79176. {
  79177. value = 0;
  79178. }
  79179. }
  79180. return value;
  79181. };
  79182. /**
  79183. * Function: isNumericAttribute
  79184. *
  79185. * Returns true if the given XML attribute is or should be a numeric value.
  79186. *
  79187. * Parameters:
  79188. *
  79189. * dec - <mxCodec> that controls the decoding process.
  79190. * attr - XML attribute to be converted.
  79191. * obj - Objec to convert the attribute for.
  79192. */
  79193. mxObjectCodec.prototype.isNumericAttribute = function(dec, attr, obj)
  79194. {
  79195. // Handles known numeric attributes for generic objects
  79196. var result = (obj.constructor == mxGeometry &&
  79197. (attr.name == 'x' || attr.name == 'y' ||
  79198. attr.name == 'width' || attr.name == 'height')) ||
  79199. (obj.constructor == mxPoint &&
  79200. (attr.name == 'x' || attr.name == 'y')) ||
  79201. mxUtils.isNumeric(attr.value);
  79202. return result;
  79203. };
  79204. /**
  79205. * Function: beforeEncode
  79206. *
  79207. * Hook for subclassers to pre-process the object before
  79208. * encoding. This returns the input object. The return
  79209. * value of this function is used in <encode> to perform
  79210. * the default encoding into the given node.
  79211. *
  79212. * Parameters:
  79213. *
  79214. * enc - <mxCodec> that controls the encoding process.
  79215. * obj - Object to be encoded.
  79216. * node - XML node to encode the object into.
  79217. */
  79218. mxObjectCodec.prototype.beforeEncode = function(enc, obj, node)
  79219. {
  79220. return obj;
  79221. };
  79222. /**
  79223. * Function: afterEncode
  79224. *
  79225. * Hook for subclassers to post-process the node
  79226. * for the given object after encoding and return the
  79227. * post-processed node. This implementation returns
  79228. * the input node. The return value of this method
  79229. * is returned to the encoder from <encode>.
  79230. *
  79231. * Parameters:
  79232. *
  79233. * enc - <mxCodec> that controls the encoding process.
  79234. * obj - Object to be encoded.
  79235. * node - XML node that represents the default encoding.
  79236. */
  79237. mxObjectCodec.prototype.afterEncode = function(enc, obj, node)
  79238. {
  79239. return node;
  79240. };
  79241. /**
  79242. * Function: decode
  79243. *
  79244. * Parses the given node into the object or returns a new object
  79245. * representing the given node.
  79246. *
  79247. * Dec is a reference to the calling decoder. It is used to decode
  79248. * complex objects and resolve references.
  79249. *
  79250. * If a node has an id attribute then the object cache is checked for the
  79251. * object. If the object is not yet in the cache then it is constructed
  79252. * using the constructor of <template> and cached in <mxCodec.objects>.
  79253. *
  79254. * This implementation decodes all attributes and childs of a node
  79255. * according to the following rules:
  79256. *
  79257. * - If the variable name is in <exclude> or if the attribute name is "id"
  79258. * or "as" then it is ignored.
  79259. * - If the variable name is in <idrefs> then <mxCodec.getObject> is used
  79260. * to replace the reference with an object.
  79261. * - The variable name is mapped using a reverse <mapping>.
  79262. * - If the value has a child node, then the codec is used to create a
  79263. * child object with the variable name taken from the "as" attribute.
  79264. * - If the object is an array and the variable name is empty then the
  79265. * value or child object is appended to the array.
  79266. * - If an add child has no value or the object is not an array then
  79267. * the child text content is evaluated using <mxUtils.eval>.
  79268. *
  79269. * For add nodes where the object is not an array and the variable name
  79270. * is defined, the default mechanism is used, allowing to override/add
  79271. * methods as follows:
  79272. *
  79273. * (code)
  79274. * <Object>
  79275. * <add as="hello"><![CDATA[
  79276. * function(arg1) {
  79277. * mxUtils.alert('Hello '+arg1);
  79278. * }
  79279. * ]]></add>
  79280. * </Object>
  79281. * (end)
  79282. *
  79283. * If no object exists for an ID in <idrefs> a warning is issued
  79284. * using <mxLog.warn>.
  79285. *
  79286. * Returns the resulting object that represents the given XML node
  79287. * or the object given to the method as the into parameter.
  79288. *
  79289. * Parameters:
  79290. *
  79291. * dec - <mxCodec> that controls the decoding process.
  79292. * node - XML node to be decoded.
  79293. * into - Optional objec to encode the node into.
  79294. */
  79295. mxObjectCodec.prototype.decode = function(dec, node, into)
  79296. {
  79297. var id = node.getAttribute('id');
  79298. var obj = dec.objects[id];
  79299. if (obj == null)
  79300. {
  79301. obj = into || this.cloneTemplate();
  79302. if (id != null)
  79303. {
  79304. dec.putObject(id, obj);
  79305. }
  79306. }
  79307. node = this.beforeDecode(dec, node, obj);
  79308. this.decodeNode(dec, node, obj);
  79309. return this.afterDecode(dec, node, obj);
  79310. };
  79311. /**
  79312. * Function: decodeNode
  79313. *
  79314. * Calls <decodeAttributes> and <decodeChildren> for the given node.
  79315. *
  79316. * Parameters:
  79317. *
  79318. * dec - <mxCodec> that controls the decoding process.
  79319. * node - XML node to be decoded.
  79320. * obj - Objec to encode the node into.
  79321. */
  79322. mxObjectCodec.prototype.decodeNode = function(dec, node, obj)
  79323. {
  79324. if (node != null)
  79325. {
  79326. this.decodeAttributes(dec, node, obj);
  79327. this.decodeChildren(dec, node, obj);
  79328. }
  79329. };
  79330. /**
  79331. * Function: decodeAttributes
  79332. *
  79333. * Decodes all attributes of the given node using <decodeAttribute>.
  79334. *
  79335. * Parameters:
  79336. *
  79337. * dec - <mxCodec> that controls the decoding process.
  79338. * node - XML node to be decoded.
  79339. * obj - Objec to encode the node into.
  79340. */
  79341. mxObjectCodec.prototype.decodeAttributes = function(dec, node, obj)
  79342. {
  79343. var attrs = node.attributes;
  79344. if (attrs != null)
  79345. {
  79346. for (var i = 0; i < attrs.length; i++)
  79347. {
  79348. this.decodeAttribute(dec, attrs[i], obj);
  79349. }
  79350. }
  79351. };
  79352. /**
  79353. * Function: isIgnoredAttribute
  79354. *
  79355. * Returns true if the given attribute should be ignored. This implementation
  79356. * returns true if the attribute name is "as" or "id".
  79357. *
  79358. * Parameters:
  79359. *
  79360. * dec - <mxCodec> that controls the decoding process.
  79361. * attr - XML attribute to be decoded.
  79362. * obj - Objec to encode the attribute into.
  79363. */
  79364. mxObjectCodec.prototype.isIgnoredAttribute = function(dec, attr, obj)
  79365. {
  79366. return attr.nodeName == 'as' || attr.nodeName == 'id';
  79367. };
  79368. /**
  79369. * Function: decodeAttribute
  79370. *
  79371. * Reads the given attribute into the specified object.
  79372. *
  79373. * Parameters:
  79374. *
  79375. * dec - <mxCodec> that controls the decoding process.
  79376. * attr - XML attribute to be decoded.
  79377. * obj - Objec to encode the attribute into.
  79378. */
  79379. mxObjectCodec.prototype.decodeAttribute = function(dec, attr, obj)
  79380. {
  79381. if (!this.isIgnoredAttribute(dec, attr, obj))
  79382. {
  79383. var name = attr.nodeName;
  79384. // Converts the string true and false to their boolean values.
  79385. // This may require an additional check on the obj to see if
  79386. // the existing field is a boolean value or uninitialized, in
  79387. // which case we may want to convert true and false to a string.
  79388. var value = this.convertAttributeFromXml(dec, attr, obj);
  79389. var fieldname = this.getFieldName(name);
  79390. if (this.isReference(obj, fieldname, value, false))
  79391. {
  79392. var tmp = dec.getObject(value);
  79393. if (tmp == null)
  79394. {
  79395. mxLog.warn('mxObjectCodec.decode: No object for ' +
  79396. this.getName() + '.' + name + '=' + value);
  79397. return; // exit
  79398. }
  79399. value = tmp;
  79400. }
  79401. if (!this.isExcluded(obj, name, value, false))
  79402. {
  79403. //mxLog.debug(mxUtils.getFunctionName(obj.constructor)+'.'+name+'='+value);
  79404. obj[name] = value;
  79405. }
  79406. }
  79407. };
  79408. /**
  79409. * Function: decodeChildren
  79410. *
  79411. * Decodes all children of the given node using <decodeChild>.
  79412. *
  79413. * Parameters:
  79414. *
  79415. * dec - <mxCodec> that controls the decoding process.
  79416. * node - XML node to be decoded.
  79417. * obj - Objec to encode the node into.
  79418. */
  79419. mxObjectCodec.prototype.decodeChildren = function(dec, node, obj)
  79420. {
  79421. var child = node.firstChild;
  79422. while (child != null)
  79423. {
  79424. var tmp = child.nextSibling;
  79425. if (child.nodeType == mxConstants.NODETYPE_ELEMENT &&
  79426. !this.processInclude(dec, child, obj))
  79427. {
  79428. this.decodeChild(dec, child, obj);
  79429. }
  79430. child = tmp;
  79431. }
  79432. };
  79433. /**
  79434. * Function: decodeChild
  79435. *
  79436. * Reads the specified child into the given object.
  79437. *
  79438. * Parameters:
  79439. *
  79440. * dec - <mxCodec> that controls the decoding process.
  79441. * child - XML child element to be decoded.
  79442. * obj - Objec to encode the node into.
  79443. */
  79444. mxObjectCodec.prototype.decodeChild = function(dec, child, obj)
  79445. {
  79446. var fieldname = this.getFieldName(child.getAttribute('as'));
  79447. if (fieldname == null || !this.isExcluded(obj, fieldname, child, false))
  79448. {
  79449. var template = this.getFieldTemplate(obj, fieldname, child);
  79450. var value = null;
  79451. if (child.nodeName == 'add')
  79452. {
  79453. value = child.getAttribute('value');
  79454. if (value == null && mxObjectCodec.allowEval)
  79455. {
  79456. value = mxUtils.eval(mxUtils.getTextContent(child));
  79457. }
  79458. }
  79459. else
  79460. {
  79461. value = dec.decode(child, template);
  79462. }
  79463. try
  79464. {
  79465. this.addObjectValue(obj, fieldname, value, template);
  79466. }
  79467. catch (e)
  79468. {
  79469. throw new Error(e.message + ' for ' + child.nodeName);
  79470. }
  79471. }
  79472. };
  79473. /**
  79474. * Function: getFieldTemplate
  79475. *
  79476. * Returns the template instance for the given field. This returns the
  79477. * value of the field, null if the value is an array or an empty collection
  79478. * if the value is a collection. The value is then used to populate the
  79479. * field for a new instance. For strongly typed languages it may be
  79480. * required to override this to return the correct collection instance
  79481. * based on the encoded child.
  79482. */
  79483. mxObjectCodec.prototype.getFieldTemplate = function(obj, fieldname, child)
  79484. {
  79485. var template = obj[fieldname];
  79486. // Non-empty arrays are replaced completely
  79487. if (template instanceof Array && template.length > 0)
  79488. {
  79489. template = null;
  79490. }
  79491. return template;
  79492. };
  79493. /**
  79494. * Function: addObjectValue
  79495. *
  79496. * Sets the decoded child node as a value of the given object. If the
  79497. * object is a map, then the value is added with the given fieldname as a
  79498. * key. If the fieldname is not empty, then setFieldValue is called or
  79499. * else, if the object is a collection, the value is added to the
  79500. * collection. For strongly typed languages it may be required to
  79501. * override this with the correct code to add an entry to an object.
  79502. */
  79503. mxObjectCodec.prototype.addObjectValue = function(obj, fieldname, value, template)
  79504. {
  79505. if (value != null && value != template)
  79506. {
  79507. if (fieldname != null && fieldname.length > 0)
  79508. {
  79509. obj[fieldname] = value;
  79510. }
  79511. else
  79512. {
  79513. obj.push(value);
  79514. }
  79515. //mxLog.debug('Decoded '+mxUtils.getFunctionName(obj.constructor)+'.'+fieldname+': '+value);
  79516. }
  79517. };
  79518. /**
  79519. * Function: processInclude
  79520. *
  79521. * Returns true if the given node is an include directive and
  79522. * executes the include by decoding the XML document. Returns
  79523. * false if the given node is not an include directive.
  79524. *
  79525. * Parameters:
  79526. *
  79527. * dec - <mxCodec> that controls the encoding/decoding process.
  79528. * node - XML node to be checked.
  79529. * into - Optional object to pass-thru to the codec.
  79530. */
  79531. mxObjectCodec.prototype.processInclude = function(dec, node, into)
  79532. {
  79533. if (node.nodeName == 'include')
  79534. {
  79535. var name = node.getAttribute('name');
  79536. if (name != null)
  79537. {
  79538. try
  79539. {
  79540. var xml = mxUtils.load(name).getDocumentElement();
  79541. if (xml != null)
  79542. {
  79543. dec.decode(xml, into);
  79544. }
  79545. }
  79546. catch (e)
  79547. {
  79548. // ignore
  79549. }
  79550. }
  79551. return true;
  79552. }
  79553. return false;
  79554. };
  79555. /**
  79556. * Function: beforeDecode
  79557. *
  79558. * Hook for subclassers to pre-process the node for
  79559. * the specified object and return the node to be
  79560. * used for further processing by <decode>.
  79561. * The object is created based on the template in the
  79562. * calling method and is never null. This implementation
  79563. * returns the input node. The return value of this
  79564. * function is used in <decode> to perform
  79565. * the default decoding into the given object.
  79566. *
  79567. * Parameters:
  79568. *
  79569. * dec - <mxCodec> that controls the decoding process.
  79570. * node - XML node to be decoded.
  79571. * obj - Object to encode the node into.
  79572. */
  79573. mxObjectCodec.prototype.beforeDecode = function(dec, node, obj)
  79574. {
  79575. return node;
  79576. };
  79577. /**
  79578. * Function: afterDecode
  79579. *
  79580. * Hook for subclassers to post-process the object after
  79581. * decoding. This implementation returns the given object
  79582. * without any changes. The return value of this method
  79583. * is returned to the decoder from <decode>.
  79584. *
  79585. * Parameters:
  79586. *
  79587. * enc - <mxCodec> that controls the encoding process.
  79588. * node - XML node to be decoded.
  79589. * obj - Object that represents the default decoding.
  79590. */
  79591. mxObjectCodec.prototype.afterDecode = function(dec, node, obj)
  79592. {
  79593. return obj;
  79594. };
  79595. /**
  79596. * Copyright (c) 2006-2015, JGraph Ltd
  79597. * Copyright (c) 2006-2015, Gaudenz Alder
  79598. */
  79599. mxCodecRegistry.register(function()
  79600. {
  79601. /**
  79602. * Class: mxCellCodec
  79603. *
  79604. * Codec for <mxCell>s. This class is created and registered
  79605. * dynamically at load time and used implicitly via <mxCodec>
  79606. * and the <mxCodecRegistry>.
  79607. *
  79608. * Transient Fields:
  79609. *
  79610. * - children
  79611. * - edges
  79612. * - overlays
  79613. * - mxTransient
  79614. *
  79615. * Reference Fields:
  79616. *
  79617. * - parent
  79618. * - source
  79619. * - target
  79620. *
  79621. * Transient fields can be added using the following code:
  79622. *
  79623. * mxCodecRegistry.getCodec(mxCell).exclude.push('name_of_field');
  79624. *
  79625. * To subclass <mxCell>, replace the template and add an alias as
  79626. * follows.
  79627. *
  79628. * (code)
  79629. * function CustomCell(value, geometry, style)
  79630. * {
  79631. * mxCell.apply(this, arguments);
  79632. * }
  79633. *
  79634. * mxUtils.extend(CustomCell, mxCell);
  79635. *
  79636. * mxCodecRegistry.getCodec(mxCell).template = new CustomCell();
  79637. * mxCodecRegistry.addAlias('CustomCell', 'mxCell');
  79638. * (end)
  79639. */
  79640. var codec = new mxObjectCodec(new mxCell(),
  79641. ['children', 'edges', 'overlays', 'mxTransient'],
  79642. ['parent', 'source', 'target']);
  79643. /**
  79644. * Function: isCellCodec
  79645. *
  79646. * Returns true since this is a cell codec.
  79647. */
  79648. codec.isCellCodec = function()
  79649. {
  79650. return true;
  79651. };
  79652. /**
  79653. * Overidden to disable conversion of value to number.
  79654. */
  79655. codec.isNumericAttribute = function(dec, attr, obj)
  79656. {
  79657. return attr.nodeName !== 'value' && mxObjectCodec.prototype.isNumericAttribute.apply(this, arguments);
  79658. };
  79659. /**
  79660. * Function: isExcluded
  79661. *
  79662. * Excludes user objects that are XML nodes.
  79663. */
  79664. codec.isExcluded = function(obj, attr, value, isWrite)
  79665. {
  79666. return mxObjectCodec.prototype.isExcluded.apply(this, arguments) ||
  79667. (isWrite && attr == 'value' &&
  79668. value.nodeType == mxConstants.NODETYPE_ELEMENT);
  79669. };
  79670. /**
  79671. * Function: afterEncode
  79672. *
  79673. * Encodes an <mxCell> and wraps the XML up inside the
  79674. * XML of the user object (inversion).
  79675. */
  79676. codec.afterEncode = function(enc, obj, node)
  79677. {
  79678. if (obj.value != null && obj.value.nodeType == mxConstants.NODETYPE_ELEMENT)
  79679. {
  79680. // Wraps the graphical annotation up in the user object (inversion)
  79681. // by putting the result of the default encoding into a clone of the
  79682. // user object (node type 1) and returning this cloned user object.
  79683. var tmp = node;
  79684. node = mxUtils.importNode(enc.document, obj.value, true);
  79685. node.appendChild(tmp);
  79686. // Moves the id attribute to the outermost XML node, namely the
  79687. // node which denotes the object boundaries in the file.
  79688. var id = tmp.getAttribute('id');
  79689. node.setAttribute('id', id);
  79690. tmp.removeAttribute('id');
  79691. }
  79692. return node;
  79693. };
  79694. /**
  79695. * Function: beforeDecode
  79696. *
  79697. * Decodes an <mxCell> and uses the enclosing XML node as
  79698. * the user object for the cell (inversion).
  79699. */
  79700. codec.beforeDecode = function(dec, node, obj)
  79701. {
  79702. var inner = node.cloneNode(true);
  79703. var classname = this.getName();
  79704. if (node.nodeName != classname)
  79705. {
  79706. // Passes the inner graphical annotation node to the
  79707. // object codec for further processing of the cell.
  79708. var tmp = node.getElementsByTagName(classname)[0];
  79709. if (tmp != null && tmp.parentNode == node)
  79710. {
  79711. mxUtils.removeWhitespace(tmp, true);
  79712. mxUtils.removeWhitespace(tmp, false);
  79713. tmp.parentNode.removeChild(tmp);
  79714. inner = tmp;
  79715. }
  79716. else
  79717. {
  79718. inner = null;
  79719. }
  79720. // Creates the user object out of the XML node
  79721. obj.value = node.cloneNode(true);
  79722. var id = obj.value.getAttribute('id');
  79723. if (id != null)
  79724. {
  79725. obj.setId(id);
  79726. obj.value.removeAttribute('id');
  79727. }
  79728. }
  79729. else
  79730. {
  79731. // Uses ID from XML file as ID for cell in model
  79732. obj.setId(node.getAttribute('id'));
  79733. }
  79734. // Preprocesses and removes all Id-references in order to use the
  79735. // correct encoder (this) for the known references to cells (all).
  79736. if (inner != null)
  79737. {
  79738. for (var i = 0; i < this.idrefs.length; i++)
  79739. {
  79740. var attr = this.idrefs[i];
  79741. var ref = inner.getAttribute(attr);
  79742. if (ref != null)
  79743. {
  79744. inner.removeAttribute(attr);
  79745. var object = dec.objects[ref] || dec.lookup(ref);
  79746. if (object == null)
  79747. {
  79748. // Needs to decode forward reference
  79749. var element = dec.getElementById(ref);
  79750. if (element != null)
  79751. {
  79752. var decoder = mxCodecRegistry.codecs[element.nodeName] || this;
  79753. object = decoder.decode(dec, element);
  79754. }
  79755. }
  79756. obj[attr] = object;
  79757. }
  79758. }
  79759. }
  79760. return inner;
  79761. };
  79762. // Returns the codec into the registry
  79763. return codec;
  79764. }());
  79765. /**
  79766. * Copyright (c) 2006-2015, JGraph Ltd
  79767. * Copyright (c) 2006-2015, Gaudenz Alder
  79768. */
  79769. mxCodecRegistry.register(function()
  79770. {
  79771. /**
  79772. * Class: mxModelCodec
  79773. *
  79774. * Codec for <mxGraphModel>s. This class is created and registered
  79775. * dynamically at load time and used implicitly via <mxCodec>
  79776. * and the <mxCodecRegistry>.
  79777. */
  79778. var codec = new mxObjectCodec(new mxGraphModel());
  79779. /**
  79780. * Function: encodeObject
  79781. *
  79782. * Encodes the given <mxGraphModel> by writing a (flat) XML sequence of
  79783. * cell nodes as produced by the <mxCellCodec>. The sequence is
  79784. * wrapped-up in a node with the name root.
  79785. */
  79786. codec.encodeObject = function(enc, obj, node)
  79787. {
  79788. var rootNode = enc.document.createElement('root');
  79789. enc.encodeCell(obj.getRoot(), rootNode);
  79790. node.appendChild(rootNode);
  79791. };
  79792. /**
  79793. * Function: decodeChild
  79794. *
  79795. * Overrides decode child to handle special child nodes.
  79796. */
  79797. codec.decodeChild = function(dec, child, obj)
  79798. {
  79799. if (child.nodeName == 'root')
  79800. {
  79801. this.decodeRoot(dec, child, obj);
  79802. }
  79803. else
  79804. {
  79805. mxObjectCodec.prototype.decodeChild.apply(this, arguments);
  79806. }
  79807. };
  79808. /**
  79809. * Function: decodeRoot
  79810. *
  79811. * Reads the cells into the graph model. All cells
  79812. * are children of the root element in the node.
  79813. */
  79814. codec.decodeRoot = function(dec, root, model)
  79815. {
  79816. var rootCell = null;
  79817. var tmp = root.firstChild;
  79818. while (tmp != null)
  79819. {
  79820. var cell = dec.decodeCell(tmp);
  79821. if (cell != null && cell.getParent() == null)
  79822. {
  79823. rootCell = cell;
  79824. }
  79825. tmp = tmp.nextSibling;
  79826. }
  79827. // Sets the root on the model if one has been decoded
  79828. if (rootCell != null)
  79829. {
  79830. model.setRoot(rootCell);
  79831. }
  79832. };
  79833. // Returns the codec into the registry
  79834. return codec;
  79835. }());
  79836. /**
  79837. * Copyright (c) 2006-2015, JGraph Ltd
  79838. * Copyright (c) 2006-2015, Gaudenz Alder
  79839. */
  79840. mxCodecRegistry.register(function()
  79841. {
  79842. /**
  79843. * Class: mxRootChangeCodec
  79844. *
  79845. * Codec for <mxRootChange>s. This class is created and registered
  79846. * dynamically at load time and used implicitly via <mxCodec> and
  79847. * the <mxCodecRegistry>.
  79848. *
  79849. * Transient Fields:
  79850. *
  79851. * - model
  79852. * - previous
  79853. * - root
  79854. */
  79855. var codec = new mxObjectCodec(new mxRootChange(),
  79856. ['model', 'previous', 'root']);
  79857. /**
  79858. * Function: onEncode
  79859. *
  79860. * Encodes the child recursively.
  79861. */
  79862. codec.afterEncode = function(enc, obj, node)
  79863. {
  79864. enc.encodeCell(obj.root, node);
  79865. return node;
  79866. };
  79867. /**
  79868. * Function: beforeDecode
  79869. *
  79870. * Decodes the optional children as cells
  79871. * using the respective decoder.
  79872. */
  79873. codec.beforeDecode = function(dec, node, obj)
  79874. {
  79875. if (node.firstChild != null &&
  79876. node.firstChild.nodeType == mxConstants.NODETYPE_ELEMENT)
  79877. {
  79878. // Makes sure the original node isn't modified
  79879. node = node.cloneNode(true);
  79880. var tmp = node.firstChild;
  79881. obj.root = dec.decodeCell(tmp, false);
  79882. var tmp2 = tmp.nextSibling;
  79883. tmp.parentNode.removeChild(tmp);
  79884. tmp = tmp2;
  79885. while (tmp != null)
  79886. {
  79887. tmp2 = tmp.nextSibling;
  79888. dec.decodeCell(tmp);
  79889. tmp.parentNode.removeChild(tmp);
  79890. tmp = tmp2;
  79891. }
  79892. }
  79893. return node;
  79894. };
  79895. /**
  79896. * Function: afterDecode
  79897. *
  79898. * Restores the state by assigning the previous value.
  79899. */
  79900. codec.afterDecode = function(dec, node, obj)
  79901. {
  79902. obj.previous = obj.root;
  79903. return obj;
  79904. };
  79905. // Returns the codec into the registry
  79906. return codec;
  79907. }());
  79908. /**
  79909. * Copyright (c) 2006-2015, JGraph Ltd
  79910. * Copyright (c) 2006-2015, Gaudenz Alder
  79911. */
  79912. mxCodecRegistry.register(function()
  79913. {
  79914. /**
  79915. * Class: mxChildChangeCodec
  79916. *
  79917. * Codec for <mxChildChange>s. This class is created and registered
  79918. * dynamically at load time and used implicitly via <mxCodec> and
  79919. * the <mxCodecRegistry>.
  79920. *
  79921. * Transient Fields:
  79922. *
  79923. * - model
  79924. * - previous
  79925. * - previousIndex
  79926. * - child
  79927. *
  79928. * Reference Fields:
  79929. *
  79930. * - parent
  79931. */
  79932. var codec = new mxObjectCodec(new mxChildChange(),
  79933. ['model', 'child', 'previousIndex'],
  79934. ['parent', 'previous']);
  79935. /**
  79936. * Function: isReference
  79937. *
  79938. * Returns true for the child attribute if the child
  79939. * cell had a previous parent or if we're reading the
  79940. * child as an attribute rather than a child node, in
  79941. * which case it's always a reference.
  79942. */
  79943. codec.isReference = function(obj, attr, value, isWrite)
  79944. {
  79945. if (attr == 'child' && (!isWrite || obj.model.contains(obj.previous)))
  79946. {
  79947. return true;
  79948. }
  79949. return mxUtils.indexOf(this.idrefs, attr) >= 0;
  79950. };
  79951. /**
  79952. * Function: isExcluded
  79953. *
  79954. * Excludes references to parent or previous if not in the model.
  79955. */
  79956. codec.isExcluded = function(obj, attr, value, write)
  79957. {
  79958. return mxObjectCodec.prototype.isExcluded.apply(this, arguments) ||
  79959. (write && value != null && (attr == 'previous' ||
  79960. attr == 'parent') && !obj.model.contains(value));
  79961. };
  79962. /**
  79963. * Function: afterEncode
  79964. *
  79965. * Encodes the child recusively and adds the result
  79966. * to the given node.
  79967. */
  79968. codec.afterEncode = function(enc, obj, node)
  79969. {
  79970. if (this.isReference(obj, 'child', obj.child, true))
  79971. {
  79972. // Encodes as reference (id)
  79973. node.setAttribute('child', enc.getId(obj.child));
  79974. }
  79975. else
  79976. {
  79977. // At this point, the encoder is no longer able to know which cells
  79978. // are new, so we have to encode the complete cell hierarchy and
  79979. // ignore the ones that are already there at decoding time. Note:
  79980. // This can only be resolved by moving the notify event into the
  79981. // execute of the edit.
  79982. enc.encodeCell(obj.child, node);
  79983. }
  79984. return node;
  79985. };
  79986. /**
  79987. * Function: beforeDecode
  79988. *
  79989. * Decodes the any child nodes as using the respective
  79990. * codec from the registry.
  79991. */
  79992. codec.beforeDecode = function(dec, node, obj)
  79993. {
  79994. if (node.firstChild != null &&
  79995. node.firstChild.nodeType == mxConstants.NODETYPE_ELEMENT)
  79996. {
  79997. // Makes sure the original node isn't modified
  79998. node = node.cloneNode(true);
  79999. var tmp = node.firstChild;
  80000. obj.child = dec.decodeCell(tmp, false);
  80001. var tmp2 = tmp.nextSibling;
  80002. tmp.parentNode.removeChild(tmp);
  80003. tmp = tmp2;
  80004. while (tmp != null)
  80005. {
  80006. tmp2 = tmp.nextSibling;
  80007. if (tmp.nodeType == mxConstants.NODETYPE_ELEMENT)
  80008. {
  80009. // Ignores all existing cells because those do not need to
  80010. // be re-inserted into the model. Since the encoded version
  80011. // of these cells contains the new parent, this would leave
  80012. // to an inconsistent state on the model (ie. a parent
  80013. // change without a call to parentForCellChanged).
  80014. var id = tmp.getAttribute('id');
  80015. if (dec.lookup(id) == null)
  80016. {
  80017. dec.decodeCell(tmp);
  80018. }
  80019. }
  80020. tmp.parentNode.removeChild(tmp);
  80021. tmp = tmp2;
  80022. }
  80023. }
  80024. else
  80025. {
  80026. var childRef = node.getAttribute('child');
  80027. obj.child = dec.getObject(childRef);
  80028. }
  80029. return node;
  80030. };
  80031. /**
  80032. * Function: afterDecode
  80033. *
  80034. * Restores object state in the child change.
  80035. */
  80036. codec.afterDecode = function(dec, node, obj)
  80037. {
  80038. // Cells are decoded here after a complete transaction so the previous
  80039. // parent must be restored on the cell for the case where the cell was
  80040. // added. This is needed for the local model to identify the cell as a
  80041. // new cell and register the ID.
  80042. if (obj.child != null)
  80043. {
  80044. if (obj.child.parent != null && obj.previous != null &&
  80045. obj.child.parent != obj.previous)
  80046. {
  80047. obj.previous = obj.child.parent;
  80048. }
  80049. obj.child.parent = obj.previous;
  80050. obj.previous = obj.parent;
  80051. obj.previousIndex = obj.index;
  80052. }
  80053. return obj;
  80054. };
  80055. // Returns the codec into the registry
  80056. return codec;
  80057. }());
  80058. /**
  80059. * Copyright (c) 2006-2015, JGraph Ltd
  80060. * Copyright (c) 2006-2015, Gaudenz Alder
  80061. */
  80062. mxCodecRegistry.register(function()
  80063. {
  80064. /**
  80065. * Class: mxTerminalChangeCodec
  80066. *
  80067. * Codec for <mxTerminalChange>s. This class is created and registered
  80068. * dynamically at load time and used implicitly via <mxCodec> and
  80069. * the <mxCodecRegistry>.
  80070. *
  80071. * Transient Fields:
  80072. *
  80073. * - model
  80074. * - previous
  80075. *
  80076. * Reference Fields:
  80077. *
  80078. * - cell
  80079. * - terminal
  80080. */
  80081. var codec = new mxObjectCodec(new mxTerminalChange(),
  80082. ['model', 'previous'], ['cell', 'terminal']);
  80083. /**
  80084. * Function: afterDecode
  80085. *
  80086. * Restores the state by assigning the previous value.
  80087. */
  80088. codec.afterDecode = function(dec, node, obj)
  80089. {
  80090. obj.previous = obj.terminal;
  80091. return obj;
  80092. };
  80093. // Returns the codec into the registry
  80094. return codec;
  80095. }());
  80096. /**
  80097. * Copyright (c) 2006-2015, JGraph Ltd
  80098. * Copyright (c) 2006-2015, Gaudenz Alder
  80099. */
  80100. /**
  80101. * Class: mxGenericChangeCodec
  80102. *
  80103. * Codec for <mxValueChange>s, <mxStyleChange>s, <mxGeometryChange>s,
  80104. * <mxCollapseChange>s and <mxVisibleChange>s. This class is created
  80105. * and registered dynamically at load time and used implicitly
  80106. * via <mxCodec> and the <mxCodecRegistry>.
  80107. *
  80108. * Transient Fields:
  80109. *
  80110. * - model
  80111. * - previous
  80112. *
  80113. * Reference Fields:
  80114. *
  80115. * - cell
  80116. *
  80117. * Constructor: mxGenericChangeCodec
  80118. *
  80119. * Factory function that creates a <mxObjectCodec> for
  80120. * the specified change and fieldname.
  80121. *
  80122. * Parameters:
  80123. *
  80124. * obj - An instance of the change object.
  80125. * variable - The fieldname for the change data.
  80126. */
  80127. var mxGenericChangeCodec = function(obj, variable)
  80128. {
  80129. var codec = new mxObjectCodec(obj, ['model', 'previous'], ['cell']);
  80130. /**
  80131. * Function: afterDecode
  80132. *
  80133. * Restores the state by assigning the previous value.
  80134. */
  80135. codec.afterDecode = function(dec, node, obj)
  80136. {
  80137. // Allows forward references in sessions. This is a workaround
  80138. // for the sequence of edits in mxGraph.moveCells and cellsAdded.
  80139. if (mxUtils.isNode(obj.cell))
  80140. {
  80141. obj.cell = dec.decodeCell(obj.cell, false);
  80142. }
  80143. obj.previous = obj[variable];
  80144. return obj;
  80145. };
  80146. return codec;
  80147. };
  80148. // Registers the codecs
  80149. mxCodecRegistry.register(mxGenericChangeCodec(new mxValueChange(), 'value'));
  80150. mxCodecRegistry.register(mxGenericChangeCodec(new mxStyleChange(), 'style'));
  80151. mxCodecRegistry.register(mxGenericChangeCodec(new mxGeometryChange(), 'geometry'));
  80152. mxCodecRegistry.register(mxGenericChangeCodec(new mxCollapseChange(), 'collapsed'));
  80153. mxCodecRegistry.register(mxGenericChangeCodec(new mxVisibleChange(), 'visible'));
  80154. mxCodecRegistry.register(mxGenericChangeCodec(new mxCellAttributeChange(), 'value'));
  80155. /**
  80156. * Copyright (c) 2006-2015, JGraph Ltd
  80157. * Copyright (c) 2006-2015, Gaudenz Alder
  80158. */
  80159. mxCodecRegistry.register(function()
  80160. {
  80161. /**
  80162. * Class: mxGraphCodec
  80163. *
  80164. * Codec for <mxGraph>s. This class is created and registered
  80165. * dynamically at load time and used implicitly via <mxCodec>
  80166. * and the <mxCodecRegistry>.
  80167. *
  80168. * Transient Fields:
  80169. *
  80170. * - graphListeners
  80171. * - eventListeners
  80172. * - view
  80173. * - container
  80174. * - cellRenderer
  80175. * - editor
  80176. * - selection
  80177. */
  80178. return new mxObjectCodec(new mxGraph(),
  80179. ['graphListeners', 'eventListeners', 'view', 'container',
  80180. 'cellRenderer', 'editor', 'selection']);
  80181. }());
  80182. /**
  80183. * Copyright (c) 2006-2015, JGraph Ltd
  80184. * Copyright (c) 2006-2015, Gaudenz Alder
  80185. */
  80186. mxCodecRegistry.register(function()
  80187. {
  80188. /**
  80189. * Class: mxGraphViewCodec
  80190. *
  80191. * Custom encoder for <mxGraphView>s. This class is created
  80192. * and registered dynamically at load time and used implicitly via
  80193. * <mxCodec> and the <mxCodecRegistry>. This codec only writes views
  80194. * into a XML format that can be used to create an image for
  80195. * the graph, that is, it contains absolute coordinates with
  80196. * computed perimeters, edge styles and cell styles.
  80197. */
  80198. var codec = new mxObjectCodec(new mxGraphView());
  80199. /**
  80200. * Function: encode
  80201. *
  80202. * Encodes the given <mxGraphView> using <encodeCell>
  80203. * starting at the model's root. This returns the
  80204. * top-level graph node of the recursive encoding.
  80205. */
  80206. codec.encode = function(enc, view)
  80207. {
  80208. return this.encodeCell(enc, view,
  80209. view.graph.getModel().getRoot());
  80210. };
  80211. /**
  80212. * Function: encodeCell
  80213. *
  80214. * Recursively encodes the specifed cell. Uses layer
  80215. * as the default nodename. If the cell's parent is
  80216. * null, then graph is used for the nodename. If
  80217. * <mxGraphModel.isEdge> returns true for the cell,
  80218. * then edge is used for the nodename, else if
  80219. * <mxGraphModel.isVertex> returns true for the cell,
  80220. * then vertex is used for the nodename.
  80221. *
  80222. * <mxGraph.getLabel> is used to create the label
  80223. * attribute for the cell. For graph nodes and vertices
  80224. * the bounds are encoded into x, y, width and height.
  80225. * For edges the points are encoded into a points
  80226. * attribute as a space-separated list of comma-separated
  80227. * coordinate pairs (eg. x0,y0 x1,y1 ... xn,yn). All
  80228. * values from the cell style are added as attribute
  80229. * values to the node.
  80230. */
  80231. codec.encodeCell = function(enc, view, cell)
  80232. {
  80233. var model = view.graph.getModel();
  80234. var state = view.getState(cell);
  80235. var parent = model.getParent(cell);
  80236. if (parent == null || state != null)
  80237. {
  80238. var childCount = model.getChildCount(cell);
  80239. var geo = view.graph.getCellGeometry(cell);
  80240. var name = null;
  80241. if (parent == model.getRoot())
  80242. {
  80243. name = 'layer';
  80244. }
  80245. else if (parent == null)
  80246. {
  80247. name = 'graph';
  80248. }
  80249. else if (model.isEdge(cell))
  80250. {
  80251. name = 'edge';
  80252. }
  80253. else if (childCount > 0 && geo != null)
  80254. {
  80255. name = 'group';
  80256. }
  80257. else if (model.isVertex(cell))
  80258. {
  80259. name = 'vertex';
  80260. }
  80261. if (name != null)
  80262. {
  80263. var node = enc.document.createElement(name);
  80264. var lab = view.graph.getLabel(cell);
  80265. if (lab != null)
  80266. {
  80267. node.setAttribute('label', view.graph.getLabel(cell));
  80268. if (view.graph.isHtmlLabel(cell))
  80269. {
  80270. node.setAttribute('html', true);
  80271. }
  80272. }
  80273. if (parent == null)
  80274. {
  80275. var bounds = view.getGraphBounds();
  80276. if (bounds != null)
  80277. {
  80278. node.setAttribute('x', Math.round(bounds.x));
  80279. node.setAttribute('y', Math.round(bounds.y));
  80280. node.setAttribute('width', Math.round(bounds.width));
  80281. node.setAttribute('height', Math.round(bounds.height));
  80282. }
  80283. node.setAttribute('scale', view.scale);
  80284. }
  80285. else if (state != null && geo != null)
  80286. {
  80287. // Writes each key, value in the style pair to an attribute
  80288. for (var i in state.style)
  80289. {
  80290. var value = state.style[i];
  80291. // Tries to turn objects and functions into strings
  80292. if (typeof(value) == 'function' &&
  80293. typeof(value) == 'object')
  80294. {
  80295. value = mxStyleRegistry.getName(value);
  80296. }
  80297. if (value != null &&
  80298. typeof(value) != 'function' &&
  80299. typeof(value) != 'object')
  80300. {
  80301. node.setAttribute(i, value);
  80302. }
  80303. }
  80304. var abs = state.absolutePoints;
  80305. // Writes the list of points into one attribute
  80306. if (abs != null && abs.length > 0)
  80307. {
  80308. var pts = Math.round(abs[0].x) + ',' + Math.round(abs[0].y);
  80309. for (var i=1; i<abs.length; i++)
  80310. {
  80311. pts += ' ' + Math.round(abs[i].x) + ',' +
  80312. Math.round(abs[i].y);
  80313. }
  80314. node.setAttribute('points', pts);
  80315. }
  80316. // Writes the bounds into 4 attributes
  80317. else
  80318. {
  80319. node.setAttribute('x', Math.round(state.x));
  80320. node.setAttribute('y', Math.round(state.y));
  80321. node.setAttribute('width', Math.round(state.width));
  80322. node.setAttribute('height', Math.round(state.height));
  80323. }
  80324. var offset = state.absoluteOffset;
  80325. // Writes the offset into 2 attributes
  80326. if (offset != null)
  80327. {
  80328. if (offset.x != 0)
  80329. {
  80330. node.setAttribute('dx', Math.round(offset.x));
  80331. }
  80332. if (offset.y != 0)
  80333. {
  80334. node.setAttribute('dy', Math.round(offset.y));
  80335. }
  80336. }
  80337. }
  80338. for (var i=0; i<childCount; i++)
  80339. {
  80340. var childNode = this.encodeCell(enc,
  80341. view, model.getChildAt(cell, i));
  80342. if (childNode != null)
  80343. {
  80344. node.appendChild(childNode);
  80345. }
  80346. }
  80347. }
  80348. }
  80349. return node;
  80350. };
  80351. // Returns the codec into the registry
  80352. return codec;
  80353. }());
  80354. /**
  80355. * Copyright (c) 2006-2015, JGraph Ltd
  80356. * Copyright (c) 2006-2015, Gaudenz Alder
  80357. */
  80358. /**
  80359. * Class: mxStylesheetCodec
  80360. *
  80361. * Codec for <mxStylesheet>s. This class is created and registered
  80362. * dynamically at load time and used implicitly via <mxCodec>
  80363. * and the <mxCodecRegistry>.
  80364. */
  80365. var mxStylesheetCodec = mxCodecRegistry.register(function()
  80366. {
  80367. var codec = new mxObjectCodec(new mxStylesheet());
  80368. /**
  80369. * Function: encode
  80370. *
  80371. * Encodes a stylesheet. See <decode> for a description of the
  80372. * format.
  80373. */
  80374. codec.encode = function(enc, obj)
  80375. {
  80376. var node = enc.document.createElement(this.getName());
  80377. for (var i in obj.styles)
  80378. {
  80379. var style = obj.styles[i];
  80380. var styleNode = enc.document.createElement('add');
  80381. if (i != null)
  80382. {
  80383. styleNode.setAttribute('as', i);
  80384. for (var j in style)
  80385. {
  80386. var value = this.getStringValue(j, style[j]);
  80387. if (value != null)
  80388. {
  80389. var entry = enc.document.createElement('add');
  80390. entry.setAttribute('value', value);
  80391. entry.setAttribute('as', j);
  80392. styleNode.appendChild(entry);
  80393. }
  80394. }
  80395. if (styleNode.childNodes.length > 0)
  80396. {
  80397. node.appendChild(styleNode);
  80398. }
  80399. }
  80400. }
  80401. return node;
  80402. };
  80403. /**
  80404. * Function: getStringValue
  80405. *
  80406. * Returns the string for encoding the given value.
  80407. */
  80408. codec.getStringValue = function(key, value)
  80409. {
  80410. var type = typeof(value);
  80411. if (type == 'function')
  80412. {
  80413. value = mxStyleRegistry.getName(value);
  80414. }
  80415. else if (type == 'object')
  80416. {
  80417. value = null;
  80418. }
  80419. return value;
  80420. };
  80421. /**
  80422. * Function: decode
  80423. *
  80424. * Reads a sequence of the following child nodes
  80425. * and attributes:
  80426. *
  80427. * Child Nodes:
  80428. *
  80429. * add - Adds a new style.
  80430. *
  80431. * Attributes:
  80432. *
  80433. * as - Name of the style.
  80434. * extend - Name of the style to inherit from.
  80435. *
  80436. * Each node contains another sequence of add and remove nodes with the following
  80437. * attributes:
  80438. *
  80439. * as - Name of the style (see <mxConstants>).
  80440. * value - Value for the style.
  80441. *
  80442. * Instead of the value-attribute, one can put Javascript expressions into
  80443. * the node as follows if <mxStylesheetCodec.allowEval> is true:
  80444. * <add as="perimeter">mxPerimeter.RectanglePerimeter</add>
  80445. *
  80446. * A remove node will remove the entry with the name given in the as-attribute
  80447. * from the style.
  80448. *
  80449. * Example:
  80450. *
  80451. * (code)
  80452. * <mxStylesheet as="stylesheet">
  80453. * <add as="text">
  80454. * <add as="fontSize" value="12"/>
  80455. * </add>
  80456. * <add as="defaultVertex" extend="text">
  80457. * <add as="shape" value="rectangle"/>
  80458. * </add>
  80459. * </mxStylesheet>
  80460. * (end)
  80461. */
  80462. codec.decode = function(dec, node, into)
  80463. {
  80464. var obj = into || new this.template.constructor();
  80465. var id = node.getAttribute('id');
  80466. if (id != null)
  80467. {
  80468. dec.objects[id] = obj;
  80469. }
  80470. node = node.firstChild;
  80471. while (node != null)
  80472. {
  80473. if (!this.processInclude(dec, node, obj) && node.nodeName == 'add')
  80474. {
  80475. var as = node.getAttribute('as');
  80476. if (as != null)
  80477. {
  80478. var extend = node.getAttribute('extend');
  80479. var style = (extend != null) ? mxUtils.clone(obj.styles[extend]) : null;
  80480. if (style == null)
  80481. {
  80482. if (extend != null)
  80483. {
  80484. mxLog.warn('mxStylesheetCodec.decode: stylesheet ' +
  80485. extend + ' not found to extend');
  80486. }
  80487. style = new Object();
  80488. }
  80489. var entry = node.firstChild;
  80490. while (entry != null)
  80491. {
  80492. if (entry.nodeType == mxConstants.NODETYPE_ELEMENT)
  80493. {
  80494. var key = entry.getAttribute('as');
  80495. if (entry.nodeName == 'add')
  80496. {
  80497. var text = mxUtils.getTextContent(entry);
  80498. var value = null;
  80499. if (text != null && text.length > 0 && mxStylesheetCodec.allowEval)
  80500. {
  80501. value = mxUtils.eval(text);
  80502. }
  80503. else
  80504. {
  80505. value = entry.getAttribute('value');
  80506. if (mxUtils.isNumeric(value))
  80507. {
  80508. value = parseFloat(value);
  80509. }
  80510. }
  80511. if (value != null)
  80512. {
  80513. style[key] = value;
  80514. }
  80515. }
  80516. else if (entry.nodeName == 'remove')
  80517. {
  80518. delete style[key];
  80519. }
  80520. }
  80521. entry = entry.nextSibling;
  80522. }
  80523. obj.putCellStyle(as, style);
  80524. }
  80525. }
  80526. node = node.nextSibling;
  80527. }
  80528. return obj;
  80529. };
  80530. // Returns the codec into the registry
  80531. return codec;
  80532. }());
  80533. /**
  80534. * Variable: allowEval
  80535. *
  80536. * Static global switch that specifies if the use of eval is allowed for
  80537. * evaluating text content. Default is true. Set this to false if stylesheets
  80538. * may contain user input.
  80539. */
  80540. mxStylesheetCodec.allowEval = true;
  80541. /**
  80542. * Copyright (c) 2006-2015, JGraph Ltd
  80543. * Copyright (c) 2006-2015, Gaudenz Alder
  80544. */
  80545. mxCodecRegistry.register(function()
  80546. {
  80547. /**
  80548. * Class: mxDefaultKeyHandlerCodec
  80549. *
  80550. * Custom codec for configuring <mxDefaultKeyHandler>s. This class is created
  80551. * and registered dynamically at load time and used implicitly via
  80552. * <mxCodec> and the <mxCodecRegistry>. This codec only reads configuration
  80553. * data for existing key handlers, it does not encode or create key handlers.
  80554. */
  80555. var codec = new mxObjectCodec(new mxDefaultKeyHandler());
  80556. /**
  80557. * Function: encode
  80558. *
  80559. * Returns null.
  80560. */
  80561. codec.encode = function(enc, obj)
  80562. {
  80563. return null;
  80564. };
  80565. /**
  80566. * Function: decode
  80567. *
  80568. * Reads a sequence of the following child nodes
  80569. * and attributes:
  80570. *
  80571. * Child Nodes:
  80572. *
  80573. * add - Binds a keystroke to an actionname.
  80574. *
  80575. * Attributes:
  80576. *
  80577. * as - Keycode.
  80578. * action - Actionname to execute in editor.
  80579. * control - Optional boolean indicating if
  80580. * the control key must be pressed.
  80581. *
  80582. * Example:
  80583. *
  80584. * (code)
  80585. * <mxDefaultKeyHandler as="keyHandler">
  80586. * <add as="88" control="true" action="cut"/>
  80587. * <add as="67" control="true" action="copy"/>
  80588. * <add as="86" control="true" action="paste"/>
  80589. * </mxDefaultKeyHandler>
  80590. * (end)
  80591. *
  80592. * The keycodes are for the x, c and v keys.
  80593. *
  80594. * See also: <mxDefaultKeyHandler.bindAction>,
  80595. * http://www.js-examples.com/page/tutorials__key_codes.html
  80596. */
  80597. codec.decode = function(dec, node, into)
  80598. {
  80599. if (into != null)
  80600. {
  80601. var editor = into.editor;
  80602. node = node.firstChild;
  80603. while (node != null)
  80604. {
  80605. if (!this.processInclude(dec, node, into) &&
  80606. node.nodeName == 'add')
  80607. {
  80608. var as = node.getAttribute('as');
  80609. var action = node.getAttribute('action');
  80610. var control = node.getAttribute('control');
  80611. into.bindAction(as, action, control);
  80612. }
  80613. node = node.nextSibling;
  80614. }
  80615. }
  80616. return into;
  80617. };
  80618. // Returns the codec into the registry
  80619. return codec;
  80620. }());
  80621. /**
  80622. * Copyright (c) 2006-2015, JGraph Ltd
  80623. * Copyright (c) 2006-2015, Gaudenz Alder
  80624. */
  80625. /**
  80626. * Class: mxDefaultToolbarCodec
  80627. *
  80628. * Custom codec for configuring <mxDefaultToolbar>s. This class is created
  80629. * and registered dynamically at load time and used implicitly via
  80630. * <mxCodec> and the <mxCodecRegistry>. This codec only reads configuration
  80631. * data for existing toolbars handlers, it does not encode or create toolbars.
  80632. */
  80633. var mxDefaultToolbarCodec = mxCodecRegistry.register(function()
  80634. {
  80635. var codec = new mxObjectCodec(new mxDefaultToolbar());
  80636. /**
  80637. * Function: encode
  80638. *
  80639. * Returns null.
  80640. */
  80641. codec.encode = function(enc, obj)
  80642. {
  80643. return null;
  80644. };
  80645. /**
  80646. * Function: decode
  80647. *
  80648. * Reads a sequence of the following child nodes
  80649. * and attributes:
  80650. *
  80651. * Child Nodes:
  80652. *
  80653. * add - Adds a new item to the toolbar. See below for attributes.
  80654. * separator - Adds a vertical separator. No attributes.
  80655. * hr - Adds a horizontal separator. No attributes.
  80656. * br - Adds a linefeed. No attributes.
  80657. *
  80658. * Attributes:
  80659. *
  80660. * as - Resource key for the label.
  80661. * action - Name of the action to execute in enclosing editor.
  80662. * mode - Modename (see below).
  80663. * template - Template name for cell insertion.
  80664. * style - Optional style to override the template style.
  80665. * icon - Icon (relative/absolute URL).
  80666. * pressedIcon - Optional icon for pressed state (relative/absolute URL).
  80667. * id - Optional ID to be used for the created DOM element.
  80668. * toggle - Optional 0 or 1 to disable toggling of the element. Default is
  80669. * 1 (true).
  80670. *
  80671. * The action, mode and template attributes are mutually exclusive. The
  80672. * style can only be used with the template attribute. The add node may
  80673. * contain another sequence of add nodes with as and action attributes
  80674. * to create a combo box in the toolbar. If the icon is specified then
  80675. * a list of the child node is expected to have its template attribute
  80676. * set and the action is ignored instead.
  80677. *
  80678. * Nodes with a specified template may define a function to be used for
  80679. * inserting the cloned template into the graph. Here is an example of such
  80680. * a node:
  80681. *
  80682. * (code)
  80683. * <add as="Swimlane" template="swimlane" icon="images/swimlane.gif"><![CDATA[
  80684. * function (editor, cell, evt, targetCell)
  80685. * {
  80686. * var pt = mxUtils.convertPoint(
  80687. * editor.graph.container, mxEvent.getClientX(evt),
  80688. * mxEvent.getClientY(evt));
  80689. * return editor.addVertex(targetCell, cell, pt.x, pt.y);
  80690. * }
  80691. * ]]></add>
  80692. * (end)
  80693. *
  80694. * In the above function, editor is the enclosing <mxEditor> instance, cell
  80695. * is the clone of the template, evt is the mouse event that represents the
  80696. * drop and targetCell is the cell under the mousepointer where the drop
  80697. * occurred. The targetCell is retrieved using <mxGraph.getCellAt>.
  80698. *
  80699. * Futhermore, nodes with the mode attribute may define a function to
  80700. * be executed upon selection of the respective toolbar icon. In the
  80701. * example below, the default edge style is set when this specific
  80702. * connect-mode is activated:
  80703. *
  80704. * (code)
  80705. * <add as="connect" mode="connect"><![CDATA[
  80706. * function (editor)
  80707. * {
  80708. * if (editor.defaultEdge != null)
  80709. * {
  80710. * editor.defaultEdge.style = 'straightEdge';
  80711. * }
  80712. * }
  80713. * ]]></add>
  80714. * (end)
  80715. *
  80716. * Both functions require <mxDefaultToolbarCodec.allowEval> to be set to true.
  80717. *
  80718. * Modes:
  80719. *
  80720. * select - Left mouse button used for rubberband- & cell-selection.
  80721. * connect - Allows connecting vertices by inserting new edges.
  80722. * pan - Disables selection and switches to panning on the left button.
  80723. *
  80724. * Example:
  80725. *
  80726. * To add items to the toolbar:
  80727. *
  80728. * (code)
  80729. * <mxDefaultToolbar as="toolbar">
  80730. * <add as="save" action="save" icon="images/save.gif"/>
  80731. * <br/><hr/>
  80732. * <add as="select" mode="select" icon="images/select.gif"/>
  80733. * <add as="connect" mode="connect" icon="images/connect.gif"/>
  80734. * </mxDefaultToolbar>
  80735. * (end)
  80736. */
  80737. codec.decode = function(dec, node, into)
  80738. {
  80739. if (into != null)
  80740. {
  80741. var editor = into.editor;
  80742. node = node.firstChild;
  80743. while (node != null)
  80744. {
  80745. if (node.nodeType == mxConstants.NODETYPE_ELEMENT)
  80746. {
  80747. if (!this.processInclude(dec, node, into))
  80748. {
  80749. if (node.nodeName == 'separator')
  80750. {
  80751. into.addSeparator();
  80752. }
  80753. else if (node.nodeName == 'br')
  80754. {
  80755. into.toolbar.addBreak();
  80756. }
  80757. else if (node.nodeName == 'hr')
  80758. {
  80759. into.toolbar.addLine();
  80760. }
  80761. else if (node.nodeName == 'add')
  80762. {
  80763. var as = node.getAttribute('as');
  80764. as = mxResources.get(as) || as;
  80765. var icon = node.getAttribute('icon');
  80766. var pressedIcon = node.getAttribute('pressedIcon');
  80767. var action = node.getAttribute('action');
  80768. var mode = node.getAttribute('mode');
  80769. var template = node.getAttribute('template');
  80770. var toggle = node.getAttribute('toggle') != '0';
  80771. var text = mxUtils.getTextContent(node);
  80772. var elt = null;
  80773. if (action != null)
  80774. {
  80775. elt = into.addItem(as, icon, action, pressedIcon);
  80776. }
  80777. else if (mode != null)
  80778. {
  80779. var funct = (mxDefaultToolbarCodec.allowEval) ? mxUtils.eval(text) : null;
  80780. elt = into.addMode(as, icon, mode, pressedIcon, funct);
  80781. }
  80782. else if (template != null || (text != null && text.length > 0))
  80783. {
  80784. var cell = editor.templates[template];
  80785. var style = node.getAttribute('style');
  80786. if (cell != null && style != null)
  80787. {
  80788. cell = editor.graph.cloneCell(cell);
  80789. cell.setStyle(style);
  80790. }
  80791. var insertFunction = null;
  80792. if (text != null && text.length > 0 && mxDefaultToolbarCodec.allowEval)
  80793. {
  80794. insertFunction = mxUtils.eval(text);
  80795. }
  80796. elt = into.addPrototype(as, icon, cell, pressedIcon, insertFunction, toggle);
  80797. }
  80798. else
  80799. {
  80800. var children = mxUtils.getChildNodes(node);
  80801. if (children.length > 0)
  80802. {
  80803. if (icon == null)
  80804. {
  80805. var combo = into.addActionCombo(as);
  80806. for (var i=0; i<children.length; i++)
  80807. {
  80808. var child = children[i];
  80809. if (child.nodeName == 'separator')
  80810. {
  80811. into.addOption(combo, '---');
  80812. }
  80813. else if (child.nodeName == 'add')
  80814. {
  80815. var lab = child.getAttribute('as');
  80816. var act = child.getAttribute('action');
  80817. into.addActionOption(combo, lab, act);
  80818. }
  80819. }
  80820. }
  80821. else
  80822. {
  80823. var select = null;
  80824. var create = function()
  80825. {
  80826. var template = editor.templates[select.value];
  80827. if (template != null)
  80828. {
  80829. var clone = template.clone();
  80830. var style = select.options[select.selectedIndex].cellStyle;
  80831. if (style != null)
  80832. {
  80833. clone.setStyle(style);
  80834. }
  80835. return clone;
  80836. }
  80837. else
  80838. {
  80839. mxLog.warn('Template '+template+' not found');
  80840. }
  80841. return null;
  80842. };
  80843. var img = into.addPrototype(as, icon, create, null, null, toggle);
  80844. select = into.addCombo();
  80845. // Selects the toolbar icon if a selection change
  80846. // is made in the corresponding combobox.
  80847. mxEvent.addListener(select, 'change', function()
  80848. {
  80849. into.toolbar.selectMode(img, function(evt)
  80850. {
  80851. var pt = mxUtils.convertPoint(editor.graph.container,
  80852. mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  80853. return editor.addVertex(null, funct(), pt.x, pt.y);
  80854. });
  80855. into.toolbar.noReset = false;
  80856. });
  80857. // Adds the entries to the combobox
  80858. for (var i=0; i<children.length; i++)
  80859. {
  80860. var child = children[i];
  80861. if (child.nodeName == 'separator')
  80862. {
  80863. into.addOption(select, '---');
  80864. }
  80865. else if (child.nodeName == 'add')
  80866. {
  80867. var lab = child.getAttribute('as');
  80868. var tmp = child.getAttribute('template');
  80869. var option = into.addOption(select, lab, tmp || template);
  80870. option.cellStyle = child.getAttribute('style');
  80871. }
  80872. }
  80873. }
  80874. }
  80875. }
  80876. // Assigns an ID to the created element to access it later.
  80877. if (elt != null)
  80878. {
  80879. var id = node.getAttribute('id');
  80880. if (id != null && id.length > 0)
  80881. {
  80882. elt.setAttribute('id', id);
  80883. }
  80884. }
  80885. }
  80886. }
  80887. }
  80888. node = node.nextSibling;
  80889. }
  80890. }
  80891. return into;
  80892. };
  80893. // Returns the codec into the registry
  80894. return codec;
  80895. }());
  80896. /**
  80897. * Variable: allowEval
  80898. *
  80899. * Static global switch that specifies if the use of eval is allowed for
  80900. * evaluating text content. Default is true. Set this to false if stylesheets
  80901. * may contain user input
  80902. */
  80903. mxDefaultToolbarCodec.allowEval = true;
  80904. /**
  80905. * Copyright (c) 2006-2015, JGraph Ltd
  80906. * Copyright (c) 2006-2015, Gaudenz Alder
  80907. */
  80908. mxCodecRegistry.register(function()
  80909. {
  80910. /**
  80911. * Class: mxDefaultPopupMenuCodec
  80912. *
  80913. * Custom codec for configuring <mxDefaultPopupMenu>s. This class is created
  80914. * and registered dynamically at load time and used implicitly via
  80915. * <mxCodec> and the <mxCodecRegistry>. This codec only reads configuration
  80916. * data for existing popup menus, it does not encode or create menus. Note
  80917. * that this codec only passes the configuration node to the popup menu,
  80918. * which uses the config to dynamically create menus. See
  80919. * <mxDefaultPopupMenu.createMenu>.
  80920. */
  80921. var codec = new mxObjectCodec(new mxDefaultPopupMenu());
  80922. /**
  80923. * Function: encode
  80924. *
  80925. * Returns null.
  80926. */
  80927. codec.encode = function(enc, obj)
  80928. {
  80929. return null;
  80930. };
  80931. /**
  80932. * Function: decode
  80933. *
  80934. * Uses the given node as the config for <mxDefaultPopupMenu>.
  80935. */
  80936. codec.decode = function(dec, node, into)
  80937. {
  80938. var inc = node.getElementsByTagName('include')[0];
  80939. if (inc != null)
  80940. {
  80941. this.processInclude(dec, inc, into);
  80942. }
  80943. else if (into != null)
  80944. {
  80945. into.config = node;
  80946. }
  80947. return into;
  80948. };
  80949. // Returns the codec into the registry
  80950. return codec;
  80951. }());
  80952. /**
  80953. * Copyright (c) 2006-2015, JGraph Ltd
  80954. * Copyright (c) 2006-2015, Gaudenz Alder
  80955. */
  80956. mxCodecRegistry.register(function()
  80957. {
  80958. /**
  80959. * Class: mxEditorCodec
  80960. *
  80961. * Codec for <mxEditor>s. This class is created and registered
  80962. * dynamically at load time and used implicitly via <mxCodec>
  80963. * and the <mxCodecRegistry>.
  80964. *
  80965. * Transient Fields:
  80966. *
  80967. * - modified
  80968. * - lastSnapshot
  80969. * - ignoredChanges
  80970. * - undoManager
  80971. * - graphContainer
  80972. * - toolbarContainer
  80973. */
  80974. var codec = new mxObjectCodec(new mxEditor(),
  80975. ['modified', 'lastSnapshot', 'ignoredChanges',
  80976. 'undoManager', 'graphContainer', 'toolbarContainer']);
  80977. /**
  80978. * Function: beforeDecode
  80979. *
  80980. * Decodes the ui-part of the configuration node by reading
  80981. * a sequence of the following child nodes and attributes
  80982. * and passes the control to the default decoding mechanism:
  80983. *
  80984. * Child Nodes:
  80985. *
  80986. * stylesheet - Adds a CSS stylesheet to the document.
  80987. * resource - Adds the basename of a resource bundle.
  80988. * add - Creates or configures a known UI element.
  80989. *
  80990. * These elements may appear in any order given that the
  80991. * graph UI element is added before the toolbar element
  80992. * (see Known Keys).
  80993. *
  80994. * Attributes:
  80995. *
  80996. * as - Key for the UI element (see below).
  80997. * element - ID for the element in the document.
  80998. * style - CSS style to be used for the element or window.
  80999. * x - X coordinate for the new window.
  81000. * y - Y coordinate for the new window.
  81001. * width - Width for the new window.
  81002. * height - Optional height for the new window.
  81003. * name - Name of the stylesheet (absolute/relative URL).
  81004. * basename - Basename of the resource bundle (see <mxResources>).
  81005. *
  81006. * The x, y, width and height attributes are used to create a new
  81007. * <mxWindow> if the element attribute is not specified in an add
  81008. * node. The name and basename are only used in the stylesheet and
  81009. * resource nodes, respectively.
  81010. *
  81011. * Known Keys:
  81012. *
  81013. * graph - Main graph element (see <mxEditor.setGraphContainer>).
  81014. * title - Title element (see <mxEditor.setTitleContainer>).
  81015. * toolbar - Toolbar element (see <mxEditor.setToolbarContainer>).
  81016. * status - Status bar element (see <mxEditor.setStatusContainer>).
  81017. *
  81018. * Example:
  81019. *
  81020. * (code)
  81021. * <ui>
  81022. * <stylesheet name="css/process.css"/>
  81023. * <resource basename="resources/app"/>
  81024. * <add as="graph" element="graph"
  81025. * style="left:70px;right:20px;top:20px;bottom:40px"/>
  81026. * <add as="status" element="status"/>
  81027. * <add as="toolbar" x="10" y="20" width="54"/>
  81028. * </ui>
  81029. * (end)
  81030. */
  81031. codec.afterDecode = function(dec, node, obj)
  81032. {
  81033. // Assigns the specified templates for edges
  81034. var defaultEdge = node.getAttribute('defaultEdge');
  81035. if (defaultEdge != null)
  81036. {
  81037. node.removeAttribute('defaultEdge');
  81038. obj.defaultEdge = obj.templates[defaultEdge];
  81039. }
  81040. // Assigns the specified templates for groups
  81041. var defaultGroup = node.getAttribute('defaultGroup');
  81042. if (defaultGroup != null)
  81043. {
  81044. node.removeAttribute('defaultGroup');
  81045. obj.defaultGroup = obj.templates[defaultGroup];
  81046. }
  81047. return obj;
  81048. };
  81049. /**
  81050. * Function: decodeChild
  81051. *
  81052. * Overrides decode child to handle special child nodes.
  81053. */
  81054. codec.decodeChild = function(dec, child, obj)
  81055. {
  81056. if (child.nodeName == 'Array')
  81057. {
  81058. var role = child.getAttribute('as');
  81059. if (role == 'templates')
  81060. {
  81061. this.decodeTemplates(dec, child, obj);
  81062. return;
  81063. }
  81064. }
  81065. else if (child.nodeName == 'ui')
  81066. {
  81067. this.decodeUi(dec, child, obj);
  81068. return;
  81069. }
  81070. mxObjectCodec.prototype.decodeChild.apply(this, arguments);
  81071. };
  81072. /**
  81073. * Function: decodeTemplates
  81074. *
  81075. * Decodes the cells from the given node as templates.
  81076. */
  81077. codec.decodeUi = function(dec, node, editor)
  81078. {
  81079. var tmp = node.firstChild;
  81080. while (tmp != null)
  81081. {
  81082. if (tmp.nodeName == 'add')
  81083. {
  81084. var as = tmp.getAttribute('as');
  81085. var elt = tmp.getAttribute('element');
  81086. var style = tmp.getAttribute('style');
  81087. var element = null;
  81088. if (elt != null)
  81089. {
  81090. element = document.getElementById(elt);
  81091. if (element != null && style != null)
  81092. {
  81093. element.style.cssText += ';' + style;
  81094. }
  81095. }
  81096. else
  81097. {
  81098. var x = parseInt(tmp.getAttribute('x'));
  81099. var y = parseInt(tmp.getAttribute('y'));
  81100. var width = tmp.getAttribute('width');
  81101. var height = tmp.getAttribute('height');
  81102. // Creates a new window around the element
  81103. element = document.createElement('div');
  81104. element.style.cssText = style;
  81105. var wnd = new mxWindow(mxResources.get(as) || as,
  81106. element, x, y, width, height, false, true);
  81107. wnd.setVisible(true);
  81108. }
  81109. // TODO: Make more generic
  81110. if (as == 'graph')
  81111. {
  81112. editor.setGraphContainer(element);
  81113. }
  81114. else if (as == 'toolbar')
  81115. {
  81116. editor.setToolbarContainer(element);
  81117. }
  81118. else if (as == 'title')
  81119. {
  81120. editor.setTitleContainer(element);
  81121. }
  81122. else if (as == 'status')
  81123. {
  81124. editor.setStatusContainer(element);
  81125. }
  81126. else if (as == 'map')
  81127. {
  81128. editor.setMapContainer(element);
  81129. }
  81130. }
  81131. else if (tmp.nodeName == 'resource')
  81132. {
  81133. mxResources.add(tmp.getAttribute('basename'));
  81134. }
  81135. else if (tmp.nodeName == 'stylesheet')
  81136. {
  81137. mxClient.link('stylesheet', tmp.getAttribute('name'));
  81138. }
  81139. tmp = tmp.nextSibling;
  81140. }
  81141. };
  81142. /**
  81143. * Function: decodeTemplates
  81144. *
  81145. * Decodes the cells from the given node as templates.
  81146. */
  81147. codec.decodeTemplates = function(dec, node, editor)
  81148. {
  81149. if (editor.templates == null)
  81150. {
  81151. editor.templates = [];
  81152. }
  81153. var children = mxUtils.getChildNodes(node);
  81154. for (var j=0; j<children.length; j++)
  81155. {
  81156. var name = children[j].getAttribute('as');
  81157. var child = children[j].firstChild;
  81158. while (child != null && child.nodeType != 1)
  81159. {
  81160. child = child.nextSibling;
  81161. }
  81162. if (child != null)
  81163. {
  81164. // LATER: Only single cells means you need
  81165. // to group multiple cells within another
  81166. // cell. This should be changed to support
  81167. // arrays of cells, or the wrapper must
  81168. // be automatically handled in this class.
  81169. editor.templates[name] = dec.decodeCell(child);
  81170. }
  81171. }
  81172. };
  81173. // Returns the codec into the registry
  81174. return codec;
  81175. }());