raphael.js 308 KB

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