raphael.no-deps.js 297 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959
  1. // ┌───────────────────────────────────────────────────────────────────────────────────────────────────────┐ \\
  2. // │ Raphaël 2.2.0 - JavaScript Vector Library │ \\
  3. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  4. // │ Copyright © 2008-2016 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5. // │ Copyright © 2008-2016 Sencha Labs (http://sencha.com) │ \\
  6. // ├───────────────────────────────────────────────────────────────────────────────────────────────────────┤ \\
  7. // │ Licensed under the MIT (https://github.com/DmitryBaranovskiy/raphael/blob/master/license.txt) license.│ \\
  8. // └───────────────────────────────────────────────────────────────────────────────────────────────────────┘ \\
  9. (function webpackUniversalModuleDefinition(root, factory) {
  10. if(typeof exports === 'object' && typeof module === 'object')
  11. module.exports = factory(require("eve"));
  12. else if(typeof define === 'function' && define.amd)
  13. define("Raphael", ["eve"], factory);
  14. else if(typeof exports === 'object')
  15. exports["Raphael"] = factory(require("eve"));
  16. else
  17. root["Raphael"] = factory(root["eve"]);
  18. })(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
  19. return /******/ (function(modules) { // webpackBootstrap
  20. /******/ // The module cache
  21. /******/ var installedModules = {};
  22. /******/ // The require function
  23. /******/ function __webpack_require__(moduleId) {
  24. /******/ // Check if module is in cache
  25. /******/ if(installedModules[moduleId])
  26. /******/ return installedModules[moduleId].exports;
  27. /******/ // Create a new module (and put it into the cache)
  28. /******/ var module = installedModules[moduleId] = {
  29. /******/ exports: {},
  30. /******/ id: moduleId,
  31. /******/ loaded: false
  32. /******/ };
  33. /******/ // Execute the module function
  34. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  35. /******/ // Flag the module as loaded
  36. /******/ module.loaded = true;
  37. /******/ // Return the exports of the module
  38. /******/ return module.exports;
  39. /******/ }
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/ // expose the module cache
  43. /******/ __webpack_require__.c = installedModules;
  44. /******/ // __webpack_public_path__
  45. /******/ __webpack_require__.p = "";
  46. /******/ // Load entry module and return exports
  47. /******/ return __webpack_require__(0);
  48. /******/ })
  49. /************************************************************************/
  50. /******/ ([
  51. /* 0 */
  52. /***/ function(module, exports, __webpack_require__) {
  53. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// ┌────────────────────────────────────────────────────────────────────┐ \\
  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) {
  5407. module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
  5408. /***/ },
  5409. /* 3 */
  5410. /***/ function(module, exports, __webpack_require__) {
  5411. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// ┌─────────────────────────────────────────────────────────────────────┐ \\
  5412. // │ Raphaël @@VERSION - JavaScript Vector Library │ \\
  5413. // ├─────────────────────────────────────────────────────────────────────┤ \\
  5414. // │ SVG Module │ \\
  5415. // ├─────────────────────────────────────────────────────────────────────┤ \\
  5416. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5417. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  5418. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  5419. // └─────────────────────────────────────────────────────────────────────┘ \\
  5420. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1)], __WEBPACK_AMD_DEFINE_RESULT__ = function(R) {
  5421. if (R && !R.svg) {
  5422. return;
  5423. }
  5424. var has = "hasOwnProperty",
  5425. Str = String,
  5426. toFloat = parseFloat,
  5427. toInt = parseInt,
  5428. math = Math,
  5429. mmax = math.max,
  5430. abs = math.abs,
  5431. pow = math.pow,
  5432. separator = /[, ]+/,
  5433. eve = R.eve,
  5434. E = "",
  5435. S = " ";
  5436. var xlink = "http://www.w3.org/1999/xlink",
  5437. markers = {
  5438. block: "M5,0 0,2.5 5,5z",
  5439. classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
  5440. diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
  5441. open: "M6,1 1,3.5 6,6",
  5442. oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
  5443. },
  5444. markerCounter = {};
  5445. R.toString = function () {
  5446. return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
  5447. };
  5448. var $ = function (el, attr) {
  5449. if (attr) {
  5450. if (typeof el == "string") {
  5451. el = $(el);
  5452. }
  5453. for (var key in attr) if (attr[has](key)) {
  5454. if (key.substring(0, 6) == "xlink:") {
  5455. el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
  5456. } else {
  5457. el.setAttribute(key, Str(attr[key]));
  5458. }
  5459. }
  5460. } else {
  5461. el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
  5462. el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
  5463. }
  5464. return el;
  5465. },
  5466. addGradientFill = function (element, gradient) {
  5467. var type = "linear",
  5468. id = element.id + gradient,
  5469. fx = .5, fy = .5,
  5470. o = element.node,
  5471. SVG = element.paper,
  5472. s = o.style,
  5473. el = R._g.doc.getElementById(id);
  5474. if (!el) {
  5475. gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
  5476. type = "radial";
  5477. if (_fx && _fy) {
  5478. fx = toFloat(_fx);
  5479. fy = toFloat(_fy);
  5480. var dir = ((fy > .5) * 2 - 1);
  5481. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
  5482. (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
  5483. fy != .5 &&
  5484. (fy = fy.toFixed(5) - 1e-5 * dir);
  5485. }
  5486. return E;
  5487. });
  5488. gradient = gradient.split(/\s*\-\s*/);
  5489. if (type == "linear") {
  5490. var angle = gradient.shift();
  5491. angle = -toFloat(angle);
  5492. if (isNaN(angle)) {
  5493. return null;
  5494. }
  5495. var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
  5496. max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
  5497. vector[2] *= max;
  5498. vector[3] *= max;
  5499. if (vector[2] < 0) {
  5500. vector[0] = -vector[2];
  5501. vector[2] = 0;
  5502. }
  5503. if (vector[3] < 0) {
  5504. vector[1] = -vector[3];
  5505. vector[3] = 0;
  5506. }
  5507. }
  5508. var dots = R._parseDots(gradient);
  5509. if (!dots) {
  5510. return null;
  5511. }
  5512. id = id.replace(/[\(\)\s,\xb0#]/g, "_");
  5513. if (element.gradient && id != element.gradient.id) {
  5514. SVG.defs.removeChild(element.gradient);
  5515. delete element.gradient;
  5516. }
  5517. if (!element.gradient) {
  5518. el = $(type + "Gradient", {id: id});
  5519. element.gradient = el;
  5520. $(el, type == "radial" ? {
  5521. fx: fx,
  5522. fy: fy
  5523. } : {
  5524. x1: vector[0],
  5525. y1: vector[1],
  5526. x2: vector[2],
  5527. y2: vector[3],
  5528. gradientTransform: element.matrix.invert()
  5529. });
  5530. SVG.defs.appendChild(el);
  5531. for (var i = 0, ii = dots.length; i < ii; i++) {
  5532. el.appendChild($("stop", {
  5533. offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
  5534. "stop-color": dots[i].color || "#fff",
  5535. "stop-opacity": isFinite(dots[i].opacity) ? dots[i].opacity : 1
  5536. }));
  5537. }
  5538. }
  5539. }
  5540. $(o, {
  5541. fill: fillurl(id),
  5542. opacity: 1,
  5543. "fill-opacity": 1
  5544. });
  5545. s.fill = E;
  5546. s.opacity = 1;
  5547. s.fillOpacity = 1;
  5548. return 1;
  5549. },
  5550. isIE9or10 = function () {
  5551. var mode = document.documentMode;
  5552. return mode && (mode === 9 || mode === 10);
  5553. },
  5554. fillurl = function (id) {
  5555. if (isIE9or10()) {
  5556. return "url('#" + id + "')";
  5557. }
  5558. var location = document.location;
  5559. var locationString = (
  5560. location.protocol + '//' +
  5561. location.host +
  5562. location.pathname +
  5563. location.search
  5564. );
  5565. return "url('" + locationString + "#" + id + "')";
  5566. },
  5567. updatePosition = function (o) {
  5568. var bbox = o.getBBox(1);
  5569. $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
  5570. },
  5571. addArrow = function (o, value, isEnd) {
  5572. if (o.type == "path") {
  5573. var values = Str(value).toLowerCase().split("-"),
  5574. p = o.paper,
  5575. se = isEnd ? "end" : "start",
  5576. node = o.node,
  5577. attrs = o.attrs,
  5578. stroke = attrs["stroke-width"],
  5579. i = values.length,
  5580. type = "classic",
  5581. from,
  5582. to,
  5583. dx,
  5584. refX,
  5585. attr,
  5586. w = 3,
  5587. h = 3,
  5588. t = 5;
  5589. while (i--) {
  5590. switch (values[i]) {
  5591. case "block":
  5592. case "classic":
  5593. case "oval":
  5594. case "diamond":
  5595. case "open":
  5596. case "none":
  5597. type = values[i];
  5598. break;
  5599. case "wide": h = 5; break;
  5600. case "narrow": h = 2; break;
  5601. case "long": w = 5; break;
  5602. case "short": w = 2; break;
  5603. }
  5604. }
  5605. if (type == "open") {
  5606. w += 2;
  5607. h += 2;
  5608. t += 2;
  5609. dx = 1;
  5610. refX = isEnd ? 4 : 1;
  5611. attr = {
  5612. fill: "none",
  5613. stroke: attrs.stroke
  5614. };
  5615. } else {
  5616. refX = dx = w / 2;
  5617. attr = {
  5618. fill: attrs.stroke,
  5619. stroke: "none"
  5620. };
  5621. }
  5622. if (o._.arrows) {
  5623. if (isEnd) {
  5624. o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
  5625. o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
  5626. } else {
  5627. o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
  5628. o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
  5629. }
  5630. } else {
  5631. o._.arrows = {};
  5632. }
  5633. if (type != "none") {
  5634. var pathId = "raphael-marker-" + type,
  5635. markerId = "raphael-marker-" + se + type + w + h + "-obj" + o.id;
  5636. if (!R._g.doc.getElementById(pathId)) {
  5637. p.defs.appendChild($($("path"), {
  5638. "stroke-linecap": "round",
  5639. d: markers[type],
  5640. id: pathId
  5641. }));
  5642. markerCounter[pathId] = 1;
  5643. } else {
  5644. markerCounter[pathId]++;
  5645. }
  5646. var marker = R._g.doc.getElementById(markerId),
  5647. use;
  5648. if (!marker) {
  5649. marker = $($("marker"), {
  5650. id: markerId,
  5651. markerHeight: h,
  5652. markerWidth: w,
  5653. orient: "auto",
  5654. refX: refX,
  5655. refY: h / 2
  5656. });
  5657. use = $($("use"), {
  5658. "xlink:href": "#" + pathId,
  5659. transform: (isEnd ? "rotate(180 " + w / 2 + " " + h / 2 + ") " : E) + "scale(" + w / t + "," + h / t + ")",
  5660. "stroke-width": (1 / ((w / t + h / t) / 2)).toFixed(4)
  5661. });
  5662. marker.appendChild(use);
  5663. p.defs.appendChild(marker);
  5664. markerCounter[markerId] = 1;
  5665. } else {
  5666. markerCounter[markerId]++;
  5667. use = marker.getElementsByTagName("use")[0];
  5668. }
  5669. $(use, attr);
  5670. var delta = dx * (type != "diamond" && type != "oval");
  5671. if (isEnd) {
  5672. from = o._.arrows.startdx * stroke || 0;
  5673. to = R.getTotalLength(attrs.path) - delta * stroke;
  5674. } else {
  5675. from = delta * stroke;
  5676. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  5677. }
  5678. attr = {};
  5679. attr["marker-" + se] = "url(#" + markerId + ")";
  5680. if (to || from) {
  5681. attr.d = R.getSubpath(attrs.path, from, to);
  5682. }
  5683. $(node, attr);
  5684. o._.arrows[se + "Path"] = pathId;
  5685. o._.arrows[se + "Marker"] = markerId;
  5686. o._.arrows[se + "dx"] = delta;
  5687. o._.arrows[se + "Type"] = type;
  5688. o._.arrows[se + "String"] = value;
  5689. } else {
  5690. if (isEnd) {
  5691. from = o._.arrows.startdx * stroke || 0;
  5692. to = R.getTotalLength(attrs.path) - from;
  5693. } else {
  5694. from = 0;
  5695. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  5696. }
  5697. o._.arrows[se + "Path"] && $(node, {d: R.getSubpath(attrs.path, from, to)});
  5698. delete o._.arrows[se + "Path"];
  5699. delete o._.arrows[se + "Marker"];
  5700. delete o._.arrows[se + "dx"];
  5701. delete o._.arrows[se + "Type"];
  5702. delete o._.arrows[se + "String"];
  5703. }
  5704. for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
  5705. var item = R._g.doc.getElementById(attr);
  5706. item && item.parentNode.removeChild(item);
  5707. }
  5708. }
  5709. },
  5710. dasharray = {
  5711. "-": [3, 1],
  5712. ".": [1, 1],
  5713. "-.": [3, 1, 1, 1],
  5714. "-..": [3, 1, 1, 1, 1, 1],
  5715. ". ": [1, 3],
  5716. "- ": [4, 3],
  5717. "--": [8, 3],
  5718. "- .": [4, 3, 1, 3],
  5719. "--.": [8, 3, 1, 3],
  5720. "--..": [8, 3, 1, 3, 1, 3]
  5721. },
  5722. addDashes = function (o, value, params) {
  5723. value = dasharray[Str(value).toLowerCase()];
  5724. if (value) {
  5725. var width = o.attrs["stroke-width"] || "1",
  5726. butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
  5727. dashes = [],
  5728. i = value.length;
  5729. while (i--) {
  5730. dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
  5731. }
  5732. $(o.node, {"stroke-dasharray": dashes.join(",")});
  5733. }
  5734. else {
  5735. $(o.node, {"stroke-dasharray": "none"});
  5736. }
  5737. },
  5738. setFillAndStroke = function (o, params) {
  5739. var node = o.node,
  5740. attrs = o.attrs,
  5741. vis = node.style.visibility;
  5742. node.style.visibility = "hidden";
  5743. for (var att in params) {
  5744. if (params[has](att)) {
  5745. if (!R._availableAttrs[has](att)) {
  5746. continue;
  5747. }
  5748. var value = params[att];
  5749. attrs[att] = value;
  5750. switch (att) {
  5751. case "blur":
  5752. o.blur(value);
  5753. break;
  5754. case "title":
  5755. var title = node.getElementsByTagName("title");
  5756. // Use the existing <title>.
  5757. if (title.length && (title = title[0])) {
  5758. title.firstChild.nodeValue = value;
  5759. } else {
  5760. title = $("title");
  5761. var val = R._g.doc.createTextNode(value);
  5762. title.appendChild(val);
  5763. node.appendChild(title);
  5764. }
  5765. break;
  5766. case "href":
  5767. case "target":
  5768. var pn = node.parentNode;
  5769. if (pn.tagName.toLowerCase() != "a") {
  5770. var hl = $("a");
  5771. pn.insertBefore(hl, node);
  5772. hl.appendChild(node);
  5773. pn = hl;
  5774. }
  5775. if (att == "target") {
  5776. pn.setAttributeNS(xlink, "show", value == "blank" ? "new" : value);
  5777. } else {
  5778. pn.setAttributeNS(xlink, att, value);
  5779. }
  5780. break;
  5781. case "cursor":
  5782. node.style.cursor = value;
  5783. break;
  5784. case "transform":
  5785. o.transform(value);
  5786. break;
  5787. case "arrow-start":
  5788. addArrow(o, value);
  5789. break;
  5790. case "arrow-end":
  5791. addArrow(o, value, 1);
  5792. break;
  5793. case "clip-rect":
  5794. var rect = Str(value).split(separator);
  5795. if (rect.length == 4) {
  5796. o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
  5797. var el = $("clipPath"),
  5798. rc = $("rect");
  5799. el.id = R.createUUID();
  5800. $(rc, {
  5801. x: rect[0],
  5802. y: rect[1],
  5803. width: rect[2],
  5804. height: rect[3]
  5805. });
  5806. el.appendChild(rc);
  5807. o.paper.defs.appendChild(el);
  5808. $(node, {"clip-path": "url(#" + el.id + ")"});
  5809. o.clip = rc;
  5810. }
  5811. if (!value) {
  5812. var path = node.getAttribute("clip-path");
  5813. if (path) {
  5814. var clip = R._g.doc.getElementById(path.replace(/(^url\(#|\)$)/g, E));
  5815. clip && clip.parentNode.removeChild(clip);
  5816. $(node, {"clip-path": E});
  5817. delete o.clip;
  5818. }
  5819. }
  5820. break;
  5821. case "path":
  5822. if (o.type == "path") {
  5823. $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
  5824. o._.dirty = 1;
  5825. if (o._.arrows) {
  5826. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  5827. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  5828. }
  5829. }
  5830. break;
  5831. case "width":
  5832. node.setAttribute(att, value);
  5833. o._.dirty = 1;
  5834. if (attrs.fx) {
  5835. att = "x";
  5836. value = attrs.x;
  5837. } else {
  5838. break;
  5839. }
  5840. case "x":
  5841. if (attrs.fx) {
  5842. value = -attrs.x - (attrs.width || 0);
  5843. }
  5844. case "rx":
  5845. if (att == "rx" && o.type == "rect") {
  5846. break;
  5847. }
  5848. case "cx":
  5849. node.setAttribute(att, value);
  5850. o.pattern && updatePosition(o);
  5851. o._.dirty = 1;
  5852. break;
  5853. case "height":
  5854. node.setAttribute(att, value);
  5855. o._.dirty = 1;
  5856. if (attrs.fy) {
  5857. att = "y";
  5858. value = attrs.y;
  5859. } else {
  5860. break;
  5861. }
  5862. case "y":
  5863. if (attrs.fy) {
  5864. value = -attrs.y - (attrs.height || 0);
  5865. }
  5866. case "ry":
  5867. if (att == "ry" && o.type == "rect") {
  5868. break;
  5869. }
  5870. case "cy":
  5871. node.setAttribute(att, value);
  5872. o.pattern && updatePosition(o);
  5873. o._.dirty = 1;
  5874. break;
  5875. case "r":
  5876. if (o.type == "rect") {
  5877. $(node, {rx: value, ry: value});
  5878. } else {
  5879. node.setAttribute(att, value);
  5880. }
  5881. o._.dirty = 1;
  5882. break;
  5883. case "src":
  5884. if (o.type == "image") {
  5885. node.setAttributeNS(xlink, "href", value);
  5886. }
  5887. break;
  5888. case "stroke-width":
  5889. if (o._.sx != 1 || o._.sy != 1) {
  5890. value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
  5891. }
  5892. node.setAttribute(att, value);
  5893. if (attrs["stroke-dasharray"]) {
  5894. addDashes(o, attrs["stroke-dasharray"], params);
  5895. }
  5896. if (o._.arrows) {
  5897. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  5898. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  5899. }
  5900. break;
  5901. case "stroke-dasharray":
  5902. addDashes(o, value, params);
  5903. break;
  5904. case "fill":
  5905. var isURL = Str(value).match(R._ISURL);
  5906. if (isURL) {
  5907. el = $("pattern");
  5908. var ig = $("image");
  5909. el.id = R.createUUID();
  5910. $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
  5911. $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
  5912. el.appendChild(ig);
  5913. (function (el) {
  5914. R._preload(isURL[1], function () {
  5915. var w = this.offsetWidth,
  5916. h = this.offsetHeight;
  5917. $(el, {width: w, height: h});
  5918. $(ig, {width: w, height: h});
  5919. });
  5920. })(el);
  5921. o.paper.defs.appendChild(el);
  5922. $(node, {fill: "url(#" + el.id + ")"});
  5923. o.pattern = el;
  5924. o.pattern && updatePosition(o);
  5925. break;
  5926. }
  5927. var clr = R.getRGB(value);
  5928. if (!clr.error) {
  5929. delete params.gradient;
  5930. delete attrs.gradient;
  5931. !R.is(attrs.opacity, "undefined") &&
  5932. R.is(params.opacity, "undefined") &&
  5933. $(node, {opacity: attrs.opacity});
  5934. !R.is(attrs["fill-opacity"], "undefined") &&
  5935. R.is(params["fill-opacity"], "undefined") &&
  5936. $(node, {"fill-opacity": attrs["fill-opacity"]});
  5937. } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
  5938. if ("opacity" in attrs || "fill-opacity" in attrs) {
  5939. var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  5940. if (gradient) {
  5941. var stops = gradient.getElementsByTagName("stop");
  5942. $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
  5943. }
  5944. }
  5945. attrs.gradient = value;
  5946. attrs.fill = "none";
  5947. break;
  5948. }
  5949. clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  5950. case "stroke":
  5951. clr = R.getRGB(value);
  5952. node.setAttribute(att, clr.hex);
  5953. att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  5954. if (att == "stroke" && o._.arrows) {
  5955. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  5956. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  5957. }
  5958. break;
  5959. case "gradient":
  5960. (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
  5961. break;
  5962. case "opacity":
  5963. if (attrs.gradient && !attrs[has]("stroke-opacity")) {
  5964. $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
  5965. }
  5966. // fall
  5967. case "fill-opacity":
  5968. if (attrs.gradient) {
  5969. gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  5970. if (gradient) {
  5971. stops = gradient.getElementsByTagName("stop");
  5972. $(stops[stops.length - 1], {"stop-opacity": value});
  5973. }
  5974. break;
  5975. }
  5976. default:
  5977. att == "font-size" && (value = toInt(value, 10) + "px");
  5978. var cssrule = att.replace(/(\-.)/g, function (w) {
  5979. return w.substring(1).toUpperCase();
  5980. });
  5981. node.style[cssrule] = value;
  5982. o._.dirty = 1;
  5983. node.setAttribute(att, value);
  5984. break;
  5985. }
  5986. }
  5987. }
  5988. tuneText(o, params);
  5989. node.style.visibility = vis;
  5990. },
  5991. leading = 1.2,
  5992. tuneText = function (el, params) {
  5993. if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
  5994. return;
  5995. }
  5996. var a = el.attrs,
  5997. node = el.node,
  5998. fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
  5999. if (params[has]("text")) {
  6000. a.text = params.text;
  6001. while (node.firstChild) {
  6002. node.removeChild(node.firstChild);
  6003. }
  6004. var texts = Str(params.text).split("\n"),
  6005. tspans = [],
  6006. tspan;
  6007. for (var i = 0, ii = texts.length; i < ii; i++) {
  6008. tspan = $("tspan");
  6009. i && $(tspan, {dy: fontSize * leading, x: a.x});
  6010. tspan.appendChild(R._g.doc.createTextNode(texts[i]));
  6011. node.appendChild(tspan);
  6012. tspans[i] = tspan;
  6013. }
  6014. } else {
  6015. tspans = node.getElementsByTagName("tspan");
  6016. for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
  6017. $(tspans[i], {dy: fontSize * leading, x: a.x});
  6018. } else {
  6019. $(tspans[0], {dy: 0});
  6020. }
  6021. }
  6022. $(node, {x: a.x, y: a.y});
  6023. el._.dirty = 1;
  6024. var bb = el._getBBox(),
  6025. dif = a.y - (bb.y + bb.height / 2);
  6026. dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
  6027. },
  6028. getRealNode = function (node) {
  6029. if (node.parentNode && node.parentNode.tagName.toLowerCase() === "a") {
  6030. return node.parentNode;
  6031. } else {
  6032. return node;
  6033. }
  6034. },
  6035. Element = function (node, svg) {
  6036. var X = 0,
  6037. Y = 0;
  6038. /*\
  6039. * Element.node
  6040. [ property (object) ]
  6041. **
  6042. * Gives you a reference to the DOM object, so you can assign event handlers or just mess around.
  6043. **
  6044. * Note: Don’t mess with it.
  6045. > Usage
  6046. | // draw a circle at coordinate 10,10 with radius of 10
  6047. | var c = paper.circle(10, 10, 10);
  6048. | c.node.onclick = function () {
  6049. | c.attr("fill", "red");
  6050. | };
  6051. \*/
  6052. this[0] = this.node = node;
  6053. /*\
  6054. * Element.raphael
  6055. [ property (object) ]
  6056. **
  6057. * Internal reference to @Raphael object. In case it is not available.
  6058. > Usage
  6059. | Raphael.el.red = function () {
  6060. | var hsb = this.paper.raphael.rgb2hsb(this.attr("fill"));
  6061. | hsb.h = 1;
  6062. | this.attr({fill: this.paper.raphael.hsb2rgb(hsb).hex});
  6063. | }
  6064. \*/
  6065. node.raphael = true;
  6066. /*\
  6067. * Element.id
  6068. [ property (number) ]
  6069. **
  6070. * Unique id of the element. Especially useful when you want to listen to events of the element,
  6071. * because all events are fired in format `<module>.<action>.<id>`. Also useful for @Paper.getById method.
  6072. \*/
  6073. this.id = R._oid++;
  6074. node.raphaelid = this.id;
  6075. this.matrix = R.matrix();
  6076. this.realPath = null;
  6077. /*\
  6078. * Element.paper
  6079. [ property (object) ]
  6080. **
  6081. * Internal reference to “paper” where object drawn. Mainly for use in plugins and element extensions.
  6082. > Usage
  6083. | Raphael.el.cross = function () {
  6084. | this.attr({fill: "red"});
  6085. | this.paper.path("M10,10L50,50M50,10L10,50")
  6086. | .attr({stroke: "red"});
  6087. | }
  6088. \*/
  6089. this.paper = svg;
  6090. this.attrs = this.attrs || {};
  6091. this._ = {
  6092. transform: [],
  6093. sx: 1,
  6094. sy: 1,
  6095. deg: 0,
  6096. dx: 0,
  6097. dy: 0,
  6098. dirty: 1
  6099. };
  6100. !svg.bottom && (svg.bottom = this);
  6101. /*\
  6102. * Element.prev
  6103. [ property (object) ]
  6104. **
  6105. * Reference to the previous element in the hierarchy.
  6106. \*/
  6107. this.prev = svg.top;
  6108. svg.top && (svg.top.next = this);
  6109. svg.top = this;
  6110. /*\
  6111. * Element.next
  6112. [ property (object) ]
  6113. **
  6114. * Reference to the next element in the hierarchy.
  6115. \*/
  6116. this.next = null;
  6117. },
  6118. elproto = R.el;
  6119. Element.prototype = elproto;
  6120. elproto.constructor = Element;
  6121. R._engine.path = function (pathString, SVG) {
  6122. var el = $("path");
  6123. SVG.canvas && SVG.canvas.appendChild(el);
  6124. var p = new Element(el, SVG);
  6125. p.type = "path";
  6126. setFillAndStroke(p, {
  6127. fill: "none",
  6128. stroke: "#000",
  6129. path: pathString
  6130. });
  6131. return p;
  6132. };
  6133. /*\
  6134. * Element.rotate
  6135. [ method ]
  6136. **
  6137. * Deprecated! Use @Element.transform instead.
  6138. * Adds rotation by given angle around given point to the list of
  6139. * transformations of the element.
  6140. > Parameters
  6141. - deg (number) angle in degrees
  6142. - cx (number) #optional x coordinate of the centre of rotation
  6143. - cy (number) #optional y coordinate of the centre of rotation
  6144. * If cx & cy aren’t specified centre of the shape is used as a point of rotation.
  6145. = (object) @Element
  6146. \*/
  6147. elproto.rotate = function (deg, cx, cy) {
  6148. if (this.removed) {
  6149. return this;
  6150. }
  6151. deg = Str(deg).split(separator);
  6152. if (deg.length - 1) {
  6153. cx = toFloat(deg[1]);
  6154. cy = toFloat(deg[2]);
  6155. }
  6156. deg = toFloat(deg[0]);
  6157. (cy == null) && (cx = cy);
  6158. if (cx == null || cy == null) {
  6159. var bbox = this.getBBox(1);
  6160. cx = bbox.x + bbox.width / 2;
  6161. cy = bbox.y + bbox.height / 2;
  6162. }
  6163. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  6164. return this;
  6165. };
  6166. /*\
  6167. * Element.scale
  6168. [ method ]
  6169. **
  6170. * Deprecated! Use @Element.transform instead.
  6171. * Adds scale by given amount relative to given point to the list of
  6172. * transformations of the element.
  6173. > Parameters
  6174. - sx (number) horisontal scale amount
  6175. - sy (number) vertical scale amount
  6176. - cx (number) #optional x coordinate of the centre of scale
  6177. - cy (number) #optional y coordinate of the centre of scale
  6178. * If cx & cy aren’t specified centre of the shape is used instead.
  6179. = (object) @Element
  6180. \*/
  6181. elproto.scale = function (sx, sy, cx, cy) {
  6182. if (this.removed) {
  6183. return this;
  6184. }
  6185. sx = Str(sx).split(separator);
  6186. if (sx.length - 1) {
  6187. sy = toFloat(sx[1]);
  6188. cx = toFloat(sx[2]);
  6189. cy = toFloat(sx[3]);
  6190. }
  6191. sx = toFloat(sx[0]);
  6192. (sy == null) && (sy = sx);
  6193. (cy == null) && (cx = cy);
  6194. if (cx == null || cy == null) {
  6195. var bbox = this.getBBox(1);
  6196. }
  6197. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  6198. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  6199. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  6200. return this;
  6201. };
  6202. /*\
  6203. * Element.translate
  6204. [ method ]
  6205. **
  6206. * Deprecated! Use @Element.transform instead.
  6207. * Adds translation by given amount to the list of transformations of the element.
  6208. > Parameters
  6209. - dx (number) horisontal shift
  6210. - dy (number) vertical shift
  6211. = (object) @Element
  6212. \*/
  6213. elproto.translate = function (dx, dy) {
  6214. if (this.removed) {
  6215. return this;
  6216. }
  6217. dx = Str(dx).split(separator);
  6218. if (dx.length - 1) {
  6219. dy = toFloat(dx[1]);
  6220. }
  6221. dx = toFloat(dx[0]) || 0;
  6222. dy = +dy || 0;
  6223. this.transform(this._.transform.concat([["t", dx, dy]]));
  6224. return this;
  6225. };
  6226. /*\
  6227. * Element.transform
  6228. [ method ]
  6229. **
  6230. * Adds transformation to the element which is separate to other attributes,
  6231. * i.e. translation doesn’t change `x` or `y` of the rectange. The format
  6232. * of transformation string is similar to the path string syntax:
  6233. | "t100,100r30,100,100s2,2,100,100r45s1.5"
  6234. * Each letter is a command. There are four commands: `t` is for translate, `r` is for rotate, `s` is for
  6235. * scale and `m` is for matrix.
  6236. *
  6237. * 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`.
  6238. *
  6239. * So, the example line above could be read like “translate by 100, 100; rotate 30° around 100, 100; scale twice around 100, 100;
  6240. * rotate 45° around centre; scale 1.5 times relative to centre”. As you can see rotate and scale commands have origin
  6241. * coordinates as optional parameters, the default is the centre point of the element.
  6242. * Matrix accepts six parameters.
  6243. > Usage
  6244. | var el = paper.rect(10, 20, 300, 200);
  6245. | // translate 100, 100, rotate 45°, translate -100, 0
  6246. | el.transform("t100,100r45t-100,0");
  6247. | // if you want you can append or prepend transformations
  6248. | el.transform("...t50,50");
  6249. | el.transform("s2...");
  6250. | // or even wrap
  6251. | el.transform("t50,50...t-50-50");
  6252. | // to reset transformation call method with empty string
  6253. | el.transform("");
  6254. | // to get current value call it without parameters
  6255. | console.log(el.transform());
  6256. > Parameters
  6257. - tstr (string) #optional transformation string
  6258. * If tstr isn’t specified
  6259. = (string) current transformation string
  6260. * else
  6261. = (object) @Element
  6262. \*/
  6263. elproto.transform = function (tstr) {
  6264. var _ = this._;
  6265. if (tstr == null) {
  6266. return _.transform;
  6267. }
  6268. R._extractTransform(this, tstr);
  6269. this.clip && $(this.clip, {transform: this.matrix.invert()});
  6270. this.pattern && updatePosition(this);
  6271. this.node && $(this.node, {transform: this.matrix});
  6272. if (_.sx != 1 || _.sy != 1) {
  6273. var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
  6274. this.attr({"stroke-width": sw});
  6275. }
  6276. //Reduce transform string
  6277. _.transform = this.matrix.toTransformString();
  6278. return this;
  6279. };
  6280. /*\
  6281. * Element.hide
  6282. [ method ]
  6283. **
  6284. * Makes element invisible. See @Element.show.
  6285. = (object) @Element
  6286. \*/
  6287. elproto.hide = function () {
  6288. if(!this.removed) this.node.style.display = "none";
  6289. return this;
  6290. };
  6291. /*\
  6292. * Element.show
  6293. [ method ]
  6294. **
  6295. * Makes element visible. See @Element.hide.
  6296. = (object) @Element
  6297. \*/
  6298. elproto.show = function () {
  6299. if(!this.removed) this.node.style.display = "";
  6300. return this;
  6301. };
  6302. /*\
  6303. * Element.remove
  6304. [ method ]
  6305. **
  6306. * Removes element from the paper.
  6307. \*/
  6308. elproto.remove = function () {
  6309. var node = getRealNode(this.node);
  6310. if (this.removed || !node.parentNode) {
  6311. return;
  6312. }
  6313. var paper = this.paper;
  6314. paper.__set__ && paper.__set__.exclude(this);
  6315. eve.unbind("raphael.*.*." + this.id);
  6316. if (this.gradient) {
  6317. paper.defs.removeChild(this.gradient);
  6318. }
  6319. R._tear(this, paper);
  6320. node.parentNode.removeChild(node);
  6321. // Remove custom data for element
  6322. this.removeData();
  6323. for (var i in this) {
  6324. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  6325. }
  6326. this.removed = true;
  6327. };
  6328. elproto._getBBox = function () {
  6329. if (this.node.style.display == "none") {
  6330. this.show();
  6331. var hide = true;
  6332. }
  6333. var canvasHidden = false,
  6334. containerStyle;
  6335. if (this.paper.canvas.parentElement) {
  6336. containerStyle = this.paper.canvas.parentElement.style;
  6337. } //IE10+ can't find parentElement
  6338. else if (this.paper.canvas.parentNode) {
  6339. containerStyle = this.paper.canvas.parentNode.style;
  6340. }
  6341. if(containerStyle && containerStyle.display == "none") {
  6342. canvasHidden = true;
  6343. containerStyle.display = "";
  6344. }
  6345. var bbox = {};
  6346. try {
  6347. bbox = this.node.getBBox();
  6348. } catch(e) {
  6349. // Firefox 3.0.x, 25.0.1 (probably more versions affected) play badly here - possible fix
  6350. bbox = {
  6351. x: this.node.clientLeft,
  6352. y: this.node.clientTop,
  6353. width: this.node.clientWidth,
  6354. height: this.node.clientHeight
  6355. }
  6356. } finally {
  6357. bbox = bbox || {};
  6358. if(canvasHidden){
  6359. containerStyle.display = "none";
  6360. }
  6361. }
  6362. hide && this.hide();
  6363. return bbox;
  6364. };
  6365. /*\
  6366. * Element.attr
  6367. [ method ]
  6368. **
  6369. * Sets the attributes of the element.
  6370. > Parameters
  6371. - attrName (string) attribute’s name
  6372. - value (string) value
  6373. * or
  6374. - params (object) object of name/value pairs
  6375. * or
  6376. - attrName (string) attribute’s name
  6377. * or
  6378. - attrNames (array) in this case method returns array of current values for given attribute names
  6379. = (object) @Element if attrsName & value or params are passed in.
  6380. = (...) value of the attribute if only attrsName is passed in.
  6381. = (array) array of values of the attribute if attrsNames is passed in.
  6382. = (object) object of attributes if nothing is passed in.
  6383. > Possible parameters
  6384. # <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>
  6385. 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`.
  6386. o clip-rect (string) comma or space separated values: x, y, width and height
  6387. o cursor (string) CSS type of the cursor
  6388. o cx (number) the x-axis coordinate of the center of the circle, or ellipse
  6389. o cy (number) the y-axis coordinate of the center of the circle, or ellipse
  6390. o fill (string) colour, gradient or image
  6391. o fill-opacity (number)
  6392. o font (string)
  6393. o font-family (string)
  6394. o font-size (number) font size in pixels
  6395. o font-weight (string)
  6396. o height (number)
  6397. o href (string) URL, if specified element behaves as hyperlink
  6398. o opacity (number)
  6399. o path (string) SVG path string format
  6400. o r (number) radius of the circle, ellipse or rounded corner on the rect
  6401. o rx (number) horisontal radius of the ellipse
  6402. o ry (number) vertical radius of the ellipse
  6403. o src (string) image URL, only works for @Element.image element
  6404. o stroke (string) stroke colour
  6405. o stroke-dasharray (string) [“”, “none”, “`-`”, “`.`”, “`-.`”, “`-..`”, “`. `”, “`- `”, “`--`”, “`- .`”, “`--.`”, “`--..`”]
  6406. o stroke-linecap (string) [“`butt`”, “`square`”, “`round`”]
  6407. o stroke-linejoin (string) [“`bevel`”, “`round`”, “`miter`”]
  6408. o stroke-miterlimit (number)
  6409. o stroke-opacity (number)
  6410. o stroke-width (number) stroke width in pixels, default is '1'
  6411. o target (string) used with href
  6412. o text (string) contents of the text element. Use `\n` for multiline text
  6413. o text-anchor (string) [“`start`”, “`middle`”, “`end`”], default is “`middle`”
  6414. o title (string) will create tooltip with a given text
  6415. o transform (string) see @Element.transform
  6416. o width (number)
  6417. o x (number)
  6418. o y (number)
  6419. > Gradients
  6420. * Linear gradient format: “`‹angle›-‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`90-#fff-#000`” – 90°
  6421. * gradient from white to black or “`0-#fff-#f00:20-#000`” – 0° gradient from white via red (at 20%) to black.
  6422. *
  6423. * radial gradient: “`r[(‹fx›, ‹fy›)]‹colour›[-‹colour›[:‹offset›]]*-‹colour›`”, example: “`r#fff-#000`” –
  6424. * gradient from white to black or “`r(0.25, 0.75)#fff-#000`” – gradient from white to black with focus point
  6425. * at 0.25, 0.75. Focus point coordinates are in 0..1 range. Radial gradients can only be applied to circles and ellipses.
  6426. > Path String
  6427. # <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>
  6428. > Colour Parsing
  6429. # <ul>
  6430. # <li>Colour name (“<code>red</code>”, “<code>green</code>”, “<code>cornflowerblue</code>”, etc)</li>
  6431. # <li>#••• — shortened HTML colour: (“<code>#000</code>”, “<code>#fc0</code>”, etc)</li>
  6432. # <li>#•••••• — full length HTML colour: (“<code>#000000</code>”, “<code>#bd2300</code>”)</li>
  6433. # <li>rgb(•••, •••, •••) — red, green and blue channels’ values: (“<code>rgb(200,&nbsp;100,&nbsp;0)</code>”)</li>
  6434. # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (“<code>rgb(100%,&nbsp;175%,&nbsp;0%)</code>”)</li>
  6435. # <li>rgba(•••, •••, •••, •••) — red, green and blue channels’ values: (“<code>rgba(200,&nbsp;100,&nbsp;0, .5)</code>”)</li>
  6436. # <li>rgba(•••%, •••%, •••%, •••%) — same as above, but in %: (“<code>rgba(100%,&nbsp;175%,&nbsp;0%, 50%)</code>”)</li>
  6437. # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (“<code>hsb(0.5,&nbsp;0.25,&nbsp;1)</code>”)</li>
  6438. # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li>
  6439. # <li>hsba(•••, •••, •••, •••) — same as above, but with opacity</li>
  6440. # <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>
  6441. # <li>hsl(•••%, •••%, •••%) — same as above, but in %</li>
  6442. # <li>hsla(•••, •••, •••, •••) — same as above, but with opacity</li>
  6443. # <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>
  6444. # </ul>
  6445. \*/
  6446. elproto.attr = function (name, value) {
  6447. if (this.removed) {
  6448. return this;
  6449. }
  6450. if (name == null) {
  6451. var res = {};
  6452. for (var a in this.attrs) if (this.attrs[has](a)) {
  6453. res[a] = this.attrs[a];
  6454. }
  6455. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  6456. res.transform = this._.transform;
  6457. return res;
  6458. }
  6459. if (value == null && R.is(name, "string")) {
  6460. if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
  6461. return this.attrs.gradient;
  6462. }
  6463. if (name == "transform") {
  6464. return this._.transform;
  6465. }
  6466. var names = name.split(separator),
  6467. out = {};
  6468. for (var i = 0, ii = names.length; i < ii; i++) {
  6469. name = names[i];
  6470. if (name in this.attrs) {
  6471. out[name] = this.attrs[name];
  6472. } else if (R.is(this.paper.customAttributes[name], "function")) {
  6473. out[name] = this.paper.customAttributes[name].def;
  6474. } else {
  6475. out[name] = R._availableAttrs[name];
  6476. }
  6477. }
  6478. return ii - 1 ? out : out[names[0]];
  6479. }
  6480. if (value == null && R.is(name, "array")) {
  6481. out = {};
  6482. for (i = 0, ii = name.length; i < ii; i++) {
  6483. out[name[i]] = this.attr(name[i]);
  6484. }
  6485. return out;
  6486. }
  6487. if (value != null) {
  6488. var params = {};
  6489. params[name] = value;
  6490. } else if (name != null && R.is(name, "object")) {
  6491. params = name;
  6492. }
  6493. for (var key in params) {
  6494. eve("raphael.attr." + key + "." + this.id, this, params[key]);
  6495. }
  6496. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  6497. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  6498. this.attrs[key] = params[key];
  6499. for (var subkey in par) if (par[has](subkey)) {
  6500. params[subkey] = par[subkey];
  6501. }
  6502. }
  6503. setFillAndStroke(this, params);
  6504. return this;
  6505. };
  6506. /*\
  6507. * Element.toFront
  6508. [ method ]
  6509. **
  6510. * Moves the element so it is the closest to the viewer’s eyes, on top of other elements.
  6511. = (object) @Element
  6512. \*/
  6513. elproto.toFront = function () {
  6514. if (this.removed) {
  6515. return this;
  6516. }
  6517. var node = getRealNode(this.node);
  6518. node.parentNode.appendChild(node);
  6519. var svg = this.paper;
  6520. svg.top != this && R._tofront(this, svg);
  6521. return this;
  6522. };
  6523. /*\
  6524. * Element.toBack
  6525. [ method ]
  6526. **
  6527. * Moves the element so it is the furthest from the viewer’s eyes, behind other elements.
  6528. = (object) @Element
  6529. \*/
  6530. elproto.toBack = function () {
  6531. if (this.removed) {
  6532. return this;
  6533. }
  6534. var node = getRealNode(this.node);
  6535. var parentNode = node.parentNode;
  6536. parentNode.insertBefore(node, parentNode.firstChild);
  6537. R._toback(this, this.paper);
  6538. var svg = this.paper;
  6539. return this;
  6540. };
  6541. /*\
  6542. * Element.insertAfter
  6543. [ method ]
  6544. **
  6545. * Inserts current object after the given one.
  6546. = (object) @Element
  6547. \*/
  6548. elproto.insertAfter = function (element) {
  6549. if (this.removed || !element) {
  6550. return this;
  6551. }
  6552. var node = getRealNode(this.node);
  6553. var afterNode = getRealNode(element.node || element[element.length - 1].node);
  6554. if (afterNode.nextSibling) {
  6555. afterNode.parentNode.insertBefore(node, afterNode.nextSibling);
  6556. } else {
  6557. afterNode.parentNode.appendChild(node);
  6558. }
  6559. R._insertafter(this, element, this.paper);
  6560. return this;
  6561. };
  6562. /*\
  6563. * Element.insertBefore
  6564. [ method ]
  6565. **
  6566. * Inserts current object before the given one.
  6567. = (object) @Element
  6568. \*/
  6569. elproto.insertBefore = function (element) {
  6570. if (this.removed || !element) {
  6571. return this;
  6572. }
  6573. var node = getRealNode(this.node);
  6574. var beforeNode = getRealNode(element.node || element[0].node);
  6575. beforeNode.parentNode.insertBefore(node, beforeNode);
  6576. R._insertbefore(this, element, this.paper);
  6577. return this;
  6578. };
  6579. elproto.blur = function (size) {
  6580. // Experimental. No Safari support. Use it on your own risk.
  6581. var t = this;
  6582. if (+size !== 0) {
  6583. var fltr = $("filter"),
  6584. blur = $("feGaussianBlur");
  6585. t.attrs.blur = size;
  6586. fltr.id = R.createUUID();
  6587. $(blur, {stdDeviation: +size || 1.5});
  6588. fltr.appendChild(blur);
  6589. t.paper.defs.appendChild(fltr);
  6590. t._blur = fltr;
  6591. $(t.node, {filter: "url(#" + fltr.id + ")"});
  6592. } else {
  6593. if (t._blur) {
  6594. t._blur.parentNode.removeChild(t._blur);
  6595. delete t._blur;
  6596. delete t.attrs.blur;
  6597. }
  6598. t.node.removeAttribute("filter");
  6599. }
  6600. return t;
  6601. };
  6602. R._engine.circle = function (svg, x, y, r) {
  6603. var el = $("circle");
  6604. svg.canvas && svg.canvas.appendChild(el);
  6605. var res = new Element(el, svg);
  6606. res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
  6607. res.type = "circle";
  6608. $(el, res.attrs);
  6609. return res;
  6610. };
  6611. R._engine.rect = function (svg, x, y, w, h, r) {
  6612. var el = $("rect");
  6613. svg.canvas && svg.canvas.appendChild(el);
  6614. var res = new Element(el, svg);
  6615. res.attrs = {x: x, y: y, width: w, height: h, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
  6616. res.type = "rect";
  6617. $(el, res.attrs);
  6618. return res;
  6619. };
  6620. R._engine.ellipse = function (svg, x, y, rx, ry) {
  6621. var el = $("ellipse");
  6622. svg.canvas && svg.canvas.appendChild(el);
  6623. var res = new Element(el, svg);
  6624. res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
  6625. res.type = "ellipse";
  6626. $(el, res.attrs);
  6627. return res;
  6628. };
  6629. R._engine.image = function (svg, src, x, y, w, h) {
  6630. var el = $("image");
  6631. $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
  6632. el.setAttributeNS(xlink, "href", src);
  6633. svg.canvas && svg.canvas.appendChild(el);
  6634. var res = new Element(el, svg);
  6635. res.attrs = {x: x, y: y, width: w, height: h, src: src};
  6636. res.type = "image";
  6637. return res;
  6638. };
  6639. R._engine.text = function (svg, x, y, text) {
  6640. var el = $("text");
  6641. svg.canvas && svg.canvas.appendChild(el);
  6642. var res = new Element(el, svg);
  6643. res.attrs = {
  6644. x: x,
  6645. y: y,
  6646. "text-anchor": "middle",
  6647. text: text,
  6648. "font-family": R._availableAttrs["font-family"],
  6649. "font-size": R._availableAttrs["font-size"],
  6650. stroke: "none",
  6651. fill: "#000"
  6652. };
  6653. res.type = "text";
  6654. setFillAndStroke(res, res.attrs);
  6655. return res;
  6656. };
  6657. R._engine.setSize = function (width, height) {
  6658. this.width = width || this.width;
  6659. this.height = height || this.height;
  6660. this.canvas.setAttribute("width", this.width);
  6661. this.canvas.setAttribute("height", this.height);
  6662. if (this._viewBox) {
  6663. this.setViewBox.apply(this, this._viewBox);
  6664. }
  6665. return this;
  6666. };
  6667. R._engine.create = function () {
  6668. var con = R._getContainer.apply(0, arguments),
  6669. container = con && con.container,
  6670. x = con.x,
  6671. y = con.y,
  6672. width = con.width,
  6673. height = con.height;
  6674. if (!container) {
  6675. throw new Error("SVG container not found.");
  6676. }
  6677. var cnvs = $("svg"),
  6678. css = "overflow:hidden;",
  6679. isFloating;
  6680. x = x || 0;
  6681. y = y || 0;
  6682. width = width || 512;
  6683. height = height || 342;
  6684. $(cnvs, {
  6685. height: height,
  6686. version: 1.1,
  6687. width: width,
  6688. xmlns: "http://www.w3.org/2000/svg",
  6689. "xmlns:xlink": "http://www.w3.org/1999/xlink"
  6690. });
  6691. if (container == 1) {
  6692. cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
  6693. R._g.doc.body.appendChild(cnvs);
  6694. isFloating = 1;
  6695. } else {
  6696. cnvs.style.cssText = css + "position:relative";
  6697. if (container.firstChild) {
  6698. container.insertBefore(cnvs, container.firstChild);
  6699. } else {
  6700. container.appendChild(cnvs);
  6701. }
  6702. }
  6703. container = new R._Paper;
  6704. container.width = width;
  6705. container.height = height;
  6706. container.canvas = cnvs;
  6707. container.clear();
  6708. container._left = container._top = 0;
  6709. isFloating && (container.renderfix = function () {});
  6710. container.renderfix();
  6711. return container;
  6712. };
  6713. R._engine.setViewBox = function (x, y, w, h, fit) {
  6714. eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  6715. var paperSize = this.getSize(),
  6716. size = mmax(w / paperSize.width, h / paperSize.height),
  6717. top = this.top,
  6718. aspectRatio = fit ? "xMidYMid meet" : "xMinYMin",
  6719. vb,
  6720. sw;
  6721. if (x == null) {
  6722. if (this._vbSize) {
  6723. size = 1;
  6724. }
  6725. delete this._vbSize;
  6726. vb = "0 0 " + this.width + S + this.height;
  6727. } else {
  6728. this._vbSize = size;
  6729. vb = x + S + y + S + w + S + h;
  6730. }
  6731. $(this.canvas, {
  6732. viewBox: vb,
  6733. preserveAspectRatio: aspectRatio
  6734. });
  6735. while (size && top) {
  6736. sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
  6737. top.attr({"stroke-width": sw});
  6738. top._.dirty = 1;
  6739. top._.dirtyT = 1;
  6740. top = top.prev;
  6741. }
  6742. this._viewBox = [x, y, w, h, !!fit];
  6743. return this;
  6744. };
  6745. /*\
  6746. * Paper.renderfix
  6747. [ method ]
  6748. **
  6749. * Fixes the issue of Firefox and IE9 regarding subpixel rendering. If paper is dependant
  6750. * on other elements after reflow it could shift half pixel which cause for lines to lost their crispness.
  6751. * This method fixes the issue.
  6752. **
  6753. Special thanks to Mariusz Nowak (http://www.medikoo.com/) for this method.
  6754. \*/
  6755. R.prototype.renderfix = function () {
  6756. var cnvs = this.canvas,
  6757. s = cnvs.style,
  6758. pos;
  6759. try {
  6760. pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix();
  6761. } catch (e) {
  6762. pos = cnvs.createSVGMatrix();
  6763. }
  6764. var left = -pos.e % 1,
  6765. top = -pos.f % 1;
  6766. if (left || top) {
  6767. if (left) {
  6768. this._left = (this._left + left) % 1;
  6769. s.left = this._left + "px";
  6770. }
  6771. if (top) {
  6772. this._top = (this._top + top) % 1;
  6773. s.top = this._top + "px";
  6774. }
  6775. }
  6776. };
  6777. /*\
  6778. * Paper.clear
  6779. [ method ]
  6780. **
  6781. * Clears the paper, i.e. removes all the elements.
  6782. \*/
  6783. R.prototype.clear = function () {
  6784. R.eve("raphael.clear", this);
  6785. var c = this.canvas;
  6786. while (c.firstChild) {
  6787. c.removeChild(c.firstChild);
  6788. }
  6789. this.bottom = this.top = null;
  6790. (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
  6791. c.appendChild(this.desc);
  6792. c.appendChild(this.defs = $("defs"));
  6793. };
  6794. /*\
  6795. * Paper.remove
  6796. [ method ]
  6797. **
  6798. * Removes the paper from the DOM.
  6799. \*/
  6800. R.prototype.remove = function () {
  6801. eve("raphael.remove", this);
  6802. this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  6803. for (var i in this) {
  6804. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  6805. }
  6806. };
  6807. var setproto = R.st;
  6808. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  6809. setproto[method] = (function (methodname) {
  6810. return function () {
  6811. var arg = arguments;
  6812. return this.forEach(function (el) {
  6813. el[methodname].apply(el, arg);
  6814. });
  6815. };
  6816. })(method);
  6817. }
  6818. }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  6819. /***/ },
  6820. /* 4 */
  6821. /***/ function(module, exports, __webpack_require__) {
  6822. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// ┌─────────────────────────────────────────────────────────────────────┐ \\
  6823. // │ Raphaël @@VERSION - JavaScript Vector Library │ \\
  6824. // ├─────────────────────────────────────────────────────────────────────┤ \\
  6825. // │ VML Module │ \\
  6826. // ├─────────────────────────────────────────────────────────────────────┤ \\
  6827. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  6828. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  6829. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  6830. // └─────────────────────────────────────────────────────────────────────┘ \\
  6831. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1)], __WEBPACK_AMD_DEFINE_RESULT__ = function(R) {
  6832. if (R && !R.vml) {
  6833. return;
  6834. }
  6835. var has = "hasOwnProperty",
  6836. Str = String,
  6837. toFloat = parseFloat,
  6838. math = Math,
  6839. round = math.round,
  6840. mmax = math.max,
  6841. mmin = math.min,
  6842. abs = math.abs,
  6843. fillString = "fill",
  6844. separator = /[, ]+/,
  6845. eve = R.eve,
  6846. ms = " progid:DXImageTransform.Microsoft",
  6847. S = " ",
  6848. E = "",
  6849. map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
  6850. bites = /([clmz]),?([^clmz]*)/gi,
  6851. blurregexp = / progid:\S+Blur\([^\)]+\)/g,
  6852. val = /-?[^,\s-]+/g,
  6853. cssDot = "position:absolute;left:0;top:0;width:1px;height:1px;behavior:url(#default#VML)",
  6854. zoom = 21600,
  6855. pathTypes = {path: 1, rect: 1, image: 1},
  6856. ovalTypes = {circle: 1, ellipse: 1},
  6857. path2vml = function (path) {
  6858. var total = /[ahqstv]/ig,
  6859. command = R._pathToAbsolute;
  6860. Str(path).match(total) && (command = R._path2curve);
  6861. total = /[clmz]/g;
  6862. if (command == R._pathToAbsolute && !Str(path).match(total)) {
  6863. var res = Str(path).replace(bites, function (all, command, args) {
  6864. var vals = [],
  6865. isMove = command.toLowerCase() == "m",
  6866. res = map[command];
  6867. args.replace(val, function (value) {
  6868. if (isMove && vals.length == 2) {
  6869. res += vals + map[command == "m" ? "l" : "L"];
  6870. vals = [];
  6871. }
  6872. vals.push(round(value * zoom));
  6873. });
  6874. return res + vals;
  6875. });
  6876. return res;
  6877. }
  6878. var pa = command(path), p, r;
  6879. res = [];
  6880. for (var i = 0, ii = pa.length; i < ii; i++) {
  6881. p = pa[i];
  6882. r = pa[i][0].toLowerCase();
  6883. r == "z" && (r = "x");
  6884. for (var j = 1, jj = p.length; j < jj; j++) {
  6885. r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
  6886. }
  6887. res.push(r);
  6888. }
  6889. return res.join(S);
  6890. },
  6891. compensation = function (deg, dx, dy) {
  6892. var m = R.matrix();
  6893. m.rotate(-deg, .5, .5);
  6894. return {
  6895. dx: m.x(dx, dy),
  6896. dy: m.y(dx, dy)
  6897. };
  6898. },
  6899. setCoords = function (p, sx, sy, dx, dy, deg) {
  6900. var _ = p._,
  6901. m = p.matrix,
  6902. fillpos = _.fillpos,
  6903. o = p.node,
  6904. s = o.style,
  6905. y = 1,
  6906. flip = "",
  6907. dxdy,
  6908. kx = zoom / sx,
  6909. ky = zoom / sy;
  6910. s.visibility = "hidden";
  6911. if (!sx || !sy) {
  6912. return;
  6913. }
  6914. o.coordsize = abs(kx) + S + abs(ky);
  6915. s.rotation = deg * (sx * sy < 0 ? -1 : 1);
  6916. if (deg) {
  6917. var c = compensation(deg, dx, dy);
  6918. dx = c.dx;
  6919. dy = c.dy;
  6920. }
  6921. sx < 0 && (flip += "x");
  6922. sy < 0 && (flip += " y") && (y = -1);
  6923. s.flip = flip;
  6924. o.coordorigin = (dx * -kx) + S + (dy * -ky);
  6925. if (fillpos || _.fillsize) {
  6926. var fill = o.getElementsByTagName(fillString);
  6927. fill = fill && fill[0];
  6928. o.removeChild(fill);
  6929. if (fillpos) {
  6930. c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
  6931. fill.position = c.dx * y + S + c.dy * y;
  6932. }
  6933. if (_.fillsize) {
  6934. fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
  6935. }
  6936. o.appendChild(fill);
  6937. }
  6938. s.visibility = "visible";
  6939. };
  6940. R.toString = function () {
  6941. return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
  6942. };
  6943. var addArrow = function (o, value, isEnd) {
  6944. var values = Str(value).toLowerCase().split("-"),
  6945. se = isEnd ? "end" : "start",
  6946. i = values.length,
  6947. type = "classic",
  6948. w = "medium",
  6949. h = "medium";
  6950. while (i--) {
  6951. switch (values[i]) {
  6952. case "block":
  6953. case "classic":
  6954. case "oval":
  6955. case "diamond":
  6956. case "open":
  6957. case "none":
  6958. type = values[i];
  6959. break;
  6960. case "wide":
  6961. case "narrow": h = values[i]; break;
  6962. case "long":
  6963. case "short": w = values[i]; break;
  6964. }
  6965. }
  6966. var stroke = o.node.getElementsByTagName("stroke")[0];
  6967. stroke[se + "arrow"] = type;
  6968. stroke[se + "arrowlength"] = w;
  6969. stroke[se + "arrowwidth"] = h;
  6970. },
  6971. setFillAndStroke = function (o, params) {
  6972. // o.paper.canvas.style.display = "none";
  6973. o.attrs = o.attrs || {};
  6974. var node = o.node,
  6975. a = o.attrs,
  6976. s = node.style,
  6977. xy,
  6978. 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),
  6979. isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
  6980. res = o;
  6981. for (var par in params) if (params[has](par)) {
  6982. a[par] = params[par];
  6983. }
  6984. if (newpath) {
  6985. a.path = R._getPath[o.type](o);
  6986. o._.dirty = 1;
  6987. }
  6988. params.href && (node.href = params.href);
  6989. params.title && (node.title = params.title);
  6990. params.target && (node.target = params.target);
  6991. params.cursor && (s.cursor = params.cursor);
  6992. "blur" in params && o.blur(params.blur);
  6993. if (params.path && o.type == "path" || newpath) {
  6994. node.path = path2vml(~Str(a.path).toLowerCase().indexOf("r") ? R._pathToAbsolute(a.path) : a.path);
  6995. o._.dirty = 1;
  6996. if (o.type == "image") {
  6997. o._.fillpos = [a.x, a.y];
  6998. o._.fillsize = [a.width, a.height];
  6999. setCoords(o, 1, 1, 0, 0, 0);
  7000. }
  7001. }
  7002. "transform" in params && o.transform(params.transform);
  7003. if (isOval) {
  7004. var cx = +a.cx,
  7005. cy = +a.cy,
  7006. rx = +a.rx || +a.r || 0,
  7007. ry = +a.ry || +a.r || 0;
  7008. 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));
  7009. o._.dirty = 1;
  7010. }
  7011. if ("clip-rect" in params) {
  7012. var rect = Str(params["clip-rect"]).split(separator);
  7013. if (rect.length == 4) {
  7014. rect[2] = +rect[2] + (+rect[0]);
  7015. rect[3] = +rect[3] + (+rect[1]);
  7016. var div = node.clipRect || R._g.doc.createElement("div"),
  7017. dstyle = div.style;
  7018. dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
  7019. if (!node.clipRect) {
  7020. dstyle.position = "absolute";
  7021. dstyle.top = 0;
  7022. dstyle.left = 0;
  7023. dstyle.width = o.paper.width + "px";
  7024. dstyle.height = o.paper.height + "px";
  7025. node.parentNode.insertBefore(div, node);
  7026. div.appendChild(node);
  7027. node.clipRect = div;
  7028. }
  7029. }
  7030. if (!params["clip-rect"]) {
  7031. node.clipRect && (node.clipRect.style.clip = "auto");
  7032. }
  7033. }
  7034. if (o.textpath) {
  7035. var textpathStyle = o.textpath.style;
  7036. params.font && (textpathStyle.font = params.font);
  7037. params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
  7038. params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
  7039. params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
  7040. params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
  7041. }
  7042. if ("arrow-start" in params) {
  7043. addArrow(res, params["arrow-start"]);
  7044. }
  7045. if ("arrow-end" in params) {
  7046. addArrow(res, params["arrow-end"], 1);
  7047. }
  7048. if (params.opacity != null ||
  7049. params["stroke-width"] != null ||
  7050. params.fill != null ||
  7051. params.src != null ||
  7052. params.stroke != null ||
  7053. params["stroke-width"] != null ||
  7054. params["stroke-opacity"] != null ||
  7055. params["fill-opacity"] != null ||
  7056. params["stroke-dasharray"] != null ||
  7057. params["stroke-miterlimit"] != null ||
  7058. params["stroke-linejoin"] != null ||
  7059. params["stroke-linecap"] != null) {
  7060. var fill = node.getElementsByTagName(fillString),
  7061. newfill = false;
  7062. fill = fill && fill[0];
  7063. !fill && (newfill = fill = createNode(fillString));
  7064. if (o.type == "image" && params.src) {
  7065. fill.src = params.src;
  7066. }
  7067. params.fill && (fill.on = true);
  7068. if (fill.on == null || params.fill == "none" || params.fill === null) {
  7069. fill.on = false;
  7070. }
  7071. if (fill.on && params.fill) {
  7072. var isURL = Str(params.fill).match(R._ISURL);
  7073. if (isURL) {
  7074. fill.parentNode == node && node.removeChild(fill);
  7075. fill.rotate = true;
  7076. fill.src = isURL[1];
  7077. fill.type = "tile";
  7078. var bbox = o.getBBox(1);
  7079. fill.position = bbox.x + S + bbox.y;
  7080. o._.fillpos = [bbox.x, bbox.y];
  7081. R._preload(isURL[1], function () {
  7082. o._.fillsize = [this.offsetWidth, this.offsetHeight];
  7083. });
  7084. } else {
  7085. fill.color = R.getRGB(params.fill).hex;
  7086. fill.src = E;
  7087. fill.type = "solid";
  7088. if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
  7089. a.fill = "none";
  7090. a.gradient = params.fill;
  7091. fill.rotate = false;
  7092. }
  7093. }
  7094. }
  7095. if ("fill-opacity" in params || "opacity" in params) {
  7096. var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
  7097. opacity = mmin(mmax(opacity, 0), 1);
  7098. fill.opacity = opacity;
  7099. if (fill.src) {
  7100. fill.color = "none";
  7101. }
  7102. }
  7103. node.appendChild(fill);
  7104. var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
  7105. newstroke = false;
  7106. !stroke && (newstroke = stroke = createNode("stroke"));
  7107. if ((params.stroke && params.stroke != "none") ||
  7108. params["stroke-width"] ||
  7109. params["stroke-opacity"] != null ||
  7110. params["stroke-dasharray"] ||
  7111. params["stroke-miterlimit"] ||
  7112. params["stroke-linejoin"] ||
  7113. params["stroke-linecap"]) {
  7114. stroke.on = true;
  7115. }
  7116. (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
  7117. var strokeColor = R.getRGB(params.stroke);
  7118. stroke.on && params.stroke && (stroke.color = strokeColor.hex);
  7119. opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
  7120. var width = (toFloat(params["stroke-width"]) || 1) * .75;
  7121. opacity = mmin(mmax(opacity, 0), 1);
  7122. params["stroke-width"] == null && (width = a["stroke-width"]);
  7123. params["stroke-width"] && (stroke.weight = width);
  7124. width && width < 1 && (opacity *= width) && (stroke.weight = 1);
  7125. stroke.opacity = opacity;
  7126. params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
  7127. stroke.miterlimit = params["stroke-miterlimit"] || 8;
  7128. params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
  7129. if ("stroke-dasharray" in params) {
  7130. var dasharray = {
  7131. "-": "shortdash",
  7132. ".": "shortdot",
  7133. "-.": "shortdashdot",
  7134. "-..": "shortdashdotdot",
  7135. ". ": "dot",
  7136. "- ": "dash",
  7137. "--": "longdash",
  7138. "- .": "dashdot",
  7139. "--.": "longdashdot",
  7140. "--..": "longdashdotdot"
  7141. };
  7142. stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
  7143. }
  7144. newstroke && node.appendChild(stroke);
  7145. }
  7146. if (res.type == "text") {
  7147. res.paper.canvas.style.display = E;
  7148. var span = res.paper.span,
  7149. m = 100,
  7150. fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
  7151. s = span.style;
  7152. a.font && (s.font = a.font);
  7153. a["font-family"] && (s.fontFamily = a["font-family"]);
  7154. a["font-weight"] && (s.fontWeight = a["font-weight"]);
  7155. a["font-style"] && (s.fontStyle = a["font-style"]);
  7156. fontSize = toFloat(a["font-size"] || fontSize && fontSize[0]) || 10;
  7157. s.fontSize = fontSize * m + "px";
  7158. res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "&#60;").replace(/&/g, "&#38;").replace(/\n/g, "<br>"));
  7159. var brect = span.getBoundingClientRect();
  7160. res.W = a.w = (brect.right - brect.left) / m;
  7161. res.H = a.h = (brect.bottom - brect.top) / m;
  7162. // res.paper.canvas.style.display = "none";
  7163. res.X = a.x;
  7164. res.Y = a.y + res.H / 2;
  7165. ("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));
  7166. var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
  7167. for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
  7168. res._.dirty = 1;
  7169. break;
  7170. }
  7171. // text-anchor emulation
  7172. switch (a["text-anchor"]) {
  7173. case "start":
  7174. res.textpath.style["v-text-align"] = "left";
  7175. res.bbx = res.W / 2;
  7176. break;
  7177. case "end":
  7178. res.textpath.style["v-text-align"] = "right";
  7179. res.bbx = -res.W / 2;
  7180. break;
  7181. default:
  7182. res.textpath.style["v-text-align"] = "center";
  7183. res.bbx = 0;
  7184. break;
  7185. }
  7186. res.textpath.style["v-text-kern"] = true;
  7187. }
  7188. // res.paper.canvas.style.display = E;
  7189. },
  7190. addGradientFill = function (o, gradient, fill) {
  7191. o.attrs = o.attrs || {};
  7192. var attrs = o.attrs,
  7193. pow = Math.pow,
  7194. opacity,
  7195. oindex,
  7196. type = "linear",
  7197. fxfy = ".5 .5";
  7198. o.attrs.gradient = gradient;
  7199. gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
  7200. type = "radial";
  7201. if (fx && fy) {
  7202. fx = toFloat(fx);
  7203. fy = toFloat(fy);
  7204. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
  7205. fxfy = fx + S + fy;
  7206. }
  7207. return E;
  7208. });
  7209. gradient = gradient.split(/\s*\-\s*/);
  7210. if (type == "linear") {
  7211. var angle = gradient.shift();
  7212. angle = -toFloat(angle);
  7213. if (isNaN(angle)) {
  7214. return null;
  7215. }
  7216. }
  7217. var dots = R._parseDots(gradient);
  7218. if (!dots) {
  7219. return null;
  7220. }
  7221. o = o.shape || o.node;
  7222. if (dots.length) {
  7223. o.removeChild(fill);
  7224. fill.on = true;
  7225. fill.method = "none";
  7226. fill.color = dots[0].color;
  7227. fill.color2 = dots[dots.length - 1].color;
  7228. var clrs = [];
  7229. for (var i = 0, ii = dots.length; i < ii; i++) {
  7230. dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
  7231. }
  7232. fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
  7233. if (type == "radial") {
  7234. fill.type = "gradientTitle";
  7235. fill.focus = "100%";
  7236. fill.focussize = "0 0";
  7237. fill.focusposition = fxfy;
  7238. fill.angle = 0;
  7239. } else {
  7240. // fill.rotate= true;
  7241. fill.type = "gradient";
  7242. fill.angle = (270 - angle) % 360;
  7243. }
  7244. o.appendChild(fill);
  7245. }
  7246. return 1;
  7247. },
  7248. Element = function (node, vml) {
  7249. this[0] = this.node = node;
  7250. node.raphael = true;
  7251. this.id = R._oid++;
  7252. node.raphaelid = this.id;
  7253. this.X = 0;
  7254. this.Y = 0;
  7255. this.attrs = {};
  7256. this.paper = vml;
  7257. this.matrix = R.matrix();
  7258. this._ = {
  7259. transform: [],
  7260. sx: 1,
  7261. sy: 1,
  7262. dx: 0,
  7263. dy: 0,
  7264. deg: 0,
  7265. dirty: 1,
  7266. dirtyT: 1
  7267. };
  7268. !vml.bottom && (vml.bottom = this);
  7269. this.prev = vml.top;
  7270. vml.top && (vml.top.next = this);
  7271. vml.top = this;
  7272. this.next = null;
  7273. };
  7274. var elproto = R.el;
  7275. Element.prototype = elproto;
  7276. elproto.constructor = Element;
  7277. elproto.transform = function (tstr) {
  7278. if (tstr == null) {
  7279. return this._.transform;
  7280. }
  7281. var vbs = this.paper._viewBoxShift,
  7282. vbt = vbs ? "s" + [vbs.scale, vbs.scale] + "-1-1t" + [vbs.dx, vbs.dy] : E,
  7283. oldt;
  7284. if (vbs) {
  7285. oldt = tstr = Str(tstr).replace(/\.{3}|\u2026/g, this._.transform || E);
  7286. }
  7287. R._extractTransform(this, vbt + tstr);
  7288. var matrix = this.matrix.clone(),
  7289. skew = this.skew,
  7290. o = this.node,
  7291. split,
  7292. isGrad = ~Str(this.attrs.fill).indexOf("-"),
  7293. isPatt = !Str(this.attrs.fill).indexOf("url(");
  7294. matrix.translate(1, 1);
  7295. if (isPatt || isGrad || this.type == "image") {
  7296. skew.matrix = "1 0 0 1";
  7297. skew.offset = "0 0";
  7298. split = matrix.split();
  7299. if ((isGrad && split.noRotation) || !split.isSimple) {
  7300. o.style.filter = matrix.toFilter();
  7301. var bb = this.getBBox(),
  7302. bbt = this.getBBox(1),
  7303. dx = bb.x - bbt.x,
  7304. dy = bb.y - bbt.y;
  7305. o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
  7306. setCoords(this, 1, 1, dx, dy, 0);
  7307. } else {
  7308. o.style.filter = E;
  7309. setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
  7310. }
  7311. } else {
  7312. o.style.filter = E;
  7313. skew.matrix = Str(matrix);
  7314. skew.offset = matrix.offset();
  7315. }
  7316. if (oldt !== null) { // empty string value is true as well
  7317. this._.transform = oldt;
  7318. R._extractTransform(this, oldt);
  7319. }
  7320. return this;
  7321. };
  7322. elproto.rotate = function (deg, cx, cy) {
  7323. if (this.removed) {
  7324. return this;
  7325. }
  7326. if (deg == null) {
  7327. return;
  7328. }
  7329. deg = Str(deg).split(separator);
  7330. if (deg.length - 1) {
  7331. cx = toFloat(deg[1]);
  7332. cy = toFloat(deg[2]);
  7333. }
  7334. deg = toFloat(deg[0]);
  7335. (cy == null) && (cx = cy);
  7336. if (cx == null || cy == null) {
  7337. var bbox = this.getBBox(1);
  7338. cx = bbox.x + bbox.width / 2;
  7339. cy = bbox.y + bbox.height / 2;
  7340. }
  7341. this._.dirtyT = 1;
  7342. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  7343. return this;
  7344. };
  7345. elproto.translate = function (dx, dy) {
  7346. if (this.removed) {
  7347. return this;
  7348. }
  7349. dx = Str(dx).split(separator);
  7350. if (dx.length - 1) {
  7351. dy = toFloat(dx[1]);
  7352. }
  7353. dx = toFloat(dx[0]) || 0;
  7354. dy = +dy || 0;
  7355. if (this._.bbox) {
  7356. this._.bbox.x += dx;
  7357. this._.bbox.y += dy;
  7358. }
  7359. this.transform(this._.transform.concat([["t", dx, dy]]));
  7360. return this;
  7361. };
  7362. elproto.scale = function (sx, sy, cx, cy) {
  7363. if (this.removed) {
  7364. return this;
  7365. }
  7366. sx = Str(sx).split(separator);
  7367. if (sx.length - 1) {
  7368. sy = toFloat(sx[1]);
  7369. cx = toFloat(sx[2]);
  7370. cy = toFloat(sx[3]);
  7371. isNaN(cx) && (cx = null);
  7372. isNaN(cy) && (cy = null);
  7373. }
  7374. sx = toFloat(sx[0]);
  7375. (sy == null) && (sy = sx);
  7376. (cy == null) && (cx = cy);
  7377. if (cx == null || cy == null) {
  7378. var bbox = this.getBBox(1);
  7379. }
  7380. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  7381. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  7382. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  7383. this._.dirtyT = 1;
  7384. return this;
  7385. };
  7386. elproto.hide = function () {
  7387. !this.removed && (this.node.style.display = "none");
  7388. return this;
  7389. };
  7390. elproto.show = function () {
  7391. !this.removed && (this.node.style.display = E);
  7392. return this;
  7393. };
  7394. // Needed to fix the vml setViewBox issues
  7395. elproto.auxGetBBox = R.el.getBBox;
  7396. elproto.getBBox = function(){
  7397. var b = this.auxGetBBox();
  7398. if (this.paper && this.paper._viewBoxShift)
  7399. {
  7400. var c = {};
  7401. var z = 1/this.paper._viewBoxShift.scale;
  7402. c.x = b.x - this.paper._viewBoxShift.dx;
  7403. c.x *= z;
  7404. c.y = b.y - this.paper._viewBoxShift.dy;
  7405. c.y *= z;
  7406. c.width = b.width * z;
  7407. c.height = b.height * z;
  7408. c.x2 = c.x + c.width;
  7409. c.y2 = c.y + c.height;
  7410. return c;
  7411. }
  7412. return b;
  7413. };
  7414. elproto._getBBox = function () {
  7415. if (this.removed) {
  7416. return {};
  7417. }
  7418. return {
  7419. x: this.X + (this.bbx || 0) - this.W / 2,
  7420. y: this.Y - this.H,
  7421. width: this.W,
  7422. height: this.H
  7423. };
  7424. };
  7425. elproto.remove = function () {
  7426. if (this.removed || !this.node.parentNode) {
  7427. return;
  7428. }
  7429. this.paper.__set__ && this.paper.__set__.exclude(this);
  7430. R.eve.unbind("raphael.*.*." + this.id);
  7431. R._tear(this, this.paper);
  7432. this.node.parentNode.removeChild(this.node);
  7433. this.shape && this.shape.parentNode.removeChild(this.shape);
  7434. for (var i in this) {
  7435. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  7436. }
  7437. this.removed = true;
  7438. };
  7439. elproto.attr = function (name, value) {
  7440. if (this.removed) {
  7441. return this;
  7442. }
  7443. if (name == null) {
  7444. var res = {};
  7445. for (var a in this.attrs) if (this.attrs[has](a)) {
  7446. res[a] = this.attrs[a];
  7447. }
  7448. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  7449. res.transform = this._.transform;
  7450. return res;
  7451. }
  7452. if (value == null && R.is(name, "string")) {
  7453. if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
  7454. return this.attrs.gradient;
  7455. }
  7456. var names = name.split(separator),
  7457. out = {};
  7458. for (var i = 0, ii = names.length; i < ii; i++) {
  7459. name = names[i];
  7460. if (name in this.attrs) {
  7461. out[name] = this.attrs[name];
  7462. } else if (R.is(this.paper.customAttributes[name], "function")) {
  7463. out[name] = this.paper.customAttributes[name].def;
  7464. } else {
  7465. out[name] = R._availableAttrs[name];
  7466. }
  7467. }
  7468. return ii - 1 ? out : out[names[0]];
  7469. }
  7470. if (this.attrs && value == null && R.is(name, "array")) {
  7471. out = {};
  7472. for (i = 0, ii = name.length; i < ii; i++) {
  7473. out[name[i]] = this.attr(name[i]);
  7474. }
  7475. return out;
  7476. }
  7477. var params;
  7478. if (value != null) {
  7479. params = {};
  7480. params[name] = value;
  7481. }
  7482. value == null && R.is(name, "object") && (params = name);
  7483. for (var key in params) {
  7484. eve("raphael.attr." + key + "." + this.id, this, params[key]);
  7485. }
  7486. if (params) {
  7487. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  7488. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  7489. this.attrs[key] = params[key];
  7490. for (var subkey in par) if (par[has](subkey)) {
  7491. params[subkey] = par[subkey];
  7492. }
  7493. }
  7494. // this.paper.canvas.style.display = "none";
  7495. if (params.text && this.type == "text") {
  7496. this.textpath.string = params.text;
  7497. }
  7498. setFillAndStroke(this, params);
  7499. // this.paper.canvas.style.display = E;
  7500. }
  7501. return this;
  7502. };
  7503. elproto.toFront = function () {
  7504. !this.removed && this.node.parentNode.appendChild(this.node);
  7505. this.paper && this.paper.top != this && R._tofront(this, this.paper);
  7506. return this;
  7507. };
  7508. elproto.toBack = function () {
  7509. if (this.removed) {
  7510. return this;
  7511. }
  7512. if (this.node.parentNode.firstChild != this.node) {
  7513. this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
  7514. R._toback(this, this.paper);
  7515. }
  7516. return this;
  7517. };
  7518. elproto.insertAfter = function (element) {
  7519. if (this.removed) {
  7520. return this;
  7521. }
  7522. if (element.constructor == R.st.constructor) {
  7523. element = element[element.length - 1];
  7524. }
  7525. if (element.node.nextSibling) {
  7526. element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
  7527. } else {
  7528. element.node.parentNode.appendChild(this.node);
  7529. }
  7530. R._insertafter(this, element, this.paper);
  7531. return this;
  7532. };
  7533. elproto.insertBefore = function (element) {
  7534. if (this.removed) {
  7535. return this;
  7536. }
  7537. if (element.constructor == R.st.constructor) {
  7538. element = element[0];
  7539. }
  7540. element.node.parentNode.insertBefore(this.node, element.node);
  7541. R._insertbefore(this, element, this.paper);
  7542. return this;
  7543. };
  7544. elproto.blur = function (size) {
  7545. var s = this.node.runtimeStyle,
  7546. f = s.filter;
  7547. f = f.replace(blurregexp, E);
  7548. if (+size !== 0) {
  7549. this.attrs.blur = size;
  7550. s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
  7551. s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
  7552. } else {
  7553. s.filter = f;
  7554. s.margin = 0;
  7555. delete this.attrs.blur;
  7556. }
  7557. return this;
  7558. };
  7559. R._engine.path = function (pathString, vml) {
  7560. var el = createNode("shape");
  7561. el.style.cssText = cssDot;
  7562. el.coordsize = zoom + S + zoom;
  7563. el.coordorigin = vml.coordorigin;
  7564. var p = new Element(el, vml),
  7565. attr = {fill: "none", stroke: "#000"};
  7566. pathString && (attr.path = pathString);
  7567. p.type = "path";
  7568. p.path = [];
  7569. p.Path = E;
  7570. setFillAndStroke(p, attr);
  7571. vml.canvas && vml.canvas.appendChild(el);
  7572. var skew = createNode("skew");
  7573. skew.on = true;
  7574. el.appendChild(skew);
  7575. p.skew = skew;
  7576. p.transform(E);
  7577. return p;
  7578. };
  7579. R._engine.rect = function (vml, x, y, w, h, r) {
  7580. var path = R._rectPath(x, y, w, h, r),
  7581. res = vml.path(path),
  7582. a = res.attrs;
  7583. res.X = a.x = x;
  7584. res.Y = a.y = y;
  7585. res.W = a.width = w;
  7586. res.H = a.height = h;
  7587. a.r = r;
  7588. a.path = path;
  7589. res.type = "rect";
  7590. return res;
  7591. };
  7592. R._engine.ellipse = function (vml, x, y, rx, ry) {
  7593. var res = vml.path(),
  7594. a = res.attrs;
  7595. res.X = x - rx;
  7596. res.Y = y - ry;
  7597. res.W = rx * 2;
  7598. res.H = ry * 2;
  7599. res.type = "ellipse";
  7600. setFillAndStroke(res, {
  7601. cx: x,
  7602. cy: y,
  7603. rx: rx,
  7604. ry: ry
  7605. });
  7606. return res;
  7607. };
  7608. R._engine.circle = function (vml, x, y, r) {
  7609. var res = vml.path(),
  7610. a = res.attrs;
  7611. res.X = x - r;
  7612. res.Y = y - r;
  7613. res.W = res.H = r * 2;
  7614. res.type = "circle";
  7615. setFillAndStroke(res, {
  7616. cx: x,
  7617. cy: y,
  7618. r: r
  7619. });
  7620. return res;
  7621. };
  7622. R._engine.image = function (vml, src, x, y, w, h) {
  7623. var path = R._rectPath(x, y, w, h),
  7624. res = vml.path(path).attr({stroke: "none"}),
  7625. a = res.attrs,
  7626. node = res.node,
  7627. fill = node.getElementsByTagName(fillString)[0];
  7628. a.src = src;
  7629. res.X = a.x = x;
  7630. res.Y = a.y = y;
  7631. res.W = a.width = w;
  7632. res.H = a.height = h;
  7633. a.path = path;
  7634. res.type = "image";
  7635. fill.parentNode == node && node.removeChild(fill);
  7636. fill.rotate = true;
  7637. fill.src = src;
  7638. fill.type = "tile";
  7639. res._.fillpos = [x, y];
  7640. res._.fillsize = [w, h];
  7641. node.appendChild(fill);
  7642. setCoords(res, 1, 1, 0, 0, 0);
  7643. return res;
  7644. };
  7645. R._engine.text = function (vml, x, y, text) {
  7646. var el = createNode("shape"),
  7647. path = createNode("path"),
  7648. o = createNode("textpath");
  7649. x = x || 0;
  7650. y = y || 0;
  7651. text = text || "";
  7652. path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
  7653. path.textpathok = true;
  7654. o.string = Str(text);
  7655. o.on = true;
  7656. el.style.cssText = cssDot;
  7657. el.coordsize = zoom + S + zoom;
  7658. el.coordorigin = "0 0";
  7659. var p = new Element(el, vml),
  7660. attr = {
  7661. fill: "#000",
  7662. stroke: "none",
  7663. font: R._availableAttrs.font,
  7664. text: text
  7665. };
  7666. p.shape = el;
  7667. p.path = path;
  7668. p.textpath = o;
  7669. p.type = "text";
  7670. p.attrs.text = Str(text);
  7671. p.attrs.x = x;
  7672. p.attrs.y = y;
  7673. p.attrs.w = 1;
  7674. p.attrs.h = 1;
  7675. setFillAndStroke(p, attr);
  7676. el.appendChild(o);
  7677. el.appendChild(path);
  7678. vml.canvas.appendChild(el);
  7679. var skew = createNode("skew");
  7680. skew.on = true;
  7681. el.appendChild(skew);
  7682. p.skew = skew;
  7683. p.transform(E);
  7684. return p;
  7685. };
  7686. R._engine.setSize = function (width, height) {
  7687. var cs = this.canvas.style;
  7688. this.width = width;
  7689. this.height = height;
  7690. width == +width && (width += "px");
  7691. height == +height && (height += "px");
  7692. cs.width = width;
  7693. cs.height = height;
  7694. cs.clip = "rect(0 " + width + " " + height + " 0)";
  7695. if (this._viewBox) {
  7696. R._engine.setViewBox.apply(this, this._viewBox);
  7697. }
  7698. return this;
  7699. };
  7700. R._engine.setViewBox = function (x, y, w, h, fit) {
  7701. R.eve("raphael.setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  7702. var paperSize = this.getSize(),
  7703. width = paperSize.width,
  7704. height = paperSize.height,
  7705. H, W;
  7706. if (fit) {
  7707. H = height / h;
  7708. W = width / w;
  7709. if (w * H < width) {
  7710. x -= (width - w * H) / 2 / H;
  7711. }
  7712. if (h * W < height) {
  7713. y -= (height - h * W) / 2 / W;
  7714. }
  7715. }
  7716. this._viewBox = [x, y, w, h, !!fit];
  7717. this._viewBoxShift = {
  7718. dx: -x,
  7719. dy: -y,
  7720. scale: paperSize
  7721. };
  7722. this.forEach(function (el) {
  7723. el.transform("...");
  7724. });
  7725. return this;
  7726. };
  7727. var createNode;
  7728. R._engine.initWin = function (win) {
  7729. var doc = win.document;
  7730. if (doc.styleSheets.length < 31) {
  7731. doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
  7732. } else {
  7733. // no more room, add to the existing one
  7734. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  7735. doc.styleSheets[0].addRule(".rvml", "behavior:url(#default#VML)");
  7736. }
  7737. try {
  7738. !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
  7739. createNode = function (tagName) {
  7740. return doc.createElement('<rvml:' + tagName + ' class="rvml">');
  7741. };
  7742. } catch (e) {
  7743. createNode = function (tagName) {
  7744. return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
  7745. };
  7746. }
  7747. };
  7748. R._engine.initWin(R._g.win);
  7749. R._engine.create = function () {
  7750. var con = R._getContainer.apply(0, arguments),
  7751. container = con.container,
  7752. height = con.height,
  7753. s,
  7754. width = con.width,
  7755. x = con.x,
  7756. y = con.y;
  7757. if (!container) {
  7758. throw new Error("VML container not found.");
  7759. }
  7760. var res = new R._Paper,
  7761. c = res.canvas = R._g.doc.createElement("div"),
  7762. cs = c.style;
  7763. x = x || 0;
  7764. y = y || 0;
  7765. width = width || 512;
  7766. height = height || 342;
  7767. res.width = width;
  7768. res.height = height;
  7769. width == +width && (width += "px");
  7770. height == +height && (height += "px");
  7771. res.coordsize = zoom * 1e3 + S + zoom * 1e3;
  7772. res.coordorigin = "0 0";
  7773. res.span = R._g.doc.createElement("span");
  7774. res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
  7775. c.appendChild(res.span);
  7776. 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);
  7777. if (container == 1) {
  7778. R._g.doc.body.appendChild(c);
  7779. cs.left = x + "px";
  7780. cs.top = y + "px";
  7781. cs.position = "absolute";
  7782. } else {
  7783. if (container.firstChild) {
  7784. container.insertBefore(c, container.firstChild);
  7785. } else {
  7786. container.appendChild(c);
  7787. }
  7788. }
  7789. res.renderfix = function () {};
  7790. return res;
  7791. };
  7792. R.prototype.clear = function () {
  7793. R.eve("raphael.clear", this);
  7794. this.canvas.innerHTML = E;
  7795. this.span = R._g.doc.createElement("span");
  7796. this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
  7797. this.canvas.appendChild(this.span);
  7798. this.bottom = this.top = null;
  7799. };
  7800. R.prototype.remove = function () {
  7801. R.eve("raphael.remove", this);
  7802. this.canvas.parentNode.removeChild(this.canvas);
  7803. for (var i in this) {
  7804. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  7805. }
  7806. return true;
  7807. };
  7808. var setproto = R.st;
  7809. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  7810. setproto[method] = (function (methodname) {
  7811. return function () {
  7812. var arg = arguments;
  7813. return this.forEach(function (el) {
  7814. el[methodname].apply(el, arg);
  7815. });
  7816. };
  7817. })(method);
  7818. }
  7819. }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  7820. /***/ }
  7821. /******/ ])
  7822. });
  7823. ;