25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

raphael.js 303KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438
  1. // ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐ \\
  2. // │ Raphaël 2.3.0 - JavaScript Vector Library │ \\
  3. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  4. // │ Copyright © 2008-2016 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5. // │ Copyright © 2008-2016 Sencha Labs (http://sencha.com) │ \\
  6. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  7. // │ Licensed under the MIT (https://github.com/DmitryBaranovskiy/raphael/blob/master/license.txt) license.│ \\
  8. // └───────────────────────────────────────────────────────────────────────────────────────────────────────┘ \\
  9. (function webpackUniversalModuleDefinition(root, factory) {
  10. if(typeof exports === 'object' && typeof module === 'object')
  11. module.exports = factory();
  12. else if(typeof define === 'function' && define.amd)
  13. define([], factory);
  14. else if(typeof exports === 'object')
  15. exports["Raphael"] = factory();
  16. else
  17. root["Raphael"] = factory();
  18. })(window, function() {
  19. return /******/ (function(modules) { // webpackBootstrap
  20. /******/ // The module cache
  21. /******/ var installedModules = {};
  22. /******/
  23. /******/ // The require function
  24. /******/ function __webpack_require__(moduleId) {
  25. /******/
  26. /******/ // Check if module is in cache
  27. /******/ if(installedModules[moduleId]) {
  28. /******/ return installedModules[moduleId].exports;
  29. /******/ }
  30. /******/ // Create a new module (and put it into the cache)
  31. /******/ var module = installedModules[moduleId] = {
  32. /******/ i: moduleId,
  33. /******/ l: false,
  34. /******/ exports: {}
  35. /******/ };
  36. /******/
  37. /******/ // Execute the module function
  38. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39. /******/
  40. /******/ // Flag the module as loaded
  41. /******/ module.l = true;
  42. /******/
  43. /******/ // Return the exports of the module
  44. /******/ return module.exports;
  45. /******/ }
  46. /******/
  47. /******/
  48. /******/ // expose the modules object (__webpack_modules__)
  49. /******/ __webpack_require__.m = modules;
  50. /******/
  51. /******/ // expose the module cache
  52. /******/ __webpack_require__.c = installedModules;
  53. /******/
  54. /******/ // define getter function for harmony exports
  55. /******/ __webpack_require__.d = function(exports, name, getter) {
  56. /******/ if(!__webpack_require__.o(exports, name)) {
  57. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  58. /******/ }
  59. /******/ };
  60. /******/
  61. /******/ // define __esModule on exports
  62. /******/ __webpack_require__.r = function(exports) {
  63. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  64. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  65. /******/ }
  66. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  67. /******/ };
  68. /******/
  69. /******/ // create a fake namespace object
  70. /******/ // mode & 1: value is a module id, require it
  71. /******/ // mode & 2: merge all properties of value into the ns
  72. /******/ // mode & 4: return value when already ns object
  73. /******/ // mode & 8|1: behave like require
  74. /******/ __webpack_require__.t = function(value, mode) {
  75. /******/ if(mode & 1) value = __webpack_require__(value);
  76. /******/ if(mode & 8) return value;
  77. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  78. /******/ var ns = Object.create(null);
  79. /******/ __webpack_require__.r(ns);
  80. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  81. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  82. /******/ return ns;
  83. /******/ };
  84. /******/
  85. /******/ // getDefaultExport function for compatibility with non-harmony modules
  86. /******/ __webpack_require__.n = function(module) {
  87. /******/ var getter = module && module.__esModule ?
  88. /******/ function getDefault() { return module['default']; } :
  89. /******/ function getModuleExports() { return module; };
  90. /******/ __webpack_require__.d(getter, 'a', getter);
  91. /******/ return getter;
  92. /******/ };
  93. /******/
  94. /******/ // Object.prototype.hasOwnProperty.call
  95. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  96. /******/
  97. /******/ // __webpack_public_path__
  98. /******/ __webpack_require__.p = "";
  99. /******/
  100. /******/
  101. /******/ // Load entry module and return exports
  102. /******/ return __webpack_require__(__webpack_require__.s = "./dev/raphael.amd.js");
  103. /******/ })
  104. /************************************************************************/
  105. /******/ ({
  106. /***/ "./dev/raphael.amd.js":
  107. /*!****************************!*\
  108. !*** ./dev/raphael.amd.js ***!
  109. \****************************/
  110. /*! no static exports found */
  111. /***/ (function(module, exports, __webpack_require__) {
  112. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! ./raphael.core */ "./dev/raphael.core.js"), __webpack_require__(/*! ./raphael.svg */ "./dev/raphael.svg.js"), __webpack_require__(/*! ./raphael.vml */ "./dev/raphael.vml.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(R) {
  113. return R;
  114. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  115. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  116. /***/ }),
  117. /***/ "./dev/raphael.core.js":
  118. /*!*****************************!*\
  119. !*** ./dev/raphael.core.js ***!
  120. \*****************************/
  121. /*! no static exports found */
  122. /***/ (function(module, exports, __webpack_require__) {
  123. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! eve */ "./node_modules/eve-raphael/eve.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(eve) {
  124. /*\
  125. * Raphael
  126. [ method ]
  127. **
  128. * Creates a canvas object on which to draw.
  129. * You must do this first, as all future calls to drawing methods
  130. * from this instance will be bound to this canvas.
  131. > Parameters
  132. **
  133. - container (HTMLElement|string) DOM element or its ID which is going to be a parent for drawing surface
  134. - width (number)
  135. - height (number)
  136. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  137. * or
  138. - x (number)
  139. - y (number)
  140. - width (number)
  141. - height (number)
  142. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  143. * or
  144. - all (array) (first 3 or 4 elements in the array are equal to [containerID, width, height] or [x, y, width, height]. The rest are element descriptions in format {type: type, <attributes>}). See @Paper.add.
  145. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  146. * or
  147. - onReadyCallback (function) function that is going to be called on DOM ready event. You can also subscribe to this event via Eve’s “DOMLoad” event. In this case method returns `undefined`.
  148. = (object) @Paper
  149. > Usage
  150. | // Each of the following examples create a canvas
  151. | // that is 320px wide by 200px high.
  152. | // Canvas is created at the viewport’s 10,50 coordinate.
  153. | var paper = Raphael(10, 50, 320, 200);
  154. | // Canvas is created at the top left corner of the #notepad element
  155. | // (or its top right corner in dir="rtl" elements)
  156. | var paper = Raphael(document.getElementById("notepad"), 320, 200);
  157. | // Same as above
  158. | var paper = Raphael("notepad", 320, 200);
  159. | // Image dump
  160. | var set = Raphael(["notepad", 320, 200, {
  161. | type: "rect",
  162. | x: 10,
  163. | y: 10,
  164. | width: 25,
  165. | height: 25,
  166. | stroke: "#f00"
  167. | }, {
  168. | type: "text",
  169. | x: 30,
  170. | y: 40,
  171. | text: "Dump"
  172. | }]);
  173. \*/
  174. function R(first) {
  175. if (R.is(first, "function")) {
  176. return loaded ? first() : eve.on("raphael.DOMload", first);
  177. } else if (R.is(first, array)) {
  178. return R._engine.create[apply](R, first.splice(0, 3 + R.is(first[0], nu))).add(first);
  179. } else {
  180. var args = Array.prototype.slice.call(arguments, 0);
  181. if (R.is(args[args.length - 1], "function")) {
  182. var f = args.pop();
  183. return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("raphael.DOMload", function () {
  184. f.call(R._engine.create[apply](R, args));
  185. });
  186. } else {
  187. return R._engine.create[apply](R, arguments);
  188. }
  189. }
  190. }
  191. R.version = "2.3.0";
  192. R.eve = eve;
  193. var loaded,
  194. separator = /[, ]+/,
  195. elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
  196. formatrg = /\{(\d+)\}/g,
  197. proto = "prototype",
  198. has = "hasOwnProperty",
  199. g = {
  200. doc: document,
  201. win: window
  202. },
  203. oldRaphael = {
  204. was: Object.prototype[has].call(g.win, "Raphael"),
  205. is: g.win.Raphael
  206. },
  207. Paper = function () {
  208. /*\
  209. * Paper.ca
  210. [ property (object) ]
  211. **
  212. * Shortcut for @Paper.customAttributes
  213. \*/
  214. /*\
  215. * Paper.customAttributes
  216. [ property (object) ]
  217. **
  218. * If you have a set of attributes that you would like to represent
  219. * as a function of some number you can do it easily with custom attributes:
  220. > Usage
  221. | paper.customAttributes.hue = function (num) {
  222. | num = num % 1;
  223. | return {fill: "hsb(" + num + ", 0.75, 1)"};
  224. | };
  225. | // Custom attribute “hue” will change fill
  226. | // to be given hue with fixed saturation and brightness.
  227. | // Now you can use it like this:
  228. | var c = paper.circle(10, 10, 10).attr({hue: .45});
  229. | // or even like this:
  230. | c.animate({hue: 1}, 1e3);
  231. |
  232. | // You could also create custom attribute
  233. | // with multiple parameters:
  234. | paper.customAttributes.hsb = function (h, s, b) {
  235. | return {fill: "hsb(" + [h, s, b].join(",") + ")"};
  236. | };
  237. | c.attr({hsb: "0.5 .8 1"});
  238. | c.animate({hsb: [1, 0, 0.5]}, 1e3);
  239. \*/
  240. this.ca = this.customAttributes = {};
  241. },
  242. paperproto,
  243. appendChild = "appendChild",
  244. apply = "apply",
  245. concat = "concat",
  246. //taken from Modernizr touch test: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js#L40
  247. supportsTouch = ('ontouchstart' in window) || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch,
  248. E = "",
  249. S = " ",
  250. Str = String,
  251. split = "split",
  252. events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
  253. touchMap = {
  254. mousedown: "touchstart",
  255. mousemove: "touchmove",
  256. mouseup: "touchend"
  257. },
  258. lowerCase = Str.prototype.toLowerCase,
  259. math = Math,
  260. mmax = math.max,
  261. mmin = math.min,
  262. abs = math.abs,
  263. pow = math.pow,
  264. PI = math.PI,
  265. nu = "number",
  266. string = "string",
  267. array = "array",
  268. toString = "toString",
  269. fillString = "fill",
  270. objectToString = Object.prototype.toString,
  271. paper = {},
  272. push = "push",
  273. ISURL = R._ISURL = /^url\(['"]?(.+?)['"]?\)$/i,
  274. colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
  275. isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
  276. bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
  277. round = math.round,
  278. setAttribute = "setAttribute",
  279. toFloat = parseFloat,
  280. toInt = parseInt,
  281. upperCase = Str.prototype.toUpperCase,
  282. availableAttrs = R._availableAttrs = {
  283. "arrow-end": "none",
  284. "arrow-start": "none",
  285. blur: 0,
  286. "clip-rect": "0 0 1e9 1e9",
  287. cursor: "default",
  288. cx: 0,
  289. cy: 0,
  290. fill: "#fff",
  291. "fill-opacity": 1,
  292. font: '10px "Arial"',
  293. "font-family": '"Arial"',
  294. "font-size": "10",
  295. "font-style": "normal",
  296. "font-weight": 400,
  297. gradient: 0,
  298. height: 0,
  299. href: "http://raphaeljs.com/",
  300. "letter-spacing": 0,
  301. opacity: 1,
  302. path: "M0,0",
  303. r: 0,
  304. rx: 0,
  305. ry: 0,
  306. src: "",
  307. stroke: "#000",
  308. "stroke-dasharray": "",
  309. "stroke-linecap": "butt",
  310. "stroke-linejoin": "butt",
  311. "stroke-miterlimit": 0,
  312. "stroke-opacity": 1,
  313. "stroke-width": 1,
  314. target: "_blank",
  315. "text-anchor": "middle",
  316. title: "Raphael",
  317. transform: "",
  318. width: 0,
  319. x: 0,
  320. y: 0,
  321. "class": ""
  322. },
  323. availableAnimAttrs = R._availableAnimAttrs = {
  324. blur: nu,
  325. "clip-rect": "csv",
  326. cx: nu,
  327. cy: nu,
  328. fill: "colour",
  329. "fill-opacity": nu,
  330. "font-size": nu,
  331. height: nu,
  332. opacity: nu,
  333. path: "path",
  334. r: nu,
  335. rx: nu,
  336. ry: nu,
  337. stroke: "colour",
  338. "stroke-opacity": nu,
  339. "stroke-width": nu,
  340. transform: "transform",
  341. width: nu,
  342. x: nu,
  343. y: nu
  344. },
  345. whitespace = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]/g,
  346. commaSpaces = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/,
  347. hsrg = {hs: 1, rg: 1},
  348. p2s = /,?([achlmqrstvxz]),?/gi,
  349. pathCommand = /([achlmrqstvz])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  350. tCommand = /([rstm])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  351. pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/ig,
  352. radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*([^\)]+?)\))?/,
  353. eldata = {},
  354. sortByKey = function (a, b) {
  355. return a.key - b.key;
  356. },
  357. sortByNumber = function (a, b) {
  358. return toFloat(a) - toFloat(b);
  359. },
  360. fun = function () {},
  361. pipe = function (x) {
  362. return x;
  363. },
  364. rectPath = R._rectPath = function (x, y, w, h, r) {
  365. if (r) {
  366. return [["M", x + r, y], ["l", w - r * 2, 0], ["a", r, r, 0, 0, 1, r, r], ["l", 0, h - r * 2], ["a", r, r, 0, 0, 1, -r, r], ["l", r * 2 - w, 0], ["a", r, r, 0, 0, 1, -r, -r], ["l", 0, r * 2 - h], ["a", r, r, 0, 0, 1, r, -r], ["z"]];
  367. }
  368. return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
  369. },
  370. ellipsePath = function (x, y, rx, ry) {
  371. if (ry == null) {
  372. ry = rx;
  373. }
  374. return [["M", x, y], ["m", 0, -ry], ["a", rx, ry, 0, 1, 1, 0, 2 * ry], ["a", rx, ry, 0, 1, 1, 0, -2 * ry], ["z"]];
  375. },
  376. getPath = R._getPath = {
  377. path: function (el) {
  378. return el.attr("path");
  379. },
  380. circle: function (el) {
  381. var a = el.attrs;
  382. return ellipsePath(a.cx, a.cy, a.r);
  383. },
  384. ellipse: function (el) {
  385. var a = el.attrs;
  386. return ellipsePath(a.cx, a.cy, a.rx, a.ry);
  387. },
  388. rect: function (el) {
  389. var a = el.attrs;
  390. return rectPath(a.x, a.y, a.width, a.height, a.r);
  391. },
  392. image: function (el) {
  393. var a = el.attrs;
  394. return rectPath(a.x, a.y, a.width, a.height);
  395. },
  396. text: function (el) {
  397. var bbox = el._getBBox();
  398. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  399. },
  400. set : function(el) {
  401. var bbox = el._getBBox();
  402. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  403. }
  404. },
  405. /*\
  406. * Raphael.mapPath
  407. [ method ]
  408. **
  409. * Transform the path string with given matrix.
  410. > Parameters
  411. - path (string) path string
  412. - matrix (object) see @Matrix
  413. = (string) transformed path string
  414. \*/
  415. mapPath = R.mapPath = function (path, matrix) {
  416. if (!matrix) {
  417. return path;
  418. }
  419. var x, y, i, j, ii, jj, pathi;
  420. path = path2curve(path);
  421. for (i = 0, ii = path.length; i < ii; i++) {
  422. pathi = path[i];
  423. for (j = 1, jj = pathi.length; j < jj; j += 2) {
  424. x = matrix.x(pathi[j], pathi[j + 1]);
  425. y = matrix.y(pathi[j], pathi[j + 1]);
  426. pathi[j] = x;
  427. pathi[j + 1] = y;
  428. }
  429. }
  430. return path;
  431. };
  432. R._g = g;
  433. /*\
  434. * Raphael.type
  435. [ property (string) ]
  436. **
  437. * Can be “SVG”, “VML” or empty, depending on browser support.
  438. \*/
  439. R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
  440. if (R.type == "VML") {
  441. var d = g.doc.createElement("div"),
  442. b;
  443. d.innerHTML = '<v:shape adj="1"/>';
  444. b = d.firstChild;
  445. b.style.behavior = "url(#default#VML)";
  446. if (!(b && typeof b.adj == "object")) {
  447. return (R.type = E);
  448. }
  449. d = null;
  450. }
  451. /*\
  452. * Raphael.svg
  453. [ property (boolean) ]
  454. **
  455. * `true` if browser supports SVG.
  456. \*/
  457. /*\
  458. * Raphael.vml
  459. [ property (boolean) ]
  460. **
  461. * `true` if browser supports VML.
  462. \*/
  463. R.svg = !(R.vml = R.type == "VML");
  464. R._Paper = Paper;
  465. /*\
  466. * Raphael.fn
  467. [ property (object) ]
  468. **
  469. * You can add your own method to the canvas. For example if you want to draw a pie chart,
  470. * you can create your own pie chart function and ship it as a Raphaël plugin. To do this
  471. * you need to extend the `Raphael.fn` object. You should modify the `fn` object before a
  472. * Raphaël instance is created, otherwise it will take no effect. Please note that the
  473. * ability for namespaced plugins was removed in Raphael 2.0. It is up to the plugin to
  474. * ensure any namespacing ensures proper context.
  475. > Usage
  476. | Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
  477. | return this.path( ... );
  478. | };
  479. | // or create namespace
  480. | Raphael.fn.mystuff = {
  481. | arrow: function () {…},
  482. | star: function () {…},
  483. | // etc…
  484. | };
  485. | var paper = Raphael(10, 10, 630, 480);
  486. | // then use it
  487. | paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
  488. | paper.mystuff.arrow();
  489. | paper.mystuff.star();
  490. \*/
  491. R.fn = paperproto = Paper.prototype = R.prototype;
  492. R._id = 0;
  493. /*\
  494. * Raphael.is
  495. [ method ]
  496. **
  497. * Handful of replacements for `typeof` operator.
  498. > Parameters
  499. - o (…) any object or primitive
  500. - type (string) name of the type, i.e. “string”, “function”, “number”, etc.
  501. = (boolean) is given value is of given type
  502. \*/
  503. R.is = function (o, type) {
  504. type = lowerCase.call(type);
  505. if (type == "finite") {
  506. return !isnan[has](+o);
  507. }
  508. if (type == "array") {
  509. return o instanceof Array;
  510. }
  511. return (type == "null" && o === null) ||
  512. (type == typeof o && o !== null) ||
  513. (type == "object" && o === Object(o)) ||
  514. (type == "array" && Array.isArray && Array.isArray(o)) ||
  515. objectToString.call(o).slice(8, -1).toLowerCase() == type;
  516. };
  517. function clone(obj) {
  518. if (typeof obj == "function" || Object(obj) !== obj) {
  519. return obj;
  520. }
  521. var res = new obj.constructor;
  522. for (var key in obj) if (obj[has](key)) {
  523. res[key] = clone(obj[key]);
  524. }
  525. return res;
  526. }
  527. /*\
  528. * Raphael.angle
  529. [ method ]
  530. **
  531. * Returns angle between two or three points
  532. > Parameters
  533. - x1 (number) x coord of first point
  534. - y1 (number) y coord of first point
  535. - x2 (number) x coord of second point
  536. - y2 (number) y coord of second point
  537. - x3 (number) #optional x coord of third point
  538. - y3 (number) #optional y coord of third point
  539. = (number) angle in degrees.
  540. \*/
  541. R.angle = function (x1, y1, x2, y2, x3, y3) {
  542. if (x3 == null) {
  543. var x = x1 - x2,
  544. y = y1 - y2;
  545. if (!x && !y) {
  546. return 0;
  547. }
  548. return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
  549. } else {
  550. return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
  551. }
  552. };
  553. /*\
  554. * Raphael.rad
  555. [ method ]
  556. **
  557. * Transform angle to radians
  558. > Parameters
  559. - deg (number) angle in degrees
  560. = (number) angle in radians.
  561. \*/
  562. R.rad = function (deg) {
  563. return deg % 360 * PI / 180;
  564. };
  565. /*\
  566. * Raphael.deg
  567. [ method ]
  568. **
  569. * Transform angle to degrees
  570. > Parameters
  571. - rad (number) angle in radians
  572. = (number) angle in degrees.
  573. \*/
  574. R.deg = function (rad) {
  575. return Math.round ((rad * 180 / PI% 360)* 1000) / 1000;
  576. };
  577. /*\
  578. * Raphael.snapTo
  579. [ method ]
  580. **
  581. * Snaps given value to given grid.
  582. > Parameters
  583. - values (array|number) given array of values or step of the grid
  584. - value (number) value to adjust
  585. - tolerance (number) #optional tolerance for snapping. Default is `10`.
  586. = (number) adjusted value.
  587. \*/
  588. R.snapTo = function (values, value, tolerance) {
  589. tolerance = R.is(tolerance, "finite") ? tolerance : 10;
  590. if (R.is(values, array)) {
  591. var i = values.length;
  592. while (i--) if (abs(values[i] - value) <= tolerance) {
  593. return values[i];
  594. }
  595. } else {
  596. values = +values;
  597. var rem = value % values;
  598. if (rem < tolerance) {
  599. return value - rem;
  600. }
  601. if (rem > values - tolerance) {
  602. return value - rem + values;
  603. }
  604. }
  605. return value;
  606. };
  607. /*\
  608. * Raphael.createUUID
  609. [ method ]
  610. **
  611. * Returns RFC4122, version 4 ID
  612. \*/
  613. var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) {
  614. return function () {
  615. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
  616. };
  617. })(/[xy]/g, function (c) {
  618. var r = math.random() * 16 | 0,
  619. v = c == "x" ? r : (r & 3 | 8);
  620. return v.toString(16);
  621. });
  622. /*\
  623. * Raphael.setWindow
  624. [ method ]
  625. **
  626. * Used when you need to draw in `&lt;iframe>`. Switched window to the iframe one.
  627. > Parameters
  628. - newwin (window) new window object
  629. \*/
  630. R.setWindow = function (newwin) {
  631. eve("raphael.setWindow", R, g.win, newwin);
  632. g.win = newwin;
  633. g.doc = g.win.document;
  634. if (R._engine.initWin) {
  635. R._engine.initWin(g.win);
  636. }
  637. };
  638. var toHex = function (color) {
  639. if (R.vml) {
  640. // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
  641. var trim = /^\s+|\s+$/g;
  642. var bod;
  643. try {
  644. var docum = new ActiveXObject("htmlfile");
  645. docum.write("<body>");
  646. docum.close();
  647. bod = docum.body;
  648. } catch(e) {
  649. bod = createPopup().document.body;
  650. }
  651. var range = bod.createTextRange();
  652. toHex = cacher(function (color) {
  653. try {
  654. bod.style.color = Str(color).replace(trim, E);
  655. var value = range.queryCommandValue("ForeColor");
  656. value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
  657. return "#" + ("000000" + value.toString(16)).slice(-6);
  658. } catch(e) {
  659. return "none";
  660. }
  661. });
  662. } else {
  663. var i = g.doc.createElement("i");
  664. i.title = "Rapha\xebl Colour Picker";
  665. i.style.display = "none";
  666. g.doc.body.appendChild(i);
  667. toHex = cacher(function (color) {
  668. i.style.color = color;
  669. return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
  670. });
  671. }
  672. return toHex(color);
  673. },
  674. hsbtoString = function () {
  675. return "hsb(" + [this.h, this.s, this.b] + ")";
  676. },
  677. hsltoString = function () {
  678. return "hsl(" + [this.h, this.s, this.l] + ")";
  679. },
  680. rgbtoString = function () {
  681. return this.hex;
  682. },
  683. prepareRGB = function (r, g, b) {
  684. if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
  685. b = r.b;
  686. g = r.g;
  687. r = r.r;
  688. }
  689. if (g == null && R.is(r, string)) {
  690. var clr = R.getRGB(r);
  691. r = clr.r;
  692. g = clr.g;
  693. b = clr.b;
  694. }
  695. if (r > 1 || g > 1 || b > 1) {
  696. r /= 255;
  697. g /= 255;
  698. b /= 255;
  699. }
  700. return [r, g, b];
  701. },
  702. packageRGB = function (r, g, b, o) {
  703. r *= 255;
  704. g *= 255;
  705. b *= 255;
  706. var rgb = {
  707. r: r,
  708. g: g,
  709. b: b,
  710. hex: R.rgb(r, g, b),
  711. toString: rgbtoString
  712. };
  713. R.is(o, "finite") && (rgb.opacity = o);
  714. return rgb;
  715. };
  716. /*\
  717. * Raphael.color
  718. [ method ]
  719. **
  720. * Parses the color string and returns object with all values for the given color.
  721. > Parameters
  722. - clr (string) color string in one of the supported formats (see @Raphael.getRGB)
  723. = (object) Combined RGB & HSB object in format:
  724. o {
  725. o r (number) red,
  726. o g (number) green,
  727. o b (number) blue,
  728. o hex (string) color in HTML/CSS format: #••••••,
  729. o error (boolean) `true` if string can’t be parsed,
  730. o h (number) hue,
  731. o s (number) saturation,
  732. o v (number) value (brightness),
  733. o l (number) lightness
  734. o }
  735. \*/
  736. R.color = function (clr) {
  737. var rgb;
  738. if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
  739. rgb = R.hsb2rgb(clr);
  740. clr.r = rgb.r;
  741. clr.g = rgb.g;
  742. clr.b = rgb.b;
  743. clr.hex = rgb.hex;
  744. } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
  745. rgb = R.hsl2rgb(clr);
  746. clr.r = rgb.r;
  747. clr.g = rgb.g;
  748. clr.b = rgb.b;
  749. clr.hex = rgb.hex;
  750. } else {
  751. if (R.is(clr, "string")) {
  752. clr = R.getRGB(clr);
  753. }
  754. if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
  755. rgb = R.rgb2hsl(clr);
  756. clr.h = rgb.h;
  757. clr.s = rgb.s;
  758. clr.l = rgb.l;
  759. rgb = R.rgb2hsb(clr);
  760. clr.v = rgb.b;
  761. } else {
  762. clr = {hex: "none"};
  763. clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
  764. }
  765. }
  766. clr.toString = rgbtoString;
  767. return clr;
  768. };
  769. /*\
  770. * Raphael.hsb2rgb
  771. [ method ]
  772. **
  773. * Converts HSB values to RGB object.
  774. > Parameters
  775. - h (number) hue
  776. - s (number) saturation
  777. - v (number) value or brightness
  778. = (object) RGB object in format:
  779. o {
  780. o r (number) red,
  781. o g (number) green,
  782. o b (number) blue,
  783. o hex (string) color in HTML/CSS format: #••••••
  784. o }
  785. \*/
  786. R.hsb2rgb = function (h, s, v, o) {
  787. if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
  788. v = h.b;
  789. s = h.s;
  790. o = h.o;
  791. h = h.h;
  792. }
  793. h *= 360;
  794. var R, G, B, X, C;
  795. h = (h % 360) / 60;
  796. C = v * s;
  797. X = C * (1 - abs(h % 2 - 1));
  798. R = G = B = v - C;
  799. h = ~~h;
  800. R += [C, X, 0, 0, X, C][h];
  801. G += [X, C, C, X, 0, 0][h];
  802. B += [0, 0, X, C, C, X][h];
  803. return packageRGB(R, G, B, o);
  804. };
  805. /*\
  806. * Raphael.hsl2rgb
  807. [ method ]
  808. **
  809. * Converts HSL values to RGB object.
  810. > Parameters
  811. - h (number) hue
  812. - s (number) saturation
  813. - l (number) luminosity
  814. = (object) RGB object in format:
  815. o {
  816. o r (number) red,
  817. o g (number) green,
  818. o b (number) blue,
  819. o hex (string) color in HTML/CSS format: #••••••
  820. o }
  821. \*/
  822. R.hsl2rgb = function (h, s, l, o) {
  823. if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
  824. l = h.l;
  825. s = h.s;
  826. h = h.h;
  827. }
  828. if (h > 1 || s > 1 || l > 1) {
  829. h /= 360;
  830. s /= 100;
  831. l /= 100;
  832. }
  833. h *= 360;
  834. var R, G, B, X, C;
  835. h = (h % 360) / 60;
  836. C = 2 * s * (l < .5 ? l : 1 - l);
  837. X = C * (1 - abs(h % 2 - 1));
  838. R = G = B = l - C / 2;
  839. h = ~~h;
  840. R += [C, X, 0, 0, X, C][h];
  841. G += [X, C, C, X, 0, 0][h];
  842. B += [0, 0, X, C, C, X][h];
  843. return packageRGB(R, G, B, o);
  844. };
  845. /*\
  846. * Raphael.rgb2hsb
  847. [ method ]
  848. **
  849. * Converts RGB values to HSB object.
  850. > Parameters
  851. - r (number) red
  852. - g (number) green
  853. - b (number) blue
  854. = (object) HSB object in format:
  855. o {
  856. o h (number) hue
  857. o s (number) saturation
  858. o b (number) brightness
  859. o }
  860. \*/
  861. R.rgb2hsb = function (r, g, b) {
  862. b = prepareRGB(r, g, b);
  863. r = b[0];
  864. g = b[1];
  865. b = b[2];
  866. var H, S, V, C;
  867. V = mmax(r, g, b);
  868. C = V - mmin(r, g, b);
  869. H = (C == 0 ? null :
  870. V == r ? (g - b) / C :
  871. V == g ? (b - r) / C + 2 :
  872. (r - g) / C + 4
  873. );
  874. H = ((H + 360) % 6) * 60 / 360;
  875. S = C == 0 ? 0 : C / V;
  876. return {h: H, s: S, b: V, toString: hsbtoString};
  877. };
  878. /*\
  879. * Raphael.rgb2hsl
  880. [ method ]
  881. **
  882. * Converts RGB values to HSL object.
  883. > Parameters
  884. - r (number) red
  885. - g (number) green
  886. - b (number) blue
  887. = (object) HSL object in format:
  888. o {
  889. o h (number) hue
  890. o s (number) saturation
  891. o l (number) luminosity
  892. o }
  893. \*/
  894. R.rgb2hsl = function (r, g, b) {
  895. b = prepareRGB(r, g, b);
  896. r = b[0];
  897. g = b[1];
  898. b = b[2];
  899. var H, S, L, M, m, C;
  900. M = mmax(r, g, b);
  901. m = mmin(r, g, b);
  902. C = M - m;
  903. H = (C == 0 ? null :
  904. M == r ? (g - b) / C :
  905. M == g ? (b - r) / C + 2 :
  906. (r - g) / C + 4);
  907. H = ((H + 360) % 6) * 60 / 360;
  908. L = (M + m) / 2;
  909. S = (C == 0 ? 0 :
  910. L < .5 ? C / (2 * L) :
  911. C / (2 - 2 * L));
  912. return {h: H, s: S, l: L, toString: hsltoString};
  913. };
  914. R._path2string = function () {
  915. return this.join(",").replace(p2s, "$1");
  916. };
  917. function repush(array, item) {
  918. for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
  919. return array.push(array.splice(i, 1)[0]);
  920. }
  921. }
  922. function cacher(f, scope, postprocessor) {
  923. function newf() {
  924. var arg = Array.prototype.slice.call(arguments, 0),
  925. args = arg.join("\u2400"),
  926. cache = newf.cache = newf.cache || {},
  927. count = newf.count = newf.count || [];
  928. if (cache[has](args)) {
  929. repush(count, args);
  930. return postprocessor ? postprocessor(cache[args]) : cache[args];
  931. }
  932. count.length >= 1e3 && delete cache[count.shift()];
  933. count.push(args);
  934. cache[args] = f[apply](scope, arg);
  935. return postprocessor ? postprocessor(cache[args]) : cache[args];
  936. }
  937. return newf;
  938. }
  939. var preload = R._preload = function (src, f) {
  940. var img = g.doc.createElement("img");
  941. img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
  942. img.onload = function () {
  943. f.call(this);
  944. this.onload = null;
  945. g.doc.body.removeChild(this);
  946. };
  947. img.onerror = function () {
  948. g.doc.body.removeChild(this);
  949. };
  950. g.doc.body.appendChild(img);
  951. img.src = src;
  952. };
  953. function clrToString() {
  954. return this.hex;
  955. }
  956. /*\
  957. * Raphael.getRGB
  958. [ method ]
  959. **
  960. * Parses colour string as RGB object
  961. > Parameters
  962. - colour (string) colour string in one of formats:
  963. # <ul>
  964. # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
  965. # <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
  966. # <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
  967. # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
  968. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
  969. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
  970. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  971. # <li>hsl(•••, •••, •••) — same as hsb</li>
  972. # <li>hsl(•••%, •••%, •••%) — same as hsb</li>
  973. # </ul>
  974. = (object) RGB object in format:
  975. o {
  976. o r (number) red,
  977. o g (number) green,
  978. o b (number) blue
  979. o hex (string) color in HTML/CSS format: #••••••,
  980. o error (boolean) true if string can’t be parsed
  981. o }
  982. \*/
  983. R.getRGB = cacher(function (colour) {
  984. if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
  985. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  986. }
  987. if (colour == "none") {
  988. return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
  989. }
  990. !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  991. var res,
  992. red,
  993. green,
  994. blue,
  995. opacity,
  996. t,
  997. values,
  998. rgb = colour.match(colourRegExp);
  999. if (rgb) {
  1000. if (rgb[2]) {
  1001. blue = toInt(rgb[2].substring(5), 16);
  1002. green = toInt(rgb[2].substring(3, 5), 16);
  1003. red = toInt(rgb[2].substring(1, 3), 16);
  1004. }
  1005. if (rgb[3]) {
  1006. blue = toInt((t = rgb[3].charAt(3)) + t, 16);
  1007. green = toInt((t = rgb[3].charAt(2)) + t, 16);
  1008. red = toInt((t = rgb[3].charAt(1)) + t, 16);
  1009. }
  1010. if (rgb[4]) {
  1011. values = rgb[4][split](commaSpaces);
  1012. red = toFloat(values[0]);
  1013. values[0].slice(-1) == "%" && (red *= 2.55);
  1014. green = toFloat(values[1]);
  1015. values[1].slice(-1) == "%" && (green *= 2.55);
  1016. blue = toFloat(values[2]);
  1017. values[2].slice(-1) == "%" && (blue *= 2.55);
  1018. rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
  1019. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1020. }
  1021. if (rgb[5]) {
  1022. values = rgb[5][split](commaSpaces);
  1023. red = toFloat(values[0]);
  1024. values[0].slice(-1) == "%" && (red *= 2.55);
  1025. green = toFloat(values[1]);
  1026. values[1].slice(-1) == "%" && (green *= 2.55);
  1027. blue = toFloat(values[2]);
  1028. values[2].slice(-1) == "%" && (blue *= 2.55);
  1029. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1030. rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
  1031. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1032. return R.hsb2rgb(red, green, blue, opacity);
  1033. }
  1034. if (rgb[6]) {
  1035. values = rgb[6][split](commaSpaces);
  1036. red = toFloat(values[0]);
  1037. values[0].slice(-1) == "%" && (red *= 2.55);
  1038. green = toFloat(values[1]);
  1039. values[1].slice(-1) == "%" && (green *= 2.55);
  1040. blue = toFloat(values[2]);
  1041. values[2].slice(-1) == "%" && (blue *= 2.55);
  1042. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1043. rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
  1044. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1045. return R.hsl2rgb(red, green, blue, opacity);
  1046. }
  1047. rgb = {r: red, g: green, b: blue, toString: clrToString};
  1048. rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
  1049. R.is(opacity, "finite") && (rgb.opacity = opacity);
  1050. return rgb;
  1051. }
  1052. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  1053. }, R);
  1054. /*\
  1055. * Raphael.hsb
  1056. [ method ]
  1057. **
  1058. * Converts HSB values to hex representation of the colour.
  1059. > Parameters
  1060. - h (number) hue
  1061. - s (number) saturation
  1062. - b (number) value or brightness
  1063. = (string) hex representation of the colour.
  1064. \*/
  1065. R.hsb = cacher(function (h, s, b) {
  1066. return R.hsb2rgb(h, s, b).hex;
  1067. });
  1068. /*\
  1069. * Raphael.hsl
  1070. [ method ]
  1071. **
  1072. * Converts HSL values to hex representation of the colour.
  1073. > Parameters
  1074. - h (number) hue
  1075. - s (number) saturation
  1076. - l (number) luminosity
  1077. = (string) hex representation of the colour.
  1078. \*/
  1079. R.hsl = cacher(function (h, s, l) {
  1080. return R.hsl2rgb(h, s, l).hex;
  1081. });
  1082. /*\
  1083. * Raphael.rgb
  1084. [ method ]
  1085. **
  1086. * Converts RGB values to hex representation of the colour.
  1087. > Parameters
  1088. - r (number) red
  1089. - g (number) green
  1090. - b (number) blue
  1091. = (string) hex representation of the colour.
  1092. \*/
  1093. R.rgb = cacher(function (r, g, b) {
  1094. function round(x) { return (x + 0.5) | 0; }
  1095. return "#" + (16777216 | round(b) | (round(g) << 8) | (round(r) << 16)).toString(16).slice(1);
  1096. });
  1097. /*\
  1098. * Raphael.getColor
  1099. [ method ]
  1100. **
  1101. * On each call returns next colour in the spectrum. To reset it back to red call @Raphael.getColor.reset
  1102. > Parameters
  1103. - value (number) #optional brightness, default is `0.75`
  1104. = (string) hex representation of the colour.
  1105. \*/
  1106. R.getColor = function (value) {
  1107. var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
  1108. rgb = this.hsb2rgb(start.h, start.s, start.b);
  1109. start.h += .075;
  1110. if (start.h > 1) {
  1111. start.h = 0;
  1112. start.s -= .2;
  1113. start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
  1114. }
  1115. return rgb.hex;
  1116. };
  1117. /*\
  1118. * Raphael.getColor.reset
  1119. [ method ]
  1120. **
  1121. * Resets spectrum position for @Raphael.getColor back to red.
  1122. \*/
  1123. R.getColor.reset = function () {
  1124. delete this.start;
  1125. };
  1126. // http://schepers.cc/getting-to-the-point
  1127. function catmullRom2bezier(crp, z) {
  1128. var d = [];
  1129. for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
  1130. var p = [
  1131. {x: +crp[i - 2], y: +crp[i - 1]},
  1132. {x: +crp[i], y: +crp[i + 1]},
  1133. {x: +crp[i + 2], y: +crp[i + 3]},
  1134. {x: +crp[i + 4], y: +crp[i + 5]}
  1135. ];
  1136. if (z) {
  1137. if (!i) {
  1138. p[0] = {x: +crp[iLen - 2], y: +crp[iLen - 1]};
  1139. } else if (iLen - 4 == i) {
  1140. p[3] = {x: +crp[0], y: +crp[1]};
  1141. } else if (iLen - 2 == i) {
  1142. p[2] = {x: +crp[0], y: +crp[1]};
  1143. p[3] = {x: +crp[2], y: +crp[3]};
  1144. }
  1145. } else {
  1146. if (iLen - 4 == i) {
  1147. p[3] = p[2];
  1148. } else if (!i) {
  1149. p[0] = {x: +crp[i], y: +crp[i + 1]};
  1150. }
  1151. }
  1152. d.push(["C",
  1153. (-p[0].x + 6 * p[1].x + p[2].x) / 6,
  1154. (-p[0].y + 6 * p[1].y + p[2].y) / 6,
  1155. (p[1].x + 6 * p[2].x - p[3].x) / 6,
  1156. (p[1].y + 6*p[2].y - p[3].y) / 6,
  1157. p[2].x,
  1158. p[2].y
  1159. ]);
  1160. }
  1161. return d;
  1162. }
  1163. /*\
  1164. * Raphael.parsePathString
  1165. [ method ]
  1166. **
  1167. * Utility method
  1168. **
  1169. * Parses given path string into an array of arrays of path segments.
  1170. > Parameters
  1171. - pathString (string|array) path string or array of segments (in the last case it will be returned straight away)
  1172. = (array) array of segments.
  1173. \*/
  1174. R.parsePathString = function (pathString) {
  1175. if (!pathString) {
  1176. return null;
  1177. }
  1178. var pth = paths(pathString);
  1179. if (pth.arr) {
  1180. return pathClone(pth.arr);
  1181. }
  1182. var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
  1183. data = [];
  1184. if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
  1185. data = pathClone(pathString);
  1186. }
  1187. if (!data.length) {
  1188. Str(pathString).replace(pathCommand, function (a, b, c) {
  1189. var params = [],
  1190. name = b.toLowerCase();
  1191. c.replace(pathValues, function (a, b) {
  1192. b && params.push(+b);
  1193. });
  1194. if (name == "m" && params.length > 2) {
  1195. data.push([b][concat](params.splice(0, 2)));
  1196. name = "l";
  1197. b = b == "m" ? "l" : "L";
  1198. }
  1199. if (name == "r") {
  1200. data.push([b][concat](params));
  1201. } else while (params.length >= paramCounts[name]) {
  1202. data.push([b][concat](params.splice(0, paramCounts[name])));
  1203. if (!paramCounts[name]) {
  1204. break;
  1205. }
  1206. }
  1207. });
  1208. }
  1209. data.toString = R._path2string;
  1210. pth.arr = pathClone(data);
  1211. return data;
  1212. };
  1213. /*\
  1214. * Raphael.parseTransformString
  1215. [ method ]
  1216. **
  1217. * Utility method
  1218. **
  1219. * Parses given path string into an array of transformations.
  1220. > Parameters
  1221. - TString (string|array) transform string or array of transformations (in the last case it will be returned straight away)
  1222. = (array) array of transformations.
  1223. \*/
  1224. R.parseTransformString = cacher(function (TString) {
  1225. if (!TString) {
  1226. return null;
  1227. }
  1228. var paramCounts = {r: 3, s: 4, t: 2, m: 6},
  1229. data = [];
  1230. if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
  1231. data = pathClone(TString);
  1232. }
  1233. if (!data.length) {
  1234. Str(TString).replace(tCommand, function (a, b, c) {
  1235. var params = [],
  1236. name = lowerCase.call(b);
  1237. c.replace(pathValues, function (a, b) {
  1238. b && params.push(+b);
  1239. });
  1240. data.push([b][concat](params));
  1241. });
  1242. }
  1243. data.toString = R._path2string;
  1244. return data;
  1245. }, this, function(elem) {
  1246. if (!elem) return elem;
  1247. var newData = [];
  1248. for (var i = 0; i < elem.length; i++) {
  1249. var newLevel = [];
  1250. for (var j = 0; j < elem[i].length; j++) {
  1251. newLevel.push(elem[i][j]);
  1252. }
  1253. newData.push(newLevel);
  1254. }
  1255. return newData; } );
  1256. // PATHS
  1257. var paths = function (ps) {
  1258. var p = paths.ps = paths.ps || {};
  1259. if (p[ps]) {
  1260. p[ps].sleep = 100;
  1261. } else {
  1262. p[ps] = {
  1263. sleep: 100
  1264. };
  1265. }
  1266. setTimeout(function () {
  1267. for (var key in p) if (p[has](key) && key != ps) {
  1268. p[key].sleep--;
  1269. !p[key].sleep && delete p[key];
  1270. }
  1271. });
  1272. return p[ps];
  1273. };
  1274. /*\
  1275. * Raphael.findDotsAtSegment
  1276. [ method ]
  1277. **
  1278. * Utility method
  1279. **
  1280. * Find dot coordinates on the given cubic bezier curve at the given t.
  1281. > Parameters
  1282. - p1x (number) x of the first point of the curve
  1283. - p1y (number) y of the first point of the curve
  1284. - c1x (number) x of the first anchor of the curve
  1285. - c1y (number) y of the first anchor of the curve
  1286. - c2x (number) x of the second anchor of the curve
  1287. - c2y (number) y of the second anchor of the curve
  1288. - p2x (number) x of the second point of the curve
  1289. - p2y (number) y of the second point of the curve
  1290. - t (number) position on the curve (0..1)
  1291. = (object) point information in format:
  1292. o {
  1293. o x: (number) x coordinate of the point
  1294. o y: (number) y coordinate of the point
  1295. o m: {
  1296. o x: (number) x coordinate of the left anchor
  1297. o y: (number) y coordinate of the left anchor
  1298. o }
  1299. o n: {
  1300. o x: (number) x coordinate of the right anchor
  1301. o y: (number) y coordinate of the right anchor
  1302. o }
  1303. o start: {
  1304. o x: (number) x coordinate of the start of the curve
  1305. o y: (number) y coordinate of the start of the curve
  1306. o }
  1307. o end: {
  1308. o x: (number) x coordinate of the end of the curve
  1309. o y: (number) y coordinate of the end of the curve
  1310. o }
  1311. o alpha: (number) angle of the curve derivative at the point
  1312. o }
  1313. \*/
  1314. R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  1315. var t1 = 1 - t,
  1316. t13 = pow(t1, 3),
  1317. t12 = pow(t1, 2),
  1318. t2 = t * t,
  1319. t3 = t2 * t,
  1320. x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
  1321. y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
  1322. mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
  1323. my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
  1324. nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
  1325. ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
  1326. ax = t1 * p1x + t * c1x,
  1327. ay = t1 * p1y + t * c1y,
  1328. cx = t1 * c2x + t * p2x,
  1329. cy = t1 * c2y + t * p2y,
  1330. alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
  1331. (mx > nx || my < ny) && (alpha += 180);
  1332. return {
  1333. x: x,
  1334. y: y,
  1335. m: {x: mx, y: my},
  1336. n: {x: nx, y: ny},
  1337. start: {x: ax, y: ay},
  1338. end: {x: cx, y: cy},
  1339. alpha: alpha
  1340. };
  1341. };
  1342. /*\
  1343. * Raphael.bezierBBox
  1344. [ method ]
  1345. **
  1346. * Utility method
  1347. **
  1348. * Return bounding box of a given cubic bezier curve
  1349. > Parameters
  1350. - p1x (number) x of the first point of the curve
  1351. - p1y (number) y of the first point of the curve
  1352. - c1x (number) x of the first anchor of the curve
  1353. - c1y (number) y of the first anchor of the curve
  1354. - c2x (number) x of the second anchor of the curve
  1355. - c2y (number) y of the second anchor of the curve
  1356. - p2x (number) x of the second point of the curve
  1357. - p2y (number) y of the second point of the curve
  1358. * or
  1359. - bez (array) array of six points for bezier curve
  1360. = (object) point information in format:
  1361. o {
  1362. o min: {
  1363. o x: (number) x coordinate of the left point
  1364. o y: (number) y coordinate of the top point
  1365. o }
  1366. o max: {
  1367. o x: (number) x coordinate of the right point
  1368. o y: (number) y coordinate of the bottom point
  1369. o }
  1370. o }
  1371. \*/
  1372. R.bezierBBox = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  1373. if (!R.is(p1x, "array")) {
  1374. p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
  1375. }
  1376. var bbox = curveDim.apply(null, p1x);
  1377. return {
  1378. x: bbox.min.x,
  1379. y: bbox.min.y,
  1380. x2: bbox.max.x,
  1381. y2: bbox.max.y,
  1382. width: bbox.max.x - bbox.min.x,
  1383. height: bbox.max.y - bbox.min.y
  1384. };
  1385. };
  1386. /*\
  1387. * Raphael.isPointInsideBBox
  1388. [ method ]
  1389. **
  1390. * Utility method
  1391. **
  1392. * Returns `true` if given point is inside bounding boxes.
  1393. > Parameters
  1394. - bbox (string) bounding box
  1395. - x (string) x coordinate of the point
  1396. - y (string) y coordinate of the point
  1397. = (boolean) `true` if point inside
  1398. \*/
  1399. R.isPointInsideBBox = function (bbox, x, y) {
  1400. return x >= bbox.x && x <= bbox.x2 && y >= bbox.y && y <= bbox.y2;
  1401. };
  1402. /*\
  1403. * Raphael.isBBoxIntersect
  1404. [ method ]
  1405. **
  1406. * Utility method
  1407. **
  1408. * Returns `true` if two bounding boxes intersect
  1409. > Parameters
  1410. - bbox1 (string) first bounding box
  1411. - bbox2 (string) second bounding box
  1412. = (boolean) `true` if they intersect
  1413. \*/
  1414. R.isBBoxIntersect = function (bbox1, bbox2) {
  1415. var i = R.isPointInsideBBox;
  1416. return i(bbox2, bbox1.x, bbox1.y)
  1417. || i(bbox2, bbox1.x2, bbox1.y)
  1418. || i(bbox2, bbox1.x, bbox1.y2)
  1419. || i(bbox2, bbox1.x2, bbox1.y2)
  1420. || i(bbox1, bbox2.x, bbox2.y)
  1421. || i(bbox1, bbox2.x2, bbox2.y)
  1422. || i(bbox1, bbox2.x, bbox2.y2)
  1423. || i(bbox1, bbox2.x2, bbox2.y2)
  1424. || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
  1425. && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
  1426. };
  1427. function base3(t, p1, p2, p3, p4) {
  1428. var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
  1429. t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
  1430. return t * t2 - 3 * p1 + 3 * p2;
  1431. }
  1432. function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
  1433. if (z == null) {
  1434. z = 1;
  1435. }
  1436. z = z > 1 ? 1 : z < 0 ? 0 : z;
  1437. var z2 = z / 2,
  1438. n = 12,
  1439. Tvalues = [-0.1252,0.1252,-0.3678,0.3678,-0.5873,0.5873,-0.7699,0.7699,-0.9041,0.9041,-0.9816,0.9816],
  1440. Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472],
  1441. sum = 0;
  1442. for (var i = 0; i < n; i++) {
  1443. var ct = z2 * Tvalues[i] + z2,
  1444. xbase = base3(ct, x1, x2, x3, x4),
  1445. ybase = base3(ct, y1, y2, y3, y4),
  1446. comb = xbase * xbase + ybase * ybase;
  1447. sum += Cvalues[i] * math.sqrt(comb);
  1448. }
  1449. return z2 * sum;
  1450. }
  1451. function getTatLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) {
  1452. if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) {
  1453. return;
  1454. }
  1455. var t = 1,
  1456. step = t / 2,
  1457. t2 = t - step,
  1458. l,
  1459. e = .01;
  1460. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1461. while (abs(l - ll) > e) {
  1462. step /= 2;
  1463. t2 += (l < ll ? 1 : -1) * step;
  1464. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1465. }
  1466. return t2;
  1467. }
  1468. function intersect(x1, y1, x2, y2, x3, y3, x4, y4) {
  1469. if (
  1470. mmax(x1, x2) < mmin(x3, x4) ||
  1471. mmin(x1, x2) > mmax(x3, x4) ||
  1472. mmax(y1, y2) < mmin(y3, y4) ||
  1473. mmin(y1, y2) > mmax(y3, y4)
  1474. ) {
  1475. return;
  1476. }
  1477. var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
  1478. ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
  1479. denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  1480. if (!denominator) {
  1481. return;
  1482. }
  1483. var px = nx / denominator,
  1484. py = ny / denominator,
  1485. px2 = +px.toFixed(2),
  1486. py2 = +py.toFixed(2);
  1487. if (
  1488. px2 < +mmin(x1, x2).toFixed(2) ||
  1489. px2 > +mmax(x1, x2).toFixed(2) ||
  1490. px2 < +mmin(x3, x4).toFixed(2) ||
  1491. px2 > +mmax(x3, x4).toFixed(2) ||
  1492. py2 < +mmin(y1, y2).toFixed(2) ||
  1493. py2 > +mmax(y1, y2).toFixed(2) ||
  1494. py2 < +mmin(y3, y4).toFixed(2) ||
  1495. py2 > +mmax(y3, y4).toFixed(2)
  1496. ) {
  1497. return;
  1498. }
  1499. return {x: px, y: py};
  1500. }
  1501. function inter(bez1, bez2) {
  1502. return interHelper(bez1, bez2);
  1503. }
  1504. function interCount(bez1, bez2) {
  1505. return interHelper(bez1, bez2, 1);
  1506. }
  1507. function interHelper(bez1, bez2, justCount) {
  1508. var bbox1 = R.bezierBBox(bez1),
  1509. bbox2 = R.bezierBBox(bez2);
  1510. if (!R.isBBoxIntersect(bbox1, bbox2)) {
  1511. return justCount ? 0 : [];
  1512. }
  1513. var l1 = bezlen.apply(0, bez1),
  1514. l2 = bezlen.apply(0, bez2),
  1515. n1 = mmax(~~(l1 / 5), 1),
  1516. n2 = mmax(~~(l2 / 5), 1),
  1517. dots1 = [],
  1518. dots2 = [],
  1519. xy = {},
  1520. res = justCount ? 0 : [];
  1521. for (var i = 0; i < n1 + 1; i++) {
  1522. var p = R.findDotsAtSegment.apply(R, bez1.concat(i / n1));
  1523. dots1.push({x: p.x, y: p.y, t: i / n1});
  1524. }
  1525. for (i = 0; i < n2 + 1; i++) {
  1526. p = R.findDotsAtSegment.apply(R, bez2.concat(i / n2));
  1527. dots2.push({x: p.x, y: p.y, t: i / n2});
  1528. }
  1529. for (i = 0; i < n1; i++) {
  1530. for (var j = 0; j < n2; j++) {
  1531. var di = dots1[i],
  1532. di1 = dots1[i + 1],
  1533. dj = dots2[j],
  1534. dj1 = dots2[j + 1],
  1535. ci = abs(di1.x - di.x) < .001 ? "y" : "x",
  1536. cj = abs(dj1.x - dj.x) < .001 ? "y" : "x",
  1537. is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
  1538. if (is) {
  1539. if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {
  1540. continue;
  1541. }
  1542. xy[is.x.toFixed(4)] = is.y.toFixed(4);
  1543. var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
  1544. t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
  1545. if (t1 >= 0 && t1 <= 1.001 && t2 >= 0 && t2 <= 1.001) {
  1546. if (justCount) {
  1547. res++;
  1548. } else {
  1549. res.push({
  1550. x: is.x,
  1551. y: is.y,
  1552. t1: mmin(t1, 1),
  1553. t2: mmin(t2, 1)
  1554. });
  1555. }
  1556. }
  1557. }
  1558. }
  1559. }
  1560. return res;
  1561. }
  1562. /*\
  1563. * Raphael.pathIntersection
  1564. [ method ]
  1565. **
  1566. * Utility method
  1567. **
  1568. * Finds intersections of two paths
  1569. > Parameters
  1570. - path1 (string) path string
  1571. - path2 (string) path string
  1572. = (array) dots of intersection
  1573. o [
  1574. o {
  1575. o x: (number) x coordinate of the point
  1576. o y: (number) y coordinate of the point
  1577. o t1: (number) t value for segment of path1
  1578. o t2: (number) t value for segment of path2
  1579. o segment1: (number) order number for segment of path1
  1580. o segment2: (number) order number for segment of path2
  1581. o bez1: (array) eight coordinates representing beziér curve for the segment of path1
  1582. o bez2: (array) eight coordinates representing beziér curve for the segment of path2
  1583. o }
  1584. o ]
  1585. \*/
  1586. R.pathIntersection = function (path1, path2) {
  1587. return interPathHelper(path1, path2);
  1588. };
  1589. R.pathIntersectionNumber = function (path1, path2) {
  1590. return interPathHelper(path1, path2, 1);
  1591. };
  1592. function interPathHelper(path1, path2, justCount) {
  1593. path1 = R._path2curve(path1);
  1594. path2 = R._path2curve(path2);
  1595. var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
  1596. res = justCount ? 0 : [];
  1597. for (var i = 0, ii = path1.length; i < ii; i++) {
  1598. var pi = path1[i];
  1599. if (pi[0] == "M") {
  1600. x1 = x1m = pi[1];
  1601. y1 = y1m = pi[2];
  1602. } else {
  1603. if (pi[0] == "C") {
  1604. bez1 = [x1, y1].concat(pi.slice(1));
  1605. x1 = bez1[6];
  1606. y1 = bez1[7];
  1607. } else {
  1608. bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
  1609. x1 = x1m;
  1610. y1 = y1m;
  1611. }
  1612. for (var j = 0, jj = path2.length; j < jj; j++) {
  1613. var pj = path2[j];
  1614. if (pj[0] == "M") {
  1615. x2 = x2m = pj[1];
  1616. y2 = y2m = pj[2];
  1617. } else {
  1618. if (pj[0] == "C") {
  1619. bez2 = [x2, y2].concat(pj.slice(1));
  1620. x2 = bez2[6];
  1621. y2 = bez2[7];
  1622. } else {
  1623. bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
  1624. x2 = x2m;
  1625. y2 = y2m;
  1626. }
  1627. var intr = interHelper(bez1, bez2, justCount);
  1628. if (justCount) {
  1629. res += intr;
  1630. } else {
  1631. for (var k = 0, kk = intr.length; k < kk; k++) {
  1632. intr[k].segment1 = i;
  1633. intr[k].segment2 = j;
  1634. intr[k].bez1 = bez1;
  1635. intr[k].bez2 = bez2;
  1636. }
  1637. res = res.concat(intr);
  1638. }
  1639. }
  1640. }
  1641. }
  1642. }
  1643. return res;
  1644. }
  1645. /*\
  1646. * Raphael.isPointInsidePath
  1647. [ method ]
  1648. **
  1649. * Utility method
  1650. **
  1651. * Returns `true` if given point is inside a given closed path.
  1652. > Parameters
  1653. - path (string) path string
  1654. - x (number) x of the point
  1655. - y (number) y of the point
  1656. = (boolean) true, if point is inside the path
  1657. \*/
  1658. R.isPointInsidePath = function (path, x, y) {
  1659. var bbox = R.pathBBox(path);
  1660. return R.isPointInsideBBox(bbox, x, y) &&
  1661. interPathHelper(path, [["M", x, y], ["H", bbox.x2 + 10]], 1) % 2 == 1;
  1662. };
  1663. R._removedFactory = function (methodname) {
  1664. return function () {
  1665. eve("raphael.log", null, "Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object", methodname);
  1666. };
  1667. };
  1668. /*\
  1669. * Raphael.pathBBox
  1670. [ method ]
  1671. **
  1672. * Utility method
  1673. **
  1674. * Return bounding box of a given path
  1675. > Parameters
  1676. - path (string) path string
  1677. = (object) bounding box
  1678. o {
  1679. o x: (number) x coordinate of the left top point of the box
  1680. o y: (number) y coordinate of the left top point of the box
  1681. o x2: (number) x coordinate of the right bottom point of the box
  1682. o y2: (number) y coordinate of the right bottom point of the box
  1683. o width: (number) width of the box
  1684. o height: (number) height of the box
  1685. o cx: (number) x coordinate of the center of the box
  1686. o cy: (number) y coordinate of the center of the box
  1687. o }
  1688. \*/
  1689. var pathDimensions = R.pathBBox = function (path) {
  1690. var pth = paths(path);
  1691. if (pth.bbox) {
  1692. return clone(pth.bbox);
  1693. }
  1694. if (!path) {
  1695. return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0};
  1696. }
  1697. path = path2curve(path);
  1698. var x = 0,
  1699. y = 0,
  1700. X = [],
  1701. Y = [],
  1702. p;
  1703. for (var i = 0, ii = path.length; i < ii; i++) {
  1704. p = path[i];
  1705. if (p[0] == "M") {
  1706. x = p[1];
  1707. y = p[2];
  1708. X.push(x);
  1709. Y.push(y);
  1710. } else {
  1711. var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  1712. X = X[concat](dim.min.x, dim.max.x);
  1713. Y = Y[concat](dim.min.y, dim.max.y);
  1714. x = p[5];
  1715. y = p[6];
  1716. }
  1717. }
  1718. var xmin = mmin[apply](0, X),
  1719. ymin = mmin[apply](0, Y),
  1720. xmax = mmax[apply](0, X),
  1721. ymax = mmax[apply](0, Y),
  1722. width = xmax - xmin,
  1723. height = ymax - ymin,
  1724. bb = {
  1725. x: xmin,
  1726. y: ymin,
  1727. x2: xmax,
  1728. y2: ymax,
  1729. width: width,
  1730. height: height,
  1731. cx: xmin + width / 2,
  1732. cy: ymin + height / 2
  1733. };
  1734. pth.bbox = clone(bb);
  1735. return bb;
  1736. },
  1737. pathClone = function (pathArray) {
  1738. var res = clone(pathArray);
  1739. res.toString = R._path2string;
  1740. return res;
  1741. },
  1742. pathToRelative = R._pathToRelative = function (pathArray) {
  1743. var pth = paths(pathArray);
  1744. if (pth.rel) {
  1745. return pathClone(pth.rel);
  1746. }
  1747. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1748. pathArray = R.parsePathString(pathArray);
  1749. }
  1750. var res = [],
  1751. x = 0,
  1752. y = 0,
  1753. mx = 0,
  1754. my = 0,
  1755. start = 0;
  1756. if (pathArray[0][0] == "M") {
  1757. x = pathArray[0][1];
  1758. y = pathArray[0][2];
  1759. mx = x;
  1760. my = y;
  1761. start++;
  1762. res.push(["M", x, y]);
  1763. }
  1764. for (var i = start, ii = pathArray.length; i < ii; i++) {
  1765. var r = res[i] = [],
  1766. pa = pathArray[i];
  1767. if (pa[0] != lowerCase.call(pa[0])) {
  1768. r[0] = lowerCase.call(pa[0]);
  1769. switch (r[0]) {
  1770. case "a":
  1771. r[1] = pa[1];
  1772. r[2] = pa[2];
  1773. r[3] = pa[3];
  1774. r[4] = pa[4];
  1775. r[5] = pa[5];
  1776. r[6] = +(pa[6] - x).toFixed(3);
  1777. r[7] = +(pa[7] - y).toFixed(3);
  1778. break;
  1779. case "v":
  1780. r[1] = +(pa[1] - y).toFixed(3);
  1781. break;
  1782. case "m":
  1783. mx = pa[1];
  1784. my = pa[2];
  1785. default:
  1786. for (var j = 1, jj = pa.length; j < jj; j++) {
  1787. r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
  1788. }
  1789. }
  1790. } else {
  1791. r = res[i] = [];
  1792. if (pa[0] == "m") {
  1793. mx = pa[1] + x;
  1794. my = pa[2] + y;
  1795. }
  1796. for (var k = 0, kk = pa.length; k < kk; k++) {
  1797. res[i][k] = pa[k];
  1798. }
  1799. }
  1800. var len = res[i].length;
  1801. switch (res[i][0]) {
  1802. case "z":
  1803. x = mx;
  1804. y = my;
  1805. break;
  1806. case "h":
  1807. x += +res[i][len - 1];
  1808. break;
  1809. case "v":
  1810. y += +res[i][len - 1];
  1811. break;
  1812. default:
  1813. x += +res[i][len - 2];
  1814. y += +res[i][len - 1];
  1815. }
  1816. }
  1817. res.toString = R._path2string;
  1818. pth.rel = pathClone(res);
  1819. return res;
  1820. },
  1821. pathToAbsolute = R._pathToAbsolute = function (pathArray) {
  1822. var pth = paths(pathArray);
  1823. if (pth.abs) {
  1824. return pathClone(pth.abs);
  1825. }
  1826. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1827. pathArray = R.parsePathString(pathArray);
  1828. }
  1829. if (!pathArray || !pathArray.length) {
  1830. return [["M", 0, 0]];
  1831. }
  1832. var res = [],
  1833. x = 0,
  1834. y = 0,
  1835. mx = 0,
  1836. my = 0,
  1837. start = 0;
  1838. if (pathArray[0][0] == "M") {
  1839. x = +pathArray[0][1];
  1840. y = +pathArray[0][2];
  1841. mx = x;
  1842. my = y;
  1843. start++;
  1844. res[0] = ["M", x, y];
  1845. }
  1846. var crz = pathArray.length == 3 && pathArray[0][0] == "M" && pathArray[1][0].toUpperCase() == "R" && pathArray[2][0].toUpperCase() == "Z";
  1847. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  1848. res.push(r = []);
  1849. pa = pathArray[i];
  1850. if (pa[0] != upperCase.call(pa[0])) {
  1851. r[0] = upperCase.call(pa[0]);
  1852. switch (r[0]) {
  1853. case "A":
  1854. r[1] = pa[1];
  1855. r[2] = pa[2];
  1856. r[3] = pa[3];
  1857. r[4] = pa[4];
  1858. r[5] = pa[5];
  1859. r[6] = +(pa[6] + x);
  1860. r[7] = +(pa[7] + y);
  1861. break;
  1862. case "V":
  1863. r[1] = +pa[1] + y;
  1864. break;
  1865. case "H":
  1866. r[1] = +pa[1] + x;
  1867. break;
  1868. case "R":
  1869. var dots = [x, y][concat](pa.slice(1));
  1870. for (var j = 2, jj = dots.length; j < jj; j++) {
  1871. dots[j] = +dots[j] + x;
  1872. dots[++j] = +dots[j] + y;
  1873. }
  1874. res.pop();
  1875. res = res[concat](catmullRom2bezier(dots, crz));
  1876. break;
  1877. case "M":
  1878. mx = +pa[1] + x;
  1879. my = +pa[2] + y;
  1880. default:
  1881. for (j = 1, jj = pa.length; j < jj; j++) {
  1882. r[j] = +pa[j] + ((j % 2) ? x : y);
  1883. }
  1884. }
  1885. } else if (pa[0] == "R") {
  1886. dots = [x, y][concat](pa.slice(1));
  1887. res.pop();
  1888. res = res[concat](catmullRom2bezier(dots, crz));
  1889. r = ["R"][concat](pa.slice(-2));
  1890. } else {
  1891. for (var k = 0, kk = pa.length; k < kk; k++) {
  1892. r[k] = pa[k];
  1893. }
  1894. }
  1895. switch (r[0]) {
  1896. case "Z":
  1897. x = mx;
  1898. y = my;
  1899. break;
  1900. case "H":
  1901. x = r[1];
  1902. break;
  1903. case "V":
  1904. y = r[1];
  1905. break;
  1906. case "M":
  1907. mx = r[r.length - 2];
  1908. my = r[r.length - 1];
  1909. default:
  1910. x = r[r.length - 2];
  1911. y = r[r.length - 1];
  1912. }
  1913. }
  1914. res.toString = R._path2string;
  1915. pth.abs = pathClone(res);
  1916. return res;
  1917. },
  1918. l2c = function (x1, y1, x2, y2) {
  1919. return [x1, y1, x2, y2, x2, y2];
  1920. },
  1921. q2c = function (x1, y1, ax, ay, x2, y2) {
  1922. var _13 = 1 / 3,
  1923. _23 = 2 / 3;
  1924. return [
  1925. _13 * x1 + _23 * ax,
  1926. _13 * y1 + _23 * ay,
  1927. _13 * x2 + _23 * ax,
  1928. _13 * y2 + _23 * ay,
  1929. x2,
  1930. y2
  1931. ];
  1932. },
  1933. a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  1934. // for more information of where this math came from visit:
  1935. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  1936. var _120 = PI * 120 / 180,
  1937. rad = PI / 180 * (+angle || 0),
  1938. res = [],
  1939. xy,
  1940. rotate = cacher(function (x, y, rad) {
  1941. var X = x * math.cos(rad) - y * math.sin(rad),
  1942. Y = x * math.sin(rad) + y * math.cos(rad);
  1943. return {x: X, y: Y};
  1944. });
  1945. if (!recursive) {
  1946. xy = rotate(x1, y1, -rad);
  1947. x1 = xy.x;
  1948. y1 = xy.y;
  1949. xy = rotate(x2, y2, -rad);
  1950. x2 = xy.x;
  1951. y2 = xy.y;
  1952. var cos = math.cos(PI / 180 * angle),
  1953. sin = math.sin(PI / 180 * angle),
  1954. x = (x1 - x2) / 2,
  1955. y = (y1 - y2) / 2;
  1956. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  1957. if (h > 1) {
  1958. h = math.sqrt(h);
  1959. rx = h * rx;
  1960. ry = h * ry;
  1961. }
  1962. var rx2 = rx * rx,
  1963. ry2 = ry * ry,
  1964. k = (large_arc_flag == sweep_flag ? -1 : 1) *
  1965. math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
  1966. cx = k * rx * y / ry + (x1 + x2) / 2,
  1967. cy = k * -ry * x / rx + (y1 + y2) / 2,
  1968. f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
  1969. f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  1970. f1 = x1 < cx ? PI - f1 : f1;
  1971. f2 = x2 < cx ? PI - f2 : f2;
  1972. f1 < 0 && (f1 = PI * 2 + f1);
  1973. f2 < 0 && (f2 = PI * 2 + f2);
  1974. if (sweep_flag && f1 > f2) {
  1975. f1 = f1 - PI * 2;
  1976. }
  1977. if (!sweep_flag && f2 > f1) {
  1978. f2 = f2 - PI * 2;
  1979. }
  1980. } else {
  1981. f1 = recursive[0];
  1982. f2 = recursive[1];
  1983. cx = recursive[2];
  1984. cy = recursive[3];
  1985. }
  1986. var df = f2 - f1;
  1987. if (abs(df) > _120) {
  1988. var f2old = f2,
  1989. x2old = x2,
  1990. y2old = y2;
  1991. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  1992. x2 = cx + rx * math.cos(f2);
  1993. y2 = cy + ry * math.sin(f2);
  1994. res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  1995. }
  1996. df = f2 - f1;
  1997. var c1 = math.cos(f1),
  1998. s1 = math.sin(f1),
  1999. c2 = math.cos(f2),
  2000. s2 = math.sin(f2),
  2001. t = math.tan(df / 4),
  2002. hx = 4 / 3 * rx * t,
  2003. hy = 4 / 3 * ry * t,
  2004. m1 = [x1, y1],
  2005. m2 = [x1 + hx * s1, y1 - hy * c1],
  2006. m3 = [x2 + hx * s2, y2 - hy * c2],
  2007. m4 = [x2, y2];
  2008. m2[0] = 2 * m1[0] - m2[0];
  2009. m2[1] = 2 * m1[1] - m2[1];
  2010. if (recursive) {
  2011. return [m2, m3, m4][concat](res);
  2012. } else {
  2013. res = [m2, m3, m4][concat](res).join()[split](",");
  2014. var newres = [];
  2015. for (var i = 0, ii = res.length; i < ii; i++) {
  2016. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  2017. }
  2018. return newres;
  2019. }
  2020. },
  2021. findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  2022. var t1 = 1 - t;
  2023. return {
  2024. x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
  2025. y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
  2026. };
  2027. },
  2028. curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  2029. var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
  2030. b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
  2031. c = p1x - c1x,
  2032. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2033. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2034. y = [p1y, p2y],
  2035. x = [p1x, p2x],
  2036. dot;
  2037. abs(t1) > "1e12" && (t1 = .5);
  2038. abs(t2) > "1e12" && (t2 = .5);
  2039. if (t1 > 0 && t1 < 1) {
  2040. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2041. x.push(dot.x);
  2042. y.push(dot.y);
  2043. }
  2044. if (t2 > 0 && t2 < 1) {
  2045. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2046. x.push(dot.x);
  2047. y.push(dot.y);
  2048. }
  2049. a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
  2050. b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
  2051. c = p1y - c1y;
  2052. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2053. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2054. abs(t1) > "1e12" && (t1 = .5);
  2055. abs(t2) > "1e12" && (t2 = .5);
  2056. if (t1 > 0 && t1 < 1) {
  2057. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2058. x.push(dot.x);
  2059. y.push(dot.y);
  2060. }
  2061. if (t2 > 0 && t2 < 1) {
  2062. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2063. x.push(dot.x);
  2064. y.push(dot.y);
  2065. }
  2066. return {
  2067. min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
  2068. max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
  2069. };
  2070. }),
  2071. path2curve = R._path2curve = cacher(function (path, path2) {
  2072. var pth = !path2 && paths(path);
  2073. if (!path2 && pth.curve) {
  2074. return pathClone(pth.curve);
  2075. }
  2076. var p = pathToAbsolute(path),
  2077. p2 = path2 && pathToAbsolute(path2),
  2078. attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2079. attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2080. processPath = function (path, d, pcom) {
  2081. var nx, ny, tq = {T:1, Q:1};
  2082. if (!path) {
  2083. return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
  2084. }
  2085. !(path[0] in tq) && (d.qx = d.qy = null);
  2086. switch (path[0]) {
  2087. case "M":
  2088. d.X = path[1];
  2089. d.Y = path[2];
  2090. break;
  2091. case "A":
  2092. path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
  2093. break;
  2094. case "S":
  2095. if (pcom == "C" || pcom == "S") { // In "S" case we have to take into account, if the previous command is C/S.
  2096. nx = d.x * 2 - d.bx; // And reflect the previous
  2097. ny = d.y * 2 - d.by; // command's control point relative to the current point.
  2098. }
  2099. else { // or some else or nothing
  2100. nx = d.x;
  2101. ny = d.y;
  2102. }
  2103. path = ["C", nx, ny][concat](path.slice(1));
  2104. break;
  2105. case "T":
  2106. if (pcom == "Q" || pcom == "T") { // In "T" case we have to take into account, if the previous command is Q/T.
  2107. d.qx = d.x * 2 - d.qx; // And make a reflection similar
  2108. d.qy = d.y * 2 - d.qy; // to case "S".
  2109. }
  2110. else { // or something else or nothing
  2111. d.qx = d.x;
  2112. d.qy = d.y;
  2113. }
  2114. path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  2115. break;
  2116. case "Q":
  2117. d.qx = path[1];
  2118. d.qy = path[2];
  2119. path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
  2120. break;
  2121. case "L":
  2122. path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
  2123. break;
  2124. case "H":
  2125. path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
  2126. break;
  2127. case "V":
  2128. path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
  2129. break;
  2130. case "Z":
  2131. path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
  2132. break;
  2133. }
  2134. return path;
  2135. },
  2136. fixArc = function (pp, i) {
  2137. if (pp[i].length > 7) {
  2138. pp[i].shift();
  2139. var pi = pp[i];
  2140. while (pi.length) {
  2141. pcoms1[i]="A"; // if created multiple C:s, their original seg is saved
  2142. p2 && (pcoms2[i]="A"); // the same as above
  2143. pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
  2144. }
  2145. pp.splice(i, 1);
  2146. ii = mmax(p.length, p2 && p2.length || 0);
  2147. }
  2148. },
  2149. fixM = function (path1, path2, a1, a2, i) {
  2150. if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
  2151. path2.splice(i, 0, ["M", a2.x, a2.y]);
  2152. a1.bx = 0;
  2153. a1.by = 0;
  2154. a1.x = path1[i][1];
  2155. a1.y = path1[i][2];
  2156. ii = mmax(p.length, p2 && p2.length || 0);
  2157. }
  2158. },
  2159. pcoms1 = [], // path commands of original path p
  2160. pcoms2 = [], // path commands of original path p2
  2161. pfirst = "", // temporary holder for original path command
  2162. pcom = ""; // holder for previous path command of original path
  2163. for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
  2164. p[i] && (pfirst = p[i][0]); // save current path command
  2165. if (pfirst != "C") // C is not saved yet, because it may be result of conversion
  2166. {
  2167. pcoms1[i] = pfirst; // Save current path command
  2168. i && ( pcom = pcoms1[i-1]); // Get previous path command pcom
  2169. }
  2170. p[i] = processPath(p[i], attrs, pcom); // Previous path command is inputted to processPath
  2171. if (pcoms1[i] != "A" && pfirst == "C") pcoms1[i] = "C"; // A is the only command
  2172. // which may produce multiple C:s
  2173. // so we have to make sure that C is also C in original path
  2174. fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1
  2175. if (p2) { // the same procedures is done to p2
  2176. p2[i] && (pfirst = p2[i][0]);
  2177. if (pfirst != "C")
  2178. {
  2179. pcoms2[i] = pfirst;
  2180. i && (pcom = pcoms2[i-1]);
  2181. }
  2182. p2[i] = processPath(p2[i], attrs2, pcom);
  2183. if (pcoms2[i]!="A" && pfirst=="C") pcoms2[i]="C";
  2184. fixArc(p2, i);
  2185. }
  2186. fixM(p, p2, attrs, attrs2, i);
  2187. fixM(p2, p, attrs2, attrs, i);
  2188. var seg = p[i],
  2189. seg2 = p2 && p2[i],
  2190. seglen = seg.length,
  2191. seg2len = p2 && seg2.length;
  2192. attrs.x = seg[seglen - 2];
  2193. attrs.y = seg[seglen - 1];
  2194. attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
  2195. attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
  2196. attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
  2197. attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
  2198. attrs2.x = p2 && seg2[seg2len - 2];
  2199. attrs2.y = p2 && seg2[seg2len - 1];
  2200. }
  2201. if (!p2) {
  2202. pth.curve = pathClone(p);
  2203. }
  2204. return p2 ? [p, p2] : p;
  2205. }, null, pathClone),
  2206. parseDots = R._parseDots = cacher(function (gradient) {
  2207. var dots = [];
  2208. for (var i = 0, ii = gradient.length; i < ii; i++) {
  2209. var dot = {},
  2210. par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
  2211. dot.color = R.getRGB(par[1]);
  2212. if (dot.color.error) {
  2213. return null;
  2214. }
  2215. dot.opacity = dot.color.opacity;
  2216. dot.color = dot.color.hex;
  2217. par[2] && (dot.offset = par[2] + "%");
  2218. dots.push(dot);
  2219. }
  2220. for (i = 1, ii = dots.length - 1; i < ii; i++) {
  2221. if (!dots[i].offset) {
  2222. var start = toFloat(dots[i - 1].offset || 0),
  2223. end = 0;
  2224. for (var j = i + 1; j < ii; j++) {
  2225. if (dots[j].offset) {
  2226. end = dots[j].offset;
  2227. break;
  2228. }
  2229. }
  2230. if (!end) {
  2231. end = 100;
  2232. j = ii;
  2233. }
  2234. end = toFloat(end);
  2235. var d = (end - start) / (j - i + 1);
  2236. for (; i < j; i++) {
  2237. start += d;
  2238. dots[i].offset = start + "%";
  2239. }
  2240. }
  2241. }
  2242. return dots;
  2243. }),
  2244. tear = R._tear = function (el, paper) {
  2245. el == paper.top && (paper.top = el.prev);
  2246. el == paper.bottom && (paper.bottom = el.next);
  2247. el.next && (el.next.prev = el.prev);
  2248. el.prev && (el.prev.next = el.next);
  2249. },
  2250. tofront = R._tofront = function (el, paper) {
  2251. if (paper.top === el) {
  2252. return;
  2253. }
  2254. tear(el, paper);
  2255. el.next = null;
  2256. el.prev = paper.top;
  2257. paper.top.next = el;
  2258. paper.top = el;
  2259. },
  2260. toback = R._toback = function (el, paper) {
  2261. if (paper.bottom === el) {
  2262. return;
  2263. }
  2264. tear(el, paper);
  2265. el.next = paper.bottom;
  2266. el.prev = null;
  2267. paper.bottom.prev = el;
  2268. paper.bottom = el;
  2269. },
  2270. insertafter = R._insertafter = function (el, el2, paper) {
  2271. tear(el, paper);
  2272. el2 == paper.top && (paper.top = el);
  2273. el2.next && (el2.next.prev = el);
  2274. el.next = el2.next;
  2275. el.prev = el2;
  2276. el2.next = el;
  2277. },
  2278. insertbefore = R._insertbefore = function (el, el2, paper) {
  2279. tear(el, paper);
  2280. el2 == paper.bottom && (paper.bottom = el);
  2281. el2.prev && (el2.prev.next = el);
  2282. el.prev = el2.prev;
  2283. el2.prev = el;
  2284. el.next = el2;
  2285. },
  2286. /*\
  2287. * Raphael.toMatrix
  2288. [ method ]
  2289. **
  2290. * Utility method
  2291. **
  2292. * Returns matrix of transformations applied to a given path
  2293. > Parameters
  2294. - path (string) path string
  2295. - transform (string|array) transformation string
  2296. = (object) @Matrix
  2297. \*/
  2298. toMatrix = R.toMatrix = function (path, transform) {
  2299. var bb = pathDimensions(path),
  2300. el = {
  2301. _: {
  2302. transform: E
  2303. },
  2304. getBBox: function () {
  2305. return bb;
  2306. }
  2307. };
  2308. extractTransform(el, transform);
  2309. return el.matrix;
  2310. },
  2311. /*\
  2312. * Raphael.transformPath
  2313. [ method ]
  2314. **
  2315. * Utility method
  2316. **
  2317. * Returns path transformed by a given transformation
  2318. > Parameters
  2319. - path (string) path string
  2320. - transform (string|array) transformation string
  2321. = (string) path
  2322. \*/
  2323. transformPath = R.transformPath = function (path, transform) {
  2324. return mapPath(path, toMatrix(path, transform));
  2325. },
  2326. extractTransform = R._extractTransform = function (el, tstr) {
  2327. if (tstr == null) {
  2328. return el._.transform;
  2329. }
  2330. tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
  2331. var tdata = R.parseTransformString(tstr),
  2332. deg = 0,
  2333. dx = 0,
  2334. dy = 0,
  2335. sx = 1,
  2336. sy = 1,
  2337. _ = el._,
  2338. m = new Matrix;
  2339. _.transform = tdata || [];
  2340. if (tdata) {
  2341. for (var i = 0, ii = tdata.length; i < ii; i++) {
  2342. var t = tdata[i],
  2343. tlen = t.length,
  2344. command = Str(t[0]).toLowerCase(),
  2345. absolute = t[0] != command,
  2346. inver = absolute ? m.invert() : 0,
  2347. x1,
  2348. y1,
  2349. x2,
  2350. y2,
  2351. bb;
  2352. if (command == "t" && tlen == 3) {
  2353. if (absolute) {
  2354. x1 = inver.x(0, 0);
  2355. y1 = inver.y(0, 0);
  2356. x2 = inver.x(t[1], t[2]);
  2357. y2 = inver.y(t[1], t[2]);
  2358. m.translate(x2 - x1, y2 - y1);
  2359. } else {
  2360. m.translate(t[1], t[2]);
  2361. }
  2362. } else if (command == "r") {
  2363. if (tlen == 2) {
  2364. bb = bb || el.getBBox(1);
  2365. m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2366. deg += t[1];
  2367. } else if (tlen == 4) {
  2368. if (absolute) {
  2369. x2 = inver.x(t[2], t[3]);
  2370. y2 = inver.y(t[2], t[3]);
  2371. m.rotate(t[1], x2, y2);
  2372. } else {
  2373. m.rotate(t[1], t[2], t[3]);
  2374. }
  2375. deg += t[1];
  2376. }
  2377. } else if (command == "s") {
  2378. if (tlen == 2 || tlen == 3) {
  2379. bb = bb || el.getBBox(1);
  2380. m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2381. sx *= t[1];
  2382. sy *= t[tlen - 1];
  2383. } else if (tlen == 5) {
  2384. if (absolute) {
  2385. x2 = inver.x(t[3], t[4]);
  2386. y2 = inver.y(t[3], t[4]);
  2387. m.scale(t[1], t[2], x2, y2);
  2388. } else {
  2389. m.scale(t[1], t[2], t[3], t[4]);
  2390. }
  2391. sx *= t[1];
  2392. sy *= t[2];
  2393. }
  2394. } else if (command == "m" && tlen == 7) {
  2395. m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
  2396. }
  2397. _.dirtyT = 1;
  2398. el.matrix = m;
  2399. }
  2400. }
  2401. /*\
  2402. * Element.matrix
  2403. [ property (object) ]
  2404. **
  2405. * Keeps @Matrix object, which represents element transformation
  2406. \*/
  2407. el.matrix = m;
  2408. _.sx = sx;
  2409. _.sy = sy;
  2410. _.deg = deg;
  2411. _.dx = dx = m.e;
  2412. _.dy = dy = m.f;
  2413. if (sx == 1 && sy == 1 && !deg && _.bbox) {
  2414. _.bbox.x += +dx;
  2415. _.bbox.y += +dy;
  2416. } else {
  2417. _.dirtyT = 1;
  2418. }
  2419. },
  2420. getEmpty = function (item) {
  2421. var l = item[0];
  2422. switch (l.toLowerCase()) {
  2423. case "t": return [l, 0, 0];
  2424. case "m": return [l, 1, 0, 0, 1, 0, 0];
  2425. case "r": if (item.length == 4) {
  2426. return [l, 0, item[2], item[3]];
  2427. } else {
  2428. return [l, 0];
  2429. }
  2430. case "s": if (item.length == 5) {
  2431. return [l, 1, 1, item[3], item[4]];
  2432. } else if (item.length == 3) {
  2433. return [l, 1, 1];
  2434. } else {
  2435. return [l, 1];
  2436. }
  2437. }
  2438. },
  2439. equaliseTransform = R._equaliseTransform = function (t1, t2) {
  2440. t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
  2441. t1 = R.parseTransformString(t1) || [];
  2442. t2 = R.parseTransformString(t2) || [];
  2443. var maxlength = mmax(t1.length, t2.length),
  2444. from = [],
  2445. to = [],
  2446. i = 0, j, jj,
  2447. tt1, tt2;
  2448. for (; i < maxlength; i++) {
  2449. tt1 = t1[i] || getEmpty(t2[i]);
  2450. tt2 = t2[i] || getEmpty(tt1);
  2451. if ((tt1[0] != tt2[0]) ||
  2452. (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
  2453. (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
  2454. ) {
  2455. return;
  2456. }
  2457. from[i] = [];
  2458. to[i] = [];
  2459. for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
  2460. j in tt1 && (from[i][j] = tt1[j]);
  2461. j in tt2 && (to[i][j] = tt2[j]);
  2462. }
  2463. }
  2464. return {
  2465. from: from,
  2466. to: to
  2467. };
  2468. };
  2469. R._getContainer = function (x, y, w, h) {
  2470. var container;
  2471. container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
  2472. if (container == null) {
  2473. return;
  2474. }
  2475. if (container.tagName) {
  2476. if (y == null) {
  2477. return {
  2478. container: container,
  2479. width: container.style.pixelWidth || container.offsetWidth,
  2480. height: container.style.pixelHeight || container.offsetHeight
  2481. };
  2482. } else {
  2483. return {
  2484. container: container,
  2485. width: y,
  2486. height: w
  2487. };
  2488. }
  2489. }
  2490. return {
  2491. container: 1,
  2492. x: x,
  2493. y: y,
  2494. width: w,
  2495. height: h
  2496. };
  2497. };
  2498. /*\
  2499. * Raphael.pathToRelative
  2500. [ method ]
  2501. **
  2502. * Utility method
  2503. **
  2504. * Converts path to relative form
  2505. > Parameters
  2506. - pathString (string|array) path string or array of segments
  2507. = (array) array of segments.
  2508. \*/
  2509. R.pathToRelative = pathToRelative;
  2510. R._engine = {};
  2511. /*\
  2512. * Raphael.path2curve
  2513. [ method ]
  2514. **
  2515. * Utility method
  2516. **
  2517. * Converts path to a new path where all segments are cubic bezier curves.
  2518. > Parameters
  2519. - pathString (string|array) path string or array of segments
  2520. = (array) array of segments.
  2521. \*/
  2522. R.path2curve = path2curve;
  2523. /*\
  2524. * Raphael.matrix
  2525. [ method ]
  2526. **
  2527. * Utility method
  2528. **
  2529. * Returns matrix based on given parameters.
  2530. > Parameters
  2531. - a (number)
  2532. - b (number)
  2533. - c (number)
  2534. - d (number)
  2535. - e (number)
  2536. - f (number)
  2537. = (object) @Matrix
  2538. \*/
  2539. R.matrix = function (a, b, c, d, e, f) {
  2540. return new Matrix(a, b, c, d, e, f);
  2541. };
  2542. function Matrix(a, b, c, d, e, f) {
  2543. if (a != null) {
  2544. this.a = +a;
  2545. this.b = +b;
  2546. this.c = +c;
  2547. this.d = +d;
  2548. this.e = +e;
  2549. this.f = +f;
  2550. } else {
  2551. this.a = 1;
  2552. this.b = 0;
  2553. this.c = 0;
  2554. this.d = 1;
  2555. this.e = 0;
  2556. this.f = 0;
  2557. }
  2558. }
  2559. (function (matrixproto) {
  2560. /*\
  2561. * Matrix.add
  2562. [ method ]
  2563. **
  2564. * Adds given matrix to existing one.
  2565. > Parameters
  2566. - a (number)
  2567. - b (number)
  2568. - c (number)
  2569. - d (number)
  2570. - e (number)
  2571. - f (number)
  2572. or
  2573. - matrix (object) @Matrix
  2574. \*/
  2575. matrixproto.add = function (a, b, c, d, e, f) {
  2576. var out = [[], [], []],
  2577. m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
  2578. matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
  2579. x, y, z, res;
  2580. if (a && a instanceof Matrix) {
  2581. matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
  2582. }
  2583. for (x = 0; x < 3; x++) {
  2584. for (y = 0; y < 3; y++) {
  2585. res = 0;
  2586. for (z = 0; z < 3; z++) {
  2587. res += m[x][z] * matrix[z][y];
  2588. }
  2589. out[x][y] = res;
  2590. }
  2591. }
  2592. this.a = out[0][0];
  2593. this.b = out[1][0];
  2594. this.c = out[0][1];
  2595. this.d = out[1][1];
  2596. this.e = out[0][2];
  2597. this.f = out[1][2];
  2598. };
  2599. /*\
  2600. * Matrix.invert
  2601. [ method ]
  2602. **
  2603. * Returns inverted version of the matrix
  2604. = (object) @Matrix
  2605. \*/
  2606. matrixproto.invert = function () {
  2607. var me = this,
  2608. x = me.a * me.d - me.b * me.c;
  2609. return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x);
  2610. };
  2611. /*\
  2612. * Matrix.clone
  2613. [ method ]
  2614. **
  2615. * Returns copy of the matrix
  2616. = (object) @Matrix
  2617. \*/
  2618. matrixproto.clone = function () {
  2619. return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
  2620. };
  2621. /*\
  2622. * Matrix.translate
  2623. [ method ]
  2624. **
  2625. * Translate the matrix
  2626. > Parameters
  2627. - x (number)
  2628. - y (number)
  2629. \*/
  2630. matrixproto.translate = function (x, y) {
  2631. this.add(1, 0, 0, 1, x, y);
  2632. };
  2633. /*\
  2634. * Matrix.scale
  2635. [ method ]
  2636. **
  2637. * Scales the matrix
  2638. > Parameters
  2639. - x (number)
  2640. - y (number) #optional
  2641. - cx (number) #optional
  2642. - cy (number) #optional
  2643. \*/
  2644. matrixproto.scale = function (x, y, cx, cy) {
  2645. y == null && (y = x);
  2646. (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
  2647. this.add(x, 0, 0, y, 0, 0);
  2648. (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
  2649. };
  2650. /*\
  2651. * Matrix.rotate
  2652. [ method ]
  2653. **
  2654. * Rotates the matrix
  2655. > Parameters
  2656. - a (number)
  2657. - x (number)
  2658. - y (number)
  2659. \*/
  2660. matrixproto.rotate = function (a, x, y) {
  2661. a = R.rad(a);
  2662. x = x || 0;
  2663. y = y || 0;
  2664. var cos = +math.cos(a).toFixed(9),
  2665. sin = +math.sin(a).toFixed(9);
  2666. this.add(cos, sin, -sin, cos, x, y);
  2667. this.add(1, 0, 0, 1, -x, -y);
  2668. };
  2669. /*\
  2670. * Matrix.x
  2671. [ method ]
  2672. **
  2673. * Return x coordinate for given point after transformation described by the matrix. See also @Matrix.y
  2674. > Parameters
  2675. - x (number)
  2676. - y (number)
  2677. = (number) x
  2678. \*/
  2679. matrixproto.x = function (x, y) {
  2680. return x * this.a + y * this.c + this.e;
  2681. };
  2682. /*\
  2683. * Matrix.y
  2684. [ method ]
  2685. **
  2686. * Return y coordinate for given point after transformation described by the matrix. See also @Matrix.x
  2687. > Parameters
  2688. - x (number)
  2689. - y (number)
  2690. = (number) y
  2691. \*/
  2692. matrixproto.y = function (x, y) {
  2693. return x * this.b + y * this.d + this.f;
  2694. };
  2695. matrixproto.get = function (i) {
  2696. return +this[Str.fromCharCode(97 + i)].toFixed(4);
  2697. };
  2698. matrixproto.toString = function () {
  2699. return R.svg ?
  2700. "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
  2701. [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
  2702. };
  2703. matrixproto.toFilter = function () {
  2704. return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
  2705. ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
  2706. ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
  2707. };
  2708. matrixproto.offset = function () {
  2709. return [this.e.toFixed(4), this.f.toFixed(4)];
  2710. };
  2711. function norm(a) {
  2712. return a[0] * a[0] + a[1] * a[1];
  2713. }
  2714. function normalize(a) {
  2715. var mag = math.sqrt(norm(a));
  2716. a[0] && (a[0] /= mag);
  2717. a[1] && (a[1] /= mag);
  2718. }
  2719. /*\
  2720. * Matrix.split
  2721. [ method ]
  2722. **
  2723. * Splits matrix into primitive transformations
  2724. = (object) in format:
  2725. o dx (number) translation by x
  2726. o dy (number) translation by y
  2727. o scalex (number) scale by x
  2728. o scaley (number) scale by y
  2729. o shear (number) shear
  2730. o rotate (number) rotation in deg
  2731. o isSimple (boolean) could it be represented via simple transformations
  2732. \*/
  2733. matrixproto.split = function () {
  2734. var out = {};
  2735. // translation
  2736. out.dx = this.e;
  2737. out.dy = this.f;
  2738. // scale and shear
  2739. var row = [[this.a, this.c], [this.b, this.d]];
  2740. out.scalex = math.sqrt(norm(row[0]));
  2741. normalize(row[0]);
  2742. out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
  2743. row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
  2744. out.scaley = math.sqrt(norm(row[1]));
  2745. normalize(row[1]);
  2746. out.shear /= out.scaley;
  2747. // rotation
  2748. var sin = -row[0][1],
  2749. cos = row[1][1];
  2750. if (cos < 0) {
  2751. out.rotate = R.deg(math.acos(cos));
  2752. if (sin < 0) {
  2753. out.rotate = 360 - out.rotate;
  2754. }
  2755. } else {
  2756. out.rotate = R.deg(math.asin(sin));
  2757. }
  2758. out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
  2759. out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
  2760. out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
  2761. return out;
  2762. };
  2763. /*\
  2764. * Matrix.toTransformString
  2765. [ method ]
  2766. **
  2767. * Return transform string that represents given matrix
  2768. = (string) transform string
  2769. \*/
  2770. matrixproto.toTransformString = function (shorter) {
  2771. var s = shorter || this[split]();
  2772. if (s.isSimple) {
  2773. s.scalex = +s.scalex.toFixed(4);
  2774. s.scaley = +s.scaley.toFixed(4);
  2775. s.rotate = +s.rotate.toFixed(4);
  2776. return (s.dx || s.dy ? "t" + [s.dx, s.dy] : E) +
  2777. (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
  2778. (s.rotate ? "r" + [s.rotate, 0, 0] : E);
  2779. } else {
  2780. return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
  2781. }
  2782. };
  2783. })(Matrix.prototype);
  2784. var preventDefault = function () {
  2785. this.returnValue = false;
  2786. },
  2787. preventTouch = function () {
  2788. return this.originalEvent.preventDefault();
  2789. },
  2790. stopPropagation = function () {
  2791. this.cancelBubble = true;
  2792. },
  2793. stopTouch = function () {
  2794. return this.originalEvent.stopPropagation();
  2795. },
  2796. getEventPosition = function (e) {
  2797. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  2798. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
  2799. return {
  2800. x: e.clientX + scrollX,
  2801. y: e.clientY + scrollY
  2802. };
  2803. },
  2804. addEvent = (function () {
  2805. if (g.doc.addEventListener) {
  2806. return function (obj, type, fn, element) {
  2807. var f = function (e) {
  2808. var pos = getEventPosition(e);
  2809. return fn.call(element, e, pos.x, pos.y);
  2810. };
  2811. obj.addEventListener(type, f, false);
  2812. if (supportsTouch && touchMap[type]) {
  2813. var _f = function (e) {
  2814. var pos = getEventPosition(e),
  2815. olde = e;
  2816. for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
  2817. if (e.targetTouches[i].target == obj) {
  2818. e = e.targetTouches[i];
  2819. e.originalEvent = olde;
  2820. e.preventDefault = preventTouch;
  2821. e.stopPropagation = stopTouch;
  2822. break;
  2823. }
  2824. }
  2825. return fn.call(element, e, pos.x, pos.y);
  2826. };
  2827. obj.addEventListener(touchMap[type], _f, false);
  2828. }
  2829. return function () {
  2830. obj.removeEventListener(type, f, false);
  2831. if (supportsTouch && touchMap[type])
  2832. obj.removeEventListener(touchMap[type], _f, false);
  2833. return true;
  2834. };
  2835. };
  2836. } else if (g.doc.attachEvent) {
  2837. return function (obj, type, fn, element) {
  2838. var f = function (e) {
  2839. e = e || g.win.event;
  2840. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  2841. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  2842. x = e.clientX + scrollX,
  2843. y = e.clientY + scrollY;
  2844. e.preventDefault = e.preventDefault || preventDefault;
  2845. e.stopPropagation = e.stopPropagation || stopPropagation;
  2846. return fn.call(element, e, x, y);
  2847. };
  2848. obj.attachEvent("on" + type, f);
  2849. var detacher = function () {
  2850. obj.detachEvent("on" + type, f);
  2851. return true;
  2852. };
  2853. return detacher;
  2854. };
  2855. }
  2856. })(),
  2857. drag = [],
  2858. dragMove = function (e) {
  2859. var x = e.clientX,
  2860. y = e.clientY,
  2861. scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  2862. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  2863. dragi,
  2864. j = drag.length;
  2865. while (j--) {
  2866. dragi = drag[j];
  2867. if (supportsTouch && e.touches) {
  2868. var i = e.touches.length,
  2869. touch;
  2870. while (i--) {
  2871. touch = e.touches[i];
  2872. if (touch.identifier == dragi.el._drag.id) {
  2873. x = touch.clientX;
  2874. y = touch.clientY;
  2875. (e.originalEvent ? e.originalEvent : e).preventDefault();
  2876. break;
  2877. }
  2878. }
  2879. } else {
  2880. e.preventDefault();
  2881. }
  2882. var node = dragi.el.node,
  2883. o,
  2884. next = node.nextSibling,
  2885. parent = node.parentNode,
  2886. display = node.style.display;
  2887. g.win.opera && parent.removeChild(node);
  2888. node.style.display = "none";
  2889. o = dragi.el.paper.getElementByPoint(x, y);
  2890. node.style.display = display;
  2891. g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
  2892. o && eve("raphael.drag.over." + dragi.el.id, dragi.el, o);
  2893. x += scrollX;
  2894. y += scrollY;
  2895. eve("raphael.drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
  2896. }
  2897. },
  2898. dragUp = function (e) {
  2899. R.unmousemove(dragMove).unmouseup(dragUp);
  2900. var i = drag.length,
  2901. dragi;
  2902. while (i--) {
  2903. dragi = drag[i];
  2904. dragi.el._drag = {};
  2905. eve("raphael.drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
  2906. }
  2907. drag = [];
  2908. },
  2909. /*\
  2910. * Raphael.el
  2911. [ property (object) ]
  2912. **
  2913. * You can add your own method to elements. This is useful when you want to hack default functionality or
  2914. * want to wrap some common transformation or attributes in one method. In difference to canvas methods,
  2915. * you can redefine element method at any time. Expending element methods wouldn’t affect set.
  2916. > Usage
  2917. | Raphael.el.red = function () {
  2918. | this.attr({fill: "#f00"});
  2919. | };
  2920. | // then use it
  2921. | paper.circle(100, 100, 20).red();
  2922. \*/
  2923. elproto = R.el = {};
  2924. /*\
  2925. * Element.click
  2926. [ method ]
  2927. **
  2928. * Adds event handler for click for the element.
  2929. > Parameters
  2930. - handler (function) handler for the event
  2931. = (object) @Element
  2932. \*/
  2933. /*\
  2934. * Element.unclick
  2935. [ method ]
  2936. **
  2937. * Removes event handler for click for the element.
  2938. > Parameters
  2939. - handler (function) #optional handler for the event
  2940. = (object) @Element
  2941. \*/
  2942. /*\
  2943. * Element.dblclick
  2944. [ method ]
  2945. **
  2946. * Adds event handler for double click for the element.
  2947. > Parameters
  2948. - handler (function) handler for the event
  2949. = (object) @Element
  2950. \*/
  2951. /*\
  2952. * Element.undblclick
  2953. [ method ]
  2954. **
  2955. * Removes event handler for double click for the element.
  2956. > Parameters
  2957. - handler (function) #optional handler for the event
  2958. = (object) @Element
  2959. \*/
  2960. /*\
  2961. * Element.mousedown
  2962. [ method ]
  2963. **
  2964. * Adds event handler for mousedown for the element.
  2965. > Parameters
  2966. - handler (function) handler for the event
  2967. = (object) @Element
  2968. \*/
  2969. /*\
  2970. * Element.unmousedown
  2971. [ method ]
  2972. **
  2973. * Removes event handler for mousedown for the element.
  2974. > Parameters
  2975. - handler (function) #optional handler for the event
  2976. = (object) @Element
  2977. \*/
  2978. /*\
  2979. * Element.mousemove
  2980. [ method ]
  2981. **
  2982. * Adds event handler for mousemove for the element.
  2983. > Parameters
  2984. - handler (function) handler for the event
  2985. = (object) @Element
  2986. \*/
  2987. /*\
  2988. * Element.unmousemove
  2989. [ method ]
  2990. **
  2991. * Removes event handler for mousemove for the element.
  2992. > Parameters
  2993. - handler (function) #optional handler for the event
  2994. = (object) @Element
  2995. \*/
  2996. /*\
  2997. * Element.mouseout
  2998. [ method ]
  2999. **
  3000. * Adds event handler for mouseout for the element.
  3001. > Parameters
  3002. - handler (function) handler for the event
  3003. = (object) @Element
  3004. \*/
  3005. /*\
  3006. * Element.unmouseout
  3007. [ method ]
  3008. **
  3009. * Removes event handler for mouseout for the element.
  3010. > Parameters
  3011. - handler (function) #optional handler for the event
  3012. = (object) @Element
  3013. \*/
  3014. /*\
  3015. * Element.mouseover
  3016. [ method ]
  3017. **
  3018. * Adds event handler for mouseover for the element.
  3019. > Parameters
  3020. - handler (function) handler for the event
  3021. = (object) @Element
  3022. \*/
  3023. /*\
  3024. * Element.unmouseover
  3025. [ method ]
  3026. **
  3027. * Removes event handler for mouseover for the element.
  3028. > Parameters
  3029. - handler (function) #optional handler for the event
  3030. = (object) @Element
  3031. \*/
  3032. /*\
  3033. * Element.mouseup
  3034. [ method ]
  3035. **
  3036. * Adds event handler for mouseup for the element.
  3037. > Parameters
  3038. - handler (function) handler for the event
  3039. = (object) @Element
  3040. \*/
  3041. /*\
  3042. * Element.unmouseup
  3043. [ method ]
  3044. **
  3045. * Removes event handler for mouseup for the element.
  3046. > Parameters
  3047. - handler (function) #optional handler for the event
  3048. = (object) @Element
  3049. \*/
  3050. /*\
  3051. * Element.touchstart
  3052. [ method ]
  3053. **
  3054. * Adds event handler for touchstart for the element.
  3055. > Parameters
  3056. - handler (function) handler for the event
  3057. = (object) @Element
  3058. \*/
  3059. /*\
  3060. * Element.untouchstart
  3061. [ method ]
  3062. **
  3063. * Removes event handler for touchstart for the element.
  3064. > Parameters
  3065. - handler (function) #optional handler for the event
  3066. = (object) @Element
  3067. \*/
  3068. /*\
  3069. * Element.touchmove
  3070. [ method ]
  3071. **
  3072. * Adds event handler for touchmove for the element.
  3073. > Parameters
  3074. - handler (function) handler for the event
  3075. = (object) @Element
  3076. \*/
  3077. /*\
  3078. * Element.untouchmove
  3079. [ method ]
  3080. **
  3081. * Removes event handler for touchmove for the element.
  3082. > Parameters
  3083. - handler (function) #optional handler for the event
  3084. = (object) @Element
  3085. \*/
  3086. /*\
  3087. * Element.touchend
  3088. [ method ]
  3089. **
  3090. * Adds event handler for touchend for the element.
  3091. > Parameters
  3092. - handler (function) handler for the event
  3093. = (object) @Element
  3094. \*/
  3095. /*\
  3096. * Element.untouchend
  3097. [ method ]
  3098. **
  3099. * Removes event handler for touchend for the element.
  3100. > Parameters
  3101. - handler (function) #optional handler for the event
  3102. = (object) @Element
  3103. \*/
  3104. /*\
  3105. * Element.touchcancel
  3106. [ method ]
  3107. **
  3108. * Adds event handler for touchcancel for the element.
  3109. > Parameters
  3110. - handler (function) handler for the event
  3111. = (object) @Element
  3112. \*/
  3113. /*\
  3114. * Element.untouchcancel
  3115. [ method ]
  3116. **
  3117. * Removes event handler for touchcancel for the element.
  3118. > Parameters
  3119. - handler (function) #optional handler for the event
  3120. = (object) @Element
  3121. \*/
  3122. for (var i = events.length; i--;) {
  3123. (function (eventName) {
  3124. R[eventName] = elproto[eventName] = function (fn, scope) {
  3125. if (R.is(fn, "function")) {
  3126. this.events = this.events || [];
  3127. this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
  3128. }
  3129. return this;
  3130. };
  3131. R["un" + eventName] = elproto["un" + eventName] = function (fn) {
  3132. var events = this.events || [],
  3133. l = events.length;
  3134. while (l--){
  3135. if (events[l].name == eventName && (R.is(fn, "undefined") || events[l].f == fn)) {
  3136. events[l].unbind();
  3137. events.splice(l, 1);
  3138. !events.length && delete this.events;
  3139. }
  3140. }
  3141. return this;
  3142. };
  3143. })(events[i]);
  3144. }
  3145. /*\
  3146. * Element.data
  3147. [ method ]
  3148. **
  3149. * Adds or retrieves given value associated with given key.
  3150. **
  3151. * See also @Element.removeData
  3152. > Parameters
  3153. - key (string) key to store data
  3154. - value (any) #optional value to store
  3155. = (object) @Element
  3156. * or, if value is not specified:
  3157. = (any) value
  3158. * or, if key and value are not specified:
  3159. = (object) Key/value pairs for all the data associated with the element.
  3160. > Usage
  3161. | for (var i = 0, i < 5, i++) {
  3162. | paper.circle(10 + 15 * i, 10, 10)
  3163. | .attr({fill: "#000"})
  3164. | .data("i", i)
  3165. | .click(function () {
  3166. | alert(this.data("i"));
  3167. | });
  3168. | }
  3169. \*/
  3170. elproto.data = function (key, value) {
  3171. var data = eldata[this.id] = eldata[this.id] || {};
  3172. if (arguments.length == 0) {
  3173. return data;
  3174. }
  3175. if (arguments.length == 1) {
  3176. if (R.is(key, "object")) {
  3177. for (var i in key) if (key[has](i)) {
  3178. this.data(i, key[i]);
  3179. }
  3180. return this;
  3181. }
  3182. eve("raphael.data.get." + this.id, this, data[key], key);
  3183. return data[key];
  3184. }
  3185. data[key] = value;
  3186. eve("raphael.data.set." + this.id, this, value, key);
  3187. return this;
  3188. };
  3189. /*\
  3190. * Element.removeData
  3191. [ method ]
  3192. **
  3193. * Removes value associated with an element by given key.
  3194. * If key is not provided, removes all the data of the element.
  3195. > Parameters
  3196. - key (string) #optional key
  3197. = (object) @Element
  3198. \*/
  3199. elproto.removeData = function (key) {
  3200. if (key == null) {
  3201. delete eldata[this.id];
  3202. } else {
  3203. eldata[this.id] && delete eldata[this.id][key];
  3204. }
  3205. return this;
  3206. };
  3207. /*\
  3208. * Element.getData
  3209. [ method ]
  3210. **
  3211. * Retrieves the element data
  3212. = (object) data
  3213. \*/
  3214. elproto.getData = function () {
  3215. return clone(eldata[this.id] || {});
  3216. };
  3217. /*\
  3218. * Element.hover
  3219. [ method ]
  3220. **
  3221. * Adds event handlers for hover for the element.
  3222. > Parameters
  3223. - f_in (function) handler for hover in
  3224. - f_out (function) handler for hover out
  3225. - icontext (object) #optional context for hover in handler
  3226. - ocontext (object) #optional context for hover out handler
  3227. = (object) @Element
  3228. \*/
  3229. elproto.hover = function (f_in, f_out, scope_in, scope_out) {
  3230. return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
  3231. };
  3232. /*\
  3233. * Element.unhover
  3234. [ method ]
  3235. **
  3236. * Removes event handlers for hover for the element.
  3237. > Parameters
  3238. - f_in (function) handler for hover in
  3239. - f_out (function) handler for hover out
  3240. = (object) @Element
  3241. \*/
  3242. elproto.unhover = function (f_in, f_out) {
  3243. return this.unmouseover(f_in).unmouseout(f_out);
  3244. };
  3245. var draggable = [];
  3246. /*\
  3247. * Element.drag
  3248. [ method ]
  3249. **
  3250. * Adds event handlers for drag of the element.
  3251. > Parameters
  3252. - onmove (function) handler for moving
  3253. - onstart (function) handler for drag start
  3254. - onend (function) handler for drag end
  3255. - mcontext (object) #optional context for moving handler
  3256. - scontext (object) #optional context for drag start handler
  3257. - econtext (object) #optional context for drag end handler
  3258. * Additionally following `drag` events will be triggered: `drag.start.<id>` on start,
  3259. * `drag.end.<id>` on end and `drag.move.<id>` on every move. When element will be dragged over another element
  3260. * `drag.over.<id>` will be fired as well.
  3261. *
  3262. * Start event and start handler will be called in specified context or in context of the element with following parameters:
  3263. o x (number) x position of the mouse
  3264. o y (number) y position of the mouse
  3265. o event (object) DOM event object
  3266. * Move event and move handler will be called in specified context or in context of the element with following parameters:
  3267. o dx (number) shift by x from the start point
  3268. o dy (number) shift by y from the start point
  3269. o x (number) x position of the mouse
  3270. o y (number) y position of the mouse
  3271. o event (object) DOM event object
  3272. * End event and end handler will be called in specified context or in context of the element with following parameters:
  3273. o event (object) DOM event object
  3274. = (object) @Element
  3275. \*/
  3276. elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
  3277. function start(e) {
  3278. (e.originalEvent || e).preventDefault();
  3279. var x = e.clientX,
  3280. y = e.clientY,
  3281. scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  3282. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
  3283. this._drag.id = e.identifier;
  3284. if (supportsTouch && e.touches) {
  3285. var i = e.touches.length, touch;
  3286. while (i--) {
  3287. touch = e.touches[i];
  3288. this._drag.id = touch.identifier;
  3289. if (touch.identifier == this._drag.id) {
  3290. x = touch.clientX;
  3291. y = touch.clientY;
  3292. break;
  3293. }
  3294. }
  3295. }
  3296. this._drag.x = x + scrollX;
  3297. this._drag.y = y + scrollY;
  3298. !drag.length && R.mousemove(dragMove).mouseup(dragUp);
  3299. drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
  3300. onstart && eve.on("raphael.drag.start." + this.id, onstart);
  3301. onmove && eve.on("raphael.drag.move." + this.id, onmove);
  3302. onend && eve.on("raphael.drag.end." + this.id, onend);
  3303. eve("raphael.drag.start." + this.id, start_scope || move_scope || this, this._drag.x, this._drag.y, e);
  3304. }
  3305. this._drag = {};
  3306. draggable.push({el: this, start: start});
  3307. this.mousedown(start);
  3308. return this;
  3309. };
  3310. /*\
  3311. * Element.onDragOver
  3312. [ method ]
  3313. **
  3314. * Shortcut for assigning event handler for `drag.over.<id>` event, where id is id of the element (see @Element.id).
  3315. > Parameters
  3316. - f (function) handler for event, first argument would be the element you are dragging over
  3317. \*/
  3318. elproto.onDragOver = function (f) {
  3319. f ? eve.on("raphael.drag.over." + this.id, f) : eve.unbind("raphael.drag.over." + this.id);
  3320. };
  3321. /*\
  3322. * Element.undrag
  3323. [ method ]
  3324. **
  3325. * Removes all drag event handlers from given element.
  3326. \*/
  3327. elproto.undrag = function () {
  3328. var i = draggable.length;
  3329. while (i--) if (draggable[i].el == this) {
  3330. this.unmousedown(draggable[i].start);
  3331. draggable.splice(i, 1);
  3332. eve.unbind("raphael.drag.*." + this.id);
  3333. }
  3334. !draggable.length && R.unmousemove(dragMove).unmouseup(dragUp);
  3335. drag = [];
  3336. };
  3337. /*\
  3338. * Paper.circle
  3339. [ method ]
  3340. **
  3341. * Draws a circle.
  3342. **
  3343. > Parameters
  3344. **
  3345. - x (number) x coordinate of the centre
  3346. - y (number) y coordinate of the centre
  3347. - r (number) radius
  3348. = (object) Raphaël element object with type “circle”
  3349. **
  3350. > Usage
  3351. | var c = paper.circle(50, 50, 40);
  3352. \*/
  3353. paperproto.circle = function (x, y, r) {
  3354. var out = R._engine.circle(this, x || 0, y || 0, r || 0);
  3355. this.__set__ && this.__set__.push(out);
  3356. return out;
  3357. };
  3358. /*\
  3359. * Paper.rect
  3360. [ method ]
  3361. *
  3362. * Draws a rectangle.
  3363. **
  3364. > Parameters
  3365. **
  3366. - x (number) x coordinate of the top left corner
  3367. - y (number) y coordinate of the top left corner
  3368. - width (number) width
  3369. - height (number) height
  3370. - r (number) #optional radius for rounded corners, default is 0
  3371. = (object) Raphaël element object with type “rect”
  3372. **
  3373. > Usage
  3374. | // regular rectangle
  3375. | var c = paper.rect(10, 10, 50, 50);
  3376. | // rectangle with rounded corners
  3377. | var c = paper.rect(40, 40, 50, 50, 10);
  3378. \*/
  3379. paperproto.rect = function (x, y, w, h, r) {
  3380. var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
  3381. this.__set__ && this.__set__.push(out);
  3382. return out;
  3383. };
  3384. /*\
  3385. * Paper.ellipse
  3386. [ method ]
  3387. **
  3388. * Draws an ellipse.
  3389. **
  3390. > Parameters
  3391. **
  3392. - x (number) x coordinate of the centre
  3393. - y (number) y coordinate of the centre
  3394. - rx (number) horizontal radius
  3395. - ry (number) vertical radius
  3396. = (object) Raphaël element object with type “ellipse”
  3397. **
  3398. > Usage
  3399. | var c = paper.ellipse(50, 50, 40, 20);
  3400. \*/
  3401. paperproto.ellipse = function (x, y, rx, ry) {
  3402. var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
  3403. this.__set__ && this.__set__.push(out);
  3404. return out;
  3405. };
  3406. /*\
  3407. * Paper.path
  3408. [ method ]
  3409. **
  3410. * Creates a path element by given path data string.
  3411. > Parameters
  3412. - pathString (string) #optional path string in SVG format.
  3413. * Path string consists of one-letter commands, followed by comma seprarated arguments in numercal form. Example:
  3414. | "M10,20L30,40"
  3415. * Here we can see two commands: “M”, with arguments `(10, 20)` and “L” with arguments `(30, 40)`. Upper case letter mean command is absolute, lower case—relative.
  3416. *
  3417. # <p>Here is short list of commands available, for more details see <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path's data attribute's format are described in the SVG specification.">SVG path string format</a>.</p>
  3418. # <table><thead><tr><th>Command</th><th>Name</th><th>Parameters</th></tr></thead><tbody>
  3419. # <tr><td>M</td><td>moveto</td><td>(x y)+</td></tr>
  3420. # <tr><td>Z</td><td>closepath</td><td>(none)</td></tr>
  3421. # <tr><td>L</td><td>lineto</td><td>(x y)+</td></tr>
  3422. # <tr><td>H</td><td>horizontal lineto</td><td>x+</td></tr>
  3423. # <tr><td>V</td><td>vertical lineto</td><td>y+</td></tr>
  3424. # <tr><td>C</td><td>curveto</td><td>(x1 y1 x2 y2 x y)+</td></tr>
  3425. # <tr><td>S</td><td>smooth curveto</td><td>(x2 y2 x y)+</td></tr>
  3426. # <tr><td>Q</td><td>quadratic Bézier curveto</td><td>(x1 y1 x y)+</td></tr>
  3427. # <tr><td>T</td><td>smooth quadratic Bézier curveto</td><td>(x y)+</td></tr>
  3428. # <tr><td>A</td><td>elliptical arc</td><td>(rx ry x-axis-rotation large-arc-flag sweep-flag x y)+</td></tr>
  3429. # <tr><td>R</td><td><a href="http://en.wikipedia.org/wiki/Catmull–Rom_spline#Catmull.E2.80.93Rom_spline">Catmull-Rom curveto</a>*</td><td>x1 y1 (x y)+</td></tr></tbody></table>
  3430. * * “Catmull-Rom curveto” is a not standard SVG command and added in 2.0 to make life easier.
  3431. * Note: there is a special case when path consist of just three commands: “M10,10R…z”. In this case path will smoothly connects to its beginning.
  3432. > Usage
  3433. | var c = paper.path("M10 10L90 90");
  3434. | // draw a diagonal line:
  3435. | // move to 10,10, line to 90,90
  3436. * For example of path strings, check out these icons: http://raphaeljs.com/icons/
  3437. \*/
  3438. paperproto.path = function (pathString) {
  3439. pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
  3440. var out = R._engine.path(R.format[apply](R, arguments), this);
  3441. this.__set__ && this.__set__.push(out);
  3442. return out;
  3443. };
  3444. /*\
  3445. * Paper.image
  3446. [ method ]
  3447. **
  3448. * Embeds an image into the surface.
  3449. **
  3450. > Parameters
  3451. **
  3452. - src (string) URI of the source image
  3453. - x (number) x coordinate position
  3454. - y (number) y coordinate position
  3455. - width (number) width of the image
  3456. - height (number) height of the image
  3457. = (object) Raphaël element object with type “image”
  3458. **
  3459. > Usage
  3460. | var c = paper.image("apple.png", 10, 10, 80, 80);
  3461. \*/
  3462. paperproto.image = function (src, x, y, w, h) {
  3463. var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
  3464. this.__set__ && this.__set__.push(out);
  3465. return out;
  3466. };
  3467. /*\
  3468. * Paper.text
  3469. [ method ]
  3470. **
  3471. * Draws a text string. If you need line breaks, put “\n” in the string.
  3472. **
  3473. > Parameters
  3474. **
  3475. - x (number) x coordinate position
  3476. - y (number) y coordinate position
  3477. - text (string) The text string to draw
  3478. = (object) Raphaël element object with type “text”
  3479. **
  3480. > Usage
  3481. | var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");
  3482. \*/
  3483. paperproto.text = function (x, y, text) {
  3484. var out = R._engine.text(this, x || 0, y || 0, Str(text));
  3485. this.__set__ && this.__set__.push(out);
  3486. return out;
  3487. };
  3488. /*\
  3489. * Paper.set
  3490. [ method ]
  3491. **
  3492. * Creates array-like object to keep and operate several elements at once.
  3493. * Warning: it doesn’t create any elements for itself in the page, it just groups existing elements.
  3494. * Sets act as pseudo elements — all methods available to an element can be used on a set.
  3495. = (object) array-like object that represents set of elements
  3496. **
  3497. > Usage
  3498. | var st = paper.set();
  3499. | st.push(
  3500. | paper.circle(10, 10, 5),
  3501. | paper.circle(30, 10, 5)
  3502. | );
  3503. | st.attr({fill: "red"}); // changes the fill of both circles
  3504. \*/
  3505. paperproto.set = function (itemsArray) {
  3506. !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
  3507. var out = new Set(itemsArray);
  3508. this.__set__ && this.__set__.push(out);
  3509. out["paper"] = this;
  3510. out["type"] = "set";
  3511. return out;
  3512. };
  3513. /*\
  3514. * Paper.setStart
  3515. [ method ]
  3516. **
  3517. * Creates @Paper.set. All elements that will be created after calling this method and before calling
  3518. * @Paper.setFinish will be added to the set.
  3519. **
  3520. > Usage
  3521. | paper.setStart();
  3522. | paper.circle(10, 10, 5),
  3523. | paper.circle(30, 10, 5)
  3524. | var st = paper.setFinish();
  3525. | st.attr({fill: "red"}); // changes the fill of both circles
  3526. \*/
  3527. paperproto.setStart = function (set) {
  3528. this.__set__ = set || this.set();
  3529. };
  3530. /*\
  3531. * Paper.setFinish
  3532. [ method ]
  3533. **
  3534. * See @Paper.setStart. This method finishes catching and returns resulting set.
  3535. **
  3536. = (object) set
  3537. \*/
  3538. paperproto.setFinish = function (set) {
  3539. var out = this.__set__;
  3540. delete this.__set__;
  3541. return out;
  3542. };
  3543. /*\
  3544. * Paper.getSize
  3545. [ method ]
  3546. **
  3547. * Obtains current paper actual size.
  3548. **
  3549. = (object)
  3550. \*/
  3551. paperproto.getSize = function () {
  3552. var container = this.canvas.parentNode;
  3553. return {
  3554. width: container.offsetWidth,
  3555. height: container.offsetHeight
  3556. };
  3557. };
  3558. /*\
  3559. * Paper.setSize
  3560. [ method ]
  3561. **
  3562. * If you need to change dimensions of the canvas call this method
  3563. **
  3564. > Parameters
  3565. **
  3566. - width (number) new width of the canvas
  3567. - height (number) new height of the canvas
  3568. \*/
  3569. paperproto.setSize = function (width, height) {
  3570. return R._engine.setSize.call(this, width, height);
  3571. };
  3572. /*\
  3573. * Paper.setViewBox
  3574. [ method ]
  3575. **
  3576. * Sets the view box of the paper. Practically it gives you ability to zoom and pan whole paper surface by
  3577. * specifying new boundaries.
  3578. **
  3579. > Parameters
  3580. **
  3581. - x (number) new x position, default is `0`
  3582. - y (number) new y position, default is `0`
  3583. - w (number) new width of the canvas
  3584. - h (number) new height of the canvas
  3585. - fit (boolean) `true` if you want graphics to fit into new boundary box
  3586. \*/
  3587. paperproto.setViewBox = function (x, y, w, h, fit) {
  3588. return R._engine.setViewBox.call(this, x, y, w, h, fit);
  3589. };
  3590. /*\
  3591. * Paper.top
  3592. [ property ]
  3593. **
  3594. * Points to the topmost element on the paper
  3595. \*/
  3596. /*\
  3597. * Paper.bottom
  3598. [ property ]
  3599. **
  3600. * Points to the bottom element on the paper
  3601. \*/
  3602. paperproto.top = paperproto.bottom = null;
  3603. /*\
  3604. * Paper.raphael
  3605. [ property ]
  3606. **
  3607. * Points to the @Raphael object/function
  3608. \*/
  3609. paperproto.raphael = R;
  3610. var getOffset = function (elem) {
  3611. var box = elem.getBoundingClientRect(),
  3612. doc = elem.ownerDocument,
  3613. body = doc.body,
  3614. docElem = doc.documentElement,
  3615. clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
  3616. top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
  3617. left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
  3618. return {
  3619. y: top,
  3620. x: left
  3621. };
  3622. };
  3623. /*\
  3624. * Paper.getElementByPoint
  3625. [ method ]
  3626. **
  3627. * Returns you topmost element under given point.
  3628. **
  3629. = (object) Raphaël element object
  3630. > Parameters
  3631. **
  3632. - x (number) x coordinate from the top left corner of the window
  3633. - y (number) y coordinate from the top left corner of the window
  3634. > Usage
  3635. | paper.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"});
  3636. \*/
  3637. paperproto.getElementByPoint = function (x, y) {
  3638. var paper = this,
  3639. svg = paper.canvas,
  3640. target = g.doc.elementFromPoint(x, y);
  3641. if (g.win.opera && target.tagName == "svg") {
  3642. var so = getOffset(svg),
  3643. sr = svg.createSVGRect();
  3644. sr.x = x - so.x;
  3645. sr.y = y - so.y;
  3646. sr.width = sr.height = 1;
  3647. var hits = svg.getIntersectionList(sr, null);
  3648. if (hits.length) {
  3649. target = hits[hits.length - 1];
  3650. }
  3651. }
  3652. if (!target) {
  3653. return null;
  3654. }
  3655. while (target.parentNode && target != svg.parentNode && !target.raphael) {
  3656. target = target.parentNode;
  3657. }
  3658. target == paper.canvas.parentNode && (target = svg);
  3659. target = target && target.raphael ? paper.getById(target.raphaelid) : null;
  3660. return target;
  3661. };
  3662. /*\
  3663. * Paper.getElementsByBBox
  3664. [ method ]
  3665. **
  3666. * Returns set of elements that have an intersecting bounding box
  3667. **
  3668. > Parameters
  3669. **
  3670. - bbox (object) bbox to check with
  3671. = (object) @Set
  3672. \*/
  3673. paperproto.getElementsByBBox = function (bbox) {
  3674. var set = this.set();
  3675. this.forEach(function (el) {
  3676. if (R.isBBoxIntersect(el.getBBox(), bbox)) {
  3677. set.push(el);
  3678. }
  3679. });
  3680. return set;
  3681. };
  3682. /*\
  3683. * Paper.getById
  3684. [ method ]
  3685. **
  3686. * Returns you element by its internal ID.
  3687. **
  3688. > Parameters
  3689. **
  3690. - id (number) id
  3691. = (object) Raphaël element object
  3692. \*/
  3693. paperproto.getById = function (id) {
  3694. var bot = this.bottom;
  3695. while (bot) {
  3696. if (bot.id == id) {
  3697. return bot;
  3698. }
  3699. bot = bot.next;
  3700. }
  3701. return null;
  3702. };
  3703. /*\
  3704. * Paper.forEach
  3705. [ method ]
  3706. **
  3707. * Executes given function for each element on the paper
  3708. *
  3709. * If callback function returns `false` it will stop loop running.
  3710. **
  3711. > Parameters
  3712. **
  3713. - callback (function) function to run
  3714. - thisArg (object) context object for the callback
  3715. = (object) Paper object
  3716. > Usage
  3717. | paper.forEach(function (el) {
  3718. | el.attr({ stroke: "blue" });
  3719. | });
  3720. \*/
  3721. paperproto.forEach = function (callback, thisArg) {
  3722. var bot = this.bottom;
  3723. while (bot) {
  3724. if (callback.call(thisArg, bot) === false) {
  3725. return this;
  3726. }
  3727. bot = bot.next;
  3728. }
  3729. return this;
  3730. };
  3731. /*\
  3732. * Paper.getElementsByPoint
  3733. [ method ]
  3734. **
  3735. * Returns set of elements that have common point inside
  3736. **
  3737. > Parameters
  3738. **
  3739. - x (number) x coordinate of the point
  3740. - y (number) y coordinate of the point
  3741. = (object) @Set
  3742. \*/
  3743. paperproto.getElementsByPoint = function (x, y) {
  3744. var set = this.set();
  3745. this.forEach(function (el) {
  3746. if (el.isPointInside(x, y)) {
  3747. set.push(el);
  3748. }
  3749. });
  3750. return set;
  3751. };
  3752. function x_y() {
  3753. return this.x + S + this.y;
  3754. }
  3755. function x_y_w_h() {
  3756. return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
  3757. }
  3758. /*\
  3759. * Element.isPointInside
  3760. [ method ]
  3761. **
  3762. * Determine if given point is inside this element’s shape
  3763. **
  3764. > Parameters
  3765. **
  3766. - x (number) x coordinate of the point
  3767. - y (number) y coordinate of the point
  3768. = (boolean) `true` if point inside the shape
  3769. \*/
  3770. elproto.isPointInside = function (x, y) {
  3771. var rp = this.realPath = getPath[this.type](this);
  3772. if (this.attr('transform') && this.attr('transform').length) {
  3773. rp = R.transformPath(rp, this.attr('transform'));
  3774. }
  3775. return R.isPointInsidePath(rp, x, y);
  3776. };
  3777. /*\
  3778. * Element.getBBox
  3779. [ method ]
  3780. **
  3781. * Return bounding box for a given element
  3782. **
  3783. > Parameters
  3784. **
  3785. - isWithoutTransform (boolean) flag, `true` if you want to have bounding box before transformations. Default is `false`.
  3786. = (object) Bounding box object:
  3787. o {
  3788. o x: (number) top left corner x
  3789. o y: (number) top left corner y
  3790. o x2: (number) bottom right corner x
  3791. o y2: (number) bottom right corner y
  3792. o width: (number) width
  3793. o height: (number) height
  3794. o }
  3795. \*/
  3796. elproto.getBBox = function (isWithoutTransform) {
  3797. if (this.removed) {
  3798. return {};
  3799. }
  3800. var _ = this._;
  3801. if (isWithoutTransform) {
  3802. if (_.dirty || !_.bboxwt) {
  3803. this.realPath = getPath[this.type](this);
  3804. _.bboxwt = pathDimensions(this.realPath);
  3805. _.bboxwt.toString = x_y_w_h;
  3806. _.dirty = 0;
  3807. }
  3808. return _.bboxwt;
  3809. }
  3810. if (_.dirty || _.dirtyT || !_.bbox) {
  3811. if (_.dirty || !this.realPath) {
  3812. _.bboxwt = 0;
  3813. this.realPath = getPath[this.type](this);
  3814. }
  3815. _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
  3816. _.bbox.toString = x_y_w_h;
  3817. _.dirty = _.dirtyT = 0;
  3818. }
  3819. return _.bbox;
  3820. };
  3821. /*\
  3822. * Element.clone
  3823. [ method ]
  3824. **
  3825. = (object) clone of a given element
  3826. **
  3827. \*/
  3828. elproto.clone = function () {
  3829. if (this.removed) {
  3830. return null;
  3831. }
  3832. var out = this.paper[this.type]().attr(this.attr());
  3833. this.__set__ && this.__set__.push(out);
  3834. return out;
  3835. };
  3836. /*\
  3837. * Element.glow
  3838. [ method ]
  3839. **
  3840. * Return set of elements that create glow-like effect around given element. See @Paper.set.
  3841. *
  3842. * Note: Glow is not connected to the element. If you change element attributes it won’t adjust itself.
  3843. **
  3844. > Parameters
  3845. **
  3846. - glow (object) #optional parameters object with all properties optional:
  3847. o {
  3848. o width (number) size of the glow, default is `10`
  3849. o fill (boolean) will it be filled, default is `false`
  3850. o opacity (number) opacity, default is `0.5`
  3851. o offsetx (number) horizontal offset, default is `0`
  3852. o offsety (number) vertical offset, default is `0`
  3853. o color (string) glow colour, default is `black`
  3854. o }
  3855. = (object) @Paper.set of elements that represents glow
  3856. \*/
  3857. elproto.glow = function (glow) {
  3858. if (this.type == "text") {
  3859. return null;
  3860. }
  3861. glow = glow || {};
  3862. var s = {
  3863. width: (glow.width || 10) + (+this.attr("stroke-width") || 1),
  3864. fill: glow.fill || false,
  3865. opacity: glow.opacity == null ? .5 : glow.opacity,
  3866. offsetx: glow.offsetx || 0,
  3867. offsety: glow.offsety || 0,
  3868. color: glow.color || "#000"
  3869. },
  3870. c = s.width / 2,
  3871. r = this.paper,
  3872. out = r.set(),
  3873. path = this.realPath || getPath[this.type](this);
  3874. path = this.matrix ? mapPath(path, this.matrix) : path;
  3875. for (var i = 1; i < c + 1; i++) {
  3876. out.push(r.path(path).attr({
  3877. stroke: s.color,
  3878. fill: s.fill ? s.color : "none",
  3879. "stroke-linejoin": "round",
  3880. "stroke-linecap": "round",
  3881. "stroke-width": +(s.width / c * i).toFixed(3),
  3882. opacity: +(s.opacity / c).toFixed(3)
  3883. }));
  3884. }
  3885. return out.insertBefore(this).translate(s.offsetx, s.offsety);
  3886. };
  3887. var curveslengths = {},
  3888. getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  3889. if (length == null) {
  3890. return bezlen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
  3891. } else {
  3892. return R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, getTatLen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length));
  3893. }
  3894. },
  3895. getLengthFactory = function (istotal, subpath) {
  3896. return function (path, length, onlystart) {
  3897. path = path2curve(path);
  3898. var x, y, p, l, sp = "", subpaths = {}, point,
  3899. len = 0;
  3900. for (var i = 0, ii = path.length; i < ii; i++) {
  3901. p = path[i];
  3902. if (p[0] == "M") {
  3903. x = +p[1];
  3904. y = +p[2];
  3905. } else {
  3906. l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  3907. if (len + l > length) {
  3908. if (subpath && !subpaths.start) {
  3909. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  3910. sp += ["C" + point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
  3911. if (onlystart) {return sp;}
  3912. subpaths.start = sp;
  3913. sp = ["M" + point.x, point.y + "C" + point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]].join();
  3914. len += l;
  3915. x = +p[5];
  3916. y = +p[6];
  3917. continue;
  3918. }
  3919. if (!istotal && !subpath) {
  3920. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  3921. return {x: point.x, y: point.y, alpha: point.alpha};
  3922. }
  3923. }
  3924. len += l;
  3925. x = +p[5];
  3926. y = +p[6];
  3927. }
  3928. sp += p.shift() + p;
  3929. }
  3930. subpaths.end = sp;
  3931. point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
  3932. point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
  3933. return point;
  3934. };
  3935. };
  3936. var getTotalLength = getLengthFactory(1),
  3937. getPointAtLength = getLengthFactory(),
  3938. getSubpathsAtLength = getLengthFactory(0, 1);
  3939. /*\
  3940. * Raphael.getTotalLength
  3941. [ method ]
  3942. **
  3943. * Returns length of the given path in pixels.
  3944. **
  3945. > Parameters
  3946. **
  3947. - path (string) SVG path string.
  3948. **
  3949. = (number) length.
  3950. \*/
  3951. R.getTotalLength = getTotalLength;
  3952. /*\
  3953. * Raphael.getPointAtLength
  3954. [ method ]
  3955. **
  3956. * Return coordinates of the point located at the given length on the given path.
  3957. **
  3958. > Parameters
  3959. **
  3960. - path (string) SVG path string
  3961. - length (number)
  3962. **
  3963. = (object) representation of the point:
  3964. o {
  3965. o x: (number) x coordinate
  3966. o y: (number) y coordinate
  3967. o alpha: (number) angle of derivative
  3968. o }
  3969. \*/
  3970. R.getPointAtLength = getPointAtLength;
  3971. /*\
  3972. * Raphael.getSubpath
  3973. [ method ]
  3974. **
  3975. * Return subpath of a given path from given length to given length.
  3976. **
  3977. > Parameters
  3978. **
  3979. - path (string) SVG path string
  3980. - from (number) position of the start of the segment
  3981. - to (number) position of the end of the segment
  3982. **
  3983. = (string) pathstring for the segment
  3984. \*/
  3985. R.getSubpath = function (path, from, to) {
  3986. if (this.getTotalLength(path) - to < 1e-6) {
  3987. return getSubpathsAtLength(path, from).end;
  3988. }
  3989. var a = getSubpathsAtLength(path, to, 1);
  3990. return from ? getSubpathsAtLength(a, from).end : a;
  3991. };
  3992. /*\
  3993. * Element.getTotalLength
  3994. [ method ]
  3995. **
  3996. * Returns length of the path in pixels. Only works for element of “path” type.
  3997. = (number) length.
  3998. \*/
  3999. elproto.getTotalLength = function () {
  4000. var path = this.getPath();
  4001. if (!path) {
  4002. return;
  4003. }
  4004. if (this.node.getTotalLength) {
  4005. return this.node.getTotalLength();
  4006. }
  4007. return getTotalLength(path);
  4008. };
  4009. /*\
  4010. * Element.getPointAtLength
  4011. [ method ]
  4012. **
  4013. * Return coordinates of the point located at the given length on the given path. Only works for element of “path” type.
  4014. **
  4015. > Parameters
  4016. **
  4017. - length (number)
  4018. **
  4019. = (object) representation of the point:
  4020. o {
  4021. o x: (number) x coordinate
  4022. o y: (number) y coordinate
  4023. o alpha: (number) angle of derivative
  4024. o }
  4025. \*/
  4026. elproto.getPointAtLength = function (length) {
  4027. var path = this.getPath();
  4028. if (!path) {
  4029. return;
  4030. }
  4031. return getPointAtLength(path, length);
  4032. };
  4033. /*\
  4034. * Element.getPath
  4035. [ method ]
  4036. **
  4037. * Returns path of the element. Only works for elements of “path” type and simple elements like circle.
  4038. = (object) path
  4039. **
  4040. \*/
  4041. elproto.getPath = function () {
  4042. var path,
  4043. getPath = R._getPath[this.type];
  4044. if (this.type == "text" || this.type == "set") {
  4045. return;
  4046. }
  4047. if (getPath) {
  4048. path = getPath(this);
  4049. }
  4050. return path;
  4051. };
  4052. /*\
  4053. * Element.getSubpath
  4054. [ method ]
  4055. **
  4056. * Return subpath of a given element from given length to given length. Only works for element of “path” type.
  4057. **
  4058. > Parameters
  4059. **
  4060. - from (number) position of the start of the segment
  4061. - to (number) position of the end of the segment
  4062. **
  4063. = (string) pathstring for the segment
  4064. \*/
  4065. elproto.getSubpath = function (from, to) {
  4066. var path = this.getPath();
  4067. if (!path) {
  4068. return;
  4069. }
  4070. return R.getSubpath(path, from, to);
  4071. };
  4072. /*\
  4073. * Raphael.easing_formulas
  4074. [ property ]
  4075. **
  4076. * Object that contains easing formulas for animation. You could extend it with your own. By default it has following list of easing:
  4077. # <ul>
  4078. # <li>“linear”</li>
  4079. # <li>“&lt;” or “easeIn” or “ease-in”</li>
  4080. # <li>“>” or “easeOut” or “ease-out”</li>
  4081. # <li>“&lt;>” or “easeInOut” or “ease-in-out”</li>
  4082. # <li>“backIn” or “back-in”</li>
  4083. # <li>“backOut” or “back-out”</li>
  4084. # <li>“elastic”</li>
  4085. # <li>“bounce”</li>
  4086. # </ul>
  4087. # <p>See also <a href="http://raphaeljs.com/easing.html">Easing demo</a>.</p>
  4088. \*/
  4089. var ef = R.easing_formulas = {
  4090. linear: function (n) {
  4091. return n;
  4092. },
  4093. "<": function (n) {
  4094. return pow(n, 1.7);
  4095. },
  4096. ">": function (n) {
  4097. return pow(n, .48);
  4098. },
  4099. "<>": function (n) {
  4100. var q = .48 - n / 1.04,
  4101. Q = math.sqrt(.1734 + q * q),
  4102. x = Q - q,
  4103. X = pow(abs(x), 1 / 3) * (x < 0 ? -1 : 1),
  4104. y = -Q - q,
  4105. Y = pow(abs(y), 1 / 3) * (y < 0 ? -1 : 1),
  4106. t = X + Y + .5;
  4107. return (1 - t) * 3 * t * t + t * t * t;
  4108. },
  4109. backIn: function (n) {
  4110. var s = 1.70158;
  4111. return n * n * ((s + 1) * n - s);
  4112. },
  4113. backOut: function (n) {
  4114. n = n - 1;
  4115. var s = 1.70158;
  4116. return n * n * ((s + 1) * n + s) + 1;
  4117. },
  4118. elastic: function (n) {
  4119. if (n == !!n) {
  4120. return n;
  4121. }
  4122. return pow(2, -10 * n) * math.sin((n - .075) * (2 * PI) / .3) + 1;
  4123. },
  4124. bounce: function (n) {
  4125. var s = 7.5625,
  4126. p = 2.75,
  4127. l;
  4128. if (n < (1 / p)) {
  4129. l = s * n * n;
  4130. } else {
  4131. if (n < (2 / p)) {
  4132. n -= (1.5 / p);
  4133. l = s * n * n + .75;
  4134. } else {
  4135. if (n < (2.5 / p)) {
  4136. n -= (2.25 / p);
  4137. l = s * n * n + .9375;
  4138. } else {
  4139. n -= (2.625 / p);
  4140. l = s * n * n + .984375;
  4141. }
  4142. }
  4143. }
  4144. return l;
  4145. }
  4146. };
  4147. ef.easeIn = ef["ease-in"] = ef["<"];
  4148. ef.easeOut = ef["ease-out"] = ef[">"];
  4149. ef.easeInOut = ef["ease-in-out"] = ef["<>"];
  4150. ef["back-in"] = ef.backIn;
  4151. ef["back-out"] = ef.backOut;
  4152. var animationElements = [],
  4153. requestAnimFrame = window.requestAnimationFrame ||
  4154. window.webkitRequestAnimationFrame ||
  4155. window.mozRequestAnimationFrame ||
  4156. window.oRequestAnimationFrame ||
  4157. window.msRequestAnimationFrame ||
  4158. function (callback) {
  4159. setTimeout(callback, 16);
  4160. },
  4161. animation = function () {
  4162. var Now = +new Date,
  4163. l = 0;
  4164. for (; l < animationElements.length; l++) {
  4165. var e = animationElements[l];
  4166. if (e.el.removed || e.paused) {
  4167. continue;
  4168. }
  4169. var time = Now - e.start,
  4170. ms = e.ms,
  4171. easing = e.easing,
  4172. from = e.from,
  4173. diff = e.diff,
  4174. to = e.to,
  4175. t = e.t,
  4176. that = e.el,
  4177. set = {},
  4178. now,
  4179. init = {},
  4180. key;
  4181. if (e.initstatus) {
  4182. time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms;
  4183. e.status = e.initstatus;
  4184. delete e.initstatus;
  4185. e.stop && animationElements.splice(l--, 1);
  4186. } else {
  4187. e.status = (e.prev + (e.percent - e.prev) * (time / ms)) / e.anim.top;
  4188. }
  4189. if (time < 0) {
  4190. continue;
  4191. }
  4192. if (time < ms) {
  4193. var pos = easing(time / ms);
  4194. for (var attr in from) if (from[has](attr)) {
  4195. switch (availableAnimAttrs[attr]) {
  4196. case nu:
  4197. now = +from[attr] + pos * ms * diff[attr];
  4198. break;
  4199. case "colour":
  4200. now = "rgb(" + [
  4201. upto255(round(from[attr].r + pos * ms * diff[attr].r)),
  4202. upto255(round(from[attr].g + pos * ms * diff[attr].g)),
  4203. upto255(round(from[attr].b + pos * ms * diff[attr].b))
  4204. ].join(",") + ")";
  4205. break;
  4206. case "path":
  4207. now = [];
  4208. for (var i = 0, ii = from[attr].length; i < ii; i++) {
  4209. now[i] = [from[attr][i][0]];
  4210. for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
  4211. now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
  4212. }
  4213. now[i] = now[i].join(S);
  4214. }
  4215. now = now.join(S);
  4216. break;
  4217. case "transform":
  4218. if (diff[attr].real) {
  4219. now = [];
  4220. for (i = 0, ii = from[attr].length; i < ii; i++) {
  4221. now[i] = [from[attr][i][0]];
  4222. for (j = 1, jj = from[attr][i].length; j < jj; j++) {
  4223. now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
  4224. }
  4225. }
  4226. } else {
  4227. var get = function (i) {
  4228. return +from[attr][i] + pos * ms * diff[attr][i];
  4229. };
  4230. // now = [["r", get(2), 0, 0], ["t", get(3), get(4)], ["s", get(0), get(1), 0, 0]];
  4231. now = [["m", get(0), get(1), get(2), get(3), get(4), get(5)]];
  4232. }
  4233. break;
  4234. case "csv":
  4235. if (attr == "clip-rect") {
  4236. now = [];
  4237. i = 4;
  4238. while (i--) {
  4239. now[i] = +from[attr][i] + pos * ms * diff[attr][i];
  4240. }
  4241. }
  4242. break;
  4243. default:
  4244. var from2 = [][concat](from[attr]);
  4245. now = [];
  4246. i = that.paper.customAttributes[attr].length;
  4247. while (i--) {
  4248. now[i] = +from2[i] + pos * ms * diff[attr][i];
  4249. }
  4250. break;
  4251. }
  4252. set[attr] = now;
  4253. }
  4254. that.attr(set);
  4255. (function (id, that, anim) {
  4256. setTimeout(function () {
  4257. eve("raphael.anim.frame." + id, that, anim);
  4258. });
  4259. })(that.id, that, e.anim);
  4260. } else {
  4261. (function(f, el, a) {
  4262. setTimeout(function() {
  4263. eve("raphael.anim.frame." + el.id, el, a);
  4264. eve("raphael.anim.finish." + el.id, el, a);
  4265. R.is(f, "function") && f.call(el);
  4266. });
  4267. })(e.callback, that, e.anim);
  4268. that.attr(to);
  4269. animationElements.splice(l--, 1);
  4270. if (e.repeat > 1 && !e.next) {
  4271. for (key in to) if (to[has](key)) {
  4272. init[key] = e.totalOrigin[key];
  4273. }
  4274. e.el.attr(init);
  4275. runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1);
  4276. }
  4277. if (e.next && !e.stop) {
  4278. runAnimation(e.anim, e.el, e.next, null, e.totalOrigin, e.repeat);
  4279. }
  4280. }
  4281. }
  4282. animationElements.length && requestAnimFrame(animation);
  4283. },
  4284. upto255 = function (color) {
  4285. return color > 255 ? 255 : color < 0 ? 0 : color;
  4286. };
  4287. /*\
  4288. * Element.animateWith
  4289. [ method ]
  4290. **
  4291. * Acts similar to @Element.animate, but ensure that given animation runs in sync with another given element.
  4292. **
  4293. > Parameters
  4294. **
  4295. - el (object) element to sync with
  4296. - anim (object) animation to sync with
  4297. - params (object) #optional final attributes for the element, see also @Element.attr
  4298. - ms (number) #optional number of milliseconds for animation to run
  4299. - easing (string) #optional easing type. Accept on of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
  4300. - callback (function) #optional callback function. Will be called at the end of animation.
  4301. * or
  4302. - element (object) element to sync with
  4303. - anim (object) animation to sync with
  4304. - animation (object) #optional animation object, see @Raphael.animation
  4305. **
  4306. = (object) original element
  4307. \*/
  4308. elproto.animateWith = function (el, anim, params, ms, easing, callback) {
  4309. var element = this;
  4310. if (element.removed) {
  4311. callback && callback.call(element);
  4312. return element;
  4313. }
  4314. var a = params instanceof Animation ? params : R.animation(params, ms, easing, callback),
  4315. x, y;
  4316. runAnimation(a, element, a.percents[0], null, element.attr());
  4317. for (var i = 0, ii = animationElements.length; i < ii; i++) {
  4318. if (animationElements[i].anim == anim && animationElements[i].el == el) {
  4319. animationElements[ii - 1].start = animationElements[i].start;
  4320. break;
  4321. }
  4322. }
  4323. return element;
  4324. //
  4325. //
  4326. // var a = params ? R.animation(params, ms, easing, callback) : anim,
  4327. // status = element.status(anim);
  4328. // return this.animate(a).status(a, status * anim.ms / a.ms);
  4329. };
  4330. function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
  4331. var cx = 3 * p1x,
  4332. bx = 3 * (p2x - p1x) - cx,
  4333. ax = 1 - cx - bx,
  4334. cy = 3 * p1y,
  4335. by = 3 * (p2y - p1y) - cy,
  4336. ay = 1 - cy - by;
  4337. function sampleCurveX(t) {
  4338. return ((ax * t + bx) * t + cx) * t;
  4339. }
  4340. function solve(x, epsilon) {
  4341. var t = solveCurveX(x, epsilon);
  4342. return ((ay * t + by) * t + cy) * t;
  4343. }
  4344. function solveCurveX(x, epsilon) {
  4345. var t0, t1, t2, x2, d2, i;
  4346. for(t2 = x, i = 0; i < 8; i++) {
  4347. x2 = sampleCurveX(t2) - x;
  4348. if (abs(x2) < epsilon) {
  4349. return t2;
  4350. }
  4351. d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
  4352. if (abs(d2) < 1e-6) {
  4353. break;
  4354. }
  4355. t2 = t2 - x2 / d2;
  4356. }
  4357. t0 = 0;
  4358. t1 = 1;
  4359. t2 = x;
  4360. if (t2 < t0) {
  4361. return t0;
  4362. }
  4363. if (t2 > t1) {
  4364. return t1;
  4365. }
  4366. while (t0 < t1) {
  4367. x2 = sampleCurveX(t2);
  4368. if (abs(x2 - x) < epsilon) {
  4369. return t2;
  4370. }
  4371. if (x > x2) {
  4372. t0 = t2;
  4373. } else {
  4374. t1 = t2;
  4375. }
  4376. t2 = (t1 - t0) / 2 + t0;
  4377. }
  4378. return t2;
  4379. }
  4380. return solve(t, 1 / (200 * duration));
  4381. }
  4382. elproto.onAnimation = function (f) {
  4383. f ? eve.on("raphael.anim.frame." + this.id, f) : eve.unbind("raphael.anim.frame." + this.id);
  4384. return this;
  4385. };
  4386. function Animation(anim, ms) {
  4387. var percents = [],
  4388. newAnim = {};
  4389. this.ms = ms;
  4390. this.times = 1;
  4391. if (anim) {
  4392. for (var attr in anim) if (anim[has](attr)) {
  4393. newAnim[toFloat(attr)] = anim[attr];
  4394. percents.push(toFloat(attr));
  4395. }
  4396. percents.sort(sortByNumber);
  4397. }
  4398. this.anim = newAnim;
  4399. this.top = percents[percents.length - 1];
  4400. this.percents = percents;
  4401. }
  4402. /*\
  4403. * Animation.delay
  4404. [ method ]
  4405. **
  4406. * Creates a copy of existing animation object with given delay.
  4407. **
  4408. > Parameters
  4409. **
  4410. - delay (number) number of ms to pass between animation start and actual animation
  4411. **
  4412. = (object) new altered Animation object
  4413. | var anim = Raphael.animation({cx: 10, cy: 20}, 2e3);
  4414. | circle1.animate(anim); // run the given animation immediately
  4415. | circle2.animate(anim.delay(500)); // run the given animation after 500 ms
  4416. \*/
  4417. Animation.prototype.delay = function (delay) {
  4418. var a = new Animation(this.anim, this.ms);
  4419. a.times = this.times;
  4420. a.del = +delay || 0;
  4421. return a;
  4422. };
  4423. /*\
  4424. * Animation.repeat
  4425. [ method ]
  4426. **
  4427. * Creates a copy of existing animation object with given repetition.
  4428. **
  4429. > Parameters
  4430. **
  4431. - repeat (number) number iterations of animation. For infinite animation pass `Infinity`
  4432. **
  4433. = (object) new altered Animation object
  4434. \*/
  4435. Animation.prototype.repeat = function (times) {
  4436. var a = new Animation(this.anim, this.ms);
  4437. a.del = this.del;
  4438. a.times = math.floor(mmax(times, 0)) || 1;
  4439. return a;
  4440. };
  4441. function runAnimation(anim, element, percent, status, totalOrigin, times) {
  4442. percent = toFloat(percent);
  4443. var params,
  4444. isInAnim,
  4445. isInAnimSet,
  4446. percents = [],
  4447. next,
  4448. prev,
  4449. timestamp,
  4450. ms = anim.ms,
  4451. from = {},
  4452. to = {},
  4453. diff = {};
  4454. if (status) {
  4455. for (i = 0, ii = animationElements.length; i < ii; i++) {
  4456. var e = animationElements[i];
  4457. if (e.el.id == element.id && e.anim == anim) {
  4458. if (e.percent != percent) {
  4459. animationElements.splice(i, 1);
  4460. isInAnimSet = 1;
  4461. } else {
  4462. isInAnim = e;
  4463. }
  4464. element.attr(e.totalOrigin);
  4465. break;
  4466. }
  4467. }
  4468. } else {
  4469. status = +to; // NaN
  4470. }
  4471. for (var i = 0, ii = anim.percents.length; i < ii; i++) {
  4472. if (anim.percents[i] == percent || anim.percents[i] > status * anim.top) {
  4473. percent = anim.percents[i];
  4474. prev = anim.percents[i - 1] || 0;
  4475. ms = ms / anim.top * (percent - prev);
  4476. next = anim.percents[i + 1];
  4477. params = anim.anim[percent];
  4478. break;
  4479. } else if (status) {
  4480. element.attr(anim.anim[anim.percents[i]]);
  4481. }
  4482. }
  4483. if (!params) {
  4484. return;
  4485. }
  4486. if (!isInAnim) {
  4487. for (var attr in params) if (params[has](attr)) {
  4488. if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
  4489. from[attr] = element.attr(attr);
  4490. (from[attr] == null) && (from[attr] = availableAttrs[attr]);
  4491. to[attr] = params[attr];
  4492. switch (availableAnimAttrs[attr]) {
  4493. case nu:
  4494. diff[attr] = (to[attr] - from[attr]) / ms;
  4495. break;
  4496. case "colour":
  4497. from[attr] = R.getRGB(from[attr]);
  4498. var toColour = R.getRGB(to[attr]);
  4499. diff[attr] = {
  4500. r: (toColour.r - from[attr].r) / ms,
  4501. g: (toColour.g - from[attr].g) / ms,
  4502. b: (toColour.b - from[attr].b) / ms
  4503. };
  4504. break;
  4505. case "path":
  4506. var pathes = path2curve(from[attr], to[attr]),
  4507. toPath = pathes[1];
  4508. from[attr] = pathes[0];
  4509. diff[attr] = [];
  4510. for (i = 0, ii = from[attr].length; i < ii; i++) {
  4511. diff[attr][i] = [0];
  4512. for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
  4513. diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
  4514. }
  4515. }
  4516. break;
  4517. case "transform":
  4518. var _ = element._,
  4519. eq = equaliseTransform(_[attr], to[attr]);
  4520. if (eq) {
  4521. from[attr] = eq.from;
  4522. to[attr] = eq.to;
  4523. diff[attr] = [];
  4524. diff[attr].real = true;
  4525. for (i = 0, ii = from[attr].length; i < ii; i++) {
  4526. diff[attr][i] = [from[attr][i][0]];
  4527. for (j = 1, jj = from[attr][i].length; j < jj; j++) {
  4528. diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
  4529. }
  4530. }
  4531. } else {
  4532. var m = (element.matrix || new Matrix),
  4533. to2 = {
  4534. _: {transform: _.transform},
  4535. getBBox: function () {
  4536. return element.getBBox(1);
  4537. }
  4538. };
  4539. from[attr] = [
  4540. m.a,
  4541. m.b,
  4542. m.c,
  4543. m.d,
  4544. m.e,
  4545. m.f
  4546. ];
  4547. extractTransform(to2, to[attr]);
  4548. to[attr] = to2._.transform;
  4549. diff[attr] = [
  4550. (to2.matrix.a - m.a) / ms,
  4551. (to2.matrix.b - m.b) / ms,
  4552. (to2.matrix.c - m.c) / ms,
  4553. (to2.matrix.d - m.d) / ms,
  4554. (to2.matrix.e - m.e) / ms,
  4555. (to2.matrix.f - m.f) / ms
  4556. ];
  4557. // from[attr] = [_.sx, _.sy, _.deg, _.dx, _.dy];
  4558. // var to2 = {_:{}, getBBox: function () { return element.getBBox(); }};
  4559. // extractTransform(to2, to[attr]);
  4560. // diff[attr] = [
  4561. // (to2._.sx - _.sx) / ms,
  4562. // (to2._.sy - _.sy) / ms,
  4563. // (to2._.deg - _.deg) / ms,
  4564. // (to2._.dx - _.dx) / ms,
  4565. // (to2._.dy - _.dy) / ms
  4566. // ];
  4567. }
  4568. break;
  4569. case "csv":
  4570. var values = Str(params[attr])[split](separator),
  4571. from2 = Str(from[attr])[split](separator);
  4572. if (attr == "clip-rect") {
  4573. from[attr] = from2;
  4574. diff[attr] = [];
  4575. i = from2.length;
  4576. while (i--) {
  4577. diff[attr][i] = (values[i] - from[attr][i]) / ms;
  4578. }
  4579. }
  4580. to[attr] = values;
  4581. break;
  4582. default:
  4583. values = [][concat](params[attr]);
  4584. from2 = [][concat](from[attr]);
  4585. diff[attr] = [];
  4586. i = element.paper.customAttributes[attr].length;
  4587. while (i--) {
  4588. diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
  4589. }
  4590. break;
  4591. }
  4592. }
  4593. }
  4594. var easing = params.easing,
  4595. easyeasy = R.easing_formulas[easing];
  4596. if (!easyeasy) {
  4597. easyeasy = Str(easing).match(bezierrg);
  4598. if (easyeasy && easyeasy.length == 5) {
  4599. var curve = easyeasy;
  4600. easyeasy = function (t) {
  4601. return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
  4602. };
  4603. } else {
  4604. easyeasy = pipe;
  4605. }
  4606. }
  4607. timestamp = params.start || anim.start || +new Date;
  4608. e = {
  4609. anim: anim,
  4610. percent: percent,
  4611. timestamp: timestamp,
  4612. start: timestamp + (anim.del || 0),
  4613. status: 0,
  4614. initstatus: status || 0,
  4615. stop: false,
  4616. ms: ms,
  4617. easing: easyeasy,
  4618. from: from,
  4619. diff: diff,
  4620. to: to,
  4621. el: element,
  4622. callback: params.callback,
  4623. prev: prev,
  4624. next: next,
  4625. repeat: times || anim.times,
  4626. origin: element.attr(),
  4627. totalOrigin: totalOrigin
  4628. };
  4629. animationElements.push(e);
  4630. if (status && !isInAnim && !isInAnimSet) {
  4631. e.stop = true;
  4632. e.start = new Date - ms * status;
  4633. if (animationElements.length == 1) {
  4634. return animation();
  4635. }
  4636. }
  4637. if (isInAnimSet) {
  4638. e.start = new Date - e.ms * status;
  4639. }
  4640. animationElements.length == 1 && requestAnimFrame(animation);
  4641. } else {
  4642. isInAnim.initstatus = status;
  4643. isInAnim.start = new Date - isInAnim.ms * status;
  4644. }
  4645. eve("raphael.anim.start." + element.id, element, anim);
  4646. }
  4647. /*\
  4648. * Raphael.animation
  4649. [ method ]
  4650. **
  4651. * Creates an animation object that can be passed to the @Element.animate or @Element.animateWith methods.
  4652. * See also @Animation.delay and @Animation.repeat methods.
  4653. **
  4654. > Parameters
  4655. **
  4656. - params (object) final attributes for the element, see also @Element.attr
  4657. - ms (number) number of milliseconds for animation to run
  4658. - easing (string) #optional easing type. Accept one of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
  4659. - callback (function) #optional callback function. Will be called at the end of animation.
  4660. **
  4661. = (object) @Animation
  4662. \*/
  4663. R.animation = function (params, ms, easing, callback) {
  4664. if (params instanceof Animation) {
  4665. return params;
  4666. }
  4667. if (R.is(easing, "function") || !easing) {
  4668. callback = callback || easing || null;
  4669. easing = null;
  4670. }
  4671. params = Object(params);
  4672. ms = +ms || 0;
  4673. var p = {},
  4674. json,
  4675. attr;
  4676. for (attr in params) if (params[has](attr) && toFloat(attr) != attr && toFloat(attr) + "%" != attr) {
  4677. json = true;
  4678. p[attr] = params[attr];
  4679. }
  4680. if (!json) {
  4681. // if percent-like syntax is used and end-of-all animation callback used
  4682. if(callback){
  4683. // find the last one
  4684. var lastKey = 0;
  4685. for(var i in params){
  4686. var percent = toInt(i);
  4687. if(params[has](i) && percent > lastKey){
  4688. lastKey = percent;
  4689. }
  4690. }
  4691. lastKey += '%';
  4692. // if already defined callback in the last keyframe, skip
  4693. !params[lastKey].callback && (params[lastKey].callback = callback);
  4694. }
  4695. return new Animation(params, ms);
  4696. } else {
  4697. easing && (p.easing = easing);
  4698. callback && (p.callback = callback);
  4699. return new Animation({100: p}, ms);
  4700. }
  4701. };
  4702. /*\
  4703. * Element.animate
  4704. [ method ]
  4705. **
  4706. * Creates and starts animation for given element.
  4707. **
  4708. > Parameters
  4709. **
  4710. - params (object) final attributes for the element, see also @Element.attr
  4711. - ms (number) number of milliseconds for animation to run
  4712. - easing (string) #optional easing type. Accept one of @Raphael.easing_formulas or CSS format: `cubic&#x2010;bezier(XX,&#160;XX,&#160;XX,&#160;XX)`
  4713. - callback (function) #optional callback function. Will be called at the end of animation.
  4714. * or
  4715. - animation (object) animation object, see @Raphael.animation
  4716. **
  4717. = (object) original element
  4718. \*/
  4719. elproto.animate = function (params, ms, easing, callback) {
  4720. var element = this;
  4721. if (element.removed) {
  4722. callback && callback.call(element);
  4723. return element;
  4724. }
  4725. var anim = params instanceof Animation ? params : R.animation(params, ms, easing, callback);
  4726. runAnimation(anim, element, anim.percents[0], null, element.attr());
  4727. return element;
  4728. };
  4729. /*\
  4730. * Element.setTime
  4731. [ method ]
  4732. **
  4733. * Sets the status of animation of the element in milliseconds. Similar to @Element.status method.
  4734. **
  4735. > Parameters
  4736. **
  4737. - anim (object) animation object
  4738. - value (number) number of milliseconds from the beginning of the animation
  4739. **
  4740. = (object) original element if `value` is specified
  4741. * Note, that during animation following events are triggered:
  4742. *
  4743. * On each animation frame event `anim.frame.<id>`, on start `anim.start.<id>` and on end `anim.finish.<id>`.
  4744. \*/
  4745. elproto.setTime = function (anim, value) {
  4746. if (anim && value != null) {
  4747. this.status(anim, mmin(value, anim.ms) / anim.ms);
  4748. }
  4749. return this;
  4750. };
  4751. /*\
  4752. * Element.status
  4753. [ method ]
  4754. **
  4755. * Gets or sets the status of animation of the element.
  4756. **
  4757. > Parameters
  4758. **
  4759. - anim (object) #optional animation object
  4760. - value (number) #optional 0 – 1. If specified, method works like a setter and sets the status of a given animation to the value. This will cause animation to jump to the given position.
  4761. **
  4762. = (number) status
  4763. * or
  4764. = (array) status if `anim` is not specified. Array of objects in format:
  4765. o {
  4766. o anim: (object) animation object
  4767. o status: (number) status
  4768. o }
  4769. * or
  4770. = (object) original element if `value` is specified
  4771. \*/
  4772. elproto.status = function (anim, value) {
  4773. var out = [],
  4774. i = 0,
  4775. len,
  4776. e;
  4777. if (value != null) {
  4778. runAnimation(anim, this, -1, mmin(value, 1));
  4779. return this;
  4780. } else {
  4781. len = animationElements.length;
  4782. for (; i < len; i++) {
  4783. e = animationElements[i];
  4784. if (e.el.id == this.id && (!anim || e.anim == anim)) {
  4785. if (anim) {
  4786. return e.status;
  4787. }
  4788. out.push({
  4789. anim: e.anim,
  4790. status: e.status
  4791. });
  4792. }
  4793. }
  4794. if (anim) {
  4795. return 0;
  4796. }
  4797. return out;
  4798. }
  4799. };
  4800. /*\
  4801. * Element.pause
  4802. [ method ]
  4803. **
  4804. * Stops animation of the element with ability to resume it later on.
  4805. **
  4806. > Parameters
  4807. **
  4808. - anim (object) #optional animation object
  4809. **
  4810. = (object) original element
  4811. \*/
  4812. elproto.pause = function (anim) {
  4813. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  4814. if (eve("raphael.anim.pause." + this.id, this, animationElements[i].anim) !== false) {
  4815. animationElements[i].paused = true;
  4816. }
  4817. }
  4818. return this;
  4819. };
  4820. /*\
  4821. * Element.resume
  4822. [ method ]
  4823. **
  4824. * Resumes animation if it was paused with @Element.pause method.
  4825. **
  4826. > Parameters
  4827. **
  4828. - anim (object) #optional animation object
  4829. **
  4830. = (object) original element
  4831. \*/
  4832. elproto.resume = function (anim) {
  4833. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  4834. var e = animationElements[i];
  4835. if (eve("raphael.anim.resume." + this.id, this, e.anim) !== false) {
  4836. delete e.paused;
  4837. this.status(e.anim, e.status);
  4838. }
  4839. }
  4840. return this;
  4841. };
  4842. /*\
  4843. * Element.stop
  4844. [ method ]
  4845. **
  4846. * Stops animation of the element.
  4847. **
  4848. > Parameters
  4849. **
  4850. - anim (object) #optional animation object
  4851. **
  4852. = (object) original element
  4853. \*/
  4854. elproto.stop = function (anim) {
  4855. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  4856. if (eve("raphael.anim.stop." + this.id, this, animationElements[i].anim) !== false) {
  4857. animationElements.splice(i--, 1);
  4858. }
  4859. }
  4860. return this;
  4861. };
  4862. function stopAnimation(paper) {
  4863. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.paper == paper) {
  4864. animationElements.splice(i--, 1);
  4865. }
  4866. }
  4867. eve.on("raphael.remove", stopAnimation);
  4868. eve.on("raphael.clear", stopAnimation);
  4869. elproto.toString = function () {
  4870. return "Rapha\xebl\u2019s object";
  4871. };
  4872. // Set
  4873. var Set = function (items) {
  4874. this.items = [];
  4875. this.length = 0;
  4876. this.type = "set";
  4877. if (items) {
  4878. for (var i = 0, ii = items.length; i < ii; i++) {
  4879. if (items[i] && (items[i].constructor == elproto.constructor || items[i].constructor == Set)) {
  4880. this[this.items.length] = this.items[this.items.length] = items[i];
  4881. this.length++;
  4882. }
  4883. }
  4884. }
  4885. },
  4886. setproto = Set.prototype;
  4887. /*\
  4888. * Set.push
  4889. [ method ]
  4890. **
  4891. * Adds each argument to the current set.
  4892. = (object) original element
  4893. \*/
  4894. setproto.push = function () {
  4895. var item,
  4896. len;
  4897. for (var i = 0, ii = arguments.length; i < ii; i++) {
  4898. item = arguments[i];
  4899. if (item && (item.constructor == elproto.constructor || item.constructor == Set)) {
  4900. len = this.items.length;
  4901. this[len] = this.items[len] = item;
  4902. this.length++;
  4903. }
  4904. }
  4905. return this;
  4906. };
  4907. /*\
  4908. * Set.pop
  4909. [ method ]
  4910. **
  4911. * Removes last element and returns it.
  4912. = (object) element
  4913. \*/
  4914. setproto.pop = function () {
  4915. this.length && delete this[this.length--];
  4916. return this.items.pop();
  4917. };
  4918. /*\
  4919. * Set.forEach
  4920. [ method ]
  4921. **
  4922. * Executes given function for each element in the set.
  4923. *
  4924. * If function returns `false` it will stop loop running.
  4925. **
  4926. > Parameters
  4927. **
  4928. - callback (function) function to run
  4929. - thisArg (object) context object for the callback
  4930. = (object) Set object
  4931. \*/
  4932. setproto.forEach = function (callback, thisArg) {
  4933. for (var i = 0, ii = this.items.length; i < ii; i++) {
  4934. if (callback.call(thisArg, this.items[i], i) === false) {
  4935. return this;
  4936. }
  4937. }
  4938. return this;
  4939. };
  4940. for (var method in elproto) if (elproto[has](method)) {
  4941. setproto[method] = (function (methodname) {
  4942. return function () {
  4943. var arg = arguments;
  4944. return this.forEach(function (el) {
  4945. el[methodname][apply](el, arg);
  4946. });
  4947. };
  4948. })(method);
  4949. }
  4950. setproto.attr = function (name, value) {
  4951. if (name && R.is(name, array) && R.is(name[0], "object")) {
  4952. for (var j = 0, jj = name.length; j < jj; j++) {
  4953. this.items[j].attr(name[j]);
  4954. }
  4955. } else {
  4956. for (var i = 0, ii = this.items.length; i < ii; i++) {
  4957. this.items[i].attr(name, value);
  4958. }
  4959. }
  4960. return this;
  4961. };
  4962. /*\
  4963. * Set.clear
  4964. [ method ]
  4965. **
  4966. * Removes all elements from the set
  4967. \*/
  4968. setproto.clear = function () {
  4969. while (this.length) {
  4970. this.pop();
  4971. }
  4972. };
  4973. /*\
  4974. * Set.splice
  4975. [ method ]
  4976. **
  4977. * Removes given element from the set
  4978. **
  4979. > Parameters
  4980. **
  4981. - index (number) position of the deletion
  4982. - count (number) number of element to remove
  4983. - insertion… (object) #optional elements to insert
  4984. = (object) set elements that were deleted
  4985. \*/
  4986. setproto.splice = function (index, count, insertion) {
  4987. index = index < 0 ? mmax(this.length + index, 0) : index;
  4988. count = mmax(0, mmin(this.length - index, count));
  4989. var tail = [],
  4990. todel = [],
  4991. args = [],
  4992. i;
  4993. for (i = 2; i < arguments.length; i++) {
  4994. args.push(arguments[i]);
  4995. }
  4996. for (i = 0; i < count; i++) {
  4997. todel.push(this[index + i]);
  4998. }
  4999. for (; i < this.length - index; i++) {
  5000. tail.push(this[index + i]);
  5001. }
  5002. var arglen = args.length;
  5003. for (i = 0; i < arglen + tail.length; i++) {
  5004. this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
  5005. }
  5006. i = this.items.length = this.length -= count - arglen;
  5007. while (this[i]) {
  5008. delete this[i++];
  5009. }
  5010. return new Set(todel);
  5011. };
  5012. /*\
  5013. * Set.exclude
  5014. [ method ]
  5015. **
  5016. * Removes given element from the set
  5017. **
  5018. > Parameters
  5019. **
  5020. - element (object) element to remove
  5021. = (boolean) `true` if object was found & removed from the set
  5022. \*/
  5023. setproto.exclude = function (el) {
  5024. for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) {
  5025. this.splice(i, 1);
  5026. return true;
  5027. }
  5028. };
  5029. setproto.animate = function (params, ms, easing, callback) {
  5030. (R.is(easing, "function") || !easing) && (callback = easing || null);
  5031. var len = this.items.length,
  5032. i = len,
  5033. item,
  5034. set = this,
  5035. collector;
  5036. if (!len) {
  5037. return this;
  5038. }
  5039. callback && (collector = function () {
  5040. !--len && callback.call(set);
  5041. });
  5042. easing = R.is(easing, string) ? easing : collector;
  5043. var anim = R.animation(params, ms, easing, collector);
  5044. item = this.items[--i].animate(anim);
  5045. while (i--) {
  5046. this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim, anim);
  5047. (this.items[i] && !this.items[i].removed) || len--;
  5048. }
  5049. return this;
  5050. };
  5051. setproto.insertAfter = function (el) {
  5052. var i = this.items.length;
  5053. while (i--) {
  5054. this.items[i].insertAfter(el);
  5055. }
  5056. return this;
  5057. };
  5058. setproto.getBBox = function () {
  5059. var x = [],
  5060. y = [],
  5061. x2 = [],
  5062. y2 = [];
  5063. for (var i = this.items.length; i--;) if (!this.items[i].removed) {
  5064. var box = this.items[i].getBBox();
  5065. x.push(box.x);
  5066. y.push(box.y);
  5067. x2.push(box.x + box.width);
  5068. y2.push(box.y + box.height);
  5069. }
  5070. x = mmin[apply](0, x);
  5071. y = mmin[apply](0, y);
  5072. x2 = mmax[apply](0, x2);
  5073. y2 = mmax[apply](0, y2);
  5074. return {
  5075. x: x,
  5076. y: y,
  5077. x2: x2,
  5078. y2: y2,
  5079. width: x2 - x,
  5080. height: y2 - y
  5081. };
  5082. };
  5083. setproto.clone = function (s) {
  5084. s = this.paper.set();
  5085. for (var i = 0, ii = this.items.length; i < ii; i++) {
  5086. s.push(this.items[i].clone());
  5087. }
  5088. return s;
  5089. };
  5090. setproto.toString = function () {
  5091. return "Rapha\xebl\u2018s set";
  5092. };
  5093. setproto.glow = function(glowConfig) {
  5094. var ret = this.paper.set();
  5095. this.forEach(function(shape, index){
  5096. var g = shape.glow(glowConfig);
  5097. if(g != null){
  5098. g.forEach(function(shape2, index2){
  5099. ret.push(shape2);
  5100. });
  5101. }
  5102. });
  5103. return ret;
  5104. };
  5105. /*\
  5106. * Set.isPointInside
  5107. [ method ]
  5108. **
  5109. * Determine if given point is inside this set’s elements
  5110. **
  5111. > Parameters
  5112. **
  5113. - x (number) x coordinate of the point
  5114. - y (number) y coordinate of the point
  5115. = (boolean) `true` if point is inside any of the set's elements
  5116. \*/
  5117. setproto.isPointInside = function (x, y) {
  5118. var isPointInside = false;
  5119. this.forEach(function (el) {
  5120. if (el.isPointInside(x, y)) {
  5121. isPointInside = true;
  5122. return false; // stop loop
  5123. }
  5124. });
  5125. return isPointInside;
  5126. };
  5127. /*\
  5128. * Raphael.registerFont
  5129. [ method ]
  5130. **
  5131. * Adds given font to the registered set of fonts for Raphaël. Should be used as an internal call from within Cufón’s font file.
  5132. * Returns original parameter, so it could be used with chaining.
  5133. # <a href="http://wiki.github.com/sorccu/cufon/about">More about Cufón and how to convert your font form TTF, OTF, etc to JavaScript file.</a>
  5134. **
  5135. > Parameters
  5136. **
  5137. - font (object) the font to register
  5138. = (object) the font you passed in
  5139. > Usage
  5140. | Cufon.registerFont(Raphael.registerFont({…}));
  5141. \*/
  5142. R.registerFont = function (font) {
  5143. if (!font.face) {
  5144. return font;
  5145. }
  5146. this.fonts = this.fonts || {};
  5147. var fontcopy = {
  5148. w: font.w,
  5149. face: {},
  5150. glyphs: {}
  5151. },
  5152. family = font.face["font-family"];
  5153. for (var prop in font.face) if (font.face[has](prop)) {
  5154. fontcopy.face[prop] = font.face[prop];
  5155. }
  5156. if (this.fonts[family]) {
  5157. this.fonts[family].push(fontcopy);
  5158. } else {
  5159. this.fonts[family] = [fontcopy];
  5160. }
  5161. if (!font.svg) {
  5162. fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
  5163. for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
  5164. var path = font.glyphs[glyph];
  5165. fontcopy.glyphs[glyph] = {
  5166. w: path.w,
  5167. k: {},
  5168. d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
  5169. return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
  5170. }) + "z"
  5171. };
  5172. if (path.k) {
  5173. for (var k in path.k) if (path[has](k)) {
  5174. fontcopy.glyphs[glyph].k[k] = path.k[k];
  5175. }
  5176. }
  5177. }
  5178. }
  5179. return font;
  5180. };
  5181. /*\
  5182. * Paper.getFont
  5183. [ method ]
  5184. **
  5185. * Finds font object in the registered fonts by given parameters. You could specify only one word from the font name, like “Myriad” for “Myriad Pro”.
  5186. **
  5187. > Parameters
  5188. **
  5189. - family (string) font family name or any word from it
  5190. - weight (string) #optional font weight
  5191. - style (string) #optional font style
  5192. - stretch (string) #optional font stretch
  5193. = (object) the font object
  5194. > Usage
  5195. | paper.print(100, 100, "Test string", paper.getFont("Times", 800), 30);
  5196. \*/
  5197. paperproto.getFont = function (family, weight, style, stretch) {
  5198. stretch = stretch || "normal";
  5199. style = style || "normal";
  5200. weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
  5201. if (!R.fonts) {
  5202. return;
  5203. }
  5204. var font = R.fonts[family];
  5205. if (!font) {
  5206. var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
  5207. for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
  5208. if (name.test(fontName)) {
  5209. font = R.fonts[fontName];
  5210. break;
  5211. }
  5212. }
  5213. }
  5214. var thefont;
  5215. if (font) {
  5216. for (var i = 0, ii = font.length; i < ii; i++) {
  5217. thefont = font[i];
  5218. if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
  5219. break;
  5220. }
  5221. }
  5222. }
  5223. return thefont;
  5224. };
  5225. /*\
  5226. * Paper.print
  5227. [ method ]
  5228. **
  5229. * Creates path that represent given text written using given font at given position with given size.
  5230. * Result of the method is path element that contains whole text as a separate path.
  5231. **
  5232. > Parameters
  5233. **
  5234. - x (number) x position of the text
  5235. - y (number) y position of the text
  5236. - string (string) text to print
  5237. - font (object) font object, see @Paper.getFont
  5238. - size (number) #optional size of the font, default is `16`
  5239. - origin (string) #optional could be `"baseline"` or `"middle"`, default is `"middle"`
  5240. - letter_spacing (number) #optional number in range `-1..1`, default is `0`
  5241. - line_spacing (number) #optional number in range `1..3`, default is `1`
  5242. = (object) resulting path element, which consist of all letters
  5243. > Usage
  5244. | var txt = r.print(10, 50, "print", r.getFont("Museo"), 30).attr({fill: "#fff"});
  5245. \*/
  5246. paperproto.print = function (x, y, string, font, size, origin, letter_spacing, line_spacing) {
  5247. origin = origin || "middle"; // baseline|middle
  5248. letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
  5249. line_spacing = mmax(mmin(line_spacing || 1, 3), 1);
  5250. var letters = Str(string)[split](E),
  5251. shift = 0,
  5252. notfirst = 0,
  5253. path = E,
  5254. scale;
  5255. R.is(font, "string") && (font = this.getFont(font));
  5256. if (font) {
  5257. scale = (size || 16) / font.face["units-per-em"];
  5258. var bb = font.face.bbox[split](separator),
  5259. top = +bb[0],
  5260. lineHeight = bb[3] - bb[1],
  5261. shifty = 0,
  5262. height = +bb[1] + (origin == "baseline" ? lineHeight + (+font.face.descent) : lineHeight / 2);
  5263. for (var i = 0, ii = letters.length; i < ii; i++) {
  5264. if (letters[i] == "\n") {
  5265. shift = 0;
  5266. curr = 0;
  5267. notfirst = 0;
  5268. shifty += lineHeight * line_spacing;
  5269. } else {
  5270. var prev = notfirst && font.glyphs[letters[i - 1]] || {},
  5271. curr = font.glyphs[letters[i]];
  5272. shift += notfirst ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
  5273. notfirst = 1;
  5274. }
  5275. if (curr && curr.d) {
  5276. path += R.transformPath(curr.d, ["t", shift * scale, shifty * scale, "s", scale, scale, top, height, "t", (x - top) / scale, (y - height) / scale]);
  5277. }
  5278. }
  5279. }
  5280. return this.path(path).attr({
  5281. fill: "#000",
  5282. stroke: "none"
  5283. });
  5284. };
  5285. /*\
  5286. * Paper.add
  5287. [ method ]
  5288. **
  5289. * Imports elements in JSON array in format `{type: type, <attributes>}`
  5290. **
  5291. > Parameters
  5292. **
  5293. - json (array)
  5294. = (object) resulting set of imported elements
  5295. > Usage
  5296. | paper.add([
  5297. | {
  5298. | type: "circle",
  5299. | cx: 10,
  5300. | cy: 10,
  5301. | r: 5
  5302. | },
  5303. | {
  5304. | type: "rect",
  5305. | x: 10,
  5306. | y: 10,
  5307. | width: 10,
  5308. | height: 10,
  5309. | fill: "#fc0"
  5310. | }
  5311. | ]);
  5312. \*/
  5313. paperproto.add = function (json) {
  5314. if (R.is(json, "array")) {
  5315. var res = this.set(),
  5316. i = 0,
  5317. ii = json.length,
  5318. j;
  5319. for (; i < ii; i++) {
  5320. j = json[i] || {};
  5321. elements[has](j.type) && res.push(this[j.type]().attr(j));
  5322. }
  5323. }
  5324. return res;
  5325. };
  5326. /*\
  5327. * Raphael.format
  5328. [ method ]
  5329. **
  5330. * Simple format function. Replaces construction of type “`{<number>}`” to the corresponding argument.
  5331. **
  5332. > Parameters
  5333. **
  5334. - token (string) string to format
  5335. - … (string) rest of arguments will be treated as parameters for replacement
  5336. = (string) formated string
  5337. > Usage
  5338. | var x = 10,
  5339. | y = 20,
  5340. | width = 40,
  5341. | height = 50;
  5342. | // this will draw a rectangular shape equivalent to "M10,20h40v50h-40z"
  5343. | paper.path(Raphael.format("M{0},{1}h{2}v{3}h{4}z", x, y, width, height, -width));
  5344. \*/
  5345. R.format = function (token, params) {
  5346. var args = R.is(params, array) ? [0][concat](params) : arguments;
  5347. token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) {
  5348. return args[++i] == null ? E : args[i];
  5349. }));
  5350. return token || E;
  5351. };
  5352. /*\
  5353. * Raphael.fullfill
  5354. [ method ]
  5355. **
  5356. * A little bit more advanced format function than @Raphael.format. Replaces construction of type “`{<name>}`” to the corresponding argument.
  5357. **
  5358. > Parameters
  5359. **
  5360. - token (string) string to format
  5361. - json (object) object which properties will be used as a replacement
  5362. = (string) formated string
  5363. > Usage
  5364. | // this will draw a rectangular shape equivalent to "M10,20h40v50h-40z"
  5365. | paper.path(Raphael.fullfill("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", {
  5366. | x: 10,
  5367. | y: 20,
  5368. | dim: {
  5369. | width: 40,
  5370. | height: 50,
  5371. | "negative width": -40
  5372. | }
  5373. | }));
  5374. \*/
  5375. R.fullfill = (function () {
  5376. var tokenRegex = /\{([^\}]+)\}/g,
  5377. objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties
  5378. replacer = function (all, key, obj) {
  5379. var res = obj;
  5380. key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) {
  5381. name = name || quotedName;
  5382. if (res) {
  5383. if (name in res) {
  5384. res = res[name];
  5385. }
  5386. typeof res == "function" && isFunc && (res = res());
  5387. }
  5388. });
  5389. res = (res == null || res == obj ? all : res) + "";
  5390. return res;
  5391. };
  5392. return function (str, obj) {
  5393. return String(str).replace(tokenRegex, function (all, key) {
  5394. return replacer(all, key, obj);
  5395. });
  5396. };
  5397. })();
  5398. /*\
  5399. * Raphael.ninja
  5400. [ method ]
  5401. **
  5402. * If you want to leave no trace of Raphaël (Well, Raphaël creates only one global variable `Raphael`, but anyway.) You can use `ninja` method.
  5403. * Beware, that in this case plugins could stop working, because they are depending on global variable existence.
  5404. **
  5405. = (object) Raphael object
  5406. > Usage
  5407. | (function (local_raphael) {
  5408. | var paper = local_raphael(10, 10, 320, 200);
  5409. | …
  5410. | })(Raphael.ninja());
  5411. \*/
  5412. R.ninja = function () {
  5413. if (oldRaphael.was) {
  5414. g.win.Raphael = oldRaphael.is;
  5415. } else {
  5416. // IE8 raises an error when deleting window property
  5417. window.Raphael = undefined;
  5418. try {
  5419. delete window.Raphael;
  5420. } catch(e) {}
  5421. }
  5422. return R;
  5423. };
  5424. /*\
  5425. * Raphael.st
  5426. [ property (object) ]
  5427. **
  5428. * You can add your own method to elements and sets. It is wise to add a set method for each element method
  5429. * you added, so you will be able to call the same method on sets too.
  5430. **
  5431. * See also @Raphael.el.
  5432. > Usage
  5433. | Raphael.el.red = function () {
  5434. | this.attr({fill: "#f00"});
  5435. | };
  5436. | Raphael.st.red = function () {
  5437. | this.forEach(function (el) {
  5438. | el.red();
  5439. | });
  5440. | };
  5441. | // then use it
  5442. | paper.set(paper.circle(100, 100, 20), paper.circle(110, 100, 20)).red();
  5443. \*/
  5444. R.st = setproto;
  5445. eve.on("raphael.DOMload", function () {
  5446. loaded = true;
  5447. });
  5448. // Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
  5449. (function (doc, loaded, f) {
  5450. if (doc.readyState == null && doc.addEventListener){
  5451. doc.addEventListener(loaded, f = function () {
  5452. doc.removeEventListener(loaded, f, false);
  5453. doc.readyState = "complete";
  5454. }, false);
  5455. doc.readyState = "loading";
  5456. }
  5457. function isLoaded() {
  5458. (/in/).test(doc.readyState) ? setTimeout(isLoaded, 9) : R.eve("raphael.DOMload");
  5459. }
  5460. isLoaded();
  5461. })(document, "DOMContentLoaded");
  5462. return R;
  5463. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  5464. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  5465. /***/ }),
  5466. /***/ "./dev/raphael.svg.js":
  5467. /*!****************************!*\
  5468. !*** ./dev/raphael.svg.js ***!
  5469. \****************************/
  5470. /*! no static exports found */
  5471. /***/ (function(module, exports, __webpack_require__) {
  5472. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! ./raphael.core */ "./dev/raphael.core.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(R) {
  5473. if (R && !R.svg) {
  5474. return;
  5475. }
  5476. var has = "hasOwnProperty",
  5477. Str = String,
  5478. toFloat = parseFloat,
  5479. toInt = parseInt,
  5480. math = Math,
  5481. mmax = math.max,
  5482. abs = math.abs,
  5483. pow = math.pow,
  5484. separator = /[, ]+/,
  5485. eve = R.eve,
  5486. E = "",
  5487. S = " ";
  5488. var xlink = "http://www.w3.org/1999/xlink",
  5489. markers = {
  5490. block: "M5,0 0,2.5 5,5z",
  5491. classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
  5492. diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
  5493. open: "M6,1 1,3.5 6,6",
  5494. oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
  5495. },
  5496. markerCounter = {};
  5497. R.toString = function () {
  5498. return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
  5499. };
  5500. var $ = function (el, attr) {
  5501. if (attr) {
  5502. if (typeof el == "string") {
  5503. el = $(el);
  5504. }
  5505. for (var key in attr) if (attr[has](key)) {
  5506. if (key.substring(0, 6) == "xlink:") {
  5507. el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
  5508. } else {
  5509. el.setAttribute(key, Str(attr[key]));
  5510. }
  5511. }
  5512. } else {
  5513. el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
  5514. el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
  5515. }
  5516. return el;
  5517. },
  5518. addGradientFill = function (element, gradient) {
  5519. var type = "linear",
  5520. id = element.id + gradient,
  5521. fx = .5, fy = .5,
  5522. o = element.node,
  5523. SVG = element.paper,
  5524. s = o.style,
  5525. el = R._g.doc.getElementById(id);
  5526. if (!el) {
  5527. gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
  5528. type = "radial";
  5529. if (_fx && _fy) {
  5530. fx = toFloat(_fx);
  5531. fy = toFloat(_fy);
  5532. var dir = ((fy > .5) * 2 - 1);
  5533. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
  5534. (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
  5535. fy != .5 &&
  5536. (fy = fy.toFixed(5) - 1e-5 * dir);
  5537. }
  5538. return E;
  5539. });
  5540. gradient = gradient.split(/\s*\-\s*/);
  5541. if (type == "linear") {
  5542. var angle = gradient.shift();
  5543. angle = -toFloat(angle);
  5544. if (isNaN(angle)) {
  5545. return null;
  5546. }
  5547. var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
  5548. max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
  5549. vector[2] *= max;
  5550. vector[3] *= max;
  5551. if (vector[2] < 0) {
  5552. vector[0] = -vector[2];
  5553. vector[2] = 0;
  5554. }
  5555. if (vector[3] < 0) {
  5556. vector[1] = -vector[3];
  5557. vector[3] = 0;
  5558. }
  5559. }
  5560. var dots = R._parseDots(gradient);
  5561. if (!dots) {
  5562. return null;
  5563. }
  5564. id = id.replace(/[\(\)\s,\xb0#]/g, "_");
  5565. if (element.gradient && id != element.gradient.id) {
  5566. SVG.defs.removeChild(element.gradient);
  5567. delete element.gradient;
  5568. }
  5569. if (!element.gradient) {
  5570. el = $(type + "Gradient", {id: id});
  5571. element.gradient = el;
  5572. $(el, type == "radial" ? {
  5573. fx: fx,
  5574. fy: fy
  5575. } : {
  5576. x1: vector[0],
  5577. y1: vector[1],
  5578. x2: vector[2],
  5579. y2: vector[3],
  5580. gradientTransform: element.matrix.invert()
  5581. });
  5582. SVG.defs.appendChild(el);
  5583. for (var i = 0, ii = dots.length; i < ii; i++) {
  5584. el.appendChild($("stop", {
  5585. offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
  5586. "stop-color": dots[i].color || "#fff",
  5587. "stop-opacity": isFinite(dots[i].opacity) ? dots[i].opacity : 1
  5588. }));
  5589. }
  5590. }
  5591. }
  5592. $(o, {
  5593. fill: fillurl(id),
  5594. opacity: 1,
  5595. "fill-opacity": 1
  5596. });
  5597. s.fill = E;
  5598. s.opacity = 1;
  5599. s.fillOpacity = 1;
  5600. return 1;
  5601. },
  5602. isIE9or10 = function () {
  5603. var mode = document.documentMode;
  5604. return mode && (mode === 9 || mode === 10);
  5605. },
  5606. fillurl = function (id) {
  5607. if (isIE9or10()) {
  5608. return "url('#" + id + "')";
  5609. }
  5610. var location = document.location;
  5611. var locationString = (
  5612. location.protocol + '//' +
  5613. location.host +
  5614. location.pathname +
  5615. location.search
  5616. );
  5617. return "url('" + locationString + "#" + id + "')";
  5618. },
  5619. updatePosition = function (o) {
  5620. var bbox = o.getBBox(1);
  5621. $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
  5622. },
  5623. addArrow = function (o, value, isEnd) {
  5624. if (o.type == "path") {
  5625. var values = Str(value).toLowerCase().split("-"),
  5626. p = o.paper,
  5627. se = isEnd ? "end" : "start",
  5628. node = o.node,
  5629. attrs = o.attrs,
  5630. stroke = attrs["stroke-width"],
  5631. i = values.length,
  5632. type = "classic",
  5633. from,
  5634. to,
  5635. dx,
  5636. refX,
  5637. attr,
  5638. w = 3,
  5639. h = 3,
  5640. t = 5;
  5641. while (i--) {
  5642. switch (values[i]) {
  5643. case "block":
  5644. case "classic":
  5645. case "oval":
  5646. case "diamond":
  5647. case "open":
  5648. case "none":
  5649. type = values[i];
  5650. break;
  5651. case "wide": h = 5; break;
  5652. case "narrow": h = 2; break;
  5653. case "long": w = 5; break;
  5654. case "short": w = 2; break;
  5655. }
  5656. }
  5657. if (type == "open") {
  5658. w += 2;
  5659. h += 2;
  5660. t += 2;
  5661. dx = 1;
  5662. refX = isEnd ? 4 : 1;
  5663. attr = {
  5664. fill: "none",
  5665. stroke: attrs.stroke
  5666. };
  5667. } else {
  5668. refX = dx = w / 2;
  5669. attr = {
  5670. fill: attrs.stroke,
  5671. stroke: "none"
  5672. };
  5673. }
  5674. if (o._.arrows) {
  5675. if (isEnd) {
  5676. o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
  5677. o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
  5678. } else {
  5679. o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
  5680. o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
  5681. }
  5682. } else {
  5683. o._.arrows = {};
  5684. }
  5685. if (type != "none") {
  5686. var pathId = "raphael-marker-" + type,
  5687. markerId = "raphael-marker-" + se + type + w + h + "-obj" + o.id;
  5688. if (!R._g.doc.getElementById(pathId)) {
  5689. p.defs.appendChild($($("path"), {
  5690. "stroke-linecap": "round",
  5691. d: markers[type],
  5692. id: pathId
  5693. }));
  5694. markerCounter[pathId] = 1;
  5695. } else {
  5696. markerCounter[pathId]++;
  5697. }
  5698. var marker = R._g.doc.getElementById(markerId),
  5699. use;
  5700. if (!marker) {
  5701. marker = $($("marker"), {
  5702. id: markerId,
  5703. markerHeight: h,
  5704. markerWidth: w,
  5705. orient: "auto",
  5706. refX: refX,
  5707. refY: h / 2
  5708. });
  5709. use = $($("use"), {
  5710. "xlink:href": "#" + pathId,
  5711. transform: (isEnd ? "rotate(180 " + w / 2 + " " + h / 2 + ") " : E) + "scale(" + w / t + "," + h / t + ")",
  5712. "stroke-width": (1 / ((w / t + h / t) / 2)).toFixed(4)
  5713. });
  5714. marker.appendChild(use);
  5715. p.defs.appendChild(marker);
  5716. markerCounter[markerId] = 1;
  5717. } else {
  5718. markerCounter[markerId]++;
  5719. use = marker.getElementsByTagName("use")[0];
  5720. }
  5721. $(use, attr);
  5722. var delta = dx * (type != "diamond" && type != "oval");
  5723. if (isEnd) {
  5724. from = o._.arrows.startdx * stroke || 0;
  5725. to = R.getTotalLength(attrs.path) - delta * stroke;
  5726. } else {
  5727. from = delta * stroke;
  5728. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  5729. }
  5730. attr = {};
  5731. attr["marker-" + se] = "url(#" + markerId + ")";
  5732. if (to || from) {
  5733. attr.d = R.getSubpath(attrs.path, from, to);
  5734. }
  5735. $(node, attr);
  5736. o._.arrows[se + "Path"] = pathId;
  5737. o._.arrows[se + "Marker"] = markerId;
  5738. o._.arrows[se + "dx"] = delta;
  5739. o._.arrows[se + "Type"] = type;
  5740. o._.arrows[se + "String"] = value;
  5741. } else {
  5742. if (isEnd) {
  5743. from = o._.arrows.startdx * stroke || 0;
  5744. to = R.getTotalLength(attrs.path) - from;
  5745. } else {
  5746. from = 0;
  5747. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  5748. }
  5749. o._.arrows[se + "Path"] && $(node, {d: R.getSubpath(attrs.path, from, to)});
  5750. delete o._.arrows[se + "Path"];
  5751. delete o._.arrows[se + "Marker"];
  5752. delete o._.arrows[se + "dx"];
  5753. delete o._.arrows[se + "Type"];
  5754. delete o._.arrows[se + "String"];
  5755. }
  5756. for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
  5757. var item = R._g.doc.getElementById(attr);
  5758. item && item.parentNode.removeChild(item);
  5759. }
  5760. }
  5761. },
  5762. dasharray = {
  5763. "-": [3, 1],
  5764. ".": [1, 1],
  5765. "-.": [3, 1, 1, 1],
  5766. "-..": [3, 1, 1, 1, 1, 1],
  5767. ". ": [1, 3],
  5768. "- ": [4, 3],
  5769. "--": [8, 3],
  5770. "- .": [4, 3, 1, 3],
  5771. "--.": [8, 3, 1, 3],
  5772. "--..": [8, 3, 1, 3, 1, 3]
  5773. },
  5774. addDashes = function (o, value, params) {
  5775. value = dasharray[Str(value).toLowerCase()];
  5776. if (value) {
  5777. var width = o.attrs["stroke-width"] || "1",
  5778. butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
  5779. dashes = [],
  5780. i = value.length;
  5781. while (i--) {
  5782. dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
  5783. }
  5784. $(o.node, {"stroke-dasharray": dashes.join(",")});
  5785. }
  5786. else {
  5787. $(o.node, {"stroke-dasharray": "none"});
  5788. }
  5789. },
  5790. setFillAndStroke = function (o, params) {
  5791. var node = o.node,
  5792. attrs = o.attrs,
  5793. vis = node.style.visibility;
  5794. node.style.visibility = "hidden";
  5795. for (var att in params) {
  5796. if (params[has](att)) {
  5797. if (!R._availableAttrs[has](att)) {
  5798. continue;
  5799. }
  5800. var value = params[att];
  5801. attrs[att] = value;
  5802. switch (att) {
  5803. case "blur":
  5804. o.blur(value);
  5805. break;
  5806. case "title":
  5807. var title = node.getElementsByTagName("title");
  5808. // Use the existing <title>.
  5809. if (title.length && (title = title[0])) {
  5810. title.firstChild.nodeValue = value;
  5811. } else {
  5812. title = $("title");
  5813. var val = R._g.doc.createTextNode(value);
  5814. title.appendChild(val);
  5815. node.appendChild(title);
  5816. }
  5817. break;
  5818. case "href":
  5819. case "target":
  5820. var pn = node.parentNode;
  5821. if (pn.tagName.toLowerCase() != "a") {
  5822. var hl = $("a");
  5823. pn.insertBefore(hl, node);
  5824. hl.appendChild(node);
  5825. pn = hl;
  5826. }
  5827. if (att == "target") {
  5828. pn.setAttributeNS(xlink, "show", value == "blank" ? "new" : value);
  5829. } else {
  5830. pn.setAttributeNS(xlink, att, value);
  5831. }
  5832. break;
  5833. case "cursor":
  5834. node.style.cursor = value;
  5835. break;
  5836. case "transform":
  5837. o.transform(value);
  5838. break;
  5839. case "arrow-start":
  5840. addArrow(o, value);
  5841. break;
  5842. case "arrow-end":
  5843. addArrow(o, value, 1);
  5844. break;
  5845. case "clip-rect":
  5846. var rect = Str(value).split(separator);
  5847. if (rect.length == 4) {
  5848. o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
  5849. var el = $("clipPath"),
  5850. rc = $("rect");
  5851. el.id = R.createUUID();
  5852. $(rc, {
  5853. x: rect[0],
  5854. y: rect[1],
  5855. width: rect[2],
  5856. height: rect[3]
  5857. });
  5858. el.appendChild(rc);
  5859. o.paper.defs.appendChild(el);
  5860. $(node, {"clip-path": "url(#" + el.id + ")"});
  5861. o.clip = rc;
  5862. }
  5863. if (!value) {
  5864. var path = node.getAttribute("clip-path");
  5865. if (path) {
  5866. var clip = R._g.doc.getElementById(path.replace(/(^url\(#|\)$)/g, E));
  5867. clip && clip.parentNode.removeChild(clip);
  5868. $(node, {"clip-path": E});
  5869. delete o.clip;
  5870. }
  5871. }
  5872. break;
  5873. case "path":
  5874. if (o.type == "path") {
  5875. $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
  5876. o._.dirty = 1;
  5877. if (o._.arrows) {
  5878. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  5879. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  5880. }
  5881. }
  5882. break;
  5883. case "width":
  5884. node.setAttribute(att, value);
  5885. o._.dirty = 1;
  5886. if (attrs.fx) {
  5887. att = "x";
  5888. value = attrs.x;
  5889. } else {
  5890. break;
  5891. }
  5892. case "x":
  5893. if (attrs.fx) {
  5894. value = -attrs.x - (attrs.width || 0);
  5895. }
  5896. case "rx":
  5897. if (att == "rx" && o.type == "rect") {
  5898. break;
  5899. }
  5900. case "cx":
  5901. node.setAttribute(att, value);
  5902. o.pattern && updatePosition(o);
  5903. o._.dirty = 1;
  5904. break;
  5905. case "height":
  5906. node.setAttribute(att, value);
  5907. o._.dirty = 1;
  5908. if (attrs.fy) {
  5909. att = "y";
  5910. value = attrs.y;
  5911. } else {
  5912. break;
  5913. }
  5914. case "y":
  5915. if (attrs.fy) {
  5916. value = -attrs.y - (attrs.height || 0);
  5917. }
  5918. case "ry":
  5919. if (att == "ry" && o.type == "rect") {
  5920. break;
  5921. }
  5922. case "cy":
  5923. node.setAttribute(att, value);
  5924. o.pattern && updatePosition(o);
  5925. o._.dirty = 1;
  5926. break;
  5927. case "r":
  5928. if (o.type == "rect") {
  5929. $(node, {rx: value, ry: value});
  5930. } else {
  5931. node.setAttribute(att, value);
  5932. }
  5933. o._.dirty = 1;
  5934. break;
  5935. case "src":
  5936. if (o.type == "image") {
  5937. node.setAttributeNS(xlink, "href", value);
  5938. }
  5939. break;
  5940. case "stroke-width":
  5941. if (o._.sx != 1 || o._.sy != 1) {
  5942. value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
  5943. }
  5944. node.setAttribute(att, value);
  5945. if (attrs["stroke-dasharray"]) {
  5946. addDashes(o, attrs["stroke-dasharray"], params);
  5947. }
  5948. if (o._.arrows) {
  5949. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  5950. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  5951. }
  5952. break;
  5953. case "stroke-dasharray":
  5954. addDashes(o, value, params);
  5955. break;
  5956. case "fill":
  5957. var isURL = Str(value).match(R._ISURL);
  5958. if (isURL) {
  5959. el = $("pattern");
  5960. var ig = $("image");
  5961. el.id = R.createUUID();
  5962. $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
  5963. $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
  5964. el.appendChild(ig);
  5965. (function (el) {
  5966. R._preload(isURL[1], function () {
  5967. var w = this.offsetWidth,
  5968. h = this.offsetHeight;
  5969. $(el, {width: w, height: h});
  5970. $(ig, {width: w, height: h});
  5971. });
  5972. })(el);
  5973. o.paper.defs.appendChild(el);
  5974. $(node, {fill: "url(#" + el.id + ")"});
  5975. o.pattern = el;
  5976. o.pattern && updatePosition(o);
  5977. break;
  5978. }
  5979. var clr = R.getRGB(value);
  5980. if (!clr.error) {
  5981. delete params.gradient;
  5982. delete attrs.gradient;
  5983. !R.is(attrs.opacity, "undefined") &&
  5984. R.is(params.opacity, "undefined") &&
  5985. $(node, {opacity: attrs.opacity});
  5986. !R.is(attrs["fill-opacity"], "undefined") &&
  5987. R.is(params["fill-opacity"], "undefined") &&
  5988. $(node, {"fill-opacity": attrs["fill-opacity"]});
  5989. } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
  5990. if ("opacity" in attrs || "fill-opacity" in attrs) {
  5991. var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  5992. if (gradient) {
  5993. var stops = gradient.getElementsByTagName("stop");
  5994. $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
  5995. }
  5996. }
  5997. attrs.gradient = value;
  5998. attrs.fill = "none";
  5999. break;
  6000. }
  6001. clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  6002. case "stroke":
  6003. clr = R.getRGB(value);
  6004. node.setAttribute(att, clr.hex);
  6005. att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  6006. if (att == "stroke" && o._.arrows) {
  6007. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  6008. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  6009. }
  6010. break;
  6011. case "gradient":
  6012. (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
  6013. break;
  6014. case "opacity":
  6015. if (attrs.gradient && !attrs[has]("stroke-opacity")) {
  6016. $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
  6017. }
  6018. // fall
  6019. case "fill-opacity":
  6020. if (attrs.gradient) {
  6021. gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  6022. if (gradient) {
  6023. stops = gradient.getElementsByTagName("stop");
  6024. $(stops[stops.length - 1], {"stop-opacity": value});
  6025. }
  6026. break;
  6027. }
  6028. default:
  6029. att == "font-size" && (value = toInt(value, 10) + "px");
  6030. var cssrule = att.replace(/(\-.)/g, function (w) {
  6031. return w.substring(1).toUpperCase();
  6032. });
  6033. node.style[cssrule] = value;
  6034. o._.dirty = 1;
  6035. node.setAttribute(att, value);
  6036. break;
  6037. }
  6038. }
  6039. }
  6040. tuneText(o, params);
  6041. node.style.visibility = vis;
  6042. },
  6043. leading = 1.2,
  6044. tuneText = function (el, params) {
  6045. if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
  6046. return;
  6047. }
  6048. var a = el.attrs,
  6049. node = el.node,
  6050. fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
  6051. if (params[has]("text")) {
  6052. a.text = params.text;
  6053. while (node.firstChild) {
  6054. node.removeChild(node.firstChild);
  6055. }
  6056. var texts = Str(params.text).split("\n"),
  6057. tspans = [],
  6058. tspan;
  6059. for (var i = 0, ii = texts.length; i < ii; i++) {
  6060. tspan = $("tspan");
  6061. i && $(tspan, {dy: fontSize * leading, x: a.x});
  6062. tspan.appendChild(R._g.doc.createTextNode(texts[i]));
  6063. node.appendChild(tspan);
  6064. tspans[i] = tspan;
  6065. }
  6066. } else {
  6067. tspans = node.getElementsByTagName("tspan");
  6068. for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
  6069. $(tspans[i], {dy: fontSize * leading, x: a.x});
  6070. } else {
  6071. $(tspans[0], {dy: 0});
  6072. }
  6073. }
  6074. $(node, {x: a.x, y: a.y});
  6075. el._.dirty = 1;
  6076. var bb = el._getBBox(),
  6077. dif = a.y - (bb.y + bb.height / 2);
  6078. dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
  6079. },
  6080. getRealNode = function (node) {
  6081. if (node.parentNode && node.parentNode.tagName.toLowerCase() === "a") {
  6082. return node.parentNode;
  6083. } else {
  6084. return node;
  6085. }
  6086. },
  6087. Element = function (node, svg) {
  6088. var X = 0,
  6089. Y = 0;
  6090. /*\
  6091. * Element.node
  6092. [ property (object) ]
  6093. **
  6094. * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
  6095. **
  6096. * Note: Don’t mess with it.
  6097. > Usage
  6098. | // draw a circle at coordinate 10,10 with radius of 10
  6099. | var c = paper.circle(10, 10, 10);
  6100. | c.node.onclick = function () {
  6101. | c.attr("fill", "red");
  6102. | };
  6103. \*/
  6104. this[0] = this.node = node;
  6105. /*\
  6106. * Element.raphael
  6107. [ property (object) ]
  6108. **
  6109. * Internal reference to @Raphael object. In case it is not available.
  6110. > Usage
  6111. | Raphael.el.red = function () {
  6112. | var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
  6113. | hsb.h = 1;
  6114. | this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
  6115. | }
  6116. \*/
  6117. node.raphael = true;
  6118. /*\
  6119. * Element.id
  6120. [ property (number) ]
  6121. **
  6122. * Unique id of the element. Especially useful when you want to listen to events of the element,
  6123. * because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
  6124. \*/
  6125. this.id = guid();
  6126. node.raphaelid = this.id;
  6127. /**
  6128. * Method that returns a 5 letter/digit id, enough for 36^5 = 60466176 elements
  6129. * @returns {string} id
  6130. */
  6131. function guid() {
  6132. return ("0000" + (Math.random()*Math.pow(36,5) << 0).toString(36)).slice(-5);
  6133. }
  6134. this.matrix = R.matrix();
  6135. this.realPath = null;
  6136. /*\
  6137. * Element.paper
  6138. [ property (object) ]
  6139. **
  6140. * Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
  6141. > Usage
  6142. | Raphael.el.cross = function () {
  6143. | this.attr({fill: "red"});
  6144. | this.paper.path("M10,10L50,50M50,10L10,50")
  6145. | .attr({stroke: "red"});
  6146. | }
  6147. \*/
  6148. this.paper = svg;
  6149. this.attrs = this.attrs || {};
  6150. this._ = {
  6151. transform: [],
  6152. sx: 1,
  6153. sy: 1,
  6154. deg: 0,
  6155. dx: 0,
  6156. dy: 0,
  6157. dirty: 1
  6158. };
  6159. !svg.bottom && (svg.bottom = this);
  6160. /*\
  6161. * Element.prev
  6162. [ property (object) ]
  6163. **
  6164. * Reference to the previous element in the hierarchy.
  6165. \*/
  6166. this.prev = svg.top;
  6167. svg.top && (svg.top.next = this);
  6168. svg.top = this;
  6169. /*\
  6170. * Element.next
  6171. [ property (object) ]
  6172. **
  6173. * Reference to the next element in the hierarchy.
  6174. \*/
  6175. this.next = null;
  6176. },
  6177. elproto = R.el;
  6178. Element.prototype = elproto;
  6179. elproto.constructor = Element;
  6180. R._engine.path = function (pathString, SVG) {
  6181. var el = $("path");
  6182. SVG.canvas && SVG.canvas.appendChild(el);
  6183. var p = new Element(el, SVG);
  6184. p.type = "path";
  6185. setFillAndStroke(p, {
  6186. fill: "none",
  6187. stroke: "#000",
  6188. path: pathString
  6189. });
  6190. return p;
  6191. };
  6192. /*\
  6193. * Element.rotate
  6194. [ method ]
  6195. **
  6196. * Deprecated! Use @Element.transform instead.
  6197. * Adds rotation by given angle around given point to the list of
  6198. * transformations of the element.
  6199. > Parameters
  6200. - deg (number) angle in degrees
  6201. - cx (number) #optional x coordinate of the centre of rotation
  6202. - cy (number) #optional y coordinate of the centre of rotation
  6203. * If cx & cy aren’t specified centre of the shape is used as a point of rotation.
  6204. = (object) @Element
  6205. \*/
  6206. elproto.rotate = function (deg, cx, cy) {
  6207. if (this.removed) {
  6208. return this;
  6209. }
  6210. deg = Str(deg).split(separator);
  6211. if (deg.length - 1) {
  6212. cx = toFloat(deg[1]);
  6213. cy = toFloat(deg[2]);
  6214. }
  6215. deg = toFloat(deg[0]);
  6216. (cy == null) && (cx = cy);
  6217. if (cx == null || cy == null) {
  6218. var bbox = this.getBBox(1);
  6219. cx = bbox.x + bbox.width / 2;
  6220. cy = bbox.y + bbox.height / 2;
  6221. }
  6222. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  6223. return this;
  6224. };
  6225. /*\
  6226. * Element.scale
  6227. [ method ]
  6228. **
  6229. * Deprecated! Use @Element.transform instead.
  6230. * Adds scale by given amount relative to given point to the list of
  6231. * transformations of the element.
  6232. > Parameters
  6233. - sx (number) horisontal scale amount
  6234. - sy (number) vertical scale amount
  6235. - cx (number) #optional x coordinate of the centre of scale
  6236. - cy (number) #optional y coordinate of the centre of scale
  6237. * If cx & cy aren’t specified centre of the shape is used instead.
  6238. = (object) @Element
  6239. \*/
  6240. elproto.scale = function (sx, sy, cx, cy) {
  6241. if (this.removed) {
  6242. return this;
  6243. }
  6244. sx = Str(sx).split(separator);
  6245. if (sx.length - 1) {
  6246. sy = toFloat(sx[1]);
  6247. cx = toFloat(sx[2]);
  6248. cy = toFloat(sx[3]);
  6249. }
  6250. sx = toFloat(sx[0]);
  6251. (sy == null) && (sy = sx);
  6252. (cy == null) && (cx = cy);
  6253. if (cx == null || cy == null) {
  6254. var bbox = this.getBBox(1);
  6255. }
  6256. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  6257. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  6258. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  6259. return this;
  6260. };
  6261. /*\
  6262. * Element.translate
  6263. [ method ]
  6264. **
  6265. * Deprecated! Use @Element.transform instead.
  6266. * Adds translation by given amount to the list of transformations of the element.
  6267. > Parameters
  6268. - dx (number) horisontal shift
  6269. - dy (number) vertical shift
  6270. = (object) @Element
  6271. \*/
  6272. elproto.translate = function (dx, dy) {
  6273. if (this.removed) {
  6274. return this;
  6275. }
  6276. dx = Str(dx).split(separator);
  6277. if (dx.length - 1) {
  6278. dy = toFloat(dx[1]);
  6279. }
  6280. dx = toFloat(dx[0]) || 0;
  6281. dy = +dy || 0;
  6282. this.transform(this._.transform.concat([["t", dx, dy]]));
  6283. return this;
  6284. };
  6285. /*\
  6286. * Element.transform
  6287. [ method ]
  6288. **
  6289. * Adds transformation to the element which is separate to other attributes,
  6290. * i.e. translation doesn’t change `x` or `y` of the rectange. The format
  6291. * of transformation string is similar to the path string syntax:
  6292. | "t100,100r30,100,100s2,2,100,100r45s1.5"
  6293. * Each letter is a command. There are four commands: `t` is for translate, `r` is for rotate, `s` is for
  6294. * scale and `m` is for matrix.
  6295. *
  6296. * There are also alternative “absolute” translation, rotation and scale: `T`, `R` and `S`. They will not take previous transformation into account. For example, `...T100,0` will always move element 100 px horisontally, while `...t100,0` could move it vertically if there is `r90` before. Just compare results of `r90t100,0` and `r90T100,0`.
  6297. *
  6298. * So, the example line above could be read like “translate by 100, 100; rotate 30° around 100, 100; scale twice around 100, 100;
  6299. * rotate 45° around centre; scale 1.5 times relative to centre”. As you can see rotate and scale commands have origin
  6300. * coordinates as optional parameters, the default is the centre point of the element.
  6301. * Matrix accepts six parameters.
  6302. > Usage
  6303. | var el = paper.rect(10, 20, 300, 200);
  6304. | // translate 100, 100, rotate 45°, translate -100, 0
  6305. | el.transform("t100,100r45t-100,0");
  6306. | // if you want you can append or prepend transformations
  6307. | el.transform("...t50,50");
  6308. | el.transform("s2...");
  6309. | // or even wrap
  6310. | el.transform("t50,50...t-50-50");
  6311. | // to reset transformation call method with empty string
  6312. | el.transform("");
  6313. | // to get current value call it without parameters
  6314. | console.log(el.transform());
  6315. > Parameters
  6316. - tstr (string) #optional transformation string
  6317. * If tstr isn’t specified
  6318. = (string) current transformation string
  6319. * else
  6320. = (object) @Element
  6321. \*/
  6322. elproto.transform = function (tstr) {
  6323. var _ = this._;
  6324. if (tstr == null) {
  6325. return _.transform;
  6326. }
  6327. R._extractTransform(this, tstr);
  6328. this.clip && $(this.clip, {transform: this.matrix.invert()});
  6329. this.pattern && updatePosition(this);
  6330. this.node && $(this.node, {transform: this.matrix});
  6331. if (_.sx != 1 || _.sy != 1) {
  6332. var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
  6333. this.attr({"stroke-width": sw});
  6334. }
  6335. return this;
  6336. };
  6337. /*\
  6338. * Element.hide
  6339. [ method ]
  6340. **
  6341. * Makes element invisible. See @Element.show.
  6342. = (object) @Element
  6343. \*/
  6344. elproto.hide = function () {
  6345. if(!this.removed) this.node.style.display = "none";
  6346. return this;
  6347. };
  6348. /*\
  6349. * Element.show
  6350. [ method ]
  6351. **
  6352. * Makes element visible. See @Element.hide.
  6353. = (object) @Element
  6354. \*/
  6355. elproto.show = function () {
  6356. if(!this.removed) this.node.style.display = "";
  6357. return this;
  6358. };
  6359. /*\
  6360. * Element.remove
  6361. [ method ]
  6362. **
  6363. * Removes element from the paper.
  6364. \*/
  6365. elproto.remove = function () {
  6366. var node = getRealNode(this.node);
  6367. if (this.removed || !node.parentNode) {
  6368. return;
  6369. }
  6370. var paper = this.paper;
  6371. paper.__set__ && paper.__set__.exclude(this);
  6372. eve.unbind("raphael.*.*." + this.id);
  6373. if (this.gradient) {
  6374. paper.defs.removeChild(this.gradient);
  6375. }
  6376. R._tear(this, paper);
  6377. node.parentNode.removeChild(node);
  6378. // Remove custom data for element
  6379. this.removeData();
  6380. for (var i in this) {
  6381. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  6382. }
  6383. this.removed = true;
  6384. };
  6385. elproto._getBBox = function () {
  6386. if (this.node.style.display == "none") {
  6387. this.show();
  6388. var hide = true;
  6389. }
  6390. var canvasHidden = false,
  6391. containerStyle;
  6392. if (this.paper.canvas.parentElement) {
  6393. containerStyle = this.paper.canvas.parentElement.style;
  6394. } //IE10+ can't find parentElement
  6395. else if (this.paper.canvas.parentNode) {
  6396. containerStyle = this.paper.canvas.parentNode.style;
  6397. }
  6398. if(containerStyle && containerStyle.display == "none") {
  6399. canvasHidden = true;
  6400. containerStyle.display = "";
  6401. }
  6402. var bbox = {};
  6403. try {
  6404. bbox = this.node.getBBox();
  6405. } catch(e) {
  6406. // Firefox 3.0.x, 25.0.1 (probably more versions affected) play badly here - possible fix
  6407. bbox = {
  6408. x: this.node.clientLeft,
  6409. y: this.node.clientTop,
  6410. width: this.node.clientWidth,
  6411. height: this.node.clientHeight
  6412. }
  6413. } finally {
  6414. bbox = bbox || {};
  6415. if(canvasHidden){
  6416. containerStyle.display = "none";
  6417. }
  6418. }
  6419. hide && this.hide();
  6420. return bbox;
  6421. };
  6422. /*\
  6423. * Element.attr
  6424. [ method ]
  6425. **
  6426. * Sets the attributes of the element.
  6427. > Parameters
  6428. - attrName (string) attribute’s name
  6429. - value (string) value
  6430. * or
  6431. - params (object) object of name/value pairs
  6432. * or
  6433. - attrName (string) attribute’s name
  6434. * or
  6435. - attrNames (array) in this case method returns array of current values for given attribute names
  6436. = (object) @Element if attrsName & value or params are passed in.
  6437. = (...) value of the attribute if only attrsName is passed in.
  6438. = (array) array of values of the attribute if attrsNames is passed in.
  6439. = (object) object of attributes if nothing is passed in.
  6440. > Possible parameters
  6441. # <p>Please refer to the <a href="http://www.w3.org/TR/SVG/" title="The W3C Recommendation for the SVG language describes these properties in detail.">SVG specification</a> for an explanation of these parameters.</p>
  6442. o arrow-end (string) arrowhead on the end of the path. The format for string is `<type>[-<width>[-<length>]]`. Possible types: `classic`, `block`, `open`, `oval`, `diamond`, `none`, width: `wide`, `narrow`, `medium`, length: `long`, `short`, `midium`.
  6443. o clip-rect (string) comma or space separated values: x, y, width and height
  6444. o cursor (string) CSS type of the cursor
  6445. o cx (number) the x-axis coordinate of the center of the circle, or ellipse
  6446. o cy (number) the y-axis coordinate of the center of the circle, or ellipse
  6447. o fill (string) colour, gradient or image
  6448. o fill-opacity (number)
  6449. o font (string)
  6450. o font-family (string)
  6451. o font-size (number) font size in pixels
  6452. o font-weight (string)
  6453. o height (number)
  6454. o href (string) URL, if specified element behaves as hyperlink
  6455. o opacity (number)
  6456. o path (string) SVG path string format
  6457. o r (number) radius of the circle, ellipse or rounded corner on the rect
  6458. o rx (number) horisontal radius of the ellipse
  6459. o ry (number) vertical radius of the ellipse
  6460. o src (string) image URL, only works for @Element.image element
  6461. o stroke (string) stroke colour
  6462. o stroke-dasharray (string) [“”, “none”, “`-`”, “`.`”, “`-.`”, “`-..`”, “`. `”, “`- `”, “`--`”, “`- .`”, “`--.`”, “`--..`”]
  6463. o stroke-linecap (string) [“`butt`”, “`square`”, “`round`”]
  6464. o stroke-linejoin (string) [“`bevel`”, “`round`”, “`miter`”]
  6465. o stroke-miterlimit (number)
  6466. o stroke-opacity (number)
  6467. o stroke-width (number) stroke width in pixels, default is '1'
  6468. o target (string) used with href
  6469. o text (string) contents of the text element. Use `\n` for multiline text
  6470. o text-anchor (string) [“`start`”, “`middle`”, “`end`”], default is “`middle`”
  6471. o title (string) will create tooltip with a given text
  6472. o transform (string) see @Element.transform
  6473. o width (number)
  6474. o x (number)
  6475. o y (number)
  6476. > Gradients
  6477. * Linear gradient format: “`‹angle›-‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`90-#fff-#000`” – 90°
  6478. * gradient from white to black or “`0-#fff-#f00:20-#000`” – 0° gradient from white via red (at 20%) to black.
  6479. *
  6480. * radial gradient: “`r[(‹fx›, ‹fy›)]‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`r#fff-#000`” –
  6481. * gradient from white to black or “`r(0.25, 0.75)#fff-#000`” – gradient from white to black with focus point
  6482. * at 0.25, 0.75. Focus point coordinates are in 0..1 range. Radial gradients can only be applied to circles and ellipses.
  6483. > Path String
  6484. # <p>Please refer to <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path’s data attribute’s format are described in the SVG specification.">SVG documentation regarding path string</a>. Raphaël fully supports it.</p>
  6485. > Colour Parsing
  6486. # <ul>
  6487. # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
  6488. # <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
  6489. # <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
  6490. # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
  6491. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
  6492. # <li>rgba(•••, •••, •••, •••) — red, green and blue channels’ values: (“<code>rgba(200,&nbsp;100,&nbsp;0, .5)</code>”)</li>
  6493. # <li>rgba(•••%, •••%, •••%, •••%) — same as above, but in %: (“<code>rgba(100%,&nbsp;175%,&nbsp;0%, 50%)</code>”)</li>
  6494. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
  6495. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  6496. # <li>hsba(•••, •••, •••, •••) — same as above, but with opacity</li>
  6497. # <li>hsl(•••, •••, •••) — almost the same as hsb, see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV" title="HSL and HSV - Wikipedia, the free encyclopedia">Wikipedia page</a></li>
  6498. # <li>hsl(•••%, •••%, •••%) — same as above, but in %</li>
  6499. # <li>hsla(•••, •••, •••, •••) — same as above, but with opacity</li>
  6500. # <li>Optionally for hsb and hsl you could specify hue as a degree: “<code>hsl(240deg,&nbsp;1,&nbsp;.5)</code>” or, if you want to go fancy, “<code>hsl(240°,&nbsp;1,&nbsp;.5)</code>”</li>
  6501. # </ul>
  6502. \*/
  6503. elproto.attr = function (name, value) {
  6504. if (this.removed) {
  6505. return this;
  6506. }
  6507. if (name == null) {
  6508. var res = {};
  6509. for (var a in this.attrs) if (this.attrs[has](a)) {
  6510. res[a] = this.attrs[a];
  6511. }
  6512. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  6513. res.transform = this._.transform;
  6514. return res;
  6515. }
  6516. if (value == null && R.is(name, "string")) {
  6517. if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
  6518. return this.attrs.gradient;
  6519. }
  6520. if (name == "transform") {
  6521. return this._.transform;
  6522. }
  6523. var names = name.split(separator),
  6524. out = {};
  6525. for (var i = 0, ii = names.length; i < ii; i++) {
  6526. name = names[i];
  6527. if (name in this.attrs) {
  6528. out[name] = this.attrs[name];
  6529. } else if (R.is(this.paper.customAttributes[name], "function")) {
  6530. out[name] = this.paper.customAttributes[name].def;
  6531. } else {
  6532. out[name] = R._availableAttrs[name];
  6533. }
  6534. }
  6535. return ii - 1 ? out : out[names[0]];
  6536. }
  6537. if (value == null && R.is(name, "array")) {
  6538. out = {};
  6539. for (i = 0, ii = name.length; i < ii; i++) {
  6540. out[name[i]] = this.attr(name[i]);
  6541. }
  6542. return out;
  6543. }
  6544. if (value != null) {
  6545. var params = {};
  6546. params[name] = value;
  6547. } else if (name != null && R.is(name, "object")) {
  6548. params = name;
  6549. }
  6550. for (var key in params) {
  6551. eve("raphael.attr." + key + "." + this.id, this, params[key]);
  6552. }
  6553. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  6554. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  6555. this.attrs[key] = params[key];
  6556. for (var subkey in par) if (par[has](subkey)) {
  6557. params[subkey] = par[subkey];
  6558. }
  6559. }
  6560. setFillAndStroke(this, params);
  6561. return this;
  6562. };
  6563. /*\
  6564. * Element.toFront
  6565. [ method ]
  6566. **
  6567. * Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
  6568. = (object) @Element
  6569. \*/
  6570. elproto.toFront = function () {
  6571. if (this.removed) {
  6572. return this;
  6573. }
  6574. var node = getRealNode(this.node);
  6575. node.parentNode.appendChild(node);
  6576. var svg = this.paper;
  6577. svg.top != this && R._tofront(this, svg);
  6578. return this;
  6579. };
  6580. /*\
  6581. * Element.toBack
  6582. [ method ]
  6583. **
  6584. * Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
  6585. = (object) @Element
  6586. \*/
  6587. elproto.toBack = function () {
  6588. if (this.removed) {
  6589. return this;
  6590. }
  6591. var node = getRealNode(this.node);
  6592. var parentNode = node.parentNode;
  6593. parentNode.insertBefore(node, parentNode.firstChild);
  6594. R._toback(this, this.paper);
  6595. var svg = this.paper;
  6596. return this;
  6597. };
  6598. /*\
  6599. * Element.insertAfter
  6600. [ method ]
  6601. **
  6602. * Inserts current object after the given one.
  6603. = (object) @Element
  6604. \*/
  6605. elproto.insertAfter = function (element) {
  6606. if (this.removed || !element) {
  6607. return this;
  6608. }
  6609. var node = getRealNode(this.node);
  6610. var afterNode = getRealNode(element.node || element[element.length - 1].node);
  6611. if (afterNode.nextSibling) {
  6612. afterNode.parentNode.insertBefore(node, afterNode.nextSibling);
  6613. } else {
  6614. afterNode.parentNode.appendChild(node);
  6615. }
  6616. R._insertafter(this, element, this.paper);
  6617. return this;
  6618. };
  6619. /*\
  6620. * Element.insertBefore
  6621. [ method ]
  6622. **
  6623. * Inserts current object before the given one.
  6624. = (object) @Element
  6625. \*/
  6626. elproto.insertBefore = function (element) {
  6627. if (this.removed || !element) {
  6628. return this;
  6629. }
  6630. var node = getRealNode(this.node);
  6631. var beforeNode = getRealNode(element.node || element[0].node);
  6632. beforeNode.parentNode.insertBefore(node, beforeNode);
  6633. R._insertbefore(this, element, this.paper);
  6634. return this;
  6635. };
  6636. elproto.blur = function (size) {
  6637. // Experimental. No Safari support. Use it on your own risk.
  6638. var t = this;
  6639. if (+size !== 0) {
  6640. var fltr = $("filter"),
  6641. blur = $("feGaussianBlur");
  6642. t.attrs.blur = size;
  6643. fltr.id = R.createUUID();
  6644. $(blur, {stdDeviation: +size || 1.5});
  6645. fltr.appendChild(blur);
  6646. t.paper.defs.appendChild(fltr);
  6647. t._blur = fltr;
  6648. $(t.node, {filter: "url(#" + fltr.id + ")"});
  6649. } else {
  6650. if (t._blur) {
  6651. t._blur.parentNode.removeChild(t._blur);
  6652. delete t._blur;
  6653. delete t.attrs.blur;
  6654. }
  6655. t.node.removeAttribute("filter");
  6656. }
  6657. return t;
  6658. };
  6659. R._engine.circle = function (svg, x, y, r) {
  6660. var el = $("circle");
  6661. svg.canvas && svg.canvas.appendChild(el);
  6662. var res = new Element(el, svg);
  6663. res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
  6664. res.type = "circle";
  6665. $(el, res.attrs);
  6666. return res;
  6667. };
  6668. R._engine.rect = function (svg, x, y, w, h, r) {
  6669. var el = $("rect");
  6670. svg.canvas && svg.canvas.appendChild(el);
  6671. var res = new Element(el, svg);
  6672. res.attrs = {x: x, y: y, width: w, height: h, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
  6673. res.type = "rect";
  6674. $(el, res.attrs);
  6675. return res;
  6676. };
  6677. R._engine.ellipse = function (svg, x, y, rx, ry) {
  6678. var el = $("ellipse");
  6679. svg.canvas && svg.canvas.appendChild(el);
  6680. var res = new Element(el, svg);
  6681. res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
  6682. res.type = "ellipse";
  6683. $(el, res.attrs);
  6684. return res;
  6685. };
  6686. R._engine.image = function (svg, src, x, y, w, h) {
  6687. var el = $("image");
  6688. $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
  6689. el.setAttributeNS(xlink, "href", src);
  6690. svg.canvas && svg.canvas.appendChild(el);
  6691. var res = new Element(el, svg);
  6692. res.attrs = {x: x, y: y, width: w, height: h, src: src};
  6693. res.type = "image";
  6694. return res;
  6695. };
  6696. R._engine.text = function (svg, x, y, text) {
  6697. var el = $("text");
  6698. svg.canvas && svg.canvas.appendChild(el);
  6699. var res = new Element(el, svg);
  6700. res.attrs = {
  6701. x: x,
  6702. y: y,
  6703. "text-anchor": "middle",
  6704. text: text,
  6705. "font-family": R._availableAttrs["font-family"],
  6706. "font-size": R._availableAttrs["font-size"],
  6707. stroke: "none",
  6708. fill: "#000"
  6709. };
  6710. res.type = "text";
  6711. setFillAndStroke(res, res.attrs);
  6712. return res;
  6713. };
  6714. R._engine.setSize = function (width, height) {
  6715. this.width = width || this.width;
  6716. this.height = height || this.height;
  6717. this.canvas.setAttribute("width", this.width);
  6718. this.canvas.setAttribute("height", this.height);
  6719. if (this._viewBox) {
  6720. this.setViewBox.apply(this, this._viewBox);
  6721. }
  6722. return this;
  6723. };
  6724. R._engine.create = function () {
  6725. var con = R._getContainer.apply(0, arguments),
  6726. container = con && con.container;
  6727. if (!container) {
  6728. throw new Error("SVG container not found.");
  6729. }
  6730. var x = con.x,
  6731. y = con.y,
  6732. width = con.width,
  6733. height = con.height,
  6734. cnvs = $("svg"),
  6735. css = "overflow:hidden;",
  6736. isFloating;
  6737. x = x || 0;
  6738. y = y || 0;
  6739. width = width || 512;
  6740. height = height || 342;
  6741. $(cnvs, {
  6742. height: height,
  6743. version: 1.1,
  6744. width: width,
  6745. xmlns: "http://www.w3.org/2000/svg",
  6746. "xmlns:xlink": "http://www.w3.org/1999/xlink"
  6747. });
  6748. if (container == 1) {
  6749. cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
  6750. R._g.doc.body.appendChild(cnvs);
  6751. isFloating = 1;
  6752. } else {
  6753. cnvs.style.cssText = css + "position:relative";
  6754. if (container.firstChild) {
  6755. container.insertBefore(cnvs, container.firstChild);
  6756. } else {
  6757. container.appendChild(cnvs);
  6758. }
  6759. }
  6760. container = new R._Paper;
  6761. container.width = width;
  6762. container.height = height;
  6763. container.canvas = cnvs;
  6764. container.clear();
  6765. container._left = container._top = 0;
  6766. isFloating && (container.renderfix = function () {});
  6767. container.renderfix();
  6768. return container;
  6769. };
  6770. R._engine.setViewBox = function (x, y, w, h, fit) {
  6771. eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  6772. var paperSize = this.getSize(),
  6773. size = mmax(w / paperSize.width, h / paperSize.height),
  6774. top = this.top,
  6775. aspectRatio = fit ? "xMidYMid meet" : "xMinYMin",
  6776. vb,
  6777. sw;
  6778. if (x == null) {
  6779. if (this._vbSize) {
  6780. size = 1;
  6781. }
  6782. delete this._vbSize;
  6783. vb = "0 0 " + this.width + S + this.height;
  6784. } else {
  6785. this._vbSize = size;
  6786. vb = x + S + y + S + w + S + h;
  6787. }
  6788. $(this.canvas, {
  6789. viewBox: vb,
  6790. preserveAspectRatio: aspectRatio
  6791. });
  6792. while (size && top) {
  6793. sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
  6794. top.attr({"stroke-width": sw});
  6795. top._.dirty = 1;
  6796. top._.dirtyT = 1;
  6797. top = top.prev;
  6798. }
  6799. this._viewBox = [x, y, w, h, !!fit];
  6800. return this;
  6801. };
  6802. /*\
  6803. * Paper.renderfix
  6804. [ method ]
  6805. **
  6806. * Fixes the issue of Firefox and IE9 regarding subpixel rendering. If paper is dependent
  6807. * on other elements after reflow it could shift half pixel which cause for lines to lost their crispness.
  6808. * This method fixes the issue.
  6809. **
  6810. Special thanks to Mariusz Nowak (http://www.medikoo.com/) for this method.
  6811. \*/
  6812. R.prototype.renderfix = function () {
  6813. var cnvs = this.canvas,
  6814. s = cnvs.style,
  6815. pos;
  6816. try {
  6817. pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix();
  6818. } catch (e) {
  6819. pos = cnvs.createSVGMatrix();
  6820. }
  6821. var left = -pos.e % 1,
  6822. top = -pos.f % 1;
  6823. if (left || top) {
  6824. if (left) {
  6825. this._left = (this._left + left) % 1;
  6826. s.left = this._left + "px";
  6827. }
  6828. if (top) {
  6829. this._top = (this._top + top) % 1;
  6830. s.top = this._top + "px";
  6831. }
  6832. }
  6833. };
  6834. /*\
  6835. * Paper.clear
  6836. [ method ]
  6837. **
  6838. * Clears the paper, i.e. removes all the elements.
  6839. \*/
  6840. R.prototype.clear = function () {
  6841. R.eve("raphael.clear", this);
  6842. var c = this.canvas;
  6843. while (c.firstChild) {
  6844. c.removeChild(c.firstChild);
  6845. }
  6846. this.bottom = this.top = null;
  6847. (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
  6848. c.appendChild(this.desc);
  6849. c.appendChild(this.defs = $("defs"));
  6850. };
  6851. /*\
  6852. * Paper.remove
  6853. [ method ]
  6854. **
  6855. * Removes the paper from the DOM.
  6856. \*/
  6857. R.prototype.remove = function () {
  6858. eve("raphael.remove", this);
  6859. this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  6860. for (var i in this) {
  6861. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  6862. }
  6863. };
  6864. var setproto = R.st;
  6865. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  6866. setproto[method] = (function (methodname) {
  6867. return function () {
  6868. var arg = arguments;
  6869. return this.forEach(function (el) {
  6870. el[methodname].apply(el, arg);
  6871. });
  6872. };
  6873. })(method);
  6874. }
  6875. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  6876. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  6877. /***/ }),
  6878. /***/ "./dev/raphael.vml.js":
  6879. /*!****************************!*\
  6880. !*** ./dev/raphael.vml.js ***!
  6881. \****************************/
  6882. /*! no static exports found */
  6883. /***/ (function(module, exports, __webpack_require__) {
  6884. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! ./raphael.core */ "./dev/raphael.core.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(R) {
  6885. if (R && !R.vml) {
  6886. return;
  6887. }
  6888. var has = "hasOwnProperty",
  6889. Str = String,
  6890. toFloat = parseFloat,
  6891. math = Math,
  6892. round = math.round,
  6893. mmax = math.max,
  6894. mmin = math.min,
  6895. abs = math.abs,
  6896. fillString = "fill",
  6897. separator = /[, ]+/,
  6898. eve = R.eve,
  6899. ms = " progid:DXImageTransform.Microsoft",
  6900. S = " ",
  6901. E = "",
  6902. map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
  6903. bites = /([clmz]),?([^clmz]*)/gi,
  6904. blurregexp = / progid:\S+Blur\([^\)]+\)/g,
  6905. val = /-?[^,\s-]+/g,
  6906. cssDot = "position:absolute;left:0;top:0;width:1px;height:1px;behavior:url(#default#VML)",
  6907. zoom = 21600,
  6908. pathTypes = {path: 1, rect: 1, image: 1},
  6909. ovalTypes = {circle: 1, ellipse: 1},
  6910. path2vml = function (path) {
  6911. var total = /[ahqstv]/ig,
  6912. command = R._pathToAbsolute;
  6913. Str(path).match(total) && (command = R._path2curve);
  6914. total = /[clmz]/g;
  6915. if (command == R._pathToAbsolute && !Str(path).match(total)) {
  6916. var res = Str(path).replace(bites, function (all, command, args) {
  6917. var vals = [],
  6918. isMove = command.toLowerCase() == "m",
  6919. res = map[command];
  6920. args.replace(val, function (value) {
  6921. if (isMove && vals.length == 2) {
  6922. res += vals + map[command == "m" ? "l" : "L"];
  6923. vals = [];
  6924. }
  6925. vals.push(round(value * zoom));
  6926. });
  6927. return res + vals;
  6928. });
  6929. return res;
  6930. }
  6931. var pa = command(path), p, r;
  6932. res = [];
  6933. for (var i = 0, ii = pa.length; i < ii; i++) {
  6934. p = pa[i];
  6935. r = pa[i][0].toLowerCase();
  6936. r == "z" && (r = "x");
  6937. for (var j = 1, jj = p.length; j < jj; j++) {
  6938. r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
  6939. }
  6940. res.push(r);
  6941. }
  6942. return res.join(S);
  6943. },
  6944. compensation = function (deg, dx, dy) {
  6945. var m = R.matrix();
  6946. m.rotate(-deg, .5, .5);
  6947. return {
  6948. dx: m.x(dx, dy),
  6949. dy: m.y(dx, dy)
  6950. };
  6951. },
  6952. setCoords = function (p, sx, sy, dx, dy, deg) {
  6953. var _ = p._,
  6954. m = p.matrix,
  6955. fillpos = _.fillpos,
  6956. o = p.node,
  6957. s = o.style,
  6958. y = 1,
  6959. flip = "",
  6960. dxdy,
  6961. kx = zoom / sx,
  6962. ky = zoom / sy;
  6963. s.visibility = "hidden";
  6964. if (!sx || !sy) {
  6965. return;
  6966. }
  6967. o.coordsize = abs(kx) + S + abs(ky);
  6968. s.rotation = deg * (sx * sy < 0 ? -1 : 1);
  6969. if (deg) {
  6970. var c = compensation(deg, dx, dy);
  6971. dx = c.dx;
  6972. dy = c.dy;
  6973. }
  6974. sx < 0 && (flip += "x");
  6975. sy < 0 && (flip += " y") && (y = -1);
  6976. s.flip = flip;
  6977. o.coordorigin = (dx * -kx) + S + (dy * -ky);
  6978. if (fillpos || _.fillsize) {
  6979. var fill = o.getElementsByTagName(fillString);
  6980. fill = fill && fill[0];
  6981. o.removeChild(fill);
  6982. if (fillpos) {
  6983. c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
  6984. fill.position = c.dx * y + S + c.dy * y;
  6985. }
  6986. if (_.fillsize) {
  6987. fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
  6988. }
  6989. o.appendChild(fill);
  6990. }
  6991. s.visibility = "visible";
  6992. };
  6993. R.toString = function () {
  6994. return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
  6995. };
  6996. var addArrow = function (o, value, isEnd) {
  6997. var values = Str(value).toLowerCase().split("-"),
  6998. se = isEnd ? "end" : "start",
  6999. i = values.length,
  7000. type = "classic",
  7001. w = "medium",
  7002. h = "medium";
  7003. while (i--) {
  7004. switch (values[i]) {
  7005. case "block":
  7006. case "classic":
  7007. case "oval":
  7008. case "diamond":
  7009. case "open":
  7010. case "none":
  7011. type = values[i];
  7012. break;
  7013. case "wide":
  7014. case "narrow": h = values[i]; break;
  7015. case "long":
  7016. case "short": w = values[i]; break;
  7017. }
  7018. }
  7019. var stroke = o.node.getElementsByTagName("stroke")[0];
  7020. stroke[se + "arrow"] = type;
  7021. stroke[se + "arrowlength"] = w;
  7022. stroke[se + "arrowwidth"] = h;
  7023. },
  7024. setFillAndStroke = function (o, params) {
  7025. // o.paper.canvas.style.display = "none";
  7026. o.attrs = o.attrs || {};
  7027. var node = o.node,
  7028. a = o.attrs,
  7029. s = node.style,
  7030. xy,
  7031. newpath = pathTypes[o.type] && (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.cx != a.cx || params.cy != a.cy || params.rx != a.rx || params.ry != a.ry || params.r != a.r),
  7032. isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
  7033. res = o;
  7034. for (var par in params) if (params[has](par)) {
  7035. a[par] = params[par];
  7036. }
  7037. if (newpath) {
  7038. a.path = R._getPath[o.type](o);
  7039. o._.dirty = 1;
  7040. }
  7041. params.href && (node.href = params.href);
  7042. params.title && (node.title = params.title);
  7043. params.target && (node.target = params.target);
  7044. params.cursor && (s.cursor = params.cursor);
  7045. "blur" in params && o.blur(params.blur);
  7046. if (params.path && o.type == "path" || newpath) {
  7047. node.path = path2vml(~Str(a.path).toLowerCase().indexOf("r") ? R._pathToAbsolute(a.path) : a.path);
  7048. o._.dirty = 1;
  7049. if (o.type == "image") {
  7050. o._.fillpos = [a.x, a.y];
  7051. o._.fillsize = [a.width, a.height];
  7052. setCoords(o, 1, 1, 0, 0, 0);
  7053. }
  7054. }
  7055. "transform" in params && o.transform(params.transform);
  7056. if (isOval) {
  7057. var cx = +a.cx,
  7058. cy = +a.cy,
  7059. rx = +a.rx || +a.r || 0,
  7060. ry = +a.ry || +a.r || 0;
  7061. node.path = R.format("ar{0},{1},{2},{3},{4},{1},{4},{1}x", round((cx - rx) * zoom), round((cy - ry) * zoom), round((cx + rx) * zoom), round((cy + ry) * zoom), round(cx * zoom));
  7062. o._.dirty = 1;
  7063. }
  7064. if ("clip-rect" in params) {
  7065. var rect = Str(params["clip-rect"]).split(separator);
  7066. if (rect.length == 4) {
  7067. rect[2] = +rect[2] + (+rect[0]);
  7068. rect[3] = +rect[3] + (+rect[1]);
  7069. var div = node.clipRect || R._g.doc.createElement("div"),
  7070. dstyle = div.style;
  7071. dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
  7072. if (!node.clipRect) {
  7073. dstyle.position = "absolute";
  7074. dstyle.top = 0;
  7075. dstyle.left = 0;
  7076. dstyle.width = o.paper.width + "px";
  7077. dstyle.height = o.paper.height + "px";
  7078. node.parentNode.insertBefore(div, node);
  7079. div.appendChild(node);
  7080. node.clipRect = div;
  7081. }
  7082. }
  7083. if (!params["clip-rect"]) {
  7084. node.clipRect && (node.clipRect.style.clip = "auto");
  7085. }
  7086. }
  7087. if (o.textpath) {
  7088. var textpathStyle = o.textpath.style;
  7089. params.font && (textpathStyle.font = params.font);
  7090. params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
  7091. params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
  7092. params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
  7093. params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
  7094. }
  7095. if ("arrow-start" in params) {
  7096. addArrow(res, params["arrow-start"]);
  7097. }
  7098. if ("arrow-end" in params) {
  7099. addArrow(res, params["arrow-end"], 1);
  7100. }
  7101. if (params.opacity != null ||
  7102. params.fill != null ||
  7103. params.src != null ||
  7104. params.stroke != null ||
  7105. params["stroke-width"] != null ||
  7106. params["stroke-opacity"] != null ||
  7107. params["fill-opacity"] != null ||
  7108. params["stroke-dasharray"] != null ||
  7109. params["stroke-miterlimit"] != null ||
  7110. params["stroke-linejoin"] != null ||
  7111. params["stroke-linecap"] != null) {
  7112. var fill = node.getElementsByTagName(fillString),
  7113. newfill = false;
  7114. fill = fill && fill[0];
  7115. !fill && (newfill = fill = createNode(fillString));
  7116. if (o.type == "image" && params.src) {
  7117. fill.src = params.src;
  7118. }
  7119. params.fill && (fill.on = true);
  7120. if (fill.on == null || params.fill == "none" || params.fill === null) {
  7121. fill.on = false;
  7122. }
  7123. if (fill.on && params.fill) {
  7124. var isURL = Str(params.fill).match(R._ISURL);
  7125. if (isURL) {
  7126. fill.parentNode == node && node.removeChild(fill);
  7127. fill.rotate = true;
  7128. fill.src = isURL[1];
  7129. fill.type = "tile";
  7130. var bbox = o.getBBox(1);
  7131. fill.position = bbox.x + S + bbox.y;
  7132. o._.fillpos = [bbox.x, bbox.y];
  7133. R._preload(isURL[1], function () {
  7134. o._.fillsize = [this.offsetWidth, this.offsetHeight];
  7135. });
  7136. } else {
  7137. fill.color = R.getRGB(params.fill).hex;
  7138. fill.src = E;
  7139. fill.type = "solid";
  7140. if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
  7141. a.fill = "none";
  7142. a.gradient = params.fill;
  7143. fill.rotate = false;
  7144. }
  7145. }
  7146. }
  7147. if ("fill-opacity" in params || "opacity" in params) {
  7148. var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
  7149. opacity = mmin(mmax(opacity, 0), 1);
  7150. fill.opacity = opacity;
  7151. if (fill.src) {
  7152. fill.color = "none";
  7153. }
  7154. }
  7155. node.appendChild(fill);
  7156. var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
  7157. newstroke = false;
  7158. !stroke && (newstroke = stroke = createNode("stroke"));
  7159. if ((params.stroke && params.stroke != "none") ||
  7160. params["stroke-width"] ||
  7161. params["stroke-opacity"] != null ||
  7162. params["stroke-dasharray"] ||
  7163. params["stroke-miterlimit"] ||
  7164. params["stroke-linejoin"] ||
  7165. params["stroke-linecap"]) {
  7166. stroke.on = true;
  7167. }
  7168. (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
  7169. var strokeColor = R.getRGB(params.stroke);
  7170. stroke.on && params.stroke && (stroke.color = strokeColor.hex);
  7171. opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
  7172. var width = (toFloat(params["stroke-width"]) || 1) * .75;
  7173. opacity = mmin(mmax(opacity, 0), 1);
  7174. params["stroke-width"] == null && (width = a["stroke-width"]);
  7175. params["stroke-width"] && (stroke.weight = width);
  7176. width && width < 1 && (opacity *= width) && (stroke.weight = 1);
  7177. stroke.opacity = opacity;
  7178. params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
  7179. stroke.miterlimit = params["stroke-miterlimit"] || 8;
  7180. params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
  7181. if ("stroke-dasharray" in params) {
  7182. var dasharray = {
  7183. "-": "shortdash",
  7184. ".": "shortdot",
  7185. "-.": "shortdashdot",
  7186. "-..": "shortdashdotdot",
  7187. ". ": "dot",
  7188. "- ": "dash",
  7189. "--": "longdash",
  7190. "- .": "dashdot",
  7191. "--.": "longdashdot",
  7192. "--..": "longdashdotdot"
  7193. };
  7194. stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
  7195. }
  7196. newstroke && node.appendChild(stroke);
  7197. }
  7198. if (res.type == "text") {
  7199. res.paper.canvas.style.display = E;
  7200. var span = res.paper.span,
  7201. m = 100,
  7202. fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
  7203. s = span.style;
  7204. a.font && (s.font = a.font);
  7205. a["font-family"] && (s.fontFamily = a["font-family"]);
  7206. a["font-weight"] && (s.fontWeight = a["font-weight"]);
  7207. a["font-style"] && (s.fontStyle = a["font-style"]);
  7208. fontSize = toFloat(a["font-size"] || fontSize && fontSize[0]) || 10;
  7209. s.fontSize = fontSize * m + "px";
  7210. res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "&#60;").replace(/&/g, "&#38;").replace(/\n/g, "<br>"));
  7211. var brect = span.getBoundingClientRect();
  7212. res.W = a.w = (brect.right - brect.left) / m;
  7213. res.H = a.h = (brect.bottom - brect.top) / m;
  7214. // res.paper.canvas.style.display = "none";
  7215. res.X = a.x;
  7216. res.Y = a.y + res.H / 2;
  7217. ("x" in params || "y" in params) && (res.path.v = R.format("m{0},{1}l{2},{1}", round(a.x * zoom), round(a.y * zoom), round(a.x * zoom) + 1));
  7218. var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
  7219. for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
  7220. res._.dirty = 1;
  7221. break;
  7222. }
  7223. // text-anchor emulation
  7224. switch (a["text-anchor"]) {
  7225. case "start":
  7226. res.textpath.style["v-text-align"] = "left";
  7227. res.bbx = res.W / 2;
  7228. break;
  7229. case "end":
  7230. res.textpath.style["v-text-align"] = "right";
  7231. res.bbx = -res.W / 2;
  7232. break;
  7233. default:
  7234. res.textpath.style["v-text-align"] = "center";
  7235. res.bbx = 0;
  7236. break;
  7237. }
  7238. res.textpath.style["v-text-kern"] = true;
  7239. }
  7240. // res.paper.canvas.style.display = E;
  7241. },
  7242. addGradientFill = function (o, gradient, fill) {
  7243. o.attrs = o.attrs || {};
  7244. var attrs = o.attrs,
  7245. pow = Math.pow,
  7246. opacity,
  7247. oindex,
  7248. type = "linear",
  7249. fxfy = ".5 .5";
  7250. o.attrs.gradient = gradient;
  7251. gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
  7252. type = "radial";
  7253. if (fx && fy) {
  7254. fx = toFloat(fx);
  7255. fy = toFloat(fy);
  7256. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
  7257. fxfy = fx + S + fy;
  7258. }
  7259. return E;
  7260. });
  7261. gradient = gradient.split(/\s*\-\s*/);
  7262. if (type == "linear") {
  7263. var angle = gradient.shift();
  7264. angle = -toFloat(angle);
  7265. if (isNaN(angle)) {
  7266. return null;
  7267. }
  7268. }
  7269. var dots = R._parseDots(gradient);
  7270. if (!dots) {
  7271. return null;
  7272. }
  7273. o = o.shape || o.node;
  7274. if (dots.length) {
  7275. o.removeChild(fill);
  7276. fill.on = true;
  7277. fill.method = "none";
  7278. fill.color = dots[0].color;
  7279. fill.color2 = dots[dots.length - 1].color;
  7280. var clrs = [];
  7281. for (var i = 0, ii = dots.length; i < ii; i++) {
  7282. dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
  7283. }
  7284. fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
  7285. if (type == "radial") {
  7286. fill.type = "gradientTitle";
  7287. fill.focus = "100%";
  7288. fill.focussize = "0 0";
  7289. fill.focusposition = fxfy;
  7290. fill.angle = 0;
  7291. } else {
  7292. // fill.rotate= true;
  7293. fill.type = "gradient";
  7294. fill.angle = (270 - angle) % 360;
  7295. }
  7296. o.appendChild(fill);
  7297. }
  7298. return 1;
  7299. },
  7300. Element = function (node, vml) {
  7301. this[0] = this.node = node;
  7302. node.raphael = true;
  7303. this.id = R._oid++;
  7304. node.raphaelid = this.id;
  7305. this.X = 0;
  7306. this.Y = 0;
  7307. this.attrs = {};
  7308. this.paper = vml;
  7309. this.matrix = R.matrix();
  7310. this._ = {
  7311. transform: [],
  7312. sx: 1,
  7313. sy: 1,
  7314. dx: 0,
  7315. dy: 0,
  7316. deg: 0,
  7317. dirty: 1,
  7318. dirtyT: 1
  7319. };
  7320. !vml.bottom && (vml.bottom = this);
  7321. this.prev = vml.top;
  7322. vml.top && (vml.top.next = this);
  7323. vml.top = this;
  7324. this.next = null;
  7325. };
  7326. var elproto = R.el;
  7327. Element.prototype = elproto;
  7328. elproto.constructor = Element;
  7329. elproto.transform = function (tstr) {
  7330. if (tstr == null) {
  7331. return this._.transform;
  7332. }
  7333. var vbs = this.paper._viewBoxShift,
  7334. vbt = vbs ? "s" + [vbs.scale, vbs.scale] + "-1-1t" + [vbs.dx, vbs.dy] : E,
  7335. oldt;
  7336. if (vbs) {
  7337. oldt = tstr = Str(tstr).replace(/\.{3}|\u2026/g, this._.transform || E);
  7338. }
  7339. R._extractTransform(this, vbt + tstr);
  7340. var matrix = this.matrix.clone(),
  7341. skew = this.skew,
  7342. o = this.node,
  7343. split,
  7344. isGrad = ~Str(this.attrs.fill).indexOf("-"),
  7345. isPatt = !Str(this.attrs.fill).indexOf("url(");
  7346. matrix.translate(1, 1);
  7347. if (isPatt || isGrad || this.type == "image") {
  7348. skew.matrix = "1 0 0 1";
  7349. skew.offset = "0 0";
  7350. split = matrix.split();
  7351. if ((isGrad && split.noRotation) || !split.isSimple) {
  7352. o.style.filter = matrix.toFilter();
  7353. var bb = this.getBBox(),
  7354. bbt = this.getBBox(1),
  7355. dx = bb.x - bbt.x,
  7356. dy = bb.y - bbt.y;
  7357. o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
  7358. setCoords(this, 1, 1, dx, dy, 0);
  7359. } else {
  7360. o.style.filter = E;
  7361. setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
  7362. }
  7363. } else {
  7364. o.style.filter = E;
  7365. skew.matrix = Str(matrix);
  7366. skew.offset = matrix.offset();
  7367. }
  7368. if (oldt !== null) { // empty string value is true as well
  7369. this._.transform = oldt;
  7370. R._extractTransform(this, oldt);
  7371. }
  7372. return this;
  7373. };
  7374. elproto.rotate = function (deg, cx, cy) {
  7375. if (this.removed) {
  7376. return this;
  7377. }
  7378. if (deg == null) {
  7379. return;
  7380. }
  7381. deg = Str(deg).split(separator);
  7382. if (deg.length - 1) {
  7383. cx = toFloat(deg[1]);
  7384. cy = toFloat(deg[2]);
  7385. }
  7386. deg = toFloat(deg[0]);
  7387. (cy == null) && (cx = cy);
  7388. if (cx == null || cy == null) {
  7389. var bbox = this.getBBox(1);
  7390. cx = bbox.x + bbox.width / 2;
  7391. cy = bbox.y + bbox.height / 2;
  7392. }
  7393. this._.dirtyT = 1;
  7394. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  7395. return this;
  7396. };
  7397. elproto.translate = function (dx, dy) {
  7398. if (this.removed) {
  7399. return this;
  7400. }
  7401. dx = Str(dx).split(separator);
  7402. if (dx.length - 1) {
  7403. dy = toFloat(dx[1]);
  7404. }
  7405. dx = toFloat(dx[0]) || 0;
  7406. dy = +dy || 0;
  7407. if (this._.bbox) {
  7408. this._.bbox.x += dx;
  7409. this._.bbox.y += dy;
  7410. }
  7411. this.transform(this._.transform.concat([["t", dx, dy]]));
  7412. return this;
  7413. };
  7414. elproto.scale = function (sx, sy, cx, cy) {
  7415. if (this.removed) {
  7416. return this;
  7417. }
  7418. sx = Str(sx).split(separator);
  7419. if (sx.length - 1) {
  7420. sy = toFloat(sx[1]);
  7421. cx = toFloat(sx[2]);
  7422. cy = toFloat(sx[3]);
  7423. isNaN(cx) && (cx = null);
  7424. isNaN(cy) && (cy = null);
  7425. }
  7426. sx = toFloat(sx[0]);
  7427. (sy == null) && (sy = sx);
  7428. (cy == null) && (cx = cy);
  7429. if (cx == null || cy == null) {
  7430. var bbox = this.getBBox(1);
  7431. }
  7432. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  7433. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  7434. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  7435. this._.dirtyT = 1;
  7436. return this;
  7437. };
  7438. elproto.hide = function () {
  7439. !this.removed && (this.node.style.display = "none");
  7440. return this;
  7441. };
  7442. elproto.show = function () {
  7443. !this.removed && (this.node.style.display = E);
  7444. return this;
  7445. };
  7446. // Needed to fix the vml setViewBox issues
  7447. elproto.auxGetBBox = R.el.getBBox;
  7448. elproto.getBBox = function(){
  7449. var b = this.auxGetBBox();
  7450. if (this.paper && this.paper._viewBoxShift)
  7451. {
  7452. var c = {};
  7453. var z = 1/this.paper._viewBoxShift.scale;
  7454. c.x = b.x - this.paper._viewBoxShift.dx;
  7455. c.x *= z;
  7456. c.y = b.y - this.paper._viewBoxShift.dy;
  7457. c.y *= z;
  7458. c.width = b.width * z;
  7459. c.height = b.height * z;
  7460. c.x2 = c.x + c.width;
  7461. c.y2 = c.y + c.height;
  7462. return c;
  7463. }
  7464. return b;
  7465. };
  7466. elproto._getBBox = function () {
  7467. if (this.removed) {
  7468. return {};
  7469. }
  7470. return {
  7471. x: this.X + (this.bbx || 0) - this.W / 2,
  7472. y: this.Y - this.H,
  7473. width: this.W,
  7474. height: this.H
  7475. };
  7476. };
  7477. elproto.remove = function () {
  7478. if (this.removed || !this.node.parentNode) {
  7479. return;
  7480. }
  7481. this.paper.__set__ && this.paper.__set__.exclude(this);
  7482. R.eve.unbind("raphael.*.*." + this.id);
  7483. R._tear(this, this.paper);
  7484. this.node.parentNode.removeChild(this.node);
  7485. this.shape && this.shape.parentNode.removeChild(this.shape);
  7486. for (var i in this) {
  7487. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  7488. }
  7489. this.removed = true;
  7490. };
  7491. elproto.attr = function (name, value) {
  7492. if (this.removed) {
  7493. return this;
  7494. }
  7495. if (name == null) {
  7496. var res = {};
  7497. for (var a in this.attrs) if (this.attrs[has](a)) {
  7498. res[a] = this.attrs[a];
  7499. }
  7500. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  7501. res.transform = this._.transform;
  7502. return res;
  7503. }
  7504. if (value == null && R.is(name, "string")) {
  7505. if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
  7506. return this.attrs.gradient;
  7507. }
  7508. var names = name.split(separator),
  7509. out = {};
  7510. for (var i = 0, ii = names.length; i < ii; i++) {
  7511. name = names[i];
  7512. if (name in this.attrs) {
  7513. out[name] = this.attrs[name];
  7514. } else if (R.is(this.paper.customAttributes[name], "function")) {
  7515. out[name] = this.paper.customAttributes[name].def;
  7516. } else {
  7517. out[name] = R._availableAttrs[name];
  7518. }
  7519. }
  7520. return ii - 1 ? out : out[names[0]];
  7521. }
  7522. if (this.attrs && value == null && R.is(name, "array")) {
  7523. out = {};
  7524. for (i = 0, ii = name.length; i < ii; i++) {
  7525. out[name[i]] = this.attr(name[i]);
  7526. }
  7527. return out;
  7528. }
  7529. var params;
  7530. if (value != null) {
  7531. params = {};
  7532. params[name] = value;
  7533. }
  7534. value == null && R.is(name, "object") && (params = name);
  7535. for (var key in params) {
  7536. eve("raphael.attr." + key + "." + this.id, this, params[key]);
  7537. }
  7538. if (params) {
  7539. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  7540. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  7541. this.attrs[key] = params[key];
  7542. for (var subkey in par) if (par[has](subkey)) {
  7543. params[subkey] = par[subkey];
  7544. }
  7545. }
  7546. // this.paper.canvas.style.display = "none";
  7547. if (params.text && this.type == "text") {
  7548. this.textpath.string = params.text;
  7549. }
  7550. setFillAndStroke(this, params);
  7551. // this.paper.canvas.style.display = E;
  7552. }
  7553. return this;
  7554. };
  7555. elproto.toFront = function () {
  7556. !this.removed && this.node.parentNode.appendChild(this.node);
  7557. this.paper && this.paper.top != this && R._tofront(this, this.paper);
  7558. return this;
  7559. };
  7560. elproto.toBack = function () {
  7561. if (this.removed) {
  7562. return this;
  7563. }
  7564. if (this.node.parentNode.firstChild != this.node) {
  7565. this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
  7566. R._toback(this, this.paper);
  7567. }
  7568. return this;
  7569. };
  7570. elproto.insertAfter = function (element) {
  7571. if (this.removed) {
  7572. return this;
  7573. }
  7574. if (element.constructor == R.st.constructor) {
  7575. element = element[element.length - 1];
  7576. }
  7577. if (element.node.nextSibling) {
  7578. element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
  7579. } else {
  7580. element.node.parentNode.appendChild(this.node);
  7581. }
  7582. R._insertafter(this, element, this.paper);
  7583. return this;
  7584. };
  7585. elproto.insertBefore = function (element) {
  7586. if (this.removed) {
  7587. return this;
  7588. }
  7589. if (element.constructor == R.st.constructor) {
  7590. element = element[0];
  7591. }
  7592. element.node.parentNode.insertBefore(this.node, element.node);
  7593. R._insertbefore(this, element, this.paper);
  7594. return this;
  7595. };
  7596. elproto.blur = function (size) {
  7597. var s = this.node.runtimeStyle,
  7598. f = s.filter;
  7599. f = f.replace(blurregexp, E);
  7600. if (+size !== 0) {
  7601. this.attrs.blur = size;
  7602. s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
  7603. s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
  7604. } else {
  7605. s.filter = f;
  7606. s.margin = 0;
  7607. delete this.attrs.blur;
  7608. }
  7609. return this;
  7610. };
  7611. R._engine.path = function (pathString, vml) {
  7612. var el = createNode("shape");
  7613. el.style.cssText = cssDot;
  7614. el.coordsize = zoom + S + zoom;
  7615. el.coordorigin = vml.coordorigin;
  7616. var p = new Element(el, vml),
  7617. attr = {fill: "none", stroke: "#000"};
  7618. pathString && (attr.path = pathString);
  7619. p.type = "path";
  7620. p.path = [];
  7621. p.Path = E;
  7622. setFillAndStroke(p, attr);
  7623. vml.canvas && vml.canvas.appendChild(el);
  7624. var skew = createNode("skew");
  7625. skew.on = true;
  7626. el.appendChild(skew);
  7627. p.skew = skew;
  7628. p.transform(E);
  7629. return p;
  7630. };
  7631. R._engine.rect = function (vml, x, y, w, h, r) {
  7632. var path = R._rectPath(x, y, w, h, r),
  7633. res = vml.path(path),
  7634. a = res.attrs;
  7635. res.X = a.x = x;
  7636. res.Y = a.y = y;
  7637. res.W = a.width = w;
  7638. res.H = a.height = h;
  7639. a.r = r;
  7640. a.path = path;
  7641. res.type = "rect";
  7642. return res;
  7643. };
  7644. R._engine.ellipse = function (vml, x, y, rx, ry) {
  7645. var res = vml.path(),
  7646. a = res.attrs;
  7647. res.X = x - rx;
  7648. res.Y = y - ry;
  7649. res.W = rx * 2;
  7650. res.H = ry * 2;
  7651. res.type = "ellipse";
  7652. setFillAndStroke(res, {
  7653. cx: x,
  7654. cy: y,
  7655. rx: rx,
  7656. ry: ry
  7657. });
  7658. return res;
  7659. };
  7660. R._engine.circle = function (vml, x, y, r) {
  7661. var res = vml.path(),
  7662. a = res.attrs;
  7663. res.X = x - r;
  7664. res.Y = y - r;
  7665. res.W = res.H = r * 2;
  7666. res.type = "circle";
  7667. setFillAndStroke(res, {
  7668. cx: x,
  7669. cy: y,
  7670. r: r
  7671. });
  7672. return res;
  7673. };
  7674. R._engine.image = function (vml, src, x, y, w, h) {
  7675. var path = R._rectPath(x, y, w, h),
  7676. res = vml.path(path).attr({stroke: "none"}),
  7677. a = res.attrs,
  7678. node = res.node,
  7679. fill = node.getElementsByTagName(fillString)[0];
  7680. a.src = src;
  7681. res.X = a.x = x;
  7682. res.Y = a.y = y;
  7683. res.W = a.width = w;
  7684. res.H = a.height = h;
  7685. a.path = path;
  7686. res.type = "image";
  7687. fill.parentNode == node && node.removeChild(fill);
  7688. fill.rotate = true;
  7689. fill.src = src;
  7690. fill.type = "tile";
  7691. res._.fillpos = [x, y];
  7692. res._.fillsize = [w, h];
  7693. node.appendChild(fill);
  7694. setCoords(res, 1, 1, 0, 0, 0);
  7695. return res;
  7696. };
  7697. R._engine.text = function (vml, x, y, text) {
  7698. var el = createNode("shape"),
  7699. path = createNode("path"),
  7700. o = createNode("textpath");
  7701. x = x || 0;
  7702. y = y || 0;
  7703. text = text || "";
  7704. path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
  7705. path.textpathok = true;
  7706. o.string = Str(text);
  7707. o.on = true;
  7708. el.style.cssText = cssDot;
  7709. el.coordsize = zoom + S + zoom;
  7710. el.coordorigin = "0 0";
  7711. var p = new Element(el, vml),
  7712. attr = {
  7713. fill: "#000",
  7714. stroke: "none",
  7715. font: R._availableAttrs.font,
  7716. text: text
  7717. };
  7718. p.shape = el;
  7719. p.path = path;
  7720. p.textpath = o;
  7721. p.type = "text";
  7722. p.attrs.text = Str(text);
  7723. p.attrs.x = x;
  7724. p.attrs.y = y;
  7725. p.attrs.w = 1;
  7726. p.attrs.h = 1;
  7727. setFillAndStroke(p, attr);
  7728. el.appendChild(o);
  7729. el.appendChild(path);
  7730. vml.canvas.appendChild(el);
  7731. var skew = createNode("skew");
  7732. skew.on = true;
  7733. el.appendChild(skew);
  7734. p.skew = skew;
  7735. p.transform(E);
  7736. return p;
  7737. };
  7738. R._engine.setSize = function (width, height) {
  7739. var cs = this.canvas.style;
  7740. this.width = width;
  7741. this.height = height;
  7742. width == +width && (width += "px");
  7743. height == +height && (height += "px");
  7744. cs.width = width;
  7745. cs.height = height;
  7746. cs.clip = "rect(0 " + width + " " + height + " 0)";
  7747. if (this._viewBox) {
  7748. R._engine.setViewBox.apply(this, this._viewBox);
  7749. }
  7750. return this;
  7751. };
  7752. R._engine.setViewBox = function (x, y, w, h, fit) {
  7753. R.eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  7754. var paperSize = this.getSize(),
  7755. width = paperSize.width,
  7756. height = paperSize.height,
  7757. H, W;
  7758. if (fit) {
  7759. H = height / h;
  7760. W = width / w;
  7761. if (w * H < width) {
  7762. x -= (width - w * H) / 2 / H;
  7763. }
  7764. if (h * W < height) {
  7765. y -= (height - h * W) / 2 / W;
  7766. }
  7767. }
  7768. this._viewBox = [x, y, w, h, !!fit];
  7769. this._viewBoxShift = {
  7770. dx: -x,
  7771. dy: -y,
  7772. scale: paperSize
  7773. };
  7774. this.forEach(function (el) {
  7775. el.transform("...");
  7776. });
  7777. return this;
  7778. };
  7779. var createNode;
  7780. R._engine.initWin = function (win) {
  7781. var doc = win.document;
  7782. if (doc.styleSheets.length < 31) {
  7783. doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
  7784. } else {
  7785. // no more room, add to the existing one
  7786. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  7787. doc.styleSheets[0].addRule(".rvml", "behavior:url(#default#VML)");
  7788. }
  7789. try {
  7790. !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
  7791. createNode = function (tagName) {
  7792. return doc.createElement('<rvml:' + tagName + ' class="rvml">');
  7793. };
  7794. } catch (e) {
  7795. createNode = function (tagName) {
  7796. return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
  7797. };
  7798. }
  7799. };
  7800. R._engine.initWin(R._g.win);
  7801. R._engine.create = function () {
  7802. var con = R._getContainer.apply(0, arguments),
  7803. container = con.container,
  7804. height = con.height,
  7805. s,
  7806. width = con.width,
  7807. x = con.x,
  7808. y = con.y;
  7809. if (!container) {
  7810. throw new Error("VML container not found.");
  7811. }
  7812. var res = new R._Paper,
  7813. c = res.canvas = R._g.doc.createElement("div"),
  7814. cs = c.style;
  7815. x = x || 0;
  7816. y = y || 0;
  7817. width = width || 512;
  7818. height = height || 342;
  7819. res.width = width;
  7820. res.height = height;
  7821. width == +width && (width += "px");
  7822. height == +height && (height += "px");
  7823. res.coordsize = zoom * 1e3 + S + zoom * 1e3;
  7824. res.coordorigin = "0 0";
  7825. res.span = R._g.doc.createElement("span");
  7826. res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
  7827. c.appendChild(res.span);
  7828. cs.cssText = R.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden", width, height);
  7829. if (container == 1) {
  7830. R._g.doc.body.appendChild(c);
  7831. cs.left = x + "px";
  7832. cs.top = y + "px";
  7833. cs.position = "absolute";
  7834. } else {
  7835. if (container.firstChild) {
  7836. container.insertBefore(c, container.firstChild);
  7837. } else {
  7838. container.appendChild(c);
  7839. }
  7840. }
  7841. res.renderfix = function () {};
  7842. return res;
  7843. };
  7844. R.prototype.clear = function () {
  7845. R.eve("raphael.clear", this);
  7846. this.canvas.innerHTML = E;
  7847. this.span = R._g.doc.createElement("span");
  7848. this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
  7849. this.canvas.appendChild(this.span);
  7850. this.bottom = this.top = null;
  7851. };
  7852. R.prototype.remove = function () {
  7853. R.eve("raphael.remove", this);
  7854. this.canvas.parentNode.removeChild(this.canvas);
  7855. for (var i in this) {
  7856. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  7857. }
  7858. return true;
  7859. };
  7860. var setproto = R.st;
  7861. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  7862. setproto[method] = (function (methodname) {
  7863. return function () {
  7864. var arg = arguments;
  7865. return this.forEach(function (el) {
  7866. el[methodname].apply(el, arg);
  7867. });
  7868. };
  7869. })(method);
  7870. }
  7871. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  7872. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  7873. /***/ }),
  7874. /***/ "./node_modules/eve-raphael/eve.js":
  7875. /*!*****************************************!*\
  7876. !*** ./node_modules/eve-raphael/eve.js ***!
  7877. \*****************************************/
  7878. /*! no static exports found */
  7879. /***/ (function(module, exports, __webpack_require__) {
  7880. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  7881. //
  7882. // Licensed under the Apache License, Version 2.0 (the "License");
  7883. // you may not use this file except in compliance with the License.
  7884. // You may obtain a copy of the License at
  7885. //
  7886. // http://www.apache.org/licenses/LICENSE-2.0
  7887. //
  7888. // Unless required by applicable law or agreed to in writing, software
  7889. // distributed under the License is distributed on an "AS IS" BASIS,
  7890. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7891. // See the License for the specific language governing permissions and
  7892. // limitations under the License.
  7893. // ┌────────────────────────────────────────────────────────────┐ \\
  7894. // │ Eve 0.5.0 - JavaScript Events Library │ \\
  7895. // ├────────────────────────────────────────────────────────────┤ \\
  7896. // │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
  7897. // └────────────────────────────────────────────────────────────┘ \\
  7898. (function (glob) {
  7899. var version = "0.5.0",
  7900. has = "hasOwnProperty",
  7901. separator = /[\.\/]/,
  7902. comaseparator = /\s*,\s*/,
  7903. wildcard = "*",
  7904. fun = function () {},
  7905. numsort = function (a, b) {
  7906. return a - b;
  7907. },
  7908. current_event,
  7909. stop,
  7910. events = {n: {}},
  7911. firstDefined = function () {
  7912. for (var i = 0, ii = this.length; i < ii; i++) {
  7913. if (typeof this[i] != "undefined") {
  7914. return this[i];
  7915. }
  7916. }
  7917. },
  7918. lastDefined = function () {
  7919. var i = this.length;
  7920. while (--i) {
  7921. if (typeof this[i] != "undefined") {
  7922. return this[i];
  7923. }
  7924. }
  7925. },
  7926. objtos = Object.prototype.toString,
  7927. Str = String,
  7928. isArray = Array.isArray || function (ar) {
  7929. return ar instanceof Array || objtos.call(ar) == "[object Array]";
  7930. };
  7931. /*\
  7932. * eve
  7933. [ method ]
  7934. * Fires event with given `name`, given scope and other parameters.
  7935. > Arguments
  7936. - name (string) name of the *event*, dot (`.`) or slash (`/`) separated
  7937. - scope (object) context for the event handlers
  7938. - varargs (...) the rest of arguments will be sent to event handlers
  7939. = (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value.
  7940. \*/
  7941. var eve = function (name, scope) {
  7942. var e = events,
  7943. oldstop = stop,
  7944. args = Array.prototype.slice.call(arguments, 2),
  7945. listeners = eve.listeners(name),
  7946. z = 0,
  7947. f = false,
  7948. l,
  7949. indexed = [],
  7950. queue = {},
  7951. out = [],
  7952. ce = current_event,
  7953. errors = [];
  7954. out.firstDefined = firstDefined;
  7955. out.lastDefined = lastDefined;
  7956. current_event = name;
  7957. stop = 0;
  7958. for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
  7959. indexed.push(listeners[i].zIndex);
  7960. if (listeners[i].zIndex < 0) {
  7961. queue[listeners[i].zIndex] = listeners[i];
  7962. }
  7963. }
  7964. indexed.sort(numsort);
  7965. while (indexed[z] < 0) {
  7966. l = queue[indexed[z++]];
  7967. out.push(l.apply(scope, args));
  7968. if (stop) {
  7969. stop = oldstop;
  7970. return out;
  7971. }
  7972. }
  7973. for (i = 0; i < ii; i++) {
  7974. l = listeners[i];
  7975. if ("zIndex" in l) {
  7976. if (l.zIndex == indexed[z]) {
  7977. out.push(l.apply(scope, args));
  7978. if (stop) {
  7979. break;
  7980. }
  7981. do {
  7982. z++;
  7983. l = queue[indexed[z]];
  7984. l && out.push(l.apply(scope, args));
  7985. if (stop) {
  7986. break;
  7987. }
  7988. } while (l)
  7989. } else {
  7990. queue[l.zIndex] = l;
  7991. }
  7992. } else {
  7993. out.push(l.apply(scope, args));
  7994. if (stop) {
  7995. break;
  7996. }
  7997. }
  7998. }
  7999. stop = oldstop;
  8000. current_event = ce;
  8001. return out;
  8002. };
  8003. // Undocumented. Debug only.
  8004. eve._events = events;
  8005. /*\
  8006. * eve.listeners
  8007. [ method ]
  8008. * Internal method which gives you array of all event handlers that will be triggered by the given `name`.
  8009. > Arguments
  8010. - name (string) name of the event, dot (`.`) or slash (`/`) separated
  8011. = (array) array of event handlers
  8012. \*/
  8013. eve.listeners = function (name) {
  8014. var names = isArray(name) ? name : name.split(separator),
  8015. e = events,
  8016. item,
  8017. items,
  8018. k,
  8019. i,
  8020. ii,
  8021. j,
  8022. jj,
  8023. nes,
  8024. es = [e],
  8025. out = [];
  8026. for (i = 0, ii = names.length; i < ii; i++) {
  8027. nes = [];
  8028. for (j = 0, jj = es.length; j < jj; j++) {
  8029. e = es[j].n;
  8030. items = [e[names[i]], e[wildcard]];
  8031. k = 2;
  8032. while (k--) {
  8033. item = items[k];
  8034. if (item) {
  8035. nes.push(item);
  8036. out = out.concat(item.f || []);
  8037. }
  8038. }
  8039. }
  8040. es = nes;
  8041. }
  8042. return out;
  8043. };
  8044. /*\
  8045. * eve.separator
  8046. [ method ]
  8047. * If for some reasons you don’t like default separators (`.` or `/`) you can specify yours
  8048. * here. Be aware that if you pass a string longer than one character it will be treated as
  8049. * a list of characters.
  8050. - separator (string) new separator. Empty string resets to default: `.` or `/`.
  8051. \*/
  8052. eve.separator = function (sep) {
  8053. if (sep) {
  8054. sep = Str(sep).replace(/(?=[\.\^\]\[\-])/g, "\\");
  8055. sep = "[" + sep + "]";
  8056. separator = new RegExp(sep);
  8057. } else {
  8058. separator = /[\.\/]/;
  8059. }
  8060. };
  8061. /*\
  8062. * eve.on
  8063. [ method ]
  8064. **
  8065. * Binds given event handler with a given name. You can use wildcards “`*`” for the names:
  8066. | eve.on("*.under.*", f);
  8067. | eve("mouse.under.floor"); // triggers f
  8068. * Use @eve to trigger the listener.
  8069. **
  8070. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  8071. - f (function) event handler function
  8072. **
  8073. - name (array) if you don’t want to use separators, you can use array of strings
  8074. - f (function) event handler function
  8075. **
  8076. = (function) returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment.
  8077. > Example:
  8078. | eve.on("mouse", eatIt)(2);
  8079. | eve.on("mouse", scream);
  8080. | eve.on("mouse", catchIt)(1);
  8081. * This will ensure that `catchIt` function will be called before `eatIt`.
  8082. *
  8083. * If you want to put your handler before non-indexed handlers, specify a negative value.
  8084. * Note: I assume most of the time you don’t need to worry about z-index, but it’s nice to have this feature “just in case”.
  8085. \*/
  8086. eve.on = function (name, f) {
  8087. if (typeof f != "function") {
  8088. return function () {};
  8089. }
  8090. var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator);
  8091. for (var i = 0, ii = names.length; i < ii; i++) {
  8092. (function (name) {
  8093. var names = isArray(name) ? name : Str(name).split(separator),
  8094. e = events,
  8095. exist;
  8096. for (var i = 0, ii = names.length; i < ii; i++) {
  8097. e = e.n;
  8098. e = e.hasOwnProperty(names[i]) && e[names[i]] || (e[names[i]] = {n: {}});
  8099. }
  8100. e.f = e.f || [];
  8101. for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
  8102. exist = true;
  8103. break;
  8104. }
  8105. !exist && e.f.push(f);
  8106. }(names[i]));
  8107. }
  8108. return function (zIndex) {
  8109. if (+zIndex == +zIndex) {
  8110. f.zIndex = +zIndex;
  8111. }
  8112. };
  8113. };
  8114. /*\
  8115. * eve.f
  8116. [ method ]
  8117. **
  8118. * Returns function that will fire given event with optional arguments.
  8119. * Arguments that will be passed to the result function will be also
  8120. * concated to the list of final arguments.
  8121. | el.onclick = eve.f("click", 1, 2);
  8122. | eve.on("click", function (a, b, c) {
  8123. | console.log(a, b, c); // 1, 2, [event object]
  8124. | });
  8125. > Arguments
  8126. - event (string) event name
  8127. - varargs (…) and any other arguments
  8128. = (function) possible event handler function
  8129. \*/
  8130. eve.f = function (event) {
  8131. var attrs = [].slice.call(arguments, 1);
  8132. return function () {
  8133. eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0)));
  8134. };
  8135. };
  8136. /*\
  8137. * eve.stop
  8138. [ method ]
  8139. **
  8140. * Is used inside an event handler to stop the event, preventing any subsequent listeners from firing.
  8141. \*/
  8142. eve.stop = function () {
  8143. stop = 1;
  8144. };
  8145. /*\
  8146. * eve.nt
  8147. [ method ]
  8148. **
  8149. * Could be used inside event handler to figure out actual name of the event.
  8150. **
  8151. > Arguments
  8152. **
  8153. - subname (string) #optional subname of the event
  8154. **
  8155. = (string) name of the event, if `subname` is not specified
  8156. * or
  8157. = (boolean) `true`, if current event’s name contains `subname`
  8158. \*/
  8159. eve.nt = function (subname) {
  8160. var cur = isArray(current_event) ? current_event.join(".") : current_event;
  8161. if (subname) {
  8162. return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(cur);
  8163. }
  8164. return cur;
  8165. };
  8166. /*\
  8167. * eve.nts
  8168. [ method ]
  8169. **
  8170. * Could be used inside event handler to figure out actual name of the event.
  8171. **
  8172. **
  8173. = (array) names of the event
  8174. \*/
  8175. eve.nts = function () {
  8176. return isArray(current_event) ? current_event : current_event.split(separator);
  8177. };
  8178. /*\
  8179. * eve.off
  8180. [ method ]
  8181. **
  8182. * Removes given function from the list of event listeners assigned to given name.
  8183. * If no arguments specified all the events will be cleared.
  8184. **
  8185. > Arguments
  8186. **
  8187. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  8188. - f (function) event handler function
  8189. \*/
  8190. /*\
  8191. * eve.unbind
  8192. [ method ]
  8193. **
  8194. * See @eve.off
  8195. \*/
  8196. eve.off = eve.unbind = function (name, f) {
  8197. if (!name) {
  8198. eve._events = events = {n: {}};
  8199. return;
  8200. }
  8201. var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator);
  8202. if (names.length > 1) {
  8203. for (var i = 0, ii = names.length; i < ii; i++) {
  8204. eve.off(names[i], f);
  8205. }
  8206. return;
  8207. }
  8208. names = isArray(name) ? name : Str(name).split(separator);
  8209. var e,
  8210. key,
  8211. splice,
  8212. i, ii, j, jj,
  8213. cur = [events];
  8214. for (i = 0, ii = names.length; i < ii; i++) {
  8215. for (j = 0; j < cur.length; j += splice.length - 2) {
  8216. splice = [j, 1];
  8217. e = cur[j].n;
  8218. if (names[i] != wildcard) {
  8219. if (e[names[i]]) {
  8220. splice.push(e[names[i]]);
  8221. }
  8222. } else {
  8223. for (key in e) if (e[has](key)) {
  8224. splice.push(e[key]);
  8225. }
  8226. }
  8227. cur.splice.apply(cur, splice);
  8228. }
  8229. }
  8230. for (i = 0, ii = cur.length; i < ii; i++) {
  8231. e = cur[i];
  8232. while (e.n) {
  8233. if (f) {
  8234. if (e.f) {
  8235. for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) {
  8236. e.f.splice(j, 1);
  8237. break;
  8238. }
  8239. !e.f.length && delete e.f;
  8240. }
  8241. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  8242. var funcs = e.n[key].f;
  8243. for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) {
  8244. funcs.splice(j, 1);
  8245. break;
  8246. }
  8247. !funcs.length && delete e.n[key].f;
  8248. }
  8249. } else {
  8250. delete e.f;
  8251. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  8252. delete e.n[key].f;
  8253. }
  8254. }
  8255. e = e.n;
  8256. }
  8257. }
  8258. };
  8259. /*\
  8260. * eve.once
  8261. [ method ]
  8262. **
  8263. * Binds given event handler with a given name to only run once then unbind itself.
  8264. | eve.once("login", f);
  8265. | eve("login"); // triggers f
  8266. | eve("login"); // no listeners
  8267. * Use @eve to trigger the listener.
  8268. **
  8269. > Arguments
  8270. **
  8271. - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
  8272. - f (function) event handler function
  8273. **
  8274. = (function) same return function as @eve.on
  8275. \*/
  8276. eve.once = function (name, f) {
  8277. var f2 = function () {
  8278. eve.off(name, f2);
  8279. return f.apply(this, arguments);
  8280. };
  8281. return eve.on(name, f2);
  8282. };
  8283. /*\
  8284. * eve.version
  8285. [ property (string) ]
  8286. **
  8287. * Current version of the library.
  8288. \*/
  8289. eve.version = version;
  8290. eve.toString = function () {
  8291. return "You are running Eve " + version;
  8292. };
  8293. ( true && module.exports) ? (module.exports = eve) : ( true ? (!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function() { return eve; }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  8294. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))) : (undefined));
  8295. })(this);
  8296. /***/ })
  8297. /******/ });
  8298. });