raphael.js 310 KB

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