You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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