raphael.js 202 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462
  1. // ┌─────────────────────────────────────────────────────────────────────┐ \\
  2. // │ Raphaël 2.0.1 - JavaScript Vector Library │ \\
  3. // ├─────────────────────────────────────────────────────────────────────┤ \\
  4. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  5. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  6. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  7. // └─────────────────────────────────────────────────────────────────────┘ \\
  8. // ┌──────────────────────────────────────────────────────────────────────────────────────┐ \\
  9. // │ Eve 0.4.0 - JavaScript Events Library │ \\
  10. // ├──────────────────────────────────────────────────────────────────────────────────────┤ \\
  11. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
  12. // │ Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. │ \\
  13. // └──────────────────────────────────────────────────────────────────────────────────────┘ \\
  14. (function (glob) {
  15. var version = "0.4.0",
  16. has = "hasOwnProperty",
  17. separator = /[\.\/]/,
  18. wildcard = "*",
  19. fun = function () {},
  20. numsort = function (a, b) {
  21. return a - b;
  22. },
  23. current_event,
  24. stop,
  25. events = {n: {}},
  26. eve = function (name, scope) {
  27. var e = events,
  28. oldstop = stop,
  29. args = Array.prototype.slice.call(arguments, 2),
  30. listeners = eve.listeners(name),
  31. z = 0,
  32. f = false,
  33. l,
  34. indexed = [],
  35. queue = {},
  36. out = [],
  37. errors = [];
  38. current_event = name;
  39. stop = 0;
  40. for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) {
  41. indexed.push(listeners[i].zIndex);
  42. if (listeners[i].zIndex < 0) {
  43. queue[listeners[i].zIndex] = listeners[i];
  44. }
  45. }
  46. indexed.sort(numsort);
  47. while (indexed[z] < 0) {
  48. l = queue[indexed[z++]];
  49. out.push(l.apply(scope, args));
  50. if (stop) {
  51. stop = oldstop;
  52. return out;
  53. }
  54. }
  55. for (i = 0; i < ii; i++) {
  56. l = listeners[i];
  57. if ("zIndex" in l) {
  58. if (l.zIndex == indexed[z]) {
  59. out.push(l.apply(scope, args));
  60. if (stop) {
  61. stop = oldstop;
  62. return out;
  63. }
  64. do {
  65. z++;
  66. l = queue[indexed[z]];
  67. l && out.push(l.apply(scope, args));
  68. if (stop) {
  69. stop = oldstop;
  70. return out;
  71. }
  72. } while (l)
  73. } else {
  74. queue[l.zIndex] = l;
  75. }
  76. } else {
  77. out.push(l.apply(scope, args));
  78. if (stop) {
  79. stop = oldstop;
  80. return out;
  81. }
  82. }
  83. }
  84. stop = oldstop;
  85. return out.length ? out : null;
  86. };
  87. eve.listeners = function (name) {
  88. var names = name.split(separator),
  89. e = events,
  90. item,
  91. items,
  92. k,
  93. i,
  94. ii,
  95. j,
  96. jj,
  97. nes,
  98. es = [e],
  99. out = [];
  100. for (i = 0, ii = names.length; i < ii; i++) {
  101. nes = [];
  102. for (j = 0, jj = es.length; j < jj; j++) {
  103. e = es[j].n;
  104. items = [e[names[i]], e[wildcard]];
  105. k = 2;
  106. while (k--) {
  107. item = items[k];
  108. if (item) {
  109. nes.push(item);
  110. out = out.concat(item.f || []);
  111. }
  112. }
  113. }
  114. es = nes;
  115. }
  116. return out;
  117. };
  118. eve.on = function (name, f) {
  119. var names = name.split(separator),
  120. e = events;
  121. for (var i = 0, ii = names.length; i < ii; i++) {
  122. e = e.n;
  123. !e[names[i]] && (e[names[i]] = {n: {}});
  124. e = e[names[i]];
  125. }
  126. e.f = e.f || [];
  127. for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) {
  128. return fun;
  129. }
  130. e.f.push(f);
  131. return function (zIndex) {
  132. if (+zIndex == +zIndex) {
  133. f.zIndex = +zIndex;
  134. }
  135. };
  136. };
  137. eve.stop = function () {
  138. stop = 1;
  139. };
  140. eve.nt = function (subname) {
  141. if (subname) {
  142. return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event);
  143. }
  144. return current_event;
  145. };
  146. eve.unbind = function (name, f) {
  147. var names = name.split(separator),
  148. e,
  149. key,
  150. splice,
  151. i, ii, j, jj,
  152. cur = [events];
  153. for (i = 0, ii = names.length; i < ii; i++) {
  154. for (j = 0; j < cur.length; j += splice.length - 2) {
  155. splice = [j, 1];
  156. e = cur[j].n;
  157. if (names[i] != wildcard) {
  158. if (e[names[i]]) {
  159. splice.push(e[names[i]]);
  160. }
  161. } else {
  162. for (key in e) if (e[has](key)) {
  163. splice.push(e[key]);
  164. }
  165. }
  166. cur.splice.apply(cur, splice);
  167. }
  168. }
  169. for (i = 0, ii = cur.length; i < ii; i++) {
  170. e = cur[i];
  171. while (e.n) {
  172. if (f) {
  173. if (e.f) {
  174. for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) {
  175. e.f.splice(j, 1);
  176. break;
  177. }
  178. !e.f.length && delete e.f;
  179. }
  180. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  181. var funcs = e.n[key].f;
  182. for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) {
  183. funcs.splice(j, 1);
  184. break;
  185. }
  186. !funcs.length && delete e.n[key].f;
  187. }
  188. } else {
  189. delete e.f;
  190. for (key in e.n) if (e.n[has](key) && e.n[key].f) {
  191. delete e.n[key].f;
  192. }
  193. }
  194. e = e.n;
  195. }
  196. }
  197. };
  198. eve.once = function (name, f) {
  199. var f2 = function () {
  200. f.apply(this, arguments);
  201. eve.unbind(name, f2);
  202. };
  203. return eve.on(name, f2);
  204. };
  205. eve.version = version;
  206. eve.toString = function () {
  207. return "You are running Eve " + version;
  208. };
  209. (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (glob.eve = eve);
  210. })(this);
  211. // ┌─────────────────────────────────────────────────────────────────────┐ \\
  212. // │ "Raphaël 2.0.1" - JavaScript Vector Library │ \\
  213. // ├─────────────────────────────────────────────────────────────────────┤ \\
  214. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  215. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  216. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  217. // └─────────────────────────────────────────────────────────────────────┘ \\
  218. (function () {
  219. function R(first) {
  220. if (R.is(first, "function")) {
  221. return loaded ? first() : eve.on("DOMload", first);
  222. } else if (R.is(first, array)) {
  223. return R._engine.create[apply](R, first.splice(0, 3 + R.is(first[0], nu))).add(first);
  224. } else {
  225. var args = Array.prototype.slice.call(arguments, 0);
  226. if (R.is(args[args.length - 1], "function")) {
  227. var f = args.pop();
  228. return loaded ? f.call(R._engine.create[apply](R, args)) : eve.on("DOMload", function () {
  229. f.call(R._engine.create[apply](R, args));
  230. });
  231. } else {
  232. return R._engine.create[apply](R, arguments);
  233. }
  234. }
  235. }
  236. R.version = "2.0.1";
  237. R.eve = eve;
  238. var loaded,
  239. separator = /[, ]+/,
  240. elements = {circle: 1, rect: 1, path: 1, ellipse: 1, text: 1, image: 1},
  241. formatrg = /\{(\d+)\}/g,
  242. proto = "prototype",
  243. has = "hasOwnProperty",
  244. g = {
  245. doc: document,
  246. win: window
  247. },
  248. oldRaphael = {
  249. was: Object.prototype[has].call(g.win, "Raphael"),
  250. is: g.win.Raphael
  251. },
  252. Paper = function () {
  253. this.ca = this.customAttributes = {};
  254. },
  255. paperproto,
  256. appendChild = "appendChild",
  257. apply = "apply",
  258. concat = "concat",
  259. supportsTouch = "createTouch" in g.doc,
  260. E = "",
  261. S = " ",
  262. Str = String,
  263. split = "split",
  264. events = "click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[split](S),
  265. touchMap = {
  266. mousedown: "touchstart",
  267. mousemove: "touchmove",
  268. mouseup: "touchend"
  269. },
  270. lowerCase = Str.prototype.toLowerCase,
  271. math = Math,
  272. mmax = math.max,
  273. mmin = math.min,
  274. abs = math.abs,
  275. pow = math.pow,
  276. PI = math.PI,
  277. nu = "number",
  278. string = "string",
  279. array = "array",
  280. toString = "toString",
  281. fillString = "fill",
  282. objectToString = Object.prototype.toString,
  283. paper = {},
  284. push = "push",
  285. ISURL = R._ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
  286. 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,
  287. isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
  288. bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
  289. round = math.round,
  290. setAttribute = "setAttribute",
  291. toFloat = parseFloat,
  292. toInt = parseInt,
  293. upperCase = Str.prototype.toUpperCase,
  294. availableAttrs = R._availableAttrs = {
  295. "arrow-end": "none",
  296. "arrow-start": "none",
  297. blur: 0,
  298. "clip-rect": "0 0 1e9 1e9",
  299. cursor: "default",
  300. cx: 0,
  301. cy: 0,
  302. fill: "#fff",
  303. "fill-opacity": 1,
  304. font: '10px "Arial"',
  305. "font-family": '"Arial"',
  306. "font-size": "10",
  307. "font-style": "normal",
  308. "font-weight": 400,
  309. gradient: 0,
  310. height: 0,
  311. href: "http://raphaeljs.com/",
  312. "letter-spacing": 0,
  313. opacity: 1,
  314. path: "M0,0",
  315. r: 0,
  316. rx: 0,
  317. ry: 0,
  318. src: "",
  319. stroke: "#000",
  320. "stroke-dasharray": "",
  321. "stroke-linecap": "butt",
  322. "stroke-linejoin": "butt",
  323. "stroke-miterlimit": 0,
  324. "stroke-opacity": 1,
  325. "stroke-width": 1,
  326. target: "_blank",
  327. "text-anchor": "middle",
  328. title: "Raphael",
  329. transform: "",
  330. width: 0,
  331. x: 0,
  332. y: 0
  333. },
  334. availableAnimAttrs = R._availableAnimAttrs = {
  335. blur: nu,
  336. "clip-rect": "csv",
  337. cx: nu,
  338. cy: nu,
  339. fill: "colour",
  340. "fill-opacity": nu,
  341. "font-size": nu,
  342. height: nu,
  343. opacity: nu,
  344. path: "path",
  345. r: nu,
  346. rx: nu,
  347. ry: nu,
  348. stroke: "colour",
  349. "stroke-opacity": nu,
  350. "stroke-width": nu,
  351. transform: "transform",
  352. width: nu,
  353. x: nu,
  354. y: nu
  355. },
  356. commaSpaces = /\s*,\s*/,
  357. hsrg = {hs: 1, rg: 1},
  358. p2s = /,?([achlmqrstvxz]),?/gi,
  359. pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
  360. tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
  361. pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,
  362. radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
  363. eldata = {},
  364. sortByKey = function (a, b) {
  365. return a.key - b.key;
  366. },
  367. sortByNumber = function (a, b) {
  368. return toFloat(a) - toFloat(b);
  369. },
  370. fun = function () {},
  371. pipe = function (x) {
  372. return x;
  373. },
  374. rectPath = R._rectPath = function (x, y, w, h, r) {
  375. if (r) {
  376. 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"]];
  377. }
  378. return [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]];
  379. },
  380. ellipsePath = function (x, y, rx, ry) {
  381. if (ry == null) {
  382. ry = rx;
  383. }
  384. 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"]];
  385. },
  386. getPath = R._getPath = {
  387. path: function (el) {
  388. return el.attr("path");
  389. },
  390. circle: function (el) {
  391. var a = el.attrs;
  392. return ellipsePath(a.cx, a.cy, a.r);
  393. },
  394. ellipse: function (el) {
  395. var a = el.attrs;
  396. return ellipsePath(a.cx, a.cy, a.rx, a.ry);
  397. },
  398. rect: function (el) {
  399. var a = el.attrs;
  400. return rectPath(a.x, a.y, a.width, a.height, a.r);
  401. },
  402. image: function (el) {
  403. var a = el.attrs;
  404. return rectPath(a.x, a.y, a.width, a.height);
  405. },
  406. text: function (el) {
  407. var bbox = el._getBBox();
  408. return rectPath(bbox.x, bbox.y, bbox.width, bbox.height);
  409. }
  410. },
  411. mapPath = R.mapPath = function (path, matrix) {
  412. if (!matrix) {
  413. return path;
  414. }
  415. var x, y, i, j, ii, jj, pathi;
  416. path = path2curve(path);
  417. for (i = 0, ii = path.length; i < ii; i++) {
  418. pathi = path[i];
  419. for (j = 1, jj = pathi.length; j < jj; j += 2) {
  420. x = matrix.x(pathi[j], pathi[j + 1]);
  421. y = matrix.y(pathi[j], pathi[j + 1]);
  422. pathi[j] = x;
  423. pathi[j + 1] = y;
  424. }
  425. }
  426. return path;
  427. };
  428. R._g = g;
  429. R.type = (g.win.SVGAngle || g.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1") ? "SVG" : "VML");
  430. if (R.type == "VML") {
  431. var d = g.doc.createElement("div"),
  432. b;
  433. d.innerHTML = '<v:shape adj="1"/>';
  434. b = d.firstChild;
  435. b.style.behavior = "url(#default#VML)";
  436. if (!(b && typeof b.adj == "object")) {
  437. return (R.type = E);
  438. }
  439. d = null;
  440. }
  441. R.svg = !(R.vml = R.type == "VML");
  442. R._Paper = Paper;
  443. R.fn = paperproto = Paper.prototype = R.prototype;
  444. R._id = 0;
  445. R._oid = 0;
  446. R.is = function (o, type) {
  447. type = lowerCase.call(type);
  448. if (type == "finite") {
  449. return !isnan[has](+o);
  450. }
  451. if (type == "array") {
  452. return o instanceof Array;
  453. }
  454. return (type == "null" && o === null) ||
  455. (type == typeof o && o !== null) ||
  456. (type == "object" && o === Object(o)) ||
  457. (type == "array" && Array.isArray && Array.isArray(o)) ||
  458. objectToString.call(o).slice(8, -1).toLowerCase() == type;
  459. };
  460. R.angle = function (x1, y1, x2, y2, x3, y3) {
  461. if (x3 == null) {
  462. var x = x1 - x2,
  463. y = y1 - y2;
  464. if (!x && !y) {
  465. return 0;
  466. }
  467. return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360;
  468. } else {
  469. return R.angle(x1, y1, x3, y3) - R.angle(x2, y2, x3, y3);
  470. }
  471. };
  472. R.rad = function (deg) {
  473. return deg % 360 * PI / 180;
  474. };
  475. R.deg = function (rad) {
  476. return rad * 180 / PI % 360;
  477. };
  478. R.snapTo = function (values, value, tolerance) {
  479. tolerance = R.is(tolerance, "finite") ? tolerance : 10;
  480. if (R.is(values, array)) {
  481. var i = values.length;
  482. while (i--) if (abs(values[i] - value) <= tolerance) {
  483. return values[i];
  484. }
  485. } else {
  486. values = +values;
  487. var rem = value % values;
  488. if (rem < tolerance) {
  489. return value - rem;
  490. }
  491. if (rem > values - tolerance) {
  492. return value - rem + values;
  493. }
  494. }
  495. return value;
  496. };
  497. var createUUID = R.createUUID = (function (uuidRegEx, uuidReplacer) {
  498. return function () {
  499. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
  500. };
  501. })(/[xy]/g, function (c) {
  502. var r = math.random() * 16 | 0,
  503. v = c == "x" ? r : (r & 3 | 8);
  504. return v.toString(16);
  505. });
  506. R.setWindow = function (newwin) {
  507. eve("setWindow", R, g.win, newwin);
  508. g.win = newwin;
  509. g.doc = g.win.document;
  510. if (R._engine.initWin) {
  511. R._engine.initWin(g.win);
  512. }
  513. };
  514. var toHex = function (color) {
  515. if (R.vml) {
  516. // http://dean.edwards.name/weblog/2009/10/convert-any-colour-value-to-hex-in-msie/
  517. var trim = /^\s+|\s+$/g;
  518. var bod;
  519. try {
  520. var docum = new ActiveXObject("htmlfile");
  521. docum.write("<body>");
  522. docum.close();
  523. bod = docum.body;
  524. } catch(e) {
  525. bod = createPopup().document.body;
  526. }
  527. var range = bod.createTextRange();
  528. toHex = cacher(function (color) {
  529. try {
  530. bod.style.color = Str(color).replace(trim, E);
  531. var value = range.queryCommandValue("ForeColor");
  532. value = ((value & 255) << 16) | (value & 65280) | ((value & 16711680) >>> 16);
  533. return "#" + ("000000" + value.toString(16)).slice(-6);
  534. } catch(e) {
  535. return "none";
  536. }
  537. });
  538. } else {
  539. var i = g.doc.createElement("i");
  540. i.title = "Rapha\xebl Colour Picker";
  541. i.style.display = "none";
  542. g.doc.body.appendChild(i);
  543. toHex = cacher(function (color) {
  544. i.style.color = color;
  545. return g.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color");
  546. });
  547. }
  548. return toHex(color);
  549. },
  550. hsbtoString = function () {
  551. return "hsb(" + [this.h, this.s, this.b] + ")";
  552. },
  553. hsltoString = function () {
  554. return "hsl(" + [this.h, this.s, this.l] + ")";
  555. },
  556. rgbtoString = function () {
  557. return this.hex;
  558. },
  559. prepareRGB = function (r, g, b) {
  560. if (g == null && R.is(r, "object") && "r" in r && "g" in r && "b" in r) {
  561. b = r.b;
  562. g = r.g;
  563. r = r.r;
  564. }
  565. if (g == null && R.is(r, string)) {
  566. var clr = R.getRGB(r);
  567. r = clr.r;
  568. g = clr.g;
  569. b = clr.b;
  570. }
  571. if (r > 1 || g > 1 || b > 1) {
  572. r /= 255;
  573. g /= 255;
  574. b /= 255;
  575. }
  576. return [r, g, b];
  577. },
  578. packageRGB = function (r, g, b, o) {
  579. r *= 255;
  580. g *= 255;
  581. b *= 255;
  582. var rgb = {
  583. r: r,
  584. g: g,
  585. b: b,
  586. hex: R.rgb(r, g, b),
  587. toString: rgbtoString
  588. };
  589. R.is(o, "finite") && (rgb.opacity = o);
  590. return rgb;
  591. };
  592. R.color = function (clr) {
  593. var rgb;
  594. if (R.is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) {
  595. rgb = R.hsb2rgb(clr);
  596. clr.r = rgb.r;
  597. clr.g = rgb.g;
  598. clr.b = rgb.b;
  599. clr.hex = rgb.hex;
  600. } else if (R.is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) {
  601. rgb = R.hsl2rgb(clr);
  602. clr.r = rgb.r;
  603. clr.g = rgb.g;
  604. clr.b = rgb.b;
  605. clr.hex = rgb.hex;
  606. } else {
  607. if (R.is(clr, "string")) {
  608. clr = R.getRGB(clr);
  609. }
  610. if (R.is(clr, "object") && "r" in clr && "g" in clr && "b" in clr) {
  611. rgb = R.rgb2hsl(clr);
  612. clr.h = rgb.h;
  613. clr.s = rgb.s;
  614. clr.l = rgb.l;
  615. rgb = R.rgb2hsb(clr);
  616. clr.v = rgb.b;
  617. } else {
  618. clr = {hex: "none"};
  619. clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1;
  620. }
  621. }
  622. clr.toString = rgbtoString;
  623. return clr;
  624. };
  625. R.hsb2rgb = function (h, s, v, o) {
  626. if (this.is(h, "object") && "h" in h && "s" in h && "b" in h) {
  627. v = h.b;
  628. s = h.s;
  629. h = h.h;
  630. o = h.o;
  631. }
  632. h *= 360;
  633. var R, G, B, X, C;
  634. h = (h % 360) / 60;
  635. C = v * s;
  636. X = C * (1 - abs(h % 2 - 1));
  637. R = G = B = v - C;
  638. h = ~~h;
  639. R += [C, X, 0, 0, X, C][h];
  640. G += [X, C, C, X, 0, 0][h];
  641. B += [0, 0, X, C, C, X][h];
  642. return packageRGB(R, G, B, o);
  643. };
  644. R.hsl2rgb = function (h, s, l, o) {
  645. if (this.is(h, "object") && "h" in h && "s" in h && "l" in h) {
  646. l = h.l;
  647. s = h.s;
  648. h = h.h;
  649. }
  650. if (h > 1 || s > 1 || l > 1) {
  651. h /= 360;
  652. s /= 100;
  653. l /= 100;
  654. }
  655. h *= 360;
  656. var R, G, B, X, C;
  657. h = (h % 360) / 60;
  658. C = 2 * s * (l < .5 ? l : 1 - l);
  659. X = C * (1 - abs(h % 2 - 1));
  660. R = G = B = l - C / 2;
  661. h = ~~h;
  662. R += [C, X, 0, 0, X, C][h];
  663. G += [X, C, C, X, 0, 0][h];
  664. B += [0, 0, X, C, C, X][h];
  665. return packageRGB(R, G, B, o);
  666. };
  667. R.rgb2hsb = function (r, g, b) {
  668. b = prepareRGB(r, g, b);
  669. r = b[0];
  670. g = b[1];
  671. b = b[2];
  672. var H, S, V, C;
  673. V = mmax(r, g, b);
  674. C = V - mmin(r, g, b);
  675. H = (C == 0 ? null :
  676. V == r ? (g - b) / C :
  677. V == g ? (b - r) / C + 2 :
  678. (r - g) / C + 4
  679. );
  680. H = ((H + 360) % 6) * 60 / 360;
  681. S = C == 0 ? 0 : C / V;
  682. return {h: H, s: S, b: V, toString: hsbtoString};
  683. };
  684. R.rgb2hsl = function (r, g, b) {
  685. b = prepareRGB(r, g, b);
  686. r = b[0];
  687. g = b[1];
  688. b = b[2];
  689. var H, S, L, M, m, C;
  690. M = mmax(r, g, b);
  691. m = mmin(r, g, b);
  692. C = M - m;
  693. H = (C == 0 ? null :
  694. M == r ? (g - b) / C :
  695. M == g ? (b - r) / C + 2 :
  696. (r - g) / C + 4);
  697. H = ((H + 360) % 6) * 60 / 360;
  698. L = (M + m) / 2;
  699. S = (C == 0 ? 0 :
  700. L < .5 ? C / (2 * L) :
  701. C / (2 - 2 * L));
  702. return {h: H, s: S, l: L, toString: hsltoString};
  703. };
  704. R._path2string = function () {
  705. return this.join(",").replace(p2s, "$1");
  706. };
  707. function repush(array, item) {
  708. for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
  709. return array.push(array.splice(i, 1)[0]);
  710. }
  711. }
  712. function cacher(f, scope, postprocessor) {
  713. function newf() {
  714. var arg = Array.prototype.slice.call(arguments, 0),
  715. args = arg.join("\u2400"),
  716. cache = newf.cache = newf.cache || {},
  717. count = newf.count = newf.count || [];
  718. if (cache[has](args)) {
  719. repush(count, args);
  720. return postprocessor ? postprocessor(cache[args]) : cache[args];
  721. }
  722. count.length >= 1e3 && delete cache[count.shift()];
  723. count.push(args);
  724. cache[args] = f[apply](scope, arg);
  725. return postprocessor ? postprocessor(cache[args]) : cache[args];
  726. }
  727. return newf;
  728. }
  729. var preload = R._preload = function (src, f) {
  730. var img = g.doc.createElement("img");
  731. img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
  732. img.onload = function () {
  733. f.call(this);
  734. this.onload = null;
  735. g.doc.body.removeChild(this);
  736. };
  737. img.onerror = function () {
  738. g.doc.body.removeChild(this);
  739. };
  740. g.doc.body.appendChild(img);
  741. img.src = src;
  742. };
  743. function clrToString() {
  744. return this.hex;
  745. }
  746. R.getRGB = cacher(function (colour) {
  747. if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) {
  748. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  749. }
  750. if (colour == "none") {
  751. return {r: -1, g: -1, b: -1, hex: "none", toString: clrToString};
  752. }
  753. !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  754. var res,
  755. red,
  756. green,
  757. blue,
  758. opacity,
  759. t,
  760. values,
  761. rgb = colour.match(colourRegExp);
  762. if (rgb) {
  763. if (rgb[2]) {
  764. blue = toInt(rgb[2].substring(5), 16);
  765. green = toInt(rgb[2].substring(3, 5), 16);
  766. red = toInt(rgb[2].substring(1, 3), 16);
  767. }
  768. if (rgb[3]) {
  769. blue = toInt((t = rgb[3].charAt(3)) + t, 16);
  770. green = toInt((t = rgb[3].charAt(2)) + t, 16);
  771. red = toInt((t = rgb[3].charAt(1)) + t, 16);
  772. }
  773. if (rgb[4]) {
  774. values = rgb[4][split](commaSpaces);
  775. red = toFloat(values[0]);
  776. values[0].slice(-1) == "%" && (red *= 2.55);
  777. green = toFloat(values[1]);
  778. values[1].slice(-1) == "%" && (green *= 2.55);
  779. blue = toFloat(values[2]);
  780. values[2].slice(-1) == "%" && (blue *= 2.55);
  781. rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3]));
  782. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  783. }
  784. if (rgb[5]) {
  785. values = rgb[5][split](commaSpaces);
  786. red = toFloat(values[0]);
  787. values[0].slice(-1) == "%" && (red *= 2.55);
  788. green = toFloat(values[1]);
  789. values[1].slice(-1) == "%" && (green *= 2.55);
  790. blue = toFloat(values[2]);
  791. values[2].slice(-1) == "%" && (blue *= 2.55);
  792. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  793. rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3]));
  794. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  795. return R.hsb2rgb(red, green, blue, opacity);
  796. }
  797. if (rgb[6]) {
  798. values = rgb[6][split](commaSpaces);
  799. red = toFloat(values[0]);
  800. values[0].slice(-1) == "%" && (red *= 2.55);
  801. green = toFloat(values[1]);
  802. values[1].slice(-1) == "%" && (green *= 2.55);
  803. blue = toFloat(values[2]);
  804. values[2].slice(-1) == "%" && (blue *= 2.55);
  805. (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
  806. rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3]));
  807. values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
  808. return R.hsl2rgb(red, green, blue, opacity);
  809. }
  810. rgb = {r: red, g: green, b: blue, toString: clrToString};
  811. rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1);
  812. R.is(opacity, "finite") && (rgb.opacity = opacity);
  813. return rgb;
  814. }
  815. return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: clrToString};
  816. }, R);
  817. R.hsb = cacher(function (h, s, b) {
  818. return R.hsb2rgb(h, s, b).hex;
  819. });
  820. R.hsl = cacher(function (h, s, l) {
  821. return R.hsl2rgb(h, s, l).hex;
  822. });
  823. R.rgb = cacher(function (r, g, b) {
  824. return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1);
  825. });
  826. R.getColor = function (value) {
  827. var start = this.getColor.start = this.getColor.start || {h: 0, s: 1, b: value || .75},
  828. rgb = this.hsb2rgb(start.h, start.s, start.b);
  829. start.h += .075;
  830. if (start.h > 1) {
  831. start.h = 0;
  832. start.s -= .2;
  833. start.s <= 0 && (this.getColor.start = {h: 0, s: 1, b: start.b});
  834. }
  835. return rgb.hex;
  836. };
  837. R.getColor.reset = function () {
  838. delete this.start;
  839. };
  840. // http://schepers.cc/getting-to-the-point
  841. function catmullRom2bezier(crp) {
  842. var d = [];
  843. for (var i = 0, iLen = crp.length; iLen - 2 > i; i += 2) {
  844. var p = [{x: +crp[i], y: +crp[i + 1]},
  845. {x: +crp[i], y: +crp[i + 1]},
  846. {x: +crp[i + 2], y: +crp[i + 3]},
  847. {x: +crp[i + 4], y: +crp[i + 5]}];
  848. if (iLen - 4 == i) {
  849. p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
  850. p[3] = p[2];
  851. } else if (i) {
  852. p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
  853. }
  854. d.push(["C",
  855. (-p[0].x + 6 * p[1].x + p[2].x) / 6,
  856. (-p[0].y + 6 * p[1].y + p[2].y) / 6,
  857. (p[1].x + 6 * p[2].x - p[3].x) / 6,
  858. (p[1].y + 6*p[2].y - p[3].y) / 6,
  859. p[2].x,
  860. p[2].y
  861. ]);
  862. }
  863. return d;
  864. }
  865. R.parsePathString = cacher(function (pathString) {
  866. if (!pathString) {
  867. return null;
  868. }
  869. var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
  870. data = [];
  871. if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
  872. data = pathClone(pathString);
  873. }
  874. if (!data.length) {
  875. Str(pathString).replace(pathCommand, function (a, b, c) {
  876. var params = [],
  877. name = b.toLowerCase();
  878. c.replace(pathValues, function (a, b) {
  879. b && params.push(+b);
  880. });
  881. if (name == "m" && params.length > 2) {
  882. data.push([b][concat](params.splice(0, 2)));
  883. name = "l";
  884. b = b == "m" ? "l" : "L";
  885. }
  886. if (name == "r") {
  887. data.push([b][concat](params));
  888. } else while (params.length >= paramCounts[name]) {
  889. data.push([b][concat](params.splice(0, paramCounts[name])));
  890. if (!paramCounts[name]) {
  891. break;
  892. }
  893. }
  894. });
  895. }
  896. data.toString = R._path2string;
  897. return data;
  898. });
  899. R.parseTransformString = cacher(function (TString) {
  900. if (!TString) {
  901. return null;
  902. }
  903. var paramCounts = {r: 3, s: 4, t: 2, m: 6},
  904. data = [];
  905. if (R.is(TString, array) && R.is(TString[0], array)) { // rough assumption
  906. data = pathClone(TString);
  907. }
  908. if (!data.length) {
  909. Str(TString).replace(tCommand, function (a, b, c) {
  910. var params = [],
  911. name = lowerCase.call(b);
  912. c.replace(pathValues, function (a, b) {
  913. b && params.push(+b);
  914. });
  915. data.push([b][concat](params));
  916. });
  917. }
  918. data.toString = R._path2string;
  919. return data;
  920. });
  921. R.findDotsAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  922. var t1 = 1 - t,
  923. t13 = pow(t1, 3),
  924. t12 = pow(t1, 2),
  925. t2 = t * t,
  926. t3 = t2 * t,
  927. x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
  928. y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
  929. mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
  930. my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
  931. nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
  932. ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
  933. ax = t1 * p1x + t * c1x,
  934. ay = t1 * p1y + t * c1y,
  935. cx = t1 * c2x + t * p2x,
  936. cy = t1 * c2y + t * p2y,
  937. alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
  938. (mx > nx || my < ny) && (alpha += 180);
  939. return {
  940. x: x,
  941. y: y,
  942. m: {x: mx, y: my},
  943. n: {x: nx, y: ny},
  944. start: {x: ax, y: ay},
  945. end: {x: cx, y: cy},
  946. alpha: alpha
  947. };
  948. };
  949. R._removedFactory = function (methodname) {
  950. return function () {
  951. throw new Error("Rapha\xebl: you are calling to method \u201c" + methodname + "\u201d of removed object");
  952. };
  953. };
  954. var pathDimensions = cacher(function (path) {
  955. if (!path) {
  956. return {x: 0, y: 0, width: 0, height: 0};
  957. }
  958. path = path2curve(path);
  959. var x = 0,
  960. y = 0,
  961. X = [],
  962. Y = [],
  963. p;
  964. for (var i = 0, ii = path.length; i < ii; i++) {
  965. p = path[i];
  966. if (p[0] == "M") {
  967. x = p[1];
  968. y = p[2];
  969. X.push(x);
  970. Y.push(y);
  971. } else {
  972. var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  973. X = X[concat](dim.min.x, dim.max.x);
  974. Y = Y[concat](dim.min.y, dim.max.y);
  975. x = p[5];
  976. y = p[6];
  977. }
  978. }
  979. var xmin = mmin[apply](0, X),
  980. ymin = mmin[apply](0, Y);
  981. return {
  982. x: xmin,
  983. y: ymin,
  984. width: mmax[apply](0, X) - xmin,
  985. height: mmax[apply](0, Y) - ymin
  986. };
  987. }, null, function (o) {
  988. return {
  989. x: o.x,
  990. y: o.y,
  991. width: o.width,
  992. height: o.height
  993. };
  994. }),
  995. pathClone = function (pathArray) {
  996. var res = [];
  997. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  998. pathArray = R.parsePathString(pathArray);
  999. }
  1000. for (var i = 0, ii = pathArray.length; i < ii; i++) {
  1001. res[i] = [];
  1002. for (var j = 0, jj = pathArray[i].length; j < jj; j++) {
  1003. res[i][j] = pathArray[i][j];
  1004. }
  1005. }
  1006. res.toString = R._path2string;
  1007. return res;
  1008. },
  1009. pathToRelative = R._pathToRelative = cacher(function (pathArray) {
  1010. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1011. pathArray = R.parsePathString(pathArray);
  1012. }
  1013. var res = [],
  1014. x = 0,
  1015. y = 0,
  1016. mx = 0,
  1017. my = 0,
  1018. start = 0;
  1019. if (pathArray[0][0] == "M") {
  1020. x = pathArray[0][1];
  1021. y = pathArray[0][2];
  1022. mx = x;
  1023. my = y;
  1024. start++;
  1025. res.push(["M", x, y]);
  1026. }
  1027. for (var i = start, ii = pathArray.length; i < ii; i++) {
  1028. var r = res[i] = [],
  1029. pa = pathArray[i];
  1030. if (pa[0] != lowerCase.call(pa[0])) {
  1031. r[0] = lowerCase.call(pa[0]);
  1032. switch (r[0]) {
  1033. case "a":
  1034. r[1] = pa[1];
  1035. r[2] = pa[2];
  1036. r[3] = pa[3];
  1037. r[4] = pa[4];
  1038. r[5] = pa[5];
  1039. r[6] = +(pa[6] - x).toFixed(3);
  1040. r[7] = +(pa[7] - y).toFixed(3);
  1041. break;
  1042. case "v":
  1043. r[1] = +(pa[1] - y).toFixed(3);
  1044. break;
  1045. case "m":
  1046. mx = pa[1];
  1047. my = pa[2];
  1048. default:
  1049. for (var j = 1, jj = pa.length; j < jj; j++) {
  1050. r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
  1051. }
  1052. }
  1053. } else {
  1054. r = res[i] = [];
  1055. if (pa[0] == "m") {
  1056. mx = pa[1] + x;
  1057. my = pa[2] + y;
  1058. }
  1059. for (var k = 0, kk = pa.length; k < kk; k++) {
  1060. res[i][k] = pa[k];
  1061. }
  1062. }
  1063. var len = res[i].length;
  1064. switch (res[i][0]) {
  1065. case "z":
  1066. x = mx;
  1067. y = my;
  1068. break;
  1069. case "h":
  1070. x += +res[i][len - 1];
  1071. break;
  1072. case "v":
  1073. y += +res[i][len - 1];
  1074. break;
  1075. default:
  1076. x += +res[i][len - 2];
  1077. y += +res[i][len - 1];
  1078. }
  1079. }
  1080. res.toString = R._path2string;
  1081. return res;
  1082. }, 0, pathClone),
  1083. pathToAbsolute = R._pathToAbsolute = cacher(function (pathArray) {
  1084. if (!R.is(pathArray, array) || !R.is(pathArray && pathArray[0], array)) { // rough assumption
  1085. pathArray = R.parsePathString(pathArray);
  1086. }
  1087. if (!pathArray || !pathArray.length) {
  1088. return [["M", 0, 0]];
  1089. }
  1090. var res = [],
  1091. x = 0,
  1092. y = 0,
  1093. mx = 0,
  1094. my = 0,
  1095. start = 0;
  1096. if (pathArray[0][0] == "M") {
  1097. x = +pathArray[0][1];
  1098. y = +pathArray[0][2];
  1099. mx = x;
  1100. my = y;
  1101. start++;
  1102. res[0] = ["M", x, y];
  1103. }
  1104. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  1105. res.push(r = []);
  1106. pa = pathArray[i];
  1107. if (pa[0] != upperCase.call(pa[0])) {
  1108. r[0] = upperCase.call(pa[0]);
  1109. switch (r[0]) {
  1110. case "A":
  1111. r[1] = pa[1];
  1112. r[2] = pa[2];
  1113. r[3] = pa[3];
  1114. r[4] = pa[4];
  1115. r[5] = pa[5];
  1116. r[6] = +(pa[6] + x);
  1117. r[7] = +(pa[7] + y);
  1118. break;
  1119. case "V":
  1120. r[1] = +pa[1] + y;
  1121. break;
  1122. case "H":
  1123. r[1] = +pa[1] + x;
  1124. break;
  1125. case "R":
  1126. var dots = [x, y][concat](pa.slice(1));
  1127. for (var j = 2, jj = dots.length; j < jj; j++) {
  1128. dots[j] = +dots[j] + x;
  1129. dots[++j] = +dots[j] + y;
  1130. }
  1131. res.pop();
  1132. res = res[concat](catmullRom2bezier(dots));
  1133. break;
  1134. case "M":
  1135. mx = +pa[1] + x;
  1136. my = +pa[2] + y;
  1137. default:
  1138. for (j = 1, jj = pa.length; j < jj; j++) {
  1139. r[j] = +pa[j] + ((j % 2) ? x : y);
  1140. }
  1141. }
  1142. } else if (pa[0] == "R") {
  1143. dots = [x, y][concat](pa.slice(1));
  1144. res.pop();
  1145. res = res[concat](catmullRom2bezier(dots));
  1146. r = ["R"][concat](pa.slice(-2));
  1147. } else {
  1148. for (var k = 0, kk = pa.length; k < kk; k++) {
  1149. r[k] = pa[k];
  1150. }
  1151. }
  1152. switch (r[0]) {
  1153. case "Z":
  1154. x = mx;
  1155. y = my;
  1156. break;
  1157. case "H":
  1158. x = r[1];
  1159. break;
  1160. case "V":
  1161. y = r[1];
  1162. break;
  1163. case "M":
  1164. mx = r[r.length - 2];
  1165. my = r[r.length - 1];
  1166. default:
  1167. x = r[r.length - 2];
  1168. y = r[r.length - 1];
  1169. }
  1170. }
  1171. res.toString = R._path2string;
  1172. return res;
  1173. }, null, pathClone),
  1174. l2c = function (x1, y1, x2, y2) {
  1175. return [x1, y1, x2, y2, x2, y2];
  1176. },
  1177. q2c = function (x1, y1, ax, ay, x2, y2) {
  1178. var _13 = 1 / 3,
  1179. _23 = 2 / 3;
  1180. return [
  1181. _13 * x1 + _23 * ax,
  1182. _13 * y1 + _23 * ay,
  1183. _13 * x2 + _23 * ax,
  1184. _13 * y2 + _23 * ay,
  1185. x2,
  1186. y2
  1187. ];
  1188. },
  1189. a2c = function (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  1190. // for more information of where this math came from visit:
  1191. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  1192. var _120 = PI * 120 / 180,
  1193. rad = PI / 180 * (+angle || 0),
  1194. res = [],
  1195. xy,
  1196. rotate = cacher(function (x, y, rad) {
  1197. var X = x * math.cos(rad) - y * math.sin(rad),
  1198. Y = x * math.sin(rad) + y * math.cos(rad);
  1199. return {x: X, y: Y};
  1200. });
  1201. if (!recursive) {
  1202. xy = rotate(x1, y1, -rad);
  1203. x1 = xy.x;
  1204. y1 = xy.y;
  1205. xy = rotate(x2, y2, -rad);
  1206. x2 = xy.x;
  1207. y2 = xy.y;
  1208. var cos = math.cos(PI / 180 * angle),
  1209. sin = math.sin(PI / 180 * angle),
  1210. x = (x1 - x2) / 2,
  1211. y = (y1 - y2) / 2;
  1212. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  1213. if (h > 1) {
  1214. h = math.sqrt(h);
  1215. rx = h * rx;
  1216. ry = h * ry;
  1217. }
  1218. var rx2 = rx * rx,
  1219. ry2 = ry * ry,
  1220. k = (large_arc_flag == sweep_flag ? -1 : 1) *
  1221. math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
  1222. cx = k * rx * y / ry + (x1 + x2) / 2,
  1223. cy = k * -ry * x / rx + (y1 + y2) / 2,
  1224. f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
  1225. f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  1226. f1 = x1 < cx ? PI - f1 : f1;
  1227. f2 = x2 < cx ? PI - f2 : f2;
  1228. f1 < 0 && (f1 = PI * 2 + f1);
  1229. f2 < 0 && (f2 = PI * 2 + f2);
  1230. if (sweep_flag && f1 > f2) {
  1231. f1 = f1 - PI * 2;
  1232. }
  1233. if (!sweep_flag && f2 > f1) {
  1234. f2 = f2 - PI * 2;
  1235. }
  1236. } else {
  1237. f1 = recursive[0];
  1238. f2 = recursive[1];
  1239. cx = recursive[2];
  1240. cy = recursive[3];
  1241. }
  1242. var df = f2 - f1;
  1243. if (abs(df) > _120) {
  1244. var f2old = f2,
  1245. x2old = x2,
  1246. y2old = y2;
  1247. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  1248. x2 = cx + rx * math.cos(f2);
  1249. y2 = cy + ry * math.sin(f2);
  1250. res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  1251. }
  1252. df = f2 - f1;
  1253. var c1 = math.cos(f1),
  1254. s1 = math.sin(f1),
  1255. c2 = math.cos(f2),
  1256. s2 = math.sin(f2),
  1257. t = math.tan(df / 4),
  1258. hx = 4 / 3 * rx * t,
  1259. hy = 4 / 3 * ry * t,
  1260. m1 = [x1, y1],
  1261. m2 = [x1 + hx * s1, y1 - hy * c1],
  1262. m3 = [x2 + hx * s2, y2 - hy * c2],
  1263. m4 = [x2, y2];
  1264. m2[0] = 2 * m1[0] - m2[0];
  1265. m2[1] = 2 * m1[1] - m2[1];
  1266. if (recursive) {
  1267. return [m2, m3, m4][concat](res);
  1268. } else {
  1269. res = [m2, m3, m4][concat](res).join()[split](",");
  1270. var newres = [];
  1271. for (var i = 0, ii = res.length; i < ii; i++) {
  1272. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  1273. }
  1274. return newres;
  1275. }
  1276. },
  1277. findDotAtSegment = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  1278. var t1 = 1 - t;
  1279. return {
  1280. x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x,
  1281. y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y
  1282. };
  1283. },
  1284. curveDim = cacher(function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  1285. var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x),
  1286. b = 2 * (c1x - p1x) - 2 * (c2x - c1x),
  1287. c = p1x - c1x,
  1288. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a,
  1289. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a,
  1290. y = [p1y, p2y],
  1291. x = [p1x, p2x],
  1292. dot;
  1293. abs(t1) > "1e12" && (t1 = .5);
  1294. abs(t2) > "1e12" && (t2 = .5);
  1295. if (t1 > 0 && t1 < 1) {
  1296. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  1297. x.push(dot.x);
  1298. y.push(dot.y);
  1299. }
  1300. if (t2 > 0 && t2 < 1) {
  1301. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  1302. x.push(dot.x);
  1303. y.push(dot.y);
  1304. }
  1305. a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
  1306. b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
  1307. c = p1y - c1y;
  1308. t1 = (-b + math.sqrt(b * b - 4 * a * c)) / 2 / a;
  1309. t2 = (-b - math.sqrt(b * b - 4 * a * c)) / 2 / a;
  1310. abs(t1) > "1e12" && (t1 = .5);
  1311. abs(t2) > "1e12" && (t2 = .5);
  1312. if (t1 > 0 && t1 < 1) {
  1313. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  1314. x.push(dot.x);
  1315. y.push(dot.y);
  1316. }
  1317. if (t2 > 0 && t2 < 1) {
  1318. dot = findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  1319. x.push(dot.x);
  1320. y.push(dot.y);
  1321. }
  1322. return {
  1323. min: {x: mmin[apply](0, x), y: mmin[apply](0, y)},
  1324. max: {x: mmax[apply](0, x), y: mmax[apply](0, y)}
  1325. };
  1326. }),
  1327. path2curve = R._path2curve = cacher(function (path, path2) {
  1328. var p = pathToAbsolute(path),
  1329. p2 = path2 && pathToAbsolute(path2),
  1330. attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  1331. attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null},
  1332. processPath = function (path, d) {
  1333. var nx, ny;
  1334. if (!path) {
  1335. return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
  1336. }
  1337. !(path[0] in {T:1, Q:1}) && (d.qx = d.qy = null);
  1338. switch (path[0]) {
  1339. case "M":
  1340. d.X = path[1];
  1341. d.Y = path[2];
  1342. break;
  1343. case "A":
  1344. path = ["C"][concat](a2c[apply](0, [d.x, d.y][concat](path.slice(1))));
  1345. break;
  1346. case "S":
  1347. nx = d.x + (d.x - (d.bx || d.x));
  1348. ny = d.y + (d.y - (d.by || d.y));
  1349. path = ["C", nx, ny][concat](path.slice(1));
  1350. break;
  1351. case "T":
  1352. d.qx = d.x + (d.x - (d.qx || d.x));
  1353. d.qy = d.y + (d.y - (d.qy || d.y));
  1354. path = ["C"][concat](q2c(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  1355. break;
  1356. case "Q":
  1357. d.qx = path[1];
  1358. d.qy = path[2];
  1359. path = ["C"][concat](q2c(d.x, d.y, path[1], path[2], path[3], path[4]));
  1360. break;
  1361. case "L":
  1362. path = ["C"][concat](l2c(d.x, d.y, path[1], path[2]));
  1363. break;
  1364. case "H":
  1365. path = ["C"][concat](l2c(d.x, d.y, path[1], d.y));
  1366. break;
  1367. case "V":
  1368. path = ["C"][concat](l2c(d.x, d.y, d.x, path[1]));
  1369. break;
  1370. case "Z":
  1371. path = ["C"][concat](l2c(d.x, d.y, d.X, d.Y));
  1372. break;
  1373. }
  1374. return path;
  1375. },
  1376. fixArc = function (pp, i) {
  1377. if (pp[i].length > 7) {
  1378. pp[i].shift();
  1379. var pi = pp[i];
  1380. while (pi.length) {
  1381. pp.splice(i++, 0, ["C"][concat](pi.splice(0, 6)));
  1382. }
  1383. pp.splice(i, 1);
  1384. ii = mmax(p.length, p2 && p2.length || 0);
  1385. }
  1386. },
  1387. fixM = function (path1, path2, a1, a2, i) {
  1388. if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") {
  1389. path2.splice(i, 0, ["M", a2.x, a2.y]);
  1390. a1.bx = 0;
  1391. a1.by = 0;
  1392. a1.x = path1[i][1];
  1393. a1.y = path1[i][2];
  1394. ii = mmax(p.length, p2 && p2.length || 0);
  1395. }
  1396. };
  1397. for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
  1398. p[i] = processPath(p[i], attrs);
  1399. fixArc(p, i);
  1400. p2 && (p2[i] = processPath(p2[i], attrs2));
  1401. p2 && fixArc(p2, i);
  1402. fixM(p, p2, attrs, attrs2, i);
  1403. fixM(p2, p, attrs2, attrs, i);
  1404. var seg = p[i],
  1405. seg2 = p2 && p2[i],
  1406. seglen = seg.length,
  1407. seg2len = p2 && seg2.length;
  1408. attrs.x = seg[seglen - 2];
  1409. attrs.y = seg[seglen - 1];
  1410. attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
  1411. attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
  1412. attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
  1413. attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
  1414. attrs2.x = p2 && seg2[seg2len - 2];
  1415. attrs2.y = p2 && seg2[seg2len - 1];
  1416. }
  1417. return p2 ? [p, p2] : p;
  1418. }, null, pathClone),
  1419. parseDots = R._parseDots = cacher(function (gradient) {
  1420. var dots = [];
  1421. for (var i = 0, ii = gradient.length; i < ii; i++) {
  1422. var dot = {},
  1423. par = gradient[i].match(/^([^:]*):?([\d\.]*)/);
  1424. dot.color = R.getRGB(par[1]);
  1425. if (dot.color.error) {
  1426. return null;
  1427. }
  1428. dot.color = dot.color.hex;
  1429. par[2] && (dot.offset = par[2] + "%");
  1430. dots.push(dot);
  1431. }
  1432. for (i = 1, ii = dots.length - 1; i < ii; i++) {
  1433. if (!dots[i].offset) {
  1434. var start = toFloat(dots[i - 1].offset || 0),
  1435. end = 0;
  1436. for (var j = i + 1; j < ii; j++) {
  1437. if (dots[j].offset) {
  1438. end = dots[j].offset;
  1439. break;
  1440. }
  1441. }
  1442. if (!end) {
  1443. end = 100;
  1444. j = ii;
  1445. }
  1446. end = toFloat(end);
  1447. var d = (end - start) / (j - i + 1);
  1448. for (; i < j; i++) {
  1449. start += d;
  1450. dots[i].offset = start + "%";
  1451. }
  1452. }
  1453. }
  1454. return dots;
  1455. }),
  1456. tear = R._tear = function (el, paper) {
  1457. el == paper.top && (paper.top = el.prev);
  1458. el == paper.bottom && (paper.bottom = el.next);
  1459. el.next && (el.next.prev = el.prev);
  1460. el.prev && (el.prev.next = el.next);
  1461. },
  1462. tofront = R._tofront = function (el, paper) {
  1463. if (paper.top === el) {
  1464. return;
  1465. }
  1466. tear(el, paper);
  1467. el.next = null;
  1468. el.prev = paper.top;
  1469. paper.top.next = el;
  1470. paper.top = el;
  1471. },
  1472. toback = R._toback = function (el, paper) {
  1473. if (paper.bottom === el) {
  1474. return;
  1475. }
  1476. tear(el, paper);
  1477. el.next = paper.bottom;
  1478. el.prev = null;
  1479. paper.bottom.prev = el;
  1480. paper.bottom = el;
  1481. },
  1482. insertafter = R._insertafter = function (el, el2, paper) {
  1483. tear(el, paper);
  1484. el2 == paper.top && (paper.top = el);
  1485. el2.next && (el2.next.prev = el);
  1486. el.next = el2.next;
  1487. el.prev = el2;
  1488. el2.next = el;
  1489. },
  1490. insertbefore = R._insertbefore = function (el, el2, paper) {
  1491. tear(el, paper);
  1492. el2 == paper.bottom && (paper.bottom = el);
  1493. el2.prev && (el2.prev.next = el);
  1494. el.prev = el2.prev;
  1495. el2.prev = el;
  1496. el.next = el2;
  1497. },
  1498. extractTransform = R._extractTransform = function (el, tstr) {
  1499. if (tstr == null) {
  1500. return el._.transform;
  1501. }
  1502. tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E);
  1503. var tdata = R.parseTransformString(tstr),
  1504. deg = 0,
  1505. dx = 0,
  1506. dy = 0,
  1507. sx = 1,
  1508. sy = 1,
  1509. _ = el._,
  1510. m = new Matrix;
  1511. _.transform = tdata || [];
  1512. if (tdata) {
  1513. for (var i = 0, ii = tdata.length; i < ii; i++) {
  1514. var t = tdata[i],
  1515. tlen = t.length,
  1516. command = Str(t[0]).toLowerCase(),
  1517. absolute = t[0] != command,
  1518. inver = absolute ? m.invert() : 0,
  1519. x1,
  1520. y1,
  1521. x2,
  1522. y2,
  1523. bb;
  1524. if (command == "t" && tlen == 3) {
  1525. if (absolute) {
  1526. x1 = inver.x(0, 0);
  1527. y1 = inver.y(0, 0);
  1528. x2 = inver.x(t[1], t[2]);
  1529. y2 = inver.y(t[1], t[2]);
  1530. m.translate(x2 - x1, y2 - y1);
  1531. } else {
  1532. m.translate(t[1], t[2]);
  1533. }
  1534. } else if (command == "r") {
  1535. if (tlen == 2) {
  1536. bb = bb || el.getBBox(1);
  1537. m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  1538. deg += t[1];
  1539. } else if (tlen == 4) {
  1540. if (absolute) {
  1541. x2 = inver.x(t[2], t[3]);
  1542. y2 = inver.y(t[2], t[3]);
  1543. m.rotate(t[1], x2, y2);
  1544. } else {
  1545. m.rotate(t[1], t[2], t[3]);
  1546. }
  1547. deg += t[1];
  1548. }
  1549. } else if (command == "s") {
  1550. if (tlen == 2 || tlen == 3) {
  1551. bb = bb || el.getBBox(1);
  1552. m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2);
  1553. sx *= t[1];
  1554. sy *= t[tlen - 1];
  1555. } else if (tlen == 5) {
  1556. if (absolute) {
  1557. x2 = inver.x(t[3], t[4]);
  1558. y2 = inver.y(t[3], t[4]);
  1559. m.scale(t[1], t[2], x2, y2);
  1560. } else {
  1561. m.scale(t[1], t[2], t[3], t[4]);
  1562. }
  1563. sx *= t[1];
  1564. sy *= t[2];
  1565. }
  1566. } else if (command == "m" && tlen == 7) {
  1567. m.add(t[1], t[2], t[3], t[4], t[5], t[6]);
  1568. }
  1569. _.dirtyT = 1;
  1570. el.matrix = m;
  1571. }
  1572. }
  1573. el.matrix = m;
  1574. _.sx = sx;
  1575. _.sy = sy;
  1576. _.deg = deg;
  1577. _.dx = dx = m.e;
  1578. _.dy = dy = m.f;
  1579. if (sx == 1 && sy == 1 && !deg && _.bbox) {
  1580. _.bbox.x += +dx;
  1581. _.bbox.y += +dy;
  1582. } else {
  1583. _.dirtyT = 1;
  1584. }
  1585. },
  1586. getEmpty = function (item) {
  1587. var l = item[0];
  1588. switch (l.toLowerCase()) {
  1589. case "t": return [l, 0, 0];
  1590. case "m": return [l, 1, 0, 0, 1, 0, 0];
  1591. case "r": if (item.length == 4) {
  1592. return [l, 0, item[2], item[3]];
  1593. } else {
  1594. return [l, 0];
  1595. }
  1596. case "s": if (item.length == 5) {
  1597. return [l, 1, 1, item[3], item[4]];
  1598. } else if (item.length == 3) {
  1599. return [l, 1, 1];
  1600. } else {
  1601. return [l, 1];
  1602. }
  1603. }
  1604. },
  1605. equaliseTransform = R._equaliseTransform = function (t1, t2) {
  1606. t2 = Str(t2).replace(/\.{3}|\u2026/g, t1);
  1607. t1 = R.parseTransformString(t1) || [];
  1608. t2 = R.parseTransformString(t2) || [];
  1609. var maxlength = mmax(t1.length, t2.length),
  1610. from = [],
  1611. to = [],
  1612. i = 0, j, jj,
  1613. tt1, tt2;
  1614. for (; i < maxlength; i++) {
  1615. tt1 = t1[i] || getEmpty(t2[i]);
  1616. tt2 = t2[i] || getEmpty(tt1);
  1617. if ((tt1[0] != tt2[0]) ||
  1618. (tt1[0].toLowerCase() == "r" && (tt1[2] != tt2[2] || tt1[3] != tt2[3])) ||
  1619. (tt1[0].toLowerCase() == "s" && (tt1[3] != tt2[3] || tt1[4] != tt2[4]))
  1620. ) {
  1621. return;
  1622. }
  1623. from[i] = [];
  1624. to[i] = [];
  1625. for (j = 0, jj = mmax(tt1.length, tt2.length); j < jj; j++) {
  1626. j in tt1 && (from[i][j] = tt1[j]);
  1627. j in tt2 && (to[i][j] = tt2[j]);
  1628. }
  1629. }
  1630. return {
  1631. from: from,
  1632. to: to
  1633. };
  1634. };
  1635. R._getContainer = function (x, y, w, h) {
  1636. var container;
  1637. container = h == null && !R.is(x, "object") ? g.doc.getElementById(x) : x;
  1638. if (container == null) {
  1639. return;
  1640. }
  1641. if (container.tagName) {
  1642. if (y == null) {
  1643. return {
  1644. container: container,
  1645. width: container.style.pixelWidth || container.offsetWidth,
  1646. height: container.style.pixelHeight || container.offsetHeight
  1647. };
  1648. } else {
  1649. return {
  1650. container: container,
  1651. width: y,
  1652. height: w
  1653. };
  1654. }
  1655. }
  1656. return {
  1657. container: 1,
  1658. x: x,
  1659. y: y,
  1660. width: w,
  1661. height: h
  1662. };
  1663. };
  1664. R.pathToRelative = pathToRelative;
  1665. R._engine = {};
  1666. R.path2curve = path2curve;
  1667. R.matrix = function (a, b, c, d, e, f) {
  1668. return new Matrix(a, b, c, d, e, f);
  1669. };
  1670. function Matrix(a, b, c, d, e, f) {
  1671. if (a != null) {
  1672. this.a = +a;
  1673. this.b = +b;
  1674. this.c = +c;
  1675. this.d = +d;
  1676. this.e = +e;
  1677. this.f = +f;
  1678. } else {
  1679. this.a = 1;
  1680. this.b = 0;
  1681. this.c = 0;
  1682. this.d = 1;
  1683. this.e = 0;
  1684. this.f = 0;
  1685. }
  1686. }
  1687. (function (matrixproto) {
  1688. matrixproto.add = function (a, b, c, d, e, f) {
  1689. var out = [[], [], []],
  1690. m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]],
  1691. matrix = [[a, c, e], [b, d, f], [0, 0, 1]],
  1692. x, y, z, res;
  1693. if (a && a instanceof Matrix) {
  1694. matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]];
  1695. }
  1696. for (x = 0; x < 3; x++) {
  1697. for (y = 0; y < 3; y++) {
  1698. res = 0;
  1699. for (z = 0; z < 3; z++) {
  1700. res += m[x][z] * matrix[z][y];
  1701. }
  1702. out[x][y] = res;
  1703. }
  1704. }
  1705. this.a = out[0][0];
  1706. this.b = out[1][0];
  1707. this.c = out[0][1];
  1708. this.d = out[1][1];
  1709. this.e = out[0][2];
  1710. this.f = out[1][2];
  1711. };
  1712. matrixproto.invert = function () {
  1713. var me = this,
  1714. x = me.a * me.d - me.b * me.c;
  1715. 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);
  1716. };
  1717. matrixproto.clone = function () {
  1718. return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
  1719. };
  1720. matrixproto.translate = function (x, y) {
  1721. this.add(1, 0, 0, 1, x, y);
  1722. };
  1723. matrixproto.scale = function (x, y, cx, cy) {
  1724. y == null && (y = x);
  1725. (cx || cy) && this.add(1, 0, 0, 1, cx, cy);
  1726. this.add(x, 0, 0, y, 0, 0);
  1727. (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy);
  1728. };
  1729. matrixproto.rotate = function (a, x, y) {
  1730. a = R.rad(a);
  1731. x = x || 0;
  1732. y = y || 0;
  1733. var cos = +math.cos(a).toFixed(9),
  1734. sin = +math.sin(a).toFixed(9);
  1735. this.add(cos, sin, -sin, cos, x, y);
  1736. this.add(1, 0, 0, 1, -x, -y);
  1737. };
  1738. matrixproto.x = function (x, y) {
  1739. return x * this.a + y * this.c + this.e;
  1740. };
  1741. matrixproto.y = function (x, y) {
  1742. return x * this.b + y * this.d + this.f;
  1743. };
  1744. matrixproto.get = function (i) {
  1745. return +this[Str.fromCharCode(97 + i)].toFixed(4);
  1746. };
  1747. matrixproto.toString = function () {
  1748. return R.svg ?
  1749. "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")" :
  1750. [this.get(0), this.get(2), this.get(1), this.get(3), 0, 0].join();
  1751. };
  1752. matrixproto.toFilter = function () {
  1753. return "progid:DXImageTransform.Microsoft.Matrix(M11=" + this.get(0) +
  1754. ", M12=" + this.get(2) + ", M21=" + this.get(1) + ", M22=" + this.get(3) +
  1755. ", Dx=" + this.get(4) + ", Dy=" + this.get(5) + ", sizingmethod='auto expand')";
  1756. };
  1757. matrixproto.offset = function () {
  1758. return [this.e.toFixed(4), this.f.toFixed(4)];
  1759. };
  1760. function norm(a) {
  1761. return a[0] * a[0] + a[1] * a[1];
  1762. }
  1763. function normalize(a) {
  1764. var mag = math.sqrt(norm(a));
  1765. a[0] && (a[0] /= mag);
  1766. a[1] && (a[1] /= mag);
  1767. }
  1768. matrixproto.split = function () {
  1769. var out = {};
  1770. // translation
  1771. out.dx = this.e;
  1772. out.dy = this.f;
  1773. // scale and shear
  1774. var row = [[this.a, this.c], [this.b, this.d]];
  1775. out.scalex = math.sqrt(norm(row[0]));
  1776. normalize(row[0]);
  1777. out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1];
  1778. row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear];
  1779. out.scaley = math.sqrt(norm(row[1]));
  1780. normalize(row[1]);
  1781. out.shear /= out.scaley;
  1782. // rotation
  1783. var sin = -row[0][1],
  1784. cos = row[1][1];
  1785. if (cos < 0) {
  1786. out.rotate = R.deg(math.acos(cos));
  1787. if (sin < 0) {
  1788. out.rotate = 360 - out.rotate;
  1789. }
  1790. } else {
  1791. out.rotate = R.deg(math.asin(sin));
  1792. }
  1793. out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
  1794. out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate;
  1795. out.noRotation = !+out.shear.toFixed(9) && !out.rotate;
  1796. return out;
  1797. };
  1798. matrixproto.toTransformString = function (shorter) {
  1799. var s = shorter || this[split]();
  1800. if (s.isSimple) {
  1801. s.scalex = +s.scalex.toFixed(4);
  1802. s.scaley = +s.scaley.toFixed(4);
  1803. s.rotate = +s.rotate.toFixed(4);
  1804. return (s.dx && s.dy ? "t" + [s.dx, s.dy] : E) +
  1805. (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) +
  1806. (s.rotate ? "r" + [s.rotate, 0, 0] : E);
  1807. } else {
  1808. return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)];
  1809. }
  1810. };
  1811. })(Matrix.prototype);
  1812. // WebKit rendering bug workaround method
  1813. var version = navigator.userAgent.match(/Version\/(.*?)\s/) || navigator.userAgent.match(/Chrome\/(\d+)/);
  1814. if ((navigator.vendor == "Apple Computer, Inc.") && (version && version[1] < 4 || navigator.platform.slice(0, 2) == "iP") ||
  1815. (navigator.vendor == "Google Inc." && version && version[1] < 8)) {
  1816. paperproto.safari = function () {
  1817. var rect = this.rect(-99, -99, this.width + 99, this.height + 99).attr({stroke: "none"});
  1818. setTimeout(function () {rect.remove();});
  1819. };
  1820. } else {
  1821. paperproto.safari = fun;
  1822. }
  1823. var preventDefault = function () {
  1824. this.returnValue = false;
  1825. },
  1826. preventTouch = function () {
  1827. return this.originalEvent.preventDefault();
  1828. },
  1829. stopPropagation = function () {
  1830. this.cancelBubble = true;
  1831. },
  1832. stopTouch = function () {
  1833. return this.originalEvent.stopPropagation();
  1834. },
  1835. addEvent = (function () {
  1836. if (g.doc.addEventListener) {
  1837. return function (obj, type, fn, element) {
  1838. var realName = supportsTouch && touchMap[type] ? touchMap[type] : type,
  1839. f = function (e) {
  1840. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  1841. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  1842. x = e.clientX + scrollX,
  1843. y = e.clientY + scrollY;
  1844. if (supportsTouch && touchMap[has](type)) {
  1845. for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) {
  1846. if (e.targetTouches[i].target == obj) {
  1847. var olde = e;
  1848. e = e.targetTouches[i];
  1849. e.originalEvent = olde;
  1850. e.preventDefault = preventTouch;
  1851. e.stopPropagation = stopTouch;
  1852. break;
  1853. }
  1854. }
  1855. }
  1856. return fn.call(element, e, x, y);
  1857. };
  1858. obj.addEventListener(realName, f, false);
  1859. return function () {
  1860. obj.removeEventListener(realName, f, false);
  1861. return true;
  1862. };
  1863. };
  1864. } else if (g.doc.attachEvent) {
  1865. return function (obj, type, fn, element) {
  1866. var f = function (e) {
  1867. e = e || g.win.event;
  1868. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  1869. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  1870. x = e.clientX + scrollX,
  1871. y = e.clientY + scrollY;
  1872. e.preventDefault = e.preventDefault || preventDefault;
  1873. e.stopPropagation = e.stopPropagation || stopPropagation;
  1874. return fn.call(element, e, x, y);
  1875. };
  1876. obj.attachEvent("on" + type, f);
  1877. var detacher = function () {
  1878. obj.detachEvent("on" + type, f);
  1879. return true;
  1880. };
  1881. return detacher;
  1882. };
  1883. }
  1884. })(),
  1885. drag = [],
  1886. dragMove = function (e) {
  1887. var x = e.clientX,
  1888. y = e.clientY,
  1889. scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  1890. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft,
  1891. dragi,
  1892. j = drag.length;
  1893. while (j--) {
  1894. dragi = drag[j];
  1895. if (supportsTouch) {
  1896. var i = e.touches.length,
  1897. touch;
  1898. while (i--) {
  1899. touch = e.touches[i];
  1900. if (touch.identifier == dragi.el._drag.id) {
  1901. x = touch.clientX;
  1902. y = touch.clientY;
  1903. (e.originalEvent ? e.originalEvent : e).preventDefault();
  1904. break;
  1905. }
  1906. }
  1907. } else {
  1908. e.preventDefault();
  1909. }
  1910. var node = dragi.el.node,
  1911. o,
  1912. next = node.nextSibling,
  1913. parent = node.parentNode,
  1914. display = node.style.display;
  1915. g.win.opera && parent.removeChild(node);
  1916. node.style.display = "none";
  1917. o = dragi.el.paper.getElementByPoint(x, y);
  1918. node.style.display = display;
  1919. g.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node));
  1920. o && eve("drag.over." + dragi.el.id, dragi.el, o);
  1921. x += scrollX;
  1922. y += scrollY;
  1923. eve("drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e);
  1924. }
  1925. },
  1926. dragUp = function (e) {
  1927. R.unmousemove(dragMove).unmouseup(dragUp);
  1928. var i = drag.length,
  1929. dragi;
  1930. while (i--) {
  1931. dragi = drag[i];
  1932. dragi.el._drag = {};
  1933. eve("drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e);
  1934. }
  1935. drag = [];
  1936. },
  1937. elproto = R.el = {};
  1938. for (var i = events.length; i--;) {
  1939. (function (eventName) {
  1940. R[eventName] = elproto[eventName] = function (fn, scope) {
  1941. if (R.is(fn, "function")) {
  1942. this.events = this.events || [];
  1943. this.events.push({name: eventName, f: fn, unbind: addEvent(this.shape || this.node || g.doc, eventName, fn, scope || this)});
  1944. }
  1945. return this;
  1946. };
  1947. R["un" + eventName] = elproto["un" + eventName] = function (fn) {
  1948. var events = this.events,
  1949. l = events.length;
  1950. while (l--) if (events[l].name == eventName && events[l].f == fn) {
  1951. events[l].unbind();
  1952. events.splice(l, 1);
  1953. !events.length && delete this.events;
  1954. return this;
  1955. }
  1956. return this;
  1957. };
  1958. })(events[i]);
  1959. }
  1960. elproto.data = function (key, value) {
  1961. var data = eldata[this.id] = eldata[this.id] || {};
  1962. if (arguments.length == 1) {
  1963. if (R.is(key, "object")) {
  1964. for (var i in key) if (key[has](i)) {
  1965. this.data(i, key[i]);
  1966. }
  1967. return this;
  1968. }
  1969. eve("data.get." + this.id, this, data[key], key);
  1970. return data[key];
  1971. }
  1972. data[key] = value;
  1973. eve("data.set." + this.id, this, value, key);
  1974. return this;
  1975. };
  1976. elproto.removeData = function (key) {
  1977. if (key == null) {
  1978. eldata[this.id] = {};
  1979. } else {
  1980. eldata[this.id] && delete eldata[this.id][key];
  1981. }
  1982. return this;
  1983. };
  1984. elproto.hover = function (f_in, f_out, scope_in, scope_out) {
  1985. return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in);
  1986. };
  1987. elproto.unhover = function (f_in, f_out) {
  1988. return this.unmouseover(f_in).unmouseout(f_out);
  1989. };
  1990. var draggable = [];
  1991. elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) {
  1992. function start(e) {
  1993. (e.originalEvent || e).preventDefault();
  1994. var scrollY = g.doc.documentElement.scrollTop || g.doc.body.scrollTop,
  1995. scrollX = g.doc.documentElement.scrollLeft || g.doc.body.scrollLeft;
  1996. this._drag.x = e.clientX + scrollX;
  1997. this._drag.y = e.clientY + scrollY;
  1998. this._drag.id = e.identifier;
  1999. !drag.length && R.mousemove(dragMove).mouseup(dragUp);
  2000. drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope});
  2001. onstart && eve.on("drag.start." + this.id, onstart);
  2002. onmove && eve.on("drag.move." + this.id, onmove);
  2003. onend && eve.on("drag.end." + this.id, onend);
  2004. eve("drag.start." + this.id, start_scope || move_scope || this, e.clientX + scrollX, e.clientY + scrollY, e);
  2005. }
  2006. this._drag = {};
  2007. draggable.push({el: this, start: start});
  2008. this.mousedown(start);
  2009. return this;
  2010. };
  2011. elproto.onDragOver = function (f) {
  2012. f ? eve.on("drag.over." + this.id, f) : eve.unbind("drag.over." + this.id);
  2013. };
  2014. elproto.undrag = function () {
  2015. var i = draggable.length;
  2016. while (i--) if (draggable[i].el == this) {
  2017. this.unmousedown(draggable[i].start);
  2018. draggable.splice(i, 1);
  2019. eve.unbind("drag.*." + this.id);
  2020. }
  2021. !draggable.length && R.unmousemove(dragMove).unmouseup(dragUp);
  2022. };
  2023. paperproto.circle = function (x, y, r) {
  2024. var out = R._engine.circle(this, x || 0, y || 0, r || 0);
  2025. this.__set__ && this.__set__.push(out);
  2026. return out;
  2027. };
  2028. paperproto.rect = function (x, y, w, h, r) {
  2029. var out = R._engine.rect(this, x || 0, y || 0, w || 0, h || 0, r || 0);
  2030. this.__set__ && this.__set__.push(out);
  2031. return out;
  2032. };
  2033. paperproto.ellipse = function (x, y, rx, ry) {
  2034. var out = R._engine.ellipse(this, x || 0, y || 0, rx || 0, ry || 0);
  2035. this.__set__ && this.__set__.push(out);
  2036. return out;
  2037. };
  2038. paperproto.path = function (pathString) {
  2039. pathString && !R.is(pathString, string) && !R.is(pathString[0], array) && (pathString += E);
  2040. var out = R._engine.path(R.format[apply](R, arguments), this);
  2041. this.__set__ && this.__set__.push(out);
  2042. return out;
  2043. };
  2044. paperproto.image = function (src, x, y, w, h) {
  2045. var out = R._engine.image(this, src || "about:blank", x || 0, y || 0, w || 0, h || 0);
  2046. this.__set__ && this.__set__.push(out);
  2047. return out;
  2048. };
  2049. paperproto.text = function (x, y, text) {
  2050. var out = R._engine.text(this, x || 0, y || 0, Str(text));
  2051. this.__set__ && this.__set__.push(out);
  2052. return out;
  2053. };
  2054. paperproto.set = function (itemsArray) {
  2055. !R.is(itemsArray, "array") && (itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length));
  2056. var out = new Set(itemsArray);
  2057. this.__set__ && this.__set__.push(out);
  2058. return out;
  2059. };
  2060. paperproto.setStart = function (set) {
  2061. this.__set__ = set || this.set();
  2062. };
  2063. paperproto.setFinish = function (set) {
  2064. var out = this.__set__;
  2065. delete this.__set__;
  2066. return out;
  2067. };
  2068. paperproto.setSize = function (width, height) {
  2069. return R._engine.setSize.call(this, width, height);
  2070. };
  2071. paperproto.setViewBox = function (x, y, w, h, fit) {
  2072. return R._engine.setViewBox.call(this, x, y, w, h, fit);
  2073. };
  2074. paperproto.top = paperproto.bottom = null;
  2075. paperproto.raphael = R;
  2076. var getOffset = function (elem) {
  2077. var box = elem.getBoundingClientRect(),
  2078. doc = elem.ownerDocument,
  2079. body = doc.body,
  2080. docElem = doc.documentElement,
  2081. clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
  2082. top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop,
  2083. left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft;
  2084. return {
  2085. y: top,
  2086. x: left
  2087. };
  2088. };
  2089. paperproto.getElementByPoint = function (x, y) {
  2090. var paper = this,
  2091. svg = paper.canvas,
  2092. target = g.doc.elementFromPoint(x, y);
  2093. if (g.win.opera && target.tagName == "svg") {
  2094. var so = getOffset(svg),
  2095. sr = svg.createSVGRect();
  2096. sr.x = x - so.x;
  2097. sr.y = y - so.y;
  2098. sr.width = sr.height = 1;
  2099. var hits = svg.getIntersectionList(sr, null);
  2100. if (hits.length) {
  2101. target = hits[hits.length - 1];
  2102. }
  2103. }
  2104. if (!target) {
  2105. return null;
  2106. }
  2107. while (target.parentNode && target != svg.parentNode && !target.raphael) {
  2108. target = target.parentNode;
  2109. }
  2110. target == paper.canvas.parentNode && (target = svg);
  2111. target = target && target.raphael ? paper.getById(target.raphaelid) : null;
  2112. return target;
  2113. };
  2114. paperproto.getById = function (id) {
  2115. var bot = this.bottom;
  2116. while (bot) {
  2117. if (bot.id == id) {
  2118. return bot;
  2119. }
  2120. bot = bot.next;
  2121. }
  2122. return null;
  2123. };
  2124. paperproto.forEach = function (callback, thisArg) {
  2125. var bot = this.bottom;
  2126. while (bot) {
  2127. if (callback.call(thisArg, bot) === false) {
  2128. return this;
  2129. }
  2130. bot = bot.next;
  2131. }
  2132. return this;
  2133. };
  2134. function x_y() {
  2135. return this.x + S + this.y;
  2136. }
  2137. function x_y_w_h() {
  2138. return this.x + S + this.y + S + this.width + " \xd7 " + this.height;
  2139. }
  2140. elproto.getBBox = function (isWithoutTransform) {
  2141. if (this.removed) {
  2142. return {};
  2143. }
  2144. var _ = this._;
  2145. if (isWithoutTransform) {
  2146. if (_.dirty || !_.bboxwt) {
  2147. this.realPath = getPath[this.type](this);
  2148. _.bboxwt = pathDimensions(this.realPath);
  2149. _.bboxwt.toString = x_y_w_h;
  2150. _.dirty = 0;
  2151. }
  2152. return _.bboxwt;
  2153. }
  2154. if (_.dirty || _.dirtyT || !_.bbox) {
  2155. if (_.dirty || !this.realPath) {
  2156. _.bboxwt = 0;
  2157. this.realPath = getPath[this.type](this);
  2158. }
  2159. _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
  2160. _.bbox.toString = x_y_w_h;
  2161. _.dirty = _.dirtyT = 0;
  2162. }
  2163. return _.bbox;
  2164. };
  2165. elproto.clone = function () {
  2166. if (this.removed) {
  2167. return null;
  2168. }
  2169. var out = this.paper[this.type]().attr(this.attr());
  2170. this.__set__ && this.__set__.push(out);
  2171. return out;
  2172. };
  2173. elproto.glow = function (glow) {
  2174. if (this.type == "text") {
  2175. return null;
  2176. }
  2177. glow = glow || {};
  2178. var s = {
  2179. width: (glow.width || 10) + (+this.attr("stroke-width") || 1),
  2180. fill: glow.fill || false,
  2181. opacity: glow.opacity || .5,
  2182. offsetx: glow.offsetx || 0,
  2183. offsety: glow.offsety || 0,
  2184. color: glow.color || "#000"
  2185. },
  2186. c = s.width / 2,
  2187. r = this.paper,
  2188. out = r.set(),
  2189. path = this.realPath || getPath[this.type](this);
  2190. path = this.matrix ? mapPath(path, this.matrix) : path;
  2191. for (var i = 1; i < c + 1; i++) {
  2192. out.push(r.path(path).attr({
  2193. stroke: s.color,
  2194. fill: s.fill ? s.color : "none",
  2195. "stroke-linejoin": "round",
  2196. "stroke-linecap": "round",
  2197. "stroke-width": +(s.width / c * i).toFixed(3),
  2198. opacity: +(s.opacity / c).toFixed(3)
  2199. }));
  2200. }
  2201. return out.insertBefore(this).translate(s.offsetx, s.offsety);
  2202. };
  2203. var curveslengths = {},
  2204. getPointAtSegmentLength = function (p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  2205. var len = 0,
  2206. precision = 100,
  2207. name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join(),
  2208. cache = curveslengths[name],
  2209. old, dot;
  2210. !cache && (curveslengths[name] = cache = {data: []});
  2211. cache.timer && clearTimeout(cache.timer);
  2212. cache.timer = setTimeout(function () {delete curveslengths[name];}, 2e3);
  2213. if (length != null && !cache.precision) {
  2214. var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
  2215. cache.precision = ~~total * 10;
  2216. cache.data = [];
  2217. }
  2218. precision = cache.precision || precision;
  2219. for (var i = 0; i < precision + 1; i++) {
  2220. if (cache.data[i * precision]) {
  2221. dot = cache.data[i * precision];
  2222. } else {
  2223. dot = R.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
  2224. cache.data[i * precision] = dot;
  2225. }
  2226. i && (len += pow(pow(old.x - dot.x, 2) + pow(old.y - dot.y, 2), .5));
  2227. if (length != null && len >= length) {
  2228. return dot;
  2229. }
  2230. old = dot;
  2231. }
  2232. if (length == null) {
  2233. return len;
  2234. }
  2235. },
  2236. getLengthFactory = function (istotal, subpath) {
  2237. return function (path, length, onlystart) {
  2238. path = path2curve(path);
  2239. var x, y, p, l, sp = "", subpaths = {}, point,
  2240. len = 0;
  2241. for (var i = 0, ii = path.length; i < ii; i++) {
  2242. p = path[i];
  2243. if (p[0] == "M") {
  2244. x = +p[1];
  2245. y = +p[2];
  2246. } else {
  2247. l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  2248. if (len + l > length) {
  2249. if (subpath && !subpaths.start) {
  2250. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  2251. sp += ["C" + point.start.x, point.start.y, point.m.x, point.m.y, point.x, point.y];
  2252. if (onlystart) {return sp;}
  2253. subpaths.start = sp;
  2254. sp = ["M" + point.x, point.y + "C" + point.n.x, point.n.y, point.end.x, point.end.y, p[5], p[6]].join();
  2255. len += l;
  2256. x = +p[5];
  2257. y = +p[6];
  2258. continue;
  2259. }
  2260. if (!istotal && !subpath) {
  2261. point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  2262. return {x: point.x, y: point.y, alpha: point.alpha};
  2263. }
  2264. }
  2265. len += l;
  2266. x = +p[5];
  2267. y = +p[6];
  2268. }
  2269. sp += p.shift() + p;
  2270. }
  2271. subpaths.end = sp;
  2272. point = istotal ? len : subpath ? subpaths : R.findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1);
  2273. point.alpha && (point = {x: point.x, y: point.y, alpha: point.alpha});
  2274. return point;
  2275. };
  2276. };
  2277. var getTotalLength = getLengthFactory(1),
  2278. getPointAtLength = getLengthFactory(),
  2279. getSubpathsAtLength = getLengthFactory(0, 1);
  2280. R.getTotalLength = getTotalLength;
  2281. R.getPointAtLength = getPointAtLength;
  2282. R.getSubpath = function (path, from, to) {
  2283. if (this.getTotalLength(path) - to < 1e-6) {
  2284. return getSubpathsAtLength(path, from).end;
  2285. }
  2286. var a = getSubpathsAtLength(path, to, 1);
  2287. return from ? getSubpathsAtLength(a, from).end : a;
  2288. };
  2289. elproto.getTotalLength = function () {
  2290. if (this.type != "path") {return;}
  2291. if (this.node.getTotalLength) {
  2292. return this.node.getTotalLength();
  2293. }
  2294. return getTotalLength(this.attrs.path);
  2295. };
  2296. elproto.getPointAtLength = function (length) {
  2297. if (this.type != "path") {return;}
  2298. return getPointAtLength(this.attrs.path, length);
  2299. };
  2300. elproto.getSubpath = function (from, to) {
  2301. if (this.type != "path") {return;}
  2302. return R.getSubpath(this.attrs.path, from, to);
  2303. };
  2304. var ef = R.easing_formulas = {
  2305. linear: function (n) {
  2306. return n;
  2307. },
  2308. "<": function (n) {
  2309. return pow(n, 1.7);
  2310. },
  2311. ">": function (n) {
  2312. return pow(n, .48);
  2313. },
  2314. "<>": function (n) {
  2315. var q = .48 - n / 1.04,
  2316. Q = math.sqrt(.1734 + q * q),
  2317. x = Q - q,
  2318. X = pow(abs(x), 1 / 3) * (x < 0 ? -1 : 1),
  2319. y = -Q - q,
  2320. Y = pow(abs(y), 1 / 3) * (y < 0 ? -1 : 1),
  2321. t = X + Y + .5;
  2322. return (1 - t) * 3 * t * t + t * t * t;
  2323. },
  2324. backIn: function (n) {
  2325. var s = 1.70158;
  2326. return n * n * ((s + 1) * n - s);
  2327. },
  2328. backOut: function (n) {
  2329. n = n - 1;
  2330. var s = 1.70158;
  2331. return n * n * ((s + 1) * n + s) + 1;
  2332. },
  2333. elastic: function (n) {
  2334. if (n == !!n) {
  2335. return n;
  2336. }
  2337. return pow(2, -10 * n) * math.sin((n - .075) * (2 * PI) / .3) + 1;
  2338. },
  2339. bounce: function (n) {
  2340. var s = 7.5625,
  2341. p = 2.75,
  2342. l;
  2343. if (n < (1 / p)) {
  2344. l = s * n * n;
  2345. } else {
  2346. if (n < (2 / p)) {
  2347. n -= (1.5 / p);
  2348. l = s * n * n + .75;
  2349. } else {
  2350. if (n < (2.5 / p)) {
  2351. n -= (2.25 / p);
  2352. l = s * n * n + .9375;
  2353. } else {
  2354. n -= (2.625 / p);
  2355. l = s * n * n + .984375;
  2356. }
  2357. }
  2358. }
  2359. return l;
  2360. }
  2361. };
  2362. ef.easeIn = ef["ease-in"] = ef["<"];
  2363. ef.easeOut = ef["ease-out"] = ef[">"];
  2364. ef.easeInOut = ef["ease-in-out"] = ef["<>"];
  2365. ef["back-in"] = ef.backIn;
  2366. ef["back-out"] = ef.backOut;
  2367. var animationElements = [],
  2368. requestAnimFrame = window.requestAnimationFrame ||
  2369. window.webkitRequestAnimationFrame ||
  2370. window.mozRequestAnimationFrame ||
  2371. window.oRequestAnimationFrame ||
  2372. window.msRequestAnimationFrame ||
  2373. function (callback) {
  2374. setTimeout(callback, 16);
  2375. },
  2376. animation = function () {
  2377. var Now = +new Date,
  2378. l = 0;
  2379. for (; l < animationElements.length; l++) {
  2380. var e = animationElements[l];
  2381. if (e.el.removed || e.paused) {
  2382. continue;
  2383. }
  2384. var time = Now - e.start,
  2385. ms = e.ms,
  2386. easing = e.easing,
  2387. from = e.from,
  2388. diff = e.diff,
  2389. to = e.to,
  2390. t = e.t,
  2391. that = e.el,
  2392. set = {},
  2393. now,
  2394. init = {},
  2395. key;
  2396. if (e.initstatus) {
  2397. time = (e.initstatus * e.anim.top - e.prev) / (e.percent - e.prev) * ms;
  2398. e.status = e.initstatus;
  2399. delete e.initstatus;
  2400. e.stop && animationElements.splice(l--, 1);
  2401. } else {
  2402. e.status = (e.prev + (e.percent - e.prev) * (time / ms)) / e.anim.top;
  2403. }
  2404. if (time < 0) {
  2405. continue;
  2406. }
  2407. if (time < ms) {
  2408. var pos = easing(time / ms);
  2409. for (var attr in from) if (from[has](attr)) {
  2410. switch (availableAnimAttrs[attr]) {
  2411. case nu:
  2412. now = +from[attr] + pos * ms * diff[attr];
  2413. break;
  2414. case "colour":
  2415. now = "rgb(" + [
  2416. upto255(round(from[attr].r + pos * ms * diff[attr].r)),
  2417. upto255(round(from[attr].g + pos * ms * diff[attr].g)),
  2418. upto255(round(from[attr].b + pos * ms * diff[attr].b))
  2419. ].join(",") + ")";
  2420. break;
  2421. case "path":
  2422. now = [];
  2423. for (var i = 0, ii = from[attr].length; i < ii; i++) {
  2424. now[i] = [from[attr][i][0]];
  2425. for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
  2426. now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
  2427. }
  2428. now[i] = now[i].join(S);
  2429. }
  2430. now = now.join(S);
  2431. break;
  2432. case "transform":
  2433. if (diff[attr].real) {
  2434. now = [];
  2435. for (i = 0, ii = from[attr].length; i < ii; i++) {
  2436. now[i] = [from[attr][i][0]];
  2437. for (j = 1, jj = from[attr][i].length; j < jj; j++) {
  2438. now[i][j] = from[attr][i][j] + pos * ms * diff[attr][i][j];
  2439. }
  2440. }
  2441. } else {
  2442. var get = function (i) {
  2443. return +from[attr][i] + pos * ms * diff[attr][i];
  2444. };
  2445. // now = [["r", get(2), 0, 0], ["t", get(3), get(4)], ["s", get(0), get(1), 0, 0]];
  2446. now = [["m", get(0), get(1), get(2), get(3), get(4), get(5)]];
  2447. }
  2448. break;
  2449. case "csv":
  2450. if (attr == "clip-rect") {
  2451. now = [];
  2452. i = 4;
  2453. while (i--) {
  2454. now[i] = +from[attr][i] + pos * ms * diff[attr][i];
  2455. }
  2456. }
  2457. break;
  2458. default:
  2459. var from2 = [][concat](from[attr]);
  2460. now = [];
  2461. i = that.paper.customAttributes[attr].length;
  2462. while (i--) {
  2463. now[i] = +from2[i] + pos * ms * diff[attr][i];
  2464. }
  2465. break;
  2466. }
  2467. set[attr] = now;
  2468. }
  2469. that.attr(set);
  2470. (function (id, that, anim) {
  2471. setTimeout(function () {
  2472. eve("anim.frame." + id, that, anim);
  2473. });
  2474. })(that.id, that, e.anim);
  2475. } else {
  2476. (function(f, el, a) {
  2477. setTimeout(function() {
  2478. eve("anim.frame." + el.id, el, a);
  2479. eve("anim.finish." + el.id, el, a);
  2480. R.is(f, "function") && f.call(el);
  2481. });
  2482. })(e.callback, that, e.anim);
  2483. that.attr(to);
  2484. animationElements.splice(l--, 1);
  2485. if (e.repeat > 1 && !e.next) {
  2486. for (key in to) if (to[has](key)) {
  2487. init[key] = e.totalOrigin[key];
  2488. }
  2489. e.el.attr(init);
  2490. runAnimation(e.anim, e.el, e.anim.percents[0], null, e.totalOrigin, e.repeat - 1);
  2491. }
  2492. if (e.next && !e.stop) {
  2493. runAnimation(e.anim, e.el, e.next, null, e.totalOrigin, e.repeat);
  2494. }
  2495. }
  2496. }
  2497. R.svg && that && that.paper && that.paper.safari();
  2498. animationElements.length && requestAnimFrame(animation);
  2499. },
  2500. upto255 = function (color) {
  2501. return color > 255 ? 255 : color < 0 ? 0 : color;
  2502. };
  2503. elproto.animateWith = function (element, anim, params, ms, easing, callback) {
  2504. var a = params ? R.animation(params, ms, easing, callback) : anim,
  2505. status = element.status(anim);
  2506. return this.animate(a).status(a, status * anim.ms / a.ms);
  2507. };
  2508. function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
  2509. var cx = 3 * p1x,
  2510. bx = 3 * (p2x - p1x) - cx,
  2511. ax = 1 - cx - bx,
  2512. cy = 3 * p1y,
  2513. by = 3 * (p2y - p1y) - cy,
  2514. ay = 1 - cy - by;
  2515. function sampleCurveX(t) {
  2516. return ((ax * t + bx) * t + cx) * t;
  2517. }
  2518. function solve(x, epsilon) {
  2519. var t = solveCurveX(x, epsilon);
  2520. return ((ay * t + by) * t + cy) * t;
  2521. }
  2522. function solveCurveX(x, epsilon) {
  2523. var t0, t1, t2, x2, d2, i;
  2524. for(t2 = x, i = 0; i < 8; i++) {
  2525. x2 = sampleCurveX(t2) - x;
  2526. if (abs(x2) < epsilon) {
  2527. return t2;
  2528. }
  2529. d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
  2530. if (abs(d2) < 1e-6) {
  2531. break;
  2532. }
  2533. t2 = t2 - x2 / d2;
  2534. }
  2535. t0 = 0;
  2536. t1 = 1;
  2537. t2 = x;
  2538. if (t2 < t0) {
  2539. return t0;
  2540. }
  2541. if (t2 > t1) {
  2542. return t1;
  2543. }
  2544. while (t0 < t1) {
  2545. x2 = sampleCurveX(t2);
  2546. if (abs(x2 - x) < epsilon) {
  2547. return t2;
  2548. }
  2549. if (x > x2) {
  2550. t0 = t2;
  2551. } else {
  2552. t1 = t2;
  2553. }
  2554. t2 = (t1 - t0) / 2 + t0;
  2555. }
  2556. return t2;
  2557. }
  2558. return solve(t, 1 / (200 * duration));
  2559. }
  2560. elproto.onAnimation = function (f) {
  2561. f ? eve.on("anim.frame." + this.id, f) : eve.unbind("anim.frame." + this.id);
  2562. return this;
  2563. };
  2564. function Animation(anim, ms) {
  2565. var percents = [],
  2566. newAnim = {};
  2567. this.ms = ms;
  2568. this.times = 1;
  2569. if (anim) {
  2570. for (var attr in anim) if (anim[has](attr)) {
  2571. newAnim[toFloat(attr)] = anim[attr];
  2572. percents.push(toFloat(attr));
  2573. }
  2574. percents.sort(sortByNumber);
  2575. }
  2576. this.anim = newAnim;
  2577. this.top = percents[percents.length - 1];
  2578. this.percents = percents;
  2579. }
  2580. Animation.prototype.delay = function (delay) {
  2581. var a = new Animation(this.anim, this.ms);
  2582. a.times = this.times;
  2583. a.del = +delay || 0;
  2584. return a;
  2585. };
  2586. Animation.prototype.repeat = function (times) {
  2587. var a = new Animation(this.anim, this.ms);
  2588. a.del = this.del;
  2589. a.times = math.floor(mmax(times, 0)) || 1;
  2590. return a;
  2591. };
  2592. function runAnimation(anim, element, percent, status, totalOrigin, times) {
  2593. percent = toFloat(percent);
  2594. var params,
  2595. isInAnim,
  2596. isInAnimSet,
  2597. percents = [],
  2598. next,
  2599. prev,
  2600. timestamp,
  2601. ms = anim.ms,
  2602. from = {},
  2603. to = {},
  2604. diff = {};
  2605. if (status) {
  2606. for (i = 0, ii = animationElements.length; i < ii; i++) {
  2607. var e = animationElements[i];
  2608. if (e.el.id == element.id && e.anim == anim) {
  2609. if (e.percent != percent) {
  2610. animationElements.splice(i, 1);
  2611. isInAnimSet = 1;
  2612. } else {
  2613. isInAnim = e;
  2614. }
  2615. element.attr(e.totalOrigin);
  2616. break;
  2617. }
  2618. }
  2619. } else {
  2620. status = +to; // NaN
  2621. }
  2622. for (var i = 0, ii = anim.percents.length; i < ii; i++) {
  2623. if (anim.percents[i] == percent || anim.percents[i] > status * anim.top) {
  2624. percent = anim.percents[i];
  2625. prev = anim.percents[i - 1] || 0;
  2626. ms = ms / anim.top * (percent - prev);
  2627. next = anim.percents[i + 1];
  2628. params = anim.anim[percent];
  2629. break;
  2630. } else if (status) {
  2631. element.attr(anim.anim[anim.percents[i]]);
  2632. }
  2633. }
  2634. if (!params) {
  2635. return;
  2636. }
  2637. if (!isInAnim) {
  2638. for (var attr in params) if (params[has](attr)) {
  2639. if (availableAnimAttrs[has](attr) || element.paper.customAttributes[has](attr)) {
  2640. from[attr] = element.attr(attr);
  2641. (from[attr] == null) && (from[attr] = availableAttrs[attr]);
  2642. to[attr] = params[attr];
  2643. switch (availableAnimAttrs[attr]) {
  2644. case nu:
  2645. diff[attr] = (to[attr] - from[attr]) / ms;
  2646. break;
  2647. case "colour":
  2648. from[attr] = R.getRGB(from[attr]);
  2649. var toColour = R.getRGB(to[attr]);
  2650. diff[attr] = {
  2651. r: (toColour.r - from[attr].r) / ms,
  2652. g: (toColour.g - from[attr].g) / ms,
  2653. b: (toColour.b - from[attr].b) / ms
  2654. };
  2655. break;
  2656. case "path":
  2657. var pathes = path2curve(from[attr], to[attr]),
  2658. toPath = pathes[1];
  2659. from[attr] = pathes[0];
  2660. diff[attr] = [];
  2661. for (i = 0, ii = from[attr].length; i < ii; i++) {
  2662. diff[attr][i] = [0];
  2663. for (var j = 1, jj = from[attr][i].length; j < jj; j++) {
  2664. diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
  2665. }
  2666. }
  2667. break;
  2668. case "transform":
  2669. var _ = element._,
  2670. eq = equaliseTransform(_[attr], to[attr]);
  2671. if (eq) {
  2672. from[attr] = eq.from;
  2673. to[attr] = eq.to;
  2674. diff[attr] = [];
  2675. diff[attr].real = true;
  2676. for (i = 0, ii = from[attr].length; i < ii; i++) {
  2677. diff[attr][i] = [from[attr][i][0]];
  2678. for (j = 1, jj = from[attr][i].length; j < jj; j++) {
  2679. diff[attr][i][j] = (to[attr][i][j] - from[attr][i][j]) / ms;
  2680. }
  2681. }
  2682. } else {
  2683. var m = (element.matrix || new Matrix),
  2684. to2 = {
  2685. _: {transform: _.transform},
  2686. getBBox: function () {
  2687. return element.getBBox(1);
  2688. }
  2689. };
  2690. from[attr] = [
  2691. m.a,
  2692. m.b,
  2693. m.c,
  2694. m.d,
  2695. m.e,
  2696. m.f
  2697. ];
  2698. extractTransform(to2, to[attr]);
  2699. to[attr] = to2._.transform;
  2700. diff[attr] = [
  2701. (to2.matrix.a - m.a) / ms,
  2702. (to2.matrix.b - m.b) / ms,
  2703. (to2.matrix.c - m.c) / ms,
  2704. (to2.matrix.d - m.d) / ms,
  2705. (to2.matrix.e - m.e) / ms,
  2706. (to2.matrix.e - m.f) / ms
  2707. ];
  2708. // from[attr] = [_.sx, _.sy, _.deg, _.dx, _.dy];
  2709. // var to2 = {_:{}, getBBox: function () { return element.getBBox(); }};
  2710. // extractTransform(to2, to[attr]);
  2711. // diff[attr] = [
  2712. // (to2._.sx - _.sx) / ms,
  2713. // (to2._.sy - _.sy) / ms,
  2714. // (to2._.deg - _.deg) / ms,
  2715. // (to2._.dx - _.dx) / ms,
  2716. // (to2._.dy - _.dy) / ms
  2717. // ];
  2718. }
  2719. break;
  2720. case "csv":
  2721. var values = Str(params[attr])[split](separator),
  2722. from2 = Str(from[attr])[split](separator);
  2723. if (attr == "clip-rect") {
  2724. from[attr] = from2;
  2725. diff[attr] = [];
  2726. i = from2.length;
  2727. while (i--) {
  2728. diff[attr][i] = (values[i] - from[attr][i]) / ms;
  2729. }
  2730. }
  2731. to[attr] = values;
  2732. break;
  2733. default:
  2734. values = [][concat](params[attr]);
  2735. from2 = [][concat](from[attr]);
  2736. diff[attr] = [];
  2737. i = element.paper.customAttributes[attr].length;
  2738. while (i--) {
  2739. diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
  2740. }
  2741. break;
  2742. }
  2743. }
  2744. }
  2745. var easing = params.easing,
  2746. easyeasy = R.easing_formulas[easing];
  2747. if (!easyeasy) {
  2748. easyeasy = Str(easing).match(bezierrg);
  2749. if (easyeasy && easyeasy.length == 5) {
  2750. var curve = easyeasy;
  2751. easyeasy = function (t) {
  2752. return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
  2753. };
  2754. } else {
  2755. easyeasy = pipe;
  2756. }
  2757. }
  2758. timestamp = params.start || anim.start || +new Date;
  2759. e = {
  2760. anim: anim,
  2761. percent: percent,
  2762. timestamp: timestamp,
  2763. start: timestamp + (anim.del || 0),
  2764. status: 0,
  2765. initstatus: status || 0,
  2766. stop: false,
  2767. ms: ms,
  2768. easing: easyeasy,
  2769. from: from,
  2770. diff: diff,
  2771. to: to,
  2772. el: element,
  2773. callback: params.callback,
  2774. prev: prev,
  2775. next: next,
  2776. repeat: times || anim.times,
  2777. origin: element.attr(),
  2778. totalOrigin: totalOrigin
  2779. };
  2780. animationElements.push(e);
  2781. if (status && !isInAnim && !isInAnimSet) {
  2782. e.stop = true;
  2783. e.start = new Date - ms * status;
  2784. if (animationElements.length == 1) {
  2785. return animation();
  2786. }
  2787. }
  2788. if (isInAnimSet) {
  2789. e.start = new Date - e.ms * status;
  2790. }
  2791. animationElements.length == 1 && requestAnimFrame(animation);
  2792. } else {
  2793. isInAnim.initstatus = status;
  2794. isInAnim.start = new Date - isInAnim.ms * status;
  2795. }
  2796. eve("anim.start." + element.id, element, anim);
  2797. }
  2798. R.animation = function (params, ms, easing, callback) {
  2799. if (params instanceof Animation) {
  2800. return params;
  2801. }
  2802. if (R.is(easing, "function") || !easing) {
  2803. callback = callback || easing || null;
  2804. easing = null;
  2805. }
  2806. params = Object(params);
  2807. ms = +ms || 0;
  2808. var p = {},
  2809. json,
  2810. attr;
  2811. for (attr in params) if (params[has](attr) && toFloat(attr) != attr && toFloat(attr) + "%" != attr) {
  2812. json = true;
  2813. p[attr] = params[attr];
  2814. }
  2815. if (!json) {
  2816. return new Animation(params, ms);
  2817. } else {
  2818. easing && (p.easing = easing);
  2819. callback && (p.callback = callback);
  2820. return new Animation({100: p}, ms);
  2821. }
  2822. };
  2823. elproto.animate = function (params, ms, easing, callback) {
  2824. var element = this;
  2825. if (element.removed) {
  2826. callback && callback.call(element);
  2827. return element;
  2828. }
  2829. var anim = params instanceof Animation ? params : R.animation(params, ms, easing, callback);
  2830. runAnimation(anim, element, anim.percents[0], null, element.attr());
  2831. return element;
  2832. };
  2833. elproto.setTime = function (anim, value) {
  2834. if (anim && value != null) {
  2835. this.status(anim, mmin(value, anim.ms) / anim.ms);
  2836. }
  2837. return this;
  2838. };
  2839. elproto.status = function (anim, value) {
  2840. var out = [],
  2841. i = 0,
  2842. len,
  2843. e;
  2844. if (value != null) {
  2845. runAnimation(anim, this, -1, mmin(value, 1));
  2846. return this;
  2847. } else {
  2848. len = animationElements.length;
  2849. for (; i < len; i++) {
  2850. e = animationElements[i];
  2851. if (e.el.id == this.id && (!anim || e.anim == anim)) {
  2852. if (anim) {
  2853. return e.status;
  2854. }
  2855. out.push({
  2856. anim: e.anim,
  2857. status: e.status
  2858. });
  2859. }
  2860. }
  2861. if (anim) {
  2862. return 0;
  2863. }
  2864. return out;
  2865. }
  2866. };
  2867. elproto.pause = function (anim) {
  2868. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  2869. if (eve("anim.pause." + this.id, this, animationElements[i].anim) !== false) {
  2870. animationElements[i].paused = true;
  2871. }
  2872. }
  2873. return this;
  2874. };
  2875. elproto.resume = function (anim) {
  2876. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  2877. var e = animationElements[i];
  2878. if (eve("anim.resume." + this.id, this, e.anim) !== false) {
  2879. delete e.paused;
  2880. this.status(e.anim, e.status);
  2881. }
  2882. }
  2883. return this;
  2884. };
  2885. elproto.stop = function (anim) {
  2886. for (var i = 0; i < animationElements.length; i++) if (animationElements[i].el.id == this.id && (!anim || animationElements[i].anim == anim)) {
  2887. if (eve("anim.stop." + this.id, this, animationElements[i].anim) !== false) {
  2888. animationElements.splice(i--, 1);
  2889. }
  2890. }
  2891. return this;
  2892. };
  2893. elproto.toString = function () {
  2894. return "Rapha\xebl\u2019s object";
  2895. };
  2896. // Set
  2897. var Set = function (items) {
  2898. this.items = [];
  2899. this.length = 0;
  2900. this.type = "set";
  2901. if (items) {
  2902. for (var i = 0, ii = items.length; i < ii; i++) {
  2903. if (items[i] && (items[i].constructor == elproto.constructor || items[i].constructor == Set)) {
  2904. this[this.items.length] = this.items[this.items.length] = items[i];
  2905. this.length++;
  2906. }
  2907. }
  2908. }
  2909. },
  2910. setproto = Set.prototype;
  2911. setproto.push = function () {
  2912. var item,
  2913. len;
  2914. for (var i = 0, ii = arguments.length; i < ii; i++) {
  2915. item = arguments[i];
  2916. if (item && (item.constructor == elproto.constructor || item.constructor == Set)) {
  2917. len = this.items.length;
  2918. this[len] = this.items[len] = item;
  2919. this.length++;
  2920. }
  2921. }
  2922. return this;
  2923. };
  2924. setproto.pop = function () {
  2925. this.length && delete this[this.length--];
  2926. return this.items.pop();
  2927. };
  2928. setproto.forEach = function (callback, thisArg) {
  2929. for (var i = 0, ii = this.items.length; i < ii; i++) {
  2930. if (callback.call(thisArg, this.items[i], i) === false) {
  2931. return this;
  2932. }
  2933. }
  2934. return this;
  2935. };
  2936. for (var method in elproto) if (elproto[has](method)) {
  2937. setproto[method] = (function (methodname) {
  2938. return function () {
  2939. var arg = arguments;
  2940. return this.forEach(function (el) {
  2941. el[methodname][apply](el, arg);
  2942. });
  2943. };
  2944. })(method);
  2945. }
  2946. setproto.attr = function (name, value) {
  2947. if (name && R.is(name, array) && R.is(name[0], "object")) {
  2948. for (var j = 0, jj = name.length; j < jj; j++) {
  2949. this.items[j].attr(name[j]);
  2950. }
  2951. } else {
  2952. for (var i = 0, ii = this.items.length; i < ii; i++) {
  2953. this.items[i].attr(name, value);
  2954. }
  2955. }
  2956. return this;
  2957. };
  2958. setproto.clear = function () {
  2959. while (this.length) {
  2960. this.pop();
  2961. }
  2962. };
  2963. setproto.splice = function (index, count, insertion) {
  2964. index = index < 0 ? mmax(this.length + index, 0) : index;
  2965. count = mmax(0, mmin(this.length - index, count));
  2966. var tail = [],
  2967. todel = [],
  2968. args = [],
  2969. i;
  2970. for (i = 2; i < arguments.length; i++) {
  2971. args.push(arguments[i]);
  2972. }
  2973. for (i = 0; i < count; i++) {
  2974. todel.push(this[index + i]);
  2975. }
  2976. for (; i < this.length - index; i++) {
  2977. tail.push(this[index + i]);
  2978. }
  2979. var arglen = args.length;
  2980. for (i = 0; i < arglen + tail.length; i++) {
  2981. this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
  2982. }
  2983. i = this.items.length = this.length -= count - arglen;
  2984. while (this[i]) {
  2985. delete this[i++];
  2986. }
  2987. return new Set(todel);
  2988. };
  2989. setproto.exclude = function (el) {
  2990. for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) {
  2991. this.splice(i, 1);
  2992. return true;
  2993. }
  2994. };
  2995. setproto.animate = function (params, ms, easing, callback) {
  2996. (R.is(easing, "function") || !easing) && (callback = easing || null);
  2997. var len = this.items.length,
  2998. i = len,
  2999. item,
  3000. set = this,
  3001. collector;
  3002. if (!len) {
  3003. return this;
  3004. }
  3005. callback && (collector = function () {
  3006. !--len && callback.call(set);
  3007. });
  3008. easing = R.is(easing, string) ? easing : collector;
  3009. var anim = R.animation(params, ms, easing, collector);
  3010. item = this.items[--i].animate(anim);
  3011. while (i--) {
  3012. this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
  3013. }
  3014. return this;
  3015. };
  3016. setproto.insertAfter = function (el) {
  3017. var i = this.items.length;
  3018. while (i--) {
  3019. this.items[i].insertAfter(el);
  3020. }
  3021. return this;
  3022. };
  3023. setproto.getBBox = function () {
  3024. var x = [],
  3025. y = [],
  3026. w = [],
  3027. h = [];
  3028. for (var i = this.items.length; i--;) if (!this.items[i].removed) {
  3029. var box = this.items[i].getBBox();
  3030. x.push(box.x);
  3031. y.push(box.y);
  3032. w.push(box.x + box.width);
  3033. h.push(box.y + box.height);
  3034. }
  3035. x = mmin[apply](0, x);
  3036. y = mmin[apply](0, y);
  3037. return {
  3038. x: x,
  3039. y: y,
  3040. width: mmax[apply](0, w) - x,
  3041. height: mmax[apply](0, h) - y
  3042. };
  3043. };
  3044. setproto.clone = function (s) {
  3045. s = new Set;
  3046. for (var i = 0, ii = this.items.length; i < ii; i++) {
  3047. s.push(this.items[i].clone());
  3048. }
  3049. return s;
  3050. };
  3051. setproto.toString = function () {
  3052. return "Rapha\xebl\u2018s set";
  3053. };
  3054. R.registerFont = function (font) {
  3055. if (!font.face) {
  3056. return font;
  3057. }
  3058. this.fonts = this.fonts || {};
  3059. var fontcopy = {
  3060. w: font.w,
  3061. face: {},
  3062. glyphs: {}
  3063. },
  3064. family = font.face["font-family"];
  3065. for (var prop in font.face) if (font.face[has](prop)) {
  3066. fontcopy.face[prop] = font.face[prop];
  3067. }
  3068. if (this.fonts[family]) {
  3069. this.fonts[family].push(fontcopy);
  3070. } else {
  3071. this.fonts[family] = [fontcopy];
  3072. }
  3073. if (!font.svg) {
  3074. fontcopy.face["units-per-em"] = toInt(font.face["units-per-em"], 10);
  3075. for (var glyph in font.glyphs) if (font.glyphs[has](glyph)) {
  3076. var path = font.glyphs[glyph];
  3077. fontcopy.glyphs[glyph] = {
  3078. w: path.w,
  3079. k: {},
  3080. d: path.d && "M" + path.d.replace(/[mlcxtrv]/g, function (command) {
  3081. return {l: "L", c: "C", x: "z", t: "m", r: "l", v: "c"}[command] || "M";
  3082. }) + "z"
  3083. };
  3084. if (path.k) {
  3085. for (var k in path.k) if (path[has](k)) {
  3086. fontcopy.glyphs[glyph].k[k] = path.k[k];
  3087. }
  3088. }
  3089. }
  3090. }
  3091. return font;
  3092. };
  3093. paperproto.getFont = function (family, weight, style, stretch) {
  3094. stretch = stretch || "normal";
  3095. style = style || "normal";
  3096. weight = +weight || {normal: 400, bold: 700, lighter: 300, bolder: 800}[weight] || 400;
  3097. if (!R.fonts) {
  3098. return;
  3099. }
  3100. var font = R.fonts[family];
  3101. if (!font) {
  3102. var name = new RegExp("(^|\\s)" + family.replace(/[^\w\d\s+!~.:_-]/g, E) + "(\\s|$)", "i");
  3103. for (var fontName in R.fonts) if (R.fonts[has](fontName)) {
  3104. if (name.test(fontName)) {
  3105. font = R.fonts[fontName];
  3106. break;
  3107. }
  3108. }
  3109. }
  3110. var thefont;
  3111. if (font) {
  3112. for (var i = 0, ii = font.length; i < ii; i++) {
  3113. thefont = font[i];
  3114. if (thefont.face["font-weight"] == weight && (thefont.face["font-style"] == style || !thefont.face["font-style"]) && thefont.face["font-stretch"] == stretch) {
  3115. break;
  3116. }
  3117. }
  3118. }
  3119. return thefont;
  3120. };
  3121. paperproto.print = function (x, y, string, font, size, origin, letter_spacing) {
  3122. origin = origin || "middle"; // baseline|middle
  3123. letter_spacing = mmax(mmin(letter_spacing || 0, 1), -1);
  3124. var out = this.set(),
  3125. letters = Str(string)[split](E),
  3126. shift = 0,
  3127. path = E,
  3128. scale;
  3129. R.is(font, string) && (font = this.getFont(font));
  3130. if (font) {
  3131. scale = (size || 16) / font.face["units-per-em"];
  3132. var bb = font.face.bbox[split](separator),
  3133. top = +bb[0],
  3134. height = +bb[1] + (origin == "baseline" ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
  3135. for (var i = 0, ii = letters.length; i < ii; i++) {
  3136. var prev = i && font.glyphs[letters[i - 1]] || {},
  3137. curr = font.glyphs[letters[i]];
  3138. shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letter_spacing) : 0;
  3139. curr && curr.d && out.push(this.path(curr.d).attr({
  3140. fill: "#000",
  3141. stroke: "none",
  3142. transform: [["t", shift * scale, 0]]
  3143. }));
  3144. }
  3145. out.transform(["...s", scale, scale, top, height, "t", (x - top) / scale, (y - height) / scale]);
  3146. }
  3147. return out;
  3148. };
  3149. paperproto.add = function (json) {
  3150. if (R.is(json, "array")) {
  3151. var res = this.set(),
  3152. i = 0,
  3153. ii = json.length,
  3154. j;
  3155. for (; i < ii; i++) {
  3156. j = json[i] || {};
  3157. elements[has](j.type) && res.push(this[j.type]().attr(j));
  3158. }
  3159. }
  3160. return res;
  3161. };
  3162. R.format = function (token, params) {
  3163. var args = R.is(params, array) ? [0][concat](params) : arguments;
  3164. token && R.is(token, string) && args.length - 1 && (token = token.replace(formatrg, function (str, i) {
  3165. return args[++i] == null ? E : args[i];
  3166. }));
  3167. return token || E;
  3168. };
  3169. R.fullfill = (function () {
  3170. var tokenRegex = /\{([^\}]+)\}/g,
  3171. objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties
  3172. replacer = function (all, key, obj) {
  3173. var res = obj;
  3174. key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) {
  3175. name = name || quotedName;
  3176. if (res) {
  3177. if (name in res) {
  3178. res = res[name];
  3179. }
  3180. typeof res == "function" && isFunc && (res = res());
  3181. }
  3182. });
  3183. res = (res == null || res == obj ? all : res) + "";
  3184. return res;
  3185. };
  3186. return function (str, obj) {
  3187. return String(str).replace(tokenRegex, function (all, key) {
  3188. return replacer(all, key, obj);
  3189. });
  3190. };
  3191. })();
  3192. R.ninja = function () {
  3193. oldRaphael.was ? (g.win.Raphael = oldRaphael.is) : delete Raphael;
  3194. return R;
  3195. };
  3196. R.st = setproto;
  3197. // Firefox <3.6 fix: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
  3198. (function (doc, loaded, f) {
  3199. if (doc.readyState == null && doc.addEventListener){
  3200. doc.addEventListener(loaded, f = function () {
  3201. doc.removeEventListener(loaded, f, false);
  3202. doc.readyState = "complete";
  3203. }, false);
  3204. doc.readyState = "loading";
  3205. }
  3206. function isLoaded() {
  3207. (/in/).test(doc.readyState) ? setTimeout(isLoaded, 9) : R.eve("DOMload");
  3208. }
  3209. isLoaded();
  3210. })(document, "DOMContentLoaded");
  3211. oldRaphael.was ? (g.win.Raphael = R) : (Raphael = R);
  3212. eve.on("DOMload", function () {
  3213. loaded = true;
  3214. });
  3215. })();
  3216. // ┌─────────────────────────────────────────────────────────────────────┐ \\
  3217. // │ Raphaël - JavaScript Vector Library │ \\
  3218. // ├─────────────────────────────────────────────────────────────────────┤ \\
  3219. // │ SVG Module │ \\
  3220. // ├─────────────────────────────────────────────────────────────────────┤ \\
  3221. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  3222. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  3223. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  3224. // └─────────────────────────────────────────────────────────────────────┘ \\
  3225. window.Raphael.svg && function (R) {
  3226. var has = "hasOwnProperty",
  3227. Str = String,
  3228. toFloat = parseFloat,
  3229. toInt = parseInt,
  3230. math = Math,
  3231. mmax = math.max,
  3232. abs = math.abs,
  3233. pow = math.pow,
  3234. separator = /[, ]+/,
  3235. eve = R.eve,
  3236. E = "",
  3237. S = " ";
  3238. var xlink = "http://www.w3.org/1999/xlink",
  3239. markers = {
  3240. block: "M5,0 0,2.5 5,5z",
  3241. classic: "M5,0 0,2.5 5,5 3.5,3 3.5,2z",
  3242. diamond: "M2.5,0 5,2.5 2.5,5 0,2.5z",
  3243. open: "M6,1 1,3.5 6,6",
  3244. oval: "M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"
  3245. },
  3246. markerCounter = {};
  3247. R.toString = function () {
  3248. return "Your browser supports SVG.\nYou are running Rapha\xebl " + this.version;
  3249. };
  3250. var $ = function (el, attr) {
  3251. if (attr) {
  3252. if (typeof el == "string") {
  3253. el = $(el);
  3254. }
  3255. for (var key in attr) if (attr[has](key)) {
  3256. if (key.substring(0, 6) == "xlink:") {
  3257. el.setAttributeNS(xlink, key.substring(6), Str(attr[key]));
  3258. } else {
  3259. el.setAttribute(key, Str(attr[key]));
  3260. }
  3261. }
  3262. } else {
  3263. el = R._g.doc.createElementNS("http://www.w3.org/2000/svg", el);
  3264. el.style && (el.style.webkitTapHighlightColor = "rgba(0,0,0,0)");
  3265. }
  3266. return el;
  3267. },
  3268. addGradientFill = function (element, gradient) {
  3269. var type = "linear",
  3270. id = element.id + gradient,
  3271. fx = .5, fy = .5,
  3272. o = element.node,
  3273. SVG = element.paper,
  3274. s = o.style,
  3275. el = R._g.doc.getElementById(id);
  3276. if (!el) {
  3277. gradient = Str(gradient).replace(R._radial_gradient, function (all, _fx, _fy) {
  3278. type = "radial";
  3279. if (_fx && _fy) {
  3280. fx = toFloat(_fx);
  3281. fy = toFloat(_fy);
  3282. var dir = ((fy > .5) * 2 - 1);
  3283. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 &&
  3284. (fy = math.sqrt(.25 - pow(fx - .5, 2)) * dir + .5) &&
  3285. fy != .5 &&
  3286. (fy = fy.toFixed(5) - 1e-5 * dir);
  3287. }
  3288. return E;
  3289. });
  3290. gradient = gradient.split(/\s*\-\s*/);
  3291. if (type == "linear") {
  3292. var angle = gradient.shift();
  3293. angle = -toFloat(angle);
  3294. if (isNaN(angle)) {
  3295. return null;
  3296. }
  3297. var vector = [0, 0, math.cos(R.rad(angle)), math.sin(R.rad(angle))],
  3298. max = 1 / (mmax(abs(vector[2]), abs(vector[3])) || 1);
  3299. vector[2] *= max;
  3300. vector[3] *= max;
  3301. if (vector[2] < 0) {
  3302. vector[0] = -vector[2];
  3303. vector[2] = 0;
  3304. }
  3305. if (vector[3] < 0) {
  3306. vector[1] = -vector[3];
  3307. vector[3] = 0;
  3308. }
  3309. }
  3310. var dots = R._parseDots(gradient);
  3311. if (!dots) {
  3312. return null;
  3313. }
  3314. id = id.replace(/[\(\)\s,\xb0#]/g, "_");
  3315. if (element.gradient && id != element.gradient.id) {
  3316. SVG.defs.removeChild(element.gradient);
  3317. delete element.gradient;
  3318. }
  3319. if (!element.gradient) {
  3320. el = $(type + "Gradient", {id: id});
  3321. element.gradient = el;
  3322. $(el, type == "radial" ? {
  3323. fx: fx,
  3324. fy: fy
  3325. } : {
  3326. x1: vector[0],
  3327. y1: vector[1],
  3328. x2: vector[2],
  3329. y2: vector[3],
  3330. gradientTransform: element.matrix.invert()
  3331. });
  3332. SVG.defs.appendChild(el);
  3333. for (var i = 0, ii = dots.length; i < ii; i++) {
  3334. el.appendChild($("stop", {
  3335. offset: dots[i].offset ? dots[i].offset : i ? "100%" : "0%",
  3336. "stop-color": dots[i].color || "#fff"
  3337. }));
  3338. }
  3339. }
  3340. }
  3341. $(o, {
  3342. fill: "url(#" + id + ")",
  3343. opacity: 1,
  3344. "fill-opacity": 1
  3345. });
  3346. s.fill = E;
  3347. s.opacity = 1;
  3348. s.fillOpacity = 1;
  3349. return 1;
  3350. },
  3351. updatePosition = function (o) {
  3352. var bbox = o.getBBox(1);
  3353. $(o.pattern, {patternTransform: o.matrix.invert() + " translate(" + bbox.x + "," + bbox.y + ")"});
  3354. },
  3355. addArrow = function (o, value, isEnd) {
  3356. if (o.type == "path") {
  3357. var values = Str(value).toLowerCase().split("-"),
  3358. p = o.paper,
  3359. se = isEnd ? "end" : "start",
  3360. node = o.node,
  3361. attrs = o.attrs,
  3362. stroke = attrs["stroke-width"],
  3363. i = values.length,
  3364. type = "classic",
  3365. from,
  3366. to,
  3367. dx,
  3368. refX,
  3369. attr,
  3370. w = 3,
  3371. h = 3,
  3372. t = 5;
  3373. while (i--) {
  3374. switch (values[i]) {
  3375. case "block":
  3376. case "classic":
  3377. case "oval":
  3378. case "diamond":
  3379. case "open":
  3380. case "none":
  3381. type = values[i];
  3382. break;
  3383. case "wide": h = 5; break;
  3384. case "narrow": h = 2; break;
  3385. case "long": w = 5; break;
  3386. case "short": w = 2; break;
  3387. }
  3388. }
  3389. if (type == "open") {
  3390. w += 2;
  3391. h += 2;
  3392. t += 2;
  3393. dx = 1;
  3394. refX = isEnd ? 4 : 1;
  3395. attr = {
  3396. fill: "none",
  3397. stroke: attrs.stroke
  3398. };
  3399. } else {
  3400. refX = dx = w / 2;
  3401. attr = {
  3402. fill: attrs.stroke,
  3403. stroke: "none"
  3404. };
  3405. }
  3406. if (o._.arrows) {
  3407. if (isEnd) {
  3408. o._.arrows.endPath && markerCounter[o._.arrows.endPath]--;
  3409. o._.arrows.endMarker && markerCounter[o._.arrows.endMarker]--;
  3410. } else {
  3411. o._.arrows.startPath && markerCounter[o._.arrows.startPath]--;
  3412. o._.arrows.startMarker && markerCounter[o._.arrows.startMarker]--;
  3413. }
  3414. } else {
  3415. o._.arrows = {};
  3416. }
  3417. if (type != "none") {
  3418. var pathId = "raphael-marker-" + type,
  3419. markerId = "raphael-marker-" + se + type + w + h;
  3420. if (!R._g.doc.getElementById(pathId)) {
  3421. p.defs.appendChild($($("path"), {
  3422. "stroke-linecap": "round",
  3423. d: markers[type],
  3424. id: pathId
  3425. }));
  3426. markerCounter[pathId] = 1;
  3427. } else {
  3428. markerCounter[pathId]++;
  3429. }
  3430. var marker = R._g.doc.getElementById(markerId),
  3431. use;
  3432. if (!marker) {
  3433. marker = $($("marker"), {
  3434. id: markerId,
  3435. markerHeight: h,
  3436. markerWidth: w,
  3437. orient: "auto",
  3438. refX: refX,
  3439. refY: h / 2
  3440. });
  3441. use = $($("use"), {
  3442. "xlink:href": "#" + pathId,
  3443. transform: (isEnd ? " rotate(180 " + w / 2 + " " + h / 2 + ") " : S) + "scale(" + w / t + "," + h / t + ")",
  3444. "stroke-width": 1 / ((w / t + h / t) / 2)
  3445. });
  3446. marker.appendChild(use);
  3447. p.defs.appendChild(marker);
  3448. markerCounter[markerId] = 1;
  3449. } else {
  3450. markerCounter[markerId]++;
  3451. use = marker.getElementsByTagName("use")[0];
  3452. }
  3453. $(use, attr);
  3454. var delta = dx * (type != "diamond" && type != "oval");
  3455. if (isEnd) {
  3456. from = o._.arrows.startdx * stroke || 0;
  3457. to = R.getTotalLength(attrs.path) - delta * stroke;
  3458. } else {
  3459. from = delta * stroke;
  3460. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  3461. }
  3462. attr = {};
  3463. attr["marker-" + se] = "url(#" + markerId + ")";
  3464. if (to || from) {
  3465. attr.d = Raphael.getSubpath(attrs.path, from, to);
  3466. }
  3467. $(node, attr);
  3468. o._.arrows[se + "Path"] = pathId;
  3469. o._.arrows[se + "Marker"] = markerId;
  3470. o._.arrows[se + "dx"] = delta;
  3471. o._.arrows[se + "Type"] = type;
  3472. o._.arrows[se + "String"] = value;
  3473. } else {
  3474. if (isEnd) {
  3475. from = o._.arrows.startdx * stroke || 0;
  3476. to = R.getTotalLength(attrs.path) - from;
  3477. } else {
  3478. from = 0;
  3479. to = R.getTotalLength(attrs.path) - (o._.arrows.enddx * stroke || 0);
  3480. }
  3481. o._.arrows[se + "Path"] && $(node, {d: Raphael.getSubpath(attrs.path, from, to)});
  3482. delete o._.arrows[se + "Path"];
  3483. delete o._.arrows[se + "Marker"];
  3484. delete o._.arrows[se + "dx"];
  3485. delete o._.arrows[se + "Type"];
  3486. delete o._.arrows[se + "String"];
  3487. }
  3488. for (attr in markerCounter) if (markerCounter[has](attr) && !markerCounter[attr]) {
  3489. var item = R._g.doc.getElementById(attr);
  3490. item && item.parentNode.removeChild(item);
  3491. }
  3492. }
  3493. },
  3494. dasharray = {
  3495. "": [0],
  3496. "none": [0],
  3497. "-": [3, 1],
  3498. ".": [1, 1],
  3499. "-.": [3, 1, 1, 1],
  3500. "-..": [3, 1, 1, 1, 1, 1],
  3501. ". ": [1, 3],
  3502. "- ": [4, 3],
  3503. "--": [8, 3],
  3504. "- .": [4, 3, 1, 3],
  3505. "--.": [8, 3, 1, 3],
  3506. "--..": [8, 3, 1, 3, 1, 3]
  3507. },
  3508. addDashes = function (o, value, params) {
  3509. value = dasharray[Str(value).toLowerCase()];
  3510. if (value) {
  3511. var width = o.attrs["stroke-width"] || "1",
  3512. butt = {round: width, square: width, butt: 0}[o.attrs["stroke-linecap"] || params["stroke-linecap"]] || 0,
  3513. dashes = [],
  3514. i = value.length;
  3515. while (i--) {
  3516. dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
  3517. }
  3518. $(o.node, {"stroke-dasharray": dashes.join(",")});
  3519. }
  3520. },
  3521. setFillAndStroke = function (o, params) {
  3522. var node = o.node,
  3523. attrs = o.attrs,
  3524. vis = node.style.visibility;
  3525. node.style.visibility = "hidden";
  3526. for (var att in params) {
  3527. if (params[has](att)) {
  3528. if (!R._availableAttrs[has](att)) {
  3529. continue;
  3530. }
  3531. var value = params[att];
  3532. attrs[att] = value;
  3533. switch (att) {
  3534. case "blur":
  3535. o.blur(value);
  3536. break;
  3537. case "href":
  3538. case "title":
  3539. case "target":
  3540. var pn = node.parentNode;
  3541. if (pn.tagName.toLowerCase() != "a") {
  3542. var hl = $("a");
  3543. pn.insertBefore(hl, node);
  3544. hl.appendChild(node);
  3545. pn = hl;
  3546. }
  3547. if (att == "target" && value == "blank") {
  3548. pn.setAttributeNS(xlink, "show", "new");
  3549. } else {
  3550. pn.setAttributeNS(xlink, att, value);
  3551. }
  3552. break;
  3553. case "cursor":
  3554. node.style.cursor = value;
  3555. break;
  3556. case "transform":
  3557. o.transform(value);
  3558. break;
  3559. case "arrow-start":
  3560. addArrow(o, value);
  3561. break;
  3562. case "arrow-end":
  3563. addArrow(o, value, 1);
  3564. break;
  3565. case "clip-rect":
  3566. var rect = Str(value).split(separator);
  3567. if (rect.length == 4) {
  3568. o.clip && o.clip.parentNode.parentNode.removeChild(o.clip.parentNode);
  3569. var el = $("clipPath"),
  3570. rc = $("rect");
  3571. el.id = R.createUUID();
  3572. $(rc, {
  3573. x: rect[0],
  3574. y: rect[1],
  3575. width: rect[2],
  3576. height: rect[3]
  3577. });
  3578. el.appendChild(rc);
  3579. o.paper.defs.appendChild(el);
  3580. $(node, {"clip-path": "url(#" + el.id + ")"});
  3581. o.clip = rc;
  3582. }
  3583. if (!value) {
  3584. var path = node.getAttribute("clip-path");
  3585. if (path) {
  3586. var clip = R._g.doc.getElementById(path.replace(/(^url\(#|\)$)/g, E));
  3587. clip && clip.parentNode.removeChild(clip);
  3588. $(node, {"clip-path": E});
  3589. delete o.clip;
  3590. }
  3591. }
  3592. break;
  3593. case "path":
  3594. if (o.type == "path") {
  3595. $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"});
  3596. o._.dirty = 1;
  3597. if (o._.arrows) {
  3598. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  3599. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  3600. }
  3601. }
  3602. break;
  3603. case "width":
  3604. node.setAttribute(att, value);
  3605. o._.dirty = 1;
  3606. if (attrs.fx) {
  3607. att = "x";
  3608. value = attrs.x;
  3609. } else {
  3610. break;
  3611. }
  3612. case "x":
  3613. if (attrs.fx) {
  3614. value = -attrs.x - (attrs.width || 0);
  3615. }
  3616. case "rx":
  3617. if (att == "rx" && o.type == "rect") {
  3618. break;
  3619. }
  3620. case "cx":
  3621. node.setAttribute(att, value);
  3622. o.pattern && updatePosition(o);
  3623. o._.dirty = 1;
  3624. break;
  3625. case "height":
  3626. node.setAttribute(att, value);
  3627. o._.dirty = 1;
  3628. if (attrs.fy) {
  3629. att = "y";
  3630. value = attrs.y;
  3631. } else {
  3632. break;
  3633. }
  3634. case "y":
  3635. if (attrs.fy) {
  3636. value = -attrs.y - (attrs.height || 0);
  3637. }
  3638. case "ry":
  3639. if (att == "ry" && o.type == "rect") {
  3640. break;
  3641. }
  3642. case "cy":
  3643. node.setAttribute(att, value);
  3644. o.pattern && updatePosition(o);
  3645. o._.dirty = 1;
  3646. break;
  3647. case "r":
  3648. if (o.type == "rect") {
  3649. $(node, {rx: value, ry: value});
  3650. } else {
  3651. node.setAttribute(att, value);
  3652. }
  3653. o._.dirty = 1;
  3654. break;
  3655. case "src":
  3656. if (o.type == "image") {
  3657. node.setAttributeNS(xlink, "href", value);
  3658. }
  3659. break;
  3660. case "stroke-width":
  3661. if (o._.sx != 1 || o._.sy != 1) {
  3662. value /= mmax(abs(o._.sx), abs(o._.sy)) || 1;
  3663. }
  3664. if (o.paper._vbSize) {
  3665. value *= o.paper._vbSize;
  3666. }
  3667. node.setAttribute(att, value);
  3668. if (attrs["stroke-dasharray"]) {
  3669. addDashes(o, attrs["stroke-dasharray"], params);
  3670. }
  3671. if (o._.arrows) {
  3672. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  3673. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  3674. }
  3675. break;
  3676. case "stroke-dasharray":
  3677. addDashes(o, value, params);
  3678. break;
  3679. case "fill":
  3680. var isURL = Str(value).match(R._ISURL);
  3681. if (isURL) {
  3682. el = $("pattern");
  3683. var ig = $("image");
  3684. el.id = R.createUUID();
  3685. $(el, {x: 0, y: 0, patternUnits: "userSpaceOnUse", height: 1, width: 1});
  3686. $(ig, {x: 0, y: 0, "xlink:href": isURL[1]});
  3687. el.appendChild(ig);
  3688. (function (el) {
  3689. R._preload(isURL[1], function () {
  3690. var w = this.offsetWidth,
  3691. h = this.offsetHeight;
  3692. $(el, {width: w, height: h});
  3693. $(ig, {width: w, height: h});
  3694. o.paper.safari();
  3695. });
  3696. })(el);
  3697. o.paper.defs.appendChild(el);
  3698. node.style.fill = "url(#" + el.id + ")";
  3699. $(node, {fill: "url(#" + el.id + ")"});
  3700. o.pattern = el;
  3701. o.pattern && updatePosition(o);
  3702. break;
  3703. }
  3704. var clr = R.getRGB(value);
  3705. if (!clr.error) {
  3706. delete params.gradient;
  3707. delete attrs.gradient;
  3708. !R.is(attrs.opacity, "undefined") &&
  3709. R.is(params.opacity, "undefined") &&
  3710. $(node, {opacity: attrs.opacity});
  3711. !R.is(attrs["fill-opacity"], "undefined") &&
  3712. R.is(params["fill-opacity"], "undefined") &&
  3713. $(node, {"fill-opacity": attrs["fill-opacity"]});
  3714. } else if ((o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value)) {
  3715. if ("opacity" in attrs || "fill-opacity" in attrs) {
  3716. var gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  3717. if (gradient) {
  3718. var stops = gradient.getElementsByTagName("stop");
  3719. $(stops[stops.length - 1], {"stop-opacity": ("opacity" in attrs ? attrs.opacity : 1) * ("fill-opacity" in attrs ? attrs["fill-opacity"] : 1)});
  3720. }
  3721. }
  3722. attrs.gradient = value;
  3723. attrs.fill = "none";
  3724. break;
  3725. }
  3726. clr[has]("opacity") && $(node, {"fill-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  3727. case "stroke":
  3728. clr = R.getRGB(value);
  3729. node.setAttribute(att, clr.hex);
  3730. att == "stroke" && clr[has]("opacity") && $(node, {"stroke-opacity": clr.opacity > 1 ? clr.opacity / 100 : clr.opacity});
  3731. if (att == "stroke" && o._.arrows) {
  3732. "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
  3733. "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
  3734. }
  3735. break;
  3736. case "gradient":
  3737. (o.type == "circle" || o.type == "ellipse" || Str(value).charAt() != "r") && addGradientFill(o, value);
  3738. break;
  3739. case "opacity":
  3740. if (attrs.gradient && !attrs[has]("stroke-opacity")) {
  3741. $(node, {"stroke-opacity": value > 1 ? value / 100 : value});
  3742. }
  3743. // fall
  3744. case "fill-opacity":
  3745. if (attrs.gradient) {
  3746. gradient = R._g.doc.getElementById(node.getAttribute("fill").replace(/^url\(#|\)$/g, E));
  3747. if (gradient) {
  3748. stops = gradient.getElementsByTagName("stop");
  3749. $(stops[stops.length - 1], {"stop-opacity": value});
  3750. }
  3751. break;
  3752. }
  3753. default:
  3754. att == "font-size" && (value = toInt(value, 10) + "px");
  3755. var cssrule = att.replace(/(\-.)/g, function (w) {
  3756. return w.substring(1).toUpperCase();
  3757. });
  3758. node.style[cssrule] = value;
  3759. o._.dirty = 1;
  3760. node.setAttribute(att, value);
  3761. break;
  3762. }
  3763. }
  3764. }
  3765. tuneText(o, params);
  3766. node.style.visibility = vis;
  3767. },
  3768. leading = 1.2,
  3769. tuneText = function (el, params) {
  3770. if (el.type != "text" || !(params[has]("text") || params[has]("font") || params[has]("font-size") || params[has]("x") || params[has]("y"))) {
  3771. return;
  3772. }
  3773. var a = el.attrs,
  3774. node = el.node,
  3775. fontSize = node.firstChild ? toInt(R._g.doc.defaultView.getComputedStyle(node.firstChild, E).getPropertyValue("font-size"), 10) : 10;
  3776. if (params[has]("text")) {
  3777. a.text = params.text;
  3778. while (node.firstChild) {
  3779. node.removeChild(node.firstChild);
  3780. }
  3781. var texts = Str(params.text).split("\n"),
  3782. tspans = [],
  3783. tspan;
  3784. for (var i = 0, ii = texts.length; i < ii; i++) {
  3785. tspan = $("tspan");
  3786. i && $(tspan, {dy: fontSize * leading, x: a.x});
  3787. tspan.appendChild(R._g.doc.createTextNode(texts[i]));
  3788. node.appendChild(tspan);
  3789. tspans[i] = tspan;
  3790. }
  3791. } else {
  3792. tspans = node.getElementsByTagName("tspan");
  3793. for (i = 0, ii = tspans.length; i < ii; i++) if (i) {
  3794. $(tspans[i], {dy: fontSize * leading, x: a.x});
  3795. } else {
  3796. $(tspans[0], {dy: 0});
  3797. }
  3798. }
  3799. $(node, {x: a.x, y: a.y});
  3800. el._.dirty = 1;
  3801. var bb = el._getBBox(),
  3802. dif = a.y - (bb.y + bb.height / 2);
  3803. dif && R.is(dif, "finite") && $(tspans[0], {dy: dif});
  3804. },
  3805. Element = function (node, svg) {
  3806. var X = 0,
  3807. Y = 0;
  3808. this[0] = this.node = node;
  3809. node.raphael = true;
  3810. this.id = R._oid++;
  3811. node.raphaelid = this.id;
  3812. this.matrix = R.matrix();
  3813. this.realPath = null;
  3814. this.paper = svg;
  3815. this.attrs = this.attrs || {};
  3816. this._ = {
  3817. transform: [],
  3818. sx: 1,
  3819. sy: 1,
  3820. deg: 0,
  3821. dx: 0,
  3822. dy: 0,
  3823. dirty: 1
  3824. };
  3825. !svg.bottom && (svg.bottom = this);
  3826. this.prev = svg.top;
  3827. svg.top && (svg.top.next = this);
  3828. svg.top = this;
  3829. this.next = null;
  3830. },
  3831. elproto = R.el;
  3832. Element.prototype = elproto;
  3833. elproto.constructor = Element;
  3834. R._engine.path = function (pathString, SVG) {
  3835. var el = $("path");
  3836. SVG.canvas && SVG.canvas.appendChild(el);
  3837. var p = new Element(el, SVG);
  3838. p.type = "path";
  3839. setFillAndStroke(p, {
  3840. fill: "none",
  3841. stroke: "#000",
  3842. path: pathString
  3843. });
  3844. return p;
  3845. };
  3846. elproto.rotate = function (deg, cx, cy) {
  3847. if (this.removed) {
  3848. return this;
  3849. }
  3850. deg = Str(deg).split(separator);
  3851. if (deg.length - 1) {
  3852. cx = toFloat(deg[1]);
  3853. cy = toFloat(deg[2]);
  3854. }
  3855. deg = toFloat(deg[0]);
  3856. (cy == null) && (cx = cy);
  3857. if (cx == null || cy == null) {
  3858. var bbox = this.getBBox(1);
  3859. cx = bbox.x + bbox.width / 2;
  3860. cy = bbox.y + bbox.height / 2;
  3861. }
  3862. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  3863. return this;
  3864. };
  3865. elproto.scale = function (sx, sy, cx, cy) {
  3866. if (this.removed) {
  3867. return this;
  3868. }
  3869. sx = Str(sx).split(separator);
  3870. if (sx.length - 1) {
  3871. sy = toFloat(sx[1]);
  3872. cx = toFloat(sx[2]);
  3873. cy = toFloat(sx[3]);
  3874. }
  3875. sx = toFloat(sx[0]);
  3876. (sy == null) && (sy = sx);
  3877. (cy == null) && (cx = cy);
  3878. if (cx == null || cy == null) {
  3879. var bbox = this.getBBox(1);
  3880. }
  3881. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  3882. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  3883. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  3884. return this;
  3885. };
  3886. elproto.translate = function (dx, dy) {
  3887. if (this.removed) {
  3888. return this;
  3889. }
  3890. dx = Str(dx).split(separator);
  3891. if (dx.length - 1) {
  3892. dy = toFloat(dx[1]);
  3893. }
  3894. dx = toFloat(dx[0]) || 0;
  3895. dy = +dy || 0;
  3896. this.transform(this._.transform.concat([["t", dx, dy]]));
  3897. return this;
  3898. };
  3899. elproto.transform = function (tstr) {
  3900. var _ = this._;
  3901. if (tstr == null) {
  3902. return _.transform;
  3903. }
  3904. R._extractTransform(this, tstr);
  3905. this.clip && $(this.clip, {transform: this.matrix.invert()});
  3906. this.pattern && updatePosition(this);
  3907. this.node && $(this.node, {transform: this.matrix});
  3908. if (_.sx != 1 || _.sy != 1) {
  3909. var sw = this.attrs[has]("stroke-width") ? this.attrs["stroke-width"] : 1;
  3910. this.attr({"stroke-width": sw});
  3911. }
  3912. return this;
  3913. };
  3914. elproto.hide = function () {
  3915. !this.removed && this.paper.safari(this.node.style.display = "none");
  3916. return this;
  3917. };
  3918. elproto.show = function () {
  3919. !this.removed && this.paper.safari(this.node.style.display = "");
  3920. return this;
  3921. };
  3922. elproto.remove = function () {
  3923. if (this.removed) {
  3924. return;
  3925. }
  3926. var paper = this.paper;
  3927. paper.__set__ && paper.__set__.exclude(this);
  3928. eve.unbind("*.*." + this.id);
  3929. if (this.gradient) {
  3930. paper.defs.removeChild(this.gradient);
  3931. }
  3932. R._tear(this, paper);
  3933. this.node.parentNode.removeChild(this.node);
  3934. for (var i in this) {
  3935. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  3936. }
  3937. this.removed = true;
  3938. };
  3939. elproto._getBBox = function () {
  3940. if (this.node.style.display == "none") {
  3941. this.show();
  3942. var hide = true;
  3943. }
  3944. var bbox = {};
  3945. try {
  3946. bbox = this.node.getBBox();
  3947. } catch(e) {
  3948. // Firefox 3.0.x plays badly here
  3949. } finally {
  3950. bbox = bbox || {};
  3951. }
  3952. hide && this.hide();
  3953. return bbox;
  3954. };
  3955. elproto.attr = function (name, value) {
  3956. if (this.removed) {
  3957. return this;
  3958. }
  3959. if (name == null) {
  3960. var res = {};
  3961. for (var a in this.attrs) if (this.attrs[has](a)) {
  3962. res[a] = this.attrs[a];
  3963. }
  3964. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  3965. res.transform = this._.transform;
  3966. return res;
  3967. }
  3968. if (value == null && R.is(name, "string")) {
  3969. if (name == "fill" && this.attrs.fill == "none" && this.attrs.gradient) {
  3970. return this.attrs.gradient;
  3971. }
  3972. if (name == "transform") {
  3973. return this._.transform;
  3974. }
  3975. var names = name.split(separator),
  3976. out = {};
  3977. for (var i = 0, ii = names.length; i < ii; i++) {
  3978. name = names[i];
  3979. if (name in this.attrs) {
  3980. out[name] = this.attrs[name];
  3981. } else if (R.is(this.paper.customAttributes[name], "function")) {
  3982. out[name] = this.paper.customAttributes[name].def;
  3983. } else {
  3984. out[name] = R._availableAttrs[name];
  3985. }
  3986. }
  3987. return ii - 1 ? out : out[names[0]];
  3988. }
  3989. if (value == null && R.is(name, "array")) {
  3990. out = {};
  3991. for (i = 0, ii = name.length; i < ii; i++) {
  3992. out[name[i]] = this.attr(name[i]);
  3993. }
  3994. return out;
  3995. }
  3996. if (value != null) {
  3997. var params = {};
  3998. params[name] = value;
  3999. } else if (name != null && R.is(name, "object")) {
  4000. params = name;
  4001. }
  4002. for (var key in params) {
  4003. eve("attr." + key + "." + this.id, this, params[key]);
  4004. }
  4005. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  4006. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  4007. this.attrs[key] = params[key];
  4008. for (var subkey in par) if (par[has](subkey)) {
  4009. params[subkey] = par[subkey];
  4010. }
  4011. }
  4012. setFillAndStroke(this, params);
  4013. return this;
  4014. };
  4015. elproto.toFront = function () {
  4016. if (this.removed) {
  4017. return this;
  4018. }
  4019. if (this.node.parentNode.tagName.toLowerCase() == "a") {
  4020. this.node.parentNode.parentNode.appendChild(this.node.parentNode);
  4021. } else {
  4022. this.node.parentNode.appendChild(this.node);
  4023. }
  4024. var svg = this.paper;
  4025. svg.top != this && R._tofront(this, svg);
  4026. return this;
  4027. };
  4028. elproto.toBack = function () {
  4029. if (this.removed) {
  4030. return this;
  4031. }
  4032. var parent = this.node.parentNode;
  4033. if (parent.tagName.toLowerCase() == "a") {
  4034. parent.parentNode.insertBefore(this.node.parentNode, this.node.parentNode.parentNode.firstChild);
  4035. } else if (parent.firstChild != this.node) {
  4036. parent.insertBefore(this.node, this.node.parentNode.firstChild);
  4037. }
  4038. R._toback(this, this.paper);
  4039. var svg = this.paper;
  4040. return this;
  4041. };
  4042. elproto.insertAfter = function (element) {
  4043. if (this.removed) {
  4044. return this;
  4045. }
  4046. var node = element.node || element[element.length - 1].node;
  4047. if (node.nextSibling) {
  4048. node.parentNode.insertBefore(this.node, node.nextSibling);
  4049. } else {
  4050. node.parentNode.appendChild(this.node);
  4051. }
  4052. R._insertafter(this, element, this.paper);
  4053. return this;
  4054. };
  4055. elproto.insertBefore = function (element) {
  4056. if (this.removed) {
  4057. return this;
  4058. }
  4059. var node = element.node || element[0].node;
  4060. node.parentNode.insertBefore(this.node, node);
  4061. R._insertbefore(this, element, this.paper);
  4062. return this;
  4063. };
  4064. elproto.blur = function (size) {
  4065. // Experimental. No Safari support. Use it on your own risk.
  4066. var t = this;
  4067. if (+size !== 0) {
  4068. var fltr = $("filter"),
  4069. blur = $("feGaussianBlur");
  4070. t.attrs.blur = size;
  4071. fltr.id = R.createUUID();
  4072. $(blur, {stdDeviation: +size || 1.5});
  4073. fltr.appendChild(blur);
  4074. t.paper.defs.appendChild(fltr);
  4075. t._blur = fltr;
  4076. $(t.node, {filter: "url(#" + fltr.id + ")"});
  4077. } else {
  4078. if (t._blur) {
  4079. t._blur.parentNode.removeChild(t._blur);
  4080. delete t._blur;
  4081. delete t.attrs.blur;
  4082. }
  4083. t.node.removeAttribute("filter");
  4084. }
  4085. };
  4086. R._engine.circle = function (svg, x, y, r) {
  4087. var el = $("circle");
  4088. svg.canvas && svg.canvas.appendChild(el);
  4089. var res = new Element(el, svg);
  4090. res.attrs = {cx: x, cy: y, r: r, fill: "none", stroke: "#000"};
  4091. res.type = "circle";
  4092. $(el, res.attrs);
  4093. return res;
  4094. };
  4095. R._engine.rect = function (svg, x, y, w, h, r) {
  4096. var el = $("rect");
  4097. svg.canvas && svg.canvas.appendChild(el);
  4098. var res = new Element(el, svg);
  4099. res.attrs = {x: x, y: y, width: w, height: h, r: r || 0, rx: r || 0, ry: r || 0, fill: "none", stroke: "#000"};
  4100. res.type = "rect";
  4101. $(el, res.attrs);
  4102. return res;
  4103. };
  4104. R._engine.ellipse = function (svg, x, y, rx, ry) {
  4105. var el = $("ellipse");
  4106. svg.canvas && svg.canvas.appendChild(el);
  4107. var res = new Element(el, svg);
  4108. res.attrs = {cx: x, cy: y, rx: rx, ry: ry, fill: "none", stroke: "#000"};
  4109. res.type = "ellipse";
  4110. $(el, res.attrs);
  4111. return res;
  4112. };
  4113. R._engine.image = function (svg, src, x, y, w, h) {
  4114. var el = $("image");
  4115. $(el, {x: x, y: y, width: w, height: h, preserveAspectRatio: "none"});
  4116. el.setAttributeNS(xlink, "href", src);
  4117. svg.canvas && svg.canvas.appendChild(el);
  4118. var res = new Element(el, svg);
  4119. res.attrs = {x: x, y: y, width: w, height: h, src: src};
  4120. res.type = "image";
  4121. return res;
  4122. };
  4123. R._engine.text = function (svg, x, y, text) {
  4124. var el = $("text");
  4125. // $(el, {x: x, y: y, "text-anchor": "middle"});
  4126. svg.canvas && svg.canvas.appendChild(el);
  4127. var res = new Element(el, svg);
  4128. res.attrs = {
  4129. x: x,
  4130. y: y,
  4131. "text-anchor": "middle",
  4132. text: text,
  4133. font: R._availableAttrs.font,
  4134. stroke: "none",
  4135. fill: "#000"
  4136. };
  4137. res.type = "text";
  4138. setFillAndStroke(res, res.attrs);
  4139. return res;
  4140. };
  4141. R._engine.setSize = function (width, height) {
  4142. this.width = width || this.width;
  4143. this.height = height || this.height;
  4144. this.canvas.setAttribute("width", this.width);
  4145. this.canvas.setAttribute("height", this.height);
  4146. if (this._viewBox) {
  4147. this.setViewBox.apply(this, this._viewBox);
  4148. }
  4149. return this;
  4150. };
  4151. R._engine.create = function () {
  4152. var con = R._getContainer.apply(0, arguments),
  4153. container = con && con.container,
  4154. x = con.x,
  4155. y = con.y,
  4156. width = con.width,
  4157. height = con.height;
  4158. if (!container) {
  4159. throw new Error("SVG container not found.");
  4160. }
  4161. var cnvs = $("svg"),
  4162. css = "overflow:hidden;",
  4163. isFloating;
  4164. x = x || 0;
  4165. y = y || 0;
  4166. width = width || 512;
  4167. height = height || 342;
  4168. $(cnvs, {
  4169. height: height,
  4170. version: 1.1,
  4171. width: width,
  4172. xmlns: "http://www.w3.org/2000/svg"
  4173. });
  4174. if (container == 1) {
  4175. cnvs.style.cssText = css + "position:absolute;left:" + x + "px;top:" + y + "px";
  4176. R._g.doc.body.appendChild(cnvs);
  4177. isFloating = 1;
  4178. } else {
  4179. cnvs.style.cssText = css + "position:relative";
  4180. if (container.firstChild) {
  4181. container.insertBefore(cnvs, container.firstChild);
  4182. } else {
  4183. container.appendChild(cnvs);
  4184. }
  4185. }
  4186. container = new R._Paper;
  4187. container.width = width;
  4188. container.height = height;
  4189. container.canvas = cnvs;
  4190. // plugins.call(container, container, R.fn);
  4191. container.clear();
  4192. container._left = container._top = 0;
  4193. isFloating && (container.renderfix = function () {});
  4194. container.renderfix();
  4195. return container;
  4196. };
  4197. R._engine.setViewBox = function (x, y, w, h, fit) {
  4198. eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  4199. var size = mmax(w / this.width, h / this.height),
  4200. top = this.top,
  4201. aspectRatio = fit ? "meet" : "xMinYMin",
  4202. vb,
  4203. sw;
  4204. if (x == null) {
  4205. if (this._vbSize) {
  4206. size = 1;
  4207. }
  4208. delete this._vbSize;
  4209. vb = "0 0 " + this.width + S + this.height;
  4210. } else {
  4211. this._vbSize = size;
  4212. vb = x + S + y + S + w + S + h;
  4213. }
  4214. $(this.canvas, {
  4215. viewBox: vb,
  4216. preserveAspectRatio: aspectRatio
  4217. });
  4218. while (size && top) {
  4219. sw = "stroke-width" in top.attrs ? top.attrs["stroke-width"] : 1;
  4220. top.attr({"stroke-width": sw});
  4221. top._.dirty = 1;
  4222. top._.dirtyT = 1;
  4223. top = top.prev;
  4224. }
  4225. this._viewBox = [x, y, w, h, !!fit];
  4226. return this;
  4227. };
  4228. R.prototype.renderfix = function () {
  4229. var cnvs = this.canvas,
  4230. s = cnvs.style,
  4231. pos = cnvs.getScreenCTM() || cnvs.createSVGMatrix(),
  4232. left = -pos.e % 1,
  4233. top = -pos.f % 1;
  4234. if (left || top) {
  4235. if (left) {
  4236. this._left = (this._left + left) % 1;
  4237. s.left = this._left + "px";
  4238. }
  4239. if (top) {
  4240. this._top = (this._top + top) % 1;
  4241. s.top = this._top + "px";
  4242. }
  4243. }
  4244. };
  4245. R.prototype.clear = function () {
  4246. R.eve("clear", this);
  4247. var c = this.canvas;
  4248. while (c.firstChild) {
  4249. c.removeChild(c.firstChild);
  4250. }
  4251. this.bottom = this.top = null;
  4252. (this.desc = $("desc")).appendChild(R._g.doc.createTextNode("Created with Rapha\xebl " + R.version));
  4253. c.appendChild(this.desc);
  4254. c.appendChild(this.defs = $("defs"));
  4255. };
  4256. R.prototype.remove = function () {
  4257. eve("remove", this);
  4258. this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  4259. for (var i in this) {
  4260. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  4261. }
  4262. };
  4263. var setproto = R.st;
  4264. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  4265. setproto[method] = (function (methodname) {
  4266. return function () {
  4267. var arg = arguments;
  4268. return this.forEach(function (el) {
  4269. el[methodname].apply(el, arg);
  4270. });
  4271. };
  4272. })(method);
  4273. }
  4274. }(window.Raphael);
  4275. // ┌─────────────────────────────────────────────────────────────────────┐ \\
  4276. // │ Raphaël - JavaScript Vector Library │ \\
  4277. // ├─────────────────────────────────────────────────────────────────────┤ \\
  4278. // │ VML Module │ \\
  4279. // ├─────────────────────────────────────────────────────────────────────┤ \\
  4280. // │ Copyright (c) 2008-2011 Dmitry Baranovskiy (http://raphaeljs.com) │ \\
  4281. // │ Copyright (c) 2008-2011 Sencha Labs (http://sencha.com) │ \\
  4282. // │ Licensed under the MIT (http://raphaeljs.com/license.html) license. │ \\
  4283. // └─────────────────────────────────────────────────────────────────────┘ \\
  4284. window.Raphael.vml && function (R) {
  4285. var has = "hasOwnProperty",
  4286. Str = String,
  4287. toFloat = parseFloat,
  4288. math = Math,
  4289. round = math.round,
  4290. mmax = math.max,
  4291. mmin = math.min,
  4292. abs = math.abs,
  4293. fillString = "fill",
  4294. separator = /[, ]+/,
  4295. eve = R.eve,
  4296. ms = " progid:DXImageTransform.Microsoft",
  4297. S = " ",
  4298. E = "",
  4299. map = {M: "m", L: "l", C: "c", Z: "x", m: "t", l: "r", c: "v", z: "x"},
  4300. bites = /([clmz]),?([^clmz]*)/gi,
  4301. blurregexp = / progid:\S+Blur\([^\)]+\)/g,
  4302. val = /-?[^,\s-]+/g,
  4303. cssDot = "position:absolute;left:0;top:0;width:1px;height:1px",
  4304. zoom = 21600,
  4305. pathTypes = {path: 1, rect: 1, image: 1},
  4306. ovalTypes = {circle: 1, ellipse: 1},
  4307. path2vml = function (path) {
  4308. var total = /[ahqstv]/ig,
  4309. command = R._pathToAbsolute;
  4310. Str(path).match(total) && (command = R._path2curve);
  4311. total = /[clmz]/g;
  4312. if (command == R._pathToAbsolute && !Str(path).match(total)) {
  4313. var res = Str(path).replace(bites, function (all, command, args) {
  4314. var vals = [],
  4315. isMove = command.toLowerCase() == "m",
  4316. res = map[command];
  4317. args.replace(val, function (value) {
  4318. if (isMove && vals.length == 2) {
  4319. res += vals + map[command == "m" ? "l" : "L"];
  4320. vals = [];
  4321. }
  4322. vals.push(round(value * zoom));
  4323. });
  4324. return res + vals;
  4325. });
  4326. return res;
  4327. }
  4328. var pa = command(path), p, r;
  4329. res = [];
  4330. for (var i = 0, ii = pa.length; i < ii; i++) {
  4331. p = pa[i];
  4332. r = pa[i][0].toLowerCase();
  4333. r == "z" && (r = "x");
  4334. for (var j = 1, jj = p.length; j < jj; j++) {
  4335. r += round(p[j] * zoom) + (j != jj - 1 ? "," : E);
  4336. }
  4337. res.push(r);
  4338. }
  4339. return res.join(S);
  4340. },
  4341. compensation = function (deg, dx, dy) {
  4342. var m = R.matrix();
  4343. m.rotate(-deg, .5, .5);
  4344. return {
  4345. dx: m.x(dx, dy),
  4346. dy: m.y(dx, dy)
  4347. };
  4348. },
  4349. setCoords = function (p, sx, sy, dx, dy, deg) {
  4350. var _ = p._,
  4351. m = p.matrix,
  4352. fillpos = _.fillpos,
  4353. o = p.node,
  4354. s = o.style,
  4355. y = 1,
  4356. flip = "",
  4357. dxdy,
  4358. kx = zoom / sx,
  4359. ky = zoom / sy;
  4360. s.visibility = "hidden";
  4361. if (!sx || !sy) {
  4362. return;
  4363. }
  4364. o.coordsize = abs(kx) + S + abs(ky);
  4365. s.rotation = deg * (sx * sy < 0 ? -1 : 1);
  4366. if (deg) {
  4367. var c = compensation(deg, dx, dy);
  4368. dx = c.dx;
  4369. dy = c.dy;
  4370. }
  4371. sx < 0 && (flip += "x");
  4372. sy < 0 && (flip += " y") && (y = -1);
  4373. s.flip = flip;
  4374. o.coordorigin = (dx * -kx) + S + (dy * -ky);
  4375. if (fillpos || _.fillsize) {
  4376. var fill = o.getElementsByTagName(fillString);
  4377. fill = fill && fill[0];
  4378. o.removeChild(fill);
  4379. if (fillpos) {
  4380. c = compensation(deg, m.x(fillpos[0], fillpos[1]), m.y(fillpos[0], fillpos[1]));
  4381. fill.position = c.dx * y + S + c.dy * y;
  4382. }
  4383. if (_.fillsize) {
  4384. fill.size = _.fillsize[0] * abs(sx) + S + _.fillsize[1] * abs(sy);
  4385. }
  4386. o.appendChild(fill);
  4387. }
  4388. s.visibility = "visible";
  4389. };
  4390. R.toString = function () {
  4391. return "Your browser doesn\u2019t support SVG. Falling down to VML.\nYou are running Rapha\xebl " + this.version;
  4392. };
  4393. var addArrow = function (o, value, isEnd) {
  4394. var values = Str(value).toLowerCase().split("-"),
  4395. se = isEnd ? "end" : "start",
  4396. i = values.length,
  4397. type = "classic",
  4398. w = "medium",
  4399. h = "medium";
  4400. while (i--) {
  4401. switch (values[i]) {
  4402. case "block":
  4403. case "classic":
  4404. case "oval":
  4405. case "diamond":
  4406. case "open":
  4407. case "none":
  4408. type = values[i];
  4409. break;
  4410. case "wide":
  4411. case "narrow": h = values[i]; break;
  4412. case "long":
  4413. case "short": w = values[i]; break;
  4414. }
  4415. }
  4416. var stroke = o.node.getElementsByTagName("stroke")[0];
  4417. stroke[se + "arrow"] = type;
  4418. stroke[se + "arrowlength"] = w;
  4419. stroke[se + "arrowwidth"] = h;
  4420. },
  4421. setFillAndStroke = function (o, params) {
  4422. // o.paper.canvas.style.display = "none";
  4423. o.attrs = o.attrs || {};
  4424. var node = o.node,
  4425. a = o.attrs,
  4426. s = node.style,
  4427. xy,
  4428. 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),
  4429. isOval = ovalTypes[o.type] && (a.cx != params.cx || a.cy != params.cy || a.r != params.r || a.rx != params.rx || a.ry != params.ry),
  4430. res = o;
  4431. for (var par in params) if (params[has](par)) {
  4432. a[par] = params[par];
  4433. }
  4434. if (newpath) {
  4435. a.path = R._getPath[o.type](o);
  4436. o._.dirty = 1;
  4437. }
  4438. params.href && (node.href = params.href);
  4439. params.title && (node.title = params.title);
  4440. params.target && (node.target = params.target);
  4441. params.cursor && (s.cursor = params.cursor);
  4442. "blur" in params && o.blur(params.blur);
  4443. if (params.path && o.type == "path" || newpath) {
  4444. node.path = path2vml(~Str(a.path).toLowerCase().indexOf("r") ? R._pathToAbsolute(a.path) : a.path);
  4445. if (o.type == "image") {
  4446. o._.fillpos = [a.x, a.y];
  4447. o._.fillsize = [a.width, a.height];
  4448. setCoords(o, 1, 1, 0, 0, 0);
  4449. }
  4450. }
  4451. "transform" in params && o.transform(params.transform);
  4452. if (isOval) {
  4453. var cx = +a.cx,
  4454. cy = +a.cy,
  4455. rx = +a.rx || +a.r || 0,
  4456. ry = +a.ry || +a.r || 0;
  4457. 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));
  4458. }
  4459. if ("clip-rect" in params) {
  4460. var rect = Str(params["clip-rect"]).split(separator);
  4461. if (rect.length == 4) {
  4462. rect[2] = +rect[2] + (+rect[0]);
  4463. rect[3] = +rect[3] + (+rect[1]);
  4464. var div = node.clipRect || R._g.doc.createElement("div"),
  4465. dstyle = div.style;
  4466. dstyle.clip = R.format("rect({1}px {2}px {3}px {0}px)", rect);
  4467. if (!node.clipRect) {
  4468. dstyle.position = "absolute";
  4469. dstyle.top = 0;
  4470. dstyle.left = 0;
  4471. dstyle.width = o.paper.width + "px";
  4472. dstyle.height = o.paper.height + "px";
  4473. node.parentNode.insertBefore(div, node);
  4474. div.appendChild(node);
  4475. node.clipRect = div;
  4476. }
  4477. }
  4478. if (!params["clip-rect"]) {
  4479. node.clipRect && (node.clipRect.style.clip = "auto");
  4480. }
  4481. }
  4482. if (o.textpath) {
  4483. var textpathStyle = o.textpath.style;
  4484. params.font && (textpathStyle.font = params.font);
  4485. params["font-family"] && (textpathStyle.fontFamily = '"' + params["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g, E) + '"');
  4486. params["font-size"] && (textpathStyle.fontSize = params["font-size"]);
  4487. params["font-weight"] && (textpathStyle.fontWeight = params["font-weight"]);
  4488. params["font-style"] && (textpathStyle.fontStyle = params["font-style"]);
  4489. }
  4490. if ("arrow-start" in params) {
  4491. addArrow(res, params["arrow-start"]);
  4492. }
  4493. if ("arrow-end" in params) {
  4494. addArrow(res, params["arrow-end"], 1);
  4495. }
  4496. if (params.opacity != null ||
  4497. params["stroke-width"] != null ||
  4498. params.fill != null ||
  4499. params.src != null ||
  4500. params.stroke != null ||
  4501. params["stroke-width"] != null ||
  4502. params["stroke-opacity"] != null ||
  4503. params["fill-opacity"] != null ||
  4504. params["stroke-dasharray"] != null ||
  4505. params["stroke-miterlimit"] != null ||
  4506. params["stroke-linejoin"] != null ||
  4507. params["stroke-linecap"] != null) {
  4508. var fill = node.getElementsByTagName(fillString),
  4509. newfill = false;
  4510. fill = fill && fill[0];
  4511. !fill && (newfill = fill = createNode(fillString));
  4512. if (o.type == "image" && params.src) {
  4513. fill.src = params.src;
  4514. }
  4515. params.fill && (fill.on = true);
  4516. if (fill.on == null || params.fill == "none" || params.fill === null) {
  4517. fill.on = false;
  4518. }
  4519. if (fill.on && params.fill) {
  4520. var isURL = Str(params.fill).match(R._ISURL);
  4521. if (isURL) {
  4522. fill.parentNode == node && node.removeChild(fill);
  4523. fill.rotate = true;
  4524. fill.src = isURL[1];
  4525. fill.type = "tile";
  4526. var bbox = o.getBBox(1);
  4527. fill.position = bbox.x + S + bbox.y;
  4528. o._.fillpos = [bbox.x, bbox.y];
  4529. R._preload(isURL[1], function () {
  4530. o._.fillsize = [this.offsetWidth, this.offsetHeight];
  4531. });
  4532. } else {
  4533. fill.color = R.getRGB(params.fill).hex;
  4534. fill.src = E;
  4535. fill.type = "solid";
  4536. if (R.getRGB(params.fill).error && (res.type in {circle: 1, ellipse: 1} || Str(params.fill).charAt() != "r") && addGradientFill(res, params.fill, fill)) {
  4537. a.fill = "none";
  4538. a.gradient = params.fill;
  4539. fill.rotate = false;
  4540. }
  4541. }
  4542. }
  4543. if ("fill-opacity" in params || "opacity" in params) {
  4544. var opacity = ((+a["fill-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+R.getRGB(params.fill).o + 1 || 2) - 1);
  4545. opacity = mmin(mmax(opacity, 0), 1);
  4546. fill.opacity = opacity;
  4547. if (fill.src) {
  4548. fill.color = "none";
  4549. }
  4550. }
  4551. node.appendChild(fill);
  4552. var stroke = (node.getElementsByTagName("stroke") && node.getElementsByTagName("stroke")[0]),
  4553. newstroke = false;
  4554. !stroke && (newstroke = stroke = createNode("stroke"));
  4555. if ((params.stroke && params.stroke != "none") ||
  4556. params["stroke-width"] ||
  4557. params["stroke-opacity"] != null ||
  4558. params["stroke-dasharray"] ||
  4559. params["stroke-miterlimit"] ||
  4560. params["stroke-linejoin"] ||
  4561. params["stroke-linecap"]) {
  4562. stroke.on = true;
  4563. }
  4564. (params.stroke == "none" || params.stroke === null || stroke.on == null || params.stroke == 0 || params["stroke-width"] == 0) && (stroke.on = false);
  4565. var strokeColor = R.getRGB(params.stroke);
  4566. stroke.on && params.stroke && (stroke.color = strokeColor.hex);
  4567. opacity = ((+a["stroke-opacity"] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
  4568. var width = (toFloat(params["stroke-width"]) || 1) * .75;
  4569. opacity = mmin(mmax(opacity, 0), 1);
  4570. params["stroke-width"] == null && (width = a["stroke-width"]);
  4571. params["stroke-width"] && (stroke.weight = width);
  4572. width && width < 1 && (opacity *= width) && (stroke.weight = 1);
  4573. stroke.opacity = opacity;
  4574. params["stroke-linejoin"] && (stroke.joinstyle = params["stroke-linejoin"] || "miter");
  4575. stroke.miterlimit = params["stroke-miterlimit"] || 8;
  4576. params["stroke-linecap"] && (stroke.endcap = params["stroke-linecap"] == "butt" ? "flat" : params["stroke-linecap"] == "square" ? "square" : "round");
  4577. if (params["stroke-dasharray"]) {
  4578. var dasharray = {
  4579. "-": "shortdash",
  4580. ".": "shortdot",
  4581. "-.": "shortdashdot",
  4582. "-..": "shortdashdotdot",
  4583. ". ": "dot",
  4584. "- ": "dash",
  4585. "--": "longdash",
  4586. "- .": "dashdot",
  4587. "--.": "longdashdot",
  4588. "--..": "longdashdotdot"
  4589. };
  4590. stroke.dashstyle = dasharray[has](params["stroke-dasharray"]) ? dasharray[params["stroke-dasharray"]] : E;
  4591. }
  4592. newstroke && node.appendChild(stroke);
  4593. }
  4594. if (res.type == "text") {
  4595. res.paper.canvas.style.display = E;
  4596. var span = res.paper.span,
  4597. m = 100,
  4598. fontSize = a.font && a.font.match(/\d+(?:\.\d*)?(?=px)/);
  4599. s = span.style;
  4600. a.font && (s.font = a.font);
  4601. a["font-family"] && (s.fontFamily = a["font-family"]);
  4602. a["font-weight"] && (s.fontWeight = a["font-weight"]);
  4603. a["font-style"] && (s.fontStyle = a["font-style"]);
  4604. fontSize = toFloat(a["font-size"] || fontSize && fontSize[0]) || 10;
  4605. s.fontSize = fontSize * m + "px";
  4606. res.textpath.string && (span.innerHTML = Str(res.textpath.string).replace(/</g, "&#60;").replace(/&/g, "&#38;").replace(/\n/g, "<br>"));
  4607. var brect = span.getBoundingClientRect();
  4608. res.W = a.w = (brect.right - brect.left) / m;
  4609. res.H = a.h = (brect.bottom - brect.top) / m;
  4610. // res.paper.canvas.style.display = "none";
  4611. res.X = a.x;
  4612. res.Y = a.y + res.H / 2;
  4613. ("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));
  4614. var dirtyattrs = ["x", "y", "text", "font", "font-family", "font-weight", "font-style", "font-size"];
  4615. for (var d = 0, dd = dirtyattrs.length; d < dd; d++) if (dirtyattrs[d] in params) {
  4616. res._.dirty = 1;
  4617. break;
  4618. }
  4619. // text-anchor emulation
  4620. switch (a["text-anchor"]) {
  4621. case "start":
  4622. res.textpath.style["v-text-align"] = "left";
  4623. res.bbx = res.W / 2;
  4624. break;
  4625. case "end":
  4626. res.textpath.style["v-text-align"] = "right";
  4627. res.bbx = -res.W / 2;
  4628. break;
  4629. default:
  4630. res.textpath.style["v-text-align"] = "center";
  4631. res.bbx = 0;
  4632. break;
  4633. }
  4634. res.textpath.style["v-text-kern"] = true;
  4635. }
  4636. // res.paper.canvas.style.display = E;
  4637. },
  4638. addGradientFill = function (o, gradient, fill) {
  4639. o.attrs = o.attrs || {};
  4640. var attrs = o.attrs,
  4641. pow = Math.pow,
  4642. opacity,
  4643. oindex,
  4644. type = "linear",
  4645. fxfy = ".5 .5";
  4646. o.attrs.gradient = gradient;
  4647. gradient = Str(gradient).replace(R._radial_gradient, function (all, fx, fy) {
  4648. type = "radial";
  4649. if (fx && fy) {
  4650. fx = toFloat(fx);
  4651. fy = toFloat(fy);
  4652. pow(fx - .5, 2) + pow(fy - .5, 2) > .25 && (fy = math.sqrt(.25 - pow(fx - .5, 2)) * ((fy > .5) * 2 - 1) + .5);
  4653. fxfy = fx + S + fy;
  4654. }
  4655. return E;
  4656. });
  4657. gradient = gradient.split(/\s*\-\s*/);
  4658. if (type == "linear") {
  4659. var angle = gradient.shift();
  4660. angle = -toFloat(angle);
  4661. if (isNaN(angle)) {
  4662. return null;
  4663. }
  4664. }
  4665. var dots = R._parseDots(gradient);
  4666. if (!dots) {
  4667. return null;
  4668. }
  4669. o = o.shape || o.node;
  4670. if (dots.length) {
  4671. o.removeChild(fill);
  4672. fill.on = true;
  4673. fill.method = "none";
  4674. fill.color = dots[0].color;
  4675. fill.color2 = dots[dots.length - 1].color;
  4676. var clrs = [];
  4677. for (var i = 0, ii = dots.length; i < ii; i++) {
  4678. dots[i].offset && clrs.push(dots[i].offset + S + dots[i].color);
  4679. }
  4680. fill.colors = clrs.length ? clrs.join() : "0% " + fill.color;
  4681. if (type == "radial") {
  4682. fill.type = "gradientTitle";
  4683. fill.focus = "100%";
  4684. fill.focussize = "0 0";
  4685. fill.focusposition = fxfy;
  4686. fill.angle = 0;
  4687. } else {
  4688. // fill.rotate= true;
  4689. fill.type = "gradient";
  4690. fill.angle = (270 - angle) % 360;
  4691. }
  4692. o.appendChild(fill);
  4693. }
  4694. return 1;
  4695. },
  4696. Element = function (node, vml) {
  4697. this[0] = this.node = node;
  4698. node.raphael = true;
  4699. this.id = R._oid++;
  4700. node.raphaelid = this.id;
  4701. this.X = 0;
  4702. this.Y = 0;
  4703. this.attrs = {};
  4704. this.paper = vml;
  4705. this.matrix = R.matrix();
  4706. this._ = {
  4707. transform: [],
  4708. sx: 1,
  4709. sy: 1,
  4710. dx: 0,
  4711. dy: 0,
  4712. deg: 0,
  4713. dirty: 1,
  4714. dirtyT: 1
  4715. };
  4716. !vml.bottom && (vml.bottom = this);
  4717. this.prev = vml.top;
  4718. vml.top && (vml.top.next = this);
  4719. vml.top = this;
  4720. this.next = null;
  4721. };
  4722. var elproto = R.el;
  4723. Element.prototype = elproto;
  4724. elproto.constructor = Element;
  4725. elproto.transform = function (tstr) {
  4726. if (tstr == null) {
  4727. return this._.transform;
  4728. }
  4729. var vbs = this.paper._viewBoxShift,
  4730. vbt = vbs ? "s" + [vbs.scale, vbs.scale] + "-1-1t" + [vbs.dx, vbs.dy] : E,
  4731. oldt;
  4732. if (vbs) {
  4733. oldt = tstr = Str(tstr).replace(/\.{3}|\u2026/g, this._.transform || E);
  4734. }
  4735. R._extractTransform(this, vbt + tstr);
  4736. var matrix = this.matrix.clone(),
  4737. skew = this.skew,
  4738. o = this.node,
  4739. split,
  4740. isGrad = ~Str(this.attrs.fill).indexOf("-"),
  4741. isPatt = !Str(this.attrs.fill).indexOf("url(");
  4742. matrix.translate(-.5, -.5);
  4743. if (isPatt || isGrad || this.type == "image") {
  4744. skew.matrix = "1 0 0 1";
  4745. skew.offset = "0 0";
  4746. split = matrix.split();
  4747. if ((isGrad && split.noRotation) || !split.isSimple) {
  4748. o.style.filter = matrix.toFilter();
  4749. var bb = this.getBBox(),
  4750. bbt = this.getBBox(1),
  4751. dx = bb.x - bbt.x,
  4752. dy = bb.y - bbt.y;
  4753. o.coordorigin = (dx * -zoom) + S + (dy * -zoom);
  4754. setCoords(this, 1, 1, dx, dy, 0);
  4755. } else {
  4756. o.style.filter = E;
  4757. setCoords(this, split.scalex, split.scaley, split.dx, split.dy, split.rotate);
  4758. }
  4759. } else {
  4760. o.style.filter = E;
  4761. skew.matrix = Str(matrix);
  4762. skew.offset = matrix.offset();
  4763. }
  4764. oldt && (this._.transform = oldt);
  4765. return this;
  4766. };
  4767. elproto.rotate = function (deg, cx, cy) {
  4768. if (this.removed) {
  4769. return this;
  4770. }
  4771. if (deg == null) {
  4772. return;
  4773. }
  4774. deg = Str(deg).split(separator);
  4775. if (deg.length - 1) {
  4776. cx = toFloat(deg[1]);
  4777. cy = toFloat(deg[2]);
  4778. }
  4779. deg = toFloat(deg[0]);
  4780. (cy == null) && (cx = cy);
  4781. if (cx == null || cy == null) {
  4782. var bbox = this.getBBox(1);
  4783. cx = bbox.x + bbox.width / 2;
  4784. cy = bbox.y + bbox.height / 2;
  4785. }
  4786. this._.dirtyT = 1;
  4787. this.transform(this._.transform.concat([["r", deg, cx, cy]]));
  4788. return this;
  4789. };
  4790. elproto.translate = function (dx, dy) {
  4791. if (this.removed) {
  4792. return this;
  4793. }
  4794. dx = Str(dx).split(separator);
  4795. if (dx.length - 1) {
  4796. dy = toFloat(dx[1]);
  4797. }
  4798. dx = toFloat(dx[0]) || 0;
  4799. dy = +dy || 0;
  4800. if (this._.bbox) {
  4801. this._.bbox.x += dx;
  4802. this._.bbox.y += dy;
  4803. }
  4804. this.transform(this._.transform.concat([["t", dx, dy]]));
  4805. return this;
  4806. };
  4807. elproto.scale = function (sx, sy, cx, cy) {
  4808. if (this.removed) {
  4809. return this;
  4810. }
  4811. sx = Str(sx).split(separator);
  4812. if (sx.length - 1) {
  4813. sy = toFloat(sx[1]);
  4814. cx = toFloat(sx[2]);
  4815. cy = toFloat(sx[3]);
  4816. isNaN(cx) && (cx = null);
  4817. isNaN(cy) && (cy = null);
  4818. }
  4819. sx = toFloat(sx[0]);
  4820. (sy == null) && (sy = sx);
  4821. (cy == null) && (cx = cy);
  4822. if (cx == null || cy == null) {
  4823. var bbox = this.getBBox(1);
  4824. }
  4825. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  4826. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  4827. this.transform(this._.transform.concat([["s", sx, sy, cx, cy]]));
  4828. this._.dirtyT = 1;
  4829. return this;
  4830. };
  4831. elproto.hide = function () {
  4832. !this.removed && (this.node.style.display = "none");
  4833. return this;
  4834. };
  4835. elproto.show = function () {
  4836. !this.removed && (this.node.style.display = E);
  4837. return this;
  4838. };
  4839. elproto._getBBox = function () {
  4840. if (this.removed) {
  4841. return {};
  4842. }
  4843. return {
  4844. x: this.X + (this.bbx || 0) - this.W / 2,
  4845. y: this.Y - this.H,
  4846. width: this.W,
  4847. height: this.H
  4848. };
  4849. };
  4850. elproto.remove = function () {
  4851. if (this.removed) {
  4852. return;
  4853. }
  4854. this.paper.__set__ && this.paper.__set__.exclude(this);
  4855. R.eve.unbind("*.*." + this.id);
  4856. R._tear(this, this.paper);
  4857. this.node.parentNode.removeChild(this.node);
  4858. this.shape && this.shape.parentNode.removeChild(this.shape);
  4859. for (var i in this) {
  4860. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  4861. }
  4862. this.removed = true;
  4863. };
  4864. elproto.attr = function (name, value) {
  4865. if (this.removed) {
  4866. return this;
  4867. }
  4868. if (name == null) {
  4869. var res = {};
  4870. for (var a in this.attrs) if (this.attrs[has](a)) {
  4871. res[a] = this.attrs[a];
  4872. }
  4873. res.gradient && res.fill == "none" && (res.fill = res.gradient) && delete res.gradient;
  4874. res.transform = this._.transform;
  4875. return res;
  4876. }
  4877. if (value == null && R.is(name, "string")) {
  4878. if (name == fillString && this.attrs.fill == "none" && this.attrs.gradient) {
  4879. return this.attrs.gradient;
  4880. }
  4881. var names = name.split(separator),
  4882. out = {};
  4883. for (var i = 0, ii = names.length; i < ii; i++) {
  4884. name = names[i];
  4885. if (name in this.attrs) {
  4886. out[name] = this.attrs[name];
  4887. } else if (R.is(this.paper.customAttributes[name], "function")) {
  4888. out[name] = this.paper.customAttributes[name].def;
  4889. } else {
  4890. out[name] = R._availableAttrs[name];
  4891. }
  4892. }
  4893. return ii - 1 ? out : out[names[0]];
  4894. }
  4895. if (this.attrs && value == null && R.is(name, "array")) {
  4896. out = {};
  4897. for (i = 0, ii = name.length; i < ii; i++) {
  4898. out[name[i]] = this.attr(name[i]);
  4899. }
  4900. return out;
  4901. }
  4902. var params;
  4903. if (value != null) {
  4904. params = {};
  4905. params[name] = value;
  4906. }
  4907. value == null && R.is(name, "object") && (params = name);
  4908. for (var key in params) {
  4909. eve("attr." + key + "." + this.id, this, params[key]);
  4910. }
  4911. if (params) {
  4912. for (key in this.paper.customAttributes) if (this.paper.customAttributes[has](key) && params[has](key) && R.is(this.paper.customAttributes[key], "function")) {
  4913. var par = this.paper.customAttributes[key].apply(this, [].concat(params[key]));
  4914. this.attrs[key] = params[key];
  4915. for (var subkey in par) if (par[has](subkey)) {
  4916. params[subkey] = par[subkey];
  4917. }
  4918. }
  4919. // this.paper.canvas.style.display = "none";
  4920. if (params.text && this.type == "text") {
  4921. this.textpath.string = params.text;
  4922. }
  4923. setFillAndStroke(this, params);
  4924. // this.paper.canvas.style.display = E;
  4925. }
  4926. return this;
  4927. };
  4928. elproto.toFront = function () {
  4929. !this.removed && this.node.parentNode.appendChild(this.node);
  4930. this.paper && this.paper.top != this && R._tofront(this, this.paper);
  4931. return this;
  4932. };
  4933. elproto.toBack = function () {
  4934. if (this.removed) {
  4935. return this;
  4936. }
  4937. if (this.node.parentNode.firstChild != this.node) {
  4938. this.node.parentNode.insertBefore(this.node, this.node.parentNode.firstChild);
  4939. R._toback(this, this.paper);
  4940. }
  4941. return this;
  4942. };
  4943. elproto.insertAfter = function (element) {
  4944. if (this.removed) {
  4945. return this;
  4946. }
  4947. if (element.constructor == R.st.constructor) {
  4948. element = element[element.length - 1];
  4949. }
  4950. if (element.node.nextSibling) {
  4951. element.node.parentNode.insertBefore(this.node, element.node.nextSibling);
  4952. } else {
  4953. element.node.parentNode.appendChild(this.node);
  4954. }
  4955. R._insertafter(this, element, this.paper);
  4956. return this;
  4957. };
  4958. elproto.insertBefore = function (element) {
  4959. if (this.removed) {
  4960. return this;
  4961. }
  4962. if (element.constructor == R.st.constructor) {
  4963. element = element[0];
  4964. }
  4965. element.node.parentNode.insertBefore(this.node, element.node);
  4966. R._insertbefore(this, element, this.paper);
  4967. return this;
  4968. };
  4969. elproto.blur = function (size) {
  4970. var s = this.node.runtimeStyle,
  4971. f = s.filter;
  4972. f = f.replace(blurregexp, E);
  4973. if (+size !== 0) {
  4974. this.attrs.blur = size;
  4975. s.filter = f + S + ms + ".Blur(pixelradius=" + (+size || 1.5) + ")";
  4976. s.margin = R.format("-{0}px 0 0 -{0}px", round(+size || 1.5));
  4977. } else {
  4978. s.filter = f;
  4979. s.margin = 0;
  4980. delete this.attrs.blur;
  4981. }
  4982. };
  4983. R._engine.path = function (pathString, vml) {
  4984. var el = createNode("shape");
  4985. el.style.cssText = cssDot;
  4986. el.coordsize = zoom + S + zoom;
  4987. el.coordorigin = vml.coordorigin;
  4988. var p = new Element(el, vml),
  4989. attr = {fill: "none", stroke: "#000"};
  4990. pathString && (attr.path = pathString);
  4991. p.type = "path";
  4992. p.path = [];
  4993. p.Path = E;
  4994. setFillAndStroke(p, attr);
  4995. vml.canvas.appendChild(el);
  4996. var skew = createNode("skew");
  4997. skew.on = true;
  4998. el.appendChild(skew);
  4999. p.skew = skew;
  5000. p.transform(E);
  5001. return p;
  5002. };
  5003. R._engine.rect = function (vml, x, y, w, h, r) {
  5004. var path = R._rectPath(x, y, w, h, r),
  5005. res = vml.path(path),
  5006. a = res.attrs;
  5007. res.X = a.x = x;
  5008. res.Y = a.y = y;
  5009. res.W = a.width = w;
  5010. res.H = a.height = h;
  5011. a.r = r;
  5012. a.path = path;
  5013. res.type = "rect";
  5014. return res;
  5015. };
  5016. R._engine.ellipse = function (vml, x, y, rx, ry) {
  5017. var res = vml.path(),
  5018. a = res.attrs;
  5019. res.X = x - rx;
  5020. res.Y = y - ry;
  5021. res.W = rx * 2;
  5022. res.H = ry * 2;
  5023. res.type = "ellipse";
  5024. setFillAndStroke(res, {
  5025. cx: x,
  5026. cy: y,
  5027. rx: rx,
  5028. ry: ry
  5029. });
  5030. return res;
  5031. };
  5032. R._engine.circle = function (vml, x, y, r) {
  5033. var res = vml.path(),
  5034. a = res.attrs;
  5035. res.X = x - r;
  5036. res.Y = y - r;
  5037. res.W = res.H = r * 2;
  5038. res.type = "circle";
  5039. setFillAndStroke(res, {
  5040. cx: x,
  5041. cy: y,
  5042. r: r
  5043. });
  5044. return res;
  5045. };
  5046. R._engine.image = function (vml, src, x, y, w, h) {
  5047. var path = R._rectPath(x, y, w, h),
  5048. res = vml.path(path).attr({stroke: "none"}),
  5049. a = res.attrs,
  5050. node = res.node,
  5051. fill = node.getElementsByTagName(fillString)[0];
  5052. a.src = src;
  5053. res.X = a.x = x;
  5054. res.Y = a.y = y;
  5055. res.W = a.width = w;
  5056. res.H = a.height = h;
  5057. a.path = path;
  5058. res.type = "image";
  5059. fill.parentNode == node && node.removeChild(fill);
  5060. fill.rotate = true;
  5061. fill.src = src;
  5062. fill.type = "tile";
  5063. res._.fillpos = [x, y];
  5064. res._.fillsize = [w, h];
  5065. node.appendChild(fill);
  5066. setCoords(res, 1, 1, 0, 0, 0);
  5067. return res;
  5068. };
  5069. R._engine.text = function (vml, x, y, text) {
  5070. var el = createNode("shape"),
  5071. path = createNode("path"),
  5072. o = createNode("textpath");
  5073. x = x || 0;
  5074. y = y || 0;
  5075. text = text || "";
  5076. path.v = R.format("m{0},{1}l{2},{1}", round(x * zoom), round(y * zoom), round(x * zoom) + 1);
  5077. path.textpathok = true;
  5078. o.string = Str(text);
  5079. o.on = true;
  5080. el.style.cssText = cssDot;
  5081. el.coordsize = zoom + S + zoom;
  5082. el.coordorigin = "0 0";
  5083. var p = new Element(el, vml),
  5084. attr = {
  5085. fill: "#000",
  5086. stroke: "none",
  5087. font: R._availableAttrs.font,
  5088. text: text
  5089. };
  5090. p.shape = el;
  5091. p.path = path;
  5092. p.textpath = o;
  5093. p.type = "text";
  5094. p.attrs.text = Str(text);
  5095. p.attrs.x = x;
  5096. p.attrs.y = y;
  5097. p.attrs.w = 1;
  5098. p.attrs.h = 1;
  5099. setFillAndStroke(p, attr);
  5100. el.appendChild(o);
  5101. el.appendChild(path);
  5102. vml.canvas.appendChild(el);
  5103. var skew = createNode("skew");
  5104. skew.on = true;
  5105. el.appendChild(skew);
  5106. p.skew = skew;
  5107. p.transform(E);
  5108. return p;
  5109. };
  5110. R._engine.setSize = function (width, height) {
  5111. var cs = this.canvas.style;
  5112. this.width = width;
  5113. this.height = height;
  5114. width == +width && (width += "px");
  5115. height == +height && (height += "px");
  5116. cs.width = width;
  5117. cs.height = height;
  5118. cs.clip = "rect(0 " + width + " " + height + " 0)";
  5119. if (this._viewBox) {
  5120. R._engine.setViewBox.apply(this, this._viewBox);
  5121. }
  5122. return this;
  5123. };
  5124. R._engine.setViewBox = function (x, y, w, h, fit) {
  5125. R.eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
  5126. var width = this.width,
  5127. height = this.height,
  5128. size = 1 / mmax(w / width, h / height),
  5129. H, W;
  5130. if (fit) {
  5131. H = height / h;
  5132. W = width / w;
  5133. if (w * H < width) {
  5134. x -= (width - w * H) / 2 / H;
  5135. }
  5136. if (h * W < height) {
  5137. y -= (height - h * W) / 2 / W;
  5138. }
  5139. }
  5140. this._viewBox = [x, y, w, h, !!fit];
  5141. this._viewBoxShift = {
  5142. dx: -x,
  5143. dy: -y,
  5144. scale: size
  5145. };
  5146. this.forEach(function (el) {
  5147. el.transform("...");
  5148. });
  5149. return this;
  5150. };
  5151. var createNode;
  5152. R._engine.initWin = function (win) {
  5153. var doc = win.document;
  5154. doc.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)");
  5155. try {
  5156. !doc.namespaces.rvml && doc.namespaces.add("rvml", "urn:schemas-microsoft-com:vml");
  5157. createNode = function (tagName) {
  5158. return doc.createElement('<rvml:' + tagName + ' class="rvml">');
  5159. };
  5160. } catch (e) {
  5161. createNode = function (tagName) {
  5162. return doc.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
  5163. };
  5164. }
  5165. };
  5166. R._engine.initWin(R._g.win);
  5167. R._engine.create = function () {
  5168. var con = R._getContainer.apply(0, arguments),
  5169. container = con.container,
  5170. height = con.height,
  5171. s,
  5172. width = con.width,
  5173. x = con.x,
  5174. y = con.y;
  5175. if (!container) {
  5176. throw new Error("VML container not found.");
  5177. }
  5178. var res = new R._Paper,
  5179. c = res.canvas = R._g.doc.createElement("div"),
  5180. cs = c.style;
  5181. x = x || 0;
  5182. y = y || 0;
  5183. width = width || 512;
  5184. height = height || 342;
  5185. res.width = width;
  5186. res.height = height;
  5187. width == +width && (width += "px");
  5188. height == +height && (height += "px");
  5189. res.coordsize = zoom * 1e3 + S + zoom * 1e3;
  5190. res.coordorigin = "0 0";
  5191. res.span = R._g.doc.createElement("span");
  5192. res.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;";
  5193. c.appendChild(res.span);
  5194. 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);
  5195. if (container == 1) {
  5196. R._g.doc.body.appendChild(c);
  5197. cs.left = x + "px";
  5198. cs.top = y + "px";
  5199. cs.position = "absolute";
  5200. } else {
  5201. if (container.firstChild) {
  5202. container.insertBefore(c, container.firstChild);
  5203. } else {
  5204. container.appendChild(c);
  5205. }
  5206. }
  5207. // plugins.call(res, res, R.fn);
  5208. res.renderfix = function () {};
  5209. return res;
  5210. };
  5211. R.prototype.clear = function () {
  5212. R.eve("clear", this);
  5213. this.canvas.innerHTML = E;
  5214. this.span = R._g.doc.createElement("span");
  5215. this.span.style.cssText = "position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;";
  5216. this.canvas.appendChild(this.span);
  5217. this.bottom = this.top = null;
  5218. };
  5219. R.prototype.remove = function () {
  5220. R.eve("remove", this);
  5221. this.canvas.parentNode.removeChild(this.canvas);
  5222. for (var i in this) {
  5223. this[i] = typeof this[i] == "function" ? R._removedFactory(i) : null;
  5224. }
  5225. return true;
  5226. };
  5227. var setproto = R.st;
  5228. for (var method in elproto) if (elproto[has](method) && !setproto[has](method)) {
  5229. setproto[method] = (function (methodname) {
  5230. return function () {
  5231. var arg = arguments;
  5232. return this.forEach(function (el) {
  5233. el[methodname].apply(el, arg);
  5234. });
  5235. };
  5236. })(method);
  5237. }
  5238. }(window.Raphael);