raphael.no-deps.js 292 KB

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