raphael.js 305 KB

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