Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

raphael.js 303KB

2 lat temu
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438
  1. // ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐ \\
  2. // │ Raphaël 2.3.0 - JavaScript Vector Library │ \\
  3. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  4. // │ Copyright © 2008-2016 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5. // │ Copyright © 2008-2016 Sencha Labs (http://sencha.com) │ \\
  6. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  7. // │ Licensed under the MIT (https://github.com/DmitryBaranovskiy/raphael/blob/master/license.txt) license.│ \\
  8. // └───────────────────────────────────────────────────────────────────────────────────────────────────────┘ \\
  9. (function webpackUniversalModuleDefinition(root, factory) {
  10. if(typeof exports === 'object' && typeof module === 'object')
  11. module.exports = factory();
  12. else if(typeof define === 'function' && define.amd)
  13. define([], factory);
  14. else if(typeof exports === 'object')
  15. exports["Raphael"] = factory();
  16. else
  17. root["Raphael"] = factory();
  18. })(window, function() {
  19. return /******/ (function(modules) { // webpackBootstrap
  20. /******/ // The module cache
  21. /******/ var installedModules = {};
  22. /******/
  23. /******/ // The require function
  24. /******/ function __webpack_require__(moduleId) {
  25. /******/
  26. /******/ // Check if module is in cache
  27. /******/ if(installedModules[moduleId]) {
  28. /******/ return installedModules[moduleId].exports;
  29. /******/ }
  30. /******/ // Create a new module (and put it into the cache)
  31. /******/ var module = installedModules[moduleId] = {
  32. /******/ i: moduleId,
  33. /******/ l: false,
  34. /******/ exports: {}
  35. /******/ };
  36. /******/
  37. /******/ // Execute the module function
  38. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39. /******/
  40. /******/ // Flag the module as loaded
  41. /******/ module.l = true;
  42. /******/
  43. /******/ // Return the exports of the module
  44. /******/ return module.exports;
  45. /******/ }
  46. /******/
  47. /******/
  48. /******/ // expose the modules object (__webpack_modules__)
  49. /******/ __webpack_require__.m = modules;
  50. /******/
  51. /******/ // expose the module cache
  52. /******/ __webpack_require__.c = installedModules;
  53. /******/
  54. /******/ // define getter function for harmony exports
  55. /******/ __webpack_require__.d = function(exports, name, getter) {
  56. /******/ if(!__webpack_require__.o(exports, name)) {
  57. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  58. /******/ }
  59. /******/ };
  60. /******/
  61. /******/ // define __esModule on exports
  62. /******/ __webpack_require__.r = function(exports) {
  63. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  64. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  65. /******/ }
  66. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  67. /******/ };
  68. /******/
  69. /******/ // create a fake namespace object
  70. /******/ // mode & 1: value is a module id, require it
  71. /******/ // mode & 2: merge all properties of value into the ns
  72. /******/ // mode & 4: return value when already ns object
  73. /******/ // mode & 8|1: behave like require
  74. /******/ __webpack_require__.t = function(value, mode) {
  75. /******/ if(mode & 1) value = __webpack_require__(value);
  76. /******/ if(mode & 8) return value;
  77. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  78. /******/ var ns = Object.create(null);
  79. /******/ __webpack_require__.r(ns);
  80. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  81. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  82. /******/ return ns;
  83. /******/ };
  84. /******/
  85. /******/ // getDefaultExport function for compatibility with non-harmony modules
  86. /******/ __webpack_require__.n = function(module) {
  87. /******/ var getter = module && module.__esModule ?
  88. /******/ function getDefault() { return module['default']; } :
  89. /******/ function getModuleExports() { return module; };
  90. /******/ __webpack_require__.d(getter, 'a', getter);
  91. /******/ return getter;
  92. /******/ };
  93. /******/
  94. /******/ // Object.prototype.hasOwnProperty.call
  95. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  96. /******/
  97. /******/ // __webpack_public_path__
  98. /******/ __webpack_require__.p = "";
  99. /******/
  100. /******/
  101. /******/ // Load entry module and return exports
  102. /******/ return __webpack_require__(__webpack_require__.s = "./dev/raphael.amd.js");
  103. /******/ })
  104. /************************************************************************/
  105. /******/ ({
  106. /***/ "./dev/raphael.amd.js":
  107. /*!****************************!*\
  108. !*** ./dev/raphael.amd.js ***!
  109. \****************************/
  110. /*! no static exports found */
  111. /***/ (function(module, exports, __webpack_require__) {
  112. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! ./raphael.core */ "./dev/raphael.core.js"), __webpack_require__(/*! ./raphael.svg */ "./dev/raphael.svg.js"), __webpack_require__(/*! ./raphael.vml */ "./dev/raphael.vml.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(R) {
  113. return R;
  114. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  115. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  116. /***/ }),
  117. /***/ "./dev/raphael.core.js":
  118. /*!*****************************!*\
  119. !*** ./dev/raphael.core.js ***!
  120. \*****************************/
  121. /*! no static exports found */
  122. /***/ (function(module, exports, __webpack_require__) {
  123. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! eve */ "./node_modules/eve-raphael/eve.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function(eve) {
  124. /*\
  125. * Raphael
  126. [ method ]
  127. **
  128. * Creates a canvas object on which to draw.
  129. * You must do this first, as all future calls to drawing methods
  130. * from this instance will be bound to this canvas.
  131. > Parameters
  132. **
  133. - container (HTMLElement|string) DOM element or its ID which is going to be a parent for drawing surface
  134. - width (number)
  135. - height (number)
  136. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  137. * or
  138. - x (number)
  139. - y (number)
  140. - width (number)
  141. - height (number)
  142. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  143. * or
  144. - all (array) (first 3 or 4 elements in the array are equal to [containerID, width, height] or [x, y, width, height]. The rest are element descriptions in format {type: type, <attributes>}). See @Paper.add.
  145. - callback (function) #optional callback function which is going to be executed in the context of newly created paper
  146. * or
  147. - onReadyCallback (function) function that is going to be called on DOM ready event. You can also subscribe to this event via Eve’s “DOMLoad” event. In this case method returns `undefined`.
  148. = (object) @Paper
  149. > Usage
  150. | // Each of the following examples create a canvas
  151. | // that is 320px wide by 200px high.
  152. | // Canvas is created at the viewport’s 10,50 coordinate.
  153. | var paper = Raphael(10, 50, 320, 200);
  154. | // Canvas is created at the top left corner of the #notepad element
  155. | // (or its top right corner in dir="rtl" elements)
  156. | var paper = Raphael(document.getElementById("notepad"), 320, 200);
  157. | // Same as above
  158. | var paper = Raphael("notepad", 320, 200);
  159. | // Image dump
  160. | var set = Raphael(["notepad", 320, 200, {
  161. | type: "rect",
  162. | x: 10,
  163. | y: 10,
  164. | width: 25,
  165. | height: 25,
  166. | stroke: "#f00"
  167. | }, {
  168. | type: "text",
  169. | x: 30,
  170. | y: 40,
  171. | text: "Dump"
  172. | }]);
  173. \*/
  174. function R(first) {
  175. if (R.is(first, "function")) {
  176. return loaded ? first() : eve.on("raphael.DOMload", first);
  177. } else if (R.is(first, array)) {
  178. return R._engine.create[apply](R, first.splice(0, 3 + R.is(first[0], nu))).add(first);
  179. } else {
  180. var args = Array.prototype.slice.call(arguments, 0);
  181. if (R.is(args[args.length - 1], "function")) {
  182. var f = args.pop();
  183. return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("raphael.DOMload", function () {
  184. f.call(R._engine.create[apply](R, args));
  185. });
  186. } else {
  187. return R._engine.create[apply](R, arguments);
  188. }
  189. }
  190. }
  191. R.version = "2.3.0";
  192. R.eve = eve;
  193. var loaded,
  194. separator = /[, ]+/,
  195. elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
  196. formatrg = /\{(\d+)\}/g,
  197. proto = "prototype",
  198. has = "hasOwnProperty",
  199. g = {
  200. doc: document,
  201. win: window
  202. },
  203. oldRaphael = {
  204. was: Object.prototype[has].call(g.win, "Raphael"),
  205. is: g.win.Raphael
  206. },
  207. Paper = function () {
  208. /*\
  209. * Paper.ca
  210. [ property (object) ]
  211. **
  212. * Shortcut for @Paper.customAttributes
  213. \*/
  214. /*\
  215. * Paper.customAttributes
  216. [ property (object) ]
  217. **
  218. * If you have a set of attributes that you would like to represent
  219. * as a function of some number you can do it easily with custom attributes:
  220. > Usage
  221. | paper.customAttributes.hue = function (num) {
  222. | num = num % 1;
  223. | return {fill: "hsb(" + num + ", 0.75, 1)"};
  224. | };
  225. | // Custom attribute “hue” will change fill
  226. | // to be given hue with fixed saturation and brightness.
  227. | // Now you can use it like this:
  228. | var c = paper.circle(10, 10, 10).attr({hue: .45});
  229. | // or even like this:
  230. | c.animate({hue: 1}, 1e3);
  231. |
  232. | // You could also create custom attribute
  233. | // with multiple parameters:
  234. | paper.customAttributes.hsb = function (h, s, b) {
  235. | return {fill: "hsb(" + [h, s, b].join(",") + ")"};
  236. | };
  237. | c.attr({hsb: "0.5 .8 1"});
  238. | c.animate({hsb: [1, 0, 0.5]}, 1e3);
  239. \*/
  240. this.ca = this.customAttributes = {};
  241. },
  242. paperproto,
  243. appendChild = "appendChild",
  244. apply = "apply",
  245. concat = "concat",
  246. //taken from Modernizr touch test: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js#L40
  247. supportsTouch = ('ontouchstart' in window) || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch,
  248. E = "",
  249. S = " ",
  250. Str = String,
  251. split = "split",
  252. events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
  253. touchMap = {
  254. mousedown: "touchstart",
  255. mousemove: "touchmove",
  256. mouseup: "touchend"
  257. },
  258. lowerCase = Str.prototype.toLowerCase,
  259. math = Math,
  260. mmax = math.max,
  261. mmin = math.min,
  262. abs = math.abs,
  263. pow = math.pow,
  264. PI = math.PI,
  265. nu = "number",
  266. string = "string",
  267. array = "array",
  268. toString = "toString",
  269. fillString = "fill",
  270. objectToString = Object.prototype.toString,
  271. paper = {},
  272. push = "push",
  273. ISURL = R._ISURL = /^url\(['"]?(.+?)['"]?\)$/i,
  274. colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i,
  275. isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
  276. bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
  277. round = math.round,
  278. setAttribute = "setAttribute",
  279. toFloat = parseFloat,
  280. toInt = parseInt,
  281. upperCase = Str.prototype.toUpperCase,
  282. availableAttrs = R._availableAttrs = {
  283. "arrow-end": "none",
  284. "arrow-start": "none",
  285. blur: 0,
  286. "clip-rect": "0 0 1e9 1e9",
  287. cursor: "default",
  288. cx: 0,
  289. cy: 0,
  290. fill: "#fff",
  291. "fill-opacity": 1,
  292. font: '10px "Arial"',
  293. "font-family": '"Arial"',
  294. "font-size": "10",
  295. "font-style": "normal",
  296. "font-weight": 400,
  297. gradient: 0,
  298. height: 0,
  299. href: "http://raphaeljs.com/",
  300. "letter-spacing": 0,
  301. opacity: 1,
  302. path: "M0,0",
  303. r: 0,
  304. rx: 0,
  305. ry: 0,
  306. src: "",
  307. stroke: "#000",
  308. "stroke-dasharray": "",
  309. "stroke-linecap": "butt",
  310. "stroke-linejoin": "butt",
  311. "stroke-miterlimit": 0,
  312. "stroke-opacity": 1,
  313. "stroke-width": 1,
  314. target: "_blank",
  315. "text-anchor": "middle",
  316. title: "Raphael",
  317. transform: "",
  318. width: 0,
  319. x: 0,
  320. y: 0,
  321. "class": ""
  322. },
  323. availableAnimAttrs = R._availableAnimAttrs = {
  324. blur: nu,
  325. "clip-rect": "csv",
  326. cx: nu,
  327. cy: nu,
  328. fill: "colour",
  329. "fill-opacity": nu,
  330. "font-size": nu,
  331. height: nu,
  332. opacity: nu,
  333. path: "path",
  334. r: nu,
  335. rx: nu,
  336. ry: nu,
  337. stroke: "colour",
  338. "stroke-opacity": nu,
  339. "stroke-width": nu,
  340. transform: "transform",
  341. width: nu,
  342. x: nu,
  343. y: nu
  344. },
  345. whitespace = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]/g,
  346. commaSpaces = /[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/,
  347. hsrg = {hs: 1, rg: 1},
  348. p2s = /,?([achlmqrstvxz]),?/gi,
  349. pathCommand = /([achlmrqstvz])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  350. tCommand = /([rstm])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/ig,
  351. pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/ig,
  352. radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*([^\)]+?)\))?/,
  353. eldata = {},
  354. sortByKey = function (a, b) {
  355. return a.key - b.key;
  356. },
  357. sortByNumber = function (a, b) {
  358. return toFloat(a) - toFloat(b);
  359. },
  360. fun = function () {},
  361. pipe = function (x) {
  362. return x;
  363. },
  364. rectPath = R._rectPath = function (x, y, w, h, r) {
  365. if (r) {
  366. return [["M", x + r, y], ["l", w - r * 2, 0], ["a", r, r, 0, 0, 1, r, r], ["l", 0, h - r * 2], ["a", r, r, 0, 0, 1, -r, r], ["l", r * 2 - w, 0], ["a", r, r, 0, 0, 1, -r, -r], ["l", 0, r * 2 - h], ["a", r, r, 0, 0, 1, r, -r], ["z"]];
  367. }
  368. return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
  369. },
  370. ellipsePath = function (x, y, rx, ry) {
  371. if (ry == null) {
  372. ry = rx;
  373. }
  374. return [["M", x, y], ["m", 0, -ry], ["a", rx, ry, 0, 1, 1, 0, 2 * ry], ["a", rx, ry, 0, 1, 1, 0, -2 * ry], ["z"]];
  375. },
  376. getPath = R._getPath = {
  377. path: function (el) {
  378. return el.attr("path");
  379. },
  380. circle: function (el) {
  381. var a = el.attrs;
  382. return ellipsePath(a.cx, a.cy, a.r);
  383. },
  384. ellipse: function (el) {
  385. var a = el.attrs;
  386. return ellipsePath(a.cx, a.cy, a.rx, a.ry);
  387. },
  388. rect: function (el) {
  389. var a = el.attrs;
  390. return rectPath(a.x, a.y, a.width, a.height, a.r);
  391. },
  392. image: function (el) {
  393. var a = el.attrs;
  394. return rectPath(a.x, a.y, a.width, a.height);
  395. },
  396. text: function (el) {
  397. var bbox = el._getBBox();
  398. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  399. },
  400. set : function(el) {
  401. var bbox = el._getBBox();
  402. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  403. }
  404. },
  405. /*\
  406. * Raphael.mapPath
  407. [ method ]
  408. **
  409. * Transform the path string with given matrix.
  410. > Parameters
  411. - path (string) path string
  412. - matrix (object) see @Matrix
  413. = (string) transformed path string
  414. \*/
  415. mapPath = R.mapPath = function (path, matrix) {
  416. if (!matrix) {
  417. return path;
  418. }
  419. var x, y, i, j, ii, jj, pathi;
  420. path = path2curve(path);
  421. for (i = 0, ii = path.length; i < ii; i++) {
  422. pathi = path[i];
  423. for (j = 1, jj = pathi.length; j < jj; j += 2) {
  424. x = matrix.x(pathi[j], pathi[j + 1]);
  425. y = matrix.y(pathi[j], pathi[j + 1]);
  426. pathi[j] = x;
  427. pathi[j + 1] = y;
  428. }
  429. }
  430. return path;
  431. };
  432. R._g = g;
  433. /*\
  434. * Raphael.type
  435. [ property (string) ]
  436. **
  437. * Can be “SVG”, “VML” or empty, depending on browser support.
  438. \*/
  439. R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
  440. if (R.type == "VML") {
  441. var d = g.doc.createElement("div"),
  442. b;
  443. d.innerHTML = '<v:shape adj="1"/>';
  444. b = d.firstChild;
  445. b.style.behavior = "url(#default#VML)";
  446. if (!(b && typeof b.adj == "object")) {
  447. return (R.type = E);
  448. }
  449. d = null;
  450. }
  451. /*\
  452. * Raphael.svg
  453. [ property (boolean) ]
  454. **
  455. * `true` if browser supports SVG.
  456. \*/
  457. /*\
  458. * Raphael.vml
  459. [ property (boolean) ]
  460. **
  461. * `true` if browser supports VML.
  462. \*/
  463. R.svg = !(R.vml = R.type == "VML");
  464. R._Paper = Paper;
  465. /*\
  466. * Raphael.fn
  467. [ property (object) ]
  468. **
  469. * You can add your own method to the canvas. For example if you want to draw a pie chart,
  470. * you can create your own pie chart function and ship it as a Raphaël plugin. To do this
  471. * you need to extend the `Raphael.fn` object. You should modify the `fn` object before a
  472. * Raphaël instance is created, otherwise it will take no effect. Please note that the
  473. * ability for namespaced plugins was removed in Raphael 2.0. It is up to the plugin to
  474. * ensure any namespacing ensures proper context.
  475. > Usage
  476. | Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
  477. | return this.path( ... );
  478. | };
  479. | // or create namespace
  480. | Raphael.fn.mystuff = {
  481. | arrow: function () {…},
  482. | star: function () {…},
  483. | // etc…
  484. | };
  485. | var paper = Raphael(10, 10, 630, 480);
  486. | // then use it
  487. | paper.arrow(10, 10, 30, 30, 5).attr({fill: "#f00"});
  488. | paper.mystuff.arrow();
  489. | paper.mystuff.star();
  490. \*/
  491. R.fn = paperproto = Paper.prototype = R.prototype;
  492. R._id = 0;
  493. /*\
  494. * Raphael.is
  495. [ method ]
  496. **
  497. * Handful of replacements for `typeof` operator.
  498. > Parameters
  499. - o (…) any object or primitive
  500. - type (string) name of the type, i.e. “string”, “function”, “number”, etc.
  501. = (boolean) is given value is of given type
  502. \*/
  503. R.is = function (o, type) {
  504. type = lowerCase.call(type);
  505. if (type == "finite") {
  506. return !isnan[has](+o);
  507. }
  508. if (type == "array") {
  509. return o instanceof Array;
  510. }
  511. return (type == "null" && o === null) ||
  512. (type == typeof o && o !== null) ||
  513. (type == "object" && o === Object(o)) ||
  514. (type == "array" && Array.isArray && Array.isArray(o)) ||
  515. objectToString.call(o).slice(8, -1).toLowerCase() == type;
  516. };
  517. function clone(obj) {
  518. if (typeof obj == "function" || Object(obj) !== obj) {
  519. return obj;
  520. }
  521. var res = new obj.constructor;
  522. for (var key in obj) if (obj[has](key)) {
  523. res[key] = clone(obj[key]);
  524. }
  525. return res;
  526. }
  527. /*\
  528. * Raphael.angle
  529. [ method ]
  530. **
  531. * Returns angle between two or three points
  532. > Parameters
  533. - x1 (number) x coord of first point
  534. - y1 (number) y coord of first point
  535. - x2 (number) x coord of second point
  536. - y2 (number) y coord of second point
  537. - x3 (number) #optional x coord of third point
  538. - y3 (number) #optional y coord of third point
  539. = (number) angle in degrees.
  540. \*/
  541. R.angle = function (x1, y1, x2, y2, x3, y3) {
  542. if (x3 == null) {
  543. var x = x1 - x2,
  544. y = y1 - y2;
  545. if (!x && !y) {
  546. return 0;
  547. }
  548. return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
  549. } else {
  550. return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
  551. }
  552. };
  553. /*\
  554. * Raphael.rad
  555. [ method ]
  556. **
  557. * Transform angle to radians
  558. > Parameters
  559. - deg (number) angle in degrees
  560. = (number) angle in radians.
  561. \*/
  562. R.rad = function (deg) {
  563. return deg % 360 * PI / 180;
  564. };
  565. /*\
  566. * Raphael.deg
  567. [ method ]
  568. **
  569. * Transform angle to degrees
  570. > Parameters
  571. - rad (number) angle in radians
  572. = (number) angle in degrees.
  573. \*/
  574. R.deg = function (rad) {
  575. return Math.round ((rad * 180 / PI% 360)* 1000) / 1000;
  576. };
  577. /*\
  578. * Raphael.snapTo
  579. [ method ]
  580. **
  581. * Snaps given value to given grid.
  582. > Parameters
  583. - values (array|number) given array of values or step of the grid
  584. - value (number) value to adjust
  585. - tolerance (number) #optional tolerance for snapping. Default is `10`.
  586. = (number) adjusted value.
  587. \*/
  588. R.snapTo = function (values, value, tolerance) {
  589. tolerance = R.is(tolerance, "finite") ? tolerance : 10;
  590. if (R.is(values, array)) {
  591. var i = values.length;
  592. while (i--) if (abs(values[i] - value) <= tolerance) {
  593. return values[i];
  594. }
  595. } else {
  596. values = +values;
  597. var rem = value % values;
  598. if (rem < tolerance) {
  599. return value - rem;
  600. }
  601. if (rem > values - tolerance) {
  602. return value - rem + values;
  603. }
  604. }
  605. return value;
  606. };
  607. /*\
  608. * Raphael.createUUID
  609. [ method ]
  610. **
  611. * Returns RFC4122, version 4 ID
  612. \*/
  613. var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) {
  614. return function () {
  615. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
  616. };
  617. })(/[xy]/g, function (c) {
  618. var r = math.random() * 16 | 0,
  619. v = c == "x" ? r : (r & 3 | 8);
  620. return v.toString(16);
  621. });
  622. /*\
  623. * Raphael.setWindow
  624. [ method ]
  625. **
  626. * Used when you need to draw in `&lt;iframe>`. Switched window to the iframe one.
  627. > Parameters
  628. - newwin (window) new window object
  629. \*/
  630. R.setWindow = function (newwin) {
  631. eve("raphael.setWindow", R, g.win, newwin);
  632. g.win = newwin;
  633. g.doc = g.win.document;
  634. if (R._engine.initWin) {
  635. R._engine.initWin(g.win);
  636. }
  637. };
  638. var toHex = function (color) {
  639. if (R.vml) {
  640. // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
  641. var trim = /^\s+|\s+$/g;
  642. var bod;
  643. try {
  644. var docum = new ActiveXObject("htmlfile");
  645. docum.write("<body>");
  646. docum.close();
  647. bod = docum.body;
  648. } catch(e) {
  649. bod = createPopup().document.body;
  650. }
  651. var range = bod.createTextRange();
  652. toHex = cacher(function (color) {
  653. try {
  654. bod.style.color = Str(color).replace(trim, E);
  655. var value = range.queryCommandValue("ForeColor");
  656. value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
  657. return "#" + ("000000" + value.toString(16)).slice(-6);
  658. } catch(e) {
  659. return "none";
  660. }
  661. });
  662. } else {
  663. var i = g.doc.createElement("i");
  664. i.title = "Rapha\xebl Colour Picker";
  665. i.style.display = "none";
  666. g.doc.body.appendChild(i);
  667. toHex = cacher(function (color) {
  668. i.style.color = color;
  669. return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
  670. });
  671. }
  672. return toHex(color);
  673. },
  674. hsbtoString = function () {
  675. return "hsb(" + [this.h, this.s, this.b] + ")";
  676. },
  677. hsltoString = function () {
  678. return "hsl(" + [this.h, this.s, this.l] + ")";
  679. },
  680. rgbtoString = function () {
  681. return this.hex;
  682. },
  683. prepareRGB = function (r, g, b) {
  684. if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
  685. b = r.b;
  686. g = r.g;
  687. r = r.r;
  688. }
  689. if (g == null && R.is(r, string)) {
  690. var clr = R.getRGB(r);
  691. r = clr.r;
  692. g = clr.g;
  693. b = clr.b;
  694. }
  695. if (r > 1 || g > 1 || b > 1) {
  696. r /= 255;
  697. g /= 255;
  698. b /= 255;
  699. }
  700. return [r, g, b];
  701. },
  702. packageRGB = function (r, g, b, o) {
  703. r *= 255;
  704. g *= 255;
  705. b *= 255;
  706. var rgb = {
  707. r: r,
  708. g: g,
  709. b: b,
  710. hex: R.rgb(r, g, b),
  711. toString: rgbtoString
  712. };
  713. R.is(o, "finite") && (rgb.opacity = o);
  714. return rgb;
  715. };
  716. /*\
  717. * Raphael.color
  718. [ method ]
  719. **
  720. * Parses the color string and returns object with all values for the given color.
  721. > Parameters
  722. - clr (string) color string in one of the supported formats (see @Raphael.getRGB)
  723. = (object) Combined RGB & HSB object in format:
  724. o {
  725. o r (number) red,
  726. o g (number) green,
  727. o b (number) blue,
  728. o hex (string) color in HTML/CSS format: #••••••,
  729. o error (boolean) `true` if string can’t be parsed,
  730. o h (number) hue,
  731. o s (number) saturation,
  732. o v (number) value (brightness),
  733. o l (number) lightness
  734. o }
  735. \*/
  736. R.color = function (clr) {
  737. var rgb;
  738. if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
  739. rgb = R.hsb2rgb(clr);
  740. clr.r = rgb.r;
  741. clr.g = rgb.g;
  742. clr.b = rgb.b;
  743. clr.hex = rgb.hex;
  744. } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
  745. rgb = R.hsl2rgb(clr);
  746. clr.r = rgb.r;
  747. clr.g = rgb.g;
  748. clr.b = rgb.b;
  749. clr.hex = rgb.hex;
  750. } else {
  751. if (R.is(clr, "string")) {
  752. clr = R.getRGB(clr);
  753. }
  754. if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
  755. rgb = R.rgb2hsl(clr);
  756. clr.h = rgb.h;
  757. clr.s = rgb.s;
  758. clr.l = rgb.l;
  759. rgb = R.rgb2hsb(clr);
  760. clr.v = rgb.b;
  761. } else {
  762. clr = {hex: "none"};
  763. clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
  764. }
  765. }
  766. clr.toString = rgbtoString;
  767. return clr;
  768. };
  769. /*\
  770. * Raphael.hsb2rgb
  771. [ method ]
  772. **
  773. * Converts HSB values to RGB object.
  774. > Parameters
  775. - h (number) hue
  776. - s (number) saturation
  777. - v (number) value or brightness
  778. = (object) RGB object in format:
  779. o {
  780. o r (number) red,
  781. o g (number) green,
  782. o b (number) blue,
  783. o hex (string) color in HTML/CSS format: #••••••
  784. o }
  785. \*/
  786. R.hsb2rgb = function (h, s, v, o) {
  787. if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
  788. v = h.b;
  789. s = h.s;
  790. o = h.o;
  791. h = h.h;
  792. }
  793. h *= 360;
  794. var R, G, B, X, C;
  795. h = (h % 360) / 60;
  796. C = v * s;
  797. X = C * (1 - abs(h % 2 - 1));
  798. R = G = B = v - C;
  799. h = ~~h;
  800. R += [C, X, 0, 0, X, C][h];
  801. G += [X, C, C, X, 0, 0][h];
  802. B += [0, 0, X, C, C, X][h];
  803. return packageRGB(R, G, B, o);
  804. };
  805. /*\
  806. * Raphael.hsl2rgb
  807. [ method ]
  808. **
  809. * Converts HSL values to RGB object.
  810. > Parameters
  811. - h (number) hue
  812. - s (number) saturation
  813. - l (number) luminosity
  814. = (object) RGB object in format:
  815. o {
  816. o r (number) red,
  817. o g (number) green,
  818. o b (number) blue,
  819. o hex (string) color in HTML/CSS format: #••••••
  820. o }
  821. \*/
  822. R.hsl2rgb = function (h, s, l, o) {
  823. if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
  824. l = h.l;
  825. s = h.s;
  826. h = h.h;
  827. }
  828. if (h > 1 || s > 1 || l > 1) {
  829. h /= 360;
  830. s /= 100;
  831. l /= 100;
  832. }
  833. h *= 360;
  834. var R, G, B, X, C;
  835. h = (h % 360) / 60;
  836. C = 2 * s * (l < .5 ? l : 1 - l);
  837. X = C * (1 - abs(h % 2 - 1));
  838. R = G = B = l - C / 2;
  839. h = ~~h;
  840. R += [C, X, 0, 0, X, C][h];
  841. G += [X, C, C, X, 0, 0][h];
  842. B += [0, 0, X, C, C, X][h];
  843. return packageRGB(R, G, B, o);
  844. };
  845. /*\
  846. * Raphael.rgb2hsb
  847. [ method ]
  848. **
  849. * Converts RGB values to HSB object.
  850. > Parameters
  851. - r (number) red
  852. - g (number) green
  853. - b (number) blue
  854. = (object) HSB object in format:
  855. o {
  856. o h (number) hue
  857. o s (number) saturation
  858. o b (number) brightness
  859. o }
  860. \*/
  861. R.rgb2hsb = function (r, g, b) {
  862. b = prepareRGB(r, g, b);
  863. r = b[0];
  864. g = b[1];
  865. b = b[2];
  866. var H, S, V, C;
  867. V = mmax(r, g, b);
  868. C = V - mmin(r, g, b);
  869. H = (C == 0 ? null :
  870. V == r ? (g - b) / C :
  871. V == g ? (b - r) / C + 2 :
  872. (r - g) / C + 4
  873. );
  874. H = ((H + 360) % 6) * 60 / 360;
  875. S = C == 0 ? 0 : C / V;
  876. return {h: H, s: S, b: V, toString: hsbtoString};
  877. };
  878. /*\
  879. * Raphael.rgb2hsl
  880. [ method ]
  881. **
  882. * Converts RGB values to HSL object.
  883. > Parameters
  884. - r (number) red
  885. - g (number) green
  886. - b (number) blue
  887. = (object) HSL object in format:
  888. o {
  889. o h (number) hue
  890. o s (number) saturation
  891. o l (number) luminosity
  892. o }
  893. \*/
  894. R.rgb2hsl = function (r, g, b) {
  895. b = prepareRGB(r, g, b);
  896. r = b[0];
  897. g = b[1];
  898. b = b[2];
  899. var H, S, L, M, m, C;
  900. M = mmax(r, g, b);
  901. m = mmin(r, g, b);
  902. C = M - m;
  903. H = (C == 0 ? null :
  904. M == r ? (g - b) / C :
  905. M == g ? (b - r) / C + 2 :
  906. (r - g) / C + 4);
  907. H = ((H + 360) % 6) * 60 / 360;
  908. L = (M + m) / 2;
  909. S = (C == 0 ? 0 :
  910. L < .5 ? C / (2 * L) :
  911. C / (2 - 2 * L));
  912. return {h: H, s: S, l: L, toString: hsltoString};
  913. };
  914. R._path2string = function () {
  915. return this.join(",").replace(p2s, "$1");
  916. };
  917. function repush(array, item) {
  918. for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
  919. return array.push(array.splice(i, 1)[0]);
  920. }
  921. }
  922. function cacher(f, scope, postprocessor) {
  923. function newf() {
  924. var arg = Array.prototype.slice.call(arguments, 0),
  925. args = arg.join("\u2400"),
  926. cache = newf.cache = newf.cache || {},
  927. count = newf.count = newf.count || [];
  928. if (cache[has](args)) {
  929. repush(count, args);
  930. return postprocessor ? postprocessor(cache[args]) : cache[args];
  931. }
  932. count.length >= 1e3 && delete cache[count.shift()];
  933. count.push(args);
  934. cache[args] = f[apply](scope, arg);
  935. return postprocessor ? postprocessor(cache[args]) : cache[args];
  936. }
  937. return newf;
  938. }
  939. var preload = R._preload = function (src, f) {
  940. var img = g.doc.createElement("img");
  941. img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
  942. img.onload = function () {
  943. f.call(this);
  944. this.onload = null;
  945. g.doc.body.removeChild(this);
  946. };
  947. img.onerror = function () {
  948. g.doc.body.removeChild(this);
  949. };
  950. g.doc.body.appendChild(img);
  951. img.src = src;
  952. };
  953. function clrToString() {
  954. return this.hex;
  955. }
  956. /*\
  957. * Raphael.getRGB
  958. [ method ]
  959. **
  960. * Parses colour string as RGB object
  961. > Parameters
  962. - colour (string) colour string in one of formats:
  963. # <ul>
  964. # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
  965. # <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
  966. # <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
  967. # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
  968. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
  969. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
  970. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  971. # <li>hsl(•••, •••, •••) — same as hsb</li>
  972. # <li>hsl(•••%, •••%, •••%) — same as hsb</li>
  973. # </ul>
  974. = (object) RGB object in format:
  975. o {
  976. o r (number) red,
  977. o g (number) green,
  978. o b (number) blue
  979. o hex (string) color in HTML/CSS format: #••••••,
  980. o error (boolean) true if string can’t be parsed
  981. o }
  982. \*/
  983. R.getRGB = cacher(function (colour) {
  984. if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
  985. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  986. }
  987. if (colour == "none") {
  988. return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
  989. }
  990. !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  991. var res,
  992. red,
  993. green,
  994. blue,
  995. opacity,
  996. t,
  997. values,
  998. rgb = colour.match(colourRegExp);
  999. if (rgb) {
  1000. if (rgb[2]) {
  1001. blue = toInt(rgb[2].substring(5), 16);
  1002. green = toInt(rgb[2].substring(3, 5), 16);
  1003. red = toInt(rgb[2].substring(1, 3), 16);
  1004. }
  1005. if (rgb[3]) {
  1006. blue = toInt((t = rgb[3].charAt(3)) + t, 16);
  1007. green = toInt((t = rgb[3].charAt(2)) + t, 16);
  1008. red = toInt((t = rgb[3].charAt(1)) + t, 16);
  1009. }
  1010. if (rgb[4]) {
  1011. values = rgb[4][split](commaSpaces);
  1012. red = toFloat(values[0]);
  1013. values[0].slice(-1) == "%" && (red *= 2.55);
  1014. green = toFloat(values[1]);
  1015. values[1].slice(-1) == "%" && (green *= 2.55);
  1016. blue = toFloat(values[2]);
  1017. values[2].slice(-1) == "%" && (blue *= 2.55);
  1018. rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
  1019. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1020. }
  1021. if (rgb[5]) {
  1022. values = rgb[5][split](commaSpaces);
  1023. red = toFloat(values[0]);
  1024. values[0].slice(-1) == "%" && (red *= 2.55);
  1025. green = toFloat(values[1]);
  1026. values[1].slice(-1) == "%" && (green *= 2.55);
  1027. blue = toFloat(values[2]);
  1028. values[2].slice(-1) == "%" && (blue *= 2.55);
  1029. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1030. rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
  1031. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1032. return R.hsb2rgb(red, green, blue, opacity);
  1033. }
  1034. if (rgb[6]) {
  1035. values = rgb[6][split](commaSpaces);
  1036. red = toFloat(values[0]);
  1037. values[0].slice(-1) == "%" && (red *= 2.55);
  1038. green = toFloat(values[1]);
  1039. values[1].slice(-1) == "%" && (green *= 2.55);
  1040. blue = toFloat(values[2]);
  1041. values[2].slice(-1) == "%" && (blue *= 2.55);
  1042. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  1043. rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
  1044. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  1045. return R.hsl2rgb(red, green, blue, opacity);
  1046. }
  1047. rgb = {r: red, g: green, b: blue, toString: clrToString};
  1048. rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
  1049. R.is(opacity, "finite") && (rgb.opacity = opacity);
  1050. return rgb;
  1051. }
  1052. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  1053. }, R);
  1054. /*\
  1055. * Raphael.hsb
  1056. [ method ]
  1057. **
  1058. * Converts HSB values to hex representation of the colour.
  1059. > Parameters
  1060. - h (number) hue
  1061. - s (number) saturation
  1062. - b (number) value or brightness
  1063. = (string) hex representation of the colour.
  1064. \*/
  1065. R.hsb = cacher(function (h, s, b) {
  1066. return R.hsb2rgb(h, s, b).hex;
  1067. });
  1068. /*\
  1069. * Raphael.hsl
  1070. [ method ]
  1071. **
  1072. * Converts HSL values to hex representation of the colour.
  1073. > Parameters
  1074. - h (number) hue
  1075. - s (number) saturation
  1076. - l (number) luminosity
  1077. = (string) hex representation of the colour.
  1078. \*/
  1079. R.hsl = cacher(function (h, s, l) {
  1080. return R.hsl2rgb(h, s, l).hex;
  1081. });
  1082. /*\
  1083. * Raphael.rgb
  1084. [ method ]
  1085. **
  1086. * Converts RGB values to hex representation of the colour.
  1087. > Parameters
  1088. - r (number) red
  1089. - g (number) green
  1090. - b (number) blue
  1091. = (string) hex representation of the colour.
  1092. \*/
  1093. R.rgb = cacher(function (r, g, b) {
  1094. function round(x) { return (x + 0.5) | 0; }
  1095. return "#" + (16777216 | round(b) | (round(g) << 8) | (round(r) << 16)).toString(16).slice(1);
  1096. });
  1097. /*\
  1098. * Raphael.getColor
  1099. [ method ]
  1100. **
  1101. * On each call returns next colour in the spectrum. To reset it back to red call @Raphael.getColor.reset
  1102. > Parameters
  1103. - value (number) #optional brightness, default is `0.75`
  1104. = (string) hex representation of the colour.
  1105. \*/
  1106. R.getColor = function (value) {
  1107. var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
  1108. rgb = this.hsb2rgb(start.h, start.s, start.b);
  1109. start.h += .075;
  1110. if (start.h > 1) {
  1111. start.h = 0;
  1112. start.s -= .2;
  1113. start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
  1114. }
  1115. return rgb.hex;
  1116. };
  1117. /*\
  1118. * Raphael.getColor.reset
  1119. [ method ]
  1120. **
  1121. * Resets spectrum position for @Raphael.getColor back to red.
  1122. \*/
  1123. R.getColor.reset = function () {
  1124. delete this.start;
  1125. };
  1126. // http://schepers.cc/getting-to-the-point
  1127. function catmullRom2bezier(crp, z) {
  1128. var d = [];
  1129. for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
  1130. var p = [
  1131. {x: +crp[i - 2], y: +crp[i - 1]},
  1132. {x: +crp[i], y: +crp[i + 1]},
  1133. {x: +crp[i + 2], y: +crp[i + 3]},
  1134. {x: +crp[i + 4], y: +crp[i + 5]}
  1135. ];
  1136. if (z) {
  1137. if (!i) {
  1138. p[0] = {x: +crp[iLen - 2], y: +crp[iLen - 1]};
  1139. } else if (iLen - 4 == i) {
  1140. p[3] = {x: +crp[0], y: +crp[1]};
  1141. } else if (iLen - 2 == i) {
  1142. p[2] = {x: +crp[0], y: +crp[1]};
  1143. p[3] = {x: +crp[2], y: +crp[3]};
  1144. }
  1145. } else {
  1146. if (iLen - 4 == i) {
  1147. p[3] = p[2];
  1148. } else if (!i) {
  1149. p[0] = {x: +crp[i], y: +crp[i + 1]};
  1150. }
  1151. }
  1152. d.push(["C",
  1153. (-p[0].x + 6 * p[1].x + p[2].x) / 6,
  1154. (-p[0].y + 6 * p[1].y + p[2].y) / 6,
  1155. (p[1].x + 6 * p[2].x - p[3].x) / 6,
  1156. (p[1].y + 6*p[2].y - p[3].y) / 6,
  1157. p[2].x,
  1158. p[2].y
  1159. ]);
  1160. }
  1161. return d;
  1162. }
  1163. /*\
  1164. * Raphael.parsePathString
  1165. [ method ]
  1166. **
  1167. * Utility method
  1168. **
  1169. * Parses given path string into an array of arrays of path segments.
  1170. > Parameters
  1171. - pathString (string|array) path string or array of segments (in the last case it will be returned straight away)
  1172. = (array) array of segments.
  1173. \*/
  1174. R.parsePathString = function (pathString) {
  1175. if (!pathString) {
  1176. return null;
  1177. }
  1178. var pth = paths(pathString);
  1179. if (pth.arr) {
  1180. return pathClone(pth.arr);
  1181. }
  1182. var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
  1183. data = [];
  1184. if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
  1185. data = pathClone(pathString);
  1186. }
  1187. if (!data.length) {
  1188. Str(pathString).replace(pathCommand, function (a, b, c) {
  1189. var params = [],
  1190. name = b.toLowerCase();
  1191. c.replace(pathValues, function (a, b) {
  1192. b && params.push(+b);
  1193. });
  1194. if (name == "m" && params.length > 2) {
  1195. data.push([b][concat](params.splice(0, 2)));
  1196. name = "l";
  1197. b = b == "m" ? "l" : "L";
  1198. }
  1199. if (name == "r") {
  1200. data.push([b][concat](params));
  1201. } else while (params.length >= paramCounts[name]) {
  1202. data.push([b][concat](params.splice(0, paramCounts[name])));
  1203. if (!paramCounts[name]) {
  1204. break;
  1205. }
  1206. }
  1207. });
  1208. }
  1209. data.toString = R._path2string;
  1210. pth.arr = pathClone(data);
  1211. return data;
  1212. };
  1213. /*\
  1214. * Raphael.parseTransformString
  1215. [ method ]
  1216. **
  1217. * Utility method
  1218. **
  1219. * Parses given path string into an array of transformations.
  1220. > Parameters
  1221. - TString (string|array) transform string or array of transformations (in the last case it will be returned straight away)
  1222. = (array) array of transformations.
  1223. \*/
  1224. R.parseTransformString = cacher(function (TString) {
  1225. if (!TString) {
  1226. return null;
  1227. }
  1228. var paramCounts = {r: 3, s: 4, t: 2, m: 6},
  1229. data = [];
  1230. if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
  1231. data = pathClone(TString);
  1232. }
  1233. if (!data.length) {
  1234. Str(TString).replace(tCommand, function (a, b, c) {
  1235. var params = [],
  1236. name = lowerCase.call(b);
  1237. c.replace(pathValues, function (a, b) {
  1238. b && params.push(+b);
  1239. });
  1240. data.push([b][concat](params));
  1241. });
  1242. }
  1243. data.toString = R._path2string;
  1244. return data;
  1245. }, this, function(elem) {
  1246. if (!elem) return elem;
  1247. var newData = [];
  1248. for (var i = 0; i < elem.length; i++) {
  1249. var newLevel = [];
  1250. for (var j = 0; j < elem[i].length; j++) {
  1251. newLevel.push(elem[i][j]);
  1252. }
  1253. newData.push(newLevel);
  1254. }
  1255. return newData; } );
  1256. // PATHS
  1257. var paths = function (ps) {
  1258. var p = paths.ps = paths.ps || {};
  1259. if (p[ps]) {
  1260. p[ps].sleep = 100;
  1261. } else {
  1262. p[ps] = {
  1263. sleep: 100
  1264. };
  1265. }
  1266. setTimeout(function () {
  1267. for (var key in p) if (p[has](key) && key != ps) {
  1268. p[key].sleep--;
  1269. !p[key].sleep && delete p[key];
  1270. }
  1271. });
  1272. return p[ps];
  1273. };
  1274. /*\
  1275. * Raphael.findDotsAtSegment
  1276. [ method ]
  1277. **
  1278. * Utility method
  1279. **
  1280. * Find dot coordinates on the given cubic bezier curve at the given t.
  1281. > Parameters
  1282. - p1x (number) x of the first point of the curve
  1283. - p1y (number) y of the first point of the curve
  1284. - c1x (number) x of the first anchor of the curve
  1285. - c1y (number) y of the first anchor of the curve
  1286. - c2x (number) x of the second anchor of the curve
  1287. - c2y (number) y of the second anchor of the curve
  1288. - p2x (number) x of the second point of the curve
  1289. - p2y (number) y of the second point of the curve
  1290. - t (number) position on the curve (0..1)
  1291. = (object) point information in format:
  1292. o {
  1293. o x: (number) x coordinate of the point
  1294. o y: (number) y coordinate of the point
  1295. o m: {
  1296. o x: (number) x coordinate of the left anchor
  1297. o y: (number) y coordinate of the left anchor
  1298. o }
  1299. o n: {
  1300. o x: (number) x coordinate of the right anchor
  1301. o y: (number) y coordinate of the right anchor
  1302. o }
  1303. o start: {
  1304. o x: (number) x coordinate of the start of the curve
  1305. o y: (number) y coordinate of the start of the curve
  1306. o }
  1307. o end: {
  1308. o x: (number) x coordinate of the end of the curve
  1309. o y: (number) y coordinate of the end of the curve
  1310. o }
  1311. o alpha: (number) angle of the curve derivative at the point
  1312. o }
  1313. \*/
  1314. R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  1315. var t1 = 1 - t,
  1316. t13 = pow(t1, 3),
  1317. t12 = pow(t1, 2),
  1318. t2 = t * t,
  1319. t3 = t2 * t,
  1320. x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
  1321. y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
  1322. mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
  1323. my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
  1324. nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
  1325. ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
  1326. ax = t1 * p1x + t * c1x,
  1327. ay = t1 * p1y + t * c1y,
  1328. cx = t1 * c2x + t * p2x,
  1329. cy = t1 * c2y + t * p2y,
  1330. alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
  1331. (mx > nx || my < ny) && (alpha += 180);
  1332. return {
  1333. x: x,
  1334. y: y,
  1335. m: {x: mx, y: my},
  1336. n: {x: nx, y: ny},
  1337. start: {x: ax, y: ay},
  1338. end: {x: cx, y: cy},
  1339. alpha: alpha
  1340. };
  1341. };
  1342. /*\
  1343. * Raphael.bezierBBox
  1344. [ method ]
  1345. **
  1346. * Utility method
  1347. **
  1348. * Return bounding box of a given cubic bezier curve
  1349. > Parameters
  1350. - p1x (number) x of the first point of the curve
  1351. - p1y (number) y of the first point of the curve
  1352. - c1x (number) x of the first anchor of the curve
  1353. - c1y (number) y of the first anchor of the curve
  1354. - c2x (number) x of the second anchor of the curve
  1355. - c2y (number) y of the second anchor of the curve
  1356. - p2x (number) x of the second point of the curve
  1357. - p2y (number) y of the second point of the curve
  1358. * or
  1359. - bez (array) array of six points for bezier curve
  1360. = (object) point information in format:
  1361. o {
  1362. o min: {
  1363. o x: (number) x coordinate of the left point
  1364. o y: (number) y coordinate of the top point
  1365. o }
  1366. o max: {
  1367. o x: (number) x coordinate of the right point
  1368. o y: (number) y coordinate of the bottom point
  1369. o }
  1370. o }
  1371. \*/
  1372. R.bezierBBox = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  1373. if (!R.is(p1x, "array")) {
  1374. p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
  1375. }
  1376. var bbox = curveDim.apply(null, p1x);
  1377. return {
  1378. x: bbox.min.x,
  1379. y: bbox.min.y,
  1380. x2: bbox.max.x,
  1381. y2: bbox.max.y,
  1382. width: bbox.max.x - bbox.min.x,
  1383. height: bbox.max.y - bbox.min.y
  1384. };
  1385. };
  1386. /*\
  1387. * Raphael.isPointInsideBBox
  1388. [ method ]
  1389. **
  1390. * Utility method
  1391. **
  1392. * Returns `true` if given point is inside bounding boxes.
  1393. > Parameters
  1394. - bbox (string) bounding box
  1395. - x (string) x coordinate of the point
  1396. - y (string) y coordinate of the point
  1397. = (boolean) `true` if point inside
  1398. \*/
  1399. R.isPointInsideBBox = function (bbox, x, y) {
  1400. return x >= bbox.x && x <= bbox.x2 && y >= bbox.y && y <= bbox.y2;
  1401. };
  1402. /*\
  1403. * Raphael.isBBoxIntersect
  1404. [ method ]
  1405. **
  1406. * Utility method
  1407. **
  1408. * Returns `true` if two bounding boxes intersect
  1409. > Parameters
  1410. - bbox1 (string) first bounding box
  1411. - bbox2 (string) second bounding box
  1412. = (boolean) `true` if they intersect
  1413. \*/
  1414. R.isBBoxIntersect = function (bbox1, bbox2) {
  1415. var i = R.isPointInsideBBox;
  1416. return i(bbox2, bbox1.x, bbox1.y)
  1417. || i(bbox2, bbox1.x2, bbox1.y)
  1418. || i(bbox2, bbox1.x, bbox1.y2)
  1419. || i(bbox2, bbox1.x2, bbox1.y2)
  1420. || i(bbox1, bbox2.x, bbox2.y)
  1421. || i(bbox1, bbox2.x2, bbox2.y)
  1422. || i(bbox1, bbox2.x, bbox2.y2)
  1423. || i(bbox1, bbox2.x2, bbox2.y2)
  1424. || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
  1425. && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
  1426. };
  1427. function base3(t, p1, p2, p3, p4) {
  1428. var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
  1429. t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
  1430. return t * t2 - 3 * p1 + 3 * p2;
  1431. }
  1432. function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
  1433. if (z == null) {
  1434. z = 1;
  1435. }
  1436. z = z > 1 ? 1 : z < 0 ? 0 : z;
  1437. var z2 = z / 2,
  1438. n = 12,
  1439. Tvalues = [-0.1252,0.1252,-0.3678,0.3678,-0.5873,0.5873,-0.7699,0.7699,-0.9041,0.9041,-0.9816,0.9816],
  1440. Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472],
  1441. sum = 0;
  1442. for (var i = 0; i < n; i++) {
  1443. var ct = z2 * Tvalues[i] + z2,
  1444. xbase = base3(ct, x1, x2, x3, x4),
  1445. ybase = base3(ct, y1, y2, y3, y4),
  1446. comb = xbase * xbase + ybase * ybase;
  1447. sum += Cvalues[i] * math.sqrt(comb);
  1448. }
  1449. return z2 * sum;
  1450. }
  1451. function getTatLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) {
  1452. if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) {
  1453. return;
  1454. }
  1455. var t = 1,
  1456. step = t / 2,
  1457. t2 = t - step,
  1458. l,
  1459. e = .01;
  1460. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1461. while (abs(l - ll) > e) {
  1462. step /= 2;
  1463. t2 += (l < ll ? 1 : -1) * step;
  1464. l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2);
  1465. }
  1466. return t2;
  1467. }
  1468. function intersect(x1, y1, x2, y2, x3, y3, x4, y4) {
  1469. if (
  1470. mmax(x1, x2) < mmin(x3, x4) ||
  1471. mmin(x1, x2) > mmax(x3, x4) ||
  1472. mmax(y1, y2) < mmin(y3, y4) ||
  1473. mmin(y1, y2) > mmax(y3, y4)
  1474. ) {
  1475. return;
  1476. }
  1477. var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
  1478. ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
  1479. denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  1480. if (!denominator) {
  1481. return;
  1482. }
  1483. var px = nx / denominator,
  1484. py = ny / denominator,
  1485. px2 = +px.toFixed(2),
  1486. py2 = +py.toFixed(2);
  1487. if (
  1488. px2 < +mmin(x1, x2).toFixed(2) ||
  1489. px2 > +mmax(x1, x2).toFixed(2) ||
  1490. px2 < +mmin(x3, x4).toFixed(2) ||
  1491. px2 > +mmax(x3, x4).toFixed(2) ||
  1492. py2 < +mmin(y1, y2).toFixed(2) ||
  1493. py2 > +mmax(y1, y2).toFixed(2) ||
  1494. py2 < +mmin(y3, y4).toFixed(2) ||
  1495. py2 > +mmax(y3, y4).toFixed(2)
  1496. ) {
  1497. return;
  1498. }
  1499. return {x: px, y: py};
  1500. }
  1501. function inter(bez1, bez2) {
  1502. return interHelper(bez1, bez2);
  1503. }
  1504. function interCount(bez1, bez2) {
  1505. return interHelper(bez1, bez2, 1);
  1506. }
  1507. function interHelper(bez1, bez2, justCount) {
  1508. var bbox1 = R.bezierBBox(bez1),
  1509. bbox2 = R.bezierBBox(bez2);
  1510. if (!R.isBBoxIntersect(bbox1, bbox2)) {
  1511. return justCount ? 0 : [];
  1512. }
  1513. var l1 = bezlen.apply(0, bez1),
  1514. l2 = bezlen.apply(0, bez2),
  1515. n1 = mmax(~~(l1 / 5), 1),
  1516. n2 = mmax(~~(l2 / 5), 1),
  1517. dots1 = [],
  1518. dots2 = [],
  1519. xy = {},
  1520. res = justCount ? 0 : [];
  1521. for (var i = 0; i < n1 + 1; i++) {
  1522. var p = R.findDotsAtSegment.apply(R, bez1.concat(i / n1));
  1523. dots1.push({x: p.x, y: p.y, t: i / n1});
  1524. }
  1525. for (i = 0; i < n2 + 1; i++) {
  1526. p = R.findDotsAtSegment.apply(R, bez2.concat(i / n2));
  1527. dots2.push({x: p.x, y: p.y, t: i / n2});
  1528. }
  1529. for (i = 0; i < n1; i++) {
  1530. for (var j = 0; j < n2; j++) {
  1531. var di = dots1[i],
  1532. di1 = dots1[i + 1],
  1533. dj = dots2[j],
  1534. dj1 = dots2[j + 1],
  1535. ci = abs(di1.x - di.x) < .001 ? "y" : "x",
  1536. cj = abs(dj1.x - dj.x) < .001 ? "y" : "x",
  1537. is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
  1538. if (is) {
  1539. if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {
  1540. continue;
  1541. }
  1542. xy[is.x.toFixed(4)] = is.y.toFixed(4);
  1543. var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
  1544. t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
  1545. if (t1 >= 0 && t1 <= 1.001 && t2 >= 0 && t2 <= 1.001) {
  1546. if (justCount) {
  1547. res++;
  1548. } else {
  1549. res.push({
  1550. x: is.x,
  1551. y: is.y,
  1552. t1: mmin(t1, 1),
  1553. t2: mmin(t2, 1)
  1554. });
  1555. }
  1556. }
  1557. }
  1558. }
  1559. }
  1560. return res;
  1561. }
  1562. /*\
  1563. * Raphael.pathIntersection
  1564. [ method ]
  1565. **
  1566. * Utility method
  1567. **
  1568. * Finds intersections of two paths
  1569. > Parameters
  1570. - path1 (string) path string
  1571. - path2 (string) path string
  1572. = (array) dots of intersection
  1573. o [
  1574. o {
  1575. o x: (number) x coordinate of the point
  1576. o y: (number) y coordinate of the point
  1577. o t1: (number) t value for segment of path1
  1578. o t2: (number) t value for segment of path2
  1579. o segment1: (number) order number for segment of path1
  1580. o segment2: (number) order number for segment of path2
  1581. o bez1: (array) eight coordinates representing beziér curve for the segment of path1
  1582. o bez2: (array) eight coordinates representing beziér curve for the segment of path2
  1583. o }
  1584. o ]
  1585. \*/
  1586. R.pathIntersection = function (path1, path2) {
  1587. return interPathHelper(path1, path2);
  1588. };
  1589. R.pathIntersectionNumber = function (path1, path2) {
  1590. return interPathHelper(path1, path2, 1);
  1591. };
  1592. function interPathHelper(path1, path2, justCount) {
  1593. path1 = R._path2curve(path1);
  1594. path2 = R._path2curve(path2);
  1595. var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
  1596. res = justCount ? 0 : [];
  1597. for (var i = 0, ii = path1.length; i < ii; i++) {
  1598. var pi = path1[i];
  1599. if (pi[0] == "M") {
  1600. x1 = x1m = pi[1];
  1601. y1 = y1m = pi[2];
  1602. } else {
  1603. if (pi[0] == "C") {
  1604. bez1 = [x1, y1].concat(pi.slice(1));
  1605. x1 = bez1[6];
  1606. y1 = bez1[7];
  1607. } else {
  1608. bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
  1609. x1 = x1m;
  1610. y1 = y1m;
  1611. }
  1612. for (var j = 0, jj = path2.length; j < jj; j++) {
  1613. var pj = path2[j];
  1614. if (pj[0] == "M") {
  1615. x2 = x2m = pj[1];
  1616. y2 = y2m = pj[2];
  1617. } else {
  1618. if (pj[0] == "C") {
  1619. bez2 = [x2, y2].concat(pj.slice(1));
  1620. x2 = bez2[6];
  1621. y2 = bez2[7];
  1622. } else {
  1623. bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
  1624. x2 = x2m;
  1625. y2 = y2m;
  1626. }
  1627. var intr = interHelper(bez1, bez2, justCount);
  1628. if (justCount) {
  1629. res += intr;
  1630. } else {
  1631. for (var k = 0, kk = intr.length; k < kk; k++) {
  1632. intr[k].segment1 = i;
  1633. intr[k].segment2 = j;
  1634. intr[k].bez1 = bez1;
  1635. intr[k].bez2 = bez2;
  1636. }
  1637. res = res.concat(intr);
  1638. }
  1639. }
  1640. }
  1641. }
  1642. }
  1643. return res;
  1644. }
  1645. /*\
  1646. * Raphael.isPointInsidePath
  1647. [ method ]
  1648. **
  1649. * Utility method
  1650. **
  1651. * Returns `true` if given point is inside a given closed path.
  1652. > Parameters
  1653. - path (string) path string
  1654. - x (number) x of the point
  1655. - y (number) y of the point
  1656. = (boolean) true, if point is inside the path
  1657. \*/
  1658. R.isPointInsidePath = function (path, x, y) {
  1659. var bbox = R.pathBBox(path);
  1660. return R.isPointInsideBBox(bbox, x, y) &&
  1661. interPathHelper(path, [["M", x, y], ["H", bbox.x2 + 10]], 1) % 2 == 1;
  1662. };
  1663. R._removedFactory = function (methodname) {
  1664. return function () {
  1665. eve("raphael.log", null, "Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object", methodname);
  1666. };
  1667. };
  1668. /*\
  1669. * Raphael.pathBBox
  1670. [ method ]
  1671. **
  1672. * Utility method
  1673. **
  1674. * Return bounding box of a given path
  1675. > Parameters
  1676. - path (string) path string
  1677. = (object) bounding box
  1678. o {
  1679. o x: (number) x coordinate of the left top point of the box
  1680. o y: (number) y coordinate of the left top point of the box
  1681. o x2: (number) x coordinate of the right bottom point of the box
  1682. o y2: (number) y coordinate of the right bottom point of the box
  1683. o width: (number) width of the box
  1684. o height: (number) height of the box
  1685. o cx: (number) x coordinate of the center of the box
  1686. o cy: (number) y coordinate of the center of the box
  1687. o }
  1688. \*/
  1689. var pathDimensions = R.pathBBox = function (path) {
  1690. var pth = paths(path);
  1691. if (pth.bbox) {
  1692. return clone(pth.bbox);
  1693. }
  1694. if (!path) {
  1695. return {x: 0, y: 0, width: 0, height: 0, x2: 0, y2: 0};
  1696. }
  1697. path = path2curve(path);
  1698. var x = 0,
  1699. y = 0,
  1700. X = [],
  1701. Y = [],
  1702. p;
  1703. for (var i = 0, ii = path.length; i < ii; i++) {
  1704. p = path[i];
  1705. if (p[0] == "M") {
  1706. x = p[1];
  1707. y = p[2];
  1708. X.push(x);
  1709. Y.push(y);
  1710. } else {
  1711. var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  1712. X = X[concat](dim.min.x, dim.max.x);
  1713. Y = Y[concat](dim.min.y, dim.max.y);
  1714. x = p[5];
  1715. y = p[6];
  1716. }
  1717. }
  1718. var xmin = mmin[apply](0, X),
  1719. ymin = mmin[apply](0, Y),
  1720. xmax = mmax[apply](0, X),
  1721. ymax = mmax[apply](0, Y),
  1722. width = xmax - xmin,
  1723. height = ymax - ymin,
  1724. bb = {
  1725. x: xmin,
  1726. y: ymin,
  1727. x2: xmax,
  1728. y2: ymax,
  1729. width: width,
  1730. height: height,
  1731. cx: xmin + width / 2,
  1732. cy: ymin + height / 2
  1733. };
  1734. pth.bbox = clone(bb);
  1735. return bb;
  1736. },
  1737. pathClone = function (pathArray) {
  1738. var res = clone(pathArray);
  1739. res.toString = R._path2string;
  1740. return res;
  1741. },
  1742. pathToRelative = R._pathToRelative = function (pathArray) {
  1743. var pth = paths(pathArray);
  1744. if (pth.rel) {
  1745. return pathClone(pth.rel);
  1746. }
  1747. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1748. pathArray = R.parsePathString(pathArray);
  1749. }
  1750. var res = [],
  1751. x = 0,
  1752. y = 0,
  1753. mx = 0,
  1754. my = 0,
  1755. start = 0;
  1756. if (pathArray[0][0] == "M") {
  1757. x = pathArray[0][1];
  1758. y = pathArray[0][2];
  1759. mx = x;
  1760. my = y;
  1761. start++;
  1762. res.push(["M", x, y]);
  1763. }
  1764. for (var i = start, ii = pathArray.length; i < ii; i++) {
  1765. var r = res[i] = [],
  1766. pa = pathArray[i];
  1767. if (pa[0] != lowerCase.call(pa[0])) {
  1768. r[0] = lowerCase.call(pa[0]);
  1769. switch (r[0]) {
  1770. case "a":
  1771. r[1] = pa[1];
  1772. r[2] = pa[2];
  1773. r[3] = pa[3];
  1774. r[4] = pa[4];
  1775. r[5] = pa[5];
  1776. r[6] = +(pa[6] - x).toFixed(3);
  1777. r[7] = +(pa[7] - y).toFixed(3);
  1778. break;
  1779. case "v":
  1780. r[1] = +(pa[1] - y).toFixed(3);
  1781. break;
  1782. case "m":
  1783. mx = pa[1];
  1784. my = pa[2];
  1785. default:
  1786. for (var j = 1, jj = pa.length; j < jj; j++) {
  1787. r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
  1788. }
  1789. }
  1790. } else {
  1791. r = res[i] = [];
  1792. if (pa[0] == "m") {
  1793. mx = pa[1] + x;
  1794. my = pa[2] + y;
  1795. }
  1796. for (var k = 0, kk = pa.length; k < kk; k++) {
  1797. res[i][k] = pa[k];
  1798. }
  1799. }
  1800. var len = res[i].length;
  1801. switch (res[i][0]) {
  1802. case "z":
  1803. x = mx;
  1804. y = my;
  1805. break;
  1806. case "h":
  1807. x += +res[i][len - 1];
  1808. break;
  1809. case "v":
  1810. y += +res[i][len - 1];
  1811. break;
  1812. default:
  1813. x += +res[i][len - 2];
  1814. y += +res[i][len - 1];
  1815. }
  1816. }
  1817. res.toString = R._path2string;
  1818. pth.rel = pathClone(res);
  1819. return res;
  1820. },
  1821. pathToAbsolute = R._pathToAbsolute = function (pathArray) {
  1822. var pth = paths(pathArray);
  1823. if (pth.abs) {
  1824. return pathClone(pth.abs);
  1825. }
  1826. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1827. pathArray = R.parsePathString(pathArray);
  1828. }
  1829. if (!pathArray || !pathArray.length) {
  1830. return [["M", 0, 0]];
  1831. }
  1832. var res = [],
  1833. x = 0,
  1834. y = 0,
  1835. mx = 0,
  1836. my = 0,
  1837. start = 0;
  1838. if (pathArray[0][0] == "M") {
  1839. x = +pathArray[0][1];
  1840. y = +pathArray[0][2];
  1841. mx = x;
  1842. my = y;
  1843. start++;
  1844. res[0] = ["M", x, y];
  1845. }
  1846. var crz = pathArray.length == 3 && pathArray[0][0] == "M" && pathArray[1][0].toUpperCase() == "R" && pathArray[2][0].toUpperCase() == "Z";
  1847. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  1848. res.push(r = []);
  1849. pa = pathArray[i];
  1850. if (pa[0] != upperCase.call(pa[0])) {
  1851. r[0] = upperCase.call(pa[0]);
  1852. switch (r[0]) {
  1853. case "A":
  1854. r[1] = pa[1];
  1855. r[2] = pa[2];
  1856. r[3] = pa[3];
  1857. r[4] = pa[4];
  1858. r[5] = pa[5];
  1859. r[6] = +(pa[6] + x);
  1860. r[7] = +(pa[7] + y);
  1861. break;
  1862. case "V":
  1863. r[1] = +pa[1] + y;
  1864. break;
  1865. case "H":
  1866. r[1] = +pa[1] + x;
  1867. break;
  1868. case "R":
  1869. var dots = [x, y][concat](pa.slice(1));
  1870. for (var j = 2, jj = dots.length; j < jj; j++) {
  1871. dots[j] = +dots[j] + x;
  1872. dots[++j] = +dots[j] + y;
  1873. }
  1874. res.pop();
  1875. res = res[concat](catmullRom2bezier(dots, crz));
  1876. break;
  1877. case "M":
  1878. mx = +pa[1] + x;
  1879. my = +pa[2] + y;
  1880. default:
  1881. for (j = 1, jj = pa.length; j < jj; j++) {
  1882. r[j] = +pa[j] + ((j % 2) ? x : y);
  1883. }
  1884. }
  1885. } else if (pa[0] == "R") {
  1886. dots = [x, y][concat](pa.slice(1));
  1887. res.pop();
  1888. res = res[concat](catmullRom2bezier(dots, crz));
  1889. r = ["R"][concat](pa.slice(-2));
  1890. } else {
  1891. for (var k = 0, kk = pa.length; k < kk; k++) {
  1892. r[k] = pa[k];
  1893. }
  1894. }
  1895. switch (r[0]) {
  1896. case "Z":
  1897. x = mx;
  1898. y = my;
  1899. break;
  1900. case "H":
  1901. x = r[1];
  1902. break;
  1903. case "V":
  1904. y = r[1];
  1905. break;
  1906. case "M":
  1907. mx = r[r.length - 2];
  1908. my = r[r.length - 1];
  1909. default:
  1910. x = r[r.length - 2];
  1911. y = r[r.length - 1];
  1912. }
  1913. }
  1914. res.toString = R._path2string;
  1915. pth.abs = pathClone(res);
  1916. return res;
  1917. },
  1918. l2c = function (x1, y1, x2, y2) {
  1919. return [x1, y1, x2, y2, x2, y2];
  1920. },
  1921. q2c = function (x1, y1, ax, ay, x2, y2) {
  1922. var _13 = 1 / 3,
  1923. _23 = 2 / 3;
  1924. return [
  1925. _13 * x1 + _23 * ax,
  1926. _13 * y1 + _23 * ay,
  1927. _13 * x2 + _23 * ax,
  1928. _13 * y2 + _23 * ay,
  1929. x2,
  1930. y2
  1931. ];
  1932. },
  1933. a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  1934. // for more information of where this math came from visit:
  1935. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  1936. var _120 = PI * 120 / 180,
  1937. rad = PI / 180 * (+angle || 0),
  1938. res = [],
  1939. xy,
  1940. rotate = cacher(function (x, y, rad) {
  1941. var X = x * math.cos(rad) - y * math.sin(rad),
  1942. Y = x * math.sin(rad) + y * math.cos(rad);
  1943. return {x: X, y: Y};
  1944. });
  1945. if (!recursive) {
  1946. xy = rotate(x1, y1, -rad);
  1947. x1 = xy.x;
  1948. y1 = xy.y;
  1949. xy = rotate(x2, y2, -rad);
  1950. x2 = xy.x;
  1951. y2 = xy.y;
  1952. var cos = math.cos(PI / 180 * angle),
  1953. sin = math.sin(PI / 180 * angle),
  1954. x = (x1 - x2) / 2,
  1955. y = (y1 - y2) / 2;
  1956. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  1957. if (h > 1) {
  1958. h = math.sqrt(h);
  1959. rx = h * rx;
  1960. ry = h * ry;
  1961. }
  1962. var rx2 = rx * rx,
  1963. ry2 = ry * ry,
  1964. k = (large_arc_flag == sweep_flag ? -1 : 1) *
  1965. math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
  1966. cx = k * rx * y / ry + (x1 + x2) / 2,
  1967. cy = k * -ry * x / rx + (y1 + y2) / 2,
  1968. f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
  1969. f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  1970. f1 = x1 < cx ? PI - f1 : f1;
  1971. f2 = x2 < cx ? PI - f2 : f2;
  1972. f1 < 0 && (f1 = PI * 2 + f1);
  1973. f2 < 0 && (f2 = PI * 2 + f2);
  1974. if (sweep_flag && f1 > f2) {
  1975. f1 = f1 - PI * 2;
  1976. }
  1977. if (!sweep_flag && f2 > f1) {
  1978. f2 = f2 - PI * 2;
  1979. }
  1980. } else {
  1981. f1 = recursive[0];
  1982. f2 = recursive[1];
  1983. cx = recursive[2];
  1984. cy = recursive[3];
  1985. }
  1986. var df = f2 - f1;
  1987. if (abs(df) > _120) {
  1988. var f2old = f2,
  1989. x2old = x2,
  1990. y2old = y2;
  1991. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  1992. x2 = cx + rx * math.cos(f2);
  1993. y2 = cy + ry * math.sin(f2);
  1994. res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  1995. }
  1996. df = f2 - f1;
  1997. var c1 = math.cos(f1),
  1998. s1 = math.sin(f1),
  1999. c2 = math.cos(f2),
  2000. s2 = math.sin(f2),
  2001. t = math.tan(df / 4),
  2002. hx = 4 / 3 * rx * t,
  2003. hy = 4 / 3 * ry * t,
  2004. m1 = [x1, y1],
  2005. m2 = [x1 + hx * s1, y1 - hy * c1],
  2006. m3 = [x2 + hx * s2, y2 - hy * c2],
  2007. m4 = [x2, y2];
  2008. m2[0] = 2 * m1[0] - m2[0];
  2009. m2[1] = 2 * m1[1] - m2[1];
  2010. if (recursive) {
  2011. return [m2, m3, m4][concat](res);
  2012. } else {
  2013. res = [m2, m3, m4][concat](res).join()[split](",");
  2014. var newres = [];
  2015. for (var i = 0, ii = res.length; i < ii; i++) {
  2016. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  2017. }
  2018. return newres;
  2019. }
  2020. },
  2021. findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  2022. var t1 = 1 - t;
  2023. return {
  2024. x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
  2025. y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
  2026. };
  2027. },
  2028. curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  2029. var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
  2030. b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
  2031. c = p1x - c1x,
  2032. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2033. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
  2034. y = [p1y, p2y],
  2035. x = [p1x, p2x],
  2036. dot;
  2037. abs(t1) > "1e12" && (t1 = .5);
  2038. abs(t2) > "1e12" && (t2 = .5);
  2039. if (t1 > 0 && t1 < 1) {
  2040. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2041. x.push(dot.x);
  2042. y.push(dot.y);
  2043. }
  2044. if (t2 > 0 && t2 < 1) {
  2045. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2046. x.push(dot.x);
  2047. y.push(dot.y);
  2048. }
  2049. a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
  2050. b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
  2051. c = p1y - c1y;
  2052. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2053. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
  2054. abs(t1) > "1e12" && (t1 = .5);
  2055. abs(t2) > "1e12" && (t2 = .5);
  2056. if (t1 > 0 && t1 < 1) {
  2057. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  2058. x.push(dot.x);
  2059. y.push(dot.y);
  2060. }
  2061. if (t2 > 0 && t2 < 1) {
  2062. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  2063. x.push(dot.x);
  2064. y.push(dot.y);
  2065. }
  2066. return {
  2067. min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
  2068. max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
  2069. };
  2070. }),
  2071. path2curve = R._path2curve = cacher(function (path, path2) {
  2072. var pth = !path2 && paths(path);
  2073. if (!path2 && pth.curve) {
  2074. return pathClone(pth.curve);
  2075. }
  2076. var p = pathToAbsolute(path),
  2077. p2 = path2 && pathToAbsolute(path2),
  2078. attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2079. attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  2080. processPath = function (path, d, pcom) {
  2081. var nx, ny, tq = {T:1, Q:1};
  2082. if (!path) {
  2083. return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
  2084. }
  2085. !(path[0] in tq) && (d.qx = d.qy = null);
  2086. switch (path[0]) {
  2087. case "M":
  2088. d.X = path[1];
  2089. d.Y = path[2];
  2090. break;
  2091. case "A":
  2092. path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
  2093. break;
  2094. case "S":
  2095. if (pcom == "C" || pcom == "S") { // In "S" case we have to take into account, if the previous command is C/S.
  2096. nx = d.x * 2 - d.bx; // And reflect the previous
  2097. ny = d.y * 2 - d.by; // command's control point relative to the current point.
  2098. }
  2099. else { // or some else or nothing
  2100. nx = d.x;
  2101. ny = d.y;
  2102. }
  2103. path = ["C", nx, ny][concat](path.slice(1));
  2104. break;
  2105. case "T":
  2106. if (pcom == "Q" || pcom == "T") { // In "T" case we have to take into account, if the previous command is Q/T.
  2107. d.qx = d.x * 2 - d.qx; // And make a reflection similar
  2108. d.qy = d.y * 2 - d.qy; // to case "S".
  2109. }
  2110. else { // or something else or nothing
  2111. d.qx = d.x;
  2112. d.qy = d.y;
  2113. }
  2114. path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  2115. break;
  2116. case "Q":
  2117. d.qx = path[1];
  2118. d.qy = path[2];
  2119. path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
  2120. break;
  2121. case "L":
  2122. path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
  2123. break;
  2124. case "H":
  2125. path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
  2126. break;
  2127. case "V":
  2128. path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
  2129. break;
  2130. case "Z":
  2131. path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
  2132. break;
  2133. }
  2134. return path;
  2135. },
  2136. fixArc = function (pp, i) {
  2137. if (pp[i].length > 7) {
  2138. pp[i].shift();
  2139. var pi = pp[i];
  2140. while (pi.length) {
  2141. pcoms1[i]="A"; // if created multiple C:s, their original seg is saved
  2142. p2 && (pcoms2[i]="A"); // the same as above
  2143. pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
  2144. }
  2145. pp.splice(i, 1);
  2146. ii = mmax(p.length, p2 && p2.length || 0);
  2147. }
  2148. },
  2149. fixM = function (path1, path2, a1, a2, i) {
  2150. if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
  2151. path2.splice(i, 0, ["M", a2.x, a2.y]);
  2152. a1.bx = 0;
  2153. a1.by = 0;
  2154. a1.x = path1[i][1];
  2155. a1.y = path1[i][2];
  2156. ii = mmax(p.length, p2 && p2.length || 0);
  2157. }
  2158. },
  2159. pcoms1 = [], // path commands of original path p
  2160. pcoms2 = [], // path commands of original path p2
  2161. pfirst = "", // temporary holder for original path command
  2162. pcom = ""; // holder for previous path command of original path
  2163. for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
  2164. p[i] && (pfirst = p[i][0]); // save current path command
  2165. if (pfirst != "C") // C is not saved yet, because it may be result of conversion
  2166. {
  2167. pcoms1[i] = pfirst; // Save current path command
  2168. i && ( pcom = pcoms1[i-1]); // Get previous path command pcom
  2169. }
  2170. p[i] = processPath(p[i], attrs, pcom); // Previous path command is inputted to processPath
  2171. if (pcoms1[i] != "A" && pfirst == "C") pcoms1[i] = "C"; // A is the only command
  2172. // which may produce multiple C:s
  2173. // so we have to make sure that C is also C in original path
  2174. fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1
  2175. if (p2) { // the same procedures is done to p2
  2176. p2[i] && (pfirst = p2[i][0]);
  2177. if (pfirst != "C")
  2178. {
  2179. pcoms2[i] = pfirst;
  2180. i && (pcom = pcoms2[i-1]);
  2181. }
  2182. p2[i] = processPath(p2[i], attrs2, pcom);
  2183. if (pcoms2[i]!="A" && pfirst=="C") pcoms2[i]="C";
  2184. fixArc(p2, i);
  2185. }
  2186. fixM(p, p2, attrs, attrs2, i);
  2187. fixM(p2, p, attrs2, attrs, i);
  2188. var seg = p[i],
  2189. seg2 = p2 && p2[i],
  2190. seglen = seg.length,
  2191. seg2len = p2 && seg2.length;
  2192. attrs.x = seg[seglen - 2];
  2193. attrs.y = seg[seglen - 1];
  2194. attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
  2195. attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
  2196. attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
  2197. attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
  2198. attrs2.x = p2 && seg2[seg2len - 2];
  2199. attrs2.y = p2 && seg2[seg2len - 1];
  2200. }
  2201. if (!p2) {
  2202. pth.curve = pathClone(p);
  2203. }
  2204. return p2 ? [p, p2] : p;
  2205. }, null, pathClone),
  2206. parseDots = R._parseDots = cacher(function (gradient) {
  2207. var dots = [];
  2208. for (var i = 0, ii = gradient.length; i < ii; i++) {
  2209. var dot = {},
  2210. par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
  2211. dot.color = R.getRGB(par[1]);
  2212. if (dot.color.error) {
  2213. return null;
  2214. }
  2215. dot.opacity = dot.color.opacity;
  2216. dot.color = dot.color.hex;
  2217. par[2] && (dot.offset = par[2] + "%");
  2218. dots.push(dot);
  2219. }
  2220. for (i = 1, ii = dots.length - 1; i < ii; i++) {
  2221. if (!dots[i].offset) {
  2222. var start = toFloat(dots[i - 1].offset || 0),
  2223. end = 0;
  2224. for (var j = i + 1; j < ii; j++) {
  2225. if (dots[j].offset) {
  2226. end = dots[j].offset;
  2227. break;
  2228. }
  2229. }
  2230. if (!end) {
  2231. end = 100;
  2232. j = ii;
  2233. }
  2234. end = toFloat(end);
  2235. var d = (end - start) / (j - i + 1);
  2236. for (; i < j; i++) {
  2237. start += d;
  2238. dots[i].offset = start + "%";
  2239. }
  2240. }
  2241. }
  2242. return dots;
  2243. }),
  2244. tear = R._tear = function (el, paper) {
  2245. el == paper.top && (paper.top = el.prev);
  2246. el == paper.bottom && (paper.bottom = el.next);
  2247. el.next && (el.next.prev = el.prev);
  2248. el.prev && (el.prev.next = el.next);
  2249. },
  2250. tofront = R._tofront = function (el, paper) {
  2251. if (paper.top === el) {
  2252. return;
  2253. }
  2254. tear(el, paper);
  2255. el.next = null;
  2256. el.prev = paper.top;
  2257. paper.top.next = el;
  2258. paper.top = el;
  2259. },
  2260. toback = R._toback = function (el, paper) {
  2261. if (paper.bottom === el) {
  2262. return;
  2263. }
  2264. tear(el, paper);
  2265. el.next = paper.bottom;
  2266. el.prev = null;
  2267. paper.bottom.prev = el;
  2268. paper.bottom = el;
  2269. },
  2270. insertafter = R._insertafter = function (el, el2, paper) {
  2271. tear(el, paper);
  2272. el2 == paper.top && (paper.top = el);
  2273. el2.next && (el2.next.prev = el);
  2274. el.next = el2.next;
  2275. el.prev = el2;
  2276. el2.next = el;
  2277. },
  2278. insertbefore = R._insertbefore = function (el, el2, paper) {
  2279. tear(el, paper);
  2280. el2 == paper.bottom && (paper.bottom = el);
  2281. el2.prev && (el2.prev.next = el);
  2282. el.prev = el2.prev;
  2283. el2.prev = el;
  2284. el.next = el2;
  2285. },
  2286. /*\
  2287. * Raphael.toMatrix
  2288. [ method ]
  2289. **
  2290. * Utility method
  2291. **
  2292. * Returns matrix of transformations applied to a given path
  2293. > Parameters
  2294. - path (string) path string
  2295. - transform (string|array) transformation string
  2296. = (object) @Matrix
  2297. \*/
  2298. toMatrix = R.toMatrix = function (path, transform) {
  2299. var bb = pathDimensions(path),
  2300. el = {
  2301. _: {
  2302. transform: E
  2303. },
  2304. getBBox: function () {
  2305. return bb;
  2306. }
  2307. };
  2308. extractTransform(el, transform);
  2309. return el.matrix;
  2310. },
  2311. /*\
  2312. * Raphael.transformPath
  2313. [ method ]
  2314. **
  2315. * Utility method
  2316. **
  2317. * Returns path transformed by a given transformation
  2318. > Parameters
  2319. - path (string) path string
  2320. - transform (string|array) transformation string
  2321. = (string) path
  2322. \*/
  2323. transformPath = R.transformPath = function (path, transform) {
  2324. return mapPath(path, toMatrix(path, transform));
  2325. },
  2326. extractTransform = R._extractTransform = function (el, tstr) {
  2327. if (tstr == null) {
  2328. return el._.transform;
  2329. }
  2330. tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
  2331. var tdata = R.parseTransformString(tstr),
  2332. deg = 0,
  2333. dx = 0,
  2334. dy = 0,
  2335. sx = 1,
  2336. sy = 1,
  2337. _ = el._,
  2338. m = new Matrix;
  2339. _.transform = tdata || [];
  2340. if (tdata) {
  2341. for (var i = 0, ii = tdata.length; i < ii; i++) {
  2342. var t = tdata[i],
  2343. tlen = t.length,
  2344. command = Str(t[0]).toLowerCase(),
  2345. absolute = t[0] != command,
  2346. inver = absolute ? m.invert() : 0,
  2347. x1,
  2348. y1,
  2349. x2,
  2350. y2,
  2351. bb;
  2352. if (command == "t" && tlen == 3) {
  2353. if (absolute) {
  2354. x1 = inver.x(0, 0);
  2355. y1 = inver.y(0, 0);
  2356. x2 = inver.x(t[1], t[2]);
  2357. y2 = inver.y(t[1], t[2]);
  2358. m.translate(x2 - x1, y2 - y1);
  2359. } else {
  2360. m.translate(t[1], t[2]);
  2361. }
  2362. } else if (command == "r") {
  2363. if (tlen == 2) {
  2364. bb = bb || el.getBBox(1);
  2365. m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2366. deg += t[1];
  2367. } else if (tlen == 4) {
  2368. if (absolute) {
  2369. x2 = inver.x(t[2], t[3]);
  2370. y2 = inver.y(t[2], t[3]);
  2371. m.rotate(t[1], x2, y2);
  2372. } else {
  2373. m.rotate(t[1], t[2], t[3]);
  2374. }
  2375. deg += t[1];
  2376. }
  2377. } else if (command == "s") {
  2378. if (tlen == 2 || tlen == 3) {
  2379. bb = bb || el.getBBox(1);
  2380. m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  2381. sx *= t[1];
  2382. sy *= t[tlen - 1];
  2383. } else if (tlen == 5) {
  2384. if (absolute) {
  2385. x2 = inver.x(t[3], t[4]);
  2386. y2 = inver.y(t[3], t[4]);
  2387. m.scale(t[1], t[2], x2, y2);
  2388. } else {
  2389. m.scale(t[1], t[2], t[3], t[4]);
  2390. }
  2391. sx *= t[1];
  2392. sy *= t[2];
  2393. }
  2394. } else if (command == "m" && tlen == 7) {
  2395. m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
  2396. }
  2397. _.dirtyT = 1;
  2398. el.matrix = m;
  2399. }
  2400. }
  2401. /*\
  2402. * Element.matrix
  2403. [ property (object) ]
  2404. **
  2405. * Keeps @Matrix object, which represents element transformation
  2406. \*/
  2407. el.matrix = m;
  2408. _.sx = sx;
  2409. _.sy = sy;
  2410. _.deg = deg;
  2411. _.dx = dx = m.e;
  2412. _.dy = dy = m.f;
  2413. if (sx == 1 && sy == 1 && !deg && _.bbox) {
  2414. _.bbox.x += +dx;
  2415. _.bbox.y += +dy;
  2416. } else {
  2417. _.dirtyT = 1;
  2418. }
  2419. },
  2420. getEmpty = function (item) {
  2421. var l = item[0];
  2422. switch (l.toLowerCase()) {
  2423. case "t": return [l, 0, 0];
  2424. case "m": return [l, 1, 0, 0, 1, 0, 0];
  2425. case "r": if (item.length == 4) {
  2426. return [l, 0, item[2], item[3]];
  2427. } else {
  2428. return [l, 0];
  2429. }
  2430. case "s": if (item.length == 5) {
  2431. return [l, 1, 1, item[3], item[4]];
  2432. } else if (item.length == 3) {
  2433. return [l, 1, 1];
  2434. } else {
  2435. return [l, 1];
  2436. }
  2437. }
  2438. },
  2439. equaliseTransform = R._equaliseTransform = function (t1, t2) {
  2440. t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
  2441. t1 = R.parseTransformString(t1) || [];
  2442. t2 = R.parseTransformString(t2) || [];
  2443. var maxlength = mmax(t1.length, t2.length),
  2444. from = [],
  2445. to = [],
  2446. i = 0, j, jj,
  2447. tt1, tt2;
  2448. for (; i < maxlength; i++) {
  2449. tt1 = t1[i] || getEmpty(t2[i]);
  2450. tt2 = t2[i] || getEmpty(tt1);
  2451. if ((tt1[0] != tt2[0]) ||
  2452. (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
  2453. (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
  2454. ) {
  2455. return;
  2456. }
  2457. from[i] = [];
  2458. to[i] = [];
  2459. for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
  2460. j in tt1 && (from[i][j] = tt1[j]);
  2461. j in tt2 && (to[i][j] = tt2[j]);
  2462. }
  2463. }
  2464. return {
  2465. from: from,
  2466. to: to
  2467. };
  2468. };
  2469. R._getContainer = function (x, y, w, h) {
  2470. var container;
  2471. container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
  2472. if (container == null) {
  2473. return;
  2474. }
  2475. if (container.tagName) {
  2476. if (y == null) {
  2477. return {
  2478. container: container,
  2479. width: container.style.pixelWidth || container.offsetWidth,
  2480. height: container.style.pixelHeight || container.offsetHeight
  2481. };
  2482. } else {
  2483. return {
  2484. container: container,
  2485. width: y,
  2486. height: w
  2487. };
  2488. }
  2489. }
  2490. return {
  2491. container: 1,
  2492. x: x,
  2493. y: y,
  2494. width: w,
  2495. height: h
  2496. };
  2497. };
  2498. /*\
  2499. * Raphael.pathToRelative
  2500. [ method ]
  2501. **
  2502. * Utility method
  2503. **
  2504. * Converts path to relative form
  2505. > Parameters
  2506. - pathString (string|array) path string or array of segments
  2507. = (array) array of segments.
  2508. \*/
  2509. R.pathToRelative = pathToRelative;
  2510. R._engine = {};
  2511. /*\
  2512. * Raphael.path2curve
  2513. [ method ]
  2514. **
  2515. * Utility method
  2516. **
  2517. * Converts path to a new path where all segments are cubic bezier curves.
  2518. > Parameters
  2519. - pathString (string|array) path string or array of segments
  2520. = (array) array of segments.
  2521. \*/
  2522. R.path2curve = path2curve;
  2523. /*\
  2524. * Raphael.matrix
  2525. [ method ]
  2526. **
  2527. * Utility method
  2528. **
  2529. * Returns matrix based on given parameters.
  2530. > Parameters
  2531. - a (number)
  2532. - b (number)
  2533. - c (number)
  2534. - d (number)
  2535. - e (number)
  2536. - f (number)
  2537. = (object) @Matrix
  2538. \*/
  2539. R.matrix = function (a, b, c, d, e, f) {
  2540. return new Matrix(a, b, c, d, e, f);
  2541. };
  2542. function Matrix(a, b, c, d, e, f) {
  2543. if (a != null) {
  2544. this.a = +a;
  2545. this.b = +b;
  2546. this.c = +c;
  2547. this.d = +d;
  2548. this.e = +e;
  2549. this.f = +f;
  2550. } else {
  2551. this.a = 1;
  2552. this.b = 0;
  2553. this.c = 0;
  2554. this.d = 1;
  2555. this.e = 0;
  2556. this.f = 0;
  2557. }
  2558. }
  2559. (function (matrixproto) {
  2560. /*\
  2561. * Matrix.add
  2562. [ method ]
  2563. **
  2564. * Adds given matrix to existing one.
  2565. > Parameters
  2566. - a (number)
  2567. - b (number)
  2568. - c (number)
  2569. - d (number)
  2570. - e (number)
  2571. - f (number)
  2572. or
  2573. - matrix (object) @Matrix
  2574. \*/
  2575. matrixproto.add = function (a, b, c, d, e, f) {
  2576. var out = [[], [], []],
  2577. m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
  2578. matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
  2579. x, y, z, res;
  2580. if (a && a instanceof Matrix) {
  2581. matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
  2582. }
  2583. for (x = 0; x < 3; x++) {
  2584. for (y = 0; y < 3; y++) {
  2585. res = 0;
  2586. for (z = 0; z < 3; z++) {
  2587. res += m[x][z] * matrix[z][y];
  2588. }
  2589. out[x][y] = res;
  2590. }
  2591. }
  2592. this.a = out[0][0];
  2593. this.b = out[1][0];
  2594. this.c = out[0][1];
  2595. this.d = out[1][1];
  2596. this.e = out[0][2];
  2597. this.f = out[1][2];
  2598. };
  2599. /*\
  2600. * Matrix.invert
  2601. [ method ]
  2602. **
  2603. * Returns inverted version of the matrix
  2604. = (object) @Matrix
  2605. \*/
  2606. matrixproto.invert = function () {
  2607. var me = this,
  2608. x = me.a * me.d - me.b * me.c;
  2609. return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x);
  2610. };
  2611. /*\
  2612. * Matrix.clone
  2613. [ method ]
  2614. **
  2615. * Returns copy of the matrix
  2616. = (object) @Matrix
  2617. \*/
  2618. matrixproto.clone = function () {
  2619. return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
  2620. };
  2621. /*\
  2622. * Matrix.translate
  2623. [ method ]
  2624. **
  2625. * Translate the matrix
  2626. > Parameters
  2627. - x (number)
  2628. - y (number)
  2629. \*/
  2630. matrixproto.translate = function (x, y) {
  2631. this.add(1, 0, 0, 1, x, y);
  2632. };
  2633. /*\
  2634. * Matrix.scale
  2635. [ method ]
  2636. **
  2637. * Scales the matrix
  2638. > Parameters
  2639. - x (number)
  2640. - y (number) #optional
  2641. - cx (number) #optional
  2642. - cy (number) #optional
  2643. \*/
  2644. matrixproto.scale = function (x, y, cx, cy) {
  2645. y == null && (y = x);
  2646. (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
  2647. this.add(x, 0, 0, y, 0, 0);
  2648. (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
  2649. };
  2650. /*\
  2651. * Matrix.rotate
  2652. [ method ]
  2653. **
  2654. * Rotates the matrix
  2655. > Parameters
  2656. - a (number)
  2657. - x (number)
  2658. - y (number)
  2659. \*/
  2660. matrixproto.rotate = function (a, x, y) {
  2661. a = R.rad(a);
  2662. x = x || 0;
  2663. y = y || 0;
  2664. var cos = +math.cos(a).toFixed(9),
  2665. sin = +math.sin(a).toFixed(9);
  2666. this.add(cos, sin, -sin, cos, x, y);
  2667. this.add(1, 0, 0, 1, -x, -y);
  2668. };
  2669. /*\
  2670. * Matrix.x
  2671. [ method ]
  2672. **
  2673. * Return x coordinate for given point after transformation described by the matrix. See also @Matrix.y
  2674. > Parameters
  2675. - x (number)
  2676. - y (number)
  2677. = (number) x
  2678. \*/
  2679. matrixproto.x = function (x, y) {
  2680. return x * this.a + y * this.c + this.e;
  2681. };
  2682. /*\
  2683. * Matrix.y
  2684. [ method ]
  2685. **
  2686. * Return y coordinate for given point after transformation described by the matrix. See also @Matrix.x
  2687. > Parameters
  2688. - x (number)
  2689. - y (number)
  2690. = (number) y
  2691. \*/
  2692. matrixproto.y = function (x, y) {
  2693. return x * this.b + y * this.d + this.f;
  2694. };
  2695. matrixproto.get = function (i) {
  2696. return +this[Str.fromCharCode(97 + i)].toFixed(4);
  2697. };
  2698. matrixproto.toString = function () {
  2699. return R.svg ?
  2700. "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
  2701. [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
  2702. };
  2703. matrixproto.toFilter = function () {
  2704. return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
  2705. ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
  2706. ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
  2707. };
  2708. matrixproto.offset = function () {
  2709. return [this.e.toFixed(4), this.f.toFixed(4)];
  2710. };
  2711. function norm(a) {
  2712. return a[0] * a[0] + a[1] * a[1];
  2713. }
  2714. function normalize(a) {
  2715. var mag = math.sqrt(norm(a));
  2716. a[0] && (a[0] /= mag);
  2717. a[1] && (a[1] /= mag);
  2718. }
  2719. /*\
  2720. * Matrix.split
  2721. [ method ]
  2722. **
  2723. * Splits matrix into primitive transformations
  2724. = (object) in format:
  2725. o dx (number) translation by x
  2726. o dy (number) translation by y
  2727. o scalex (number) scale by x
  2728. o scaley (number) scale by y
  2729. o shear (number) shear
  2730. o rotate (number) rotation in deg
  2731. o isSimple (boolean) could it be represented via simple transformations
  2732. \*/
  2733. matrixproto.split = function () {
  2734. var out = {};
  2735. // translation
  2736. out.dx = this.e;
  2737. out.dy = this.f;
  2738. // scale and shear
  2739. var row = [[this.a, this.c], [this.b, this.d]];
  2740. out.scalex = math.sqrt(norm(row[0]));
  2741. normalize(row[0]);
  2742. out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
  2743. row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
  2744. out.scaley = math.sqrt(norm(row[1]));
  2745. normalize(row[1]);
  2746. out.shear /= out.scaley;
  2747. // rotation
  2748. var sin = -row[0][1],
  2749. cos = row[1][1];
  2750. if (cos < 0) {
  2751. out.rotate = R.deg(math.acos(cos));
  2752. if (sin < 0) {
  2753. out.rotate = 360 - out.rotate;
  2754. }
  2755. } else {
  2756. out.rotate = R.deg(math.asin(sin));
  2757. }
  2758. out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
  2759. out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
  2760. out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
  2761. return out;
  2762. };
  2763. /*\
  2764. * Matrix.toTransformString
  2765. [ method ]
  2766. **
  2767. * Return transform string that represents given matrix
  2768. = (string) transform string
  2769. \*/
  2770. matrixproto.toTransformString = function (shorter) {
  2771. var s = shorter || this[split]();
  2772. if (s.isSimple) {
  2773. s.scalex = +s.scalex.toFixed(4);
  2774. s.scaley = +s.scaley.toFixed(4);
  2775. s.rotate = +s.rotate.toFixed(4);
  2776. return (s.dx || s.dy ? "t" + [s.dx, s.dy] : E) +
  2777. (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
  2778. (s.rotate ? "r" + [s.rotate, 0, 0] : E);
  2779. } else {
  2780. return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
  2781. }
  2782. };
  2783. })(Matrix.prototype);
  2784. var preventDefault = function () {
  2785. this.returnValue = false;
  2786. },
  2787. preventTouch = function () {
  2788. return this.originalEvent.preventDefault();
  2789. },
  2790. stopPropagation = function () {
  2791. this.cancelBubble = true;
  2792. },
  2793. stopTouch = function () {
  2794. return this.originalEvent.stopPropagation();
  2795. },
  2796. getEventPosition = function (e) {
  2797. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  2798. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
  2799. return {
  2800. x: e.clientX + scrollX,
  2801. y: e.clientY + scrollY
  2802. };
  2803. },
  2804. addEvent = (function () {
  2805. if (g.doc.addEventListener) {
  2806. return function (obj, type, fn, element) {
  2807. var f = function (e) {
  2808. var pos = getEventPosition(e);
  2809. return fn.call(element, e, pos.x, pos.y);
  2810. };
  2811. obj.addEventListener(type, f, false);
  2812. if (supportsTouch && touchMap[type]) {
  2813. var _f = function (e) {
  2814. var pos = getEventPosition(e),
  2815. olde = e;
  2816. for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
  2817. if (e.targetTouches[i].target == obj) {
  2818. e = e.targetTouches[i];
  2819. e.originalEvent = olde;
  2820. e.preventDefault = preventTouch;
  2821. e.stopPropagation = stopTouch;
  2822. break;
  2823. }
  2824. }
  2825. return fn.call(element, e, pos.x, pos.y);
  2826. };
  2827. obj.addEventListener(touchMap[type], _f, false);
  2828. }
  2829. return function () {
  2830. obj.removeEventListener(type, f, false);
  2831. if (supportsTouch && touchMap[type])
  2832. obj.removeEventListener(touchMap[type], _f, false);
  2833. return true;
  2834. };
  2835. };
  2836. } else if (g.doc.attachEvent) {
  2837. return function (obj, type, fn, element) {
  2838. var f = function (e) {
  2839. e = e || g.win.event;
  2840. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  2841. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  2842. x = e.clientX + scrollX,
  2843. y = e.clientY + scrollY;
  2844. e.preventDefault = e.preventDefault || preventDefault;
  2845. e.stopPropagation = e.stopPropagation || stopPropagation;
  2846. return fn.call(element, e, x, y);
  2847. };
  2848. obj.attachEvent("on" + type, f);
  2849. var detacher = function () {
  2850. obj.detachEvent("on" + type, f);
  2851. return true;
  2852. };
  2853. return detacher;
  2854. };
  2855. }
  2856. })(),
  2857. drag = [],
  2858. dragMove = function (e) {
  2859. var x = e.clientX,
  2860. y = e.clientY,
  2861. scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  2862. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  2863. dragi,
  2864. j = drag.length;
  2865. while (j--) {
  2866. dragi = drag[j];
  2867. if (supportsTouch && e.touches) {
  2868. var i = e.touches.length,
  2869. touch;
  2870. while (i--) {
  2871. touch = e.touches[i];
  2872. if (touch.identifier == dragi.el._drag.id) {
  2873. x = touch.clientX;
  2874. y = touch.clientY;
  2875. (e.originalEvent ? e.originalEvent : e).preventDefault();
  2876. break;
  2877. }
  2878. }
  2879. } else {
  2880. e.preventDefault();
  2881. }
  2882. var node = dragi.el.node,
  2883. o,
  2884. next = node.nextSibling,
  2885. parent = node.parentNode,
  2886. display = node.style.display;
  2887. g.win.opera && parent.removeChild(node);
  2888. node.style.display = "none";
  2889. o = dragi.el.paper.getElementByPoint(x, y);
  2890. node.style.display = display;
  2891. g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
  2892. o && eve("raphael.drag.over." + dragi.el.id, dragi.el, o);
  2893. x += scrollX;
  2894. y += scrollY;
  2895. eve("raphael.drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
  2896. }
  2897. },
  2898. dragUp = function (e) {
  2899. R.unmousemove(dragMove).unmouseup(dragUp);
  2900. var i = drag.length,
  2901. dragi;
  2902. while (i--) {
  2903. dragi = drag[i];
  2904. dragi.el._drag = {};
  2905. eve("raphael.drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
  2906. }
  2907. drag = [];
  2908. },
  2909. /*\
  2910. * Raphael.el
  2911. [ property (object) ]
  2912. **
  2913. * You can add your own method to elements. This is useful when you want to hack default functionality or
  2914. * want to wrap some common transformation or attributes in one method. In difference to canvas methods,
  2915. * you can redefine element method at any time. Expending element methods wouldn’t affect set.
  2916. > Usage
  2917. | Raphael.el.red = function () {
  2918. | this.attr({fill: "#f00"});
  2919. | };
  2920. | // then use it
  2921. | paper.circle(100, 100, 20).red();
  2922. \*/
  2923. elproto = R.el = {};
  2924. /*\
  2925. * Element.click
  2926. [ method ]
  2927. **
  2928. * Adds event handler for click for the element.
  2929. > Parameters
  2930. - handler (function) handler for the event
  2931. = (object) @Element
  2932. \*/
  2933. /*\
  2934. * Element.unclick
  2935. [ method ]
  2936. **
  2937. * Removes event handler for click for the element.
  2938. > Parameters
  2939. - handler (function) #optional handler for the event
  2940. = (object) @Element
  2941. \*/
  2942. /*\
  2943. * Element.dblclick
  2944. [ method ]
  2945. **
  2946. * Adds event handler for double click for the element.
  2947. > Parameters
  2948. - handler (function) handler for the event
  2949. = (object) @Element
  2950. \*/
  2951. /*\
  2952. * Element.undblclick
  2953. [ method ]
  2954. **
  2955. * Removes event handler for double click for the element.
  2956. > Parameters
  2957. - handler (function) #optional handler for the event
  2958. = (object) @Element
  2959. \*/
  2960. /*\
  2961. * Element.mousedown
  2962. [ method ]
  2963. **
  2964. * Adds event handler for mousedown for the element.
  2965. > Parameters
  2966. - handler (function) handler for the event
  2967. = (object) @Element
  2968. \*/
  2969. /*\
  2970. * Element.unmousedown
  2971. [ method ]
  2972. **
  2973. * Removes event handler for mousedown for the element.
  2974. > Parameters
  2975. - handler (function) #optional handler for the event
  2976. = (object) @Element
  2977. \*/
  2978. /*\
  2979. * Element.mousemove
  2980. [ method ]
  2981. **
  2982. * Adds event handler for mousemove for the element.
  2983. > Parameters
  2984. - handler (function) handler for the event
  2985. = (object) @Element
  2986. \*/
  2987. /*\
  2988. * Element.unmousemove
  2989. [ method ]
  2990. **
  2991. * Removes event handler for mousemove for the element.
  2992. > Parameters
  2993. - handler (function) #optional handler for the event
  2994. = (object) @Element
  2995. \*/
  2996. /*\
  2997. * Element.mouseout
  2998. [ method ]
  2999. **
  3000. * Adds event handler for mouseout for the element.
  3001. > Parameters
  3002. - handler (function) handler for the event
  3003. = (object) @Element
  3004. \*/
  3005. /*\
  3006. * Element.unmouseout
  3007. [ method ]
  3008. **
  3009. * Removes event handler for mouseout for the element.
  3010. > Parameters
  3011. - handler (function) #optional handler for the event
  3012. = (object) @Element
  3013. \*/
  3014. /*\
  3015. * Element.mouseover
  3016. [ method ]
  3017. **
  3018. * Adds event handler for mouseover for the element.
  3019. > Parameters
  3020. - handler (function) handler for the event
  3021. = (object) @Element
  3022. \*/
  3023. /*\
  3024. * Element.unmouseover
  3025. [ method ]
  3026. **
  3027. * Removes event handler for mouseover for the element.
  3028. > Parameters
  3029. - handler (function) #optional handler for the event
  3030. = (object) @Element
  3031. \*/
  3032. /*\
  3033. * Element.mouseup
  3034. [ method ]
  3035. **
  3036. * Adds event handler for mouseup for the element.
  3037. > Parameters
  3038. - handler (function) handler for the event
  3039. = (object) @Element
  3040. \*/
  3041. /*\
  3042. * Element.unmouseup
  3043. [ method ]
  3044. **
  3045. * Removes event handler for mouseup for the element.
  3046. > Parameters
  3047. - handler (function) #optional handler for the event
  3048. = (object) @Element
  3049. \*/
  3050. /*\
  3051. * Element.touchstart
  3052. [ method ]
  3053. **
  3054. * Adds event handler for touchstart for the element.
  3055. > Parameters
  3056. - handler (function) handler for the event
  3057. = (object) @Element
  3058. \*/
  3059. /*\
  3060. * Element.untouchstart
  3061. [ method ]
  3062. **
  3063. * Removes event handler for touchstart for the element.
  3064. > Parameters
  3065. - handler (function) #optional handler for the event
  3066. = (object) @Element
  3067. \*/
  3068. /*\
  3069. * Element.touchmove
  3070. [ method ]
  3071. **
  3072. * Adds event handler for touchmove for the element.
  3073. > Parameters
  3074. - handler (function) handler for the event
  3075. = (object) @Element
  3076. \*/
  3077. /*\
  3078. * Element.untouchmove
  3079. [ method ]
  3080. **
  3081. * Removes event handler for touchmove for the element.
  3082. > Parameters
  3083. - handler (function) #optional handler for the event
  3084. = (object) @Element
  3085. \*/
  3086. /*\
  3087. * Element.touchend
  3088. [ method ]
  3089. **
  3090. * Adds event handler for touchend for the element.
  3091. > Parameters
  3092. - handler (function) handler for the event
  3093. = (object) @Element
  3094. \*/
  3095. /*\
  3096. * Element.untouchend
  3097. [ method ]
  3098. **
  3099. * Removes event handler for touchend for the element.
  3100. > Parameters
  3101. - handler (function) #optional handler for the event
  3102. = (object) @Element
  3103. \*/
  3104. /*\
  3105. * Element.touchcancel
  3106. [ method ]
  3107. **
  3108. * Adds event handler for touchcancel for the element.
  3109. > Parameters
  3110. - handler (function) handler for the event
  3111. = (object) @Element
  3112. \*/
  3113. /*\
  3114. * Element.untouchcancel
  3115. [ method ]
  3116. **
  3117. * Removes event handler for touchcancel for the element.
  3118. > Parameters
  3119. - handler (function) #optional handler for the event
  3120. = (object) @Element
  3121. \*/
  3122. for (var i = events.length; i--;) {
  3123. (function (eventName) {
  3124. R[eventName] = elproto[eventName] = function (fn, scope) {
  3125. if (R.is(fn, "function")) {
  3126. this.events = this.events || [];
  3127. this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
  3128. }
  3129. return this;
  3130. };
  3131. R["un" + eventName] = elproto["un" + eventName] = function (fn) {
  3132. var events = this.events || [],
  3133. l = events.length;
  3134. while (l--){
  3135. if (events[l].name == eventName && (R.is(fn, "undefined") || events[l].f == fn)) {
  3136. events[l].unbind();
  3137. events.splice(l, 1);
  3138. !events.length && delete this.events;
  3139. }
  3140. }
  3141. return this;
  3142. };
  3143. })(events[i]);
  3144. }
  3145. /*\
  3146. * Element.data
  3147. [ method ]
  3148. **
  3149. * Adds or retrieves given value associated with given key.
  3150. **
  3151. * See also @Element.removeData
  3152. > Parameters
  3153. - key (string) key to store data
  3154. - value (any) #optional value to store
  3155. = (object) @Element
  3156. * or, if value is not specified:
  3157. = (any) value
  3158. * or, if key and value are not specified:
  3159. = (object) Key/value pairs for all the data associated with the element.
  3160. > Usage
  3161. | for (var i = 0, i < 5, i++) {
  3162. | paper.circle(10 + 15 * i, 10, 10)
  3163. | .attr({fill: "#000"})
  3164. | .data("i", i)
  3165. | .click(function () {
  3166. | alert(this.data("i"));
  3167. | });
  3168. | }
  3169. \*/
  3170. elproto.data = function (key, value) {
  3171. var data = eldata[this.id] = eldata[this.id] || {};
  3172. if (arguments.length == 0) {
  3173. return data;
  3174. }
  3175. if (arguments.length == 1) {
  3176. if (R.is(key, "object")) {
  3177. for (var i in key) if (key[has](i)) {
  3178. this.data(i, key[i]);
  3179. }
  3180. return this;
  3181. }
  3182. eve("raphael.data.get." + this.id, this, data[key], key);
  3183. return data[key];
  3184. }
  3185. data[key] = value;
  3186. eve("raphael.data.set." + this.id, this, value, key);
  3187. return this;
  3188. };
  3189. /*\
  3190. * Element.removeData
  3191. [ method ]
  3192. **
  3193. * Removes value associated with an element by given key.
  3194. * If key is not provided, removes all the data of the element.
  3195. > Parameters
  3196. - key (string) #optional key
  3197. = (object) @Element
  3198. \*/
  3199. elproto.removeData = function (key) {
  3200. if (key == null) {
  3201. delete eldata[this.id];
  3202. } else {
  3203. eldata[this.id] && delete eldata[this.id][key];
  3204. }
  3205. return this;
  3206. };
  3207. /*\
  3208. * Element.getData
  3209. [ method ]
  3210. **
  3211. * Retrieves the element data
  3212. = (object) data
  3213. \*/
  3214. elproto.getData = function () {
  3215. return clone(eldata[this.id] || {});
  3216. };
  3217. /*\
  3218. * Element.hover
  3219. [ method ]
  3220. **
  3221. * Adds event handlers for hover for the element.
  3222. > Parameters
  3223. - f_in (function) handler for hover in
  3224. - f_out (function) handler for hover out
  3225. - icontext (object) #optional context for hover in handler
  3226. - ocontext (object) #optional context for hover out handler
  3227. = (object) @Element
  3228. \*/
  3229. elproto.hover = function (f_in, f_out, scope_in, scope_out) {
  3230. return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
  3231. };
  3232. /*\
  3233. * Element.unhover
  3234. [ method ]
  3235. **
  3236. * Removes event handlers for hover for the element.
  3237. > Parameters
  3238. - f_in (function) handler for hover in
  3239. - f_out (function) handler for hover out
  3240. = (object) @Element
  3241. \*/
  3242. elproto.unhover = function (f_in, f_out) {
  3243. return this.unmouseover(f_in).unmouseout(f_out);
  3244. };
  3245. var draggable = [];
  3246. /*\
  3247. * Element.drag
  3248. [ method ]
  3249. **
  3250. * Adds event handlers for drag of the element.
  3251. > Parameters
  3252. - onmove (function) handler for moving
  3253. - onstart (function) handler for drag start
  3254. - onend (function) handler for drag end
  3255. - mcontext (object) #optional context for moving handler
  3256. - scontext (object) #optional context for drag start handler
  3257. - econtext (object) #optional context for drag end handler
  3258. * Additionally following `drag` events will be triggered: `drag.start.<id>` on start,
  3259. * `drag.end.<id>` on end and `drag.move.<id>` on every move. When element will be dragged over another element
  3260. * `drag.over.<id>` will be fired as well.
  3261. *
  3262. * Start event and start handler will be called in specified context or in context of the element with following parameters:
  3263. o x (number) x position of the mouse
  3264. o y (number) y position of the mouse
  3265. o event (object) DOM event object
  3266. * Move event and move handler will be called in specified context or in context of the element with following parameters:
  3267. o dx (number) shift by x from the start point
  3268. o dy (number) shift by y from the start point
  3269. o x (number) x position of the mouse
  3270. o y (number) y position of the mouse
  3271. o event (object) DOM event object
  3272. * End event and end handler will be called in specified context or in context of the element with following parameters:
  3273. o event (object) DOM event object
  3274. = (object) @Element
  3275. \*/
  3276. elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
  3277. function start(e) {
  3278. (e.originalEvent || e).preventDefault();
  3279. var x = e.clientX,
  3280. y = e.clientY,
  3281. scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  3282. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
  3283. this._drag.id = e.identifier;
  3284. if (supportsTouch && e.touches) {
  3285. var i = e.touches.length, touch;
  3286. while (i--) {
  3287. touch = e.touches[i];
  3288. this._drag.id = touch.identifier;
  3289. if (touch.identifier == this._drag.id) {
  3290. x = touch.clientX;
  3291. y = touch.clientY;
  3292. break;
  3293. }
  3294. }
  3295. }
  3296. this._drag.x = x + scrollX;
  3297. this._drag.y = y + scrollY;
  3298. !drag.length && R.mousemove(dragMove).mouseup(dragUp);
  3299. drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
  3300. onstart && eve.on("raphael.drag.start." + this.id, onstart);
  3301. onmove && eve.on("raphael.drag.move." + this.id, onmove);
  3302. onend && eve.on("raphael.drag.end." + this.id, onend);
  3303. eve("raphael.drag.start." + this.id, start_scope || move_scope || this, this._drag.x, this._drag.y, e);
  3304. }
  3305. this._drag = {};
  3306. draggable.push({el: this, start: start});
  3307. this.mousedown(start);
  3308. return this;
  3309. };
  3310. /*\
  3311. * Element.onDragOver
  3312. [ method ]
  3313. **
  3314. * Shortcut for assigning event handler for `drag.over.<id>` event, where id is id of the element (see @Element.id).
  3315. > Parameters
  3316. - f (function) handler for event, first argument would be the element you are dragging over
  3317. \*/
  3318. elproto.onDragOver = function (f) {
  3319. f ? eve.on("raphael.drag.over." + this.id, f) : eve.unbind("raphael.drag.over." + this.id);
  3320. };
  3321. /*\
  3322. * Element.undrag
  3323. [ method ]
  3324. **
  3325. * Removes all drag event handlers from given element.
  3326. \*/
  3327. elproto.undrag = function () {
  3328. var i = draggable.length;
  3329. while (i--) if (draggable[i].el == this) {
  3330. this.unmousedown(draggable[i].start);
  3331. draggable.splice(i, 1);
  3332. eve.unbind("raphael.drag.*." + this.id);
  3333. }
  3334. !draggable.length && R.unmousemove(dragMove).unmouseup(dragUp);
  3335. drag = [];
  3336. };
  3337. /*\
  3338. * Paper.circle
  3339. [ method ]
  3340. **
  3341. * Draws a circle.
  3342. **
  3343. > Parameters
  3344. **
  3345. - x (number) x coordinate of the centre
  3346. - y (number) y coordinate of the centre
  3347. - r (number) radius
  3348. = (object) Raphaël element object with type “circle”
  3349. **
  3350. > Usage
  3351. | var c = paper.circle(50, 50, 40);
  3352. \*/
  3353. paperproto.circle = function (x, y, r) {
  3354. var out = R._engine.circle(this, x || 0, y || 0, r || 0);
  3355. this.__set__ && this.__set__.push(out);
  3356. return out;
  3357. };
  3358. /*\
  3359. * Paper.rect
  3360. [ method ]
  3361. *
  3362. * Draws a rectangle.
  3363. **
  3364. > Parameters
  3365. **
  3366. - x (number) x coordinate of the top left corner
  3367. - y (number) y coordinate of the top left corner
  3368. - width (number) width
  3369. - height (number) height
  3370. - r (number) #optional radius for rounded corners, default is 0
  3371. = (object) Raphaël element object with type “rect”
  3372. **
  3373. > Usage
  3374. | // regular rectangle
  3375. | var c = paper.rect(10, 10, 50, 50);
  3376. | // rectangle with rounded corners
  3377. | var c = paper.rect(40, 40, 50, 50, 10);
  3378. \*/
  3379. paperproto.rect = function (x, y, w, h, r) {
  3380. var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
  3381. this.__set__ && this.__set__.push(out);
  3382. return out;
  3383. };
  3384. /*\
  3385. * Paper.ellipse
  3386. [ method ]
  3387. **
  3388. * Draws an ellipse.
  3389. **
  3390. > Parameters
  3391. **
  3392. - x (number) x coordinate of the centre
  3393. - y (number) y coordinate of the centre
  3394. - rx (number) horizontal radius
  3395. - ry (number) vertical radius
  3396. = (object) Raphaël element object with type “ellipse”
  3397. **
  3398. > Usage
  3399. | var c = paper.ellipse(50, 50, 40, 20);
  3400. \*/
  3401. paperproto.ellipse = function (x, y, rx, ry) {
  3402. var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
  3403. this.__set__ && this.__set__.push(out);
  3404. return out;
  3405. };
  3406. /*\
  3407. * Paper.path
  3408. [ method ]
  3409. **
  3410. * Creates a path element by given path data string.
  3411. > Parameters
  3412. - pathString (string) #optional path string in SVG format.
  3413. * Path string consists of one-letter commands, followed by comma seprarated arguments in numercal form. Example:
  3414. | "M10,20L30,40"
  3415. * Here we can see two commands: “M”, with arguments `(10, 20)` and “L” with arguments `(30, 40)`. Upper case letter mean command is absolute, lower case—relative.
  3416. *
  3417. # <p>Here is short list of commands available, for more details see <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path's data attribute's format are described in the SVG specification.">SVG path string format</a>.</p>
  3418. # <table><thead><tr><th>Command</th><th>Name</th><th>Parameters</th></tr></thead><tbody>
  3419. # <tr><td>M</td><td>moveto</td><td>(x y)+</td></tr>
  3420. # <tr><td>Z</td><td>closepath</td><td>(none)</td></tr>
  3421. # <tr><td>L</td><td>lineto</td><td>(x y)+</td></tr>
  3422. # <tr><td>H</td><td>horizontal lineto</td><td>x+</td></tr>
  3423. # <tr><td>V</td><td>vertical lineto</td><td>y+</td></tr>
  3424. # <tr><td>C</td><td>curveto</td><td>(x1 y1 x2 y2 x y)+</td></tr>
  3425. # <tr><td>S</td><td>smooth curveto</td><td>(x2 y2 x y)+</td></tr>
  3426. # <tr><td>Q</td><td>quadratic Bézier curveto</td><td>(x1 y1 x y)+</td></tr>
  3427. # <tr><td>T</td><td>smooth quadratic Bézier curveto</td><td>(x y)+</td></tr>
  3428. # <tr><td>A</td><td>elliptical arc</td><td>(rx ry x-axis-rotation large-arc-flag sweep-flag x y)+</td></tr>
  3429. # <tr><td>R</td><td><a href="http://en.wikipedia.org/wiki/Catmull–Rom_spline#Catmull.E2.80.93Rom_spline">Catmull-Rom curveto</a>*</td><td>x1 y1 (x y)+</td></tr></tbody></table>
  3430. * * “Catmull-Rom curveto” is a not standard SVG command and added in 2.0 to make life easier.
  3431. * Note: there is a special case when path consist of just three commands: “M10,10R…z”. In this case path will smoothly connects to its beginning.
  3432. > Usage
  3433. | var c = paper.path("M10 10L90 90");
  3434. | // draw a diagonal line:
  3435. | // move to 10,10, line to 90,90
  3436. * For example of path strings, check out these icons: http://raphaeljs.com/icons/
  3437. \*/
  3438. paperproto.path = function (pathString) {
  3439. pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
  3440. var out = R._engine.path(R.format[apply](R, arguments), this);
  3441. this.__set__ && this.__set__.push(out);
  3442. return out;
  3443. };
  3444. /*\
  3445. * Paper.image
  3446. [ method ]
  3447. **
  3448. * Embeds an image into the surface.
  3449. **
  3450. > Parameters
  3451. **
  3452. - src (string) URI of the source image
  3453. - x (number) x coordinate position
  3454. - y (number) y coordinate position
  3455. - width (number) width of the image
  3456. - height (number) height of the image
  3457. = (object) Raphaël element object with type “image”
  3458. **
  3459. > Usage
  3460. | var c = paper.image("apple.png", 10, 10, 80, 80);
  3461. \*/
  3462. paperproto.image = function (src, x, y, w, h) {
  3463. var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
  3464. this.__set__ && this.__set__.push(out);
  3465. return out;
  3466. };
  3467. /*\
  3468. * Paper.text
  3469. [ method ]
  3470. **
  3471. * Draws a text string. If you need line breaks, put “\n” in the string.
  3472. **
  3473. > Parameters
  3474. **
  3475. - x (number) x coordinate position
  3476. - y (number) y coordinate position
  3477. - text (string) The text string to draw
  3478. = (object) Raphaël element object with type “text”
  3479. **
  3480. > Usage
  3481. | var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");
  3482. \*/
  3483. paperproto.text = function (x, y, text) {
  3484. var out = R._engine.text(this, x || 0, y || 0, Str(text));
  3485. this.__set__ && this.__set__.push(out);
  3486. return out;
  3487. };
  3488. /*\
  3489. * Paper.set
  3490. [ method ]
  3491. **
  3492. * Creates array-like object to keep and operate several elements at once.
  3493. * Warning: it doesn’t create any elements for itself in the page, it just groups existing elements.
  3494. * Sets act as pseudo elements — all methods available to an element can be used on a set.
  3495. = (object) array-like object that represents set of elements
  3496. **
  3497. > Usage
  3498. | var st = paper.set();
  3499. | st.push(
  3500. | paper.circle(10, 10, 5),
  3501. | paper.circle(30, 10, 5)
  3502. | );
  3503. | st.attr({fill: "red"}); // changes the fill of both circles
  3504. \*/
  3505. paperproto.set = function (itemsArray) {
  3506. !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
  3507. var out = new Set(itemsArray);
  3508. this.__set__ && this.__set__.push(out);
  3509. out["paper"] = this;
  3510. out["type"] = "set";
  3511. return out;
  3512. };
  3513. /*\
  3514. * Paper.setStart
  3515. [ method ]
  3516. **
  3517. * Creates @Paper.set. All elements that will be created after calling this method and before calling
  3518. * @Paper.setFinish will be added to the set.
  3519. **
  3520. > Usage
  3521. | paper.setStart();
  3522. | paper.circle(10, 10, 5),
  3523. | paper.circle(30, 10, 5)
  3524. | var st = paper.setFinish();
  3525. | st.attr({fill: "red"}); // changes the fill of both circles
  3526. \*/
  3527. paperproto.setStart = function (set) {
  3528. this.__set__ = set || this.set();
  3529. };
  3530. /*\
  3531. * Paper.setFinish
  3532. [ method ]
  3533. **
  3534. * See @Paper.setStart. This method finishes catching and returns resulting set.
  3535. **
  3536. = (object) set
  3537. \*/
  3538. paperproto.setFinish = function (set) {
  3539. var out = this.__set__;
  3540. delete this.__set__;
  3541. return out;
  3542. };
  3543. /*\
  3544. * Paper.getSize
  3545. [ method ]
  3546. **
  3547. * Obtains current paper actual size.
  3548. **
  3549. = (object)
  3550. \*/
  3551. paperproto.getSize = function () {
  3552. var container = this.canvas.parentNode;
  3553. return {
  3554. width: container.offsetWidth,
  3555. height: container.offsetHeight
  3556. };
  3557. };
  3558. /*\
  3559. * Paper.setSize
  3560. [ method ]
  3561. **
  3562. * If you need to change dimensions of the canvas call this method
  3563. **
  3564. > Parameters
  3565. **
  3566. - width (number) new width of the canvas
  3567. - height (number) new height of the canvas
  3568. \*/
  3569. paperproto.setSize = function (width, height) {
  3570. return R._engine.setSize.call(this, width, height);
  3571. };
  3572. /*\
  3573. * Paper.setViewBox
  3574. [ method ]
  3575. **
  3576. * Sets the view box of the paper. Practically it gives you ability to zoom and pan whole paper surface by
  3577. * specifying new boundaries.
  3578. **
  3579. > Parameters
  3580. **
  3581. - x (number) new x position, default is `0`
  3582. - y (number) new y position, default is `0`
  3583. - w (number) new width of the canvas
  3584. - h (number) new height of the canvas
  3585. - fit (boolean) `true` if you want graphics to fit into new boundary box
  3586. \*/
  3587. paperproto.setViewBox = function (x, y, w, h, fit) {
  3588. return R._engine.setViewBox.call(this, x, y, w, h, fit);
  3589. };
  3590. /*\
  3591. * Paper.top
  3592. [ property ]
  3593. **
  3594. * Points to the topmost element on the paper
  3595. \*/
  3596. /*\
  3597. * Paper.bottom
  3598. [ property ]
  3599. **
  3600. * Points to the bottom element on the paper
  3601. \*/
  3602. paperproto.top = paperproto.bottom = null;
  3603. /*\
  3604. * Paper.raphael
  3605. [ property ]
  3606. **
  3607. * Points to the @Raphael object/function
  3608. \*/
  3609. paperproto.raphael = R;
  3610. var getOffset = function (elem) {
  3611. var box = elem.getBoundingClientRect(),
  3612. doc = elem.ownerDocument,
  3613. body = doc.body,
  3614. docElem = doc.documentElement,
  3615. clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
  3616. top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
  3617. left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
  3618. return {
  3619. y: top,
  3620. x: left
  3621. };
  3622. };
  3623. /*\
  3624. * Paper.getElementByPoint
  3625. [ method ]
  3626. **
  3627. * Returns you topmost element under given point.
  3628. **
  3629. = (object) Raphaël element object
  3630. > Parameters
  3631. **
  3632. - x (number) x coordinate from the top left corner of the window
  3633. - y (number) y coordinate from the top left corner of the window
  3634. > Usage
  3635. | paper.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"});
  3636. \*/
  3637. paperproto.getElementByPoint = function (x, y) {
  3638. var paper = this,
  3639. svg = paper.canvas,
  3640. target = g.doc.elementFromPoint(x, y);
  3641. if (g.win.opera && target.tagName == "svg") {
  3642. var so = getOffset(svg),
  3643. sr = svg.createSVGRect();
  3644. sr.x = x - so.x;
  3645. sr.y = y - so.y;
  3646. sr.width = sr.height = 1;
  3647. var hits = svg.getIntersectionList(sr, null);
  3648. if (hits.length) {
  3649. target = hits[hits.length - 1];
  3650. }
  3651. }
  3652. if (!target) {
  3653. return null;
  3654. }
  3655. while (target.parentNode && target != svg.parentNode && !target.raphael) {
  3656. target = target.parentNode;
  3657. }
  3658. target == paper.canvas.parentNode && (target = svg);
  3659. target = target && target.raphael ? paper.getById(target.raphaelid) : null;
  3660. return target;
  3661. };
  3662. /*\
  3663. * Paper.getElementsByBBox
  3664. [ method ]
  3665. **
  3666. * Returns set of elements that have an intersecting bounding box
  3667. **
  3668. > Parameters
  3669. **
  3670. - bbox (object) bbox to check with
  3671. = (object) @Set
  3672. \*/
  3673. paperproto.getElementsByBBox = function (bbox) {
  3674. var set = this.set();
  3675. this.forEach(function (el) {
  3676. if (R.isBBoxIntersect(el.getBBox(), bbox)) {
  3677. set.push(el);
  3678. }
  3679. });
  3680. return set;
  3681. };
  3682. /*\
  3683. * Paper.getById
  3684. [ method ]
  3685. **
  3686. * Returns you element by its internal ID.
  3687. **
  3688. > Parameters
  3689. **
  3690. - id (number) id
  3691. = (object) Raphaël element object
  3692. \*/
  3693. paperproto.getById = function (id) {
  3694. var bot = this.bottom;
  3695. while (bot) {
  3696. if (bot.id == id) {
  3697. return bot;
  3698. }
  3699. bot = bot.next;
  3700. }
  3701. return null;
  3702. };
  3703. /*\
  3704. * Paper.forEach
  3705. [ method ]
  3706. **
  3707. * Executes given function for each element on the paper
  3708. *
  3709. * If callback function returns `false` it will stop loop running.
  3710. **
  3711. > Parameters
  3712. **
  3713. - callback (function) function to run
  3714. - thisArg (object) context object for the callback
  3715. = (object) Paper object
  3716. > Usage
  3717. | paper.forEach(function (el) {
  3718. | el.attr({ stroke: "blue" });
  3719. | });
  3720. \*/
  3721. paperproto.forEach = function (callback, thisArg) {
  3722. var bot = this.bottom;
  3723. while (bot) {
  3724. if (callback.call(thisArg, bot) === false) {
  3725. return this;
  3726. }
  3727. bot = bot.next;
  3728. }
  3729. return this;
  3730. };
  3731. /*\
  3732. * Paper.getElementsByPoint
  3733. [ method ]
  3734. **
  3735. * Returns set of elements that have common point inside
  3736. **
  3737. > Parameters
  3738. **
  3739. - x (number) x coordinate of the point
  3740. - y (number) y coordinate of the point
  3741. = (object) @Set
  3742. \*/
  3743. paperproto.getElementsByPoint = function (x, y) {
  3744. var set = this.set();
  3745. this.forEach(function (el) {
  3746. if (el.isPointInside(x, y)) {
  3747. set.push(el);
  3748. }
  3749. });
  3750. return set;
  3751. };
  3752. function x_y() {
  3753. return this.x + S + this.y;
  3754. }
  3755. function x_y_w_h() {
  3756. return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
  3757. }
  3758. /*\
  3759. * Element.isPointInside
  3760. [ method ]
  3761. **
  3762. * Determine if given point is inside this element’s shape
  3763. **
  3764. > Parameters
  3765. **
  3766. - x (number) x coordinate of the point
  3767. - y (number) y coordinate of the point
  3768. = (boolean) `true` if point inside the shape
  3769. \*/
  3770. elproto.isPointInside = function (x, y) {
  3771. var rp = this.realPath = getPath[this.type](this);
  3772. if (this.attr('transform') && this.attr('transform').length) {
  3773. rp = R.transformPath(rp, this.attr('transform'));
  3774. }
  3775. return R.isPointInsidePath(rp, x, y);
  3776. };
  3777. /*\
  3778. * Element.getBBox
  3779. [ method ]
  3780. **
  3781. * Return bounding box for a given element
  3782. **
  3783. > Parameters
  3784. **
  3785. - isWithoutTransform (boolean) flag, `true` if you want to have bounding box before transformations. Default is `false`.
  3786. = (object) Bounding box object:
  3787. o {
  3788. o x: (number) top left corner x
  3789. o y: (number) top left corner y
  3790. o x2: (number) bottom right corner x
  3791. o y2: (number) bottom right corner y
  3792. o width: (number) width
  3793. o height: (number) height
  3794. o }
  3795. \*/
  3796. elproto.getBBox = function (isWithoutTransform) {
  3797. if (this.removed) {
  3798. return {};
  3799. }
  3800. var _ = this._;
  3801. if (isWithoutTransform) {
  3802. if (_.dirty || !_.bboxwt) {
  3803. this.realPath = getPath[this.type](this);
  3804. _.bboxwt = pathDimensions(this.realPath);
  3805. _.bboxwt.toString = x_y_w_h;
  3806. _.dirty = 0;
  3807. }
  3808. return _.bboxwt;
  3809. }
  3810. if (_.dirty || _.dirtyT || !_.bbox) {
  3811. if (_.dirty || !this.realPath) {
  3812. _.bboxwt = 0;
  3813. this.realPath = getPath[this.type](this);
  3814. }
  3815. _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
  3816. _.bbox.toString = x_y_w_h;
  3817. _.dirty = _.dirtyT = 0;
  3818. }
  3819. return _.bbox;
  3820. };
  3821. /*\
  3822. * Element.clone
  3823. [ method ]
  3824. **
  3825. = (object) clone of a given element
  3826. **
  3827. \*/
  3828. elproto.clone = function () {
  3829. if (this.removed) {
  3830. return null;
  3831. }
  3832. var out = this.paper[this.type]().attr(this.attr());
  3833. this.__set__ && this.__set__.push(out);
  3834. return out;
  3835. };
  3836. /*\
  3837. * Element.glow
  3838. [ method ]
  3839. **
  3840. * Return set of elements that create glow-like effect around given element. See @Paper.set.
  3841. *
  3842. * Note: Glow is not connected to the element. If you change element attributes it won’t adjust itself.
  3843. **
  3844. > Parameters
  3845. **
  3846. - glow (object) #optional parameters object with all properties optional:
  3847. o {
  3848. o width (number) size of the glow, default is `10`
  3849. o fill (boolean) will it be filled, default is `false`
  3850. o opacity (number) opacity, default is `0.5`
  3851. o offsetx (number) horizontal offset, default is `0`
  3852. o offsety (number) vertical offset, default is `0`
  3853. o color (string) glow colour, default is `black`
  3854. o }
  3855. = (object) @Paper.set of elements that represents glow
  3856. \*/