raphael.no-deps.js 292 KB

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